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 && autocvar_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 && autocvar_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)
84 telefragger = teleporter.owner;
88 makevectors (to_angles);
90 if(player.classname == "player") // don't play sounds or show particles for anything that isn't a player, maybe change later to block only observers
92 if(self.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
94 if(tflags & TELEPORT_FLAG_SOUND)
95 sound (player, CH_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTN_NORM);
96 if(tflags & TELEPORT_FLAG_PARTICLES)
98 pointparticles(particleeffectnum("teleport"), player.origin, '0 0 0', 1);
99 pointparticles(particleeffectnum("teleport"), to + v_forward * 32, '0 0 0', 1);
101 self.pushltime = time + 0.2;
105 // Relocate the player
106 // assuming to allows PL_MIN to PL_MAX box and some more
107 from = player.origin;
108 setorigin (player, to);
109 player.oldorigin = to; // don't undo the teleport by unsticking
110 player.angles = to_angles;
111 player.fixangle = TRUE;
112 player.velocity = to_velocity;
113 BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
115 UpdateCSQCProjectileAfterTeleport(player);
117 if(player.classname == "player")
119 if(tflags & TELEPORT_FLAG_TDEATH)
120 if(player.takedamage && player.deadflag == DEAD_NO && !g_race && !g_cts && (autocvar_g_telefrags || (tflags & TELEPORT_FLAG_FORCE_TDEATH)))
121 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
123 // player no longer is on ground
124 player.flags &~= FL_ONGROUND;
126 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
127 player.oldvelocity = player.velocity;
129 // reset tracking of who pushed you into a hazard (for kill credit)
132 player.pusher = teleporter.owner;
133 player.pushltime = time + autocvar_g_maxpushtime;
137 player.pushltime = 0;
140 player.lastteleporttime = time;
144 entity Simple_TeleportPlayer(entity teleporter, entity player)
150 // Find the output teleporter
153 e = teleporter.enemy;
157 RandomSelection_Init();
158 for(e = world; (e = find(e, targetname, teleporter.target)); )
161 if(autocvar_g_telefrags_avoid)
163 locout = e.origin + '0 0 1' * (1 - player.mins_z - 24);
164 if(check_tdeath(player, locout, '0 0 0', '0 0 0'))
167 RandomSelection_Add(e, 0, string_null, (e.cnt ? e.cnt : 1), p);
169 e = RandomSelection_chosen_ent;
172 if(!e) { sprint(player, "Teleport destination vanished. Sorry... please complain to the mapper.\n"); }
174 makevectors(e.mangle);
177 if(vlen(player.velocity) > e.speed)
178 player.velocity = normalize(player.velocity) * max(0, e.speed);
180 if(autocvar_g_teleport_maxspeed)
181 if(vlen(player.velocity) > autocvar_g_teleport_maxspeed)
182 player.velocity = normalize(player.velocity) * max(0, autocvar_g_teleport_maxspeed);
184 locout = e.origin + '0 0 1' * (1 - player.mins_z - 24);
185 TeleportPlayer(teleporter, player, locout, e.mangle, v_forward * vlen(player.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
190 void Teleport_Touch (void)
195 if (self.active != ACTIVE_ACTIVE)
198 if not(other.iscreature)
201 // for gameplay: vehicles can't teleport
202 if (other.vehicle_flags & VHF_ISVEHICLE)
205 if (other.deadflag != DEAD_NO)
209 if((self.spawnflags & 4 == 0) == (self.team != other.team))
214 if(other.classname == "player")
215 RemoveGrapplingHook(other);
218 e = Simple_TeleportPlayer(self, other);
221 s = self.target; self.target = string_null;
223 if not(self.target) self.target = s;
231 void spawnfunc_info_teleport_destination (void)
233 self.classname = "info_teleport_destination";
235 self.mangle = self.angles;
236 self.angles = '0 0 0';
238 //setorigin (self, self.origin + '0 0 27'); // To fix a mappers' habit as old as Quake
239 setorigin (self, self.origin);
245 objerror ("^3Teleport destination without a targetname");
248 void spawnfunc_misc_teleporter_dest (void)
250 spawnfunc_info_teleport_destination();
253 void spawnfunc_target_teleporter (void)
255 spawnfunc_info_teleport_destination();
258 void teleport_findtarget (void)
264 for(e = world; (e = find(e, targetname, self.target)); )
267 if(e.movetype == MOVETYPE_NONE)
268 waypoint_spawnforteleporter(self, e.origin, 0);
269 if(e.classname != "info_teleport_destination")
270 print("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.\n");
276 objerror ("Teleporter with nonexistant target");
281 // exactly one dest - bots love that
282 self.enemy = find(e, targetname, self.target);
286 // have to use random selection every single time
291 self.touch = Teleport_Touch;
294 entity Teleport_Find(vector mi, vector ma)
297 for(e = world; (e = find(e, classname, "trigger_teleport")); )
298 if(WarpZoneLib_BoxTouchesBrush(mi, ma, e, world))
303 entity teleport_first;
304 .entity teleport_next;
305 void spawnfunc_trigger_teleport (void)
307 self.angles = '0 0 0';
311 self.active = ACTIVE_ACTIVE;
313 self.use = trigger_teleport_use;
315 // this must be called to spawn the teleport waypoints for bots
316 InitializeEntity(self, teleport_findtarget, INITPRIO_FINDTARGET);
320 objerror ("Teleporter with no target");
324 self.teleport_next = teleport_first;
325 teleport_first = self;
328 void WarpZone_PostTeleportPlayer_Callback(entity pl)
330 UpdateCSQCProjectileAfterTeleport(pl);
331 // "disown" projectiles after teleport
333 if(pl.owner == pl.realowner)
335 if(!(pl.flags & FL_PROJECTILE))
336 print("A non-projectile got through a warpzone and its owner cleared. It's a ", pl.classname, ".\n");
339 if(pl.classname == "player")
341 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
342 pl.oldvelocity = pl.velocity;
343 // reset teleport time tracking too (or multijump can cause insane speeds)
344 pl.lastteleporttime = time;