]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/sv_main.qc
Add an option to burn the player when they enter lava
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / sv_main.qc
1
2 #include "anticheat.qh"
3 #include "g_hook.qh"
4 #include "g_world.qh"
5
6 #include "bot/bot.qh"
7 #include "bot/waypoints.qh"
8
9 #include "command/common.qh"
10
11 #include "mutators/all.qh"
12 #include "weapons/csqcprojectile.qh"
13
14 #include "../common/constants.qh"
15 #include "../common/deathtypes/all.qh"
16 #include "../common/debug.qh"
17 #include "../common/mapinfo.qh"
18 #include "../common/util.qh"
19
20 #include "../common/vehicles/all.qh"
21 #include "../common/weapons/all.qh"
22
23 #include "../lib/csqcmodel/sv_model.qh"
24
25 #include "../lib/warpzone/common.qh"
26 #include "../lib/warpzone/server.qh"
27
28 .float lastground;
29 .int state;
30
31 void CreatureFrame ()
32 {SELFPARAM();
33         float dm;
34
35         for(entity e = world; (e = findfloat(e, damagedbycontents, true)); )
36         {
37                 setself(e);
38                 if (self.movetype == MOVETYPE_NOCLIP) { continue; }
39
40                 float vehic = IS_VEHICLE(self);
41                 float projectile = (self.flags & FL_PROJECTILE);
42                 float monster = IS_MONSTER(self);
43
44                 if (self.watertype <= CONTENT_WATER && self.waterlevel > 0) // workaround a retarded bug made by id software :P (yes, it's that old of a bug)
45                 {
46                         if (!(self.flags & FL_INWATER))
47                         {
48                                 self.flags |= FL_INWATER;
49                                 self.dmgtime = 0;
50                         }
51
52                         if(!vehic && !projectile && !monster) // vehicles, monsters and projectiles don't drown
53                         {
54                                 if (self.waterlevel != WATERLEVEL_SUBMERGED)
55                                 {
56                                         if(self.air_finished < time)
57                                                 PlayerSound(playersound_gasp, CH_PLAYER, VOICETYPE_PLAYERSOUND);
58                                         self.air_finished = time + autocvar_g_balance_contents_drowndelay;
59                                         self.dmg = 2;
60                                 }
61                                 else if (self.air_finished < time)
62                                 {       // drown!
63                                         if (!self.deadflag)
64                                         if (self.pain_finished < time)
65                                         {
66                                                 Damage (self, world, world, autocvar_g_balance_contents_playerdamage_drowning * autocvar_g_balance_contents_damagerate, DEATH_DROWN.m_id, self.origin, '0 0 0');
67                                                 self.pain_finished = time + 0.5;
68                                         }
69                                 }
70                         }
71
72                         if (self.dmgtime < time)
73                         {
74                                 self.dmgtime = time + autocvar_g_balance_contents_damagerate;
75
76                                 if (projectile)
77                                 {
78                                         if (self.watertype == CONTENT_LAVA)
79                                         {
80                                                 Damage (self, world, world, autocvar_g_balance_contents_projectiledamage * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_LAVA.m_id, self.origin, '0 0 0');
81                                         }
82                                         else if (self.watertype == CONTENT_SLIME)
83                                         {
84                                                 Damage (self, world, world, autocvar_g_balance_contents_projectiledamage * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_SLIME.m_id, self.origin, '0 0 0');
85                                         }
86                                 }
87                                 else
88                                 {
89                                         if (self.watertype == CONTENT_LAVA)
90                                         {
91                                                 if (self.watersound_finished < time)
92                                                 {
93                                                         self.watersound_finished = time + 0.5;
94                                                         sound (self, CH_PLAYER_SINGLE, SND_LAVA, VOL_BASE, ATTEN_NORM);
95                                                 }
96                                                 Damage (self, world, world, autocvar_g_balance_contents_playerdamage_lava * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_LAVA.m_id, self.origin, '0 0 0');
97                                                 if(autocvar_g_balance_contents_playerdamage_lava_burn)
98                                                         Fire_AddDamage(self, world, autocvar_g_balance_contents_playerdamage_lava_burn * self.waterlevel, autocvar_g_balance_contents_playerdamage_lava_burn_time * self.waterlevel, DEATH_LAVA.m_id);
99                                         }
100                                         else if (self.watertype == CONTENT_SLIME)
101                                         {
102                                                 if (self.watersound_finished < time)
103                                                 {
104                                                         self.watersound_finished = time + 0.5;
105                                                         sound (self, CH_PLAYER_SINGLE, SND_SLIME, VOL_BASE, ATTEN_NORM);
106                                                 }
107                                                 Damage (self, world, world, autocvar_g_balance_contents_playerdamage_slime * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_SLIME.m_id, self.origin, '0 0 0');
108                                         }
109                                 }
110                         }
111                 }
112                 else
113                 {
114                         if (self.flags & FL_INWATER)
115                         {
116                                 // play leave water sound
117                                 self.flags &= ~FL_INWATER;
118                                 self.dmgtime = 0;
119                         }
120                         self.air_finished = time + 12;
121                         self.dmg = 2;
122                 }
123
124                 if(!vehic && !projectile) // vehicles don't get falling damage
125                 {
126                         // check for falling damage
127                         float velocity_len = vlen(self.velocity);
128                         if(!self.hook.state)
129                         {
130                                 dm = vlen(self.oldvelocity) - velocity_len; // dm is now the velocity DECREASE. Velocity INCREASE should never cause a sound or any damage.
131                                 if (self.deadflag)
132                                         dm = (dm - autocvar_g_balance_falldamage_deadminspeed) * autocvar_g_balance_falldamage_factor;
133                                 else
134                                         dm = min((dm - autocvar_g_balance_falldamage_minspeed) * autocvar_g_balance_falldamage_factor, autocvar_g_balance_falldamage_maxdamage);
135                                 if (dm > 0)
136                                         Damage (self, world, world, dm, DEATH_FALL.m_id, self.origin, '0 0 0');
137                         }
138
139                         if(autocvar_g_maxspeed > 0 && velocity_len > autocvar_g_maxspeed)
140                                 Damage (self, world, world, 100000, DEATH_SHOOTING_STAR.m_id, self.origin, '0 0 0');
141                         // play stupid sounds
142                         if (g_footsteps)
143                         if (!gameover)
144                         if (self.flags & FL_ONGROUND)
145                         if (!self.crouch)
146                         if (velocity_len > autocvar_sv_maxspeed * 0.6)
147                         if (!self.deadflag)
148                         if (time < self.lastground + 0.2)
149                         {
150                                 if((time > self.nextstep) || (time < (self.nextstep - 10.0)))
151                                 {
152                                         self.nextstep = time + 0.3 + random() * 0.1;
153                                         trace_dphitq3surfaceflags = 0;
154                                         tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
155                                         /*
156                                         if(trace_fraction == 1)
157                                                 dprint("nohit\n");
158                                         else
159                                                 dprint(ftos(trace_dphitq3surfaceflags), "\n");
160                                         */
161                                         if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS))
162                                         {
163                                                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
164                                                         GlobalSound(GS_STEP_METAL, CH_PLAYER, VOICETYPE_PLAYERSOUND);
165                                                 else
166                                                         GlobalSound(GS_STEP, CH_PLAYER, VOICETYPE_PLAYERSOUND);
167                                         }
168                                 }
169                         }
170                 }
171
172         self.oldvelocity = self.velocity;
173         }
174         setself(this);
175 }
176
177
178 /*
179 =============
180 StartFrame
181
182 Called before each frame by the server
183 =============
184 */
185
186 float game_delay;
187 float game_delay_last;
188
189 float RedirectionThink();
190 void StartFrame()
191 {
192         SELFPARAM();
193         execute_next_frame();
194
195         remove = remove_unsafely; // not during spawning!
196         serverprevtime = servertime;
197         servertime = time;
198         serverframetime = frametime;
199
200 #ifdef PROFILING
201         if(time > client_cefc_accumulatortime + 1)
202         {
203                 float t = client_cefc_accumulator / (time - client_cefc_accumulatortime);
204                 LOG_INFO("CEFC time: ", ftos(t * 1000), "ms; ");
205                 int c_seeing = 0;
206                 int c_seen = 0;
207                 entity cl;
208                 FOR_EACH_CLIENT(cl)
209                 {
210                         if(IS_REAL_CLIENT(cl))
211                                 ++c_seeing;
212                         if(IS_PLAYER(cl))
213                                 ++c_seen;
214                 }
215                 LOG_INFO("CEFC calls per second: ", ftos(c_seeing * (c_seen - 1) / t), "; ");
216                 LOG_INFO("CEFC 100% load at: ", ftos(solve_quadratic(t, -t, -1) * '0 1 0'), "\n");
217
218                 client_cefc_accumulatortime = time;
219                 client_cefc_accumulator = 0;
220         }
221 #endif
222
223         for(entity e = world; (e = findfloat(e, csqcprojectile_clientanimate, 1)); )
224                 CSQCProjectile_Check(e);
225
226         if(RedirectionThink())
227                 return;
228
229         UncustomizeEntitiesRun();
230         InitializeEntitiesRun();
231
232         WarpZone_StartFrame();
233
234         sys_frametime = autocvar_sys_ticrate * autocvar_slowmo;
235         if(sys_frametime <= 0)
236                 sys_frametime = 1.0 / 60.0; // somewhat safe fallback
237
238         if (timeout_status == TIMEOUT_LEADTIME) // just before the timeout (when timeout_status will be TIMEOUT_ACTIVE)
239                 orig_slowmo = autocvar_slowmo; // slowmo will be restored after the timeout
240
241         skill = autocvar_skill;
242
243         // detect when the pre-game countdown (if any) has ended and the game has started
244         game_delay = (time < game_starttime);
245
246         if(autocvar_sv_eventlog && game_delay_last && !game_delay)
247                 GameLogEcho(":startdelay_ended");
248
249         game_delay_last = game_delay;
250
251         CreatureFrame();
252         CheckRules_World();
253
254         // if in warmup stage and limit for warmup is hit start match
255         if(warmup_stage)
256         if(!gameover)
257         if((g_warmup_limit > 0 && time >= g_warmup_limit)
258          || (g_warmup_limit == 0 && autocvar_timelimit != 0 && time >= autocvar_timelimit * 60))
259         {
260                 ReadyRestart();
261                 return;
262         }
263
264         bot_serverframe();
265         anticheat_startframe();
266         MUTATOR_CALLHOOK(SV_StartFrame);
267 }
268
269 .vector originjitter;
270 .vector anglesjitter;
271 .float anglejitter;
272 .string gametypefilter;
273 .string cvarfilter;
274 float DoesQ3ARemoveThisEntity();
275 void SV_OnEntityPreSpawnFunction()
276 {SELFPARAM();
277         if (self)
278         if (self.gametypefilter != "")
279         if (!isGametypeInFilter(MapInfo_LoadedGametype, teamplay, have_team_spawns, self.gametypefilter))
280         {
281                 remove(self);
282                 return;
283         }
284         if(self.cvarfilter != "")
285         {
286                 float n, i, o, inv;
287                 string s, k, v;
288                 inv = 0;
289
290                 s = self.cvarfilter;
291                 if(substring(s, 0, 1) == "+")
292                 {
293                         s = substring(s, 1, -1);
294                 }
295                 else if(substring(s, 0, 1) == "-")
296                 {
297                         inv = 1;
298                         s = substring(s, 1, -1);
299                 }
300
301                 n = tokenize_console(s);
302                 for(i = 0; i < n; ++i)
303                 {
304                         s = argv(i);
305                         // syntax:
306                         // var>x
307                         // var<x
308                         // var>=x
309                         // var<=x
310                         // var==x
311                         // var!=x
312                         // var===x
313                         // var!==x
314                         if((o = strstrofs(s, ">=", 0)) >= 0)
315                         {
316                                 k = substring(s, 0, o);
317                                 v = substring(s, o+2, -1);
318                                 if(cvar(k) < stof(v))
319                                         goto cvar_fail;
320                         }
321                         else if((o = strstrofs(s, "<=", 0)) >= 0)
322                         {
323                                 k = substring(s, 0, o);
324                                 v = substring(s, o+2, -1);
325                                 if(cvar(k) > stof(v))
326                                         goto cvar_fail;
327                         }
328                         else if((o = strstrofs(s, ">", 0)) >= 0)
329                         {
330                                 k = substring(s, 0, o);
331                                 v = substring(s, o+1, -1);
332                                 if(cvar(k) <= stof(v))
333                                         goto cvar_fail;
334                         }
335                         else if((o = strstrofs(s, "<", 0)) >= 0)
336                         {
337                                 k = substring(s, 0, o);
338                                 v = substring(s, o+1, -1);
339                                 if(cvar(k) >= stof(v))
340                                         goto cvar_fail;
341                         }
342                         else if((o = strstrofs(s, "==", 0)) >= 0)
343                         {
344                                 k = substring(s, 0, o);
345                                 v = substring(s, o+2, -1);
346                                 if(cvar(k) != stof(v))
347                                         goto cvar_fail;
348                         }
349                         else if((o = strstrofs(s, "!=", 0)) >= 0)
350                         {
351                                 k = substring(s, 0, o);
352                                 v = substring(s, o+2, -1);
353                                 if(cvar(k) == stof(v))
354                                         goto cvar_fail;
355                         }
356                         else if((o = strstrofs(s, "===", 0)) >= 0)
357                         {
358                                 k = substring(s, 0, o);
359                                 v = substring(s, o+2, -1);
360                                 if(cvar_string(k) != v)
361                                         goto cvar_fail;
362                         }
363                         else if((o = strstrofs(s, "!==", 0)) >= 0)
364                         {
365                                 k = substring(s, 0, o);
366                                 v = substring(s, o+2, -1);
367                                 if(cvar_string(k) == v)
368                                         goto cvar_fail;
369                         }
370                         else if(substring(s, 0, 1) == "!")
371                         {
372                                 k = substring(s, 1, -1);
373                                 if(cvar(k))
374                                         goto cvar_fail;
375                         }
376                         else
377                         {
378                                 k = s;
379                                 if (!cvar(k))
380                                         goto cvar_fail;
381                         }
382                 }
383                 inv = !inv;
384 :cvar_fail
385                 // now inv is 1 if we want to keep the item, and 0 if we want to get rid of it
386                 if (!inv)
387                 {
388                         //print("cvarfilter fail\n");
389                         remove(self);
390                         return;
391                 }
392         }
393
394         if(DoesQ3ARemoveThisEntity())
395         {
396                 remove(self);
397                 return;
398         }
399
400         // support special -1 and -2 angle from radiant
401         if (self.angles == '0 -1 0')
402                 self.angles = '-90 0 0';
403         else if (self.angles == '0 -2 0')
404                 self.angles = '+90 0 0';
405
406         if(self.originjitter.x != 0)
407                 self.origin_x = self.origin.x + (random() * 2 - 1) * self.originjitter.x;
408         if(self.originjitter.y != 0)
409                 self.origin_y = self.origin.y + (random() * 2 - 1) * self.originjitter.y;
410         if(self.originjitter.z != 0)
411                 self.origin_z = self.origin.z + (random() * 2 - 1) * self.originjitter.z;
412         if(self.anglesjitter.x != 0)
413                 self.angles_x = self.angles.x + (random() * 2 - 1) * self.anglesjitter.x;
414         if(self.anglesjitter.y != 0)
415                 self.angles_y = self.angles.y + (random() * 2 - 1) * self.anglesjitter.y;
416         if(self.anglesjitter.z != 0)
417                 self.angles_z = self.angles.z + (random() * 2 - 1) * self.anglesjitter.z;
418         if(self.anglejitter != 0)
419                 self.angles_y = self.angles.y + (random() * 2 - 1) * self.anglejitter;
420
421         if(MUTATOR_CALLHOOK(OnEntityPreSpawn))
422         {
423                 remove(self);
424                 return;
425         }
426 }
427
428 void WarpZone_PostInitialize_Callback()
429 {
430         // create waypoint links for warpzones
431         entity e;
432         for(e = world; (e = find(e, classname, "trigger_warpzone")); )
433         {
434                 vector src, dst;
435                 src = (e.absmin + e.absmax) * 0.5;
436                 makevectors(e.warpzone_angles);
437                 src = src + ((e.warpzone_origin - src) * v_forward) * v_forward + 16 * v_right;
438                 dst = (e.enemy.absmin + e.enemy.absmax) * 0.5;
439                 makevectors(e.enemy.warpzone_angles);
440                 dst = dst + ((e.enemy.warpzone_origin - dst) * v_forward) * v_forward - 16 * v_right;
441                 waypoint_spawnforteleporter_v(e, src, dst, 0);
442         }
443 }