1 void trigger_teleport_use()
\r
4 self.team = activator.team;
\r
7 #define TDEATHLOOP(o) \
\r
11 float deathradius; \
\r
12 deathmin = (o) + player.mins; \
\r
13 deathmax = (o) + player.maxs; \
\r
14 if(telefragmin != telefragmax) \
\r
16 if(deathmin_x > telefragmin_x) deathmin_x = telefragmin_x; \
\r
17 if(deathmin_y > telefragmin_y) deathmin_y = telefragmin_y; \
\r
18 if(deathmin_z > telefragmin_z) deathmin_z = telefragmin_z; \
\r
19 if(deathmax_x < telefragmax_x) deathmax_x = telefragmax_x; \
\r
20 if(deathmax_y < telefragmax_y) deathmax_y = telefragmax_y; \
\r
21 if(deathmax_z < telefragmax_z) deathmax_z = telefragmax_z; \
\r
23 deathradius = max(vlen(deathmin), vlen(deathmax)); \
\r
24 for(head = findradius(o, deathradius); head; head = head.chain) \
\r
25 if(head != player) \
\r
26 if(head.takedamage) \
\r
27 if(boxesoverlap(deathmin, deathmax, head.absmin, head.absmax))
\r
29 float check_tdeath(entity player, vector org, vector telefragmin, vector telefragmax)
\r
33 if ((player.classname == "player") && (player.health >= 1))
\r
35 if(head.classname == "player")
\r
36 if(head.health >= 1)
\r
43 void tdeath(entity player, entity teleporter, entity telefragger, vector telefragmin, vector telefragmax)
\r
45 tdeath_hit += 0; // dummy for compiler warning
\r
46 TDEATHLOOP(player.origin)
\r
48 if ((player.classname == "player") && (player.health >= 1))
\r
50 if(head.classname == "player")
\r
51 if(head.health >= 1)
\r
53 Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');
\r
55 else if (telefragger.health < 1) // corpses gib
\r
56 Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');
\r
57 else // dead bodies and monsters gib themselves instead of telefragging
\r
58 Damage (telefragger, teleporter, telefragger, 10000, DEATH_TELEFRAG, telefragger.origin, '0 0 0');
\r
62 void spawn_tdeath(vector v0, entity e, vector v)
\r
64 tdeath(e, e, e, '0 0 0', '0 0 0');
\r
68 #define TELEPORT_FLAG_SOUND 1
\r
69 #define TELEPORT_FLAG_PARTICLES 2
\r
70 #define TELEPORT_FLAG_TDEATH 4
\r
72 #define TELEPORT_FLAGS_WARPZONE 0
\r
73 #define TELEPORT_FLAGS_PORTAL (TELEPORT_FLAG_SOUND | TELEPORT_FLAG_PARTICLES)
\r
74 #define TELEPORT_FLAGS_TELEPORTER (TELEPORT_FLAG_SOUND | TELEPORT_FLAG_PARTICLES | TELEPORT_FLAG_TDEATH)
\r
75 void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity, vector telefragmin, vector telefragmax, float tflags)
\r
81 if(teleporter.owner)
\r
82 telefragger = teleporter.owner;
\r
84 telefragger = player;
\r
86 makevectors (to_angles);
\r
88 if(self.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
\r
90 if(tflags & TELEPORT_FLAG_SOUND)
\r
91 sound (player, CHAN_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTN_NORM);
\r
92 if(tflags & TELEPORT_FLAG_PARTICLES)
\r
94 pointparticles(particleeffectnum("teleport"), player.origin, '0 0 0', 1);
\r
95 pointparticles(particleeffectnum("teleport"), to + v_forward * 32, '0 0 0', 1);
\r
97 self.pushltime = time + 0.2;
\r
100 // Relocate the player
\r
101 // assuming to allows PL_MIN to PL_MAX box and some more
\r
102 from = player.origin;
\r
103 setorigin (player, to);
\r
104 player.oldorigin = to; // don't undo the teleport by unsticking
\r
105 player.angles = to_angles;
\r
106 player.fixangle = TRUE;
\r
107 player.velocity = to_velocity;
\r
108 BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
\r
110 UpdateCSQCProjectileAfterTeleport(player);
\r
112 if(player.classname == "player")
\r
114 if(tflags & TELEPORT_FLAG_TDEATH)
\r
115 if(player.takedamage && player.deadflag == DEAD_NO && !g_race && !g_cts && cvar("g_telefrags"))
\r
116 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
\r
118 // player no longer is on ground
\r
119 player.flags &~= FL_ONGROUND;
\r
121 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
\r
122 player.oldvelocity = player.velocity;
\r
124 // reset tracking of who pushed you into a hazard (for kill credit)
\r
125 if(teleporter.owner)
\r
127 player.pusher = teleporter.owner;
\r
128 player.pushltime = time + cvar("g_maxpushtime");
\r
132 player.pushltime = 0;
\r
135 player.lastteleporttime = time;
\r
137 // stop player name display
\r
141 ClearSelectedPlayer();
\r
147 void Teleport_Touch (void)
\r
153 if (other.health < 1)
\r
155 if not(other.flags & FL_CLIENT) // FIXME: Make missiles firable through the teleport too
\r
159 if((self.spawnflags & 4 == 0) == (self.team != other.team))
\r
162 EXACTTRIGGER_TOUCH;
\r
164 makevectors(self.enemy.mangle);
\r
166 if(other.classname == "player")
\r
167 RemoveGrabber(other);
\r
175 RandomSelection_Init();
\r
176 for(e = world; (e = find(e, targetname, self.target)); )
\r
179 if(cvar("g_telefrags_avoid"))
\r
181 o = e.origin + '0 0 1' * (1 - other.mins_z - 24);
\r
182 if(check_tdeath(other, o, '0 0 0', '0 0 0'))
\r
186 RandomSelection_Add(e, 0, string_null, e.cnt, p);
\r
188 RandomSelection_Add(e, 0, string_null, 1, p);
\r
190 e = RandomSelection_chosen_ent;
\r
195 sprint(other, "Teleport destination vanished. Sorry... please complain to the mapper.\n");
\r
199 if(vlen(other.velocity) > e.speed)
\r
200 other.velocity = normalize(other.velocity) * max(0, e.speed);
\r
201 if(cvar("g_teleport_maxspeed"))
\r
202 if(vlen(other.velocity) > cvar("g_teleport_maxspeed"))
\r
203 other.velocity = normalize(other.velocity) * max(0, cvar("g_teleport_maxspeed"));
\r
205 o = e.origin + '0 0 1' * (1 - other.mins_z - 24);
\r
206 TeleportPlayer(self, other, o, e.mangle, v_forward * vlen(other.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
\r
218 void spawnfunc_info_teleport_destination (void)
\r
220 self.classname = "info_teleport_destination";
\r
222 self.mangle = self.angles;
\r
223 self.angles = '0 0 0';
\r
225 //setorigin (self, self.origin + '0 0 27'); // To fix a mappers' habit as old as Quake
\r
226 setorigin (self, self.origin);
\r
232 objerror ("^3Teleport destination without a targetname");
\r
235 void spawnfunc_misc_teleporter_dest (void)
\r
237 spawnfunc_info_teleport_destination();
\r
240 void spawnfunc_target_teleporter (void)
\r
242 spawnfunc_info_teleport_destination();
\r
245 void teleport_findtarget (void)
\r
250 RandomSelection_Init();
\r
252 for(e = world; (e = find(e, targetname, self.target)); )
\r
255 if(e.movetype == MOVETYPE_NONE)
\r
256 RandomSelection_Add(e, 0, string_null, 1, 1);
\r
257 if(e.classname != "info_teleport_destination")
\r
258 print("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.\n");
\r
260 if(RandomSelection_chosen_ent)
\r
261 waypoint_spawnforteleporter(self, RandomSelection_chosen_ent.origin, 0);
\r
266 objerror ("Teleporter with nonexistant target");
\r
271 // exactly one dest - bots love that
\r
272 self.enemy = find(e, targetname, self.target);
\r
273 self.dest = self.enemy.origin;
\r
277 // have to use random selection every single time
\r
278 self.enemy = world;
\r
281 // now enable touch
\r
282 self.touch = Teleport_Touch;
\r
285 void spawnfunc_trigger_teleport (void)
\r
287 self.angles = '0 0 0';
\r
291 self.use = trigger_teleport_use;
\r
293 // this must be called to spawn the teleport waypoints for bots
\r
294 InitializeEntity(self, teleport_findtarget, INITPRIO_FINDTARGET);
\r
298 objerror ("Teleporter with no target");
\r
303 void WarpZone_PostTeleportPlayer_Callback(entity pl)
\r
305 UpdateCSQCProjectileAfterTeleport(pl);
\r
306 if(pl.classname == "player")
\r
308 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
\r
309 pl.oldvelocity = pl.velocity;
\r
310 // reset teleport time tracking too (or multijump can cause insane speeds)
\r
311 pl.lastteleporttime = time;
\r