]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/t_teleporters.qc
Merge remote branch 'refs/remotes/origin/fruitiex/newpanelhud_stable'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / t_teleporters.qc
1 void trigger_teleport_use()
2 {
3         if(teams_matter)
4                 self.team = activator.team;
5 }
6
7 #define TDEATHLOOP(o) \
8         entity head; \
9         vector deathmin; \
10         vector deathmax; \
11         float deathradius; \
12         deathmin = (o) + player.mins; \
13         deathmax = (o) + player.maxs; \
14         if(telefragmin != telefragmax) \
15         { \
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; \
22         } \
23         deathradius = max(vlen(deathmin), vlen(deathmax)); \
24         for(head = findradius(o, deathradius); head; head = head.chain) \
25                 if(head != player) \
26                         if(head.takedamage) \
27                                 if(boxesoverlap(deathmin, deathmax, head.absmin, head.absmax))
28         
29
30 float check_tdeath(entity player, vector org, vector telefragmin, vector telefragmax)
31 {
32         if (player.classname == "player" && player.health >= 1)
33         {
34                 TDEATHLOOP(org)
35                 {
36                         if not(teamplay && cvar("g_telefrags_teamplay") && head.team == player.team)
37                                 if(head.classname == "player")
38                                         if(head.health >= 1)
39                                                 return 1;
40                 }
41         }
42         return 0;
43 }
44 float tdeath_hit;
45 void tdeath(entity player, entity teleporter, entity telefragger, vector telefragmin, vector telefragmax)
46 {
47         TDEATHLOOP(player.origin)
48         {
49                 if (player.classname == "player" && player.health >= 1)
50                 {
51                         if not(teamplay && cvar("g_telefrags_teamplay") && head.team == player.team)
52                         {
53                                 if(head.classname == "player")
54                                         if(head.health >= 1)
55                                                 ++tdeath_hit;
56                                 Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');
57                         }
58                 }
59                 else // dead bodies and monsters gib themselves instead of telefragging
60                         Damage (telefragger, teleporter, telefragger, 10000, DEATH_TELEFRAG, telefragger.origin, '0 0 0');
61         }
62 }
63
64 void spawn_tdeath(vector v0, entity e, vector v)
65 {
66         tdeath(e, e, e, '0 0 0', '0 0 0');
67 }
68
69 .entity pusher;
70 #define TELEPORT_FLAG_SOUND 1
71 #define TELEPORT_FLAG_PARTICLES 2
72 #define TELEPORT_FLAG_TDEATH 4
73 #define TELEPORT_FLAG_FORCE_TDEATH 8
74
75 #define TELEPORT_FLAGS_WARPZONE   0
76 #define TELEPORT_FLAGS_PORTAL     (TELEPORT_FLAG_SOUND | TELEPORT_FLAG_PARTICLES | TELEPORT_FLAG_TDEATH | TELEPORT_FLAG_FORCE_TDEATH)
77 #define TELEPORT_FLAGS_TELEPORTER (TELEPORT_FLAG_SOUND | TELEPORT_FLAG_PARTICLES | TELEPORT_FLAG_TDEATH)
78 void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity, vector telefragmin, vector telefragmax, float tflags)
79 {
80         entity oldself;
81         entity telefragger;
82         vector from;
83
84         if(teleporter.owner)
85                 telefragger = teleporter.owner;
86         else
87                 telefragger = player;
88
89         makevectors (to_angles);
90
91         if(self.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
92         {
93                 if(tflags & TELEPORT_FLAG_SOUND)
94                         sound (player, CHAN_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTN_NORM);
95                 if(tflags & TELEPORT_FLAG_PARTICLES)
96                 {
97                         pointparticles(particleeffectnum("teleport"), player.origin, '0 0 0', 1);
98                         pointparticles(particleeffectnum("teleport"), to + v_forward * 32, '0 0 0', 1);
99                 }
100                 self.pushltime = time + 0.2;
101         }
102
103         // Relocate the player
104         // assuming to allows PL_MIN to PL_MAX box and some more
105         from = player.origin;
106         setorigin (player, to);
107         player.oldorigin = to; // don't undo the teleport by unsticking
108         player.angles = to_angles;
109         player.fixangle = TRUE;
110         player.velocity = to_velocity;
111         BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
112
113         UpdateCSQCProjectileAfterTeleport(player);
114
115         if(player.classname == "player")
116         {
117                 if(tflags & TELEPORT_FLAG_TDEATH)
118                         if(player.takedamage && player.deadflag == DEAD_NO && !g_race && !g_cts && (cvar("g_telefrags") || (tflags & TELEPORT_FLAG_FORCE_TDEATH)))
119                                 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
120
121                 // player no longer is on ground
122                 player.flags &~= FL_ONGROUND;
123
124                 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
125                 player.oldvelocity = player.velocity;
126
127                 // reset tracking of who pushed you into a hazard (for kill credit)
128                 if(teleporter.owner)
129                 {
130                         player.pusher = teleporter.owner;
131                         player.pushltime = time + cvar("g_maxpushtime");
132                 }
133                 else
134                 {
135                         player.pushltime = 0;
136                 }
137
138                 player.lastteleporttime = time;
139
140                 // stop player name display
141                 {
142                         oldself = self;
143                         self = player;
144                         ClearSelectedPlayer();
145                         self = oldself;
146                 }
147         }
148 }
149
150 void Teleport_Touch (void)
151 {
152         entity oldself, e;
153         vector o;
154         float p;
155
156         if (other.health < 1)
157                 return;
158         if not(other.flags & FL_CLIENT) // FIXME: Make missiles firable through the teleport too
159                 return;
160
161         if(self.team)
162                 if((self.spawnflags & 4 == 0) == (self.team != other.team))
163                         return;
164
165         EXACTTRIGGER_TOUCH;
166
167         makevectors(self.enemy.mangle);
168
169         if(other.classname == "player")
170                 RemoveGrapplingHook(other);
171         
172         if(self.enemy)
173         {
174                 e = self.enemy;
175         }
176         else
177         {
178                 RandomSelection_Init();
179                 for(e = world; (e = find(e, targetname, self.target)); )
180                 {
181                         p = 1;
182                         if(cvar("g_telefrags_avoid"))
183                         {
184                                 o = e.origin + '0 0 1' * (1 - other.mins_z - 24);
185                                 if(check_tdeath(other, o, '0 0 0', '0 0 0'))
186                                         p = 0;
187                         }
188                         if(e.cnt)
189                                 RandomSelection_Add(e, 0, string_null, e.cnt, p);
190                         else
191                                 RandomSelection_Add(e, 0, string_null, 1, p);
192                 }
193                 e = RandomSelection_chosen_ent;
194         }
195
196         if(!e)
197         {
198                 sprint(other, "Teleport destination vanished. Sorry... please complain to the mapper.\n");
199         }
200
201         if(e.speed)
202                 if(vlen(other.velocity) > e.speed)
203                         other.velocity = normalize(other.velocity) * max(0, e.speed);
204         if(cvar("g_teleport_maxspeed"))
205                 if(vlen(other.velocity) > cvar("g_teleport_maxspeed"))
206                         other.velocity = normalize(other.velocity) * max(0, cvar("g_teleport_maxspeed"));
207
208         o = e.origin + '0 0 1' * (1 - other.mins_z - 24);
209         TeleportPlayer(self, other, o, e.mangle, v_forward * vlen(other.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
210
211         if(e.target)
212         {
213                 oldself = self;
214                 activator = other;
215                 self = e;
216                 SUB_UseTargets();
217                 self = oldself;
218         }
219 }
220
221 void spawnfunc_info_teleport_destination (void)
222 {
223         self.classname = "info_teleport_destination";
224
225         self.mangle = self.angles;
226         self.angles = '0 0 0';
227
228         //setorigin (self, self.origin + '0 0 27');     // To fix a mappers' habit as old as Quake
229         setorigin (self, self.origin);
230
231         IFTARGETED
232         {
233         }
234         else
235                 objerror ("^3Teleport destination without a targetname");
236 }
237
238 void spawnfunc_misc_teleporter_dest (void)
239 {
240         spawnfunc_info_teleport_destination();
241 }
242
243 void spawnfunc_target_teleporter (void)
244 {
245         spawnfunc_info_teleport_destination();
246 }
247
248 void teleport_findtarget (void)
249 {
250         entity e;
251         float n;
252
253         RandomSelection_Init();
254         n = 0;
255         for(e = world; (e = find(e, targetname, self.target)); )
256         {
257                 ++n;
258                 if(e.movetype == MOVETYPE_NONE)
259                         RandomSelection_Add(e, 0, string_null, 1, 1);
260                 if(e.classname != "info_teleport_destination")
261                         print("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.\n");
262         }
263         if(RandomSelection_chosen_ent)
264                 waypoint_spawnforteleporter(self, RandomSelection_chosen_ent.origin, 0);
265
266         if(n == 0)
267         {
268                 // no dest!
269                 objerror ("Teleporter with nonexistant target");
270                 return;
271         }
272         else if(n == 1)
273         {
274                 // exactly one dest - bots love that
275                 self.enemy = find(e, targetname, self.target);
276                 self.dest = self.enemy.origin;
277         }
278         else
279         {
280                 // have to use random selection every single time
281                 self.enemy = world;
282         }
283
284         // now enable touch
285         self.touch = Teleport_Touch;
286 }
287
288 void spawnfunc_trigger_teleport (void)
289 {
290         self.angles = '0 0 0';
291
292         EXACTTRIGGER_INIT;
293
294         self.use = trigger_teleport_use;
295
296         // this must be called to spawn the teleport waypoints for bots
297         InitializeEntity(self, teleport_findtarget, INITPRIO_FINDTARGET);
298
299         if (!self.target)
300         {
301                 objerror ("Teleporter with no target");
302                 return;
303         }
304 }
305
306 void WarpZone_PostTeleportPlayer_Callback(entity pl)
307 {
308         UpdateCSQCProjectileAfterTeleport(pl);
309         if(pl.classname == "player")
310         {
311                 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
312                 pl.oldvelocity = pl.velocity;
313                 // reset teleport time tracking too (or multijump can cause insane speeds)
314                 pl.lastteleporttime = time;
315         }
316 }