1 #include "teleporters.qh"
6 #include "../../server/_all.qh"
7 #include "../../warpzonelib/common.qh"
8 #include "../../warpzonelib/util_server.qh"
9 #include "../../warpzonelib/server.qh"
10 #include "../constants.qh"
11 #include "../triggers/subs.qh"
13 #include "../../server/weapons/csqcprojectile.qh"
14 #include "../../server/autocvars.qh"
15 #include "../../server/constants.qh"
16 #include "../../server/defs.qh"
17 #include "../deathtypes.qh"
18 #include "../turrets/sv_turrets.qh"
19 #include "../vehicles/all.qh"
20 #include "../mapinfo.qh"
21 #include "../../server/anticheat.qh"
26 float check_tdeath(entity player, vector org, vector telefragmin, vector telefragmax)
28 if (IS_PLAYER(player) && player.health >= 1)
32 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
41 void tdeath(entity player, entity teleporter, entity telefragger, vector telefragmin, vector telefragmax)
43 TDEATHLOOP(player.origin)
45 if (IS_PLAYER(player) && player.health >= 1)
47 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
52 Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');
55 else // dead bodies and monsters gib themselves instead of telefragging
56 Damage (telefragger, teleporter, telefragger, 10000, DEATH_TELEFRAG, telefragger.origin, '0 0 0');
60 void spawn_tdeath(vector v0, entity e, vector v)
62 tdeath(e, e, e, '0 0 0', '0 0 0');
65 void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity, vector telefragmin, vector telefragmax, float tflags)
71 telefragger = teleporter.owner;
75 makevectors (to_angles);
77 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
79 if(self.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
81 if(tflags & TELEPORT_FLAG_SOUND)
82 sound (player, CH_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTEN_NORM);
83 if(tflags & TELEPORT_FLAG_PARTICLES)
85 Send_Effect("teleport", player.origin, '0 0 0', 1);
86 Send_Effect("teleport", to + v_forward * 32, '0 0 0', 1);
88 self.pushltime = time + 0.2;
92 // Relocate the player
93 // assuming to allows PL_MIN to PL_MAX box and some more
95 setorigin (player, to);
96 player.oldorigin = to; // don't undo the teleport by unsticking
97 player.angles = to_angles;
98 player.fixangle = true;
99 player.velocity = to_velocity;
100 BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
102 makevectors(player.angles);
103 Reset_ArcBeam(player, v_forward);
104 UpdateCSQCProjectileAfterTeleport(player);
106 if(IS_PLAYER(player))
108 if(tflags & TELEPORT_FLAG_TDEATH)
109 if(player.takedamage && player.deadflag == DEAD_NO && !g_race && !g_cts && (autocvar_g_telefrags || (tflags & TELEPORT_FLAG_FORCE_TDEATH)))
110 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
112 // player no longer is on ground
113 player.flags &= ~FL_ONGROUND;
115 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
116 player.oldvelocity = player.velocity;
118 // reset tracking of who pushed you into a hazard (for kill credit)
121 player.pusher = teleporter.owner;
122 player.pushltime = time + autocvar_g_maxpushtime;
123 player.istypefrag = player.BUTTON_CHAT;
127 player.pushltime = 0;
128 player.istypefrag = 0;
131 player.lastteleporttime = time;
135 entity Simple_TeleportPlayer(entity teleporter, entity player)
141 // Find the output teleporter
144 e = teleporter.enemy;
148 RandomSelection_Init();
149 for(e = world; (e = find(e, targetname, teleporter.target)); )
152 if(autocvar_g_telefrags_avoid)
154 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
155 if(check_tdeath(player, locout, '0 0 0', '0 0 0'))
158 RandomSelection_Add(e, 0, string_null, (e.cnt ? e.cnt : 1), p);
160 e = RandomSelection_chosen_ent;
163 if(!e) { sprint(player, "Teleport destination vanished. Sorry... please complain to the mapper.\n"); }
165 makevectors(e.mangle);
168 if(vlen(player.velocity) > e.speed)
169 player.velocity = normalize(player.velocity) * max(0, e.speed);
171 if(autocvar_g_teleport_maxspeed)
172 if(vlen(player.velocity) > autocvar_g_teleport_maxspeed)
173 player.velocity = normalize(player.velocity) * max(0, autocvar_g_teleport_maxspeed);
175 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
176 TeleportPlayer(teleporter, player, locout, e.mangle, v_forward * vlen(player.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
181 void teleport_findtarget (void)
187 for(e = world; (e = find(e, targetname, self.target)); )
190 if(e.movetype == MOVETYPE_NONE)
191 waypoint_spawnforteleporter(self, e.origin, 0);
192 if(e.classname != "info_teleport_destination")
193 print("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.\n");
199 objerror ("Teleporter with nonexistant target");
204 // exactly one dest - bots love that
205 self.enemy = find(e, targetname, self.target);
209 // have to use random selection every single time
214 self.touch = Teleport_Touch;
217 entity Teleport_Find(vector mi, vector ma)
220 for(e = world; (e = find(e, classname, "trigger_teleport")); )
221 if(WarpZoneLib_BoxTouchesBrush(mi, ma, e, world))
226 void WarpZone_PostTeleportPlayer_Callback(entity pl)
228 makevectors(pl.angles);
229 Reset_ArcBeam(pl, v_forward);
230 UpdateCSQCProjectileAfterTeleport(pl);
232 entity oldself = self;
234 anticheat_fixangle();
237 // "disown" projectiles after teleport
239 if(pl.owner == pl.realowner)
241 if(!(pl.flags & FL_PROJECTILE))
242 print("A non-projectile got through a warpzone and its owner cleared. It's a ", pl.classname, ".\n");
247 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
248 pl.oldvelocity = pl.velocity;
249 // reset teleport time tracking too (or multijump can cause insane speeds)
250 pl.lastteleporttime = time;