1 void trigger_teleport_use()
4 self.team = activator.team;
7 #define TDEATHLOOP(o) \
12 deathmin = (o) + player.mins; \
13 deathmax = (o) + player.maxs; \
14 if(telefragmin != telefragmax) \
16 if(deathmin_x > telefragmin_x) deathmin_x = telefragmin_x; \
17 if(deathmin_y > telefragmin_y) deathmin_y = telefragmin_y; \
18 if(deathmin_z > telefragmin_z) deathmin_z = telefragmin_z; \
19 if(deathmax_x < telefragmax_x) deathmax_x = telefragmax_x; \
20 if(deathmax_y < telefragmax_y) deathmax_y = telefragmax_y; \
21 if(deathmax_z < telefragmax_z) deathmax_z = telefragmax_z; \
23 deathradius = max(vlen(deathmin), vlen(deathmax)); \
24 for(head = findradius(o, deathradius); head; head = head.chain) \
27 if(boxesoverlap(deathmin, deathmax, head.absmin, head.absmax))
30 float check_tdeath(entity player, vector org, vector telefragmin, vector telefragmax)
34 if ((player.classname == "player") && (player.health >= 1))
36 if(head.classname == "player")
44 void tdeath(entity player, entity teleporter, entity telefragger, vector telefragmin, vector telefragmax)
46 TDEATHLOOP(player.origin)
48 if ((player.classname == "player") && (player.health >= 1))
50 if(head.classname == "player")
53 Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');
55 else if (telefragger.health < 1) // corpses gib
56 Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');
57 else // dead bodies and monsters gib themselves instead of telefragging
58 Damage (telefragger, teleporter, telefragger, 10000, DEATH_TELEFRAG, telefragger.origin, '0 0 0');
62 void spawn_tdeath(vector v0, entity e, vector v)
64 tdeath(e, e, e, '0 0 0', '0 0 0');
68 #define TELEPORT_FLAG_SOUND 1
69 #define TELEPORT_FLAG_PARTICLES 2
70 #define TELEPORT_FLAG_TDEATH 4
72 #define TELEPORT_FLAGS_WARPZONE 0
73 #define TELEPORT_FLAGS_PORTAL (TELEPORT_FLAG_SOUND | TELEPORT_FLAG_PARTICLES)
74 #define TELEPORT_FLAGS_TELEPORTER (TELEPORT_FLAG_SOUND | TELEPORT_FLAG_PARTICLES | TELEPORT_FLAG_TDEATH)
75 void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity, vector telefragmin, vector telefragmax, float tflags)
82 telefragger = teleporter.owner;
86 makevectors (to_angles);
88 if(self.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
90 if(tflags & TELEPORT_FLAG_SOUND)
91 sound (player, CHAN_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTN_NORM);
92 if(tflags & TELEPORT_FLAG_PARTICLES)
94 pointparticles(particleeffectnum("teleport"), player.origin, '0 0 0', 1);
95 pointparticles(particleeffectnum("teleport"), to + v_forward * 32, '0 0 0', 1);
97 self.pushltime = time + 0.2;
100 // Relocate the player
101 // 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 UpdateCSQCProjectileAfterTeleport(player);
112 if(player.classname == "player")
114 if(tflags & TELEPORT_FLAG_TDEATH)
115 if(player.takedamage && player.deadflag == DEAD_NO && !g_race && !g_cts && cvar("g_telefrags"))
116 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
118 // player no longer is on ground
119 player.flags &~= FL_ONGROUND;
121 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
122 player.oldvelocity = player.velocity;
124 // reset tracking of who pushed you into a hazard (for kill credit)
127 player.pusher = teleporter.owner;
128 player.pushltime = time + cvar("g_maxpushtime");
132 player.pushltime = 0;
136 player.lastteleporttime = time;
138 // stop player name display
142 ClearSelectedPlayer();
148 void Teleport_Touch (void)
154 if (other.health < 1)
156 if not(other.flags & FL_CLIENT) // FIXME: Make missiles firable through the teleport too
160 if((self.spawnflags & 4 == 0) == (self.team != other.team))
165 makevectors(self.enemy.mangle);
167 if(other.classname == "player")
168 RemoveGrapplingHook(other);
176 RandomSelection_Init();
177 for(e = world; (e = find(e, targetname, self.target)); )
180 if(cvar("g_telefrags_avoid"))
182 o = e.origin + '0 0 1' * (1 - other.mins_z - 24);
183 if(check_tdeath(other, o, '0 0 0', '0 0 0'))
187 RandomSelection_Add(e, 0, string_null, e.cnt, p);
189 RandomSelection_Add(e, 0, string_null, 1, p);
191 e = RandomSelection_chosen_ent;
196 sprint(other, "Teleport destination vanished. Sorry... please complain to the mapper.\n");
200 if(vlen(other.velocity) > e.speed)
201 other.velocity = normalize(other.velocity) * max(0, e.speed);
202 if(cvar("g_teleport_maxspeed"))
203 if(vlen(other.velocity) > cvar("g_teleport_maxspeed"))
204 other.velocity = normalize(other.velocity) * max(0, cvar("g_teleport_maxspeed"));
206 o = e.origin + '0 0 1' * (1 - other.mins_z - 24);
207 TeleportPlayer(self, other, o, e.mangle, v_forward * vlen(other.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
219 void spawnfunc_info_teleport_destination (void)
221 self.classname = "info_teleport_destination";
223 self.mangle = self.angles;
224 self.angles = '0 0 0';
226 //setorigin (self, self.origin + '0 0 27'); // To fix a mappers' habit as old as Quake
227 setorigin (self, self.origin);
233 objerror ("^3Teleport destination without a targetname");
236 void spawnfunc_misc_teleporter_dest (void)
238 spawnfunc_info_teleport_destination();
241 void spawnfunc_target_teleporter (void)
243 spawnfunc_info_teleport_destination();
246 void teleport_findtarget (void)
251 RandomSelection_Init();
253 for(e = world; (e = find(e, targetname, self.target)); )
256 if(e.movetype == MOVETYPE_NONE)
257 RandomSelection_Add(e, 0, string_null, 1, 1);
258 if(e.classname != "info_teleport_destination")
259 print("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.\n");
261 if(RandomSelection_chosen_ent)
262 waypoint_spawnforteleporter(self, RandomSelection_chosen_ent.origin, 0);
267 objerror ("Teleporter with nonexistant target");
272 // exactly one dest - bots love that
273 self.enemy = find(e, targetname, self.target);
274 self.dest = self.enemy.origin;
278 // have to use random selection every single time
283 self.touch = Teleport_Touch;
286 void spawnfunc_trigger_teleport (void)
288 self.angles = '0 0 0';
292 self.use = trigger_teleport_use;
294 // this must be called to spawn the teleport waypoints for bots
295 InitializeEntity(self, teleport_findtarget, INITPRIO_FINDTARGET);
299 objerror ("Teleporter with no target");
304 void WarpZone_PostTeleportPlayer_Callback(entity pl)
306 UpdateCSQCProjectileAfterTeleport(pl);
307 if(pl.classname == "player")
309 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
310 pl.oldvelocity = pl.velocity;