1 #include "teleporters.qh"
6 #include <lib/warpzone/common.qh>
7 #include <lib/warpzone/util_server.qh>
8 #include <lib/warpzone/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/all.qh"
17 #include "../turrets/sv_turrets.qh"
18 #include "../vehicles/all.qh"
19 #include "../mapinfo.qh"
20 #include <server/anticheat.qh>
23 float check_tdeath(entity player, vector org, vector telefragmin, vector telefragmax)
25 if (IS_PLAYER(player) && !IS_DEAD(player))
30 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
42 void trigger_teleport_link(entity this);
44 void tdeath(entity player, entity teleporter, entity telefragger, vector telefragmin, vector telefragmax)
46 TDEATHLOOP(player.origin)
48 if (IS_PLAYER(player) && player.health >= 1)
50 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
55 Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG.m_id, head.origin, '0 0 0');
58 else // dead bodies and monsters gib themselves instead of telefragging
59 Damage (telefragger, teleporter, telefragger, 10000, DEATH_TELEFRAG.m_id, telefragger.origin, '0 0 0');
63 void spawn_tdeath(vector v0, entity e, vector v)
65 tdeath(e, e, e, '0 0 0', '0 0 0');
70 void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity, vector telefragmin, vector telefragmax, float tflags)
76 telefragger = teleporter.owner;
80 makevectors (to_angles);
84 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
86 if(self.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
88 if(tflags & TELEPORT_FLAG_SOUND)
90 string thesound = SND(TELEPORT);
91 if(teleporter.noise != "")
93 RandomSelection_Init();
94 FOREACH_WORD(teleporter.noise, true,
96 RandomSelection_Add(NULL, 0, it, 1, 1);
98 thesound = RandomSelection_chosen_string;
100 _sound (player, CH_TRIGGER, thesound, VOL_BASE, ATTEN_NORM);
102 if(tflags & TELEPORT_FLAG_PARTICLES)
104 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
105 Send_Effect(EFFECT_TELEPORT, to + v_forward * 32, '0 0 0', 1);
107 self.pushltime = time + 0.2;
112 // Relocate the player
113 // assuming to allows PL_MIN to PL_MAX box and some more
115 from = player.origin;
116 setorigin (player, to);
117 player.oldorigin = to; // don't undo the teleport by unsticking
118 player.angles = to_angles;
119 player.fixangle = true;
120 player.velocity = to_velocity;
121 BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
123 makevectors(player.angles);
124 Reset_ArcBeam(player, v_forward);
125 UpdateCSQCProjectileAfterTeleport(player);
126 UpdateItemAfterTeleport(player);
128 from = player.move_origin;
129 player.move_origin = to;
130 player.move_angles = to_angles;
131 player.move_velocity = to_velocity;
132 player.move_flags &= ~FL_ONGROUND;
133 player.iflags |= IFLAG_TELEPORTED | IFLAG_V_ANGLE | IFLAG_ANGLES;
134 player.csqcmodel_teleported = 1;
135 player.v_angle = to_angles;
137 if(player.isplayermodel) // not for anything but the main player
139 setproperty(VF_ANGLES, player.move_angles);
140 setproperty(VF_CL_VIEWANGLES, player.move_angles);
143 makevectors(player.move_angles);
147 if(IS_PLAYER(player))
149 if(tflags & TELEPORT_FLAG_TDEATH)
150 if(player.takedamage && !IS_DEAD(player) && !g_race && !g_cts && (autocvar_g_telefrags || (tflags & TELEPORT_FLAG_FORCE_TDEATH)))
151 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
153 // player no longer is on ground
154 UNSET_ONGROUND(player);
156 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
157 player.oldvelocity = player.velocity;
159 // reset tracking of who pushed you into a hazard (for kill credit)
162 player.pusher = teleporter.owner;
163 player.pushltime = time + autocvar_g_maxpushtime;
164 player.istypefrag = PHYS_INPUT_BUTTON_CHAT(player);
168 player.pushltime = 0;
169 player.istypefrag = 0;
172 player.lastteleporttime = time;
177 entity Simple_TeleportPlayer(entity teleporter, entity player)
183 // Find the output teleporter
186 e = teleporter.enemy;
190 RandomSelection_Init();
191 for(e = world; (e = find(e, targetname, teleporter.target)); )
194 if(STAT(TELEPORT_TELEFRAG_AVOID, player))
197 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
199 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
201 if(check_tdeath(player, locout, '0 0 0', '0 0 0'))
204 RandomSelection_Add(e, 0, string_null, (e.cnt ? e.cnt : 1), p);
206 e = RandomSelection_chosen_ent;
210 if(!e) { sprint(player, "Teleport destination vanished. Sorry... please complain to the mapper.\n"); }
212 if(!e) { LOG_INFO("Teleport destination could not be found from CSQC.\n"); }
215 makevectors(e.mangle);
219 if(vdist(player.velocity, >, e.speed))
220 player.velocity = normalize(player.velocity) * max(0, e.speed);
223 if(vdist(player.move_velocity, >, e.speed))
224 player.move_velocity = normalize(player.move_velocity) * max(0, e.speed);
228 if(STAT(TELEPORT_MAXSPEED, player))
229 if(vdist(player.velocity, >, STAT(TELEPORT_MAXSPEED, player)))
230 player.velocity = normalize(player.velocity) * max(0, STAT(TELEPORT_MAXSPEED, player));
232 if(STAT(TELEPORT_MAXSPEED, player))
233 if(vdist(player.move_velocity, >, STAT(TELEPORT_MAXSPEED, player)))
234 player.move_velocity = normalize(player.move_velocity) * max(0, STAT(TELEPORT_MAXSPEED, player));
238 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
240 TeleportPlayer(teleporter, player, locout, e.mangle, v_forward * vlen(player.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
242 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
244 TeleportPlayer(teleporter, player, locout, e.mangle, v_forward * vlen(player.move_velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
250 void teleport_findtarget(entity this)
254 for(e = world; (e = find(e, targetname, self.target)); )
258 if(e.movetype == MOVETYPE_NONE)
259 waypoint_spawnforteleporter(self, e.origin, 0);
260 if(e.classname != "info_teleport_destination")
261 LOG_INFO("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.\n");
268 objerror ("Teleporter with nonexistant target");
273 // exactly one dest - bots love that
274 self.enemy = find(e, targetname, self.target);
278 // have to use random selection every single time
284 self.touch = Teleport_Touch;
286 trigger_teleport_link(self);
288 self.move_touch = Teleport_Touch;
292 entity Teleport_Find(vector mi, vector ma)
295 for(e = world; (e = find(e, classname, "trigger_teleport")); )
296 if(WarpZoneLib_BoxTouchesBrush(mi, ma, e, world))
301 void WarpZone_PostTeleportPlayer_Callback(entity pl)
304 makevectors(pl.angles);
305 Reset_ArcBeam(pl, v_forward);
306 UpdateCSQCProjectileAfterTeleport(pl);
307 UpdateItemAfterTeleport(pl);
308 if (IS_PLAYER(pl)) anticheat_fixangle(pl);
310 // "disown" projectiles after teleport
312 if(pl.owner == pl.realowner)
315 if(!(pl.flags & FL_PROJECTILE))
317 if(!(pl.move_flags & BIT(15))) // FL_PROJECTILE
319 LOG_INFO("A non-projectile got through a warpzone and its owner cleared. It's a ", pl.classname, ".\n");
324 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
326 pl.oldvelocity = pl.velocity;
328 // reset teleport time tracking too (or multijump can cause insane speeds)
329 pl.lastteleporttime = time;