1 #include "t_teleporters.qh"
6 #include "../warpzonelib/common.qh"
7 #include "../warpzonelib/util_server.qh"
8 #include "../warpzonelib/server.qh"
9 #include "../common/constants.qh"
10 #include "../common/util.qh"
11 #include "weapons/csqcprojectile.qh"
12 #include "autocvars.qh"
13 #include "constants.qh"
15 #include "../common/deathtypes.qh"
16 #include "tturrets/include/turrets_early.qh"
17 #include "vehicles/vehicles_def.qh"
18 #include "../common/mapinfo.qh"
19 #include "anticheat.qh"
22 void trigger_teleport_use()
25 self.team = activator.team;
28 float check_tdeath(entity player, vector org, vector telefragmin, vector telefragmax)
30 if (IS_PLAYER(player) && player.health >= 1)
34 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
43 void tdeath(entity player, entity teleporter, entity telefragger, vector telefragmin, vector telefragmax)
45 TDEATHLOOP(player.origin)
47 if (IS_PLAYER(player) && player.health >= 1)
49 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
54 Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');
57 else // dead bodies and monsters gib themselves instead of telefragging
58 Damage (telefragger, teleporter, telefragger, 10000, DEATH_TELEFRAG, telefragger.origin, '0 0 0');
62 void spawn_tdeath(vector v0, entity e, vector v)
64 tdeath(e, e, e, '0 0 0', '0 0 0');
67 void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity, vector telefragmin, vector telefragmax, float tflags)
73 telefragger = teleporter.owner;
77 makevectors (to_angles);
79 if(player.teleportable == TELEPORT_NORMAL) // don't play sounds or show particles for anything that isn't a player, maybe change later to block only observers
81 if(self.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
83 if(tflags & TELEPORT_FLAG_SOUND)
84 sound (player, CH_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTEN_NORM);
85 if(tflags & TELEPORT_FLAG_PARTICLES)
87 pointparticles(particleeffectnum("teleport"), player.origin, '0 0 0', 1);
88 pointparticles(particleeffectnum("teleport"), to + v_forward * 32, '0 0 0', 1);
90 self.pushltime = time + 0.2;
94 // Relocate the player
95 // assuming to allows PL_MIN to PL_MAX box and some more
97 setorigin (player, to);
98 player.oldorigin = to; // don't undo the teleport by unsticking
99 player.angles = to_angles;
100 player.fixangle = true;
101 player.velocity = to_velocity;
102 BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
104 makevectors(player.angles);
105 Reset_ArcBeam(player, v_forward);
106 UpdateCSQCProjectileAfterTeleport(player);
108 if(IS_PLAYER(player))
110 if(tflags & TELEPORT_FLAG_TDEATH)
111 if(player.takedamage && player.deadflag == DEAD_NO && !g_race && !g_cts && (autocvar_g_telefrags || (tflags & TELEPORT_FLAG_FORCE_TDEATH)))
112 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
114 // player no longer is on ground
115 player.flags &= ~FL_ONGROUND;
117 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
118 player.oldvelocity = player.velocity;
120 // reset tracking of who pushed you into a hazard (for kill credit)
123 player.pusher = teleporter.owner;
124 player.pushltime = time + autocvar_g_maxpushtime;
125 player.istypefrag = player.BUTTON_CHAT;
129 player.pushltime = 0;
130 player.istypefrag = 0;
133 player.lastteleporttime = time;
137 entity Simple_TeleportPlayer(entity teleporter, entity player)
143 // Find the output teleporter
146 e = teleporter.enemy;
150 RandomSelection_Init();
151 for(e = world; (e = find(e, targetname, teleporter.target)); )
154 if(autocvar_g_telefrags_avoid)
156 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
157 if(check_tdeath(player, locout, '0 0 0', '0 0 0'))
160 RandomSelection_Add(e, 0, string_null, (e.cnt ? e.cnt : 1), p);
162 e = RandomSelection_chosen_ent;
165 if(!e) { sprint(player, "Teleport destination vanished. Sorry... please complain to the mapper.\n"); }
167 makevectors(e.mangle);
170 if(vlen(player.velocity) > e.speed)
171 player.velocity = normalize(player.velocity) * max(0, e.speed);
173 if(autocvar_g_teleport_maxspeed)
174 if(vlen(player.velocity) > autocvar_g_teleport_maxspeed)
175 player.velocity = normalize(player.velocity) * max(0, autocvar_g_teleport_maxspeed);
177 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
178 TeleportPlayer(teleporter, player, locout, e.mangle, v_forward * vlen(player.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
183 void Teleport_Touch (void)
188 if (self.active != ACTIVE_ACTIVE)
191 if (!other.teleportable)
195 if(!other.vehicle.teleportable)
198 if(other.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
201 if(other.deadflag != DEAD_NO)
205 if(((self.spawnflags & 4) == 0) == (self.team != other.team))
211 RemoveGrapplingHook(other);
214 e = Simple_TeleportPlayer(self, other);
217 s = self.target; self.target = string_null;
219 if (!self.target) self.target = s;
227 void spawnfunc_info_teleport_destination (void)
229 self.classname = "info_teleport_destination";
231 self.mangle = self.angles;
232 self.angles = '0 0 0';
234 //setorigin (self, self.origin + '0 0 27'); // To fix a mappers' habit as old as Quake
235 setorigin (self, self.origin);
241 objerror ("^3Teleport destination without a targetname");
244 void spawnfunc_misc_teleporter_dest (void)
246 spawnfunc_info_teleport_destination();
249 void spawnfunc_target_teleporter (void)
251 spawnfunc_info_teleport_destination();
254 void teleport_findtarget (void)
260 for(e = world; (e = find(e, targetname, self.target)); )
263 if(e.movetype == MOVETYPE_NONE)
264 waypoint_spawnforteleporter(self, e.origin, 0);
265 if(e.classname != "info_teleport_destination")
266 print("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.\n");
272 objerror ("Teleporter with nonexistant target");
277 // exactly one dest - bots love that
278 self.enemy = find(e, targetname, self.target);
282 // have to use random selection every single time
287 self.touch = Teleport_Touch;
290 entity Teleport_Find(vector mi, vector ma)
293 for(e = world; (e = find(e, classname, "trigger_teleport")); )
294 if(WarpZoneLib_BoxTouchesBrush(mi, ma, e, world))
299 void spawnfunc_trigger_teleport (void)
301 self.angles = '0 0 0';
305 self.active = ACTIVE_ACTIVE;
307 self.use = trigger_teleport_use;
309 // this must be called to spawn the teleport waypoints for bots
310 InitializeEntity(self, teleport_findtarget, INITPRIO_FINDTARGET);
312 if (self.target == "")
314 objerror ("Teleporter with no target");
318 self.teleport_next = teleport_first;
319 teleport_first = self;
322 void WarpZone_PostTeleportPlayer_Callback(entity pl)
324 makevectors(pl.angles);
325 Reset_ArcBeam(pl, v_forward);
326 UpdateCSQCProjectileAfterTeleport(pl);
328 entity oldself = self;
330 anticheat_fixangle();
333 // "disown" projectiles after teleport
335 if(pl.owner == pl.realowner)
337 if(!(pl.flags & FL_PROJECTILE))
338 print("A non-projectile got through a warpzone and its owner cleared. It's a ", pl.classname, ".\n");
343 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
344 pl.oldvelocity = pl.velocity;
345 // reset teleport time tracking too (or multijump can cause insane speeds)
346 pl.lastteleporttime = time;