]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamec/g_world.c
sv_logspam_console now enables a slightly modified format of sv_logscores_console...
[divverent/nexuiz.git] / data / qcsrc / server / gamec / g_world.c
1 string GetMapname();
2
3 void worldspawn (void)
4 {
5
6         // Precache all player models
7         // Workaround for "invisible players"
8         precache_model("models/player/carni.zym");
9         precache_model("models/player/crash.zym");
10         precache_model("models/player/grunt.zym");
11         precache_model("models/player/headhunter.zym");
12         precache_model("models/player/insurrectionist.zym");
13         precache_model("models/player/jeandarc.zym");
14         precache_model("models/player/lurk.zym");
15         precache_model("models/player/lycanthrope.zym");
16         precache_model("models/player/marine.zym");
17         precache_model("models/player/nexus.zym");
18         precache_model("models/player/pyria.zym");
19         precache_model("models/player/shock.zym");
20         precache_model("models/player/skadi.zym");
21         precache_model("models/player/specop.zym");
22         precache_model("models/player/visitant.zym");
23
24         //precache_model ("progs/beam.mdl");
25         precache_model ("models/bullet.mdl");
26         precache_model ("models/casing_bronze.mdl");
27         precache_model ("models/casing_shell.mdl");
28         precache_model ("models/casing_steel.mdl");
29         precache_model ("models/ebomb.mdl");
30         precache_model ("models/elaser.mdl");
31         precache_model ("models/flash.md3");
32         precache_model ("models/gibs/bloodyskull.md3");
33         precache_model ("models/gibs/chunk.mdl");
34         precache_model ("models/gibs/eye.md3");
35         precache_model ("models/gibs/gib1.md3");
36         //precache_model ("models/gibs/gib2.md3");
37         //precache_model ("models/gibs/gib3.md3");
38         //precache_model ("models/gibs/gib4.md3");
39         precache_model ("models/gibs/gib5.md3");
40         //precache_model ("models/gibs/gib6.md3");
41         precache_model ("models/gibs/gib1.mdl");
42         precache_model ("models/gibs/gib2.mdl");
43         precache_model ("models/gibs/gib3.mdl");
44         precache_model ("models/grenademodel.md3");
45         precache_model ("models/hagarmissile.mdl");
46         precache_model ("models/items/a_bullets.mdl");
47         precache_model ("models/items/a_cells.md3");
48         precache_model ("models/items/a_rockets.md3");
49         precache_model ("models/items/a_shells.md3");
50         precache_model ("models/items/g_a1.md3");
51         precache_model ("models/items/g_a25.md3");
52         precache_model ("models/items/g_h1.md3");
53         precache_model ("models/items/g_h25.md3");
54         precache_model ("models/items/g_h100.md3");
55         precache_model ("models/items/g_invincible.md3");
56         precache_model ("models/items/g_strength.md3");
57         precache_model ("models/laser.mdl");
58         precache_model ("models/misc/chatbubble.spr");
59         precache_model ("models/misc/teambubble.spr");
60         precache_model ("models/nexflash.md3");
61         precache_model ("models/plasma.mdl");
62         precache_model ("models/plasmatrail.mdl");
63         precache_model ("models/rocket.md3");
64         precache_model ("models/sprites/grenexpl.spr");
65         precache_model ("models/sprites/hagar.spr");
66         precache_model ("models/sprites/muzzleflash.spr32");
67         precache_model ("models/sprites/electrocombo.spr32");
68         //precache_model ("models/sprites/plasmahitwall.spr32");
69         //precache_model ("models/sprites/plasmashot.spr32");
70         precache_model ("models/sprites/rockexpl.spr");
71         precache_model ("models/tracer.mdl");
72         precache_model ("models/uziflash.md3");
73         precache_model ("models/weapons/g_crylink.md3");
74         precache_model ("models/weapons/g_electro.md3");
75         precache_model ("models/weapons/g_gl.md3");
76         precache_model ("models/weapons/g_hagar.md3");
77         precache_model ("models/weapons/g_nex.md3");
78         precache_model ("models/weapons/g_rl.md3");
79         precache_model ("models/weapons/g_shotgun.md3");
80         precache_model ("models/weapons/g_uzi.md3");
81         precache_model ("models/weapons/v_crylink.md3");
82         precache_model ("models/weapons/v_electro.md3");
83         precache_model ("models/weapons/v_gl.md3");
84         precache_model ("models/weapons/v_hagar.md3");
85         precache_model ("models/weapons/v_laser.md3");
86         precache_model ("models/weapons/v_nex.md3");
87         precache_model ("models/weapons/v_rl.md3");
88         precache_model ("models/weapons/v_shotgun.md3");
89         precache_model ("models/weapons/v_uzi.md3");
90         precache_model ("models/weapons/w_crylink.zym");
91         precache_model ("models/weapons/w_electro.zym");
92         precache_model ("models/weapons/w_gl.zym");
93         precache_model ("models/weapons/w_hagar.zym");
94         precache_model ("models/weapons/w_laser.zym");
95         precache_model ("models/weapons/w_nex.zym");
96         precache_model ("models/weapons/w_rl.zym");
97         precache_model ("models/weapons/w_shotgun.zym");
98         precache_model ("models/weapons/w_uzi.zym");
99
100         // laser for laser-guided weapons
101         precache_model ("models/laser_dot.mdl");
102
103         precache_sound ("misc/null.wav");
104         precache_sound ("misc/armor1.wav");
105         precache_sound ("misc/armor25.wav");
106         precache_sound ("misc/armorimpact.wav");
107         precache_sound ("misc/bodyimpact1.wav");
108         precache_sound ("misc/bodyimpact2.wav");
109         precache_sound ("misc/gib.wav");
110         precache_sound ("misc/gib_splat01.wav");
111         precache_sound ("misc/gib_splat02.wav");
112         precache_sound ("misc/gib_splat03.wav");
113         precache_sound ("misc/gib_splat04.wav");
114         //precache_sound ("misc/h2ohit.wav");
115         precache_sound ("misc/hit.wav");
116         precache_sound ("misc/footstep01.wav");
117         precache_sound ("misc/footstep02.wav");
118         precache_sound ("misc/footstep03.wav");
119         precache_sound ("misc/footstep04.wav");
120         precache_sound ("misc/footstep05.wav");
121         precache_sound ("misc/footstep06.wav");
122         precache_sound ("misc/hitground1.ogg");
123         precache_sound ("misc/hitground2.ogg");
124         precache_sound ("misc/hitground3.ogg");
125         precache_sound ("misc/hitground4.ogg");
126         precache_sound ("misc/itempickup.ogg");
127         precache_sound ("misc/itemrespawn.ogg");
128         precache_sound ("misc/jumppad.ogg");
129         precache_sound ("misc/mediumhealth.ogg");
130         precache_sound ("misc/megahealth.ogg");
131         precache_sound ("misc/minihealth.ogg");
132         precache_sound ("misc/powerup.ogg");
133         precache_sound ("misc/powerup_shield.ogg");
134         precache_sound ("misc/talk.wav");
135         precache_sound ("misc/teleport.ogg");
136         precache_sound ("plats/medplat1.wav");
137         precache_sound ("plats/medplat2.wav");
138         precache_sound ("player/lava.wav");
139         precache_sound ("player/slime.wav");
140         precache_sound ("weapons/crylink_fire.ogg");
141         precache_sound ("weapons/electro_bounce.ogg");
142         precache_sound ("weapons/electro_fire.ogg");
143         precache_sound ("weapons/electro_fire2.ogg");
144         precache_sound ("weapons/electro_fly.wav");
145         precache_sound ("weapons/electro_impact.ogg");
146         precache_sound ("weapons/electro_impact_combo.ogg");
147         //precache_sound ("weapons/grenade_bounce.ogg");
148         precache_sound ("weapons/grenade_bounce1.ogg");
149         precache_sound ("weapons/grenade_bounce2.ogg");
150         precache_sound ("weapons/grenade_bounce3.ogg");
151         precache_sound ("weapons/grenade_fire.ogg");
152         precache_sound ("weapons/grenade_impact.ogg");
153         precache_sound ("weapons/hagar_fire.ogg");
154         precache_sound ("weapons/hagexp1.ogg");
155         precache_sound ("weapons/hagexp2.ogg");
156         precache_sound ("weapons/hagexp3.ogg");
157         precache_sound ("weapons/hook_fire.ogg");
158         precache_sound ("weapons/hook_impact.ogg");
159         precache_sound ("weapons/lasergun_fire.ogg");
160         precache_sound ("weapons/laserimpact.ogg");
161         precache_sound ("weapons/nexfire.ogg");
162         precache_sound ("weapons/neximpact.ogg");
163         precache_sound ("weapons/ric1.ogg");
164         precache_sound ("weapons/ric2.ogg");
165         precache_sound ("weapons/ric3.ogg");
166         precache_sound ("weapons/rocket_fire.ogg");
167         precache_sound ("weapons/rocket_fly.wav");
168         precache_sound ("weapons/rocket_impact.ogg");
169         precache_sound ("weapons/rocket_det.ogg");
170         precache_sound ("weapons/shotgun_fire.ogg");
171         precache_sound ("weapons/tink1.ogg");
172         precache_sound ("weapons/uzi_fire.ogg");
173         precache_sound ("weapons/weapon_switch.ogg");
174         precache_sound ("weapons/weaponpickup.ogg");
175         precache_sound ("weapons/strength_fire.ogg");
176
177         //precache_sound ("announce/male/kill10.ogg");
178         //precache_sound ("announce/male/kill15.ogg");
179         //precache_sound ("announce/male/kill20.ogg");
180         //precache_sound ("announce/male/kill25.ogg");
181         //precache_sound ("announce/male/kill3.ogg");
182         //precache_sound ("announce/male/kill30.ogg");
183         //precache_sound ("announce/male/kill4.ogg");
184         //precache_sound ("announce/male/kill5.ogg");
185         //precache_sound ("announce/male/kill6.ogg");
186         //precache_sound ("announce/male/mapkill1.ogg");
187         //precache_sound ("announce/robotic/last_second_save.ogg");
188         //precache_sound ("announce/robotic/narrowly_averted.ogg");
189         //precache_sound ("minstagib/mockery.ogg");
190
191         // announcer sounds - male
192         precache_sound ("announcer/male/03kills.ogg");
193         precache_sound ("announcer/male/05kills.ogg");
194         precache_sound ("announcer/male/10kills.ogg");
195         precache_sound ("announcer/male/15kills.ogg");
196         precache_sound ("announcer/male/20kills.ogg");
197         precache_sound ("announcer/male/25kills.ogg");
198         precache_sound ("announcer/male/30kills.ogg");
199         precache_sound ("announcer/male/botlike.ogg");
200         precache_sound ("announcer/male/electrobitch.ogg");
201         precache_sound ("announcer/male/welcome.ogg");
202         precache_sound ("announcer/male/yoda.ogg");
203
204         // announcer sounds - robotic
205         precache_sound ("announcer/robotic/1fragleft.ogg");
206         precache_sound ("announcer/robotic/1minuteremains.ogg");
207         precache_sound ("announcer/robotic/2fragsleft.ogg");
208         precache_sound ("announcer/robotic/3fragsleft.ogg");
209         precache_sound ("announcer/robotic/lastsecond.ogg");
210         precache_sound ("announcer/robotic/narrowly.ogg");
211
212         // plays music for the level if there is any
213         if (self.noise)
214         {
215                 precache_sound (self.noise);
216                 ambientsound ('0 0 0', self.noise, 1.00, ATTN_NONE);
217         }
218
219                 // 0 normal
220         lightstyle(0, "m");
221
222         // 1 FLICKER (first variety)
223         lightstyle(1, "mmnmmommommnonmmonqnmmo");
224
225         // 2 SLOW STRONG PULSE
226         lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
227
228         // 3 CANDLE (first variety)
229         lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
230
231         // 4 FAST STROBE
232         lightstyle(4, "mamamamamama");
233
234         // 5 GENTLE PULSE 1
235         lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
236
237         // 6 FLICKER (second variety)
238         lightstyle(6, "nmonqnmomnmomomno");
239
240         // 7 CANDLE (second variety)
241         lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
242
243         // 8 CANDLE (third variety)
244         lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
245
246         // 9 SLOW STROBE (fourth variety)
247         lightstyle(9, "aaaaaaaazzzzzzzz");
248
249         // 10 FLUORESCENT FLICKER
250         lightstyle(10, "mmamammmmammamamaaamammma");
251
252         // 11 SLOW PULSE NOT FADE TO BLACK
253         lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
254
255         // styles 32-62 are assigned by the light program for switchable lights
256
257         // 63 testing
258         lightstyle(63, "a");
259
260         player_count = 0;
261         lms_dead_count = 0;
262         lms_lowest_lives = 0;
263
264         InitGameplayMode();
265         //if (cvar("g_domination"))
266         //      dom_init();
267
268         // Urrebot setting
269         urrebots_navopt = cvar("urrebots_navopt");
270
271         local entity head;
272         head = nextent(world);
273         maxclients = 0;
274         while(head)
275         {
276                 maxclients++;
277                 head = nextent(head);
278         }
279
280         if(cvar("sv_logspam_console"))
281                 ServerConsoleEcho(strcat(":gamestart:", GetMapname()), FALSE);
282
283         cvar_set("nextmap", "");
284 }
285
286 void light (void)
287 {
288         makestatic (self);
289 }
290
291 float( string pFilename ) TryFile =
292 {
293         local float lHandle;
294         dprint("TryFile(\"", pFilename, "\")\n");
295         lHandle = fopen( pFilename, FILE_READ );
296         if( lHandle != -1 ) {
297                 fclose( lHandle );
298                 return TRUE;
299         } else {
300                 return FALSE;
301         }
302 };
303
304 string GetMapname()
305 {
306         if (game == GAME_DEATHMATCH)
307                 return strcat("dm_", mapname);
308         else if (game == GAME_TEAM_DEATHMATCH)
309                 return strcat("tdm_", mapname);
310         else if (game == GAME_DOMINATION)
311                 return strcat("dom_", mapname);
312         else if (game == GAME_CTF)
313                 return strcat("ctf_", mapname);
314         else if (game == GAME_RUNEMATCH)
315                 return strcat("rune_", mapname);
316         else if (game == GAME_LMS)
317                 return strcat("lms_", mapname);
318         return strcat("dm_", mapname);
319 }
320
321 float GetMaplistPosition()
322 {
323         float pos, f;
324         string map, s;
325
326         map = strzone(GetMapname());
327         pos = 0;
328         f = tokenize(cvar_string("g_maplist"));
329
330         while(pos < f)
331         {
332                 s = strzone(argv(pos));
333                 if(s == map)
334                 {
335                         strunzone(s);
336                         strunzone(map);
337                         return pos;
338                 }
339                 strunzone(s);
340                 pos++;
341         }
342
343         strunzone(map);
344         // resume normal maplist rotation if current map is not in g_maplist
345         return cvar("g_maplist_index");          
346 }
347
348 void() GotoNextMap =
349 {
350         //local string nextmap;
351         //local float n, nummaps;
352         //local string s;
353         string exit_cfg;
354         if (alreadychangedlevel)
355                 return;
356         alreadychangedlevel = TRUE;
357         if (cvar("samelevel")) // if samelevel is set, stay on same level
358         {
359                 // this does not work because it tries to exec maps/nexdm01.mapcfg (which doesn't exist, it should be trying maps/dm_nexdm01.mapcfg for example)
360                 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
361                 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
362                 localcmd("restart\n");
363                 //changelevel (mapname);
364                 return;
365         }
366
367         // if an exit cfg is defined by exiting map, exec it.
368         exit_cfg = cvar_string("exit_cfg");
369         if(exit_cfg != "")
370                 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
371
372         ResetGameCvars();
373
374
375         if (cvar("lastlevel"))
376         {
377                 localcmd(strcat("set lastlevel 0\n"));
378                 localcmd(strcat("togglemenu\n"));
379         }
380         else
381         {
382                 // method 0
383                 local float lCurrent;
384                 local float lSize;
385                 local float lOldCurrent;
386                 local float pass;
387
388                 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
389                 {
390                         localcmd(strcat("exec \"maps/", cvar_string("nextmap"), ".mapcfg\"\n"));
391                         return;
392                 }
393
394                 pass = 0;
395                 while (pass < 2)
396                 {
397                         pass = pass + 1;
398                         local string temp;
399                         temp = cvar_string( "g_maplist" );
400                         if(temp == "")
401                         {
402                                 bprint( "Maplist is empty!  Resetting it to default map list.\n" );
403                                 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
404                                 temp = cvar_string( "g_maplist" );
405                         }
406                         temp = strzone(temp);
407                         dprint("g_maplist is ", temp, "\n");
408                         lCurrent = max(0, GetMaplistPosition());
409                         lSize = tokenize( temp );
410                         lOldCurrent = lCurrent;
411                         dprint(ftos(lOldCurrent), " / ", ftos(lSize), " (start)\n");
412                         while( 1 ) {
413                                 local string lFilename;
414
415                                 lCurrent = lCurrent + 1;
416                                 dprint(ftos(lCurrent), " / ", ftos(lSize), "\n");
417                                 if( lCurrent >= lSize ) {
418                                         lCurrent = 0;
419                                 }
420                                 if( lOldCurrent == lCurrent ) {
421                                         // we couldn't find a valid map at all
422                                         if (pass == 1)
423                                         {
424                                                 bprint( "Maplist is bad/messed up. Not one good mapcfg can be found in it!  Resetting it to default map list.\n" );
425                                                 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
426                                                 // let the loop restart with the default list now
427                                         }
428                                         else
429                                         {
430                                                 bprint( "Both g_maplist and g_maplist_defaultlist are messed up!  Complain to developers!\n" );
431                                                 localcmd( "disconnect\n" );
432                                         }
433                                         break;
434                                 }
435
436                                 cvar_set( "g_maplist_index", ftos( lCurrent ) );
437
438                                 lFilename = strcat( "maps/", argv( lCurrent ), ".mapcfg" );
439                                 if( TryFile( lFilename ) ) {
440                                         localcmd(strcat("exec \"", lFilename ,"\"\n"));
441                                         pass = 2; // exit the outer loop
442                                         break;
443                                 } else {
444                                         dprint( "Couldn't find '", lFilename, "'..\n" );
445                                 }
446                                 //changelevel( argv( lCurrent ) );
447                         }
448                         strunzone(temp);
449                 }
450
451                 /*
452                 // method 1
453
454                 //local entity pos;
455                 local float fh;
456                 local string line;
457
458                 // restart current map if no cycle is found
459                 nextmap = strzone(mapname);
460                 fh = fopen("maplist.cfg", FILE_READ);
461                 if (fh >= 0)
462                 {
463                         while (1)
464                         {
465                                 line = fgets(fh);
466                                 if (nextmap == mapname)
467                                 {
468                                         strunzone(nextmap);
469                                         nextmap = strzone(line);
470                                 }
471                                 if (!line)
472                                         break;
473                                 if (line == mapname)
474                                 {
475                                         line = fgets(fh);
476                                         if (!line)
477                                                 break;
478                                         strunzone(nextmap);
479                                         nextmap = strzone(line);
480                                         break;
481                                 }
482                         }
483                         fclose(fh);
484                 }
485                 changelevel (nextmap);
486                 strunzone(nextmap);*/
487
488                 // method 3
489                 /*
490                 s = cvar_string("g_maplist");
491                 nummaps = tokenize(s);
492                 // if no map list, restart current one
493                 nextmap = mapname;
494                 if (nummaps >= 1)
495                 {
496                         n = 0;
497                         while (n < nummaps)
498                         {
499                                 if (argv(n) == mapname)
500                                         break;
501                                 n = n + 1;
502                         }
503                         n = n + 1;
504                         if (n >= nummaps)
505                                 n = 0;
506                         nextmap = argv(n);
507                 }
508                 changelevel (nextmap);
509                 */
510         }
511 };
512
513
514 /*
515 ============
516 IntermissionThink
517
518 When the player presses attack or jump, change to the next level
519 ============
520 */
521 void() IntermissionThink =
522 {
523         if (time < intermission_exittime)
524                 return;
525
526         if (time < intermission_exittime + 10 && !self.button0 && !self.button1 && !self.button2 && !self.button3)
527                 return;
528
529         GotoNextMap ();
530 };
531
532 /*
533 ============
534 FindIntermission
535
536 Returns the entity to view from
537 ============
538 */
539 /*
540 entity() FindIntermission =
541 {
542         local   entity spot;
543         local   float cyc;
544
545 // look for info_intermission first
546         spot = find (world, classname, "info_intermission");
547         if (spot)
548         {       // pick a random one
549                 cyc = random() * 4;
550                 while (cyc > 1)
551                 {
552                         spot = find (spot, classname, "info_intermission");
553                         if (!spot)
554                                 spot = find (spot, classname, "info_intermission");
555                         cyc = cyc - 1;
556                 }
557                 return spot;
558         }
559
560 // then look for the start position
561         spot = find (world, classname, "info_player_start");
562         if (spot)
563                 return spot;
564
565 // testinfo_player_start is only found in regioned levels
566         spot = find (world, classname, "testplayerstart");
567         if (spot)
568                 return spot;
569
570 // then look for the start position
571         spot = find (world, classname, "info_player_deathmatch");
572         if (spot)
573                 return spot;
574
575         //objerror ("FindIntermission: no spot");
576         return world;
577 };
578 */
579
580 /*
581 ===============================================================================
582
583 RULES
584
585 ===============================================================================
586 */
587
588 void() DumpStats =
589 {
590         local float file;
591         local string s;
592
593         if(cvar("_printstats"))
594                 cvar_set("_printstats", "0");
595         else if(!gameover)
596                 return;
597
598         if(gameover)
599                 s = ":scores:";
600         else
601                 s = ":status:";
602
603         s = strcat(s, GetMapname(), ":", ftos(rint(time)));
604
605         if(cvar("sv_logscores_console") || cvar("sv_logspam_console"))
606                 ServerConsoleEcho(s, FALSE);
607         if(cvar("sv_logscores_file"))
608         {
609                 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
610                 fputs(file, strcat(s, "\n"));
611         }
612
613         other = findchain(classname, "player");
614         while (other)
615         {
616                 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
617                 {
618                         s = strcat(":player:", ftos(other.frags), ":");
619                         s = strcat(s, ftos(other.deaths), ":");
620                         s = strcat(s, ftos(rint(time - other.jointime)), ":");
621                         s = strcat(s, ftos(other.team), ":");
622
623                         if(cvar("sv_logscores_file"))
624                                 fputs(file, strcat(s, other.netname, "\n"));
625                         if(cvar("sv_logspam_console"))
626                                 ServerConsoleEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
627                         else if(cvar("sv_logscores_console"))
628                                 ServerConsoleEcho(strcat(s, other.netname), TRUE);
629                 }
630                 other = other.chain;
631         }
632
633         if(cvar("sv_logscores_console") || cvar("sv_logspam_console"))
634                 ServerConsoleEcho(":end", FALSE);
635         if(cvar("sv_logscores_file"))
636         {
637                 fputs(file, ":end\n");
638                 fclose(file);
639         }
640 }
641
642
643 /*
644 go to the next level for deathmatch
645 only called if a time or frag limit has expired
646 */
647 void() NextLevel =
648 {
649         gameover = TRUE;
650
651         intermission_running = 1;
652
653 // enforce a wait time before allowing changelevel
654         intermission_exittime = time + cvar("sv_mapchange_delay");
655
656         WriteByte (MSG_ALL, SVC_CDTRACK);
657         WriteByte (MSG_ALL, 3);
658         WriteByte (MSG_ALL, 3);
659
660         //pos = FindIntermission ();
661
662         VoteReset();
663
664         DumpStats();
665
666         if(cvar("sv_logspam_console"))
667                 ServerConsoleEcho(":gameover", FALSE);
668
669         other = findchainflags(flags, FL_CLIENT);
670         while (other != world)
671         {
672                 //other.nextthink = time + 0.5;
673                 other.takedamage = DAMAGE_NO;
674                 other.solid = SOLID_NOT;
675                 other.movetype = MOVETYPE_NONE;
676                 other.angles = other.v_angle;
677                 other.angles_x = other.angles_x * -1;
678
679                 self = other;
680                 weapon_action(other.weapon, WR_IDLE);
681
682                 if(clienttype(other) == CLIENTTYPE_REAL)
683                 if(cvar("sv_autoscreenshot"))
684                         stuffcmd(other, "screenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
685
686                 /*
687                 if (pos != world);
688                 {
689                         other.modelindex = 0;
690                         other.weaponentity = world; // remove weapon model
691                         other.view_ofs = '0 0 0';
692                         other.angles = other.v_angle = pos.mangle;
693                         if (!other.angles)
694                         {
695                                 other.angles = other.v_angle = pos.angles;
696                                 other.v_angle_x = other.v_angle_x * -1;
697                         }
698                         other.fixangle = TRUE;          // turn this way immediately
699                         setorigin (other, pos.origin);
700                 }
701                 */
702                 other = other.chain;
703         }
704
705         WriteByte (MSG_ALL, SVC_INTERMISSION);
706 };
707
708 /*
709 ============
710 CheckRules_Player
711
712 Exit deathmatch games upon conditions
713 ============
714 */
715 void() CheckRules_Player =
716 {
717         local float fraglimit;
718
719         if (gameover)   // someone else quit the game already
720                 return;
721
722         // fixme: don't check players; instead check dom_team and ctf_team entities
723
724         fraglimit = cvar("fraglimit");
725
726         if(!cvar("g_lms") && !(cvar("g_tdm") || (cvar("teamplay") && cvar("g_runematch"))))
727         {
728                 if (fraglimit && self.frags >= fraglimit)
729                 {
730                         NextLevel ();
731                         return;
732                 }
733         }
734 };
735
736 float checkrules_oneminutewarning;
737 float checkrules_leaderfrags;
738 entity checkrules_leader;
739 float tdm_max_score, tdm_old_score;
740
741 /*
742 ============
743 CheckRules_World
744
745 Exit deathmatch games upon conditions
746 ============
747 */
748 void() CheckRules_World =
749 {
750         local float timelimit;
751         local float fraglimit;
752         local float checkrules_oldleaderfrags;
753         local float f;
754         local entity checkrules_oldleader;
755         local entity head;
756
757         VoteThink();
758
759         if (intermission_running)
760         if (time >= intermission_exittime + 60)
761         {
762                 GotoNextMap();
763                 return;
764         }
765
766         if (gameover)   // someone else quit the game already
767                 return;
768
769         DumpStats();
770
771         timelimit = cvar("timelimit") * 60;
772         fraglimit = cvar("fraglimit");
773
774         if (timelimit && time >= timelimit)
775         {
776                 NextLevel ();
777                 return;
778         }
779
780         if (!checkrules_oneminutewarning && timelimit && time > timelimit - 60)
781         {
782                 checkrules_oneminutewarning = TRUE;
783                 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.ogg", 1, ATTN_NONE);
784         }
785
786         if(cvar("minplayers"))
787         {
788                 if(cvar("minplayers") >= maxclients)
789                         cvar_set("minplayers", ftos(maxclients - 1));
790
791                 f = cvar("minplayers") - (player_count - bot_number);
792                 if((player_count - bot_number) < 1)
793                         f = 0;
794
795                 if(cvar("bot_number") != f)
796                 {
797                         if(cvar("minplayers") != f)
798                                 cvar_set("bot_number", ftos(f));
799                         else
800                                 cvar_set("bot_number", "0");
801                 }
802         }
803
804         // last man camping winning conditions
805         if(cvar("g_lms"))
806         {
807                 if(lms_dead_count < 0)
808                         lms_dead_count = 0;
809
810                 // goto next map if only one player is alive or
811                 // if there is only one player as spectator (could happen with g_lms_join_anytime 1)
812                 if((player_count > 1 && (player_count - lms_dead_count) <= 1) ||
813                   (player_count == 1 && lms_dead_count == 1))
814                         NextLevel();
815                 return;
816         }
817
818         if((cvar("g_tdm") || (cvar("teamplay") && cvar("g_runematch"))) && fraglimit)
819         {
820                 team1_score = team2_score = team3_score = team4_score = 0;
821
822                 head = findchain(classname, "player");
823                 while (head)
824                 {
825                         if(head.team == COLOR_TEAM1)
826                                 team1_score += head.frags;
827                         else if(head.team == COLOR_TEAM2)
828                                 team2_score += head.frags;
829                         else if(head.team == COLOR_TEAM3)
830                                 team3_score += head.frags;
831                         else if(head.team == COLOR_TEAM4)
832                                 team4_score += head.frags;
833                         head = head.chain;
834                 }
835
836                 tdm_old_score = tdm_max_score;
837                 tdm_max_score = max(team1_score, team2_score, team3_score, team4_score);
838
839                 if(tdm_max_score >= fraglimit)
840                         NextLevel();
841
842                 if(!cvar("g_domination") && !cvar("g_runematch"))
843                 if(tdm_max_score != tdm_old_score)
844                 {
845                         if(tdm_max_score == fraglimit - 1)
846                                 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.ogg", 1, ATTN_NONE);
847                         else if(tdm_max_score == fraglimit - 2)
848                                 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.ogg", 1, ATTN_NONE);
849                         else if(tdm_max_score == fraglimit - 3)
850                                 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.ogg", 1, ATTN_NONE);
851                 }
852                 return;
853         }
854
855         checkrules_oldleader = checkrules_leader;
856         checkrules_oldleaderfrags = checkrules_leaderfrags;
857         checkrules_leaderfrags = 0;
858         checkrules_leader = world;
859         head = findchain(classname, "player");
860         while (head)
861         {
862                 if (checkrules_leaderfrags < head.frags)
863                 {
864                         checkrules_leaderfrags = head.frags;
865                         checkrules_leader = head;
866                 }
867                 head = head.chain;
868         }
869         if (checkrules_leaderfrags <= 0)
870         {
871                 checkrules_leader = world;
872                 checkrules_leaderfrags = 0;
873         }
874         checkrules_leaderfrags = floor(checkrules_leaderfrags);
875
876         if (!cvar("g_domination") && !cvar("g_runematch"))
877         if (checkrules_leaderfrags != checkrules_oldleaderfrags)
878         {
879                 if (checkrules_leaderfrags == fraglimit - 1)
880                         sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.ogg", 1, ATTN_NONE);
881                 else if (checkrules_leaderfrags == fraglimit - 2)
882                         sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.ogg", 1, ATTN_NONE);
883                 else if (checkrules_leaderfrags == fraglimit - 3)
884                         sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.ogg", 1, ATTN_NONE);
885         }
886 //      if (checkrules_leader != checkrules_oldleader)// && checkrules_leaderfrags > checkrules_oldleaderfrags)
887 //              bprint("^1",checkrules_leader.netname, " has taken the lead with ", ftos(checkrules_leaderfrags), " frags\n");
888 };