1 #include "t_teleporters.qh"
4 #include "anticheat.qh"
5 #include "cl_player.qh"
7 #include "bot/waypoints.qh"
8 #include "tturrets/include/turrets_early.qh"
9 #include "weapons/csqcprojectile.qh"
10 #include "../common/constants.qh"
11 #include "../common/deathtypes.qh"
12 #include "../common/mapinfo.qh"
13 #include "../common/util.qh"
14 #include "../common/vehicles/sv_vehicles.qh"
15 #include "../warpzonelib/common.qh"
16 #include "../warpzonelib/server.qh"
17 #include "../warpzonelib/util_server.qh"
19 .float lastteleporttime;
21 void trigger_teleport_use()
24 self.team = activator.team;
27 float check_tdeath(entity player, vector org, vector telefragmin, vector telefragmax)
29 if (IS_PLAYER(player) && player.health >= 1)
33 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
42 void tdeath(entity player, entity teleporter, entity telefragger, vector telefragmin, vector telefragmax)
44 TDEATHLOOP(player.origin)
46 if (IS_PLAYER(player) && player.health >= 1)
48 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
53 Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');
56 else // dead bodies and monsters gib themselves instead of telefragging
57 Damage (telefragger, teleporter, telefragger, 10000, DEATH_TELEFRAG, telefragger.origin, '0 0 0');
61 void spawn_tdeath(vector v0, entity e, vector v)
63 tdeath(e, e, e, '0 0 0', '0 0 0');
66 void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity, vector telefragmin, vector telefragmax, float tflags)
72 telefragger = teleporter.owner;
76 makevectors (to_angles);
78 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
80 if(self.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
82 if(tflags & TELEPORT_FLAG_SOUND)
83 sound (player, CH_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTEN_NORM);
84 if(tflags & TELEPORT_FLAG_PARTICLES)
86 pointparticles(particleeffectnum("teleport"), player.origin, '0 0 0', 1);
87 pointparticles(particleeffectnum("teleport"), to + v_forward * 32, '0 0 0', 1);
89 self.pushltime = time + 0.2;
93 // Relocate the player
94 // assuming to allows PL_MIN to PL_MAX box and some more
96 setorigin (player, to);
97 player.oldorigin = to; // don't undo the teleport by unsticking
98 player.angles = to_angles;
99 player.fixangle = true;
100 player.velocity = to_velocity;
101 BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
103 makevectors(player.angles);
104 Reset_ArcBeam(player, v_forward);
105 UpdateCSQCProjectileAfterTeleport(player);
107 if(IS_PLAYER(player))
109 if(tflags & TELEPORT_FLAG_TDEATH)
110 if(player.takedamage && player.deadflag == DEAD_NO && !g_race && !g_cts && (autocvar_g_telefrags || (tflags & TELEPORT_FLAG_FORCE_TDEATH)))
111 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
113 // player no longer is on ground
114 player.flags &= ~FL_ONGROUND;
116 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
117 player.oldvelocity = player.velocity;
119 // reset tracking of who pushed you into a hazard (for kill credit)
122 player.pusher = teleporter.owner;
123 player.pushltime = time + autocvar_g_maxpushtime;
124 player.istypefrag = player.BUTTON_CHAT;
128 player.pushltime = 0;
129 player.istypefrag = 0;
132 player.lastteleporttime = time;
136 entity Simple_TeleportPlayer(entity teleporter, entity player)
142 // Find the output teleporter
145 e = teleporter.enemy;
149 RandomSelection_Init();
150 for(e = world; (e = find(e, targetname, teleporter.target)); )
153 if(autocvar_g_telefrags_avoid)
155 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
156 if(check_tdeath(player, locout, '0 0 0', '0 0 0'))
159 RandomSelection_Add(e, 0, string_null, (e.cnt ? e.cnt : 1), p);
161 e = RandomSelection_chosen_ent;
164 if(!e) { sprint(player, "Teleport destination vanished. Sorry... please complain to the mapper.\n"); }
166 makevectors(e.mangle);
169 if(vlen(player.velocity) > e.speed)
170 player.velocity = normalize(player.velocity) * max(0, e.speed);
172 if(autocvar_g_teleport_maxspeed)
173 if(vlen(player.velocity) > autocvar_g_teleport_maxspeed)
174 player.velocity = normalize(player.velocity) * max(0, autocvar_g_teleport_maxspeed);
176 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
177 TeleportPlayer(teleporter, player, locout, e.mangle, v_forward * vlen(player.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
182 void Teleport_Touch (void)
187 if (self.active != ACTIVE_ACTIVE)
190 if (!other.teleportable)
194 if(!other.vehicle.teleportable)
197 if(other.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
200 if(other.deadflag != DEAD_NO)
204 if(((self.spawnflags & 4) == 0) == (self.team != other.team))
210 RemoveGrapplingHook(other);
213 e = Simple_TeleportPlayer(self, other);
216 s = self.target; self.target = string_null;
218 if (!self.target) self.target = s;
226 void spawnfunc_info_teleport_destination (void)
228 self.classname = "info_teleport_destination";
230 self.mangle = self.angles;
231 self.angles = '0 0 0';
233 //setorigin (self, self.origin + '0 0 27'); // To fix a mappers' habit as old as Quake
234 setorigin (self, self.origin);
240 objerror ("^3Teleport destination without a targetname");
243 void spawnfunc_misc_teleporter_dest (void)
245 spawnfunc_info_teleport_destination();
248 void spawnfunc_target_teleporter (void)
250 spawnfunc_info_teleport_destination();
253 void teleport_findtarget (void)
259 for(e = world; (e = find(e, targetname, self.target)); )
262 if(e.movetype == MOVETYPE_NONE)
263 waypoint_spawnforteleporter(self, e.origin, 0);
264 if(e.classname != "info_teleport_destination")
265 print("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.\n");
271 objerror ("Teleporter with nonexistant target");
276 // exactly one dest - bots love that
277 self.enemy = find(e, targetname, self.target);
281 // have to use random selection every single time
286 self.touch = Teleport_Touch;
289 entity Teleport_Find(vector mi, vector ma)
292 for(e = world; (e = find(e, classname, "trigger_teleport")); )
293 if(WarpZoneLib_BoxTouchesBrush(mi, ma, e, world))
298 void spawnfunc_trigger_teleport (void)
300 self.angles = '0 0 0';
304 self.active = ACTIVE_ACTIVE;
306 self.use = trigger_teleport_use;
308 // this must be called to spawn the teleport waypoints for bots
309 InitializeEntity(self, teleport_findtarget, INITPRIO_FINDTARGET);
311 if (self.target == "")
313 objerror ("Teleporter with no target");
317 self.teleport_next = teleport_first;
318 teleport_first = self;
321 void WarpZone_PostTeleportPlayer_Callback(entity pl)
323 makevectors(pl.angles);
324 Reset_ArcBeam(pl, v_forward);
325 UpdateCSQCProjectileAfterTeleport(pl);
327 entity oldself = self;
329 anticheat_fixangle();
332 // "disown" projectiles after teleport
334 if(pl.owner == pl.realowner)
336 if(!(pl.flags & FL_PROJECTILE))
337 print("A non-projectile got through a warpzone and its owner cleared. It's a ", pl.classname, ".\n");
342 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
343 pl.oldvelocity = pl.velocity;
344 // reset teleport time tracking too (or multijump can cause insane speeds)
345 pl.lastteleporttime = time;