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 return GametypeNameFromType(game);
388 float IsSameGametype(string mapcfgname)
391 return TRUE; // can't change game type by map name here
395 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
401 string getmapname_stored;
407 if(getmapname_stored == "")
408 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
409 return getmapname_stored;
413 float Map_Count, Map_Current;
414 string Map_Current_Name;
416 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
417 float GetMaplistPosition()
423 idx = cvar("g_maplist_index");
430 for(pos = 0; pos < Map_Count; ++pos)
434 // resume normal maplist rotation if current map is not in g_maplist
438 float MapHasRightSize(string map)
441 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
442 if(cvar("g_maplist_check_waypoints"))
444 dprint("checkwp "); dprint(map);
445 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
448 dprint(": no waypoints\n");
451 dprint(": has waypoints\n");
455 // open map size restriction file
456 dprint("opensize "); dprint(map);
457 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
460 float mapmin, mapmax;
462 mapmin = stof(fgets(fh));
463 mapmax = stof(fgets(fh));
465 if(player_count < mapmin)
467 dprint("not enough\n");
470 if(player_count > mapmax)
472 dprint("too many\n");
475 dprint("right size\n");
478 dprint(": not found\n");
482 string Map_Filename(float position)
485 return strcat("maps/", argv(position), ".bsp");
487 return strcat("maps/", argv(position), ".mapcfg");
491 string strwords(string s, float w)
494 for(endpos = 0; w && endpos >= 0; --w)
495 endpos = strstrofs(s, " ", endpos + 1);
499 return substring(s, 0, endpos);
502 float strhasword(string s, string w)
504 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
507 void Map_MarkAsRecent(string m)
509 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
512 float Map_IsRecent(string m)
514 return strhasword(cvar_string("g_maplist_mostrecent"), m);
517 float Map_Check(float position, float pass)
521 map_next = argv(position);
524 if(map_next == Map_Current_Name) // same map again in first pass?
526 if(Map_IsRecent(map_next))
529 filename = Map_Filename(position);
531 if(MapInfo_CheckMap(map_next))
533 if(TryFile(filename))
538 if(MapHasRightSize(map_next))
543 dprint( "Couldn't select '", filename, "'..\n" );
548 void Map_Goto_SetStr(string nextmapname)
550 if(getmapname_stored != "")
551 strunzone(getmapname_stored);
552 if(nextmapname == "")
553 getmapname_stored = "";
555 getmapname_stored = strzone(nextmapname);
558 void Map_Goto_SetFloat(float position)
560 cvar_set("g_maplist_index", ftos(position));
561 Map_Goto_SetStr(argv(position));
567 // settings persist, except...
568 if(cvar("g_campaign"))
569 localcmd("\nexec mutator_reset.cfg\n");
570 localcmd("\nsettemp_restore\n");
572 // if an exit cfg is defined by exiting map, exec it.
574 exit_cfg = cvar_string("exit_cfg");
576 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
578 localcmd("exec game_reset.cfg\n");
584 Map_MarkAsRecent(getmapname_stored);
587 MapInfo_LoadMap(getmapname_stored);
589 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
593 // return codes of map selectors:
594 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
595 // -2 = permanent failure
596 float() MaplistMethod_Iterate = // usual method
600 for(pass = 1; pass <= 2; ++pass)
602 for(i = 1; i < Map_Count; ++i)
605 mapindex = mod(i + Map_Current, Map_Count);
606 if(Map_Check(mapindex, pass))
613 float() MaplistMethod_Repeat = // fallback method
615 if(Map_Check(Map_Current, 2))
620 float() MaplistMethod_Random = // random map selection
626 for(i = 0; i <= imax; ++i)
629 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
630 if(Map_Check(mapindex, 1))
636 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
637 // the exponent sets a bias on the map selection:
638 // the higher the exponent, the less likely "shortly repeated" same maps are
640 float i, j, imax, insertpos;
644 for(i = 0; i <= imax; ++i)
648 // now reinsert this at another position
649 insertpos = pow(random(), 1 / exponent); // ]0, 1]
650 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
651 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
652 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
654 // insert the current map there
657 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
658 newlist = strcat(newlist, " ", argv(j));
659 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
660 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
661 newlist = strcat(newlist, " ", argv(j));
662 newlist = substring(newlist, 1, strlen(newlist) - 1);
664 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
665 newlist = strcat(newlist, "'", argv(j), "'");
666 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
667 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
668 newlist = strcat(newlist, "'", argv(j), "'");
670 cvar_set("g_maplist", newlist);
672 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
674 Map_Count = tokenize(newlist);
677 // NOTE: the selected map has just been inserted at (insertpos-1)th position
678 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
679 if(Map_Check(Map_Current, 1))
688 temp = cvar_string("g_maplist");
690 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
692 Map_Count = tokenize(temp);
696 bprint( "Maplist is empty! Resetting it to default map list.\n" );
698 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
699 localcmd("\nmenu_cmd sync\n");
700 Map_Count = tokenizebyseparator(temp, " ");
702 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
703 Map_Count = tokenize(temp);
707 error("empty maplist, cannot select a new map");
708 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
711 strunzone(Map_Current_Name);
712 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
713 // this may or may not be correct, but who cares, in the worst case a map
714 // isn't chosen in the first pass that should have been
725 if(cvar("g_maplist_shuffle") > 0)
726 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
729 if(cvar("g_maplist_selectrandom"))
730 nextMap = MaplistMethod_Random();
733 nextMap = MaplistMethod_Iterate();
736 nextMap = MaplistMethod_Repeat();
740 Map_Goto_SetFloat(nextMap);
741 return getmapname_stored;
747 float DoNextMapOverride()
749 if(cvar("g_campaign"))
751 CampaignPostIntermission();
752 alreadychangedlevel = TRUE;
755 if(cvar("quit_when_empty"))
757 if(player_count <= currentbots)
760 alreadychangedlevel = TRUE;
764 if(cvar_string("quit_and_redirect") != "")
766 redirection_target = strzone(cvar_string("quit_and_redirect"));
767 alreadychangedlevel = TRUE;
770 if (cvar("samelevel")) // if samelevel is set, stay on same level
772 // 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)
773 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
774 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
775 localcmd("restart\n");
776 //changelevel (mapname);
777 alreadychangedlevel = TRUE;
780 if(cvar_string("nextmap") != "")
782 if(MapInfo_CheckMap(cvar_string("nextmap")))
784 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
787 Map_Goto_SetStr(cvar_string("nextmap"));
789 alreadychangedlevel = TRUE;
792 if(cvar("lastlevel"))
795 localcmd("set lastlevel 0\ntogglemenu\n");
796 alreadychangedlevel = TRUE;
804 //local string nextmap;
805 //local float n, nummaps;
807 if (alreadychangedlevel)
809 alreadychangedlevel = TRUE;
815 for(allowReset = 1; allowReset >= 0; --allowReset)
817 nextMap = GetNextMap();
823 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
825 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
826 localcmd("\nmenu_cmd sync\n");
828 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
833 error("Everything is broken - not even the default map list works. Please report this to the developers.");
845 When the player presses attack or jump, change to the next level
848 .float autoscreenshot;
849 void() MapVote_Start;
850 void() MapVote_Think;
851 float mapvote_initialized;
852 void IntermissionThink()
854 FixIntermissionClient(self);
856 if(cvar("sv_autoscreenshot"))
857 if(self.autoscreenshot > 0)
858 if(time > self.autoscreenshot)
860 self.autoscreenshot = -1;
861 if(clienttype(self) == CLIENTTYPE_REAL)
862 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
866 if (time < intermission_exittime)
869 if(!mapvote_initialized)
870 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
880 Returns the entity to view from
884 entity FindIntermission()
889 // look for info_intermission first
890 spot = find (world, classname, "info_intermission");
892 { // pick a random one
896 spot = find (spot, classname, "info_intermission");
898 spot = find (spot, classname, "info_intermission");
904 // then look for the start position
905 spot = find (world, classname, "info_player_start");
909 // testinfo_player_start is only found in regioned levels
910 spot = find (world, classname, "testplayerstart");
914 // then look for the start position
915 spot = find (world, classname, "info_player_deathmatch");
919 //objerror ("FindIntermission: no spot");
925 ===============================================================================
929 ===============================================================================
932 void DumpStats(float final)
936 local float to_console;
937 local float to_eventlog;
940 to_console = cvar("sv_logscores_console");
941 to_eventlog = cvar("sv_eventlog");
942 to_file = cvar("sv_logscores_file");
946 to_console = TRUE; // always print printstats replies
947 to_eventlog = FALSE; // but never print them to the event log
951 if(cvar("sv_eventlog_console"))
952 to_console = FALSE; // otherwise we get the output twice
959 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
961 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
965 ServerConsoleEcho(s, FALSE);
967 GameLogEcho(s, FALSE);
970 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
974 fputs(file, strcat(s, "\n"));
977 FOR_EACH_CLIENT(other)
979 // FIXME make this use the new score system
980 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
982 s = strcat(":player:", ftos(other.frags), ":");
983 s = strcat(s, ftos(other.deaths), ":");
984 s = strcat(s, ftos(rint(time - other.jointime)), ":");
985 s = strcat(s, ftos(other.team), ":");
988 ServerConsoleEcho(strcat(s, other.netname), TRUE);
990 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
992 fputs(file, strcat(s, other.netname, "\n"));
997 if(cvar("g_ctf_win_mode") != 2)
999 s = strcat(":teamscores:", ftos(COLOR_TEAM1), ":");
1000 s = strcat(s, ftos(caps_team1), ":");
1001 s = strcat(s, ftos(COLOR_TEAM2), ":");
1002 s = strcat(s, ftos(caps_team2));
1004 ServerConsoleEcho(s, TRUE);
1006 GameLogEcho(s, TRUE);
1008 fputs(file, strcat(s, "\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 GetWinningCode(float fraglimitreached, float equality)
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 SetWinners(.float field, float value)
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 AddWinners(.float field, float value)
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 ClearFragsForEveryoneBut(.float field, float value)
1209 // FIXME make this use the new score system (probably not needed any more, can just send this as an event)
1211 FOR_EACH_PLAYER(head)
1212 if(head.field != value)
1213 head.frags = max(head.frags, 0);
1216 // clear the .winning flags
1217 void ClearWinners(void)
1220 FOR_EACH_PLAYER(head)
1224 // Onslaught winning condition:
1225 // game terminates if only one team has a working generator (or none)
1226 float WinningCondition_Onslaught()
1229 local float t1, t2, t3, t4;
1230 // first check if the game has ended
1231 t1 = t2 = t3 = t4 = 0;
1232 head = find(world, classname, "onslaught_generator");
1235 if (head.health > 0)
1237 if (head.team == COLOR_TEAM1) t1 = 1;
1238 if (head.team == COLOR_TEAM2) t2 = 1;
1239 if (head.team == COLOR_TEAM3) t3 = 1;
1240 if (head.team == COLOR_TEAM4) t4 = 1;
1242 head = find(head, classname, "onslaught_generator");
1244 if (t1 + t2 + t3 + t4 < 2)
1246 // game over, only one team remains (or none)
1248 if (t1) SetWinners(team, COLOR_TEAM1);
1249 if (t2) SetWinners(team, COLOR_TEAM2);
1250 if (t3) SetWinners(team, COLOR_TEAM3);
1251 if (t4) SetWinners(team, COLOR_TEAM4);
1252 dprint("Have a winner, ending game.\n");
1256 // Two or more teams remain
1260 float LMS_NewPlayerLives()
1263 fl = cvar("fraglimit");
1267 // first player has left the game for dying too much? Nobody else can get in.
1268 if(lms_lowest_lives < 1)
1271 if(!cvar("g_lms_join_anytime"))
1272 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1275 return bound(1, lms_lowest_lives, fl);
1278 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1279 // they win. Otherwise the defending team wins once the timelimit passes.
1280 void assault_new_round();
1281 float WinningCondition_Assault()
1284 status = WINNING_NO;
1286 // as the timelimit has not yet passed just assume the defending team will win
1287 if(assault_attacker_team == COLOR_TEAM1)
1289 SetWinners(team, COLOR_TEAM2);
1293 SetWinners(team, COLOR_TEAM1);
1297 ent = find(world, classname, "target_assault_roundend");
1300 if(ent.winning) // round end has been triggered by attacking team
1302 SetWinners(team, assault_attacker_team);
1303 if(assault_attacker_team == COLOR_TEAM1)
1305 team1_score = team1_score + 50;
1309 team2_score = team2_score + 50;
1312 if(ent.cnt == 1) // this was the second round
1314 status = WINNING_YES;
1318 local entity oldself;
1321 cvar_set("timelimit", ftos((2*time)/60));
1322 assault_new_round();
1333 // LMS winning condition: game terminates if and only if there's at most one
1334 // one player who's living lives. Top two scores being equal cancels the time
1336 float WinningCondition_LMS()
1338 // FIXME make this use the new score system
1344 have_player = FALSE;
1345 have_players = FALSE;
1346 l = LMS_NewPlayerLives();
1348 head = find(world, classname, "player");
1351 head = find(head, classname, "player");
1353 have_players = TRUE;
1357 // we have at least one player
1360 // two or more active players - continue with the game
1364 // exactly one player?
1367 // but no game has taken place yet
1372 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1373 dprint("Have a winner, ending game.\n");
1380 // nobody is playing at all...
1383 // wait for players...
1387 // SNAFU (maybe a draw game?)
1389 dprint("No players, ending game.\n");
1394 // When we get here, we have at least two players who are actually LIVING,
1395 // or one player who is still waiting for a victim to join the server. Now
1396 // check if the top two players have equal score.
1398 checkrules_leaderfrags = 0;
1399 checkrules_equality = FALSE;
1400 FOR_EACH_PLAYER(head)
1402 if(head.frags > checkrules_leaderfrags)
1404 checkrules_leaderfrags = head.frags;
1405 checkrules_equality = FALSE;
1407 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1408 checkrules_equality = TRUE;
1411 SetWinners(frags, checkrules_leaderfrags);
1413 // The top two players have the same amount of lives? No timelimit then,
1414 // enter overtime...
1416 if(checkrules_equality)
1417 return WINNING_NEVER;
1419 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1423 // DM winning condition: game terminates if a player reached the fraglimit,
1424 // unless the first two players have the same score. The latter case also
1425 // breaks the time limit.
1426 float WinningCondition_MaxIndividualScore(float fraglimit)
1429 float checkrules_oldleaderfrags;
1432 checkrules_oldleaderfrags = checkrules_leaderfrags;
1433 checkrules_leaderfrags = 0;
1434 checkrules_equality = FALSE;
1435 FOR_EACH_PLAYER(head)
1437 if(head.frags > checkrules_leaderfrags)
1439 checkrules_leaderfrags = head.frags;
1440 checkrules_equality = FALSE;
1442 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1443 checkrules_equality = TRUE;
1446 if(checkrules_leaderfrags > 0)
1447 SetWinners(frags, checkrules_leaderfrags);
1452 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1454 if (checkrules_leaderfrags == fraglimit - 1)
1455 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1456 else if (checkrules_leaderfrags == fraglimit - 2)
1457 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1458 else if (checkrules_leaderfrags == fraglimit - 3)
1459 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1462 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1465 float WinningConditionBase_Teamplay(float fraglimit)
1468 tdm_old_score = tdm_max_score;
1469 tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1471 checkrules_equality =
1476 (team1_score == tdm_max_score)
1477 + (team2_score == tdm_max_score)
1478 + (team3_score == tdm_max_score)
1479 + (team4_score == tdm_max_score)
1483 if(tdm_max_score > 0)
1485 if(team1_score == tdm_max_score)
1486 AddWinners(team, COLOR_TEAM1);
1487 if(team2_score == tdm_max_score)
1488 AddWinners(team, COLOR_TEAM2);
1489 if(team3_score == tdm_max_score)
1490 AddWinners(team, COLOR_TEAM3);
1491 if(team4_score == tdm_max_score)
1492 AddWinners(team, COLOR_TEAM4);
1495 if(!g_runematch && !g_domination && !g_ctf)
1496 if(tdm_max_score != tdm_old_score)
1498 if(tdm_max_score == fraglimit - 1)
1499 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1500 else if(tdm_max_score == fraglimit - 2)
1501 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1502 else if(tdm_max_score == fraglimit - 3)
1503 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1506 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1509 // TDM winning condition: game terminates if a team's score sum reached the
1510 // fraglimit, unless the first two teams have the same total score. The latter
1511 // case also breaks the time limit.
1512 float WinningCondition_MaxTeamSum(float fraglimit)
1517 team1_score = team2_score = team3_score = team4_score = 0;
1519 FOR_EACH_PLAYER(head)
1521 if(head.team == COLOR_TEAM1)
1522 team1_score += head.frags;
1523 else if(head.team == COLOR_TEAM2)
1524 team2_score += head.frags;
1525 else if(head.team == COLOR_TEAM3)
1526 team3_score += head.frags;
1527 else if(head.team == COLOR_TEAM4)
1528 team4_score += head.frags;
1531 return WinningConditionBase_Teamplay(fraglimit);
1534 // DOM/CTF winning condition: game terminates if the max of a team's players'
1535 // score reached the fraglimit, unless the first two teams have the same
1536 // maximum score. The latter case also breaks the time limit.
1537 float WinningCondition_MaxTeamMax(float fraglimit)
1542 team1_score = team2_score = team3_score = team4_score = 0;
1544 FOR_EACH_PLAYER(head)
1546 if(head.team == COLOR_TEAM1)
1548 if(head.frags > team1_score)
1549 team1_score = head.frags;
1551 else if(head.team == COLOR_TEAM2)
1553 if(head.frags > team2_score)
1554 team2_score = head.frags;
1556 else if(head.team == COLOR_TEAM3)
1558 if(head.frags > team3_score)
1559 team3_score = head.frags;
1561 else if(head.team == COLOR_TEAM4)
1563 if(head.frags > team4_score)
1564 team4_score = head.frags;
1568 return WinningConditionBase_Teamplay(fraglimit);
1571 float WinningCondition_CTF(float capturelimit, float fraglimit)
1574 if(cvar("g_ctf_win_mode") == 2)
1575 return WinningCondition_MaxTeamSum(fraglimit);
1577 team1_score = caps_team1;
1578 team2_score = caps_team2;
1579 team3_score = team4_score = 0;
1581 if(team1_score == team2_score && cvar("g_ctf_win_mode"))
1583 return WinningCondition_MaxTeamSum(0);
1586 return WinningConditionBase_Teamplay(capturelimit);
1589 void print_to(entity e, string s)
1592 sprint(e, strcat(s, "\n"));
1594 ServerConsoleEcho(s, TRUE);
1597 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1599 // FIXME kill this, or make it support the new scoring system
1608 FOR_EACH_PLAYER(head)
1610 if(!whichteam || head.team == whichteam)
1614 print_to(e, strcat(" ", colorcode, name, ":"));
1616 fragtotal = fragtotal + head.frags;
1617 s = ftos(head.frags);
1618 s = strcat(s, "/", ftos(head.deaths));
1619 s = strcat(s, " @ ", ftos(head.ping));
1620 if(clienttype(head) == CLIENTTYPE_BOT)
1621 s = strcat(s, "botms");
1623 s = strcat(s, "ms");
1624 v = PlayerValue(head);
1626 s = strcat(s, " / ", ftos(v));
1627 print_to(e, strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"));
1630 if(whichteam && found)
1632 s = ftos(fragtotal);
1633 s = strcat(s, " / ", ftos(teamvalue));
1634 print_to(e, strcat(colorcode, " (total: ", s, ")"));
1638 void PrintScoreboard(entity e)
1640 // FIXME kill this, or make it support the new scoring system
1641 print_to(e, strcat("Time: ", ftos(time / 60)));
1642 print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1643 print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1644 print_to(e, "Scoreboard:");
1647 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1648 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1649 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM3);
1650 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM4);
1654 PrintScoreboardFor(e, "", "^7", 0);
1659 void ShuffleMaplist()
1667 result = cvar_string("g_maplist");
1669 litems = tokenizebyseparator(result, " ");
1671 litems = tokenize(result);
1674 for(start = 0; start < litems - 1; ++start)
1678 // select a random item
1679 selected = ceil(random() * (litems - start) + start) - 1;
1681 // shift this item to the place start
1683 for(i = 0; i < start; ++i)
1684 result = strcat(result, " ", argv(i));
1685 result = strcat(result, " ", argv(selected));
1686 for(i = start; i < litems; ++i)
1688 result = strcat(result, " ", argv(i));
1689 result = substring(result, 1, strlen(result) - 1);
1691 litems = tokenizebyseparator(result, " ");
1693 for(i = 0; i < start; ++i)
1694 result = strcat(result, "'", argv(i), "'");
1695 result = strcat(result, "'", argv(selected), "'");
1696 for(i = start; i < litems; ++i)
1698 result = strcat(result, "'", argv(i), "'");
1700 litems = tokenize(result);
1703 //dprint(result, "\n");
1706 cvar_set("g_maplist", result);
1709 float WinningCondition_Scores(float limit)
1711 // TODO make everything use THIS winning condition (except LMS perhaps, but... better even LMS)
1712 WinningConditionHelper();
1715 if(WinningConditionHelper_winner)
1716 WinningConditionHelper_winner.winning = 1;
1717 if(WinningConditionHelper_winnerteam >= 0)
1718 SetWinners(team, WinningConditionHelper_winnerteam);
1720 return GetWinningCode(WinningConditionHelper_topscore >= limit, WinningConditionHelper_equality);
1723 float WinningCondition_RanOutOfSpawns()
1727 if(!have_team_spawns)
1730 if(!some_spawn_has_been_used)
1733 team1_score = team2_score = team3_score = team4_score = 0;
1735 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1737 if(head.team == COLOR_TEAM1)
1739 else if(head.team == COLOR_TEAM2)
1741 else if(head.team == COLOR_TEAM3)
1743 else if(head.team == COLOR_TEAM4)
1747 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1749 if(head.team == COLOR_TEAM1)
1751 else if(head.team == COLOR_TEAM2)
1753 else if(head.team == COLOR_TEAM3)
1755 else if(head.team == COLOR_TEAM4)
1760 if(team1_score + team2_score + team3_score + team4_score == 0)
1762 checkrules_equality = TRUE;
1765 else if(team1_score + team2_score + team3_score + team4_score == 1)
1769 AddWinners(team, COLOR_TEAM1);
1770 ClearFragsForEveryoneBut(team, COLOR_TEAM1);
1774 AddWinners(team, COLOR_TEAM2);
1775 ClearFragsForEveryoneBut(team, COLOR_TEAM2);
1779 AddWinners(team, COLOR_TEAM3);
1780 ClearFragsForEveryoneBut(team, COLOR_TEAM3);
1784 AddWinners(team, COLOR_TEAM4);
1785 ClearFragsForEveryoneBut(team, COLOR_TEAM4);
1797 Exit deathmatch games upon conditions
1800 void CheckRules_World()
1803 local float timelimit;
1804 local float fraglimit;
1805 local float capturelimit;
1813 MapVote_Think should now do that part
1814 if (intermission_running)
1815 if (time >= intermission_exittime + 60)
1817 if(!DoNextMapOverride())
1823 if (gameover) // someone else quit the game already
1825 if(player_count == 0) // Nobody there? Then let's go to the next map
1827 // this will actually check the player count in the next frame
1828 // again, but this shouldn't hurt
1832 timelimit = cvar("timelimit") * 60;
1833 fraglimit = cvar("fraglimit");
1834 capturelimit = cvar("capturelimit");
1836 if(checkrules_overtimeend)
1838 if(!checkrules_overtimewarning)
1840 checkrules_overtimewarning = TRUE;
1841 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1842 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1847 if (timelimit && time >= timelimit)
1851 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1857 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1859 checkrules_oneminutewarning = TRUE;
1860 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1863 status = WinningCondition_RanOutOfSpawns();
1864 if(status == WINNING_YES)
1866 bprint("Hey! Someone ran out of spawns!\n");
1870 status = WinningCondition_Assault();
1874 status = WinningCondition_LMS();
1876 else if (g_onslaught)
1878 status = WinningCondition_Onslaught();
1882 status = WinningCondition_CTF(capturelimit, fraglimit);
1888 if(g_tdm || g_runematch || g_ctf || g_domination || g_keyhunt)
1889 status = WinningCondition_MaxTeamSum(fraglimit);
1891 // status = WinningCondition_MaxTeamMax(fraglimit);
1894 dprint("div0: How can this happen?\n");
1895 status = WinningCondition_MaxTeamMax(fraglimit);
1899 status = WinningCondition_MaxIndividualScore(fraglimit);
1902 if(status == WINNING_STARTOVERTIME)
1904 status = WINNING_NEVER;
1908 if(status == WINNING_NEVER)
1909 // equality cases! Nobody wins if the overtime ends in a draw.
1912 if(checkrules_overtimeend)
1913 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1914 status = WINNING_YES;
1916 if(status == WINNING_YES)
1920 float mapvote_nextthink;
1921 float mapvote_initialized;
1922 float mapvote_keeptwotime;
1923 float mapvote_timeout;
1924 string mapvote_message;
1925 string mapvote_screenshot_dir;
1927 float mapvote_count;
1928 float mapvote_count_real;
1929 string mapvote_maps[MAPVOTE_COUNT];
1930 float mapvote_maps_suggested[MAPVOTE_COUNT];
1931 string mapvote_suggestions[MAPVOTE_COUNT];
1932 float mapvote_suggestion_ptr;
1933 float mapvote_maxlen;
1934 float mapvote_voters;
1935 float mapvote_votes[MAPVOTE_COUNT];
1937 float mapvote_detail;
1938 float mapvote_abstain;
1939 float mapvote_dirty;
1942 void MapVote_ClearAllVotes()
1944 FOR_EACH_CLIENT(other)
1948 string MapVote_Suggest(string m)
1952 return "That's not how to use this command.";
1953 if(!cvar("g_maplist_votable_suggestions"))
1954 return "Suggestions are not accepted on this server.";
1955 if(mapvote_initialized)
1956 return "Can't suggest - voting is already in progress!";
1958 m = MapInfo_FixName(m);
1960 return "The map you suggested is not available on this server.";
1962 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1963 if(!IsSameGametype(m))
1964 return "This server does not allow changing the game type by map suggestions.";
1966 if(!cvar("g_maplist_votable_override_mostrecent"))
1968 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1971 if(!MapInfo_CheckMap(m))
1972 return "The map you suggested does not support the current game mode.";
1974 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1975 return "The map you suggested is not available on this server.";
1977 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1978 if(mapvote_suggestions[i] == m)
1979 return "This map was already suggested.";
1980 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1982 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1986 i = mapvote_suggestion_ptr;
1987 mapvote_suggestion_ptr += 1;
1989 if(mapvote_suggestions[i] != "")
1990 strunzone(mapvote_suggestions[i]);
1991 mapvote_suggestions[i] = strzone(m);
1992 if(cvar("sv_eventlog"))
1993 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)), TRUE);
1994 return strcat("Suggestion of ", m, " accepted.");
1997 void MapVote_AddVotable(string nextMap, float isSuggestion)
2002 for(j = 0; j < mapvote_count; ++j)
2003 if(mapvote_maps[j] == nextMap)
2005 if(strlen(nextMap) > mapvote_maxlen)
2006 mapvote_maxlen = strlen(nextMap);
2007 mapvote_maps[mapvote_count] = strzone(nextMap);
2008 mapvote_maps_suggested[mapvote_count] = isSuggestion;
2012 void MapVote_SendData(float target);
2018 MapVote_ClearAllVotes();
2021 mapvote_detail = !cvar("g_maplist_votable_nodetail");
2022 mapvote_abstain = cvar("g_maplist_votable_abstain");
2025 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
2027 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
2028 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
2030 if(mapvote_suggestion_ptr)
2031 for(i = 0; i < 100 && mapvote_count < smax; ++i)
2032 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
2034 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2035 MapVote_AddVotable(GetNextMap(), FALSE);
2037 if(mapvote_count == 0)
2039 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
2041 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
2042 localcmd("\nmenu_cmd sync\n");
2044 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
2046 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2047 MapVote_AddVotable(GetNextMap(), FALSE);
2050 mapvote_count_real = mapvote_count;
2052 MapVote_AddVotable("don't care", 0);
2054 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
2056 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
2057 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
2058 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
2059 mapvote_keeptwotime = 0;
2060 mapvote_message = "Choose a map and press its key!";
2062 mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
2063 if(mapvote_screenshot_dir == "")
2064 mapvote_screenshot_dir = "maps";
2065 mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
2067 if(!cvar("g_maplist_textonly"))
2068 MapVote_SendData(MSG_BROADCAST);
2071 void MapVote_SendPicture(float id)
2074 WriteByte(MSG_ONE, SVC_TEMPENTITY);
2075 WriteByte(MSG_ONE, TE_CSQC_MAPVOTE);
2076 WriteByte(MSG_ONE, MAPVOTE_NET_PIC);
2077 WriteByte(MSG_ONE, id);
2078 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 1024);
2081 float GameCommand_MapVote(string cmd)
2083 if(!intermission_running)
2085 if(!cvar("g_maplist_textonly"))
2087 if(cmd == "mv_getpic")
2089 MapVote_SendPicture(stof(argv(1)));
2097 float MapVote_GetMapMask()
2099 float mask, i, power;
2101 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
2102 if(mapvote_maps[i] != "")
2107 void MapVote_SendData(float targ)
2109 string mapfile, pakfile;
2111 WriteByte(targ, SVC_TEMPENTITY);
2112 WriteByte(targ, TE_CSQC_CONFIG);
2113 WriteString(targ, "mv_screenshot_dir");
2114 WriteString(targ, mapvote_screenshot_dir);
2116 WriteByte(targ, SVC_TEMPENTITY);
2117 WriteByte(targ, TE_CSQC_MAPVOTE);
2118 WriteByte(targ, MAPVOTE_NET_INIT);
2120 WriteByte(targ, mapvote_count);
2121 WriteByte(targ, mapvote_abstain);
2122 WriteByte(targ, mapvote_detail);
2123 WriteByte(targ, mapvote_timeout - time);
2124 if(mapvote_count <= 8)
2125 WriteByte(targ, MapVote_GetMapMask());
2127 WriteShort(targ, MapVote_GetMapMask());
2128 for(i = 0; i < mapvote_count; ++i)
2129 if(mapvote_maps[i] != "")
2131 WriteString(targ, mapvote_maps[i]);
2132 mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
2133 pakfile = whichpack(strcat(mapfile, ".tga"));
2135 pakfile = whichpack(strcat(mapfile, ".jpg"));
2137 pakfile = whichpack(strcat(mapfile, ".png"));
2138 print("pakfile is ", pakfile, "\n");
2139 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
2140 pakfile = substring(pakfile, o, 999);
2141 WriteString(targ, pakfile);
2145 void MapVote_UpdateData(float targ)
2148 WriteByte(targ, SVC_TEMPENTITY);
2149 WriteByte(targ, TE_CSQC_MAPVOTE);
2150 WriteByte(targ, MAPVOTE_NET_UPDATE);
2151 if(mapvote_count <= 8)
2152 WriteByte(targ, MapVote_GetMapMask());
2154 WriteShort(targ, MapVote_GetMapMask());
2156 for(i = 0; i < mapvote_count; ++i)
2157 if(mapvote_maps[i] != "")
2158 WriteByte(targ, mapvote_votes[i]);
2161 void MapVote_TellVote(float targ, float vote)
2163 WriteByte(targ, SVC_TEMPENTITY);
2164 WriteByte(targ, TE_CSQC_MAPVOTE);
2165 WriteByte(targ, MAPVOTE_NET_OWNVOTE);
2166 WriteByte(targ, vote);
2169 float MapVote_Finished(float mappos)
2175 if(cvar("sv_eventlog"))
2177 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2178 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
2179 didntvote = mapvote_voters;
2180 for(i = 0; i < mapvote_count; ++i)
2181 if(mapvote_maps[i] != "")
2183 didntvote -= mapvote_votes[i];
2186 result = strcat(result, ":", mapvote_maps[i]);
2187 result = strcat(result, ":", ftos(mapvote_votes[i]));
2190 result = strcat(result, ":didn't vote:", ftos(didntvote));
2192 GameLogEcho(result, FALSE);
2193 if(mapvote_maps_suggested[mappos])
2194 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
2197 FOR_EACH_REALCLIENT(other)
2198 FixClientCvars(other);
2200 Map_Goto_SetStr(mapvote_maps[mappos]);
2202 alreadychangedlevel = TRUE;
2205 void MapVote_CheckRules_1()
2209 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2211 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2212 mapvote_votes[i] = 0;
2216 FOR_EACH_REALCLIENT(other)
2221 i = other.mapvote - 1;
2222 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2223 mapvote_votes[i] = mapvote_votes[i] + 1;
2228 float MapVote_CheckRules_2()
2231 float firstPlace, secondPlace;
2232 float firstPlaceVotes, secondPlaceVotes;
2233 float mapvote_voters_real;
2236 mapvote_voters_real = mapvote_voters;
2238 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2240 RandomSelection_Init();
2241 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2242 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2243 firstPlace = RandomSelection_chosen_float;
2244 firstPlaceVotes = RandomSelection_best_priority;
2245 //dprint("First place: ", ftos(firstPlace), "\n");
2246 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2248 RandomSelection_Init();
2249 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2251 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2252 secondPlace = RandomSelection_chosen_float;
2253 secondPlaceVotes = RandomSelection_best_priority;
2254 //dprint("Second place: ", ftos(secondPlace), "\n");
2255 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2257 if(firstPlace == -1)
2258 error("No first place in map vote... WTF?");
2260 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2261 return MapVote_Finished(firstPlace);
2263 if(mapvote_keeptwotime)
2264 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2267 mapvote_dirty = TRUE;
2268 mapvote_message = "Now decide between the TOP TWO!";
2269 mapvote_keeptwotime = 0;
2270 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2271 result = strcat(result, ":", ftos(firstPlaceVotes));
2272 result = strcat(result, ":", mapvote_maps[secondPlace]);
2273 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2274 didntvote = mapvote_voters;
2275 for(i = 0; i < mapvote_count; ++i)
2276 if(mapvote_maps[i] != "")
2278 didntvote -= mapvote_votes[i];
2280 if(i != secondPlace)
2282 result = strcat(result, ":", mapvote_maps[i]);
2283 result = strcat(result, ":", ftos(mapvote_votes[i]));
2284 if(i < mapvote_count_real)
2286 strunzone(mapvote_maps[i]);
2287 mapvote_maps[i] = "";
2291 result = strcat(result, ":didn't vote:", ftos(didntvote));
2292 if(cvar("sv_eventlog"))
2293 GameLogEcho(result, FALSE);
2306 keeptwo = mapvote_keeptwotime;
2307 MapVote_CheckRules_1(); // count
2308 if(MapVote_CheckRules_2()) // decide
2312 FOR_EACH_REALCLIENT(other)
2314 // hide scoreboard again
2315 if(other.health != 2342)
2317 other.health = 2342;
2319 if(clienttype(other) == CLIENTTYPE_REAL)
2321 if(cvar("g_maplist_textonly"))
2322 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");
2325 WriteByte(MSG_ONE, SVC_FINALE);
2326 WriteString(MSG_ONE, "");
2330 // notify about keep-two
2331 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2332 play2(other, "misc/invshot.wav");
2334 // clear possibly invalid votes
2335 if(mapvote_maps[other.mapvote - 1] == "")
2337 // use impulses as new vote
2338 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2339 if(mapvote_maps[other.impulse - 1] != "")
2341 other.mapvote = other.impulse;
2343 mapvote_dirty = TRUE;
2346 MapVote_TellVote(MSG_ONE, other.mapvote);
2354 MapVote_CheckRules_1(); // just count
2356 if(!cvar("g_maplist_textonly"))
2357 if(mapvote_dirty) // 1 if "keeptwo" or "impulse" happened before
2359 MapVote_UpdateData(MSG_BROADCAST);
2360 mapvote_dirty = FALSE;
2363 if(cvar("g_maplist_textonly"))
2365 FOR_EACH_REALCLIENT(other)
2367 // display voting screen
2368 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2369 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2371 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2372 msgstr = strcat(msgstr, mapvote_message);
2373 msgstr = strcat(msgstr, "\n\n");
2374 for(i = 0; i < mapvote_count; ++i)
2375 if(mapvote_maps[i] == "")
2376 msgstr = strcat(msgstr, "\n");
2379 tmp = mapvote_maps[i];
2380 tmp = strpad(mapvote_maxlen, tmp);
2381 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2384 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2385 if(mapvote_votes[i] != 1)
2386 tmp = strcat(tmp, "s");
2387 tmp = strcat(tmp, ")");
2388 tmp = strpad(mapvote_maxlen + 15, tmp);
2391 if(i == mapvote_count - 1)
2392 msgstr = strcat(msgstr, "\n");
2393 if(other.mapvote == i + 1)
2394 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2396 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2399 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2401 msgstr = strcat(msgstr, "s");
2402 msgstr = strcat(msgstr, " cast");
2403 i = ceil(mapvote_timeout - time);
2404 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2406 msgstr = strcat(msgstr, "s");
2407 msgstr = strcat(msgstr, " left");
2409 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2413 void MapVote_Start()
2419 MapInfo_Enumerate();
2420 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2424 void MapVote_Think()
2429 if(alreadychangedlevel)
2432 if(time < mapvote_nextthink)
2436 mapvote_nextthink = time + 0.5;
2438 if(!mapvote_initialized)
2440 mapvote_initialized = TRUE;
2441 if(DoNextMapOverride())
2443 if(!cvar("g_maplist_votable") || player_count <= 0)
2454 string GotoMap(string m)
2457 if(!MapInfo_CheckMap(m))
2459 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2461 return "The map you chose is not available on this server.";
2462 cvar_set("nextmap", m);
2463 cvar_set("timelimit", "-1");
2464 if(mapvote_initialized || alreadychangedlevel)
2466 if(DoNextMapOverride())
2467 return "Map switch initiated.";
2469 return "Hm... no. For some reason I like THIS map more.";
2472 return "Map switch will happen after scoreboard.";
2478 FOR_EACH_REALCLIENT(self)
2480 if(self.classname == "spectator")
2482 if(self.enemy.hitsound)
2483 play2(self, "misc/hit.wav");
2488 play2(self, "misc/hit.wav");
2491 FOR_EACH_CLIENT(self)
2492 self.hitsound = FALSE;
2498 * returns TRUE if redirecting
2500 float redirection_timeout;
2501 float redirection_nextthink;
2502 float RedirectionThink()
2504 float clients_found;
2506 if(redirection_target == "")
2509 if(!redirection_timeout)
2511 cvar_set("sv_public", "-2");
2512 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2513 if(redirection_target == "self")
2514 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2516 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2519 if(time < redirection_nextthink)
2522 redirection_nextthink = time + 1;
2525 FOR_EACH_REALCLIENT(self)
2527 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2528 if(redirection_target == "self")
2529 stuffcmd(self, "\ndisconnect; reconnect\n");
2531 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2535 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2537 if(time > redirection_timeout || clients_found == 0)
2538 localcmd("\nwait; wait; wait; quit\n");
2545 if(world_initialized)
2547 world_initialized = 0;
2548 print("Saving persistent data...\n");
2551 db_save(ServerProgsDB, "server.db");
2552 db_close(ServerProgsDB);
2554 // tell the bot system the game is ending now
2561 print("NOTE: crashed before even initializing the world, not saving persistent data\n");