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())
85 float world_already_spawned;
86 void worldspawn (void)
88 dprint_load(); // load dprint status from cvar
90 if(world_already_spawned)
91 error("world already spawned - you may have EXACTLY ONE worldspawn!");
92 world_already_spawned = TRUE;
95 MapInfo_LoadMapSettings(mapname);
98 ServerProgsDB = db_load("server.db");
101 TODO sound pack system
102 // initialize sound pack system
103 soundpack = cvar_string("g_soundpack");
105 soundpack = strcat(soundpack, "/");
106 soundpack = strzone(soundpack);
112 // 1 FLICKER (first variety)
113 lightstyle(1, "mmnmmommommnonmmonqnmmo");
115 // 2 SLOW STRONG PULSE
116 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
118 // 3 CANDLE (first variety)
119 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
122 lightstyle(4, "mamamamamama");
125 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
127 // 6 FLICKER (second variety)
128 lightstyle(6, "nmonqnmomnmomomno");
130 // 7 CANDLE (second variety)
131 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
133 // 8 CANDLE (third variety)
134 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
136 // 9 SLOW STROBE (fourth variety)
137 lightstyle(9, "aaaaaaaazzzzzzzz");
139 // 10 FLUORESCENT FLICKER
140 lightstyle(10, "mmamammmmammamamaaamammma");
142 // 11 SLOW PULSE NOT FADE TO BLACK
143 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
145 // styles 32-62 are assigned by the light program for switchable lights
150 // for setting by mapinfo
151 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
152 cvar_set("sv_q3acompat_machineshotgunswap", "0");
155 lms_lowest_lives = 0;
160 bot_waypoints_for_items = cvar("g_waypoints_for_items");
161 if(bot_waypoints_for_items == 1)
162 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
163 bot_waypoints_for_items = 0;
165 if(cvar("g_campaign"))
172 WaypointSprite_Init();
178 head = nextent(world);
183 head = nextent(head);
186 GameLogInit(); // prepare everything
187 if(cvar("sv_eventlog"))
190 GameLogEcho(":logversion:2", FALSE);
191 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
192 s = strcat(s, ftos(random()));
194 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s), FALSE);
196 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
198 s = ":gameinfo:mutators:LIST";
199 if(cvar("g_grappling_hook"))
200 s = strcat(s, ":grappling_hook");
201 if(!cvar("g_use_ammunition"))
202 s = strcat(s, ":no_use_ammunition");
203 if(!cvar("g_pickup_items"))
204 s = strcat(s, ":no_pickup_items");
205 if(cvar("g_instagib"))
206 s = strcat(s, ":instagib");
207 if(cvar("g_rocketarena"))
208 s = strcat(s, ":rockerarena");
210 s = strcat(s, ":nixnex");
211 if(cvar("g_vampire"))
212 s = strcat(s, ":vampire");
213 if(cvar("g_laserguided_missile"))
214 s = strcat(s, ":laserguided_missile");
215 if(cvar("g_norecoil"))
216 s = strcat(s, ":norecoil");
218 s = strcat(s, ":midair");
219 if(cvar("g_minstagib"))
220 s = strcat(s, ":minstagib");
221 GameLogEcho(s, FALSE);
222 GameLogEcho(":gameinfo:end", FALSE);
225 cvar_set("nextmap", "");
229 if(cvar("g_campaign"))
238 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
241 world_initialized = 1;
246 //makestatic (self); // Who the f___ did that?
250 float( string pFilename ) TryFile =
253 dprint("TryFile(\"", pFilename, "\")\n");
254 lHandle = fopen( pFilename, FILE_READ );
255 if( lHandle != -1 ) {
265 if (game == GAME_DEATHMATCH)
267 else if (game == GAME_TEAM_DEATHMATCH)
269 else if (game == GAME_DOMINATION)
271 else if (game == GAME_CTF)
273 else if (game == GAME_RUNEMATCH)
275 else if (game == GAME_LMS)
277 else if (game == GAME_KEYHUNT)
279 else if (game == GAME_ONSLAUGHT)
281 else if (game == GAME_ASSAULT)
286 float IsSameGametype(string mapcfgname)
289 return TRUE; // can't change game type by map name here
293 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
299 string getmapname_stored;
305 if(getmapname_stored == "")
306 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
307 return getmapname_stored;
311 float Map_Count, Map_Current;
312 string Map_Current_Name;
314 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
315 float GetMaplistPosition()
321 idx = cvar("g_maplist_index");
328 for(pos = 0; pos < Map_Count; ++pos)
332 // resume normal maplist rotation if current map is not in g_maplist
336 float MapHasRightSize(string map)
338 // open map size restriction file
340 dprint("opensize "); dprint(map);
341 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
344 float mapmin, mapmax;
346 mapmin = stof(fgets(fh));
347 mapmax = stof(fgets(fh));
349 if(player_count < mapmin)
351 dprint("not enough\n");
354 if(player_count > mapmax)
356 dprint("too many\n");
359 dprint("right size\n");
362 dprint(": not found\n");
366 string Map_Filename(float position)
369 return strcat("maps/", argv(position), ".bsp");
371 return strcat("maps/", argv(position), ".mapcfg");
375 string strwords(string s, float w)
378 for(endpos = 0; w && endpos >= 0; --w)
379 endpos = strstrofs(s, " ", endpos + 1);
383 return substring(s, 0, endpos);
386 float strhasword(string s, string w)
388 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
391 void Map_MarkAsRecent(string m)
393 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
396 float Map_IsRecent(string m)
398 return strhasword(cvar_string("g_maplist_mostrecent"), m);
401 float(float position, float pass) Map_Check =
405 map_next = argv(position);
408 if(map_next == Map_Current_Name) // same map again in first pass?
410 if(Map_IsRecent(map_next))
413 filename = Map_Filename(position);
415 if(MapInfo_CheckMap(map_next))
417 if(TryFile(filename))
422 if(MapHasRightSize(map_next))
427 dprint( "Couldn't find '", filename, "'..\n" );
432 void(string nextmapname) Map_Goto_SetStr =
434 if(getmapname_stored != "")
435 strunzone(getmapname_stored);
436 if(nextmapname == "")
437 getmapname_stored = "";
439 getmapname_stored = strzone(nextmapname);
442 void(float position) Map_Goto_SetFloat =
444 cvar_set("g_maplist_index", ftos(position));
445 Map_Goto_SetStr(argv(position));
448 void() GameResetCfg =
451 // settings persist, except...
452 if(cvar("g_campaign"))
453 localcmd("\nexec mutator_reset.cfg\n");
454 localcmd("\nsettemp_restore\n");
456 // if an exit cfg is defined by exiting map, exec it.
458 exit_cfg = cvar_string("exit_cfg");
460 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
462 localcmd("exec game_reset.cfg\n");
468 Map_MarkAsRecent(getmapname_stored);
471 MapInfo_LoadMap(getmapname_stored);
473 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
477 // return codes of map selectors:
478 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
479 // -2 = permanent failure
480 float() MaplistMethod_Iterate = // usual method
484 for(pass = 1; pass <= 2; ++pass)
486 for(i = 1; i < Map_Count; ++i)
489 mapindex = mod(i + Map_Current, Map_Count);
490 if(Map_Check(mapindex, pass))
497 float() MaplistMethod_Repeat = // fallback method
499 if(Map_Check(Map_Current, 2))
504 float() MaplistMethod_Random = // random map selection
510 for(i = 0; i <= imax; ++i)
513 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
514 if(Map_Check(mapindex, 1))
520 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
521 // the exponent sets a bias on the map selection:
522 // the higher the exponent, the less likely "shortly repeated" same maps are
524 float i, j, imax, insertpos;
528 for(i = 0; i <= imax; ++i)
532 // now reinsert this at another position
533 insertpos = pow(random(), 1 / exponent); // ]0, 1]
534 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
535 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
536 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
538 // insert the current map there
541 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
542 newlist = strcat(newlist, " ", argv(j));
543 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
544 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
545 newlist = strcat(newlist, " ", argv(j));
546 newlist = substring(newlist, 1, strlen(newlist) - 1);
548 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
549 newlist = strcat(newlist, "'", argv(j), "'");
550 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
551 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
552 newlist = strcat(newlist, "'", argv(j), "'");
554 cvar_set("g_maplist", newlist);
556 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
558 Map_Count = tokenize(newlist);
561 // NOTE: the selected map has just been inserted at (insertpos-1)th position
562 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
563 if(Map_Check(Map_Current, 1))
569 void() Maplist_Init =
572 temp = cvar_string("g_maplist");
574 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
576 Map_Count = tokenize(temp);
580 bprint( "Maplist is empty! Resetting it to default map list.\n" );
582 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
583 localcmd("\nmenu_cmd sync\n");
584 Map_Count = tokenizebyseparator(temp, " ");
586 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
587 Map_Count = tokenize(temp);
591 error("empty maplist, cannot select a new map");
592 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
594 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
595 // this may or may not be correct, but who cares, in the worst case a map
596 // isn't chosen in the first pass that should have been
599 string() GetNextMap =
607 if(cvar("g_maplist_shuffle") > 0)
608 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
611 if(cvar("g_maplist_selectrandom"))
612 nextMap = MaplistMethod_Random();
615 nextMap = MaplistMethod_Iterate();
618 nextMap = MaplistMethod_Repeat();
622 Map_Goto_SetFloat(nextMap);
623 return getmapname_stored;
629 float() DoNextMapOverride =
631 if(cvar("g_campaign"))
633 CampaignPostIntermission();
634 alreadychangedlevel = TRUE;
637 if(cvar("quit_when_empty"))
639 if(player_count <= currentbots)
642 alreadychangedlevel = TRUE;
646 if(cvar_string("quit_and_redirect") != "")
648 redirection_target = strzone(cvar_string("quit_and_redirect"));
649 alreadychangedlevel = TRUE;
652 if (cvar("samelevel")) // if samelevel is set, stay on same level
654 // 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)
655 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
656 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
657 localcmd("restart\n");
658 //changelevel (mapname);
659 alreadychangedlevel = TRUE;
662 if(cvar_string("nextmap") != "")
664 if(MapInfo_CheckMap(cvar_string("nextmap")))
666 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
669 Map_Goto_SetStr(cvar_string("nextmap"));
671 alreadychangedlevel = TRUE;
674 if(cvar("lastlevel"))
677 localcmd("set lastlevel 0\ntogglemenu\n");
678 alreadychangedlevel = TRUE;
686 //local string nextmap;
687 //local float n, nummaps;
689 if (alreadychangedlevel)
691 alreadychangedlevel = TRUE;
697 for(allowReset = 1; allowReset >= 0; --allowReset)
699 nextMap = GetNextMap();
705 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
707 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
708 localcmd("\nmenu_cmd sync\n");
710 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
715 error("Everything is broken - not even the default map list works. Please report this to the developers.");
727 When the player presses attack or jump, change to the next level
730 .float autoscreenshot;
731 void() MapVote_Start;
732 void() MapVote_Think;
733 float mapvote_initialized;
734 void() IntermissionThink =
736 FixIntermissionClient(self);
738 if(cvar("sv_autoscreenshot"))
739 if(self.autoscreenshot > 0)
740 if(time > self.autoscreenshot)
742 self.autoscreenshot = -1;
743 if(clienttype(self) == CLIENTTYPE_REAL)
744 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
748 if (time < intermission_exittime)
751 if(!mapvote_initialized)
752 if (time < intermission_exittime + 10 && !self.button0 && !self.button2 && !self.button3 && !self.button6 && !self.buttonuse)
762 Returns the entity to view from
766 entity() FindIntermission =
771 // look for info_intermission first
772 spot = find (world, classname, "info_intermission");
774 { // pick a random one
778 spot = find (spot, classname, "info_intermission");
780 spot = find (spot, classname, "info_intermission");
786 // then look for the start position
787 spot = find (world, classname, "info_player_start");
791 // testinfo_player_start is only found in regioned levels
792 spot = find (world, classname, "testplayerstart");
796 // then look for the start position
797 spot = find (world, classname, "info_player_deathmatch");
801 //objerror ("FindIntermission: no spot");
807 ===============================================================================
811 ===============================================================================
814 void(float final) DumpStats =
818 local float to_console;
819 local float to_eventlog;
822 to_console = cvar("sv_logscores_console");
823 to_eventlog = cvar("sv_eventlog");
824 to_file = cvar("sv_logscores_file");
828 to_console = TRUE; // always print printstats replies
829 to_eventlog = FALSE; // but never print them to the event log
833 if(cvar("sv_eventlog_console"))
834 to_console = FALSE; // otherwise we get the output twice
841 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
843 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
847 ServerConsoleEcho(s, FALSE);
849 GameLogEcho(s, FALSE);
852 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
856 fputs(file, strcat(s, "\n"));
859 FOR_EACH_CLIENT(other)
861 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
863 s = strcat(":player:", ftos(other.frags), ":");
864 s = strcat(s, ftos(other.deaths), ":");
865 s = strcat(s, ftos(rint(time - other.jointime)), ":");
866 s = strcat(s, ftos(other.team), ":");
869 ServerConsoleEcho(strcat(s, other.netname), TRUE);
871 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
873 fputs(file, strcat(s, other.netname, "\n"));
878 ServerConsoleEcho(":end", FALSE);
880 GameLogEcho(":end", FALSE);
883 fputs(file, ":end\n");
888 void FixIntermissionClient(entity e)
890 if(!e.autoscreenshot) // initial call
892 e.angles = e.v_angle;
893 e.angles_x = -e.angles_x;
894 e.autoscreenshot = time + 0.8; // used for autoscreenshot
896 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
898 e.movetype = MOVETYPE_NONE;
899 e.takedamage = DAMAGE_NO;
901 e.weaponentity.effects = EF_NODRAW;
902 stuffcmd(e, "\nscr_printspeed 1000000\n");
903 if(clienttype(e) == CLIENTTYPE_REAL)
906 WriteByte(MSG_ONE, SVC_INTERMISSION);
910 //e.velocity = '0 0 0';
913 // TODO halt weapon animation
918 go to the next level for deathmatch
919 only called if a time or frag limit has expired
930 intermission_running = 1;
932 // enforce a wait time before allowing changelevel
934 intermission_exittime = time + cvar("sv_mapchange_delay");
936 intermission_exittime = -1;
938 WriteByte (MSG_ALL, SVC_CDTRACK);
939 WriteByte (MSG_ALL, 3);
940 WriteByte (MSG_ALL, 3);
942 //pos = FindIntermission ();
948 if(cvar("sv_eventlog"))
949 GameLogEcho(":gameover", FALSE);
953 FOR_EACH_CLIENT(other)
955 FixIntermissionClient(other);
958 bprint(other.netname, " ^7wins.\n");
963 FOR_EACH_PLAYER(other)
965 if(maxTotalFrags < other.totalfrags)
966 maxTotalFrags = other.totalfrags;
967 if(minTotalFrags > other.totalfrags)
968 minTotalFrags = other.totalfrags;
973 FOR_EACH_PLAYER(other)
975 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
976 f = bound(0, other.play_time / max(time, 1), 1);
977 // store some statistics?
981 if(cvar("g_campaign"))
982 CampaignPreIntermission();
984 // WriteByte (MSG_ALL, SVC_INTERMISSION);
991 Exit deathmatch games upon conditions
994 void() CheckRules_Player =
996 if (gameover) // someone else quit the game already
999 if(self.deadflag == DEAD_NO)
1000 self.play_time += frametime;
1002 // fixme: don't check players; instead check dom_team and ctf_team entities
1003 // (div0: and that in CheckRules_World please)
1006 float checkrules_oneminutewarning;
1007 float checkrules_leaderfrags;
1008 float tdm_max_score, tdm_old_score;
1010 float checkrules_equality;
1011 float checkrules_overtimewarning;
1012 float checkrules_overtimeend;
1014 void() InitiateOvertime =
1016 if(!checkrules_overtimeend)
1017 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1020 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1021 float WINNING_YES = 1; // winner found
1022 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1023 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1025 float(float fraglimitreached, float equality) GetWinningCode =
1028 if(fraglimitreached)
1029 return WINNING_STARTOVERTIME;
1031 return WINNING_NEVER;
1033 if(fraglimitreached)
1039 // set the .winning flag for exactly those players with a given field value
1040 void(.float field, float value) SetWinners =
1043 FOR_EACH_PLAYER(head)
1044 head.winning = (head.field == value);
1047 // set the .winning flag for those players with a given field value
1048 void(.float field, float value) AddWinners =
1051 FOR_EACH_PLAYER(head)
1052 if(head.field == value)
1056 // clear the .winning flags
1057 void(void) ClearWinners =
1060 FOR_EACH_PLAYER(head)
1064 // Onslaught winning condition:
1065 // game terminates if only one team has a working generator (or none)
1066 float() WinningCondition_Onslaught =
1069 local float t1, t2, t3, t4;
1070 // first check if the game has ended
1071 t1 = t2 = t3 = t4 = 0;
1072 head = find(world, classname, "onslaught_generator");
1075 if (head.health > 0)
1077 if (head.team == COLOR_TEAM1) t1 = 1;
1078 if (head.team == COLOR_TEAM2) t2 = 1;
1079 if (head.team == COLOR_TEAM3) t3 = 1;
1080 if (head.team == COLOR_TEAM4) t4 = 1;
1082 head = find(head, classname, "onslaught_generator");
1084 if (t1 + t2 + t3 + t4 < 2)
1086 // game over, only one team remains (or none)
1088 if (t1) SetWinners(team, COLOR_TEAM1);
1089 if (t2) SetWinners(team, COLOR_TEAM2);
1090 if (t3) SetWinners(team, COLOR_TEAM3);
1091 if (t4) SetWinners(team, COLOR_TEAM4);
1092 dprint("Have a winner, ending game.\n");
1096 // Two or more teams remain
1100 float() LMS_NewPlayerLives =
1103 fl = cvar("fraglimit");
1107 // first player has left the game for dying too much? Nobody else can get in.
1108 if(lms_lowest_lives < 1)
1111 if(!cvar("g_lms_join_anytime"))
1112 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1115 return bound(1, lms_lowest_lives, fl);
1118 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1119 // they win. Otherwise the defending team wins once the timelimit passes.
1120 void assault_new_round();
1121 float() WinningCondition_Assault =
1124 status = WINNING_NO;
1126 // as the timelimit has not yet passed just assume the defending team will win
1127 if(assault_attacker_team == COLOR_TEAM1)
1129 SetWinners(team, COLOR_TEAM2);
1133 SetWinners(team, COLOR_TEAM1);
1137 ent = find(world, classname, "target_assault_roundend");
1140 if(ent.winning) // round end has been triggered by attacking team
1142 SetWinners(team, assault_attacker_team);
1143 if(assault_attacker_team == COLOR_TEAM1)
1145 team1_score = team1_score + 50;
1149 team2_score = team2_score + 50;
1152 if(ent.cnt == 1) // this was the second round
1154 status = WINNING_YES;
1158 cvar_set("timelimit", ftos((2*time)/60));
1159 assault_new_round();
1169 // LMS winning condition: game terminates if and only if there's at most one
1170 // one player who's living lives. Top two scores being equal cancels the time
1172 float() WinningCondition_LMS =
1179 have_player = FALSE;
1180 have_players = FALSE;
1181 l = LMS_NewPlayerLives();
1183 head = find(world, classname, "player");
1186 head = find(head, classname, "player");
1188 have_players = TRUE;
1192 // we have at least one player
1195 // two or more active players - continue with the game
1199 // exactly one player?
1202 // but no game has taken place yet
1207 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1208 dprint("Have a winner, ending game.\n");
1215 // nobody is playing at all...
1218 // wait for players...
1222 // SNAFU (maybe a draw game?)
1224 dprint("No players, ending game.\n");
1229 // When we get here, we have at least two players who are actually LIVING,
1230 // or one player who is still waiting for a victim to join the server. Now
1231 // check if the top two players have equal score.
1233 checkrules_leaderfrags = 0;
1234 checkrules_equality = FALSE;
1235 FOR_EACH_PLAYER(head)
1237 if(head.frags > checkrules_leaderfrags)
1239 checkrules_leaderfrags = head.frags;
1240 checkrules_equality = FALSE;
1242 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1243 checkrules_equality = TRUE;
1246 SetWinners(frags, checkrules_leaderfrags);
1248 // The top two players have the same amount of lives? No timelimit then,
1249 // enter overtime...
1251 if(checkrules_equality)
1252 return WINNING_NEVER;
1254 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1258 // DM winning condition: game terminates if a player reached the fraglimit,
1259 // unless the first two players have the same score. The latter case also
1260 // breaks the time limit.
1261 float(float fraglimit) WinningCondition_MaxIndividualScore =
1263 float checkrules_oldleaderfrags;
1266 checkrules_oldleaderfrags = checkrules_leaderfrags;
1267 checkrules_leaderfrags = 0;
1268 checkrules_equality = FALSE;
1269 FOR_EACH_PLAYER(head)
1271 if(head.frags > checkrules_leaderfrags)
1273 checkrules_leaderfrags = head.frags;
1274 checkrules_equality = FALSE;
1276 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1277 checkrules_equality = TRUE;
1280 if(checkrules_leaderfrags > 0)
1281 SetWinners(frags, checkrules_leaderfrags);
1286 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1288 if (checkrules_leaderfrags == fraglimit - 1)
1289 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1290 else if (checkrules_leaderfrags == fraglimit - 2)
1291 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1292 else if (checkrules_leaderfrags == fraglimit - 3)
1293 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1296 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1299 float(float fraglimit) WinningConditionBase_Teamplay =
1301 tdm_old_score = tdm_max_score;
1302 tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1304 checkrules_equality =
1309 (team1_score == tdm_max_score)
1310 + (team2_score == tdm_max_score)
1311 + (team3_score == tdm_max_score)
1312 + (team4_score == tdm_max_score)
1316 if(tdm_max_score > 0)
1318 if(team1_score == tdm_max_score)
1319 AddWinners(team, COLOR_TEAM1);
1320 if(team2_score == tdm_max_score)
1321 AddWinners(team, COLOR_TEAM2);
1322 if(team3_score == tdm_max_score)
1323 AddWinners(team, COLOR_TEAM3);
1324 if(team4_score == tdm_max_score)
1325 AddWinners(team, COLOR_TEAM4);
1328 if(!g_runematch && !g_domination)
1329 if(tdm_max_score != tdm_old_score)
1331 if(tdm_max_score == fraglimit - 1)
1332 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1333 else if(tdm_max_score == fraglimit - 2)
1334 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1335 else if(tdm_max_score == fraglimit - 3)
1336 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1339 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1342 // TDM winning condition: game terminates if a team's score sum reached the
1343 // fraglimit, unless the first two teams have the same total score. The latter
1344 // case also breaks the time limit.
1345 float(float fraglimit) WinningCondition_MaxTeamSum =
1349 team1_score = team2_score = team3_score = team4_score = 0;
1351 FOR_EACH_PLAYER(head)
1353 if(head.team == COLOR_TEAM1)
1354 team1_score += head.frags;
1355 else if(head.team == COLOR_TEAM2)
1356 team2_score += head.frags;
1357 else if(head.team == COLOR_TEAM3)
1358 team3_score += head.frags;
1359 else if(head.team == COLOR_TEAM4)
1360 team4_score += head.frags;
1363 return WinningConditionBase_Teamplay(fraglimit);
1366 // DOM/CTF winning condition: game terminates if the max of a team's players'
1367 // score reached the fraglimit, unless the first two teams have the same
1368 // maximum score. The latter case also breaks the time limit.
1369 float(float fraglimit) WinningCondition_MaxTeamMax =
1373 team1_score = team2_score = team3_score = team4_score = 0;
1375 FOR_EACH_PLAYER(head)
1377 if(head.team == COLOR_TEAM1)
1379 if(head.frags > team1_score)
1380 team1_score = head.frags;
1382 else if(head.team == COLOR_TEAM2)
1384 if(head.frags > team2_score)
1385 team2_score = head.frags;
1387 else if(head.team == COLOR_TEAM3)
1389 if(head.frags > team3_score)
1390 team3_score = head.frags;
1392 else if(head.team == COLOR_TEAM4)
1394 if(head.frags > team4_score)
1395 team4_score = head.frags;
1399 return WinningConditionBase_Teamplay(fraglimit);
1402 void print_to(entity e, string s)
1405 sprint(e, strcat(s, "\n"));
1407 ServerConsoleEcho(s, TRUE);
1410 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1420 FOR_EACH_PLAYER(head)
1422 if(!whichteam || head.team == whichteam)
1426 print_to(e, strcat(" ", colorcode, name, ":"));
1428 fragtotal = fragtotal + head.frags;
1429 s = ftos(head.frags);
1430 s = strcat(s, "/", ftos(head.deaths));
1431 s = strcat(s, " @ ", ftos(head.ping));
1432 if(clienttype(head) == CLIENTTYPE_BOT)
1433 s = strcat(s, "botms");
1435 s = strcat(s, "ms");
1436 v = PlayerValue(head);
1438 s = strcat(s, " / ", ftos(v));
1439 print_to(e, strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"));
1442 if(whichteam && found)
1444 s = ftos(fragtotal);
1445 s = strcat(s, " / ", ftos(teamvalue));
1446 print_to(e, strcat(colorcode, " (total: ", s, ")"));
1450 void PrintScoreboard(entity e)
1452 print_to(e, strcat("Time: ", ftos(time / 60)));
1453 print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1454 print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1455 print_to(e, "Scoreboard:");
1458 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1459 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1460 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM3);
1461 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM4);
1465 PrintScoreboardFor(e, "", "^7", 0);
1470 void ShuffleMaplist()
1478 result = cvar_string("g_maplist");
1480 litems = tokenizebyseparator(result, " ");
1482 litems = tokenize(result);
1485 for(start = 0; start < litems - 1; ++start)
1489 // select a random item
1490 selected = ceil(random() * (litems - start) + start) - 1;
1492 // shift this item to the place start
1494 for(i = 0; i < start; ++i)
1495 result = strcat(result, " ", argv(i));
1496 result = strcat(result, " ", argv(selected));
1497 for(i = start; i < litems; ++i)
1499 result = strcat(result, " ", argv(i));
1500 result = substring(result, 1, strlen(result) - 1);
1502 litems = tokenizebyseparator(result, " ");
1504 for(i = 0; i < start; ++i)
1505 result = strcat(result, "'", argv(i), "'");
1506 result = strcat(result, "'", argv(selected), "'");
1507 for(i = start; i < litems; ++i)
1509 result = strcat(result, "'", argv(i), "'");
1511 litems = tokenize(result);
1514 //dprint(result, "\n");
1517 cvar_set("g_maplist", result);
1524 Exit deathmatch games upon conditions
1527 void() CheckRules_World =
1530 local float timelimit;
1531 local float fraglimit;
1539 MapVote_Think should now do that part
1540 if (intermission_running)
1541 if (time >= intermission_exittime + 60)
1543 if(!DoNextMapOverride())
1549 if (gameover) // someone else quit the game already
1551 if(player_count == 0) // Nobody there? Then let's go to the next map
1553 // this will actually check the player count in the next frame
1554 // again, but this shouldn't hurt
1558 timelimit = cvar("timelimit") * 60;
1559 fraglimit = cvar("fraglimit");
1561 if(checkrules_overtimeend)
1563 if(!checkrules_overtimewarning)
1565 checkrules_overtimewarning = TRUE;
1566 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1567 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1572 if (timelimit && time >= timelimit)
1576 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1582 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1584 checkrules_oneminutewarning = TRUE;
1585 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1588 status = WINNING_NO;
1591 status = WinningCondition_Assault();
1595 status = WinningCondition_LMS();
1597 else if (g_onslaught)
1599 status = WinningCondition_Onslaught();
1605 if(g_tdm || g_runematch || g_ctf || g_domination || g_keyhunt)
1606 status = WinningCondition_MaxTeamSum(fraglimit);
1608 // status = WinningCondition_MaxTeamMax(fraglimit);
1611 dprint("div0: How can this happen?\n");
1612 status = WinningCondition_MaxTeamMax(fraglimit);
1616 status = WinningCondition_MaxIndividualScore(fraglimit);
1619 if(status == WINNING_STARTOVERTIME)
1621 status = WINNING_NEVER;
1625 if(status == WINNING_NEVER)
1626 // equality cases! Nobody wins if the overtime ends in a draw.
1629 if(checkrules_overtimeend)
1630 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1631 status = WINNING_YES;
1633 if(status == WINNING_YES)
1637 float randsel_value;
1638 float randsel_priority;
1639 float randsel_count;
1643 randsel_priority = -1;
1646 void RandSel_Add(float priority, float value)
1648 if(priority > randsel_priority)
1650 randsel_priority = priority;
1651 randsel_value = value;
1654 else if(priority == randsel_priority)
1657 if(ceil(random() * randsel_count) == 1)
1658 randsel_value = value;
1662 float mapvote_nextthink;
1663 float mapvote_initialized;
1664 float mapvote_keeptwotime;
1665 float mapvote_timeout;
1666 string mapvote_message;
1668 #define MAPVOTE_COUNT 10
1669 float mapvote_count;
1670 float mapvote_count_real;
1671 string mapvote_maps[MAPVOTE_COUNT];
1672 float mapvote_maps_suggested[MAPVOTE_COUNT];
1673 string mapvote_suggestions[MAPVOTE_COUNT];
1674 float mapvote_suggestion_ptr;
1675 float mapvote_maxlen;
1676 float mapvote_voters;
1677 float mapvote_votes[MAPVOTE_COUNT];
1679 float mapvote_detail;
1680 float mapvote_abstain;
1683 void MapVote_ClearAllVotes()
1685 FOR_EACH_CLIENT(other)
1689 string MapVote_Suggest(string m)
1693 return "That's not how to use this command.";
1694 if(!cvar("g_maplist_votable_suggestions"))
1695 return "Suggestions are not accepted on this server.";
1696 if(mapvote_initialized)
1697 return "Can't suggest - voting is already in progress!";
1699 m = MapInfo_FixName(m);
1701 return "The map you suggested is not available on this server.";
1703 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1704 if(!IsSameGametype(m))
1705 return "This server does not allow changing the game type by map suggestions.";
1706 if(!cvar("g_maplist_votable_override_mostrecent"))
1708 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1711 if(!MapInfo_CheckMap(m))
1712 return "The map you suggested does not support the current game mode.";
1714 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1715 return "The map you suggested is not available on this server.";
1717 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1718 if(mapvote_suggestions[i] == m)
1719 return "This map was already suggested.";
1720 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1722 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1726 i = mapvote_suggestion_ptr;
1727 mapvote_suggestion_ptr += 1;
1729 if(mapvote_suggestions[i] != "")
1730 strunzone(mapvote_suggestions[i]);
1731 mapvote_suggestions[i] = strzone(m);
1732 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid), ":", self.netname), TRUE);
1733 return strcat("Suggestion of ", m, " accepted.");
1736 void MapVote_AddVotable(string nextMap, float isSuggestion)
1741 for(j = 0; j < mapvote_count; ++j)
1742 if(mapvote_maps[j] == nextMap)
1744 if(strlen(nextMap) > mapvote_maxlen)
1745 mapvote_maxlen = strlen(nextMap);
1746 mapvote_maps[mapvote_count] = strzone(nextMap);
1747 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1756 MapVote_ClearAllVotes();
1759 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1760 mapvote_abstain = cvar("g_maplist_votable_abstain");
1763 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1765 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1766 smax = min(nmax, cvar("g_maplist_votable_suggestions"));
1768 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1769 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1771 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1772 MapVote_AddVotable(GetNextMap(), FALSE);
1774 if(mapvote_count == 0)
1776 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1778 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1779 localcmd("\nmenu_cmd sync\n");
1781 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1783 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1784 MapVote_AddVotable(GetNextMap(), FALSE);
1787 mapvote_count_real = mapvote_count;
1789 MapVote_AddVotable("don't care", 0);
1791 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1793 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1794 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1795 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1796 mapvote_keeptwotime = 0;
1797 mapvote_message = "Choose a map and press its key!";
1799 float MapVote_Finished(float mappos)
1805 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1806 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1807 didntvote = mapvote_voters;
1808 for(i = 0; i < mapvote_count; ++i)
1809 if(mapvote_maps[i] != "")
1811 didntvote -= mapvote_votes[i];
1814 result = strcat(result, ":", mapvote_maps[i]);
1815 result = strcat(result, ":", ftos(mapvote_votes[i]));
1818 result = strcat(result, ":didn't vote:", ftos(didntvote));
1820 GameLogEcho(result, FALSE);
1821 if(mapvote_maps_suggested[mappos])
1822 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
1824 FOR_EACH_REALCLIENT(other)
1825 FixClientCvars(other);
1827 Map_Goto_SetStr(mapvote_maps[mappos]);
1829 alreadychangedlevel = TRUE;
1832 void MapVote_CheckRules_1()
1836 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1838 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1839 mapvote_votes[i] = 0;
1843 FOR_EACH_REALCLIENT(other)
1848 i = other.mapvote - 1;
1849 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1850 mapvote_votes[i] = mapvote_votes[i] + 1;
1855 float MapVote_CheckRules_2()
1858 float firstPlace, secondPlace;
1859 float firstPlaceVotes, secondPlaceVotes;
1860 float mapvote_voters_real;
1863 mapvote_voters_real = mapvote_voters;
1865 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
1868 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1869 RandSel_Add(mapvote_votes[i], i);
1870 firstPlace = randsel_value;
1871 firstPlaceVotes = randsel_priority;
1872 //dprint("First place: ", ftos(firstPlace), "\n");
1873 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1876 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1878 RandSel_Add(mapvote_votes[i], i);
1879 secondPlace = randsel_value;
1880 secondPlaceVotes = randsel_priority;
1881 //dprint("Second place: ", ftos(secondPlace), "\n");
1882 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1884 if(firstPlace == -1)
1885 error("No first place in map vote... WTF?");
1887 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
1888 return MapVote_Finished(firstPlace);
1890 if(mapvote_keeptwotime)
1891 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
1894 mapvote_message = "Now decide between the TOP TWO!";
1895 mapvote_keeptwotime = 0;
1896 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
1897 result = strcat(result, ":", ftos(firstPlaceVotes));
1898 result = strcat(result, ":", mapvote_maps[secondPlace]);
1899 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
1900 didntvote = mapvote_voters;
1901 for(i = 0; i < mapvote_count; ++i)
1902 if(mapvote_maps[i] != "")
1904 didntvote -= mapvote_votes[i];
1906 if(i != secondPlace)
1908 result = strcat(result, ":", mapvote_maps[i]);
1909 result = strcat(result, ":", ftos(mapvote_votes[i]));
1910 if(i < mapvote_count_real)
1912 strunzone(mapvote_maps[i]);
1913 mapvote_maps[i] = "";
1917 result = strcat(result, ":didn't vote:", ftos(didntvote));
1918 GameLogEcho(result, FALSE);
1931 keeptwo = mapvote_keeptwotime;
1932 MapVote_CheckRules_1(); // count
1933 if(MapVote_CheckRules_2()) // decide
1937 FOR_EACH_REALCLIENT(other)
1939 // hide scoreboard again
1940 if(other.health != 2342)
1942 other.health = 2342;
1944 if(clienttype(other) == CLIENTTYPE_REAL)
1946 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");
1948 WriteByte(MSG_ONE, SVC_FINALE);
1949 WriteString(MSG_ONE, "");
1953 // notify about keep-two
1954 if(keeptwo != 0 && mapvote_keeptwotime == 0)
1955 play2(other, "misc/invshot.wav");
1957 // clear possibly invalid votes
1958 if(mapvote_maps[other.mapvote - 1] == "")
1960 // use impulses as new vote
1961 if(other.impulse >= 1 && other.impulse <= mapvote_count)
1962 if(mapvote_maps[other.impulse - 1] != "")
1963 other.mapvote = other.impulse;
1970 MapVote_CheckRules_1(); // just count
1972 FOR_EACH_REALCLIENT(other)
1974 // display voting screen
1975 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
1976 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
1978 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
1979 msgstr = strcat(msgstr, mapvote_message);
1980 msgstr = strcat(msgstr, "\n\n");
1981 for(i = 0; i < mapvote_count; ++i)
1982 if(mapvote_maps[i] == "")
1983 msgstr = strcat(msgstr, "\n");
1986 tmp = mapvote_maps[i];
1987 tmp = strpad(mapvote_maxlen, tmp);
1988 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
1991 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
1992 if(mapvote_votes[i] != 1)
1993 tmp = strcat(tmp, "s");
1994 tmp = strcat(tmp, ")");
1995 tmp = strpad(mapvote_maxlen + 15, tmp);
1998 if(i == mapvote_count - 1)
1999 msgstr = strcat(msgstr, "\n");
2000 if(other.mapvote == i + 1)
2001 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2003 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2006 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2008 msgstr = strcat(msgstr, "s");
2009 msgstr = strcat(msgstr, " cast");
2010 i = ceil(mapvote_timeout - time);
2011 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2013 msgstr = strcat(msgstr, "s");
2014 msgstr = strcat(msgstr, " left");
2016 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2019 void MapVote_Start()
2025 MapInfo_Enumerate();
2026 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2030 void MapVote_Think()
2035 if(alreadychangedlevel)
2038 if(time < mapvote_nextthink)
2042 mapvote_nextthink = time + 0.5;
2044 if(!mapvote_initialized)
2046 mapvote_initialized = TRUE;
2047 if(DoNextMapOverride())
2049 if(!cvar("g_maplist_votable") || player_count <= 0)
2060 string GotoMap(string m)
2063 if(!MapInfo_CheckMap(m))
2065 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2067 return "The map you chose is not available on this server.";
2068 cvar_set("nextmap", m);
2069 cvar_set("timelimit", "-1");
2070 if(mapvote_initialized || alreadychangedlevel)
2072 if(DoNextMapOverride())
2073 return "Map switch initiated.";
2075 return "Hm... no. For some reason I like THIS map more.";
2078 return "Map switch will happen after scoreboard.";
2084 FOR_EACH_REALCLIENT(self)
2086 if(self.classname == "spectator")
2088 if(self.enemy.hitsound)
2089 play2(self, "misc/hit.wav");
2094 play2(self, "misc/hit.wav");
2097 FOR_EACH_CLIENT(self)
2098 self.hitsound = FALSE;
2104 * returns TRUE if redirecting
2106 float redirection_timeout;
2107 float redirection_nextthink;
2108 float RedirectionThink()
2110 float clients_found;
2112 if(redirection_target == "")
2115 if(!redirection_timeout)
2117 cvar_set("sv_public", "-2");
2118 redirection_timeout = time + 0.5; // this will only try twice... should be able to keep more clients
2119 if(redirection_target == "self")
2120 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2122 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2125 if(time < redirection_nextthink)
2128 redirection_nextthink = time + 1;
2131 FOR_EACH_REALCLIENT(self)
2133 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2134 if(redirection_target == "self")
2135 stuffcmd(self, "\ndisconnect; reconnect\n");
2137 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2141 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2143 if(time > redirection_timeout || clients_found == 0)
2144 localcmd("\nwait; wait; wait; quit\n");
2151 if(world_initialized)
2153 world_initialized = 0;
2154 print("Saving persistent data...\n");
2156 db_save(ServerProgsDB, "server.db");
2161 print("NOTE: crashed before even initializing the world, not saving persistent data\n");