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 <common/weapons/_all.qh>
15 #include <common/stats.qh>
16 #include "../deathtypes/all.qh"
17 #include <server/main.qh>
18 #include "../turrets/sv_turrets.qh"
19 #include "../vehicles/all.qh"
20 #include <common/gamemodes/_mod.qh>
21 #include <server/anticheat.qh>
25 float check_tdeath(entity player, vector org, vector telefragmin, vector telefragmax)
27 if (IS_PLAYER(player) && !IS_DEAD(player))
32 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) && GetResource(player, RES_HEALTH) >= 1)
50 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
53 if(GetResource(head, RES_HEALTH) >= 1)
55 Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG.m_id, DMG_NOWEP, 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, DMG_NOWEP, 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');
69 void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity, vector telefragmin, vector telefragmax, float tflags)
75 telefragger = teleporter.owner;
79 makevectors (to_angles);
82 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
84 if(teleporter.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
86 if(tflags & TELEPORT_FLAG_SOUND)
88 string thesound = SND(TELEPORT);
89 if(teleporter.noise != "")
91 RandomSelection_Init();
92 FOREACH_WORD(teleporter.noise, true,
94 RandomSelection_AddString(it, 1, 1);
96 thesound = RandomSelection_chosen_string;
98 _sound (player, CH_TRIGGER, thesound, VOL_BASE, ATTEN_NORM);
100 if(tflags & TELEPORT_FLAG_PARTICLES)
102 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
103 Send_Effect(EFFECT_TELEPORT, to + v_forward * 32, '0 0 0', 1);
105 teleporter.pushltime = time + 0.2;
110 // Relocate the player
111 // assuming to allows PL_MIN to PL_MAX box and some more
113 from = player.origin;
114 setorigin(player, to);
115 player.oldorigin = to; // don't undo the teleport by unsticking
116 player.angles = to_angles;
117 if (IS_BOT_CLIENT(player))
119 player.v_angle = player.angles;
120 bot_aim_reset(player);
122 player.fixangle = true;
123 player.velocity = to_velocity;
124 BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
126 makevectors(player.angles);
127 Reset_ArcBeam(player, v_forward);
128 UpdateCSQCProjectileAfterTeleport(player);
129 UpdateItemAfterTeleport(player);
131 from = player.origin;
132 setorigin(player, to);
133 player.angles = to_angles;
134 player.velocity = to_velocity;
135 UNSET_ONGROUND(player);
136 player.iflags |= IFLAG_TELEPORTED | IFLAG_V_ANGLE | IFLAG_ANGLES;
137 player.csqcmodel_teleported = 1;
138 player.v_angle = to_angles;
140 if(player == csqcplayer) // not for anything but the main player
142 setproperty(VF_ANGLES, player.angles);
143 setproperty(VF_CL_VIEWANGLES, player.angles);
148 if(IS_PLAYER(player))
150 if((tflags & TELEPORT_FLAG_TDEATH) && player.takedamage && !IS_DEAD(player)
151 && !g_race && !g_cts && (autocvar_g_telefrags || (tflags & TELEPORT_FLAG_FORCE_TDEATH))
152 && !(round_handler_IsActive() && !round_handler_IsRoundStarted()))
154 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
157 // player no longer is on ground
158 UNSET_ONGROUND(player);
160 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
161 player.oldvelocity = player.velocity;
163 // reset tracking of who pushed you into a hazard (for kill credit)
166 player.pusher = teleporter.owner;
167 player.pushltime = time + autocvar_g_maxpushtime;
168 player.istypefrag = PHYS_INPUT_BUTTON_CHAT(player);
172 player.pushltime = 0;
173 player.istypefrag = 0;
176 player.lastteleporttime = time;
177 player.lastteleport_origin = from;
182 entity Simple_TeleportPlayer(entity teleporter, entity player)
187 // Find the output teleporter
190 e = teleporter.enemy;
194 // sorry CSQC, random stuff ain't gonna happen
196 RandomSelection_Init();
197 FOREACH_ENTITY_STRING(targetname, teleporter.target,
200 if(STAT(TELEPORT_TELEFRAG_AVOID, player))
203 locout = it.origin + '0 0 1' * (1 - player.mins.z - 24);
205 locout = it.origin + '0 0 1' * (1 - player.mins.z - 24);
207 if(check_tdeath(player, locout, '0 0 0', '0 0 0'))
210 RandomSelection_AddEnt(it, (it.cnt ? it.cnt : 1), p);
212 e = RandomSelection_chosen_ent;
217 if(!e) { sprint(player, "Teleport destination vanished. Sorry... please complain to the mapper.\n"); }
219 if(!e) { LOG_INFO("Teleport destination could not be found from CSQC."); }
222 makevectors(e.mangle);
225 if(vdist(player.velocity, >, e.speed))
226 player.velocity = normalize(player.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 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
234 TeleportPlayer(teleporter, player, locout, e.mangle, v_forward * vlen(player.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
239 void teleport_findtarget(entity this)
241 bool istrigger = (this.solid == SOLID_TRIGGER);
244 for(entity e = NULL; (e = find(e, targetname, this.target)); )
248 if(e.move_movetype == MOVETYPE_NONE)
250 entity tracetest_ent = spawn();
251 setsize(tracetest_ent, PL_MIN_CONST, PL_MAX_CONST);
252 tracetest_ent.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
253 waypoint_spawnforteleporter(this, e.origin, 0, tracetest_ent);
254 delete(tracetest_ent);
256 if(e.classname != "info_teleport_destination")
257 LOG_INFO("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.");
264 objerror (this, "Teleporter with nonexistent target");
269 // exactly one dest - bots love that
270 this.enemy = find(NULL, targetname, this.target);
274 // have to use random selection every single time
280 settouch(this, Teleport_Touch);
283 trigger_teleport_link(this);
287 entity Teleport_Find(vector mi, vector ma)
289 IL_EACH(g_teleporters, WarpZoneLib_BoxTouchesBrush(mi, ma, it, NULL),
296 void WarpZone_PostTeleportPlayer_Callback(entity pl)
299 makevectors(pl.angles);
300 Reset_ArcBeam(pl, v_forward);
301 UpdateCSQCProjectileAfterTeleport(pl);
302 UpdateItemAfterTeleport(pl);
303 if (IS_PLAYER(pl)) anticheat_fixangle(pl);
305 // "disown" projectiles after teleport
307 if(pl.owner == pl.realowner)
310 if(!(pl.flags & FL_PROJECTILE))
312 if(!(pl.flags & BIT(15))) // FL_PROJECTILE
314 LOG_INFO("A non-projectile got through a warpzone and its owner cleared. It's a ", pl.classname, ".");
319 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
321 pl.oldvelocity = pl.velocity;