1 float SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS = 1;
2 string redirection_target;
3 float world_initialized;
9 float() DoNextMapOverride;
11 void SetDefaultAlpha()
13 if(cvar("g_running_guns"))
15 default_player_alpha = -1;
16 default_weapon_alpha = +1;
20 default_player_alpha = cvar("g_balance_cloaked_alpha");
21 default_weapon_alpha = default_player_alpha;
25 default_player_alpha = cvar("g_player_alpha");
26 if(default_player_alpha <= 0)
27 default_player_alpha = 1;
28 default_weapon_alpha = default_player_alpha;
32 void fteqcc_testbugs()
36 if(!cvar("developer_fteqccbugs"))
39 dprint("*** fteqcc test: checking for bugs...\n");
43 if(sqrt(a) - sqrt(b - a) == 0)
44 dprint("*** fteqcc test: found same-function-twice bug\n");
46 dprint("*** fteqcc test: same-function-twice bug got FINALLY FIXED! HOORAY!\n");
50 world.enemy.frags += 10;
51 if(world.frags > 0.2 || world.frags < -0.2) // don't error out if it's just roundoff errors
52 dprint("*** fteqcc test: found += bug\n");
54 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
62 cvar_set("_sv_init", "0");
63 if(cvar("g_maplist_shuffle"))
66 tokenizebyseparator(cvar_string("g_maplist"), " ");
68 tokenize(cvar_string("g_maplist"));
70 if(argv(0) != GetMapname())
72 cvar_set("nextmap", argv(0));
76 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
79 if(!DoNextMapOverride())
88 float world_already_spawned;
89 void worldspawn (void)
91 dprint_load(); // load dprint status from cvar
93 if(world_already_spawned)
94 error("world already spawned - you may have EXACTLY ONE worldspawn!");
95 world_already_spawned = TRUE;
100 MapInfo_LoadMapSettings(mapname);
103 ServerProgsDB = db_load("server.db");
106 TODO sound pack system
107 // initialize sound pack system
108 soundpack = cvar_string("g_soundpack");
110 soundpack = strcat(soundpack, "/");
111 soundpack = strzone(soundpack);
117 // 1 FLICKER (first variety)
118 lightstyle(1, "mmnmmommommnonmmonqnmmo");
120 // 2 SLOW STRONG PULSE
121 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
123 // 3 CANDLE (first variety)
124 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
127 lightstyle(4, "mamamamamama");
130 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
132 // 6 FLICKER (second variety)
133 lightstyle(6, "nmonqnmomnmomomno");
135 // 7 CANDLE (second variety)
136 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
138 // 8 CANDLE (third variety)
139 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
141 // 9 SLOW STROBE (fourth variety)
142 lightstyle(9, "aaaaaaaazzzzzzzz");
144 // 10 FLUORESCENT FLICKER
145 lightstyle(10, "mmamammmmammamamaaamammma");
147 // 11 SLOW PULSE NOT FADE TO BLACK
148 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
150 // styles 32-62 are assigned by the light program for switchable lights
155 // for setting by mapinfo
156 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
157 cvar_set("sv_q3acompat_machineshotgunswap", "0");
160 lms_lowest_lives = 0;
163 bot_waypoints_for_items = cvar("g_waypoints_for_items");
164 if(bot_waypoints_for_items == 1)
165 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
166 bot_waypoints_for_items = 0;
168 if(cvar("g_campaign"))
175 WaypointSprite_Init();
181 head = nextent(world);
186 head = nextent(head);
189 GameLogInit(); // prepare everything
190 if(cvar("sv_eventlog"))
193 GameLogEcho(":logversion:2", FALSE);
194 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
195 s = strcat(s, ftos(random()));
197 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s), FALSE);
199 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
201 s = ":gameinfo:mutators:LIST";
202 if(cvar("g_grappling_hook"))
203 s = strcat(s, ":grappling_hook");
204 if(!cvar("g_use_ammunition"))
205 s = strcat(s, ":no_use_ammunition");
206 if(!cvar("g_pickup_items"))
207 s = strcat(s, ":no_pickup_items");
208 if(cvar("g_instagib"))
209 s = strcat(s, ":instagib");
210 if(cvar("g_rocketarena"))
211 s = strcat(s, ":rockerarena");
213 s = strcat(s, ":nixnex");
214 if(cvar("g_vampire"))
215 s = strcat(s, ":vampire");
216 if(cvar("g_laserguided_missile"))
217 s = strcat(s, ":laserguided_missile");
218 if(cvar("g_norecoil"))
219 s = strcat(s, ":norecoil");
221 s = strcat(s, ":midair");
222 if(cvar("g_minstagib"))
223 s = strcat(s, ":minstagib");
224 GameLogEcho(s, FALSE);
225 GameLogEcho(":gameinfo:end", FALSE);
228 cvar_set("nextmap", "");
232 if(cvar("g_campaign"))
241 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
244 world_initialized = 1;
249 //makestatic (self); // Who the f___ did that?
253 float( string pFilename ) TryFile =
256 dprint("TryFile(\"", pFilename, "\")\n");
257 lHandle = fopen( pFilename, FILE_READ );
258 if( lHandle != -1 ) {
268 if (game == GAME_DEATHMATCH)
270 else if (game == GAME_TEAM_DEATHMATCH)
272 else if (game == GAME_DOMINATION)
274 else if (game == GAME_CTF)
276 else if (game == GAME_RUNEMATCH)
278 else if (game == GAME_LMS)
280 else if (game == GAME_KEYHUNT)
282 else if (game == GAME_ONSLAUGHT)
284 else if (game == GAME_ASSAULT)
289 float IsSameGametype(string mapcfgname)
292 return TRUE; // can't change game type by map name here
296 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
302 string getmapname_stored;
308 if(getmapname_stored == "")
309 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
310 return getmapname_stored;
314 float Map_Count, Map_Current;
315 string Map_Current_Name;
317 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
318 float GetMaplistPosition()
324 idx = cvar("g_maplist_index");
331 for(pos = 0; pos < Map_Count; ++pos)
335 // resume normal maplist rotation if current map is not in g_maplist
339 float MapHasRightSize(string map)
341 // open map size restriction file
343 dprint("opensize "); dprint(map);
344 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
347 float mapmin, mapmax;
349 mapmin = stof(fgets(fh));
350 mapmax = stof(fgets(fh));
352 if(player_count < mapmin)
354 dprint("not enough\n");
357 if(player_count > mapmax)
359 dprint("too many\n");
362 dprint("right size\n");
365 dprint(": not found\n");
369 string Map_Filename(float position)
372 return strcat("maps/", argv(position), ".bsp");
374 return strcat("maps/", argv(position), ".mapcfg");
378 string strwords(string s, float w)
381 for(endpos = 0; w && endpos >= 0; --w)
382 endpos = strstrofs(s, " ", endpos + 1);
386 return substring(s, 0, endpos);
389 float strhasword(string s, string w)
391 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
394 void Map_MarkAsRecent(string m)
396 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
399 float Map_IsRecent(string m)
401 return strhasword(cvar_string("g_maplist_mostrecent"), m);
404 float(float position, float pass) Map_Check =
408 map_next = argv(position);
411 if(map_next == Map_Current_Name) // same map again in first pass?
413 if(Map_IsRecent(map_next))
416 filename = Map_Filename(position);
418 if(MapInfo_CheckMap(map_next))
420 if(TryFile(filename))
425 if(MapHasRightSize(map_next))
430 dprint( "Couldn't find '", filename, "'..\n" );
435 void(string nextmapname) Map_Goto_SetStr =
437 if(getmapname_stored != "")
438 strunzone(getmapname_stored);
439 if(nextmapname == "")
440 getmapname_stored = "";
442 getmapname_stored = strzone(nextmapname);
445 void(float position) Map_Goto_SetFloat =
447 cvar_set("g_maplist_index", ftos(position));
448 Map_Goto_SetStr(argv(position));
451 void() GameResetCfg =
454 // settings persist, except...
455 if(cvar("g_campaign"))
456 localcmd("\nexec mutator_reset.cfg\n");
457 localcmd("\nsettemp_restore\n");
459 // if an exit cfg is defined by exiting map, exec it.
461 exit_cfg = cvar_string("exit_cfg");
463 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
465 localcmd("exec game_reset.cfg\n");
471 Map_MarkAsRecent(getmapname_stored);
474 MapInfo_LoadMap(getmapname_stored);
476 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
480 // return codes of map selectors:
481 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
482 // -2 = permanent failure
483 float() MaplistMethod_Iterate = // usual method
487 for(pass = 1; pass <= 2; ++pass)
489 for(i = 1; i < Map_Count; ++i)
492 mapindex = mod(i + Map_Current, Map_Count);
493 if(Map_Check(mapindex, pass))
500 float() MaplistMethod_Repeat = // fallback method
502 if(Map_Check(Map_Current, 2))
507 float() MaplistMethod_Random = // random map selection
513 for(i = 0; i <= imax; ++i)
516 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
517 if(Map_Check(mapindex, 1))
523 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
524 // the exponent sets a bias on the map selection:
525 // the higher the exponent, the less likely "shortly repeated" same maps are
527 float i, j, imax, insertpos;
531 for(i = 0; i <= imax; ++i)
535 // now reinsert this at another position
536 insertpos = pow(random(), 1 / exponent); // ]0, 1]
537 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
538 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
539 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
541 // insert the current map there
544 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
545 newlist = strcat(newlist, " ", argv(j));
546 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
547 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
548 newlist = strcat(newlist, " ", argv(j));
549 newlist = substring(newlist, 1, strlen(newlist) - 1);
551 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
552 newlist = strcat(newlist, "'", argv(j), "'");
553 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
554 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
555 newlist = strcat(newlist, "'", argv(j), "'");
557 cvar_set("g_maplist", newlist);
559 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
561 Map_Count = tokenize(newlist);
564 // NOTE: the selected map has just been inserted at (insertpos-1)th position
565 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
566 if(Map_Check(Map_Current, 1))
572 void() Maplist_Init =
575 temp = cvar_string("g_maplist");
577 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
579 Map_Count = tokenize(temp);
583 bprint( "Maplist is empty! Resetting it to default map list.\n" );
585 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
586 localcmd("\nmenu_cmd sync\n");
587 Map_Count = tokenizebyseparator(temp, " ");
589 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
590 Map_Count = tokenize(temp);
594 error("empty maplist, cannot select a new map");
595 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
597 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
598 // this may or may not be correct, but who cares, in the worst case a map
599 // isn't chosen in the first pass that should have been
602 string() GetNextMap =
610 if(cvar("g_maplist_shuffle") > 0)
611 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
614 if(cvar("g_maplist_selectrandom"))
615 nextMap = MaplistMethod_Random();
618 nextMap = MaplistMethod_Iterate();
621 nextMap = MaplistMethod_Repeat();
625 Map_Goto_SetFloat(nextMap);
626 return getmapname_stored;
632 float() DoNextMapOverride =
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
933 intermission_running = 1;
935 // enforce a wait time before allowing changelevel
937 intermission_exittime = time + cvar("sv_mapchange_delay");
939 intermission_exittime = -1;
941 WriteByte (MSG_ALL, SVC_CDTRACK);
942 WriteByte (MSG_ALL, 3);
943 WriteByte (MSG_ALL, 3);
945 //pos = FindIntermission ();
951 if(cvar("sv_eventlog"))
952 GameLogEcho(":gameover", FALSE);
956 FOR_EACH_CLIENT(other)
958 FixIntermissionClient(other);
961 bprint(other.netname, " ^7wins.\n");
966 FOR_EACH_PLAYER(other)
968 if(maxTotalFrags < other.totalfrags)
969 maxTotalFrags = other.totalfrags;
970 if(minTotalFrags > other.totalfrags)
971 minTotalFrags = other.totalfrags;
976 FOR_EACH_PLAYER(other)
978 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
979 f = bound(0, other.play_time / max(time, 1), 1);
980 // store some statistics?
984 if(cvar("g_campaign"))
985 CampaignPreIntermission();
987 // WriteByte (MSG_ALL, SVC_INTERMISSION);
994 Exit deathmatch games upon conditions
997 void() CheckRules_Player =
999 if (gameover) // someone else quit the game already
1002 if(self.deadflag == DEAD_NO)
1003 self.play_time += frametime;
1005 // fixme: don't check players; instead check dom_team and ctf_team entities
1006 // (div0: and that in CheckRules_World please)
1009 float checkrules_oneminutewarning;
1010 float checkrules_leaderfrags;
1011 float tdm_max_score, tdm_old_score;
1013 float checkrules_equality;
1014 float checkrules_overtimewarning;
1015 float checkrules_overtimeend;
1017 void() InitiateOvertime =
1019 if(!checkrules_overtimeend)
1020 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1023 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1024 float WINNING_YES = 1; // winner found
1025 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1026 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1028 float(float fraglimitreached, float equality) GetWinningCode =
1031 if(fraglimitreached)
1032 return WINNING_STARTOVERTIME;
1034 return WINNING_NEVER;
1036 if(fraglimitreached)
1042 // set the .winning flag for exactly those players with a given field value
1043 void(.float field, float value) SetWinners =
1046 FOR_EACH_PLAYER(head)
1047 head.winning = (head.field == value);
1050 // set the .winning flag for those players with a given field value
1051 void(.float field, float value) AddWinners =
1054 FOR_EACH_PLAYER(head)
1055 if(head.field == value)
1059 // clear frags for all players but the team given (when they ran out of spawnpoints)
1060 void(.float field, float value) ClearFragsForEveryoneBut =
1063 FOR_EACH_PLAYER(head)
1064 if(head.field != value)
1065 head.frags = max(head.frags, 0);
1068 // clear the .winning flags
1069 void(void) ClearWinners =
1072 FOR_EACH_PLAYER(head)
1076 // Onslaught winning condition:
1077 // game terminates if only one team has a working generator (or none)
1078 float() WinningCondition_Onslaught =
1081 local float t1, t2, t3, t4;
1082 // first check if the game has ended
1083 t1 = t2 = t3 = t4 = 0;
1084 head = find(world, classname, "onslaught_generator");
1087 if (head.health > 0)
1089 if (head.team == COLOR_TEAM1) t1 = 1;
1090 if (head.team == COLOR_TEAM2) t2 = 1;
1091 if (head.team == COLOR_TEAM3) t3 = 1;
1092 if (head.team == COLOR_TEAM4) t4 = 1;
1094 head = find(head, classname, "onslaught_generator");
1096 if (t1 + t2 + t3 + t4 < 2)
1098 // game over, only one team remains (or none)
1100 if (t1) SetWinners(team, COLOR_TEAM1);
1101 if (t2) SetWinners(team, COLOR_TEAM2);
1102 if (t3) SetWinners(team, COLOR_TEAM3);
1103 if (t4) SetWinners(team, COLOR_TEAM4);
1104 dprint("Have a winner, ending game.\n");
1108 // Two or more teams remain
1112 float() LMS_NewPlayerLives =
1115 fl = cvar("fraglimit");
1119 // first player has left the game for dying too much? Nobody else can get in.
1120 if(lms_lowest_lives < 1)
1123 if(!cvar("g_lms_join_anytime"))
1124 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1127 return bound(1, lms_lowest_lives, fl);
1130 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1131 // they win. Otherwise the defending team wins once the timelimit passes.
1132 void assault_new_round();
1133 float() WinningCondition_Assault =
1136 status = WINNING_NO;
1138 // as the timelimit has not yet passed just assume the defending team will win
1139 if(assault_attacker_team == COLOR_TEAM1)
1141 SetWinners(team, COLOR_TEAM2);
1145 SetWinners(team, COLOR_TEAM1);
1149 ent = find(world, classname, "target_assault_roundend");
1152 if(ent.winning) // round end has been triggered by attacking team
1154 SetWinners(team, assault_attacker_team);
1155 if(assault_attacker_team == COLOR_TEAM1)
1157 team1_score = team1_score + 50;
1161 team2_score = team2_score + 50;
1164 if(ent.cnt == 1) // this was the second round
1166 status = WINNING_YES;
1170 cvar_set("timelimit", ftos((2*time)/60));
1171 assault_new_round();
1181 // LMS winning condition: game terminates if and only if there's at most one
1182 // one player who's living lives. Top two scores being equal cancels the time
1184 float() WinningCondition_LMS =
1191 have_player = FALSE;
1192 have_players = FALSE;
1193 l = LMS_NewPlayerLives();
1195 head = find(world, classname, "player");
1198 head = find(head, classname, "player");
1200 have_players = TRUE;
1204 // we have at least one player
1207 // two or more active players - continue with the game
1211 // exactly one player?
1214 // but no game has taken place yet
1219 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1220 dprint("Have a winner, ending game.\n");
1227 // nobody is playing at all...
1230 // wait for players...
1234 // SNAFU (maybe a draw game?)
1236 dprint("No players, ending game.\n");
1241 // When we get here, we have at least two players who are actually LIVING,
1242 // or one player who is still waiting for a victim to join the server. Now
1243 // check if the top two players have equal score.
1245 checkrules_leaderfrags = 0;
1246 checkrules_equality = FALSE;
1247 FOR_EACH_PLAYER(head)
1249 if(head.frags > checkrules_leaderfrags)
1251 checkrules_leaderfrags = head.frags;
1252 checkrules_equality = FALSE;
1254 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1255 checkrules_equality = TRUE;
1258 SetWinners(frags, checkrules_leaderfrags);
1260 // The top two players have the same amount of lives? No timelimit then,
1261 // enter overtime...
1263 if(checkrules_equality)
1264 return WINNING_NEVER;
1266 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1270 // DM winning condition: game terminates if a player reached the fraglimit,
1271 // unless the first two players have the same score. The latter case also
1272 // breaks the time limit.
1273 float(float fraglimit) WinningCondition_MaxIndividualScore =
1275 float checkrules_oldleaderfrags;
1278 checkrules_oldleaderfrags = checkrules_leaderfrags;
1279 checkrules_leaderfrags = 0;
1280 checkrules_equality = FALSE;
1281 FOR_EACH_PLAYER(head)
1283 if(head.frags > checkrules_leaderfrags)
1285 checkrules_leaderfrags = head.frags;
1286 checkrules_equality = FALSE;
1288 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1289 checkrules_equality = TRUE;
1292 if(checkrules_leaderfrags > 0)
1293 SetWinners(frags, checkrules_leaderfrags);
1298 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1300 if (checkrules_leaderfrags == fraglimit - 1)
1301 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1302 else if (checkrules_leaderfrags == fraglimit - 2)
1303 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1304 else if (checkrules_leaderfrags == fraglimit - 3)
1305 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1308 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1311 float(float fraglimit) WinningConditionBase_Teamplay =
1313 tdm_old_score = tdm_max_score;
1314 tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1316 checkrules_equality =
1321 (team1_score == tdm_max_score)
1322 + (team2_score == tdm_max_score)
1323 + (team3_score == tdm_max_score)
1324 + (team4_score == tdm_max_score)
1328 if(tdm_max_score > 0)
1330 if(team1_score == tdm_max_score)
1331 AddWinners(team, COLOR_TEAM1);
1332 if(team2_score == tdm_max_score)
1333 AddWinners(team, COLOR_TEAM2);
1334 if(team3_score == tdm_max_score)
1335 AddWinners(team, COLOR_TEAM3);
1336 if(team4_score == tdm_max_score)
1337 AddWinners(team, COLOR_TEAM4);
1340 if(!g_runematch && !g_domination)
1341 if(tdm_max_score != tdm_old_score)
1343 if(tdm_max_score == fraglimit - 1)
1344 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1345 else if(tdm_max_score == fraglimit - 2)
1346 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1347 else if(tdm_max_score == fraglimit - 3)
1348 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1351 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1354 // TDM winning condition: game terminates if a team's score sum reached the
1355 // fraglimit, unless the first two teams have the same total score. The latter
1356 // case also breaks the time limit.
1357 float(float fraglimit) WinningCondition_MaxTeamSum =
1361 team1_score = team2_score = team3_score = team4_score = 0;
1363 FOR_EACH_PLAYER(head)
1365 if(head.team == COLOR_TEAM1)
1366 team1_score += head.frags;
1367 else if(head.team == COLOR_TEAM2)
1368 team2_score += head.frags;
1369 else if(head.team == COLOR_TEAM3)
1370 team3_score += head.frags;
1371 else if(head.team == COLOR_TEAM4)
1372 team4_score += head.frags;
1375 return WinningConditionBase_Teamplay(fraglimit);
1378 // DOM/CTF winning condition: game terminates if the max of a team's players'
1379 // score reached the fraglimit, unless the first two teams have the same
1380 // maximum score. The latter case also breaks the time limit.
1381 float(float fraglimit) WinningCondition_MaxTeamMax =
1385 team1_score = team2_score = team3_score = team4_score = 0;
1387 FOR_EACH_PLAYER(head)
1389 if(head.team == COLOR_TEAM1)
1391 if(head.frags > team1_score)
1392 team1_score = head.frags;
1394 else if(head.team == COLOR_TEAM2)
1396 if(head.frags > team2_score)
1397 team2_score = head.frags;
1399 else if(head.team == COLOR_TEAM3)
1401 if(head.frags > team3_score)
1402 team3_score = head.frags;
1404 else if(head.team == COLOR_TEAM4)
1406 if(head.frags > team4_score)
1407 team4_score = head.frags;
1411 return WinningConditionBase_Teamplay(fraglimit);
1414 void print_to(entity e, string s)
1417 sprint(e, strcat(s, "\n"));
1419 ServerConsoleEcho(s, TRUE);
1422 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1432 FOR_EACH_PLAYER(head)
1434 if(!whichteam || head.team == whichteam)
1438 print_to(e, strcat(" ", colorcode, name, ":"));
1440 fragtotal = fragtotal + head.frags;
1441 s = ftos(head.frags);
1442 s = strcat(s, "/", ftos(head.deaths));
1443 s = strcat(s, " @ ", ftos(head.ping));
1444 if(clienttype(head) == CLIENTTYPE_BOT)
1445 s = strcat(s, "botms");
1447 s = strcat(s, "ms");
1448 v = PlayerValue(head);
1450 s = strcat(s, " / ", ftos(v));
1451 print_to(e, strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"));
1454 if(whichteam && found)
1456 s = ftos(fragtotal);
1457 s = strcat(s, " / ", ftos(teamvalue));
1458 print_to(e, strcat(colorcode, " (total: ", s, ")"));
1462 void PrintScoreboard(entity e)
1464 print_to(e, strcat("Time: ", ftos(time / 60)));
1465 print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1466 print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1467 print_to(e, "Scoreboard:");
1470 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1471 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1472 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM3);
1473 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM4);
1477 PrintScoreboardFor(e, "", "^7", 0);
1482 void ShuffleMaplist()
1490 result = cvar_string("g_maplist");
1492 litems = tokenizebyseparator(result, " ");
1494 litems = tokenize(result);
1497 for(start = 0; start < litems - 1; ++start)
1501 // select a random item
1502 selected = ceil(random() * (litems - start) + start) - 1;
1504 // shift this item to the place start
1506 for(i = 0; i < start; ++i)
1507 result = strcat(result, " ", argv(i));
1508 result = strcat(result, " ", argv(selected));
1509 for(i = start; i < litems; ++i)
1511 result = strcat(result, " ", argv(i));
1512 result = substring(result, 1, strlen(result) - 1);
1514 litems = tokenizebyseparator(result, " ");
1516 for(i = 0; i < start; ++i)
1517 result = strcat(result, "'", argv(i), "'");
1518 result = strcat(result, "'", argv(selected), "'");
1519 for(i = start; i < litems; ++i)
1521 result = strcat(result, "'", argv(i), "'");
1523 litems = tokenize(result);
1526 //dprint(result, "\n");
1529 cvar_set("g_maplist", result);
1532 float WinningCondition_RanOutOfSpawns()
1539 team1_score = team2_score = team3_score = team4_score = 0;
1541 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1543 if(head.team == COLOR_TEAM1)
1545 else if(head.team == COLOR_TEAM2)
1547 else if(head.team == COLOR_TEAM3)
1549 else if(head.team == COLOR_TEAM4)
1553 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1555 if(head.team == COLOR_TEAM1)
1557 else if(head.team == COLOR_TEAM2)
1559 else if(head.team == COLOR_TEAM3)
1561 else if(head.team == COLOR_TEAM4)
1566 if(team1_score + team2_score + team3_score + team4_score == 0)
1568 checkrules_equality = TRUE;
1571 else if(team1_score + team2_score + team3_score + team4_score == 1)
1575 AddWinners(team, COLOR_TEAM1);
1576 ClearFragsForEveryoneBut(team, COLOR_TEAM1);
1580 AddWinners(team, COLOR_TEAM2);
1581 ClearFragsForEveryoneBut(team, COLOR_TEAM1);
1585 AddWinners(team, COLOR_TEAM3);
1586 ClearFragsForEveryoneBut(team, COLOR_TEAM1);
1590 AddWinners(team, COLOR_TEAM4);
1591 ClearFragsForEveryoneBut(team, COLOR_TEAM1);
1603 Exit deathmatch games upon conditions
1606 void() CheckRules_World =
1609 local float timelimit;
1610 local float fraglimit;
1618 MapVote_Think should now do that part
1619 if (intermission_running)
1620 if (time >= intermission_exittime + 60)
1622 if(!DoNextMapOverride())
1628 if (gameover) // someone else quit the game already
1630 if(player_count == 0) // Nobody there? Then let's go to the next map
1632 // this will actually check the player count in the next frame
1633 // again, but this shouldn't hurt
1637 timelimit = cvar("timelimit") * 60;
1638 fraglimit = cvar("fraglimit");
1640 if(checkrules_overtimeend)
1642 if(!checkrules_overtimewarning)
1644 checkrules_overtimewarning = TRUE;
1645 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1646 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1651 if (timelimit && time >= timelimit)
1655 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1661 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1663 checkrules_oneminutewarning = TRUE;
1664 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1667 status = WinningCondition_RanOutOfSpawns();
1668 if(status == WINNING_YES)
1670 bprint("Hey! Someone ran out of spawns!\n");
1674 status = WinningCondition_Assault();
1678 status = WinningCondition_LMS();
1680 else if (g_onslaught)
1682 status = WinningCondition_Onslaught();
1688 if(g_tdm || g_runematch || g_ctf || g_domination || g_keyhunt)
1689 status = WinningCondition_MaxTeamSum(fraglimit);
1691 // status = WinningCondition_MaxTeamMax(fraglimit);
1694 dprint("div0: How can this happen?\n");
1695 status = WinningCondition_MaxTeamMax(fraglimit);
1699 status = WinningCondition_MaxIndividualScore(fraglimit);
1702 if(status == WINNING_STARTOVERTIME)
1704 status = WINNING_NEVER;
1708 if(status == WINNING_NEVER)
1709 // equality cases! Nobody wins if the overtime ends in a draw.
1712 if(checkrules_overtimeend)
1713 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1714 status = WINNING_YES;
1716 if(status == WINNING_YES)
1720 float randsel_value;
1721 float randsel_priority;
1722 float randsel_count;
1726 randsel_priority = -1;
1729 void RandSel_Add(float priority, float value)
1731 if(priority > randsel_priority)
1733 randsel_priority = priority;
1734 randsel_value = value;
1737 else if(priority == randsel_priority)
1740 if(ceil(random() * randsel_count) == 1)
1741 randsel_value = value;
1745 float mapvote_nextthink;
1746 float mapvote_initialized;
1747 float mapvote_keeptwotime;
1748 float mapvote_timeout;
1749 string mapvote_message;
1751 #define MAPVOTE_COUNT 10
1752 float mapvote_count;
1753 float mapvote_count_real;
1754 string mapvote_maps[MAPVOTE_COUNT];
1755 float mapvote_maps_suggested[MAPVOTE_COUNT];
1756 string mapvote_suggestions[MAPVOTE_COUNT];
1757 float mapvote_suggestion_ptr;
1758 float mapvote_maxlen;
1759 float mapvote_voters;
1760 float mapvote_votes[MAPVOTE_COUNT];
1762 float mapvote_detail;
1763 float mapvote_abstain;
1766 void MapVote_ClearAllVotes()
1768 FOR_EACH_CLIENT(other)
1772 string MapVote_Suggest(string m)
1776 return "That's not how to use this command.";
1777 if(!cvar("g_maplist_votable_suggestions"))
1778 return "Suggestions are not accepted on this server.";
1779 if(mapvote_initialized)
1780 return "Can't suggest - voting is already in progress!";
1782 m = MapInfo_FixName(m);
1784 return "The map you suggested is not available on this server.";
1786 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1787 if(!IsSameGametype(m))
1788 return "This server does not allow changing the game type by map suggestions.";
1789 if(!cvar("g_maplist_votable_override_mostrecent"))
1791 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1794 if(!MapInfo_CheckMap(m))
1795 return "The map you suggested does not support the current game mode.";
1797 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1798 return "The map you suggested is not available on this server.";
1800 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1801 if(mapvote_suggestions[i] == m)
1802 return "This map was already suggested.";
1803 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1805 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1809 i = mapvote_suggestion_ptr;
1810 mapvote_suggestion_ptr += 1;
1812 if(mapvote_suggestions[i] != "")
1813 strunzone(mapvote_suggestions[i]);
1814 mapvote_suggestions[i] = strzone(m);
1815 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid), ":", self.netname), TRUE);
1816 return strcat("Suggestion of ", m, " accepted.");
1819 void MapVote_AddVotable(string nextMap, float isSuggestion)
1824 for(j = 0; j < mapvote_count; ++j)
1825 if(mapvote_maps[j] == nextMap)
1827 if(strlen(nextMap) > mapvote_maxlen)
1828 mapvote_maxlen = strlen(nextMap);
1829 mapvote_maps[mapvote_count] = strzone(nextMap);
1830 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1839 MapVote_ClearAllVotes();
1842 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1843 mapvote_abstain = cvar("g_maplist_votable_abstain");
1846 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1848 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1849 smax = min(nmax, cvar("g_maplist_votable_suggestions"));
1851 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1852 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1854 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1855 MapVote_AddVotable(GetNextMap(), FALSE);
1857 if(mapvote_count == 0)
1859 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1861 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1862 localcmd("\nmenu_cmd sync\n");
1864 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1866 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1867 MapVote_AddVotable(GetNextMap(), FALSE);
1870 mapvote_count_real = mapvote_count;
1872 MapVote_AddVotable("don't care", 0);
1874 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1876 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1877 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1878 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1879 mapvote_keeptwotime = 0;
1880 mapvote_message = "Choose a map and press its key!";
1882 float MapVote_Finished(float mappos)
1888 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1889 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1890 didntvote = mapvote_voters;
1891 for(i = 0; i < mapvote_count; ++i)
1892 if(mapvote_maps[i] != "")
1894 didntvote -= mapvote_votes[i];
1897 result = strcat(result, ":", mapvote_maps[i]);
1898 result = strcat(result, ":", ftos(mapvote_votes[i]));
1901 result = strcat(result, ":didn't vote:", ftos(didntvote));
1903 GameLogEcho(result, FALSE);
1904 if(mapvote_maps_suggested[mappos])
1905 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
1907 FOR_EACH_REALCLIENT(other)
1908 FixClientCvars(other);
1910 Map_Goto_SetStr(mapvote_maps[mappos]);
1912 alreadychangedlevel = TRUE;
1915 void MapVote_CheckRules_1()
1919 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1921 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1922 mapvote_votes[i] = 0;
1926 FOR_EACH_REALCLIENT(other)
1931 i = other.mapvote - 1;
1932 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1933 mapvote_votes[i] = mapvote_votes[i] + 1;
1938 float MapVote_CheckRules_2()
1941 float firstPlace, secondPlace;
1942 float firstPlaceVotes, secondPlaceVotes;
1943 float mapvote_voters_real;
1946 mapvote_voters_real = mapvote_voters;
1948 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
1951 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1952 RandSel_Add(mapvote_votes[i], i);
1953 firstPlace = randsel_value;
1954 firstPlaceVotes = randsel_priority;
1955 //dprint("First place: ", ftos(firstPlace), "\n");
1956 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1959 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1961 RandSel_Add(mapvote_votes[i], i);
1962 secondPlace = randsel_value;
1963 secondPlaceVotes = randsel_priority;
1964 //dprint("Second place: ", ftos(secondPlace), "\n");
1965 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1967 if(firstPlace == -1)
1968 error("No first place in map vote... WTF?");
1970 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
1971 return MapVote_Finished(firstPlace);
1973 if(mapvote_keeptwotime)
1974 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
1977 mapvote_message = "Now decide between the TOP TWO!";
1978 mapvote_keeptwotime = 0;
1979 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
1980 result = strcat(result, ":", ftos(firstPlaceVotes));
1981 result = strcat(result, ":", mapvote_maps[secondPlace]);
1982 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
1983 didntvote = mapvote_voters;
1984 for(i = 0; i < mapvote_count; ++i)
1985 if(mapvote_maps[i] != "")
1987 didntvote -= mapvote_votes[i];
1989 if(i != secondPlace)
1991 result = strcat(result, ":", mapvote_maps[i]);
1992 result = strcat(result, ":", ftos(mapvote_votes[i]));
1993 if(i < mapvote_count_real)
1995 strunzone(mapvote_maps[i]);
1996 mapvote_maps[i] = "";
2000 result = strcat(result, ":didn't vote:", ftos(didntvote));
2001 GameLogEcho(result, FALSE);
2014 keeptwo = mapvote_keeptwotime;
2015 MapVote_CheckRules_1(); // count
2016 if(MapVote_CheckRules_2()) // decide
2020 FOR_EACH_REALCLIENT(other)
2022 // hide scoreboard again
2023 if(other.health != 2342)
2025 other.health = 2342;
2027 if(clienttype(other) == CLIENTTYPE_REAL)
2029 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");
2031 WriteByte(MSG_ONE, SVC_FINALE);
2032 WriteString(MSG_ONE, "");
2036 // notify about keep-two
2037 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2038 play2(other, "misc/invshot.wav");
2040 // clear possibly invalid votes
2041 if(mapvote_maps[other.mapvote - 1] == "")
2043 // use impulses as new vote
2044 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2045 if(mapvote_maps[other.impulse - 1] != "")
2046 other.mapvote = other.impulse;
2053 MapVote_CheckRules_1(); // just count
2055 FOR_EACH_REALCLIENT(other)
2057 // display voting screen
2058 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2059 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2061 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2062 msgstr = strcat(msgstr, mapvote_message);
2063 msgstr = strcat(msgstr, "\n\n");
2064 for(i = 0; i < mapvote_count; ++i)
2065 if(mapvote_maps[i] == "")
2066 msgstr = strcat(msgstr, "\n");
2069 tmp = mapvote_maps[i];
2070 tmp = strpad(mapvote_maxlen, tmp);
2071 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2074 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2075 if(mapvote_votes[i] != 1)
2076 tmp = strcat(tmp, "s");
2077 tmp = strcat(tmp, ")");
2078 tmp = strpad(mapvote_maxlen + 15, tmp);
2081 if(i == mapvote_count - 1)
2082 msgstr = strcat(msgstr, "\n");
2083 if(other.mapvote == i + 1)
2084 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2086 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2089 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2091 msgstr = strcat(msgstr, "s");
2092 msgstr = strcat(msgstr, " cast");
2093 i = ceil(mapvote_timeout - time);
2094 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2096 msgstr = strcat(msgstr, "s");
2097 msgstr = strcat(msgstr, " left");
2099 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2102 void MapVote_Start()
2108 MapInfo_Enumerate();
2109 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2113 void MapVote_Think()
2118 if(alreadychangedlevel)
2121 if(time < mapvote_nextthink)
2125 mapvote_nextthink = time + 0.5;
2127 if(!mapvote_initialized)
2129 mapvote_initialized = TRUE;
2130 if(DoNextMapOverride())
2132 if(!cvar("g_maplist_votable") || player_count <= 0)
2143 string GotoMap(string m)
2146 if(!MapInfo_CheckMap(m))
2148 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2150 return "The map you chose is not available on this server.";
2151 cvar_set("nextmap", m);
2152 cvar_set("timelimit", "-1");
2153 if(mapvote_initialized || alreadychangedlevel)
2155 if(DoNextMapOverride())
2156 return "Map switch initiated.";
2158 return "Hm... no. For some reason I like THIS map more.";
2161 return "Map switch will happen after scoreboard.";
2167 FOR_EACH_REALCLIENT(self)
2169 if(self.classname == "spectator")
2171 if(self.enemy.hitsound)
2172 play2(self, "misc/hit.wav");
2177 play2(self, "misc/hit.wav");
2180 FOR_EACH_CLIENT(self)
2181 self.hitsound = FALSE;
2187 * returns TRUE if redirecting
2189 float redirection_timeout;
2190 float redirection_nextthink;
2191 float RedirectionThink()
2193 float clients_found;
2195 if(redirection_target == "")
2198 if(!redirection_timeout)
2200 cvar_set("sv_public", "-2");
2201 redirection_timeout = time + 0.5; // this will only try twice... should be able to keep more clients
2202 if(redirection_target == "self")
2203 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2205 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2208 if(time < redirection_nextthink)
2211 redirection_nextthink = time + 1;
2214 FOR_EACH_REALCLIENT(self)
2216 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2217 if(redirection_target == "self")
2218 stuffcmd(self, "\ndisconnect; reconnect\n");
2220 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2224 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2226 if(time > redirection_timeout || clients_found == 0)
2227 localcmd("\nwait; wait; wait; quit\n");
2234 if(world_initialized)
2236 world_initialized = 0;
2237 print("Saving persistent data...\n");
2239 db_save(ServerProgsDB, "server.db");
2244 print("NOTE: crashed before even initializing the world, not saving persistent data\n");