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