1 #include "teleporters.qh"
6 #include "../../warpzonelib/common.qh"
7 #include "../../warpzonelib/util_server.qh"
8 #include "../../warpzonelib/server.qh"
9 #include "../constants.qh"
10 #include "../triggers/subs.qh"
12 #include "../../server/weapons/csqcprojectile.qh"
13 #include "../../server/autocvars.qh"
14 #include "../../server/constants.qh"
15 #include "../../server/defs.qh"
16 #include "../deathtypes.qh"
17 #include "../../server/tturrets/include/turrets_early.qh"
18 #include "../../server/vehicles/vehicles_def.qh"
19 #include "../mapinfo.qh"
20 #include "../../server/anticheat.qh"
25 float check_tdeath(entity player, vector org, vector telefragmin, vector telefragmax)
27 if (IS_PLAYER(player) && player.health >= 1)
31 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
40 void tdeath(entity player, entity teleporter, entity telefragger, vector telefragmin, vector telefragmax)
42 TDEATHLOOP(player.origin)
44 if (IS_PLAYER(player) && player.health >= 1)
46 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
51 Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');
54 else // dead bodies and monsters gib themselves instead of telefragging
55 Damage (telefragger, teleporter, telefragger, 10000, DEATH_TELEFRAG, telefragger.origin, '0 0 0');
59 void spawn_tdeath(vector v0, entity e, vector v)
61 tdeath(e, e, e, '0 0 0', '0 0 0');
64 void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity, vector telefragmin, vector telefragmax, float tflags)
70 telefragger = teleporter.owner;
74 makevectors (to_angles);
76 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
78 if(self.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
80 if(tflags & TELEPORT_FLAG_SOUND)
81 sound (player, CH_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTEN_NORM);
82 if(tflags & TELEPORT_FLAG_PARTICLES)
84 pointparticles(particleeffectnum("teleport"), player.origin, '0 0 0', 1);
85 pointparticles(particleeffectnum("teleport"), to + v_forward * 32, '0 0 0', 1);
87 self.pushltime = time + 0.2;
91 // Relocate the player
92 // assuming to allows PL_MIN to PL_MAX box and some more
94 setorigin (player, to);
95 player.oldorigin = to; // don't undo the teleport by unsticking
96 player.angles = to_angles;
97 player.fixangle = true;
98 player.velocity = to_velocity;
99 BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
101 makevectors(player.angles);
102 Reset_ArcBeam(player, v_forward);
103 UpdateCSQCProjectileAfterTeleport(player);
105 if(IS_PLAYER(player))
107 if(tflags & TELEPORT_FLAG_TDEATH)
108 if(player.takedamage && player.deadflag == DEAD_NO && !g_race && !g_cts && (autocvar_g_telefrags || (tflags & TELEPORT_FLAG_FORCE_TDEATH)))
109 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
111 // player no longer is on ground
112 player.flags &= ~FL_ONGROUND;
114 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
115 player.oldvelocity = player.velocity;
117 // reset tracking of who pushed you into a hazard (for kill credit)
120 player.pusher = teleporter.owner;
121 player.pushltime = time + autocvar_g_maxpushtime;
122 player.istypefrag = player.BUTTON_CHAT;
126 player.pushltime = 0;
127 player.istypefrag = 0;
130 player.lastteleporttime = time;
134 entity Simple_TeleportPlayer(entity teleporter, entity player)
140 // Find the output teleporter
143 e = teleporter.enemy;
147 RandomSelection_Init();
148 for(e = world; (e = find(e, targetname, teleporter.target)); )
151 if(autocvar_g_telefrags_avoid)
153 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
154 if(check_tdeath(player, locout, '0 0 0', '0 0 0'))
157 RandomSelection_Add(e, 0, string_null, (e.cnt ? e.cnt : 1), p);
159 e = RandomSelection_chosen_ent;
162 if(!e) { sprint(player, "Teleport destination vanished. Sorry... please complain to the mapper.\n"); }
164 makevectors(e.mangle);
167 if(vlen(player.velocity) > e.speed)
168 player.velocity = normalize(player.velocity) * max(0, e.speed);
170 if(autocvar_g_teleport_maxspeed)
171 if(vlen(player.velocity) > autocvar_g_teleport_maxspeed)
172 player.velocity = normalize(player.velocity) * max(0, autocvar_g_teleport_maxspeed);
174 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
175 TeleportPlayer(teleporter, player, locout, e.mangle, v_forward * vlen(player.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
180 void teleport_findtarget (void)
186 for(e = world; (e = find(e, targetname, self.target)); )
189 if(e.movetype == MOVETYPE_NONE)
190 waypoint_spawnforteleporter(self, e.origin, 0);
191 if(e.classname != "info_teleport_destination")
192 print("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.\n");
198 objerror ("Teleporter with nonexistant target");
203 // exactly one dest - bots love that
204 self.enemy = find(e, targetname, self.target);
208 // have to use random selection every single time
213 self.touch = Teleport_Touch;
216 entity Teleport_Find(vector mi, vector ma)
219 for(e = world; (e = find(e, classname, "trigger_teleport")); )
220 if(WarpZoneLib_BoxTouchesBrush(mi, ma, e, world))
225 void WarpZone_PostTeleportPlayer_Callback(entity pl)
227 makevectors(pl.angles);
228 Reset_ArcBeam(pl, v_forward);
229 UpdateCSQCProjectileAfterTeleport(pl);
231 entity oldself = self;
233 anticheat_fixangle();
236 // "disown" projectiles after teleport
238 if(pl.owner == pl.realowner)
240 if(!(pl.flags & FL_PROJECTILE))
241 print("A non-projectile got through a warpzone and its owner cleared. It's a ", pl.classname, ".\n");
246 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
247 pl.oldvelocity = pl.velocity;
248 // reset teleport time tracking too (or multijump can cause insane speeds)
249 pl.lastteleporttime = time;