1 #include "teleporters.qh"
6 #include <common/constants.qh>
7 #include <common/deathtypes/all.qh>
8 #include <common/gamemodes/_mod.qh>
9 #include <common/mapobjects/subs.qh>
10 #include <common/stats.qh>
11 #include <common/turrets/sv_turrets.qh>
12 #include <common/util.qh>
13 #include <common/vehicles/all.qh>
14 #include <common/weapons/_all.qh>
15 #include <lib/warpzone/common.qh>
16 #include <lib/warpzone/server.qh>
17 #include <lib/warpzone/util_server.qh>
18 #include <server/anticheat.qh>
19 #include <server/weapons/csqcprojectile.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))
40 void trigger_teleport_link(entity this);
42 void tdeath(entity player, entity teleporter, entity telefragger, vector telefragmin, vector telefragmax)
44 TDEATHLOOP(player.origin)
46 if (IS_PLAYER(player) && GetResource(player, RES_HEALTH) >= 1)
48 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
51 if(GetResource(head, RES_HEALTH) >= 1)
53 Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG.m_id, DMG_NOWEP, head.origin, '0 0 0');
56 else // dead bodies and monsters gib themselves instead of telefragging
57 Damage (telefragger, teleporter, telefragger, 10000, DEATH_TELEFRAG.m_id, DMG_NOWEP, 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');
67 void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity, vector telefragmin, vector telefragmax, float tflags)
73 telefragger = teleporter.owner;
77 makevectors (to_angles);
80 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
82 if(teleporter.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
84 if(tflags & TELEPORT_FLAG_SOUND)
86 string thesound = SND(TELEPORT);
87 if(teleporter.noise != "")
89 RandomSelection_Init();
90 FOREACH_WORD(teleporter.noise, true,
92 RandomSelection_AddString(it, 1, 1);
94 thesound = RandomSelection_chosen_string;
96 _sound (player, CH_TRIGGER, thesound, VOL_BASE, ATTEN_NORM);
98 if(tflags & TELEPORT_FLAG_PARTICLES)
100 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
101 Send_Effect(EFFECT_TELEPORT, to + v_forward * 32, '0 0 0', 1);
103 teleporter.pushltime = time + 0.2;
108 // Relocate the player
109 // assuming to allows PL_MIN to PL_MAX box and some more
111 from = player.origin;
112 setorigin(player, to);
113 player.oldorigin = to; // don't undo the teleport by unsticking
114 player.angles = to_angles;
115 if (IS_BOT_CLIENT(player))
117 player.v_angle = player.angles;
118 bot_aim_reset(player);
120 player.fixangle = true;
121 player.velocity = to_velocity;
122 BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
124 makevectors(player.angles);
125 Reset_ArcBeam(player, v_forward);
126 UpdateCSQCProjectileAfterTeleport(player);
127 UpdateItemAfterTeleport(player);
129 from = player.origin;
130 setorigin(player, to);
131 player.angles = to_angles;
132 player.velocity = to_velocity;
133 UNSET_ONGROUND(player);
134 player.iflags |= IFLAG_TELEPORTED | IFLAG_V_ANGLE | IFLAG_ANGLES;
135 player.csqcmodel_teleported = 1;
136 player.v_angle = to_angles;
138 if(player == csqcplayer) // not for anything but the main player
140 setproperty(VF_ANGLES, player.angles);
141 setproperty(VF_CL_VIEWANGLES, player.angles);
146 if(IS_PLAYER(player))
148 if((tflags & TELEPORT_FLAG_TDEATH) && player.takedamage && !IS_DEAD(player)
149 && !g_race && !g_cts && (autocvar_g_telefrags || (tflags & TELEPORT_FLAG_FORCE_TDEATH))
150 && !(round_handler_IsActive() && !round_handler_IsRoundStarted()))
152 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
155 // player no longer is on ground
156 UNSET_ONGROUND(player);
158 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
159 player.oldvelocity = player.velocity;
161 // reset tracking of who pushed you into a hazard (for kill credit)
164 player.pusher = teleporter.owner;
165 player.pushltime = time + autocvar_g_maxpushtime;
166 player.istypefrag = PHYS_INPUT_BUTTON_CHAT(player);
170 player.pushltime = 0;
171 player.istypefrag = 0;
174 player.lastteleporttime = time;
175 player.lastteleport_origin = from;
180 entity Simple_TeleportPlayer(entity teleporter, entity player)
185 // Find the output teleporter
188 e = teleporter.enemy;
192 // sorry CSQC, random stuff ain't gonna happen
194 RandomSelection_Init();
195 FOREACH_ENTITY_STRING(targetname, teleporter.target,
198 if(STAT(TELEPORT_TELEFRAG_AVOID, player))
201 locout = it.origin + '0 0 1' * (1 - player.mins.z - 24);
203 locout = it.origin + '0 0 1' * (1 - player.mins.z - 24);
205 if(check_tdeath(player, locout, '0 0 0', '0 0 0'))
208 RandomSelection_AddEnt(it, (it.cnt ? it.cnt : 1), p);
210 e = RandomSelection_chosen_ent;
215 if(!e) { sprint(player, "Teleport destination vanished. Sorry... please complain to the mapper.\n"); }
217 if(!e) { LOG_INFO("Teleport destination could not be found from CSQC."); }
220 makevectors(e.mangle);
223 if(vdist(player.velocity, >, e.speed))
224 player.velocity = normalize(player.velocity) * max(0, e.speed);
226 if(!(teleporter.classname == "trigger_teleport" && (teleporter.spawnflags & TELEPORT_KEEP_SPEED)) &&
227 !(teleporter.classname == "target_teleporter" && (teleporter.spawnflags & TARGET_TELEPORTER_KEEP_SPEED)))
229 // test if player is slower than min
230 if(STAT(TELEPORT_MINSPEED, player))
231 if(vdist(player.velocity, <, STAT(TELEPORT_MINSPEED, player)))
232 player.velocity = normalize(player.velocity) * max(0, STAT(TELEPORT_MINSPEED, player));
233 // test if player is faster than max (or if min is above max)
234 if(STAT(TELEPORT_MAXSPEED, player))
235 if(vdist(player.velocity, >, STAT(TELEPORT_MAXSPEED, player)))
236 player.velocity = normalize(player.velocity) * max(0, STAT(TELEPORT_MAXSPEED, player));
239 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
241 TeleportPlayer(teleporter, player, locout, e.mangle, v_forward * vlen(player.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
246 void teleport_findtarget(entity this)
248 bool istrigger = (this.solid == SOLID_TRIGGER);
251 for(entity e = NULL; (e = find(e, targetname, this.target)); )
255 if(e.move_movetype == MOVETYPE_NONE)
257 entity tracetest_ent = spawn();
258 setsize(tracetest_ent, PL_MIN_CONST, PL_MAX_CONST);
259 tracetest_ent.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
260 waypoint_spawnforteleporter(this, e.origin, 0, tracetest_ent);
261 delete(tracetest_ent);
263 if(e.classname != "info_teleport_destination")
264 LOG_INFO("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.");
271 objerror (this, "Teleporter with nonexistent target");
276 // exactly one dest - bots love that
277 this.enemy = find(NULL, targetname, this.target);
281 // have to use random selection every single time
287 settouch(this, Teleport_Touch);
290 trigger_teleport_link(this);
294 entity Teleport_Find(vector mi, vector ma)
296 IL_EACH(g_teleporters, WarpZoneLib_BoxTouchesBrush(mi, ma, it, NULL),
303 void WarpZone_PostTeleportPlayer_Callback(entity pl)
306 makevectors(pl.angles);
307 Reset_ArcBeam(pl, v_forward);
308 UpdateCSQCProjectileAfterTeleport(pl);
309 UpdateItemAfterTeleport(pl);
310 if (IS_PLAYER(pl)) anticheat_fixangle(pl);
312 // "disown" projectiles after teleport
314 if(pl.owner == pl.realowner)
317 if(!(pl.flags & FL_PROJECTILE))
319 if(!(pl.flags & BIT(15))) // FL_PROJECTILE
321 LOG_INFO("A non-projectile got through a warpzone and its owner cleared. It's a ", pl.classname, ".");
326 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
328 pl.oldvelocity = pl.velocity;