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;
178 compressShortVector_init();
181 head = nextent(world);
186 head = nextent(head);
193 ServerProgsDB = db_create();
195 ServerProgsDB = db_load("server.db");
198 TODO sound pack system
199 // initialize sound pack system
200 soundpack = cvar_string("g_soundpack");
202 soundpack = strcat(soundpack, "/");
203 soundpack = strzone(soundpack);
209 // 1 FLICKER (first variety)
210 lightstyle(1, "mmnmmommommnonmmonqnmmo");
212 // 2 SLOW STRONG PULSE
213 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
215 // 3 CANDLE (first variety)
216 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
219 lightstyle(4, "mamamamamama");
222 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
224 // 6 FLICKER (second variety)
225 lightstyle(6, "nmonqnmomnmomomno");
227 // 7 CANDLE (second variety)
228 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
230 // 8 CANDLE (third variety)
231 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
233 // 9 SLOW STROBE (fourth variety)
234 lightstyle(9, "aaaaaaaazzzzzzzz");
236 // 10 FLUORESCENT FLICKER
237 lightstyle(10, "mmamammmmammamamaaamammma");
239 // 11 SLOW PULSE NOT FADE TO BLACK
240 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
242 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
247 if(cvar("g_campaign"))
254 bot_waypoints_for_items = cvar("g_waypoints_for_items");
255 if(bot_waypoints_for_items == 1)
256 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
257 bot_waypoints_for_items = 0;
259 // for setting by mapinfo
260 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
261 cvar_set("sv_q3acompat_machineshotgunswap", "0");
265 WaypointSprite_Init();
270 GameLogInit(); // prepare everything
271 if(cvar("sv_eventlog"))
273 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
274 s = strcat(s, ftos(random()));
276 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s), FALSE);
278 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
280 s = ":gameinfo:mutators:LIST";
281 if(cvar("g_grappling_hook"))
282 s = strcat(s, ":grappling_hook");
283 if(!cvar("g_use_ammunition"))
284 s = strcat(s, ":no_use_ammunition");
285 if(!cvar("g_pickup_items"))
286 s = strcat(s, ":no_pickup_items");
287 if(cvar("g_instagib"))
288 s = strcat(s, ":instagib");
289 if(cvar("g_rocketarena"))
290 s = strcat(s, ":rockerarena");
292 s = strcat(s, ":nixnex");
293 if(cvar("g_vampire"))
294 s = strcat(s, ":vampire");
295 if(cvar("g_laserguided_missile"))
296 s = strcat(s, ":laserguided_missile");
297 if(cvar("g_norecoil"))
298 s = strcat(s, ":norecoil");
300 s = strcat(s, ":midair");
301 if(cvar("g_minstagib"))
302 s = strcat(s, ":minstagib");
303 GameLogEcho(s, FALSE);
304 GameLogEcho(":gameinfo:end", FALSE);
307 cvar_set("nextmap", "");
311 if(cvar("g_campaign"))
318 //initialise globals related to sv_timeout
319 sys_ticrate = cvar("sys_ticrate");
320 orig_slowmo = cvar("slowmo");
324 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
327 //if tourney is used map starts in warmup mode. if this mode shall stay unlimited, reset timelimit, but save the original one
328 if(g_tourney && cvar("g_tourney_warmup_unlimited_time")) {
329 timelimit_orig = cvar("timelimit");
330 cvar_set("timelimit", "0");
333 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
335 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
338 while((s = fgets(fd)))
345 print("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
346 print(" cdtrack ", argv(2), "\n");
348 else if(argv(0) == "fog")
350 print("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
351 print(" \"fog\" \"", s, "\"\n");
353 else if(argv(0) == "set")
355 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
356 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
358 else if(argv(0) != "//")
360 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
361 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
368 next_pingtime = time + 5;
369 world_initialized = 1;
372 void spawnfunc_light (void)
374 //makestatic (self); // Who the f___ did that?
378 float TryFile( string pFilename )
381 dprint("TryFile(\"", pFilename, "\")\n");
382 lHandle = fopen( pFilename, FILE_READ );
383 if( lHandle != -1 ) {
393 return GametypeNameFromType(game);
396 float IsSameGametype(string mapcfgname)
399 return TRUE; // can't change game type by map name here
403 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
409 string getmapname_stored;
415 if(getmapname_stored == "")
416 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
417 return getmapname_stored;
421 float Map_Count, Map_Current;
422 string Map_Current_Name;
424 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
425 float GetMaplistPosition()
431 idx = cvar("g_maplist_index");
438 for(pos = 0; pos < Map_Count; ++pos)
442 // resume normal maplist rotation if current map is not in g_maplist
446 float MapHasRightSize(string map)
449 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
450 if(cvar("g_maplist_check_waypoints"))
452 dprint("checkwp "); dprint(map);
453 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
456 dprint(": no waypoints\n");
459 dprint(": has waypoints\n");
463 // open map size restriction file
464 dprint("opensize "); dprint(map);
465 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
468 float mapmin, mapmax;
470 mapmin = stof(fgets(fh));
471 mapmax = stof(fgets(fh));
473 if(player_count < mapmin)
475 dprint("not enough\n");
478 if(player_count > mapmax)
480 dprint("too many\n");
483 dprint("right size\n");
486 dprint(": not found\n");
490 string Map_Filename(float position)
493 return strcat("maps/", argv(position), ".bsp");
495 return strcat("maps/", argv(position), ".mapcfg");
499 string strwords(string s, float w)
502 for(endpos = 0; w && endpos >= 0; --w)
503 endpos = strstrofs(s, " ", endpos + 1);
507 return substring(s, 0, endpos);
510 float strhasword(string s, string w)
512 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
515 void Map_MarkAsRecent(string m)
517 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
520 float Map_IsRecent(string m)
522 return strhasword(cvar_string("g_maplist_mostrecent"), m);
525 float Map_Check(float position, float pass)
529 map_next = argv(position);
532 if(map_next == Map_Current_Name) // same map again in first pass?
534 if(Map_IsRecent(map_next))
537 filename = Map_Filename(position);
539 if(MapInfo_CheckMap(map_next))
541 if(TryFile(filename))
546 if(MapHasRightSize(map_next))
551 dprint( "Couldn't select '", filename, "'..\n" );
556 void Map_Goto_SetStr(string nextmapname)
558 if(getmapname_stored != "")
559 strunzone(getmapname_stored);
560 if(nextmapname == "")
561 getmapname_stored = "";
563 getmapname_stored = strzone(nextmapname);
566 void Map_Goto_SetFloat(float position)
568 cvar_set("g_maplist_index", ftos(position));
569 Map_Goto_SetStr(argv(position));
575 // settings persist, except...
576 if(cvar("g_campaign"))
577 localcmd("\nexec mutator_reset.cfg\n");
578 localcmd("\nsettemp_restore\n");
580 // if an exit cfg is defined by exiting map, exec it.
582 exit_cfg = cvar_string("exit_cfg");
584 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
586 localcmd("exec game_reset.cfg\n");
592 Map_MarkAsRecent(getmapname_stored);
595 MapInfo_LoadMap(getmapname_stored);
597 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
601 // return codes of map selectors:
602 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
603 // -2 = permanent failure
604 float() MaplistMethod_Iterate = // usual method
608 for(pass = 1; pass <= 2; ++pass)
610 for(i = 1; i < Map_Count; ++i)
613 mapindex = mod(i + Map_Current, Map_Count);
614 if(Map_Check(mapindex, pass))
621 float() MaplistMethod_Repeat = // fallback method
623 if(Map_Check(Map_Current, 2))
628 float() MaplistMethod_Random = // random map selection
634 for(i = 0; i <= imax; ++i)
637 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
638 if(Map_Check(mapindex, 1))
644 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
645 // the exponent sets a bias on the map selection:
646 // the higher the exponent, the less likely "shortly repeated" same maps are
648 float i, j, imax, insertpos;
652 for(i = 0; i <= imax; ++i)
656 // now reinsert this at another position
657 insertpos = pow(random(), 1 / exponent); // ]0, 1]
658 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
659 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
660 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
662 // insert the current map there
665 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
666 newlist = strcat(newlist, " ", argv(j));
667 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
668 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
669 newlist = strcat(newlist, " ", argv(j));
670 newlist = substring(newlist, 1, strlen(newlist) - 1);
672 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
673 newlist = strcat(newlist, "'", argv(j), "'");
674 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
675 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
676 newlist = strcat(newlist, "'", argv(j), "'");
678 cvar_set("g_maplist", newlist);
680 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
682 Map_Count = tokenize(newlist);
685 // NOTE: the selected map has just been inserted at (insertpos-1)th position
686 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
687 if(Map_Check(Map_Current, 1))
696 temp = cvar_string("g_maplist");
698 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
700 Map_Count = tokenize(temp);
704 bprint( "Maplist is empty! Resetting it to default map list.\n" );
706 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
707 localcmd("\nmenu_cmd sync\n");
708 Map_Count = tokenizebyseparator(temp, " ");
710 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
711 Map_Count = tokenize(temp);
715 error("empty maplist, cannot select a new map");
716 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
719 strunzone(Map_Current_Name);
720 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
721 // this may or may not be correct, but who cares, in the worst case a map
722 // isn't chosen in the first pass that should have been
733 if(cvar("g_maplist_shuffle") > 0)
734 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
737 if(cvar("g_maplist_selectrandom"))
738 nextMap = MaplistMethod_Random();
741 nextMap = MaplistMethod_Iterate();
744 nextMap = MaplistMethod_Repeat();
748 Map_Goto_SetFloat(nextMap);
749 return getmapname_stored;
755 float DoNextMapOverride()
757 if(cvar("g_campaign"))
759 CampaignPostIntermission();
760 alreadychangedlevel = TRUE;
763 if(cvar("quit_when_empty"))
765 if(player_count <= currentbots)
768 alreadychangedlevel = TRUE;
772 if(cvar_string("quit_and_redirect") != "")
774 redirection_target = strzone(cvar_string("quit_and_redirect"));
775 alreadychangedlevel = TRUE;
778 if (cvar("samelevel")) // if samelevel is set, stay on same level
780 // 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)
781 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
782 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
783 localcmd("restart\n");
784 //changelevel (mapname);
785 alreadychangedlevel = TRUE;
788 if(cvar_string("nextmap") != "")
790 if(MapInfo_CheckMap(cvar_string("nextmap")))
792 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
795 Map_Goto_SetStr(cvar_string("nextmap"));
797 alreadychangedlevel = TRUE;
800 if(cvar("lastlevel"))
803 localcmd("set lastlevel 0\ntogglemenu\n");
804 alreadychangedlevel = TRUE;
812 //local string nextmap;
813 //local float n, nummaps;
815 if (alreadychangedlevel)
817 alreadychangedlevel = TRUE;
823 for(allowReset = 1; allowReset >= 0; --allowReset)
825 nextMap = GetNextMap();
831 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
833 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
834 localcmd("\nmenu_cmd sync\n");
836 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
841 error("Everything is broken - not even the default map list works. Please report this to the developers.");
853 When the player presses attack or jump, change to the next level
856 .float autoscreenshot;
857 void() MapVote_Start;
858 void() MapVote_Think;
859 float mapvote_initialized;
860 void IntermissionThink()
862 FixIntermissionClient(self);
864 if(cvar("sv_autoscreenshot"))
865 if(self.autoscreenshot > 0)
866 if(time > self.autoscreenshot)
868 self.autoscreenshot = -1;
869 if(clienttype(self) == CLIENTTYPE_REAL)
870 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
874 if (time < intermission_exittime)
877 if(!mapvote_initialized)
878 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
888 Returns the entity to view from
892 entity FindIntermission()
897 // look for info_intermission first
898 spot = find (world, classname, "info_intermission");
900 { // pick a random one
904 spot = find (spot, classname, "info_intermission");
906 spot = find (spot, classname, "info_intermission");
912 // then look for the start position
913 spot = find (world, classname, "info_player_start");
917 // testinfo_player_start is only found in regioned levels
918 spot = find (world, classname, "testplayerstart");
922 // then look for the start position
923 spot = find (world, classname, "info_player_deathmatch");
927 //objerror ("FindIntermission: no spot");
933 ===============================================================================
937 ===============================================================================
940 void DumpStats(float final)
944 local float to_console;
945 local float to_eventlog;
949 to_console = cvar("sv_logscores_console");
950 to_eventlog = cvar("sv_eventlog");
951 to_file = cvar("sv_logscores_file");
955 to_console = TRUE; // always print printstats replies
956 to_eventlog = FALSE; // but never print them to the event log
960 if(cvar("sv_eventlog_console"))
961 to_console = FALSE; // otherwise we get the output twice
968 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
970 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
974 ServerConsoleEcho(s, FALSE);
976 GameLogEcho(s, FALSE);
979 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
983 fputs(file, strcat(s, "\n"));
986 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
988 ServerConsoleEcho(s, TRUE);
990 GameLogEcho(s, TRUE);
992 fputs(file, strcat(s, "\n"));
994 FOR_EACH_CLIENT(other)
996 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
998 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
999 s = strcat(s, ftos(rint(time - other.jointime)), ":");
1000 if(other.classname == "player" || g_arena || g_lms)
1001 s = strcat(s, ftos(other.team), ":");
1003 s = strcat(s, "spectator:");
1006 ServerConsoleEcho(strcat(s, other.netname), TRUE);
1008 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
1010 fputs(file, strcat(s, other.netname, "\n"));
1016 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
1018 ServerConsoleEcho(s, TRUE);
1020 GameLogEcho(s, TRUE);
1022 fputs(file, strcat(s, "\n"));
1024 for(i = 1; i < 16; ++i)
1026 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
1027 s = strcat(s, ":", ftos(i));
1029 ServerConsoleEcho(s, TRUE);
1031 GameLogEcho(s, TRUE);
1033 fputs(file, strcat(s, "\n"));
1038 ServerConsoleEcho(":end", FALSE);
1040 GameLogEcho(":end", FALSE);
1043 fputs(file, ":end\n");
1048 void FixIntermissionClient(entity e)
1051 if(!e.autoscreenshot) // initial call
1053 e.angles = e.v_angle;
1054 e.angles_x = -e.angles_x;
1055 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1057 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1058 e.solid = SOLID_NOT;
1059 e.movetype = MOVETYPE_NONE;
1060 e.takedamage = DAMAGE_NO;
1062 e.weaponentity.effects = EF_NODRAW;
1063 if(clienttype(e) == CLIENTTYPE_REAL)
1065 stuffcmd(e, "\nscr_printspeed 1000000\n");
1066 s = cvar_string("sv_intermission_cdtrack");
1068 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1070 WriteByte(MSG_ONE, SVC_INTERMISSION);
1074 //e.velocity = '0 0 0';
1075 //e.fixangle = TRUE;
1077 // TODO halt weapon animation
1082 go to the next level for deathmatch
1083 only called if a time or frag limit has expired
1087 float minTotalFrags;
1088 float maxTotalFrags;
1094 intermission_running = 1;
1096 // enforce a wait time before allowing changelevel
1097 if(player_count > 0)
1098 intermission_exittime = time + cvar("sv_mapchange_delay");
1100 intermission_exittime = -1;
1103 WriteByte (MSG_ALL, SVC_CDTRACK);
1104 WriteByte (MSG_ALL, 3);
1105 WriteByte (MSG_ALL, 3);
1106 // done in FixIntermission
1109 //pos = FindIntermission ();
1115 if(cvar("sv_eventlog"))
1116 GameLogEcho(":gameover", FALSE);
1120 FOR_EACH_CLIENT(other)
1122 FixIntermissionClient(other);
1125 bprint(other.netname, " ^7wins.\n");
1130 FOR_EACH_PLAYER(other)
1132 if(maxTotalFrags < other.totalfrags)
1133 maxTotalFrags = other.totalfrags;
1134 if(minTotalFrags > other.totalfrags)
1135 minTotalFrags = other.totalfrags;
1140 FOR_EACH_PLAYER(other)
1142 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1143 f = bound(0, other.play_time / max(time, 1), 1);
1144 // store some statistics?
1148 if(cvar("g_campaign"))
1149 CampaignPreIntermission();
1151 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1158 Exit deathmatch games upon conditions
1162 void CheckRules_Player()
1164 if (gameover) // someone else quit the game already
1167 if(self.deadflag == DEAD_NO)
1168 self.play_time += frametime;
1172 if(time > self.fogtime)
1174 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1175 self.fogtime = time + sv_foginterval;
1178 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1179 // (div0: and that in CheckRules_World please)
1182 float checkrules_oneminutewarning;
1184 float checkrules_equality;
1185 float checkrules_overtimewarning;
1186 float checkrules_overtimeend;
1188 void InitiateOvertime()
1190 if(!checkrules_overtimeend)
1191 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1194 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1195 float WINNING_YES = 1; // winner found
1196 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1197 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1199 float GetWinningCode(float fraglimitreached, float equality)
1202 if(fraglimitreached)
1203 return WINNING_STARTOVERTIME;
1205 return WINNING_NEVER;
1207 if(fraglimitreached)
1213 // set the .winning flag for exactly those players with a given field value
1214 void SetWinners(.float field, float value)
1217 FOR_EACH_PLAYER(head)
1218 head.winning = (head.field == value);
1221 // set the .winning flag for those players with a given field value
1222 void AddWinners(.float field, float value)
1225 FOR_EACH_PLAYER(head)
1226 if(head.field == value)
1230 // clear the .winning flags
1231 void ClearWinners(void)
1234 FOR_EACH_PLAYER(head)
1238 // Onslaught winning condition:
1239 // game terminates if only one team has a working generator (or none)
1240 float WinningCondition_Onslaught()
1243 local float t1, t2, t3, t4;
1244 // first check if the game has ended
1245 t1 = t2 = t3 = t4 = 0;
1246 head = find(world, classname, "onslaught_generator");
1249 if (head.health > 0)
1251 if (head.team == COLOR_TEAM1) t1 = 1;
1252 if (head.team == COLOR_TEAM2) t2 = 1;
1253 if (head.team == COLOR_TEAM3) t3 = 1;
1254 if (head.team == COLOR_TEAM4) t4 = 1;
1256 head = find(head, classname, "onslaught_generator");
1258 if (t1 + t2 + t3 + t4 < 2)
1260 // game over, only one team remains (or none)
1262 if (t1) SetWinners(team, COLOR_TEAM1);
1263 if (t2) SetWinners(team, COLOR_TEAM2);
1264 if (t3) SetWinners(team, COLOR_TEAM3);
1265 if (t4) SetWinners(team, COLOR_TEAM4);
1266 dprint("Have a winner, ending game.\n");
1270 // Two or more teams remain
1274 float LMS_NewPlayerLives()
1277 fl = cvar("fraglimit");
1281 // first player has left the game for dying too much? Nobody else can get in.
1282 if(lms_lowest_lives < 1)
1285 if(!cvar("g_lms_join_anytime"))
1286 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1289 return bound(1, lms_lowest_lives, fl);
1292 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1293 // they win. Otherwise the defending team wins once the timelimit passes.
1294 void assault_new_round();
1295 float WinningCondition_Assault()
1298 status = WINNING_NO;
1300 // as the timelimit has not yet passed just assume the defending team will win
1301 if(assault_attacker_team == COLOR_TEAM1)
1303 SetWinners(team, COLOR_TEAM2);
1307 SetWinners(team, COLOR_TEAM1);
1311 ent = find(world, classname, "target_assault_roundend");
1314 if(ent.winning) // round end has been triggered by attacking team
1316 SetWinners(team, assault_attacker_team);
1317 if(assault_attacker_team == COLOR_TEAM1)
1319 team1_score = team1_score + 50;
1323 team2_score = team2_score + 50;
1326 if(ent.cnt == 1) // this was the second round
1328 status = WINNING_YES;
1332 local entity oldself;
1335 cvar_set("timelimit", ftos((2*time)/60));
1336 assault_new_round();
1346 // LMS winning condition: game terminates if and only if there's at most one
1347 // one player who's living lives. Top two scores being equal cancels the time
1349 float WinningCondition_LMS()
1356 have_player = FALSE;
1357 have_players = FALSE;
1358 l = LMS_NewPlayerLives();
1360 head = find(world, classname, "player");
1363 head2 = find(head, classname, "player");
1365 have_players = TRUE;
1369 // we have at least one player
1372 // two or more active players - continue with the game
1376 // exactly one player?
1379 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1383 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1389 // and assign him his first place
1390 PlayerScore_Add(head, SP_LMS_RANK, 1);
1397 // nobody is playing at all...
1400 // wait for players...
1404 // SNAFU (maybe a draw game?)
1406 dprint("No players, ending game.\n");
1411 // When we get here, we have at least two players who are actually LIVING,
1412 // now check if the top two players have equal score.
1413 WinningConditionHelper();
1416 if(WinningConditionHelper_winner)
1417 WinningConditionHelper_winner.winning = TRUE;
1418 if(WinningConditionHelper_equality)
1419 return WINNING_NEVER;
1421 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1425 void print_to(entity e, string s)
1428 sprint(e, strcat(s, "\n"));
1430 ServerConsoleEcho(s, TRUE);
1433 void ShuffleMaplist()
1441 result = cvar_string("g_maplist");
1443 litems = tokenizebyseparator(result, " ");
1445 litems = tokenize(result);
1448 for(start = 0; start < litems - 1; ++start)
1452 // select a random item
1453 selected = ceil(random() * (litems - start) + start) - 1;
1455 // shift this item to the place start
1457 for(i = 0; i < start; ++i)
1458 result = strcat(result, " ", argv(i));
1459 result = strcat(result, " ", argv(selected));
1460 for(i = start; i < litems; ++i)
1462 result = strcat(result, " ", argv(i));
1463 result = substring(result, 1, strlen(result) - 1);
1465 litems = tokenizebyseparator(result, " ");
1467 for(i = 0; i < start; ++i)
1468 result = strcat(result, "'", argv(i), "'");
1469 result = strcat(result, "'", argv(selected), "'");
1470 for(i = start; i < litems; ++i)
1472 result = strcat(result, "'", argv(i), "'");
1474 litems = tokenize(result);
1477 //dprint(result, "\n");
1480 cvar_set("g_maplist", result);
1483 float WinningCondition_Scores(float limit)
1485 // TODO make everything use THIS winning condition (except LMS)
1486 WinningConditionHelper();
1490 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1491 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1492 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1493 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1497 if(WinningConditionHelper_winner)
1498 WinningConditionHelper_winner.winning = 1;
1499 if(WinningConditionHelper_winnerteam >= 0)
1500 SetWinners(team, WinningConditionHelper_winnerteam);
1502 if(WinningConditionHelper_topscore == 0)
1503 WinningConditionHelper_equality = 0;
1505 if(WinningConditionHelper_lowerisbetter)
1507 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1511 return GetWinningCode(limit && WinningConditionHelper_topscore && (WinningConditionHelper_topscore >= limit), WinningConditionHelper_equality);
1514 float WinningCondition_Race(float fraglimit)
1518 wc = WinningCondition_Scores(fraglimit);
1520 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1521 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1522 // do NOT support equality when the laps are all raced!
1525 if not(p.race_completed)
1526 return WINNING_STARTOVERTIME;
1532 void ReadyRestart();
1533 float WinningCondition_QualifyingThenRace(float limit)
1536 wc = WinningCondition_Scores(limit);
1538 // NEVER initiate overtime
1539 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1540 // do NOT support equality when the laps are all raced!
1543 float playerswithlaps;
1545 totalplayers = playerswithlaps = 0;
1546 FOR_EACH_PLAYER(head)
1549 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
1553 // at least 2/3 of the players have completed a lap: start the RACE
1554 // otherwise, the players should end the qualifying on their own
1555 if(totalplayers >= 3)
1556 if(playerswithlaps >= totalplayers * 2 / 3)
1558 checkrules_overtimeend = 0;
1560 return WINNING_NEVER;
1569 float WinningCondition_RanOutOfSpawns()
1573 if(!have_team_spawns)
1576 if(!some_spawn_has_been_used)
1579 team1_score = team2_score = team3_score = team4_score = 0;
1581 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1583 if(head.team == COLOR_TEAM1)
1585 else if(head.team == COLOR_TEAM2)
1587 else if(head.team == COLOR_TEAM3)
1589 else if(head.team == COLOR_TEAM4)
1593 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1595 if(head.team == COLOR_TEAM1)
1597 else if(head.team == COLOR_TEAM2)
1599 else if(head.team == COLOR_TEAM3)
1601 else if(head.team == COLOR_TEAM4)
1606 if(team1_score + team2_score + team3_score + team4_score == 0)
1608 checkrules_equality = TRUE;
1611 else if(team1_score + team2_score + team3_score + team4_score == 1)
1614 if(team1_score) t = COLOR_TEAM1;
1615 if(team2_score) t = COLOR_TEAM2;
1616 if(team3_score) t = COLOR_TEAM3;
1617 if(team4_score) t = COLOR_TEAM4;
1618 CheckAllowedTeams(world);
1619 for(i = 0; i < MAX_TEAMSCORE; ++i)
1621 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
1622 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
1623 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
1624 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
1627 AddWinners(team, t);
1638 Exit deathmatch games upon conditions
1641 void CheckRules_World()
1644 local float timelimit;
1645 local float fraglimit;
1653 MapVote_Think should now do that part
1654 if (intermission_running)
1655 if (time >= intermission_exittime + 60)
1657 if(!DoNextMapOverride())
1663 if (gameover) // someone else quit the game already
1665 if(player_count == 0) // Nobody there? Then let's go to the next map
1667 // this will actually check the player count in the next frame
1668 // again, but this shouldn't hurt
1672 timelimit = cvar("timelimit") * 60;
1673 fraglimit = cvar("fraglimit");
1675 if(checkrules_overtimeend)
1677 if(!checkrules_overtimewarning)
1679 checkrules_overtimewarning = TRUE;
1680 //announceall("announcer/robotic/1minuteremains.wav");
1681 if(!g_race_qualifying)
1682 bcenterprint("^3Everyone, finish your lap! The race is over!");
1684 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1689 if (timelimit && time >= timelimit)
1693 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1699 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1701 checkrules_oneminutewarning = TRUE;
1702 play2all("announcer/robotic/1minuteremains.wav");
1705 status = WinningCondition_RanOutOfSpawns();
1706 if(status == WINNING_YES)
1708 bprint("Hey! Someone ran out of spawns!\n");
1710 else if(g_race && !g_race_qualifying && timelimit >= 0)
1712 status = WinningCondition_Race(fraglimit);
1714 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
1716 status = WinningCondition_QualifyingThenRace(fraglimit);
1720 status = WinningCondition_Assault(); // TODO remove this?
1724 status = WinningCondition_LMS();
1726 else if (g_onslaught)
1728 status = WinningCondition_Onslaught(); // TODO remove this?
1732 status = WinningCondition_Scores(fraglimit);
1735 if(status == WINNING_STARTOVERTIME)
1737 status = WINNING_NEVER;
1741 if(status == WINNING_NEVER)
1742 // equality cases! Nobody wins if the overtime ends in a draw.
1745 if(checkrules_overtimeend)
1746 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1747 status = WINNING_YES;
1749 if(status == WINNING_YES)
1753 float mapvote_nextthink;
1754 float mapvote_initialized;
1755 float mapvote_keeptwotime;
1756 float mapvote_timeout;
1757 string mapvote_message;
1758 string mapvote_screenshot_dir;
1760 float mapvote_count;
1761 float mapvote_count_real;
1762 string mapvote_maps[MAPVOTE_COUNT];
1763 float mapvote_maps_suggested[MAPVOTE_COUNT];
1764 string mapvote_suggestions[MAPVOTE_COUNT];
1765 float mapvote_suggestion_ptr;
1766 float mapvote_maxlen;
1767 float mapvote_voters;
1768 float mapvote_votes[MAPVOTE_COUNT];
1770 float mapvote_detail;
1771 float mapvote_abstain;
1772 float mapvote_dirty;
1775 void MapVote_ClearAllVotes()
1777 FOR_EACH_CLIENT(other)
1781 string MapVote_Suggest(string m)
1785 return "That's not how to use this command.";
1786 if(!cvar("g_maplist_votable_suggestions"))
1787 return "Suggestions are not accepted on this server.";
1788 if(mapvote_initialized)
1789 return "Can't suggest - voting is already in progress!";
1791 m = MapInfo_FixName(m);
1793 return "The map you suggested is not available on this server.";
1795 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1796 if(!IsSameGametype(m))
1797 return "This server does not allow changing the game type by map suggestions.";
1799 if(!cvar("g_maplist_votable_override_mostrecent"))
1801 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1804 if(!MapInfo_CheckMap(m))
1805 return "The map you suggested does not support the current game mode.";
1807 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1808 return "The map you suggested is not available on this server.";
1810 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1811 if(mapvote_suggestions[i] == m)
1812 return "This map was already suggested.";
1813 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1815 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1819 i = mapvote_suggestion_ptr;
1820 mapvote_suggestion_ptr += 1;
1822 if(mapvote_suggestions[i] != "")
1823 strunzone(mapvote_suggestions[i]);
1824 mapvote_suggestions[i] = strzone(m);
1825 if(cvar("sv_eventlog"))
1826 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)), TRUE);
1827 return strcat("Suggestion of ", m, " accepted.");
1830 void MapVote_AddVotable(string nextMap, float isSuggestion)
1835 for(j = 0; j < mapvote_count; ++j)
1836 if(mapvote_maps[j] == nextMap)
1838 if(strlen(nextMap) > mapvote_maxlen)
1839 mapvote_maxlen = strlen(nextMap);
1840 mapvote_maps[mapvote_count] = strzone(nextMap);
1841 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1845 void MapVote_SendData(float target);
1851 MapVote_ClearAllVotes();
1854 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1855 mapvote_abstain = cvar("g_maplist_votable_abstain");
1858 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1860 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1861 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
1863 if(mapvote_suggestion_ptr)
1864 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1865 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1867 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1868 MapVote_AddVotable(GetNextMap(), FALSE);
1870 if(mapvote_count == 0)
1872 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1874 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1875 localcmd("\nmenu_cmd sync\n");
1877 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1879 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1880 MapVote_AddVotable(GetNextMap(), FALSE);
1883 mapvote_count_real = mapvote_count;
1885 MapVote_AddVotable("don't care", 0);
1887 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1889 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1890 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1891 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1892 mapvote_keeptwotime = 0;
1893 mapvote_message = "Choose a map and press its key!";
1895 mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
1896 if(mapvote_screenshot_dir == "")
1897 mapvote_screenshot_dir = "maps";
1898 mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
1900 if(!cvar("g_maplist_textonly"))
1901 MapVote_SendData(MSG_ALL);
1904 void MapVote_SendPicture(float id)
1907 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1908 WriteByte(MSG_ONE, TE_CSQC_MAPVOTE);
1909 WriteByte(MSG_ONE, MAPVOTE_NET_PIC);
1910 WriteByte(MSG_ONE, id);
1911 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 3072);
1914 float GameCommand_MapVote(string cmd)
1916 if(!intermission_running)
1918 if(!cvar("g_maplist_textonly"))
1920 if(cmd == "mv_getpic")
1922 MapVote_SendPicture(stof(argv(1)));
1930 float MapVote_GetMapMask()
1932 float mask, i, power;
1934 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
1935 if(mapvote_maps[i] != "")
1940 void MapVote_SendData(float targ)
1942 string mapfile, pakfile;
1944 WriteByte(targ, SVC_TEMPENTITY);
1945 WriteByte(targ, TE_CSQC_CONFIG);
1946 WriteString(targ, "mv_screenshot_dir");
1947 WriteString(targ, mapvote_screenshot_dir);
1949 WriteByte(targ, SVC_TEMPENTITY);
1950 WriteByte(targ, TE_CSQC_MAPVOTE);
1951 WriteByte(targ, MAPVOTE_NET_INIT);
1953 WriteByte(targ, mapvote_count);
1954 WriteByte(targ, mapvote_abstain);
1955 WriteByte(targ, mapvote_detail);
1956 WriteCoord(targ, mapvote_timeout);
1957 if(mapvote_count <= 8)
1958 WriteByte(targ, MapVote_GetMapMask());
1960 WriteShort(targ, MapVote_GetMapMask());
1961 for(i = 0; i < mapvote_count; ++i)
1962 if(mapvote_maps[i] != "")
1964 WriteString(targ, mapvote_maps[i]);
1965 mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
1966 pakfile = whichpack(strcat(mapfile, ".tga"));
1968 pakfile = whichpack(strcat(mapfile, ".jpg"));
1970 pakfile = whichpack(strcat(mapfile, ".png"));
1971 print("pakfile is ", pakfile, "\n");
1972 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
1973 pakfile = substring(pakfile, o, 999);
1974 WriteString(targ, pakfile);
1978 void MapVote_UpdateData(float targ)
1981 WriteByte(targ, SVC_TEMPENTITY);
1982 WriteByte(targ, TE_CSQC_MAPVOTE);
1983 WriteByte(targ, MAPVOTE_NET_UPDATE);
1984 if(mapvote_count <= 8)
1985 WriteByte(targ, MapVote_GetMapMask());
1987 WriteShort(targ, MapVote_GetMapMask());
1989 for(i = 0; i < mapvote_count; ++i)
1990 if(mapvote_maps[i] != "")
1991 WriteByte(targ, mapvote_votes[i]);
1994 void MapVote_TellVote(float targ, float vote)
1996 WriteByte(targ, SVC_TEMPENTITY);
1997 WriteByte(targ, TE_CSQC_MAPVOTE);
1998 WriteByte(targ, MAPVOTE_NET_OWNVOTE);
1999 WriteByte(targ, vote);
2002 float MapVote_Finished(float mappos)
2008 if(cvar("sv_eventlog"))
2010 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2011 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
2012 didntvote = mapvote_voters;
2013 for(i = 0; i < mapvote_count; ++i)
2014 if(mapvote_maps[i] != "")
2016 didntvote -= mapvote_votes[i];
2019 result = strcat(result, ":", mapvote_maps[i]);
2020 result = strcat(result, ":", ftos(mapvote_votes[i]));
2023 result = strcat(result, ":didn't vote:", ftos(didntvote));
2025 GameLogEcho(result, FALSE);
2026 if(mapvote_maps_suggested[mappos])
2027 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
2030 FOR_EACH_REALCLIENT(other)
2031 FixClientCvars(other);
2033 Map_Goto_SetStr(mapvote_maps[mappos]);
2035 alreadychangedlevel = TRUE;
2038 void MapVote_CheckRules_1()
2042 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2044 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2045 mapvote_votes[i] = 0;
2049 FOR_EACH_REALCLIENT(other)
2054 i = other.mapvote - 1;
2055 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2056 mapvote_votes[i] = mapvote_votes[i] + 1;
2061 float MapVote_CheckRules_2()
2064 float firstPlace, secondPlace;
2065 float firstPlaceVotes, secondPlaceVotes;
2066 float mapvote_voters_real;
2069 mapvote_voters_real = mapvote_voters;
2071 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2073 RandomSelection_Init();
2074 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2075 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2076 firstPlace = RandomSelection_chosen_float;
2077 firstPlaceVotes = RandomSelection_best_priority;
2078 //dprint("First place: ", ftos(firstPlace), "\n");
2079 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2081 RandomSelection_Init();
2082 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2084 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2085 secondPlace = RandomSelection_chosen_float;
2086 secondPlaceVotes = RandomSelection_best_priority;
2087 //dprint("Second place: ", ftos(secondPlace), "\n");
2088 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2090 if(firstPlace == -1)
2091 error("No first place in map vote... WTF?");
2093 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2094 return MapVote_Finished(firstPlace);
2096 if(mapvote_keeptwotime)
2097 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2100 mapvote_dirty = TRUE;
2101 mapvote_message = "Now decide between the TOP TWO!";
2102 mapvote_keeptwotime = 0;
2103 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2104 result = strcat(result, ":", ftos(firstPlaceVotes));
2105 result = strcat(result, ":", mapvote_maps[secondPlace]);
2106 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2107 didntvote = mapvote_voters;
2108 for(i = 0; i < mapvote_count; ++i)
2109 if(mapvote_maps[i] != "")
2111 didntvote -= mapvote_votes[i];
2113 if(i != secondPlace)
2115 result = strcat(result, ":", mapvote_maps[i]);
2116 result = strcat(result, ":", ftos(mapvote_votes[i]));
2117 if(i < mapvote_count_real)
2119 strunzone(mapvote_maps[i]);
2120 mapvote_maps[i] = "";
2124 result = strcat(result, ":didn't vote:", ftos(didntvote));
2125 if(cvar("sv_eventlog"))
2126 GameLogEcho(result, FALSE);
2139 keeptwo = mapvote_keeptwotime;
2140 MapVote_CheckRules_1(); // count
2141 if(MapVote_CheckRules_2()) // decide
2145 FOR_EACH_REALCLIENT(other)
2147 // hide scoreboard again
2148 if(other.health != 2342)
2150 other.health = 2342;
2152 if(clienttype(other) == CLIENTTYPE_REAL)
2154 if(cvar("g_maplist_textonly"))
2155 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");
2158 WriteByte(MSG_ONE, SVC_FINALE);
2159 WriteString(MSG_ONE, "");
2163 // notify about keep-two
2164 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2165 play2(other, "misc/invshot.wav");
2167 // clear possibly invalid votes
2168 if(mapvote_maps[other.mapvote - 1] == "")
2170 // use impulses as new vote
2171 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2172 if(mapvote_maps[other.impulse - 1] != "")
2174 other.mapvote = other.impulse;
2176 mapvote_dirty = TRUE;
2179 MapVote_TellVote(MSG_ONE, other.mapvote);
2187 MapVote_CheckRules_1(); // just count
2189 if(!cvar("g_maplist_textonly"))
2190 if(mapvote_dirty) // 1 if "keeptwo" or "impulse" happened before
2192 MapVote_UpdateData(MSG_BROADCAST);
2193 mapvote_dirty = FALSE;
2196 if(cvar("g_maplist_textonly"))
2198 FOR_EACH_REALCLIENT(other)
2200 // display voting screen
2201 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2202 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2204 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2205 msgstr = strcat(msgstr, mapvote_message);
2206 msgstr = strcat(msgstr, "\n\n");
2207 for(i = 0; i < mapvote_count; ++i)
2208 if(mapvote_maps[i] == "")
2209 msgstr = strcat(msgstr, "\n");
2212 tmp = mapvote_maps[i];
2213 tmp = strpad(mapvote_maxlen, tmp);
2214 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2217 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2218 if(mapvote_votes[i] != 1)
2219 tmp = strcat(tmp, "s");
2220 tmp = strcat(tmp, ")");
2221 tmp = strpad(mapvote_maxlen + 15, tmp);
2224 if(i == mapvote_count - 1)
2225 msgstr = strcat(msgstr, "\n");
2226 if(other.mapvote == i + 1)
2227 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2229 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2232 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2234 msgstr = strcat(msgstr, "s");
2235 msgstr = strcat(msgstr, " cast");
2236 i = ceil(mapvote_timeout - time);
2237 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2239 msgstr = strcat(msgstr, "s");
2240 msgstr = strcat(msgstr, " left");
2242 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2246 void MapVote_Start()
2252 MapInfo_Enumerate();
2253 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2257 void MapVote_Think()
2262 if(alreadychangedlevel)
2265 if(time < mapvote_nextthink)
2269 mapvote_nextthink = time + 0.5;
2271 if(!mapvote_initialized)
2273 mapvote_initialized = TRUE;
2274 if(DoNextMapOverride())
2276 if(!cvar("g_maplist_votable") || player_count <= 0)
2287 string GotoMap(string m)
2290 if(!MapInfo_CheckMap(m))
2292 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2294 return "The map you chose is not available on this server.";
2295 cvar_set("nextmap", m);
2296 cvar_set("timelimit", "-1");
2297 if(mapvote_initialized || alreadychangedlevel)
2299 if(DoNextMapOverride())
2300 return "Map switch initiated.";
2302 return "Hm... no. For some reason I like THIS map more.";
2305 return "Map switch will happen after scoreboard.";
2311 FOR_EACH_REALCLIENT(self)
2313 if(self.classname == "spectator")
2315 if(self.enemy.hitsound)
2316 play2(self, "misc/hit.wav");
2321 play2(self, "misc/hit.wav");
2324 FOR_EACH_CLIENT(self)
2325 self.hitsound = FALSE;
2331 * returns TRUE if redirecting
2333 float redirection_timeout;
2334 float redirection_nextthink;
2335 float RedirectionThink()
2337 float clients_found;
2339 if(redirection_target == "")
2342 if(!redirection_timeout)
2344 cvar_set("sv_public", "-2");
2345 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2346 if(redirection_target == "self")
2347 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2349 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2352 if(time < redirection_nextthink)
2355 redirection_nextthink = time + 1;
2358 FOR_EACH_REALCLIENT(self)
2360 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2361 if(redirection_target == "self")
2362 stuffcmd(self, "\ndisconnect; reconnect\n");
2364 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2368 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2370 if(time > redirection_timeout || clients_found == 0)
2371 localcmd("\nwait; wait; wait; quit\n");
2378 // Loaded from a save game
2379 // some things then break, so let's work around them...
2381 // Progs DB (capture records)
2383 ServerProgsDB = db_create();
2385 ServerProgsDB = db_load("server.db");
2390 MapInfo_Enumerate();
2391 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
2397 if(world_initialized)
2399 world_initialized = 0;
2400 print("Saving persistent data...\n");
2403 db_save(ServerProgsDB, "server.db");
2404 db_close(ServerProgsDB);
2406 // tell the bot system the game is ending now
2413 print("NOTE: crashed before even initializing the world, not saving persistent data\n");