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