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 TODO sound pack system
95 // initialize sound pack system
96 soundpack = cvar_string("g_soundpack");
98 soundpack = strcat(soundpack, "/");
99 soundpack = strzone(soundpack);
105 // 1 FLICKER (first variety)
106 lightstyle(1, "mmnmmommommnonmmonqnmmo");
108 // 2 SLOW STRONG PULSE
109 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
111 // 3 CANDLE (first variety)
112 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
115 lightstyle(4, "mamamamamama");
118 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
120 // 6 FLICKER (second variety)
121 lightstyle(6, "nmonqnmomnmomomno");
123 // 7 CANDLE (second variety)
124 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
126 // 8 CANDLE (third variety)
127 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
129 // 9 SLOW STROBE (fourth variety)
130 lightstyle(9, "aaaaaaaazzzzzzzz");
132 // 10 FLUORESCENT FLICKER
133 lightstyle(10, "mmamammmmammamamaaamammma");
135 // 11 SLOW PULSE NOT FADE TO BLACK
136 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
138 // styles 32-62 are assigned by the light program for switchable lights
144 lms_lowest_lives = 0;
149 bot_waypoints_for_items = cvar("g_waypoints_for_items");
150 if(bot_waypoints_for_items == 1)
151 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
152 bot_waypoints_for_items = 0;
154 if(cvar("g_campaign"))
161 WaypointSprite_Init();
167 head = nextent(world);
172 head = nextent(head);
175 GameLogInit(); // prepare everything
176 if(cvar("sv_eventlog"))
179 GameLogEcho(":logversion:2", FALSE);
180 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
181 s = strcat(s, ftos(random()));
183 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s), FALSE);
185 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
187 s = ":gameinfo:mutators:LIST";
188 if(cvar("g_grappling_hook"))
189 s = strcat(s, ":grappling_hook");
190 if(!cvar("g_use_ammunition"))
191 s = strcat(s, ":no_use_ammunition");
192 if(!cvar("g_pickup_items"))
193 s = strcat(s, ":no_pickup_items");
194 if(cvar("g_instagib"))
195 s = strcat(s, ":instagib");
196 if(cvar("g_rocketarena"))
197 s = strcat(s, ":rockerarena");
199 s = strcat(s, ":nixnex");
200 if(cvar("g_vampire"))
201 s = strcat(s, ":vampire");
202 if(cvar("g_laserguided_missile"))
203 s = strcat(s, ":laserguided_missile");
204 if(cvar("g_norecoil"))
205 s = strcat(s, ":norecoil");
207 s = strcat(s, ":midair");
208 if(cvar("g_minstagib"))
209 s = strcat(s, ":minstagib");
210 GameLogEcho(s, FALSE);
211 GameLogEcho(":gameinfo:end", FALSE);
214 cvar_set("nextmap", "");
218 if(cvar("g_campaign"))
227 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
233 //makestatic (self); // Who the f___ did that?
237 float( string pFilename ) TryFile =
240 dprint("TryFile(\"", pFilename, "\")\n");
241 lHandle = fopen( pFilename, FILE_READ );
242 if( lHandle != -1 ) {
252 if (game == GAME_DEATHMATCH)
254 else if (game == GAME_TEAM_DEATHMATCH)
256 else if (game == GAME_DOMINATION)
258 else if (game == GAME_CTF)
260 else if (game == GAME_RUNEMATCH)
262 else if (game == GAME_LMS)
264 else if (game == GAME_KEYHUNT)
266 else if (game == GAME_ONSLAUGHT)
268 else if (game == GAME_ASSAULT)
273 float IsSameGametype(string mapcfgname)
276 return TRUE; // can't change game type by map name here
280 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
286 string getmapname_stored;
292 if(getmapname_stored == "")
293 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
294 return getmapname_stored;
298 float Map_Count, Map_Current;
299 string Map_Current_Name;
301 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
302 float GetMaplistPosition()
308 idx = cvar("g_maplist_index");
315 for(pos = 0; pos < Map_Count; ++pos)
319 // resume normal maplist rotation if current map is not in g_maplist
323 float MapHasRightSize(string map)
325 // open map size restriction file
327 dprint("opensize "); dprint(map);
328 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
331 float mapmin, mapmax;
333 mapmin = stof(fgets(fh));
334 mapmax = stof(fgets(fh));
336 if(player_count < mapmin)
338 dprint("not enough\n");
341 if(player_count > mapmax)
343 dprint("too many\n");
346 dprint("right size\n");
349 dprint(": not found\n");
353 string Map_Filename(float position)
356 return strcat("maps/", argv(position), ".bsp");
358 return strcat("maps/", argv(position), ".mapcfg");
362 string strwords(string s, float w)
365 for(endpos = 0; w && endpos >= 0; --w)
366 endpos = strstrofs(s, " ", endpos + 1);
370 return substring(s, 0, endpos);
373 float strhasword(string s, string w)
375 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
378 void Map_MarkAsRecent(string m)
380 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
383 float Map_IsRecent(string m)
385 return strhasword(cvar_string("g_maplist_mostrecent"), m);
388 float(float position, float pass) Map_Check =
392 map_next = argv(position);
395 if(map_next == Map_Current_Name) // same map again in first pass?
397 if(Map_IsRecent(map_next))
400 filename = Map_Filename(position);
402 if(MapInfo_CheckMap(map_next))
404 if(TryFile(filename))
409 if(MapHasRightSize(map_next))
414 dprint( "Couldn't find '", filename, "'..\n" );
419 void(string nextmapname) Map_Goto_SetStr =
421 if(getmapname_stored != "")
422 strunzone(getmapname_stored);
423 if(nextmapname == "")
424 getmapname_stored = "";
426 getmapname_stored = strzone(nextmapname);
429 void(float position) Map_Goto_SetFloat =
431 cvar_set("g_maplist_index", ftos(position));
432 Map_Goto_SetStr(argv(position));
435 void() GameResetCfg =
438 // settings persist, except...
439 if(cvar("g_campaign"))
440 localcmd("\nexec mutator_reset.cfg\n");
441 localcmd("\nsettemp_restore\n");
443 // if an exit cfg is defined by exiting map, exec it.
445 exit_cfg = cvar_string("exit_cfg");
447 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
449 localcmd("exec game_reset.cfg\n");
457 Map_MarkAsRecent(getmapname_stored);
460 MapInfo_LoadMap(getmapname_stored);
462 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
466 // return codes of map selectors:
467 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
468 // -2 = permanent failure
469 float() MaplistMethod_Iterate = // usual method
473 for(pass = 1; pass <= 2; ++pass)
475 for(i = 1; i < Map_Count; ++i)
478 mapindex = math_mod(i + Map_Current, Map_Count);
479 if(Map_Check(mapindex, pass))
486 float() MaplistMethod_Repeat = // fallback method
488 if(Map_Check(Map_Current, 2))
493 float() MaplistMethod_Random = // random map selection
499 for(i = 0; i <= imax; ++i)
502 mapindex = math_mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
503 if(Map_Check(mapindex, 1))
509 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
510 // the exponent sets a bias on the map selection:
511 // the higher the exponent, the less likely "shortly repeated" same maps are
513 float i, j, imax, insertpos;
517 for(i = 0; i <= imax; ++i)
521 // now reinsert this at another position
522 insertpos = pow(random(), 1 / exponent); // ]0, 1]
523 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
524 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
525 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
527 // insert the current map there
530 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
531 newlist = strcat(newlist, " ", argv(j));
532 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
533 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
534 newlist = strcat(newlist, " ", argv(j));
535 newlist = substring(newlist, 1, strlen(newlist) - 1);
537 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
538 newlist = strcat(newlist, "'", argv(j), "'");
539 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
540 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
541 newlist = strcat(newlist, "'", argv(j), "'");
543 cvar_set("g_maplist", newlist);
545 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
547 Map_Count = tokenize(newlist);
550 // NOTE: the selected map has just been inserted at (insertpos-1)th position
551 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
552 if(Map_Check(Map_Current, 1))
558 void() Maplist_Init =
561 temp = cvar_string("g_maplist");
563 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
565 Map_Count = tokenize(temp);
569 bprint( "Maplist is empty! Resetting it to default map list.\n" );
571 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
572 localcmd("\nmenu_cmd sync\n");
573 Map_Count = tokenizebyseparator(temp, " ");
575 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
576 Map_Count = tokenize(temp);
580 error("empty maplist, cannot select a new map");
581 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
583 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
584 // this may or may not be correct, but who cares, in the worst case a map
585 // isn't chosen in the first pass that should have been
588 string() GetNextMap =
596 if(cvar("g_maplist_shuffle") > 0)
597 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
600 if(cvar("g_maplist_selectrandom"))
601 nextMap = MaplistMethod_Random();
604 nextMap = MaplistMethod_Iterate();
607 nextMap = MaplistMethod_Repeat();
611 Map_Goto_SetFloat(nextMap);
612 return getmapname_stored;
618 float() DoNextMapOverride =
622 if(cvar("g_campaign"))
624 CampaignPostIntermission();
625 alreadychangedlevel = TRUE;
628 if(cvar("quit_when_empty"))
630 if(player_count <= currentbots)
633 alreadychangedlevel = TRUE;
637 if(cvar_string("quit_and_redirect") != "")
639 redirection_target = strzone(cvar_string("quit_and_redirect"));
640 alreadychangedlevel = TRUE;
643 if (cvar("samelevel")) // if samelevel is set, stay on same level
645 // 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)
646 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
647 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
648 localcmd("restart\n");
649 //changelevel (mapname);
650 alreadychangedlevel = TRUE;
653 if(cvar_string("nextmap") != "")
655 if(MapInfo_CheckMap(cvar_string("nextmap")))
657 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
660 Map_Goto_SetStr(cvar_string("nextmap"));
662 alreadychangedlevel = TRUE;
665 if(cvar("lastlevel"))
668 localcmd("set lastlevel 0\ntogglemenu\n");
669 alreadychangedlevel = TRUE;
677 //local string nextmap;
678 //local float n, nummaps;
680 if (alreadychangedlevel)
682 alreadychangedlevel = TRUE;
688 for(allowReset = 1; allowReset >= 0; --allowReset)
690 nextMap = GetNextMap();
696 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
698 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
699 localcmd("\nmenu_cmd sync\n");
701 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
706 error("Everything is broken - not even the default map list works. Please report this to the developers.");
718 When the player presses attack or jump, change to the next level
721 .float autoscreenshot;
722 void() MapVote_Start;
723 void() MapVote_Think;
724 float mapvote_initialized;
725 void() IntermissionThink =
727 FixIntermissionClient(self);
729 if(cvar("sv_autoscreenshot"))
730 if(self.autoscreenshot > 0)
731 if(time > self.autoscreenshot)
733 self.autoscreenshot = -1;
734 if(clienttype(self) == CLIENTTYPE_REAL)
735 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
739 if (time < intermission_exittime)
742 if(!mapvote_initialized)
743 if (time < intermission_exittime + 10 && !self.button0 && !self.button2 && !self.button3 && !self.button6 && !self.buttonuse)
753 Returns the entity to view from
757 entity() FindIntermission =
762 // look for info_intermission first
763 spot = find (world, classname, "info_intermission");
765 { // pick a random one
769 spot = find (spot, classname, "info_intermission");
771 spot = find (spot, classname, "info_intermission");
777 // then look for the start position
778 spot = find (world, classname, "info_player_start");
782 // testinfo_player_start is only found in regioned levels
783 spot = find (world, classname, "testplayerstart");
787 // then look for the start position
788 spot = find (world, classname, "info_player_deathmatch");
792 //objerror ("FindIntermission: no spot");
798 ===============================================================================
802 ===============================================================================
805 void(float final) DumpStats =
809 local float to_console;
810 local float to_eventlog;
813 to_console = cvar("sv_logscores_console");
814 to_eventlog = cvar("sv_eventlog");
815 to_file = cvar("sv_logscores_file");
819 to_console = TRUE; // always print printstats replies
820 to_eventlog = FALSE; // but never print them to the event log
824 if(cvar("sv_eventlog_console"))
825 to_console = FALSE; // otherwise we get the output twice
832 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
834 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
838 ServerConsoleEcho(s, FALSE);
840 GameLogEcho(s, FALSE);
843 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
847 fputs(file, strcat(s, "\n"));
850 FOR_EACH_CLIENT(other)
852 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
854 s = strcat(":player:", ftos(other.frags), ":");
855 s = strcat(s, ftos(other.deaths), ":");
856 s = strcat(s, ftos(rint(time - other.jointime)), ":");
857 s = strcat(s, ftos(other.team), ":");
860 ServerConsoleEcho(strcat(s, other.netname), TRUE);
862 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
864 fputs(file, strcat(s, other.netname, "\n"));
869 ServerConsoleEcho(":end", FALSE);
871 GameLogEcho(":end", FALSE);
874 fputs(file, ":end\n");
879 void FixIntermissionClient(entity e)
881 if(!e.autoscreenshot) // initial call
883 e.angles = e.v_angle;
884 e.angles_x = -e.angles_x;
885 e.autoscreenshot = time + 0.8; // used for autoscreenshot
887 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
889 e.movetype = MOVETYPE_NONE;
890 e.takedamage = DAMAGE_NO;
892 e.weaponentity.effects = EF_NODRAW;
893 stuffcmd(e, "\nscr_printspeed 1000000\n");
894 if(clienttype(e) == CLIENTTYPE_REAL)
897 WriteByte(MSG_ONE, SVC_INTERMISSION);
901 //e.velocity = '0 0 0';
904 // TODO halt weapon animation
909 go to the next level for deathmatch
910 only called if a time or frag limit has expired
921 intermission_running = 1;
923 // enforce a wait time before allowing changelevel
925 intermission_exittime = time + cvar("sv_mapchange_delay");
927 intermission_exittime = -1;
929 WriteByte (MSG_ALL, SVC_CDTRACK);
930 WriteByte (MSG_ALL, 3);
931 WriteByte (MSG_ALL, 3);
933 //pos = FindIntermission ();
939 if(cvar("sv_eventlog"))
940 GameLogEcho(":gameover", FALSE);
944 FOR_EACH_CLIENT(other)
946 FixIntermissionClient(other);
949 bprint(other.netname, " ^7wins.\n");
954 FOR_EACH_PLAYER(other)
956 if(maxTotalFrags < other.totalfrags)
957 maxTotalFrags = other.totalfrags;
958 if(minTotalFrags > other.totalfrags)
959 minTotalFrags = other.totalfrags;
964 FOR_EACH_PLAYER(other)
966 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
967 f = bound(0, other.play_time / max(time, 1), 1);
968 // store some statistics?
972 if(cvar("g_campaign"))
973 CampaignPreIntermission();
975 // WriteByte (MSG_ALL, SVC_INTERMISSION);
982 Exit deathmatch games upon conditions
985 void() CheckRules_Player =
987 if (gameover) // someone else quit the game already
990 if(self.deadflag == DEAD_NO)
991 self.play_time += frametime;
993 // fixme: don't check players; instead check dom_team and ctf_team entities
994 // (div0: and that in CheckRules_World please)
997 float checkrules_oneminutewarning;
998 float checkrules_leaderfrags;
999 float tdm_max_score, tdm_old_score;
1001 float checkrules_equality;
1002 float checkrules_overtimewarning;
1003 float checkrules_overtimeend;
1005 void() InitiateOvertime =
1007 if(!checkrules_overtimeend)
1008 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1011 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1012 float WINNING_YES = 1; // winner found
1013 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1014 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1016 float(float fraglimitreached, float equality) GetWinningCode =
1019 if(fraglimitreached)
1020 return WINNING_STARTOVERTIME;
1022 return WINNING_NEVER;
1024 if(fraglimitreached)
1030 // set the .winning flag for exactly those players with a given field value
1031 void(.float field, float value) SetWinners =
1034 FOR_EACH_PLAYER(head)
1035 head.winning = (head.field == value);
1038 // set the .winning flag for those players with a given field value
1039 void(.float field, float value) AddWinners =
1042 FOR_EACH_PLAYER(head)
1043 if(head.field == value)
1047 // clear the .winning flags
1048 void(void) ClearWinners =
1051 FOR_EACH_PLAYER(head)
1055 // Onslaught winning condition:
1056 // game terminates if only one team has a working generator (or none)
1057 float() WinningCondition_Onslaught =
1060 local float t1, t2, t3, t4;
1061 // first check if the game has ended
1062 t1 = t2 = t3 = t4 = 0;
1063 head = find(world, classname, "onslaught_generator");
1066 if (head.health > 0)
1068 if (head.team == COLOR_TEAM1) t1 = 1;
1069 if (head.team == COLOR_TEAM2) t2 = 1;
1070 if (head.team == COLOR_TEAM3) t3 = 1;
1071 if (head.team == COLOR_TEAM4) t4 = 1;
1073 head = find(head, classname, "onslaught_generator");
1075 if (t1 + t2 + t3 + t4 < 2)
1077 // game over, only one team remains (or none)
1079 if (t1) SetWinners(team, COLOR_TEAM1);
1080 if (t2) SetWinners(team, COLOR_TEAM2);
1081 if (t3) SetWinners(team, COLOR_TEAM3);
1082 if (t4) SetWinners(team, COLOR_TEAM4);
1083 dprint("Have a winner, ending game.\n");
1087 // Two or more teams remain
1091 float() LMS_NewPlayerLives =
1094 fl = cvar("fraglimit");
1098 // first player has left the game for dying too much? Nobody else can get in.
1099 if(lms_lowest_lives < 1)
1102 if(!cvar("g_lms_join_anytime"))
1103 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1106 return bound(1, lms_lowest_lives, fl);
1109 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1110 // they win. Otherwise the defending team wins once the timelimit passes.
1111 void assault_new_round();
1112 float() WinningCondition_Assault =
1115 status = WINNING_NO;
1117 // as the timelimit has not yet passed just assume the defending team will win
1118 if(assault_attacker_team == COLOR_TEAM1)
1120 SetWinners(team, COLOR_TEAM2);
1124 SetWinners(team, COLOR_TEAM1);
1128 ent = find(world, classname, "target_assault_roundend");
1131 if(ent.winning) // round end has been triggered by attacking team
1133 SetWinners(team, assault_attacker_team);
1134 if(assault_attacker_team == COLOR_TEAM1)
1136 team1_score = team1_score + 50;
1140 team2_score = team2_score + 50;
1143 if(ent.cnt == 1) // this was the second round
1145 status = WINNING_YES;
1149 cvar_set("timelimit", ftos((2*time)/60));
1150 assault_new_round();
1160 // LMS winning condition: game terminates if and only if there's at most one
1161 // one player who's living lives. Top two scores being equal cancels the time
1163 float() WinningCondition_LMS =
1170 have_player = FALSE;
1171 have_players = FALSE;
1172 l = LMS_NewPlayerLives();
1174 head = find(world, classname, "player");
1177 head = find(head, classname, "player");
1179 have_players = TRUE;
1183 // we have at least one player
1186 // two or more active players - continue with the game
1190 // exactly one player?
1193 // but no game has taken place yet
1198 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1199 dprint("Have a winner, ending game.\n");
1206 // nobody is playing at all...
1209 // wait for players...
1213 // SNAFU (maybe a draw game?)
1215 dprint("No players, ending game.\n");
1220 // When we get here, we have at least two players who are actually LIVING,
1221 // or one player who is still waiting for a victim to join the server. Now
1222 // check if the top two players have equal score.
1224 checkrules_leaderfrags = 0;
1225 checkrules_equality = FALSE;
1226 FOR_EACH_PLAYER(head)
1228 if(head.frags > checkrules_leaderfrags)
1230 checkrules_leaderfrags = head.frags;
1231 checkrules_equality = FALSE;
1233 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1234 checkrules_equality = TRUE;
1237 SetWinners(frags, checkrules_leaderfrags);
1239 // The top two players have the same amount of lives? No timelimit then,
1240 // enter overtime...
1242 if(checkrules_equality)
1243 return WINNING_NEVER;
1245 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1249 // DM winning condition: game terminates if a player reached the fraglimit,
1250 // unless the first two players have the same score. The latter case also
1251 // breaks the time limit.
1252 float(float fraglimit) WinningCondition_MaxIndividualScore =
1254 float checkrules_oldleaderfrags;
1257 checkrules_oldleaderfrags = checkrules_leaderfrags;
1258 checkrules_leaderfrags = 0;
1259 checkrules_equality = FALSE;
1260 FOR_EACH_PLAYER(head)
1262 if(head.frags > checkrules_leaderfrags)
1264 checkrules_leaderfrags = head.frags;
1265 checkrules_equality = FALSE;
1267 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1268 checkrules_equality = TRUE;
1271 if(checkrules_leaderfrags > 0)
1272 SetWinners(frags, checkrules_leaderfrags);
1277 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1279 if (checkrules_leaderfrags == fraglimit - 1)
1280 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1281 else if (checkrules_leaderfrags == fraglimit - 2)
1282 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1283 else if (checkrules_leaderfrags == fraglimit - 3)
1284 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1287 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1290 float(float fraglimit) WinningConditionBase_Teamplay =
1292 tdm_old_score = tdm_max_score;
1293 tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1295 checkrules_equality =
1300 (team1_score == tdm_max_score)
1301 + (team2_score == tdm_max_score)
1302 + (team3_score == tdm_max_score)
1303 + (team4_score == tdm_max_score)
1307 if(tdm_max_score > 0)
1309 if(team1_score == tdm_max_score)
1310 AddWinners(team, COLOR_TEAM1);
1311 if(team2_score == tdm_max_score)
1312 AddWinners(team, COLOR_TEAM2);
1313 if(team3_score == tdm_max_score)
1314 AddWinners(team, COLOR_TEAM3);
1315 if(team4_score == tdm_max_score)
1316 AddWinners(team, COLOR_TEAM4);
1319 if(!g_runematch && !g_domination)
1320 if(tdm_max_score != tdm_old_score)
1322 if(tdm_max_score == fraglimit - 1)
1323 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1324 else if(tdm_max_score == fraglimit - 2)
1325 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1326 else if(tdm_max_score == fraglimit - 3)
1327 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1330 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1333 // TDM winning condition: game terminates if a team's score sum reached the
1334 // fraglimit, unless the first two teams have the same total score. The latter
1335 // case also breaks the time limit.
1336 float(float fraglimit) WinningCondition_MaxTeamSum =
1340 team1_score = team2_score = team3_score = team4_score = 0;
1342 FOR_EACH_PLAYER(head)
1344 if(head.team == COLOR_TEAM1)
1345 team1_score += head.frags;
1346 else if(head.team == COLOR_TEAM2)
1347 team2_score += head.frags;
1348 else if(head.team == COLOR_TEAM3)
1349 team3_score += head.frags;
1350 else if(head.team == COLOR_TEAM4)
1351 team4_score += head.frags;
1354 return WinningConditionBase_Teamplay(fraglimit);
1357 // DOM/CTF winning condition: game terminates if the max of a team's players'
1358 // score reached the fraglimit, unless the first two teams have the same
1359 // maximum score. The latter case also breaks the time limit.
1360 float(float fraglimit) WinningCondition_MaxTeamMax =
1364 team1_score = team2_score = team3_score = team4_score = 0;
1366 FOR_EACH_PLAYER(head)
1368 if(head.team == COLOR_TEAM1)
1370 if(head.frags > team1_score)
1371 team1_score = head.frags;
1373 else if(head.team == COLOR_TEAM2)
1375 if(head.frags > team2_score)
1376 team2_score = head.frags;
1378 else if(head.team == COLOR_TEAM3)
1380 if(head.frags > team3_score)
1381 team3_score = head.frags;
1383 else if(head.team == COLOR_TEAM4)
1385 if(head.frags > team4_score)
1386 team4_score = head.frags;
1390 return WinningConditionBase_Teamplay(fraglimit);
1393 void print_to(entity e, string s)
1396 sprint(e, strcat(s, "\n"));
1398 ServerConsoleEcho(s, TRUE);
1401 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1411 FOR_EACH_PLAYER(head)
1413 if(!whichteam || head.team == whichteam)
1417 print_to(e, strcat(" ", colorcode, name, ":"));
1419 fragtotal = fragtotal + head.frags;
1420 s = ftos(head.frags);
1421 s = strcat(s, "/", ftos(head.deaths));
1422 s = strcat(s, " @ ", ftos(head.ping));
1423 if(clienttype(head) == CLIENTTYPE_BOT)
1424 s = strcat(s, "botms");
1426 s = strcat(s, "ms");
1427 v = PlayerValue(head);
1429 s = strcat(s, " / ", ftos(v));
1430 print_to(e, strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"));
1433 if(whichteam && found)
1435 s = ftos(fragtotal);
1436 s = strcat(s, " / ", ftos(teamvalue));
1437 print_to(e, strcat(colorcode, " (total: ", s, ")"));
1441 void PrintScoreboard(entity e)
1443 print_to(e, strcat("Time: ", ftos(time / 60)));
1444 print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1445 print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1446 print_to(e, "Scoreboard:");
1449 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1450 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1451 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM3);
1452 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM4);
1456 PrintScoreboardFor(e, "", "^7", 0);
1461 void ShuffleMaplist()
1469 result = cvar_string("g_maplist");
1471 litems = tokenizebyseparator(result, " ");
1473 litems = tokenize(result);
1476 for(start = 0; start < litems - 1; ++start)
1480 // select a random item
1481 selected = ceil(random() * (litems - start) + start) - 1;
1483 // shift this item to the place start
1485 for(i = 0; i < start; ++i)
1486 result = strcat(result, " ", argv(i));
1487 result = strcat(result, " ", argv(selected));
1488 for(i = start; i < litems; ++i)
1490 result = strcat(result, " ", argv(i));
1491 result = substring(result, 1, strlen(result) - 1);
1493 litems = tokenizebyseparator(result, " ");
1495 for(i = 0; i < start; ++i)
1496 result = strcat(result, "'", argv(i), "'");
1497 result = strcat(result, "'", argv(selected), "'");
1498 for(i = start; i < litems; ++i)
1500 result = strcat(result, "'", argv(i), "'");
1502 litems = tokenize(result);
1505 //dprint(result, "\n");
1508 cvar_set("g_maplist", result);
1515 Exit deathmatch games upon conditions
1518 void() CheckRules_World =
1521 local float timelimit;
1522 local float fraglimit;
1530 MapVote_Think should now do that part
1531 if (intermission_running)
1532 if (time >= intermission_exittime + 60)
1534 if(!DoNextMapOverride())
1540 if (gameover) // someone else quit the game already
1542 if(player_count == 0) // Nobody there? Then let's go to the next map
1544 // this will actually check the player count in the next frame
1545 // again, but this shouldn't hurt
1549 timelimit = cvar("timelimit") * 60;
1550 fraglimit = cvar("fraglimit");
1552 if(checkrules_overtimeend)
1554 if(!checkrules_overtimewarning)
1556 checkrules_overtimewarning = TRUE;
1557 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1558 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1563 if (timelimit && time >= timelimit)
1567 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1573 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1575 checkrules_oneminutewarning = TRUE;
1576 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1579 status = WINNING_NO;
1582 status = WinningCondition_Assault();
1586 status = WinningCondition_LMS();
1588 else if (g_onslaught)
1590 status = WinningCondition_Onslaught();
1596 if(g_tdm || g_runematch || g_ctf || g_domination || g_keyhunt)
1597 status = WinningCondition_MaxTeamSum(fraglimit);
1599 // status = WinningCondition_MaxTeamMax(fraglimit);
1602 dprint("div0: How can this happen?\n");
1603 status = WinningCondition_MaxTeamMax(fraglimit);
1607 status = WinningCondition_MaxIndividualScore(fraglimit);
1610 if(status == WINNING_STARTOVERTIME)
1612 status = WINNING_NEVER;
1616 if(status == WINNING_NEVER)
1617 // equality cases! Nobody wins if the overtime ends in a draw.
1620 if(checkrules_overtimeend)
1621 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1622 status = WINNING_YES;
1624 if(status == WINNING_YES)
1628 float randsel_value;
1629 float randsel_priority;
1630 float randsel_count;
1634 randsel_priority = -1;
1637 void RandSel_Add(float priority, float value)
1639 if(priority > randsel_priority)
1641 randsel_priority = priority;
1642 randsel_value = value;
1645 else if(priority == randsel_priority)
1648 if(ceil(random() * randsel_count) == 1)
1649 randsel_value = value;
1653 float mapvote_nextthink;
1654 float mapvote_initialized;
1655 float mapvote_keeptwotime;
1656 float mapvote_timeout;
1657 string mapvote_message;
1659 #define MAPVOTE_COUNT 10
1660 float mapvote_count;
1661 float mapvote_count_real;
1662 string mapvote_maps[MAPVOTE_COUNT];
1663 float mapvote_maps_suggested[MAPVOTE_COUNT];
1664 string mapvote_suggestions[MAPVOTE_COUNT];
1665 float mapvote_suggestion_ptr;
1666 float mapvote_maxlen;
1667 float mapvote_voters;
1668 float mapvote_votes[MAPVOTE_COUNT];
1670 float mapvote_detail;
1671 float mapvote_abstain;
1674 void MapVote_ClearAllVotes()
1676 FOR_EACH_CLIENT(other)
1680 string MapVote_Suggest(string m)
1684 return "That's not how to use this command.";
1685 if(!cvar("g_maplist_votable_suggestions"))
1686 return "Suggestions are not accepted on this server.";
1687 if(mapvote_initialized)
1688 return "Can't suggest - voting is already in progress!";
1690 m = MapInfo_FixName(m);
1692 return "The map you suggested is not available on this server.";
1694 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1695 if(!IsSameGametype(m))
1696 return "This server does not allow changing the game type by map suggestions.";
1697 if(!cvar("g_maplist_votable_override_mostrecent"))
1699 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1702 if(!MapInfo_CheckMap(m))
1703 return "The map you suggested does not support the current game mode.";
1705 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1706 return "The map you suggested is not available on this server.";
1708 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1709 if(mapvote_suggestions[i] == m)
1710 return "This map was already suggested.";
1711 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1713 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1717 i = mapvote_suggestion_ptr;
1718 mapvote_suggestion_ptr += 1;
1720 if(mapvote_suggestions[i] != "")
1721 strunzone(mapvote_suggestions[i]);
1722 mapvote_suggestions[i] = strzone(m);
1723 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid), ":", self.netname), TRUE);
1724 return strcat("Suggestion of ", m, " accepted.");
1727 void MapVote_AddVotable(string nextMap, float isSuggestion)
1732 for(j = 0; j < mapvote_count; ++j)
1733 if(mapvote_maps[j] == nextMap)
1735 if(strlen(nextMap) > mapvote_maxlen)
1736 mapvote_maxlen = strlen(nextMap);
1737 mapvote_maps[mapvote_count] = strzone(nextMap);
1738 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1747 MapVote_ClearAllVotes();
1750 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1751 mapvote_abstain = cvar("g_maplist_votable_abstain");
1754 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1756 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1757 smax = min(nmax, cvar("g_maplist_votable_suggestions"));
1759 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1760 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1762 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1763 MapVote_AddVotable(GetNextMap(), FALSE);
1765 if(mapvote_count == 0)
1767 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1769 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1770 localcmd("\nmenu_cmd sync\n");
1772 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1774 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1775 MapVote_AddVotable(GetNextMap(), FALSE);
1778 mapvote_count_real = mapvote_count;
1780 MapVote_AddVotable("/abstain", 0);
1782 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1784 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1785 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1786 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1787 mapvote_keeptwotime = 0;
1788 mapvote_message = "Choose a map and press its key!";
1790 float MapVote_Finished(float mappos)
1795 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1796 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1797 for(i = 0; i < mapvote_count_real; ++i)
1799 if(mapvote_maps[i] != "")
1801 result = strcat(result, ":", mapvote_maps[i]);
1802 result = strcat(result, ":", ftos(mapvote_votes[i]));
1804 GameLogEcho(result, FALSE);
1805 if(mapvote_maps_suggested[mappos])
1806 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
1808 FOR_EACH_REALCLIENT(other)
1809 FixClientCvars(other);
1811 Map_Goto_SetStr(mapvote_maps[mappos]);
1813 alreadychangedlevel = TRUE;
1816 void MapVote_CheckRules_1()
1820 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1822 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1823 mapvote_votes[i] = 0;
1827 FOR_EACH_REALCLIENT(other)
1832 i = other.mapvote - 1;
1833 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1834 mapvote_votes[i] = mapvote_votes[i] + 1;
1839 float MapVote_CheckRules_2()
1842 float firstPlace, secondPlace;
1843 float firstPlaceVotes, secondPlaceVotes;
1844 float mapvote_voters_real;
1847 mapvote_voters_real = mapvote_voters;
1849 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
1852 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1853 RandSel_Add(mapvote_votes[i], i);
1854 firstPlace = randsel_value;
1855 firstPlaceVotes = randsel_priority;
1856 //dprint("First place: ", ftos(firstPlace), "\n");
1857 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1860 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1862 RandSel_Add(mapvote_votes[i], i);
1863 secondPlace = randsel_value;
1864 secondPlaceVotes = randsel_priority;
1865 //dprint("Second place: ", ftos(secondPlace), "\n");
1866 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1868 if(firstPlace == -1)
1869 error("No first place in map vote... WTF?");
1871 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
1872 return MapVote_Finished(firstPlace);
1874 if(mapvote_keeptwotime)
1875 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
1877 mapvote_message = "Now decide between the TOP TWO!";
1878 mapvote_keeptwotime = 0;
1879 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
1880 result = strcat(result, ":", ftos(firstPlaceVotes));
1881 result = strcat(result, ":", mapvote_maps[secondPlace]);
1882 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
1883 for(i = 0; i < mapvote_count_real; ++i)
1885 if(i != secondPlace)
1886 if(mapvote_maps[i] != "")
1888 result = strcat(result, ":", mapvote_maps[i]);
1889 result = strcat(result, ":", ftos(mapvote_votes[i]));
1890 strunzone(mapvote_maps[i]);
1891 mapvote_maps[i] = "";
1893 GameLogEcho(result, FALSE);
1906 keeptwo = mapvote_keeptwotime;
1907 MapVote_CheckRules_1(); // count
1908 if(MapVote_CheckRules_2()) // decide
1912 FOR_EACH_REALCLIENT(other)
1914 // hide scoreboard again
1915 if(other.health != 2342)
1917 other.health = 2342;
1919 if(clienttype(other) == CLIENTTYPE_REAL)
1921 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");
1923 WriteByte(MSG_ONE, SVC_FINALE);
1924 WriteString(MSG_ONE, "");
1928 // notify about keep-two
1929 if(keeptwo != 0 && mapvote_keeptwotime == 0)
1930 play2(other, "misc/invshot.wav");
1932 // clear possibly invalid votes
1933 if(mapvote_maps[other.mapvote - 1] == "")
1935 // use impulses as new vote
1936 if(other.impulse >= 1 && other.impulse <= mapvote_count)
1937 if(mapvote_maps[other.impulse - 1] != "")
1938 other.mapvote = other.impulse;
1945 MapVote_CheckRules_1(); // just count
1947 FOR_EACH_REALCLIENT(other)
1949 // display voting screen
1950 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
1951 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
1952 msgstr = strcat(msgstr, mapvote_message);
1953 msgstr = strcat(msgstr, "\n\n");
1954 for(i = 0; i < mapvote_count; ++i)
1955 if(mapvote_maps[i] == "")
1956 msgstr = strcat(msgstr, "\n");
1959 tmp = mapvote_maps[i];
1960 if(tmp == "/abstain")
1962 tmp = strpad(mapvote_maxlen, tmp);
1963 tmp = strcat(ftos(math_mod(i + 1, 10)), ": ", tmp);
1966 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
1967 if(mapvote_votes[i] != 1)
1968 tmp = strcat(tmp, "s");
1969 tmp = strcat(tmp, ")");
1970 tmp = strpad(mapvote_maxlen + 15, tmp);
1972 if(other.mapvote == i + 1)
1973 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
1975 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
1978 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
1980 msgstr = strcat(msgstr, "s");
1981 msgstr = strcat(msgstr, " cast");
1982 i = ceil(mapvote_timeout - time);
1983 msgstr = strcat(msgstr, "\n", ftos(i), " second");
1985 msgstr = strcat(msgstr, "s");
1986 msgstr = strcat(msgstr, " left");
1988 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
1991 void MapVote_Start()
1997 MapInfo_Enumerate();
1998 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2002 void MapVote_Think()
2007 if(alreadychangedlevel)
2010 if(time < mapvote_nextthink)
2014 mapvote_nextthink = time + 0.5;
2016 if(!mapvote_initialized)
2018 mapvote_initialized = TRUE;
2019 if(DoNextMapOverride())
2021 if(!cvar("g_maplist_votable") || player_count <= 0)
2032 string GotoMap(string m)
2035 if(!MapInfo_CheckMap(m))
2037 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2039 return "The map you chose is not available on this server.";
2040 cvar_set("nextmap", m);
2041 cvar_set("timelimit", "-1");
2042 if(mapvote_initialized || alreadychangedlevel)
2044 if(DoNextMapOverride())
2045 return "Map switch initiated.";
2047 return "Hm... no. For some reason I like THIS map more.";
2050 return "Map switch will happen after scoreboard.";
2056 FOR_EACH_REALCLIENT(self)
2058 if(self.classname == "spectator")
2060 if(self.enemy.hitsound)
2061 play2(self, "misc/hit.wav");
2066 play2(self, "misc/hit.wav");
2069 FOR_EACH_CLIENT(self)
2070 self.hitsound = FALSE;
2076 * returns TRUE if redirecting
2078 float redirection_timeout;
2079 float redirection_nextthink;
2080 float RedirectionThink()
2082 float clients_found;
2084 if(redirection_target == "")
2087 if(!redirection_timeout)
2089 cvar_set("sv_public", "-2");
2090 redirection_timeout = time + 0.5; // this will only try twice... should be able to keep more clients
2091 if(redirection_target == "self")
2092 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2094 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2097 if(time < redirection_nextthink)
2100 redirection_nextthink = time + 1;
2103 FOR_EACH_REALCLIENT(self)
2105 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2106 if(redirection_target == "self")
2107 stuffcmd(self, "\ndisconnect; reconnect\n");
2109 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2113 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2115 if(time > redirection_timeout || clients_found == 0)
2116 localcmd("\nwait; wait; wait; quit\n");