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/autocvars.qh>
20 #include <server/weapons/csqcprojectile.qh>
24 float check_tdeath(entity player, vector org, vector telefragmin, vector telefragmax)
26 if (IS_PLAYER(player) && !IS_DEAD(player))
31 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
41 void trigger_teleport_link(entity this);
43 void tdeath(entity player, entity teleporter, entity telefragger, vector telefragmin, vector telefragmax)
45 TDEATHLOOP(player.origin)
47 if (IS_PLAYER(player) && GetResource(player, RES_HEALTH) >= 1)
49 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
52 if(GetResource(head, RES_HEALTH) >= 1)
54 Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG.m_id, DMG_NOWEP, head.origin, '0 0 0');
57 else // dead bodies and monsters gib themselves instead of telefragging
58 Damage (telefragger, teleporter, telefragger, 10000, DEATH_TELEFRAG.m_id, DMG_NOWEP, telefragger.origin, '0 0 0');
62 void spawn_tdeath(vector v0, entity e, vector v)
64 tdeath(e, e, e, '0 0 0', '0 0 0');
68 void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity, vector telefragmin, vector telefragmax, float tflags)
74 telefragger = teleporter.owner;
78 makevectors (to_angles);
81 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
83 if(teleporter.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
85 if(tflags & TELEPORT_FLAG_SOUND)
87 string thesound = SND(TELEPORT);
88 if(teleporter.noise != "")
90 RandomSelection_Init();
91 FOREACH_WORD(teleporter.noise, true,
93 RandomSelection_AddString(it, 1, 1);
95 thesound = RandomSelection_chosen_string;
97 _sound (player, CH_TRIGGER, thesound, VOL_BASE, ATTEN_NORM);
99 if(tflags & TELEPORT_FLAG_PARTICLES)
101 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
102 Send_Effect(EFFECT_TELEPORT, to + v_forward * 32, '0 0 0', 1);
104 teleporter.pushltime = time + 0.2;
109 // Relocate the player
110 // assuming to allows PL_MIN to PL_MAX box and some more
112 from = player.origin;
113 setorigin(player, to);
114 player.oldorigin = to; // don't undo the teleport by unsticking
115 player.angles = to_angles;
116 if (IS_BOT_CLIENT(player))
118 player.v_angle = player.angles;
119 bot_aim_reset(player);
121 player.fixangle = true;
122 player.velocity = to_velocity;
123 BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
125 makevectors(player.angles);
126 Reset_ArcBeam(player, v_forward);
127 UpdateCSQCProjectileAfterTeleport(player);
128 UpdateItemAfterTeleport(player);
130 from = player.origin;
131 setorigin(player, to);
132 player.angles = to_angles;
133 player.velocity = to_velocity;
134 UNSET_ONGROUND(player);
135 player.iflags |= IFLAG_TELEPORTED | IFLAG_V_ANGLE | IFLAG_ANGLES;
136 player.csqcmodel_teleported = 1;
137 player.v_angle = to_angles;
139 if(player == csqcplayer) // not for anything but the main player
141 setproperty(VF_ANGLES, player.angles);
142 setproperty(VF_CL_VIEWANGLES, player.angles);
147 if(IS_PLAYER(player))
149 if((tflags & TELEPORT_FLAG_TDEATH) && player.takedamage && !IS_DEAD(player)
150 && !g_race && !g_cts && (autocvar_g_telefrags || (tflags & TELEPORT_FLAG_FORCE_TDEATH))
151 && !(round_handler_IsActive() && !round_handler_IsRoundStarted()))
153 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
156 // player no longer is on ground
157 UNSET_ONGROUND(player);
159 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
160 player.oldvelocity = player.velocity;
162 // reset tracking of who pushed you into a hazard (for kill credit)
165 player.pusher = teleporter.owner;
166 player.pushltime = time + autocvar_g_maxpushtime;
167 player.istypefrag = PHYS_INPUT_BUTTON_CHAT(player);
171 player.pushltime = 0;
172 player.istypefrag = 0;
175 player.lastteleporttime = time;
176 player.lastteleport_origin = from;
181 entity Simple_TeleportPlayer(entity teleporter, entity player)
186 // Find the output teleporter
189 e = teleporter.enemy;
193 // sorry CSQC, random stuff ain't gonna happen
195 RandomSelection_Init();
196 FOREACH_ENTITY_STRING(targetname, teleporter.target,
199 if(STAT(TELEPORT_TELEFRAG_AVOID, player))
202 locout = it.origin + '0 0 1' * (1 - player.mins.z - 24);
204 locout = it.origin + '0 0 1' * (1 - player.mins.z - 24);
206 if(check_tdeath(player, locout, '0 0 0', '0 0 0'))
209 RandomSelection_AddEnt(it, (it.cnt ? it.cnt : 1), p);
211 e = RandomSelection_chosen_ent;
216 if(!e) { sprint(player, "Teleport destination vanished. Sorry... please complain to the mapper.\n"); }
218 if(!e) { LOG_INFO("Teleport destination could not be found from CSQC."); }
221 makevectors(e.mangle);
224 if(vdist(player.velocity, >, e.speed))
225 player.velocity = normalize(player.velocity) * max(0, e.speed);
227 if(STAT(TELEPORT_MAXSPEED, player))
228 if(vdist(player.velocity, >, STAT(TELEPORT_MAXSPEED, player)))
229 player.velocity = normalize(player.velocity) * max(0, STAT(TELEPORT_MAXSPEED, player));
231 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
233 TeleportPlayer(teleporter, player, locout, e.mangle, v_forward * vlen(player.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
238 void teleport_findtarget(entity this)
240 bool istrigger = (this.solid == SOLID_TRIGGER);
243 for(entity e = NULL; (e = find(e, targetname, this.target)); )
247 if(e.move_movetype == MOVETYPE_NONE)
249 entity tracetest_ent = spawn();
250 setsize(tracetest_ent, PL_MIN_CONST, PL_MAX_CONST);
251 tracetest_ent.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
252 waypoint_spawnforteleporter(this, e.origin, 0, tracetest_ent);
253 delete(tracetest_ent);
255 if(e.classname != "info_teleport_destination")
256 LOG_INFO("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.");
263 objerror (this, "Teleporter with nonexistent target");
268 // exactly one dest - bots love that
269 this.enemy = find(NULL, targetname, this.target);
273 // have to use random selection every single time
279 settouch(this, Teleport_Touch);
282 trigger_teleport_link(this);
286 entity Teleport_Find(vector mi, vector ma)
288 IL_EACH(g_teleporters, WarpZoneLib_BoxTouchesBrush(mi, ma, it, NULL),
295 void WarpZone_PostTeleportPlayer_Callback(entity pl)
298 makevectors(pl.angles);
299 Reset_ArcBeam(pl, v_forward);
300 UpdateCSQCProjectileAfterTeleport(pl);
301 UpdateItemAfterTeleport(pl);
302 if (IS_PLAYER(pl)) anticheat_fixangle(pl);
304 // "disown" projectiles after teleport
306 if(pl.owner == pl.realowner)
309 if(!(pl.flags & FL_PROJECTILE))
311 if(!(pl.flags & BIT(15))) // FL_PROJECTILE
313 LOG_INFO("A non-projectile got through a warpzone and its owner cleared. It's a ", pl.classname, ".");
318 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
320 pl.oldvelocity = pl.velocity;