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)
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 ServerProgsDB = db_create();
193 ServerProgsDB = db_load("server.db");
196 TODO sound pack system
197 // initialize sound pack system
198 soundpack = cvar_string("g_soundpack");
200 soundpack = strcat(soundpack, "/");
201 soundpack = strzone(soundpack);
207 // 1 FLICKER (first variety)
208 lightstyle(1, "mmnmmommommnonmmonqnmmo");
210 // 2 SLOW STRONG PULSE
211 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
213 // 3 CANDLE (first variety)
214 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
217 lightstyle(4, "mamamamamama");
220 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
222 // 6 FLICKER (second variety)
223 lightstyle(6, "nmonqnmomnmomomno");
225 // 7 CANDLE (second variety)
226 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
228 // 8 CANDLE (third variety)
229 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
231 // 9 SLOW STROBE (fourth variety)
232 lightstyle(9, "aaaaaaaazzzzzzzz");
234 // 10 FLUORESCENT FLICKER
235 lightstyle(10, "mmamammmmammamamaaamammma");
237 // 11 SLOW PULSE NOT FADE TO BLACK
238 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
240 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
245 if(cvar("g_campaign"))
252 bot_waypoints_for_items = cvar("g_waypoints_for_items");
253 if(bot_waypoints_for_items == 1)
254 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
255 bot_waypoints_for_items = 0;
257 // for setting by mapinfo
258 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
259 cvar_set("sv_q3acompat_machineshotgunswap", "0");
263 WaypointSprite_Init();
268 GameLogInit(); // prepare everything
269 if(cvar("sv_eventlog"))
271 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
272 s = strcat(s, ftos(random()));
274 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s), FALSE);
276 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
278 s = ":gameinfo:mutators:LIST";
279 if(cvar("g_grappling_hook"))
280 s = strcat(s, ":grappling_hook");
281 if(!cvar("g_use_ammunition"))
282 s = strcat(s, ":no_use_ammunition");
283 if(!cvar("g_pickup_items"))
284 s = strcat(s, ":no_pickup_items");
285 if(cvar("g_instagib"))
286 s = strcat(s, ":instagib");
287 if(cvar("g_rocketarena"))
288 s = strcat(s, ":rockerarena");
290 s = strcat(s, ":nixnex");
291 if(cvar("g_vampire"))
292 s = strcat(s, ":vampire");
293 if(cvar("g_laserguided_missile"))
294 s = strcat(s, ":laserguided_missile");
295 if(cvar("g_norecoil"))
296 s = strcat(s, ":norecoil");
298 s = strcat(s, ":midair");
299 if(cvar("g_minstagib"))
300 s = strcat(s, ":minstagib");
301 GameLogEcho(s, FALSE);
302 GameLogEcho(":gameinfo:end", FALSE);
305 cvar_set("nextmap", "");
309 if(cvar("g_campaign"))
316 //initialise globals related to sv_timeout
317 sys_ticrate = cvar("sys_ticrate");
318 orig_slowmo = cvar("slowmo");
322 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
325 //if tourney is used map starts in warmup mode. if this mode shall stay unlimited, reset timelimit, but save the original one
326 if(g_tourney && cvar("g_tourney_warmup_unlimited_time")) {
327 timelimit_orig = cvar("timelimit");
328 cvar_set("timelimit", "0");
331 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
333 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
336 while((s = fgets(fd)))
343 print("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
344 print(" cdtrack ", argv(2), "\n");
346 else if(argv(0) == "fog")
348 print("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
349 print(" \"fog\" \"", s, "\"\n");
351 else if(argv(0) == "set")
353 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
354 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
356 else if(argv(0) != "//")
358 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
359 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
366 next_pingtime = time + 5;
367 world_initialized = 1;
370 void spawnfunc_light (void)
372 //makestatic (self); // Who the f___ did that?
376 float TryFile( string pFilename )
379 dprint("TryFile(\"", pFilename, "\")\n");
380 lHandle = fopen( pFilename, FILE_READ );
381 if( lHandle != -1 ) {
391 return GametypeNameFromType(game);
394 float IsSameGametype(string mapcfgname)
397 return TRUE; // can't change game type by map name here
401 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
407 string getmapname_stored;
413 if(getmapname_stored == "")
414 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
415 return getmapname_stored;
419 float Map_Count, Map_Current;
420 string Map_Current_Name;
422 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
423 float GetMaplistPosition()
429 idx = cvar("g_maplist_index");
436 for(pos = 0; pos < Map_Count; ++pos)
440 // resume normal maplist rotation if current map is not in g_maplist
444 float MapHasRightSize(string map)
447 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
448 if(cvar("g_maplist_check_waypoints"))
450 dprint("checkwp "); dprint(map);
451 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
454 dprint(": no waypoints\n");
457 dprint(": has waypoints\n");
461 // open map size restriction file
462 dprint("opensize "); dprint(map);
463 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
466 float mapmin, mapmax;
468 mapmin = stof(fgets(fh));
469 mapmax = stof(fgets(fh));
471 if(player_count < mapmin)
473 dprint("not enough\n");
476 if(player_count > mapmax)
478 dprint("too many\n");
481 dprint("right size\n");
484 dprint(": not found\n");
488 string Map_Filename(float position)
491 return strcat("maps/", argv(position), ".bsp");
493 return strcat("maps/", argv(position), ".mapcfg");
497 string strwords(string s, float w)
500 for(endpos = 0; w && endpos >= 0; --w)
501 endpos = strstrofs(s, " ", endpos + 1);
505 return substring(s, 0, endpos);
508 float strhasword(string s, string w)
510 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
513 void Map_MarkAsRecent(string m)
515 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
518 float Map_IsRecent(string m)
520 return strhasword(cvar_string("g_maplist_mostrecent"), m);
523 float Map_Check(float position, float pass)
527 map_next = argv(position);
530 if(map_next == Map_Current_Name) // same map again in first pass?
532 if(Map_IsRecent(map_next))
535 filename = Map_Filename(position);
537 if(MapInfo_CheckMap(map_next))
539 if(TryFile(filename))
544 if(MapHasRightSize(map_next))
549 dprint( "Couldn't select '", filename, "'..\n" );
554 void Map_Goto_SetStr(string nextmapname)
556 if(getmapname_stored != "")
557 strunzone(getmapname_stored);
558 if(nextmapname == "")
559 getmapname_stored = "";
561 getmapname_stored = strzone(nextmapname);
564 void Map_Goto_SetFloat(float position)
566 cvar_set("g_maplist_index", ftos(position));
567 Map_Goto_SetStr(argv(position));
573 // settings persist, except...
574 if(cvar("g_campaign"))
575 localcmd("\nexec mutator_reset.cfg\n");
576 localcmd("\nsettemp_restore\n");
578 // if an exit cfg is defined by exiting map, exec it.
580 exit_cfg = cvar_string("exit_cfg");
582 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
584 localcmd("exec game_reset.cfg\n");
590 Map_MarkAsRecent(getmapname_stored);
593 MapInfo_LoadMap(getmapname_stored);
595 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
599 // return codes of map selectors:
600 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
601 // -2 = permanent failure
602 float() MaplistMethod_Iterate = // usual method
606 for(pass = 1; pass <= 2; ++pass)
608 for(i = 1; i < Map_Count; ++i)
611 mapindex = mod(i + Map_Current, Map_Count);
612 if(Map_Check(mapindex, pass))
619 float() MaplistMethod_Repeat = // fallback method
621 if(Map_Check(Map_Current, 2))
626 float() MaplistMethod_Random = // random map selection
632 for(i = 0; i <= imax; ++i)
635 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
636 if(Map_Check(mapindex, 1))
642 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
643 // the exponent sets a bias on the map selection:
644 // the higher the exponent, the less likely "shortly repeated" same maps are
646 float i, j, imax, insertpos;
650 for(i = 0; i <= imax; ++i)
654 // now reinsert this at another position
655 insertpos = pow(random(), 1 / exponent); // ]0, 1]
656 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
657 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
658 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
660 // insert the current map there
663 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
664 newlist = strcat(newlist, " ", argv(j));
665 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
666 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
667 newlist = strcat(newlist, " ", argv(j));
668 newlist = substring(newlist, 1, strlen(newlist) - 1);
670 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
671 newlist = strcat(newlist, "'", argv(j), "'");
672 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
673 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
674 newlist = strcat(newlist, "'", argv(j), "'");
676 cvar_set("g_maplist", newlist);
678 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
680 Map_Count = tokenize(newlist);
683 // NOTE: the selected map has just been inserted at (insertpos-1)th position
684 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
685 if(Map_Check(Map_Current, 1))
694 temp = cvar_string("g_maplist");
696 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
698 Map_Count = tokenize(temp);
702 bprint( "Maplist is empty! Resetting it to default map list.\n" );
704 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
705 localcmd("\nmenu_cmd sync\n");
706 Map_Count = tokenizebyseparator(temp, " ");
708 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
709 Map_Count = tokenize(temp);
713 error("empty maplist, cannot select a new map");
714 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
717 strunzone(Map_Current_Name);
718 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
719 // this may or may not be correct, but who cares, in the worst case a map
720 // isn't chosen in the first pass that should have been
731 if(cvar("g_maplist_shuffle") > 0)
732 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
735 if(cvar("g_maplist_selectrandom"))
736 nextMap = MaplistMethod_Random();
739 nextMap = MaplistMethod_Iterate();
742 nextMap = MaplistMethod_Repeat();
746 Map_Goto_SetFloat(nextMap);
747 return getmapname_stored;
753 float DoNextMapOverride()
755 if(cvar("g_campaign"))
757 CampaignPostIntermission();
758 alreadychangedlevel = TRUE;
761 if(cvar("quit_when_empty"))
763 if(player_count <= currentbots)
766 alreadychangedlevel = TRUE;
770 if(cvar_string("quit_and_redirect") != "")
772 redirection_target = strzone(cvar_string("quit_and_redirect"));
773 alreadychangedlevel = TRUE;
776 if (cvar("samelevel")) // if samelevel is set, stay on same level
778 // 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)
779 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
780 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
781 localcmd("restart\n");
782 //changelevel (mapname);
783 alreadychangedlevel = TRUE;
786 if(cvar_string("nextmap") != "")
788 if(MapInfo_CheckMap(cvar_string("nextmap")))
790 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
793 Map_Goto_SetStr(cvar_string("nextmap"));
795 alreadychangedlevel = TRUE;
798 if(cvar("lastlevel"))
801 localcmd("set lastlevel 0\ntogglemenu\n");
802 alreadychangedlevel = TRUE;
810 //local string nextmap;
811 //local float n, nummaps;
813 if (alreadychangedlevel)
815 alreadychangedlevel = TRUE;
821 for(allowReset = 1; allowReset >= 0; --allowReset)
823 nextMap = GetNextMap();
829 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
831 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
832 localcmd("\nmenu_cmd sync\n");
834 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
839 error("Everything is broken - not even the default map list works. Please report this to the developers.");
851 When the player presses attack or jump, change to the next level
854 .float autoscreenshot;
855 void() MapVote_Start;
856 void() MapVote_Think;
857 float mapvote_initialized;
858 void IntermissionThink()
860 FixIntermissionClient(self);
862 if(cvar("sv_autoscreenshot"))
863 if(self.autoscreenshot > 0)
864 if(time > self.autoscreenshot)
866 self.autoscreenshot = -1;
867 if(clienttype(self) == CLIENTTYPE_REAL)
868 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
872 if (time < intermission_exittime)
875 if(!mapvote_initialized)
876 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
886 Returns the entity to view from
890 entity FindIntermission()
895 // look for info_intermission first
896 spot = find (world, classname, "info_intermission");
898 { // pick a random one
902 spot = find (spot, classname, "info_intermission");
904 spot = find (spot, classname, "info_intermission");
910 // then look for the start position
911 spot = find (world, classname, "info_player_start");
915 // testinfo_player_start is only found in regioned levels
916 spot = find (world, classname, "testplayerstart");
920 // then look for the start position
921 spot = find (world, classname, "info_player_deathmatch");
925 //objerror ("FindIntermission: no spot");
931 ===============================================================================
935 ===============================================================================
938 void DumpStats(float final)
942 local float to_console;
943 local float to_eventlog;
947 to_console = cvar("sv_logscores_console");
948 to_eventlog = cvar("sv_eventlog");
949 to_file = cvar("sv_logscores_file");
953 to_console = TRUE; // always print printstats replies
954 to_eventlog = FALSE; // but never print them to the event log
958 if(cvar("sv_eventlog_console"))
959 to_console = FALSE; // otherwise we get the output twice
966 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
968 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
972 ServerConsoleEcho(s, FALSE);
974 GameLogEcho(s, FALSE);
977 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
981 fputs(file, strcat(s, "\n"));
984 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
986 ServerConsoleEcho(s, TRUE);
988 GameLogEcho(s, TRUE);
990 fputs(file, strcat(s, "\n"));
992 FOR_EACH_CLIENT(other)
994 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
996 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
997 s = strcat(s, ftos(rint(time - other.jointime)), ":");
998 if(other.classname == "player" || g_arena || g_lms)
999 s = strcat(s, ftos(other.team), ":");
1001 s = strcat(s, "spectator:");
1004 ServerConsoleEcho(strcat(s, other.netname), TRUE);
1006 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
1008 fputs(file, strcat(s, other.netname, "\n"));
1014 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
1016 ServerConsoleEcho(s, TRUE);
1018 GameLogEcho(s, TRUE);
1020 fputs(file, strcat(s, "\n"));
1022 for(i = 1; i < 16; ++i)
1024 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
1025 s = strcat(s, ":", ftos(i));
1027 ServerConsoleEcho(s, TRUE);
1029 GameLogEcho(s, TRUE);
1031 fputs(file, strcat(s, "\n"));
1036 ServerConsoleEcho(":end", FALSE);
1038 GameLogEcho(":end", FALSE);
1041 fputs(file, ":end\n");
1046 void FixIntermissionClient(entity e)
1049 if(!e.autoscreenshot) // initial call
1051 e.angles = e.v_angle;
1052 e.angles_x = -e.angles_x;
1053 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1055 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1056 e.solid = SOLID_NOT;
1057 e.movetype = MOVETYPE_NONE;
1058 e.takedamage = DAMAGE_NO;
1060 e.weaponentity.effects = EF_NODRAW;
1061 if(clienttype(e) == CLIENTTYPE_REAL)
1063 stuffcmd(e, "\nscr_printspeed 1000000\n");
1064 s = cvar_string("sv_intermission_cdtrack");
1066 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1068 WriteByte(MSG_ONE, SVC_INTERMISSION);
1072 //e.velocity = '0 0 0';
1073 //e.fixangle = TRUE;
1075 // TODO halt weapon animation
1080 go to the next level for deathmatch
1081 only called if a time or frag limit has expired
1085 float minTotalFrags;
1086 float maxTotalFrags;
1092 intermission_running = 1;
1094 // enforce a wait time before allowing changelevel
1095 if(player_count > 0)
1096 intermission_exittime = time + cvar("sv_mapchange_delay");
1098 intermission_exittime = -1;
1101 WriteByte (MSG_ALL, SVC_CDTRACK);
1102 WriteByte (MSG_ALL, 3);
1103 WriteByte (MSG_ALL, 3);
1104 // done in FixIntermission
1107 //pos = FindIntermission ();
1113 if(cvar("sv_eventlog"))
1114 GameLogEcho(":gameover", FALSE);
1118 FOR_EACH_CLIENT(other)
1120 FixIntermissionClient(other);
1123 bprint(other.netname, " ^7wins.\n");
1128 FOR_EACH_PLAYER(other)
1130 if(maxTotalFrags < other.totalfrags)
1131 maxTotalFrags = other.totalfrags;
1132 if(minTotalFrags > other.totalfrags)
1133 minTotalFrags = other.totalfrags;
1138 FOR_EACH_PLAYER(other)
1140 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1141 f = bound(0, other.play_time / max(time, 1), 1);
1142 // store some statistics?
1146 if(cvar("g_campaign"))
1147 CampaignPreIntermission();
1149 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1156 Exit deathmatch games upon conditions
1160 void CheckRules_Player()
1162 if (gameover) // someone else quit the game already
1165 if(self.deadflag == DEAD_NO)
1166 self.play_time += frametime;
1170 if(time > self.fogtime)
1172 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1173 self.fogtime = time + sv_foginterval;
1176 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1177 // (div0: and that in CheckRules_World please)
1180 float checkrules_oneminutewarning;
1182 float checkrules_equality;
1183 float checkrules_overtimewarning;
1184 float checkrules_overtimeend;
1186 void InitiateOvertime()
1188 if(!checkrules_overtimeend)
1189 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1192 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1193 float WINNING_YES = 1; // winner found
1194 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1195 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1197 float GetWinningCode(float fraglimitreached, float equality)
1200 if(fraglimitreached)
1201 return WINNING_STARTOVERTIME;
1203 return WINNING_NEVER;
1205 if(fraglimitreached)
1211 // set the .winning flag for exactly those players with a given field value
1212 void SetWinners(.float field, float value)
1215 FOR_EACH_PLAYER(head)
1216 head.winning = (head.field == value);
1219 // set the .winning flag for those players with a given field value
1220 void AddWinners(.float field, float value)
1223 FOR_EACH_PLAYER(head)
1224 if(head.field == value)
1228 // clear the .winning flags
1229 void ClearWinners(void)
1232 FOR_EACH_PLAYER(head)
1236 // Onslaught winning condition:
1237 // game terminates if only one team has a working generator (or none)
1238 float WinningCondition_Onslaught()
1241 local float t1, t2, t3, t4;
1242 // first check if the game has ended
1243 t1 = t2 = t3 = t4 = 0;
1244 head = find(world, classname, "onslaught_generator");
1247 if (head.health > 0)
1249 if (head.team == COLOR_TEAM1) t1 = 1;
1250 if (head.team == COLOR_TEAM2) t2 = 1;
1251 if (head.team == COLOR_TEAM3) t3 = 1;
1252 if (head.team == COLOR_TEAM4) t4 = 1;
1254 head = find(head, classname, "onslaught_generator");
1256 if (t1 + t2 + t3 + t4 < 2)
1258 // game over, only one team remains (or none)
1260 if (t1) SetWinners(team, COLOR_TEAM1);
1261 if (t2) SetWinners(team, COLOR_TEAM2);
1262 if (t3) SetWinners(team, COLOR_TEAM3);
1263 if (t4) SetWinners(team, COLOR_TEAM4);
1264 dprint("Have a winner, ending game.\n");
1268 // Two or more teams remain
1272 float LMS_NewPlayerLives()
1275 fl = cvar("fraglimit");
1279 // first player has left the game for dying too much? Nobody else can get in.
1280 if(lms_lowest_lives < 1)
1283 if(!cvar("g_lms_join_anytime"))
1284 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1287 return bound(1, lms_lowest_lives, fl);
1290 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1291 // they win. Otherwise the defending team wins once the timelimit passes.
1292 void assault_new_round();
1293 float WinningCondition_Assault()
1296 status = WINNING_NO;
1298 // as the timelimit has not yet passed just assume the defending team will win
1299 if(assault_attacker_team == COLOR_TEAM1)
1301 SetWinners(team, COLOR_TEAM2);
1305 SetWinners(team, COLOR_TEAM1);
1309 ent = find(world, classname, "target_assault_roundend");
1312 if(ent.winning) // round end has been triggered by attacking team
1314 SetWinners(team, assault_attacker_team);
1315 if(assault_attacker_team == COLOR_TEAM1)
1317 team1_score = team1_score + 50;
1321 team2_score = team2_score + 50;
1324 if(ent.cnt == 1) // this was the second round
1326 status = WINNING_YES;
1330 local entity oldself;
1333 cvar_set("timelimit", ftos((2*time)/60));
1334 assault_new_round();
1344 // LMS winning condition: game terminates if and only if there's at most one
1345 // one player who's living lives. Top two scores being equal cancels the time
1347 float WinningCondition_LMS()
1354 have_player = FALSE;
1355 have_players = FALSE;
1356 l = LMS_NewPlayerLives();
1358 head = find(world, classname, "player");
1361 head2 = find(head, classname, "player");
1363 have_players = TRUE;
1367 // we have at least one player
1370 // two or more active players - continue with the game
1374 // exactly one player?
1377 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1381 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1387 // and assign him his first place
1388 PlayerScore_Add(head, SP_LMS_RANK, 1);
1395 // nobody is playing at all...
1398 // wait for players...
1402 // SNAFU (maybe a draw game?)
1404 dprint("No players, ending game.\n");
1409 // When we get here, we have at least two players who are actually LIVING,
1410 // now check if the top two players have equal score.
1411 WinningConditionHelper();
1414 if(WinningConditionHelper_winner)
1415 WinningConditionHelper_winner.winning = TRUE;
1416 if(WinningConditionHelper_equality)
1417 return WINNING_NEVER;
1419 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1423 void print_to(entity e, string s)
1426 sprint(e, strcat(s, "\n"));
1428 ServerConsoleEcho(s, TRUE);
1431 void ShuffleMaplist()
1439 result = cvar_string("g_maplist");
1441 litems = tokenizebyseparator(result, " ");
1443 litems = tokenize(result);
1446 for(start = 0; start < litems - 1; ++start)
1450 // select a random item
1451 selected = ceil(random() * (litems - start) + start) - 1;
1453 // shift this item to the place start
1455 for(i = 0; i < start; ++i)
1456 result = strcat(result, " ", argv(i));
1457 result = strcat(result, " ", argv(selected));
1458 for(i = start; i < litems; ++i)
1460 result = strcat(result, " ", argv(i));
1461 result = substring(result, 1, strlen(result) - 1);
1463 litems = tokenizebyseparator(result, " ");
1465 for(i = 0; i < start; ++i)
1466 result = strcat(result, "'", argv(i), "'");
1467 result = strcat(result, "'", argv(selected), "'");
1468 for(i = start; i < litems; ++i)
1470 result = strcat(result, "'", argv(i), "'");
1472 litems = tokenize(result);
1475 //dprint(result, "\n");
1478 cvar_set("g_maplist", result);
1481 float WinningCondition_Scores(float limit)
1483 // TODO make everything use THIS winning condition (except LMS)
1484 WinningConditionHelper();
1488 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1489 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1490 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1491 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1495 if(WinningConditionHelper_winner)
1496 WinningConditionHelper_winner.winning = 1;
1497 if(WinningConditionHelper_winnerteam >= 0)
1498 SetWinners(team, WinningConditionHelper_winnerteam);
1500 if(WinningConditionHelper_topscore == 0)
1501 WinningConditionHelper_equality = 0;
1503 if(WinningConditionHelper_lowerisbetter)
1505 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1509 return GetWinningCode(limit && WinningConditionHelper_topscore && (WinningConditionHelper_topscore >= limit), WinningConditionHelper_equality);
1512 float WinningCondition_Race(float fraglimit)
1516 wc = WinningCondition_Scores(fraglimit);
1518 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1519 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1520 // do NOT support equality when the laps are all raced!
1523 if not(p.race_completed)
1524 return WINNING_STARTOVERTIME;
1530 void ReadyRestart();
1531 float WinningCondition_QualifyingThenRace()
1534 wc = WinningCondition_Scores(0);
1536 // NEVER initiate overtime
1537 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1538 // do NOT support equality when the laps are all raced!
1541 float playerswithlaps;
1543 totalplayers = playerswithlaps = 0;
1544 FOR_EACH_PLAYER(head)
1547 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
1551 // at least 2/3 of the players have completed a lap: start the RACE
1552 // otherwise, the players should end the qualifying on their own
1553 if(totalplayers >= 3)
1554 if(playerswithlaps >= totalplayers * 2 / 3)
1556 checkrules_overtimeend = 0;
1558 return WINNING_NEVER;
1567 float WinningCondition_RanOutOfSpawns()
1571 if(!have_team_spawns)
1574 if(!some_spawn_has_been_used)
1577 team1_score = team2_score = team3_score = team4_score = 0;
1579 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1581 if(head.team == COLOR_TEAM1)
1583 else if(head.team == COLOR_TEAM2)
1585 else if(head.team == COLOR_TEAM3)
1587 else if(head.team == COLOR_TEAM4)
1591 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1593 if(head.team == COLOR_TEAM1)
1595 else if(head.team == COLOR_TEAM2)
1597 else if(head.team == COLOR_TEAM3)
1599 else if(head.team == COLOR_TEAM4)
1604 if(team1_score + team2_score + team3_score + team4_score == 0)
1606 checkrules_equality = TRUE;
1609 else if(team1_score + team2_score + team3_score + team4_score == 1)
1612 if(team1_score) t = COLOR_TEAM1;
1613 if(team2_score) t = COLOR_TEAM2;
1614 if(team3_score) t = COLOR_TEAM3;
1615 if(team4_score) t = COLOR_TEAM4;
1616 CheckAllowedTeams(world);
1617 for(i = 0; i < MAX_TEAMSCORE; ++i)
1619 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
1620 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
1621 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
1622 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
1625 AddWinners(team, t);
1636 Exit deathmatch games upon conditions
1639 void CheckRules_World()
1642 local float timelimit;
1643 local float fraglimit;
1651 MapVote_Think should now do that part
1652 if (intermission_running)
1653 if (time >= intermission_exittime + 60)
1655 if(!DoNextMapOverride())
1661 if (gameover) // someone else quit the game already
1663 if(player_count == 0) // Nobody there? Then let's go to the next map
1665 // this will actually check the player count in the next frame
1666 // again, but this shouldn't hurt
1670 timelimit = cvar("timelimit") * 60;
1671 fraglimit = cvar("fraglimit");
1673 if(checkrules_overtimeend)
1675 if(!checkrules_overtimewarning)
1677 checkrules_overtimewarning = TRUE;
1678 //announceall("announcer/robotic/1minuteremains.wav");
1679 if(!g_race_qualifying)
1680 bcenterprint("^3Everyone, finish your lap! The race is over!");
1682 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1687 if (timelimit && time >= timelimit)
1691 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1697 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1699 checkrules_oneminutewarning = TRUE;
1700 play2all("announcer/robotic/1minuteremains.wav");
1703 status = WinningCondition_RanOutOfSpawns();
1704 if(status == WINNING_YES)
1706 bprint("Hey! Someone ran out of spawns!\n");
1708 else if(g_race && !g_race_qualifying && timelimit >= 0)
1710 status = WinningCondition_Race(fraglimit);
1712 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
1714 status = WinningCondition_QualifyingThenRace();
1718 status = WinningCondition_Assault(); // TODO remove this?
1722 status = WinningCondition_LMS();
1724 else if (g_onslaught)
1726 status = WinningCondition_Onslaught(); // TODO remove this?
1730 status = WinningCondition_Scores(fraglimit);
1733 if(status == WINNING_STARTOVERTIME)
1735 status = WINNING_NEVER;
1739 if(status == WINNING_NEVER)
1740 // equality cases! Nobody wins if the overtime ends in a draw.
1743 if(checkrules_overtimeend)
1744 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1745 status = WINNING_YES;
1747 if(status == WINNING_YES)
1751 float mapvote_nextthink;
1752 float mapvote_initialized;
1753 float mapvote_keeptwotime;
1754 float mapvote_timeout;
1755 string mapvote_message;
1756 string mapvote_screenshot_dir;
1758 float mapvote_count;
1759 float mapvote_count_real;
1760 string mapvote_maps[MAPVOTE_COUNT];
1761 float mapvote_maps_suggested[MAPVOTE_COUNT];
1762 string mapvote_suggestions[MAPVOTE_COUNT];
1763 float mapvote_suggestion_ptr;
1764 float mapvote_maxlen;
1765 float mapvote_voters;
1766 float mapvote_votes[MAPVOTE_COUNT];
1768 float mapvote_detail;
1769 float mapvote_abstain;
1770 float mapvote_dirty;
1773 void MapVote_ClearAllVotes()
1775 FOR_EACH_CLIENT(other)
1779 string MapVote_Suggest(string m)
1783 return "That's not how to use this command.";
1784 if(!cvar("g_maplist_votable_suggestions"))
1785 return "Suggestions are not accepted on this server.";
1786 if(mapvote_initialized)
1787 return "Can't suggest - voting is already in progress!";
1789 m = MapInfo_FixName(m);
1791 return "The map you suggested is not available on this server.";
1793 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1794 if(!IsSameGametype(m))
1795 return "This server does not allow changing the game type by map suggestions.";
1797 if(!cvar("g_maplist_votable_override_mostrecent"))
1799 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1802 if(!MapInfo_CheckMap(m))
1803 return "The map you suggested does not support the current game mode.";
1805 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1806 return "The map you suggested is not available on this server.";
1808 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1809 if(mapvote_suggestions[i] == m)
1810 return "This map was already suggested.";
1811 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1813 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1817 i = mapvote_suggestion_ptr;
1818 mapvote_suggestion_ptr += 1;
1820 if(mapvote_suggestions[i] != "")
1821 strunzone(mapvote_suggestions[i]);
1822 mapvote_suggestions[i] = strzone(m);
1823 if(cvar("sv_eventlog"))
1824 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)), TRUE);
1825 return strcat("Suggestion of ", m, " accepted.");
1828 void MapVote_AddVotable(string nextMap, float isSuggestion)
1833 for(j = 0; j < mapvote_count; ++j)
1834 if(mapvote_maps[j] == nextMap)
1836 if(strlen(nextMap) > mapvote_maxlen)
1837 mapvote_maxlen = strlen(nextMap);
1838 mapvote_maps[mapvote_count] = strzone(nextMap);
1839 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1843 void MapVote_SendData(float target);
1849 MapVote_ClearAllVotes();
1852 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1853 mapvote_abstain = cvar("g_maplist_votable_abstain");
1856 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1858 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1859 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
1861 if(mapvote_suggestion_ptr)
1862 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1863 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1865 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1866 MapVote_AddVotable(GetNextMap(), FALSE);
1868 if(mapvote_count == 0)
1870 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1872 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1873 localcmd("\nmenu_cmd sync\n");
1875 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1877 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1878 MapVote_AddVotable(GetNextMap(), FALSE);
1881 mapvote_count_real = mapvote_count;
1883 MapVote_AddVotable("don't care", 0);
1885 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1887 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1888 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1889 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1890 mapvote_keeptwotime = 0;
1891 mapvote_message = "Choose a map and press its key!";
1893 mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
1894 if(mapvote_screenshot_dir == "")
1895 mapvote_screenshot_dir = "maps";
1896 mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
1898 if(!cvar("g_maplist_textonly"))
1899 MapVote_SendData(MSG_ALL);
1902 void MapVote_SendPicture(float id)
1905 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1906 WriteByte(MSG_ONE, TE_CSQC_MAPVOTE);
1907 WriteByte(MSG_ONE, MAPVOTE_NET_PIC);
1908 WriteByte(MSG_ONE, id);
1909 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 3072);
1912 float GameCommand_MapVote(string cmd)
1914 if(!intermission_running)
1916 if(!cvar("g_maplist_textonly"))
1918 if(cmd == "mv_getpic")
1920 MapVote_SendPicture(stof(argv(1)));
1928 float MapVote_GetMapMask()
1930 float mask, i, power;
1932 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
1933 if(mapvote_maps[i] != "")
1938 void MapVote_SendData(float targ)
1940 string mapfile, pakfile;
1942 WriteByte(targ, SVC_TEMPENTITY);
1943 WriteByte(targ, TE_CSQC_CONFIG);
1944 WriteString(targ, "mv_screenshot_dir");
1945 WriteString(targ, mapvote_screenshot_dir);
1947 WriteByte(targ, SVC_TEMPENTITY);
1948 WriteByte(targ, TE_CSQC_MAPVOTE);
1949 WriteByte(targ, MAPVOTE_NET_INIT);
1951 WriteByte(targ, mapvote_count);
1952 WriteByte(targ, mapvote_abstain);
1953 WriteByte(targ, mapvote_detail);
1954 WriteCoord(targ, mapvote_timeout);
1955 if(mapvote_count <= 8)
1956 WriteByte(targ, MapVote_GetMapMask());
1958 WriteShort(targ, MapVote_GetMapMask());
1959 for(i = 0; i < mapvote_count; ++i)
1960 if(mapvote_maps[i] != "")
1962 WriteString(targ, mapvote_maps[i]);
1963 mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
1964 pakfile = whichpack(strcat(mapfile, ".tga"));
1966 pakfile = whichpack(strcat(mapfile, ".jpg"));
1968 pakfile = whichpack(strcat(mapfile, ".png"));
1969 print("pakfile is ", pakfile, "\n");
1970 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
1971 pakfile = substring(pakfile, o, 999);
1972 WriteString(targ, pakfile);
1976 void MapVote_UpdateData(float targ)
1979 WriteByte(targ, SVC_TEMPENTITY);
1980 WriteByte(targ, TE_CSQC_MAPVOTE);
1981 WriteByte(targ, MAPVOTE_NET_UPDATE);
1982 if(mapvote_count <= 8)
1983 WriteByte(targ, MapVote_GetMapMask());
1985 WriteShort(targ, MapVote_GetMapMask());
1987 for(i = 0; i < mapvote_count; ++i)
1988 if(mapvote_maps[i] != "")
1989 WriteByte(targ, mapvote_votes[i]);
1992 void MapVote_TellVote(float targ, float vote)
1994 WriteByte(targ, SVC_TEMPENTITY);
1995 WriteByte(targ, TE_CSQC_MAPVOTE);
1996 WriteByte(targ, MAPVOTE_NET_OWNVOTE);
1997 WriteByte(targ, vote);
2000 float MapVote_Finished(float mappos)
2006 if(cvar("sv_eventlog"))
2008 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2009 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
2010 didntvote = mapvote_voters;
2011 for(i = 0; i < mapvote_count; ++i)
2012 if(mapvote_maps[i] != "")
2014 didntvote -= mapvote_votes[i];
2017 result = strcat(result, ":", mapvote_maps[i]);
2018 result = strcat(result, ":", ftos(mapvote_votes[i]));
2021 result = strcat(result, ":didn't vote:", ftos(didntvote));
2023 GameLogEcho(result, FALSE);
2024 if(mapvote_maps_suggested[mappos])
2025 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
2028 FOR_EACH_REALCLIENT(other)
2029 FixClientCvars(other);
2031 Map_Goto_SetStr(mapvote_maps[mappos]);
2033 alreadychangedlevel = TRUE;
2036 void MapVote_CheckRules_1()
2040 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2042 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2043 mapvote_votes[i] = 0;
2047 FOR_EACH_REALCLIENT(other)
2052 i = other.mapvote - 1;
2053 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2054 mapvote_votes[i] = mapvote_votes[i] + 1;
2059 float MapVote_CheckRules_2()
2062 float firstPlace, secondPlace;
2063 float firstPlaceVotes, secondPlaceVotes;
2064 float mapvote_voters_real;
2067 mapvote_voters_real = mapvote_voters;
2069 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2071 RandomSelection_Init();
2072 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2073 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2074 firstPlace = RandomSelection_chosen_float;
2075 firstPlaceVotes = RandomSelection_best_priority;
2076 //dprint("First place: ", ftos(firstPlace), "\n");
2077 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2079 RandomSelection_Init();
2080 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2082 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2083 secondPlace = RandomSelection_chosen_float;
2084 secondPlaceVotes = RandomSelection_best_priority;
2085 //dprint("Second place: ", ftos(secondPlace), "\n");
2086 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2088 if(firstPlace == -1)
2089 error("No first place in map vote... WTF?");
2091 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2092 return MapVote_Finished(firstPlace);
2094 if(mapvote_keeptwotime)
2095 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2098 mapvote_dirty = TRUE;
2099 mapvote_message = "Now decide between the TOP TWO!";
2100 mapvote_keeptwotime = 0;
2101 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2102 result = strcat(result, ":", ftos(firstPlaceVotes));
2103 result = strcat(result, ":", mapvote_maps[secondPlace]);
2104 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2105 didntvote = mapvote_voters;
2106 for(i = 0; i < mapvote_count; ++i)
2107 if(mapvote_maps[i] != "")
2109 didntvote -= mapvote_votes[i];
2111 if(i != secondPlace)
2113 result = strcat(result, ":", mapvote_maps[i]);
2114 result = strcat(result, ":", ftos(mapvote_votes[i]));
2115 if(i < mapvote_count_real)
2117 strunzone(mapvote_maps[i]);
2118 mapvote_maps[i] = "";
2122 result = strcat(result, ":didn't vote:", ftos(didntvote));
2123 if(cvar("sv_eventlog"))
2124 GameLogEcho(result, FALSE);
2137 keeptwo = mapvote_keeptwotime;
2138 MapVote_CheckRules_1(); // count
2139 if(MapVote_CheckRules_2()) // decide
2143 FOR_EACH_REALCLIENT(other)
2145 // hide scoreboard again
2146 if(other.health != 2342)
2148 other.health = 2342;
2150 if(clienttype(other) == CLIENTTYPE_REAL)
2152 if(cvar("g_maplist_textonly"))
2153 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");
2156 WriteByte(MSG_ONE, SVC_FINALE);
2157 WriteString(MSG_ONE, "");
2161 // notify about keep-two
2162 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2163 play2(other, "misc/invshot.wav");
2165 // clear possibly invalid votes
2166 if(mapvote_maps[other.mapvote - 1] == "")
2168 // use impulses as new vote
2169 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2170 if(mapvote_maps[other.impulse - 1] != "")
2172 other.mapvote = other.impulse;
2174 mapvote_dirty = TRUE;
2177 MapVote_TellVote(MSG_ONE, other.mapvote);
2185 MapVote_CheckRules_1(); // just count
2187 if(!cvar("g_maplist_textonly"))
2188 if(mapvote_dirty) // 1 if "keeptwo" or "impulse" happened before
2190 MapVote_UpdateData(MSG_BROADCAST);
2191 mapvote_dirty = FALSE;
2194 if(cvar("g_maplist_textonly"))
2196 FOR_EACH_REALCLIENT(other)
2198 // display voting screen
2199 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2200 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2202 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2203 msgstr = strcat(msgstr, mapvote_message);
2204 msgstr = strcat(msgstr, "\n\n");
2205 for(i = 0; i < mapvote_count; ++i)
2206 if(mapvote_maps[i] == "")
2207 msgstr = strcat(msgstr, "\n");
2210 tmp = mapvote_maps[i];
2211 tmp = strpad(mapvote_maxlen, tmp);
2212 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2215 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2216 if(mapvote_votes[i] != 1)
2217 tmp = strcat(tmp, "s");
2218 tmp = strcat(tmp, ")");
2219 tmp = strpad(mapvote_maxlen + 15, tmp);
2222 if(i == mapvote_count - 1)
2223 msgstr = strcat(msgstr, "\n");
2224 if(other.mapvote == i + 1)
2225 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2227 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2230 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2232 msgstr = strcat(msgstr, "s");
2233 msgstr = strcat(msgstr, " cast");
2234 i = ceil(mapvote_timeout - time);
2235 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2237 msgstr = strcat(msgstr, "s");
2238 msgstr = strcat(msgstr, " left");
2240 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2244 void MapVote_Start()
2250 MapInfo_Enumerate();
2251 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2255 void MapVote_Think()
2260 if(alreadychangedlevel)
2263 if(time < mapvote_nextthink)
2267 mapvote_nextthink = time + 0.5;
2269 if(!mapvote_initialized)
2271 mapvote_initialized = TRUE;
2272 if(DoNextMapOverride())
2274 if(!cvar("g_maplist_votable") || player_count <= 0)
2285 string GotoMap(string m)
2288 if(!MapInfo_CheckMap(m))
2290 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2292 return "The map you chose is not available on this server.";
2293 cvar_set("nextmap", m);
2294 cvar_set("timelimit", "-1");
2295 if(mapvote_initialized || alreadychangedlevel)
2297 if(DoNextMapOverride())
2298 return "Map switch initiated.";
2300 return "Hm... no. For some reason I like THIS map more.";
2303 return "Map switch will happen after scoreboard.";
2309 FOR_EACH_REALCLIENT(self)
2311 if(self.classname == "spectator")
2313 if(self.enemy.hitsound)
2314 play2(self, "misc/hit.wav");
2319 play2(self, "misc/hit.wav");
2322 FOR_EACH_CLIENT(self)
2323 self.hitsound = FALSE;
2329 * returns TRUE if redirecting
2331 float redirection_timeout;
2332 float redirection_nextthink;
2333 float RedirectionThink()
2335 float clients_found;
2337 if(redirection_target == "")
2340 if(!redirection_timeout)
2342 cvar_set("sv_public", "-2");
2343 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2344 if(redirection_target == "self")
2345 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2347 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2350 if(time < redirection_nextthink)
2353 redirection_nextthink = time + 1;
2356 FOR_EACH_REALCLIENT(self)
2358 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2359 if(redirection_target == "self")
2360 stuffcmd(self, "\ndisconnect; reconnect\n");
2362 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2366 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2368 if(time > redirection_timeout || clients_found == 0)
2369 localcmd("\nwait; wait; wait; quit\n");
2376 // Loaded from a save game
2377 // some things then break, so let's work around them...
2379 // Progs DB (capture records)
2381 ServerProgsDB = db_create();
2383 ServerProgsDB = db_load("server.db");
2388 MapInfo_Enumerate();
2389 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
2395 if(world_initialized)
2397 world_initialized = 0;
2398 print("Saving persistent data...\n");
2401 db_save(ServerProgsDB, "server.db");
2402 db_close(ServerProgsDB);
2404 // tell the bot system the game is ending now
2411 print("NOTE: crashed before even initializing the world, not saving persistent data\n");