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 "../mapobjects/subs.qh"
12 #include <server/weapons/csqcprojectile.qh>
13 #include <server/autocvars.qh>
14 #include <server/constants.qh>
15 #include <common/weapons/_all.qh>
16 #include <common/stats.qh>
17 #include "../deathtypes/all.qh"
18 #include <server/sv_main.qh>
19 #include "../turrets/sv_turrets.qh"
20 #include "../vehicles/all.qh"
21 #include <common/gamemodes/_mod.qh>
22 #include <server/anticheat.qh>
26 float check_tdeath(entity player, vector org, vector telefragmin, vector telefragmax)
28 if (IS_PLAYER(player) && !IS_DEAD(player))
33 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
43 void trigger_teleport_link(entity this);
45 void tdeath(entity player, entity teleporter, entity telefragger, vector telefragmin, vector telefragmax)
47 TDEATHLOOP(player.origin)
49 if (IS_PLAYER(player) && GetResource(player, RES_HEALTH) >= 1)
51 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
54 if(GetResource(head, RES_HEALTH) >= 1)
56 Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG.m_id, DMG_NOWEP, head.origin, '0 0 0');
59 else // dead bodies and monsters gib themselves instead of telefragging
60 Damage (telefragger, teleporter, telefragger, 10000, DEATH_TELEFRAG.m_id, DMG_NOWEP, telefragger.origin, '0 0 0');
64 void spawn_tdeath(vector v0, entity e, vector v)
66 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);
83 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
85 if(teleporter.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
87 if(tflags & TELEPORT_FLAG_SOUND)
89 string thesound = SND(TELEPORT);
90 if(teleporter.noise != "")
92 RandomSelection_Init();
93 FOREACH_WORD(teleporter.noise, true,
95 RandomSelection_AddString(it, 1, 1);
97 thesound = RandomSelection_chosen_string;
99 _sound (player, CH_TRIGGER, thesound, VOL_BASE, ATTEN_NORM);
101 if(tflags & TELEPORT_FLAG_PARTICLES)
103 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
104 Send_Effect(EFFECT_TELEPORT, to + v_forward * 32, '0 0 0', 1);
106 teleporter.pushltime = time + 0.2;
111 // Relocate the player
112 // assuming to allows PL_MIN to PL_MAX box and some more
114 from = player.origin;
115 setorigin(player, to);
116 player.oldorigin = to; // don't undo the teleport by unsticking
117 player.angles = to_angles;
118 if (IS_BOT_CLIENT(player))
120 player.v_angle = player.angles;
121 bot_aim_reset(player);
123 player.fixangle = true;
124 player.velocity = to_velocity;
125 BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
127 makevectors(player.angles);
128 Reset_ArcBeam(player, v_forward);
129 UpdateCSQCProjectileAfterTeleport(player);
130 UpdateItemAfterTeleport(player);
132 from = player.origin;
133 setorigin(player, to);
134 player.angles = to_angles;
135 player.velocity = to_velocity;
136 UNSET_ONGROUND(player);
137 player.iflags |= IFLAG_TELEPORTED | IFLAG_V_ANGLE | IFLAG_ANGLES;
138 player.csqcmodel_teleported = 1;
139 player.v_angle = to_angles;
141 if(player == csqcplayer) // not for anything but the main player
143 setproperty(VF_ANGLES, player.angles);
144 setproperty(VF_CL_VIEWANGLES, player.angles);
149 if(IS_PLAYER(player))
151 if((tflags & TELEPORT_FLAG_TDEATH) && player.takedamage && !IS_DEAD(player)
152 && !g_race && !g_cts && (autocvar_g_telefrags || (tflags & TELEPORT_FLAG_FORCE_TDEATH))
153 && !(round_handler_IsActive() && !round_handler_IsRoundStarted()))
155 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
158 // player no longer is on ground
159 UNSET_ONGROUND(player);
161 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
162 player.oldvelocity = player.velocity;
164 // reset tracking of who pushed you into a hazard (for kill credit)
167 player.pusher = teleporter.owner;
168 player.pushltime = time + autocvar_g_maxpushtime;
169 player.istypefrag = PHYS_INPUT_BUTTON_CHAT(player);
173 player.pushltime = 0;
174 player.istypefrag = 0;
177 player.lastteleporttime = time;
178 player.lastteleport_origin = from;
183 entity Simple_TeleportPlayer(entity teleporter, entity player)
188 // Find the output teleporter
191 e = teleporter.enemy;
195 // sorry CSQC, random stuff ain't gonna happen
197 RandomSelection_Init();
198 FOREACH_ENTITY_STRING(targetname, teleporter.target,
201 if(STAT(TELEPORT_TELEFRAG_AVOID, player))
204 locout = it.origin + '0 0 1' * (1 - player.mins.z - 24);
206 locout = it.origin + '0 0 1' * (1 - player.mins.z - 24);
208 if(check_tdeath(player, locout, '0 0 0', '0 0 0'))
211 RandomSelection_AddEnt(it, (it.cnt ? it.cnt : 1), p);
213 e = RandomSelection_chosen_ent;
218 if(!e) { sprint(player, "Teleport destination vanished. Sorry... please complain to the mapper.\n"); }
220 if(!e) { LOG_INFO("Teleport destination could not be found from CSQC."); }
223 makevectors(e.mangle);
226 if(vdist(player.velocity, >, e.speed))
227 player.velocity = normalize(player.velocity) * max(0, e.speed);
229 if(STAT(TELEPORT_MAXSPEED, player))
230 if(vdist(player.velocity, >, STAT(TELEPORT_MAXSPEED, player)))
231 player.velocity = normalize(player.velocity) * max(0, STAT(TELEPORT_MAXSPEED, player));
233 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
235 TeleportPlayer(teleporter, player, locout, e.mangle, v_forward * vlen(player.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
240 void teleport_findtarget(entity this)
242 bool istrigger = (this.solid == SOLID_TRIGGER);
245 for(entity e = NULL; (e = find(e, targetname, this.target)); )
249 if(e.move_movetype == MOVETYPE_NONE)
251 entity tracetest_ent = spawn();
252 setsize(tracetest_ent, PL_MIN_CONST, PL_MAX_CONST);
253 tracetest_ent.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
254 waypoint_spawnforteleporter(this, e.origin, 0, tracetest_ent);
255 delete(tracetest_ent);
257 if(e.classname != "info_teleport_destination")
258 LOG_INFO("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.");
265 objerror (this, "Teleporter with nonexistent target");
270 // exactly one dest - bots love that
271 this.enemy = find(NULL, targetname, this.target);
275 // have to use random selection every single time
281 settouch(this, Teleport_Touch);
284 trigger_teleport_link(this);
288 entity Teleport_Find(vector mi, vector ma)
290 IL_EACH(g_teleporters, WarpZoneLib_BoxTouchesBrush(mi, ma, it, NULL),
297 void WarpZone_PostTeleportPlayer_Callback(entity pl)
300 makevectors(pl.angles);
301 Reset_ArcBeam(pl, v_forward);
302 UpdateCSQCProjectileAfterTeleport(pl);
303 UpdateItemAfterTeleport(pl);
304 if (IS_PLAYER(pl)) anticheat_fixangle(pl);
306 // "disown" projectiles after teleport
308 if(pl.owner == pl.realowner)
311 if(!(pl.flags & FL_PROJECTILE))
313 if(!(pl.flags & BIT(15))) // FL_PROJECTILE
315 LOG_INFO("A non-projectile got through a warpzone and its owner cleared. It's a ", pl.classname, ".");
320 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
322 pl.oldvelocity = pl.velocity;