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);
183 // needs to be done so early as they would still spawn
190 ServerProgsDB = db_create();
192 ServerProgsDB = db_load("server.db");
195 TODO sound pack system
196 // initialize sound pack system
197 soundpack = cvar_string("g_soundpack");
199 soundpack = strcat(soundpack, "/");
200 soundpack = strzone(soundpack);
206 // 1 FLICKER (first variety)
207 lightstyle(1, "mmnmmommommnonmmonqnmmo");
209 // 2 SLOW STRONG PULSE
210 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
212 // 3 CANDLE (first variety)
213 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
216 lightstyle(4, "mamamamamama");
219 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
221 // 6 FLICKER (second variety)
222 lightstyle(6, "nmonqnmomnmomomno");
224 // 7 CANDLE (second variety)
225 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
227 // 8 CANDLE (third variety)
228 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
230 // 9 SLOW STROBE (fourth variety)
231 lightstyle(9, "aaaaaaaazzzzzzzz");
233 // 10 FLUORESCENT FLICKER
234 lightstyle(10, "mmamammmmammamamaaamammma");
236 // 11 SLOW PULSE NOT FADE TO BLACK
237 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
239 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
244 if(cvar("g_campaign"))
251 bot_waypoints_for_items = cvar("g_waypoints_for_items");
252 if(bot_waypoints_for_items == 1)
253 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
254 bot_waypoints_for_items = 0;
256 // for setting by mapinfo
257 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
258 cvar_set("sv_q3acompat_machineshotgunswap", "0");
262 WaypointSprite_Init();
267 GameLogInit(); // prepare everything
268 if(cvar("sv_eventlog"))
270 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
271 s = strcat(s, ftos(random()));
272 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
273 s = ":gameinfo:mutators:LIST";
274 if(cvar("g_grappling_hook"))
275 s = strcat(s, ":grappling_hook");
276 if(!cvar("g_use_ammunition"))
277 s = strcat(s, ":no_use_ammunition");
278 if(!cvar("g_pickup_items"))
279 s = strcat(s, ":no_pickup_items");
280 if(cvar("g_instagib"))
281 s = strcat(s, ":instagib");
282 if(cvar("g_rocketarena"))
283 s = strcat(s, ":rockerarena");
285 s = strcat(s, ":nixnex");
286 if(cvar("g_vampire"))
287 s = strcat(s, ":vampire");
288 if(cvar("g_laserguided_missile"))
289 s = strcat(s, ":laserguided_missile");
290 if(cvar("g_norecoil"))
291 s = strcat(s, ":norecoil");
293 s = strcat(s, ":midair");
294 if(cvar("g_minstagib"))
295 s = strcat(s, ":minstagib");
297 GameLogEcho(":gameinfo:end");
300 cvar_set("nextmap", "");
304 if(cvar("g_campaign"))
311 //initialise globals related to sv_timeout
312 sys_ticrate = cvar("sys_ticrate");
313 orig_slowmo = cvar("slowmo");
316 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
318 //if tourney is used map starts in warmup mode. if this mode shall stay unlimited, reset timelimit, but save the original one
320 timelimit_orig = cvar("timelimit");
321 cvar_set("timelimit", "0");
324 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
326 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
329 while((s = fgets(fd)))
336 print("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
337 print(" cdtrack ", argv(2), "\n");
339 else if(argv(0) == "fog")
341 print("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
342 print(" \"fog\" \"", s, "\"\n");
344 else if(argv(0) == "set")
346 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
347 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
349 else if(argv(0) != "//")
351 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
352 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
359 addstat(STAT_SYS_TICRATE, AS_FLOAT, stat_sys_ticrate);
360 addstat(STAT_WEAPONS, AS_INT, weapons);
361 addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
363 next_pingtime = time + 5;
364 world_initialized = 1;
367 void spawnfunc_light (void)
369 //makestatic (self); // Who the f___ did that?
373 float TryFile( string pFilename )
376 dprint("TryFile(\"", pFilename, "\")\n");
377 lHandle = fopen( pFilename, FILE_READ );
378 if( lHandle != -1 ) {
388 return GametypeNameFromType(game);
391 string getmapname_stored;
397 float Map_Count, Map_Current;
398 string Map_Current_Name;
400 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
401 float GetMaplistPosition()
407 idx = cvar("g_maplist_index");
414 for(pos = 0; pos < Map_Count; ++pos)
418 // resume normal maplist rotation if current map is not in g_maplist
422 float MapHasRightSize(string map)
425 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
426 if(cvar("g_maplist_check_waypoints"))
428 dprint("checkwp "); dprint(map);
429 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
432 dprint(": no waypoints\n");
435 dprint(": has waypoints\n");
439 // open map size restriction file
440 dprint("opensize "); dprint(map);
441 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
444 float mapmin, mapmax;
446 mapmin = stof(fgets(fh));
447 mapmax = stof(fgets(fh));
449 if(player_count < mapmin)
451 dprint("not enough\n");
454 if(player_count > mapmax)
456 dprint("too many\n");
459 dprint("right size\n");
462 dprint(": not found\n");
466 string Map_Filename(float position)
468 return strcat("maps/", argv(position), ".bsp");
471 string strwords(string s, float w)
474 for(endpos = 0; w && endpos >= 0; --w)
475 endpos = strstrofs(s, " ", endpos + 1);
479 return substring(s, 0, endpos);
482 float strhasword(string s, string w)
484 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
487 void Map_MarkAsRecent(string m)
489 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
492 float Map_IsRecent(string m)
494 return strhasword(cvar_string("g_maplist_mostrecent"), m);
497 float Map_Check(float position, float pass)
501 map_next = argv(position);
504 if(map_next == Map_Current_Name) // same map again in first pass?
506 if(Map_IsRecent(map_next))
509 filename = Map_Filename(position);
510 if(MapInfo_CheckMap(map_next))
514 if(MapHasRightSize(map_next))
519 dprint( "Couldn't select '", filename, "'..\n" );
524 void Map_Goto_SetStr(string nextmapname)
526 if(getmapname_stored != "")
527 strunzone(getmapname_stored);
528 if(nextmapname == "")
529 getmapname_stored = "";
531 getmapname_stored = strzone(nextmapname);
534 void Map_Goto_SetFloat(float position)
536 cvar_set("g_maplist_index", ftos(position));
537 Map_Goto_SetStr(argv(position));
542 // settings persist, except...
543 if(cvar("g_campaign"))
544 localcmd("\nexec mutator_reset.cfg\n");
545 localcmd("\nsettemp_restore\n");
550 Map_MarkAsRecent(getmapname_stored);
552 MapInfo_LoadMap(getmapname_stored);
555 // return codes of map selectors:
556 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
557 // -2 = permanent failure
558 float() MaplistMethod_Iterate = // usual method
562 for(pass = 1; pass <= 2; ++pass)
564 for(i = 1; i < Map_Count; ++i)
567 mapindex = mod(i + Map_Current, Map_Count);
568 if(Map_Check(mapindex, pass))
575 float() MaplistMethod_Repeat = // fallback method
577 if(Map_Check(Map_Current, 2))
582 float() MaplistMethod_Random = // random map selection
588 for(i = 0; i <= imax; ++i)
591 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
592 if(Map_Check(mapindex, 1))
598 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
599 // the exponent sets a bias on the map selection:
600 // the higher the exponent, the less likely "shortly repeated" same maps are
602 float i, j, imax, insertpos;
606 for(i = 0; i <= imax; ++i)
610 // now reinsert this at another position
611 insertpos = pow(random(), 1 / exponent); // ]0, 1]
612 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
613 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
614 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
616 // insert the current map there
618 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
619 newlist = strcat(newlist, " ", argv(j));
620 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
621 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
622 newlist = strcat(newlist, " ", argv(j));
623 newlist = substring(newlist, 1, strlen(newlist) - 1);
624 cvar_set("g_maplist", newlist);
625 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
627 // NOTE: the selected map has just been inserted at (insertpos-1)th position
628 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
629 if(Map_Check(Map_Current, 1))
638 temp = cvar_string("g_maplist");
639 Map_Count = tokenizebyseparator(temp, " ");
642 bprint( "Maplist is empty! Resetting it to default map list.\n" );
643 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
644 localcmd("\nmenu_cmd sync\n");
645 Map_Count = tokenizebyseparator(temp, " ");
648 error("empty maplist, cannot select a new map");
649 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
652 strunzone(Map_Current_Name);
653 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
654 // this may or may not be correct, but who cares, in the worst case a map
655 // isn't chosen in the first pass that should have been
666 if(cvar("g_maplist_shuffle") > 0)
667 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
670 if(cvar("g_maplist_selectrandom"))
671 nextMap = MaplistMethod_Random();
674 nextMap = MaplistMethod_Iterate();
677 nextMap = MaplistMethod_Repeat();
681 Map_Goto_SetFloat(nextMap);
682 return getmapname_stored;
688 float DoNextMapOverride()
690 if(cvar("g_campaign"))
692 CampaignPostIntermission();
693 alreadychangedlevel = TRUE;
696 if(cvar("quit_when_empty"))
698 if(player_count <= currentbots)
701 alreadychangedlevel = TRUE;
705 if(cvar_string("quit_and_redirect") != "")
707 redirection_target = strzone(cvar_string("quit_and_redirect"));
708 alreadychangedlevel = TRUE;
711 if (cvar("samelevel")) // if samelevel is set, stay on same level
713 // 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)
714 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
715 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
716 localcmd("restart\n");
717 //changelevel (mapname);
718 alreadychangedlevel = TRUE;
721 if(cvar_string("nextmap") != "")
722 if(MapInfo_CheckMap(cvar_string("nextmap")))
724 Map_Goto_SetStr(cvar_string("nextmap"));
726 alreadychangedlevel = TRUE;
729 if(cvar("lastlevel"))
732 localcmd("set lastlevel 0\ntogglemenu\n");
733 alreadychangedlevel = TRUE;
741 //local string nextmap;
742 //local float n, nummaps;
744 if (alreadychangedlevel)
746 alreadychangedlevel = TRUE;
752 for(allowReset = 1; allowReset >= 0; --allowReset)
754 nextMap = GetNextMap();
760 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
761 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
762 localcmd("\nmenu_cmd sync\n");
766 error("Everything is broken - not even the default map list works. Please report this to the developers.");
778 When the player presses attack or jump, change to the next level
781 .float autoscreenshot;
782 void() MapVote_Start;
783 void() MapVote_Think;
784 float mapvote_initialized;
785 void IntermissionThink()
787 FixIntermissionClient(self);
789 if(cvar("sv_autoscreenshot"))
790 if(self.autoscreenshot > 0)
791 if(time > self.autoscreenshot)
793 self.autoscreenshot = -1;
794 if(clienttype(self) == CLIENTTYPE_REAL)
795 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
799 if (time < intermission_exittime)
802 if(!mapvote_initialized)
803 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
813 Returns the entity to view from
817 entity FindIntermission()
822 // look for info_intermission first
823 spot = find (world, classname, "info_intermission");
825 { // pick a random one
829 spot = find (spot, classname, "info_intermission");
831 spot = find (spot, classname, "info_intermission");
837 // then look for the start position
838 spot = find (world, classname, "info_player_start");
842 // testinfo_player_start is only found in regioned levels
843 spot = find (world, classname, "testplayerstart");
847 // then look for the start position
848 spot = find (world, classname, "info_player_deathmatch");
852 //objerror ("FindIntermission: no spot");
858 ===============================================================================
862 ===============================================================================
865 void DumpStats(float final)
869 local float to_console;
870 local float to_eventlog;
874 to_console = cvar("sv_logscores_console");
875 to_eventlog = cvar("sv_eventlog");
876 to_file = cvar("sv_logscores_file");
880 to_console = TRUE; // always print printstats replies
881 to_eventlog = FALSE; // but never print them to the event log
885 if(cvar("sv_eventlog_console"))
886 to_console = FALSE; // otherwise we get the output twice
892 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
900 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
904 fputs(file, strcat(s, "\n"));
907 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
912 fputs(file, strcat(s, "\n"));
914 FOR_EACH_CLIENT(other)
916 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
918 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
919 s = strcat(s, ftos(rint(time - other.jointime)), ":");
920 if(other.classname == "player" || g_arena || g_lms)
921 s = strcat(s, ftos(other.team), ":");
923 s = strcat(s, "spectator:");
926 print(s, other.netname, "\n");
928 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
930 fputs(file, strcat(s, other.netname, "\n"));
936 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
942 fputs(file, strcat(s, "\n"));
944 for(i = 1; i < 16; ++i)
946 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
947 s = strcat(s, ":", ftos(i));
953 fputs(file, strcat(s, "\n"));
963 fputs(file, ":end\n");
968 void FixIntermissionClient(entity e)
971 if(!e.autoscreenshot) // initial call
973 e.angles = e.v_angle;
974 e.angles_x = -e.angles_x;
975 e.autoscreenshot = time + 0.8; // used for autoscreenshot
977 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
979 e.movetype = MOVETYPE_NONE;
980 e.takedamage = DAMAGE_NO;
982 e.weaponentity.effects = EF_NODRAW;
983 if(clienttype(e) == CLIENTTYPE_REAL)
985 stuffcmd(e, "\nscr_printspeed 1000000\n");
986 s = cvar_string("sv_intermission_cdtrack");
988 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
990 WriteByte(MSG_ONE, SVC_INTERMISSION);
994 //e.velocity = '0 0 0';
997 // TODO halt weapon animation
1002 go to the next level for deathmatch
1003 only called if a time or frag limit has expired
1007 float minTotalFrags;
1008 float maxTotalFrags;
1014 intermission_running = 1;
1016 // enforce a wait time before allowing changelevel
1017 if(player_count > 0)
1018 intermission_exittime = time + cvar("sv_mapchange_delay");
1020 intermission_exittime = -1;
1023 WriteByte (MSG_ALL, SVC_CDTRACK);
1024 WriteByte (MSG_ALL, 3);
1025 WriteByte (MSG_ALL, 3);
1026 // done in FixIntermission
1029 //pos = FindIntermission ();
1035 if(cvar("sv_eventlog"))
1036 GameLogEcho(":gameover");
1040 FOR_EACH_CLIENT(other)
1042 FixIntermissionClient(other);
1045 bprint(other.netname, " ^7wins.\n");
1050 FOR_EACH_PLAYER(other)
1052 if(maxTotalFrags < other.totalfrags)
1053 maxTotalFrags = other.totalfrags;
1054 if(minTotalFrags > other.totalfrags)
1055 minTotalFrags = other.totalfrags;
1060 FOR_EACH_PLAYER(other)
1062 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1063 f = bound(0, other.play_time / max(time, 1), 1);
1064 // store some statistics?
1068 if(cvar("g_campaign"))
1069 CampaignPreIntermission();
1071 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1078 Exit deathmatch games upon conditions
1082 void CheckRules_Player()
1084 if (gameover) // someone else quit the game already
1087 if(self.deadflag == DEAD_NO)
1088 self.play_time += frametime;
1092 if(time > self.fogtime)
1094 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1095 self.fogtime = time + sv_foginterval;
1098 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1099 // (div0: and that in CheckRules_World please)
1102 float checkrules_oneminutewarning;
1104 float checkrules_equality;
1105 float checkrules_overtimewarning;
1106 float checkrules_overtimeend;
1108 void InitiateOvertime()
1110 if(!checkrules_overtimeend)
1111 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1114 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1115 float WINNING_YES = 1; // winner found
1116 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1117 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1119 float GetWinningCode(float fraglimitreached, float equality)
1122 if(fraglimitreached)
1123 return WINNING_STARTOVERTIME;
1125 return WINNING_NEVER;
1127 if(fraglimitreached)
1133 // set the .winning flag for exactly those players with a given field value
1134 void SetWinners(.float field, float value)
1137 FOR_EACH_PLAYER(head)
1138 head.winning = (head.field == value);
1141 // set the .winning flag for those players with a given field value
1142 void AddWinners(.float field, float value)
1145 FOR_EACH_PLAYER(head)
1146 if(head.field == value)
1150 // clear the .winning flags
1151 void ClearWinners(void)
1154 FOR_EACH_PLAYER(head)
1158 // Onslaught winning condition:
1159 // game terminates if only one team has a working generator (or none)
1160 float WinningCondition_Onslaught()
1163 local float t1, t2, t3, t4;
1164 // first check if the game has ended
1165 t1 = t2 = t3 = t4 = 0;
1166 head = find(world, classname, "onslaught_generator");
1169 if (head.health > 0)
1171 if (head.team == COLOR_TEAM1) t1 = 1;
1172 if (head.team == COLOR_TEAM2) t2 = 1;
1173 if (head.team == COLOR_TEAM3) t3 = 1;
1174 if (head.team == COLOR_TEAM4) t4 = 1;
1176 head = find(head, classname, "onslaught_generator");
1178 if (t1 + t2 + t3 + t4 < 2)
1180 // game over, only one team remains (or none)
1182 if (t1) SetWinners(team, COLOR_TEAM1);
1183 if (t2) SetWinners(team, COLOR_TEAM2);
1184 if (t3) SetWinners(team, COLOR_TEAM3);
1185 if (t4) SetWinners(team, COLOR_TEAM4);
1186 dprint("Have a winner, ending game.\n");
1190 // Two or more teams remain
1194 float LMS_NewPlayerLives()
1197 fl = cvar("fraglimit");
1201 // first player has left the game for dying too much? Nobody else can get in.
1202 if(lms_lowest_lives < 1)
1205 if(!cvar("g_lms_join_anytime"))
1206 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1209 return bound(1, lms_lowest_lives, fl);
1212 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1213 // they win. Otherwise the defending team wins once the timelimit passes.
1214 void assault_new_round();
1215 float WinningCondition_Assault()
1218 status = WINNING_NO;
1220 // as the timelimit has not yet passed just assume the defending team will win
1221 if(assault_attacker_team == COLOR_TEAM1)
1223 SetWinners(team, COLOR_TEAM2);
1227 SetWinners(team, COLOR_TEAM1);
1231 ent = find(world, classname, "target_assault_roundend");
1234 if(ent.winning) // round end has been triggered by attacking team
1236 SetWinners(team, assault_attacker_team);
1237 if(assault_attacker_team == COLOR_TEAM1)
1239 team1_score = team1_score + 50;
1243 team2_score = team2_score + 50;
1246 if(ent.cnt == 1) // this was the second round
1248 status = WINNING_YES;
1252 local entity oldself;
1255 cvar_set("timelimit", ftos((2*time)/60));
1256 assault_new_round();
1266 // LMS winning condition: game terminates if and only if there's at most one
1267 // one player who's living lives. Top two scores being equal cancels the time
1269 float WinningCondition_LMS()
1276 have_player = FALSE;
1277 have_players = FALSE;
1278 l = LMS_NewPlayerLives();
1280 head = find(world, classname, "player");
1283 head2 = find(head, classname, "player");
1285 have_players = TRUE;
1289 // we have at least one player
1292 // two or more active players - continue with the game
1296 // exactly one player?
1299 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1303 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1309 // and assign him his first place
1310 PlayerScore_Add(head, SP_LMS_RANK, 1);
1317 // nobody is playing at all...
1320 // wait for players...
1324 // SNAFU (maybe a draw game?)
1326 dprint("No players, ending game.\n");
1331 // When we get here, we have at least two players who are actually LIVING,
1332 // now check if the top two players have equal score.
1333 WinningConditionHelper();
1336 if(WinningConditionHelper_winner)
1337 WinningConditionHelper_winner.winning = TRUE;
1338 if(WinningConditionHelper_equality)
1339 return WINNING_NEVER;
1341 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1345 void print_to(entity e, string s)
1348 sprint(e, strcat(s, "\n"));
1353 void ShuffleMaplist()
1361 result = cvar_string("g_maplist");
1362 litems = tokenizebyseparator(result, " ");
1364 for(start = 0; start < litems - 1; ++start)
1368 // select a random item
1369 selected = ceil(random() * (litems - start) + start) - 1;
1371 // shift this item to the place start
1372 for(i = 0; i < start; ++i)
1373 result = strcat(result, " ", argv(i));
1374 result = strcat(result, " ", argv(selected));
1375 for(i = start; i < litems; ++i)
1377 result = strcat(result, " ", argv(i));
1378 result = substring(result, 1, strlen(result) - 1);
1380 litems = tokenizebyseparator(result, " ");
1382 //dprint(result, "\n");
1385 cvar_set("g_maplist", result);
1388 float WinningCondition_Scores(float limit)
1390 // TODO make everything use THIS winning condition (except LMS)
1391 WinningConditionHelper();
1395 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1396 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1397 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1398 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1402 if(WinningConditionHelper_winner)
1403 WinningConditionHelper_winner.winning = 1;
1404 if(WinningConditionHelper_winnerteam >= 0)
1405 SetWinners(team, WinningConditionHelper_winnerteam);
1407 if(WinningConditionHelper_topscore == 0)
1408 WinningConditionHelper_equality = 0;
1410 if(WinningConditionHelper_lowerisbetter)
1412 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1416 return GetWinningCode(limit && WinningConditionHelper_topscore && (WinningConditionHelper_topscore >= limit), WinningConditionHelper_equality);
1419 float WinningCondition_Race(float fraglimit)
1423 wc = WinningCondition_Scores(fraglimit);
1425 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1426 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1427 // do NOT support equality when the laps are all raced!
1430 if not(p.race_completed)
1431 return WINNING_STARTOVERTIME;
1437 void ReadyRestart();
1438 float WinningCondition_QualifyingThenRace(float limit)
1441 wc = WinningCondition_Scores(limit);
1443 // NEVER initiate overtime
1444 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1445 // do NOT support equality when the laps are all raced!
1448 float playerswithlaps;
1450 totalplayers = playerswithlaps = 0;
1451 FOR_EACH_PLAYER(head)
1454 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
1458 // at least 2/3 of the players have completed a lap: start the RACE
1459 // otherwise, the players should end the qualifying on their own
1460 if(totalplayers >= 3)
1461 if(playerswithlaps >= totalplayers * 2 / 3)
1463 checkrules_overtimeend = 0;
1465 return WINNING_NEVER;
1474 float WinningCondition_RanOutOfSpawns()
1478 if(!have_team_spawns)
1481 if(!some_spawn_has_been_used)
1484 team1_score = team2_score = team3_score = team4_score = 0;
1486 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1488 if(head.team == COLOR_TEAM1)
1490 else if(head.team == COLOR_TEAM2)
1492 else if(head.team == COLOR_TEAM3)
1494 else if(head.team == COLOR_TEAM4)
1498 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1500 if(head.team == COLOR_TEAM1)
1502 else if(head.team == COLOR_TEAM2)
1504 else if(head.team == COLOR_TEAM3)
1506 else if(head.team == COLOR_TEAM4)
1511 if(team1_score + team2_score + team3_score + team4_score == 0)
1513 checkrules_equality = TRUE;
1516 else if(team1_score + team2_score + team3_score + team4_score == 1)
1519 if(team1_score) t = COLOR_TEAM1;
1520 if(team2_score) t = COLOR_TEAM2;
1521 if(team3_score) t = COLOR_TEAM3;
1522 if(team4_score) t = COLOR_TEAM4;
1523 CheckAllowedTeams(world);
1524 for(i = 0; i < MAX_TEAMSCORE; ++i)
1526 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
1527 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
1528 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
1529 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
1532 AddWinners(team, t);
1543 Exit deathmatch games upon conditions
1546 void CheckRules_World()
1549 local float timelimit;
1550 local float fraglimit;
1558 MapVote_Think should now do that part
1559 if (intermission_running)
1560 if (time >= intermission_exittime + 60)
1562 if(!DoNextMapOverride())
1568 if (gameover) // someone else quit the game already
1570 if(player_count == 0) // Nobody there? Then let's go to the next map
1572 // this will actually check the player count in the next frame
1573 // again, but this shouldn't hurt
1577 timelimit = cvar("timelimit") * 60;
1578 fraglimit = cvar("fraglimit");
1581 fraglimit = 0; // no fraglimit for now
1583 if(checkrules_overtimeend)
1585 if(!checkrules_overtimewarning)
1587 checkrules_overtimewarning = TRUE;
1588 //announceall("announcer/robotic/1minuteremains.wav");
1589 if(!g_race_qualifying)
1590 bcenterprint("^3Everyone, finish your lap! The race is over!");
1592 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1597 if (timelimit && time >= timelimit)
1601 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1607 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1609 checkrules_oneminutewarning = TRUE;
1610 play2all("announcer/robotic/1minuteremains.wav");
1613 status = WinningCondition_RanOutOfSpawns();
1614 if(status == WINNING_YES)
1616 bprint("Hey! Someone ran out of spawns!\n");
1618 else if(g_race && !g_race_qualifying && timelimit >= 0)
1620 status = WinningCondition_Race(fraglimit);
1622 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
1624 status = WinningCondition_QualifyingThenRace(fraglimit);
1628 status = WinningCondition_Assault(); // TODO remove this?
1632 status = WinningCondition_LMS();
1634 else if (g_onslaught)
1636 status = WinningCondition_Onslaught(); // TODO remove this?
1640 status = WinningCondition_Scores(fraglimit);
1643 if(status == WINNING_STARTOVERTIME)
1645 status = WINNING_NEVER;
1649 if(status == WINNING_NEVER)
1650 // equality cases! Nobody wins if the overtime ends in a draw.
1653 if(checkrules_overtimeend)
1654 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1655 status = WINNING_YES;
1657 if(status == WINNING_YES)
1661 float mapvote_nextthink;
1662 float mapvote_initialized;
1663 float mapvote_keeptwotime;
1664 float mapvote_timeout;
1665 string mapvote_message;
1666 string mapvote_screenshot_dir;
1668 float mapvote_count;
1669 float mapvote_count_real;
1670 string mapvote_maps[MAPVOTE_COUNT];
1671 float mapvote_maps_suggested[MAPVOTE_COUNT];
1672 string mapvote_suggestions[MAPVOTE_COUNT];
1673 float mapvote_suggestion_ptr;
1674 float mapvote_maxlen;
1675 float mapvote_voters;
1676 float mapvote_votes[MAPVOTE_COUNT];
1678 float mapvote_detail;
1679 float mapvote_abstain;
1680 float mapvote_dirty;
1683 void MapVote_ClearAllVotes()
1685 FOR_EACH_CLIENT(other)
1689 string MapVote_Suggest(string m)
1693 return "That's not how to use this command.";
1694 if(!cvar("g_maplist_votable_suggestions"))
1695 return "Suggestions are not accepted on this server.";
1696 if(mapvote_initialized)
1697 return "Can't suggest - voting is already in progress!";
1698 m = MapInfo_FixName(m);
1700 return "The map you suggested is not available on this server.";
1701 if(!cvar("g_maplist_votable_override_mostrecent"))
1703 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1705 if(!MapInfo_CheckMap(m))
1706 return "The map you suggested does not support the current game mode.";
1707 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1708 if(mapvote_suggestions[i] == m)
1709 return "This map was already suggested.";
1710 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1712 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1716 i = mapvote_suggestion_ptr;
1717 mapvote_suggestion_ptr += 1;
1719 if(mapvote_suggestions[i] != "")
1720 strunzone(mapvote_suggestions[i]);
1721 mapvote_suggestions[i] = strzone(m);
1722 if(cvar("sv_eventlog"))
1723 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
1724 return strcat("Suggestion of ", m, " accepted.");
1727 void MapVote_AddVotable(string nextMap, float isSuggestion)
1732 for(j = 0; j < mapvote_count; ++j)
1733 if(mapvote_maps[j] == nextMap)
1735 if(strlen(nextMap) > mapvote_maxlen)
1736 mapvote_maxlen = strlen(nextMap);
1737 mapvote_maps[mapvote_count] = strzone(nextMap);
1738 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1742 void MapVote_SendData(float target);
1748 MapVote_ClearAllVotes();
1751 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1752 mapvote_abstain = cvar("g_maplist_votable_abstain");
1755 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1757 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1758 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
1760 if(mapvote_suggestion_ptr)
1761 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1762 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1764 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1765 MapVote_AddVotable(GetNextMap(), FALSE);
1767 if(mapvote_count == 0)
1769 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1770 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1771 localcmd("\nmenu_cmd sync\n");
1772 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1773 MapVote_AddVotable(GetNextMap(), FALSE);
1776 mapvote_count_real = mapvote_count;
1778 MapVote_AddVotable("don't care", 0);
1780 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1782 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1783 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1784 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1785 mapvote_keeptwotime = 0;
1786 mapvote_message = "Choose a map and press its key!";
1788 mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
1789 if(mapvote_screenshot_dir == "")
1790 mapvote_screenshot_dir = "maps";
1791 mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
1793 if(!cvar("g_maplist_textonly"))
1794 MapVote_SendData(MSG_ALL);
1797 void MapVote_SendPicture(float id)
1800 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1801 WriteByte(MSG_ONE, TE_CSQC_MAPVOTE);
1802 WriteByte(MSG_ONE, MAPVOTE_NET_PIC);
1803 WriteByte(MSG_ONE, id);
1804 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 3072);
1807 float GameCommand_MapVote(string cmd)
1809 if(!intermission_running)
1811 if(!cvar("g_maplist_textonly"))
1813 if(cmd == "mv_getpic")
1815 MapVote_SendPicture(stof(argv(1)));
1823 float MapVote_GetMapMask()
1825 float mask, i, power;
1827 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
1828 if(mapvote_maps[i] != "")
1833 void MapVote_SendData(float targ)
1835 string mapfile, pakfile;
1837 WriteByte(targ, SVC_TEMPENTITY);
1838 WriteByte(targ, TE_CSQC_CONFIG);
1839 WriteString(targ, "mv_screenshot_dir");
1840 WriteString(targ, mapvote_screenshot_dir);
1842 WriteByte(targ, SVC_TEMPENTITY);
1843 WriteByte(targ, TE_CSQC_MAPVOTE);
1844 WriteByte(targ, MAPVOTE_NET_INIT);
1846 WriteByte(targ, mapvote_count);
1847 WriteByte(targ, mapvote_abstain);
1848 WriteByte(targ, mapvote_detail);
1849 WriteCoord(targ, mapvote_timeout);
1850 if(mapvote_count <= 8)
1851 WriteByte(targ, MapVote_GetMapMask());
1853 WriteShort(targ, MapVote_GetMapMask());
1854 for(i = 0; i < mapvote_count; ++i)
1855 if(mapvote_maps[i] != "")
1857 WriteString(targ, mapvote_maps[i]);
1858 mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
1859 pakfile = whichpack(strcat(mapfile, ".tga"));
1861 pakfile = whichpack(strcat(mapfile, ".jpg"));
1863 pakfile = whichpack(strcat(mapfile, ".png"));
1864 print("pakfile is ", pakfile, "\n");
1865 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
1866 pakfile = substring(pakfile, o, 999);
1867 WriteString(targ, pakfile);
1871 void MapVote_UpdateData(float targ)
1874 WriteByte(targ, SVC_TEMPENTITY);
1875 WriteByte(targ, TE_CSQC_MAPVOTE);
1876 WriteByte(targ, MAPVOTE_NET_UPDATE);
1877 if(mapvote_count <= 8)
1878 WriteByte(targ, MapVote_GetMapMask());
1880 WriteShort(targ, MapVote_GetMapMask());
1882 for(i = 0; i < mapvote_count; ++i)
1883 if(mapvote_maps[i] != "")
1884 WriteByte(targ, mapvote_votes[i]);
1887 void MapVote_TellVote(float targ, float vote)
1889 WriteByte(targ, SVC_TEMPENTITY);
1890 WriteByte(targ, TE_CSQC_MAPVOTE);
1891 WriteByte(targ, MAPVOTE_NET_OWNVOTE);
1892 WriteByte(targ, vote);
1895 float MapVote_Finished(float mappos)
1901 if(cvar("sv_eventlog"))
1903 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1904 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1905 didntvote = mapvote_voters;
1906 for(i = 0; i < mapvote_count; ++i)
1907 if(mapvote_maps[i] != "")
1909 didntvote -= mapvote_votes[i];
1912 result = strcat(result, ":", mapvote_maps[i]);
1913 result = strcat(result, ":", ftos(mapvote_votes[i]));
1916 result = strcat(result, ":didn't vote:", ftos(didntvote));
1918 GameLogEcho(result);
1919 if(mapvote_maps_suggested[mappos])
1920 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
1923 FOR_EACH_REALCLIENT(other)
1924 FixClientCvars(other);
1926 Map_Goto_SetStr(mapvote_maps[mappos]);
1928 alreadychangedlevel = TRUE;
1931 void MapVote_CheckRules_1()
1935 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1937 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1938 mapvote_votes[i] = 0;
1942 FOR_EACH_REALCLIENT(other)
1947 i = other.mapvote - 1;
1948 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1949 mapvote_votes[i] = mapvote_votes[i] + 1;
1954 float MapVote_CheckRules_2()
1957 float firstPlace, secondPlace;
1958 float firstPlaceVotes, secondPlaceVotes;
1959 float mapvote_voters_real;
1962 mapvote_voters_real = mapvote_voters;
1964 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
1966 RandomSelection_Init();
1967 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1968 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
1969 firstPlace = RandomSelection_chosen_float;
1970 firstPlaceVotes = RandomSelection_best_priority;
1971 //dprint("First place: ", ftos(firstPlace), "\n");
1972 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1974 RandomSelection_Init();
1975 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1977 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
1978 secondPlace = RandomSelection_chosen_float;
1979 secondPlaceVotes = RandomSelection_best_priority;
1980 //dprint("Second place: ", ftos(secondPlace), "\n");
1981 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1983 if(firstPlace == -1)
1984 error("No first place in map vote... WTF?");
1986 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
1987 return MapVote_Finished(firstPlace);
1989 if(mapvote_keeptwotime)
1990 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
1993 mapvote_dirty = TRUE;
1994 mapvote_message = "Now decide between the TOP TWO!";
1995 mapvote_keeptwotime = 0;
1996 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
1997 result = strcat(result, ":", ftos(firstPlaceVotes));
1998 result = strcat(result, ":", mapvote_maps[secondPlace]);
1999 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2000 didntvote = mapvote_voters;
2001 for(i = 0; i < mapvote_count; ++i)
2002 if(mapvote_maps[i] != "")
2004 didntvote -= mapvote_votes[i];
2006 if(i != secondPlace)
2008 result = strcat(result, ":", mapvote_maps[i]);
2009 result = strcat(result, ":", ftos(mapvote_votes[i]));
2010 if(i < mapvote_count_real)
2012 strunzone(mapvote_maps[i]);
2013 mapvote_maps[i] = "";
2017 result = strcat(result, ":didn't vote:", ftos(didntvote));
2018 if(cvar("sv_eventlog"))
2019 GameLogEcho(result);
2032 keeptwo = mapvote_keeptwotime;
2033 MapVote_CheckRules_1(); // count
2034 if(MapVote_CheckRules_2()) // decide
2038 FOR_EACH_REALCLIENT(other)
2040 // hide scoreboard again
2041 if(other.health != 2342)
2043 other.health = 2342;
2045 if(clienttype(other) == CLIENTTYPE_REAL)
2047 if(cvar("g_maplist_textonly"))
2048 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");
2051 WriteByte(MSG_ONE, SVC_FINALE);
2052 WriteString(MSG_ONE, "");
2056 // notify about keep-two
2057 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2058 play2(other, "misc/invshot.wav");
2060 // clear possibly invalid votes
2061 if(mapvote_maps[other.mapvote - 1] == "")
2063 // use impulses as new vote
2064 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2065 if(mapvote_maps[other.impulse - 1] != "")
2067 other.mapvote = other.impulse;
2069 mapvote_dirty = TRUE;
2072 MapVote_TellVote(MSG_ONE, other.mapvote);
2080 MapVote_CheckRules_1(); // just count
2082 if(!cvar("g_maplist_textonly"))
2083 if(mapvote_dirty) // 1 if "keeptwo" or "impulse" happened before
2085 MapVote_UpdateData(MSG_BROADCAST);
2086 mapvote_dirty = FALSE;
2089 if(cvar("g_maplist_textonly"))
2091 FOR_EACH_REALCLIENT(other)
2093 // display voting screen
2094 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2095 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2097 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2098 msgstr = strcat(msgstr, mapvote_message);
2099 msgstr = strcat(msgstr, "\n\n");
2100 for(i = 0; i < mapvote_count; ++i)
2101 if(mapvote_maps[i] == "")
2102 msgstr = strcat(msgstr, "\n");
2105 tmp = mapvote_maps[i];
2106 tmp = strpad(mapvote_maxlen, tmp);
2107 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2110 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2111 if(mapvote_votes[i] != 1)
2112 tmp = strcat(tmp, "s");
2113 tmp = strcat(tmp, ")");
2114 tmp = strpad(mapvote_maxlen + 15, tmp);
2117 if(i == mapvote_count - 1)
2118 msgstr = strcat(msgstr, "\n");
2119 if(other.mapvote == i + 1)
2120 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2122 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2125 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2127 msgstr = strcat(msgstr, "s");
2128 msgstr = strcat(msgstr, " cast");
2129 i = ceil(mapvote_timeout - time);
2130 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2132 msgstr = strcat(msgstr, "s");
2133 msgstr = strcat(msgstr, " left");
2135 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2139 void MapVote_Start()
2144 MapInfo_Enumerate();
2145 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2148 void MapVote_Think()
2153 if(alreadychangedlevel)
2156 if(time < mapvote_nextthink)
2160 mapvote_nextthink = time + 0.5;
2162 if(!mapvote_initialized)
2164 mapvote_initialized = TRUE;
2165 if(DoNextMapOverride())
2167 if(!cvar("g_maplist_votable") || player_count <= 0)
2178 string GotoMap(string m)
2180 if(!MapInfo_CheckMap(m))
2181 return "The map you chose is not available on this server.";
2182 cvar_set("nextmap", m);
2183 cvar_set("timelimit", "-1");
2184 if(mapvote_initialized || alreadychangedlevel)
2186 if(DoNextMapOverride())
2187 return "Map switch initiated.";
2189 return "Hm... no. For some reason I like THIS map more.";
2192 return "Map switch will happen after scoreboard.";
2198 FOR_EACH_REALCLIENT(self)
2200 if(self.classname == "spectator")
2202 if(self.enemy.hitsound)
2203 play2(self, "misc/hit.wav");
2208 play2(self, "misc/hit.wav");
2211 FOR_EACH_CLIENT(self)
2212 self.hitsound = FALSE;
2218 * returns TRUE if redirecting
2220 float redirection_timeout;
2221 float redirection_nextthink;
2222 float RedirectionThink()
2224 float clients_found;
2226 if(redirection_target == "")
2229 if(!redirection_timeout)
2231 cvar_set("sv_public", "-2");
2232 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2233 if(redirection_target == "self")
2234 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2236 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2239 if(time < redirection_nextthink)
2242 redirection_nextthink = time + 1;
2245 FOR_EACH_REALCLIENT(self)
2247 print("Redirecting: sending connect command to ", self.netname, "\n");
2248 if(redirection_target == "self")
2249 stuffcmd(self, "\ndisconnect; reconnect\n");
2251 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2255 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2257 if(time > redirection_timeout || clients_found == 0)
2258 localcmd("\nwait; wait; wait; quit\n");
2265 // Loaded from a save game
2266 // some things then break, so let's work around them...
2268 // Progs DB (capture records)
2270 ServerProgsDB = db_create();
2272 ServerProgsDB = db_load("server.db");
2276 MapInfo_Enumerate();
2277 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
2282 if(world_initialized)
2284 world_initialized = 0;
2285 print("Saving persistent data...\n");
2288 db_save(ServerProgsDB, "server.db");
2289 db_close(ServerProgsDB);
2291 // tell the bot system the game is ending now
2298 print("NOTE: crashed before even initializing the world, not saving persistent data\n");