Scaled the weapon models down about 30% to match 2.5.2 sizes. Except the tuba, I...
[divverent/nexuiz.git] / data / qcsrc / server / sv_main.qc
1
2 void CreatureFrame (void)
3 {
4         local entity oldself;
5         local float dm;
6         oldself = self;
7         self = findfloat(world, iscreature, TRUE);
8         while (self)
9         {
10                 if (self.movetype != MOVETYPE_NOCLIP)
11                 {
12                         if (self.waterlevel)
13                         {
14                                 if (!(self.flags & FL_INWATER))
15                                 {
16                                         self.flags |= FL_INWATER;
17                                         self.dmgtime = 0;
18                                 }
19                                 if (self.waterlevel != WATERLEVEL_SUBMERGED)
20                                 {
21                                         if(self.air_finished < time + 9)
22                                                 PlayerSound(playersound_gasp, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
23                                         self.air_finished = time + 12;
24                                         self.dmg = 2;
25                                 }
26                                 else if (self.air_finished < time)
27                                 {       // drown!
28                                         if (!self.deadflag)
29                                         if (self.pain_finished < time)
30                                         {
31                                                 Damage (self, world, world, 5, DEATH_DROWN, self.origin, '0 0 0');
32                                                 self.pain_finished = time + 0.5;
33                                         }
34                                 }
35                                 if (self.dmgtime < time)
36                                 {
37                                         self.dmgtime = time + 0.1;
38                                         if (self.watertype == CONTENT_LAVA)
39                                         {
40                                                 if (self.watersound_finished < time)
41                                                 {
42                                                         self.watersound_finished = time + 0.5;
43                                                         sound (self, CHAN_PLAYER, "player/lava.wav", VOL_BASE, ATTN_NORM);
44                                                 }
45                                                 Damage (self, world, world, 6 * self.waterlevel, DEATH_LAVA, self.origin, '0 0 0');
46                                         }
47                                         else if (self.watertype == CONTENT_SLIME)
48                                         {
49                                                 if (self.watersound_finished < time)
50                                                 {
51                                                         self.watersound_finished = time + 0.5;
52                                                         sound (self, CHAN_PLAYER, "player/slime.wav", VOL_BASE, ATTN_NORM);
53                                                 }
54                                                 Damage (self, world, world, 2 * self.waterlevel, DEATH_SLIME, self.origin, '0 0 0');
55                                         }
56                                 }
57                         }
58                         else
59                         {
60                                 if (self.flags & FL_INWATER)
61                                 {
62                                         // play leave water sound
63                                         self.flags &~= FL_INWATER;
64                                         self.dmgtime = 0;
65                                 }
66                                 self.air_finished = time + 12;
67                                 self.dmg = 2;
68                         }
69                         // check for falling damage
70                         if(!self.hook.state && !g_ca && !(g_cts && !cvar("g_cts_selfdamage")))
71                         {
72                                 dm = vlen(self.oldvelocity) - vlen(self.velocity); // dm is now the velocity DECREASE. Velocity INCREASE should never cause a sound or any damage.
73                                 if (self.deadflag)
74                                         dm = (dm - cvar("g_balance_falldamage_deadminspeed")) * cvar("g_balance_falldamage_factor");
75                                 else
76                                         dm = min((dm - cvar("g_balance_falldamage_minspeed")) * cvar("g_balance_falldamage_factor"), cvar("g_balance_falldamage_maxdamage"));
77                                 if (dm > 0)
78                                 {
79                                         Damage (self, world, world, dm, DEATH_FALL, self.origin, '0 0 0');
80                                 }
81                                 else if(vlen(self.velocity) > 100000 && cvar("developer"))
82                                 {
83                                         dprint(strcat(self.netname, " became too fast, please investigate: ", vtos(self.spawnorigin), "\n"));
84                                         Damage (self, world, world, 50000, DEATH_SHOOTING_STAR, self.origin, '0 0 0');
85                                 }
86                         }
87
88                         // play stupid sounds
89                         if (g_footsteps)
90                         if (!gameover)
91                         if (self.flags & FL_ONGROUND)
92                         if (vlen(self.velocity) > sv_maxspeed * 0.6)
93                         if (!self.deadflag)
94                         if (time < self.lastground + 0.2)
95                         {
96                                 if((time > self.nextstep) || (time < (self.nextstep - 10.0)))
97                                 {
98                                         self.nextstep = time + 0.3 + random() * 0.1;
99                                         trace_dphitq3surfaceflags = 0;
100                                         tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
101                                         /*
102                                         if(trace_fraction == 1)
103                                                 dprint("nohit\n");
104                                         else
105                                                 dprint(ftos(trace_dphitq3surfaceflags), "\n");
106                                         */
107                                         if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
108                                         {
109                                                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
110                                                         GlobalSound(globalsound_metalstep, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
111                                                 else
112                                                         GlobalSound(globalsound_step, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
113                                         }
114                                 }
115                         }
116                         self.oldvelocity = self.velocity;
117                 }
118                 self = findfloat(self, iscreature, TRUE);
119         }
120         self = oldself;
121 }
122
123
124 /*
125 =============
126 StartFrame
127
128 Called before each frame by the server
129 =============
130 */
131
132 float game_delay;
133 float game_delay_last;
134
135 void RuneMatchGivePoints();
136 float RedirectionThink();
137 entity SelectSpawnPoint (float anypoint);
138 void StartFrame (void)
139 {
140         remove = remove_unsafely; // not during spawning!
141         serverprevtime = servertime;
142         servertime = time;
143         serverframetime = frametime;
144
145 #ifdef PROFILING
146         if(time > client_cefc_accumulatortime + 1)
147         {
148                 float t, pp, c_seeing, c_seen;
149                 entity cl;
150                 t = client_cefc_accumulator / (time - client_cefc_accumulatortime);
151                 print("CEFC time: ", ftos(t * 1000), "ms; ");
152                 c_seeing = 0;
153                 c_seen = 0;
154                 FOR_EACH_CLIENT(cl)
155                 {
156                         if(clienttype(cl) == CLIENTTYPE_REAL)
157                                 ++c_seeing;
158                         if(cl.classname == "player")
159                                 ++c_seen;
160                 }
161                 print("CEFC calls per second: ", ftos(c_seeing * (c_seen - 1) / t), "; ");
162                 print("CEFC 100% load at: ", ftos(solve_quadratic(t, -t, -1) * '0 1 0'), "\n");
163
164                 client_cefc_accumulatortime = time;
165                 client_cefc_accumulator = 0;
166         }
167 #endif
168
169         entity e;
170         for(e = world; (e = findfloat(e, csqcprojectile_clientanimate, 1)); )
171                 CSQCProjectile_Check(e);
172
173         if(RedirectionThink())
174                 return;
175
176         UncustomizeEntitiesRun();
177         InitializeEntitiesRun();
178
179         WarpZone_StartFrame();
180
181         sv_gravity = cvar("sv_gravity");
182         sv_maxairspeed = cvar("sv_maxairspeed");
183         sv_maxspeed = cvar ("sv_maxspeed");
184         sv_friction = cvar ("sv_friction");
185         sv_accelerate = cvar ("sv_accelerate");
186         sv_airaccelerate = cvar("sv_airaccelerate");
187         sv_airaccel_sideways_friction = cvar("sv_airaccel_sideways_friction");
188         sv_airaccel_qw = cvar("sv_airaccel_qw");
189         sv_stopspeed = cvar ("sv_stopspeed");
190         sv_airstopaccelerate = cvar("sv_airstopaccelerate");
191         sv_airstrafeaccelerate = cvar("sv_airstrafeaccelerate");
192         sv_maxairstrafespeed = cvar("sv_maxairstrafespeed");
193         sv_aircontrol = cvar("sv_aircontrol");
194         sv_warsowbunny_airforwardaccel = cvar("sv_warsowbunny_airforwardaccel");
195         sv_warsowbunny_accel = cvar("sv_warsowbunny_accel");
196         sv_warsowbunny_topspeed = cvar("sv_warsowbunny_topspeed");
197         sv_warsowbunny_turnaccel = cvar("sv_warsowbunny_turnaccel");
198         sv_warsowbunny_backtosideratio = cvar("sv_warsowbunny_backtosideratio");
199         teamplay = cvar ("teamplay");
200         sys_frametime = cvar("sys_ticrate") * cvar("slowmo");
201
202         if (timeoutStatus == 1) // just before the timeout (when timeoutStatus will be 2)
203                 orig_slowmo = cvar("slowmo"); // slowmo will be restored after the timeout
204
205         if(teams_matter && !teamplay)
206                 teamplay = 3;
207         if(!teams_matter && teamplay)
208                 teamplay = 0;
209
210         skill = cvar("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(cvar("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 && cvar("timelimit") != 0 && time >= cvar("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(cvar("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 void SV_OnEntityPreSpawnFunction()
261 {
262         if(self.gametypefilter != "")
263         if not(isGametypeInFilter(game, teams_matter, self.gametypefilter))
264         {
265                 remove(self);
266                 return;
267         }
268         if(self.cvarfilter != "")
269         {
270                 float n, i, o, inv;
271                 string s, k, v;
272                 inv = 0;
273
274                 s = self.cvarfilter;
275                 if(substring(s, 0, 1) == "+")
276                 {
277                         s = substring(s, 1, -1);
278                 }
279                 else if(substring(s, 0, 1) == "-")
280                 {
281                         inv = 1;
282                         s = substring(s, 1, -1);
283                 }
284
285                 n = tokenize(s);
286                 for(i = 0; i < n; ++i)
287                 {
288                         s = argv(i);
289                         // syntax:
290                         // var>x
291                         // var<x
292                         // var>=x
293                         // var<=x
294                         // var==x
295                         // var!=x
296                         // var===x
297                         // var!==x
298                         if((o = strstrofs(s, ">=", 0)) >= 0)
299                         {
300                                 k = substring(s, 0, o);
301                                 v = substring(s, o+2, -1);
302                                 if(cvar(k) < stof(v))
303                                         goto cvar_fail;
304                         }
305                         else if((o = strstrofs(s, "<=", 0)) >= 0)
306                         {
307                                 k = substring(s, 0, o);
308                                 v = substring(s, o+2, -1);
309                                 if(cvar(k) > stof(v))
310                                         goto cvar_fail;
311                         }
312                         else if((o = strstrofs(s, ">", 0)) >= 0)
313                         {
314                                 k = substring(s, 0, o);
315                                 v = substring(s, o+1, -1);
316                                 if(cvar(k) <= stof(v))
317                                         goto cvar_fail;
318                         }
319                         else if((o = strstrofs(s, "<", 0)) >= 0)
320                         {
321                                 k = substring(s, 0, o);
322                                 v = substring(s, o+1, -1);
323                                 if(cvar(k) >= stof(v))
324                                         goto cvar_fail;
325                         }
326                         else if((o = strstrofs(s, "==", 0)) >= 0)
327                         {
328                                 k = substring(s, 0, o);
329                                 v = substring(s, o+2, -1);
330                                 if(cvar(k) != stof(v))
331                                         goto cvar_fail;
332                         }
333                         else if((o = strstrofs(s, "!=", 0)) >= 0)
334                         {
335                                 k = substring(s, 0, o);
336                                 v = substring(s, o+2, -1);
337                                 if(cvar(k) == stof(v))
338                                         goto cvar_fail;
339                         }
340                         else if((o = strstrofs(s, "===", 0)) >= 0)
341                         {
342                                 k = substring(s, 0, o);
343                                 v = substring(s, o+2, -1);
344                                 if(cvar_string(k) != v)
345                                         goto cvar_fail;
346                         }
347                         else if((o = strstrofs(s, "!==", 0)) >= 0)
348                         {
349                                 k = substring(s, 0, o);
350                                 v = substring(s, o+2, -1);
351                                 if(cvar_string(k) == v)
352                                         goto cvar_fail;
353                         }
354                         else if(substring(s, 0, 1) == "!")
355                         {
356                                 k = substring(s, 1, -1);
357                                 if(cvar(k))
358                                         goto cvar_fail;
359                         }
360                         else
361                         {
362                                 k = s;
363                                 if not(cvar(k))
364                                         goto cvar_fail;
365                         }
366                 }
367                 inv = !inv;
368 :cvar_fail
369                 // now inv is 1 if we want to keep the item, and 0 if we want to get rid of it
370                 if not(inv)
371                 {
372                         //print("cvarfilter fail\n");
373                         remove(self);
374                         return;
375                 }
376         }
377
378         // support special -1 and -2 angle from radiant
379         if (self.angles == '0 -1 0')
380                 self.angles = '-90 0 0';
381         else if (self.angles == '0 -2 0')
382                 self.angles = '+90 0 0';
383
384         if(self.originjitter_x != 0)
385                 self.origin_x = self.origin_x + (random() * 2 - 1) * self.originjitter_x;
386         if(self.originjitter_y != 0)
387                 self.origin_y = self.origin_y + (random() * 2 - 1) * self.originjitter_y;
388         if(self.originjitter_z != 0)
389                 self.origin_z = self.origin_z + (random() * 2 - 1) * self.originjitter_z;
390         if(self.anglesjitter_x != 0)
391                 self.angles_x = self.angles_x + (random() * 2 - 1) * self.anglesjitter_x;
392         if(self.anglesjitter_y != 0)
393                 self.angles_y = self.angles_y + (random() * 2 - 1) * self.anglesjitter_y;
394         if(self.anglesjitter_z != 0)
395                 self.angles_z = self.angles_z + (random() * 2 - 1) * self.anglesjitter_z;
396         if(self.anglejitter != 0)
397                 self.angles_y = self.angles_y + (random() * 2 - 1) * self.anglejitter;
398 }