1 void trigger_teleport_use()
4 self.team = activator.team;
7 #define TDEATHLOOP(o) \
12 deathmin = (o) + player.mins; \
13 deathmax = (o) + player.maxs; \
14 if(telefragmin != telefragmax) \
16 if(deathmin_x > telefragmin_x) deathmin_x = telefragmin_x; \
17 if(deathmin_y > telefragmin_y) deathmin_y = telefragmin_y; \
18 if(deathmin_z > telefragmin_z) deathmin_z = telefragmin_z; \
19 if(deathmax_x < telefragmax_x) deathmax_x = telefragmax_x; \
20 if(deathmax_y < telefragmax_y) deathmax_y = telefragmax_y; \
21 if(deathmax_z < telefragmax_z) deathmax_z = telefragmax_z; \
23 deathradius = max(vlen(deathmin), vlen(deathmax)); \
24 for(head = findradius(o, deathradius); head; head = head.chain) \
27 if(boxesoverlap(deathmin, deathmax, head.absmin, head.absmax))
30 float check_tdeath(entity player, vector org, vector telefragmin, vector telefragmax)
32 if (player.classname == "player" && player.health >= 1)
36 if not(teamplay && cvar("g_telefrags_teamplay") && head.team == player.team)
37 if(head.classname == "player")
45 void tdeath(entity player, entity teleporter, entity telefragger, vector telefragmin, vector telefragmax)
47 TDEATHLOOP(player.origin)
49 if (player.classname == "player" && player.health >= 1)
51 if not(teamplay && cvar("g_telefrags_teamplay") && head.team == player.team)
53 if(head.classname == "player")
56 Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');
59 else // dead bodies and monsters gib themselves instead of telefragging
60 Damage (telefragger, teleporter, telefragger, 10000, DEATH_TELEFRAG, telefragger.origin, '0 0 0');
64 void spawn_tdeath(vector v0, entity e, vector v)
66 tdeath(e, e, e, '0 0 0', '0 0 0');
70 #define TELEPORT_FLAG_SOUND 1
71 #define TELEPORT_FLAG_PARTICLES 2
72 #define TELEPORT_FLAG_TDEATH 4
73 #define TELEPORT_FLAG_FORCE_TDEATH 8
75 #define TELEPORT_FLAGS_WARPZONE 0
76 #define TELEPORT_FLAGS_PORTAL (TELEPORT_FLAG_SOUND | TELEPORT_FLAG_PARTICLES | TELEPORT_FLAG_TDEATH | TELEPORT_FLAG_FORCE_TDEATH)
77 #define TELEPORT_FLAGS_TELEPORTER (TELEPORT_FLAG_SOUND | TELEPORT_FLAG_PARTICLES | TELEPORT_FLAG_TDEATH)
78 void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity, vector telefragmin, vector telefragmax, float tflags)
85 telefragger = teleporter.owner;
89 makevectors (to_angles);
91 if(self.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
93 if(tflags & TELEPORT_FLAG_SOUND)
94 sound (player, CHAN_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTN_NORM);
95 if(tflags & TELEPORT_FLAG_PARTICLES)
97 pointparticles(particleeffectnum("teleport"), player.origin, '0 0 0', 1);
98 pointparticles(particleeffectnum("teleport"), to + v_forward * 32, '0 0 0', 1);
100 self.pushltime = time + 0.2;
103 // Relocate the player
104 // assuming to allows PL_MIN to PL_MAX box and some more
105 from = player.origin;
106 setorigin (player, to);
107 player.oldorigin = to; // don't undo the teleport by unsticking
108 player.angles = to_angles;
109 player.fixangle = TRUE;
110 player.velocity = to_velocity;
111 BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
113 UpdateCSQCProjectileAfterTeleport(player);
115 if(player.classname == "player")
117 if(tflags & TELEPORT_FLAG_TDEATH)
118 if(player.takedamage && player.deadflag == DEAD_NO && !g_race && !g_cts && (cvar("g_telefrags") || (tflags & TELEPORT_FLAG_FORCE_TDEATH)))
119 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
121 // player no longer is on ground
122 player.flags &~= FL_ONGROUND;
124 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
125 player.oldvelocity = player.velocity;
127 // reset tracking of who pushed you into a hazard (for kill credit)
130 player.pusher = teleporter.owner;
131 player.pushltime = time + cvar("g_maxpushtime");
135 player.pushltime = 0;
138 player.lastteleporttime = time;
140 // stop player name display
144 ClearSelectedPlayer();
150 void Teleport_Touch (void)
157 if (other.health < 1)
159 if not(other.flags & FL_CLIENT) // FIXME: Make missiles firable through the teleport too
163 if((self.spawnflags & 4 == 0) == (self.team != other.team))
168 makevectors(self.enemy.mangle);
170 if(other.classname == "player")
171 RemoveGrapplingHook(other);
179 RandomSelection_Init();
180 for(e = world; (e = find(e, targetname, self.target)); )
183 if(cvar("g_telefrags_avoid"))
185 o = e.origin + '0 0 1' * (1 - other.mins_z - 24);
186 if(check_tdeath(other, o, '0 0 0', '0 0 0'))
190 RandomSelection_Add(e, 0, string_null, e.cnt, p);
192 RandomSelection_Add(e, 0, string_null, 1, p);
194 e = RandomSelection_chosen_ent;
199 sprint(other, "Teleport destination vanished. Sorry... please complain to the mapper.\n");
203 if(vlen(other.velocity) > e.speed)
204 other.velocity = normalize(other.velocity) * max(0, e.speed);
205 if(cvar("g_teleport_maxspeed"))
206 if(vlen(other.velocity) > cvar("g_teleport_maxspeed"))
207 other.velocity = normalize(other.velocity) * max(0, cvar("g_teleport_maxspeed"));
209 o = e.origin + '0 0 1' * (1 - other.mins_z - 24);
210 TeleportPlayer(self, other, o, e.mangle, v_forward * vlen(other.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
213 s = self.target; self.target = string_null;
215 if not(self.target) self.target = s;
223 void spawnfunc_info_teleport_destination (void)
225 self.classname = "info_teleport_destination";
227 self.mangle = self.angles;
228 self.angles = '0 0 0';
230 //setorigin (self, self.origin + '0 0 27'); // To fix a mappers' habit as old as Quake
231 setorigin (self, self.origin);
237 objerror ("^3Teleport destination without a targetname");
240 void spawnfunc_misc_teleporter_dest (void)
242 spawnfunc_info_teleport_destination();
245 void spawnfunc_target_teleporter (void)
247 spawnfunc_info_teleport_destination();
250 void teleport_findtarget (void)
255 RandomSelection_Init();
257 for(e = world; (e = find(e, targetname, self.target)); )
260 if(e.movetype == MOVETYPE_NONE)
261 RandomSelection_Add(e, 0, string_null, 1, 1);
262 if(e.classname != "info_teleport_destination")
263 print("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.\n");
265 if(RandomSelection_chosen_ent)
266 waypoint_spawnforteleporter(self, RandomSelection_chosen_ent.origin, 0);
271 objerror ("Teleporter with nonexistant target");
276 // exactly one dest - bots love that
277 self.enemy = find(e, targetname, self.target);
278 self.dest = self.enemy.origin;
282 // have to use random selection every single time
287 self.touch = Teleport_Touch;
290 void spawnfunc_trigger_teleport (void)
292 self.angles = '0 0 0';
296 self.use = trigger_teleport_use;
298 // this must be called to spawn the teleport waypoints for bots
299 InitializeEntity(self, teleport_findtarget, INITPRIO_FINDTARGET);
303 objerror ("Teleporter with no target");
308 void WarpZone_PostTeleportPlayer_Callback(entity pl)
310 UpdateCSQCProjectileAfterTeleport(pl);
311 if(pl.classname == "player")
313 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
314 pl.oldvelocity = pl.velocity;
315 // reset teleport time tracking too (or multijump can cause insane speeds)
316 pl.lastteleporttime = time;