g_newtrig.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // Copyright (c) ZeniMax Media Inc.
  2. // Licensed under the GNU General Public License 2.0.
  3. // g_newtrig.c
  4. // pmack
  5. // october 1997
  6. #include "g_local.h"
  7. #define TELEPORT_PLAYER_ONLY 1
  8. #define TELEPORT_SILENT 2
  9. #define TELEPORT_CTF_ONLY 4
  10. #define TELEPORT_START_ON 8
  11. extern void TeleportEffect (vec3_t origin);
  12. /*QUAKED info_teleport_destination (.5 .5 .5) (-16 -16 -24) (16 16 32)
  13. Destination marker for a teleporter.
  14. */
  15. void SP_info_teleport_destination (edict_t *self)
  16. {
  17. }
  18. /*QUAKED trigger_teleport (.5 .5 .5) ? player_only silent ctf_only start_on
  19. Any object touching this will be transported to the corresponding
  20. info_teleport_destination entity. You must set the "target" field,
  21. and create an object with a "targetname" field that matches.
  22. If the trigger_teleport has a targetname, it will only teleport
  23. entities when it has been fired.
  24. player_only: only players are teleported
  25. silent: <not used right now>
  26. ctf_only: <not used right now>
  27. start_on: when trigger has targetname, start active, deactivate when used.
  28. */
  29. void trigger_teleport_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
  30. {
  31. edict_t *dest;
  32. int i;
  33. if(/*(self->spawnflags & TELEPORT_PLAYER_ONLY) &&*/ !(other->client))
  34. return;
  35. if(self->delay)
  36. return;
  37. dest = G_Find (NULL, FOFS(targetname), self->target);
  38. if(!dest)
  39. {
  40. gi.dprintf("Teleport Destination not found!\n");
  41. return;
  42. }
  43. gi.WriteByte (svc_temp_entity);
  44. gi.WriteByte (TE_TELEPORT_EFFECT);
  45. gi.WritePosition (other->s.origin);
  46. gi.multicast (other->s.origin, MULTICAST_PVS);
  47. // unlink to make sure it can't possibly interfere with KillBox
  48. gi.unlinkentity (other);
  49. VectorCopy (dest->s.origin, other->s.origin);
  50. VectorCopy (dest->s.origin, other->s.old_origin);
  51. other->s.origin[2] += 10;
  52. // clear the velocity and hold them in place briefly
  53. VectorClear (other->velocity);
  54. if(other->client)
  55. {
  56. other->client->ps.pmove.pm_time = 160>>3; // hold time
  57. other->client->ps.pmove.pm_flags |= PMF_TIME_TELEPORT;
  58. // draw the teleport splash at source and on the player
  59. // self->s.event = EV_PLAYER_TELEPORT;
  60. other->s.event = EV_PLAYER_TELEPORT;
  61. // set angles
  62. for (i=0 ; i<3 ; i++)
  63. other->client->ps.pmove.delta_angles[i] = ANGLE2SHORT(dest->s.angles[i] - other->client->resp.cmd_angles[i]);
  64. VectorClear (other->client->ps.viewangles);
  65. VectorClear (other->client->v_angle);
  66. }
  67. VectorClear (other->s.angles);
  68. // kill anything at the destination
  69. KillBox (other);
  70. gi.linkentity (other);
  71. }
  72. void trigger_teleport_use (edict_t *self, edict_t *other, edict_t *activator)
  73. {
  74. if(self->delay)
  75. self->delay = 0;
  76. else
  77. self->delay = 1;
  78. }
  79. void SP_trigger_teleport(edict_t *self)
  80. {
  81. if (!self->wait)
  82. self->wait = 0.2;
  83. self->delay = 0;
  84. if (self->targetname)
  85. {
  86. self->use = trigger_teleport_use;
  87. if(!(self->spawnflags & TELEPORT_START_ON))
  88. self->delay = 1;
  89. }
  90. self->touch = trigger_teleport_touch;
  91. self->solid = SOLID_TRIGGER;
  92. self->movetype = MOVETYPE_NONE;
  93. // self->flags |= FL_NOCLIENT;
  94. if (!VectorCompare(self->s.angles, vec3_origin))
  95. G_SetMovedir (self->s.angles, self->movedir);
  96. gi.setmodel (self, self->model);
  97. gi.linkentity (self);
  98. }
  99. // ***************************
  100. // TRIGGER_DISGUISE
  101. // ***************************
  102. /*QUAKED trigger_disguise (.5 .5 .5) ? TOGGLE START_ON REMOVE
  103. Anything passing through this trigger when it is active will
  104. be marked as disguised.
  105. TOGGLE - field is turned off and on when used.
  106. START_ON - field is active when spawned.
  107. REMOVE - field removes the disguise
  108. */
  109. void trigger_disguise_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
  110. {
  111. if (other->client)
  112. {
  113. if(self->spawnflags & 4)
  114. other->flags &= ~FL_DISGUISED;
  115. else
  116. other->flags |= FL_DISGUISED;
  117. }
  118. }
  119. void trigger_disguise_use (edict_t *self, edict_t *other, edict_t *activator)
  120. {
  121. if(self->solid == SOLID_NOT)
  122. self->solid = SOLID_TRIGGER;
  123. else
  124. self->solid = SOLID_NOT;
  125. gi.linkentity(self);
  126. }
  127. void SP_trigger_disguise (edict_t *self)
  128. {
  129. if(self->spawnflags & 2)
  130. self->solid = SOLID_TRIGGER;
  131. else
  132. self->solid = SOLID_NOT;
  133. self->touch = trigger_disguise_touch;
  134. self->use = trigger_disguise_use;
  135. self->movetype = MOVETYPE_NONE;
  136. self->svflags = SVF_NOCLIENT;
  137. gi.setmodel (self, self->model);
  138. gi.linkentity(self);
  139. }