1 float SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS = 1;
2 string redirection_target;
3 float world_initialized;
9 float() DoNextMapOverride;
11 void SetDefaultAlpha()
13 if(cvar("g_running_guns"))
15 default_player_alpha = -1;
16 default_weapon_alpha = +1;
20 default_player_alpha = cvar("g_balance_cloaked_alpha");
21 default_weapon_alpha = default_player_alpha;
25 default_player_alpha = cvar("g_player_alpha");
26 if(default_player_alpha <= 0)
27 default_player_alpha = 1;
28 default_weapon_alpha = default_player_alpha;
32 void fteqcc_testbugs()
36 if(!cvar("developer_fteqccbugs"))
39 dprint("*** fteqcc test: checking for bugs...\n");
43 if(sqrt(a) - sqrt(b - a) == 0)
44 dprint("*** fteqcc test: found same-function-twice bug\n");
46 dprint("*** fteqcc test: same-function-twice bug got FINALLY FIXED! HOORAY!\n");
50 world.enemy.cnt += 10;
51 if(world.cnt > 0.2 || world.cnt < -0.2) // don't error out if it's just roundoff errors
52 dprint("*** fteqcc test: found += bug\n");
54 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
59 * Takes care of pausing and unpausing the game.
60 * Centerprints the information about an upcoming or active timeout to all active
61 * players. Also plays reminder sounds.
63 void timeoutHandler_Think() {
66 if (timeoutStatus == 1) {
67 if (remainingLeadTime > 0) {
68 //centerprint the information to every player
69 timeStr = getTimeoutText(0);
70 FOR_EACH_REALCLIENT(plr) {
71 if(plr.classname == "player") {
72 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
75 remainingLeadTime -= 1;
76 //think again in 1 second:
77 self.nextthink = time + 1;
82 cvar_set("slowmo", ftos(TIMEOUT_SLOWMO_VALUE));
83 //copy .v_angle to .lastV_angle for every player in order to fix their view during pause (see PlayerPreThink)
84 FOR_EACH_REALPLAYER(plr) {
85 plr.lastV_angle = plr.v_angle;
87 self.nextthink = time;
90 else if (timeoutStatus == 2) {
91 if (remainingTimeoutTime > 0) {
92 timeStr = getTimeoutText(0);
93 FOR_EACH_REALCLIENT(plr) {
94 if(plr.classname == "player") {
95 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
98 if(remainingTimeoutTime == cvar("sv_timeout_resumetime")) { //play a warning sound when only <sv_timeout_resumetime> seconds are left
99 play2all("announcer/robotic/prepareforbattle.wav");
101 remainingTimeoutTime -= 1;
102 self.nextthink = time + TIMEOUT_SLOWMO_VALUE;
105 //unpause the game again
106 remainingTimeoutTime = timeoutStatus = 0;
107 cvar_set("slowmo", ftos(orig_slowmo));
108 //and unlock the fixed view again once there is no timeout active anymore
109 FOR_EACH_REALPLAYER(plr) {
110 plr.fixangle = FALSE;
112 //get rid of the countdown message
113 FOR_EACH_REALCLIENT(plr) {
114 if(plr.classname == "player") {
115 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
123 else if (timeoutStatus == 0) { //if a player called the resumegame command (which set timeoutStatus to 0 already)
124 FOR_EACH_REALCLIENT(plr) {
125 if(plr.classname == "player") {
126 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
138 cvar_set("_sv_init", "0");
139 if(cvar("g_maplist_shuffle"))
141 tokenizebyseparator(cvar_string("g_maplist"), " ");
143 cvar_set("nextmap", argv(0));
146 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
148 if(!DoNextMapOverride())
157 void cvar_changes_init()
164 strunzone(cvar_changes);
165 cvar_changes = string_null;
166 fh = fopen("cvars.txt", FILE_READ);
169 while((s = fgets(fh)))
178 d = cvar_defstring(v);
181 cvar_changes = strcat(cvar_changes, k, " \"", v, "\" // ", d, "\n");
182 if(strlen(cvar_changes) > 16384)
184 cvar_changes = "// too many settings have been changed to show them here\n";
190 cvar_changes = strzone(cvar_changes);
193 float world_already_spawned;
194 void RegisterWeapons();
196 void spawnfunc_worldspawn (void)
201 dprint_load(); // load dprint status from cvar
203 if(world_already_spawned)
204 error("world already spawned - you may have EXACTLY ONE worldspawn!");
205 world_already_spawned = TRUE;
207 compressShortVector_init();
210 head = nextent(world);
215 head = nextent(head);
218 // needs to be done so early as they would still spawn
225 ServerProgsDB = db_create();
227 ServerProgsDB = db_load("server.db");
230 TODO sound pack system
231 // initialize sound pack system
232 soundpack = cvar_string("g_soundpack");
234 soundpack = strcat(soundpack, "/");
235 soundpack = strzone(soundpack);
241 // 1 FLICKER (first variety)
242 lightstyle(1, "mmnmmommommnonmmonqnmmo");
244 // 2 SLOW STRONG PULSE
245 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
247 // 3 CANDLE (first variety)
248 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
251 lightstyle(4, "mamamamamama");
254 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
256 // 6 FLICKER (second variety)
257 lightstyle(6, "nmonqnmomnmomomno");
259 // 7 CANDLE (second variety)
260 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
262 // 8 CANDLE (third variety)
263 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
265 // 9 SLOW STROBE (fourth variety)
266 lightstyle(9, "aaaaaaaazzzzzzzz");
268 // 10 FLUORESCENT FLICKER
269 lightstyle(10, "mmamammmmammamamaaamammma");
271 // 11 SLOW PULSE NOT FADE TO BLACK
272 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
274 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
279 if(cvar("g_campaign"))
286 bot_waypoints_for_items = cvar("g_waypoints_for_items");
287 if(bot_waypoints_for_items == 1)
288 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
289 bot_waypoints_for_items = 0;
291 // for setting by mapinfo
292 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
293 cvar_set("sv_q3acompat_machineshotgunswap", "0");
297 WaypointSprite_Init();
302 GameLogInit(); // prepare everything
303 if(cvar("sv_eventlog"))
305 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
306 s = strcat(s, ftos(random()));
307 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
308 s = ":gameinfo:mutators:LIST";
309 if(cvar("g_grappling_hook"))
310 s = strcat(s, ":grappling_hook");
311 if(!cvar("g_use_ammunition"))
312 s = strcat(s, ":no_use_ammunition");
313 if(!cvar("g_pickup_items"))
314 s = strcat(s, ":no_pickup_items");
315 if(cvar("g_instagib"))
316 s = strcat(s, ":instagib");
317 if(cvar("g_rocketarena"))
318 s = strcat(s, ":rockerarena");
320 s = strcat(s, ":nixnex");
321 if(cvar("g_vampire"))
322 s = strcat(s, ":vampire");
323 if(cvar("g_laserguided_missile"))
324 s = strcat(s, ":laserguided_missile");
325 if(cvar("g_norecoil"))
326 s = strcat(s, ":norecoil");
328 s = strcat(s, ":midair");
329 if(cvar("g_minstagib"))
330 s = strcat(s, ":minstagib");
332 GameLogEcho(":gameinfo:end");
335 cvar_set("nextmap", "");
339 if(cvar("g_campaign"))
346 //initialise globals related to sv_timeout
347 sys_ticrate = cvar("sys_ticrate");
348 orig_slowmo = cvar("slowmo");
351 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
353 //if tourney is used map starts in warmup mode. if this mode shall stay unlimited, reset timelimit, but save the original one
355 timelimit_orig = cvar("timelimit");
356 cvar_set("timelimit", "0");
359 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
361 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
364 while((s = fgets(fd)))
371 print("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
372 print(" cdtrack ", argv(2), "\n");
374 else if(argv(0) == "fog")
376 print("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
377 print(" \"fog\" \"", s, "\"\n");
379 else if(argv(0) == "set")
381 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
382 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
384 else if(argv(0) != "//")
386 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
387 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
394 addstat(STAT_SYS_TICRATE, AS_FLOAT, stat_sys_ticrate);
395 addstat(STAT_WEAPONS, AS_INT, weapons);
396 addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
399 next_pingtime = time + 5;
400 world_initialized = 1;
402 InitializeEntity(self, cvar_changes_init, INITPRIO_CVARS);
405 void spawnfunc_light (void)
407 //makestatic (self); // Who the f___ did that?
411 float TryFile( string pFilename )
414 dprint("TryFile(\"", pFilename, "\")\n");
415 lHandle = fopen( pFilename, FILE_READ );
416 if( lHandle != -1 ) {
426 return GametypeNameFromType(game);
429 string getmapname_stored;
435 float Map_Count, Map_Current;
436 string Map_Current_Name;
438 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
439 float GetMaplistPosition()
445 idx = cvar("g_maplist_index");
452 for(pos = 0; pos < Map_Count; ++pos)
456 // resume normal maplist rotation if current map is not in g_maplist
460 float MapHasRightSize(string map)
463 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
464 if(cvar("g_maplist_check_waypoints"))
466 dprint("checkwp "); dprint(map);
467 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
470 dprint(": no waypoints\n");
473 dprint(": has waypoints\n");
477 // open map size restriction file
478 dprint("opensize "); dprint(map);
479 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
482 float mapmin, mapmax;
484 mapmin = stof(fgets(fh));
485 mapmax = stof(fgets(fh));
487 if(player_count < mapmin)
489 dprint("not enough\n");
492 if(player_count > mapmax)
494 dprint("too many\n");
497 dprint("right size\n");
500 dprint(": not found\n");
504 string Map_Filename(float position)
506 return strcat("maps/", argv(position), ".bsp");
509 string strwords(string s, float w)
512 for(endpos = 0; w && endpos >= 0; --w)
513 endpos = strstrofs(s, " ", endpos + 1);
517 return substring(s, 0, endpos);
520 float strhasword(string s, string w)
522 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
525 void Map_MarkAsRecent(string m)
527 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
530 float Map_IsRecent(string m)
532 return strhasword(cvar_string("g_maplist_mostrecent"), m);
535 float Map_Check(float position, float pass)
539 map_next = argv(position);
542 if(map_next == Map_Current_Name) // same map again in first pass?
544 if(Map_IsRecent(map_next))
547 filename = Map_Filename(position);
548 if(MapInfo_CheckMap(map_next))
552 if(MapHasRightSize(map_next))
557 dprint( "Couldn't select '", filename, "'..\n" );
562 void Map_Goto_SetStr(string nextmapname)
564 if(getmapname_stored != "")
565 strunzone(getmapname_stored);
566 if(nextmapname == "")
567 getmapname_stored = "";
569 getmapname_stored = strzone(nextmapname);
572 void Map_Goto_SetFloat(float position)
574 cvar_set("g_maplist_index", ftos(position));
575 Map_Goto_SetStr(argv(position));
580 // settings persist, except...
581 if(cvar("g_campaign"))
582 localcmd("\nexec mutator_reset.cfg\n");
583 localcmd("\nsettemp_restore\n");
588 Map_MarkAsRecent(getmapname_stored);
590 MapInfo_LoadMap(getmapname_stored);
593 // return codes of map selectors:
594 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
595 // -2 = permanent failure
596 float() MaplistMethod_Iterate = // usual method
600 for(pass = 1; pass <= 2; ++pass)
602 for(i = 1; i < Map_Count; ++i)
605 mapindex = mod(i + Map_Current, Map_Count);
606 if(Map_Check(mapindex, pass))
613 float() MaplistMethod_Repeat = // fallback method
615 if(Map_Check(Map_Current, 2))
620 float() MaplistMethod_Random = // random map selection
626 for(i = 0; i <= imax; ++i)
629 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
630 if(Map_Check(mapindex, 1))
636 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
637 // the exponent sets a bias on the map selection:
638 // the higher the exponent, the less likely "shortly repeated" same maps are
640 float i, j, imax, insertpos;
644 for(i = 0; i <= imax; ++i)
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");
654 // insert the current map there
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 newlist = substring(newlist, 1, strlen(newlist) - 1);
662 cvar_set("g_maplist", newlist);
663 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
665 // NOTE: the selected map has just been inserted at (insertpos-1)th position
666 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
667 if(Map_Check(Map_Current, 1))
676 temp = cvar_string("g_maplist");
677 Map_Count = tokenizebyseparator(temp, " ");
680 bprint( "Maplist is empty! Resetting it to default map list.\n" );
681 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
682 localcmd("\nmenu_cmd sync\n");
683 Map_Count = tokenizebyseparator(temp, " ");
686 error("empty maplist, cannot select a new map");
687 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
690 strunzone(Map_Current_Name);
691 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
692 // this may or may not be correct, but who cares, in the worst case a map
693 // isn't chosen in the first pass that should have been
704 if(cvar("g_maplist_shuffle") > 0)
705 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
708 if(cvar("g_maplist_selectrandom"))
709 nextMap = MaplistMethod_Random();
712 nextMap = MaplistMethod_Iterate();
715 nextMap = MaplistMethod_Repeat();
719 Map_Goto_SetFloat(nextMap);
720 return getmapname_stored;
726 float DoNextMapOverride()
728 if(cvar("g_campaign"))
730 CampaignPostIntermission();
731 alreadychangedlevel = TRUE;
734 if(cvar("quit_when_empty"))
736 if(player_count <= currentbots)
739 alreadychangedlevel = TRUE;
743 if(cvar_string("quit_and_redirect") != "")
745 redirection_target = strzone(cvar_string("quit_and_redirect"));
746 alreadychangedlevel = TRUE;
749 if (cvar("samelevel")) // if samelevel is set, stay on same level
751 // 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)
752 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
753 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
754 localcmd("restart\n");
755 //changelevel (mapname);
756 alreadychangedlevel = TRUE;
759 if(cvar_string("nextmap") != "")
760 if(MapInfo_CheckMap(cvar_string("nextmap")))
762 Map_Goto_SetStr(cvar_string("nextmap"));
764 alreadychangedlevel = TRUE;
767 if(cvar("lastlevel"))
770 localcmd("set lastlevel 0\ntogglemenu\n");
771 alreadychangedlevel = TRUE;
779 //local string nextmap;
780 //local float n, nummaps;
782 if (alreadychangedlevel)
784 alreadychangedlevel = TRUE;
790 for(allowReset = 1; allowReset >= 0; --allowReset)
792 nextMap = GetNextMap();
798 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
799 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
800 localcmd("\nmenu_cmd sync\n");
804 error("Everything is broken - not even the default map list works. Please report this to the developers.");
816 When the player presses attack or jump, change to the next level
819 .float autoscreenshot;
820 void() MapVote_Start;
821 void() MapVote_Think;
822 float mapvote_initialized;
823 void IntermissionThink()
825 FixIntermissionClient(self);
827 if(cvar("sv_autoscreenshot"))
828 if(self.autoscreenshot > 0)
829 if(time > self.autoscreenshot)
831 self.autoscreenshot = -1;
832 if(clienttype(self) == CLIENTTYPE_REAL)
833 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
837 if (time < intermission_exittime)
840 if(!mapvote_initialized)
841 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
851 Returns the entity to view from
855 entity FindIntermission()
860 // look for info_intermission first
861 spot = find (world, classname, "info_intermission");
863 { // pick a random one
867 spot = find (spot, classname, "info_intermission");
869 spot = find (spot, classname, "info_intermission");
875 // then look for the start position
876 spot = find (world, classname, "info_player_start");
880 // testinfo_player_start is only found in regioned levels
881 spot = find (world, classname, "testplayerstart");
885 // then look for the start position
886 spot = find (world, classname, "info_player_deathmatch");
890 //objerror ("FindIntermission: no spot");
896 ===============================================================================
900 ===============================================================================
903 void DumpStats(float final)
907 local float to_console;
908 local float to_eventlog;
912 to_console = cvar("sv_logscores_console");
913 to_eventlog = cvar("sv_eventlog");
914 to_file = cvar("sv_logscores_file");
918 to_console = TRUE; // always print printstats replies
919 to_eventlog = FALSE; // but never print them to the event log
923 if(cvar("sv_eventlog_console"))
924 to_console = FALSE; // otherwise we get the output twice
930 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
938 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
942 fputs(file, strcat(s, "\n"));
945 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
950 fputs(file, strcat(s, "\n"));
952 FOR_EACH_CLIENT(other)
954 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
956 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
957 s = strcat(s, ftos(rint(time - other.jointime)), ":");
958 if(other.classname == "player" || g_arena || g_lms)
959 s = strcat(s, ftos(other.team), ":");
961 s = strcat(s, "spectator:");
964 print(s, other.netname, "\n");
966 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
968 fputs(file, strcat(s, other.netname, "\n"));
974 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
980 fputs(file, strcat(s, "\n"));
982 for(i = 1; i < 16; ++i)
984 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
985 s = strcat(s, ":", ftos(i));
991 fputs(file, strcat(s, "\n"));
1001 fputs(file, ":end\n");
1006 void FixIntermissionClient(entity e)
1009 if(!e.autoscreenshot) // initial call
1011 e.angles = e.v_angle;
1012 e.angles_x = -e.angles_x;
1013 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1015 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1016 e.solid = SOLID_NOT;
1017 e.movetype = MOVETYPE_NONE;
1018 e.takedamage = DAMAGE_NO;
1020 e.weaponentity.effects = EF_NODRAW;
1021 if(clienttype(e) == CLIENTTYPE_REAL)
1023 stuffcmd(e, "\nscr_printspeed 1000000\n");
1024 s = cvar_string("sv_intermission_cdtrack");
1026 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1028 WriteByte(MSG_ONE, SVC_INTERMISSION);
1032 //e.velocity = '0 0 0';
1033 //e.fixangle = TRUE;
1035 // TODO halt weapon animation
1040 go to the next level for deathmatch
1041 only called if a time or frag limit has expired
1045 float minTotalFrags;
1046 float maxTotalFrags;
1052 intermission_running = 1;
1054 // enforce a wait time before allowing changelevel
1055 if(player_count > 0)
1056 intermission_exittime = time + cvar("sv_mapchange_delay");
1058 intermission_exittime = -1;
1061 WriteByte (MSG_ALL, SVC_CDTRACK);
1062 WriteByte (MSG_ALL, 3);
1063 WriteByte (MSG_ALL, 3);
1064 // done in FixIntermission
1067 //pos = FindIntermission ();
1073 if(cvar("sv_eventlog"))
1074 GameLogEcho(":gameover");
1078 FOR_EACH_CLIENT(other)
1080 FixIntermissionClient(other);
1083 bprint(other.netname, " ^7wins.\n");
1088 FOR_EACH_PLAYER(other)
1090 if(maxTotalFrags < other.totalfrags)
1091 maxTotalFrags = other.totalfrags;
1092 if(minTotalFrags > other.totalfrags)
1093 minTotalFrags = other.totalfrags;
1098 FOR_EACH_PLAYER(other)
1100 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1101 f = bound(0, other.play_time / max(time, 1), 1);
1102 // store some statistics?
1106 if(cvar("g_campaign"))
1107 CampaignPreIntermission();
1109 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1116 Exit deathmatch games upon conditions
1119 void CheckRules_Player()
1121 if (gameover) // someone else quit the game already
1124 if(self.deadflag == DEAD_NO)
1125 self.play_time += frametime;
1127 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1128 // (div0: and that in CheckRules_World please)
1131 float checkrules_oneminutewarning;
1133 float checkrules_equality;
1134 float checkrules_overtimewarning;
1135 float checkrules_overtimeend;
1137 void InitiateOvertime()
1139 if(!checkrules_overtimeend)
1140 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1143 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1144 float WINNING_YES = 1; // winner found
1145 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1146 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1148 float GetWinningCode(float fraglimitreached, float equality)
1151 if(fraglimitreached)
1152 return WINNING_STARTOVERTIME;
1154 return WINNING_NEVER;
1156 if(fraglimitreached)
1162 // set the .winning flag for exactly those players with a given field value
1163 void SetWinners(.float field, float value)
1166 FOR_EACH_PLAYER(head)
1167 head.winning = (head.field == value);
1170 // set the .winning flag for those players with a given field value
1171 void AddWinners(.float field, float value)
1174 FOR_EACH_PLAYER(head)
1175 if(head.field == value)
1179 // clear the .winning flags
1180 void ClearWinners(void)
1183 FOR_EACH_PLAYER(head)
1187 // Onslaught winning condition:
1188 // game terminates if only one team has a working generator (or none)
1189 float WinningCondition_Onslaught()
1192 local float t1, t2, t3, t4;
1193 // first check if the game has ended
1194 t1 = t2 = t3 = t4 = 0;
1195 head = find(world, classname, "onslaught_generator");
1198 if (head.health > 0)
1200 if (head.team == COLOR_TEAM1) t1 = 1;
1201 if (head.team == COLOR_TEAM2) t2 = 1;
1202 if (head.team == COLOR_TEAM3) t3 = 1;
1203 if (head.team == COLOR_TEAM4) t4 = 1;
1205 head = find(head, classname, "onslaught_generator");
1207 if (t1 + t2 + t3 + t4 < 2)
1209 // game over, only one team remains (or none)
1211 if (t1) SetWinners(team, COLOR_TEAM1);
1212 if (t2) SetWinners(team, COLOR_TEAM2);
1213 if (t3) SetWinners(team, COLOR_TEAM3);
1214 if (t4) SetWinners(team, COLOR_TEAM4);
1215 dprint("Have a winner, ending game.\n");
1219 // Two or more teams remain
1223 float LMS_NewPlayerLives()
1226 fl = cvar("fraglimit");
1230 // first player has left the game for dying too much? Nobody else can get in.
1231 if(lms_lowest_lives < 1)
1234 if(!cvar("g_lms_join_anytime"))
1235 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1238 return bound(1, lms_lowest_lives, fl);
1241 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1242 // they win. Otherwise the defending team wins once the timelimit passes.
1243 void assault_new_round();
1244 float WinningCondition_Assault()
1247 status = WINNING_NO;
1249 // as the timelimit has not yet passed just assume the defending team will win
1250 if(assault_attacker_team == COLOR_TEAM1)
1252 SetWinners(team, COLOR_TEAM2);
1256 SetWinners(team, COLOR_TEAM1);
1260 ent = find(world, classname, "target_assault_roundend");
1263 if(ent.winning) // round end has been triggered by attacking team
1265 SetWinners(team, assault_attacker_team);
1266 if(assault_attacker_team == COLOR_TEAM1)
1268 team1_score = team1_score + 50;
1272 team2_score = team2_score + 50;
1275 if(ent.cnt == 1) // this was the second round
1277 status = WINNING_YES;
1281 local entity oldself;
1284 cvar_set("timelimit", ftos((2*time)/60));
1285 assault_new_round();
1295 // LMS winning condition: game terminates if and only if there's at most one
1296 // one player who's living lives. Top two scores being equal cancels the time
1298 float WinningCondition_LMS()
1305 have_player = FALSE;
1306 have_players = FALSE;
1307 l = LMS_NewPlayerLives();
1309 head = find(world, classname, "player");
1312 head2 = find(head, classname, "player");
1314 have_players = TRUE;
1318 // we have at least one player
1321 // two or more active players - continue with the game
1325 // exactly one player?
1328 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1332 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1338 // and assign him his first place
1339 PlayerScore_Add(head, SP_LMS_RANK, 1);
1346 // nobody is playing at all...
1349 // wait for players...
1353 // SNAFU (maybe a draw game?)
1355 dprint("No players, ending game.\n");
1360 // When we get here, we have at least two players who are actually LIVING,
1361 // now check if the top two players have equal score.
1362 WinningConditionHelper();
1365 if(WinningConditionHelper_winner)
1366 WinningConditionHelper_winner.winning = TRUE;
1367 if(WinningConditionHelper_equality)
1368 return WINNING_NEVER;
1370 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1374 void print_to(entity e, string s)
1377 sprint(e, strcat(s, "\n"));
1382 void ShuffleMaplist()
1390 result = cvar_string("g_maplist");
1391 litems = tokenizebyseparator(result, " ");
1393 for(start = 0; start < litems - 1; ++start)
1397 // select a random item
1398 selected = ceil(random() * (litems - start) + start) - 1;
1400 // shift this item to the place start
1401 for(i = 0; i < start; ++i)
1402 result = strcat(result, " ", argv(i));
1403 result = strcat(result, " ", argv(selected));
1404 for(i = start; i < litems; ++i)
1406 result = strcat(result, " ", argv(i));
1407 result = substring(result, 1, strlen(result) - 1);
1409 litems = tokenizebyseparator(result, " ");
1411 //dprint(result, "\n");
1414 cvar_set("g_maplist", result);
1417 float WinningCondition_Scores(float limit)
1419 // TODO make everything use THIS winning condition (except LMS)
1420 WinningConditionHelper();
1424 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1425 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1426 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1427 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1431 if(WinningConditionHelper_winner)
1432 WinningConditionHelper_winner.winning = 1;
1433 if(WinningConditionHelper_winnerteam >= 0)
1434 SetWinners(team, WinningConditionHelper_winnerteam);
1436 if(WinningConditionHelper_lowerisbetter)
1438 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1442 return GetWinningCode(limit && WinningConditionHelper_topscore && (WinningConditionHelper_topscore >= limit), WinningConditionHelper_equality);
1445 float WinningCondition_Race(float fraglimit)
1449 wc = WinningCondition_Scores(fraglimit);
1451 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1452 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1453 // do NOT support equality when the laps are all raced!
1456 if not(p.race_completed)
1457 return WINNING_STARTOVERTIME;
1463 void ReadyRestart();
1464 float WinningCondition_QualifyingThenRace(float limit)
1467 wc = WinningCondition_Scores(limit);
1469 // NEVER initiate overtime
1470 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1471 // do NOT support equality when the laps are all raced!
1474 float playerswithlaps;
1477 totalplayers = playerswithlaps = readyplayers = 0;
1478 FOR_EACH_PLAYER(head)
1481 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
1487 // at least 2/3 of the players have completed a lap: start the RACE
1488 // otherwise, the players should end the qualifying on their own
1489 if(readyplayers || ((totalplayers >= 3) && (playerswithlaps * 3 >= totalplayers * 2)))
1491 checkrules_overtimeend = 0;
1493 return WINNING_NEVER;
1502 float WinningCondition_RanOutOfSpawns()
1506 if(!have_team_spawns)
1509 if(!some_spawn_has_been_used)
1512 team1_score = team2_score = team3_score = team4_score = 0;
1514 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1516 if(head.team == COLOR_TEAM1)
1518 else if(head.team == COLOR_TEAM2)
1520 else if(head.team == COLOR_TEAM3)
1522 else if(head.team == COLOR_TEAM4)
1526 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1528 if(head.team == COLOR_TEAM1)
1530 else if(head.team == COLOR_TEAM2)
1532 else if(head.team == COLOR_TEAM3)
1534 else if(head.team == COLOR_TEAM4)
1539 if(team1_score + team2_score + team3_score + team4_score == 0)
1541 checkrules_equality = TRUE;
1544 else if(team1_score + team2_score + team3_score + team4_score == 1)
1547 if(team1_score) t = COLOR_TEAM1;
1548 if(team2_score) t = COLOR_TEAM2;
1549 if(team3_score) t = COLOR_TEAM3;
1550 if(team4_score) t = COLOR_TEAM4;
1551 CheckAllowedTeams(world);
1552 for(i = 0; i < MAX_TEAMSCORE; ++i)
1554 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
1555 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
1556 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
1557 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
1560 AddWinners(team, t);
1571 Exit deathmatch games upon conditions
1574 void CheckRules_World()
1577 local float timelimit;
1578 local float fraglimit;
1586 MapVote_Think should now do that part
1587 if (intermission_running)
1588 if (time >= intermission_exittime + 60)
1590 if(!DoNextMapOverride())
1596 if (gameover) // someone else quit the game already
1598 if(player_count == 0) // Nobody there? Then let's go to the next map
1600 // this will actually check the player count in the next frame
1601 // again, but this shouldn't hurt
1605 timelimit = cvar("timelimit") * 60;
1606 fraglimit = cvar("fraglimit");
1609 fraglimit = 0; // no fraglimit for now
1611 if(checkrules_overtimeend)
1613 if(!checkrules_overtimewarning)
1615 checkrules_overtimewarning = TRUE;
1616 //announceall("announcer/robotic/1minuteremains.wav");
1617 if(!g_race_qualifying)
1618 bcenterprint("^3Everyone, finish your lap! The race is over!");
1620 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1625 if (timelimit && time >= timelimit)
1629 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1635 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1637 checkrules_oneminutewarning = TRUE;
1638 play2all("announcer/robotic/1minuteremains.wav");
1641 status = WinningCondition_RanOutOfSpawns();
1642 if(status == WINNING_YES)
1644 bprint("Hey! Someone ran out of spawns!\n");
1646 else if(g_race && !g_race_qualifying && timelimit >= 0)
1648 status = WinningCondition_Race(fraglimit);
1650 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
1652 status = WinningCondition_QualifyingThenRace(fraglimit);
1656 status = WinningCondition_Assault(); // TODO remove this?
1660 status = WinningCondition_LMS();
1662 else if (g_onslaught)
1664 status = WinningCondition_Onslaught(); // TODO remove this?
1668 status = WinningCondition_Scores(fraglimit);
1671 if(status == WINNING_STARTOVERTIME)
1673 status = WINNING_NEVER;
1677 if(status == WINNING_NEVER)
1678 // equality cases! Nobody wins if the overtime ends in a draw.
1681 if(checkrules_overtimeend)
1682 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1683 status = WINNING_YES;
1685 if(status == WINNING_YES)
1689 float mapvote_nextthink;
1690 float mapvote_initialized;
1691 float mapvote_keeptwotime;
1692 float mapvote_timeout;
1693 string mapvote_message;
1694 string mapvote_screenshot_dir;
1696 float mapvote_count;
1697 float mapvote_count_real;
1698 string mapvote_maps[MAPVOTE_COUNT];
1699 float mapvote_maps_suggested[MAPVOTE_COUNT];
1700 string mapvote_suggestions[MAPVOTE_COUNT];
1701 float mapvote_suggestion_ptr;
1702 float mapvote_maxlen;
1703 float mapvote_voters;
1704 float mapvote_votes[MAPVOTE_COUNT];
1706 float mapvote_detail;
1707 float mapvote_abstain;
1708 float mapvote_dirty;
1711 void MapVote_ClearAllVotes()
1713 FOR_EACH_CLIENT(other)
1717 string MapVote_Suggest(string m)
1721 return "That's not how to use this command.";
1722 if(!cvar("g_maplist_votable_suggestions"))
1723 return "Suggestions are not accepted on this server.";
1724 if(mapvote_initialized)
1725 return "Can't suggest - voting is already in progress!";
1726 m = MapInfo_FixName(m);
1728 return "The map you suggested is not available on this server.";
1729 if(!cvar("g_maplist_votable_override_mostrecent"))
1731 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1733 if(!MapInfo_CheckMap(m))
1734 return "The map you suggested does not support the current game mode.";
1735 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1736 if(mapvote_suggestions[i] == m)
1737 return "This map was already suggested.";
1738 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1740 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1744 i = mapvote_suggestion_ptr;
1745 mapvote_suggestion_ptr += 1;
1747 if(mapvote_suggestions[i] != "")
1748 strunzone(mapvote_suggestions[i]);
1749 mapvote_suggestions[i] = strzone(m);
1750 if(cvar("sv_eventlog"))
1751 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
1752 return strcat("Suggestion of ", m, " accepted.");
1755 void MapVote_AddVotable(string nextMap, float isSuggestion)
1760 for(j = 0; j < mapvote_count; ++j)
1761 if(mapvote_maps[j] == nextMap)
1763 if(strlen(nextMap) > mapvote_maxlen)
1764 mapvote_maxlen = strlen(nextMap);
1765 mapvote_maps[mapvote_count] = strzone(nextMap);
1766 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1770 void MapVote_SendData(float target);
1776 MapVote_ClearAllVotes();
1779 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1780 mapvote_abstain = cvar("g_maplist_votable_abstain");
1783 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1785 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1786 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
1788 if(mapvote_suggestion_ptr)
1789 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1790 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1792 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1793 MapVote_AddVotable(GetNextMap(), FALSE);
1795 if(mapvote_count == 0)
1797 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1798 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1799 localcmd("\nmenu_cmd sync\n");
1800 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1801 MapVote_AddVotable(GetNextMap(), FALSE);
1804 mapvote_count_real = mapvote_count;
1806 MapVote_AddVotable("don't care", 0);
1808 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1810 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1811 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1812 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1813 mapvote_keeptwotime = 0;
1814 mapvote_message = "Choose a map and press its key!";
1816 mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
1817 if(mapvote_screenshot_dir == "")
1818 mapvote_screenshot_dir = "maps";
1819 mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
1821 if(!cvar("g_maplist_textonly"))
1822 MapVote_SendData(MSG_ALL);
1825 void MapVote_SendPicture(float id)
1828 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1829 WriteByte(MSG_ONE, TE_CSQC_MAPVOTE);
1830 WriteByte(MSG_ONE, MAPVOTE_NET_PIC);
1831 WriteByte(MSG_ONE, id);
1832 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 3072);
1835 float GameCommand_MapVote(string cmd)
1837 if(!intermission_running)
1839 if(!cvar("g_maplist_textonly"))
1841 if(cmd == "mv_getpic")
1843 MapVote_SendPicture(stof(argv(1)));
1851 float MapVote_GetMapMask()
1853 float mask, i, power;
1855 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
1856 if(mapvote_maps[i] != "")
1861 void MapVote_SendData(float targ)
1863 string mapfile, pakfile;
1865 WriteByte(targ, SVC_TEMPENTITY);
1866 WriteByte(targ, TE_CSQC_CONFIG);
1867 WriteString(targ, "mv_screenshot_dir");
1868 WriteString(targ, mapvote_screenshot_dir);
1870 WriteByte(targ, SVC_TEMPENTITY);
1871 WriteByte(targ, TE_CSQC_MAPVOTE);
1872 WriteByte(targ, MAPVOTE_NET_INIT);
1874 WriteByte(targ, mapvote_count);
1875 WriteByte(targ, mapvote_abstain);
1876 WriteByte(targ, mapvote_detail);
1877 WriteCoord(targ, mapvote_timeout);
1878 if(mapvote_count <= 8)
1879 WriteByte(targ, MapVote_GetMapMask());
1881 WriteShort(targ, MapVote_GetMapMask());
1882 for(i = 0; i < mapvote_count; ++i)
1883 if(mapvote_maps[i] != "")
1885 WriteString(targ, mapvote_maps[i]);
1886 mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
1887 pakfile = whichpack(strcat(mapfile, ".tga"));
1889 pakfile = whichpack(strcat(mapfile, ".jpg"));
1891 pakfile = whichpack(strcat(mapfile, ".png"));
1892 print("pakfile is ", pakfile, "\n");
1893 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
1894 pakfile = substring(pakfile, o, 999);
1895 WriteString(targ, pakfile);
1899 void MapVote_UpdateData(float targ)
1902 WriteByte(targ, SVC_TEMPENTITY);
1903 WriteByte(targ, TE_CSQC_MAPVOTE);
1904 WriteByte(targ, MAPVOTE_NET_UPDATE);
1905 if(mapvote_count <= 8)
1906 WriteByte(targ, MapVote_GetMapMask());
1908 WriteShort(targ, MapVote_GetMapMask());
1910 for(i = 0; i < mapvote_count; ++i)
1911 if(mapvote_maps[i] != "")
1912 WriteByte(targ, mapvote_votes[i]);
1915 void MapVote_TellVote(float targ, float vote)
1917 WriteByte(targ, SVC_TEMPENTITY);
1918 WriteByte(targ, TE_CSQC_MAPVOTE);
1919 WriteByte(targ, MAPVOTE_NET_OWNVOTE);
1920 WriteByte(targ, vote);
1923 float MapVote_Finished(float mappos)
1929 if(cvar("sv_eventlog"))
1931 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1932 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1933 didntvote = mapvote_voters;
1934 for(i = 0; i < mapvote_count; ++i)
1935 if(mapvote_maps[i] != "")
1937 didntvote -= mapvote_votes[i];
1940 result = strcat(result, ":", mapvote_maps[i]);
1941 result = strcat(result, ":", ftos(mapvote_votes[i]));
1944 result = strcat(result, ":didn't vote:", ftos(didntvote));
1946 GameLogEcho(result);
1947 if(mapvote_maps_suggested[mappos])
1948 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
1951 FOR_EACH_REALCLIENT(other)
1952 FixClientCvars(other);
1954 Map_Goto_SetStr(mapvote_maps[mappos]);
1956 alreadychangedlevel = TRUE;
1959 void MapVote_CheckRules_1()
1963 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1965 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1966 mapvote_votes[i] = 0;
1970 FOR_EACH_REALCLIENT(other)
1975 i = other.mapvote - 1;
1976 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1977 mapvote_votes[i] = mapvote_votes[i] + 1;
1982 float MapVote_CheckRules_2()
1985 float firstPlace, secondPlace;
1986 float firstPlaceVotes, secondPlaceVotes;
1987 float mapvote_voters_real;
1990 mapvote_voters_real = mapvote_voters;
1992 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
1994 RandomSelection_Init();
1995 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1996 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
1997 firstPlace = RandomSelection_chosen_float;
1998 firstPlaceVotes = RandomSelection_best_priority;
1999 //dprint("First place: ", ftos(firstPlace), "\n");
2000 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2002 RandomSelection_Init();
2003 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2005 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2006 secondPlace = RandomSelection_chosen_float;
2007 secondPlaceVotes = RandomSelection_best_priority;
2008 //dprint("Second place: ", ftos(secondPlace), "\n");
2009 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2011 if(firstPlace == -1)
2012 error("No first place in map vote... WTF?");
2014 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2015 return MapVote_Finished(firstPlace);
2017 if(mapvote_keeptwotime)
2018 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2021 mapvote_dirty = TRUE;
2022 mapvote_message = "Now decide between the TOP TWO!";
2023 mapvote_keeptwotime = 0;
2024 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2025 result = strcat(result, ":", ftos(firstPlaceVotes));
2026 result = strcat(result, ":", mapvote_maps[secondPlace]);
2027 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2028 didntvote = mapvote_voters;
2029 for(i = 0; i < mapvote_count; ++i)
2030 if(mapvote_maps[i] != "")
2032 didntvote -= mapvote_votes[i];
2034 if(i != secondPlace)
2036 result = strcat(result, ":", mapvote_maps[i]);
2037 result = strcat(result, ":", ftos(mapvote_votes[i]));
2038 if(i < mapvote_count_real)
2040 strunzone(mapvote_maps[i]);
2041 mapvote_maps[i] = "";
2045 result = strcat(result, ":didn't vote:", ftos(didntvote));
2046 if(cvar("sv_eventlog"))
2047 GameLogEcho(result);
2060 keeptwo = mapvote_keeptwotime;
2061 MapVote_CheckRules_1(); // count
2062 if(MapVote_CheckRules_2()) // decide
2066 FOR_EACH_REALCLIENT(other)
2068 // hide scoreboard again
2069 if(other.health != 2342)
2071 other.health = 2342;
2073 if(clienttype(other) == CLIENTTYPE_REAL)
2075 if(cvar("g_maplist_textonly"))
2076 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");
2079 WriteByte(MSG_ONE, SVC_FINALE);
2080 WriteString(MSG_ONE, "");
2084 // notify about keep-two
2085 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2086 play2(other, "misc/invshot.wav");
2088 // clear possibly invalid votes
2089 if(mapvote_maps[other.mapvote - 1] == "")
2091 // use impulses as new vote
2092 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2093 if(mapvote_maps[other.impulse - 1] != "")
2095 other.mapvote = other.impulse;
2097 mapvote_dirty = TRUE;
2100 MapVote_TellVote(MSG_ONE, other.mapvote);
2108 MapVote_CheckRules_1(); // just count
2110 if(!cvar("g_maplist_textonly"))
2111 if(mapvote_dirty) // 1 if "keeptwo" or "impulse" happened before
2113 MapVote_UpdateData(MSG_BROADCAST);
2114 mapvote_dirty = FALSE;
2117 if(cvar("g_maplist_textonly"))
2119 FOR_EACH_REALCLIENT(other)
2121 // display voting screen
2122 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2123 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2125 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2126 msgstr = strcat(msgstr, mapvote_message);
2127 msgstr = strcat(msgstr, "\n\n");
2128 for(i = 0; i < mapvote_count; ++i)
2129 if(mapvote_maps[i] == "")
2130 msgstr = strcat(msgstr, "\n");
2133 tmp = mapvote_maps[i];
2134 tmp = strpad(mapvote_maxlen, tmp);
2135 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2138 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2139 if(mapvote_votes[i] != 1)
2140 tmp = strcat(tmp, "s");
2141 tmp = strcat(tmp, ")");
2142 tmp = strpad(mapvote_maxlen + 15, tmp);
2145 if(i == mapvote_count - 1)
2146 msgstr = strcat(msgstr, "\n");
2147 if(other.mapvote == i + 1)
2148 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2150 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2153 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2155 msgstr = strcat(msgstr, "s");
2156 msgstr = strcat(msgstr, " cast");
2157 i = ceil(mapvote_timeout - time);
2158 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2160 msgstr = strcat(msgstr, "s");
2161 msgstr = strcat(msgstr, " left");
2163 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2167 void MapVote_Start()
2172 MapInfo_Enumerate();
2173 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2176 void MapVote_Think()
2181 if(alreadychangedlevel)
2184 if(time < mapvote_nextthink)
2188 mapvote_nextthink = time + 0.5;
2190 if(!mapvote_initialized)
2192 mapvote_initialized = TRUE;
2193 if(DoNextMapOverride())
2195 if(!cvar("g_maplist_votable") || player_count <= 0)
2206 string GotoMap(string m)
2208 if(!MapInfo_CheckMap(m))
2209 return "The map you chose is not available on this server.";
2210 cvar_set("nextmap", m);
2211 cvar_set("timelimit", "-1");
2212 if(mapvote_initialized || alreadychangedlevel)
2214 if(DoNextMapOverride())
2215 return "Map switch initiated.";
2217 return "Hm... no. For some reason I like THIS map more.";
2220 return "Map switch will happen after scoreboard.";
2226 FOR_EACH_REALCLIENT(self)
2228 if(self.classname == "spectator")
2230 if(self.enemy.hitsound)
2231 play2(self, "misc/hit.wav");
2236 play2(self, "misc/hit.wav");
2239 FOR_EACH_CLIENT(self)
2240 self.hitsound = FALSE;
2246 * returns TRUE if redirecting
2248 float redirection_timeout;
2249 float redirection_nextthink;
2250 float RedirectionThink()
2252 float clients_found;
2254 if(redirection_target == "")
2257 if(!redirection_timeout)
2259 cvar_set("sv_public", "-2");
2260 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2261 if(redirection_target == "self")
2262 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2264 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2267 if(time < redirection_nextthink)
2270 redirection_nextthink = time + 1;
2273 FOR_EACH_REALCLIENT(self)
2275 print("Redirecting: sending connect command to ", self.netname, "\n");
2276 if(redirection_target == "self")
2277 stuffcmd(self, "\ndisconnect; reconnect\n");
2279 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2283 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2285 if(time > redirection_timeout || clients_found == 0)
2286 localcmd("\nwait; wait; wait; quit\n");
2293 // Loaded from a save game
2294 // some things then break, so let's work around them...
2296 // Progs DB (capture records)
2298 ServerProgsDB = db_create();
2300 ServerProgsDB = db_load("server.db");
2304 MapInfo_Enumerate();
2305 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
2310 if(world_initialized)
2312 world_initialized = 0;
2313 print("Saving persistent data...\n");
2316 db_save(ServerProgsDB, "server.db");
2317 db_close(ServerProgsDB);
2319 // tell the bot system the game is ending now
2326 print("NOTE: crashed before even initializing the world, not saving persistent data\n");