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