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