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) && !PHYS_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);
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(self.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
87 if(tflags & TELEPORT_FLAG_SOUND)
88 sound (player, CH_TRIGGER, SND_TELEPORT, VOL_BASE, ATTEN_NORM);
89 if(tflags & TELEPORT_FLAG_PARTICLES)
91 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
92 Send_Effect(EFFECT_TELEPORT, to + v_forward * 32, '0 0 0', 1);
94 self.pushltime = time + 0.2;
99 // Relocate the player
100 // assuming to allows PL_MIN to PL_MAX box and some more
102 from = player.origin;
103 setorigin (player, to);
104 player.oldorigin = to; // don't undo the teleport by unsticking
105 player.angles = to_angles;
106 player.fixangle = true;
107 player.velocity = to_velocity;
108 BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
110 makevectors(player.angles);
111 Reset_ArcBeam(player, v_forward);
112 UpdateCSQCProjectileAfterTeleport(player);
114 from = player.move_origin;
115 player.move_origin = to;
116 player.move_angles = to_angles;
117 player.move_velocity = to_velocity;
118 player.move_flags &= ~FL_ONGROUND;
119 player.iflags |= IFLAG_TELEPORTED | IFLAG_V_ANGLE | IFLAG_ANGLES;
120 player.csqcmodel_teleported = 1;
121 player.v_angle = to_angles;
122 setproperty(VF_ANGLES, player.move_angles);
123 setproperty(VF_CL_VIEWANGLES, player.move_angles);
125 makevectors(player.move_angles);
129 if(IS_PLAYER(player))
131 if(tflags & TELEPORT_FLAG_TDEATH)
132 if(player.takedamage && player.deadflag == DEAD_NO && !g_race && !g_cts && (autocvar_g_telefrags || (tflags & TELEPORT_FLAG_FORCE_TDEATH)))
133 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
135 // player no longer is on ground
136 player.flags &= ~FL_ONGROUND;
138 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
139 player.oldvelocity = player.velocity;
141 // reset tracking of who pushed you into a hazard (for kill credit)
144 player.pusher = teleporter.owner;
145 player.pushltime = time + autocvar_g_maxpushtime;
146 player.istypefrag = player.BUTTON_CHAT;
150 player.pushltime = 0;
151 player.istypefrag = 0;
154 player.lastteleporttime = time;
159 entity Simple_TeleportPlayer(entity teleporter, entity player)
165 // Find the output teleporter
168 e = teleporter.enemy;
172 RandomSelection_Init();
173 for(e = world; (e = find(e, targetname, teleporter.target)); )
176 if(STAT(TELEPORT_TELEFRAG_AVOID, player))
179 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
181 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
183 if(check_tdeath(player, locout, '0 0 0', '0 0 0'))
186 RandomSelection_Add(e, 0, string_null, (e.cnt ? e.cnt : 1), p);
188 e = RandomSelection_chosen_ent;
192 if(!e) { sprint(player, "Teleport destination vanished. Sorry... please complain to the mapper.\n"); }
194 if(!e) { LOG_INFO("Teleport destination could not be found from CSQC.\n"); }
197 makevectors(e.mangle);
201 if(vlen(player.velocity) > e.speed)
202 player.velocity = normalize(player.velocity) * max(0, e.speed);
205 if(vlen(player.move_velocity) > e.speed)
206 player.move_velocity = normalize(player.move_velocity) * max(0, e.speed);
210 if(STAT(TELEPORT_MAXSPEED, player))
211 if(vlen(player.velocity) > STAT(TELEPORT_MAXSPEED, player))
212 player.velocity = normalize(player.velocity) * max(0, STAT(TELEPORT_MAXSPEED, player));
214 if(STAT(TELEPORT_MAXSPEED, player))
215 if(vlen(player.move_velocity) > STAT(TELEPORT_MAXSPEED, player))
216 player.move_velocity = normalize(player.move_velocity) * max(0, STAT(TELEPORT_MAXSPEED, player));
220 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
222 TeleportPlayer(teleporter, player, locout, e.mangle, v_forward * vlen(player.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
224 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
226 TeleportPlayer(teleporter, player, locout, e.mangle, v_forward * vlen(player.move_velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
232 void teleport_findtarget()
236 for(e = world; (e = find(e, targetname, self.target)); )
240 if(e.movetype == MOVETYPE_NONE)
241 waypoint_spawnforteleporter(self, e.origin, 0);
242 if(e.classname != "info_teleport_destination")
243 LOG_INFO("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.\n");
250 objerror ("Teleporter with nonexistant target");
255 // exactly one dest - bots love that
256 self.enemy = find(e, targetname, self.target);
260 // have to use random selection every single time
266 self.touch = Teleport_Touch;
268 trigger_teleport_link(self);
270 self.move_touch = Teleport_Touch;
274 entity Teleport_Find(vector mi, vector ma)
277 for(e = world; (e = find(e, classname, "trigger_teleport")); )
278 if(WarpZoneLib_BoxTouchesBrush(mi, ma, e, world))
284 void WarpZone_PostTeleportPlayer_Callback(entity pl)
286 makevectors(pl.angles);
287 Reset_ArcBeam(pl, v_forward);
288 UpdateCSQCProjectileAfterTeleport(pl);
290 WITH(entity, self, pl, anticheat_fixangle());
292 // "disown" projectiles after teleport
294 if(pl.owner == pl.realowner)
296 if(!(pl.flags & FL_PROJECTILE))
297 LOG_INFO("A non-projectile got through a warpzone and its owner cleared. It's a ", pl.classname, ".\n");
302 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
303 pl.oldvelocity = pl.velocity;
304 // reset teleport time tracking too (or multijump can cause insane speeds)
305 pl.lastteleporttime = time;