4 #include "../dpdefs/progsdefs.qh"
5 #include "../dpdefs/dpextensions.qh"
6 #include "../warpzonelib/common.qh"
7 #include "../warpzonelib/util_server.qh"
8 #include "../warpzonelib/server.qh"
9 #include "../common/constants.qh"
10 #include "../common/util.qh"
11 #include "weapons/csqcprojectile.qh"
12 #include "autocvars.qh"
13 #include "constants.qh"
15 #include "../common/deathtypes.qh"
16 #include "tturrets/include/turrets_early.qh"
17 #include "vehicles/vehicles_def.qh"
18 #include "../common/mapinfo.qh"
19 #include "anticheat.qh"
22 void trigger_teleport_use()
25 self.team = activator.team;
28 #define TDEATHLOOP(o) \
33 deathmin = (o) + player.mins; \
34 deathmax = (o) + player.maxs; \
35 if(telefragmin != telefragmax) \
37 if(deathmin.x > telefragmin.x) deathmin_x = telefragmin.x; \
38 if(deathmin.y > telefragmin.y) deathmin_y = telefragmin.y; \
39 if(deathmin.z > telefragmin.z) deathmin_z = telefragmin.z; \
40 if(deathmax.x < telefragmax.x) deathmax_x = telefragmax.x; \
41 if(deathmax.y < telefragmax.y) deathmax_y = telefragmax.y; \
42 if(deathmax.z < telefragmax.z) deathmax_z = telefragmax.z; \
44 deathradius = max(vlen(deathmin), vlen(deathmax)); \
45 for(head = findradius(o, deathradius); head; head = head.chain) \
48 if(boxesoverlap(deathmin, deathmax, head.absmin, head.absmax))
51 float check_tdeath(entity player, vector org, vector telefragmin, vector telefragmax)
53 if (IS_PLAYER(player) && player.health >= 1)
57 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
66 void tdeath(entity player, entity teleporter, entity telefragger, vector telefragmin, vector telefragmax)
68 TDEATHLOOP(player.origin)
70 if (IS_PLAYER(player) && player.health >= 1)
72 if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
77 Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');
80 else // dead bodies and monsters gib themselves instead of telefragging
81 Damage (telefragger, teleporter, telefragger, 10000, DEATH_TELEFRAG, telefragger.origin, '0 0 0');
85 void spawn_tdeath(vector v0, entity e, vector v)
87 tdeath(e, e, e, '0 0 0', '0 0 0');
91 const float TELEPORT_FLAG_SOUND = 1;
92 const float TELEPORT_FLAG_PARTICLES = 2;
93 const float TELEPORT_FLAG_TDEATH = 4;
94 const float TELEPORT_FLAG_FORCE_TDEATH = 8;
96 #define TELEPORT_FLAGS_WARPZONE 0
97 #define TELEPORT_FLAGS_PORTAL (TELEPORT_FLAG_SOUND | TELEPORT_FLAG_PARTICLES | TELEPORT_FLAG_TDEATH | TELEPORT_FLAG_FORCE_TDEATH)
98 #define TELEPORT_FLAGS_TELEPORTER (TELEPORT_FLAG_SOUND | TELEPORT_FLAG_PARTICLES | TELEPORT_FLAG_TDEATH)
100 // types for .teleportable entity setting
101 const float TELEPORT_NORMAL = 1; // play sounds/effects etc
102 const float TELEPORT_SIMPLE = 2; // only do teleport, nothing special
104 void Reset_ArcBeam(entity player, vector forward);
105 void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity, vector telefragmin, vector telefragmax, float tflags)
111 telefragger = teleporter.owner;
113 telefragger = player;
115 makevectors (to_angles);
117 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
119 if(self.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
121 if(tflags & TELEPORT_FLAG_SOUND)
122 sound (player, CH_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTEN_NORM);
123 if(tflags & TELEPORT_FLAG_PARTICLES)
125 pointparticles(particleeffectnum("teleport"), player.origin, '0 0 0', 1);
126 pointparticles(particleeffectnum("teleport"), to + v_forward * 32, '0 0 0', 1);
128 self.pushltime = time + 0.2;
132 // Relocate the player
133 // assuming to allows PL_MIN to PL_MAX box and some more
134 from = player.origin;
135 setorigin (player, to);
136 player.oldorigin = to; // don't undo the teleport by unsticking
137 player.angles = to_angles;
138 player.fixangle = true;
139 player.velocity = to_velocity;
140 BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
142 makevectors(player.angles);
143 Reset_ArcBeam(player, v_forward);
144 UpdateCSQCProjectileAfterTeleport(player);
146 if(IS_PLAYER(player))
148 if(tflags & TELEPORT_FLAG_TDEATH)
149 if(player.takedamage && player.deadflag == DEAD_NO && !g_race && !g_cts && (autocvar_g_telefrags || (tflags & TELEPORT_FLAG_FORCE_TDEATH)))
150 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
152 // player no longer is on ground
153 player.flags &= ~FL_ONGROUND;
155 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
156 player.oldvelocity = player.velocity;
158 // reset tracking of who pushed you into a hazard (for kill credit)
161 player.pusher = teleporter.owner;
162 player.pushltime = time + autocvar_g_maxpushtime;
163 player.istypefrag = player.BUTTON_CHAT;
167 player.pushltime = 0;
168 player.istypefrag = 0;
171 player.lastteleporttime = time;
175 entity Simple_TeleportPlayer(entity teleporter, entity player)
181 // Find the output teleporter
184 e = teleporter.enemy;
188 RandomSelection_Init();
189 for(e = world; (e = find(e, targetname, teleporter.target)); )
192 if(autocvar_g_telefrags_avoid)
194 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
195 if(check_tdeath(player, locout, '0 0 0', '0 0 0'))
198 RandomSelection_Add(e, 0, string_null, (e.cnt ? e.cnt : 1), p);
200 e = RandomSelection_chosen_ent;
203 if(!e) { sprint(player, "Teleport destination vanished. Sorry... please complain to the mapper.\n"); }
205 makevectors(e.mangle);
208 if(vlen(player.velocity) > e.speed)
209 player.velocity = normalize(player.velocity) * max(0, e.speed);
211 if(autocvar_g_teleport_maxspeed)
212 if(vlen(player.velocity) > autocvar_g_teleport_maxspeed)
213 player.velocity = normalize(player.velocity) * max(0, autocvar_g_teleport_maxspeed);
215 locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
216 TeleportPlayer(teleporter, player, locout, e.mangle, v_forward * vlen(player.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
221 void Teleport_Touch (void)
226 if (self.active != ACTIVE_ACTIVE)
229 if (!other.teleportable)
233 if(!other.vehicle.teleportable)
236 if(other.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
239 if(other.deadflag != DEAD_NO)
243 if(((self.spawnflags & 4) == 0) == (self.team != other.team))
249 RemoveGrapplingHook(other);
252 e = Simple_TeleportPlayer(self, other);
255 s = self.target; self.target = string_null;
257 if (!self.target) self.target = s;
265 void spawnfunc_info_teleport_destination (void)
267 self.classname = "info_teleport_destination";
269 self.mangle = self.angles;
270 self.angles = '0 0 0';
272 //setorigin (self, self.origin + '0 0 27'); // To fix a mappers' habit as old as Quake
273 setorigin (self, self.origin);
279 objerror ("^3Teleport destination without a targetname");
282 void spawnfunc_misc_teleporter_dest (void)
284 spawnfunc_info_teleport_destination();
287 void spawnfunc_target_teleporter (void)
289 spawnfunc_info_teleport_destination();
292 void teleport_findtarget (void)
298 for(e = world; (e = find(e, targetname, self.target)); )
301 if(e.movetype == MOVETYPE_NONE)
302 waypoint_spawnforteleporter(self, e.origin, 0);
303 if(e.classname != "info_teleport_destination")
304 print("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.\n");
310 objerror ("Teleporter with nonexistant target");
315 // exactly one dest - bots love that
316 self.enemy = find(e, targetname, self.target);
320 // have to use random selection every single time
325 self.touch = Teleport_Touch;
328 entity Teleport_Find(vector mi, vector ma)
331 for(e = world; (e = find(e, classname, "trigger_teleport")); )
332 if(WarpZoneLib_BoxTouchesBrush(mi, ma, e, world))
337 entity teleport_first;
338 .entity teleport_next;
339 void spawnfunc_trigger_teleport (void)
341 self.angles = '0 0 0';
345 self.active = ACTIVE_ACTIVE;
347 self.use = trigger_teleport_use;
349 // this must be called to spawn the teleport waypoints for bots
350 InitializeEntity(self, teleport_findtarget, INITPRIO_FINDTARGET);
352 if (self.target == "")
354 objerror ("Teleporter with no target");
358 self.teleport_next = teleport_first;
359 teleport_first = self;
362 void WarpZone_PostTeleportPlayer_Callback(entity pl)
364 makevectors(pl.angles);
365 Reset_ArcBeam(pl, v_forward);
366 UpdateCSQCProjectileAfterTeleport(pl);
368 entity oldself = self;
370 anticheat_fixangle();
373 // "disown" projectiles after teleport
375 if(pl.owner == pl.realowner)
377 if(!(pl.flags & FL_PROJECTILE))
378 print("A non-projectile got through a warpzone and its owner cleared. It's a ", pl.classname, ".\n");
383 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
384 pl.oldvelocity = pl.velocity;
385 // reset teleport time tracking too (or multijump can cause insane speeds)
386 pl.lastteleporttime = time;