1 #include "t_teleporters.qh"
7 #include "../warpzonelib/common.qh"
8 #include "../warpzonelib/util_server.qh"
9 #include "../warpzonelib/server.qh"
10 #include "../common/constants.qh"
11 #include "../common/util.qh"
12 #include "weapons/csqcprojectile.qh"
13 #include "../common/deathtypes.qh"
14 #include "tturrets/include/turrets_early.qh"
15 #include "vehicles/vehicles_def.qh"
16 #include "../common/mapinfo.qh"
17 #include "anticheat.qh"
20 void trigger_teleport_use()
23 self.team = activator.team;
26 float check_tdeath(entity player, vector org, vector telefragmin, vector telefragmax)
28 if (IS_PLAYER(player) && player.health >= 1)
32 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
41 void tdeath(entity player, entity teleporter, entity telefragger, vector telefragmin, vector telefragmax)
43 TDEATHLOOP(player.origin)
45 if (IS_PLAYER(player) && player.health >= 1)
47 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
52 Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');
55 else // dead bodies and monsters gib themselves instead of telefragging
56 Damage (telefragger, teleporter, telefragger, 10000, DEATH_TELEFRAG, telefragger.origin, '0 0 0');
60 void spawn_tdeath(vector v0, entity e, vector v)
62 tdeath(e, e, e, '0 0 0', '0 0 0');
65 void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity, vector telefragmin, vector telefragmax, float tflags)
71 telefragger = teleporter.owner;
75 makevectors (to_angles);
77 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
79 if(self.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
81 if(tflags & TELEPORT_FLAG_SOUND)
82 sound (player, CH_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTEN_NORM);
83 if(tflags & TELEPORT_FLAG_PARTICLES)
85 pointparticles(particleeffectnum("teleport"), player.origin, '0 0 0', 1);
86 pointparticles(particleeffectnum("teleport"), to + v_forward * 32, '0 0 0', 1);
88 self.pushltime = time + 0.2;
92 // Relocate the player
93 // assuming to allows PL_MIN to PL_MAX box and some more
95 setorigin (player, to);
96 player.oldorigin = to; // don't undo the teleport by unsticking
97 player.angles = to_angles;
98 player.fixangle = true;
99 player.velocity = to_velocity;
100 BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
102 makevectors(player.angles);
103 Reset_ArcBeam(player, v_forward);
104 UpdateCSQCProjectileAfterTeleport(player);
106 if(IS_PLAYER(player))
108 if(tflags & TELEPORT_FLAG_TDEATH)
109 if(player.takedamage && player.deadflag == DEAD_NO && !g_race && !g_cts && (autocvar_g_telefrags || (tflags & TELEPORT_FLAG_FORCE_TDEATH)))
110 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
112 // player no longer is on ground
113 player.flags &= ~FL_ONGROUND;
115 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
116 player.oldvelocity = player.velocity;
118 // reset tracking of who pushed you into a hazard (for kill credit)
121 player.pusher = teleporter.owner;
122 player.pushltime = time + autocvar_g_maxpushtime;
123 player.istypefrag = player.BUTTON_CHAT;
127 player.pushltime = 0;
128 player.istypefrag = 0;
131 player.lastteleporttime = time;
135 entity Simple_TeleportPlayer(entity teleporter, entity player)
141 // Find the output teleporter
144 e = teleporter.enemy;
148 RandomSelection_Init();
149 for(e = world; (e = find(e, targetname, teleporter.target)); )
152 if(autocvar_g_telefrags_avoid)
154 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
155 if(check_tdeath(player, locout, '0 0 0', '0 0 0'))
158 RandomSelection_Add(e, 0, string_null, (e.cnt ? e.cnt : 1), p);
160 e = RandomSelection_chosen_ent;
163 if(!e) { sprint(player, "Teleport destination vanished. Sorry... please complain to the mapper.\n"); }
165 makevectors(e.mangle);
168 if(vlen(player.velocity) > e.speed)
169 player.velocity = normalize(player.velocity) * max(0, e.speed);
171 if(autocvar_g_teleport_maxspeed)
172 if(vlen(player.velocity) > autocvar_g_teleport_maxspeed)
173 player.velocity = normalize(player.velocity) * max(0, autocvar_g_teleport_maxspeed);
175 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
176 TeleportPlayer(teleporter, player, locout, e.mangle, v_forward * vlen(player.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
181 void Teleport_Touch (void)
186 if (self.active != ACTIVE_ACTIVE)
189 if (!other.teleportable)
193 if(!other.vehicle.teleportable)
196 if(other.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
199 if(other.deadflag != DEAD_NO)
203 if(((self.spawnflags & 4) == 0) == (self.team != other.team))
209 RemoveGrapplingHook(other);
212 e = Simple_TeleportPlayer(self, other);
215 s = self.target; self.target = string_null;
217 if (!self.target) self.target = s;
225 void spawnfunc_info_teleport_destination (void)
227 self.classname = "info_teleport_destination";
229 self.mangle = self.angles;
230 self.angles = '0 0 0';
232 //setorigin (self, self.origin + '0 0 27'); // To fix a mappers' habit as old as Quake
233 setorigin (self, self.origin);
239 objerror ("^3Teleport destination without a targetname");
242 void spawnfunc_misc_teleporter_dest (void)
244 spawnfunc_info_teleport_destination();
247 void spawnfunc_target_teleporter (void)
249 spawnfunc_info_teleport_destination();
252 void teleport_findtarget (void)
258 for(e = world; (e = find(e, targetname, self.target)); )
261 if(e.movetype == MOVETYPE_NONE)
262 waypoint_spawnforteleporter(self, e.origin, 0);
263 if(e.classname != "info_teleport_destination")
264 print("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.\n");
270 objerror ("Teleporter with nonexistant target");
275 // exactly one dest - bots love that
276 self.enemy = find(e, targetname, self.target);
280 // have to use random selection every single time
285 self.touch = Teleport_Touch;
288 entity Teleport_Find(vector mi, vector ma)
291 for(e = world; (e = find(e, classname, "trigger_teleport")); )
292 if(WarpZoneLib_BoxTouchesBrush(mi, ma, e, world))
297 void spawnfunc_trigger_teleport (void)
299 self.angles = '0 0 0';
303 self.active = ACTIVE_ACTIVE;
305 self.use = trigger_teleport_use;
307 // this must be called to spawn the teleport waypoints for bots
308 InitializeEntity(self, teleport_findtarget, INITPRIO_FINDTARGET);
310 if (self.target == "")
312 objerror ("Teleporter with no target");
316 self.teleport_next = teleport_first;
317 teleport_first = self;
320 void WarpZone_PostTeleportPlayer_Callback(entity pl)
322 makevectors(pl.angles);
323 Reset_ArcBeam(pl, v_forward);
324 UpdateCSQCProjectileAfterTeleport(pl);
326 entity oldself = self;
328 anticheat_fixangle();
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");
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;