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);
104 ServerProgsDB = db_create();
106 ServerProgsDB = db_load("server.db");
109 TODO sound pack system
110 // initialize sound pack system
111 soundpack = cvar_string("g_soundpack");
113 soundpack = strcat(soundpack, "/");
114 soundpack = strzone(soundpack);
120 // 1 FLICKER (first variety)
121 lightstyle(1, "mmnmmommommnonmmonqnmmo");
123 // 2 SLOW STRONG PULSE
124 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
126 // 3 CANDLE (first variety)
127 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
130 lightstyle(4, "mamamamamama");
133 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
135 // 6 FLICKER (second variety)
136 lightstyle(6, "nmonqnmomnmomomno");
138 // 7 CANDLE (second variety)
139 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
141 // 8 CANDLE (third variety)
142 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
144 // 9 SLOW STROBE (fourth variety)
145 lightstyle(9, "aaaaaaaazzzzzzzz");
147 // 10 FLUORESCENT FLICKER
148 lightstyle(10, "mmamammmmammamamaaamammma");
150 // 11 SLOW PULSE NOT FADE TO BLACK
151 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
153 // styles 32-62 are assigned by the light program for switchable lights
158 // for setting by mapinfo
159 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
160 cvar_set("sv_q3acompat_machineshotgunswap", "0");
163 lms_lowest_lives = 0;
166 bot_waypoints_for_items = cvar("g_waypoints_for_items");
167 if(bot_waypoints_for_items == 1)
168 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
169 bot_waypoints_for_items = 0;
171 if(cvar("g_campaign"))
178 WaypointSprite_Init();
184 head = nextent(world);
189 head = nextent(head);
192 GameLogInit(); // prepare everything
193 if(cvar("sv_eventlog"))
196 GameLogEcho(":logversion:2", FALSE);
197 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
198 s = strcat(s, ftos(random()));
200 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s), FALSE);
202 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
204 s = ":gameinfo:mutators:LIST";
205 if(cvar("g_grappling_hook"))
206 s = strcat(s, ":grappling_hook");
207 if(!cvar("g_use_ammunition"))
208 s = strcat(s, ":no_use_ammunition");
209 if(!cvar("g_pickup_items"))
210 s = strcat(s, ":no_pickup_items");
211 if(cvar("g_instagib"))
212 s = strcat(s, ":instagib");
213 if(cvar("g_rocketarena"))
214 s = strcat(s, ":rockerarena");
216 s = strcat(s, ":nixnex");
217 if(cvar("g_vampire"))
218 s = strcat(s, ":vampire");
219 if(cvar("g_laserguided_missile"))
220 s = strcat(s, ":laserguided_missile");
221 if(cvar("g_norecoil"))
222 s = strcat(s, ":norecoil");
224 s = strcat(s, ":midair");
225 if(cvar("g_minstagib"))
226 s = strcat(s, ":minstagib");
227 GameLogEcho(s, FALSE);
228 GameLogEcho(":gameinfo:end", FALSE);
231 cvar_set("nextmap", "");
235 if(cvar("g_campaign"))
244 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
247 world_initialized = 1;
252 //makestatic (self); // Who the f___ did that?
256 float( string pFilename ) TryFile =
259 dprint("TryFile(\"", pFilename, "\")\n");
260 lHandle = fopen( pFilename, FILE_READ );
261 if( lHandle != -1 ) {
271 if (game == GAME_DEATHMATCH)
273 else if (game == GAME_TEAM_DEATHMATCH)
275 else if (game == GAME_DOMINATION)
277 else if (game == GAME_CTF)
279 else if (game == GAME_RUNEMATCH)
281 else if (game == GAME_LMS)
283 else if (game == GAME_KEYHUNT)
285 else if (game == GAME_ONSLAUGHT)
287 else if (game == GAME_ASSAULT)
292 float IsSameGametype(string mapcfgname)
295 return TRUE; // can't change game type by map name here
299 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
305 string getmapname_stored;
311 if(getmapname_stored == "")
312 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
313 return getmapname_stored;
317 float Map_Count, Map_Current;
318 string Map_Current_Name;
320 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
321 float GetMaplistPosition()
327 idx = cvar("g_maplist_index");
334 for(pos = 0; pos < Map_Count; ++pos)
338 // resume normal maplist rotation if current map is not in g_maplist
342 float MapHasRightSize(string map)
344 // open map size restriction file
346 dprint("opensize "); dprint(map);
347 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
350 float mapmin, mapmax;
352 mapmin = stof(fgets(fh));
353 mapmax = stof(fgets(fh));
355 if(player_count < mapmin)
357 dprint("not enough\n");
360 if(player_count > mapmax)
362 dprint("too many\n");
365 dprint("right size\n");
368 dprint(": not found\n");
372 string Map_Filename(float position)
375 return strcat("maps/", argv(position), ".bsp");
377 return strcat("maps/", argv(position), ".mapcfg");
381 string strwords(string s, float w)
384 for(endpos = 0; w && endpos >= 0; --w)
385 endpos = strstrofs(s, " ", endpos + 1);
389 return substring(s, 0, endpos);
392 float strhasword(string s, string w)
394 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
397 void Map_MarkAsRecent(string m)
399 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
402 float Map_IsRecent(string m)
404 return strhasword(cvar_string("g_maplist_mostrecent"), m);
407 float(float position, float pass) Map_Check =
411 map_next = argv(position);
414 if(map_next == Map_Current_Name) // same map again in first pass?
416 if(Map_IsRecent(map_next))
419 filename = Map_Filename(position);
421 if(MapInfo_CheckMap(map_next))
423 if(TryFile(filename))
428 if(MapHasRightSize(map_next))
433 dprint( "Couldn't find '", filename, "'..\n" );
438 void(string nextmapname) Map_Goto_SetStr =
440 if(getmapname_stored != "")
441 strunzone(getmapname_stored);
442 if(nextmapname == "")
443 getmapname_stored = "";
445 getmapname_stored = strzone(nextmapname);
448 void(float position) Map_Goto_SetFloat =
450 cvar_set("g_maplist_index", ftos(position));
451 Map_Goto_SetStr(argv(position));
454 void() GameResetCfg =
457 // settings persist, except...
458 if(cvar("g_campaign"))
459 localcmd("\nexec mutator_reset.cfg\n");
460 localcmd("\nsettemp_restore\n");
462 // if an exit cfg is defined by exiting map, exec it.
464 exit_cfg = cvar_string("exit_cfg");
466 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
468 localcmd("exec game_reset.cfg\n");
474 Map_MarkAsRecent(getmapname_stored);
477 MapInfo_LoadMap(getmapname_stored);
479 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
483 // return codes of map selectors:
484 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
485 // -2 = permanent failure
486 float() MaplistMethod_Iterate = // usual method
490 for(pass = 1; pass <= 2; ++pass)
492 for(i = 1; i < Map_Count; ++i)
495 mapindex = mod(i + Map_Current, Map_Count);
496 if(Map_Check(mapindex, pass))
503 float() MaplistMethod_Repeat = // fallback method
505 if(Map_Check(Map_Current, 2))
510 float() MaplistMethod_Random = // random map selection
516 for(i = 0; i <= imax; ++i)
519 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
520 if(Map_Check(mapindex, 1))
526 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
527 // the exponent sets a bias on the map selection:
528 // the higher the exponent, the less likely "shortly repeated" same maps are
530 float i, j, imax, insertpos;
534 for(i = 0; i <= imax; ++i)
538 // now reinsert this at another position
539 insertpos = pow(random(), 1 / exponent); // ]0, 1]
540 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
541 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
542 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
544 // insert the current map there
547 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
548 newlist = strcat(newlist, " ", argv(j));
549 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
550 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
551 newlist = strcat(newlist, " ", argv(j));
552 newlist = substring(newlist, 1, strlen(newlist) - 1);
554 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
555 newlist = strcat(newlist, "'", argv(j), "'");
556 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
557 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
558 newlist = strcat(newlist, "'", argv(j), "'");
560 cvar_set("g_maplist", newlist);
562 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
564 Map_Count = tokenize(newlist);
567 // NOTE: the selected map has just been inserted at (insertpos-1)th position
568 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
569 if(Map_Check(Map_Current, 1))
575 void() Maplist_Init =
578 temp = cvar_string("g_maplist");
580 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
582 Map_Count = tokenize(temp);
586 bprint( "Maplist is empty! Resetting it to default map list.\n" );
588 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
589 localcmd("\nmenu_cmd sync\n");
590 Map_Count = tokenizebyseparator(temp, " ");
592 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
593 Map_Count = tokenize(temp);
597 error("empty maplist, cannot select a new map");
598 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
600 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
601 // this may or may not be correct, but who cares, in the worst case a map
602 // isn't chosen in the first pass that should have been
605 string() GetNextMap =
613 if(cvar("g_maplist_shuffle") > 0)
614 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
617 if(cvar("g_maplist_selectrandom"))
618 nextMap = MaplistMethod_Random();
621 nextMap = MaplistMethod_Iterate();
624 nextMap = MaplistMethod_Repeat();
628 Map_Goto_SetFloat(nextMap);
629 return getmapname_stored;
635 float() DoNextMapOverride =
637 if(cvar("g_campaign"))
639 CampaignPostIntermission();
640 alreadychangedlevel = TRUE;
643 if(cvar("quit_when_empty"))
645 if(player_count <= currentbots)
648 alreadychangedlevel = TRUE;
652 if(cvar_string("quit_and_redirect") != "")
654 redirection_target = strzone(cvar_string("quit_and_redirect"));
655 alreadychangedlevel = TRUE;
658 if (cvar("samelevel")) // if samelevel is set, stay on same level
660 // 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)
661 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
662 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
663 localcmd("restart\n");
664 //changelevel (mapname);
665 alreadychangedlevel = TRUE;
668 if(cvar_string("nextmap") != "")
670 if(MapInfo_CheckMap(cvar_string("nextmap")))
672 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
675 Map_Goto_SetStr(cvar_string("nextmap"));
677 alreadychangedlevel = TRUE;
680 if(cvar("lastlevel"))
683 localcmd("set lastlevel 0\ntogglemenu\n");
684 alreadychangedlevel = TRUE;
692 //local string nextmap;
693 //local float n, nummaps;
695 if (alreadychangedlevel)
697 alreadychangedlevel = TRUE;
703 for(allowReset = 1; allowReset >= 0; --allowReset)
705 nextMap = GetNextMap();
711 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
713 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
714 localcmd("\nmenu_cmd sync\n");
716 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
721 error("Everything is broken - not even the default map list works. Please report this to the developers.");
733 When the player presses attack or jump, change to the next level
736 .float autoscreenshot;
737 void() MapVote_Start;
738 void() MapVote_Think;
739 float mapvote_initialized;
740 void() IntermissionThink =
742 FixIntermissionClient(self);
744 if(cvar("sv_autoscreenshot"))
745 if(self.autoscreenshot > 0)
746 if(time > self.autoscreenshot)
748 self.autoscreenshot = -1;
749 if(clienttype(self) == CLIENTTYPE_REAL)
750 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
754 if (time < intermission_exittime)
757 if(!mapvote_initialized)
758 if (time < intermission_exittime + 10 && !self.button0 && !self.button2 && !self.button3 && !self.button6 && !self.buttonuse)
768 Returns the entity to view from
772 entity() FindIntermission =
777 // look for info_intermission first
778 spot = find (world, classname, "info_intermission");
780 { // pick a random one
784 spot = find (spot, classname, "info_intermission");
786 spot = find (spot, classname, "info_intermission");
792 // then look for the start position
793 spot = find (world, classname, "info_player_start");
797 // testinfo_player_start is only found in regioned levels
798 spot = find (world, classname, "testplayerstart");
802 // then look for the start position
803 spot = find (world, classname, "info_player_deathmatch");
807 //objerror ("FindIntermission: no spot");
813 ===============================================================================
817 ===============================================================================
820 void(float final) DumpStats =
824 local float to_console;
825 local float to_eventlog;
828 to_console = cvar("sv_logscores_console");
829 to_eventlog = cvar("sv_eventlog");
830 to_file = cvar("sv_logscores_file");
834 to_console = TRUE; // always print printstats replies
835 to_eventlog = FALSE; // but never print them to the event log
839 if(cvar("sv_eventlog_console"))
840 to_console = FALSE; // otherwise we get the output twice
847 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
849 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
853 ServerConsoleEcho(s, FALSE);
855 GameLogEcho(s, FALSE);
858 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
862 fputs(file, strcat(s, "\n"));
865 FOR_EACH_CLIENT(other)
867 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
869 s = strcat(":player:", ftos(other.frags), ":");
870 s = strcat(s, ftos(other.deaths), ":");
871 s = strcat(s, ftos(rint(time - other.jointime)), ":");
872 s = strcat(s, ftos(other.team), ":");
875 ServerConsoleEcho(strcat(s, other.netname), TRUE);
877 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
879 fputs(file, strcat(s, other.netname, "\n"));
884 ServerConsoleEcho(":end", FALSE);
886 GameLogEcho(":end", FALSE);
889 fputs(file, ":end\n");
894 void FixIntermissionClient(entity e)
896 if(!e.autoscreenshot) // initial call
898 e.angles = e.v_angle;
899 e.angles_x = -e.angles_x;
900 e.autoscreenshot = time + 0.8; // used for autoscreenshot
902 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
904 e.movetype = MOVETYPE_NONE;
905 e.takedamage = DAMAGE_NO;
907 e.weaponentity.effects = EF_NODRAW;
908 stuffcmd(e, "\nscr_printspeed 1000000\n");
909 if(clienttype(e) == CLIENTTYPE_REAL)
912 WriteByte(MSG_ONE, SVC_INTERMISSION);
916 //e.velocity = '0 0 0';
919 // TODO halt weapon animation
924 go to the next level for deathmatch
925 only called if a time or frag limit has expired
936 intermission_running = 1;
938 // enforce a wait time before allowing changelevel
940 intermission_exittime = time + cvar("sv_mapchange_delay");
942 intermission_exittime = -1;
944 WriteByte (MSG_ALL, SVC_CDTRACK);
945 WriteByte (MSG_ALL, 3);
946 WriteByte (MSG_ALL, 3);
948 //pos = FindIntermission ();
954 if(cvar("sv_eventlog"))
955 GameLogEcho(":gameover", FALSE);
959 FOR_EACH_CLIENT(other)
961 FixIntermissionClient(other);
964 bprint(other.netname, " ^7wins.\n");
969 FOR_EACH_PLAYER(other)
971 if(maxTotalFrags < other.totalfrags)
972 maxTotalFrags = other.totalfrags;
973 if(minTotalFrags > other.totalfrags)
974 minTotalFrags = other.totalfrags;
979 FOR_EACH_PLAYER(other)
981 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
982 f = bound(0, other.play_time / max(time, 1), 1);
983 // store some statistics?
987 if(cvar("g_campaign"))
988 CampaignPreIntermission();
990 // WriteByte (MSG_ALL, SVC_INTERMISSION);
997 Exit deathmatch games upon conditions
1000 void() CheckRules_Player =
1002 if (gameover) // someone else quit the game already
1005 if(self.deadflag == DEAD_NO)
1006 self.play_time += frametime;
1008 // fixme: don't check players; instead check dom_team and ctf_team entities
1009 // (div0: and that in CheckRules_World please)
1012 float checkrules_oneminutewarning;
1013 float checkrules_leaderfrags;
1014 float tdm_max_score, tdm_old_score;
1016 float checkrules_equality;
1017 float checkrules_overtimewarning;
1018 float checkrules_overtimeend;
1020 void() InitiateOvertime =
1022 if(!checkrules_overtimeend)
1023 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1026 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1027 float WINNING_YES = 1; // winner found
1028 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1029 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1031 float(float fraglimitreached, float equality) GetWinningCode =
1034 if(fraglimitreached)
1035 return WINNING_STARTOVERTIME;
1037 return WINNING_NEVER;
1039 if(fraglimitreached)
1045 // set the .winning flag for exactly those players with a given field value
1046 void(.float field, float value) SetWinners =
1049 FOR_EACH_PLAYER(head)
1050 head.winning = (head.field == value);
1053 // set the .winning flag for those players with a given field value
1054 void(.float field, float value) AddWinners =
1057 FOR_EACH_PLAYER(head)
1058 if(head.field == value)
1062 // clear frags for all players but the team given (when they ran out of spawnpoints)
1063 void(.float field, float value) ClearFragsForEveryoneBut =
1066 FOR_EACH_PLAYER(head)
1067 if(head.field != value)
1068 head.frags = max(head.frags, 0);
1071 // clear the .winning flags
1072 void(void) ClearWinners =
1075 FOR_EACH_PLAYER(head)
1079 // Onslaught winning condition:
1080 // game terminates if only one team has a working generator (or none)
1081 float() WinningCondition_Onslaught =
1084 local float t1, t2, t3, t4;
1085 // first check if the game has ended
1086 t1 = t2 = t3 = t4 = 0;
1087 head = find(world, classname, "onslaught_generator");
1090 if (head.health > 0)
1092 if (head.team == COLOR_TEAM1) t1 = 1;
1093 if (head.team == COLOR_TEAM2) t2 = 1;
1094 if (head.team == COLOR_TEAM3) t3 = 1;
1095 if (head.team == COLOR_TEAM4) t4 = 1;
1097 head = find(head, classname, "onslaught_generator");
1099 if (t1 + t2 + t3 + t4 < 2)
1101 // game over, only one team remains (or none)
1103 if (t1) SetWinners(team, COLOR_TEAM1);
1104 if (t2) SetWinners(team, COLOR_TEAM2);
1105 if (t3) SetWinners(team, COLOR_TEAM3);
1106 if (t4) SetWinners(team, COLOR_TEAM4);
1107 dprint("Have a winner, ending game.\n");
1111 // Two or more teams remain
1115 float() LMS_NewPlayerLives =
1118 fl = cvar("fraglimit");
1122 // first player has left the game for dying too much? Nobody else can get in.
1123 if(lms_lowest_lives < 1)
1126 if(!cvar("g_lms_join_anytime"))
1127 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1130 return bound(1, lms_lowest_lives, fl);
1133 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1134 // they win. Otherwise the defending team wins once the timelimit passes.
1135 void assault_new_round();
1136 float() WinningCondition_Assault =
1139 status = WINNING_NO;
1141 // as the timelimit has not yet passed just assume the defending team will win
1142 if(assault_attacker_team == COLOR_TEAM1)
1144 SetWinners(team, COLOR_TEAM2);
1148 SetWinners(team, COLOR_TEAM1);
1152 ent = find(world, classname, "target_assault_roundend");
1155 if(ent.winning) // round end has been triggered by attacking team
1157 SetWinners(team, assault_attacker_team);
1158 if(assault_attacker_team == COLOR_TEAM1)
1160 team1_score = team1_score + 50;
1164 team2_score = team2_score + 50;
1167 if(ent.cnt == 1) // this was the second round
1169 status = WINNING_YES;
1173 cvar_set("timelimit", ftos((2*time)/60));
1174 assault_new_round();
1184 // LMS winning condition: game terminates if and only if there's at most one
1185 // one player who's living lives. Top two scores being equal cancels the time
1187 float() WinningCondition_LMS =
1194 have_player = FALSE;
1195 have_players = FALSE;
1196 l = LMS_NewPlayerLives();
1198 head = find(world, classname, "player");
1201 head = find(head, classname, "player");
1203 have_players = TRUE;
1207 // we have at least one player
1210 // two or more active players - continue with the game
1214 // exactly one player?
1217 // but no game has taken place yet
1222 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1223 dprint("Have a winner, ending game.\n");
1230 // nobody is playing at all...
1233 // wait for players...
1237 // SNAFU (maybe a draw game?)
1239 dprint("No players, ending game.\n");
1244 // When we get here, we have at least two players who are actually LIVING,
1245 // or one player who is still waiting for a victim to join the server. Now
1246 // check if the top two players have equal score.
1248 checkrules_leaderfrags = 0;
1249 checkrules_equality = FALSE;
1250 FOR_EACH_PLAYER(head)
1252 if(head.frags > checkrules_leaderfrags)
1254 checkrules_leaderfrags = head.frags;
1255 checkrules_equality = FALSE;
1257 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1258 checkrules_equality = TRUE;
1261 SetWinners(frags, checkrules_leaderfrags);
1263 // The top two players have the same amount of lives? No timelimit then,
1264 // enter overtime...
1266 if(checkrules_equality)
1267 return WINNING_NEVER;
1269 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1273 // DM winning condition: game terminates if a player reached the fraglimit,
1274 // unless the first two players have the same score. The latter case also
1275 // breaks the time limit.
1276 float(float fraglimit) WinningCondition_MaxIndividualScore =
1278 float checkrules_oldleaderfrags;
1281 checkrules_oldleaderfrags = checkrules_leaderfrags;
1282 checkrules_leaderfrags = 0;
1283 checkrules_equality = FALSE;
1284 FOR_EACH_PLAYER(head)
1286 if(head.frags > checkrules_leaderfrags)
1288 checkrules_leaderfrags = head.frags;
1289 checkrules_equality = FALSE;
1291 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1292 checkrules_equality = TRUE;
1295 if(checkrules_leaderfrags > 0)
1296 SetWinners(frags, checkrules_leaderfrags);
1301 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1303 if (checkrules_leaderfrags == fraglimit - 1)
1304 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1305 else if (checkrules_leaderfrags == fraglimit - 2)
1306 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1307 else if (checkrules_leaderfrags == fraglimit - 3)
1308 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1311 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1314 float(float fraglimit) WinningConditionBase_Teamplay =
1316 tdm_old_score = tdm_max_score;
1317 tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1319 checkrules_equality =
1324 (team1_score == tdm_max_score)
1325 + (team2_score == tdm_max_score)
1326 + (team3_score == tdm_max_score)
1327 + (team4_score == tdm_max_score)
1331 if(tdm_max_score > 0)
1333 if(team1_score == tdm_max_score)
1334 AddWinners(team, COLOR_TEAM1);
1335 if(team2_score == tdm_max_score)
1336 AddWinners(team, COLOR_TEAM2);
1337 if(team3_score == tdm_max_score)
1338 AddWinners(team, COLOR_TEAM3);
1339 if(team4_score == tdm_max_score)
1340 AddWinners(team, COLOR_TEAM4);
1343 if(!g_runematch && !g_domination)
1344 if(tdm_max_score != tdm_old_score)
1346 if(tdm_max_score == fraglimit - 1)
1347 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1348 else if(tdm_max_score == fraglimit - 2)
1349 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1350 else if(tdm_max_score == fraglimit - 3)
1351 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1354 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1357 // TDM winning condition: game terminates if a team's score sum reached the
1358 // fraglimit, unless the first two teams have the same total score. The latter
1359 // case also breaks the time limit.
1360 float(float fraglimit) WinningCondition_MaxTeamSum =
1364 team1_score = team2_score = team3_score = team4_score = 0;
1366 FOR_EACH_PLAYER(head)
1368 if(head.team == COLOR_TEAM1)
1369 team1_score += head.frags;
1370 else if(head.team == COLOR_TEAM2)
1371 team2_score += head.frags;
1372 else if(head.team == COLOR_TEAM3)
1373 team3_score += head.frags;
1374 else if(head.team == COLOR_TEAM4)
1375 team4_score += head.frags;
1378 return WinningConditionBase_Teamplay(fraglimit);
1381 // DOM/CTF winning condition: game terminates if the max of a team's players'
1382 // score reached the fraglimit, unless the first two teams have the same
1383 // maximum score. The latter case also breaks the time limit.
1384 float(float fraglimit) WinningCondition_MaxTeamMax =
1388 team1_score = team2_score = team3_score = team4_score = 0;
1390 FOR_EACH_PLAYER(head)
1392 if(head.team == COLOR_TEAM1)
1394 if(head.frags > team1_score)
1395 team1_score = head.frags;
1397 else if(head.team == COLOR_TEAM2)
1399 if(head.frags > team2_score)
1400 team2_score = head.frags;
1402 else if(head.team == COLOR_TEAM3)
1404 if(head.frags > team3_score)
1405 team3_score = head.frags;
1407 else if(head.team == COLOR_TEAM4)
1409 if(head.frags > team4_score)
1410 team4_score = head.frags;
1414 return WinningConditionBase_Teamplay(fraglimit);
1417 void print_to(entity e, string s)
1420 sprint(e, strcat(s, "\n"));
1422 ServerConsoleEcho(s, TRUE);
1425 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1435 FOR_EACH_PLAYER(head)
1437 if(!whichteam || head.team == whichteam)
1441 print_to(e, strcat(" ", colorcode, name, ":"));
1443 fragtotal = fragtotal + head.frags;
1444 s = ftos(head.frags);
1445 s = strcat(s, "/", ftos(head.deaths));
1446 s = strcat(s, " @ ", ftos(head.ping));
1447 if(clienttype(head) == CLIENTTYPE_BOT)
1448 s = strcat(s, "botms");
1450 s = strcat(s, "ms");
1451 v = PlayerValue(head);
1453 s = strcat(s, " / ", ftos(v));
1454 print_to(e, strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"));
1457 if(whichteam && found)
1459 s = ftos(fragtotal);
1460 s = strcat(s, " / ", ftos(teamvalue));
1461 print_to(e, strcat(colorcode, " (total: ", s, ")"));
1465 void PrintScoreboard(entity e)
1467 print_to(e, strcat("Time: ", ftos(time / 60)));
1468 print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1469 print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1470 print_to(e, "Scoreboard:");
1473 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1474 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1475 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM3);
1476 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM4);
1480 PrintScoreboardFor(e, "", "^7", 0);
1485 void ShuffleMaplist()
1493 result = cvar_string("g_maplist");
1495 litems = tokenizebyseparator(result, " ");
1497 litems = tokenize(result);
1500 for(start = 0; start < litems - 1; ++start)
1504 // select a random item
1505 selected = ceil(random() * (litems - start) + start) - 1;
1507 // shift this item to the place start
1509 for(i = 0; i < start; ++i)
1510 result = strcat(result, " ", argv(i));
1511 result = strcat(result, " ", argv(selected));
1512 for(i = start; i < litems; ++i)
1514 result = strcat(result, " ", argv(i));
1515 result = substring(result, 1, strlen(result) - 1);
1517 litems = tokenizebyseparator(result, " ");
1519 for(i = 0; i < start; ++i)
1520 result = strcat(result, "'", argv(i), "'");
1521 result = strcat(result, "'", argv(selected), "'");
1522 for(i = start; i < litems; ++i)
1524 result = strcat(result, "'", argv(i), "'");
1526 litems = tokenize(result);
1529 //dprint(result, "\n");
1532 cvar_set("g_maplist", result);
1535 float WinningCondition_RanOutOfSpawns()
1539 if(!g_ctf && !g_assault && !g_onslaught)
1542 team1_score = team2_score = team3_score = team4_score = 0;
1544 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1546 if(head.team == COLOR_TEAM1)
1548 else if(head.team == COLOR_TEAM2)
1550 else if(head.team == COLOR_TEAM3)
1552 else if(head.team == COLOR_TEAM4)
1556 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1558 if(head.team == COLOR_TEAM1)
1560 else if(head.team == COLOR_TEAM2)
1562 else if(head.team == COLOR_TEAM3)
1564 else if(head.team == COLOR_TEAM4)
1569 if(team1_score + team2_score + team3_score + team4_score == 0)
1571 checkrules_equality = TRUE;
1574 else if(team1_score + team2_score + team3_score + team4_score == 1)
1578 AddWinners(team, COLOR_TEAM1);
1579 ClearFragsForEveryoneBut(team, COLOR_TEAM1);
1583 AddWinners(team, COLOR_TEAM2);
1584 ClearFragsForEveryoneBut(team, COLOR_TEAM1);
1588 AddWinners(team, COLOR_TEAM3);
1589 ClearFragsForEveryoneBut(team, COLOR_TEAM1);
1593 AddWinners(team, COLOR_TEAM4);
1594 ClearFragsForEveryoneBut(team, COLOR_TEAM1);
1606 Exit deathmatch games upon conditions
1609 void() CheckRules_World =
1612 local float timelimit;
1613 local float fraglimit;
1621 MapVote_Think should now do that part
1622 if (intermission_running)
1623 if (time >= intermission_exittime + 60)
1625 if(!DoNextMapOverride())
1631 if (gameover) // someone else quit the game already
1633 if(player_count == 0) // Nobody there? Then let's go to the next map
1635 // this will actually check the player count in the next frame
1636 // again, but this shouldn't hurt
1640 timelimit = cvar("timelimit") * 60;
1641 fraglimit = cvar("fraglimit");
1643 if(checkrules_overtimeend)
1645 if(!checkrules_overtimewarning)
1647 checkrules_overtimewarning = TRUE;
1648 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1649 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1654 if (timelimit && time >= timelimit)
1658 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1664 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1666 checkrules_oneminutewarning = TRUE;
1667 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1670 status = WinningCondition_RanOutOfSpawns();
1671 if(status == WINNING_YES)
1673 bprint("Hey! Someone ran out of spawns!\n");
1677 status = WinningCondition_Assault();
1681 status = WinningCondition_LMS();
1683 else if (g_onslaught)
1685 status = WinningCondition_Onslaught();
1691 if(g_tdm || g_runematch || g_ctf || g_domination || g_keyhunt)
1692 status = WinningCondition_MaxTeamSum(fraglimit);
1694 // status = WinningCondition_MaxTeamMax(fraglimit);
1697 dprint("div0: How can this happen?\n");
1698 status = WinningCondition_MaxTeamMax(fraglimit);
1702 status = WinningCondition_MaxIndividualScore(fraglimit);
1705 if(status == WINNING_STARTOVERTIME)
1707 status = WINNING_NEVER;
1711 if(status == WINNING_NEVER)
1712 // equality cases! Nobody wins if the overtime ends in a draw.
1715 if(checkrules_overtimeend)
1716 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1717 status = WINNING_YES;
1719 if(status == WINNING_YES)
1723 float randsel_value;
1724 float randsel_priority;
1725 float randsel_count;
1729 randsel_priority = -1;
1732 void RandSel_Add(float priority, float value)
1734 if(priority > randsel_priority)
1736 randsel_priority = priority;
1737 randsel_value = value;
1740 else if(priority == randsel_priority)
1743 if(ceil(random() * randsel_count) == 1)
1744 randsel_value = value;
1748 float mapvote_nextthink;
1749 float mapvote_initialized;
1750 float mapvote_keeptwotime;
1751 float mapvote_timeout;
1752 string mapvote_message;
1754 #define MAPVOTE_COUNT 10
1755 float mapvote_count;
1756 float mapvote_count_real;
1757 string mapvote_maps[MAPVOTE_COUNT];
1758 float mapvote_maps_suggested[MAPVOTE_COUNT];
1759 string mapvote_suggestions[MAPVOTE_COUNT];
1760 float mapvote_suggestion_ptr;
1761 float mapvote_maxlen;
1762 float mapvote_voters;
1763 float mapvote_votes[MAPVOTE_COUNT];
1765 float mapvote_detail;
1766 float mapvote_abstain;
1769 void MapVote_ClearAllVotes()
1771 FOR_EACH_CLIENT(other)
1775 string MapVote_Suggest(string m)
1779 return "That's not how to use this command.";
1780 if(!cvar("g_maplist_votable_suggestions"))
1781 return "Suggestions are not accepted on this server.";
1782 if(mapvote_initialized)
1783 return "Can't suggest - voting is already in progress!";
1785 m = MapInfo_FixName(m);
1787 return "The map you suggested is not available on this server.";
1789 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1790 if(!IsSameGametype(m))
1791 return "This server does not allow changing the game type by map suggestions.";
1792 if(!cvar("g_maplist_votable_override_mostrecent"))
1794 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1797 if(!MapInfo_CheckMap(m))
1798 return "The map you suggested does not support the current game mode.";
1800 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1801 return "The map you suggested is not available on this server.";
1803 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1804 if(mapvote_suggestions[i] == m)
1805 return "This map was already suggested.";
1806 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1808 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1812 i = mapvote_suggestion_ptr;
1813 mapvote_suggestion_ptr += 1;
1815 if(mapvote_suggestions[i] != "")
1816 strunzone(mapvote_suggestions[i]);
1817 mapvote_suggestions[i] = strzone(m);
1818 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid), ":", self.netname), TRUE);
1819 return strcat("Suggestion of ", m, " accepted.");
1822 void MapVote_AddVotable(string nextMap, float isSuggestion)
1827 for(j = 0; j < mapvote_count; ++j)
1828 if(mapvote_maps[j] == nextMap)
1830 if(strlen(nextMap) > mapvote_maxlen)
1831 mapvote_maxlen = strlen(nextMap);
1832 mapvote_maps[mapvote_count] = strzone(nextMap);
1833 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1842 MapVote_ClearAllVotes();
1845 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1846 mapvote_abstain = cvar("g_maplist_votable_abstain");
1849 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1851 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1852 smax = min(nmax, cvar("g_maplist_votable_suggestions"));
1854 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1855 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1857 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1858 MapVote_AddVotable(GetNextMap(), FALSE);
1860 if(mapvote_count == 0)
1862 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1864 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1865 localcmd("\nmenu_cmd sync\n");
1867 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1869 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1870 MapVote_AddVotable(GetNextMap(), FALSE);
1873 mapvote_count_real = mapvote_count;
1875 MapVote_AddVotable("don't care", 0);
1877 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1879 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1880 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1881 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1882 mapvote_keeptwotime = 0;
1883 mapvote_message = "Choose a map and press its key!";
1885 float MapVote_Finished(float mappos)
1891 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1892 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1893 didntvote = mapvote_voters;
1894 for(i = 0; i < mapvote_count; ++i)
1895 if(mapvote_maps[i] != "")
1897 didntvote -= mapvote_votes[i];
1900 result = strcat(result, ":", mapvote_maps[i]);
1901 result = strcat(result, ":", ftos(mapvote_votes[i]));
1904 result = strcat(result, ":didn't vote:", ftos(didntvote));
1906 GameLogEcho(result, FALSE);
1907 if(mapvote_maps_suggested[mappos])
1908 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
1910 FOR_EACH_REALCLIENT(other)
1911 FixClientCvars(other);
1913 Map_Goto_SetStr(mapvote_maps[mappos]);
1915 alreadychangedlevel = TRUE;
1918 void MapVote_CheckRules_1()
1922 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1924 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1925 mapvote_votes[i] = 0;
1929 FOR_EACH_REALCLIENT(other)
1934 i = other.mapvote - 1;
1935 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1936 mapvote_votes[i] = mapvote_votes[i] + 1;
1941 float MapVote_CheckRules_2()
1944 float firstPlace, secondPlace;
1945 float firstPlaceVotes, secondPlaceVotes;
1946 float mapvote_voters_real;
1949 mapvote_voters_real = mapvote_voters;
1951 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
1954 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1955 RandSel_Add(mapvote_votes[i], i);
1956 firstPlace = randsel_value;
1957 firstPlaceVotes = randsel_priority;
1958 //dprint("First place: ", ftos(firstPlace), "\n");
1959 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1962 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1964 RandSel_Add(mapvote_votes[i], i);
1965 secondPlace = randsel_value;
1966 secondPlaceVotes = randsel_priority;
1967 //dprint("Second place: ", ftos(secondPlace), "\n");
1968 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1970 if(firstPlace == -1)
1971 error("No first place in map vote... WTF?");
1973 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
1974 return MapVote_Finished(firstPlace);
1976 if(mapvote_keeptwotime)
1977 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
1980 mapvote_message = "Now decide between the TOP TWO!";
1981 mapvote_keeptwotime = 0;
1982 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
1983 result = strcat(result, ":", ftos(firstPlaceVotes));
1984 result = strcat(result, ":", mapvote_maps[secondPlace]);
1985 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
1986 didntvote = mapvote_voters;
1987 for(i = 0; i < mapvote_count; ++i)
1988 if(mapvote_maps[i] != "")
1990 didntvote -= mapvote_votes[i];
1992 if(i != secondPlace)
1994 result = strcat(result, ":", mapvote_maps[i]);
1995 result = strcat(result, ":", ftos(mapvote_votes[i]));
1996 if(i < mapvote_count_real)
1998 strunzone(mapvote_maps[i]);
1999 mapvote_maps[i] = "";
2003 result = strcat(result, ":didn't vote:", ftos(didntvote));
2004 GameLogEcho(result, FALSE);
2017 keeptwo = mapvote_keeptwotime;
2018 MapVote_CheckRules_1(); // count
2019 if(MapVote_CheckRules_2()) // decide
2023 FOR_EACH_REALCLIENT(other)
2025 // hide scoreboard again
2026 if(other.health != 2342)
2028 other.health = 2342;
2030 if(clienttype(other) == CLIENTTYPE_REAL)
2032 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");
2034 WriteByte(MSG_ONE, SVC_FINALE);
2035 WriteString(MSG_ONE, "");
2039 // notify about keep-two
2040 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2041 play2(other, "misc/invshot.wav");
2043 // clear possibly invalid votes
2044 if(mapvote_maps[other.mapvote - 1] == "")
2046 // use impulses as new vote
2047 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2048 if(mapvote_maps[other.impulse - 1] != "")
2049 other.mapvote = other.impulse;
2056 MapVote_CheckRules_1(); // just count
2058 FOR_EACH_REALCLIENT(other)
2060 // display voting screen
2061 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2062 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2064 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2065 msgstr = strcat(msgstr, mapvote_message);
2066 msgstr = strcat(msgstr, "\n\n");
2067 for(i = 0; i < mapvote_count; ++i)
2068 if(mapvote_maps[i] == "")
2069 msgstr = strcat(msgstr, "\n");
2072 tmp = mapvote_maps[i];
2073 tmp = strpad(mapvote_maxlen, tmp);
2074 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2077 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2078 if(mapvote_votes[i] != 1)
2079 tmp = strcat(tmp, "s");
2080 tmp = strcat(tmp, ")");
2081 tmp = strpad(mapvote_maxlen + 15, tmp);
2084 if(i == mapvote_count - 1)
2085 msgstr = strcat(msgstr, "\n");
2086 if(other.mapvote == i + 1)
2087 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2089 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2092 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2094 msgstr = strcat(msgstr, "s");
2095 msgstr = strcat(msgstr, " cast");
2096 i = ceil(mapvote_timeout - time);
2097 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2099 msgstr = strcat(msgstr, "s");
2100 msgstr = strcat(msgstr, " left");
2102 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2105 void MapVote_Start()
2111 MapInfo_Enumerate();
2112 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2116 void MapVote_Think()
2121 if(alreadychangedlevel)
2124 if(time < mapvote_nextthink)
2128 mapvote_nextthink = time + 0.5;
2130 if(!mapvote_initialized)
2132 mapvote_initialized = TRUE;
2133 if(DoNextMapOverride())
2135 if(!cvar("g_maplist_votable") || player_count <= 0)
2146 string GotoMap(string m)
2149 if(!MapInfo_CheckMap(m))
2151 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2153 return "The map you chose is not available on this server.";
2154 cvar_set("nextmap", m);
2155 cvar_set("timelimit", "-1");
2156 if(mapvote_initialized || alreadychangedlevel)
2158 if(DoNextMapOverride())
2159 return "Map switch initiated.";
2161 return "Hm... no. For some reason I like THIS map more.";
2164 return "Map switch will happen after scoreboard.";
2170 FOR_EACH_REALCLIENT(self)
2172 if(self.classname == "spectator")
2174 if(self.enemy.hitsound)
2175 play2(self, "misc/hit.wav");
2180 play2(self, "misc/hit.wav");
2183 FOR_EACH_CLIENT(self)
2184 self.hitsound = FALSE;
2190 * returns TRUE if redirecting
2192 float redirection_timeout;
2193 float redirection_nextthink;
2194 float RedirectionThink()
2196 float clients_found;
2198 if(redirection_target == "")
2201 if(!redirection_timeout)
2203 cvar_set("sv_public", "-2");
2204 redirection_timeout = time + 0.5; // this will only try twice... should be able to keep more clients
2205 if(redirection_target == "self")
2206 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2208 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2211 if(time < redirection_nextthink)
2214 redirection_nextthink = time + 1;
2217 FOR_EACH_REALCLIENT(self)
2219 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2220 if(redirection_target == "self")
2221 stuffcmd(self, "\ndisconnect; reconnect\n");
2223 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2227 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2229 if(time > redirection_timeout || clients_found == 0)
2230 localcmd("\nwait; wait; wait; quit\n");
2237 if(world_initialized)
2239 world_initialized = 0;
2240 print("Saving persistent data...\n");
2243 db_save(ServerProgsDB, "server.db");
2248 print("NOTE: crashed before even initializing the world, not saving persistent data\n");