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 void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity, vector telefragmin, vector telefragmax)
75 telefragger = teleporter.owner;
79 makevectors (to_angles);
81 if(self.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
83 sound (player, CHAN_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTN_NORM);
84 pointparticles(particleeffectnum("teleport"), player.origin, '0 0 0', 1);
85 pointparticles(particleeffectnum("teleport"), to + v_forward * 32, '0 0 0', 1);
86 self.pushltime = time + 0.2;
89 // Relocate the player
90 // assuming to allows PL_MIN to PL_MAX box and some more
92 setorigin (player, to);
93 player.oldorigin = to; // don't undo the teleport by unsticking
94 player.angles = to_angles;
95 player.fixangle = TRUE;
96 player.velocity = to_velocity;
97 BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
99 UpdateCSQCProjectileAfterTeleport(player);
101 if(player.classname == "player")
103 if(player.takedamage && player.deadflag == DEAD_NO && !g_race && !g_cts && cvar("g_telefrags"))
104 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
106 // player no longer is on ground
107 player.flags &~= FL_ONGROUND;
109 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
110 player.oldvelocity = player.velocity;
112 // reset tracking of who pushed you into a hazard (for kill credit)
115 player.pusher = teleporter.owner;
116 player.pushltime = time + cvar("g_maxpushtime");
120 player.pushltime = 0;
124 player.lastteleporttime = time;
126 // stop player name display
130 ClearSelectedPlayer();
136 void Teleport_Touch (void)
142 if (other.health < 1)
144 if not(other.flags & FL_CLIENT) // FIXME: Make missiles firable through the teleport too
148 if((self.spawnflags & 4 == 0) == (self.team != other.team))
153 makevectors(self.enemy.mangle);
155 if(other.classname == "player")
156 RemoveGrapplingHook(other);
164 RandomSelection_Init();
165 for(e = world; (e = find(e, targetname, self.target)); )
168 if(cvar("g_telefrags_avoid"))
170 o = e.origin + '0 0 1' * (1 - other.mins_z - 24);
171 if(check_tdeath(other, o, '0 0 0', '0 0 0'))
175 RandomSelection_Add(e, 0, string_null, e.cnt, p);
177 RandomSelection_Add(e, 0, string_null, 1, p);
179 e = RandomSelection_chosen_ent;
184 sprint(other, "Teleport destination vanished. Sorry... please complain to the mapper.\n");
188 if(vlen(other.velocity) > e.speed)
189 other.velocity = normalize(other.velocity) * max(0, e.speed);
190 if(cvar("g_teleport_maxspeed"))
191 if(vlen(other.velocity) > cvar("g_teleport_maxspeed"))
192 other.velocity = normalize(other.velocity) * max(0, cvar("g_teleport_maxspeed"));
194 o = e.origin + '0 0 1' * (1 - other.mins_z - 24);
195 TeleportPlayer(self, other, o, e.mangle, v_forward * vlen(other.velocity), '0 0 0', '0 0 0');
207 void spawnfunc_info_teleport_destination (void)
209 self.classname = "info_teleport_destination";
211 self.mangle = self.angles;
212 self.angles = '0 0 0';
214 //setorigin (self, self.origin + '0 0 27'); // To fix a mappers' habit as old as Quake
215 setorigin (self, self.origin);
221 objerror ("^3Teleport destination without a targetname");
224 void spawnfunc_misc_teleporter_dest (void)
226 spawnfunc_info_teleport_destination();
229 void spawnfunc_target_teleporter (void)
231 spawnfunc_info_teleport_destination();
234 void teleport_findtarget (void)
240 for(e = world; (e = find(e, targetname, self.target)); )
243 if(e.movetype == MOVETYPE_NONE)
244 waypoint_spawnforteleporter(self, e.origin, 0);
245 if(e.classname != "info_teleport_destination")
246 print("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.\n");
252 objerror ("Teleporter with nonexistant target");
257 // exactly one dest - bots love that
258 self.enemy = find(e, targetname, self.target);
259 self.dest = self.enemy.origin;
263 // have to use random selection every single time
268 self.touch = Teleport_Touch;
271 void spawnfunc_trigger_teleport (void)
273 self.angles = '0 0 0';
277 self.use = trigger_teleport_use;
279 // this must be called to spawn the teleport waypoints for bots
280 InitializeEntity(self, teleport_findtarget, INITPRIO_FINDTARGET);
284 objerror ("Teleporter with no target");