1 float SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS = 1;
2 string redirection_target;
3 float world_initialized;
9 float() DoNextMapOverride;
13 void SetDefaultAlpha()
15 if(cvar("g_running_guns"))
17 default_player_alpha = -1;
18 default_weapon_alpha = +1;
22 default_player_alpha = cvar("g_balance_cloaked_alpha");
23 default_weapon_alpha = default_player_alpha;
27 default_player_alpha = cvar("g_player_alpha");
28 if(default_player_alpha <= 0)
29 default_player_alpha = 1;
30 default_weapon_alpha = default_player_alpha;
34 void fteqcc_testbugs()
38 if(!cvar("developer_fteqccbugs"))
41 dprint("*** fteqcc test: checking for bugs...\n");
45 if(sqrt(a) - sqrt(b - a) == 0)
46 dprint("*** fteqcc test: found same-function-twice bug\n");
48 dprint("*** fteqcc test: same-function-twice bug got FINALLY FIXED! HOORAY!\n");
52 world.enemy.cnt += 10;
53 if(world.cnt > 0.2 || world.cnt < -0.2) // don't error out if it's just roundoff errors
54 dprint("*** fteqcc test: found += bug\n");
56 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
61 * Takes care of pausing and unpausing the game.
62 * Centerprints the information about an upcoming or active timeout to all active
63 * players. Also plays reminder sounds.
65 void timeoutHandler_Think() {
68 if (timeoutStatus == 1) {
69 if (remainingLeadTime > 0) {
70 //centerprint the information to every player
71 timeStr = getTimeoutText(0);
72 FOR_EACH_REALCLIENT(plr) {
73 if(plr.classname == "player") {
74 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
77 remainingLeadTime -= 1;
78 //think again in 1 second:
79 self.nextthink = time + 1;
84 cvar_set("slowmo", ftos(TIMEOUT_SLOWMO_VALUE));
85 //copy .v_angle to .lastV_angle for every player in order to fix their view during pause (see PlayerPreThink)
86 FOR_EACH_REALPLAYER(plr) {
87 plr.lastV_angle = plr.v_angle;
89 self.nextthink = time;
92 else if (timeoutStatus == 2) {
93 if (remainingTimeoutTime > 0) {
94 timeStr = getTimeoutText(0);
95 FOR_EACH_REALCLIENT(plr) {
96 if(plr.classname == "player") {
97 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
100 if(remainingTimeoutTime == cvar("sv_timeout_resumetime")) { //play a warning sound when only <sv_timeout_resumetime> seconds are left
101 sound(world, CHAN_AUTO, "announcer/robotic/prepareforbattle.wav", 1, ATTN_NONE);
103 remainingTimeoutTime -= 1;
104 self.nextthink = time + TIMEOUT_SLOWMO_VALUE;
107 //unpause the game again
108 remainingTimeoutTime = timeoutStatus = 0;
109 cvar_set("slowmo", ftos(orig_slowmo));
110 //and unlock the fixed view again once there is no timeout active anymore
111 FOR_EACH_REALPLAYER(plr) {
112 plr.fixangle = FALSE;
114 //get rid of the countdown message
115 FOR_EACH_REALCLIENT(plr) {
116 if(plr.classname == "player") {
117 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
125 else if (timeoutStatus == 0) { //if a player called the resumegame command (which set timeoutStatus to 0 already)
126 FOR_EACH_REALCLIENT(plr) {
127 if(plr.classname == "player") {
128 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
140 cvar_set("_sv_init", "0");
141 if(cvar("g_maplist_shuffle"))
144 tokenizebyseparator(cvar_string("g_maplist"), " ");
146 tokenize(cvar_string("g_maplist"));
147 if(argv(0) != GetMapname())
150 cvar_set("nextmap", argv(0));
154 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
157 if(!DoNextMapOverride())
166 float world_already_spawned;
167 void spawnfunc_worldspawn (void)
172 dprint_load(); // load dprint status from cvar
174 if(world_already_spawned)
175 error("world already spawned - you may have EXACTLY ONE worldspawn!");
176 world_already_spawned = TRUE;
179 head = nextent(world);
184 head = nextent(head);
191 MapInfo_LoadMapSettings(mapname);
195 ServerProgsDB = db_create();
197 ServerProgsDB = db_load("server.db");
200 TODO sound pack system
201 // initialize sound pack system
202 soundpack = cvar_string("g_soundpack");
204 soundpack = strcat(soundpack, "/");
205 soundpack = strzone(soundpack);
211 // 1 FLICKER (first variety)
212 lightstyle(1, "mmnmmommommnonmmonqnmmo");
214 // 2 SLOW STRONG PULSE
215 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
217 // 3 CANDLE (first variety)
218 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
221 lightstyle(4, "mamamamamama");
224 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
226 // 6 FLICKER (second variety)
227 lightstyle(6, "nmonqnmomnmomomno");
229 // 7 CANDLE (second variety)
230 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
232 // 8 CANDLE (third variety)
233 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
235 // 9 SLOW STROBE (fourth variety)
236 lightstyle(9, "aaaaaaaazzzzzzzz");
238 // 10 FLUORESCENT FLICKER
239 lightstyle(10, "mmamammmmammamamaaamammma");
241 // 11 SLOW PULSE NOT FADE TO BLACK
242 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
244 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
249 // for setting by mapinfo
250 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
251 cvar_set("sv_q3acompat_machineshotgunswap", "0");
254 lms_lowest_lives = 0;
257 bot_waypoints_for_items = cvar("g_waypoints_for_items");
258 if(bot_waypoints_for_items == 1)
259 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
260 bot_waypoints_for_items = 0;
262 if(cvar("g_campaign"))
269 WaypointSprite_Init();
274 GameLogInit(); // prepare everything
275 if(cvar("sv_eventlog"))
277 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
278 s = strcat(s, ftos(random()));
280 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s), FALSE);
282 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
284 s = ":gameinfo:mutators:LIST";
285 if(cvar("g_grappling_hook"))
286 s = strcat(s, ":grappling_hook");
287 if(!cvar("g_use_ammunition"))
288 s = strcat(s, ":no_use_ammunition");
289 if(!cvar("g_pickup_items"))
290 s = strcat(s, ":no_pickup_items");
291 if(cvar("g_instagib"))
292 s = strcat(s, ":instagib");
293 if(cvar("g_rocketarena"))
294 s = strcat(s, ":rockerarena");
296 s = strcat(s, ":nixnex");
297 if(cvar("g_vampire"))
298 s = strcat(s, ":vampire");
299 if(cvar("g_laserguided_missile"))
300 s = strcat(s, ":laserguided_missile");
301 if(cvar("g_norecoil"))
302 s = strcat(s, ":norecoil");
304 s = strcat(s, ":midair");
305 if(cvar("g_minstagib"))
306 s = strcat(s, ":minstagib");
307 GameLogEcho(s, FALSE);
308 GameLogEcho(":gameinfo:end", FALSE);
311 cvar_set("nextmap", "");
315 if(cvar("g_campaign"))
322 //initialise globals related to sv_timeout
323 sys_ticrate = cvar("sys_ticrate");
324 orig_slowmo = cvar("slowmo");
328 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
331 //if tourney is used map starts in warmup mode. if this mode shall stay unlimited, reset timelimit, but save the original one
332 if(g_tourney && cvar("g_tourney_warmup_unlimited_time")) {
333 timelimit_orig = cvar("timelimit");
334 cvar_set("timelimit", "0");
337 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
340 while((s = fgets(fd)))
351 s = strcat(argv(l), " ", s);
353 s = substring(s, 0, strlen(s) - 1);
354 print("Found ^1DEPRECATED^7 fog command in .cfg file: ", s, "\n");
355 world.fog = strzone(s);
360 next_pingtime = time + 5;
361 world_initialized = 1;
364 void spawnfunc_light (void)
366 //makestatic (self); // Who the f___ did that?
370 float TryFile( string pFilename )
373 dprint("TryFile(\"", pFilename, "\")\n");
374 lHandle = fopen( pFilename, FILE_READ );
375 if( lHandle != -1 ) {
385 return GametypeNameFromType(game);
388 float IsSameGametype(string mapcfgname)
391 return TRUE; // can't change game type by map name here
395 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
401 string getmapname_stored;
407 if(getmapname_stored == "")
408 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
409 return getmapname_stored;
413 float Map_Count, Map_Current;
414 string Map_Current_Name;
416 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
417 float GetMaplistPosition()
423 idx = cvar("g_maplist_index");
430 for(pos = 0; pos < Map_Count; ++pos)
434 // resume normal maplist rotation if current map is not in g_maplist
438 float MapHasRightSize(string map)
441 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
442 if(cvar("g_maplist_check_waypoints"))
444 dprint("checkwp "); dprint(map);
445 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
448 dprint(": no waypoints\n");
451 dprint(": has waypoints\n");
455 // open map size restriction file
456 dprint("opensize "); dprint(map);
457 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
460 float mapmin, mapmax;
462 mapmin = stof(fgets(fh));
463 mapmax = stof(fgets(fh));
465 if(player_count < mapmin)
467 dprint("not enough\n");
470 if(player_count > mapmax)
472 dprint("too many\n");
475 dprint("right size\n");
478 dprint(": not found\n");
482 string Map_Filename(float position)
485 return strcat("maps/", argv(position), ".bsp");
487 return strcat("maps/", argv(position), ".mapcfg");
491 string strwords(string s, float w)
494 for(endpos = 0; w && endpos >= 0; --w)
495 endpos = strstrofs(s, " ", endpos + 1);
499 return substring(s, 0, endpos);
502 float strhasword(string s, string w)
504 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
507 void Map_MarkAsRecent(string m)
509 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
512 float Map_IsRecent(string m)
514 return strhasword(cvar_string("g_maplist_mostrecent"), m);
517 float Map_Check(float position, float pass)
521 map_next = argv(position);
524 if(map_next == Map_Current_Name) // same map again in first pass?
526 if(Map_IsRecent(map_next))
529 filename = Map_Filename(position);
531 if(MapInfo_CheckMap(map_next))
533 if(TryFile(filename))
538 if(MapHasRightSize(map_next))
543 dprint( "Couldn't select '", filename, "'..\n" );
548 void Map_Goto_SetStr(string nextmapname)
550 if(getmapname_stored != "")
551 strunzone(getmapname_stored);
552 if(nextmapname == "")
553 getmapname_stored = "";
555 getmapname_stored = strzone(nextmapname);
558 void Map_Goto_SetFloat(float position)
560 cvar_set("g_maplist_index", ftos(position));
561 Map_Goto_SetStr(argv(position));
567 // settings persist, except...
568 if(cvar("g_campaign"))
569 localcmd("\nexec mutator_reset.cfg\n");
570 localcmd("\nsettemp_restore\n");
572 // if an exit cfg is defined by exiting map, exec it.
574 exit_cfg = cvar_string("exit_cfg");
576 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
578 localcmd("exec game_reset.cfg\n");
584 Map_MarkAsRecent(getmapname_stored);
587 MapInfo_LoadMap(getmapname_stored);
589 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
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
657 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
658 newlist = strcat(newlist, " ", argv(j));
659 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
660 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
661 newlist = strcat(newlist, " ", argv(j));
662 newlist = substring(newlist, 1, strlen(newlist) - 1);
664 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
665 newlist = strcat(newlist, "'", argv(j), "'");
666 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
667 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
668 newlist = strcat(newlist, "'", argv(j), "'");
670 cvar_set("g_maplist", newlist);
672 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
674 Map_Count = tokenize(newlist);
677 // NOTE: the selected map has just been inserted at (insertpos-1)th position
678 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
679 if(Map_Check(Map_Current, 1))
688 temp = cvar_string("g_maplist");
690 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
692 Map_Count = tokenize(temp);
696 bprint( "Maplist is empty! Resetting it to default map list.\n" );
698 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
699 localcmd("\nmenu_cmd sync\n");
700 Map_Count = tokenizebyseparator(temp, " ");
702 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
703 Map_Count = tokenize(temp);
707 error("empty maplist, cannot select a new map");
708 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
711 strunzone(Map_Current_Name);
712 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
713 // this may or may not be correct, but who cares, in the worst case a map
714 // isn't chosen in the first pass that should have been
725 if(cvar("g_maplist_shuffle") > 0)
726 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
729 if(cvar("g_maplist_selectrandom"))
730 nextMap = MaplistMethod_Random();
733 nextMap = MaplistMethod_Iterate();
736 nextMap = MaplistMethod_Repeat();
740 Map_Goto_SetFloat(nextMap);
741 return getmapname_stored;
747 float DoNextMapOverride()
749 if(cvar("g_campaign"))
751 CampaignPostIntermission();
752 alreadychangedlevel = TRUE;
755 if(cvar("quit_when_empty"))
757 if(player_count <= currentbots)
760 alreadychangedlevel = TRUE;
764 if(cvar_string("quit_and_redirect") != "")
766 redirection_target = strzone(cvar_string("quit_and_redirect"));
767 alreadychangedlevel = TRUE;
770 if (cvar("samelevel")) // if samelevel is set, stay on same level
772 // 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)
773 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
774 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
775 localcmd("restart\n");
776 //changelevel (mapname);
777 alreadychangedlevel = TRUE;
780 if(cvar_string("nextmap") != "")
782 if(MapInfo_CheckMap(cvar_string("nextmap")))
784 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
787 Map_Goto_SetStr(cvar_string("nextmap"));
789 alreadychangedlevel = TRUE;
792 if(cvar("lastlevel"))
795 localcmd("set lastlevel 0\ntogglemenu\n");
796 alreadychangedlevel = TRUE;
804 //local string nextmap;
805 //local float n, nummaps;
807 if (alreadychangedlevel)
809 alreadychangedlevel = TRUE;
815 for(allowReset = 1; allowReset >= 0; --allowReset)
817 nextMap = GetNextMap();
823 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
825 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
826 localcmd("\nmenu_cmd sync\n");
828 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
833 error("Everything is broken - not even the default map list works. Please report this to the developers.");
845 When the player presses attack or jump, change to the next level
848 .float autoscreenshot;
849 void() MapVote_Start;
850 void() MapVote_Think;
851 float mapvote_initialized;
852 void IntermissionThink()
854 FixIntermissionClient(self);
856 if(cvar("sv_autoscreenshot"))
857 if(self.autoscreenshot > 0)
858 if(time > self.autoscreenshot)
860 self.autoscreenshot = -1;
861 if(clienttype(self) == CLIENTTYPE_REAL)
862 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
866 if (time < intermission_exittime)
869 if(!mapvote_initialized)
870 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
880 Returns the entity to view from
884 entity FindIntermission()
889 // look for info_intermission first
890 spot = find (world, classname, "info_intermission");
892 { // pick a random one
896 spot = find (spot, classname, "info_intermission");
898 spot = find (spot, classname, "info_intermission");
904 // then look for the start position
905 spot = find (world, classname, "info_player_start");
909 // testinfo_player_start is only found in regioned levels
910 spot = find (world, classname, "testplayerstart");
914 // then look for the start position
915 spot = find (world, classname, "info_player_deathmatch");
919 //objerror ("FindIntermission: no spot");
925 ===============================================================================
929 ===============================================================================
932 void DumpStats(float final)
936 local float to_console;
937 local float to_eventlog;
940 to_console = cvar("sv_logscores_console");
941 to_eventlog = cvar("sv_eventlog");
942 to_file = cvar("sv_logscores_file");
946 to_console = TRUE; // always print printstats replies
947 to_eventlog = FALSE; // but never print them to the event log
951 if(cvar("sv_eventlog_console"))
952 to_console = FALSE; // otherwise we get the output twice
959 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
961 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
965 ServerConsoleEcho(s, FALSE);
967 GameLogEcho(s, FALSE);
970 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
974 fputs(file, strcat(s, "\n"));
977 FOR_EACH_CLIENT(other)
979 // FIXME make this use the new score system
981 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
983 s = strcat(":player:", ftos(other.frags), ":");
984 s = strcat(s, ftos(other.deaths), ":");
985 s = strcat(s, ftos(rint(time - other.jointime)), ":");
986 s = strcat(s, ftos(other.team), ":");
989 ServerConsoleEcho(strcat(s, other.netname), TRUE);
991 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
993 fputs(file, strcat(s, other.netname, "\n"));
1000 if(cvar("g_ctf_win_mode") != 2)
1002 s = strcat(":teamscores:", ftos(COLOR_TEAM1), ":");
1003 s = strcat(s, ftos(caps_team1), ":");
1004 s = strcat(s, ftos(COLOR_TEAM2), ":");
1005 s = strcat(s, ftos(caps_team2));
1007 ServerConsoleEcho(s, TRUE);
1009 GameLogEcho(s, TRUE);
1011 fputs(file, strcat(s, "\n"));
1016 ServerConsoleEcho(":end", FALSE);
1018 GameLogEcho(":end", FALSE);
1021 fputs(file, ":end\n");
1026 void FixIntermissionClient(entity e)
1029 if(!e.autoscreenshot) // initial call
1031 e.angles = e.v_angle;
1032 e.angles_x = -e.angles_x;
1033 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1035 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1036 e.solid = SOLID_NOT;
1037 e.movetype = MOVETYPE_NONE;
1038 e.takedamage = DAMAGE_NO;
1040 e.weaponentity.effects = EF_NODRAW;
1041 if(clienttype(e) == CLIENTTYPE_REAL)
1043 stuffcmd(e, "\nscr_printspeed 1000000\n");
1044 s = cvar_string("sv_intermission_cdtrack");
1046 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1048 WriteByte(MSG_ONE, SVC_INTERMISSION);
1052 //e.velocity = '0 0 0';
1053 //e.fixangle = TRUE;
1055 // TODO halt weapon animation
1060 go to the next level for deathmatch
1061 only called if a time or frag limit has expired
1065 float minTotalFrags;
1066 float maxTotalFrags;
1072 intermission_running = 1;
1074 // enforce a wait time before allowing changelevel
1075 if(player_count > 0)
1076 intermission_exittime = time + cvar("sv_mapchange_delay");
1078 intermission_exittime = -1;
1081 WriteByte (MSG_ALL, SVC_CDTRACK);
1082 WriteByte (MSG_ALL, 3);
1083 WriteByte (MSG_ALL, 3);
1084 // done in FixIntermission
1087 //pos = FindIntermission ();
1093 if(cvar("sv_eventlog"))
1094 GameLogEcho(":gameover", FALSE);
1098 FOR_EACH_CLIENT(other)
1100 FixIntermissionClient(other);
1103 bprint(other.netname, " ^7wins.\n");
1108 FOR_EACH_PLAYER(other)
1110 if(maxTotalFrags < other.totalfrags)
1111 maxTotalFrags = other.totalfrags;
1112 if(minTotalFrags > other.totalfrags)
1113 minTotalFrags = other.totalfrags;
1118 FOR_EACH_PLAYER(other)
1120 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1121 f = bound(0, other.play_time / max(time, 1), 1);
1122 // store some statistics?
1126 if(cvar("g_campaign"))
1127 CampaignPreIntermission();
1129 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1136 Exit deathmatch games upon conditions
1140 void CheckRules_Player()
1142 if (gameover) // someone else quit the game already
1145 if(self.deadflag == DEAD_NO)
1146 self.play_time += frametime;
1150 if(time > self.fogtime)
1152 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1153 self.fogtime = time + sv_foginterval;
1156 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1157 // (div0: and that in CheckRules_World please)
1160 float checkrules_oneminutewarning;
1161 float checkrules_leaderfrags;
1162 float tdm_max_score, tdm_old_score;
1164 float checkrules_equality;
1165 float checkrules_overtimewarning;
1166 float checkrules_overtimeend;
1168 void InitiateOvertime()
1170 if(!checkrules_overtimeend)
1171 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1174 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1175 float WINNING_YES = 1; // winner found
1176 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1177 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1179 float GetWinningCode(float fraglimitreached, float equality)
1182 if(fraglimitreached)
1183 return WINNING_STARTOVERTIME;
1185 return WINNING_NEVER;
1187 if(fraglimitreached)
1193 // set the .winning flag for exactly those players with a given field value
1194 void SetWinners(.float field, float value)
1197 FOR_EACH_PLAYER(head)
1198 head.winning = (head.field == value);
1201 // set the .winning flag for those players with a given field value
1202 void AddWinners(.float field, float value)
1205 FOR_EACH_PLAYER(head)
1206 if(head.field == value)
1210 // clear the .winning flags
1211 void ClearWinners(void)
1214 FOR_EACH_PLAYER(head)
1218 // Onslaught winning condition:
1219 // game terminates if only one team has a working generator (or none)
1220 float WinningCondition_Onslaught()
1223 local float t1, t2, t3, t4;
1224 // first check if the game has ended
1225 t1 = t2 = t3 = t4 = 0;
1226 head = find(world, classname, "onslaught_generator");
1229 if (head.health > 0)
1231 if (head.team == COLOR_TEAM1) t1 = 1;
1232 if (head.team == COLOR_TEAM2) t2 = 1;
1233 if (head.team == COLOR_TEAM3) t3 = 1;
1234 if (head.team == COLOR_TEAM4) t4 = 1;
1236 head = find(head, classname, "onslaught_generator");
1238 if (t1 + t2 + t3 + t4 < 2)
1240 // game over, only one team remains (or none)
1242 if (t1) SetWinners(team, COLOR_TEAM1);
1243 if (t2) SetWinners(team, COLOR_TEAM2);
1244 if (t3) SetWinners(team, COLOR_TEAM3);
1245 if (t4) SetWinners(team, COLOR_TEAM4);
1246 dprint("Have a winner, ending game.\n");
1250 // Two or more teams remain
1254 float LMS_NewPlayerLives()
1257 fl = cvar("fraglimit");
1261 // first player has left the game for dying too much? Nobody else can get in.
1262 if(lms_lowest_lives < 1)
1265 if(!cvar("g_lms_join_anytime"))
1266 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1269 return bound(1, lms_lowest_lives, fl);
1272 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1273 // they win. Otherwise the defending team wins once the timelimit passes.
1274 void assault_new_round();
1275 float WinningCondition_Assault()
1278 status = WINNING_NO;
1280 // as the timelimit has not yet passed just assume the defending team will win
1281 if(assault_attacker_team == COLOR_TEAM1)
1283 SetWinners(team, COLOR_TEAM2);
1287 SetWinners(team, COLOR_TEAM1);
1291 ent = find(world, classname, "target_assault_roundend");
1294 if(ent.winning) // round end has been triggered by attacking team
1296 SetWinners(team, assault_attacker_team);
1297 if(assault_attacker_team == COLOR_TEAM1)
1299 team1_score = team1_score + 50;
1303 team2_score = team2_score + 50;
1306 if(ent.cnt == 1) // this was the second round
1308 status = WINNING_YES;
1312 local entity oldself;
1315 cvar_set("timelimit", ftos((2*time)/60));
1316 assault_new_round();
1326 // LMS winning condition: game terminates if and only if there's at most one
1327 // one player who's living lives. Top two scores being equal cancels the time
1329 float WinningCondition_LMS()
1336 have_player = FALSE;
1337 have_players = FALSE;
1338 l = LMS_NewPlayerLives();
1340 head = find(world, classname, "player");
1343 head2 = find(head, classname, "player");
1345 have_players = TRUE;
1349 // we have at least one player
1352 // two or more active players - continue with the game
1356 // exactly one player?
1359 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1363 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1369 // and assign him his first place
1370 PlayerScore_Add(head, SP_LMS_RANK, 1);
1377 // nobody is playing at all...
1380 // wait for players...
1384 // SNAFU (maybe a draw game?)
1386 dprint("No players, ending game.\n");
1391 // When we get here, we have at least two players who are actually LIVING,
1392 // now check if the top two players have equal score.
1393 WinningConditionHelper();
1396 if(WinningConditionHelper_winner)
1397 WinningConditionHelper_winner.winning = TRUE;
1398 if(WinningConditionHelper_equality)
1399 return WINNING_NEVER;
1401 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1405 void print_to(entity e, string s)
1408 sprint(e, strcat(s, "\n"));
1410 ServerConsoleEcho(s, TRUE);
1413 void ShuffleMaplist()
1421 result = cvar_string("g_maplist");
1423 litems = tokenizebyseparator(result, " ");
1425 litems = tokenize(result);
1428 for(start = 0; start < litems - 1; ++start)
1432 // select a random item
1433 selected = ceil(random() * (litems - start) + start) - 1;
1435 // shift this item to the place start
1437 for(i = 0; i < start; ++i)
1438 result = strcat(result, " ", argv(i));
1439 result = strcat(result, " ", argv(selected));
1440 for(i = start; i < litems; ++i)
1442 result = strcat(result, " ", argv(i));
1443 result = substring(result, 1, strlen(result) - 1);
1445 litems = tokenizebyseparator(result, " ");
1447 for(i = 0; i < start; ++i)
1448 result = strcat(result, "'", argv(i), "'");
1449 result = strcat(result, "'", argv(selected), "'");
1450 for(i = start; i < litems; ++i)
1452 result = strcat(result, "'", argv(i), "'");
1454 litems = tokenize(result);
1457 //dprint(result, "\n");
1460 cvar_set("g_maplist", result);
1463 float WinningCondition_Scores(float limit)
1465 // TODO make everything use THIS winning condition (except LMS)
1466 WinningConditionHelper();
1469 if(WinningConditionHelper_winner)
1470 WinningConditionHelper_winner.winning = 1;
1471 if(WinningConditionHelper_winnerteam >= 0)
1472 SetWinners(team, WinningConditionHelper_winnerteam);
1474 if(WinningConditionHelper_topscore == 0)
1475 WinningConditionHelper_equality = 0;
1477 return GetWinningCode(limit && (WinningConditionHelper_topscore >= limit), WinningConditionHelper_equality);
1480 float WinningCondition_RanOutOfSpawns()
1484 if(!have_team_spawns)
1487 if(!some_spawn_has_been_used)
1490 team1_score = team2_score = team3_score = team4_score = 0;
1492 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1494 if(head.team == COLOR_TEAM1)
1496 else if(head.team == COLOR_TEAM2)
1498 else if(head.team == COLOR_TEAM3)
1500 else if(head.team == COLOR_TEAM4)
1504 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1506 if(head.team == COLOR_TEAM1)
1508 else if(head.team == COLOR_TEAM2)
1510 else if(head.team == COLOR_TEAM3)
1512 else if(head.team == COLOR_TEAM4)
1517 if(team1_score + team2_score + team3_score + team4_score == 0)
1519 checkrules_equality = TRUE;
1522 else if(team1_score + team2_score + team3_score + team4_score == 1)
1525 if(team1_score) t = COLOR_TEAM1;
1526 if(team2_score) t = COLOR_TEAM2;
1527 if(team3_score) t = COLOR_TEAM3;
1528 if(team4_score) t = COLOR_TEAM4;
1529 CheckAllowedTeams(world);
1530 for(i = 0; i < MAX_TEAMSCORE; ++i)
1532 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
1533 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
1534 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
1535 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
1538 AddWinners(team, t);
1549 Exit deathmatch games upon conditions
1552 void CheckRules_World()
1555 local float timelimit;
1556 local float fraglimit;
1564 MapVote_Think should now do that part
1565 if (intermission_running)
1566 if (time >= intermission_exittime + 60)
1568 if(!DoNextMapOverride())
1574 if (gameover) // someone else quit the game already
1576 if(player_count == 0) // Nobody there? Then let's go to the next map
1578 // this will actually check the player count in the next frame
1579 // again, but this shouldn't hurt
1583 timelimit = cvar("timelimit") * 60;
1584 fraglimit = cvar("fraglimit");
1586 if(checkrules_overtimeend)
1588 if(!checkrules_overtimewarning)
1590 checkrules_overtimewarning = TRUE;
1591 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1592 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1597 if (timelimit && time >= timelimit)
1601 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1607 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1609 checkrules_oneminutewarning = TRUE;
1610 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1613 status = WinningCondition_RanOutOfSpawns();
1614 if(status == WINNING_YES)
1616 bprint("Hey! Someone ran out of spawns!\n");
1620 status = WinningCondition_Assault(); // TODO remove this?
1624 status = WinningCondition_LMS();
1626 else if (g_onslaught)
1628 status = WinningCondition_Onslaught(); // TODO remove this?
1632 status = WinningCondition_Scores(fraglimit);
1635 if(status == WINNING_STARTOVERTIME)
1637 status = WINNING_NEVER;
1641 if(status == WINNING_NEVER)
1642 // equality cases! Nobody wins if the overtime ends in a draw.
1645 if(checkrules_overtimeend)
1646 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1647 status = WINNING_YES;
1649 if(status == WINNING_YES)
1653 float mapvote_nextthink;
1654 float mapvote_initialized;
1655 float mapvote_keeptwotime;
1656 float mapvote_timeout;
1657 string mapvote_message;
1658 string mapvote_screenshot_dir;
1660 float mapvote_count;
1661 float mapvote_count_real;
1662 string mapvote_maps[MAPVOTE_COUNT];
1663 float mapvote_maps_suggested[MAPVOTE_COUNT];
1664 string mapvote_suggestions[MAPVOTE_COUNT];
1665 float mapvote_suggestion_ptr;
1666 float mapvote_maxlen;
1667 float mapvote_voters;
1668 float mapvote_votes[MAPVOTE_COUNT];
1670 float mapvote_detail;
1671 float mapvote_abstain;
1672 float mapvote_dirty;
1675 void MapVote_ClearAllVotes()
1677 FOR_EACH_CLIENT(other)
1681 string MapVote_Suggest(string m)
1685 return "That's not how to use this command.";
1686 if(!cvar("g_maplist_votable_suggestions"))
1687 return "Suggestions are not accepted on this server.";
1688 if(mapvote_initialized)
1689 return "Can't suggest - voting is already in progress!";
1691 m = MapInfo_FixName(m);
1693 return "The map you suggested is not available on this server.";
1695 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1696 if(!IsSameGametype(m))
1697 return "This server does not allow changing the game type by map suggestions.";
1699 if(!cvar("g_maplist_votable_override_mostrecent"))
1701 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1704 if(!MapInfo_CheckMap(m))
1705 return "The map you suggested does not support the current game mode.";
1707 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1708 return "The map you suggested is not available on this server.";
1710 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1711 if(mapvote_suggestions[i] == m)
1712 return "This map was already suggested.";
1713 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1715 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1719 i = mapvote_suggestion_ptr;
1720 mapvote_suggestion_ptr += 1;
1722 if(mapvote_suggestions[i] != "")
1723 strunzone(mapvote_suggestions[i]);
1724 mapvote_suggestions[i] = strzone(m);
1725 if(cvar("sv_eventlog"))
1726 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)), TRUE);
1727 return strcat("Suggestion of ", m, " accepted.");
1730 void MapVote_AddVotable(string nextMap, float isSuggestion)
1735 for(j = 0; j < mapvote_count; ++j)
1736 if(mapvote_maps[j] == nextMap)
1738 if(strlen(nextMap) > mapvote_maxlen)
1739 mapvote_maxlen = strlen(nextMap);
1740 mapvote_maps[mapvote_count] = strzone(nextMap);
1741 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1745 void MapVote_SendData(float target);
1751 MapVote_ClearAllVotes();
1754 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1755 mapvote_abstain = cvar("g_maplist_votable_abstain");
1758 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1760 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1761 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
1763 if(mapvote_suggestion_ptr)
1764 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1765 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1767 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1768 MapVote_AddVotable(GetNextMap(), FALSE);
1770 if(mapvote_count == 0)
1772 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1774 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1775 localcmd("\nmenu_cmd sync\n");
1777 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1779 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1780 MapVote_AddVotable(GetNextMap(), FALSE);
1783 mapvote_count_real = mapvote_count;
1785 MapVote_AddVotable("don't care", 0);
1787 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1789 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1790 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1791 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1792 mapvote_keeptwotime = 0;
1793 mapvote_message = "Choose a map and press its key!";
1795 mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
1796 if(mapvote_screenshot_dir == "")
1797 mapvote_screenshot_dir = "maps";
1798 mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
1800 if(!cvar("g_maplist_textonly"))
1801 MapVote_SendData(MSG_ALL);
1804 void MapVote_SendPicture(float id)
1807 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1808 WriteByte(MSG_ONE, TE_CSQC_MAPVOTE);
1809 WriteByte(MSG_ONE, MAPVOTE_NET_PIC);
1810 WriteByte(MSG_ONE, id);
1811 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 1024);
1814 float GameCommand_MapVote(string cmd)
1816 if(!intermission_running)
1818 if(!cvar("g_maplist_textonly"))
1820 if(cmd == "mv_getpic")
1822 MapVote_SendPicture(stof(argv(1)));
1830 float MapVote_GetMapMask()
1832 float mask, i, power;
1834 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
1835 if(mapvote_maps[i] != "")
1840 void MapVote_SendData(float targ)
1842 string mapfile, pakfile;
1844 WriteByte(targ, SVC_TEMPENTITY);
1845 WriteByte(targ, TE_CSQC_CONFIG);
1846 WriteString(targ, "mv_screenshot_dir");
1847 WriteString(targ, mapvote_screenshot_dir);
1849 WriteByte(targ, SVC_TEMPENTITY);
1850 WriteByte(targ, TE_CSQC_MAPVOTE);
1851 WriteByte(targ, MAPVOTE_NET_INIT);
1853 WriteByte(targ, mapvote_count);
1854 WriteByte(targ, mapvote_abstain);
1855 WriteByte(targ, mapvote_detail);
1856 WriteByte(targ, mapvote_timeout - time);
1857 if(mapvote_count <= 8)
1858 WriteByte(targ, MapVote_GetMapMask());
1860 WriteShort(targ, MapVote_GetMapMask());
1861 for(i = 0; i < mapvote_count; ++i)
1862 if(mapvote_maps[i] != "")
1864 WriteString(targ, mapvote_maps[i]);
1865 mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
1866 pakfile = whichpack(strcat(mapfile, ".tga"));
1868 pakfile = whichpack(strcat(mapfile, ".jpg"));
1870 pakfile = whichpack(strcat(mapfile, ".png"));
1871 print("pakfile is ", pakfile, "\n");
1872 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
1873 pakfile = substring(pakfile, o, 999);
1874 WriteString(targ, pakfile);
1878 void MapVote_UpdateData(float targ)
1881 WriteByte(targ, SVC_TEMPENTITY);
1882 WriteByte(targ, TE_CSQC_MAPVOTE);
1883 WriteByte(targ, MAPVOTE_NET_UPDATE);
1884 if(mapvote_count <= 8)
1885 WriteByte(targ, MapVote_GetMapMask());
1887 WriteShort(targ, MapVote_GetMapMask());
1889 for(i = 0; i < mapvote_count; ++i)
1890 if(mapvote_maps[i] != "")
1891 WriteByte(targ, mapvote_votes[i]);
1894 void MapVote_TellVote(float targ, float vote)
1896 WriteByte(targ, SVC_TEMPENTITY);
1897 WriteByte(targ, TE_CSQC_MAPVOTE);
1898 WriteByte(targ, MAPVOTE_NET_OWNVOTE);
1899 WriteByte(targ, vote);
1902 float MapVote_Finished(float mappos)
1908 if(cvar("sv_eventlog"))
1910 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1911 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1912 didntvote = mapvote_voters;
1913 for(i = 0; i < mapvote_count; ++i)
1914 if(mapvote_maps[i] != "")
1916 didntvote -= mapvote_votes[i];
1919 result = strcat(result, ":", mapvote_maps[i]);
1920 result = strcat(result, ":", ftos(mapvote_votes[i]));
1923 result = strcat(result, ":didn't vote:", ftos(didntvote));
1925 GameLogEcho(result, FALSE);
1926 if(mapvote_maps_suggested[mappos])
1927 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
1930 FOR_EACH_REALCLIENT(other)
1931 FixClientCvars(other);
1933 Map_Goto_SetStr(mapvote_maps[mappos]);
1935 alreadychangedlevel = TRUE;
1938 void MapVote_CheckRules_1()
1942 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1944 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1945 mapvote_votes[i] = 0;
1949 FOR_EACH_REALCLIENT(other)
1954 i = other.mapvote - 1;
1955 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1956 mapvote_votes[i] = mapvote_votes[i] + 1;
1961 float MapVote_CheckRules_2()
1964 float firstPlace, secondPlace;
1965 float firstPlaceVotes, secondPlaceVotes;
1966 float mapvote_voters_real;
1969 mapvote_voters_real = mapvote_voters;
1971 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
1973 RandomSelection_Init();
1974 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1975 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
1976 firstPlace = RandomSelection_chosen_float;
1977 firstPlaceVotes = RandomSelection_best_priority;
1978 //dprint("First place: ", ftos(firstPlace), "\n");
1979 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1981 RandomSelection_Init();
1982 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1984 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
1985 secondPlace = RandomSelection_chosen_float;
1986 secondPlaceVotes = RandomSelection_best_priority;
1987 //dprint("Second place: ", ftos(secondPlace), "\n");
1988 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1990 if(firstPlace == -1)
1991 error("No first place in map vote... WTF?");
1993 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
1994 return MapVote_Finished(firstPlace);
1996 if(mapvote_keeptwotime)
1997 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2000 mapvote_dirty = TRUE;
2001 mapvote_message = "Now decide between the TOP TWO!";
2002 mapvote_keeptwotime = 0;
2003 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2004 result = strcat(result, ":", ftos(firstPlaceVotes));
2005 result = strcat(result, ":", mapvote_maps[secondPlace]);
2006 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2007 didntvote = mapvote_voters;
2008 for(i = 0; i < mapvote_count; ++i)
2009 if(mapvote_maps[i] != "")
2011 didntvote -= mapvote_votes[i];
2013 if(i != secondPlace)
2015 result = strcat(result, ":", mapvote_maps[i]);
2016 result = strcat(result, ":", ftos(mapvote_votes[i]));
2017 if(i < mapvote_count_real)
2019 strunzone(mapvote_maps[i]);
2020 mapvote_maps[i] = "";
2024 result = strcat(result, ":didn't vote:", ftos(didntvote));
2025 if(cvar("sv_eventlog"))
2026 GameLogEcho(result, FALSE);
2039 keeptwo = mapvote_keeptwotime;
2040 MapVote_CheckRules_1(); // count
2041 if(MapVote_CheckRules_2()) // decide
2045 FOR_EACH_REALCLIENT(other)
2047 // hide scoreboard again
2048 if(other.health != 2342)
2050 other.health = 2342;
2052 if(clienttype(other) == CLIENTTYPE_REAL)
2054 if(cvar("g_maplist_textonly"))
2055 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");
2058 WriteByte(MSG_ONE, SVC_FINALE);
2059 WriteString(MSG_ONE, "");
2063 // notify about keep-two
2064 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2065 play2(other, "misc/invshot.wav");
2067 // clear possibly invalid votes
2068 if(mapvote_maps[other.mapvote - 1] == "")
2070 // use impulses as new vote
2071 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2072 if(mapvote_maps[other.impulse - 1] != "")
2074 other.mapvote = other.impulse;
2076 mapvote_dirty = TRUE;
2079 MapVote_TellVote(MSG_ONE, other.mapvote);
2087 MapVote_CheckRules_1(); // just count
2089 if(!cvar("g_maplist_textonly"))
2090 if(mapvote_dirty) // 1 if "keeptwo" or "impulse" happened before
2092 MapVote_UpdateData(MSG_BROADCAST);
2093 mapvote_dirty = FALSE;
2096 if(cvar("g_maplist_textonly"))
2098 FOR_EACH_REALCLIENT(other)
2100 // display voting screen
2101 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2102 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2104 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2105 msgstr = strcat(msgstr, mapvote_message);
2106 msgstr = strcat(msgstr, "\n\n");
2107 for(i = 0; i < mapvote_count; ++i)
2108 if(mapvote_maps[i] == "")
2109 msgstr = strcat(msgstr, "\n");
2112 tmp = mapvote_maps[i];
2113 tmp = strpad(mapvote_maxlen, tmp);
2114 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2117 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2118 if(mapvote_votes[i] != 1)
2119 tmp = strcat(tmp, "s");
2120 tmp = strcat(tmp, ")");
2121 tmp = strpad(mapvote_maxlen + 15, tmp);
2124 if(i == mapvote_count - 1)
2125 msgstr = strcat(msgstr, "\n");
2126 if(other.mapvote == i + 1)
2127 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2129 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2132 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2134 msgstr = strcat(msgstr, "s");
2135 msgstr = strcat(msgstr, " cast");
2136 i = ceil(mapvote_timeout - time);
2137 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2139 msgstr = strcat(msgstr, "s");
2140 msgstr = strcat(msgstr, " left");
2142 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2146 void MapVote_Start()
2152 MapInfo_Enumerate();
2153 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2157 void MapVote_Think()
2162 if(alreadychangedlevel)
2165 if(time < mapvote_nextthink)
2169 mapvote_nextthink = time + 0.5;
2171 if(!mapvote_initialized)
2173 mapvote_initialized = TRUE;
2174 if(DoNextMapOverride())
2176 if(!cvar("g_maplist_votable") || player_count <= 0)
2187 string GotoMap(string m)
2190 if(!MapInfo_CheckMap(m))
2192 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2194 return "The map you chose is not available on this server.";
2195 cvar_set("nextmap", m);
2196 cvar_set("timelimit", "-1");
2197 if(mapvote_initialized || alreadychangedlevel)
2199 if(DoNextMapOverride())
2200 return "Map switch initiated.";
2202 return "Hm... no. For some reason I like THIS map more.";
2205 return "Map switch will happen after scoreboard.";
2211 FOR_EACH_REALCLIENT(self)
2213 if(self.classname == "spectator")
2215 if(self.enemy.hitsound)
2216 play2(self, "misc/hit.wav");
2221 play2(self, "misc/hit.wav");
2224 FOR_EACH_CLIENT(self)
2225 self.hitsound = FALSE;
2231 * returns TRUE if redirecting
2233 float redirection_timeout;
2234 float redirection_nextthink;
2235 float RedirectionThink()
2237 float clients_found;
2239 if(redirection_target == "")
2242 if(!redirection_timeout)
2244 cvar_set("sv_public", "-2");
2245 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2246 if(redirection_target == "self")
2247 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2249 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2252 if(time < redirection_nextthink)
2255 redirection_nextthink = time + 1;
2258 FOR_EACH_REALCLIENT(self)
2260 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2261 if(redirection_target == "self")
2262 stuffcmd(self, "\ndisconnect; reconnect\n");
2264 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2268 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2270 if(time > redirection_timeout || clients_found == 0)
2271 localcmd("\nwait; wait; wait; quit\n");
2278 // Loaded from a save game
2279 // some things then break, so let's work around them...
2281 // Progs DB (capture records)
2283 ServerProgsDB = db_create();
2285 ServerProgsDB = db_load("server.db");
2290 MapInfo_Enumerate();
2291 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
2297 if(world_initialized)
2299 world_initialized = 0;
2300 print("Saving persistent data...\n");
2303 db_save(ServerProgsDB, "server.db");
2304 db_close(ServerProgsDB);
2306 // tell the bot system the game is ending now
2313 print("NOTE: crashed before even initializing the world, not saving persistent data\n");