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.cnt += 10;
53 if(world.cnt > 0.2 || world.cnt < -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 play2all("announcer/robotic/prepareforbattle.wav");
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)
169 float fd, l, complain;
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);
192 clientstuff = strzone(MapInfo_Map_clientstuff);
193 MapInfo_ClearTemps();
197 ServerProgsDB = db_create();
199 ServerProgsDB = db_load("server.db");
202 TODO sound pack system
203 // initialize sound pack system
204 soundpack = cvar_string("g_soundpack");
206 soundpack = strcat(soundpack, "/");
207 soundpack = strzone(soundpack);
213 // 1 FLICKER (first variety)
214 lightstyle(1, "mmnmmommommnonmmonqnmmo");
216 // 2 SLOW STRONG PULSE
217 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
219 // 3 CANDLE (first variety)
220 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
223 lightstyle(4, "mamamamamama");
226 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
228 // 6 FLICKER (second variety)
229 lightstyle(6, "nmonqnmomnmomomno");
231 // 7 CANDLE (second variety)
232 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
234 // 8 CANDLE (third variety)
235 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
237 // 9 SLOW STROBE (fourth variety)
238 lightstyle(9, "aaaaaaaazzzzzzzz");
240 // 10 FLUORESCENT FLICKER
241 lightstyle(10, "mmamammmmammamamaaamammma");
243 // 11 SLOW PULSE NOT FADE TO BLACK
244 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
246 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
251 // for setting by mapinfo
252 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
253 cvar_set("sv_q3acompat_machineshotgunswap", "0");
256 lms_lowest_lives = 0;
259 bot_waypoints_for_items = cvar("g_waypoints_for_items");
260 if(bot_waypoints_for_items == 1)
261 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
262 bot_waypoints_for_items = 0;
264 if(cvar("g_campaign"))
271 WaypointSprite_Init();
276 GameLogInit(); // prepare everything
277 if(cvar("sv_eventlog"))
279 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
280 s = strcat(s, ftos(random()));
282 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s), FALSE);
284 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
286 s = ":gameinfo:mutators:LIST";
287 if(cvar("g_grappling_hook"))
288 s = strcat(s, ":grappling_hook");
289 if(!cvar("g_use_ammunition"))
290 s = strcat(s, ":no_use_ammunition");
291 if(!cvar("g_pickup_items"))
292 s = strcat(s, ":no_pickup_items");
293 if(cvar("g_instagib"))
294 s = strcat(s, ":instagib");
295 if(cvar("g_rocketarena"))
296 s = strcat(s, ":rockerarena");
298 s = strcat(s, ":nixnex");
299 if(cvar("g_vampire"))
300 s = strcat(s, ":vampire");
301 if(cvar("g_laserguided_missile"))
302 s = strcat(s, ":laserguided_missile");
303 if(cvar("g_norecoil"))
304 s = strcat(s, ":norecoil");
306 s = strcat(s, ":midair");
307 if(cvar("g_minstagib"))
308 s = strcat(s, ":minstagib");
309 GameLogEcho(s, FALSE);
310 GameLogEcho(":gameinfo:end", FALSE);
313 cvar_set("nextmap", "");
317 if(cvar("g_campaign"))
324 //initialise globals related to sv_timeout
325 sys_ticrate = cvar("sys_ticrate");
326 orig_slowmo = cvar("slowmo");
330 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
333 //if tourney is used map starts in warmup mode. if this mode shall stay unlimited, reset timelimit, but save the original one
334 if(g_tourney && cvar("g_tourney_warmup_unlimited_time")) {
335 timelimit_orig = cvar("timelimit");
336 cvar_set("timelimit", "0");
339 complain = (whichpack(strcat("maps/", mapname, ".cfg")) != "");
340 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
343 while((s = fgets(fd)))
352 bprint("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
353 bprint(" cdtrack ", argv(2), "\n");
356 else if(argv(0) == "fog")
362 s = strcat(argv(l), " ", s);
364 s = substring(s, 0, strlen(s) - 1);
367 bprint("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
368 bprint(" \"fog\" \"", s, "\"\n");
370 world.fog = strzone(s);
372 else if(argv(0) == "set")
376 bprint("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
377 bprint(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
380 else if(argv(0) != "//")
384 bprint("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
385 bprint(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
392 next_pingtime = time + 5;
393 world_initialized = 1;
396 void spawnfunc_light (void)
398 //makestatic (self); // Who the f___ did that?
402 float TryFile( string pFilename )
405 dprint("TryFile(\"", pFilename, "\")\n");
406 lHandle = fopen( pFilename, FILE_READ );
407 if( lHandle != -1 ) {
417 return GametypeNameFromType(game);
420 float IsSameGametype(string mapcfgname)
423 return TRUE; // can't change game type by map name here
427 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
433 string getmapname_stored;
439 if(getmapname_stored == "")
440 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
441 return getmapname_stored;
445 float Map_Count, Map_Current;
446 string Map_Current_Name;
448 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
449 float GetMaplistPosition()
455 idx = cvar("g_maplist_index");
462 for(pos = 0; pos < Map_Count; ++pos)
466 // resume normal maplist rotation if current map is not in g_maplist
470 float MapHasRightSize(string map)
473 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
474 if(cvar("g_maplist_check_waypoints"))
476 dprint("checkwp "); dprint(map);
477 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
480 dprint(": no waypoints\n");
483 dprint(": has waypoints\n");
487 // open map size restriction file
488 dprint("opensize "); dprint(map);
489 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
492 float mapmin, mapmax;
494 mapmin = stof(fgets(fh));
495 mapmax = stof(fgets(fh));
497 if(player_count < mapmin)
499 dprint("not enough\n");
502 if(player_count > mapmax)
504 dprint("too many\n");
507 dprint("right size\n");
510 dprint(": not found\n");
514 string Map_Filename(float position)
517 return strcat("maps/", argv(position), ".bsp");
519 return strcat("maps/", argv(position), ".mapcfg");
523 string strwords(string s, float w)
526 for(endpos = 0; w && endpos >= 0; --w)
527 endpos = strstrofs(s, " ", endpos + 1);
531 return substring(s, 0, endpos);
534 float strhasword(string s, string w)
536 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
539 void Map_MarkAsRecent(string m)
541 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
544 float Map_IsRecent(string m)
546 return strhasword(cvar_string("g_maplist_mostrecent"), m);
549 float Map_Check(float position, float pass)
553 map_next = argv(position);
556 if(map_next == Map_Current_Name) // same map again in first pass?
558 if(Map_IsRecent(map_next))
561 filename = Map_Filename(position);
563 if(MapInfo_CheckMap(map_next))
565 if(TryFile(filename))
570 if(MapHasRightSize(map_next))
575 dprint( "Couldn't select '", filename, "'..\n" );
580 void Map_Goto_SetStr(string nextmapname)
582 if(getmapname_stored != "")
583 strunzone(getmapname_stored);
584 if(nextmapname == "")
585 getmapname_stored = "";
587 getmapname_stored = strzone(nextmapname);
590 void Map_Goto_SetFloat(float position)
592 cvar_set("g_maplist_index", ftos(position));
593 Map_Goto_SetStr(argv(position));
599 // settings persist, except...
600 if(cvar("g_campaign"))
601 localcmd("\nexec mutator_reset.cfg\n");
602 localcmd("\nsettemp_restore\n");
604 // if an exit cfg is defined by exiting map, exec it.
606 exit_cfg = cvar_string("exit_cfg");
608 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
610 localcmd("exec game_reset.cfg\n");
616 Map_MarkAsRecent(getmapname_stored);
619 MapInfo_LoadMap(getmapname_stored);
621 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
625 // return codes of map selectors:
626 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
627 // -2 = permanent failure
628 float() MaplistMethod_Iterate = // usual method
632 for(pass = 1; pass <= 2; ++pass)
634 for(i = 1; i < Map_Count; ++i)
637 mapindex = mod(i + Map_Current, Map_Count);
638 if(Map_Check(mapindex, pass))
645 float() MaplistMethod_Repeat = // fallback method
647 if(Map_Check(Map_Current, 2))
652 float() MaplistMethod_Random = // random map selection
658 for(i = 0; i <= imax; ++i)
661 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
662 if(Map_Check(mapindex, 1))
668 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
669 // the exponent sets a bias on the map selection:
670 // the higher the exponent, the less likely "shortly repeated" same maps are
672 float i, j, imax, insertpos;
676 for(i = 0; i <= imax; ++i)
680 // now reinsert this at another position
681 insertpos = pow(random(), 1 / exponent); // ]0, 1]
682 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
683 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
684 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
686 // insert the current map there
689 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
690 newlist = strcat(newlist, " ", argv(j));
691 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
692 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
693 newlist = strcat(newlist, " ", argv(j));
694 newlist = substring(newlist, 1, strlen(newlist) - 1);
696 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
697 newlist = strcat(newlist, "'", argv(j), "'");
698 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
699 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
700 newlist = strcat(newlist, "'", argv(j), "'");
702 cvar_set("g_maplist", newlist);
704 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
706 Map_Count = tokenize(newlist);
709 // NOTE: the selected map has just been inserted at (insertpos-1)th position
710 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
711 if(Map_Check(Map_Current, 1))
720 temp = cvar_string("g_maplist");
722 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
724 Map_Count = tokenize(temp);
728 bprint( "Maplist is empty! Resetting it to default map list.\n" );
730 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
731 localcmd("\nmenu_cmd sync\n");
732 Map_Count = tokenizebyseparator(temp, " ");
734 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
735 Map_Count = tokenize(temp);
739 error("empty maplist, cannot select a new map");
740 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
743 strunzone(Map_Current_Name);
744 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
745 // this may or may not be correct, but who cares, in the worst case a map
746 // isn't chosen in the first pass that should have been
757 if(cvar("g_maplist_shuffle") > 0)
758 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
761 if(cvar("g_maplist_selectrandom"))
762 nextMap = MaplistMethod_Random();
765 nextMap = MaplistMethod_Iterate();
768 nextMap = MaplistMethod_Repeat();
772 Map_Goto_SetFloat(nextMap);
773 return getmapname_stored;
779 float DoNextMapOverride()
781 if(cvar("g_campaign"))
783 CampaignPostIntermission();
784 alreadychangedlevel = TRUE;
787 if(cvar("quit_when_empty"))
789 if(player_count <= currentbots)
792 alreadychangedlevel = TRUE;
796 if(cvar_string("quit_and_redirect") != "")
798 redirection_target = strzone(cvar_string("quit_and_redirect"));
799 alreadychangedlevel = TRUE;
802 if (cvar("samelevel")) // if samelevel is set, stay on same level
804 // 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)
805 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
806 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
807 localcmd("restart\n");
808 //changelevel (mapname);
809 alreadychangedlevel = TRUE;
812 if(cvar_string("nextmap") != "")
814 if(MapInfo_CheckMap(cvar_string("nextmap")))
816 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
819 Map_Goto_SetStr(cvar_string("nextmap"));
821 alreadychangedlevel = TRUE;
824 if(cvar("lastlevel"))
827 localcmd("set lastlevel 0\ntogglemenu\n");
828 alreadychangedlevel = TRUE;
836 //local string nextmap;
837 //local float n, nummaps;
839 if (alreadychangedlevel)
841 alreadychangedlevel = TRUE;
847 for(allowReset = 1; allowReset >= 0; --allowReset)
849 nextMap = GetNextMap();
855 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
857 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
858 localcmd("\nmenu_cmd sync\n");
860 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
865 error("Everything is broken - not even the default map list works. Please report this to the developers.");
877 When the player presses attack or jump, change to the next level
880 .float autoscreenshot;
881 void() MapVote_Start;
882 void() MapVote_Think;
883 float mapvote_initialized;
884 void IntermissionThink()
886 FixIntermissionClient(self);
888 if(cvar("sv_autoscreenshot"))
889 if(self.autoscreenshot > 0)
890 if(time > self.autoscreenshot)
892 self.autoscreenshot = -1;
893 if(clienttype(self) == CLIENTTYPE_REAL)
894 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
898 if (time < intermission_exittime)
901 if(!mapvote_initialized)
902 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
912 Returns the entity to view from
916 entity FindIntermission()
921 // look for info_intermission first
922 spot = find (world, classname, "info_intermission");
924 { // pick a random one
928 spot = find (spot, classname, "info_intermission");
930 spot = find (spot, classname, "info_intermission");
936 // then look for the start position
937 spot = find (world, classname, "info_player_start");
941 // testinfo_player_start is only found in regioned levels
942 spot = find (world, classname, "testplayerstart");
946 // then look for the start position
947 spot = find (world, classname, "info_player_deathmatch");
951 //objerror ("FindIntermission: no spot");
957 ===============================================================================
961 ===============================================================================
964 void DumpStats(float final)
968 local float to_console;
969 local float to_eventlog;
973 to_console = cvar("sv_logscores_console");
974 to_eventlog = cvar("sv_eventlog");
975 to_file = cvar("sv_logscores_file");
979 to_console = TRUE; // always print printstats replies
980 to_eventlog = FALSE; // but never print them to the event log
984 if(cvar("sv_eventlog_console"))
985 to_console = FALSE; // otherwise we get the output twice
992 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
994 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
998 ServerConsoleEcho(s, FALSE);
1000 GameLogEcho(s, FALSE);
1003 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
1007 fputs(file, strcat(s, "\n"));
1010 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
1012 ServerConsoleEcho(s, TRUE);
1014 GameLogEcho(s, TRUE);
1016 fputs(file, strcat(s, "\n"));
1018 FOR_EACH_CLIENT(other)
1020 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
1022 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
1023 s = strcat(s, ftos(rint(time - other.jointime)), ":");
1024 if(other.classname == "player" || g_arena || g_lms)
1025 s = strcat(s, ftos(other.team), ":");
1027 s = strcat(s, "spectator:");
1030 ServerConsoleEcho(strcat(s, other.netname), TRUE);
1032 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
1034 fputs(file, strcat(s, other.netname, "\n"));
1040 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
1042 ServerConsoleEcho(s, TRUE);
1044 GameLogEcho(s, TRUE);
1046 fputs(file, strcat(s, "\n"));
1048 for(i = 1; i < 16; ++i)
1050 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
1051 s = strcat(s, ":", ftos(i));
1053 ServerConsoleEcho(s, TRUE);
1055 GameLogEcho(s, TRUE);
1057 fputs(file, strcat(s, "\n"));
1062 ServerConsoleEcho(":end", FALSE);
1064 GameLogEcho(":end", FALSE);
1067 fputs(file, ":end\n");
1072 void FixIntermissionClient(entity e)
1075 if(!e.autoscreenshot) // initial call
1077 e.angles = e.v_angle;
1078 e.angles_x = -e.angles_x;
1079 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1081 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1082 e.solid = SOLID_NOT;
1083 e.movetype = MOVETYPE_NONE;
1084 e.takedamage = DAMAGE_NO;
1086 e.weaponentity.effects = EF_NODRAW;
1087 if(clienttype(e) == CLIENTTYPE_REAL)
1089 stuffcmd(e, "\nscr_printspeed 1000000\n");
1090 s = cvar_string("sv_intermission_cdtrack");
1092 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1094 WriteByte(MSG_ONE, SVC_INTERMISSION);
1098 //e.velocity = '0 0 0';
1099 //e.fixangle = TRUE;
1101 // TODO halt weapon animation
1106 go to the next level for deathmatch
1107 only called if a time or frag limit has expired
1111 float minTotalFrags;
1112 float maxTotalFrags;
1118 intermission_running = 1;
1120 // enforce a wait time before allowing changelevel
1121 if(player_count > 0)
1122 intermission_exittime = time + cvar("sv_mapchange_delay");
1124 intermission_exittime = -1;
1127 WriteByte (MSG_ALL, SVC_CDTRACK);
1128 WriteByte (MSG_ALL, 3);
1129 WriteByte (MSG_ALL, 3);
1130 // done in FixIntermission
1133 //pos = FindIntermission ();
1139 if(cvar("sv_eventlog"))
1140 GameLogEcho(":gameover", FALSE);
1144 FOR_EACH_CLIENT(other)
1146 FixIntermissionClient(other);
1149 bprint(other.netname, " ^7wins.\n");
1154 FOR_EACH_PLAYER(other)
1156 if(maxTotalFrags < other.totalfrags)
1157 maxTotalFrags = other.totalfrags;
1158 if(minTotalFrags > other.totalfrags)
1159 minTotalFrags = other.totalfrags;
1164 FOR_EACH_PLAYER(other)
1166 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1167 f = bound(0, other.play_time / max(time, 1), 1);
1168 // store some statistics?
1172 if(cvar("g_campaign"))
1173 CampaignPreIntermission();
1175 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1182 Exit deathmatch games upon conditions
1186 void CheckRules_Player()
1188 if (gameover) // someone else quit the game already
1191 if(self.deadflag == DEAD_NO)
1192 self.play_time += frametime;
1196 if(time > self.fogtime)
1198 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1199 self.fogtime = time + sv_foginterval;
1202 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1203 // (div0: and that in CheckRules_World please)
1206 float checkrules_oneminutewarning;
1208 float checkrules_equality;
1209 float checkrules_overtimewarning;
1210 float checkrules_overtimeend;
1212 void InitiateOvertime()
1214 if(!checkrules_overtimeend)
1215 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1218 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1219 float WINNING_YES = 1; // winner found
1220 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1221 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1223 float GetWinningCode(float fraglimitreached, float equality)
1226 if(fraglimitreached)
1227 return WINNING_STARTOVERTIME;
1229 return WINNING_NEVER;
1231 if(fraglimitreached)
1237 // set the .winning flag for exactly those players with a given field value
1238 void SetWinners(.float field, float value)
1241 FOR_EACH_PLAYER(head)
1242 head.winning = (head.field == value);
1245 // set the .winning flag for those players with a given field value
1246 void AddWinners(.float field, float value)
1249 FOR_EACH_PLAYER(head)
1250 if(head.field == value)
1254 // clear the .winning flags
1255 void ClearWinners(void)
1258 FOR_EACH_PLAYER(head)
1262 // Onslaught winning condition:
1263 // game terminates if only one team has a working generator (or none)
1264 float WinningCondition_Onslaught()
1267 local float t1, t2, t3, t4;
1268 // first check if the game has ended
1269 t1 = t2 = t3 = t4 = 0;
1270 head = find(world, classname, "onslaught_generator");
1273 if (head.health > 0)
1275 if (head.team == COLOR_TEAM1) t1 = 1;
1276 if (head.team == COLOR_TEAM2) t2 = 1;
1277 if (head.team == COLOR_TEAM3) t3 = 1;
1278 if (head.team == COLOR_TEAM4) t4 = 1;
1280 head = find(head, classname, "onslaught_generator");
1282 if (t1 + t2 + t3 + t4 < 2)
1284 // game over, only one team remains (or none)
1286 if (t1) SetWinners(team, COLOR_TEAM1);
1287 if (t2) SetWinners(team, COLOR_TEAM2);
1288 if (t3) SetWinners(team, COLOR_TEAM3);
1289 if (t4) SetWinners(team, COLOR_TEAM4);
1290 dprint("Have a winner, ending game.\n");
1294 // Two or more teams remain
1298 float LMS_NewPlayerLives()
1301 fl = cvar("fraglimit");
1305 // first player has left the game for dying too much? Nobody else can get in.
1306 if(lms_lowest_lives < 1)
1309 if(!cvar("g_lms_join_anytime"))
1310 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1313 return bound(1, lms_lowest_lives, fl);
1316 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1317 // they win. Otherwise the defending team wins once the timelimit passes.
1318 void assault_new_round();
1319 float WinningCondition_Assault()
1322 status = WINNING_NO;
1324 // as the timelimit has not yet passed just assume the defending team will win
1325 if(assault_attacker_team == COLOR_TEAM1)
1327 SetWinners(team, COLOR_TEAM2);
1331 SetWinners(team, COLOR_TEAM1);
1335 ent = find(world, classname, "target_assault_roundend");
1338 if(ent.winning) // round end has been triggered by attacking team
1340 SetWinners(team, assault_attacker_team);
1341 if(assault_attacker_team == COLOR_TEAM1)
1343 team1_score = team1_score + 50;
1347 team2_score = team2_score + 50;
1350 if(ent.cnt == 1) // this was the second round
1352 status = WINNING_YES;
1356 local entity oldself;
1359 cvar_set("timelimit", ftos((2*time)/60));
1360 assault_new_round();
1370 // LMS winning condition: game terminates if and only if there's at most one
1371 // one player who's living lives. Top two scores being equal cancels the time
1373 float WinningCondition_LMS()
1380 have_player = FALSE;
1381 have_players = FALSE;
1382 l = LMS_NewPlayerLives();
1384 head = find(world, classname, "player");
1387 head2 = find(head, classname, "player");
1389 have_players = TRUE;
1393 // we have at least one player
1396 // two or more active players - continue with the game
1400 // exactly one player?
1403 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1407 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1413 // and assign him his first place
1414 PlayerScore_Add(head, SP_LMS_RANK, 1);
1421 // nobody is playing at all...
1424 // wait for players...
1428 // SNAFU (maybe a draw game?)
1430 dprint("No players, ending game.\n");
1435 // When we get here, we have at least two players who are actually LIVING,
1436 // now check if the top two players have equal score.
1437 WinningConditionHelper();
1440 if(WinningConditionHelper_winner)
1441 WinningConditionHelper_winner.winning = TRUE;
1442 if(WinningConditionHelper_equality)
1443 return WINNING_NEVER;
1445 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1449 void print_to(entity e, string s)
1452 sprint(e, strcat(s, "\n"));
1454 ServerConsoleEcho(s, TRUE);
1457 void ShuffleMaplist()
1465 result = cvar_string("g_maplist");
1467 litems = tokenizebyseparator(result, " ");
1469 litems = tokenize(result);
1472 for(start = 0; start < litems - 1; ++start)
1476 // select a random item
1477 selected = ceil(random() * (litems - start) + start) - 1;
1479 // shift this item to the place start
1481 for(i = 0; i < start; ++i)
1482 result = strcat(result, " ", argv(i));
1483 result = strcat(result, " ", argv(selected));
1484 for(i = start; i < litems; ++i)
1486 result = strcat(result, " ", argv(i));
1487 result = substring(result, 1, strlen(result) - 1);
1489 litems = tokenizebyseparator(result, " ");
1491 for(i = 0; i < start; ++i)
1492 result = strcat(result, "'", argv(i), "'");
1493 result = strcat(result, "'", argv(selected), "'");
1494 for(i = start; i < litems; ++i)
1496 result = strcat(result, "'", argv(i), "'");
1498 litems = tokenize(result);
1501 //dprint(result, "\n");
1504 cvar_set("g_maplist", result);
1507 float WinningCondition_Scores(float limit)
1509 // TODO make everything use THIS winning condition (except LMS)
1510 WinningConditionHelper();
1514 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1515 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1516 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1517 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1521 if(WinningConditionHelper_winner)
1522 WinningConditionHelper_winner.winning = 1;
1523 if(WinningConditionHelper_winnerteam >= 0)
1524 SetWinners(team, WinningConditionHelper_winnerteam);
1526 if(WinningConditionHelper_topscore == 0)
1527 WinningConditionHelper_equality = 0;
1529 if(WinningConditionHelper_lowerisbetter)
1531 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1535 return GetWinningCode(limit && WinningConditionHelper_topscore && (WinningConditionHelper_topscore >= limit), WinningConditionHelper_equality);
1538 float WinningCondition_Race(float fraglimit)
1542 wc = WinningCondition_Scores(fraglimit);
1544 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1545 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1546 // do NOT support equality when the laps are all raced!
1549 if not(p.race_completed)
1550 return WINNING_STARTOVERTIME;
1556 void ReadyRestart();
1557 float WinningCondition_QualifyingThenRace()
1560 wc = WinningCondition_Scores(0);
1562 // NEVER initiate overtime
1563 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1564 // do NOT support equality when the laps are all raced!
1567 float playerswithlaps;
1569 totalplayers = playerswithlaps = 0;
1570 FOR_EACH_PLAYER(head)
1573 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
1577 // at least 2/3 of the players have completed a lap: start the RACE
1578 // otherwise, the players should end the qualifying on their own
1579 if(totalplayers >= 3)
1580 if(playerswithlaps >= totalplayers * 2 / 3)
1582 checkrules_overtimeend = 0;
1584 return WINNING_NEVER;
1593 float WinningCondition_RanOutOfSpawns()
1597 if(!have_team_spawns)
1600 if(!some_spawn_has_been_used)
1603 team1_score = team2_score = team3_score = team4_score = 0;
1605 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1607 if(head.team == COLOR_TEAM1)
1609 else if(head.team == COLOR_TEAM2)
1611 else if(head.team == COLOR_TEAM3)
1613 else if(head.team == COLOR_TEAM4)
1617 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1619 if(head.team == COLOR_TEAM1)
1621 else if(head.team == COLOR_TEAM2)
1623 else if(head.team == COLOR_TEAM3)
1625 else if(head.team == COLOR_TEAM4)
1630 if(team1_score + team2_score + team3_score + team4_score == 0)
1632 checkrules_equality = TRUE;
1635 else if(team1_score + team2_score + team3_score + team4_score == 1)
1638 if(team1_score) t = COLOR_TEAM1;
1639 if(team2_score) t = COLOR_TEAM2;
1640 if(team3_score) t = COLOR_TEAM3;
1641 if(team4_score) t = COLOR_TEAM4;
1642 CheckAllowedTeams(world);
1643 for(i = 0; i < MAX_TEAMSCORE; ++i)
1645 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
1646 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
1647 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
1648 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
1651 AddWinners(team, t);
1662 Exit deathmatch games upon conditions
1665 void CheckRules_World()
1668 local float timelimit;
1669 local float fraglimit;
1677 MapVote_Think should now do that part
1678 if (intermission_running)
1679 if (time >= intermission_exittime + 60)
1681 if(!DoNextMapOverride())
1687 if (gameover) // someone else quit the game already
1689 if(player_count == 0) // Nobody there? Then let's go to the next map
1691 // this will actually check the player count in the next frame
1692 // again, but this shouldn't hurt
1696 timelimit = cvar("timelimit") * 60;
1697 fraglimit = cvar("fraglimit");
1699 if(checkrules_overtimeend)
1701 if(!checkrules_overtimewarning)
1703 checkrules_overtimewarning = TRUE;
1704 //announceall("announcer/robotic/1minuteremains.wav");
1705 if(!g_race_qualifying)
1706 bcenterprint("^3Everyone, finish your lap! The race is over!");
1708 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1713 if (timelimit && time >= timelimit)
1717 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1723 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1725 checkrules_oneminutewarning = TRUE;
1726 play2all("announcer/robotic/1minuteremains.wav");
1729 status = WinningCondition_RanOutOfSpawns();
1730 if(status == WINNING_YES)
1732 bprint("Hey! Someone ran out of spawns!\n");
1734 else if(g_race && !g_race_qualifying && timelimit >= 0)
1736 status = WinningCondition_Race(fraglimit);
1738 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
1740 status = WinningCondition_QualifyingThenRace();
1744 status = WinningCondition_Assault(); // TODO remove this?
1748 status = WinningCondition_LMS();
1750 else if (g_onslaught)
1752 status = WinningCondition_Onslaught(); // TODO remove this?
1756 status = WinningCondition_Scores(fraglimit);
1759 if(status == WINNING_STARTOVERTIME)
1761 status = WINNING_NEVER;
1765 if(status == WINNING_NEVER)
1766 // equality cases! Nobody wins if the overtime ends in a draw.
1769 if(checkrules_overtimeend)
1770 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1771 status = WINNING_YES;
1773 if(status == WINNING_YES)
1777 float mapvote_nextthink;
1778 float mapvote_initialized;
1779 float mapvote_keeptwotime;
1780 float mapvote_timeout;
1781 string mapvote_message;
1782 string mapvote_screenshot_dir;
1784 float mapvote_count;
1785 float mapvote_count_real;
1786 string mapvote_maps[MAPVOTE_COUNT];
1787 float mapvote_maps_suggested[MAPVOTE_COUNT];
1788 string mapvote_suggestions[MAPVOTE_COUNT];
1789 float mapvote_suggestion_ptr;
1790 float mapvote_maxlen;
1791 float mapvote_voters;
1792 float mapvote_votes[MAPVOTE_COUNT];
1794 float mapvote_detail;
1795 float mapvote_abstain;
1796 float mapvote_dirty;
1799 void MapVote_ClearAllVotes()
1801 FOR_EACH_CLIENT(other)
1805 string MapVote_Suggest(string m)
1809 return "That's not how to use this command.";
1810 if(!cvar("g_maplist_votable_suggestions"))
1811 return "Suggestions are not accepted on this server.";
1812 if(mapvote_initialized)
1813 return "Can't suggest - voting is already in progress!";
1815 m = MapInfo_FixName(m);
1817 return "The map you suggested is not available on this server.";
1819 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1820 if(!IsSameGametype(m))
1821 return "This server does not allow changing the game type by map suggestions.";
1823 if(!cvar("g_maplist_votable_override_mostrecent"))
1825 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1828 if(!MapInfo_CheckMap(m))
1829 return "The map you suggested does not support the current game mode.";
1831 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1832 return "The map you suggested is not available on this server.";
1834 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1835 if(mapvote_suggestions[i] == m)
1836 return "This map was already suggested.";
1837 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1839 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1843 i = mapvote_suggestion_ptr;
1844 mapvote_suggestion_ptr += 1;
1846 if(mapvote_suggestions[i] != "")
1847 strunzone(mapvote_suggestions[i]);
1848 mapvote_suggestions[i] = strzone(m);
1849 if(cvar("sv_eventlog"))
1850 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)), TRUE);
1851 return strcat("Suggestion of ", m, " accepted.");
1854 void MapVote_AddVotable(string nextMap, float isSuggestion)
1859 for(j = 0; j < mapvote_count; ++j)
1860 if(mapvote_maps[j] == nextMap)
1862 if(strlen(nextMap) > mapvote_maxlen)
1863 mapvote_maxlen = strlen(nextMap);
1864 mapvote_maps[mapvote_count] = strzone(nextMap);
1865 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1869 void MapVote_SendData(float target);
1875 MapVote_ClearAllVotes();
1878 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1879 mapvote_abstain = cvar("g_maplist_votable_abstain");
1882 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1884 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1885 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
1887 if(mapvote_suggestion_ptr)
1888 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1889 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1891 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1892 MapVote_AddVotable(GetNextMap(), FALSE);
1894 if(mapvote_count == 0)
1896 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1898 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1899 localcmd("\nmenu_cmd sync\n");
1901 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1903 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1904 MapVote_AddVotable(GetNextMap(), FALSE);
1907 mapvote_count_real = mapvote_count;
1909 MapVote_AddVotable("don't care", 0);
1911 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1913 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1914 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1915 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1916 mapvote_keeptwotime = 0;
1917 mapvote_message = "Choose a map and press its key!";
1919 mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
1920 if(mapvote_screenshot_dir == "")
1921 mapvote_screenshot_dir = "maps";
1922 mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
1924 if(!cvar("g_maplist_textonly"))
1925 MapVote_SendData(MSG_ALL);
1928 void MapVote_SendPicture(float id)
1931 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1932 WriteByte(MSG_ONE, TE_CSQC_MAPVOTE);
1933 WriteByte(MSG_ONE, MAPVOTE_NET_PIC);
1934 WriteByte(MSG_ONE, id);
1935 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 3072);
1938 float GameCommand_MapVote(string cmd)
1940 if(!intermission_running)
1942 if(!cvar("g_maplist_textonly"))
1944 if(cmd == "mv_getpic")
1946 MapVote_SendPicture(stof(argv(1)));
1954 float MapVote_GetMapMask()
1956 float mask, i, power;
1958 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
1959 if(mapvote_maps[i] != "")
1964 void MapVote_SendData(float targ)
1966 string mapfile, pakfile;
1968 WriteByte(targ, SVC_TEMPENTITY);
1969 WriteByte(targ, TE_CSQC_CONFIG);
1970 WriteString(targ, "mv_screenshot_dir");
1971 WriteString(targ, mapvote_screenshot_dir);
1973 WriteByte(targ, SVC_TEMPENTITY);
1974 WriteByte(targ, TE_CSQC_MAPVOTE);
1975 WriteByte(targ, MAPVOTE_NET_INIT);
1977 WriteByte(targ, mapvote_count);
1978 WriteByte(targ, mapvote_abstain);
1979 WriteByte(targ, mapvote_detail);
1980 WriteCoord(targ, mapvote_timeout);
1981 if(mapvote_count <= 8)
1982 WriteByte(targ, MapVote_GetMapMask());
1984 WriteShort(targ, MapVote_GetMapMask());
1985 for(i = 0; i < mapvote_count; ++i)
1986 if(mapvote_maps[i] != "")
1988 WriteString(targ, mapvote_maps[i]);
1989 mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
1990 pakfile = whichpack(strcat(mapfile, ".tga"));
1992 pakfile = whichpack(strcat(mapfile, ".jpg"));
1994 pakfile = whichpack(strcat(mapfile, ".png"));
1995 print("pakfile is ", pakfile, "\n");
1996 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
1997 pakfile = substring(pakfile, o, 999);
1998 WriteString(targ, pakfile);
2002 void MapVote_UpdateData(float targ)
2005 WriteByte(targ, SVC_TEMPENTITY);
2006 WriteByte(targ, TE_CSQC_MAPVOTE);
2007 WriteByte(targ, MAPVOTE_NET_UPDATE);
2008 if(mapvote_count <= 8)
2009 WriteByte(targ, MapVote_GetMapMask());
2011 WriteShort(targ, MapVote_GetMapMask());
2013 for(i = 0; i < mapvote_count; ++i)
2014 if(mapvote_maps[i] != "")
2015 WriteByte(targ, mapvote_votes[i]);
2018 void MapVote_TellVote(float targ, float vote)
2020 WriteByte(targ, SVC_TEMPENTITY);
2021 WriteByte(targ, TE_CSQC_MAPVOTE);
2022 WriteByte(targ, MAPVOTE_NET_OWNVOTE);
2023 WriteByte(targ, vote);
2026 float MapVote_Finished(float mappos)
2032 if(cvar("sv_eventlog"))
2034 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2035 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
2036 didntvote = mapvote_voters;
2037 for(i = 0; i < mapvote_count; ++i)
2038 if(mapvote_maps[i] != "")
2040 didntvote -= mapvote_votes[i];
2043 result = strcat(result, ":", mapvote_maps[i]);
2044 result = strcat(result, ":", ftos(mapvote_votes[i]));
2047 result = strcat(result, ":didn't vote:", ftos(didntvote));
2049 GameLogEcho(result, FALSE);
2050 if(mapvote_maps_suggested[mappos])
2051 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
2054 FOR_EACH_REALCLIENT(other)
2055 FixClientCvars(other);
2057 Map_Goto_SetStr(mapvote_maps[mappos]);
2059 alreadychangedlevel = TRUE;
2062 void MapVote_CheckRules_1()
2066 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2068 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2069 mapvote_votes[i] = 0;
2073 FOR_EACH_REALCLIENT(other)
2078 i = other.mapvote - 1;
2079 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2080 mapvote_votes[i] = mapvote_votes[i] + 1;
2085 float MapVote_CheckRules_2()
2088 float firstPlace, secondPlace;
2089 float firstPlaceVotes, secondPlaceVotes;
2090 float mapvote_voters_real;
2093 mapvote_voters_real = mapvote_voters;
2095 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2097 RandomSelection_Init();
2098 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2099 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2100 firstPlace = RandomSelection_chosen_float;
2101 firstPlaceVotes = RandomSelection_best_priority;
2102 //dprint("First place: ", ftos(firstPlace), "\n");
2103 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2105 RandomSelection_Init();
2106 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2108 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2109 secondPlace = RandomSelection_chosen_float;
2110 secondPlaceVotes = RandomSelection_best_priority;
2111 //dprint("Second place: ", ftos(secondPlace), "\n");
2112 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2114 if(firstPlace == -1)
2115 error("No first place in map vote... WTF?");
2117 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2118 return MapVote_Finished(firstPlace);
2120 if(mapvote_keeptwotime)
2121 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2124 mapvote_dirty = TRUE;
2125 mapvote_message = "Now decide between the TOP TWO!";
2126 mapvote_keeptwotime = 0;
2127 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2128 result = strcat(result, ":", ftos(firstPlaceVotes));
2129 result = strcat(result, ":", mapvote_maps[secondPlace]);
2130 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2131 didntvote = mapvote_voters;
2132 for(i = 0; i < mapvote_count; ++i)
2133 if(mapvote_maps[i] != "")
2135 didntvote -= mapvote_votes[i];
2137 if(i != secondPlace)
2139 result = strcat(result, ":", mapvote_maps[i]);
2140 result = strcat(result, ":", ftos(mapvote_votes[i]));
2141 if(i < mapvote_count_real)
2143 strunzone(mapvote_maps[i]);
2144 mapvote_maps[i] = "";
2148 result = strcat(result, ":didn't vote:", ftos(didntvote));
2149 if(cvar("sv_eventlog"))
2150 GameLogEcho(result, FALSE);
2163 keeptwo = mapvote_keeptwotime;
2164 MapVote_CheckRules_1(); // count
2165 if(MapVote_CheckRules_2()) // decide
2169 FOR_EACH_REALCLIENT(other)
2171 // hide scoreboard again
2172 if(other.health != 2342)
2174 other.health = 2342;
2176 if(clienttype(other) == CLIENTTYPE_REAL)
2178 if(cvar("g_maplist_textonly"))
2179 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");
2182 WriteByte(MSG_ONE, SVC_FINALE);
2183 WriteString(MSG_ONE, "");
2187 // notify about keep-two
2188 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2189 play2(other, "misc/invshot.wav");
2191 // clear possibly invalid votes
2192 if(mapvote_maps[other.mapvote - 1] == "")
2194 // use impulses as new vote
2195 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2196 if(mapvote_maps[other.impulse - 1] != "")
2198 other.mapvote = other.impulse;
2200 mapvote_dirty = TRUE;
2203 MapVote_TellVote(MSG_ONE, other.mapvote);
2211 MapVote_CheckRules_1(); // just count
2213 if(!cvar("g_maplist_textonly"))
2214 if(mapvote_dirty) // 1 if "keeptwo" or "impulse" happened before
2216 MapVote_UpdateData(MSG_BROADCAST);
2217 mapvote_dirty = FALSE;
2220 if(cvar("g_maplist_textonly"))
2222 FOR_EACH_REALCLIENT(other)
2224 // display voting screen
2225 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2226 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2228 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2229 msgstr = strcat(msgstr, mapvote_message);
2230 msgstr = strcat(msgstr, "\n\n");
2231 for(i = 0; i < mapvote_count; ++i)
2232 if(mapvote_maps[i] == "")
2233 msgstr = strcat(msgstr, "\n");
2236 tmp = mapvote_maps[i];
2237 tmp = strpad(mapvote_maxlen, tmp);
2238 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2241 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2242 if(mapvote_votes[i] != 1)
2243 tmp = strcat(tmp, "s");
2244 tmp = strcat(tmp, ")");
2245 tmp = strpad(mapvote_maxlen + 15, tmp);
2248 if(i == mapvote_count - 1)
2249 msgstr = strcat(msgstr, "\n");
2250 if(other.mapvote == i + 1)
2251 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2253 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2256 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2258 msgstr = strcat(msgstr, "s");
2259 msgstr = strcat(msgstr, " cast");
2260 i = ceil(mapvote_timeout - time);
2261 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2263 msgstr = strcat(msgstr, "s");
2264 msgstr = strcat(msgstr, " left");
2266 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2270 void MapVote_Start()
2276 MapInfo_Enumerate();
2277 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2281 void MapVote_Think()
2286 if(alreadychangedlevel)
2289 if(time < mapvote_nextthink)
2293 mapvote_nextthink = time + 0.5;
2295 if(!mapvote_initialized)
2297 mapvote_initialized = TRUE;
2298 if(DoNextMapOverride())
2300 if(!cvar("g_maplist_votable") || player_count <= 0)
2311 string GotoMap(string m)
2314 if(!MapInfo_CheckMap(m))
2316 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2318 return "The map you chose is not available on this server.";
2319 cvar_set("nextmap", m);
2320 cvar_set("timelimit", "-1");
2321 if(mapvote_initialized || alreadychangedlevel)
2323 if(DoNextMapOverride())
2324 return "Map switch initiated.";
2326 return "Hm... no. For some reason I like THIS map more.";
2329 return "Map switch will happen after scoreboard.";
2335 FOR_EACH_REALCLIENT(self)
2337 if(self.classname == "spectator")
2339 if(self.enemy.hitsound)
2340 play2(self, "misc/hit.wav");
2345 play2(self, "misc/hit.wav");
2348 FOR_EACH_CLIENT(self)
2349 self.hitsound = FALSE;
2355 * returns TRUE if redirecting
2357 float redirection_timeout;
2358 float redirection_nextthink;
2359 float RedirectionThink()
2361 float clients_found;
2363 if(redirection_target == "")
2366 if(!redirection_timeout)
2368 cvar_set("sv_public", "-2");
2369 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2370 if(redirection_target == "self")
2371 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2373 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2376 if(time < redirection_nextthink)
2379 redirection_nextthink = time + 1;
2382 FOR_EACH_REALCLIENT(self)
2384 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2385 if(redirection_target == "self")
2386 stuffcmd(self, "\ndisconnect; reconnect\n");
2388 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2392 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2394 if(time > redirection_timeout || clients_found == 0)
2395 localcmd("\nwait; wait; wait; quit\n");
2402 // Loaded from a save game
2403 // some things then break, so let's work around them...
2405 // Progs DB (capture records)
2407 ServerProgsDB = db_create();
2409 ServerProgsDB = db_load("server.db");
2414 MapInfo_Enumerate();
2415 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
2421 if(world_initialized)
2423 world_initialized = 0;
2424 print("Saving persistent data...\n");
2427 db_save(ServerProgsDB, "server.db");
2428 db_close(ServerProgsDB);
2430 // tell the bot system the game is ending now
2437 print("NOTE: crashed before even initializing the world, not saving persistent data\n");