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"
25 float check_tdeath(entity player, vector org, vector telefragmin, vector telefragmax)
27 if (IS_PLAYER(player) && player.health >= 1)
31 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
40 void tdeath(entity player, entity teleporter, entity telefragger, vector telefragmin, vector telefragmax)
42 TDEATHLOOP(player.origin)
44 if (IS_PLAYER(player) && player.health >= 1)
46 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
51 Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG.m_id, head.origin, '0 0 0');
54 else // dead bodies and monsters gib themselves instead of telefragging
55 Damage (telefragger, teleporter, telefragger, 10000, DEATH_TELEFRAG.m_id, telefragger.origin, '0 0 0');
59 void spawn_tdeath(vector v0, entity e, vector v)
61 tdeath(e, e, e, '0 0 0', '0 0 0');
64 void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity, vector telefragmin, vector telefragmax, float tflags)
70 telefragger = teleporter.owner;
74 makevectors (to_angles);
76 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
78 if(self.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
80 if(tflags & TELEPORT_FLAG_SOUND)
81 sound (player, CH_TRIGGER, SND_TELEPORT, VOL_BASE, ATTEN_NORM);
82 if(tflags & TELEPORT_FLAG_PARTICLES)
84 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
85 Send_Effect(EFFECT_TELEPORT, to + v_forward * 32, '0 0 0', 1);
87 self.pushltime = time + 0.2;
91 // Relocate the player
92 // assuming to allows PL_MIN to PL_MAX box and some more
94 setorigin (player, to);
95 player.oldorigin = to; // don't undo the teleport by unsticking
96 player.angles = to_angles;
97 player.fixangle = true;
98 player.velocity = to_velocity;
99 BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
101 makevectors(player.angles);
102 Reset_ArcBeam(player, v_forward);
103 UpdateCSQCProjectileAfterTeleport(player);
105 if(IS_PLAYER(player))
107 if(tflags & TELEPORT_FLAG_TDEATH)
108 if(player.takedamage && player.deadflag == DEAD_NO && !g_race && !g_cts && (autocvar_g_telefrags || (tflags & TELEPORT_FLAG_FORCE_TDEATH)))
109 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
111 // player no longer is on ground
112 player.flags &= ~FL_ONGROUND;
114 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
115 player.oldvelocity = player.velocity;
117 // reset tracking of who pushed you into a hazard (for kill credit)
120 player.pusher = teleporter.owner;
121 player.pushltime = time + autocvar_g_maxpushtime;
122 player.istypefrag = player.BUTTON_CHAT;
126 player.pushltime = 0;
127 player.istypefrag = 0;
130 player.lastteleporttime = time;
134 entity Simple_TeleportPlayer(entity teleporter, entity player)
140 // Find the output teleporter
143 e = teleporter.enemy;
147 RandomSelection_Init();
148 for(e = world; (e = find(e, targetname, teleporter.target)); )
151 if(autocvar_g_telefrags_avoid)
153 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
154 if(check_tdeath(player, locout, '0 0 0', '0 0 0'))
157 RandomSelection_Add(e, 0, string_null, (e.cnt ? e.cnt : 1), p);
159 e = RandomSelection_chosen_ent;
162 if(!e) { sprint(player, "Teleport destination vanished. Sorry... please complain to the mapper.\n"); }
164 makevectors(e.mangle);
167 if(vlen(player.velocity) > e.speed)
168 player.velocity = normalize(player.velocity) * max(0, e.speed);
170 if(autocvar_g_teleport_maxspeed)
171 if(vlen(player.velocity) > autocvar_g_teleport_maxspeed)
172 player.velocity = normalize(player.velocity) * max(0, autocvar_g_teleport_maxspeed);
174 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
175 TeleportPlayer(teleporter, player, locout, e.mangle, v_forward * vlen(player.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
180 void teleport_findtarget (void)
186 for(e = world; (e = find(e, targetname, self.target)); )
189 if(e.movetype == MOVETYPE_NONE)
190 waypoint_spawnforteleporter(self, e.origin, 0);
191 if(e.classname != "info_teleport_destination")
192 LOG_INFO("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.\n");
198 objerror ("Teleporter with nonexistant target");
203 // exactly one dest - bots love that
204 self.enemy = find(e, targetname, self.target);
208 // have to use random selection every single time
213 self.touch = Teleport_Touch;
216 entity Teleport_Find(vector mi, vector ma)
219 for(e = world; (e = find(e, classname, "trigger_teleport")); )
220 if(WarpZoneLib_BoxTouchesBrush(mi, ma, e, world))
225 void WarpZone_PostTeleportPlayer_Callback(entity pl)
227 makevectors(pl.angles);
228 Reset_ArcBeam(pl, v_forward);
229 UpdateCSQCProjectileAfterTeleport(pl);
231 WITH(entity, self, pl, anticheat_fixangle());
233 // "disown" projectiles after teleport
235 if(pl.owner == pl.realowner)
237 if(!(pl.flags & FL_PROJECTILE))
238 LOG_INFO("A non-projectile got through a warpzone and its owner cleared. It's a ", pl.classname, ".\n");
243 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
244 pl.oldvelocity = pl.velocity;
245 // reset teleport time tracking too (or multijump can cause insane speeds)
246 pl.lastteleporttime = time;