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