P_TELEPT.C 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // P_telept.c
  2. #include "DoomDef.h"
  3. #include "P_local.h"
  4. #include "soundst.h"
  5. //----------------------------------------------------------------------------
  6. //
  7. // FUNC P_Teleport
  8. //
  9. //----------------------------------------------------------------------------
  10. boolean P_Teleport(mobj_t *thing, fixed_t x, fixed_t y, angle_t angle)
  11. {
  12. fixed_t oldx;
  13. fixed_t oldy;
  14. fixed_t oldz;
  15. fixed_t aboveFloor;
  16. fixed_t fogDelta;
  17. player_t *player;
  18. unsigned an;
  19. mobj_t *fog;
  20. oldx = thing->x;
  21. oldy = thing->y;
  22. oldz = thing->z;
  23. aboveFloor = thing->z-thing->floorz;
  24. if(!P_TeleportMove(thing, x, y))
  25. {
  26. return(false);
  27. }
  28. if(thing->player)
  29. {
  30. player = thing->player;
  31. if(player->powers[pw_flight] && aboveFloor)
  32. {
  33. thing->z = thing->floorz+aboveFloor;
  34. if(thing->z+thing->height > thing->ceilingz)
  35. {
  36. thing->z = thing->ceilingz-thing->height;
  37. }
  38. player->viewz = thing->z+player->viewheight;
  39. }
  40. else
  41. {
  42. thing->z = thing->floorz;
  43. player->viewz = thing->z+player->viewheight;
  44. player->lookdir = 0;
  45. }
  46. }
  47. else if(thing->flags&MF_MISSILE)
  48. {
  49. thing->z = thing->floorz+aboveFloor;
  50. if(thing->z+thing->height > thing->ceilingz)
  51. {
  52. thing->z = thing->ceilingz-thing->height;
  53. }
  54. }
  55. else
  56. {
  57. thing->z = thing->floorz;
  58. }
  59. // Spawn teleport fog at source and destination
  60. fogDelta = thing->flags&MF_MISSILE ? 0 : TELEFOGHEIGHT;
  61. fog = P_SpawnMobj(oldx, oldy, oldz+fogDelta, MT_TFOG);
  62. S_StartSound(fog, sfx_telept);
  63. an = angle>>ANGLETOFINESHIFT;
  64. fog = P_SpawnMobj(x+20*finecosine[an],
  65. y+20*finesine[an], thing->z+fogDelta, MT_TFOG);
  66. S_StartSound(fog, sfx_telept);
  67. if(thing->player && !thing->player->powers[pw_weaponlevel2])
  68. { // Freeze player for about .5 sec
  69. thing->reactiontime = 18;
  70. }
  71. thing->angle = angle;
  72. if(thing->flags2&MF2_FOOTCLIP && P_GetThingFloorType(thing) != FLOOR_SOLID)
  73. {
  74. thing->flags2 |= MF2_FEETARECLIPPED;
  75. }
  76. else if(thing->flags2&MF2_FEETARECLIPPED)
  77. {
  78. thing->flags2 &= ~MF2_FEETARECLIPPED;
  79. }
  80. if(thing->flags&MF_MISSILE)
  81. {
  82. angle >>= ANGLETOFINESHIFT;
  83. thing->momx = FixedMul(thing->info->speed, finecosine[angle]);
  84. thing->momy = FixedMul(thing->info->speed, finesine[angle]);
  85. }
  86. else
  87. {
  88. thing->momx = thing->momy = thing->momz = 0;
  89. }
  90. return(true);
  91. }
  92. //----------------------------------------------------------------------------
  93. //
  94. // FUNC EV_Teleport
  95. //
  96. //----------------------------------------------------------------------------
  97. boolean EV_Teleport(line_t *line, int side, mobj_t *thing)
  98. {
  99. int i;
  100. int tag;
  101. mobj_t *m;
  102. thinker_t *thinker;
  103. sector_t *sector;
  104. if(thing->flags2&MF2_NOTELEPORT)
  105. {
  106. return(false);
  107. }
  108. if(side == 1)
  109. { // Don't teleport when crossing back side
  110. return(false);
  111. }
  112. tag = line->tag;
  113. for(i = 0; i < numsectors; i++)
  114. {
  115. if(sectors[i].tag == tag)
  116. {
  117. thinker = thinkercap.next;
  118. for(thinker = thinkercap.next; thinker != &thinkercap;
  119. thinker = thinker->next)
  120. {
  121. if(thinker->function != P_MobjThinker)
  122. { // Not a mobj
  123. continue;
  124. }
  125. m = (mobj_t *)thinker;
  126. if(m->type != MT_TELEPORTMAN )
  127. { // Not a teleportman
  128. continue;
  129. }
  130. sector = m->subsector->sector;
  131. if(sector-sectors != i)
  132. { // Wrong sector
  133. continue;
  134. }
  135. return(P_Teleport(thing, m->x, m->y, m->angle));
  136. }
  137. }
  138. }
  139. return(false);
  140. }