]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/g_world.qc
strcat cleanups;
[divverent/nexuiz.git] / data / qcsrc / server / g_world.qc
1 float SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS = 1;
2
3 string GetMapname();
4 void GotoNextMap();
5 void HandleMaplistShuffleCommands();
6 float() DoNextMapOverride;
7
8 void SetDefaultAlpha()
9 {
10         if(cvar("g_running_guns"))
11         {
12                 default_player_alpha = -1;
13                 default_weapon_alpha = +1;
14         }
15         else if(cvar("g_cloaked"))
16         {
17                 default_player_alpha = cvar("g_balance_cloaked_alpha");
18                 default_weapon_alpha = default_player_alpha;
19         }
20         else
21         {
22                 default_player_alpha = cvar("g_player_alpha");
23                 if(default_player_alpha <= 0)
24                         default_player_alpha = 1;
25                 default_weapon_alpha = default_player_alpha;
26         }
27 }
28
29 void fteqcc_testbugs()
30 {
31         float a, b;
32
33         if(!cvar("developer_fteqccbugs"))
34                 return;
35
36         dprint("*** fteqcc test: checking for bugs...\n");
37
38         a = 1;
39         b = 5;
40         if(sqrt(a) - sqrt(b - a) == 0)
41                 dprint("*** fteqcc test: found same-function-twice bug\n");
42         else
43                 dprint("*** fteqcc test: same-function-twice bug got FINALLY FIXED! HOORAY!\n");
44
45         world.frags = -10;
46         world.enemy = world;
47         world.enemy.frags += 10;
48         if(world.frags > 0.2 || world.frags < -0.2) // don't error out if it's just roundoff errors
49                 dprint("*** fteqcc test: found += bug\n");
50         else
51                 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
52         world.frags = 0;
53 }
54
55 void GotoFirstMap()
56 {
57         if(cvar("_sv_init"))
58         {
59                 cvar_set("_sv_init", "0");
60                 HandleMaplistShuffleCommands();
61                 tokenize(cvar_string("g_maplist"));
62                 if(argv(0) != GetMapname())
63                 {
64                         cvar_set("nextmap", argv(0));
65                         if(!DoNextMapOverride())
66                                 GotoNextMap();
67                 }
68         }
69 }
70
71 float world_already_spawned;
72 void worldspawn (void)
73 {
74         if(world_already_spawned)
75                 error("world already spawned - you may have EXACTLY ONE worldspawn!");
76         world_already_spawned = TRUE;
77         // Precache all player models
78         // Workaround for "invisible players"
79         precache_model("models/player/carni.zym");
80         precache_model("models/player/crash.zym");
81         precache_model("models/player/grunt.zym");
82         precache_model("models/player/headhunter.zym");
83         precache_model("models/player/insurrectionist.zym");
84         precache_model("models/player/jeandarc.zym");
85         precache_model("models/player/lurk.zym");
86         precache_model("models/player/lycanthrope.zym");
87         precache_model("models/player/marine.zym");
88         precache_model("models/player/nexus.zym");
89         precache_model("models/player/pyria.zym");
90         precache_model("models/player/shock.zym");
91         precache_model("models/player/skadi.zym");
92         precache_model("models/player/specop.zym");
93         precache_model("models/player/visitant.zym");
94
95         //precache_model ("progs/beam.mdl");
96         precache_model ("models/bullet.mdl");
97         precache_model ("models/casing_bronze.mdl");
98         precache_model ("models/casing_shell.mdl");
99         precache_model ("models/casing_steel.mdl");
100         precache_model ("models/ebomb.mdl");
101         precache_model ("models/elaser.mdl");
102         precache_model ("models/flash.md3");
103         precache_model ("models/gibs/bloodyskull.md3");
104         precache_model ("models/gibs/chunk.mdl");
105         precache_model ("models/gibs/eye.md3");
106         precache_model ("models/gibs/gib1.md3");
107         //precache_model ("models/gibs/gib2.md3");
108         //precache_model ("models/gibs/gib3.md3");
109         //precache_model ("models/gibs/gib4.md3");
110         precache_model ("models/gibs/gib5.md3");
111         //precache_model ("models/gibs/gib6.md3");
112         precache_model ("models/gibs/gib1.mdl");
113         precache_model ("models/gibs/gib2.mdl");
114         precache_model ("models/gibs/gib3.mdl");
115         precache_model ("models/grenademodel.md3");
116         precache_model ("models/hagarmissile.mdl");
117         precache_model ("models/items/a_bullets.mdl");
118         precache_model ("models/items/a_cells.md3");
119         precache_model ("models/items/a_rockets.md3");
120         precache_model ("models/items/a_shells.md3");
121         precache_model ("models/items/g_a1.md3");
122         precache_model ("models/items/g_a25.md3");
123         precache_model ("models/items/g_h1.md3");
124         precache_model ("models/items/g_h25.md3");
125         precache_model ("models/items/g_h100.md3");
126         precache_model ("models/items/g_invincible.md3");
127         precache_model ("models/items/g_strength.md3");
128         precache_model ("models/laser.mdl");
129         precache_model ("models/misc/chatbubble.spr");
130         precache_model ("models/misc/teambubble.spr");
131         precache_model ("models/nexflash.md3");
132         precache_model ("models/plasma.mdl");
133         precache_model ("models/plasmatrail.mdl");
134         precache_model ("models/rocket.md3");
135         //precache_model ("models/sprites/grenexpl.spr");
136         precache_model ("models/runematch/rune.mdl");
137         precache_model ("models/runematch/curse.mdl");
138         //precache_model ("models/sprites/hagar.spr");
139         //precache_model ("models/sprites/muzzleflash.spr32");
140         //precache_model ("models/sprites/electrocombo.spr32");
141         //precache_model ("models/sprites/plasmahitwall.spr32");
142         //precache_model ("models/sprites/plasmashot.spr32");
143         //precache_model ("models/sprites/rockexpl.spr");
144         precache_model ("models/tracer.mdl");
145         precache_model ("models/uziflash.md3");
146         precache_model ("models/weapons/g_crylink.md3");
147         precache_model ("models/weapons/g_electro.md3");
148         precache_model ("models/weapons/g_gl.md3");
149         precache_model ("models/weapons/g_hagar.md3");
150         precache_model ("models/weapons/g_nex.md3");
151         precache_model ("models/weapons/g_rl.md3");
152         precache_model ("models/weapons/g_shotgun.md3");
153         precache_model ("models/weapons/g_uzi.md3");
154         precache_model ("models/weapons/v_crylink.md3");
155         precache_model ("models/weapons/v_electro.md3");
156         precache_model ("models/weapons/v_gl.md3");
157         precache_model ("models/weapons/v_hagar.md3");
158         precache_model ("models/weapons/v_laser.md3");
159         precache_model ("models/weapons/v_nex.md3");
160         precache_model ("models/weapons/v_rl.md3");
161         precache_model ("models/weapons/v_shotgun.md3");
162         precache_model ("models/weapons/v_uzi.md3");
163         precache_model ("models/weapons/w_crylink.zym");
164         precache_model ("models/weapons/w_electro.zym");
165         precache_model ("models/weapons/w_gl.zym");
166         precache_model ("models/weapons/w_hagar.zym");
167         precache_model ("models/weapons/w_laser.zym");
168         precache_model ("models/weapons/w_nex.zym");
169         precache_model ("models/weapons/w_rl.zym");
170         precache_model ("models/weapons/w_shotgun.zym");
171         precache_model ("models/weapons/w_uzi.zym");
172
173         // laser for laser-guided weapons
174         precache_model ("models/laser_dot.mdl");
175
176         precache_sound ("misc/null.wav");
177         precache_sound ("misc/armor1.wav");
178         precache_sound ("misc/armor25.wav");
179         precache_sound ("misc/armorimpact.wav");
180         precache_sound ("misc/bodyimpact1.wav");
181         precache_sound ("misc/bodyimpact2.wav");
182         precache_sound ("misc/gib.wav");
183         precache_sound ("misc/gib_splat01.wav");
184         precache_sound ("misc/gib_splat02.wav");
185         precache_sound ("misc/gib_splat03.wav");
186         precache_sound ("misc/gib_splat04.wav");
187         //precache_sound ("misc/h2ohit.wav");
188         precache_sound ("misc/hit.wav");
189         precache_sound ("misc/footstep01.wav");
190         precache_sound ("misc/footstep02.wav");
191         precache_sound ("misc/footstep03.wav");
192         precache_sound ("misc/footstep04.wav");
193         precache_sound ("misc/footstep05.wav");
194         precache_sound ("misc/footstep06.wav");
195         precache_sound ("misc/hitground1.ogg");
196         precache_sound ("misc/hitground2.ogg");
197         precache_sound ("misc/hitground3.ogg");
198         precache_sound ("misc/hitground4.ogg");
199         precache_sound ("misc/itempickup.ogg");
200         precache_sound ("misc/itemrespawn.ogg");
201         precache_sound ("misc/jumppad.ogg");
202         precache_sound ("misc/mediumhealth.ogg");
203         precache_sound ("misc/megahealth.ogg");
204         precache_sound ("misc/minihealth.ogg");
205         precache_sound ("misc/powerup.ogg");
206         precache_sound ("misc/powerup_shield.ogg");
207         precache_sound ("misc/talk.wav");
208         precache_sound ("misc/teleport.ogg");
209         precache_sound ("plats/medplat1.wav");
210         precache_sound ("plats/medplat2.wav");
211         precache_sound ("player/lava.wav");
212         precache_sound ("player/slime.wav");
213         precache_sound ("weapons/crylink_fire.ogg");
214         precache_sound ("weapons/electro_bounce.ogg");
215         precache_sound ("weapons/electro_fire.ogg");
216         precache_sound ("weapons/electro_fire2.ogg");
217         precache_sound ("weapons/electro_fly.wav");
218         precache_sound ("weapons/electro_impact.ogg");
219         precache_sound ("weapons/electro_impact_combo.ogg");
220         //precache_sound ("weapons/grenade_bounce.ogg");
221         precache_sound ("weapons/grenade_bounce1.ogg");
222         precache_sound ("weapons/grenade_bounce2.ogg");
223         precache_sound ("weapons/grenade_bounce3.ogg");
224         precache_sound ("weapons/grenade_fire.ogg");
225         precache_sound ("weapons/grenade_impact.ogg");
226         precache_sound ("weapons/hagar_fire.ogg");
227         precache_sound ("weapons/hagexp1.ogg");
228         precache_sound ("weapons/hagexp2.ogg");
229         precache_sound ("weapons/hagexp3.ogg");
230         precache_sound ("weapons/hook_fire.ogg");
231         precache_sound ("weapons/hook_impact.ogg");
232         precache_sound ("weapons/lasergun_fire.ogg");
233         precache_sound ("weapons/laserimpact.ogg");
234         precache_sound ("weapons/nexfire.ogg");
235         precache_sound ("weapons/neximpact.ogg");
236         precache_sound ("weapons/ric1.ogg");
237         precache_sound ("weapons/ric2.ogg");
238         precache_sound ("weapons/ric3.ogg");
239         precache_sound ("weapons/rocket_fire.ogg");
240         precache_sound ("weapons/rocket_fly.wav");
241         precache_sound ("weapons/rocket_impact.ogg");
242         precache_sound ("weapons/rocket_det.ogg");
243         precache_sound ("weapons/shotgun_fire.ogg");
244         precache_sound ("weapons/tink1.ogg");
245         precache_sound ("weapons/uzi_fire.ogg");
246         precache_sound ("weapons/weapon_switch.ogg");
247         precache_sound ("weapons/weaponpickup.ogg");
248         precache_sound ("weapons/strength_fire.ogg");
249
250         //precache_sound ("announce/male/kill10.ogg");
251         //precache_sound ("announce/male/kill15.ogg");
252         //precache_sound ("announce/male/kill20.ogg");
253         //precache_sound ("announce/male/kill25.ogg");
254         //precache_sound ("announce/male/kill3.ogg");
255         //precache_sound ("announce/male/kill30.ogg");
256         //precache_sound ("announce/male/kill4.ogg");
257         //precache_sound ("announce/male/kill5.ogg");
258         //precache_sound ("announce/male/kill6.ogg");
259         //precache_sound ("announce/male/mapkill1.ogg");
260         //precache_sound ("announce/robotic/last_second_save.ogg");
261         //precache_sound ("announce/robotic/narrowly_averted.ogg");
262         //precache_sound ("minstagib/mockery.ogg");
263
264         // announcer sounds - male
265         precache_sound ("announcer/male/03kills.ogg");
266         precache_sound ("announcer/male/05kills.ogg");
267         precache_sound ("announcer/male/10kills.ogg");
268         precache_sound ("announcer/male/15kills.ogg");
269         precache_sound ("announcer/male/20kills.ogg");
270         precache_sound ("announcer/male/25kills.ogg");
271         precache_sound ("announcer/male/30kills.ogg");
272         precache_sound ("announcer/male/botlike.ogg");
273         precache_sound ("announcer/male/electrobitch.ogg");
274         precache_sound ("announcer/male/welcome.ogg");
275         precache_sound ("announcer/male/yoda.ogg");
276
277         // announcer sounds - robotic
278         precache_sound ("announcer/robotic/1fragleft.ogg");
279         precache_sound ("announcer/robotic/1minuteremains.ogg");
280         precache_sound ("announcer/robotic/2fragsleft.ogg");
281         precache_sound ("announcer/robotic/3fragsleft.ogg");
282         precache_sound ("announcer/robotic/lastsecond.ogg");
283         precache_sound ("announcer/robotic/narrowly.ogg");
284         precache_sound ("announcer/robotic/1.ogg");
285         precache_sound ("announcer/robotic/2.ogg");
286         precache_sound ("announcer/robotic/3.ogg");
287         precache_sound ("announcer/robotic/4.ogg");
288         precache_sound ("announcer/robotic/5.ogg");
289         precache_sound ("announcer/robotic/6.ogg");
290         precache_sound ("announcer/robotic/7.ogg");
291         precache_sound ("announcer/robotic/8.ogg");
292         precache_sound ("announcer/robotic/9.ogg");
293         precache_sound ("announcer/robotic/10.ogg");
294
295         // plays music for the level if there is any
296         if (self.noise)
297         {
298                 precache_sound (self.noise);
299                 ambientsound ('0 0 0', self.noise, 1.00, ATTN_NONE);
300         }
301
302         // 0 normal
303         lightstyle(0, "m");
304
305         // 1 FLICKER (first variety)
306         lightstyle(1, "mmnmmommommnonmmonqnmmo");
307
308         // 2 SLOW STRONG PULSE
309         lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
310
311         // 3 CANDLE (first variety)
312         lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
313
314         // 4 FAST STROBE
315         lightstyle(4, "mamamamamama");
316
317         // 5 GENTLE PULSE 1
318         lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
319
320         // 6 FLICKER (second variety)
321         lightstyle(6, "nmonqnmomnmomomno");
322
323         // 7 CANDLE (second variety)
324         lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
325
326         // 8 CANDLE (third variety)
327         lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
328
329         // 9 SLOW STROBE (fourth variety)
330         lightstyle(9, "aaaaaaaazzzzzzzz");
331
332         // 10 FLUORESCENT FLICKER
333         lightstyle(10, "mmamammmmammamamaaamammma");
334
335         // 11 SLOW PULSE NOT FADE TO BLACK
336         lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
337
338         // styles 32-62 are assigned by the light program for switchable lights
339
340         // 63 testing
341         lightstyle(63, "a");
342
343         registercvar("_g_maplist_shufflenow", "0");
344         registercvar("_g_maplist_have_shuffled", "0");
345         registercvar("_g_maplist_add", "");
346         registercvar("_g_maplist_remove", "");
347         registercvar("_g_maplist_putfirst", "");
348
349         player_count = 0;
350         lms_lowest_lives = 0;
351         lms_next_place = 0;
352
353         GotoFirstMap();
354
355         bot_waypoints_for_items = cvar("g_waypoints_for_items");
356         if(bot_waypoints_for_items == 1)
357                 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
358                         bot_waypoints_for_items = 0;
359
360         if(cvar("g_campaign"))
361                 CampaignPreInit();
362
363         InitGameplayMode();
364         //if (cvar("g_domination"))
365         //      dom_init();
366
367         local entity head;
368         head = nextent(world);
369         maxclients = 0;
370         while(head)
371         {
372                 maxclients++;
373                 head = nextent(head);
374         }
375
376         GameLogInit(); // prepare everything
377         if(cvar("sv_eventlog"))
378         {
379                 local string s;
380                 GameLogEcho(":logversion:2", FALSE);
381                 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
382                 s = strcat(s, ftos(random()));
383                 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
384                 s = ":gameinfo:mutators:LIST";
385                 if(cvar("g_grappling_hook"))
386                         s = strcat(s, ":grappling_hook");
387                 if(!cvar("g_use_ammunition"))
388                         s = strcat(s, ":no_use_ammunition");
389                 if(!cvar("g_pickup_items"))
390                         s = strcat(s, ":no_pickup_items");
391                 if(cvar("g_instagib"))
392                         s = strcat(s, ":instagib");
393                 if(cvar("g_rocketarena"))
394                         s = strcat(s, ":rockerarena");
395                 if(cvar("g_nixnex"))
396                         s = strcat(s, ":nixnex");
397                 if(cvar("g_vampire"))
398                         s = strcat(s, ":vampire");
399                 if(cvar("g_laserguided_missile"))
400                         s = strcat(s, ":laserguided_missile");
401                 if(cvar("g_norecoil"))
402                         s = strcat(s, ":norecoil");
403                 if(cvar("g_midair"))
404                         s = strcat(s, ":midair");
405                 if(cvar("g_minstagib"))
406                         s = strcat(s, ":minstagib");
407                 GameLogEcho(s, FALSE);
408                 GameLogEcho(":gameinfo:end", FALSE);
409         }
410
411         cvar_set("nextmap", "");
412
413         SetDefaultAlpha();
414
415         if(cvar("g_campaign"))
416                 CampaignPostInit();
417
418         // fteqcc_testbugs();
419 }
420
421 void light (void)
422 {
423         //makestatic (self); // Who the f___ did that?
424         remove(self);
425 }
426
427 float( string pFilename ) TryFile =
428 {
429         local float lHandle;
430         dprint("TryFile(\"", pFilename, "\")\n");
431         lHandle = fopen( pFilename, FILE_READ );
432         if( lHandle != -1 ) {
433                 fclose( lHandle );
434                 return TRUE;
435         } else {
436                 return FALSE;
437         }
438 };
439
440 string GetGametype()
441 {
442         if (game == GAME_DEATHMATCH)
443                 return "dm";
444         else if (game == GAME_TEAM_DEATHMATCH)
445                 return "tdm";
446         else if (game == GAME_DOMINATION)
447                 return "dom";
448         else if (game == GAME_CTF)
449                 return "ctf";
450         else if (game == GAME_RUNEMATCH)
451                 return "rune";
452         else if (game == GAME_LMS)
453                 return "lms";
454         return "dm";
455 }
456
457 string getmapname_stored;
458 string GetMapname()
459 {
460         if(getmapname_stored == "")
461                 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
462         return getmapname_stored;
463 }
464
465 float Map_Count, Map_Current;
466 string Map_Current_Name;
467
468 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
469 float GetMaplistPosition()
470 {
471         float pos, idx;
472         string map;
473
474         map = GetMapname();
475         idx = cvar("g_maplist_index");
476
477         if(idx >= 0)
478                 if(idx < Map_Count)
479                         if(map == argv(idx))
480                                 return idx;
481
482         for(pos = 0; pos < Map_Count; ++pos)
483                 if(map == argv(pos))
484                         return pos;
485
486         // resume normal maplist rotation if current map is not in g_maplist
487         return idx;
488 }
489
490 float MapHasRightSize(string map)
491 {
492         // open map size restriction file
493         float fh;
494         dprint("opensize "); dprint(map);
495         fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
496         if(fh >= 0)
497         {
498                 float mapmin, mapmax;
499                 dprint(": ok, ");
500                 mapmin = stof(fgets(fh));
501                 mapmax = stof(fgets(fh));
502                 fclose(fh);
503                 if(player_count < mapmin)
504                 {
505                         dprint("not enough\n");
506                         return FALSE;
507                 }
508                 if(player_count > mapmax)
509                 {
510                         dprint("too many\n");
511                         return FALSE;
512                 }
513                 dprint("right size\n");
514                 return TRUE;
515         }
516         dprint(": not found\n");
517         return TRUE;
518 }
519
520 string Map_Filename(float position)
521 {
522         // FIXME unused
523         return strcat("maps/", argv(position), ".mapcfg");
524 }
525
526 float(float position, float pass) Map_Check =
527 {
528         string filename;
529         string map_next;
530         map_next = argv(position);
531         if(pass <= 1)
532                 if(map_next == Map_Current_Name) // same map again in first pass?
533                         return 0;
534         filename = Map_Filename(position);
535         if(TryFile(filename))
536         {
537                 if(pass == 2)
538                         return 1;
539                 if(MapHasRightSize(argv(position)))
540                         return 1;
541                 return 0;
542         }
543         else
544                 dprint( "Couldn't find '", filename, "'..\n" );
545
546         return 0;
547 }
548
549 void(string nextmapname) Map_Goto_SetStr =
550 {
551         if(getmapname_stored != "")
552                 strunzone(getmapname_stored);
553         if(nextmapname == "")
554                 getmapname_stored = "";
555         else
556                 getmapname_stored = strzone(nextmapname);
557 }
558
559 void(float position) Map_Goto_SetFloat =
560 {
561         cvar_set("g_maplist_index", ftos(position));
562         Map_Goto_SetStr(argv(position));
563 }
564
565 void() GameResetCfg =
566 {
567         // if an exit cfg is defined by exiting map, exec it.
568         string exit_cfg;
569         exit_cfg = cvar_string("exit_cfg");
570         if(exit_cfg != "")
571                 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
572
573         localcmd("exec game_reset.cfg\n");
574 };
575
576 void() Map_Goto =
577 {
578         GameResetCfg();
579         localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
580 }
581
582 // return codes of map selectors:
583 //   -1 = temporary failure (that is, try some method that is guaranteed to succeed)
584 //   -2 = permanent failure
585 float() MaplistMethod_Iterate = // usual method
586 {
587         float pass, i;
588
589         for(pass = 1; pass <= 2; ++pass)
590         {
591                 for(i = 1; i < Map_Count; ++i)
592                 {
593                         float mapindex;
594                         mapindex = math_mod(i + Map_Current, Map_Count);
595                         if(Map_Check(mapindex, pass))
596                                 return mapindex;
597                 }
598         }
599         return -1;
600 }
601
602 float() MaplistMethod_Repeat = // fallback method
603 {
604         if(Map_Check(Map_Current, 2))
605                 return Map_Current;
606         return -2;
607 }
608
609 float() MaplistMethod_Random = // random map selection
610 {
611         float i, imax;
612
613         imax = 42;
614
615         for(i = 0; i <= imax; ++i)
616         {
617                 float mapindex;
618                 mapindex = math_mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
619                 if(Map_Check(mapindex, 1))
620                         return mapindex;
621         }
622         return -1;
623 }
624
625 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
626 // the exponent sets a bias on the map selection:
627 // the higher the exponent, the 
628 {
629         float i, j, imax, insertpos;
630
631         imax = 42;
632
633         if(Map_Count <= 1)
634                 return 0; // only one map, then always play this one
635
636         for(i = 0; i <= imax; ++i)
637         {
638                 string newlist;
639
640                 // now reinsert this at another position
641                 insertpos = pow(random(), 1 / exponent);       // ]0, 1]
642                 insertpos = insertpos * (Map_Count - 1);       // ]0, Map_Count - 1]
643                 insertpos = ceil(insertpos) + 1;               // {2, 3, 4, ..., Map_Count}
644                 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
645
646                 // insert the current map there
647                 newlist = "";
648                 for(j = 1; j < insertpos; ++j)                 // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
649                         newlist = strcat(newlist, "'", argv(j), "'");
650                 newlist = strcat(newlist, "'", argv(0), "'");  // now insert the just selected map
651                 for(j = insertpos; j < Map_Count; ++j)         // i == Map_Count: no loop, has just been inserted as last
652                         newlist = strcat(newlist, "'", argv(j), "'");
653                 cvar_set("g_maplist", newlist);
654                 Map_Count = tokenize(newlist);
655
656                 // NOTE: the selected map has just been inserted at (insertpos-1)th position
657                 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
658                 if(Map_Check(Map_Current, 1))
659                         return Map_Current;
660         }
661         return -1;
662 }
663
664 void() Maplist_Init =
665 {
666         string temp;
667         temp = cvar_string("g_maplist");
668         Map_Count = tokenize(temp);
669         if(Map_Count == 0)
670         {
671                 bprint( "Maplist is empty!  Resetting it to default map list.\n" );
672                 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
673                 Map_Count = tokenize(temp);
674         }
675         if(Map_Count == 0)
676                 error("empty maplist, cannot select a new map");
677         Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
678
679         Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
680         // this may or may not be correct, but who cares, in the worst case a map
681         // isn't chosen in the first pass that should have been
682 }
683
684 string() GetNextMap =
685 {
686         float nextMap;
687
688         Maplist_Init();
689         nextMap = -1;
690
691         if(nextMap == -1)
692                 if(cvar("g_maplist_shuffle") > 0)
693                         nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
694
695         if(nextMap == -1)
696                 if(cvar("g_maplist_selectrandom"))
697                         nextMap = MaplistMethod_Random();
698
699         if(nextMap == -1)
700                 nextMap = MaplistMethod_Iterate();
701
702         if(nextMap == -1)
703                 nextMap = MaplistMethod_Repeat();
704
705         if(nextMap >= 0)
706         {
707                 Map_Goto_SetFloat(nextMap);
708                 return getmapname_stored;
709         }
710
711         return "";
712 };
713
714 float() DoNextMapOverride =
715 {
716         if(cvar("g_campaign"))
717         {
718                 CampaignPostIntermission();
719                 return TRUE;
720         }
721         if(cvar("quit_when_empty"))
722         {
723                 if(player_count <= currentbots)
724                 {
725                         localcmd("quit\n");
726                         return TRUE;
727                 }
728         }
729         if (cvar("samelevel")) // if samelevel is set, stay on same level
730         {
731                 // 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)
732                 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
733                 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
734                 localcmd("restart\n");
735                 //changelevel (mapname);
736                 return TRUE;
737         }
738         if(cvar_string("nextmap") != "")
739                 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
740                 {
741                         Map_Goto_SetStr(cvar_string("nextmap"));
742                         Map_Goto();
743                         return TRUE;
744                 }
745         if(cvar("lastlevel"))
746         {
747                 GameResetCfg();
748                 localcmd("set lastlevel 0\ntogglemenu\n");
749                 return TRUE;
750         }
751         return FALSE;
752 };
753
754 void() GotoNextMap =
755 {
756         //local string nextmap;
757         //local float n, nummaps;
758         //local string s;
759         if (alreadychangedlevel)
760                 return;
761         alreadychangedlevel = TRUE;
762
763         {
764                 string nextMap;
765                 float allowReset;
766
767                 for(allowReset = 1; allowReset >= 0; --allowReset)
768                 {
769                         nextMap = GetNextMap();
770                         if(nextMap != "")
771                                 break;
772
773                         if(allowReset)
774                         {
775                                 bprint( "Maplist contains no single playable map!  Resetting it to default map list.\n" );
776                                 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
777                         }
778                         else
779                         {
780                                 error("Everything is broken - not even the default map list works. Please report this to the developers.");
781                         }
782                 }
783                 Map_Goto();
784         }
785 };
786
787
788 /*
789 ============
790 IntermissionThink
791
792 When the player presses attack or jump, change to the next level
793 ============
794 */
795 .float autoscreenshot;
796 void() MapVote_Think;
797 float mapvote_initialized;
798 void() IntermissionThink =
799 {
800         FixIntermissionClient(self);
801
802         if(cvar("sv_autoscreenshot"))
803         if(self.autoscreenshot)
804         if(time > self.autoscreenshot)
805         {
806                 self.autoscreenshot = FALSE;
807                 if(clienttype(self) == CLIENTTYPE_REAL)
808                         stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
809                 return;
810         }
811
812         if (time < intermission_exittime)
813                 return;
814
815         if(!mapvote_initialized)
816                 if (time < intermission_exittime + 10 && !self.button0 && !self.button2 && !self.button3 && !self.button6 && !self.buttonuse)
817                         return;
818
819         if(intermission_exittime >= 0)
820                 MapVote_Think();
821 };
822
823 /*
824 ============
825 FindIntermission
826
827 Returns the entity to view from
828 ============
829 */
830 /*
831 entity() FindIntermission =
832 {
833         local   entity spot;
834         local   float cyc;
835
836 // look for info_intermission first
837         spot = find (world, classname, "info_intermission");
838         if (spot)
839         {       // pick a random one
840                 cyc = random() * 4;
841                 while (cyc > 1)
842                 {
843                         spot = find (spot, classname, "info_intermission");
844                         if (!spot)
845                                 spot = find (spot, classname, "info_intermission");
846                         cyc = cyc - 1;
847                 }
848                 return spot;
849         }
850
851 // then look for the start position
852         spot = find (world, classname, "info_player_start");
853         if (spot)
854                 return spot;
855
856 // testinfo_player_start is only found in regioned levels
857         spot = find (world, classname, "testplayerstart");
858         if (spot)
859                 return spot;
860
861 // then look for the start position
862         spot = find (world, classname, "info_player_deathmatch");
863         if (spot)
864                 return spot;
865
866         //objerror ("FindIntermission: no spot");
867         return world;
868 };
869 */
870
871 /*
872 ===============================================================================
873
874 RULES
875
876 ===============================================================================
877 */
878
879 void() DumpStats =
880 {
881         local float file;
882         local string s;
883
884         if(cvar("_printstats"))
885                 cvar_set("_printstats", "0");
886         else if(!gameover)
887                 return;
888
889         if(gameover)
890                 s = ":scores:";
891         else
892                 s = ":status:";
893
894         s = strcat(s, GetMapname(), ":", ftos(rint(time)));
895
896         if(cvar("sv_eventlog") && gameover)
897                 GameLogEcho(s, FALSE);
898         else if(cvar("sv_logscores_console"))
899                 ServerConsoleEcho(s, FALSE);
900         if(cvar("sv_logscores_file"))
901         {
902                 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
903                 fputs(file, strcat(s, "\n"));
904         }
905
906         FOR_EACH_CLIENT(other)
907         {
908                 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
909                 {
910                         s = strcat(":player:", ftos(other.frags), ":");
911                         s = strcat(s, ftos(other.deaths), ":");
912                         s = strcat(s, ftos(rint(time - other.jointime)), ":");
913                         s = strcat(s, ftos(other.team), ":");
914
915                         if(cvar("sv_logscores_file"))
916                                 fputs(file, strcat(s, other.netname, "\n"));
917                         if(cvar("sv_eventlog") && gameover)
918                                 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
919                         else if(cvar("sv_logscores_console"))
920                                 ServerConsoleEcho(strcat(s, other.netname), TRUE);
921                 }
922         }
923
924         if(cvar("sv_eventlog") && gameover)
925                 GameLogEcho(":end", FALSE);
926         else if(cvar("sv_logscores_console"))
927                 ServerConsoleEcho(":end", FALSE);
928         if(cvar("sv_logscores_file"))
929         {
930                 fputs(file, ":end\n");
931                 fclose(file);
932         }
933 }
934
935 void FixIntermissionClient(entity e)
936 {
937         if(!e.autoscreenshot) // initial call
938         {
939                 e.angles = e.v_angle;
940                 e.angles_x = -e.angles_x;
941                 e.autoscreenshot = time + 0.8;  // used for autoscreenshot
942                 e.health = -2342;
943                 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
944                 e.solid = SOLID_NOT;
945                 e.movetype = MOVETYPE_NONE;
946                 e.takedamage = DAMAGE_NO;
947                 if(e.weaponentity)
948                         e.weaponentity.effects = EF_NODRAW;
949                 stuffcmd(e, "\nscr_printspeed 1000000\n");
950                 if(clienttype(e) == CLIENTTYPE_REAL)
951                 {
952                         msg_entity = e;
953                         WriteByte(MSG_ONE, SVC_INTERMISSION);
954                 }
955         }
956
957         //e.velocity = '0 0 0';
958         //e.fixangle = TRUE;
959
960         // TODO halt weapon animation
961 }
962
963
964 /*
965 go to the next level for deathmatch
966 only called if a time or frag limit has expired
967 */
968 void() NextLevel =
969 {
970         float minTotalFrags;
971         float maxTotalFrags;
972         float score;
973         float f;
974
975         gameover = TRUE;
976
977         intermission_running = 1;
978
979 // enforce a wait time before allowing changelevel
980         if(player_count > 0)
981                 intermission_exittime = time + cvar("sv_mapchange_delay");
982         else
983                 intermission_exittime = -60;
984
985         WriteByte (MSG_ALL, SVC_CDTRACK);
986         WriteByte (MSG_ALL, 3);
987         WriteByte (MSG_ALL, 3);
988
989         //pos = FindIntermission ();
990
991         VoteReset();
992
993         DumpStats();
994
995         if(cvar("sv_eventlog"))
996                 GameLogEcho(":gameover", FALSE);
997
998         GameLogClose();
999
1000         maxTotalFrags = 0;
1001         FOR_EACH_CLIENT(other)
1002         {
1003                 if(maxTotalFrags < other.totalfrags)
1004                         maxTotalFrags = other.totalfrags;
1005                 if(minTotalFrags > other.totalfrags)
1006                         minTotalFrags = other.totalfrags;
1007         }
1008
1009         FOR_EACH_CLIENT(other)
1010         {
1011                 FixIntermissionClient(other);
1012
1013                 self = other;
1014
1015                 if(other.winning)
1016                         bprint(other.netname, " ^7wins.\n");
1017
1018                 if(!currentbots)
1019                 {
1020                         score = (other.frags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1021                         f = bound(0, other.play_time / max(time, 1), 1);
1022                         // store some statistics?
1023                 }
1024         }
1025
1026         if(cvar("g_campaign"))
1027                 CampaignPreIntermission();
1028
1029         // WriteByte (MSG_ALL, SVC_INTERMISSION);
1030 };
1031
1032 /*
1033 ============
1034 CheckRules_Player
1035
1036 Exit deathmatch games upon conditions
1037 ============
1038 */
1039 void() CheckRules_Player =
1040 {
1041         if (gameover)   // someone else quit the game already
1042                 return;
1043
1044         if(self.deadflag == DEAD_NO)
1045                 self.play_time += frametime;
1046
1047         // fixme: don't check players; instead check dom_team and ctf_team entities
1048         //   (div0: and that in CheckRules_World please)
1049 };
1050
1051 float checkrules_oneminutewarning;
1052 float checkrules_leaderfrags;
1053 float tdm_max_score, tdm_old_score;
1054
1055 float checkrules_equality;
1056 float checkrules_overtimewarning;
1057 float checkrules_overtimeend;
1058
1059 void() InitiateOvertime =
1060 {
1061         if(!checkrules_overtimeend)
1062                 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1063 }
1064
1065 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1066 float WINNING_YES = 1; // winner found
1067 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1068 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1069
1070 float(float fraglimitreached, float equality) GetWinningCode =
1071 {
1072         if(equality)
1073                 if(fraglimitreached)
1074                         return WINNING_STARTOVERTIME;
1075                 else
1076                         return WINNING_NEVER;
1077         else
1078                 if(fraglimitreached)
1079                         return WINNING_YES;
1080                 else
1081                         return WINNING_NO;
1082 }
1083
1084 // set the .winning flag for exactly those players with a given field value
1085 void(.float field, float value) SetWinners =
1086 {
1087         entity head;
1088         FOR_EACH_PLAYER(head)
1089                 head.winning = (head.field == value);
1090 }
1091
1092 // set the .winning flag for those players with a given field value
1093 void(.float field, float value) AddWinners =
1094 {
1095         entity head;
1096         FOR_EACH_PLAYER(head)
1097                 if(head.field == value)
1098                         head.winning = 1;
1099 }
1100
1101 // clear the .winning flags
1102 void(void) ClearWinners =
1103 {
1104         entity head;
1105         FOR_EACH_PLAYER(head)
1106                 head.winning = 0;
1107 }
1108
1109 float() LMS_NewPlayerLives =
1110 {
1111         float fl;
1112         fl = cvar("fraglimit");
1113         if(fl == 0)
1114                 fl = 999;
1115
1116         // first player has left the game for dying too much? Nobody else can get in.
1117         if(lms_lowest_lives < 1)
1118                 return FALSE;
1119
1120         if(!cvar("g_lms_join_anytime"))
1121                 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1122                         return FALSE;
1123
1124         return bound(1, lms_lowest_lives, fl);
1125 }
1126
1127 // LMS winning condition: game terminates if and only if there's at most one
1128 // one player who's living lives. Top two scores being equal cancels the time
1129 // limit.
1130 float() WinningCondition_LMS =
1131 {
1132         entity head;
1133         float have_player;
1134         float have_players;
1135         float l;
1136
1137         have_player = FALSE;
1138         have_players = FALSE;
1139         l = LMS_NewPlayerLives();
1140
1141         head = find(world, classname, "player");
1142         if(head)
1143                 have_player = TRUE;
1144         head = find(head, classname, "player");
1145         if(head)
1146                 have_players = TRUE;
1147
1148         if(have_player)
1149         {
1150                 // we have at least one player
1151                 if(have_players)
1152                 {
1153                         // two or more active players - continue with the game
1154                 }
1155                 else
1156                 {
1157                         // exactly one player?
1158                         if(l)
1159                         {
1160                                 // but no game has taken place yet
1161                         }
1162                         else
1163                         {
1164                                 // a winner!
1165                                 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1166                                 dprint("Have a winner, ending game.\n");
1167                                 return WINNING_YES;
1168                         }
1169                 }
1170         }
1171         else
1172         {
1173                 // nobody is playing at all...
1174                 if(l)
1175                 {
1176                         // wait for players...
1177                 }
1178                 else
1179                 {
1180                         // SNAFU (maybe a draw game?)
1181                         ClearWinners();
1182                         dprint("No players, ending game.\n");
1183                         return WINNING_YES;
1184                 }
1185         }
1186
1187         // When we get here, we have at least two players who are actually LIVING,
1188         // or one player who is still waiting for a victim to join the server. Now
1189         // check if the top two players have equal score.
1190
1191         checkrules_leaderfrags = 0;
1192         checkrules_equality = FALSE;
1193         FOR_EACH_PLAYER(head)
1194         {
1195                 if(head.frags > checkrules_leaderfrags)
1196                 {
1197                         checkrules_leaderfrags = head.frags;
1198                         checkrules_equality = FALSE;
1199                 }
1200                 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1201                         checkrules_equality = TRUE;
1202         }
1203
1204         SetWinners(frags, checkrules_leaderfrags);
1205
1206         // The top two players have the same amount of lives? No timelimit then,
1207         // enter overtime...
1208
1209         if(checkrules_equality)
1210                 return WINNING_NEVER;
1211
1212         // Top two have different scores? Way to go for our beloved TIMELIMIT!
1213         return WINNING_NO;
1214 }
1215
1216 // DM winning condition: game terminates if a player reached the fraglimit,
1217 // unless the first two players have the same score. The latter case also
1218 // breaks the time limit.
1219 float(float fraglimit) WinningCondition_MaxIndividualScore =
1220 {
1221         float checkrules_oldleaderfrags;
1222         entity head;
1223
1224         checkrules_oldleaderfrags = checkrules_leaderfrags;
1225         checkrules_leaderfrags = 0;
1226         checkrules_equality = FALSE;
1227         FOR_EACH_PLAYER(head)
1228         {
1229                 if(head.frags > checkrules_leaderfrags)
1230                 {
1231                         checkrules_leaderfrags = head.frags;
1232                         checkrules_equality = FALSE;
1233                 }
1234                 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1235                         checkrules_equality = TRUE;
1236         }
1237
1238         if(checkrules_leaderfrags > 0)
1239                 SetWinners(frags, checkrules_leaderfrags);
1240         else
1241                 ClearWinners();
1242
1243         if (!cvar("g_runematch"))
1244                 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1245                 {
1246                         if (checkrules_leaderfrags == fraglimit - 1)
1247                                 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.ogg", 1, ATTN_NONE);
1248                         else if (checkrules_leaderfrags == fraglimit - 2)
1249                                 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.ogg", 1, ATTN_NONE);
1250                         else if (checkrules_leaderfrags == fraglimit - 3)
1251                                 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.ogg", 1, ATTN_NONE);
1252                 }
1253
1254         return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1255 }
1256
1257 float(float fraglimit) WinningConditionBase_Teamplay =
1258 {
1259         tdm_old_score = tdm_max_score;
1260         tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1261
1262         checkrules_equality =
1263         (
1264                 (tdm_max_score > 0)
1265                 &&
1266                 (
1267                           (team1_score == tdm_max_score)
1268                         + (team2_score == tdm_max_score)
1269                         + (team3_score == tdm_max_score)
1270                         + (team4_score == tdm_max_score)
1271                         >= 2));
1272
1273         ClearWinners();
1274         if(tdm_max_score > 0)
1275         {
1276                 if(team1_score == tdm_max_score)
1277                         AddWinners(team, COLOR_TEAM1);
1278                 if(team2_score == tdm_max_score)
1279                         AddWinners(team, COLOR_TEAM2);
1280                 if(team3_score == tdm_max_score)
1281                         AddWinners(team, COLOR_TEAM3);
1282                 if(team4_score == tdm_max_score)
1283                         AddWinners(team, COLOR_TEAM4);
1284         }
1285
1286         if(!cvar("g_runematch") && !cvar("g_domination"))
1287                 if(tdm_max_score != tdm_old_score)
1288                 {
1289                         if(tdm_max_score == fraglimit - 1)
1290                                 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.ogg", 1, ATTN_NONE);
1291                         else if(tdm_max_score == fraglimit - 2)
1292                                 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.ogg", 1, ATTN_NONE);
1293                         else if(tdm_max_score == fraglimit - 3)
1294                                 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.ogg", 1, ATTN_NONE);
1295                 }
1296
1297         return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1298 }
1299
1300 // TDM winning condition: game terminates if a team's score sum reached the
1301 // fraglimit, unless the first two teams have the same total score. The latter
1302 // case also breaks the time limit.
1303 float(float fraglimit) WinningCondition_MaxTeamSum =
1304 {
1305         entity head;
1306
1307         team1_score = team2_score = team3_score = team4_score = 0;
1308
1309         FOR_EACH_PLAYER(head)
1310         {
1311                 if(head.team == COLOR_TEAM1)
1312                         team1_score += head.frags;
1313                 else if(head.team == COLOR_TEAM2)
1314                         team2_score += head.frags;
1315                 else if(head.team == COLOR_TEAM3)
1316                         team3_score += head.frags;
1317                 else if(head.team == COLOR_TEAM4)
1318                         team4_score += head.frags;
1319         }
1320
1321         return WinningConditionBase_Teamplay(fraglimit);
1322 }
1323
1324 // DOM/CTF winning condition: game terminates if the max of a team's players'
1325 // score reached the fraglimit, unless the first two teams have the same
1326 // maximum score. The latter case also breaks the time limit.
1327 float(float fraglimit) WinningCondition_MaxTeamMax =
1328 {
1329         entity head;
1330
1331         team1_score = team2_score = team3_score = team4_score = 0;
1332
1333         FOR_EACH_PLAYER(head)
1334         {
1335                 if(head.team == COLOR_TEAM1)
1336                 {
1337                         if(head.frags > team1_score)
1338                                 team1_score = head.frags;
1339                 }
1340                 else if(head.team == COLOR_TEAM2)
1341                 {
1342                         if(head.frags > team2_score)
1343                                 team2_score = head.frags;
1344                 }
1345                 else if(head.team == COLOR_TEAM3)
1346                 {
1347                         if(head.frags > team3_score)
1348                                 team3_score = head.frags;
1349                 }
1350                 else if(head.team == COLOR_TEAM4)
1351                 {
1352                         if(head.frags > team4_score)
1353                                 team4_score = head.frags;
1354                 }
1355         }
1356
1357         return WinningConditionBase_Teamplay(fraglimit);
1358 }
1359
1360 void print_to(entity e, string s)
1361 {
1362         if(e)
1363                 sprint(e, strcat(s, "\n"));
1364         else
1365                 ServerConsoleEcho(s, TRUE);
1366 }
1367
1368 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1369 {
1370         entity head;
1371         float v;
1372         float teamvalue;
1373         float fragtotal;
1374         string s;
1375         float found;
1376         found = FALSE;
1377         teamvalue = 0;
1378         FOR_EACH_PLAYER(head)
1379         {
1380                 if(!whichteam || head.team == whichteam)
1381                 {
1382                         if(name != "")
1383                                 if(!found)
1384                                         print_to(e, strcat(" ", colorcode, name, ":"));
1385                         found = TRUE;
1386                         fragtotal = fragtotal + head.frags;
1387                         s = ftos(head.frags);
1388                         s = strcat(s, "/", ftos(head.deaths));
1389                         s = strcat(s, " @ ", ftos(head.ping));
1390                         if(clienttype(head) == CLIENTTYPE_BOT)
1391                                 s = strcat(s, "botms");
1392                         else
1393                                 s = strcat(s, "ms");
1394                         v = PlayerValue(head);
1395                         teamvalue += v;
1396                         s = strcat(s, " / ", ftos(v));
1397                         print_to(e, strcat("  ", colorcode, head.netname, colorcode, " (", s, ")"));
1398                 }
1399         }
1400         if(whichteam && found)
1401         {
1402                 s = ftos(fragtotal);
1403                 s = strcat(s, " / ", ftos(teamvalue));
1404                 print_to(e, strcat(colorcode, "  (total: ", s, ")"));
1405         }
1406 }
1407
1408 void PrintScoreboard(entity e)
1409 {
1410         print_to(e, strcat("Time:      ", ftos(time / 60)));
1411         print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1412         print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1413         print_to(e, "Scoreboard:");
1414         if(teams_matter)
1415         {
1416                 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1417                 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1418                 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM3);
1419                 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM4);
1420         }
1421         else
1422         {
1423                 PrintScoreboardFor(e, "", "^7", 0);
1424         }
1425         print_to(e, ".");
1426 }
1427
1428 void RemoveFromMaplist(string m)
1429 {
1430         string result;
1431         float litems;
1432         float i;
1433         float found;
1434
1435         litems = tokenize(cvar_string("g_maplist"));
1436         found = 0;
1437         result = "";
1438         for(i = 0; i < litems; ++i)
1439         {
1440                 m = strcat1(m);
1441                 result = strcat1(result);
1442                 if(argv(i) == m)
1443                         found += 1;
1444                 else
1445                         result = strcat(result, "'", argv(i), "'");
1446         }
1447         if(found)
1448                 cvar_set("g_maplist", result);
1449         ServerConsoleEcho(strcat("Removed ", ftos(found), " items."), FALSE);
1450 }
1451
1452 void AddToMaplist(string m)
1453 {
1454         string result;
1455         float found;
1456         float litems;
1457         float i;
1458         float ipos;
1459         float inserted;
1460
1461         if(!TryFile(strcat("maps/", m, ".mapcfg")))
1462         {
1463                 ServerConsoleEcho("Map not found.", FALSE);
1464                 return;
1465         }
1466
1467         litems = tokenize(cvar_string("g_maplist"));
1468         if(cvar("g_maplist_shuffle"))
1469                 ipos = ceil(random() * (litems + 1)) - 1;
1470         else
1471                 ipos = litems;
1472         found = 0;
1473         inserted = 0;
1474         for(i = 0; i < litems; ++i)
1475         {
1476                 m = strcat1(m);
1477                 if(i == ipos)
1478                 {
1479                         result = strcat(result, "'", m, "'");
1480                         inserted = 1;
1481                 }
1482                 result = strcat(result, "'", argv(i), "'");
1483                 if(argv(i) == m)
1484                         found += 1;
1485         }
1486         if(!inserted)
1487                 result = strcat(result, "'", m, "'");
1488         if(!found)
1489         {
1490                 cvar_set("g_maplist", result);
1491                 ServerConsoleEcho("Map added.", FALSE);
1492         }
1493         else
1494                 ServerConsoleEcho("Map already in list.", FALSE);
1495 }
1496
1497 void MakeFirstInMaplist(string m)
1498 {
1499         if(!TryFile(strcat("maps/", m, ".mapcfg")))
1500         {
1501                 ServerConsoleEcho("Map not found.", FALSE);
1502                 return;
1503         }
1504
1505         m = strzone(m);
1506         RemoveFromMaplist(m);
1507         cvar_set("g_maplist", strcat("'", m, "'", cvar_string("g_maplist")));
1508         strunzone(m);
1509
1510         ServerConsoleEcho("Map added as first one.", FALSE);
1511 }
1512
1513 void ShuffleMaplist()
1514 {
1515         string result;
1516         float start;
1517         float litems;
1518         float selected;
1519         float i;
1520
1521         result = cvar_string("g_maplist");
1522         litems = tokenize(result);
1523
1524         for(start = 0; start < litems - 1; ++start)
1525         {
1526                 result = "";
1527
1528                 // select a random item
1529                 selected = ceil(random() * (litems - start) + start) - 1;
1530
1531                 // shift this item to the place start
1532                 for(i = 0; i < start; ++i)
1533                         result = strcat(result, "'", argv(i), "'");
1534                 result = strcat(result, "'", argv(selected), "'");
1535                 for(i = start; i < litems; ++i)
1536                         if(i != selected)
1537                                 result = strcat(result, "'", argv(i), "'");
1538
1539                 litems = tokenize(result);
1540
1541                 //dprint(result, "\n");
1542         }
1543
1544         cvar_set("g_maplist", result);
1545 }
1546
1547 void() HandleMaplistShuffleCommands =
1548 {
1549         // automatically shuffle when setting g_maplist_shuffle
1550         if(cvar_string("_g_maplist_add") != "")
1551         {
1552                 AddToMaplist(cvar_string("_g_maplist_add"));
1553                 cvar_set("_g_maplist_add", "");
1554         }
1555         if(cvar_string("_g_maplist_remove") != "")
1556         {
1557                 RemoveFromMaplist(cvar_string("_g_maplist_remove"));
1558                 cvar_set("_g_maplist_remove", "");
1559         }
1560         if(cvar_string("_g_maplist_putfirst") != "")
1561         {
1562                 MakeFirstInMaplist(cvar_string("_g_maplist_putfirst"));
1563                 cvar_set("_g_maplist_putfirst", "");
1564         }
1565         if(cvar("_g_maplist_shufflenow") || (cvar("g_maplist_shuffle") && !cvar("_g_maplist_have_shuffled")))
1566         {
1567                 ShuffleMaplist();
1568                 cvar_set("_g_maplist_shufflenow", "0");
1569                 cvar_set("_g_maplist_have_shuffled", "1");
1570                 ServerConsoleEcho("Shuffled map list.", FALSE);
1571         }
1572         if(cvar("_g_maplist_have_shuffled"))
1573                 if(!cvar("g_maplist_shuffle"))
1574                         cvar_set("_g_maplist_have_shuffled", "0");
1575 }
1576
1577 /*
1578 ============
1579 CheckRules_World
1580
1581 Exit deathmatch games upon conditions
1582 ============
1583 */
1584 void() CheckRules_World =
1585 {
1586         local float status;
1587         local float timelimit;
1588         local float fraglimit;
1589
1590         VoteThink();
1591
1592         SetDefaultAlpha();
1593
1594         if (intermission_running)
1595                 if (time >= intermission_exittime + 60)
1596                 {
1597                         if(!DoNextMapOverride())
1598                                 GotoNextMap();
1599                         return;
1600                 }
1601
1602         if (gameover)   // someone else quit the game already
1603                 return;
1604
1605         DumpStats();
1606
1607         if(cvar("_scoreboard"))
1608         {
1609                 cvar_set("_scoreboard", "0");
1610                 PrintScoreboard(world);
1611         }
1612
1613         HandleMaplistShuffleCommands();
1614
1615         timelimit = cvar("timelimit") * 60;
1616         fraglimit = cvar("fraglimit");
1617
1618         if(checkrules_overtimeend)
1619         {
1620                 if(!checkrules_overtimewarning)
1621                 {
1622                         checkrules_overtimewarning = TRUE;
1623                         //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.ogg", 1, ATTN_NONE);
1624                         bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1625                 }
1626         }
1627         else
1628         {
1629                 if (timelimit && time >= timelimit)
1630                         InitiateOvertime();
1631         }
1632
1633         if (checkrules_overtimeend && time >= checkrules_overtimeend)
1634         {
1635                 NextLevel();
1636                 return;
1637         }
1638
1639         if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1640         {
1641                 checkrules_oneminutewarning = TRUE;
1642                 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.ogg", 1, ATTN_NONE);
1643         }
1644
1645         status = WINNING_NO;
1646         if(cvar("g_lms"))
1647         {
1648                 status = WinningCondition_LMS();
1649         }
1650         else
1651         {
1652                 if(teams_matter)
1653                 {
1654                         if(cvar("g_tdm") || cvar("g_runematch") || cvar("g_ctf") || cvar("g_domination"))
1655                                 status = WinningCondition_MaxTeamSum(fraglimit);
1656                         //else if()
1657                         //      status = WinningCondition_MaxTeamMax(fraglimit);
1658                         else
1659                         {
1660                                 dprint("div0: How can this happen?\n");
1661                                 status = WinningCondition_MaxTeamMax(fraglimit);
1662                         }
1663                 }
1664                 else
1665                         status = WinningCondition_MaxIndividualScore(fraglimit);
1666         }
1667
1668         if(status == WINNING_STARTOVERTIME)
1669         {
1670                 status = WINNING_NEVER;
1671                 InitiateOvertime();
1672         }
1673
1674         if(status == WINNING_NEVER)
1675                 // equality cases! Nobody wins if the overtime ends in a draw.
1676                 ClearWinners();
1677
1678         if(checkrules_overtimeend)
1679                 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1680                         status = WINNING_YES;
1681
1682         if(status == WINNING_YES)
1683                 NextLevel();
1684 };
1685
1686 float randsel_value;
1687 float randsel_priority;
1688 float randsel_count;
1689 void RandSel_Init()
1690 {
1691         randsel_value = -1;
1692         randsel_priority = -1;
1693         randsel_count = -1;
1694 }
1695 void RandSel_Add(float priority, float value)
1696 {
1697         if(priority > randsel_priority)
1698         {
1699                 randsel_priority = priority;
1700                 randsel_value = value;
1701                 randsel_count = 1;
1702         }
1703         else if(priority == randsel_priority)
1704         {
1705                 randsel_count += 1;
1706                 if(ceil(random() * randsel_count) == 1)
1707                         randsel_value = value;
1708         }
1709 }
1710
1711 float mapvote_nextthink;
1712 float mapvote_initialized;
1713 float mapvote_keeptwotime;
1714 float mapvote_timeout;
1715 string mapvote_message;
1716
1717 #define MAPVOTE_COUNT 10
1718 float mapvote_count;
1719 string mapvote_maps[MAPVOTE_COUNT];
1720 float mapvote_maps_suggested[MAPVOTE_COUNT];
1721 string mapvote_suggestions[MAPVOTE_COUNT];
1722 float mapvote_suggestion_ptr;
1723 string mapvote_fillstr;
1724 float mapvote_maxlen;
1725 float mapvote_voters;
1726 float mapvote_votes[MAPVOTE_COUNT];
1727 .float mapvote;
1728
1729 void MapVote_ClearAllVotes()
1730 {
1731         FOR_EACH_CLIENT(other)
1732                 other.mapvote = 0;
1733 }
1734
1735 string MapVote_Suggest(string m)
1736 {
1737         float i;
1738         if(m == "")
1739                 return "That's not how to use this command.";
1740         if(!cvar("g_maplist_votable_suggestions"))
1741                 return "Suggestions are not accepted on this server.";
1742         if(mapvote_initialized)
1743                 return "Can't suggest - voting is already in progress!";
1744         if(!TryFile(strcat("maps/", m, ".mapcfg")))
1745                 return "The map you suggested is not available on this server.";
1746         for(i = 0; i < mapvote_suggestion_ptr; ++i)
1747                 if(mapvote_suggestions[i] == m)
1748                         return "This map was already suggested.";
1749         if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1750         {
1751                 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1752         }
1753         else
1754         {
1755                 i = mapvote_suggestion_ptr;
1756                 mapvote_suggestion_ptr += 1;
1757         }
1758         if(mapvote_suggestions[i] != "")
1759                 strunzone(mapvote_suggestions[i]);
1760         mapvote_suggestions[i] = strzone(m);
1761         GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid), ":", self.netname), TRUE);
1762         return "Suggestion accepted.";
1763 }
1764
1765 void MapVote_AddVotable(string nextMap, float isSuggestion)
1766 {
1767         float j;
1768         if(nextMap == "")
1769                 return;
1770         for(j = 0; j < mapvote_count; ++j)
1771                 if(mapvote_maps[j] == nextMap)
1772                         return;
1773         if(strlen(nextMap) > mapvote_maxlen)
1774                 mapvote_maxlen = strlen(nextMap);
1775         mapvote_maps[mapvote_count] = strzone(nextMap);
1776         mapvote_maps_suggested[mapvote_count] = isSuggestion;
1777         mapvote_count += 1;
1778 }
1779
1780 void MapVote_Init()
1781 {
1782         float i;
1783         float nmax, smax;
1784
1785         MapVote_ClearAllVotes();
1786
1787         nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1788         smax = min(nmax, cvar("g_maplist_votable_suggestions"));
1789         mapvote_count = 0;
1790
1791         for(i = 0; i < 100 && mapvote_count < smax; ++i)
1792                 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1793
1794         for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1795                 MapVote_AddVotable(GetNextMap(), FALSE);
1796
1797         if(mapvote_count == 0)
1798         {
1799                 bprint( "Maplist contains no single playable map!  Resetting it to default map list.\n" );
1800                 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1801                 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1802                         MapVote_AddVotable(GetNextMap(), FALSE);
1803         }
1804
1805         //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1806
1807         mapvote_fillstr = " ";
1808         while(strlen(mapvote_fillstr) < mapvote_maxlen + 16)
1809                 mapvote_fillstr = strcat(mapvote_fillstr, mapvote_fillstr);
1810         mapvote_fillstr = strzone(mapvote_fillstr);
1811
1812         mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1813         mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1814         if(mapvote_count < 3 || mapvote_keeptwotime <= time)
1815                 mapvote_keeptwotime = 0;
1816         mapvote_message = "Choose a map and press its key!";
1817 }
1818 float MapVote_Finished(float mappos)
1819 {
1820         string result;
1821         float i;
1822
1823         result = strcat(":vote:finished:", mapvote_maps[mappos]);
1824         result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1825         for(i = 0; i < mapvote_count; ++i)
1826                 if(i != mappos)
1827                         if(mapvote_maps[i] != "")
1828                         {
1829                                 result = strcat(result, ":", mapvote_maps[i]);
1830                                 result = strcat(result, ":", ftos(mapvote_votes[i]));
1831                         }
1832         GameLogEcho(result, FALSE);
1833         if(mapvote_maps_suggested[mappos])
1834                 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
1835
1836         FOR_EACH_REALCLIENT(other)
1837                 FixClientCvars(other);
1838
1839         Map_Goto_SetStr(mapvote_maps[mappos]);
1840         Map_Goto();
1841         return TRUE;
1842 }
1843 void MapVote_CheckRules_1()
1844 {
1845         float i;
1846
1847         for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1848         {
1849                 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1850                 mapvote_votes[i] = 0;
1851         }
1852
1853         mapvote_voters = 0;
1854         FOR_EACH_REALCLIENT(other)
1855         {
1856                 ++mapvote_voters;
1857                 if(other.mapvote)
1858                 {
1859                         i = other.mapvote - 1;
1860                         //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1861                         mapvote_votes[i] = mapvote_votes[i] + 1;
1862                 }
1863         }
1864 }
1865
1866 float MapVote_CheckRules_2()
1867 {
1868         float i;
1869         float firstPlace, secondPlace;
1870         float firstPlaceVotes, secondPlaceVotes;
1871         string result;
1872
1873         RandSel_Init();
1874         for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1875                 RandSel_Add(mapvote_votes[i], i);
1876         firstPlace = randsel_value;
1877         firstPlaceVotes = randsel_priority;
1878         //dprint("First place: ", ftos(firstPlace), "\n");
1879         //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1880
1881         RandSel_Init();
1882         for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1883                 if(i != firstPlace)
1884                         RandSel_Add(mapvote_votes[i], i);
1885         secondPlace = randsel_value;
1886         secondPlaceVotes = randsel_priority;
1887         //dprint("Second place: ", ftos(secondPlace), "\n");
1888         //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1889
1890         if(firstPlace == -1)
1891                 error("No first place in map vote... WTF?");
1892
1893         if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters - firstPlaceVotes) < firstPlaceVotes)
1894                 return MapVote_Finished(firstPlace);
1895
1896         if(mapvote_keeptwotime)
1897                 if(time > mapvote_keeptwotime || (mapvote_voters - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
1898                 {
1899                         mapvote_message = "Now decide between the TOP TWO!";
1900                         mapvote_keeptwotime = 0;
1901                         result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
1902                         result = strcat(result, ":", ftos(firstPlaceVotes));
1903                         result = strcat(result, ":", mapvote_maps[secondPlace]);
1904                         result = strcat(result, ":", ftos(secondPlaceVotes), "::");
1905                         for(i = 0; i < mapvote_count; ++i)
1906                                 if(i != firstPlace)
1907                                         if(i != secondPlace)
1908                                                 if(mapvote_maps[i] != "")
1909                                                 {
1910                                                         result = strcat(result, ":", mapvote_maps[i]);
1911                                                         result = strcat(result, ":", ftos(mapvote_votes[i]));
1912                                                         strunzone(mapvote_maps[i]);
1913                                                         mapvote_maps[i] = "";
1914                                                 }
1915                         GameLogEcho(result, FALSE);
1916                 }
1917
1918         return FALSE;
1919 }
1920 void MapVote_Tick()
1921 {
1922         string msgstr;
1923         string tmp;
1924         float i;
1925         float keeptwo;
1926
1927         keeptwo = mapvote_keeptwotime;
1928         MapVote_CheckRules_1(); // count
1929         if(MapVote_CheckRules_2()) // decide
1930                 return;
1931
1932         FOR_EACH_REALCLIENT(other)
1933         {
1934                 // hide scoreboard again
1935                 if(other.health != 2342)
1936                 {
1937                         other.health = 2342;
1938                         other.impulse = 0;
1939                         if(clienttype(other) == CLIENTTYPE_REAL)
1940                         {
1941                                 stuffcmd(other, "\nin_bind 7 1 \"impulse 1\"; in_bind 7 2 \"impulse 2\"; in_bind 7 3 \"impulse 3\"; in_bind 7 4 \"impulse 4\"; in_bind 7 5 \"impulse 5\"; in_bind 7 6 \"impulse 6\"; in_bind 7 7 \"impulse 7\"; in_bind 7 8 \"impulse 8\"; in_bind 7 9 \"impulse 9\"; in_bind 7 0 \"impulse 10\"; in_bind 7 KP_1 \"impulse 1\"; in_bind 7 KP_2 \"impulse 2\"; in_bind 7 KP_3 \"impulse 3\"; in_bind 7 KP_4 \"impulse 4\"; in_bind 7 KP_5 \"impulse 5\"; in_bind 7 KP_6 \"impulse 6\"; in_bind 7 KP_7 \"impulse 7\"; in_bind 7 KP_8 \"impulse 8\"; in_bind 7 KP_9 \"impulse 9\"; in_bind 7 KP_0 \"impulse 10\"; in_bindmap 7 0\n");
1942                                 msg_entity = other;
1943                                 WriteByte(MSG_ONE, SVC_FINALE);
1944                                 WriteString(MSG_ONE, "");
1945                         }
1946                 }
1947
1948                 // notify about keep-two
1949                 if(keeptwo != 0 && mapvote_keeptwotime == 0)
1950                         stuffcmd(other, "\nplay2 misc/invshot.wav\n");
1951
1952                 // clear possibly invalid votes
1953                 if(mapvote_maps[other.mapvote - 1] == "")
1954                         other.mapvote = 0;
1955                 // use impulses as new vote
1956                 if(other.impulse >= 1 && other.impulse <= mapvote_count)
1957                         if(mapvote_maps[other.impulse - 1] != "")
1958                                 other.mapvote = other.impulse;
1959                 other.impulse = 0;
1960         }
1961
1962         MapVote_CheckRules_1(); // just count
1963
1964         FOR_EACH_REALCLIENT(other)
1965         {
1966                 // display voting screen
1967                 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
1968                 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
1969                 msgstr = strcat(msgstr, mapvote_message);
1970                 msgstr = strcat(msgstr, "\n\n");
1971                 for(i = 0; i < mapvote_count; ++i)
1972                         if(mapvote_maps[i] == "")
1973                                 msgstr = strcat(msgstr, "\n");
1974                         else
1975                         {
1976                                 tmp = mapvote_maps[i];
1977                                 tmp = strcat(tmp, substring(mapvote_fillstr, 0, mapvote_maxlen  - strlen(tmp)));
1978                                 tmp = strcat(ftos(math_mod(i + 1, 10)), ": ", tmp);
1979                                 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
1980                                 if(mapvote_votes[i] != 1)
1981                                         tmp = strcat(tmp, "s");
1982                                 tmp = strcat(tmp, ")");
1983                                 tmp = strcat(tmp, substring(mapvote_fillstr, 0, mapvote_maxlen + 15 - strlen(tmp)));
1984                                 if(other.mapvote == i + 1)
1985                                         msgstr = strcat(msgstr, "^3> ", tmp, "\n");
1986                                 else
1987                                         msgstr = strcat(msgstr, "^7  ", tmp, "\n");
1988                         }
1989                 i = ceil(mapvote_timeout - time);
1990                 msgstr = strcat(msgstr, "\n\n", ftos(i), " second");
1991                 if(i != 1)
1992                         msgstr = strcat(msgstr, "s");
1993                 msgstr = strcat(msgstr, " left");
1994
1995                 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
1996         }
1997 }
1998 void MapVote_Think()
1999 {
2000         if(alreadychangedlevel)
2001                 return;
2002         
2003         if(time < mapvote_nextthink)
2004                 return;
2005         //dprint("tick\n");
2006
2007         mapvote_nextthink = time + 0.5;
2008
2009         if(!mapvote_initialized)
2010         {
2011                 mapvote_initialized = TRUE;
2012                 if(DoNextMapOverride())
2013                 {
2014                         alreadychangedlevel = TRUE;
2015                         return;
2016                 }
2017                 if(!cvar("g_maplist_votable"))
2018                 {
2019                         GotoNextMap();
2020                         return;
2021                 }
2022                 MapVote_Init();
2023         }
2024
2025         MapVote_Tick();
2026 };
2027
2028
2029
2030 float beamindex_modulo;
2031 void EndFrame()
2032 {
2033         entity e;
2034         string value;
2035         vector mi, ma;
2036         float i;
2037
2038         value = cvar_string("_entityboxes_for");
2039         if(value == "")
2040                 return;
2041
2042         i = beamindex_modulo;
2043         beamindex_modulo += 1;
2044         if(beamindex_modulo >= 32)
2045                 beamindex_modulo = 0;
2046         for(e = world; (e = find(e, classname, value)) != world; )
2047         {
2048                 mi = e.absmin;
2049                 ma = e.absmax;
2050                 i = i + 1;
2051                 if(i >= 32)
2052                 {
2053                         i = 0;
2054                         te_lightning1(world, mi_x * '1 0 0' + mi_y * '0 1 0' + mi_z * '0 0 1', ma_x * '1 0 0' + mi_y * '0 1 0' + mi_z * '0 0 1');
2055                         te_lightning1(world, mi_x * '1 0 0' + mi_y * '0 1 0' + ma_z * '0 0 1', ma_x * '1 0 0' + mi_y * '0 1 0' + ma_z * '0 0 1');
2056                         te_lightning1(world, mi_x * '1 0 0' + ma_y * '0 1 0' + mi_z * '0 0 1', ma_x * '1 0 0' + ma_y * '0 1 0' + mi_z * '0 0 1');
2057                         te_lightning1(world, mi_x * '1 0 0' + ma_y * '0 1 0' + ma_z * '0 0 1', ma_x * '1 0 0' + ma_y * '0 1 0' + ma_z * '0 0 1');
2058                         te_lightning1(world, mi_x * '1 0 0' + mi_y * '0 1 0' + mi_z * '0 0 1', mi_x * '1 0 0' + ma_y * '0 1 0' + mi_z * '0 0 1');
2059                         te_lightning1(world, mi_x * '1 0 0' + mi_y * '0 1 0' + ma_z * '0 0 1', mi_x * '1 0 0' + ma_y * '0 1 0' + ma_z * '0 0 1');
2060                         te_lightning1(world, ma_x * '1 0 0' + mi_y * '0 1 0' + mi_z * '0 0 1', ma_x * '1 0 0' + ma_y * '0 1 0' + mi_z * '0 0 1');
2061                         te_lightning1(world, ma_x * '1 0 0' + mi_y * '0 1 0' + ma_z * '0 0 1', ma_x * '1 0 0' + ma_y * '0 1 0' + ma_z * '0 0 1');
2062                         te_lightning1(world, mi_x * '1 0 0' + mi_y * '0 1 0' + mi_z * '0 0 1', mi_x * '1 0 0' + mi_y * '0 1 0' + ma_z * '0 0 1');
2063                         te_lightning1(world, mi_x * '1 0 0' + ma_y * '0 1 0' + mi_z * '0 0 1', mi_x * '1 0 0' + ma_y * '0 1 0' + ma_z * '0 0 1');
2064                         te_lightning1(world, ma_x * '1 0 0' + mi_y * '0 1 0' + mi_z * '0 0 1', ma_x * '1 0 0' + mi_y * '0 1 0' + ma_z * '0 0 1');
2065                         te_lightning1(world, ma_x * '1 0 0' + ma_y * '0 1 0' + mi_z * '0 0 1', ma_x * '1 0 0' + ma_y * '0 1 0' + ma_z * '0 0 1');
2066                 }
2067         }
2068 }