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