1 float SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS = 1;
2 string redirection_target;
8 float() DoNextMapOverride;
10 void SetDefaultAlpha()
12 if(cvar("g_running_guns"))
14 default_player_alpha = -1;
15 default_weapon_alpha = +1;
19 default_player_alpha = cvar("g_balance_cloaked_alpha");
20 default_weapon_alpha = default_player_alpha;
24 default_player_alpha = cvar("g_player_alpha");
25 if(default_player_alpha <= 0)
26 default_player_alpha = 1;
27 default_weapon_alpha = default_player_alpha;
31 void fteqcc_testbugs()
35 if(!cvar("developer_fteqccbugs"))
38 dprint("*** fteqcc test: checking for bugs...\n");
42 if(sqrt(a) - sqrt(b - a) == 0)
43 dprint("*** fteqcc test: found same-function-twice bug\n");
45 dprint("*** fteqcc test: same-function-twice bug got FINALLY FIXED! HOORAY!\n");
49 world.enemy.frags += 10;
50 if(world.frags > 0.2 || world.frags < -0.2) // don't error out if it's just roundoff errors
51 dprint("*** fteqcc test: found += bug\n");
53 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
61 cvar_set("_sv_init", "0");
62 if(cvar("g_maplist_shuffle"))
65 tokenizebyseparator(cvar_string("g_maplist"), " ");
67 tokenize(cvar_string("g_maplist"));
69 if(argv(0) != GetMapname())
71 cvar_set("nextmap", argv(0));
75 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
78 if(!DoNextMapOverride())
84 float world_already_spawned;
85 void worldspawn (void)
87 dprint_load(); // load dprint status from cvar
89 if(world_already_spawned)
90 error("world already spawned - you may have EXACTLY ONE worldspawn!");
91 world_already_spawned = TRUE;
94 MapInfo_LoadMapSettings(mapname);
97 ServerProgsDB = db_load("server.db");
100 TODO sound pack system
101 // initialize sound pack system
102 soundpack = cvar_string("g_soundpack");
104 soundpack = strcat(soundpack, "/");
105 soundpack = strzone(soundpack);
111 // 1 FLICKER (first variety)
112 lightstyle(1, "mmnmmommommnonmmonqnmmo");
114 // 2 SLOW STRONG PULSE
115 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
117 // 3 CANDLE (first variety)
118 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
121 lightstyle(4, "mamamamamama");
124 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
126 // 6 FLICKER (second variety)
127 lightstyle(6, "nmonqnmomnmomomno");
129 // 7 CANDLE (second variety)
130 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
132 // 8 CANDLE (third variety)
133 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
135 // 9 SLOW STROBE (fourth variety)
136 lightstyle(9, "aaaaaaaazzzzzzzz");
138 // 10 FLUORESCENT FLICKER
139 lightstyle(10, "mmamammmmammamamaaamammma");
141 // 11 SLOW PULSE NOT FADE TO BLACK
142 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
144 // styles 32-62 are assigned by the light program for switchable lights
149 // for setting by mapinfo
150 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
151 cvar_set("sv_q3acompat_machineshotgunswap", "0");
154 lms_lowest_lives = 0;
159 bot_waypoints_for_items = cvar("g_waypoints_for_items");
160 if(bot_waypoints_for_items == 1)
161 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
162 bot_waypoints_for_items = 0;
164 if(cvar("g_campaign"))
171 WaypointSprite_Init();
177 head = nextent(world);
182 head = nextent(head);
185 GameLogInit(); // prepare everything
186 if(cvar("sv_eventlog"))
189 GameLogEcho(":logversion:2", FALSE);
190 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
191 s = strcat(s, ftos(random()));
193 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s), FALSE);
195 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
197 s = ":gameinfo:mutators:LIST";
198 if(cvar("g_grappling_hook"))
199 s = strcat(s, ":grappling_hook");
200 if(!cvar("g_use_ammunition"))
201 s = strcat(s, ":no_use_ammunition");
202 if(!cvar("g_pickup_items"))
203 s = strcat(s, ":no_pickup_items");
204 if(cvar("g_instagib"))
205 s = strcat(s, ":instagib");
206 if(cvar("g_rocketarena"))
207 s = strcat(s, ":rockerarena");
209 s = strcat(s, ":nixnex");
210 if(cvar("g_vampire"))
211 s = strcat(s, ":vampire");
212 if(cvar("g_laserguided_missile"))
213 s = strcat(s, ":laserguided_missile");
214 if(cvar("g_norecoil"))
215 s = strcat(s, ":norecoil");
217 s = strcat(s, ":midair");
218 if(cvar("g_minstagib"))
219 s = strcat(s, ":minstagib");
220 GameLogEcho(s, FALSE);
221 GameLogEcho(":gameinfo:end", FALSE);
224 cvar_set("nextmap", "");
228 if(cvar("g_campaign"))
237 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
243 //makestatic (self); // Who the f___ did that?
247 float( string pFilename ) TryFile =
250 dprint("TryFile(\"", pFilename, "\")\n");
251 lHandle = fopen( pFilename, FILE_READ );
252 if( lHandle != -1 ) {
262 if (game == GAME_DEATHMATCH)
264 else if (game == GAME_TEAM_DEATHMATCH)
266 else if (game == GAME_DOMINATION)
268 else if (game == GAME_CTF)
270 else if (game == GAME_RUNEMATCH)
272 else if (game == GAME_LMS)
274 else if (game == GAME_KEYHUNT)
276 else if (game == GAME_ONSLAUGHT)
278 else if (game == GAME_ASSAULT)
283 float IsSameGametype(string mapcfgname)
286 return TRUE; // can't change game type by map name here
290 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
296 string getmapname_stored;
302 if(getmapname_stored == "")
303 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
304 return getmapname_stored;
308 float Map_Count, Map_Current;
309 string Map_Current_Name;
311 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
312 float GetMaplistPosition()
318 idx = cvar("g_maplist_index");
325 for(pos = 0; pos < Map_Count; ++pos)
329 // resume normal maplist rotation if current map is not in g_maplist
333 float MapHasRightSize(string map)
335 // open map size restriction file
337 dprint("opensize "); dprint(map);
338 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
341 float mapmin, mapmax;
343 mapmin = stof(fgets(fh));
344 mapmax = stof(fgets(fh));
346 if(player_count < mapmin)
348 dprint("not enough\n");
351 if(player_count > mapmax)
353 dprint("too many\n");
356 dprint("right size\n");
359 dprint(": not found\n");
363 string Map_Filename(float position)
366 return strcat("maps/", argv(position), ".bsp");
368 return strcat("maps/", argv(position), ".mapcfg");
372 string strwords(string s, float w)
375 for(endpos = 0; w && endpos >= 0; --w)
376 endpos = strstrofs(s, " ", endpos + 1);
380 return substring(s, 0, endpos);
383 float strhasword(string s, string w)
385 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
388 void Map_MarkAsRecent(string m)
390 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
393 float Map_IsRecent(string m)
395 return strhasword(cvar_string("g_maplist_mostrecent"), m);
398 float(float position, float pass) Map_Check =
402 map_next = argv(position);
405 if(map_next == Map_Current_Name) // same map again in first pass?
407 if(Map_IsRecent(map_next))
410 filename = Map_Filename(position);
412 if(MapInfo_CheckMap(map_next))
414 if(TryFile(filename))
419 if(MapHasRightSize(map_next))
424 dprint( "Couldn't find '", filename, "'..\n" );
429 void(string nextmapname) Map_Goto_SetStr =
431 if(getmapname_stored != "")
432 strunzone(getmapname_stored);
433 if(nextmapname == "")
434 getmapname_stored = "";
436 getmapname_stored = strzone(nextmapname);
439 void(float position) Map_Goto_SetFloat =
441 cvar_set("g_maplist_index", ftos(position));
442 Map_Goto_SetStr(argv(position));
445 void() GameResetCfg =
448 // settings persist, except...
449 if(cvar("g_campaign"))
450 localcmd("\nexec mutator_reset.cfg\n");
451 localcmd("\nsettemp_restore\n");
453 // if an exit cfg is defined by exiting map, exec it.
455 exit_cfg = cvar_string("exit_cfg");
457 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
459 localcmd("exec game_reset.cfg\n");
463 db_save(ServerProgsDB, "server.db");
468 Map_MarkAsRecent(getmapname_stored);
471 MapInfo_LoadMap(getmapname_stored);
473 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
477 // return codes of map selectors:
478 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
479 // -2 = permanent failure
480 float() MaplistMethod_Iterate = // usual method
484 for(pass = 1; pass <= 2; ++pass)
486 for(i = 1; i < Map_Count; ++i)
489 mapindex = mod(i + Map_Current, Map_Count);
490 if(Map_Check(mapindex, pass))
497 float() MaplistMethod_Repeat = // fallback method
499 if(Map_Check(Map_Current, 2))
504 float() MaplistMethod_Random = // random map selection
510 for(i = 0; i <= imax; ++i)
513 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
514 if(Map_Check(mapindex, 1))
520 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
521 // the exponent sets a bias on the map selection:
522 // the higher the exponent, the less likely "shortly repeated" same maps are
524 float i, j, imax, insertpos;
528 for(i = 0; i <= imax; ++i)
532 // now reinsert this at another position
533 insertpos = pow(random(), 1 / exponent); // ]0, 1]
534 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
535 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
536 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
538 // insert the current map there
541 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
542 newlist = strcat(newlist, " ", argv(j));
543 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
544 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
545 newlist = strcat(newlist, " ", argv(j));
546 newlist = substring(newlist, 1, strlen(newlist) - 1);
548 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
549 newlist = strcat(newlist, "'", argv(j), "'");
550 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
551 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
552 newlist = strcat(newlist, "'", argv(j), "'");
554 cvar_set("g_maplist", newlist);
556 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
558 Map_Count = tokenize(newlist);
561 // NOTE: the selected map has just been inserted at (insertpos-1)th position
562 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
563 if(Map_Check(Map_Current, 1))
569 void() Maplist_Init =
572 temp = cvar_string("g_maplist");
574 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
576 Map_Count = tokenize(temp);
580 bprint( "Maplist is empty! Resetting it to default map list.\n" );
582 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
583 localcmd("\nmenu_cmd sync\n");
584 Map_Count = tokenizebyseparator(temp, " ");
586 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
587 Map_Count = tokenize(temp);
591 error("empty maplist, cannot select a new map");
592 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
594 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
595 // this may or may not be correct, but who cares, in the worst case a map
596 // isn't chosen in the first pass that should have been
599 string() GetNextMap =
607 if(cvar("g_maplist_shuffle") > 0)
608 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
611 if(cvar("g_maplist_selectrandom"))
612 nextMap = MaplistMethod_Random();
615 nextMap = MaplistMethod_Iterate();
618 nextMap = MaplistMethod_Repeat();
622 Map_Goto_SetFloat(nextMap);
623 return getmapname_stored;
629 float() DoNextMapOverride =
632 db_save(ServerProgsDB, "server.db");
634 if(cvar("g_campaign"))
636 CampaignPostIntermission();
637 alreadychangedlevel = TRUE;
640 if(cvar("quit_when_empty"))
642 if(player_count <= currentbots)
645 alreadychangedlevel = TRUE;
649 if(cvar_string("quit_and_redirect") != "")
651 redirection_target = strzone(cvar_string("quit_and_redirect"));
652 alreadychangedlevel = TRUE;
655 if (cvar("samelevel")) // if samelevel is set, stay on same level
657 // 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)
658 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
659 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
660 localcmd("restart\n");
661 //changelevel (mapname);
662 alreadychangedlevel = TRUE;
665 if(cvar_string("nextmap") != "")
667 if(MapInfo_CheckMap(cvar_string("nextmap")))
669 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
672 Map_Goto_SetStr(cvar_string("nextmap"));
674 alreadychangedlevel = TRUE;
677 if(cvar("lastlevel"))
680 localcmd("set lastlevel 0\ntogglemenu\n");
681 alreadychangedlevel = TRUE;
689 //local string nextmap;
690 //local float n, nummaps;
692 if (alreadychangedlevel)
694 alreadychangedlevel = TRUE;
700 for(allowReset = 1; allowReset >= 0; --allowReset)
702 nextMap = GetNextMap();
708 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
710 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
711 localcmd("\nmenu_cmd sync\n");
713 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
718 error("Everything is broken - not even the default map list works. Please report this to the developers.");
730 When the player presses attack or jump, change to the next level
733 .float autoscreenshot;
734 void() MapVote_Start;
735 void() MapVote_Think;
736 float mapvote_initialized;
737 void() IntermissionThink =
739 FixIntermissionClient(self);
741 if(cvar("sv_autoscreenshot"))
742 if(self.autoscreenshot > 0)
743 if(time > self.autoscreenshot)
745 self.autoscreenshot = -1;
746 if(clienttype(self) == CLIENTTYPE_REAL)
747 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
751 if (time < intermission_exittime)
754 if(!mapvote_initialized)
755 if (time < intermission_exittime + 10 && !self.button0 && !self.button2 && !self.button3 && !self.button6 && !self.buttonuse)
765 Returns the entity to view from
769 entity() FindIntermission =
774 // look for info_intermission first
775 spot = find (world, classname, "info_intermission");
777 { // pick a random one
781 spot = find (spot, classname, "info_intermission");
783 spot = find (spot, classname, "info_intermission");
789 // then look for the start position
790 spot = find (world, classname, "info_player_start");
794 // testinfo_player_start is only found in regioned levels
795 spot = find (world, classname, "testplayerstart");
799 // then look for the start position
800 spot = find (world, classname, "info_player_deathmatch");
804 //objerror ("FindIntermission: no spot");
810 ===============================================================================
814 ===============================================================================
817 void(float final) DumpStats =
821 local float to_console;
822 local float to_eventlog;
825 to_console = cvar("sv_logscores_console");
826 to_eventlog = cvar("sv_eventlog");
827 to_file = cvar("sv_logscores_file");
831 to_console = TRUE; // always print printstats replies
832 to_eventlog = FALSE; // but never print them to the event log
836 if(cvar("sv_eventlog_console"))
837 to_console = FALSE; // otherwise we get the output twice
844 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
846 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
850 ServerConsoleEcho(s, FALSE);
852 GameLogEcho(s, FALSE);
855 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
859 fputs(file, strcat(s, "\n"));
862 FOR_EACH_CLIENT(other)
864 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
866 s = strcat(":player:", ftos(other.frags), ":");
867 s = strcat(s, ftos(other.deaths), ":");
868 s = strcat(s, ftos(rint(time - other.jointime)), ":");
869 s = strcat(s, ftos(other.team), ":");
872 ServerConsoleEcho(strcat(s, other.netname), TRUE);
874 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
876 fputs(file, strcat(s, other.netname, "\n"));
881 ServerConsoleEcho(":end", FALSE);
883 GameLogEcho(":end", FALSE);
886 fputs(file, ":end\n");
891 void FixIntermissionClient(entity e)
893 if(!e.autoscreenshot) // initial call
895 e.angles = e.v_angle;
896 e.angles_x = -e.angles_x;
897 e.autoscreenshot = time + 0.8; // used for autoscreenshot
899 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
901 e.movetype = MOVETYPE_NONE;
902 e.takedamage = DAMAGE_NO;
904 e.weaponentity.effects = EF_NODRAW;
905 stuffcmd(e, "\nscr_printspeed 1000000\n");
906 if(clienttype(e) == CLIENTTYPE_REAL)
909 WriteByte(MSG_ONE, SVC_INTERMISSION);
913 //e.velocity = '0 0 0';
916 // TODO halt weapon animation
921 go to the next level for deathmatch
922 only called if a time or frag limit has expired
934 db_save(ServerProgsDB, "server.db");
936 intermission_running = 1;
938 // enforce a wait time before allowing changelevel
940 intermission_exittime = time + cvar("sv_mapchange_delay");
942 intermission_exittime = -1;
944 WriteByte (MSG_ALL, SVC_CDTRACK);
945 WriteByte (MSG_ALL, 3);
946 WriteByte (MSG_ALL, 3);
948 //pos = FindIntermission ();
954 if(cvar("sv_eventlog"))
955 GameLogEcho(":gameover", FALSE);
959 FOR_EACH_CLIENT(other)
961 FixIntermissionClient(other);
964 bprint(other.netname, " ^7wins.\n");
969 FOR_EACH_PLAYER(other)
971 if(maxTotalFrags < other.totalfrags)
972 maxTotalFrags = other.totalfrags;
973 if(minTotalFrags > other.totalfrags)
974 minTotalFrags = other.totalfrags;
979 FOR_EACH_PLAYER(other)
981 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
982 f = bound(0, other.play_time / max(time, 1), 1);
983 // store some statistics?
987 if(cvar("g_campaign"))
988 CampaignPreIntermission();
990 // WriteByte (MSG_ALL, SVC_INTERMISSION);
997 Exit deathmatch games upon conditions
1000 void() CheckRules_Player =
1002 if (gameover) // someone else quit the game already
1005 if(self.deadflag == DEAD_NO)
1006 self.play_time += frametime;
1008 // fixme: don't check players; instead check dom_team and ctf_team entities
1009 // (div0: and that in CheckRules_World please)
1012 float checkrules_oneminutewarning;
1013 float checkrules_leaderfrags;
1014 float tdm_max_score, tdm_old_score;
1016 float checkrules_equality;
1017 float checkrules_overtimewarning;
1018 float checkrules_overtimeend;
1020 void() InitiateOvertime =
1022 if(!checkrules_overtimeend)
1023 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1026 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1027 float WINNING_YES = 1; // winner found
1028 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1029 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1031 float(float fraglimitreached, float equality) GetWinningCode =
1034 if(fraglimitreached)
1035 return WINNING_STARTOVERTIME;
1037 return WINNING_NEVER;
1039 if(fraglimitreached)
1045 // set the .winning flag for exactly those players with a given field value
1046 void(.float field, float value) SetWinners =
1049 FOR_EACH_PLAYER(head)
1050 head.winning = (head.field == value);
1053 // set the .winning flag for those players with a given field value
1054 void(.float field, float value) AddWinners =
1057 FOR_EACH_PLAYER(head)
1058 if(head.field == value)
1062 // clear the .winning flags
1063 void(void) ClearWinners =
1066 FOR_EACH_PLAYER(head)
1070 // Onslaught winning condition:
1071 // game terminates if only one team has a working generator (or none)
1072 float() WinningCondition_Onslaught =
1075 local float t1, t2, t3, t4;
1076 // first check if the game has ended
1077 t1 = t2 = t3 = t4 = 0;
1078 head = find(world, classname, "onslaught_generator");
1081 if (head.health > 0)
1083 if (head.team == COLOR_TEAM1) t1 = 1;
1084 if (head.team == COLOR_TEAM2) t2 = 1;
1085 if (head.team == COLOR_TEAM3) t3 = 1;
1086 if (head.team == COLOR_TEAM4) t4 = 1;
1088 head = find(head, classname, "onslaught_generator");
1090 if (t1 + t2 + t3 + t4 < 2)
1092 // game over, only one team remains (or none)
1094 if (t1) SetWinners(team, COLOR_TEAM1);
1095 if (t2) SetWinners(team, COLOR_TEAM2);
1096 if (t3) SetWinners(team, COLOR_TEAM3);
1097 if (t4) SetWinners(team, COLOR_TEAM4);
1098 dprint("Have a winner, ending game.\n");
1102 // Two or more teams remain
1106 float() LMS_NewPlayerLives =
1109 fl = cvar("fraglimit");
1113 // first player has left the game for dying too much? Nobody else can get in.
1114 if(lms_lowest_lives < 1)
1117 if(!cvar("g_lms_join_anytime"))
1118 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1121 return bound(1, lms_lowest_lives, fl);
1124 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1125 // they win. Otherwise the defending team wins once the timelimit passes.
1126 void assault_new_round();
1127 float() WinningCondition_Assault =
1130 status = WINNING_NO;
1132 // as the timelimit has not yet passed just assume the defending team will win
1133 if(assault_attacker_team == COLOR_TEAM1)
1135 SetWinners(team, COLOR_TEAM2);
1139 SetWinners(team, COLOR_TEAM1);
1143 ent = find(world, classname, "target_assault_roundend");
1146 if(ent.winning) // round end has been triggered by attacking team
1148 SetWinners(team, assault_attacker_team);
1149 if(assault_attacker_team == COLOR_TEAM1)
1151 team1_score = team1_score + 50;
1155 team2_score = team2_score + 50;
1158 if(ent.cnt == 1) // this was the second round
1160 status = WINNING_YES;
1164 cvar_set("timelimit", ftos((2*time)/60));
1165 assault_new_round();
1175 // LMS winning condition: game terminates if and only if there's at most one
1176 // one player who's living lives. Top two scores being equal cancels the time
1178 float() WinningCondition_LMS =
1185 have_player = FALSE;
1186 have_players = FALSE;
1187 l = LMS_NewPlayerLives();
1189 head = find(world, classname, "player");
1192 head = find(head, classname, "player");
1194 have_players = TRUE;
1198 // we have at least one player
1201 // two or more active players - continue with the game
1205 // exactly one player?
1208 // but no game has taken place yet
1213 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1214 dprint("Have a winner, ending game.\n");
1221 // nobody is playing at all...
1224 // wait for players...
1228 // SNAFU (maybe a draw game?)
1230 dprint("No players, ending game.\n");
1235 // When we get here, we have at least two players who are actually LIVING,
1236 // or one player who is still waiting for a victim to join the server. Now
1237 // check if the top two players have equal score.
1239 checkrules_leaderfrags = 0;
1240 checkrules_equality = FALSE;
1241 FOR_EACH_PLAYER(head)
1243 if(head.frags > checkrules_leaderfrags)
1245 checkrules_leaderfrags = head.frags;
1246 checkrules_equality = FALSE;
1248 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1249 checkrules_equality = TRUE;
1252 SetWinners(frags, checkrules_leaderfrags);
1254 // The top two players have the same amount of lives? No timelimit then,
1255 // enter overtime...
1257 if(checkrules_equality)
1258 return WINNING_NEVER;
1260 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1264 // DM winning condition: game terminates if a player reached the fraglimit,
1265 // unless the first two players have the same score. The latter case also
1266 // breaks the time limit.
1267 float(float fraglimit) WinningCondition_MaxIndividualScore =
1269 float checkrules_oldleaderfrags;
1272 checkrules_oldleaderfrags = checkrules_leaderfrags;
1273 checkrules_leaderfrags = 0;
1274 checkrules_equality = FALSE;
1275 FOR_EACH_PLAYER(head)
1277 if(head.frags > checkrules_leaderfrags)
1279 checkrules_leaderfrags = head.frags;
1280 checkrules_equality = FALSE;
1282 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1283 checkrules_equality = TRUE;
1286 if(checkrules_leaderfrags > 0)
1287 SetWinners(frags, checkrules_leaderfrags);
1292 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1294 if (checkrules_leaderfrags == fraglimit - 1)
1295 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1296 else if (checkrules_leaderfrags == fraglimit - 2)
1297 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1298 else if (checkrules_leaderfrags == fraglimit - 3)
1299 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1302 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1305 float(float fraglimit) WinningConditionBase_Teamplay =
1307 tdm_old_score = tdm_max_score;
1308 tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1310 checkrules_equality =
1315 (team1_score == tdm_max_score)
1316 + (team2_score == tdm_max_score)
1317 + (team3_score == tdm_max_score)
1318 + (team4_score == tdm_max_score)
1322 if(tdm_max_score > 0)
1324 if(team1_score == tdm_max_score)
1325 AddWinners(team, COLOR_TEAM1);
1326 if(team2_score == tdm_max_score)
1327 AddWinners(team, COLOR_TEAM2);
1328 if(team3_score == tdm_max_score)
1329 AddWinners(team, COLOR_TEAM3);
1330 if(team4_score == tdm_max_score)
1331 AddWinners(team, COLOR_TEAM4);
1334 if(!g_runematch && !g_domination)
1335 if(tdm_max_score != tdm_old_score)
1337 if(tdm_max_score == fraglimit - 1)
1338 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1339 else if(tdm_max_score == fraglimit - 2)
1340 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1341 else if(tdm_max_score == fraglimit - 3)
1342 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1345 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1348 // TDM winning condition: game terminates if a team's score sum reached the
1349 // fraglimit, unless the first two teams have the same total score. The latter
1350 // case also breaks the time limit.
1351 float(float fraglimit) WinningCondition_MaxTeamSum =
1355 team1_score = team2_score = team3_score = team4_score = 0;
1357 FOR_EACH_PLAYER(head)
1359 if(head.team == COLOR_TEAM1)
1360 team1_score += head.frags;
1361 else if(head.team == COLOR_TEAM2)
1362 team2_score += head.frags;
1363 else if(head.team == COLOR_TEAM3)
1364 team3_score += head.frags;
1365 else if(head.team == COLOR_TEAM4)
1366 team4_score += head.frags;
1369 return WinningConditionBase_Teamplay(fraglimit);
1372 // DOM/CTF winning condition: game terminates if the max of a team's players'
1373 // score reached the fraglimit, unless the first two teams have the same
1374 // maximum score. The latter case also breaks the time limit.
1375 float(float fraglimit) WinningCondition_MaxTeamMax =
1379 team1_score = team2_score = team3_score = team4_score = 0;
1381 FOR_EACH_PLAYER(head)
1383 if(head.team == COLOR_TEAM1)
1385 if(head.frags > team1_score)
1386 team1_score = head.frags;
1388 else if(head.team == COLOR_TEAM2)
1390 if(head.frags > team2_score)
1391 team2_score = head.frags;
1393 else if(head.team == COLOR_TEAM3)
1395 if(head.frags > team3_score)
1396 team3_score = head.frags;
1398 else if(head.team == COLOR_TEAM4)
1400 if(head.frags > team4_score)
1401 team4_score = head.frags;
1405 return WinningConditionBase_Teamplay(fraglimit);
1408 void print_to(entity e, string s)
1411 sprint(e, strcat(s, "\n"));
1413 ServerConsoleEcho(s, TRUE);
1416 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1426 FOR_EACH_PLAYER(head)
1428 if(!whichteam || head.team == whichteam)
1432 print_to(e, strcat(" ", colorcode, name, ":"));
1434 fragtotal = fragtotal + head.frags;
1435 s = ftos(head.frags);
1436 s = strcat(s, "/", ftos(head.deaths));
1437 s = strcat(s, " @ ", ftos(head.ping));
1438 if(clienttype(head) == CLIENTTYPE_BOT)
1439 s = strcat(s, "botms");
1441 s = strcat(s, "ms");
1442 v = PlayerValue(head);
1444 s = strcat(s, " / ", ftos(v));
1445 print_to(e, strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"));
1448 if(whichteam && found)
1450 s = ftos(fragtotal);
1451 s = strcat(s, " / ", ftos(teamvalue));
1452 print_to(e, strcat(colorcode, " (total: ", s, ")"));
1456 void PrintScoreboard(entity e)
1458 print_to(e, strcat("Time: ", ftos(time / 60)));
1459 print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1460 print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1461 print_to(e, "Scoreboard:");
1464 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1465 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1466 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM3);
1467 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM4);
1471 PrintScoreboardFor(e, "", "^7", 0);
1476 void ShuffleMaplist()
1484 result = cvar_string("g_maplist");
1486 litems = tokenizebyseparator(result, " ");
1488 litems = tokenize(result);
1491 for(start = 0; start < litems - 1; ++start)
1495 // select a random item
1496 selected = ceil(random() * (litems - start) + start) - 1;
1498 // shift this item to the place start
1500 for(i = 0; i < start; ++i)
1501 result = strcat(result, " ", argv(i));
1502 result = strcat(result, " ", argv(selected));
1503 for(i = start; i < litems; ++i)
1505 result = strcat(result, " ", argv(i));
1506 result = substring(result, 1, strlen(result) - 1);
1508 litems = tokenizebyseparator(result, " ");
1510 for(i = 0; i < start; ++i)
1511 result = strcat(result, "'", argv(i), "'");
1512 result = strcat(result, "'", argv(selected), "'");
1513 for(i = start; i < litems; ++i)
1515 result = strcat(result, "'", argv(i), "'");
1517 litems = tokenize(result);
1520 //dprint(result, "\n");
1523 cvar_set("g_maplist", result);
1530 Exit deathmatch games upon conditions
1533 void() CheckRules_World =
1536 local float timelimit;
1537 local float fraglimit;
1545 MapVote_Think should now do that part
1546 if (intermission_running)
1547 if (time >= intermission_exittime + 60)
1549 if(!DoNextMapOverride())
1555 if (gameover) // someone else quit the game already
1557 if(player_count == 0) // Nobody there? Then let's go to the next map
1559 // this will actually check the player count in the next frame
1560 // again, but this shouldn't hurt
1564 timelimit = cvar("timelimit") * 60;
1565 fraglimit = cvar("fraglimit");
1567 if(checkrules_overtimeend)
1569 if(!checkrules_overtimewarning)
1571 checkrules_overtimewarning = TRUE;
1572 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1573 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1578 if (timelimit && time >= timelimit)
1582 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1588 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1590 checkrules_oneminutewarning = TRUE;
1591 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1594 status = WINNING_NO;
1597 status = WinningCondition_Assault();
1601 status = WinningCondition_LMS();
1603 else if (g_onslaught)
1605 status = WinningCondition_Onslaught();
1611 if(g_tdm || g_runematch || g_ctf || g_domination || g_keyhunt)
1612 status = WinningCondition_MaxTeamSum(fraglimit);
1614 // status = WinningCondition_MaxTeamMax(fraglimit);
1617 dprint("div0: How can this happen?\n");
1618 status = WinningCondition_MaxTeamMax(fraglimit);
1622 status = WinningCondition_MaxIndividualScore(fraglimit);
1625 if(status == WINNING_STARTOVERTIME)
1627 status = WINNING_NEVER;
1631 if(status == WINNING_NEVER)
1632 // equality cases! Nobody wins if the overtime ends in a draw.
1635 if(checkrules_overtimeend)
1636 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1637 status = WINNING_YES;
1639 if(status == WINNING_YES)
1643 float randsel_value;
1644 float randsel_priority;
1645 float randsel_count;
1649 randsel_priority = -1;
1652 void RandSel_Add(float priority, float value)
1654 if(priority > randsel_priority)
1656 randsel_priority = priority;
1657 randsel_value = value;
1660 else if(priority == randsel_priority)
1663 if(ceil(random() * randsel_count) == 1)
1664 randsel_value = value;
1668 float mapvote_nextthink;
1669 float mapvote_initialized;
1670 float mapvote_keeptwotime;
1671 float mapvote_timeout;
1672 string mapvote_message;
1674 #define MAPVOTE_COUNT 10
1675 float mapvote_count;
1676 float mapvote_count_real;
1677 string mapvote_maps[MAPVOTE_COUNT];
1678 float mapvote_maps_suggested[MAPVOTE_COUNT];
1679 string mapvote_suggestions[MAPVOTE_COUNT];
1680 float mapvote_suggestion_ptr;
1681 float mapvote_maxlen;
1682 float mapvote_voters;
1683 float mapvote_votes[MAPVOTE_COUNT];
1685 float mapvote_detail;
1686 float mapvote_abstain;
1689 void MapVote_ClearAllVotes()
1691 FOR_EACH_CLIENT(other)
1695 string MapVote_Suggest(string m)
1699 return "That's not how to use this command.";
1700 if(!cvar("g_maplist_votable_suggestions"))
1701 return "Suggestions are not accepted on this server.";
1702 if(mapvote_initialized)
1703 return "Can't suggest - voting is already in progress!";
1705 m = MapInfo_FixName(m);
1707 return "The map you suggested is not available on this server.";
1709 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1710 if(!IsSameGametype(m))
1711 return "This server does not allow changing the game type by map suggestions.";
1712 if(!cvar("g_maplist_votable_override_mostrecent"))
1714 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1717 if(!MapInfo_CheckMap(m))
1718 return "The map you suggested does not support the current game mode.";
1720 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1721 return "The map you suggested is not available on this server.";
1723 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1724 if(mapvote_suggestions[i] == m)
1725 return "This map was already suggested.";
1726 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1728 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1732 i = mapvote_suggestion_ptr;
1733 mapvote_suggestion_ptr += 1;
1735 if(mapvote_suggestions[i] != "")
1736 strunzone(mapvote_suggestions[i]);
1737 mapvote_suggestions[i] = strzone(m);
1738 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid), ":", self.netname), TRUE);
1739 return strcat("Suggestion of ", m, " accepted.");
1742 void MapVote_AddVotable(string nextMap, float isSuggestion)
1747 for(j = 0; j < mapvote_count; ++j)
1748 if(mapvote_maps[j] == nextMap)
1750 if(strlen(nextMap) > mapvote_maxlen)
1751 mapvote_maxlen = strlen(nextMap);
1752 mapvote_maps[mapvote_count] = strzone(nextMap);
1753 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1762 MapVote_ClearAllVotes();
1765 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1766 mapvote_abstain = cvar("g_maplist_votable_abstain");
1769 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1771 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1772 smax = min(nmax, cvar("g_maplist_votable_suggestions"));
1774 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1775 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1777 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1778 MapVote_AddVotable(GetNextMap(), FALSE);
1780 if(mapvote_count == 0)
1782 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1784 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1785 localcmd("\nmenu_cmd sync\n");
1787 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1789 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1790 MapVote_AddVotable(GetNextMap(), FALSE);
1793 mapvote_count_real = mapvote_count;
1795 MapVote_AddVotable("don't care", 0);
1797 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1799 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1800 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1801 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1802 mapvote_keeptwotime = 0;
1803 mapvote_message = "Choose a map and press its key!";
1805 float MapVote_Finished(float mappos)
1811 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1812 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1813 didntvote = mapvote_voters;
1814 for(i = 0; i < mapvote_count; ++i)
1815 if(mapvote_maps[i] != "")
1817 didntvote -= mapvote_votes[i];
1820 result = strcat(result, ":", mapvote_maps[i]);
1821 result = strcat(result, ":", ftos(mapvote_votes[i]));
1824 result = strcat(result, ":didn't vote:", ftos(didntvote));
1826 GameLogEcho(result, FALSE);
1827 if(mapvote_maps_suggested[mappos])
1828 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
1830 FOR_EACH_REALCLIENT(other)
1831 FixClientCvars(other);
1833 Map_Goto_SetStr(mapvote_maps[mappos]);
1835 alreadychangedlevel = TRUE;
1838 void MapVote_CheckRules_1()
1842 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1844 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1845 mapvote_votes[i] = 0;
1849 FOR_EACH_REALCLIENT(other)
1854 i = other.mapvote - 1;
1855 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1856 mapvote_votes[i] = mapvote_votes[i] + 1;
1861 float MapVote_CheckRules_2()
1864 float firstPlace, secondPlace;
1865 float firstPlaceVotes, secondPlaceVotes;
1866 float mapvote_voters_real;
1869 mapvote_voters_real = mapvote_voters;
1871 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
1874 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1875 RandSel_Add(mapvote_votes[i], i);
1876 firstPlace = randsel_value;
1877 firstPlaceVotes = randsel_priority;
1878 //dprint("First place: ", ftos(firstPlace), "\n");
1879 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1882 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1884 RandSel_Add(mapvote_votes[i], i);
1885 secondPlace = randsel_value;
1886 secondPlaceVotes = randsel_priority;
1887 //dprint("Second place: ", ftos(secondPlace), "\n");
1888 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1890 if(firstPlace == -1)
1891 error("No first place in map vote... WTF?");
1893 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
1894 return MapVote_Finished(firstPlace);
1896 if(mapvote_keeptwotime)
1897 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
1900 mapvote_message = "Now decide between the TOP TWO!";
1901 mapvote_keeptwotime = 0;
1902 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
1903 result = strcat(result, ":", ftos(firstPlaceVotes));
1904 result = strcat(result, ":", mapvote_maps[secondPlace]);
1905 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
1906 didntvote = mapvote_voters;
1907 for(i = 0; i < mapvote_count; ++i)
1908 if(mapvote_maps[i] != "")
1910 didntvote -= mapvote_votes[i];
1912 if(i != secondPlace)
1914 result = strcat(result, ":", mapvote_maps[i]);
1915 result = strcat(result, ":", ftos(mapvote_votes[i]));
1916 if(i < mapvote_count_real)
1918 strunzone(mapvote_maps[i]);
1919 mapvote_maps[i] = "";
1923 result = strcat(result, ":didn't vote:", ftos(didntvote));
1924 GameLogEcho(result, FALSE);
1937 keeptwo = mapvote_keeptwotime;
1938 MapVote_CheckRules_1(); // count
1939 if(MapVote_CheckRules_2()) // decide
1943 FOR_EACH_REALCLIENT(other)
1945 // hide scoreboard again
1946 if(other.health != 2342)
1948 other.health = 2342;
1950 if(clienttype(other) == CLIENTTYPE_REAL)
1952 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");
1954 WriteByte(MSG_ONE, SVC_FINALE);
1955 WriteString(MSG_ONE, "");
1959 // notify about keep-two
1960 if(keeptwo != 0 && mapvote_keeptwotime == 0)
1961 play2(other, "misc/invshot.wav");
1963 // clear possibly invalid votes
1964 if(mapvote_maps[other.mapvote - 1] == "")
1966 // use impulses as new vote
1967 if(other.impulse >= 1 && other.impulse <= mapvote_count)
1968 if(mapvote_maps[other.impulse - 1] != "")
1969 other.mapvote = other.impulse;
1976 MapVote_CheckRules_1(); // just count
1978 FOR_EACH_REALCLIENT(other)
1980 // display voting screen
1981 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
1982 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
1984 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
1985 msgstr = strcat(msgstr, mapvote_message);
1986 msgstr = strcat(msgstr, "\n\n");
1987 for(i = 0; i < mapvote_count; ++i)
1988 if(mapvote_maps[i] == "")
1989 msgstr = strcat(msgstr, "\n");
1992 tmp = mapvote_maps[i];
1993 tmp = strpad(mapvote_maxlen, tmp);
1994 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
1997 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
1998 if(mapvote_votes[i] != 1)
1999 tmp = strcat(tmp, "s");
2000 tmp = strcat(tmp, ")");
2001 tmp = strpad(mapvote_maxlen + 15, tmp);
2004 if(i == mapvote_count - 1)
2005 msgstr = strcat(msgstr, "\n");
2006 if(other.mapvote == i + 1)
2007 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2009 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2012 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2014 msgstr = strcat(msgstr, "s");
2015 msgstr = strcat(msgstr, " cast");
2016 i = ceil(mapvote_timeout - time);
2017 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2019 msgstr = strcat(msgstr, "s");
2020 msgstr = strcat(msgstr, " left");
2022 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2025 void MapVote_Start()
2031 MapInfo_Enumerate();
2032 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2036 void MapVote_Think()
2041 if(alreadychangedlevel)
2044 if(time < mapvote_nextthink)
2048 mapvote_nextthink = time + 0.5;
2050 if(!mapvote_initialized)
2052 mapvote_initialized = TRUE;
2053 if(DoNextMapOverride())
2055 if(!cvar("g_maplist_votable") || player_count <= 0)
2066 string GotoMap(string m)
2069 if(!MapInfo_CheckMap(m))
2071 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2073 return "The map you chose is not available on this server.";
2074 cvar_set("nextmap", m);
2075 cvar_set("timelimit", "-1");
2076 if(mapvote_initialized || alreadychangedlevel)
2078 if(DoNextMapOverride())
2079 return "Map switch initiated.";
2081 return "Hm... no. For some reason I like THIS map more.";
2084 return "Map switch will happen after scoreboard.";
2090 FOR_EACH_REALCLIENT(self)
2092 if(self.classname == "spectator")
2094 if(self.enemy.hitsound)
2095 play2(self, "misc/hit.wav");
2100 play2(self, "misc/hit.wav");
2103 FOR_EACH_CLIENT(self)
2104 self.hitsound = FALSE;
2110 * returns TRUE if redirecting
2112 float redirection_timeout;
2113 float redirection_nextthink;
2114 float RedirectionThink()
2116 float clients_found;
2118 if(redirection_target == "")
2121 if(!redirection_timeout)
2123 cvar_set("sv_public", "-2");
2124 redirection_timeout = time + 0.5; // this will only try twice... should be able to keep more clients
2125 if(redirection_target == "self")
2126 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2128 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2131 if(time < redirection_nextthink)
2134 redirection_nextthink = time + 1;
2137 FOR_EACH_REALCLIENT(self)
2139 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2140 if(redirection_target == "self")
2141 stuffcmd(self, "\ndisconnect; reconnect\n");
2143 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2147 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2149 if(time > redirection_timeout || clients_found == 0)
2150 localcmd("\nwait; wait; wait; quit\n");