1 float SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS = 1;
2 string redirection_target;
3 float world_initialized;
9 float() DoNextMapOverride;
13 void SetDefaultAlpha()
15 if(cvar("g_running_guns"))
17 default_player_alpha = -1;
18 default_weapon_alpha = +1;
22 default_player_alpha = cvar("g_balance_cloaked_alpha");
23 default_weapon_alpha = default_player_alpha;
27 default_player_alpha = cvar("g_player_alpha");
28 if(default_player_alpha <= 0)
29 default_player_alpha = 1;
30 default_weapon_alpha = default_player_alpha;
34 void fteqcc_testbugs()
38 if(!cvar("developer_fteqccbugs"))
41 dprint("*** fteqcc test: checking for bugs...\n");
45 if(sqrt(a) - sqrt(b - a) == 0)
46 dprint("*** fteqcc test: found same-function-twice bug\n");
48 dprint("*** fteqcc test: same-function-twice bug got FINALLY FIXED! HOORAY!\n");
52 world.enemy.frags += 10;
53 if(world.frags > 0.2 || world.frags < -0.2) // don't error out if it's just roundoff errors
54 dprint("*** fteqcc test: found += bug\n");
56 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
61 * Takes care of pausing and unpausing the game.
62 * Centerprints the information about an upcoming or active timeout to all active
63 * players. Also plays reminder sounds.
65 void timeoutHandler_Think() {
68 if (timeoutStatus == 1) {
69 if (remainingLeadTime > 0) {
70 //centerprint the information to every player
71 timeStr = getTimeoutText(0);
72 FOR_EACH_REALCLIENT(plr) {
73 if(plr.classname == "player") {
74 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
77 remainingLeadTime -= 1;
78 //think again in 1 second:
79 self.nextthink = time + 1;
84 cvar_set("slowmo", ftos(TIMEOUT_SLOWMO_VALUE));
85 //copy .v_angle to .lastV_angle for every player in order to fix their view during pause (see PlayerPreThink)
86 FOR_EACH_REALPLAYER(plr) {
87 plr.lastV_angle = plr.v_angle;
89 self.nextthink = time;
92 else if (timeoutStatus == 2) {
93 if (remainingTimeoutTime > 0) {
94 timeStr = getTimeoutText(0);
95 FOR_EACH_REALCLIENT(plr) {
96 if(plr.classname == "player") {
97 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
100 if(remainingTimeoutTime == cvar("sv_timeout_resumetime")) { //play a warning sound when only <sv_timeout_resumetime> seconds are left
101 sound(world, CHAN_AUTO, "announcer/robotic/prepareforbattle.wav", 1, ATTN_NONE);
103 remainingTimeoutTime -= 1;
104 self.nextthink = time + TIMEOUT_SLOWMO_VALUE;
107 //unpause the game again
108 remainingTimeoutTime = timeoutStatus = 0;
109 cvar_set("slowmo", ftos(orig_slowmo));
110 //and unlock the fixed view again once there is no timeout active anymore
111 FOR_EACH_REALPLAYER(plr) {
112 plr.fixangle = FALSE;
114 //get rid of the countdown message
115 FOR_EACH_REALCLIENT(plr) {
116 if(plr.classname == "player") {
117 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
125 else if (timeoutStatus == 0) { //if a player called the resumegame command (which set timeoutStatus to 0 already)
126 FOR_EACH_REALCLIENT(plr) {
127 if(plr.classname == "player") {
128 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
140 cvar_set("_sv_init", "0");
141 if(cvar("g_maplist_shuffle"))
144 tokenizebyseparator(cvar_string("g_maplist"), " ");
146 tokenize(cvar_string("g_maplist"));
147 if(argv(0) != GetMapname())
150 cvar_set("nextmap", argv(0));
154 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
157 if(!DoNextMapOverride())
166 float world_already_spawned;
167 void spawnfunc_worldspawn (void)
172 dprint_load(); // load dprint status from cvar
174 if(world_already_spawned)
175 error("world already spawned - you may have EXACTLY ONE worldspawn!");
176 world_already_spawned = TRUE;
182 MapInfo_LoadMapSettings(mapname);
186 ServerProgsDB = db_create();
188 ServerProgsDB = db_load("server.db");
191 TODO sound pack system
192 // initialize sound pack system
193 soundpack = cvar_string("g_soundpack");
195 soundpack = strcat(soundpack, "/");
196 soundpack = strzone(soundpack);
202 // 1 FLICKER (first variety)
203 lightstyle(1, "mmnmmommommnonmmonqnmmo");
205 // 2 SLOW STRONG PULSE
206 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
208 // 3 CANDLE (first variety)
209 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
212 lightstyle(4, "mamamamamama");
215 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
217 // 6 FLICKER (second variety)
218 lightstyle(6, "nmonqnmomnmomomno");
220 // 7 CANDLE (second variety)
221 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
223 // 8 CANDLE (third variety)
224 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
226 // 9 SLOW STROBE (fourth variety)
227 lightstyle(9, "aaaaaaaazzzzzzzz");
229 // 10 FLUORESCENT FLICKER
230 lightstyle(10, "mmamammmmammamamaaamammma");
232 // 11 SLOW PULSE NOT FADE TO BLACK
233 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
235 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
240 // for setting by mapinfo
241 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
242 cvar_set("sv_q3acompat_machineshotgunswap", "0");
245 lms_lowest_lives = 0;
248 bot_waypoints_for_items = cvar("g_waypoints_for_items");
249 if(bot_waypoints_for_items == 1)
250 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
251 bot_waypoints_for_items = 0;
253 if(cvar("g_campaign"))
260 WaypointSprite_Init();
266 head = nextent(world);
271 head = nextent(head);
274 GameLogInit(); // prepare everything
275 if(cvar("sv_eventlog"))
277 GameLogEcho(":logversion:2", FALSE);
278 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
279 s = strcat(s, ftos(random()));
281 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s), FALSE);
283 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
285 s = ":gameinfo:mutators:LIST";
286 if(cvar("g_grappling_hook"))
287 s = strcat(s, ":grappling_hook");
288 if(!cvar("g_use_ammunition"))
289 s = strcat(s, ":no_use_ammunition");
290 if(!cvar("g_pickup_items"))
291 s = strcat(s, ":no_pickup_items");
292 if(cvar("g_instagib"))
293 s = strcat(s, ":instagib");
294 if(cvar("g_rocketarena"))
295 s = strcat(s, ":rockerarena");
297 s = strcat(s, ":nixnex");
298 if(cvar("g_vampire"))
299 s = strcat(s, ":vampire");
300 if(cvar("g_laserguided_missile"))
301 s = strcat(s, ":laserguided_missile");
302 if(cvar("g_norecoil"))
303 s = strcat(s, ":norecoil");
305 s = strcat(s, ":midair");
306 if(cvar("g_minstagib"))
307 s = strcat(s, ":minstagib");
308 GameLogEcho(s, FALSE);
309 GameLogEcho(":gameinfo:end", FALSE);
312 cvar_set("nextmap", "");
316 if(cvar("g_campaign"))
323 //initialise globals related to sv_timeout
324 sys_ticrate = cvar("sys_ticrate");
325 orig_slowmo = cvar("slowmo");
329 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
332 //if tourney is used map starts in warmup mode. if this mode shall stay unlimited, reset timelimit, but save the original one
333 if(g_tourney && cvar("g_tourney_warmup_unlimited_time")) {
334 timelimit_orig = cvar("timelimit");
335 cvar_set("timelimit", "0");
338 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
341 while((s = fgets(fd)))
352 s = strcat(argv(l), " ", s);
354 s = substring(s, 0, strlen(s) - 1);
355 print("Found ^1DEPRECATED^7 fog command in .cfg file: ", s, "\n");
356 world.fog = strzone(s);
361 world_initialized = 1;
364 void spawnfunc_light (void)
366 //makestatic (self); // Who the f___ did that?
370 float( string pFilename ) TryFile =
373 dprint("TryFile(\"", pFilename, "\")\n");
374 lHandle = fopen( pFilename, FILE_READ );
375 if( lHandle != -1 ) {
385 if (game == GAME_DEATHMATCH)
387 else if (game == GAME_TEAM_DEATHMATCH)
389 else if (game == GAME_DOMINATION)
391 else if (game == GAME_CTF)
393 else if (game == GAME_RUNEMATCH)
395 else if (game == GAME_LMS)
397 else if (game == GAME_KEYHUNT)
399 else if (game == GAME_ONSLAUGHT)
401 else if (game == GAME_ASSAULT)
406 float IsSameGametype(string mapcfgname)
409 return TRUE; // can't change game type by map name here
413 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
419 string getmapname_stored;
425 if(getmapname_stored == "")
426 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
427 return getmapname_stored;
431 float Map_Count, Map_Current;
432 string Map_Current_Name;
434 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
435 float GetMaplistPosition()
441 idx = cvar("g_maplist_index");
448 for(pos = 0; pos < Map_Count; ++pos)
452 // resume normal maplist rotation if current map is not in g_maplist
456 float MapHasRightSize(string map)
459 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
460 if(cvar("g_maplist_check_waypoints"))
462 dprint("checkwp "); dprint(map);
463 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
466 dprint(": no waypoints\n");
469 dprint(": has waypoints\n");
473 // open map size restriction file
474 dprint("opensize "); dprint(map);
475 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
478 float mapmin, mapmax;
480 mapmin = stof(fgets(fh));
481 mapmax = stof(fgets(fh));
483 if(player_count < mapmin)
485 dprint("not enough\n");
488 if(player_count > mapmax)
490 dprint("too many\n");
493 dprint("right size\n");
496 dprint(": not found\n");
500 string Map_Filename(float position)
503 return strcat("maps/", argv(position), ".bsp");
505 return strcat("maps/", argv(position), ".mapcfg");
509 string strwords(string s, float w)
512 for(endpos = 0; w && endpos >= 0; --w)
513 endpos = strstrofs(s, " ", endpos + 1);
517 return substring(s, 0, endpos);
520 float strhasword(string s, string w)
522 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
525 void Map_MarkAsRecent(string m)
527 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
530 float Map_IsRecent(string m)
532 return strhasword(cvar_string("g_maplist_mostrecent"), m);
535 float(float position, float pass) Map_Check =
539 map_next = argv(position);
542 if(map_next == Map_Current_Name) // same map again in first pass?
544 if(Map_IsRecent(map_next))
547 filename = Map_Filename(position);
549 if(MapInfo_CheckMap(map_next))
551 if(TryFile(filename))
556 if(MapHasRightSize(map_next))
561 dprint( "Couldn't select '", filename, "'..\n" );
566 void(string nextmapname) Map_Goto_SetStr =
568 if(getmapname_stored != "")
569 strunzone(getmapname_stored);
570 if(nextmapname == "")
571 getmapname_stored = "";
573 getmapname_stored = strzone(nextmapname);
576 void(float position) Map_Goto_SetFloat =
578 cvar_set("g_maplist_index", ftos(position));
579 Map_Goto_SetStr(argv(position));
582 void() GameResetCfg =
585 // settings persist, except...
586 if(cvar("g_campaign"))
587 localcmd("\nexec mutator_reset.cfg\n");
588 localcmd("\nsettemp_restore\n");
590 // if an exit cfg is defined by exiting map, exec it.
592 exit_cfg = cvar_string("exit_cfg");
594 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
596 localcmd("exec game_reset.cfg\n");
602 Map_MarkAsRecent(getmapname_stored);
605 MapInfo_LoadMap(getmapname_stored);
607 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
611 // return codes of map selectors:
612 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
613 // -2 = permanent failure
614 float() MaplistMethod_Iterate = // usual method
618 for(pass = 1; pass <= 2; ++pass)
620 for(i = 1; i < Map_Count; ++i)
623 mapindex = mod(i + Map_Current, Map_Count);
624 if(Map_Check(mapindex, pass))
631 float() MaplistMethod_Repeat = // fallback method
633 if(Map_Check(Map_Current, 2))
638 float() MaplistMethod_Random = // random map selection
644 for(i = 0; i <= imax; ++i)
647 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
648 if(Map_Check(mapindex, 1))
654 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
655 // the exponent sets a bias on the map selection:
656 // the higher the exponent, the less likely "shortly repeated" same maps are
658 float i, j, imax, insertpos;
662 for(i = 0; i <= imax; ++i)
666 // now reinsert this at another position
667 insertpos = pow(random(), 1 / exponent); // ]0, 1]
668 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
669 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
670 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
672 // insert the current map there
675 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
676 newlist = strcat(newlist, " ", argv(j));
677 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
678 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
679 newlist = strcat(newlist, " ", argv(j));
680 newlist = substring(newlist, 1, strlen(newlist) - 1);
682 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
683 newlist = strcat(newlist, "'", argv(j), "'");
684 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
685 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
686 newlist = strcat(newlist, "'", argv(j), "'");
688 cvar_set("g_maplist", newlist);
690 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
692 Map_Count = tokenize(newlist);
695 // NOTE: the selected map has just been inserted at (insertpos-1)th position
696 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
697 if(Map_Check(Map_Current, 1))
703 void() Maplist_Init =
706 temp = cvar_string("g_maplist");
708 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
710 Map_Count = tokenize(temp);
714 bprint( "Maplist is empty! Resetting it to default map list.\n" );
716 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
717 localcmd("\nmenu_cmd sync\n");
718 Map_Count = tokenizebyseparator(temp, " ");
720 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
721 Map_Count = tokenize(temp);
725 error("empty maplist, cannot select a new map");
726 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
728 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
729 // this may or may not be correct, but who cares, in the worst case a map
730 // isn't chosen in the first pass that should have been
733 string() GetNextMap =
741 if(cvar("g_maplist_shuffle") > 0)
742 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
745 if(cvar("g_maplist_selectrandom"))
746 nextMap = MaplistMethod_Random();
749 nextMap = MaplistMethod_Iterate();
752 nextMap = MaplistMethod_Repeat();
756 Map_Goto_SetFloat(nextMap);
757 return getmapname_stored;
763 float() DoNextMapOverride =
765 if(cvar("g_campaign"))
767 CampaignPostIntermission();
768 alreadychangedlevel = TRUE;
771 if(cvar("quit_when_empty"))
773 if(player_count <= currentbots)
776 alreadychangedlevel = TRUE;
780 if(cvar_string("quit_and_redirect") != "")
782 redirection_target = strzone(cvar_string("quit_and_redirect"));
783 alreadychangedlevel = TRUE;
786 if (cvar("samelevel")) // if samelevel is set, stay on same level
788 // 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)
789 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
790 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
791 localcmd("restart\n");
792 //changelevel (mapname);
793 alreadychangedlevel = TRUE;
796 if(cvar_string("nextmap") != "")
798 if(MapInfo_CheckMap(cvar_string("nextmap")))
800 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
803 Map_Goto_SetStr(cvar_string("nextmap"));
805 alreadychangedlevel = TRUE;
808 if(cvar("lastlevel"))
811 localcmd("set lastlevel 0\ntogglemenu\n");
812 alreadychangedlevel = TRUE;
820 //local string nextmap;
821 //local float n, nummaps;
823 if (alreadychangedlevel)
825 alreadychangedlevel = TRUE;
831 for(allowReset = 1; allowReset >= 0; --allowReset)
833 nextMap = GetNextMap();
839 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
841 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
842 localcmd("\nmenu_cmd sync\n");
844 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
849 error("Everything is broken - not even the default map list works. Please report this to the developers.");
861 When the player presses attack or jump, change to the next level
864 .float autoscreenshot;
865 void() MapVote_Start;
866 void() MapVote_Think;
867 float mapvote_initialized;
868 void() IntermissionThink =
870 FixIntermissionClient(self);
872 if(cvar("sv_autoscreenshot"))
873 if(self.autoscreenshot > 0)
874 if(time > self.autoscreenshot)
876 self.autoscreenshot = -1;
877 if(clienttype(self) == CLIENTTYPE_REAL)
878 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
882 if (time < intermission_exittime)
885 if(!mapvote_initialized)
886 if (time < intermission_exittime + 10 && !self.button0 && !self.button2 && !self.button3 && !self.button6 && !self.buttonuse)
896 Returns the entity to view from
900 entity() FindIntermission =
905 // look for info_intermission first
906 spot = find (world, classname, "info_intermission");
908 { // pick a random one
912 spot = find (spot, classname, "info_intermission");
914 spot = find (spot, classname, "info_intermission");
920 // then look for the start position
921 spot = find (world, classname, "info_player_start");
925 // testinfo_player_start is only found in regioned levels
926 spot = find (world, classname, "testplayerstart");
930 // then look for the start position
931 spot = find (world, classname, "info_player_deathmatch");
935 //objerror ("FindIntermission: no spot");
941 ===============================================================================
945 ===============================================================================
948 void(float final) DumpStats =
952 local float to_console;
953 local float to_eventlog;
956 to_console = cvar("sv_logscores_console");
957 to_eventlog = cvar("sv_eventlog");
958 to_file = cvar("sv_logscores_file");
962 to_console = TRUE; // always print printstats replies
963 to_eventlog = FALSE; // but never print them to the event log
967 if(cvar("sv_eventlog_console"))
968 to_console = FALSE; // otherwise we get the output twice
975 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
977 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
981 ServerConsoleEcho(s, FALSE);
983 GameLogEcho(s, FALSE);
986 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
990 fputs(file, strcat(s, "\n"));
993 FOR_EACH_CLIENT(other)
995 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
997 s = strcat(":player:", ftos(other.frags), ":");
998 s = strcat(s, ftos(other.deaths), ":");
999 s = strcat(s, ftos(rint(time - other.jointime)), ":");
1000 s = strcat(s, ftos(other.team), ":");
1003 ServerConsoleEcho(strcat(s, other.netname), TRUE);
1005 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
1007 fputs(file, strcat(s, other.netname, "\n"));
1012 ServerConsoleEcho(":end", FALSE);
1014 GameLogEcho(":end", FALSE);
1017 fputs(file, ":end\n");
1022 void FixIntermissionClient(entity e)
1025 if(!e.autoscreenshot) // initial call
1027 e.angles = e.v_angle;
1028 e.angles_x = -e.angles_x;
1029 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1031 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1032 e.solid = SOLID_NOT;
1033 e.movetype = MOVETYPE_NONE;
1034 e.takedamage = DAMAGE_NO;
1036 e.weaponentity.effects = EF_NODRAW;
1037 if(clienttype(e) == CLIENTTYPE_REAL)
1039 stuffcmd(e, "\nscr_printspeed 1000000\n");
1040 s = cvar_string("sv_intermission_cdtrack");
1042 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1044 WriteByte(MSG_ONE, SVC_INTERMISSION);
1048 //e.velocity = '0 0 0';
1049 //e.fixangle = TRUE;
1051 // TODO halt weapon animation
1056 go to the next level for deathmatch
1057 only called if a time or frag limit has expired
1061 float minTotalFrags;
1062 float maxTotalFrags;
1068 intermission_running = 1;
1070 // enforce a wait time before allowing changelevel
1071 if(player_count > 0)
1072 intermission_exittime = time + cvar("sv_mapchange_delay");
1074 intermission_exittime = -1;
1077 WriteByte (MSG_ALL, SVC_CDTRACK);
1078 WriteByte (MSG_ALL, 3);
1079 WriteByte (MSG_ALL, 3);
1080 // done in FixIntermission
1083 //pos = FindIntermission ();
1089 if(cvar("sv_eventlog"))
1090 GameLogEcho(":gameover", FALSE);
1094 FOR_EACH_CLIENT(other)
1096 FixIntermissionClient(other);
1099 bprint(other.netname, " ^7wins.\n");
1104 FOR_EACH_PLAYER(other)
1106 if(maxTotalFrags < other.totalfrags)
1107 maxTotalFrags = other.totalfrags;
1108 if(minTotalFrags > other.totalfrags)
1109 minTotalFrags = other.totalfrags;
1114 FOR_EACH_PLAYER(other)
1116 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1117 f = bound(0, other.play_time / max(time, 1), 1);
1118 // store some statistics?
1122 if(cvar("g_campaign"))
1123 CampaignPreIntermission();
1125 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1132 Exit deathmatch games upon conditions
1136 void() CheckRules_Player =
1138 if (gameover) // someone else quit the game already
1141 if(self.deadflag == DEAD_NO)
1142 self.play_time += frametime;
1146 if(time > self.fogtime)
1148 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1149 self.fogtime = time + sv_foginterval;
1152 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1153 // (div0: and that in CheckRules_World please)
1156 float checkrules_oneminutewarning;
1157 float checkrules_leaderfrags;
1158 float tdm_max_score, tdm_old_score;
1160 float checkrules_equality;
1161 float checkrules_overtimewarning;
1162 float checkrules_overtimeend;
1164 void() InitiateOvertime =
1166 if(!checkrules_overtimeend)
1167 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1170 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1171 float WINNING_YES = 1; // winner found
1172 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1173 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1175 float(float fraglimitreached, float equality) GetWinningCode =
1178 if(fraglimitreached)
1179 return WINNING_STARTOVERTIME;
1181 return WINNING_NEVER;
1183 if(fraglimitreached)
1189 // set the .winning flag for exactly those players with a given field value
1190 void(.float field, float value) SetWinners =
1193 FOR_EACH_PLAYER(head)
1194 head.winning = (head.field == value);
1197 // set the .winning flag for those players with a given field value
1198 void(.float field, float value) AddWinners =
1201 FOR_EACH_PLAYER(head)
1202 if(head.field == value)
1206 // clear frags for all players but the team given (when they ran out of spawnpoints)
1207 void(.float field, float value) ClearFragsForEveryoneBut =
1210 FOR_EACH_PLAYER(head)
1211 if(head.field != value)
1212 head.frags = max(head.frags, 0);
1215 // clear the .winning flags
1216 void(void) ClearWinners =
1219 FOR_EACH_PLAYER(head)
1223 // Onslaught winning condition:
1224 // game terminates if only one team has a working generator (or none)
1225 float() WinningCondition_Onslaught =
1228 local float t1, t2, t3, t4;
1229 // first check if the game has ended
1230 t1 = t2 = t3 = t4 = 0;
1231 head = find(world, classname, "onslaught_generator");
1234 if (head.health > 0)
1236 if (head.team == COLOR_TEAM1) t1 = 1;
1237 if (head.team == COLOR_TEAM2) t2 = 1;
1238 if (head.team == COLOR_TEAM3) t3 = 1;
1239 if (head.team == COLOR_TEAM4) t4 = 1;
1241 head = find(head, classname, "onslaught_generator");
1243 if (t1 + t2 + t3 + t4 < 2)
1245 // game over, only one team remains (or none)
1247 if (t1) SetWinners(team, COLOR_TEAM1);
1248 if (t2) SetWinners(team, COLOR_TEAM2);
1249 if (t3) SetWinners(team, COLOR_TEAM3);
1250 if (t4) SetWinners(team, COLOR_TEAM4);
1251 dprint("Have a winner, ending game.\n");
1255 // Two or more teams remain
1259 float() LMS_NewPlayerLives =
1262 fl = cvar("fraglimit");
1266 // first player has left the game for dying too much? Nobody else can get in.
1267 if(lms_lowest_lives < 1)
1270 if(!cvar("g_lms_join_anytime"))
1271 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1274 return bound(1, lms_lowest_lives, fl);
1277 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1278 // they win. Otherwise the defending team wins once the timelimit passes.
1279 void assault_new_round();
1280 float() WinningCondition_Assault =
1283 status = WINNING_NO;
1285 // as the timelimit has not yet passed just assume the defending team will win
1286 if(assault_attacker_team == COLOR_TEAM1)
1288 SetWinners(team, COLOR_TEAM2);
1292 SetWinners(team, COLOR_TEAM1);
1296 ent = find(world, classname, "target_assault_roundend");
1299 if(ent.winning) // round end has been triggered by attacking team
1301 SetWinners(team, assault_attacker_team);
1302 if(assault_attacker_team == COLOR_TEAM1)
1304 team1_score = team1_score + 50;
1308 team2_score = team2_score + 50;
1311 if(ent.cnt == 1) // this was the second round
1313 status = WINNING_YES;
1317 cvar_set("timelimit", ftos((2*time)/60));
1318 assault_new_round();
1328 // LMS winning condition: game terminates if and only if there's at most one
1329 // one player who's living lives. Top two scores being equal cancels the time
1331 float() WinningCondition_LMS =
1338 have_player = FALSE;
1339 have_players = FALSE;
1340 l = LMS_NewPlayerLives();
1342 head = find(world, classname, "player");
1345 head = find(head, classname, "player");
1347 have_players = TRUE;
1351 // we have at least one player
1354 // two or more active players - continue with the game
1358 // exactly one player?
1361 // but no game has taken place yet
1366 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1367 dprint("Have a winner, ending game.\n");
1374 // nobody is playing at all...
1377 // wait for players...
1381 // SNAFU (maybe a draw game?)
1383 dprint("No players, ending game.\n");
1388 // When we get here, we have at least two players who are actually LIVING,
1389 // or one player who is still waiting for a victim to join the server. Now
1390 // check if the top two players have equal score.
1392 checkrules_leaderfrags = 0;
1393 checkrules_equality = FALSE;
1394 FOR_EACH_PLAYER(head)
1396 if(head.frags > checkrules_leaderfrags)
1398 checkrules_leaderfrags = head.frags;
1399 checkrules_equality = FALSE;
1401 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1402 checkrules_equality = TRUE;
1405 SetWinners(frags, checkrules_leaderfrags);
1407 // The top two players have the same amount of lives? No timelimit then,
1408 // enter overtime...
1410 if(checkrules_equality)
1411 return WINNING_NEVER;
1413 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1417 // DM winning condition: game terminates if a player reached the fraglimit,
1418 // unless the first two players have the same score. The latter case also
1419 // breaks the time limit.
1420 float(float fraglimit) WinningCondition_MaxIndividualScore =
1422 float checkrules_oldleaderfrags;
1425 checkrules_oldleaderfrags = checkrules_leaderfrags;
1426 checkrules_leaderfrags = 0;
1427 checkrules_equality = FALSE;
1428 FOR_EACH_PLAYER(head)
1430 if(head.frags > checkrules_leaderfrags)
1432 checkrules_leaderfrags = head.frags;
1433 checkrules_equality = FALSE;
1435 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1436 checkrules_equality = TRUE;
1439 if(checkrules_leaderfrags > 0)
1440 SetWinners(frags, checkrules_leaderfrags);
1445 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1447 if (checkrules_leaderfrags == fraglimit - 1)
1448 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1449 else if (checkrules_leaderfrags == fraglimit - 2)
1450 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1451 else if (checkrules_leaderfrags == fraglimit - 3)
1452 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1455 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1458 float(float fraglimit) WinningConditionBase_Teamplay =
1460 tdm_old_score = tdm_max_score;
1461 tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1463 checkrules_equality =
1468 (team1_score == tdm_max_score)
1469 + (team2_score == tdm_max_score)
1470 + (team3_score == tdm_max_score)
1471 + (team4_score == tdm_max_score)
1475 if(tdm_max_score > 0)
1477 if(team1_score == tdm_max_score)
1478 AddWinners(team, COLOR_TEAM1);
1479 if(team2_score == tdm_max_score)
1480 AddWinners(team, COLOR_TEAM2);
1481 if(team3_score == tdm_max_score)
1482 AddWinners(team, COLOR_TEAM3);
1483 if(team4_score == tdm_max_score)
1484 AddWinners(team, COLOR_TEAM4);
1487 if(!g_runematch && !g_domination)
1488 if(tdm_max_score != tdm_old_score)
1490 if(tdm_max_score == fraglimit - 1)
1491 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1492 else if(tdm_max_score == fraglimit - 2)
1493 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1494 else if(tdm_max_score == fraglimit - 3)
1495 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1498 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1501 // TDM winning condition: game terminates if a team's score sum reached the
1502 // fraglimit, unless the first two teams have the same total score. The latter
1503 // case also breaks the time limit.
1504 float(float fraglimit) WinningCondition_MaxTeamSum =
1508 team1_score = team2_score = team3_score = team4_score = 0;
1510 FOR_EACH_PLAYER(head)
1512 if(head.team == COLOR_TEAM1)
1513 team1_score += head.frags;
1514 else if(head.team == COLOR_TEAM2)
1515 team2_score += head.frags;
1516 else if(head.team == COLOR_TEAM3)
1517 team3_score += head.frags;
1518 else if(head.team == COLOR_TEAM4)
1519 team4_score += head.frags;
1522 return WinningConditionBase_Teamplay(fraglimit);
1525 // DOM/CTF winning condition: game terminates if the max of a team's players'
1526 // score reached the fraglimit, unless the first two teams have the same
1527 // maximum score. The latter case also breaks the time limit.
1528 float(float fraglimit) WinningCondition_MaxTeamMax =
1532 team1_score = team2_score = team3_score = team4_score = 0;
1534 FOR_EACH_PLAYER(head)
1536 if(head.team == COLOR_TEAM1)
1538 if(head.frags > team1_score)
1539 team1_score = head.frags;
1541 else if(head.team == COLOR_TEAM2)
1543 if(head.frags > team2_score)
1544 team2_score = head.frags;
1546 else if(head.team == COLOR_TEAM3)
1548 if(head.frags > team3_score)
1549 team3_score = head.frags;
1551 else if(head.team == COLOR_TEAM4)
1553 if(head.frags > team4_score)
1554 team4_score = head.frags;
1558 return WinningConditionBase_Teamplay(fraglimit);
1561 void print_to(entity e, string s)
1564 sprint(e, strcat(s, "\n"));
1566 ServerConsoleEcho(s, TRUE);
1569 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1579 FOR_EACH_PLAYER(head)
1581 if(!whichteam || head.team == whichteam)
1585 print_to(e, strcat(" ", colorcode, name, ":"));
1587 fragtotal = fragtotal + head.frags;
1588 s = ftos(head.frags);
1589 s = strcat(s, "/", ftos(head.deaths));
1590 s = strcat(s, " @ ", ftos(head.ping));
1591 if(clienttype(head) == CLIENTTYPE_BOT)
1592 s = strcat(s, "botms");
1594 s = strcat(s, "ms");
1595 v = PlayerValue(head);
1597 s = strcat(s, " / ", ftos(v));
1598 print_to(e, strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"));
1601 if(whichteam && found)
1603 s = ftos(fragtotal);
1604 s = strcat(s, " / ", ftos(teamvalue));
1605 print_to(e, strcat(colorcode, " (total: ", s, ")"));
1609 void PrintScoreboard(entity e)
1611 print_to(e, strcat("Time: ", ftos(time / 60)));
1612 print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1613 print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1614 print_to(e, "Scoreboard:");
1617 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1618 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1619 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM3);
1620 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM4);
1624 PrintScoreboardFor(e, "", "^7", 0);
1629 void ShuffleMaplist()
1637 result = cvar_string("g_maplist");
1639 litems = tokenizebyseparator(result, " ");
1641 litems = tokenize(result);
1644 for(start = 0; start < litems - 1; ++start)
1648 // select a random item
1649 selected = ceil(random() * (litems - start) + start) - 1;
1651 // shift this item to the place start
1653 for(i = 0; i < start; ++i)
1654 result = strcat(result, " ", argv(i));
1655 result = strcat(result, " ", argv(selected));
1656 for(i = start; i < litems; ++i)
1658 result = strcat(result, " ", argv(i));
1659 result = substring(result, 1, strlen(result) - 1);
1661 litems = tokenizebyseparator(result, " ");
1663 for(i = 0; i < start; ++i)
1664 result = strcat(result, "'", argv(i), "'");
1665 result = strcat(result, "'", argv(selected), "'");
1666 for(i = start; i < litems; ++i)
1668 result = strcat(result, "'", argv(i), "'");
1670 litems = tokenize(result);
1673 //dprint(result, "\n");
1676 cvar_set("g_maplist", result);
1679 float WinningCondition_RanOutOfSpawns()
1683 if(!have_team_spawns)
1686 if(!some_spawn_has_been_used)
1689 team1_score = team2_score = team3_score = team4_score = 0;
1691 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1693 if(head.team == COLOR_TEAM1)
1695 else if(head.team == COLOR_TEAM2)
1697 else if(head.team == COLOR_TEAM3)
1699 else if(head.team == COLOR_TEAM4)
1703 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1705 if(head.team == COLOR_TEAM1)
1707 else if(head.team == COLOR_TEAM2)
1709 else if(head.team == COLOR_TEAM3)
1711 else if(head.team == COLOR_TEAM4)
1716 if(team1_score + team2_score + team3_score + team4_score == 0)
1718 checkrules_equality = TRUE;
1721 else if(team1_score + team2_score + team3_score + team4_score == 1)
1725 AddWinners(team, COLOR_TEAM1);
1726 ClearFragsForEveryoneBut(team, COLOR_TEAM1);
1730 AddWinners(team, COLOR_TEAM2);
1731 ClearFragsForEveryoneBut(team, COLOR_TEAM2);
1735 AddWinners(team, COLOR_TEAM3);
1736 ClearFragsForEveryoneBut(team, COLOR_TEAM3);
1740 AddWinners(team, COLOR_TEAM4);
1741 ClearFragsForEveryoneBut(team, COLOR_TEAM4);
1753 Exit deathmatch games upon conditions
1756 void() CheckRules_World =
1759 local float timelimit;
1760 local float fraglimit;
1768 MapVote_Think should now do that part
1769 if (intermission_running)
1770 if (time >= intermission_exittime + 60)
1772 if(!DoNextMapOverride())
1778 if (gameover) // someone else quit the game already
1780 if(player_count == 0) // Nobody there? Then let's go to the next map
1782 // this will actually check the player count in the next frame
1783 // again, but this shouldn't hurt
1787 timelimit = cvar("timelimit") * 60;
1788 fraglimit = cvar("fraglimit");
1790 if(checkrules_overtimeend)
1792 if(!checkrules_overtimewarning)
1794 checkrules_overtimewarning = TRUE;
1795 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1796 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1801 if (timelimit && time >= timelimit)
1805 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1811 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1813 checkrules_oneminutewarning = TRUE;
1814 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1817 status = WinningCondition_RanOutOfSpawns();
1818 if(status == WINNING_YES)
1820 bprint("Hey! Someone ran out of spawns!\n");
1824 status = WinningCondition_Assault();
1828 status = WinningCondition_LMS();
1830 else if (g_onslaught)
1832 status = WinningCondition_Onslaught();
1838 if(g_tdm || g_runematch || g_ctf || g_domination || g_keyhunt)
1839 status = WinningCondition_MaxTeamSum(fraglimit);
1841 // status = WinningCondition_MaxTeamMax(fraglimit);
1844 dprint("div0: How can this happen?\n");
1845 status = WinningCondition_MaxTeamMax(fraglimit);
1849 status = WinningCondition_MaxIndividualScore(fraglimit);
1852 if(status == WINNING_STARTOVERTIME)
1854 status = WINNING_NEVER;
1858 if(status == WINNING_NEVER)
1859 // equality cases! Nobody wins if the overtime ends in a draw.
1862 if(checkrules_overtimeend)
1863 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1864 status = WINNING_YES;
1866 if(status == WINNING_YES)
1870 float randsel_value;
1871 float randsel_priority;
1872 float randsel_count;
1876 randsel_priority = -1;
1879 void RandSel_Add(float priority, float value)
1881 if(priority > randsel_priority)
1883 randsel_priority = priority;
1884 randsel_value = value;
1887 else if(priority == randsel_priority)
1890 if(ceil(random() * randsel_count) == 1)
1891 randsel_value = value;
1895 float mapvote_nextthink;
1896 float mapvote_initialized;
1897 float mapvote_keeptwotime;
1898 float mapvote_timeout;
1899 string mapvote_message;
1901 #define MAPVOTE_COUNT 10
1902 float mapvote_count;
1903 float mapvote_count_real;
1904 string mapvote_maps[MAPVOTE_COUNT];
1905 float mapvote_maps_suggested[MAPVOTE_COUNT];
1906 string mapvote_suggestions[MAPVOTE_COUNT];
1907 float mapvote_suggestion_ptr;
1908 float mapvote_maxlen;
1909 float mapvote_voters;
1910 float mapvote_votes[MAPVOTE_COUNT];
1912 float mapvote_detail;
1913 float mapvote_abstain;
1916 void MapVote_ClearAllVotes()
1918 FOR_EACH_CLIENT(other)
1922 string MapVote_Suggest(string m)
1926 return "That's not how to use this command.";
1927 if(!cvar("g_maplist_votable_suggestions"))
1928 return "Suggestions are not accepted on this server.";
1929 if(mapvote_initialized)
1930 return "Can't suggest - voting is already in progress!";
1932 m = MapInfo_FixName(m);
1934 return "The map you suggested is not available on this server.";
1936 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1937 if(!IsSameGametype(m))
1938 return "This server does not allow changing the game type by map suggestions.";
1940 if(!cvar("g_maplist_votable_override_mostrecent"))
1942 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1945 if(!MapInfo_CheckMap(m))
1946 return "The map you suggested does not support the current game mode.";
1948 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1949 return "The map you suggested is not available on this server.";
1951 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1952 if(mapvote_suggestions[i] == m)
1953 return "This map was already suggested.";
1954 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1956 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1960 i = mapvote_suggestion_ptr;
1961 mapvote_suggestion_ptr += 1;
1963 if(mapvote_suggestions[i] != "")
1964 strunzone(mapvote_suggestions[i]);
1965 mapvote_suggestions[i] = strzone(m);
1966 if(cvar("sv_eventlog"))
1967 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)), TRUE);
1968 return strcat("Suggestion of ", m, " accepted.");
1971 void MapVote_AddVotable(string nextMap, float isSuggestion)
1976 for(j = 0; j < mapvote_count; ++j)
1977 if(mapvote_maps[j] == nextMap)
1979 if(strlen(nextMap) > mapvote_maxlen)
1980 mapvote_maxlen = strlen(nextMap);
1981 mapvote_maps[mapvote_count] = strzone(nextMap);
1982 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1991 MapVote_ClearAllVotes();
1994 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1995 mapvote_abstain = cvar("g_maplist_votable_abstain");
1998 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
2000 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
2001 smax = min(nmax, cvar("g_maplist_votable_suggestions"));
2003 for(i = 0; i < 100 && mapvote_count < smax; ++i)
2004 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
2006 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2007 MapVote_AddVotable(GetNextMap(), FALSE);
2009 if(mapvote_count == 0)
2011 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
2013 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
2014 localcmd("\nmenu_cmd sync\n");
2016 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
2018 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2019 MapVote_AddVotable(GetNextMap(), FALSE);
2022 mapvote_count_real = mapvote_count;
2024 MapVote_AddVotable("don't care", 0);
2026 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
2028 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
2029 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
2030 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
2031 mapvote_keeptwotime = 0;
2032 mapvote_message = "Choose a map and press its key!";
2034 float MapVote_Finished(float mappos)
2040 if(cvar("sv_eventlog"))
2042 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2043 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
2044 didntvote = mapvote_voters;
2045 for(i = 0; i < mapvote_count; ++i)
2046 if(mapvote_maps[i] != "")
2048 didntvote -= mapvote_votes[i];
2051 result = strcat(result, ":", mapvote_maps[i]);
2052 result = strcat(result, ":", ftos(mapvote_votes[i]));
2055 result = strcat(result, ":didn't vote:", ftos(didntvote));
2057 GameLogEcho(result, FALSE);
2058 if(mapvote_maps_suggested[mappos])
2059 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
2062 FOR_EACH_REALCLIENT(other)
2063 FixClientCvars(other);
2065 Map_Goto_SetStr(mapvote_maps[mappos]);
2067 alreadychangedlevel = TRUE;
2070 void MapVote_CheckRules_1()
2074 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2076 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2077 mapvote_votes[i] = 0;
2081 FOR_EACH_REALCLIENT(other)
2086 i = other.mapvote - 1;
2087 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2088 mapvote_votes[i] = mapvote_votes[i] + 1;
2093 float MapVote_CheckRules_2()
2096 float firstPlace, secondPlace;
2097 float firstPlaceVotes, secondPlaceVotes;
2098 float mapvote_voters_real;
2101 mapvote_voters_real = mapvote_voters;
2103 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2106 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2107 RandSel_Add(mapvote_votes[i], i);
2108 firstPlace = randsel_value;
2109 firstPlaceVotes = randsel_priority;
2110 //dprint("First place: ", ftos(firstPlace), "\n");
2111 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2114 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2116 RandSel_Add(mapvote_votes[i], i);
2117 secondPlace = randsel_value;
2118 secondPlaceVotes = randsel_priority;
2119 //dprint("Second place: ", ftos(secondPlace), "\n");
2120 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2122 if(firstPlace == -1)
2123 error("No first place in map vote... WTF?");
2125 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2126 return MapVote_Finished(firstPlace);
2128 if(mapvote_keeptwotime)
2129 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2132 mapvote_message = "Now decide between the TOP TWO!";
2133 mapvote_keeptwotime = 0;
2134 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2135 result = strcat(result, ":", ftos(firstPlaceVotes));
2136 result = strcat(result, ":", mapvote_maps[secondPlace]);
2137 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2138 didntvote = mapvote_voters;
2139 for(i = 0; i < mapvote_count; ++i)
2140 if(mapvote_maps[i] != "")
2142 didntvote -= mapvote_votes[i];
2144 if(i != secondPlace)
2146 result = strcat(result, ":", mapvote_maps[i]);
2147 result = strcat(result, ":", ftos(mapvote_votes[i]));
2148 if(i < mapvote_count_real)
2150 strunzone(mapvote_maps[i]);
2151 mapvote_maps[i] = "";
2155 result = strcat(result, ":didn't vote:", ftos(didntvote));
2156 if(cvar("sv_eventlog"))
2157 GameLogEcho(result, FALSE);
2170 keeptwo = mapvote_keeptwotime;
2171 MapVote_CheckRules_1(); // count
2172 if(MapVote_CheckRules_2()) // decide
2176 FOR_EACH_REALCLIENT(other)
2178 // hide scoreboard again
2179 if(other.health != 2342)
2181 other.health = 2342;
2183 if(clienttype(other) == CLIENTTYPE_REAL)
2185 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");
2187 WriteByte(MSG_ONE, SVC_FINALE);
2188 WriteString(MSG_ONE, "");
2192 // notify about keep-two
2193 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2194 play2(other, "misc/invshot.wav");
2196 // clear possibly invalid votes
2197 if(mapvote_maps[other.mapvote - 1] == "")
2199 // use impulses as new vote
2200 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2201 if(mapvote_maps[other.impulse - 1] != "")
2202 other.mapvote = other.impulse;
2209 MapVote_CheckRules_1(); // just count
2211 FOR_EACH_REALCLIENT(other)
2213 // display voting screen
2214 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2215 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2217 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2218 msgstr = strcat(msgstr, mapvote_message);
2219 msgstr = strcat(msgstr, "\n\n");
2220 for(i = 0; i < mapvote_count; ++i)
2221 if(mapvote_maps[i] == "")
2222 msgstr = strcat(msgstr, "\n");
2225 tmp = mapvote_maps[i];
2226 tmp = strpad(mapvote_maxlen, tmp);
2227 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2230 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2231 if(mapvote_votes[i] != 1)
2232 tmp = strcat(tmp, "s");
2233 tmp = strcat(tmp, ")");
2234 tmp = strpad(mapvote_maxlen + 15, tmp);
2237 if(i == mapvote_count - 1)
2238 msgstr = strcat(msgstr, "\n");
2239 if(other.mapvote == i + 1)
2240 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2242 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2245 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2247 msgstr = strcat(msgstr, "s");
2248 msgstr = strcat(msgstr, " cast");
2249 i = ceil(mapvote_timeout - time);
2250 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2252 msgstr = strcat(msgstr, "s");
2253 msgstr = strcat(msgstr, " left");
2255 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2258 void MapVote_Start()
2264 MapInfo_Enumerate();
2265 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2269 void MapVote_Think()
2274 if(alreadychangedlevel)
2277 if(time < mapvote_nextthink)
2281 mapvote_nextthink = time + 0.5;
2283 if(!mapvote_initialized)
2285 mapvote_initialized = TRUE;
2286 if(DoNextMapOverride())
2288 if(!cvar("g_maplist_votable") || player_count <= 0)
2299 string GotoMap(string m)
2302 if(!MapInfo_CheckMap(m))
2304 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2306 return "The map you chose is not available on this server.";
2307 cvar_set("nextmap", m);
2308 cvar_set("timelimit", "-1");
2309 if(mapvote_initialized || alreadychangedlevel)
2311 if(DoNextMapOverride())
2312 return "Map switch initiated.";
2314 return "Hm... no. For some reason I like THIS map more.";
2317 return "Map switch will happen after scoreboard.";
2323 FOR_EACH_REALCLIENT(self)
2325 if(self.classname == "spectator")
2327 if(self.enemy.hitsound)
2328 play2(self, "misc/hit.wav");
2333 play2(self, "misc/hit.wav");
2336 FOR_EACH_CLIENT(self)
2337 self.hitsound = FALSE;
2343 * returns TRUE if redirecting
2345 float redirection_timeout;
2346 float redirection_nextthink;
2347 float RedirectionThink()
2349 float clients_found;
2351 if(redirection_target == "")
2354 if(!redirection_timeout)
2356 cvar_set("sv_public", "-2");
2357 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2358 if(redirection_target == "self")
2359 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2361 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2364 if(time < redirection_nextthink)
2367 redirection_nextthink = time + 1;
2370 FOR_EACH_REALCLIENT(self)
2372 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2373 if(redirection_target == "self")
2374 stuffcmd(self, "\ndisconnect; reconnect\n");
2376 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2380 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2382 if(time > redirection_timeout || clients_found == 0)
2383 localcmd("\nwait; wait; wait; quit\n");
2390 if(world_initialized)
2392 world_initialized = 0;
2393 print("Saving persistent data...\n");
2396 db_save(ServerProgsDB, "server.db");
2398 // tell the bot system the game is ending now
2403 print("NOTE: crashed before even initializing the world, not saving persistent data\n");