]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/sv_main.qc
Update Luma simple items. Minor color changes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / sv_main.qc
1 void CreatureFrame (void)
2 {
3         entity oldself;
4         float dm;
5
6         oldself = self;
7         for(self = world; (self = findfloat(self, damagedbycontents, TRUE)); )
8         {
9                 if (self.movetype == MOVETYPE_NOCLIP) { continue; }
10
11                 float vehic = (self.vehicle_flags & VHF_ISVEHICLE);
12                 float projectile = (self.flags & FL_PROJECTILE);
13                 float monster = (self.flags & FL_MONSTER);
14
15                 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)
16                 {
17                         if (!(self.flags & FL_INWATER))
18                         {
19                                 self.flags |= FL_INWATER;
20                                 self.dmgtime = 0;
21                         }
22
23                         if(!vehic && !projectile && !monster) // vehicles, monsters and projectiles don't drown
24                         {
25                                 if (self.waterlevel != WATERLEVEL_SUBMERGED)
26                                 {
27                                         if(self.air_finished < time)
28                                                 PlayerSound(playersound_gasp, CH_PLAYER, VOICETYPE_PLAYERSOUND);
29                                         self.air_finished = time + autocvar_g_balance_contents_drowndelay;
30                                         self.dmg = 2;
31                                 }
32                                 else if (self.air_finished < time)
33                                 {       // drown!
34                                         if (!self.deadflag)
35                                         if (self.pain_finished < time)
36                                         {
37                                                 Damage (self, world, world, autocvar_g_balance_contents_playerdamage_drowning * autocvar_g_balance_contents_damagerate, DEATH_DROWN, self.origin, '0 0 0');
38                                                 self.pain_finished = time + 0.5;
39                                         }
40                                 }
41                         }
42
43                         if (self.dmgtime < time)
44                         {
45                                 self.dmgtime = time + autocvar_g_balance_contents_damagerate;
46
47                                 if (projectile)
48                                 {
49                                         if (self.watertype == CONTENT_LAVA)
50                                         {
51                                                 Damage (self, world, world, autocvar_g_balance_contents_projectiledamage * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_LAVA, self.origin, '0 0 0');
52                                         }
53                                         else if (self.watertype == CONTENT_SLIME)
54                                         {
55                                                 Damage (self, world, world, autocvar_g_balance_contents_projectiledamage * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_SLIME, self.origin, '0 0 0');
56                                         }
57                                 }
58                                 else
59                                 {
60                                         if (self.watertype == CONTENT_LAVA)
61                                         {
62                                                 if (self.watersound_finished < time)
63                                                 {
64                                                         self.watersound_finished = time + 0.5;
65                                                         sound (self, CH_PLAYER, "player/lava.wav", VOL_BASE, ATTEN_NORM);
66                                                 }
67                                                 Damage (self, world, world, autocvar_g_balance_contents_playerdamage_lava * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_LAVA, self.origin, '0 0 0');
68                                         }
69                                         else if (self.watertype == CONTENT_SLIME)
70                                         {
71                                                 if (self.watersound_finished < time)
72                                                 {
73                                                         self.watersound_finished = time + 0.5;
74                                                         sound (self, CH_PLAYER, "player/slime.wav", VOL_BASE, ATTEN_NORM);
75                                                 }
76                                                 Damage (self, world, world, autocvar_g_balance_contents_playerdamage_slime * autocvar_g_balance_contents_damagerate * self.waterlevel, DEATH_SLIME, self.origin, '0 0 0');
77                                         }
78                                 }
79                         }
80                 }
81                 else
82                 {
83                         if (self.flags & FL_INWATER)
84                         {
85                                 // play leave water sound
86                                 self.flags &= ~FL_INWATER;
87                                 self.dmgtime = 0;
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_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 (!(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 float RedirectionThink();
158 entity SelectSpawnPoint (float anypoint);
159 void StartFrame (void)
160 {
161         execute_next_frame();
162
163         remove = remove_unsafely; // not during spawning!
164         serverprevtime = servertime;
165         servertime = time;
166         serverframetime = frametime;
167
168 #ifdef PROFILING
169         if(time > client_cefc_accumulatortime + 1)
170         {
171                 float t, pp, c_seeing, c_seen;
172                 entity cl;
173                 t = client_cefc_accumulator / (time - client_cefc_accumulatortime);
174                 print("CEFC time: ", ftos(t * 1000), "ms; ");
175                 c_seeing = 0;
176                 c_seen = 0;
177                 FOR_EACH_CLIENT(cl)
178                 {
179                         if(IS_REAL_CLIENT(cl))
180                                 ++c_seeing;
181                         if(IS_PLAYER(cl))
182                                 ++c_seen;
183                 }
184                 print("CEFC calls per second: ", ftos(c_seeing * (c_seen - 1) / t), "; ");
185                 print("CEFC 100% load at: ", ftos(solve_quadratic(t, -t, -1) * '0 1 0'), "\n");
186
187                 client_cefc_accumulatortime = time;
188                 client_cefc_accumulator = 0;
189         }
190 #endif
191
192         entity e;
193         for(e = world; (e = findfloat(e, csqcprojectile_clientanimate, 1)); )
194                 CSQCProjectile_Check(e);
195
196         if(RedirectionThink())
197                 return;
198
199         UncustomizeEntitiesRun();
200         InitializeEntitiesRun();
201
202         WarpZone_StartFrame();
203
204         sys_frametime = autocvar_sys_ticrate * autocvar_slowmo;
205         if(sys_frametime <= 0)
206                 sys_frametime = 1.0 / 60.0; // somewhat safe fallback
207
208         if (timeout_status == TIMEOUT_LEADTIME) // just before the timeout (when timeout_status will be TIMEOUT_ACTIVE)
209                 orig_slowmo = autocvar_slowmo; // slowmo will be restored after the timeout
210
211         skill = autocvar_skill;
212
213         // detect when the pre-game countdown (if any) has ended and the game has started
214         game_delay = (time < game_starttime) ? TRUE : FALSE;
215
216         if(game_delay_last == TRUE)
217         if(game_delay == FALSE)
218         if(autocvar_sv_eventlog)
219                 GameLogEcho(":startdelay_ended");
220
221         game_delay_last = game_delay;
222
223         CreatureFrame ();
224         CheckRules_World ();
225
226         // if in warmup stage and limit for warmup is hit start match
227         if(warmup_stage)
228         if(!gameover)
229         if((g_warmup_limit > 0 && time >= g_warmup_limit)
230          || (g_warmup_limit == 0 && autocvar_timelimit != 0 && time >= autocvar_timelimit * 60))
231         {
232                 ReadyRestart();
233                 return;
234         }
235
236         bot_serverframe();
237
238         FOR_EACH_PLAYER(self)
239                 self.porto_forbidden = max(0, self.porto_forbidden - 1);
240
241         MUTATOR_CALLHOOK(SV_StartFrame);
242 }
243
244 .vector originjitter;
245 .vector anglesjitter;
246 .float anglejitter;
247 .string gametypefilter;
248 .string cvarfilter;
249 float DoesQ3ARemoveThisEntity();
250 void SV_OnEntityPreSpawnFunction()
251 {
252         if (self)
253         if (self.gametypefilter != "")
254         if (!isGametypeInFilter(MapInfo_LoadedGametype, teamplay, have_team_spawns, self.gametypefilter))
255         {
256                 remove(self);
257                 return;
258         }
259         if(self.cvarfilter != "")
260         {
261                 float n, i, o, inv;
262                 string s, k, v;
263                 inv = 0;
264
265                 s = self.cvarfilter;
266                 if(substring(s, 0, 1) == "+")
267                 {
268                         s = substring(s, 1, -1);
269                 }
270                 else if(substring(s, 0, 1) == "-")
271                 {
272                         inv = 1;
273                         s = substring(s, 1, -1);
274                 }
275
276                 n = tokenize_console(s);
277                 for(i = 0; i < n; ++i)
278                 {
279                         s = argv(i);
280                         // syntax:
281                         // var>x
282                         // var<x
283                         // var>=x
284                         // var<=x
285                         // var==x
286                         // var!=x
287                         // var===x
288                         // var!==x
289                         if((o = strstrofs(s, ">=", 0)) >= 0)
290                         {
291                                 k = substring(s, 0, o);
292                                 v = substring(s, o+2, -1);
293                                 if(cvar(k) < stof(v))
294                                         goto cvar_fail;
295                         }
296                         else 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+1, -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+2, -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_string(k) != 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(substring(s, 0, 1) == "!")
346                         {
347                                 k = substring(s, 1, -1);
348                                 if(cvar(k))
349                                         goto cvar_fail;
350                         }
351                         else
352                         {
353                                 k = s;
354                                 if (!cvar(k))
355                                         goto cvar_fail;
356                         }
357                 }
358                 inv = !inv;
359 :cvar_fail
360                 // now inv is 1 if we want to keep the item, and 0 if we want to get rid of it
361                 if (!inv)
362                 {
363                         //print("cvarfilter fail\n");
364                         remove(self);
365                         return;
366                 }
367         }
368
369         if(DoesQ3ARemoveThisEntity())
370         {
371                 remove(self);
372                 return;
373         }
374
375         // support special -1 and -2 angle from radiant
376         if (self.angles == '0 -1 0')
377                 self.angles = '-90 0 0';
378         else if (self.angles == '0 -2 0')
379                 self.angles = '+90 0 0';
380
381         if(self.originjitter_x != 0)
382                 self.origin_x = self.origin_x + (random() * 2 - 1) * self.originjitter_x;
383         if(self.originjitter_y != 0)
384                 self.origin_y = self.origin_y + (random() * 2 - 1) * self.originjitter_y;
385         if(self.originjitter_z != 0)
386                 self.origin_z = self.origin_z + (random() * 2 - 1) * self.originjitter_z;
387         if(self.anglesjitter_x != 0)
388                 self.angles_x = self.angles_x + (random() * 2 - 1) * self.anglesjitter_x;
389         if(self.anglesjitter_y != 0)
390                 self.angles_y = self.angles_y + (random() * 2 - 1) * self.anglesjitter_y;
391         if(self.anglesjitter_z != 0)
392                 self.angles_z = self.angles_z + (random() * 2 - 1) * self.anglesjitter_z;
393         if(self.anglejitter != 0)
394                 self.angles_y = self.angles_y + (random() * 2 - 1) * self.anglejitter;
395
396         if(MUTATOR_CALLHOOK(OnEntityPreSpawn))
397         {
398                 remove(self);
399                 return;
400         }
401 }
402
403 void WarpZone_PostInitialize_Callback(void)
404 {
405         // create waypoint links for warpzones
406         entity e;
407         for(e = world; (e = find(e, classname, "trigger_warpzone")); )
408         {
409                 vector src, dst;
410                 src = (e.absmin + e.absmax) * 0.5;
411                 makevectors(e.warpzone_angles);
412                 src = src + ((e.warpzone_origin - src) * v_forward) * v_forward + 16 * v_right;
413                 dst = (e.enemy.absmin + e.enemy.absmax) * 0.5;
414                 makevectors(e.enemy.warpzone_angles);
415                 dst = dst + ((e.enemy.warpzone_origin - dst) * v_forward) * v_forward - 16 * v_right;
416                 waypoint_spawnforteleporter_v(e, src, dst, 0);
417         }
418 }