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.frags += 10;
53 if(world.frags > 0.2 || world.frags < -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;
182 MapInfo_LoadMapSettings(mapname);
186 ServerProgsDB = db_create();
188 ServerProgsDB = db_load("server.db");
191 TODO sound pack system
192 // initialize sound pack system
193 soundpack = cvar_string("g_soundpack");
195 soundpack = strcat(soundpack, "/");
196 soundpack = strzone(soundpack);
202 // 1 FLICKER (first variety)
203 lightstyle(1, "mmnmmommommnonmmonqnmmo");
205 // 2 SLOW STRONG PULSE
206 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
208 // 3 CANDLE (first variety)
209 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
212 lightstyle(4, "mamamamamama");
215 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
217 // 6 FLICKER (second variety)
218 lightstyle(6, "nmonqnmomnmomomno");
220 // 7 CANDLE (second variety)
221 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
223 // 8 CANDLE (third variety)
224 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
226 // 9 SLOW STROBE (fourth variety)
227 lightstyle(9, "aaaaaaaazzzzzzzz");
229 // 10 FLUORESCENT FLICKER
230 lightstyle(10, "mmamammmmammamamaaamammma");
232 // 11 SLOW PULSE NOT FADE TO BLACK
233 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
235 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
240 // for setting by mapinfo
241 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
242 cvar_set("sv_q3acompat_machineshotgunswap", "0");
245 lms_lowest_lives = 0;
248 bot_waypoints_for_items = cvar("g_waypoints_for_items");
249 if(bot_waypoints_for_items == 1)
250 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
251 bot_waypoints_for_items = 0;
253 if(cvar("g_campaign"))
260 WaypointSprite_Init();
266 head = nextent(world);
271 head = nextent(head);
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 if (game == GAME_DEATHMATCH)
387 else if (game == GAME_TEAM_DEATHMATCH)
389 else if (game == GAME_DOMINATION)
391 else if (game == GAME_CTF)
393 else if (game == GAME_RUNEMATCH)
395 else if (game == GAME_LMS)
397 else if (game == GAME_KEYHUNT)
399 else if (game == GAME_ONSLAUGHT)
401 else if (game == GAME_ASSAULT)
406 float IsSameGametype(string mapcfgname)
409 return TRUE; // can't change game type by map name here
413 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
419 string getmapname_stored;
425 if(getmapname_stored == "")
426 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
427 return getmapname_stored;
431 float Map_Count, Map_Current;
432 string Map_Current_Name;
434 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
435 float GetMaplistPosition()
441 idx = cvar("g_maplist_index");
448 for(pos = 0; pos < Map_Count; ++pos)
452 // resume normal maplist rotation if current map is not in g_maplist
456 float MapHasRightSize(string map)
459 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
460 if(cvar("g_maplist_check_waypoints"))
462 dprint("checkwp "); dprint(map);
463 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
466 dprint(": no waypoints\n");
469 dprint(": has waypoints\n");
473 // open map size restriction file
474 dprint("opensize "); dprint(map);
475 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
478 float mapmin, mapmax;
480 mapmin = stof(fgets(fh));
481 mapmax = stof(fgets(fh));
483 if(player_count < mapmin)
485 dprint("not enough\n");
488 if(player_count > mapmax)
490 dprint("too many\n");
493 dprint("right size\n");
496 dprint(": not found\n");
500 string Map_Filename(float position)
503 return strcat("maps/", argv(position), ".bsp");
505 return strcat("maps/", argv(position), ".mapcfg");
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);
549 if(MapInfo_CheckMap(map_next))
551 if(TryFile(filename))
556 if(MapHasRightSize(map_next))
561 dprint( "Couldn't select '", filename, "'..\n" );
566 void Map_Goto_SetStr(string nextmapname)
568 if(getmapname_stored != "")
569 strunzone(getmapname_stored);
570 if(nextmapname == "")
571 getmapname_stored = "";
573 getmapname_stored = strzone(nextmapname);
576 void Map_Goto_SetFloat(float position)
578 cvar_set("g_maplist_index", ftos(position));
579 Map_Goto_SetStr(argv(position));
585 // settings persist, except...
586 if(cvar("g_campaign"))
587 localcmd("\nexec mutator_reset.cfg\n");
588 localcmd("\nsettemp_restore\n");
590 // if an exit cfg is defined by exiting map, exec it.
592 exit_cfg = cvar_string("exit_cfg");
594 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
596 localcmd("exec game_reset.cfg\n");
602 Map_MarkAsRecent(getmapname_stored);
605 MapInfo_LoadMap(getmapname_stored);
607 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
611 // return codes of map selectors:
612 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
613 // -2 = permanent failure
614 float() MaplistMethod_Iterate = // usual method
618 for(pass = 1; pass <= 2; ++pass)
620 for(i = 1; i < Map_Count; ++i)
623 mapindex = mod(i + Map_Current, Map_Count);
624 if(Map_Check(mapindex, pass))
631 float() MaplistMethod_Repeat = // fallback method
633 if(Map_Check(Map_Current, 2))
638 float() MaplistMethod_Random = // random map selection
644 for(i = 0; i <= imax; ++i)
647 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
648 if(Map_Check(mapindex, 1))
654 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
655 // the exponent sets a bias on the map selection:
656 // the higher the exponent, the less likely "shortly repeated" same maps are
658 float i, j, imax, insertpos;
662 for(i = 0; i <= imax; ++i)
666 // now reinsert this at another position
667 insertpos = pow(random(), 1 / exponent); // ]0, 1]
668 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
669 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
670 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
672 // insert the current map there
675 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
676 newlist = strcat(newlist, " ", argv(j));
677 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
678 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
679 newlist = strcat(newlist, " ", argv(j));
680 newlist = substring(newlist, 1, strlen(newlist) - 1);
682 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
683 newlist = strcat(newlist, "'", argv(j), "'");
684 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
685 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
686 newlist = strcat(newlist, "'", argv(j), "'");
688 cvar_set("g_maplist", newlist);
690 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
692 Map_Count = tokenize(newlist);
695 // NOTE: the selected map has just been inserted at (insertpos-1)th position
696 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
697 if(Map_Check(Map_Current, 1))
706 temp = cvar_string("g_maplist");
708 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
710 Map_Count = tokenize(temp);
714 bprint( "Maplist is empty! Resetting it to default map list.\n" );
716 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
717 localcmd("\nmenu_cmd sync\n");
718 Map_Count = tokenizebyseparator(temp, " ");
720 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
721 Map_Count = tokenize(temp);
725 error("empty maplist, cannot select a new map");
726 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
728 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
729 // this may or may not be correct, but who cares, in the worst case a map
730 // isn't chosen in the first pass that should have been
741 if(cvar("g_maplist_shuffle") > 0)
742 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
745 if(cvar("g_maplist_selectrandom"))
746 nextMap = MaplistMethod_Random();
749 nextMap = MaplistMethod_Iterate();
752 nextMap = MaplistMethod_Repeat();
756 Map_Goto_SetFloat(nextMap);
757 return getmapname_stored;
763 float DoNextMapOverride()
765 if(cvar("g_campaign"))
767 CampaignPostIntermission();
768 alreadychangedlevel = TRUE;
771 if(cvar("quit_when_empty"))
773 if(player_count <= currentbots)
776 alreadychangedlevel = TRUE;
780 if(cvar_string("quit_and_redirect") != "")
782 redirection_target = strzone(cvar_string("quit_and_redirect"));
783 alreadychangedlevel = TRUE;
786 if (cvar("samelevel")) // if samelevel is set, stay on same level
788 // 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)
789 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
790 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
791 localcmd("restart\n");
792 //changelevel (mapname);
793 alreadychangedlevel = TRUE;
796 if(cvar_string("nextmap") != "")
798 if(MapInfo_CheckMap(cvar_string("nextmap")))
800 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
803 Map_Goto_SetStr(cvar_string("nextmap"));
805 alreadychangedlevel = TRUE;
808 if(cvar("lastlevel"))
811 localcmd("set lastlevel 0\ntogglemenu\n");
812 alreadychangedlevel = TRUE;
820 //local string nextmap;
821 //local float n, nummaps;
823 if (alreadychangedlevel)
825 alreadychangedlevel = TRUE;
831 for(allowReset = 1; allowReset >= 0; --allowReset)
833 nextMap = GetNextMap();
839 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
841 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
842 localcmd("\nmenu_cmd sync\n");
844 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
849 error("Everything is broken - not even the default map list works. Please report this to the developers.");
861 When the player presses attack or jump, change to the next level
864 .float autoscreenshot;
865 void() MapVote_Start;
866 void() MapVote_Think;
867 float mapvote_initialized;
868 void IntermissionThink()
870 FixIntermissionClient(self);
872 if(cvar("sv_autoscreenshot"))
873 if(self.autoscreenshot > 0)
874 if(time > self.autoscreenshot)
876 self.autoscreenshot = -1;
877 if(clienttype(self) == CLIENTTYPE_REAL)
878 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
882 if (time < intermission_exittime)
885 if(!mapvote_initialized)
886 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
896 Returns the entity to view from
900 entity FindIntermission()
905 // look for info_intermission first
906 spot = find (world, classname, "info_intermission");
908 { // pick a random one
912 spot = find (spot, classname, "info_intermission");
914 spot = find (spot, classname, "info_intermission");
920 // then look for the start position
921 spot = find (world, classname, "info_player_start");
925 // testinfo_player_start is only found in regioned levels
926 spot = find (world, classname, "testplayerstart");
930 // then look for the start position
931 spot = find (world, classname, "info_player_deathmatch");
935 //objerror ("FindIntermission: no spot");
941 ===============================================================================
945 ===============================================================================
948 void DumpStats(float final)
952 local float to_console;
953 local float to_eventlog;
956 to_console = cvar("sv_logscores_console");
957 to_eventlog = cvar("sv_eventlog");
958 to_file = cvar("sv_logscores_file");
962 to_console = TRUE; // always print printstats replies
963 to_eventlog = FALSE; // but never print them to the event log
967 if(cvar("sv_eventlog_console"))
968 to_console = FALSE; // otherwise we get the output twice
975 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
977 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
981 ServerConsoleEcho(s, FALSE);
983 GameLogEcho(s, FALSE);
986 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
990 fputs(file, strcat(s, "\n"));
993 FOR_EACH_CLIENT(other)
995 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
997 s = strcat(":player:", ftos(other.frags), ":");
998 s = strcat(s, ftos(other.deaths), ":");
999 s = strcat(s, ftos(rint(time - other.jointime)), ":");
1000 s = strcat(s, ftos(other.team), ":");
1003 ServerConsoleEcho(strcat(s, other.netname), TRUE);
1005 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
1007 fputs(file, strcat(s, other.netname, "\n"));
1012 ServerConsoleEcho(":end", FALSE);
1014 GameLogEcho(":end", FALSE);
1017 fputs(file, ":end\n");
1022 void FixIntermissionClient(entity e)
1025 if(!e.autoscreenshot) // initial call
1027 e.angles = e.v_angle;
1028 e.angles_x = -e.angles_x;
1029 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1031 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1032 e.solid = SOLID_NOT;
1033 e.movetype = MOVETYPE_NONE;
1034 e.takedamage = DAMAGE_NO;
1036 e.weaponentity.effects = EF_NODRAW;
1037 if(clienttype(e) == CLIENTTYPE_REAL)
1039 stuffcmd(e, "\nscr_printspeed 1000000\n");
1040 s = cvar_string("sv_intermission_cdtrack");
1042 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1044 WriteByte(MSG_ONE, SVC_INTERMISSION);
1048 //e.velocity = '0 0 0';
1049 //e.fixangle = TRUE;
1051 // TODO halt weapon animation
1056 go to the next level for deathmatch
1057 only called if a time or frag limit has expired
1061 float minTotalFrags;
1062 float maxTotalFrags;
1068 intermission_running = 1;
1070 // enforce a wait time before allowing changelevel
1071 if(player_count > 0)
1072 intermission_exittime = time + cvar("sv_mapchange_delay");
1074 intermission_exittime = -1;
1077 WriteByte (MSG_ALL, SVC_CDTRACK);
1078 WriteByte (MSG_ALL, 3);
1079 WriteByte (MSG_ALL, 3);
1080 // done in FixIntermission
1083 //pos = FindIntermission ();
1089 if(cvar("sv_eventlog"))
1090 GameLogEcho(":gameover", FALSE);
1094 FOR_EACH_CLIENT(other)
1096 FixIntermissionClient(other);
1099 bprint(other.netname, " ^7wins.\n");
1104 FOR_EACH_PLAYER(other)
1106 if(maxTotalFrags < other.totalfrags)
1107 maxTotalFrags = other.totalfrags;
1108 if(minTotalFrags > other.totalfrags)
1109 minTotalFrags = other.totalfrags;
1114 FOR_EACH_PLAYER(other)
1116 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1117 f = bound(0, other.play_time / max(time, 1), 1);
1118 // store some statistics?
1122 if(cvar("g_campaign"))
1123 CampaignPreIntermission();
1125 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1132 Exit deathmatch games upon conditions
1136 void CheckRules_Player()
1138 if (gameover) // someone else quit the game already
1141 if(self.deadflag == DEAD_NO)
1142 self.play_time += frametime;
1146 if(time > self.fogtime)
1148 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1149 self.fogtime = time + sv_foginterval;
1152 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1153 // (div0: and that in CheckRules_World please)
1156 float checkrules_oneminutewarning;
1157 float checkrules_leaderfrags;
1158 float tdm_max_score, tdm_old_score;
1160 float checkrules_equality;
1161 float checkrules_overtimewarning;
1162 float checkrules_overtimeend;
1164 void InitiateOvertime()
1166 if(!checkrules_overtimeend)
1167 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1170 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1171 float WINNING_YES = 1; // winner found
1172 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1173 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1175 float GetWinningCode(float fraglimitreached, float equality)
1178 if(fraglimitreached)
1179 return WINNING_STARTOVERTIME;
1181 return WINNING_NEVER;
1183 if(fraglimitreached)
1189 // set the .winning flag for exactly those players with a given field value
1190 void SetWinners(.float field, float value)
1193 FOR_EACH_PLAYER(head)
1194 head.winning = (head.field == value);
1197 // set the .winning flag for those players with a given field value
1198 void AddWinners(.float field, float value)
1201 FOR_EACH_PLAYER(head)
1202 if(head.field == value)
1206 // clear frags for all players but the team given (when they ran out of spawnpoints)
1207 void ClearFragsForEveryoneBut(.float field, float value)
1210 FOR_EACH_PLAYER(head)
1211 if(head.field != value)
1212 head.frags = max(head.frags, 0);
1215 // clear the .winning flags
1216 void ClearWinners(void)
1219 FOR_EACH_PLAYER(head)
1223 // Onslaught winning condition:
1224 // game terminates if only one team has a working generator (or none)
1225 float WinningCondition_Onslaught()
1228 local float t1, t2, t3, t4;
1229 // first check if the game has ended
1230 t1 = t2 = t3 = t4 = 0;
1231 head = find(world, classname, "onslaught_generator");
1234 if (head.health > 0)
1236 if (head.team == COLOR_TEAM1) t1 = 1;
1237 if (head.team == COLOR_TEAM2) t2 = 1;
1238 if (head.team == COLOR_TEAM3) t3 = 1;
1239 if (head.team == COLOR_TEAM4) t4 = 1;
1241 head = find(head, classname, "onslaught_generator");
1243 if (t1 + t2 + t3 + t4 < 2)
1245 // game over, only one team remains (or none)
1247 if (t1) SetWinners(team, COLOR_TEAM1);
1248 if (t2) SetWinners(team, COLOR_TEAM2);
1249 if (t3) SetWinners(team, COLOR_TEAM3);
1250 if (t4) SetWinners(team, COLOR_TEAM4);
1251 dprint("Have a winner, ending game.\n");
1255 // Two or more teams remain
1259 float LMS_NewPlayerLives()
1262 fl = cvar("fraglimit");
1266 // first player has left the game for dying too much? Nobody else can get in.
1267 if(lms_lowest_lives < 1)
1270 if(!cvar("g_lms_join_anytime"))
1271 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1274 return bound(1, lms_lowest_lives, fl);
1277 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1278 // they win. Otherwise the defending team wins once the timelimit passes.
1279 void assault_new_round();
1280 float WinningCondition_Assault()
1283 status = WINNING_NO;
1285 // as the timelimit has not yet passed just assume the defending team will win
1286 if(assault_attacker_team == COLOR_TEAM1)
1288 SetWinners(team, COLOR_TEAM2);
1292 SetWinners(team, COLOR_TEAM1);
1296 ent = find(world, classname, "target_assault_roundend");
1299 if(ent.winning) // round end has been triggered by attacking team
1301 SetWinners(team, assault_attacker_team);
1302 if(assault_attacker_team == COLOR_TEAM1)
1304 team1_score = team1_score + 50;
1308 team2_score = team2_score + 50;
1311 if(ent.cnt == 1) // this was the second round
1313 status = WINNING_YES;
1317 cvar_set("timelimit", ftos((2*time)/60));
1318 assault_new_round();
1328 // LMS winning condition: game terminates if and only if there's at most one
1329 // one player who's living lives. Top two scores being equal cancels the time
1331 float WinningCondition_LMS()
1338 have_player = FALSE;
1339 have_players = FALSE;
1340 l = LMS_NewPlayerLives();
1342 head = find(world, classname, "player");
1345 head = find(head, classname, "player");
1347 have_players = TRUE;
1351 // we have at least one player
1354 // two or more active players - continue with the game
1358 // exactly one player?
1361 // but no game has taken place yet
1366 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1367 dprint("Have a winner, ending game.\n");
1374 // nobody is playing at all...
1377 // wait for players...
1381 // SNAFU (maybe a draw game?)
1383 dprint("No players, ending game.\n");
1388 // When we get here, we have at least two players who are actually LIVING,
1389 // or one player who is still waiting for a victim to join the server. Now
1390 // check if the top two players have equal score.
1392 checkrules_leaderfrags = 0;
1393 checkrules_equality = FALSE;
1394 FOR_EACH_PLAYER(head)
1396 if(head.frags > checkrules_leaderfrags)
1398 checkrules_leaderfrags = head.frags;
1399 checkrules_equality = FALSE;
1401 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1402 checkrules_equality = TRUE;
1405 SetWinners(frags, checkrules_leaderfrags);
1407 // The top two players have the same amount of lives? No timelimit then,
1408 // enter overtime...
1410 if(checkrules_equality)
1411 return WINNING_NEVER;
1413 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1417 // DM winning condition: game terminates if a player reached the fraglimit,
1418 // unless the first two players have the same score. The latter case also
1419 // breaks the time limit.
1420 float WinningCondition_MaxIndividualScore(float fraglimit)
1422 float checkrules_oldleaderfrags;
1425 checkrules_oldleaderfrags = checkrules_leaderfrags;
1426 checkrules_leaderfrags = 0;
1427 checkrules_equality = FALSE;
1428 FOR_EACH_PLAYER(head)
1430 if(head.frags > checkrules_leaderfrags)
1432 checkrules_leaderfrags = head.frags;
1433 checkrules_equality = FALSE;
1435 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1436 checkrules_equality = TRUE;
1439 if(checkrules_leaderfrags > 0)
1440 SetWinners(frags, checkrules_leaderfrags);
1445 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1447 if (checkrules_leaderfrags == fraglimit - 1)
1448 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1449 else if (checkrules_leaderfrags == fraglimit - 2)
1450 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1451 else if (checkrules_leaderfrags == fraglimit - 3)
1452 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1455 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1458 float WinningConditionBase_Teamplay(float fraglimit)
1460 tdm_old_score = tdm_max_score;
1461 tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1463 checkrules_equality =
1468 (team1_score == tdm_max_score)
1469 + (team2_score == tdm_max_score)
1470 + (team3_score == tdm_max_score)
1471 + (team4_score == tdm_max_score)
1475 if(tdm_max_score > 0)
1477 if(team1_score == tdm_max_score)
1478 AddWinners(team, COLOR_TEAM1);
1479 if(team2_score == tdm_max_score)
1480 AddWinners(team, COLOR_TEAM2);
1481 if(team3_score == tdm_max_score)
1482 AddWinners(team, COLOR_TEAM3);
1483 if(team4_score == tdm_max_score)
1484 AddWinners(team, COLOR_TEAM4);
1487 if(!g_runematch && !g_domination && !g_ctf)
1488 if(tdm_max_score != tdm_old_score)
1490 if(tdm_max_score == fraglimit - 1)
1491 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1492 else if(tdm_max_score == fraglimit - 2)
1493 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1494 else if(tdm_max_score == fraglimit - 3)
1495 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1498 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1501 // TDM winning condition: game terminates if a team's score sum reached the
1502 // fraglimit, unless the first two teams have the same total score. The latter
1503 // case also breaks the time limit.
1504 float WinningCondition_MaxTeamSum(float fraglimit)
1508 team1_score = team2_score = team3_score = team4_score = 0;
1510 FOR_EACH_PLAYER(head)
1512 if(head.team == COLOR_TEAM1)
1513 team1_score += head.frags;
1514 else if(head.team == COLOR_TEAM2)
1515 team2_score += head.frags;
1516 else if(head.team == COLOR_TEAM3)
1517 team3_score += head.frags;
1518 else if(head.team == COLOR_TEAM4)
1519 team4_score += head.frags;
1522 return WinningConditionBase_Teamplay(fraglimit);
1525 // DOM/CTF winning condition: game terminates if the max of a team's players'
1526 // score reached the fraglimit, unless the first two teams have the same
1527 // maximum score. The latter case also breaks the time limit.
1528 float WinningCondition_MaxTeamMax(float fraglimit)
1532 team1_score = team2_score = team3_score = team4_score = 0;
1534 FOR_EACH_PLAYER(head)
1536 if(head.team == COLOR_TEAM1)
1538 if(head.frags > team1_score)
1539 team1_score = head.frags;
1541 else if(head.team == COLOR_TEAM2)
1543 if(head.frags > team2_score)
1544 team2_score = head.frags;
1546 else if(head.team == COLOR_TEAM3)
1548 if(head.frags > team3_score)
1549 team3_score = head.frags;
1551 else if(head.team == COLOR_TEAM4)
1553 if(head.frags > team4_score)
1554 team4_score = head.frags;
1558 return WinningConditionBase_Teamplay(fraglimit);
1561 float WinningCondition_CTF(float capturelimit, float fraglimit)
1563 if(cvar("g_ctf_win_mode") == 2)
1564 return WinningCondition_MaxTeamSum(fraglimit);
1566 team1_score = caps_team1;
1567 team2_score = caps_team2;
1568 team3_score = team4_score = 0;
1570 if(team1_score == team2_score && cvar("g_ctf_win_mode"))
1572 return WinningCondition_MaxTeamSum(0);
1575 return WinningConditionBase_Teamplay(capturelimit);
1578 void print_to(entity e, string s)
1581 sprint(e, strcat(s, "\n"));
1583 ServerConsoleEcho(s, TRUE);
1586 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1596 FOR_EACH_PLAYER(head)
1598 if(!whichteam || head.team == whichteam)
1602 print_to(e, strcat(" ", colorcode, name, ":"));
1604 fragtotal = fragtotal + head.frags;
1605 s = ftos(head.frags);
1606 s = strcat(s, "/", ftos(head.deaths));
1607 s = strcat(s, " @ ", ftos(head.ping));
1608 if(clienttype(head) == CLIENTTYPE_BOT)
1609 s = strcat(s, "botms");
1611 s = strcat(s, "ms");
1612 v = PlayerValue(head);
1614 s = strcat(s, " / ", ftos(v));
1615 print_to(e, strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"));
1618 if(whichteam && found)
1620 s = ftos(fragtotal);
1621 s = strcat(s, " / ", ftos(teamvalue));
1622 print_to(e, strcat(colorcode, " (total: ", s, ")"));
1626 void PrintScoreboard(entity e)
1628 print_to(e, strcat("Time: ", ftos(time / 60)));
1629 print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1630 print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1631 print_to(e, "Scoreboard:");
1634 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1635 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1636 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM3);
1637 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM4);
1641 PrintScoreboardFor(e, "", "^7", 0);
1646 void ShuffleMaplist()
1654 result = cvar_string("g_maplist");
1656 litems = tokenizebyseparator(result, " ");
1658 litems = tokenize(result);
1661 for(start = 0; start < litems - 1; ++start)
1665 // select a random item
1666 selected = ceil(random() * (litems - start) + start) - 1;
1668 // shift this item to the place start
1670 for(i = 0; i < start; ++i)
1671 result = strcat(result, " ", argv(i));
1672 result = strcat(result, " ", argv(selected));
1673 for(i = start; i < litems; ++i)
1675 result = strcat(result, " ", argv(i));
1676 result = substring(result, 1, strlen(result) - 1);
1678 litems = tokenizebyseparator(result, " ");
1680 for(i = 0; i < start; ++i)
1681 result = strcat(result, "'", argv(i), "'");
1682 result = strcat(result, "'", argv(selected), "'");
1683 for(i = start; i < litems; ++i)
1685 result = strcat(result, "'", argv(i), "'");
1687 litems = tokenize(result);
1690 //dprint(result, "\n");
1693 cvar_set("g_maplist", result);
1696 float WinningCondition_RanOutOfSpawns()
1700 if(!have_team_spawns)
1703 if(!some_spawn_has_been_used)
1706 team1_score = team2_score = team3_score = team4_score = 0;
1708 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1710 if(head.team == COLOR_TEAM1)
1712 else if(head.team == COLOR_TEAM2)
1714 else if(head.team == COLOR_TEAM3)
1716 else if(head.team == COLOR_TEAM4)
1720 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1722 if(head.team == COLOR_TEAM1)
1724 else if(head.team == COLOR_TEAM2)
1726 else if(head.team == COLOR_TEAM3)
1728 else if(head.team == COLOR_TEAM4)
1733 if(team1_score + team2_score + team3_score + team4_score == 0)
1735 checkrules_equality = TRUE;
1738 else if(team1_score + team2_score + team3_score + team4_score == 1)
1742 AddWinners(team, COLOR_TEAM1);
1743 ClearFragsForEveryoneBut(team, COLOR_TEAM1);
1747 AddWinners(team, COLOR_TEAM2);
1748 ClearFragsForEveryoneBut(team, COLOR_TEAM2);
1752 AddWinners(team, COLOR_TEAM3);
1753 ClearFragsForEveryoneBut(team, COLOR_TEAM3);
1757 AddWinners(team, COLOR_TEAM4);
1758 ClearFragsForEveryoneBut(team, COLOR_TEAM4);
1770 Exit deathmatch games upon conditions
1773 void CheckRules_World()
1776 local float timelimit;
1777 local float fraglimit;
1778 local float capturelimit;
1786 MapVote_Think should now do that part
1787 if (intermission_running)
1788 if (time >= intermission_exittime + 60)
1790 if(!DoNextMapOverride())
1796 if (gameover) // someone else quit the game already
1798 if(player_count == 0) // Nobody there? Then let's go to the next map
1800 // this will actually check the player count in the next frame
1801 // again, but this shouldn't hurt
1805 timelimit = cvar("timelimit") * 60;
1806 fraglimit = cvar("fraglimit");
1807 capturelimit = cvar("capturelimit");
1809 if(checkrules_overtimeend)
1811 if(!checkrules_overtimewarning)
1813 checkrules_overtimewarning = TRUE;
1814 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1815 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1820 if (timelimit && time >= timelimit)
1824 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1830 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1832 checkrules_oneminutewarning = TRUE;
1833 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1836 status = WinningCondition_RanOutOfSpawns();
1837 if(status == WINNING_YES)
1839 bprint("Hey! Someone ran out of spawns!\n");
1843 status = WinningCondition_Assault();
1847 status = WinningCondition_LMS();
1849 else if (g_onslaught)
1851 status = WinningCondition_Onslaught();
1855 status = WinningCondition_CTF(capturelimit, fraglimit);
1861 if(g_tdm || g_runematch || g_ctf || g_domination || g_keyhunt)
1862 status = WinningCondition_MaxTeamSum(fraglimit);
1864 // status = WinningCondition_MaxTeamMax(fraglimit);
1867 dprint("div0: How can this happen?\n");
1868 status = WinningCondition_MaxTeamMax(fraglimit);
1872 status = WinningCondition_MaxIndividualScore(fraglimit);
1875 if(status == WINNING_STARTOVERTIME)
1877 status = WINNING_NEVER;
1881 if(status == WINNING_NEVER)
1882 // equality cases! Nobody wins if the overtime ends in a draw.
1885 if(checkrules_overtimeend)
1886 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1887 status = WINNING_YES;
1889 if(status == WINNING_YES)
1893 float randsel_value;
1894 float randsel_priority;
1895 float randsel_count;
1899 randsel_priority = -1;
1902 void RandSel_Add(float priority, float value)
1904 if(priority > randsel_priority)
1906 randsel_priority = priority;
1907 randsel_value = value;
1910 else if(priority == randsel_priority)
1913 if(ceil(random() * randsel_count) == 1)
1914 randsel_value = value;
1918 float mapvote_nextthink;
1919 float mapvote_initialized;
1920 float mapvote_keeptwotime;
1921 float mapvote_timeout;
1922 string mapvote_message;
1924 #define MAPVOTE_COUNT 10
1925 float mapvote_count;
1926 float mapvote_count_real;
1927 string mapvote_maps[MAPVOTE_COUNT];
1928 float mapvote_maps_suggested[MAPVOTE_COUNT];
1929 string mapvote_suggestions[MAPVOTE_COUNT];
1930 float mapvote_suggestion_ptr;
1931 float mapvote_maxlen;
1932 float mapvote_voters;
1933 float mapvote_votes[MAPVOTE_COUNT];
1935 float mapvote_detail;
1936 float mapvote_abstain;
1939 void MapVote_ClearAllVotes()
1941 FOR_EACH_CLIENT(other)
1945 string MapVote_Suggest(string m)
1949 return "That's not how to use this command.";
1950 if(!cvar("g_maplist_votable_suggestions"))
1951 return "Suggestions are not accepted on this server.";
1952 if(mapvote_initialized)
1953 return "Can't suggest - voting is already in progress!";
1955 m = MapInfo_FixName(m);
1957 return "The map you suggested is not available on this server.";
1959 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1960 if(!IsSameGametype(m))
1961 return "This server does not allow changing the game type by map suggestions.";
1963 if(!cvar("g_maplist_votable_override_mostrecent"))
1965 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1968 if(!MapInfo_CheckMap(m))
1969 return "The map you suggested does not support the current game mode.";
1971 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1972 return "The map you suggested is not available on this server.";
1974 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1975 if(mapvote_suggestions[i] == m)
1976 return "This map was already suggested.";
1977 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1979 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1983 i = mapvote_suggestion_ptr;
1984 mapvote_suggestion_ptr += 1;
1986 if(mapvote_suggestions[i] != "")
1987 strunzone(mapvote_suggestions[i]);
1988 mapvote_suggestions[i] = strzone(m);
1989 if(cvar("sv_eventlog"))
1990 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)), TRUE);
1991 return strcat("Suggestion of ", m, " accepted.");
1994 void MapVote_AddVotable(string nextMap, float isSuggestion)
1999 for(j = 0; j < mapvote_count; ++j)
2000 if(mapvote_maps[j] == nextMap)
2002 if(strlen(nextMap) > mapvote_maxlen)
2003 mapvote_maxlen = strlen(nextMap);
2004 mapvote_maps[mapvote_count] = strzone(nextMap);
2005 mapvote_maps_suggested[mapvote_count] = isSuggestion;
2014 MapVote_ClearAllVotes();
2017 mapvote_detail = !cvar("g_maplist_votable_nodetail");
2018 mapvote_abstain = cvar("g_maplist_votable_abstain");
2021 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
2023 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
2024 smax = min(nmax, cvar("g_maplist_votable_suggestions"));
2026 for(i = 0; i < 100 && mapvote_count < smax; ++i)
2027 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
2029 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2030 MapVote_AddVotable(GetNextMap(), FALSE);
2032 if(mapvote_count == 0)
2034 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
2036 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
2037 localcmd("\nmenu_cmd sync\n");
2039 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
2041 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2042 MapVote_AddVotable(GetNextMap(), FALSE);
2045 mapvote_count_real = mapvote_count;
2047 MapVote_AddVotable("don't care", 0);
2049 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
2051 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
2052 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
2053 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
2054 mapvote_keeptwotime = 0;
2055 mapvote_message = "Choose a map and press its key!";
2057 float MapVote_Finished(float mappos)
2063 if(cvar("sv_eventlog"))
2065 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2066 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
2067 didntvote = mapvote_voters;
2068 for(i = 0; i < mapvote_count; ++i)
2069 if(mapvote_maps[i] != "")
2071 didntvote -= mapvote_votes[i];
2074 result = strcat(result, ":", mapvote_maps[i]);
2075 result = strcat(result, ":", ftos(mapvote_votes[i]));
2078 result = strcat(result, ":didn't vote:", ftos(didntvote));
2080 GameLogEcho(result, FALSE);
2081 if(mapvote_maps_suggested[mappos])
2082 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
2085 FOR_EACH_REALCLIENT(other)
2086 FixClientCvars(other);
2088 Map_Goto_SetStr(mapvote_maps[mappos]);
2090 alreadychangedlevel = TRUE;
2093 void MapVote_CheckRules_1()
2097 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2099 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2100 mapvote_votes[i] = 0;
2104 FOR_EACH_REALCLIENT(other)
2109 i = other.mapvote - 1;
2110 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2111 mapvote_votes[i] = mapvote_votes[i] + 1;
2116 float MapVote_CheckRules_2()
2119 float firstPlace, secondPlace;
2120 float firstPlaceVotes, secondPlaceVotes;
2121 float mapvote_voters_real;
2124 mapvote_voters_real = mapvote_voters;
2126 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2129 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2130 RandSel_Add(mapvote_votes[i], i);
2131 firstPlace = randsel_value;
2132 firstPlaceVotes = randsel_priority;
2133 //dprint("First place: ", ftos(firstPlace), "\n");
2134 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2137 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2139 RandSel_Add(mapvote_votes[i], i);
2140 secondPlace = randsel_value;
2141 secondPlaceVotes = randsel_priority;
2142 //dprint("Second place: ", ftos(secondPlace), "\n");
2143 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2145 if(firstPlace == -1)
2146 error("No first place in map vote... WTF?");
2148 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2149 return MapVote_Finished(firstPlace);
2151 if(mapvote_keeptwotime)
2152 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2155 mapvote_message = "Now decide between the TOP TWO!";
2156 mapvote_keeptwotime = 0;
2157 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2158 result = strcat(result, ":", ftos(firstPlaceVotes));
2159 result = strcat(result, ":", mapvote_maps[secondPlace]);
2160 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2161 didntvote = mapvote_voters;
2162 for(i = 0; i < mapvote_count; ++i)
2163 if(mapvote_maps[i] != "")
2165 didntvote -= mapvote_votes[i];
2167 if(i != secondPlace)
2169 result = strcat(result, ":", mapvote_maps[i]);
2170 result = strcat(result, ":", ftos(mapvote_votes[i]));
2171 if(i < mapvote_count_real)
2173 strunzone(mapvote_maps[i]);
2174 mapvote_maps[i] = "";
2178 result = strcat(result, ":didn't vote:", ftos(didntvote));
2179 if(cvar("sv_eventlog"))
2180 GameLogEcho(result, FALSE);
2193 keeptwo = mapvote_keeptwotime;
2194 MapVote_CheckRules_1(); // count
2195 if(MapVote_CheckRules_2()) // decide
2199 FOR_EACH_REALCLIENT(other)
2201 // hide scoreboard again
2202 if(other.health != 2342)
2204 other.health = 2342;
2206 if(clienttype(other) == CLIENTTYPE_REAL)
2208 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");
2210 WriteByte(MSG_ONE, SVC_FINALE);
2211 WriteString(MSG_ONE, "");
2215 // notify about keep-two
2216 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2217 play2(other, "misc/invshot.wav");
2219 // clear possibly invalid votes
2220 if(mapvote_maps[other.mapvote - 1] == "")
2222 // use impulses as new vote
2223 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2224 if(mapvote_maps[other.impulse - 1] != "")
2225 other.mapvote = other.impulse;
2232 MapVote_CheckRules_1(); // just count
2234 FOR_EACH_REALCLIENT(other)
2236 // display voting screen
2237 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2238 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2240 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2241 msgstr = strcat(msgstr, mapvote_message);
2242 msgstr = strcat(msgstr, "\n\n");
2243 for(i = 0; i < mapvote_count; ++i)
2244 if(mapvote_maps[i] == "")
2245 msgstr = strcat(msgstr, "\n");
2248 tmp = mapvote_maps[i];
2249 tmp = strpad(mapvote_maxlen, tmp);
2250 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2253 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2254 if(mapvote_votes[i] != 1)
2255 tmp = strcat(tmp, "s");
2256 tmp = strcat(tmp, ")");
2257 tmp = strpad(mapvote_maxlen + 15, tmp);
2260 if(i == mapvote_count - 1)
2261 msgstr = strcat(msgstr, "\n");
2262 if(other.mapvote == i + 1)
2263 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2265 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2268 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2270 msgstr = strcat(msgstr, "s");
2271 msgstr = strcat(msgstr, " cast");
2272 i = ceil(mapvote_timeout - time);
2273 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2275 msgstr = strcat(msgstr, "s");
2276 msgstr = strcat(msgstr, " left");
2278 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2281 void MapVote_Start()
2287 MapInfo_Enumerate();
2288 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2292 void MapVote_Think()
2297 if(alreadychangedlevel)
2300 if(time < mapvote_nextthink)
2304 mapvote_nextthink = time + 0.5;
2306 if(!mapvote_initialized)
2308 mapvote_initialized = TRUE;
2309 if(DoNextMapOverride())
2311 if(!cvar("g_maplist_votable") || player_count <= 0)
2322 string GotoMap(string m)
2325 if(!MapInfo_CheckMap(m))
2327 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2329 return "The map you chose is not available on this server.";
2330 cvar_set("nextmap", m);
2331 cvar_set("timelimit", "-1");
2332 if(mapvote_initialized || alreadychangedlevel)
2334 if(DoNextMapOverride())
2335 return "Map switch initiated.";
2337 return "Hm... no. For some reason I like THIS map more.";
2340 return "Map switch will happen after scoreboard.";
2346 FOR_EACH_REALCLIENT(self)
2348 if(self.classname == "spectator")
2350 if(self.enemy.hitsound)
2351 play2(self, "misc/hit.wav");
2356 play2(self, "misc/hit.wav");
2359 FOR_EACH_CLIENT(self)
2360 self.hitsound = FALSE;
2366 * returns TRUE if redirecting
2368 float redirection_timeout;
2369 float redirection_nextthink;
2370 float RedirectionThink()
2372 float clients_found;
2374 if(redirection_target == "")
2377 if(!redirection_timeout)
2379 cvar_set("sv_public", "-2");
2380 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2381 if(redirection_target == "self")
2382 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2384 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2387 if(time < redirection_nextthink)
2390 redirection_nextthink = time + 1;
2393 FOR_EACH_REALCLIENT(self)
2395 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2396 if(redirection_target == "self")
2397 stuffcmd(self, "\ndisconnect; reconnect\n");
2399 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2403 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2405 if(time > redirection_timeout || clients_found == 0)
2406 localcmd("\nwait; wait; wait; quit\n");
2413 if(world_initialized)
2415 world_initialized = 0;
2416 print("Saving persistent data...\n");
2419 db_save(ServerProgsDB, "server.db");
2421 // tell the bot system the game is ending now
2426 print("NOTE: crashed before even initializing the world, not saving persistent data\n");