p_telept.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // Emacs style mode select -*- C++ -*-
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. // $Log:$
  18. //
  19. // DESCRIPTION:
  20. // Teleportation.
  21. //
  22. //-----------------------------------------------------------------------------
  23. static const char
  24. rcsid[] = "$Id: p_telept.c,v 1.3 1997/01/28 22:08:29 b1 Exp $";
  25. #include "doomdef.h"
  26. #include "s_sound.h"
  27. #include "p_local.h"
  28. // Data.
  29. #include "sounds.h"
  30. // State.
  31. #include "r_state.h"
  32. //
  33. // TELEPORTATION
  34. //
  35. int
  36. EV_Teleport
  37. ( line_t* line,
  38. int side,
  39. mobj_t* thing )
  40. {
  41. int i;
  42. int tag;
  43. mobj_t* m;
  44. mobj_t* fog;
  45. unsigned an;
  46. thinker_t* thinker;
  47. sector_t* sector;
  48. fixed_t oldx;
  49. fixed_t oldy;
  50. fixed_t oldz;
  51. // don't teleport missiles
  52. if (thing->flags & MF_MISSILE)
  53. return 0;
  54. // Don't teleport if hit back of line,
  55. // so you can get out of teleporter.
  56. if (side == 1)
  57. return 0;
  58. tag = line->tag;
  59. for (i = 0; i < numsectors; i++)
  60. {
  61. if (sectors[ i ].tag == tag )
  62. {
  63. thinker = thinkercap.next;
  64. for (thinker = thinkercap.next;
  65. thinker != &thinkercap;
  66. thinker = thinker->next)
  67. {
  68. // not a mobj
  69. if (thinker->function.acp1 != (actionf_p1)P_MobjThinker)
  70. continue;
  71. m = (mobj_t *)thinker;
  72. // not a teleportman
  73. if (m->type != MT_TELEPORTMAN )
  74. continue;
  75. sector = m->subsector->sector;
  76. // wrong sector
  77. if (sector-sectors != i )
  78. continue;
  79. oldx = thing->x;
  80. oldy = thing->y;
  81. oldz = thing->z;
  82. if (!P_TeleportMove (thing, m->x, m->y))
  83. return 0;
  84. thing->z = thing->floorz; //fixme: not needed?
  85. if (thing->player)
  86. thing->player->viewz = thing->z+thing->player->viewheight;
  87. // spawn teleport fog at source and destination
  88. fog = P_SpawnMobj (oldx, oldy, oldz, MT_TFOG);
  89. S_StartSound (fog, sfx_telept);
  90. an = m->angle >> ANGLETOFINESHIFT;
  91. fog = P_SpawnMobj (m->x+20*finecosine[an], m->y+20*finesine[an]
  92. , thing->z, MT_TFOG);
  93. // emit sound, where?
  94. S_StartSound (fog, sfx_telept);
  95. // don't move for a bit
  96. if (thing->player)
  97. thing->reactiontime = 18;
  98. thing->angle = m->angle;
  99. thing->momx = thing->momy = thing->momz = 0;
  100. return 1;
  101. }
  102. }
  103. }
  104. return 0;
  105. }