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