]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapobjects/teleporters.qc
Sort most common includes alphabetically
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapobjects / teleporters.qc
1 #include "teleporters.qh"
2
3 #if defined(CSQC)
4 #elif defined(MENUQC)
5 #elif defined(SVQC)
6         #include <common/constants.qh>
7         #include <common/deathtypes/all.qh>
8         #include <common/gamemodes/_mod.qh>
9         #include <common/mapobjects/subs.qh>
10         #include <common/stats.qh>
11         #include <common/turrets/sv_turrets.qh>
12         #include <common/util.qh>
13         #include <common/vehicles/all.qh>
14         #include <common/weapons/_all.qh>
15         #include <lib/warpzone/common.qh>
16         #include <lib/warpzone/server.qh>
17         #include <lib/warpzone/util_server.qh>
18         #include <server/anticheat.qh>
19         #include <server/autocvars.qh>
20         #include <server/weapons/csqcprojectile.qh>
21 #endif
22
23 #ifdef SVQC
24 float check_tdeath(entity player, vector org, vector telefragmin, vector telefragmax)
25 {
26         if (IS_PLAYER(player) && !IS_DEAD(player))
27         {
28                 TDEATHLOOP(org)
29                 {
30                 #ifdef SVQC
31                         if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
32                 #endif
33                                 if(IS_PLAYER(head))
34                                         if(!IS_DEAD(head))
35                                                 return 1;
36                 }
37         }
38         return 0;
39 }
40
41 void trigger_teleport_link(entity this);
42
43 void tdeath(entity player, entity teleporter, entity telefragger, vector telefragmin, vector telefragmax)
44 {
45         TDEATHLOOP(player.origin)
46         {
47                 if (IS_PLAYER(player) && GetResource(player, RES_HEALTH) >= 1)
48                 {
49                         if (!(teamplay && autocvar_g_telefrags_teamplay && head.team == player.team))
50                         {
51                                 if(IS_PLAYER(head))
52                                         if(GetResource(head, RES_HEALTH) >= 1)
53                                                 ++tdeath_hit;
54                                 Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG.m_id, DMG_NOWEP, head.origin, '0 0 0');
55                         }
56                 }
57                 else // dead bodies and monsters gib themselves instead of telefragging
58                         Damage (telefragger, teleporter, telefragger, 10000, DEATH_TELEFRAG.m_id, DMG_NOWEP, telefragger.origin, '0 0 0');
59         }
60 }
61
62 void spawn_tdeath(vector v0, entity e, vector v)
63 {
64         tdeath(e, e, e, '0 0 0', '0 0 0');
65 }
66 #endif
67
68 void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity, vector telefragmin, vector telefragmax, float tflags)
69 {
70         entity telefragger;
71         vector from;
72
73         if(teleporter.owner)
74                 telefragger = teleporter.owner;
75         else
76                 telefragger = player;
77
78         makevectors (to_angles);
79
80 #ifdef SVQC
81         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
82         {
83                 if(teleporter.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
84                 {
85                         if(tflags & TELEPORT_FLAG_SOUND)
86                         {
87                                 string thesound = SND(TELEPORT);
88                                 if(teleporter.noise != "")
89                                 {
90                                         RandomSelection_Init();
91                                         FOREACH_WORD(teleporter.noise, true,
92                                         {
93                                                 RandomSelection_AddString(it, 1, 1);
94                                         });
95                                         thesound = RandomSelection_chosen_string;
96                                 }
97                                 _sound (player, CH_TRIGGER, thesound, VOL_BASE, ATTEN_NORM);
98                         }
99                         if(tflags & TELEPORT_FLAG_PARTICLES)
100                         {
101                                 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
102                                 Send_Effect(EFFECT_TELEPORT, to + v_forward * 32, '0 0 0', 1);
103                         }
104                         teleporter.pushltime = time + 0.2;
105                 }
106         }
107 #endif
108
109         // Relocate the player
110         // assuming to allows PL_MIN to PL_MAX box and some more
111 #ifdef SVQC
112         from = player.origin;
113         setorigin(player, to);
114         player.oldorigin = to; // don't undo the teleport by unsticking
115         player.angles = to_angles;
116         if (IS_BOT_CLIENT(player))
117         {
118                 player.v_angle = player.angles;
119                 bot_aim_reset(player);
120         }
121         player.fixangle = true;
122         player.velocity = to_velocity;
123         BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
124
125         makevectors(player.angles);
126         Reset_ArcBeam(player, v_forward);
127         UpdateCSQCProjectileAfterTeleport(player);
128         UpdateItemAfterTeleport(player);
129 #elif defined(CSQC)
130         from = player.origin;
131         setorigin(player, to);
132         player.angles = to_angles;
133         player.velocity = to_velocity;
134         UNSET_ONGROUND(player);
135         player.iflags |= IFLAG_TELEPORTED | IFLAG_V_ANGLE | IFLAG_ANGLES;
136         player.csqcmodel_teleported = 1;
137         player.v_angle = to_angles;
138
139         if(player == csqcplayer) // not for anything but the main player
140         {
141                 setproperty(VF_ANGLES, player.angles);
142                 setproperty(VF_CL_VIEWANGLES, player.angles);
143         }
144 #endif
145
146 #ifdef SVQC
147         if(IS_PLAYER(player))
148         {
149                 if((tflags & TELEPORT_FLAG_TDEATH) && player.takedamage && !IS_DEAD(player)
150                         && !g_race && !g_cts && (autocvar_g_telefrags || (tflags & TELEPORT_FLAG_FORCE_TDEATH))
151                         && !(round_handler_IsActive() && !round_handler_IsRoundStarted()))
152                 {
153                         tdeath(player, teleporter, telefragger, telefragmin, telefragmax);
154                 }
155
156                 // player no longer is on ground
157                 UNSET_ONGROUND(player);
158
159                 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
160                 player.oldvelocity = player.velocity;
161
162                 // reset tracking of who pushed you into a hazard (for kill credit)
163                 if(teleporter.owner)
164                 {
165                         player.pusher = teleporter.owner;
166                         player.pushltime = time + autocvar_g_maxpushtime;
167                         player.istypefrag = PHYS_INPUT_BUTTON_CHAT(player);
168                 }
169                 else
170                 {
171                         player.pushltime = 0;
172                         player.istypefrag = 0;
173                 }
174
175                 player.lastteleporttime = time;
176                 player.lastteleport_origin = from;
177         }
178 #endif
179 }
180
181 entity Simple_TeleportPlayer(entity teleporter, entity player)
182 {
183         vector locout;
184         entity e = NULL;
185
186         // Find the output teleporter
187         if(teleporter.enemy)
188         {
189                 e = teleporter.enemy;
190         }
191         else
192         {
193                 // sorry CSQC, random stuff ain't gonna happen
194 #ifdef SVQC
195                 RandomSelection_Init();
196                 FOREACH_ENTITY_STRING(targetname, teleporter.target,
197                 {
198                         bool p = true;
199                         if(STAT(TELEPORT_TELEFRAG_AVOID, player))
200                         {
201                         #ifdef SVQC
202                                 locout = it.origin + '0 0 1' * (1 - player.mins.z - 24);
203                         #elif defined(CSQC)
204                                 locout = it.origin + '0 0 1' * (1 - player.mins.z - 24);
205                         #endif
206                                 if(check_tdeath(player, locout, '0 0 0', '0 0 0'))
207                                         p = false;
208                         }
209                         RandomSelection_AddEnt(it, (it.cnt ? it.cnt : 1), p);
210                 });
211                 e = RandomSelection_chosen_ent;
212 #endif
213         }
214
215 #ifdef SVQC
216         if(!e) { sprint(player, "Teleport destination vanished. Sorry... please complain to the mapper.\n"); }
217 #elif defined(CSQC)
218         if(!e) { LOG_INFO("Teleport destination could not be found from CSQC."); }
219 #endif
220
221         makevectors(e.mangle);
222
223         if(e.speed)
224                 if(vdist(player.velocity, >, e.speed))
225                         player.velocity = normalize(player.velocity) * max(0, e.speed);
226
227         if(STAT(TELEPORT_MAXSPEED, player))
228                 if(vdist(player.velocity, >, STAT(TELEPORT_MAXSPEED, player)))
229                         player.velocity = normalize(player.velocity) * max(0, STAT(TELEPORT_MAXSPEED, player));
230
231         locout = e.origin + '0 0 1' * (1 - player.mins.z - 24);
232
233         TeleportPlayer(teleporter, player, locout, e.mangle, v_forward * vlen(player.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
234
235         return e;
236 }
237
238 void teleport_findtarget(entity this)
239 {
240         bool istrigger = (this.solid == SOLID_TRIGGER);
241
242         int n = 0;
243         for(entity e = NULL; (e = find(e, targetname, this.target)); )
244         {
245                 ++n;
246 #ifdef SVQC
247                 if(e.move_movetype == MOVETYPE_NONE)
248                 {
249                         entity tracetest_ent = spawn();
250                         setsize(tracetest_ent, PL_MIN_CONST, PL_MAX_CONST);
251                         tracetest_ent.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
252                         waypoint_spawnforteleporter(this, e.origin, 0, tracetest_ent);
253                         delete(tracetest_ent);
254                 }
255                 if(e.classname != "info_teleport_destination")
256                         LOG_INFO("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.");
257 #endif
258         }
259
260         if(n == 0)
261         {
262                 // no dest!
263                 objerror (this, "Teleporter with nonexistent target");
264                 return;
265         }
266         else if(n == 1)
267         {
268                 // exactly one dest - bots love that
269                 this.enemy = find(NULL, targetname, this.target);
270         }
271         else
272         {
273                 // have to use random selection every single time
274                 this.enemy = NULL;
275         }
276
277         // now enable touch
278         if(istrigger)
279                 settouch(this, Teleport_Touch);
280 #ifdef SVQC
281         if(istrigger)
282                 trigger_teleport_link(this);
283 #endif
284 }
285
286 entity Teleport_Find(vector mi, vector ma)
287 {
288         IL_EACH(g_teleporters, WarpZoneLib_BoxTouchesBrush(mi, ma, it, NULL),
289         {
290                 return it;
291         });
292         return NULL;
293 }
294
295 void WarpZone_PostTeleportPlayer_Callback(entity pl)
296 {
297 #ifdef SVQC
298         makevectors(pl.angles);
299         Reset_ArcBeam(pl, v_forward);
300         UpdateCSQCProjectileAfterTeleport(pl);
301         UpdateItemAfterTeleport(pl);
302     if (IS_PLAYER(pl)) anticheat_fixangle(pl);
303 #endif
304         // "disown" projectiles after teleport
305         if(pl.owner)
306         if(pl.owner == pl.realowner)
307         {
308         #ifdef SVQC
309                 if(!(pl.flags & FL_PROJECTILE))
310         #elif defined(CSQC)
311                 if(!(pl.flags & BIT(15))) // FL_PROJECTILE
312         #endif
313                         LOG_INFO("A non-projectile got through a warpzone and its owner cleared. It's a ", pl.classname, ".");
314                 pl.owner = NULL;
315         }
316         if(IS_PLAYER(pl))
317         {
318                 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
319         #ifdef SVQC
320                 pl.oldvelocity = pl.velocity;
321         #endif
322         }
323 }