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