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"))
143 tokenizebyseparator(cvar_string("g_maplist"), " ");
145 cvar_set("nextmap", argv(0));
148 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
150 if(!DoNextMapOverride())
159 float world_already_spawned;
160 void RegisterWeapons();
161 void spawnfunc_worldspawn (void)
166 dprint_load(); // load dprint status from cvar
168 if(world_already_spawned)
169 error("world already spawned - you may have EXACTLY ONE worldspawn!");
170 world_already_spawned = TRUE;
172 compressShortVector_init();
175 head = nextent(world);
180 head = nextent(head);
187 ServerProgsDB = db_create();
189 ServerProgsDB = db_load("server.db");
192 TODO sound pack system
193 // initialize sound pack system
194 soundpack = cvar_string("g_soundpack");
196 soundpack = strcat(soundpack, "/");
197 soundpack = strzone(soundpack);
203 // 1 FLICKER (first variety)
204 lightstyle(1, "mmnmmommommnonmmonqnmmo");
206 // 2 SLOW STRONG PULSE
207 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
209 // 3 CANDLE (first variety)
210 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
213 lightstyle(4, "mamamamamama");
216 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
218 // 6 FLICKER (second variety)
219 lightstyle(6, "nmonqnmomnmomomno");
221 // 7 CANDLE (second variety)
222 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
224 // 8 CANDLE (third variety)
225 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
227 // 9 SLOW STROBE (fourth variety)
228 lightstyle(9, "aaaaaaaazzzzzzzz");
230 // 10 FLUORESCENT FLICKER
231 lightstyle(10, "mmamammmmammamamaaamammma");
233 // 11 SLOW PULSE NOT FADE TO BLACK
234 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
236 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
243 if(cvar("g_campaign"))
250 bot_waypoints_for_items = cvar("g_waypoints_for_items");
251 if(bot_waypoints_for_items == 1)
252 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
253 bot_waypoints_for_items = 0;
255 // for setting by mapinfo
256 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
257 cvar_set("sv_q3acompat_machineshotgunswap", "0");
261 WaypointSprite_Init();
266 GameLogInit(); // prepare everything
267 if(cvar("sv_eventlog"))
269 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
270 s = strcat(s, ftos(random()));
271 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
272 s = ":gameinfo:mutators:LIST";
273 if(cvar("g_grappling_hook"))
274 s = strcat(s, ":grappling_hook");
275 if(!cvar("g_use_ammunition"))
276 s = strcat(s, ":no_use_ammunition");
277 if(!cvar("g_pickup_items"))
278 s = strcat(s, ":no_pickup_items");
279 if(cvar("g_instagib"))
280 s = strcat(s, ":instagib");
281 if(cvar("g_rocketarena"))
282 s = strcat(s, ":rockerarena");
284 s = strcat(s, ":nixnex");
285 if(cvar("g_vampire"))
286 s = strcat(s, ":vampire");
287 if(cvar("g_laserguided_missile"))
288 s = strcat(s, ":laserguided_missile");
289 if(cvar("g_norecoil"))
290 s = strcat(s, ":norecoil");
292 s = strcat(s, ":midair");
293 if(cvar("g_minstagib"))
294 s = strcat(s, ":minstagib");
296 GameLogEcho(":gameinfo:end");
299 cvar_set("nextmap", "");
303 if(cvar("g_campaign"))
310 //initialise globals related to sv_timeout
311 sys_ticrate = cvar("sys_ticrate");
312 orig_slowmo = cvar("slowmo");
315 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
317 //if tourney is used map starts in warmup mode. if this mode shall stay unlimited, reset timelimit, but save the original one
318 if(g_tourney && cvar("g_tourney_warmup_unlimited_time")) {
319 timelimit_orig = cvar("timelimit");
320 cvar_set("timelimit", "0");
323 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
325 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
328 while((s = fgets(fd)))
335 print("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
336 print(" cdtrack ", argv(2), "\n");
338 else if(argv(0) == "fog")
340 print("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
341 print(" \"fog\" \"", s, "\"\n");
343 else if(argv(0) == "set")
345 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
346 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
348 else if(argv(0) != "//")
350 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
351 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
358 addstat(STAT_SYS_TICRATE, AS_FLOAT, stat_sys_ticrate);
359 addstat(STAT_WEAPONS, AS_INT, weapons);
360 addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
362 next_pingtime = time + 5;
363 world_initialized = 1;
366 void spawnfunc_light (void)
368 //makestatic (self); // Who the f___ did that?
372 float TryFile( string pFilename )
375 dprint("TryFile(\"", pFilename, "\")\n");
376 lHandle = fopen( pFilename, FILE_READ );
377 if( lHandle != -1 ) {
387 return GametypeNameFromType(game);
390 string getmapname_stored;
396 float Map_Count, Map_Current;
397 string Map_Current_Name;
399 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
400 float GetMaplistPosition()
406 idx = cvar("g_maplist_index");
413 for(pos = 0; pos < Map_Count; ++pos)
417 // resume normal maplist rotation if current map is not in g_maplist
421 float MapHasRightSize(string map)
424 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
425 if(cvar("g_maplist_check_waypoints"))
427 dprint("checkwp "); dprint(map);
428 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
431 dprint(": no waypoints\n");
434 dprint(": has waypoints\n");
438 // open map size restriction file
439 dprint("opensize "); dprint(map);
440 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
443 float mapmin, mapmax;
445 mapmin = stof(fgets(fh));
446 mapmax = stof(fgets(fh));
448 if(player_count < mapmin)
450 dprint("not enough\n");
453 if(player_count > mapmax)
455 dprint("too many\n");
458 dprint("right size\n");
461 dprint(": not found\n");
465 string Map_Filename(float position)
467 return strcat("maps/", argv(position), ".bsp");
470 string strwords(string s, float w)
473 for(endpos = 0; w && endpos >= 0; --w)
474 endpos = strstrofs(s, " ", endpos + 1);
478 return substring(s, 0, endpos);
481 float strhasword(string s, string w)
483 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
486 void Map_MarkAsRecent(string m)
488 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
491 float Map_IsRecent(string m)
493 return strhasword(cvar_string("g_maplist_mostrecent"), m);
496 float Map_Check(float position, float pass)
500 map_next = argv(position);
503 if(map_next == Map_Current_Name) // same map again in first pass?
505 if(Map_IsRecent(map_next))
508 filename = Map_Filename(position);
509 if(MapInfo_CheckMap(map_next))
513 if(MapHasRightSize(map_next))
518 dprint( "Couldn't select '", filename, "'..\n" );
523 void Map_Goto_SetStr(string nextmapname)
525 if(getmapname_stored != "")
526 strunzone(getmapname_stored);
527 if(nextmapname == "")
528 getmapname_stored = "";
530 getmapname_stored = strzone(nextmapname);
533 void Map_Goto_SetFloat(float position)
535 cvar_set("g_maplist_index", ftos(position));
536 Map_Goto_SetStr(argv(position));
541 // settings persist, except...
542 if(cvar("g_campaign"))
543 localcmd("\nexec mutator_reset.cfg\n");
544 localcmd("\nsettemp_restore\n");
549 Map_MarkAsRecent(getmapname_stored);
551 MapInfo_LoadMap(getmapname_stored);
554 // return codes of map selectors:
555 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
556 // -2 = permanent failure
557 float() MaplistMethod_Iterate = // usual method
561 for(pass = 1; pass <= 2; ++pass)
563 for(i = 1; i < Map_Count; ++i)
566 mapindex = mod(i + Map_Current, Map_Count);
567 if(Map_Check(mapindex, pass))
574 float() MaplistMethod_Repeat = // fallback method
576 if(Map_Check(Map_Current, 2))
581 float() MaplistMethod_Random = // random map selection
587 for(i = 0; i <= imax; ++i)
590 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
591 if(Map_Check(mapindex, 1))
597 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
598 // the exponent sets a bias on the map selection:
599 // the higher the exponent, the less likely "shortly repeated" same maps are
601 float i, j, imax, insertpos;
605 for(i = 0; i <= imax; ++i)
609 // now reinsert this at another position
610 insertpos = pow(random(), 1 / exponent); // ]0, 1]
611 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
612 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
613 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
615 // insert the current map there
617 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
618 newlist = strcat(newlist, " ", argv(j));
619 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
620 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
621 newlist = strcat(newlist, " ", argv(j));
622 newlist = substring(newlist, 1, strlen(newlist) - 1);
623 cvar_set("g_maplist", newlist);
624 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
626 // NOTE: the selected map has just been inserted at (insertpos-1)th position
627 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
628 if(Map_Check(Map_Current, 1))
637 temp = cvar_string("g_maplist");
638 Map_Count = tokenizebyseparator(temp, " ");
641 bprint( "Maplist is empty! Resetting it to default map list.\n" );
642 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
643 localcmd("\nmenu_cmd sync\n");
644 Map_Count = tokenizebyseparator(temp, " ");
647 error("empty maplist, cannot select a new map");
648 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
651 strunzone(Map_Current_Name);
652 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
653 // this may or may not be correct, but who cares, in the worst case a map
654 // isn't chosen in the first pass that should have been
665 if(cvar("g_maplist_shuffle") > 0)
666 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
669 if(cvar("g_maplist_selectrandom"))
670 nextMap = MaplistMethod_Random();
673 nextMap = MaplistMethod_Iterate();
676 nextMap = MaplistMethod_Repeat();
680 Map_Goto_SetFloat(nextMap);
681 return getmapname_stored;
687 float DoNextMapOverride()
689 if(cvar("g_campaign"))
691 CampaignPostIntermission();
692 alreadychangedlevel = TRUE;
695 if(cvar("quit_when_empty"))
697 if(player_count <= currentbots)
700 alreadychangedlevel = TRUE;
704 if(cvar_string("quit_and_redirect") != "")
706 redirection_target = strzone(cvar_string("quit_and_redirect"));
707 alreadychangedlevel = TRUE;
710 if (cvar("samelevel")) // if samelevel is set, stay on same level
712 // 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)
713 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
714 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
715 localcmd("restart\n");
716 //changelevel (mapname);
717 alreadychangedlevel = TRUE;
720 if(cvar_string("nextmap") != "")
721 if(MapInfo_CheckMap(cvar_string("nextmap")))
723 Map_Goto_SetStr(cvar_string("nextmap"));
725 alreadychangedlevel = TRUE;
728 if(cvar("lastlevel"))
731 localcmd("set lastlevel 0\ntogglemenu\n");
732 alreadychangedlevel = TRUE;
740 //local string nextmap;
741 //local float n, nummaps;
743 if (alreadychangedlevel)
745 alreadychangedlevel = TRUE;
751 for(allowReset = 1; allowReset >= 0; --allowReset)
753 nextMap = GetNextMap();
759 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
760 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
761 localcmd("\nmenu_cmd sync\n");
765 error("Everything is broken - not even the default map list works. Please report this to the developers.");
777 When the player presses attack or jump, change to the next level
780 .float autoscreenshot;
781 void() MapVote_Start;
782 void() MapVote_Think;
783 float mapvote_initialized;
784 void IntermissionThink()
786 FixIntermissionClient(self);
788 if(cvar("sv_autoscreenshot"))
789 if(self.autoscreenshot > 0)
790 if(time > self.autoscreenshot)
792 self.autoscreenshot = -1;
793 if(clienttype(self) == CLIENTTYPE_REAL)
794 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
798 if (time < intermission_exittime)
801 if(!mapvote_initialized)
802 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
812 Returns the entity to view from
816 entity FindIntermission()
821 // look for info_intermission first
822 spot = find (world, classname, "info_intermission");
824 { // pick a random one
828 spot = find (spot, classname, "info_intermission");
830 spot = find (spot, classname, "info_intermission");
836 // then look for the start position
837 spot = find (world, classname, "info_player_start");
841 // testinfo_player_start is only found in regioned levels
842 spot = find (world, classname, "testplayerstart");
846 // then look for the start position
847 spot = find (world, classname, "info_player_deathmatch");
851 //objerror ("FindIntermission: no spot");
857 ===============================================================================
861 ===============================================================================
864 void DumpStats(float final)
868 local float to_console;
869 local float to_eventlog;
873 to_console = cvar("sv_logscores_console");
874 to_eventlog = cvar("sv_eventlog");
875 to_file = cvar("sv_logscores_file");
879 to_console = TRUE; // always print printstats replies
880 to_eventlog = FALSE; // but never print them to the event log
884 if(cvar("sv_eventlog_console"))
885 to_console = FALSE; // otherwise we get the output twice
891 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
899 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
903 fputs(file, strcat(s, "\n"));
906 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
911 fputs(file, strcat(s, "\n"));
913 FOR_EACH_CLIENT(other)
915 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
917 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
918 s = strcat(s, ftos(rint(time - other.jointime)), ":");
919 if(other.classname == "player" || g_arena || g_lms)
920 s = strcat(s, ftos(other.team), ":");
922 s = strcat(s, "spectator:");
925 print(s, other.netname, "\n");
927 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
929 fputs(file, strcat(s, other.netname, "\n"));
935 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
941 fputs(file, strcat(s, "\n"));
943 for(i = 1; i < 16; ++i)
945 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
946 s = strcat(s, ":", ftos(i));
952 fputs(file, strcat(s, "\n"));
962 fputs(file, ":end\n");
967 void FixIntermissionClient(entity e)
970 if(!e.autoscreenshot) // initial call
972 e.angles = e.v_angle;
973 e.angles_x = -e.angles_x;
974 e.autoscreenshot = time + 0.8; // used for autoscreenshot
976 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
978 e.movetype = MOVETYPE_NONE;
979 e.takedamage = DAMAGE_NO;
981 e.weaponentity.effects = EF_NODRAW;
982 if(clienttype(e) == CLIENTTYPE_REAL)
984 stuffcmd(e, "\nscr_printspeed 1000000\n");
985 s = cvar_string("sv_intermission_cdtrack");
987 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
989 WriteByte(MSG_ONE, SVC_INTERMISSION);
993 //e.velocity = '0 0 0';
996 // TODO halt weapon animation
1001 go to the next level for deathmatch
1002 only called if a time or frag limit has expired
1006 float minTotalFrags;
1007 float maxTotalFrags;
1013 intermission_running = 1;
1015 // enforce a wait time before allowing changelevel
1016 if(player_count > 0)
1017 intermission_exittime = time + cvar("sv_mapchange_delay");
1019 intermission_exittime = -1;
1022 WriteByte (MSG_ALL, SVC_CDTRACK);
1023 WriteByte (MSG_ALL, 3);
1024 WriteByte (MSG_ALL, 3);
1025 // done in FixIntermission
1028 //pos = FindIntermission ();
1034 if(cvar("sv_eventlog"))
1035 GameLogEcho(":gameover");
1039 FOR_EACH_CLIENT(other)
1041 FixIntermissionClient(other);
1044 bprint(other.netname, " ^7wins.\n");
1049 FOR_EACH_PLAYER(other)
1051 if(maxTotalFrags < other.totalfrags)
1052 maxTotalFrags = other.totalfrags;
1053 if(minTotalFrags > other.totalfrags)
1054 minTotalFrags = other.totalfrags;
1059 FOR_EACH_PLAYER(other)
1061 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1062 f = bound(0, other.play_time / max(time, 1), 1);
1063 // store some statistics?
1067 if(cvar("g_campaign"))
1068 CampaignPreIntermission();
1070 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1077 Exit deathmatch games upon conditions
1081 void CheckRules_Player()
1083 if (gameover) // someone else quit the game already
1086 if(self.deadflag == DEAD_NO)
1087 self.play_time += frametime;
1091 if(time > self.fogtime)
1093 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1094 self.fogtime = time + sv_foginterval;
1097 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1098 // (div0: and that in CheckRules_World please)
1101 float checkrules_oneminutewarning;
1103 float checkrules_equality;
1104 float checkrules_overtimewarning;
1105 float checkrules_overtimeend;
1107 void InitiateOvertime()
1109 if(!checkrules_overtimeend)
1110 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1113 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1114 float WINNING_YES = 1; // winner found
1115 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1116 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1118 float GetWinningCode(float fraglimitreached, float equality)
1121 if(fraglimitreached)
1122 return WINNING_STARTOVERTIME;
1124 return WINNING_NEVER;
1126 if(fraglimitreached)
1132 // set the .winning flag for exactly those players with a given field value
1133 void SetWinners(.float field, float value)
1136 FOR_EACH_PLAYER(head)
1137 head.winning = (head.field == value);
1140 // set the .winning flag for those players with a given field value
1141 void AddWinners(.float field, float value)
1144 FOR_EACH_PLAYER(head)
1145 if(head.field == value)
1149 // clear the .winning flags
1150 void ClearWinners(void)
1153 FOR_EACH_PLAYER(head)
1157 // Onslaught winning condition:
1158 // game terminates if only one team has a working generator (or none)
1159 float WinningCondition_Onslaught()
1162 local float t1, t2, t3, t4;
1163 // first check if the game has ended
1164 t1 = t2 = t3 = t4 = 0;
1165 head = find(world, classname, "onslaught_generator");
1168 if (head.health > 0)
1170 if (head.team == COLOR_TEAM1) t1 = 1;
1171 if (head.team == COLOR_TEAM2) t2 = 1;
1172 if (head.team == COLOR_TEAM3) t3 = 1;
1173 if (head.team == COLOR_TEAM4) t4 = 1;
1175 head = find(head, classname, "onslaught_generator");
1177 if (t1 + t2 + t3 + t4 < 2)
1179 // game over, only one team remains (or none)
1181 if (t1) SetWinners(team, COLOR_TEAM1);
1182 if (t2) SetWinners(team, COLOR_TEAM2);
1183 if (t3) SetWinners(team, COLOR_TEAM3);
1184 if (t4) SetWinners(team, COLOR_TEAM4);
1185 dprint("Have a winner, ending game.\n");
1189 // Two or more teams remain
1193 float LMS_NewPlayerLives()
1196 fl = cvar("fraglimit");
1200 // first player has left the game for dying too much? Nobody else can get in.
1201 if(lms_lowest_lives < 1)
1204 if(!cvar("g_lms_join_anytime"))
1205 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1208 return bound(1, lms_lowest_lives, fl);
1211 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1212 // they win. Otherwise the defending team wins once the timelimit passes.
1213 void assault_new_round();
1214 float WinningCondition_Assault()
1217 status = WINNING_NO;
1219 // as the timelimit has not yet passed just assume the defending team will win
1220 if(assault_attacker_team == COLOR_TEAM1)
1222 SetWinners(team, COLOR_TEAM2);
1226 SetWinners(team, COLOR_TEAM1);
1230 ent = find(world, classname, "target_assault_roundend");
1233 if(ent.winning) // round end has been triggered by attacking team
1235 SetWinners(team, assault_attacker_team);
1236 if(assault_attacker_team == COLOR_TEAM1)
1238 team1_score = team1_score + 50;
1242 team2_score = team2_score + 50;
1245 if(ent.cnt == 1) // this was the second round
1247 status = WINNING_YES;
1251 local entity oldself;
1254 cvar_set("timelimit", ftos((2*time)/60));
1255 assault_new_round();
1265 // LMS winning condition: game terminates if and only if there's at most one
1266 // one player who's living lives. Top two scores being equal cancels the time
1268 float WinningCondition_LMS()
1275 have_player = FALSE;
1276 have_players = FALSE;
1277 l = LMS_NewPlayerLives();
1279 head = find(world, classname, "player");
1282 head2 = find(head, classname, "player");
1284 have_players = TRUE;
1288 // we have at least one player
1291 // two or more active players - continue with the game
1295 // exactly one player?
1298 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1302 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1308 // and assign him his first place
1309 PlayerScore_Add(head, SP_LMS_RANK, 1);
1316 // nobody is playing at all...
1319 // wait for players...
1323 // SNAFU (maybe a draw game?)
1325 dprint("No players, ending game.\n");
1330 // When we get here, we have at least two players who are actually LIVING,
1331 // now check if the top two players have equal score.
1332 WinningConditionHelper();
1335 if(WinningConditionHelper_winner)
1336 WinningConditionHelper_winner.winning = TRUE;
1337 if(WinningConditionHelper_equality)
1338 return WINNING_NEVER;
1340 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1344 void print_to(entity e, string s)
1347 sprint(e, strcat(s, "\n"));
1352 void ShuffleMaplist()
1360 result = cvar_string("g_maplist");
1361 litems = tokenizebyseparator(result, " ");
1363 for(start = 0; start < litems - 1; ++start)
1367 // select a random item
1368 selected = ceil(random() * (litems - start) + start) - 1;
1370 // shift this item to the place start
1371 for(i = 0; i < start; ++i)
1372 result = strcat(result, " ", argv(i));
1373 result = strcat(result, " ", argv(selected));
1374 for(i = start; i < litems; ++i)
1376 result = strcat(result, " ", argv(i));
1377 result = substring(result, 1, strlen(result) - 1);
1379 litems = tokenizebyseparator(result, " ");
1381 //dprint(result, "\n");
1384 cvar_set("g_maplist", result);
1387 float WinningCondition_Scores(float limit)
1389 // TODO make everything use THIS winning condition (except LMS)
1390 WinningConditionHelper();
1394 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1395 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1396 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1397 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1401 if(WinningConditionHelper_winner)
1402 WinningConditionHelper_winner.winning = 1;
1403 if(WinningConditionHelper_winnerteam >= 0)
1404 SetWinners(team, WinningConditionHelper_winnerteam);
1406 if(WinningConditionHelper_topscore == 0)
1407 WinningConditionHelper_equality = 0;
1409 if(WinningConditionHelper_lowerisbetter)
1411 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1415 return GetWinningCode(limit && WinningConditionHelper_topscore && (WinningConditionHelper_topscore >= limit), WinningConditionHelper_equality);
1418 float WinningCondition_Race(float fraglimit)
1422 wc = WinningCondition_Scores(fraglimit);
1424 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1425 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1426 // do NOT support equality when the laps are all raced!
1429 if not(p.race_completed)
1430 return WINNING_STARTOVERTIME;
1436 void ReadyRestart();
1437 float WinningCondition_QualifyingThenRace(float limit)
1440 wc = WinningCondition_Scores(limit);
1442 // NEVER initiate overtime
1443 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1444 // do NOT support equality when the laps are all raced!
1447 float playerswithlaps;
1449 totalplayers = playerswithlaps = 0;
1450 FOR_EACH_PLAYER(head)
1453 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
1457 // at least 2/3 of the players have completed a lap: start the RACE
1458 // otherwise, the players should end the qualifying on their own
1459 if(totalplayers >= 3)
1460 if(playerswithlaps >= totalplayers * 2 / 3)
1462 checkrules_overtimeend = 0;
1464 return WINNING_NEVER;
1473 float WinningCondition_RanOutOfSpawns()
1477 if(!have_team_spawns)
1480 if(!some_spawn_has_been_used)
1483 team1_score = team2_score = team3_score = team4_score = 0;
1485 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1487 if(head.team == COLOR_TEAM1)
1489 else if(head.team == COLOR_TEAM2)
1491 else if(head.team == COLOR_TEAM3)
1493 else if(head.team == COLOR_TEAM4)
1497 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1499 if(head.team == COLOR_TEAM1)
1501 else if(head.team == COLOR_TEAM2)
1503 else if(head.team == COLOR_TEAM3)
1505 else if(head.team == COLOR_TEAM4)
1510 if(team1_score + team2_score + team3_score + team4_score == 0)
1512 checkrules_equality = TRUE;
1515 else if(team1_score + team2_score + team3_score + team4_score == 1)
1518 if(team1_score) t = COLOR_TEAM1;
1519 if(team2_score) t = COLOR_TEAM2;
1520 if(team3_score) t = COLOR_TEAM3;
1521 if(team4_score) t = COLOR_TEAM4;
1522 CheckAllowedTeams(world);
1523 for(i = 0; i < MAX_TEAMSCORE; ++i)
1525 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
1526 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
1527 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
1528 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
1531 AddWinners(team, t);
1542 Exit deathmatch games upon conditions
1545 void CheckRules_World()
1548 local float timelimit;
1549 local float fraglimit;
1557 MapVote_Think should now do that part
1558 if (intermission_running)
1559 if (time >= intermission_exittime + 60)
1561 if(!DoNextMapOverride())
1567 if (gameover) // someone else quit the game already
1569 if(player_count == 0) // Nobody there? Then let's go to the next map
1571 // this will actually check the player count in the next frame
1572 // again, but this shouldn't hurt
1576 timelimit = cvar("timelimit") * 60;
1577 fraglimit = cvar("fraglimit");
1579 if(checkrules_overtimeend)
1581 if(!checkrules_overtimewarning)
1583 checkrules_overtimewarning = TRUE;
1584 //announceall("announcer/robotic/1minuteremains.wav");
1585 if(!g_race_qualifying)
1586 bcenterprint("^3Everyone, finish your lap! The race is over!");
1588 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1593 if (timelimit && time >= timelimit)
1597 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1603 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1605 checkrules_oneminutewarning = TRUE;
1606 play2all("announcer/robotic/1minuteremains.wav");
1609 status = WinningCondition_RanOutOfSpawns();
1610 if(status == WINNING_YES)
1612 bprint("Hey! Someone ran out of spawns!\n");
1614 else if(g_race && !g_race_qualifying && timelimit >= 0)
1616 status = WinningCondition_Race(fraglimit);
1618 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
1620 status = WinningCondition_QualifyingThenRace(fraglimit);
1624 status = WinningCondition_Assault(); // TODO remove this?
1628 status = WinningCondition_LMS();
1630 else if (g_onslaught)
1632 status = WinningCondition_Onslaught(); // TODO remove this?
1636 status = WinningCondition_Scores(fraglimit);
1639 if(status == WINNING_STARTOVERTIME)
1641 status = WINNING_NEVER;
1645 if(status == WINNING_NEVER)
1646 // equality cases! Nobody wins if the overtime ends in a draw.
1649 if(checkrules_overtimeend)
1650 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1651 status = WINNING_YES;
1653 if(status == WINNING_YES)
1657 float mapvote_nextthink;
1658 float mapvote_initialized;
1659 float mapvote_keeptwotime;
1660 float mapvote_timeout;
1661 string mapvote_message;
1662 string mapvote_screenshot_dir;
1664 float mapvote_count;
1665 float mapvote_count_real;
1666 string mapvote_maps[MAPVOTE_COUNT];
1667 float mapvote_maps_suggested[MAPVOTE_COUNT];
1668 string mapvote_suggestions[MAPVOTE_COUNT];
1669 float mapvote_suggestion_ptr;
1670 float mapvote_maxlen;
1671 float mapvote_voters;
1672 float mapvote_votes[MAPVOTE_COUNT];
1674 float mapvote_detail;
1675 float mapvote_abstain;
1676 float mapvote_dirty;
1679 void MapVote_ClearAllVotes()
1681 FOR_EACH_CLIENT(other)
1685 string MapVote_Suggest(string m)
1689 return "That's not how to use this command.";
1690 if(!cvar("g_maplist_votable_suggestions"))
1691 return "Suggestions are not accepted on this server.";
1692 if(mapvote_initialized)
1693 return "Can't suggest - voting is already in progress!";
1694 m = MapInfo_FixName(m);
1696 return "The map you suggested is not available on this server.";
1697 if(!cvar("g_maplist_votable_override_mostrecent"))
1699 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1701 if(!MapInfo_CheckMap(m))
1702 return "The map you suggested does not support the current game mode.";
1703 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1704 if(mapvote_suggestions[i] == m)
1705 return "This map was already suggested.";
1706 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1708 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1712 i = mapvote_suggestion_ptr;
1713 mapvote_suggestion_ptr += 1;
1715 if(mapvote_suggestions[i] != "")
1716 strunzone(mapvote_suggestions[i]);
1717 mapvote_suggestions[i] = strzone(m);
1718 if(cvar("sv_eventlog"))
1719 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
1720 return strcat("Suggestion of ", m, " accepted.");
1723 void MapVote_AddVotable(string nextMap, float isSuggestion)
1728 for(j = 0; j < mapvote_count; ++j)
1729 if(mapvote_maps[j] == nextMap)
1731 if(strlen(nextMap) > mapvote_maxlen)
1732 mapvote_maxlen = strlen(nextMap);
1733 mapvote_maps[mapvote_count] = strzone(nextMap);
1734 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1738 void MapVote_SendData(float target);
1744 MapVote_ClearAllVotes();
1747 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1748 mapvote_abstain = cvar("g_maplist_votable_abstain");
1751 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1753 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1754 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
1756 if(mapvote_suggestion_ptr)
1757 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1758 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1760 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1761 MapVote_AddVotable(GetNextMap(), FALSE);
1763 if(mapvote_count == 0)
1765 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1766 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1767 localcmd("\nmenu_cmd sync\n");
1768 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1769 MapVote_AddVotable(GetNextMap(), FALSE);
1772 mapvote_count_real = mapvote_count;
1774 MapVote_AddVotable("don't care", 0);
1776 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1778 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1779 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1780 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1781 mapvote_keeptwotime = 0;
1782 mapvote_message = "Choose a map and press its key!";
1784 mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
1785 if(mapvote_screenshot_dir == "")
1786 mapvote_screenshot_dir = "maps";
1787 mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
1789 if(!cvar("g_maplist_textonly"))
1790 MapVote_SendData(MSG_ALL);
1793 void MapVote_SendPicture(float id)
1796 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1797 WriteByte(MSG_ONE, TE_CSQC_MAPVOTE);
1798 WriteByte(MSG_ONE, MAPVOTE_NET_PIC);
1799 WriteByte(MSG_ONE, id);
1800 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 3072);
1803 float GameCommand_MapVote(string cmd)
1805 if(!intermission_running)
1807 if(!cvar("g_maplist_textonly"))
1809 if(cmd == "mv_getpic")
1811 MapVote_SendPicture(stof(argv(1)));
1819 float MapVote_GetMapMask()
1821 float mask, i, power;
1823 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
1824 if(mapvote_maps[i] != "")
1829 void MapVote_SendData(float targ)
1831 string mapfile, pakfile;
1833 WriteByte(targ, SVC_TEMPENTITY);
1834 WriteByte(targ, TE_CSQC_CONFIG);
1835 WriteString(targ, "mv_screenshot_dir");
1836 WriteString(targ, mapvote_screenshot_dir);
1838 WriteByte(targ, SVC_TEMPENTITY);
1839 WriteByte(targ, TE_CSQC_MAPVOTE);
1840 WriteByte(targ, MAPVOTE_NET_INIT);
1842 WriteByte(targ, mapvote_count);
1843 WriteByte(targ, mapvote_abstain);
1844 WriteByte(targ, mapvote_detail);
1845 WriteCoord(targ, mapvote_timeout);
1846 if(mapvote_count <= 8)
1847 WriteByte(targ, MapVote_GetMapMask());
1849 WriteShort(targ, MapVote_GetMapMask());
1850 for(i = 0; i < mapvote_count; ++i)
1851 if(mapvote_maps[i] != "")
1853 WriteString(targ, mapvote_maps[i]);
1854 mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
1855 pakfile = whichpack(strcat(mapfile, ".tga"));
1857 pakfile = whichpack(strcat(mapfile, ".jpg"));
1859 pakfile = whichpack(strcat(mapfile, ".png"));
1860 print("pakfile is ", pakfile, "\n");
1861 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
1862 pakfile = substring(pakfile, o, 999);
1863 WriteString(targ, pakfile);
1867 void MapVote_UpdateData(float targ)
1870 WriteByte(targ, SVC_TEMPENTITY);
1871 WriteByte(targ, TE_CSQC_MAPVOTE);
1872 WriteByte(targ, MAPVOTE_NET_UPDATE);
1873 if(mapvote_count <= 8)
1874 WriteByte(targ, MapVote_GetMapMask());
1876 WriteShort(targ, MapVote_GetMapMask());
1878 for(i = 0; i < mapvote_count; ++i)
1879 if(mapvote_maps[i] != "")
1880 WriteByte(targ, mapvote_votes[i]);
1883 void MapVote_TellVote(float targ, float vote)
1885 WriteByte(targ, SVC_TEMPENTITY);
1886 WriteByte(targ, TE_CSQC_MAPVOTE);
1887 WriteByte(targ, MAPVOTE_NET_OWNVOTE);
1888 WriteByte(targ, vote);
1891 float MapVote_Finished(float mappos)
1897 if(cvar("sv_eventlog"))
1899 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1900 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1901 didntvote = mapvote_voters;
1902 for(i = 0; i < mapvote_count; ++i)
1903 if(mapvote_maps[i] != "")
1905 didntvote -= mapvote_votes[i];
1908 result = strcat(result, ":", mapvote_maps[i]);
1909 result = strcat(result, ":", ftos(mapvote_votes[i]));
1912 result = strcat(result, ":didn't vote:", ftos(didntvote));
1914 GameLogEcho(result);
1915 if(mapvote_maps_suggested[mappos])
1916 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
1919 FOR_EACH_REALCLIENT(other)
1920 FixClientCvars(other);
1922 Map_Goto_SetStr(mapvote_maps[mappos]);
1924 alreadychangedlevel = TRUE;
1927 void MapVote_CheckRules_1()
1931 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1933 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1934 mapvote_votes[i] = 0;
1938 FOR_EACH_REALCLIENT(other)
1943 i = other.mapvote - 1;
1944 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1945 mapvote_votes[i] = mapvote_votes[i] + 1;
1950 float MapVote_CheckRules_2()
1953 float firstPlace, secondPlace;
1954 float firstPlaceVotes, secondPlaceVotes;
1955 float mapvote_voters_real;
1958 mapvote_voters_real = mapvote_voters;
1960 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
1962 RandomSelection_Init();
1963 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1964 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
1965 firstPlace = RandomSelection_chosen_float;
1966 firstPlaceVotes = RandomSelection_best_priority;
1967 //dprint("First place: ", ftos(firstPlace), "\n");
1968 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1970 RandomSelection_Init();
1971 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1973 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
1974 secondPlace = RandomSelection_chosen_float;
1975 secondPlaceVotes = RandomSelection_best_priority;
1976 //dprint("Second place: ", ftos(secondPlace), "\n");
1977 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1979 if(firstPlace == -1)
1980 error("No first place in map vote... WTF?");
1982 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
1983 return MapVote_Finished(firstPlace);
1985 if(mapvote_keeptwotime)
1986 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
1989 mapvote_dirty = TRUE;
1990 mapvote_message = "Now decide between the TOP TWO!";
1991 mapvote_keeptwotime = 0;
1992 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
1993 result = strcat(result, ":", ftos(firstPlaceVotes));
1994 result = strcat(result, ":", mapvote_maps[secondPlace]);
1995 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
1996 didntvote = mapvote_voters;
1997 for(i = 0; i < mapvote_count; ++i)
1998 if(mapvote_maps[i] != "")
2000 didntvote -= mapvote_votes[i];
2002 if(i != secondPlace)
2004 result = strcat(result, ":", mapvote_maps[i]);
2005 result = strcat(result, ":", ftos(mapvote_votes[i]));
2006 if(i < mapvote_count_real)
2008 strunzone(mapvote_maps[i]);
2009 mapvote_maps[i] = "";
2013 result = strcat(result, ":didn't vote:", ftos(didntvote));
2014 if(cvar("sv_eventlog"))
2015 GameLogEcho(result);
2028 keeptwo = mapvote_keeptwotime;
2029 MapVote_CheckRules_1(); // count
2030 if(MapVote_CheckRules_2()) // decide
2034 FOR_EACH_REALCLIENT(other)
2036 // hide scoreboard again
2037 if(other.health != 2342)
2039 other.health = 2342;
2041 if(clienttype(other) == CLIENTTYPE_REAL)
2043 if(cvar("g_maplist_textonly"))
2044 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");
2047 WriteByte(MSG_ONE, SVC_FINALE);
2048 WriteString(MSG_ONE, "");
2052 // notify about keep-two
2053 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2054 play2(other, "misc/invshot.wav");
2056 // clear possibly invalid votes
2057 if(mapvote_maps[other.mapvote - 1] == "")
2059 // use impulses as new vote
2060 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2061 if(mapvote_maps[other.impulse - 1] != "")
2063 other.mapvote = other.impulse;
2065 mapvote_dirty = TRUE;
2068 MapVote_TellVote(MSG_ONE, other.mapvote);
2076 MapVote_CheckRules_1(); // just count
2078 if(!cvar("g_maplist_textonly"))
2079 if(mapvote_dirty) // 1 if "keeptwo" or "impulse" happened before
2081 MapVote_UpdateData(MSG_BROADCAST);
2082 mapvote_dirty = FALSE;
2085 if(cvar("g_maplist_textonly"))
2087 FOR_EACH_REALCLIENT(other)
2089 // display voting screen
2090 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2091 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2093 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2094 msgstr = strcat(msgstr, mapvote_message);
2095 msgstr = strcat(msgstr, "\n\n");
2096 for(i = 0; i < mapvote_count; ++i)
2097 if(mapvote_maps[i] == "")
2098 msgstr = strcat(msgstr, "\n");
2101 tmp = mapvote_maps[i];
2102 tmp = strpad(mapvote_maxlen, tmp);
2103 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2106 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2107 if(mapvote_votes[i] != 1)
2108 tmp = strcat(tmp, "s");
2109 tmp = strcat(tmp, ")");
2110 tmp = strpad(mapvote_maxlen + 15, tmp);
2113 if(i == mapvote_count - 1)
2114 msgstr = strcat(msgstr, "\n");
2115 if(other.mapvote == i + 1)
2116 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2118 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2121 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2123 msgstr = strcat(msgstr, "s");
2124 msgstr = strcat(msgstr, " cast");
2125 i = ceil(mapvote_timeout - time);
2126 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2128 msgstr = strcat(msgstr, "s");
2129 msgstr = strcat(msgstr, " left");
2131 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2135 void MapVote_Start()
2140 MapInfo_Enumerate();
2141 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2144 void MapVote_Think()
2149 if(alreadychangedlevel)
2152 if(time < mapvote_nextthink)
2156 mapvote_nextthink = time + 0.5;
2158 if(!mapvote_initialized)
2160 mapvote_initialized = TRUE;
2161 if(DoNextMapOverride())
2163 if(!cvar("g_maplist_votable") || player_count <= 0)
2174 string GotoMap(string m)
2176 if(!MapInfo_CheckMap(m))
2177 return "The map you chose is not available on this server.";
2178 cvar_set("nextmap", m);
2179 cvar_set("timelimit", "-1");
2180 if(mapvote_initialized || alreadychangedlevel)
2182 if(DoNextMapOverride())
2183 return "Map switch initiated.";
2185 return "Hm... no. For some reason I like THIS map more.";
2188 return "Map switch will happen after scoreboard.";
2194 FOR_EACH_REALCLIENT(self)
2196 if(self.classname == "spectator")
2198 if(self.enemy.hitsound)
2199 play2(self, "misc/hit.wav");
2204 play2(self, "misc/hit.wav");
2207 FOR_EACH_CLIENT(self)
2208 self.hitsound = FALSE;
2214 * returns TRUE if redirecting
2216 float redirection_timeout;
2217 float redirection_nextthink;
2218 float RedirectionThink()
2220 float clients_found;
2222 if(redirection_target == "")
2225 if(!redirection_timeout)
2227 cvar_set("sv_public", "-2");
2228 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2229 if(redirection_target == "self")
2230 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2232 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2235 if(time < redirection_nextthink)
2238 redirection_nextthink = time + 1;
2241 FOR_EACH_REALCLIENT(self)
2243 print("Redirecting: sending connect command to ", self.netname, "\n");
2244 if(redirection_target == "self")
2245 stuffcmd(self, "\ndisconnect; reconnect\n");
2247 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2251 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2253 if(time > redirection_timeout || clients_found == 0)
2254 localcmd("\nwait; wait; wait; quit\n");
2261 // Loaded from a save game
2262 // some things then break, so let's work around them...
2264 // Progs DB (capture records)
2266 ServerProgsDB = db_create();
2268 ServerProgsDB = db_load("server.db");
2272 MapInfo_Enumerate();
2273 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
2278 if(world_initialized)
2280 world_initialized = 0;
2281 print("Saving persistent data...\n");
2284 db_save(ServerProgsDB, "server.db");
2285 db_close(ServerProgsDB);
2287 // tell the bot system the game is ending now
2294 print("NOTE: crashed before even initializing the world, not saving persistent data\n");