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;
179 head = nextent(world);
184 head = nextent(head);
191 MapInfo_LoadMapSettings(mapname);
195 ServerProgsDB = db_create();
197 ServerProgsDB = db_load("server.db");
200 TODO sound pack system
201 // initialize sound pack system
202 soundpack = cvar_string("g_soundpack");
204 soundpack = strcat(soundpack, "/");
205 soundpack = strzone(soundpack);
211 // 1 FLICKER (first variety)
212 lightstyle(1, "mmnmmommommnonmmonqnmmo");
214 // 2 SLOW STRONG PULSE
215 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
217 // 3 CANDLE (first variety)
218 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
221 lightstyle(4, "mamamamamama");
224 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
226 // 6 FLICKER (second variety)
227 lightstyle(6, "nmonqnmomnmomomno");
229 // 7 CANDLE (second variety)
230 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
232 // 8 CANDLE (third variety)
233 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
235 // 9 SLOW STROBE (fourth variety)
236 lightstyle(9, "aaaaaaaazzzzzzzz");
238 // 10 FLUORESCENT FLICKER
239 lightstyle(10, "mmamammmmammamamaaamammma");
241 // 11 SLOW PULSE NOT FADE TO BLACK
242 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
244 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
249 // for setting by mapinfo
250 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
251 cvar_set("sv_q3acompat_machineshotgunswap", "0");
254 lms_lowest_lives = 0;
257 bot_waypoints_for_items = cvar("g_waypoints_for_items");
258 if(bot_waypoints_for_items == 1)
259 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
260 bot_waypoints_for_items = 0;
262 if(cvar("g_campaign"))
269 WaypointSprite_Init();
274 GameLogInit(); // prepare everything
275 if(cvar("sv_eventlog"))
277 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
278 s = strcat(s, ftos(random()));
280 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s), FALSE);
282 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
284 s = ":gameinfo:mutators:LIST";
285 if(cvar("g_grappling_hook"))
286 s = strcat(s, ":grappling_hook");
287 if(!cvar("g_use_ammunition"))
288 s = strcat(s, ":no_use_ammunition");
289 if(!cvar("g_pickup_items"))
290 s = strcat(s, ":no_pickup_items");
291 if(cvar("g_instagib"))
292 s = strcat(s, ":instagib");
293 if(cvar("g_rocketarena"))
294 s = strcat(s, ":rockerarena");
296 s = strcat(s, ":nixnex");
297 if(cvar("g_vampire"))
298 s = strcat(s, ":vampire");
299 if(cvar("g_laserguided_missile"))
300 s = strcat(s, ":laserguided_missile");
301 if(cvar("g_norecoil"))
302 s = strcat(s, ":norecoil");
304 s = strcat(s, ":midair");
305 if(cvar("g_minstagib"))
306 s = strcat(s, ":minstagib");
307 GameLogEcho(s, FALSE);
308 GameLogEcho(":gameinfo:end", FALSE);
311 cvar_set("nextmap", "");
315 if(cvar("g_campaign"))
322 //initialise globals related to sv_timeout
323 sys_ticrate = cvar("sys_ticrate");
324 orig_slowmo = cvar("slowmo");
328 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
331 //if tourney is used map starts in warmup mode. if this mode shall stay unlimited, reset timelimit, but save the original one
332 if(g_tourney && cvar("g_tourney_warmup_unlimited_time")) {
333 timelimit_orig = cvar("timelimit");
334 cvar_set("timelimit", "0");
337 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
340 while((s = fgets(fd)))
351 s = strcat(argv(l), " ", s);
353 s = substring(s, 0, strlen(s) - 1);
354 print("Found ^1DEPRECATED^7 fog command in .cfg file: ", s, "\n");
355 world.fog = strzone(s);
360 next_pingtime = time + 5;
361 world_initialized = 1;
364 void spawnfunc_light (void)
366 //makestatic (self); // Who the f___ did that?
370 float TryFile( string pFilename )
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 Map_Check(float position, float pass)
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 Map_Goto_SetStr(string nextmapname)
568 if(getmapname_stored != "")
569 strunzone(getmapname_stored);
570 if(nextmapname == "")
571 getmapname_stored = "";
573 getmapname_stored = strzone(nextmapname);
576 void Map_Goto_SetFloat(float position)
578 cvar_set("g_maplist_index", ftos(position));
579 Map_Goto_SetStr(argv(position));
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))
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);
729 strunzone(Map_Current_Name);
730 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
731 // this may or may not be correct, but who cares, in the worst case a map
732 // isn't chosen in the first pass that should have been
743 if(cvar("g_maplist_shuffle") > 0)
744 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
747 if(cvar("g_maplist_selectrandom"))
748 nextMap = MaplistMethod_Random();
751 nextMap = MaplistMethod_Iterate();
754 nextMap = MaplistMethod_Repeat();
758 Map_Goto_SetFloat(nextMap);
759 return getmapname_stored;
765 float DoNextMapOverride()
767 if(cvar("g_campaign"))
769 CampaignPostIntermission();
770 alreadychangedlevel = TRUE;
773 if(cvar("quit_when_empty"))
775 if(player_count <= currentbots)
778 alreadychangedlevel = TRUE;
782 if(cvar_string("quit_and_redirect") != "")
784 redirection_target = strzone(cvar_string("quit_and_redirect"));
785 alreadychangedlevel = TRUE;
788 if (cvar("samelevel")) // if samelevel is set, stay on same level
790 // 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)
791 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
792 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
793 localcmd("restart\n");
794 //changelevel (mapname);
795 alreadychangedlevel = TRUE;
798 if(cvar_string("nextmap") != "")
800 if(MapInfo_CheckMap(cvar_string("nextmap")))
802 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
805 Map_Goto_SetStr(cvar_string("nextmap"));
807 alreadychangedlevel = TRUE;
810 if(cvar("lastlevel"))
813 localcmd("set lastlevel 0\ntogglemenu\n");
814 alreadychangedlevel = TRUE;
822 //local string nextmap;
823 //local float n, nummaps;
825 if (alreadychangedlevel)
827 alreadychangedlevel = TRUE;
833 for(allowReset = 1; allowReset >= 0; --allowReset)
835 nextMap = GetNextMap();
841 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
843 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
844 localcmd("\nmenu_cmd sync\n");
846 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
851 error("Everything is broken - not even the default map list works. Please report this to the developers.");
863 When the player presses attack or jump, change to the next level
866 .float autoscreenshot;
867 void() MapVote_Start;
868 void() MapVote_Think;
869 float mapvote_initialized;
870 void IntermissionThink()
872 FixIntermissionClient(self);
874 if(cvar("sv_autoscreenshot"))
875 if(self.autoscreenshot > 0)
876 if(time > self.autoscreenshot)
878 self.autoscreenshot = -1;
879 if(clienttype(self) == CLIENTTYPE_REAL)
880 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
884 if (time < intermission_exittime)
887 if(!mapvote_initialized)
888 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
898 Returns the entity to view from
902 entity FindIntermission()
907 // look for info_intermission first
908 spot = find (world, classname, "info_intermission");
910 { // pick a random one
914 spot = find (spot, classname, "info_intermission");
916 spot = find (spot, classname, "info_intermission");
922 // then look for the start position
923 spot = find (world, classname, "info_player_start");
927 // testinfo_player_start is only found in regioned levels
928 spot = find (world, classname, "testplayerstart");
932 // then look for the start position
933 spot = find (world, classname, "info_player_deathmatch");
937 //objerror ("FindIntermission: no spot");
943 ===============================================================================
947 ===============================================================================
950 void DumpStats(float final)
954 local float to_console;
955 local float to_eventlog;
958 to_console = cvar("sv_logscores_console");
959 to_eventlog = cvar("sv_eventlog");
960 to_file = cvar("sv_logscores_file");
964 to_console = TRUE; // always print printstats replies
965 to_eventlog = FALSE; // but never print them to the event log
969 if(cvar("sv_eventlog_console"))
970 to_console = FALSE; // otherwise we get the output twice
977 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
979 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
983 ServerConsoleEcho(s, FALSE);
985 GameLogEcho(s, FALSE);
988 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
992 fputs(file, strcat(s, "\n"));
995 FOR_EACH_CLIENT(other)
997 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
999 s = strcat(":player:", ftos(other.frags), ":");
1000 s = strcat(s, ftos(other.deaths), ":");
1001 s = strcat(s, ftos(rint(time - other.jointime)), ":");
1002 s = strcat(s, ftos(other.team), ":");
1005 ServerConsoleEcho(strcat(s, other.netname), TRUE);
1007 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
1009 fputs(file, strcat(s, other.netname, "\n"));
1014 if(cvar("g_ctf_win_mode") != 2)
1016 s = strcat(":teamscores:", ftos(COLOR_TEAM1), ":");
1017 s = strcat(s, ftos(caps_team1), ":");
1018 s = strcat(s, ftos(COLOR_TEAM2), ":");
1019 s = strcat(s, ftos(caps_team2));
1021 ServerConsoleEcho(s, TRUE);
1023 GameLogEcho(s, TRUE);
1025 fputs(file, strcat(s, "\n"));
1029 ServerConsoleEcho(":end", FALSE);
1031 GameLogEcho(":end", FALSE);
1034 fputs(file, ":end\n");
1039 void FixIntermissionClient(entity e)
1042 if(!e.autoscreenshot) // initial call
1044 e.angles = e.v_angle;
1045 e.angles_x = -e.angles_x;
1046 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1048 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1049 e.solid = SOLID_NOT;
1050 e.movetype = MOVETYPE_NONE;
1051 e.takedamage = DAMAGE_NO;
1053 e.weaponentity.effects = EF_NODRAW;
1054 if(clienttype(e) == CLIENTTYPE_REAL)
1056 stuffcmd(e, "\nscr_printspeed 1000000\n");
1057 s = cvar_string("sv_intermission_cdtrack");
1059 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1061 WriteByte(MSG_ONE, SVC_INTERMISSION);
1065 //e.velocity = '0 0 0';
1066 //e.fixangle = TRUE;
1068 // TODO halt weapon animation
1073 go to the next level for deathmatch
1074 only called if a time or frag limit has expired
1078 float minTotalFrags;
1079 float maxTotalFrags;
1085 intermission_running = 1;
1087 // enforce a wait time before allowing changelevel
1088 if(player_count > 0)
1089 intermission_exittime = time + cvar("sv_mapchange_delay");
1091 intermission_exittime = -1;
1094 WriteByte (MSG_ALL, SVC_CDTRACK);
1095 WriteByte (MSG_ALL, 3);
1096 WriteByte (MSG_ALL, 3);
1097 // done in FixIntermission
1100 //pos = FindIntermission ();
1106 if(cvar("sv_eventlog"))
1107 GameLogEcho(":gameover", FALSE);
1111 FOR_EACH_CLIENT(other)
1113 FixIntermissionClient(other);
1116 bprint(other.netname, " ^7wins.\n");
1121 FOR_EACH_PLAYER(other)
1123 if(maxTotalFrags < other.totalfrags)
1124 maxTotalFrags = other.totalfrags;
1125 if(minTotalFrags > other.totalfrags)
1126 minTotalFrags = other.totalfrags;
1131 FOR_EACH_PLAYER(other)
1133 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1134 f = bound(0, other.play_time / max(time, 1), 1);
1135 // store some statistics?
1139 if(cvar("g_campaign"))
1140 CampaignPreIntermission();
1142 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1149 Exit deathmatch games upon conditions
1153 void CheckRules_Player()
1155 if (gameover) // someone else quit the game already
1158 if(self.deadflag == DEAD_NO)
1159 self.play_time += frametime;
1163 if(time > self.fogtime)
1165 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1166 self.fogtime = time + sv_foginterval;
1169 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1170 // (div0: and that in CheckRules_World please)
1173 float checkrules_oneminutewarning;
1174 float checkrules_leaderfrags;
1175 float tdm_max_score, tdm_old_score;
1177 float checkrules_equality;
1178 float checkrules_overtimewarning;
1179 float checkrules_overtimeend;
1181 void InitiateOvertime()
1183 if(!checkrules_overtimeend)
1184 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1187 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1188 float WINNING_YES = 1; // winner found
1189 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1190 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1192 float GetWinningCode(float fraglimitreached, float equality)
1195 if(fraglimitreached)
1196 return WINNING_STARTOVERTIME;
1198 return WINNING_NEVER;
1200 if(fraglimitreached)
1206 // set the .winning flag for exactly those players with a given field value
1207 void SetWinners(.float field, float value)
1210 FOR_EACH_PLAYER(head)
1211 head.winning = (head.field == value);
1214 // set the .winning flag for those players with a given field value
1215 void AddWinners(.float field, float value)
1218 FOR_EACH_PLAYER(head)
1219 if(head.field == value)
1223 // clear frags for all players but the team given (when they ran out of spawnpoints)
1224 void ClearFragsForEveryoneBut(.float field, float value)
1227 FOR_EACH_PLAYER(head)
1228 if(head.field != value)
1229 head.frags = max(head.frags, 0);
1232 // clear the .winning flags
1233 void ClearWinners(void)
1236 FOR_EACH_PLAYER(head)
1240 // Onslaught winning condition:
1241 // game terminates if only one team has a working generator (or none)
1242 float WinningCondition_Onslaught()
1245 local float t1, t2, t3, t4;
1246 // first check if the game has ended
1247 t1 = t2 = t3 = t4 = 0;
1248 head = find(world, classname, "onslaught_generator");
1251 if (head.health > 0)
1253 if (head.team == COLOR_TEAM1) t1 = 1;
1254 if (head.team == COLOR_TEAM2) t2 = 1;
1255 if (head.team == COLOR_TEAM3) t3 = 1;
1256 if (head.team == COLOR_TEAM4) t4 = 1;
1258 head = find(head, classname, "onslaught_generator");
1260 if (t1 + t2 + t3 + t4 < 2)
1262 // game over, only one team remains (or none)
1264 if (t1) SetWinners(team, COLOR_TEAM1);
1265 if (t2) SetWinners(team, COLOR_TEAM2);
1266 if (t3) SetWinners(team, COLOR_TEAM3);
1267 if (t4) SetWinners(team, COLOR_TEAM4);
1268 dprint("Have a winner, ending game.\n");
1272 // Two or more teams remain
1276 float LMS_NewPlayerLives()
1279 fl = cvar("fraglimit");
1283 // first player has left the game for dying too much? Nobody else can get in.
1284 if(lms_lowest_lives < 1)
1287 if(!cvar("g_lms_join_anytime"))
1288 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1291 return bound(1, lms_lowest_lives, fl);
1294 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1295 // they win. Otherwise the defending team wins once the timelimit passes.
1296 void assault_new_round();
1297 float WinningCondition_Assault()
1300 status = WINNING_NO;
1302 // as the timelimit has not yet passed just assume the defending team will win
1303 if(assault_attacker_team == COLOR_TEAM1)
1305 SetWinners(team, COLOR_TEAM2);
1309 SetWinners(team, COLOR_TEAM1);
1313 ent = find(world, classname, "target_assault_roundend");
1316 if(ent.winning) // round end has been triggered by attacking team
1318 SetWinners(team, assault_attacker_team);
1319 if(assault_attacker_team == COLOR_TEAM1)
1321 team1_score = team1_score + 50;
1325 team2_score = team2_score + 50;
1328 if(ent.cnt == 1) // this was the second round
1330 status = WINNING_YES;
1334 local entity oldself;
1337 cvar_set("timelimit", ftos((2*time)/60));
1338 assault_new_round();
1349 // LMS winning condition: game terminates if and only if there's at most one
1350 // one player who's living lives. Top two scores being equal cancels the time
1352 float WinningCondition_LMS()
1359 have_player = FALSE;
1360 have_players = FALSE;
1361 l = LMS_NewPlayerLives();
1363 head = find(world, classname, "player");
1366 head = find(head, classname, "player");
1368 have_players = TRUE;
1372 // we have at least one player
1375 // two or more active players - continue with the game
1379 // exactly one player?
1382 // but no game has taken place yet
1387 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1388 dprint("Have a winner, ending game.\n");
1395 // nobody is playing at all...
1398 // wait for players...
1402 // SNAFU (maybe a draw game?)
1404 dprint("No players, ending game.\n");
1409 // When we get here, we have at least two players who are actually LIVING,
1410 // or one player who is still waiting for a victim to join the server. Now
1411 // check if the top two players have equal score.
1413 checkrules_leaderfrags = 0;
1414 checkrules_equality = FALSE;
1415 FOR_EACH_PLAYER(head)
1417 if(head.frags > checkrules_leaderfrags)
1419 checkrules_leaderfrags = head.frags;
1420 checkrules_equality = FALSE;
1422 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1423 checkrules_equality = TRUE;
1426 SetWinners(frags, checkrules_leaderfrags);
1428 // The top two players have the same amount of lives? No timelimit then,
1429 // enter overtime...
1431 if(checkrules_equality)
1432 return WINNING_NEVER;
1434 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1438 // DM winning condition: game terminates if a player reached the fraglimit,
1439 // unless the first two players have the same score. The latter case also
1440 // breaks the time limit.
1441 float WinningCondition_MaxIndividualScore(float fraglimit)
1443 float checkrules_oldleaderfrags;
1446 checkrules_oldleaderfrags = checkrules_leaderfrags;
1447 checkrules_leaderfrags = 0;
1448 checkrules_equality = FALSE;
1449 FOR_EACH_PLAYER(head)
1451 if(head.frags > checkrules_leaderfrags)
1453 checkrules_leaderfrags = head.frags;
1454 checkrules_equality = FALSE;
1456 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1457 checkrules_equality = TRUE;
1460 if(checkrules_leaderfrags > 0)
1461 SetWinners(frags, checkrules_leaderfrags);
1466 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1468 if (checkrules_leaderfrags == fraglimit - 1)
1469 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1470 else if (checkrules_leaderfrags == fraglimit - 2)
1471 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1472 else if (checkrules_leaderfrags == fraglimit - 3)
1473 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1476 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1479 float WinningConditionBase_Teamplay(float fraglimit)
1481 tdm_old_score = tdm_max_score;
1482 tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1484 checkrules_equality =
1489 (team1_score == tdm_max_score)
1490 + (team2_score == tdm_max_score)
1491 + (team3_score == tdm_max_score)
1492 + (team4_score == tdm_max_score)
1496 if(tdm_max_score > 0)
1498 if(team1_score == tdm_max_score)
1499 AddWinners(team, COLOR_TEAM1);
1500 if(team2_score == tdm_max_score)
1501 AddWinners(team, COLOR_TEAM2);
1502 if(team3_score == tdm_max_score)
1503 AddWinners(team, COLOR_TEAM3);
1504 if(team4_score == tdm_max_score)
1505 AddWinners(team, COLOR_TEAM4);
1508 if(!g_runematch && !g_domination && !g_ctf)
1509 if(tdm_max_score != tdm_old_score)
1511 if(tdm_max_score == fraglimit - 1)
1512 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1513 else if(tdm_max_score == fraglimit - 2)
1514 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1515 else if(tdm_max_score == fraglimit - 3)
1516 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1519 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1522 // TDM winning condition: game terminates if a team's score sum reached the
1523 // fraglimit, unless the first two teams have the same total score. The latter
1524 // case also breaks the time limit.
1525 float WinningCondition_MaxTeamSum(float fraglimit)
1529 team1_score = team2_score = team3_score = team4_score = 0;
1531 FOR_EACH_PLAYER(head)
1533 if(head.team == COLOR_TEAM1)
1534 team1_score += head.frags;
1535 else if(head.team == COLOR_TEAM2)
1536 team2_score += head.frags;
1537 else if(head.team == COLOR_TEAM3)
1538 team3_score += head.frags;
1539 else if(head.team == COLOR_TEAM4)
1540 team4_score += head.frags;
1543 return WinningConditionBase_Teamplay(fraglimit);
1546 // DOM/CTF winning condition: game terminates if the max of a team's players'
1547 // score reached the fraglimit, unless the first two teams have the same
1548 // maximum score. The latter case also breaks the time limit.
1549 float WinningCondition_MaxTeamMax(float fraglimit)
1553 team1_score = team2_score = team3_score = team4_score = 0;
1555 FOR_EACH_PLAYER(head)
1557 if(head.team == COLOR_TEAM1)
1559 if(head.frags > team1_score)
1560 team1_score = head.frags;
1562 else if(head.team == COLOR_TEAM2)
1564 if(head.frags > team2_score)
1565 team2_score = head.frags;
1567 else if(head.team == COLOR_TEAM3)
1569 if(head.frags > team3_score)
1570 team3_score = head.frags;
1572 else if(head.team == COLOR_TEAM4)
1574 if(head.frags > team4_score)
1575 team4_score = head.frags;
1579 return WinningConditionBase_Teamplay(fraglimit);
1582 float WinningCondition_CTF(float capturelimit, float fraglimit)
1584 if(cvar("g_ctf_win_mode") == 2)
1585 return WinningCondition_MaxTeamSum(fraglimit);
1587 team1_score = caps_team1;
1588 team2_score = caps_team2;
1589 team3_score = team4_score = 0;
1591 if(team1_score == team2_score && cvar("g_ctf_win_mode"))
1593 return WinningCondition_MaxTeamSum(0);
1596 return WinningConditionBase_Teamplay(capturelimit);
1599 void print_to(entity e, string s)
1602 sprint(e, strcat(s, "\n"));
1604 ServerConsoleEcho(s, TRUE);
1607 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1617 FOR_EACH_PLAYER(head)
1619 if(!whichteam || head.team == whichteam)
1623 print_to(e, strcat(" ", colorcode, name, ":"));
1625 fragtotal = fragtotal + head.frags;
1626 s = ftos(head.frags);
1627 s = strcat(s, "/", ftos(head.deaths));
1628 s = strcat(s, " @ ", ftos(head.ping));
1629 if(clienttype(head) == CLIENTTYPE_BOT)
1630 s = strcat(s, "botms");
1632 s = strcat(s, "ms");
1633 v = PlayerValue(head);
1635 s = strcat(s, " / ", ftos(v));
1636 print_to(e, strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"));
1639 if(whichteam && found)
1641 s = ftos(fragtotal);
1642 s = strcat(s, " / ", ftos(teamvalue));
1643 print_to(e, strcat(colorcode, " (total: ", s, ")"));
1647 void PrintScoreboard(entity e)
1649 print_to(e, strcat("Time: ", ftos(time / 60)));
1650 print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1651 print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1652 print_to(e, "Scoreboard:");
1655 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1656 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1657 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM3);
1658 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM4);
1662 PrintScoreboardFor(e, "", "^7", 0);
1667 void ShuffleMaplist()
1675 result = cvar_string("g_maplist");
1677 litems = tokenizebyseparator(result, " ");
1679 litems = tokenize(result);
1682 for(start = 0; start < litems - 1; ++start)
1686 // select a random item
1687 selected = ceil(random() * (litems - start) + start) - 1;
1689 // shift this item to the place start
1691 for(i = 0; i < start; ++i)
1692 result = strcat(result, " ", argv(i));
1693 result = strcat(result, " ", argv(selected));
1694 for(i = start; i < litems; ++i)
1696 result = strcat(result, " ", argv(i));
1697 result = substring(result, 1, strlen(result) - 1);
1699 litems = tokenizebyseparator(result, " ");
1701 for(i = 0; i < start; ++i)
1702 result = strcat(result, "'", argv(i), "'");
1703 result = strcat(result, "'", argv(selected), "'");
1704 for(i = start; i < litems; ++i)
1706 result = strcat(result, "'", argv(i), "'");
1708 litems = tokenize(result);
1711 //dprint(result, "\n");
1714 cvar_set("g_maplist", result);
1717 float WinningCondition_RanOutOfSpawns()
1721 if(!have_team_spawns)
1724 if(!some_spawn_has_been_used)
1727 team1_score = team2_score = team3_score = team4_score = 0;
1729 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1731 if(head.team == COLOR_TEAM1)
1733 else if(head.team == COLOR_TEAM2)
1735 else if(head.team == COLOR_TEAM3)
1737 else if(head.team == COLOR_TEAM4)
1741 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1743 if(head.team == COLOR_TEAM1)
1745 else if(head.team == COLOR_TEAM2)
1747 else if(head.team == COLOR_TEAM3)
1749 else if(head.team == COLOR_TEAM4)
1754 if(team1_score + team2_score + team3_score + team4_score == 0)
1756 checkrules_equality = TRUE;
1759 else if(team1_score + team2_score + team3_score + team4_score == 1)
1763 AddWinners(team, COLOR_TEAM1);
1764 ClearFragsForEveryoneBut(team, COLOR_TEAM1);
1768 AddWinners(team, COLOR_TEAM2);
1769 ClearFragsForEveryoneBut(team, COLOR_TEAM2);
1773 AddWinners(team, COLOR_TEAM3);
1774 ClearFragsForEveryoneBut(team, COLOR_TEAM3);
1778 AddWinners(team, COLOR_TEAM4);
1779 ClearFragsForEveryoneBut(team, COLOR_TEAM4);
1791 Exit deathmatch games upon conditions
1794 void CheckRules_World()
1797 local float timelimit;
1798 local float fraglimit;
1799 local float capturelimit;
1807 MapVote_Think should now do that part
1808 if (intermission_running)
1809 if (time >= intermission_exittime + 60)
1811 if(!DoNextMapOverride())
1817 if (gameover) // someone else quit the game already
1819 if(player_count == 0) // Nobody there? Then let's go to the next map
1821 // this will actually check the player count in the next frame
1822 // again, but this shouldn't hurt
1826 timelimit = cvar("timelimit") * 60;
1827 fraglimit = cvar("fraglimit");
1828 capturelimit = cvar("capturelimit");
1830 if(checkrules_overtimeend)
1832 if(!checkrules_overtimewarning)
1834 checkrules_overtimewarning = TRUE;
1835 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1836 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1841 if (timelimit && time >= timelimit)
1845 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1851 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1853 checkrules_oneminutewarning = TRUE;
1854 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1857 status = WinningCondition_RanOutOfSpawns();
1858 if(status == WINNING_YES)
1860 bprint("Hey! Someone ran out of spawns!\n");
1864 status = WinningCondition_Assault();
1868 status = WinningCondition_LMS();
1870 else if (g_onslaught)
1872 status = WinningCondition_Onslaught();
1876 status = WinningCondition_CTF(capturelimit, fraglimit);
1882 if(g_tdm || g_runematch || g_ctf || g_domination || g_keyhunt)
1883 status = WinningCondition_MaxTeamSum(fraglimit);
1885 // status = WinningCondition_MaxTeamMax(fraglimit);
1888 dprint("div0: How can this happen?\n");
1889 status = WinningCondition_MaxTeamMax(fraglimit);
1893 status = WinningCondition_MaxIndividualScore(fraglimit);
1896 if(status == WINNING_STARTOVERTIME)
1898 status = WINNING_NEVER;
1902 if(status == WINNING_NEVER)
1903 // equality cases! Nobody wins if the overtime ends in a draw.
1906 if(checkrules_overtimeend)
1907 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1908 status = WINNING_YES;
1910 if(status == WINNING_YES)
1914 float mapvote_nextthink;
1915 float mapvote_initialized;
1916 float mapvote_keeptwotime;
1917 float mapvote_timeout;
1918 string mapvote_message;
1919 string mapvote_screenshot_dir;
1921 float mapvote_count;
1922 float mapvote_count_real;
1923 string mapvote_maps[MAPVOTE_COUNT];
1924 float mapvote_maps_suggested[MAPVOTE_COUNT];
1925 string mapvote_suggestions[MAPVOTE_COUNT];
1926 float mapvote_suggestion_ptr;
1927 float mapvote_maxlen;
1928 float mapvote_voters;
1929 float mapvote_votes[MAPVOTE_COUNT];
1931 float mapvote_detail;
1932 float mapvote_abstain;
1933 float mapvote_dirty;
1936 void MapVote_ClearAllVotes()
1938 FOR_EACH_CLIENT(other)
1942 string MapVote_Suggest(string m)
1946 return "That's not how to use this command.";
1947 if(!cvar("g_maplist_votable_suggestions"))
1948 return "Suggestions are not accepted on this server.";
1949 if(mapvote_initialized)
1950 return "Can't suggest - voting is already in progress!";
1952 m = MapInfo_FixName(m);
1954 return "The map you suggested is not available on this server.";
1956 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1957 if(!IsSameGametype(m))
1958 return "This server does not allow changing the game type by map suggestions.";
1960 if(!cvar("g_maplist_votable_override_mostrecent"))
1962 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1965 if(!MapInfo_CheckMap(m))
1966 return "The map you suggested does not support the current game mode.";
1968 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1969 return "The map you suggested is not available on this server.";
1971 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1972 if(mapvote_suggestions[i] == m)
1973 return "This map was already suggested.";
1974 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1976 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1980 i = mapvote_suggestion_ptr;
1981 mapvote_suggestion_ptr += 1;
1983 if(mapvote_suggestions[i] != "")
1984 strunzone(mapvote_suggestions[i]);
1985 mapvote_suggestions[i] = strzone(m);
1986 if(cvar("sv_eventlog"))
1987 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)), TRUE);
1988 return strcat("Suggestion of ", m, " accepted.");
1991 void MapVote_AddVotable(string nextMap, float isSuggestion)
1996 for(j = 0; j < mapvote_count; ++j)
1997 if(mapvote_maps[j] == nextMap)
1999 if(strlen(nextMap) > mapvote_maxlen)
2000 mapvote_maxlen = strlen(nextMap);
2001 mapvote_maps[mapvote_count] = strzone(nextMap);
2002 mapvote_maps_suggested[mapvote_count] = isSuggestion;
2006 void MapVote_SendData(float target);
2012 MapVote_ClearAllVotes();
2015 mapvote_detail = !cvar("g_maplist_votable_nodetail");
2016 mapvote_abstain = cvar("g_maplist_votable_abstain");
2019 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
2021 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
2022 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
2024 if(mapvote_suggestion_ptr)
2025 for(i = 0; i < 100 && mapvote_count < smax; ++i)
2026 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
2028 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2029 MapVote_AddVotable(GetNextMap(), FALSE);
2031 if(mapvote_count == 0)
2033 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
2035 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
2036 localcmd("\nmenu_cmd sync\n");
2038 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
2040 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2041 MapVote_AddVotable(GetNextMap(), FALSE);
2044 mapvote_count_real = mapvote_count;
2046 MapVote_AddVotable("don't care", 0);
2048 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
2050 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
2051 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
2052 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
2053 mapvote_keeptwotime = 0;
2054 mapvote_message = "Choose a map and press its key!";
2056 mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
2057 if(mapvote_screenshot_dir == "")
2058 mapvote_screenshot_dir = "maps";
2059 mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
2061 if(!cvar("g_maplist_textonly"))
2062 MapVote_SendData(MSG_BROADCAST);
2065 void MapVote_SendPicture(float id)
2068 WriteByte(MSG_ONE, SVC_TEMPENTITY);
2069 WriteByte(MSG_ONE, TE_CSQC_MAPVOTE);
2070 WriteByte(MSG_ONE, MAPVOTE_NET_PIC);
2071 WriteByte(MSG_ONE, id);
2072 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 1024);
2075 float GameCommand_MapVote(string cmd)
2077 if(!intermission_running)
2079 if(!cvar("g_maplist_textonly"))
2081 if(cmd == "mv_getpic")
2083 MapVote_SendPicture(stof(argv(1)));
2091 float MapVote_GetMapMask()
2093 float mask, i, power;
2095 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
2096 if(mapvote_maps[i] != "")
2101 void MapVote_SendData(float targ)
2103 string mapfile, pakfile;
2105 WriteByte(targ, SVC_TEMPENTITY);
2106 WriteByte(targ, TE_CSQC_CONFIG);
2107 WriteString(targ, "mv_screenshot_dir");
2108 WriteString(targ, mapvote_screenshot_dir);
2110 WriteByte(targ, SVC_TEMPENTITY);
2111 WriteByte(targ, TE_CSQC_MAPVOTE);
2112 WriteByte(targ, MAPVOTE_NET_INIT);
2114 WriteByte(targ, mapvote_count);
2115 WriteByte(targ, mapvote_abstain);
2116 WriteByte(targ, mapvote_detail);
2117 WriteByte(targ, mapvote_timeout - time);
2118 if(mapvote_count <= 8)
2119 WriteByte(targ, MapVote_GetMapMask());
2121 WriteShort(targ, MapVote_GetMapMask());
2122 for(i = 0; i < mapvote_count; ++i)
2123 if(mapvote_maps[i] != "")
2125 WriteString(targ, mapvote_maps[i]);
2126 mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
2127 pakfile = whichpack(strcat(mapfile, ".tga"));
2129 pakfile = whichpack(strcat(mapfile, ".jpg"));
2131 pakfile = whichpack(strcat(mapfile, ".png"));
2132 print("pakfile is ", pakfile, "\n");
2133 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
2134 pakfile = substring(pakfile, o, 999);
2135 WriteString(targ, pakfile);
2139 void MapVote_UpdateData(float targ)
2142 WriteByte(targ, SVC_TEMPENTITY);
2143 WriteByte(targ, TE_CSQC_MAPVOTE);
2144 WriteByte(targ, MAPVOTE_NET_UPDATE);
2145 if(mapvote_count <= 8)
2146 WriteByte(targ, MapVote_GetMapMask());
2148 WriteShort(targ, MapVote_GetMapMask());
2150 for(i = 0; i < mapvote_count; ++i)
2151 if(mapvote_maps[i] != "")
2152 WriteByte(targ, mapvote_votes[i]);
2155 void MapVote_TellVote(float targ, float vote)
2157 WriteByte(targ, SVC_TEMPENTITY);
2158 WriteByte(targ, TE_CSQC_MAPVOTE);
2159 WriteByte(targ, MAPVOTE_NET_OWNVOTE);
2160 WriteByte(targ, vote);
2163 float MapVote_Finished(float mappos)
2169 if(cvar("sv_eventlog"))
2171 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2172 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
2173 didntvote = mapvote_voters;
2174 for(i = 0; i < mapvote_count; ++i)
2175 if(mapvote_maps[i] != "")
2177 didntvote -= mapvote_votes[i];
2180 result = strcat(result, ":", mapvote_maps[i]);
2181 result = strcat(result, ":", ftos(mapvote_votes[i]));
2184 result = strcat(result, ":didn't vote:", ftos(didntvote));
2186 GameLogEcho(result, FALSE);
2187 if(mapvote_maps_suggested[mappos])
2188 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
2191 FOR_EACH_REALCLIENT(other)
2192 FixClientCvars(other);
2194 Map_Goto_SetStr(mapvote_maps[mappos]);
2196 alreadychangedlevel = TRUE;
2199 void MapVote_CheckRules_1()
2203 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2205 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2206 mapvote_votes[i] = 0;
2210 FOR_EACH_REALCLIENT(other)
2215 i = other.mapvote - 1;
2216 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2217 mapvote_votes[i] = mapvote_votes[i] + 1;
2222 float MapVote_CheckRules_2()
2225 float firstPlace, secondPlace;
2226 float firstPlaceVotes, secondPlaceVotes;
2227 float mapvote_voters_real;
2230 mapvote_voters_real = mapvote_voters;
2232 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2234 RandomSelection_Init();
2235 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2236 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2237 firstPlace = RandomSelection_chosen_float;
2238 firstPlaceVotes = RandomSelection_best_priority;
2239 //dprint("First place: ", ftos(firstPlace), "\n");
2240 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2242 RandomSelection_Init();
2243 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2245 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2246 secondPlace = RandomSelection_chosen_float;
2247 secondPlaceVotes = RandomSelection_best_priority;
2248 //dprint("Second place: ", ftos(secondPlace), "\n");
2249 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2251 if(firstPlace == -1)
2252 error("No first place in map vote... WTF?");
2254 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2255 return MapVote_Finished(firstPlace);
2257 if(mapvote_keeptwotime)
2258 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2261 mapvote_dirty = TRUE;
2262 mapvote_message = "Now decide between the TOP TWO!";
2263 mapvote_keeptwotime = 0;
2264 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2265 result = strcat(result, ":", ftos(firstPlaceVotes));
2266 result = strcat(result, ":", mapvote_maps[secondPlace]);
2267 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2268 didntvote = mapvote_voters;
2269 for(i = 0; i < mapvote_count; ++i)
2270 if(mapvote_maps[i] != "")
2272 didntvote -= mapvote_votes[i];
2274 if(i != secondPlace)
2276 result = strcat(result, ":", mapvote_maps[i]);
2277 result = strcat(result, ":", ftos(mapvote_votes[i]));
2278 if(i < mapvote_count_real)
2280 strunzone(mapvote_maps[i]);
2281 mapvote_maps[i] = "";
2285 result = strcat(result, ":didn't vote:", ftos(didntvote));
2286 if(cvar("sv_eventlog"))
2287 GameLogEcho(result, FALSE);
2300 keeptwo = mapvote_keeptwotime;
2301 MapVote_CheckRules_1(); // count
2302 if(MapVote_CheckRules_2()) // decide
2306 FOR_EACH_REALCLIENT(other)
2308 // hide scoreboard again
2309 if(other.health != 2342)
2311 other.health = 2342;
2313 if(clienttype(other) == CLIENTTYPE_REAL)
2315 if(cvar("g_maplist_textonly"))
2316 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");
2319 WriteByte(MSG_ONE, SVC_FINALE);
2320 WriteString(MSG_ONE, "");
2324 // notify about keep-two
2325 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2326 play2(other, "misc/invshot.wav");
2328 // clear possibly invalid votes
2329 if(mapvote_maps[other.mapvote - 1] == "")
2331 // use impulses as new vote
2332 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2333 if(mapvote_maps[other.impulse - 1] != "")
2335 other.mapvote = other.impulse;
2337 mapvote_dirty = TRUE;
2340 MapVote_TellVote(MSG_ONE, other.mapvote);
2348 MapVote_CheckRules_1(); // just count
2350 if(!cvar("g_maplist_textonly"))
2351 if(mapvote_dirty) // 1 if "keeptwo" or "impulse" happened before
2353 MapVote_UpdateData(MSG_BROADCAST);
2354 mapvote_dirty = FALSE;
2357 if(cvar("g_maplist_textonly"))
2359 FOR_EACH_REALCLIENT(other)
2361 // display voting screen
2362 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2363 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2365 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2366 msgstr = strcat(msgstr, mapvote_message);
2367 msgstr = strcat(msgstr, "\n\n");
2368 for(i = 0; i < mapvote_count; ++i)
2369 if(mapvote_maps[i] == "")
2370 msgstr = strcat(msgstr, "\n");
2373 tmp = mapvote_maps[i];
2374 tmp = strpad(mapvote_maxlen, tmp);
2375 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2378 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2379 if(mapvote_votes[i] != 1)
2380 tmp = strcat(tmp, "s");
2381 tmp = strcat(tmp, ")");
2382 tmp = strpad(mapvote_maxlen + 15, tmp);
2385 if(i == mapvote_count - 1)
2386 msgstr = strcat(msgstr, "\n");
2387 if(other.mapvote == i + 1)
2388 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2390 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2393 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2395 msgstr = strcat(msgstr, "s");
2396 msgstr = strcat(msgstr, " cast");
2397 i = ceil(mapvote_timeout - time);
2398 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2400 msgstr = strcat(msgstr, "s");
2401 msgstr = strcat(msgstr, " left");
2403 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2407 void MapVote_Start()
2413 MapInfo_Enumerate();
2414 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2418 void MapVote_Think()
2423 if(alreadychangedlevel)
2426 if(time < mapvote_nextthink)
2430 mapvote_nextthink = time + 0.5;
2432 if(!mapvote_initialized)
2434 mapvote_initialized = TRUE;
2435 if(DoNextMapOverride())
2437 if(!cvar("g_maplist_votable") || player_count <= 0)
2448 string GotoMap(string m)
2451 if(!MapInfo_CheckMap(m))
2453 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2455 return "The map you chose is not available on this server.";
2456 cvar_set("nextmap", m);
2457 cvar_set("timelimit", "-1");
2458 if(mapvote_initialized || alreadychangedlevel)
2460 if(DoNextMapOverride())
2461 return "Map switch initiated.";
2463 return "Hm... no. For some reason I like THIS map more.";
2466 return "Map switch will happen after scoreboard.";
2472 FOR_EACH_REALCLIENT(self)
2474 if(self.classname == "spectator")
2476 if(self.enemy.hitsound)
2477 play2(self, "misc/hit.wav");
2482 play2(self, "misc/hit.wav");
2485 FOR_EACH_CLIENT(self)
2486 self.hitsound = FALSE;
2492 * returns TRUE if redirecting
2494 float redirection_timeout;
2495 float redirection_nextthink;
2496 float RedirectionThink()
2498 float clients_found;
2500 if(redirection_target == "")
2503 if(!redirection_timeout)
2505 cvar_set("sv_public", "-2");
2506 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2507 if(redirection_target == "self")
2508 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2510 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2513 if(time < redirection_nextthink)
2516 redirection_nextthink = time + 1;
2519 FOR_EACH_REALCLIENT(self)
2521 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2522 if(redirection_target == "self")
2523 stuffcmd(self, "\ndisconnect; reconnect\n");
2525 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2529 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2531 if(time > redirection_timeout || clients_found == 0)
2532 localcmd("\nwait; wait; wait; quit\n");
2539 if(world_initialized)
2541 world_initialized = 0;
2542 print("Saving persistent data...\n");
2545 db_save(ServerProgsDB, "server.db");
2546 db_close(ServerProgsDB);
2548 // tell the bot system the game is ending now
2555 print("NOTE: crashed before even initializing the world, not saving persistent data\n");