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");
59 * Takes care of pausing and unpausing the game.
60 * Centerprints the information about an upcoming or active timeout to all active
61 * players. Also plays reminder sounds.
63 void timeoutHandler_Think() {
66 if (timeoutStatus == 1) {
67 if (remainingLeadTime > 0) {
68 //centerprint the information to every player
69 timeStr = getTimeoutText(0);
70 FOR_EACH_REALCLIENT(plr) {
71 if(plr.classname == "player") {
72 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
75 remainingLeadTime -= 1;
76 //think again in 1 second:
77 self.nextthink = time + 1;
82 cvar_set("slowmo", ftos(TIMEOUT_SLOWMO_VALUE));
83 //copy .v_angle to .lastV_angle for every player in order to fix their view during pause (see PlayerPreThink)
84 FOR_EACH_REALPLAYER(plr) {
85 plr.lastV_angle = plr.v_angle;
87 self.nextthink = time;
90 else if (timeoutStatus == 2) {
91 if (remainingTimeoutTime > 0) {
92 timeStr = getTimeoutText(0);
93 FOR_EACH_REALCLIENT(plr) {
94 if(plr.classname == "player") {
95 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
98 if(remainingTimeoutTime == cvar("sv_timeout_resumetime")) { //play a warning sound when only <sv_timeout_resumetime> seconds are left
99 sound(world, CHAN_AUTO, "announcer/robotic/prepareforbattle.wav", 1, ATTN_NONE);
101 remainingTimeoutTime -= 1;
102 self.nextthink = time + TIMEOUT_SLOWMO_VALUE;
105 //unpause the game again
106 remainingTimeoutTime = timeoutStatus = 0;
107 cvar_set("slowmo", ftos(orig_slowmo));
108 //and unlock the fixed view again once there is no timeout active anymore
109 FOR_EACH_REALPLAYER(plr) {
110 plr.fixangle = FALSE;
112 //get rid of the countdown message
113 FOR_EACH_REALCLIENT(plr) {
114 if(plr.classname == "player") {
115 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
123 else if (timeoutStatus == 0) { //if a player called the resumegame command (which set timeoutStatus to 0 already)
124 FOR_EACH_REALCLIENT(plr) {
125 if(plr.classname == "player") {
126 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
138 cvar_set("_sv_init", "0");
139 if(cvar("g_maplist_shuffle"))
142 tokenizebyseparator(cvar_string("g_maplist"), " ");
144 tokenize(cvar_string("g_maplist"));
145 if(argv(0) != GetMapname())
148 cvar_set("nextmap", argv(0));
152 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
155 if(!DoNextMapOverride())
164 float world_already_spawned;
165 void spawnfunc_worldspawn (void)
167 dprint_load(); // load dprint status from cvar
169 if(world_already_spawned)
170 error("world already spawned - you may have EXACTLY ONE worldspawn!");
171 world_already_spawned = TRUE;
177 MapInfo_LoadMapSettings(mapname);
181 ServerProgsDB = db_create();
183 ServerProgsDB = db_load("server.db");
186 TODO sound pack system
187 // initialize sound pack system
188 soundpack = cvar_string("g_soundpack");
190 soundpack = strcat(soundpack, "/");
191 soundpack = strzone(soundpack);
197 // 1 FLICKER (first variety)
198 lightstyle(1, "mmnmmommommnonmmonqnmmo");
200 // 2 SLOW STRONG PULSE
201 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
203 // 3 CANDLE (first variety)
204 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
207 lightstyle(4, "mamamamamama");
210 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
212 // 6 FLICKER (second variety)
213 lightstyle(6, "nmonqnmomnmomomno");
215 // 7 CANDLE (second variety)
216 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
218 // 8 CANDLE (third variety)
219 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
221 // 9 SLOW STROBE (fourth variety)
222 lightstyle(9, "aaaaaaaazzzzzzzz");
224 // 10 FLUORESCENT FLICKER
225 lightstyle(10, "mmamammmmammamamaaamammma");
227 // 11 SLOW PULSE NOT FADE TO BLACK
228 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
230 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
235 // for setting by mapinfo
236 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
237 cvar_set("sv_q3acompat_machineshotgunswap", "0");
240 lms_lowest_lives = 0;
243 bot_waypoints_for_items = cvar("g_waypoints_for_items");
244 if(bot_waypoints_for_items == 1)
245 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
246 bot_waypoints_for_items = 0;
248 if(cvar("g_campaign"))
255 WaypointSprite_Init();
261 head = nextent(world);
266 head = nextent(head);
269 GameLogInit(); // prepare everything
270 if(cvar("sv_eventlog"))
273 GameLogEcho(":logversion:2", FALSE);
274 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
275 s = strcat(s, ftos(random()));
277 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s), FALSE);
279 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
281 s = ":gameinfo:mutators:LIST";
282 if(cvar("g_grappling_hook"))
283 s = strcat(s, ":grappling_hook");
284 if(!cvar("g_use_ammunition"))
285 s = strcat(s, ":no_use_ammunition");
286 if(!cvar("g_pickup_items"))
287 s = strcat(s, ":no_pickup_items");
288 if(cvar("g_instagib"))
289 s = strcat(s, ":instagib");
290 if(cvar("g_rocketarena"))
291 s = strcat(s, ":rockerarena");
293 s = strcat(s, ":nixnex");
294 if(cvar("g_vampire"))
295 s = strcat(s, ":vampire");
296 if(cvar("g_laserguided_missile"))
297 s = strcat(s, ":laserguided_missile");
298 if(cvar("g_norecoil"))
299 s = strcat(s, ":norecoil");
301 s = strcat(s, ":midair");
302 if(cvar("g_minstagib"))
303 s = strcat(s, ":minstagib");
304 GameLogEcho(s, FALSE);
305 GameLogEcho(":gameinfo:end", FALSE);
308 cvar_set("nextmap", "");
312 if(cvar("g_campaign"))
319 //initialise globals related to sv_timeout
320 sys_ticrate = cvar("sys_ticrate");
321 orig_slowmo = cvar("slowmo");
325 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
328 //if tourney is used map starts in warmup mode. if this mode shall stay unlimited, reset timelimit, but save the original one
329 if(g_tourney && cvar("g_tourney_warmup_unlimited_time")) {
330 timelimit_orig = cvar("timelimit");
331 cvar_set("timelimit", "0");
334 world_initialized = 1;
337 void spawnfunc_light (void)
339 //makestatic (self); // Who the f___ did that?
343 float( string pFilename ) TryFile =
346 dprint("TryFile(\"", pFilename, "\")\n");
347 lHandle = fopen( pFilename, FILE_READ );
348 if( lHandle != -1 ) {
358 if (game == GAME_DEATHMATCH)
360 else if (game == GAME_TEAM_DEATHMATCH)
362 else if (game == GAME_DOMINATION)
364 else if (game == GAME_CTF)
366 else if (game == GAME_RUNEMATCH)
368 else if (game == GAME_LMS)
370 else if (game == GAME_KEYHUNT)
372 else if (game == GAME_ONSLAUGHT)
374 else if (game == GAME_ASSAULT)
379 float IsSameGametype(string mapcfgname)
382 return TRUE; // can't change game type by map name here
386 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
392 string getmapname_stored;
398 if(getmapname_stored == "")
399 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
400 return getmapname_stored;
404 float Map_Count, Map_Current;
405 string Map_Current_Name;
407 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
408 float GetMaplistPosition()
414 idx = cvar("g_maplist_index");
421 for(pos = 0; pos < Map_Count; ++pos)
425 // resume normal maplist rotation if current map is not in g_maplist
429 float MapHasRightSize(string map)
432 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
433 if(cvar("g_maplist_check_waypoints"))
435 dprint("checkwp "); dprint(map);
436 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
439 dprint(": no waypoints\n");
442 dprint(": has waypoints\n");
446 // open map size restriction file
447 dprint("opensize "); dprint(map);
448 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
451 float mapmin, mapmax;
453 mapmin = stof(fgets(fh));
454 mapmax = stof(fgets(fh));
456 if(player_count < mapmin)
458 dprint("not enough\n");
461 if(player_count > mapmax)
463 dprint("too many\n");
466 dprint("right size\n");
469 dprint(": not found\n");
473 string Map_Filename(float position)
476 return strcat("maps/", argv(position), ".bsp");
478 return strcat("maps/", argv(position), ".mapcfg");
482 string strwords(string s, float w)
485 for(endpos = 0; w && endpos >= 0; --w)
486 endpos = strstrofs(s, " ", endpos + 1);
490 return substring(s, 0, endpos);
493 float strhasword(string s, string w)
495 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
498 void Map_MarkAsRecent(string m)
500 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
503 float Map_IsRecent(string m)
505 return strhasword(cvar_string("g_maplist_mostrecent"), m);
508 float(float position, float pass) Map_Check =
512 map_next = argv(position);
515 if(map_next == Map_Current_Name) // same map again in first pass?
517 if(Map_IsRecent(map_next))
520 filename = Map_Filename(position);
522 if(MapInfo_CheckMap(map_next))
524 if(TryFile(filename))
529 if(MapHasRightSize(map_next))
534 dprint( "Couldn't select '", filename, "'..\n" );
539 void(string nextmapname) Map_Goto_SetStr =
541 if(getmapname_stored != "")
542 strunzone(getmapname_stored);
543 if(nextmapname == "")
544 getmapname_stored = "";
546 getmapname_stored = strzone(nextmapname);
549 void(float position) Map_Goto_SetFloat =
551 cvar_set("g_maplist_index", ftos(position));
552 Map_Goto_SetStr(argv(position));
555 void() GameResetCfg =
558 // settings persist, except...
559 if(cvar("g_campaign"))
560 localcmd("\nexec mutator_reset.cfg\n");
561 localcmd("\nsettemp_restore\n");
563 // if an exit cfg is defined by exiting map, exec it.
565 exit_cfg = cvar_string("exit_cfg");
567 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
569 localcmd("exec game_reset.cfg\n");
575 Map_MarkAsRecent(getmapname_stored);
578 MapInfo_LoadMap(getmapname_stored);
580 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
584 // return codes of map selectors:
585 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
586 // -2 = permanent failure
587 float() MaplistMethod_Iterate = // usual method
591 for(pass = 1; pass <= 2; ++pass)
593 for(i = 1; i < Map_Count; ++i)
596 mapindex = mod(i + Map_Current, Map_Count);
597 if(Map_Check(mapindex, pass))
604 float() MaplistMethod_Repeat = // fallback method
606 if(Map_Check(Map_Current, 2))
611 float() MaplistMethod_Random = // random map selection
617 for(i = 0; i <= imax; ++i)
620 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
621 if(Map_Check(mapindex, 1))
627 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
628 // the exponent sets a bias on the map selection:
629 // the higher the exponent, the less likely "shortly repeated" same maps are
631 float i, j, imax, insertpos;
635 for(i = 0; i <= imax; ++i)
639 // now reinsert this at another position
640 insertpos = pow(random(), 1 / exponent); // ]0, 1]
641 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
642 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
643 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
645 // insert the current map there
648 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
649 newlist = strcat(newlist, " ", argv(j));
650 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
651 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
652 newlist = strcat(newlist, " ", argv(j));
653 newlist = substring(newlist, 1, strlen(newlist) - 1);
655 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
656 newlist = strcat(newlist, "'", argv(j), "'");
657 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
658 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
659 newlist = strcat(newlist, "'", argv(j), "'");
661 cvar_set("g_maplist", newlist);
663 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
665 Map_Count = tokenize(newlist);
668 // NOTE: the selected map has just been inserted at (insertpos-1)th position
669 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
670 if(Map_Check(Map_Current, 1))
676 void() Maplist_Init =
679 temp = cvar_string("g_maplist");
681 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
683 Map_Count = tokenize(temp);
687 bprint( "Maplist is empty! Resetting it to default map list.\n" );
689 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
690 localcmd("\nmenu_cmd sync\n");
691 Map_Count = tokenizebyseparator(temp, " ");
693 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
694 Map_Count = tokenize(temp);
698 error("empty maplist, cannot select a new map");
699 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
701 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
702 // this may or may not be correct, but who cares, in the worst case a map
703 // isn't chosen in the first pass that should have been
706 string() GetNextMap =
714 if(cvar("g_maplist_shuffle") > 0)
715 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
718 if(cvar("g_maplist_selectrandom"))
719 nextMap = MaplistMethod_Random();
722 nextMap = MaplistMethod_Iterate();
725 nextMap = MaplistMethod_Repeat();
729 Map_Goto_SetFloat(nextMap);
730 return getmapname_stored;
736 float() DoNextMapOverride =
738 if(cvar("g_campaign"))
740 CampaignPostIntermission();
741 alreadychangedlevel = TRUE;
744 if(cvar("quit_when_empty"))
746 if(player_count <= currentbots)
749 alreadychangedlevel = TRUE;
753 if(cvar_string("quit_and_redirect") != "")
755 redirection_target = strzone(cvar_string("quit_and_redirect"));
756 alreadychangedlevel = TRUE;
759 if (cvar("samelevel")) // if samelevel is set, stay on same level
761 // 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)
762 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
763 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
764 localcmd("restart\n");
765 //changelevel (mapname);
766 alreadychangedlevel = TRUE;
769 if(cvar_string("nextmap") != "")
771 if(MapInfo_CheckMap(cvar_string("nextmap")))
773 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
776 Map_Goto_SetStr(cvar_string("nextmap"));
778 alreadychangedlevel = TRUE;
781 if(cvar("lastlevel"))
784 localcmd("set lastlevel 0\ntogglemenu\n");
785 alreadychangedlevel = TRUE;
793 //local string nextmap;
794 //local float n, nummaps;
796 if (alreadychangedlevel)
798 alreadychangedlevel = TRUE;
804 for(allowReset = 1; allowReset >= 0; --allowReset)
806 nextMap = GetNextMap();
812 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
814 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
815 localcmd("\nmenu_cmd sync\n");
817 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
822 error("Everything is broken - not even the default map list works. Please report this to the developers.");
834 When the player presses attack or jump, change to the next level
837 .float autoscreenshot;
838 void() MapVote_Start;
839 void() MapVote_Think;
840 float mapvote_initialized;
841 void() IntermissionThink =
843 FixIntermissionClient(self);
845 if(cvar("sv_autoscreenshot"))
846 if(self.autoscreenshot > 0)
847 if(time > self.autoscreenshot)
849 self.autoscreenshot = -1;
850 if(clienttype(self) == CLIENTTYPE_REAL)
851 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
855 if (time < intermission_exittime)
858 if(!mapvote_initialized)
859 if (time < intermission_exittime + 10 && !self.button0 && !self.button2 && !self.button3 && !self.button6 && !self.buttonuse)
869 Returns the entity to view from
873 entity() FindIntermission =
878 // look for info_intermission first
879 spot = find (world, classname, "info_intermission");
881 { // pick a random one
885 spot = find (spot, classname, "info_intermission");
887 spot = find (spot, classname, "info_intermission");
893 // then look for the start position
894 spot = find (world, classname, "info_player_start");
898 // testinfo_player_start is only found in regioned levels
899 spot = find (world, classname, "testplayerstart");
903 // then look for the start position
904 spot = find (world, classname, "info_player_deathmatch");
908 //objerror ("FindIntermission: no spot");
914 ===============================================================================
918 ===============================================================================
921 void(float final) DumpStats =
925 local float to_console;
926 local float to_eventlog;
929 to_console = cvar("sv_logscores_console");
930 to_eventlog = cvar("sv_eventlog");
931 to_file = cvar("sv_logscores_file");
935 to_console = TRUE; // always print printstats replies
936 to_eventlog = FALSE; // but never print them to the event log
940 if(cvar("sv_eventlog_console"))
941 to_console = FALSE; // otherwise we get the output twice
948 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
950 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
954 ServerConsoleEcho(s, FALSE);
956 GameLogEcho(s, FALSE);
959 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
963 fputs(file, strcat(s, "\n"));
966 FOR_EACH_CLIENT(other)
968 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
970 s = strcat(":player:", ftos(other.frags), ":");
971 s = strcat(s, ftos(other.deaths), ":");
972 s = strcat(s, ftos(rint(time - other.jointime)), ":");
973 s = strcat(s, ftos(other.team), ":");
976 ServerConsoleEcho(strcat(s, other.netname), TRUE);
978 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
980 fputs(file, strcat(s, other.netname, "\n"));
985 ServerConsoleEcho(":end", FALSE);
987 GameLogEcho(":end", FALSE);
990 fputs(file, ":end\n");
995 void FixIntermissionClient(entity e)
998 if(!e.autoscreenshot) // initial call
1000 e.angles = e.v_angle;
1001 e.angles_x = -e.angles_x;
1002 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1004 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1005 e.solid = SOLID_NOT;
1006 e.movetype = MOVETYPE_NONE;
1007 e.takedamage = DAMAGE_NO;
1009 e.weaponentity.effects = EF_NODRAW;
1010 if(clienttype(e) == CLIENTTYPE_REAL)
1012 stuffcmd(e, "\nscr_printspeed 1000000\n");
1013 s = cvar_string("sv_intermission_cdtrack");
1015 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1017 WriteByte(MSG_ONE, SVC_INTERMISSION);
1021 //e.velocity = '0 0 0';
1022 //e.fixangle = TRUE;
1024 // TODO halt weapon animation
1029 go to the next level for deathmatch
1030 only called if a time or frag limit has expired
1034 float minTotalFrags;
1035 float maxTotalFrags;
1041 intermission_running = 1;
1043 // enforce a wait time before allowing changelevel
1044 if(player_count > 0)
1045 intermission_exittime = time + cvar("sv_mapchange_delay");
1047 intermission_exittime = -1;
1050 WriteByte (MSG_ALL, SVC_CDTRACK);
1051 WriteByte (MSG_ALL, 3);
1052 WriteByte (MSG_ALL, 3);
1053 // done in FixIntermission
1056 //pos = FindIntermission ();
1062 if(cvar("sv_eventlog"))
1063 GameLogEcho(":gameover", FALSE);
1067 FOR_EACH_CLIENT(other)
1069 FixIntermissionClient(other);
1072 bprint(other.netname, " ^7wins.\n");
1077 FOR_EACH_PLAYER(other)
1079 if(maxTotalFrags < other.totalfrags)
1080 maxTotalFrags = other.totalfrags;
1081 if(minTotalFrags > other.totalfrags)
1082 minTotalFrags = other.totalfrags;
1087 FOR_EACH_PLAYER(other)
1089 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1090 f = bound(0, other.play_time / max(time, 1), 1);
1091 // store some statistics?
1095 if(cvar("g_campaign"))
1096 CampaignPreIntermission();
1098 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1105 Exit deathmatch games upon conditions
1108 void() CheckRules_Player =
1110 if (gameover) // someone else quit the game already
1113 if(self.deadflag == DEAD_NO)
1114 self.play_time += frametime;
1116 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1117 // (div0: and that in CheckRules_World please)
1120 float checkrules_oneminutewarning;
1121 float checkrules_leaderfrags;
1122 float tdm_max_score, tdm_old_score;
1124 float checkrules_equality;
1125 float checkrules_overtimewarning;
1126 float checkrules_overtimeend;
1128 void() InitiateOvertime =
1130 if(!checkrules_overtimeend)
1131 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1134 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1135 float WINNING_YES = 1; // winner found
1136 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1137 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1139 float(float fraglimitreached, float equality) GetWinningCode =
1142 if(fraglimitreached)
1143 return WINNING_STARTOVERTIME;
1145 return WINNING_NEVER;
1147 if(fraglimitreached)
1153 // set the .winning flag for exactly those players with a given field value
1154 void(.float field, float value) SetWinners =
1157 FOR_EACH_PLAYER(head)
1158 head.winning = (head.field == value);
1161 // set the .winning flag for those players with a given field value
1162 void(.float field, float value) AddWinners =
1165 FOR_EACH_PLAYER(head)
1166 if(head.field == value)
1170 // clear frags for all players but the team given (when they ran out of spawnpoints)
1171 void(.float field, float value) ClearFragsForEveryoneBut =
1174 FOR_EACH_PLAYER(head)
1175 if(head.field != value)
1176 head.frags = max(head.frags, 0);
1179 // clear the .winning flags
1180 void(void) ClearWinners =
1183 FOR_EACH_PLAYER(head)
1187 // Onslaught winning condition:
1188 // game terminates if only one team has a working generator (or none)
1189 float() WinningCondition_Onslaught =
1192 local float t1, t2, t3, t4;
1193 // first check if the game has ended
1194 t1 = t2 = t3 = t4 = 0;
1195 head = find(world, classname, "onslaught_generator");
1198 if (head.health > 0)
1200 if (head.team == COLOR_TEAM1) t1 = 1;
1201 if (head.team == COLOR_TEAM2) t2 = 1;
1202 if (head.team == COLOR_TEAM3) t3 = 1;
1203 if (head.team == COLOR_TEAM4) t4 = 1;
1205 head = find(head, classname, "onslaught_generator");
1207 if (t1 + t2 + t3 + t4 < 2)
1209 // game over, only one team remains (or none)
1211 if (t1) SetWinners(team, COLOR_TEAM1);
1212 if (t2) SetWinners(team, COLOR_TEAM2);
1213 if (t3) SetWinners(team, COLOR_TEAM3);
1214 if (t4) SetWinners(team, COLOR_TEAM4);
1215 dprint("Have a winner, ending game.\n");
1219 // Two or more teams remain
1223 float() LMS_NewPlayerLives =
1226 fl = cvar("fraglimit");
1230 // first player has left the game for dying too much? Nobody else can get in.
1231 if(lms_lowest_lives < 1)
1234 if(!cvar("g_lms_join_anytime"))
1235 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1238 return bound(1, lms_lowest_lives, fl);
1241 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1242 // they win. Otherwise the defending team wins once the timelimit passes.
1243 void assault_new_round();
1244 float() WinningCondition_Assault =
1247 status = WINNING_NO;
1249 // as the timelimit has not yet passed just assume the defending team will win
1250 if(assault_attacker_team == COLOR_TEAM1)
1252 SetWinners(team, COLOR_TEAM2);
1256 SetWinners(team, COLOR_TEAM1);
1260 ent = find(world, classname, "target_assault_roundend");
1263 if(ent.winning) // round end has been triggered by attacking team
1265 SetWinners(team, assault_attacker_team);
1266 if(assault_attacker_team == COLOR_TEAM1)
1268 team1_score = team1_score + 50;
1272 team2_score = team2_score + 50;
1275 if(ent.cnt == 1) // this was the second round
1277 status = WINNING_YES;
1281 cvar_set("timelimit", ftos((2*time)/60));
1282 assault_new_round();
1292 // LMS winning condition: game terminates if and only if there's at most one
1293 // one player who's living lives. Top two scores being equal cancels the time
1295 float() WinningCondition_LMS =
1302 have_player = FALSE;
1303 have_players = FALSE;
1304 l = LMS_NewPlayerLives();
1306 head = find(world, classname, "player");
1309 head = find(head, classname, "player");
1311 have_players = TRUE;
1315 // we have at least one player
1318 // two or more active players - continue with the game
1322 // exactly one player?
1325 // but no game has taken place yet
1330 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1331 dprint("Have a winner, ending game.\n");
1338 // nobody is playing at all...
1341 // wait for players...
1345 // SNAFU (maybe a draw game?)
1347 dprint("No players, ending game.\n");
1352 // When we get here, we have at least two players who are actually LIVING,
1353 // or one player who is still waiting for a victim to join the server. Now
1354 // check if the top two players have equal score.
1356 checkrules_leaderfrags = 0;
1357 checkrules_equality = FALSE;
1358 FOR_EACH_PLAYER(head)
1360 if(head.frags > checkrules_leaderfrags)
1362 checkrules_leaderfrags = head.frags;
1363 checkrules_equality = FALSE;
1365 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1366 checkrules_equality = TRUE;
1369 SetWinners(frags, checkrules_leaderfrags);
1371 // The top two players have the same amount of lives? No timelimit then,
1372 // enter overtime...
1374 if(checkrules_equality)
1375 return WINNING_NEVER;
1377 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1381 // DM winning condition: game terminates if a player reached the fraglimit,
1382 // unless the first two players have the same score. The latter case also
1383 // breaks the time limit.
1384 float(float fraglimit) WinningCondition_MaxIndividualScore =
1386 float checkrules_oldleaderfrags;
1389 checkrules_oldleaderfrags = checkrules_leaderfrags;
1390 checkrules_leaderfrags = 0;
1391 checkrules_equality = FALSE;
1392 FOR_EACH_PLAYER(head)
1394 if(head.frags > checkrules_leaderfrags)
1396 checkrules_leaderfrags = head.frags;
1397 checkrules_equality = FALSE;
1399 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1400 checkrules_equality = TRUE;
1403 if(checkrules_leaderfrags > 0)
1404 SetWinners(frags, checkrules_leaderfrags);
1409 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1411 if (checkrules_leaderfrags == fraglimit - 1)
1412 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1413 else if (checkrules_leaderfrags == fraglimit - 2)
1414 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1415 else if (checkrules_leaderfrags == fraglimit - 3)
1416 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1419 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1422 float(float fraglimit) WinningConditionBase_Teamplay =
1424 tdm_old_score = tdm_max_score;
1425 tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1427 checkrules_equality =
1432 (team1_score == tdm_max_score)
1433 + (team2_score == tdm_max_score)
1434 + (team3_score == tdm_max_score)
1435 + (team4_score == tdm_max_score)
1439 if(tdm_max_score > 0)
1441 if(team1_score == tdm_max_score)
1442 AddWinners(team, COLOR_TEAM1);
1443 if(team2_score == tdm_max_score)
1444 AddWinners(team, COLOR_TEAM2);
1445 if(team3_score == tdm_max_score)
1446 AddWinners(team, COLOR_TEAM3);
1447 if(team4_score == tdm_max_score)
1448 AddWinners(team, COLOR_TEAM4);
1451 if(!g_runematch && !g_domination)
1452 if(tdm_max_score != tdm_old_score)
1454 if(tdm_max_score == fraglimit - 1)
1455 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1456 else if(tdm_max_score == fraglimit - 2)
1457 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1458 else if(tdm_max_score == fraglimit - 3)
1459 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1462 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1465 // TDM winning condition: game terminates if a team's score sum reached the
1466 // fraglimit, unless the first two teams have the same total score. The latter
1467 // case also breaks the time limit.
1468 float(float fraglimit) WinningCondition_MaxTeamSum =
1472 team1_score = team2_score = team3_score = team4_score = 0;
1474 FOR_EACH_PLAYER(head)
1476 if(head.team == COLOR_TEAM1)
1477 team1_score += head.frags;
1478 else if(head.team == COLOR_TEAM2)
1479 team2_score += head.frags;
1480 else if(head.team == COLOR_TEAM3)
1481 team3_score += head.frags;
1482 else if(head.team == COLOR_TEAM4)
1483 team4_score += head.frags;
1486 return WinningConditionBase_Teamplay(fraglimit);
1489 // DOM/CTF winning condition: game terminates if the max of a team's players'
1490 // score reached the fraglimit, unless the first two teams have the same
1491 // maximum score. The latter case also breaks the time limit.
1492 float(float fraglimit) WinningCondition_MaxTeamMax =
1496 team1_score = team2_score = team3_score = team4_score = 0;
1498 FOR_EACH_PLAYER(head)
1500 if(head.team == COLOR_TEAM1)
1502 if(head.frags > team1_score)
1503 team1_score = head.frags;
1505 else if(head.team == COLOR_TEAM2)
1507 if(head.frags > team2_score)
1508 team2_score = head.frags;
1510 else if(head.team == COLOR_TEAM3)
1512 if(head.frags > team3_score)
1513 team3_score = head.frags;
1515 else if(head.team == COLOR_TEAM4)
1517 if(head.frags > team4_score)
1518 team4_score = head.frags;
1522 return WinningConditionBase_Teamplay(fraglimit);
1525 void print_to(entity e, string s)
1528 sprint(e, strcat(s, "\n"));
1530 ServerConsoleEcho(s, TRUE);
1533 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1543 FOR_EACH_PLAYER(head)
1545 if(!whichteam || head.team == whichteam)
1549 print_to(e, strcat(" ", colorcode, name, ":"));
1551 fragtotal = fragtotal + head.frags;
1552 s = ftos(head.frags);
1553 s = strcat(s, "/", ftos(head.deaths));
1554 s = strcat(s, " @ ", ftos(head.ping));
1555 if(clienttype(head) == CLIENTTYPE_BOT)
1556 s = strcat(s, "botms");
1558 s = strcat(s, "ms");
1559 v = PlayerValue(head);
1561 s = strcat(s, " / ", ftos(v));
1562 print_to(e, strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"));
1565 if(whichteam && found)
1567 s = ftos(fragtotal);
1568 s = strcat(s, " / ", ftos(teamvalue));
1569 print_to(e, strcat(colorcode, " (total: ", s, ")"));
1573 void PrintScoreboard(entity e)
1575 print_to(e, strcat("Time: ", ftos(time / 60)));
1576 print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1577 print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1578 print_to(e, "Scoreboard:");
1581 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1582 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1583 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM3);
1584 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM4);
1588 PrintScoreboardFor(e, "", "^7", 0);
1593 void ShuffleMaplist()
1601 result = cvar_string("g_maplist");
1603 litems = tokenizebyseparator(result, " ");
1605 litems = tokenize(result);
1608 for(start = 0; start < litems - 1; ++start)
1612 // select a random item
1613 selected = ceil(random() * (litems - start) + start) - 1;
1615 // shift this item to the place start
1617 for(i = 0; i < start; ++i)
1618 result = strcat(result, " ", argv(i));
1619 result = strcat(result, " ", argv(selected));
1620 for(i = start; i < litems; ++i)
1622 result = strcat(result, " ", argv(i));
1623 result = substring(result, 1, strlen(result) - 1);
1625 litems = tokenizebyseparator(result, " ");
1627 for(i = 0; i < start; ++i)
1628 result = strcat(result, "'", argv(i), "'");
1629 result = strcat(result, "'", argv(selected), "'");
1630 for(i = start; i < litems; ++i)
1632 result = strcat(result, "'", argv(i), "'");
1634 litems = tokenize(result);
1637 //dprint(result, "\n");
1640 cvar_set("g_maplist", result);
1643 float WinningCondition_RanOutOfSpawns()
1647 if(!have_team_spawns)
1650 if(!some_spawn_has_been_used)
1653 team1_score = team2_score = team3_score = team4_score = 0;
1655 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1657 if(head.team == COLOR_TEAM1)
1659 else if(head.team == COLOR_TEAM2)
1661 else if(head.team == COLOR_TEAM3)
1663 else if(head.team == COLOR_TEAM4)
1667 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1669 if(head.team == COLOR_TEAM1)
1671 else if(head.team == COLOR_TEAM2)
1673 else if(head.team == COLOR_TEAM3)
1675 else if(head.team == COLOR_TEAM4)
1680 if(team1_score + team2_score + team3_score + team4_score == 0)
1682 checkrules_equality = TRUE;
1685 else if(team1_score + team2_score + team3_score + team4_score == 1)
1689 AddWinners(team, COLOR_TEAM1);
1690 ClearFragsForEveryoneBut(team, COLOR_TEAM1);
1694 AddWinners(team, COLOR_TEAM2);
1695 ClearFragsForEveryoneBut(team, COLOR_TEAM2);
1699 AddWinners(team, COLOR_TEAM3);
1700 ClearFragsForEveryoneBut(team, COLOR_TEAM3);
1704 AddWinners(team, COLOR_TEAM4);
1705 ClearFragsForEveryoneBut(team, COLOR_TEAM4);
1717 Exit deathmatch games upon conditions
1720 void() CheckRules_World =
1723 local float timelimit;
1724 local float fraglimit;
1732 MapVote_Think should now do that part
1733 if (intermission_running)
1734 if (time >= intermission_exittime + 60)
1736 if(!DoNextMapOverride())
1742 if (gameover) // someone else quit the game already
1744 if(player_count == 0) // Nobody there? Then let's go to the next map
1746 // this will actually check the player count in the next frame
1747 // again, but this shouldn't hurt
1751 timelimit = cvar("timelimit") * 60;
1752 fraglimit = cvar("fraglimit");
1754 if(checkrules_overtimeend)
1756 if(!checkrules_overtimewarning)
1758 checkrules_overtimewarning = TRUE;
1759 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1760 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1765 if (timelimit && time >= timelimit)
1769 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1775 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1777 checkrules_oneminutewarning = TRUE;
1778 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1781 status = WinningCondition_RanOutOfSpawns();
1782 if(status == WINNING_YES)
1784 bprint("Hey! Someone ran out of spawns!\n");
1788 status = WinningCondition_Assault();
1792 status = WinningCondition_LMS();
1794 else if (g_onslaught)
1796 status = WinningCondition_Onslaught();
1802 if(g_tdm || g_runematch || g_ctf || g_domination || g_keyhunt)
1803 status = WinningCondition_MaxTeamSum(fraglimit);
1805 // status = WinningCondition_MaxTeamMax(fraglimit);
1808 dprint("div0: How can this happen?\n");
1809 status = WinningCondition_MaxTeamMax(fraglimit);
1813 status = WinningCondition_MaxIndividualScore(fraglimit);
1816 if(status == WINNING_STARTOVERTIME)
1818 status = WINNING_NEVER;
1822 if(status == WINNING_NEVER)
1823 // equality cases! Nobody wins if the overtime ends in a draw.
1826 if(checkrules_overtimeend)
1827 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1828 status = WINNING_YES;
1830 if(status == WINNING_YES)
1834 float randsel_value;
1835 float randsel_priority;
1836 float randsel_count;
1840 randsel_priority = -1;
1843 void RandSel_Add(float priority, float value)
1845 if(priority > randsel_priority)
1847 randsel_priority = priority;
1848 randsel_value = value;
1851 else if(priority == randsel_priority)
1854 if(ceil(random() * randsel_count) == 1)
1855 randsel_value = value;
1859 float mapvote_nextthink;
1860 float mapvote_initialized;
1861 float mapvote_keeptwotime;
1862 float mapvote_timeout;
1863 string mapvote_message;
1865 #define MAPVOTE_COUNT 10
1866 float mapvote_count;
1867 float mapvote_count_real;
1868 string mapvote_maps[MAPVOTE_COUNT];
1869 float mapvote_maps_suggested[MAPVOTE_COUNT];
1870 string mapvote_suggestions[MAPVOTE_COUNT];
1871 float mapvote_suggestion_ptr;
1872 float mapvote_maxlen;
1873 float mapvote_voters;
1874 float mapvote_votes[MAPVOTE_COUNT];
1876 float mapvote_detail;
1877 float mapvote_abstain;
1880 void MapVote_ClearAllVotes()
1882 FOR_EACH_CLIENT(other)
1886 string MapVote_Suggest(string m)
1890 return "That's not how to use this command.";
1891 if(!cvar("g_maplist_votable_suggestions"))
1892 return "Suggestions are not accepted on this server.";
1893 if(mapvote_initialized)
1894 return "Can't suggest - voting is already in progress!";
1896 m = MapInfo_FixName(m);
1898 return "The map you suggested is not available on this server.";
1900 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1901 if(!IsSameGametype(m))
1902 return "This server does not allow changing the game type by map suggestions.";
1904 if(!cvar("g_maplist_votable_override_mostrecent"))
1906 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1909 if(!MapInfo_CheckMap(m))
1910 return "The map you suggested does not support the current game mode.";
1912 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1913 return "The map you suggested is not available on this server.";
1915 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1916 if(mapvote_suggestions[i] == m)
1917 return "This map was already suggested.";
1918 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1920 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1924 i = mapvote_suggestion_ptr;
1925 mapvote_suggestion_ptr += 1;
1927 if(mapvote_suggestions[i] != "")
1928 strunzone(mapvote_suggestions[i]);
1929 mapvote_suggestions[i] = strzone(m);
1930 if(cvar("sv_eventlog"))
1931 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)), TRUE);
1932 return strcat("Suggestion of ", m, " accepted.");
1935 void MapVote_AddVotable(string nextMap, float isSuggestion)
1940 for(j = 0; j < mapvote_count; ++j)
1941 if(mapvote_maps[j] == nextMap)
1943 if(strlen(nextMap) > mapvote_maxlen)
1944 mapvote_maxlen = strlen(nextMap);
1945 mapvote_maps[mapvote_count] = strzone(nextMap);
1946 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1955 MapVote_ClearAllVotes();
1958 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1959 mapvote_abstain = cvar("g_maplist_votable_abstain");
1962 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1964 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1965 smax = min(nmax, cvar("g_maplist_votable_suggestions"));
1967 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1968 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1970 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1971 MapVote_AddVotable(GetNextMap(), FALSE);
1973 if(mapvote_count == 0)
1975 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1977 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1978 localcmd("\nmenu_cmd sync\n");
1980 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1982 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1983 MapVote_AddVotable(GetNextMap(), FALSE);
1986 mapvote_count_real = mapvote_count;
1988 MapVote_AddVotable("don't care", 0);
1990 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1992 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1993 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1994 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1995 mapvote_keeptwotime = 0;
1996 mapvote_message = "Choose a map and press its key!";
1998 float MapVote_Finished(float mappos)
2004 if(cvar("sv_eventlog"))
2006 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2007 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
2008 didntvote = mapvote_voters;
2009 for(i = 0; i < mapvote_count; ++i)
2010 if(mapvote_maps[i] != "")
2012 didntvote -= mapvote_votes[i];
2015 result = strcat(result, ":", mapvote_maps[i]);
2016 result = strcat(result, ":", ftos(mapvote_votes[i]));
2019 result = strcat(result, ":didn't vote:", ftos(didntvote));
2021 GameLogEcho(result, FALSE);
2022 if(mapvote_maps_suggested[mappos])
2023 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
2026 FOR_EACH_REALCLIENT(other)
2027 FixClientCvars(other);
2029 Map_Goto_SetStr(mapvote_maps[mappos]);
2031 alreadychangedlevel = TRUE;
2034 void MapVote_CheckRules_1()
2038 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2040 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2041 mapvote_votes[i] = 0;
2045 FOR_EACH_REALCLIENT(other)
2050 i = other.mapvote - 1;
2051 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2052 mapvote_votes[i] = mapvote_votes[i] + 1;
2057 float MapVote_CheckRules_2()
2060 float firstPlace, secondPlace;
2061 float firstPlaceVotes, secondPlaceVotes;
2062 float mapvote_voters_real;
2065 mapvote_voters_real = mapvote_voters;
2067 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2070 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2071 RandSel_Add(mapvote_votes[i], i);
2072 firstPlace = randsel_value;
2073 firstPlaceVotes = randsel_priority;
2074 //dprint("First place: ", ftos(firstPlace), "\n");
2075 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2078 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2080 RandSel_Add(mapvote_votes[i], i);
2081 secondPlace = randsel_value;
2082 secondPlaceVotes = randsel_priority;
2083 //dprint("Second place: ", ftos(secondPlace), "\n");
2084 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2086 if(firstPlace == -1)
2087 error("No first place in map vote... WTF?");
2089 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2090 return MapVote_Finished(firstPlace);
2092 if(mapvote_keeptwotime)
2093 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2096 mapvote_message = "Now decide between the TOP TWO!";
2097 mapvote_keeptwotime = 0;
2098 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2099 result = strcat(result, ":", ftos(firstPlaceVotes));
2100 result = strcat(result, ":", mapvote_maps[secondPlace]);
2101 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2102 didntvote = mapvote_voters;
2103 for(i = 0; i < mapvote_count; ++i)
2104 if(mapvote_maps[i] != "")
2106 didntvote -= mapvote_votes[i];
2108 if(i != secondPlace)
2110 result = strcat(result, ":", mapvote_maps[i]);
2111 result = strcat(result, ":", ftos(mapvote_votes[i]));
2112 if(i < mapvote_count_real)
2114 strunzone(mapvote_maps[i]);
2115 mapvote_maps[i] = "";
2119 result = strcat(result, ":didn't vote:", ftos(didntvote));
2120 if(cvar("sv_eventlog"))
2121 GameLogEcho(result, FALSE);
2134 keeptwo = mapvote_keeptwotime;
2135 MapVote_CheckRules_1(); // count
2136 if(MapVote_CheckRules_2()) // decide
2140 FOR_EACH_REALCLIENT(other)
2142 // hide scoreboard again
2143 if(other.health != 2342)
2145 other.health = 2342;
2147 if(clienttype(other) == CLIENTTYPE_REAL)
2149 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");
2151 WriteByte(MSG_ONE, SVC_FINALE);
2152 WriteString(MSG_ONE, "");
2156 // notify about keep-two
2157 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2158 play2(other, "misc/invshot.wav");
2160 // clear possibly invalid votes
2161 if(mapvote_maps[other.mapvote - 1] == "")
2163 // use impulses as new vote
2164 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2165 if(mapvote_maps[other.impulse - 1] != "")
2166 other.mapvote = other.impulse;
2173 MapVote_CheckRules_1(); // just count
2175 FOR_EACH_REALCLIENT(other)
2177 // display voting screen
2178 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2179 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2181 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2182 msgstr = strcat(msgstr, mapvote_message);
2183 msgstr = strcat(msgstr, "\n\n");
2184 for(i = 0; i < mapvote_count; ++i)
2185 if(mapvote_maps[i] == "")
2186 msgstr = strcat(msgstr, "\n");
2189 tmp = mapvote_maps[i];
2190 tmp = strpad(mapvote_maxlen, tmp);
2191 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2194 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2195 if(mapvote_votes[i] != 1)
2196 tmp = strcat(tmp, "s");
2197 tmp = strcat(tmp, ")");
2198 tmp = strpad(mapvote_maxlen + 15, tmp);
2201 if(i == mapvote_count - 1)
2202 msgstr = strcat(msgstr, "\n");
2203 if(other.mapvote == i + 1)
2204 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2206 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2209 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2211 msgstr = strcat(msgstr, "s");
2212 msgstr = strcat(msgstr, " cast");
2213 i = ceil(mapvote_timeout - time);
2214 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2216 msgstr = strcat(msgstr, "s");
2217 msgstr = strcat(msgstr, " left");
2219 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2222 void MapVote_Start()
2228 MapInfo_Enumerate();
2229 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2233 void MapVote_Think()
2238 if(alreadychangedlevel)
2241 if(time < mapvote_nextthink)
2245 mapvote_nextthink = time + 0.5;
2247 if(!mapvote_initialized)
2249 mapvote_initialized = TRUE;
2250 if(DoNextMapOverride())
2252 if(!cvar("g_maplist_votable") || player_count <= 0)
2263 string GotoMap(string m)
2266 if(!MapInfo_CheckMap(m))
2268 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2270 return "The map you chose is not available on this server.";
2271 cvar_set("nextmap", m);
2272 cvar_set("timelimit", "-1");
2273 if(mapvote_initialized || alreadychangedlevel)
2275 if(DoNextMapOverride())
2276 return "Map switch initiated.";
2278 return "Hm... no. For some reason I like THIS map more.";
2281 return "Map switch will happen after scoreboard.";
2287 FOR_EACH_REALCLIENT(self)
2289 if(self.classname == "spectator")
2291 if(self.enemy.hitsound)
2292 play2(self, "misc/hit.wav");
2297 play2(self, "misc/hit.wav");
2300 FOR_EACH_CLIENT(self)
2301 self.hitsound = FALSE;
2307 * returns TRUE if redirecting
2309 float redirection_timeout;
2310 float redirection_nextthink;
2311 float RedirectionThink()
2313 float clients_found;
2315 if(redirection_target == "")
2318 if(!redirection_timeout)
2320 cvar_set("sv_public", "-2");
2321 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2322 if(redirection_target == "self")
2323 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2325 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2328 if(time < redirection_nextthink)
2331 redirection_nextthink = time + 1;
2334 FOR_EACH_REALCLIENT(self)
2336 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2337 if(redirection_target == "self")
2338 stuffcmd(self, "\ndisconnect; reconnect\n");
2340 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2344 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2346 if(time > redirection_timeout || clients_found == 0)
2347 localcmd("\nwait; wait; wait; quit\n");
2354 if(world_initialized)
2356 world_initialized = 0;
2357 print("Saving persistent data...\n");
2360 db_save(ServerProgsDB, "server.db");
2362 // tell the bot system the game is ending now
2367 print("NOTE: crashed before even initializing the world, not saving persistent data\n");