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