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(teams_matter && 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(teams_matter && 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)
85 telefragger = teleporter.owner;
89 makevectors (to_angles);
91 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
93 if(self.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
95 if(tflags & TELEPORT_FLAG_SOUND)
96 sound (player, CHAN_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTN_NORM);
97 if(tflags & TELEPORT_FLAG_PARTICLES)
99 pointparticles(particleeffectnum("teleport"), player.origin, '0 0 0', 1);
100 pointparticles(particleeffectnum("teleport"), to + v_forward * 32, '0 0 0', 1);
102 self.pushltime = time + 0.2;
106 // Relocate the player
107 // assuming to allows PL_MIN to PL_MAX box and some more
108 from = player.origin;
109 setorigin (player, to);
110 player.oldorigin = to; // don't undo the teleport by unsticking
111 player.angles = to_angles;
112 player.fixangle = TRUE;
113 player.velocity = to_velocity;
114 BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
116 UpdateCSQCProjectileAfterTeleport(player);
118 if(player.classname == "player")
120 if(tflags & TELEPORT_FLAG_TDEATH)
121 if(player.takedamage && player.deadflag == DEAD_NO && !g_race && !g_cts && (autocvar_g_telefrags || (tflags & TELEPORT_FLAG_FORCE_TDEATH)))
122 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
124 // player no longer is on ground
125 player.flags &~= FL_ONGROUND;
127 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
128 player.oldvelocity = player.velocity;
130 // reset tracking of who pushed you into a hazard (for kill credit)
133 player.pusher = teleporter.owner;
134 player.pushltime = time + autocvar_g_maxpushtime;
138 player.pushltime = 0;
141 player.lastteleporttime = time;
143 // stop player name display
147 ClearSelectedPlayer();
153 void Simple_TeleportPlayer(entity teleporter, entity player)
159 // Find the output teleporter
160 if(!teleporter.enemy)
162 RandomSelection_Init();
163 for(e = world; (e = find(e, targetname, teleporter.target)); )
166 if(autocvar_g_telefrags_avoid)
168 locout = e.origin + '0 0 1' * (1 - player.mins_z - 24);
169 if(check_tdeath(player, locout, '0 0 0', '0 0 0'))
172 RandomSelection_Add(e, 0, string_null, (e.cnt ? e.cnt : 1), p);
174 teleporter.enemy = RandomSelection_chosen_ent;
177 if(!teleporter.enemy) { sprint(player, "Teleport destination vanished. Sorry... please complain to the mapper.\n"); }
179 makevectors(teleporter.enemy.mangle);
181 if(teleporter.enemy.speed)
182 if(vlen(player.velocity) > teleporter.enemy.speed)
183 player.velocity = normalize(player.velocity) * max(0, teleporter.enemy.speed);
185 if(autocvar_g_teleport_maxspeed)
186 if(vlen(player.velocity) > autocvar_g_teleport_maxspeed)
187 player.velocity = normalize(player.velocity) * max(0, autocvar_g_teleport_maxspeed);
189 locout = teleporter.enemy.origin + '0 0 1' * (1 - player.mins_z - 24);
190 TeleportPlayer(teleporter, player, locout, teleporter.enemy.mangle, v_forward * vlen(player.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
193 void Teleport_Touch (void)
198 if (self.active != ACTIVE_ACTIVE)
201 if (other.deadflag != DEAD_NO)
203 if not(other.flags & FL_CLIENT) // FIXME: Make missiles firable through the teleport too
207 if((self.spawnflags & 4 == 0) == (self.team != other.team))
212 if(other.classname == "player")
213 RemoveGrapplingHook(other);
215 Simple_TeleportPlayer(self, other);
218 s = self.target; self.target = string_null;
220 if not(self.target) self.target = s;
228 void spawnfunc_info_teleport_destination (void)
230 self.classname = "info_teleport_destination";
232 self.mangle = self.angles;
233 self.angles = '0 0 0';
235 //setorigin (self, self.origin + '0 0 27'); // To fix a mappers' habit as old as Quake
236 setorigin (self, self.origin);
242 objerror ("^3Teleport destination without a targetname");
245 void spawnfunc_misc_teleporter_dest (void)
247 spawnfunc_info_teleport_destination();
250 void spawnfunc_target_teleporter (void)
252 spawnfunc_info_teleport_destination();
255 void teleport_findtarget (void)
260 RandomSelection_Init();
262 for(e = world; (e = find(e, targetname, self.target)); )
265 if(e.movetype == MOVETYPE_NONE)
266 RandomSelection_Add(e, 0, string_null, 1, 1);
267 if(e.classname != "info_teleport_destination")
268 print("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.\n");
270 if(RandomSelection_chosen_ent)
271 waypoint_spawnforteleporter(self, RandomSelection_chosen_ent.origin, 0);
276 objerror ("Teleporter with nonexistant target");
281 // exactly one dest - bots love that
282 self.enemy = find(e, targetname, self.target);
283 self.dest = self.enemy.origin;
287 // have to use random selection every single time
292 self.touch = Teleport_Touch;
295 entity Teleport_Find(vector mi, vector ma)
298 for(e = world; (e = find(e, classname, "trigger_teleport")); )
299 if(WarpZoneLib_BoxTouchesBrush(mi, ma, e, world))
304 entity teleport_first;
305 .entity teleport_next;
306 void spawnfunc_trigger_teleport (void)
308 self.angles = '0 0 0';
312 self.active = ACTIVE_ACTIVE;
314 self.use = trigger_teleport_use;
316 // this must be called to spawn the teleport waypoints for bots
317 InitializeEntity(self, teleport_findtarget, INITPRIO_FINDTARGET);
321 objerror ("Teleporter with no target");
325 self.teleport_next = teleport_first;
326 teleport_first = self;
329 void WarpZone_PostTeleportPlayer_Callback(entity pl)
331 UpdateCSQCProjectileAfterTeleport(pl);
332 if(pl.classname == "player")
334 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
335 pl.oldvelocity = pl.velocity;
336 // reset teleport time tracking too (or multijump can cause insane speeds)
337 pl.lastteleporttime = time;