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);
98 TODO sound pack system
99 // initialize sound pack system
100 soundpack = cvar_string("g_soundpack");
102 soundpack = strcat(soundpack, "/");
103 soundpack = strzone(soundpack);
109 // 1 FLICKER (first variety)
110 lightstyle(1, "mmnmmommommnonmmonqnmmo");
112 // 2 SLOW STRONG PULSE
113 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
115 // 3 CANDLE (first variety)
116 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
119 lightstyle(4, "mamamamamama");
122 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
124 // 6 FLICKER (second variety)
125 lightstyle(6, "nmonqnmomnmomomno");
127 // 7 CANDLE (second variety)
128 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
130 // 8 CANDLE (third variety)
131 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
133 // 9 SLOW STROBE (fourth variety)
134 lightstyle(9, "aaaaaaaazzzzzzzz");
136 // 10 FLUORESCENT FLICKER
137 lightstyle(10, "mmamammmmammamamaaamammma");
139 // 11 SLOW PULSE NOT FADE TO BLACK
140 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
142 // styles 32-62 are assigned by the light program for switchable lights
147 // for setting by mapinfo
148 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
149 cvar_set("sv_q3acompat_machineshotgunswap", "0");
152 lms_lowest_lives = 0;
157 bot_waypoints_for_items = cvar("g_waypoints_for_items");
158 if(bot_waypoints_for_items == 1)
159 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
160 bot_waypoints_for_items = 0;
162 if(cvar("g_campaign"))
169 WaypointSprite_Init();
175 head = nextent(world);
180 head = nextent(head);
183 GameLogInit(); // prepare everything
184 if(cvar("sv_eventlog"))
187 GameLogEcho(":logversion:2", FALSE);
188 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
189 s = strcat(s, ftos(random()));
191 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s), FALSE);
193 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
195 s = ":gameinfo:mutators:LIST";
196 if(cvar("g_grappling_hook"))
197 s = strcat(s, ":grappling_hook");
198 if(!cvar("g_use_ammunition"))
199 s = strcat(s, ":no_use_ammunition");
200 if(!cvar("g_pickup_items"))
201 s = strcat(s, ":no_pickup_items");
202 if(cvar("g_instagib"))
203 s = strcat(s, ":instagib");
204 if(cvar("g_rocketarena"))
205 s = strcat(s, ":rockerarena");
207 s = strcat(s, ":nixnex");
208 if(cvar("g_vampire"))
209 s = strcat(s, ":vampire");
210 if(cvar("g_laserguided_missile"))
211 s = strcat(s, ":laserguided_missile");
212 if(cvar("g_norecoil"))
213 s = strcat(s, ":norecoil");
215 s = strcat(s, ":midair");
216 if(cvar("g_minstagib"))
217 s = strcat(s, ":minstagib");
218 GameLogEcho(s, FALSE);
219 GameLogEcho(":gameinfo:end", FALSE);
222 cvar_set("nextmap", "");
226 if(cvar("g_campaign"))
235 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
241 //makestatic (self); // Who the f___ did that?
245 float( string pFilename ) TryFile =
248 dprint("TryFile(\"", pFilename, "\")\n");
249 lHandle = fopen( pFilename, FILE_READ );
250 if( lHandle != -1 ) {
260 if (game == GAME_DEATHMATCH)
262 else if (game == GAME_TEAM_DEATHMATCH)
264 else if (game == GAME_DOMINATION)
266 else if (game == GAME_CTF)
268 else if (game == GAME_RUNEMATCH)
270 else if (game == GAME_LMS)
272 else if (game == GAME_KEYHUNT)
274 else if (game == GAME_ONSLAUGHT)
276 else if (game == GAME_ASSAULT)
281 float IsSameGametype(string mapcfgname)
284 return TRUE; // can't change game type by map name here
288 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
294 string getmapname_stored;
300 if(getmapname_stored == "")
301 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
302 return getmapname_stored;
306 float Map_Count, Map_Current;
307 string Map_Current_Name;
309 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
310 float GetMaplistPosition()
316 idx = cvar("g_maplist_index");
323 for(pos = 0; pos < Map_Count; ++pos)
327 // resume normal maplist rotation if current map is not in g_maplist
331 float MapHasRightSize(string map)
333 // open map size restriction file
335 dprint("opensize "); dprint(map);
336 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
339 float mapmin, mapmax;
341 mapmin = stof(fgets(fh));
342 mapmax = stof(fgets(fh));
344 if(player_count < mapmin)
346 dprint("not enough\n");
349 if(player_count > mapmax)
351 dprint("too many\n");
354 dprint("right size\n");
357 dprint(": not found\n");
361 string Map_Filename(float position)
364 return strcat("maps/", argv(position), ".bsp");
366 return strcat("maps/", argv(position), ".mapcfg");
370 string strwords(string s, float w)
373 for(endpos = 0; w && endpos >= 0; --w)
374 endpos = strstrofs(s, " ", endpos + 1);
378 return substring(s, 0, endpos);
381 float strhasword(string s, string w)
383 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
386 void Map_MarkAsRecent(string m)
388 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
391 float Map_IsRecent(string m)
393 return strhasword(cvar_string("g_maplist_mostrecent"), m);
396 float(float position, float pass) Map_Check =
400 map_next = argv(position);
403 if(map_next == Map_Current_Name) // same map again in first pass?
405 if(Map_IsRecent(map_next))
408 filename = Map_Filename(position);
410 if(MapInfo_CheckMap(map_next))
412 if(TryFile(filename))
417 if(MapHasRightSize(map_next))
422 dprint( "Couldn't find '", filename, "'..\n" );
427 void(string nextmapname) Map_Goto_SetStr =
429 if(getmapname_stored != "")
430 strunzone(getmapname_stored);
431 if(nextmapname == "")
432 getmapname_stored = "";
434 getmapname_stored = strzone(nextmapname);
437 void(float position) Map_Goto_SetFloat =
439 cvar_set("g_maplist_index", ftos(position));
440 Map_Goto_SetStr(argv(position));
443 void() GameResetCfg =
446 // settings persist, except...
447 if(cvar("g_campaign"))
448 localcmd("\nexec mutator_reset.cfg\n");
449 localcmd("\nsettemp_restore\n");
451 // if an exit cfg is defined by exiting map, exec it.
453 exit_cfg = cvar_string("exit_cfg");
455 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
457 localcmd("exec game_reset.cfg\n");
465 Map_MarkAsRecent(getmapname_stored);
468 MapInfo_LoadMap(getmapname_stored);
470 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
474 // return codes of map selectors:
475 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
476 // -2 = permanent failure
477 float() MaplistMethod_Iterate = // usual method
481 for(pass = 1; pass <= 2; ++pass)
483 for(i = 1; i < Map_Count; ++i)
486 mapindex = mod(i + Map_Current, Map_Count);
487 if(Map_Check(mapindex, pass))
494 float() MaplistMethod_Repeat = // fallback method
496 if(Map_Check(Map_Current, 2))
501 float() MaplistMethod_Random = // random map selection
507 for(i = 0; i <= imax; ++i)
510 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
511 if(Map_Check(mapindex, 1))
517 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
518 // the exponent sets a bias on the map selection:
519 // the higher the exponent, the less likely "shortly repeated" same maps are
521 float i, j, imax, insertpos;
525 for(i = 0; i <= imax; ++i)
529 // now reinsert this at another position
530 insertpos = pow(random(), 1 / exponent); // ]0, 1]
531 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
532 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
533 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
535 // insert the current map there
538 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
539 newlist = strcat(newlist, " ", argv(j));
540 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
541 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
542 newlist = strcat(newlist, " ", argv(j));
543 newlist = substring(newlist, 1, strlen(newlist) - 1);
545 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
546 newlist = strcat(newlist, "'", argv(j), "'");
547 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
548 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
549 newlist = strcat(newlist, "'", argv(j), "'");
551 cvar_set("g_maplist", newlist);
553 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
555 Map_Count = tokenize(newlist);
558 // NOTE: the selected map has just been inserted at (insertpos-1)th position
559 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
560 if(Map_Check(Map_Current, 1))
566 void() Maplist_Init =
569 temp = cvar_string("g_maplist");
571 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
573 Map_Count = tokenize(temp);
577 bprint( "Maplist is empty! Resetting it to default map list.\n" );
579 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
580 localcmd("\nmenu_cmd sync\n");
581 Map_Count = tokenizebyseparator(temp, " ");
583 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
584 Map_Count = tokenize(temp);
588 error("empty maplist, cannot select a new map");
589 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
591 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
592 // this may or may not be correct, but who cares, in the worst case a map
593 // isn't chosen in the first pass that should have been
596 string() GetNextMap =
604 if(cvar("g_maplist_shuffle") > 0)
605 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
608 if(cvar("g_maplist_selectrandom"))
609 nextMap = MaplistMethod_Random();
612 nextMap = MaplistMethod_Iterate();
615 nextMap = MaplistMethod_Repeat();
619 Map_Goto_SetFloat(nextMap);
620 return getmapname_stored;
626 float() DoNextMapOverride =
630 if(cvar("g_campaign"))
632 CampaignPostIntermission();
633 alreadychangedlevel = TRUE;
636 if(cvar("quit_when_empty"))
638 if(player_count <= currentbots)
641 alreadychangedlevel = TRUE;
645 if(cvar_string("quit_and_redirect") != "")
647 redirection_target = strzone(cvar_string("quit_and_redirect"));
648 alreadychangedlevel = TRUE;
651 if (cvar("samelevel")) // if samelevel is set, stay on same level
653 // 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)
654 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
655 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
656 localcmd("restart\n");
657 //changelevel (mapname);
658 alreadychangedlevel = TRUE;
661 if(cvar_string("nextmap") != "")
663 if(MapInfo_CheckMap(cvar_string("nextmap")))
665 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
668 Map_Goto_SetStr(cvar_string("nextmap"));
670 alreadychangedlevel = TRUE;
673 if(cvar("lastlevel"))
676 localcmd("set lastlevel 0\ntogglemenu\n");
677 alreadychangedlevel = TRUE;
685 //local string nextmap;
686 //local float n, nummaps;
688 if (alreadychangedlevel)
690 alreadychangedlevel = TRUE;
696 for(allowReset = 1; allowReset >= 0; --allowReset)
698 nextMap = GetNextMap();
704 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
706 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
707 localcmd("\nmenu_cmd sync\n");
709 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
714 error("Everything is broken - not even the default map list works. Please report this to the developers.");
726 When the player presses attack or jump, change to the next level
729 .float autoscreenshot;
730 void() MapVote_Start;
731 void() MapVote_Think;
732 float mapvote_initialized;
733 void() IntermissionThink =
735 FixIntermissionClient(self);
737 if(cvar("sv_autoscreenshot"))
738 if(self.autoscreenshot > 0)
739 if(time > self.autoscreenshot)
741 self.autoscreenshot = -1;
742 if(clienttype(self) == CLIENTTYPE_REAL)
743 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
747 if (time < intermission_exittime)
750 if(!mapvote_initialized)
751 if (time < intermission_exittime + 10 && !self.button0 && !self.button2 && !self.button3 && !self.button6 && !self.buttonuse)
761 Returns the entity to view from
765 entity() FindIntermission =
770 // look for info_intermission first
771 spot = find (world, classname, "info_intermission");
773 { // pick a random one
777 spot = find (spot, classname, "info_intermission");
779 spot = find (spot, classname, "info_intermission");
785 // then look for the start position
786 spot = find (world, classname, "info_player_start");
790 // testinfo_player_start is only found in regioned levels
791 spot = find (world, classname, "testplayerstart");
795 // then look for the start position
796 spot = find (world, classname, "info_player_deathmatch");
800 //objerror ("FindIntermission: no spot");
806 ===============================================================================
810 ===============================================================================
813 void(float final) DumpStats =
817 local float to_console;
818 local float to_eventlog;
821 to_console = cvar("sv_logscores_console");
822 to_eventlog = cvar("sv_eventlog");
823 to_file = cvar("sv_logscores_file");
827 to_console = TRUE; // always print printstats replies
828 to_eventlog = FALSE; // but never print them to the event log
832 if(cvar("sv_eventlog_console"))
833 to_console = FALSE; // otherwise we get the output twice
840 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
842 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
846 ServerConsoleEcho(s, FALSE);
848 GameLogEcho(s, FALSE);
851 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
855 fputs(file, strcat(s, "\n"));
858 FOR_EACH_CLIENT(other)
860 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
862 s = strcat(":player:", ftos(other.frags), ":");
863 s = strcat(s, ftos(other.deaths), ":");
864 s = strcat(s, ftos(rint(time - other.jointime)), ":");
865 s = strcat(s, ftos(other.team), ":");
868 ServerConsoleEcho(strcat(s, other.netname), TRUE);
870 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
872 fputs(file, strcat(s, other.netname, "\n"));
877 ServerConsoleEcho(":end", FALSE);
879 GameLogEcho(":end", FALSE);
882 fputs(file, ":end\n");
887 void FixIntermissionClient(entity e)
889 if(!e.autoscreenshot) // initial call
891 e.angles = e.v_angle;
892 e.angles_x = -e.angles_x;
893 e.autoscreenshot = time + 0.8; // used for autoscreenshot
895 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
897 e.movetype = MOVETYPE_NONE;
898 e.takedamage = DAMAGE_NO;
900 e.weaponentity.effects = EF_NODRAW;
901 stuffcmd(e, "\nscr_printspeed 1000000\n");
902 if(clienttype(e) == CLIENTTYPE_REAL)
905 WriteByte(MSG_ONE, SVC_INTERMISSION);
909 //e.velocity = '0 0 0';
912 // TODO halt weapon animation
917 go to the next level for deathmatch
918 only called if a time or frag limit has expired
929 intermission_running = 1;
931 // enforce a wait time before allowing changelevel
933 intermission_exittime = time + cvar("sv_mapchange_delay");
935 intermission_exittime = -1;
937 WriteByte (MSG_ALL, SVC_CDTRACK);
938 WriteByte (MSG_ALL, 3);
939 WriteByte (MSG_ALL, 3);
941 //pos = FindIntermission ();
947 if(cvar("sv_eventlog"))
948 GameLogEcho(":gameover", FALSE);
952 FOR_EACH_CLIENT(other)
954 FixIntermissionClient(other);
957 bprint(other.netname, " ^7wins.\n");
962 FOR_EACH_PLAYER(other)
964 if(maxTotalFrags < other.totalfrags)
965 maxTotalFrags = other.totalfrags;
966 if(minTotalFrags > other.totalfrags)
967 minTotalFrags = other.totalfrags;
972 FOR_EACH_PLAYER(other)
974 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
975 f = bound(0, other.play_time / max(time, 1), 1);
976 // store some statistics?
980 if(cvar("g_campaign"))
981 CampaignPreIntermission();
983 // WriteByte (MSG_ALL, SVC_INTERMISSION);
990 Exit deathmatch games upon conditions
993 void() CheckRules_Player =
995 if (gameover) // someone else quit the game already
998 if(self.deadflag == DEAD_NO)
999 self.play_time += frametime;
1001 // fixme: don't check players; instead check dom_team and ctf_team entities
1002 // (div0: and that in CheckRules_World please)
1005 float checkrules_oneminutewarning;
1006 float checkrules_leaderfrags;
1007 float tdm_max_score, tdm_old_score;
1009 float checkrules_equality;
1010 float checkrules_overtimewarning;
1011 float checkrules_overtimeend;
1013 void() InitiateOvertime =
1015 if(!checkrules_overtimeend)
1016 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1019 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1020 float WINNING_YES = 1; // winner found
1021 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1022 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1024 float(float fraglimitreached, float equality) GetWinningCode =
1027 if(fraglimitreached)
1028 return WINNING_STARTOVERTIME;
1030 return WINNING_NEVER;
1032 if(fraglimitreached)
1038 // set the .winning flag for exactly those players with a given field value
1039 void(.float field, float value) SetWinners =
1042 FOR_EACH_PLAYER(head)
1043 head.winning = (head.field == value);
1046 // set the .winning flag for those players with a given field value
1047 void(.float field, float value) AddWinners =
1050 FOR_EACH_PLAYER(head)
1051 if(head.field == value)
1055 // clear the .winning flags
1056 void(void) ClearWinners =
1059 FOR_EACH_PLAYER(head)
1063 // Onslaught winning condition:
1064 // game terminates if only one team has a working generator (or none)
1065 float() WinningCondition_Onslaught =
1068 local float t1, t2, t3, t4;
1069 // first check if the game has ended
1070 t1 = t2 = t3 = t4 = 0;
1071 head = find(world, classname, "onslaught_generator");
1074 if (head.health > 0)
1076 if (head.team == COLOR_TEAM1) t1 = 1;
1077 if (head.team == COLOR_TEAM2) t2 = 1;
1078 if (head.team == COLOR_TEAM3) t3 = 1;
1079 if (head.team == COLOR_TEAM4) t4 = 1;
1081 head = find(head, classname, "onslaught_generator");
1083 if (t1 + t2 + t3 + t4 < 2)
1085 // game over, only one team remains (or none)
1087 if (t1) SetWinners(team, COLOR_TEAM1);
1088 if (t2) SetWinners(team, COLOR_TEAM2);
1089 if (t3) SetWinners(team, COLOR_TEAM3);
1090 if (t4) SetWinners(team, COLOR_TEAM4);
1091 dprint("Have a winner, ending game.\n");
1095 // Two or more teams remain
1099 float() LMS_NewPlayerLives =
1102 fl = cvar("fraglimit");
1106 // first player has left the game for dying too much? Nobody else can get in.
1107 if(lms_lowest_lives < 1)
1110 if(!cvar("g_lms_join_anytime"))
1111 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1114 return bound(1, lms_lowest_lives, fl);
1117 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1118 // they win. Otherwise the defending team wins once the timelimit passes.
1119 void assault_new_round();
1120 float() WinningCondition_Assault =
1123 status = WINNING_NO;
1125 // as the timelimit has not yet passed just assume the defending team will win
1126 if(assault_attacker_team == COLOR_TEAM1)
1128 SetWinners(team, COLOR_TEAM2);
1132 SetWinners(team, COLOR_TEAM1);
1136 ent = find(world, classname, "target_assault_roundend");
1139 if(ent.winning) // round end has been triggered by attacking team
1141 SetWinners(team, assault_attacker_team);
1142 if(assault_attacker_team == COLOR_TEAM1)
1144 team1_score = team1_score + 50;
1148 team2_score = team2_score + 50;
1151 if(ent.cnt == 1) // this was the second round
1153 status = WINNING_YES;
1157 cvar_set("timelimit", ftos((2*time)/60));
1158 assault_new_round();
1168 // LMS winning condition: game terminates if and only if there's at most one
1169 // one player who's living lives. Top two scores being equal cancels the time
1171 float() WinningCondition_LMS =
1178 have_player = FALSE;
1179 have_players = FALSE;
1180 l = LMS_NewPlayerLives();
1182 head = find(world, classname, "player");
1185 head = find(head, classname, "player");
1187 have_players = TRUE;
1191 // we have at least one player
1194 // two or more active players - continue with the game
1198 // exactly one player?
1201 // but no game has taken place yet
1206 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1207 dprint("Have a winner, ending game.\n");
1214 // nobody is playing at all...
1217 // wait for players...
1221 // SNAFU (maybe a draw game?)
1223 dprint("No players, ending game.\n");
1228 // When we get here, we have at least two players who are actually LIVING,
1229 // or one player who is still waiting for a victim to join the server. Now
1230 // check if the top two players have equal score.
1232 checkrules_leaderfrags = 0;
1233 checkrules_equality = FALSE;
1234 FOR_EACH_PLAYER(head)
1236 if(head.frags > checkrules_leaderfrags)
1238 checkrules_leaderfrags = head.frags;
1239 checkrules_equality = FALSE;
1241 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1242 checkrules_equality = TRUE;
1245 SetWinners(frags, checkrules_leaderfrags);
1247 // The top two players have the same amount of lives? No timelimit then,
1248 // enter overtime...
1250 if(checkrules_equality)
1251 return WINNING_NEVER;
1253 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1257 // DM winning condition: game terminates if a player reached the fraglimit,
1258 // unless the first two players have the same score. The latter case also
1259 // breaks the time limit.
1260 float(float fraglimit) WinningCondition_MaxIndividualScore =
1262 float checkrules_oldleaderfrags;
1265 checkrules_oldleaderfrags = checkrules_leaderfrags;
1266 checkrules_leaderfrags = 0;
1267 checkrules_equality = FALSE;
1268 FOR_EACH_PLAYER(head)
1270 if(head.frags > checkrules_leaderfrags)
1272 checkrules_leaderfrags = head.frags;
1273 checkrules_equality = FALSE;
1275 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1276 checkrules_equality = TRUE;
1279 if(checkrules_leaderfrags > 0)
1280 SetWinners(frags, checkrules_leaderfrags);
1285 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1287 if (checkrules_leaderfrags == fraglimit - 1)
1288 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1289 else if (checkrules_leaderfrags == fraglimit - 2)
1290 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1291 else if (checkrules_leaderfrags == fraglimit - 3)
1292 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1295 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1298 float(float fraglimit) WinningConditionBase_Teamplay =
1300 tdm_old_score = tdm_max_score;
1301 tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1303 checkrules_equality =
1308 (team1_score == tdm_max_score)
1309 + (team2_score == tdm_max_score)
1310 + (team3_score == tdm_max_score)
1311 + (team4_score == tdm_max_score)
1315 if(tdm_max_score > 0)
1317 if(team1_score == tdm_max_score)
1318 AddWinners(team, COLOR_TEAM1);
1319 if(team2_score == tdm_max_score)
1320 AddWinners(team, COLOR_TEAM2);
1321 if(team3_score == tdm_max_score)
1322 AddWinners(team, COLOR_TEAM3);
1323 if(team4_score == tdm_max_score)
1324 AddWinners(team, COLOR_TEAM4);
1327 if(!g_runematch && !g_domination)
1328 if(tdm_max_score != tdm_old_score)
1330 if(tdm_max_score == fraglimit - 1)
1331 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1332 else if(tdm_max_score == fraglimit - 2)
1333 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1334 else if(tdm_max_score == fraglimit - 3)
1335 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1338 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1341 // TDM winning condition: game terminates if a team's score sum reached the
1342 // fraglimit, unless the first two teams have the same total score. The latter
1343 // case also breaks the time limit.
1344 float(float fraglimit) WinningCondition_MaxTeamSum =
1348 team1_score = team2_score = team3_score = team4_score = 0;
1350 FOR_EACH_PLAYER(head)
1352 if(head.team == COLOR_TEAM1)
1353 team1_score += head.frags;
1354 else if(head.team == COLOR_TEAM2)
1355 team2_score += head.frags;
1356 else if(head.team == COLOR_TEAM3)
1357 team3_score += head.frags;
1358 else if(head.team == COLOR_TEAM4)
1359 team4_score += head.frags;
1362 return WinningConditionBase_Teamplay(fraglimit);
1365 // DOM/CTF winning condition: game terminates if the max of a team's players'
1366 // score reached the fraglimit, unless the first two teams have the same
1367 // maximum score. The latter case also breaks the time limit.
1368 float(float fraglimit) WinningCondition_MaxTeamMax =
1372 team1_score = team2_score = team3_score = team4_score = 0;
1374 FOR_EACH_PLAYER(head)
1376 if(head.team == COLOR_TEAM1)
1378 if(head.frags > team1_score)
1379 team1_score = head.frags;
1381 else if(head.team == COLOR_TEAM2)
1383 if(head.frags > team2_score)
1384 team2_score = head.frags;
1386 else if(head.team == COLOR_TEAM3)
1388 if(head.frags > team3_score)
1389 team3_score = head.frags;
1391 else if(head.team == COLOR_TEAM4)
1393 if(head.frags > team4_score)
1394 team4_score = head.frags;
1398 return WinningConditionBase_Teamplay(fraglimit);
1401 void print_to(entity e, string s)
1404 sprint(e, strcat(s, "\n"));
1406 ServerConsoleEcho(s, TRUE);
1409 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1419 FOR_EACH_PLAYER(head)
1421 if(!whichteam || head.team == whichteam)
1425 print_to(e, strcat(" ", colorcode, name, ":"));
1427 fragtotal = fragtotal + head.frags;
1428 s = ftos(head.frags);
1429 s = strcat(s, "/", ftos(head.deaths));
1430 s = strcat(s, " @ ", ftos(head.ping));
1431 if(clienttype(head) == CLIENTTYPE_BOT)
1432 s = strcat(s, "botms");
1434 s = strcat(s, "ms");
1435 v = PlayerValue(head);
1437 s = strcat(s, " / ", ftos(v));
1438 print_to(e, strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"));
1441 if(whichteam && found)
1443 s = ftos(fragtotal);
1444 s = strcat(s, " / ", ftos(teamvalue));
1445 print_to(e, strcat(colorcode, " (total: ", s, ")"));
1449 void PrintScoreboard(entity e)
1451 print_to(e, strcat("Time: ", ftos(time / 60)));
1452 print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1453 print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1454 print_to(e, "Scoreboard:");
1457 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1458 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1459 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM3);
1460 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM4);
1464 PrintScoreboardFor(e, "", "^7", 0);
1469 void ShuffleMaplist()
1477 result = cvar_string("g_maplist");
1479 litems = tokenizebyseparator(result, " ");
1481 litems = tokenize(result);
1484 for(start = 0; start < litems - 1; ++start)
1488 // select a random item
1489 selected = ceil(random() * (litems - start) + start) - 1;
1491 // shift this item to the place start
1493 for(i = 0; i < start; ++i)
1494 result = strcat(result, " ", argv(i));
1495 result = strcat(result, " ", argv(selected));
1496 for(i = start; i < litems; ++i)
1498 result = strcat(result, " ", argv(i));
1499 result = substring(result, 1, strlen(result) - 1);
1501 litems = tokenizebyseparator(result, " ");
1503 for(i = 0; i < start; ++i)
1504 result = strcat(result, "'", argv(i), "'");
1505 result = strcat(result, "'", argv(selected), "'");
1506 for(i = start; i < litems; ++i)
1508 result = strcat(result, "'", argv(i), "'");
1510 litems = tokenize(result);
1513 //dprint(result, "\n");
1516 cvar_set("g_maplist", result);
1523 Exit deathmatch games upon conditions
1526 void() CheckRules_World =
1529 local float timelimit;
1530 local float fraglimit;
1538 MapVote_Think should now do that part
1539 if (intermission_running)
1540 if (time >= intermission_exittime + 60)
1542 if(!DoNextMapOverride())
1548 if (gameover) // someone else quit the game already
1550 if(player_count == 0) // Nobody there? Then let's go to the next map
1552 // this will actually check the player count in the next frame
1553 // again, but this shouldn't hurt
1557 timelimit = cvar("timelimit") * 60;
1558 fraglimit = cvar("fraglimit");
1560 if(checkrules_overtimeend)
1562 if(!checkrules_overtimewarning)
1564 checkrules_overtimewarning = TRUE;
1565 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1566 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1571 if (timelimit && time >= timelimit)
1575 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1581 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1583 checkrules_oneminutewarning = TRUE;
1584 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1587 status = WINNING_NO;
1590 status = WinningCondition_Assault();
1594 status = WinningCondition_LMS();
1596 else if (g_onslaught)
1598 status = WinningCondition_Onslaught();
1604 if(g_tdm || g_runematch || g_ctf || g_domination || g_keyhunt)
1605 status = WinningCondition_MaxTeamSum(fraglimit);
1607 // status = WinningCondition_MaxTeamMax(fraglimit);
1610 dprint("div0: How can this happen?\n");
1611 status = WinningCondition_MaxTeamMax(fraglimit);
1615 status = WinningCondition_MaxIndividualScore(fraglimit);
1618 if(status == WINNING_STARTOVERTIME)
1620 status = WINNING_NEVER;
1624 if(status == WINNING_NEVER)
1625 // equality cases! Nobody wins if the overtime ends in a draw.
1628 if(checkrules_overtimeend)
1629 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1630 status = WINNING_YES;
1632 if(status == WINNING_YES)
1636 float randsel_value;
1637 float randsel_priority;
1638 float randsel_count;
1642 randsel_priority = -1;
1645 void RandSel_Add(float priority, float value)
1647 if(priority > randsel_priority)
1649 randsel_priority = priority;
1650 randsel_value = value;
1653 else if(priority == randsel_priority)
1656 if(ceil(random() * randsel_count) == 1)
1657 randsel_value = value;
1661 float mapvote_nextthink;
1662 float mapvote_initialized;
1663 float mapvote_keeptwotime;
1664 float mapvote_timeout;
1665 string mapvote_message;
1667 #define MAPVOTE_COUNT 10
1668 float mapvote_count;
1669 float mapvote_count_real;
1670 string mapvote_maps[MAPVOTE_COUNT];
1671 float mapvote_maps_suggested[MAPVOTE_COUNT];
1672 string mapvote_suggestions[MAPVOTE_COUNT];
1673 float mapvote_suggestion_ptr;
1674 float mapvote_maxlen;
1675 float mapvote_voters;
1676 float mapvote_votes[MAPVOTE_COUNT];
1678 float mapvote_detail;
1679 float mapvote_abstain;
1682 void MapVote_ClearAllVotes()
1684 FOR_EACH_CLIENT(other)
1688 string MapVote_Suggest(string m)
1692 return "That's not how to use this command.";
1693 if(!cvar("g_maplist_votable_suggestions"))
1694 return "Suggestions are not accepted on this server.";
1695 if(mapvote_initialized)
1696 return "Can't suggest - voting is already in progress!";
1698 m = MapInfo_FixName(m);
1700 return "The map you suggested is not available on this server.";
1702 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1703 if(!IsSameGametype(m))
1704 return "This server does not allow changing the game type by map suggestions.";
1705 if(!cvar("g_maplist_votable_override_mostrecent"))
1707 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1710 if(!MapInfo_CheckMap(m))
1711 return "The map you suggested does not support the current game mode.";
1713 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1714 return "The map you suggested is not available on this server.";
1716 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1717 if(mapvote_suggestions[i] == m)
1718 return "This map was already suggested.";
1719 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1721 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1725 i = mapvote_suggestion_ptr;
1726 mapvote_suggestion_ptr += 1;
1728 if(mapvote_suggestions[i] != "")
1729 strunzone(mapvote_suggestions[i]);
1730 mapvote_suggestions[i] = strzone(m);
1731 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid), ":", self.netname), TRUE);
1732 return strcat("Suggestion of ", m, " accepted.");
1735 void MapVote_AddVotable(string nextMap, float isSuggestion)
1740 for(j = 0; j < mapvote_count; ++j)
1741 if(mapvote_maps[j] == nextMap)
1743 if(strlen(nextMap) > mapvote_maxlen)
1744 mapvote_maxlen = strlen(nextMap);
1745 mapvote_maps[mapvote_count] = strzone(nextMap);
1746 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1755 MapVote_ClearAllVotes();
1758 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1759 mapvote_abstain = cvar("g_maplist_votable_abstain");
1762 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1764 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1765 smax = min(nmax, cvar("g_maplist_votable_suggestions"));
1767 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1768 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1770 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1771 MapVote_AddVotable(GetNextMap(), FALSE);
1773 if(mapvote_count == 0)
1775 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1777 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1778 localcmd("\nmenu_cmd sync\n");
1780 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1782 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1783 MapVote_AddVotable(GetNextMap(), FALSE);
1786 mapvote_count_real = mapvote_count;
1788 MapVote_AddVotable("don't care", 0);
1790 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1792 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1793 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1794 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1795 mapvote_keeptwotime = 0;
1796 mapvote_message = "Choose a map and press its key!";
1798 float MapVote_Finished(float mappos)
1804 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1805 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1806 didntvote = mapvote_voters;
1807 for(i = 0; i < mapvote_count; ++i)
1808 if(mapvote_maps[i] != "")
1810 didntvote -= mapvote_votes[i];
1813 result = strcat(result, ":", mapvote_maps[i]);
1814 result = strcat(result, ":", ftos(mapvote_votes[i]));
1817 result = strcat(result, ":didn't vote:", ftos(didntvote));
1819 GameLogEcho(result, FALSE);
1820 if(mapvote_maps_suggested[mappos])
1821 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
1823 FOR_EACH_REALCLIENT(other)
1824 FixClientCvars(other);
1826 Map_Goto_SetStr(mapvote_maps[mappos]);
1828 alreadychangedlevel = TRUE;
1831 void MapVote_CheckRules_1()
1835 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1837 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1838 mapvote_votes[i] = 0;
1842 FOR_EACH_REALCLIENT(other)
1847 i = other.mapvote - 1;
1848 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1849 mapvote_votes[i] = mapvote_votes[i] + 1;
1854 float MapVote_CheckRules_2()
1857 float firstPlace, secondPlace;
1858 float firstPlaceVotes, secondPlaceVotes;
1859 float mapvote_voters_real;
1862 mapvote_voters_real = mapvote_voters;
1864 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
1867 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1868 RandSel_Add(mapvote_votes[i], i);
1869 firstPlace = randsel_value;
1870 firstPlaceVotes = randsel_priority;
1871 //dprint("First place: ", ftos(firstPlace), "\n");
1872 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1875 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1877 RandSel_Add(mapvote_votes[i], i);
1878 secondPlace = randsel_value;
1879 secondPlaceVotes = randsel_priority;
1880 //dprint("Second place: ", ftos(secondPlace), "\n");
1881 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1883 if(firstPlace == -1)
1884 error("No first place in map vote... WTF?");
1886 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
1887 return MapVote_Finished(firstPlace);
1889 if(mapvote_keeptwotime)
1890 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
1893 mapvote_message = "Now decide between the TOP TWO!";
1894 mapvote_keeptwotime = 0;
1895 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
1896 result = strcat(result, ":", ftos(firstPlaceVotes));
1897 result = strcat(result, ":", mapvote_maps[secondPlace]);
1898 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
1899 didntvote = mapvote_voters;
1900 for(i = 0; i < mapvote_count; ++i)
1901 if(mapvote_maps[i] != "")
1903 didntvote -= mapvote_votes[i];
1905 if(i != secondPlace)
1907 result = strcat(result, ":", mapvote_maps[i]);
1908 result = strcat(result, ":", ftos(mapvote_votes[i]));
1909 if(i < mapvote_count_real)
1911 strunzone(mapvote_maps[i]);
1912 mapvote_maps[i] = "";
1916 result = strcat(result, ":didn't vote:", ftos(didntvote));
1917 GameLogEcho(result, FALSE);
1930 keeptwo = mapvote_keeptwotime;
1931 MapVote_CheckRules_1(); // count
1932 if(MapVote_CheckRules_2()) // decide
1936 FOR_EACH_REALCLIENT(other)
1938 // hide scoreboard again
1939 if(other.health != 2342)
1941 other.health = 2342;
1943 if(clienttype(other) == CLIENTTYPE_REAL)
1945 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");
1947 WriteByte(MSG_ONE, SVC_FINALE);
1948 WriteString(MSG_ONE, "");
1952 // notify about keep-two
1953 if(keeptwo != 0 && mapvote_keeptwotime == 0)
1954 play2(other, "misc/invshot.wav");
1956 // clear possibly invalid votes
1957 if(mapvote_maps[other.mapvote - 1] == "")
1959 // use impulses as new vote
1960 if(other.impulse >= 1 && other.impulse <= mapvote_count)
1961 if(mapvote_maps[other.impulse - 1] != "")
1962 other.mapvote = other.impulse;
1969 MapVote_CheckRules_1(); // just count
1971 FOR_EACH_REALCLIENT(other)
1973 // display voting screen
1974 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
1975 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
1977 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
1978 msgstr = strcat(msgstr, mapvote_message);
1979 msgstr = strcat(msgstr, "\n\n");
1980 for(i = 0; i < mapvote_count; ++i)
1981 if(mapvote_maps[i] == "")
1982 msgstr = strcat(msgstr, "\n");
1985 tmp = mapvote_maps[i];
1986 tmp = strpad(mapvote_maxlen, tmp);
1987 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
1990 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
1991 if(mapvote_votes[i] != 1)
1992 tmp = strcat(tmp, "s");
1993 tmp = strcat(tmp, ")");
1994 tmp = strpad(mapvote_maxlen + 15, tmp);
1997 if(i == mapvote_count - 1)
1998 msgstr = strcat(msgstr, "\n");
1999 if(other.mapvote == i + 1)
2000 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2002 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2005 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2007 msgstr = strcat(msgstr, "s");
2008 msgstr = strcat(msgstr, " cast");
2009 i = ceil(mapvote_timeout - time);
2010 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2012 msgstr = strcat(msgstr, "s");
2013 msgstr = strcat(msgstr, " left");
2015 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2018 void MapVote_Start()
2024 MapInfo_Enumerate();
2025 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2029 void MapVote_Think()
2034 if(alreadychangedlevel)
2037 if(time < mapvote_nextthink)
2041 mapvote_nextthink = time + 0.5;
2043 if(!mapvote_initialized)
2045 mapvote_initialized = TRUE;
2046 if(DoNextMapOverride())
2048 if(!cvar("g_maplist_votable") || player_count <= 0)
2059 string GotoMap(string m)
2062 if(!MapInfo_CheckMap(m))
2064 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2066 return "The map you chose is not available on this server.";
2067 cvar_set("nextmap", m);
2068 cvar_set("timelimit", "-1");
2069 if(mapvote_initialized || alreadychangedlevel)
2071 if(DoNextMapOverride())
2072 return "Map switch initiated.";
2074 return "Hm... no. For some reason I like THIS map more.";
2077 return "Map switch will happen after scoreboard.";
2083 FOR_EACH_REALCLIENT(self)
2085 if(self.classname == "spectator")
2087 if(self.enemy.hitsound)
2088 play2(self, "misc/hit.wav");
2093 play2(self, "misc/hit.wav");
2096 FOR_EACH_CLIENT(self)
2097 self.hitsound = FALSE;
2103 * returns TRUE if redirecting
2105 float redirection_timeout;
2106 float redirection_nextthink;
2107 float RedirectionThink()
2109 float clients_found;
2111 if(redirection_target == "")
2114 if(!redirection_timeout)
2116 cvar_set("sv_public", "-2");
2117 redirection_timeout = time + 0.5; // this will only try twice... should be able to keep more clients
2118 if(redirection_target == "self")
2119 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2121 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2124 if(time < redirection_nextthink)
2127 redirection_nextthink = time + 1;
2130 FOR_EACH_REALCLIENT(self)
2132 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2133 if(redirection_target == "self")
2134 stuffcmd(self, "\ndisconnect; reconnect\n");
2136 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2140 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2142 if(time > redirection_timeout || clients_found == 0)
2143 localcmd("\nwait; wait; wait; quit\n");