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