1 float SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS = 1;
2 string redirection_target;
3 float world_initialized;
9 float() DoNextMapOverride;
11 void SetDefaultAlpha()
13 if(cvar("g_running_guns"))
15 default_player_alpha = -1;
16 default_weapon_alpha = +1;
20 default_player_alpha = cvar("g_balance_cloaked_alpha");
21 default_weapon_alpha = default_player_alpha;
25 default_player_alpha = cvar("g_player_alpha");
26 if(default_player_alpha <= 0)
27 default_player_alpha = 1;
28 default_weapon_alpha = default_player_alpha;
32 void fteqcc_testbugs()
36 if(!cvar("developer_fteqccbugs"))
39 dprint("*** fteqcc test: checking for bugs...\n");
43 if(sqrt(a) - sqrt(b - a) == 0)
44 dprint("*** fteqcc test: found same-function-twice bug\n");
46 dprint("*** fteqcc test: same-function-twice bug got FINALLY FIXED! HOORAY!\n");
50 world.enemy.cnt += 10;
51 if(world.cnt > 0.2 || world.cnt < -0.2) // don't error out if it's just roundoff errors
52 dprint("*** fteqcc test: found += bug\n");
54 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
59 * Takes care of pausing and unpausing the game.
60 * Centerprints the information about an upcoming or active timeout to all active
61 * players. Also plays reminder sounds.
63 void timeoutHandler_Think() {
66 if (timeoutStatus == 1) {
67 if (remainingLeadTime > 0) {
68 //centerprint the information to every player
69 timeStr = getTimeoutText(0);
70 FOR_EACH_REALCLIENT(plr) {
71 if(plr.classname == "player") {
72 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
75 remainingLeadTime -= 1;
76 //think again in 1 second:
77 self.nextthink = time + 1;
82 cvar_set("slowmo", ftos(TIMEOUT_SLOWMO_VALUE));
83 //copy .v_angle to .lastV_angle for every player in order to fix their view during pause (see PlayerPreThink)
84 FOR_EACH_REALPLAYER(plr) {
85 plr.lastV_angle = plr.v_angle;
87 self.nextthink = time;
90 else if (timeoutStatus == 2) {
91 if (remainingTimeoutTime > 0) {
92 timeStr = getTimeoutText(0);
93 FOR_EACH_REALCLIENT(plr) {
94 if(plr.classname == "player") {
95 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
98 if(remainingTimeoutTime == cvar("sv_timeout_resumetime")) { //play a warning sound when only <sv_timeout_resumetime> seconds are left
99 play2all("announcer/robotic/prepareforbattle.wav");
101 remainingTimeoutTime -= 1;
102 self.nextthink = time + TIMEOUT_SLOWMO_VALUE;
105 //unpause the game again
106 remainingTimeoutTime = timeoutStatus = 0;
107 cvar_set("slowmo", ftos(orig_slowmo));
108 //and unlock the fixed view again once there is no timeout active anymore
109 FOR_EACH_REALPLAYER(plr) {
110 plr.fixangle = FALSE;
112 //get rid of the countdown message
113 FOR_EACH_REALCLIENT(plr) {
114 if(plr.classname == "player") {
115 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
123 else if (timeoutStatus == 0) { //if a player called the resumegame command (which set timeoutStatus to 0 already)
124 FOR_EACH_REALCLIENT(plr) {
125 if(plr.classname == "player") {
126 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
138 cvar_set("_sv_init", "0");
139 if(cvar("g_maplist_shuffle"))
141 tokenizebyseparator(cvar_string("g_maplist"), " ");
143 cvar_set("nextmap", argv(0));
146 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
148 if(!DoNextMapOverride())
157 float world_already_spawned;
158 void RegisterWeapons();
159 void spawnfunc_worldspawn (void)
164 dprint_load(); // load dprint status from cvar
166 if(world_already_spawned)
167 error("world already spawned - you may have EXACTLY ONE worldspawn!");
168 world_already_spawned = TRUE;
170 compressShortVector_init();
173 head = nextent(world);
178 head = nextent(head);
181 // needs to be done so early as they would still spawn
188 ServerProgsDB = db_create();
190 ServerProgsDB = db_load("server.db");
193 TODO sound pack system
194 // initialize sound pack system
195 soundpack = cvar_string("g_soundpack");
197 soundpack = strcat(soundpack, "/");
198 soundpack = strzone(soundpack);
204 // 1 FLICKER (first variety)
205 lightstyle(1, "mmnmmommommnonmmonqnmmo");
207 // 2 SLOW STRONG PULSE
208 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
210 // 3 CANDLE (first variety)
211 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
214 lightstyle(4, "mamamamamama");
217 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
219 // 6 FLICKER (second variety)
220 lightstyle(6, "nmonqnmomnmomomno");
222 // 7 CANDLE (second variety)
223 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
225 // 8 CANDLE (third variety)
226 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
228 // 9 SLOW STROBE (fourth variety)
229 lightstyle(9, "aaaaaaaazzzzzzzz");
231 // 10 FLUORESCENT FLICKER
232 lightstyle(10, "mmamammmmammamamaaamammma");
234 // 11 SLOW PULSE NOT FADE TO BLACK
235 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
237 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
242 if(cvar("g_campaign"))
249 bot_waypoints_for_items = cvar("g_waypoints_for_items");
250 if(bot_waypoints_for_items == 1)
251 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
252 bot_waypoints_for_items = 0;
254 // for setting by mapinfo
255 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
256 cvar_set("sv_q3acompat_machineshotgunswap", "0");
260 WaypointSprite_Init();
265 GameLogInit(); // prepare everything
266 if(cvar("sv_eventlog"))
268 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
269 s = strcat(s, ftos(random()));
270 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
271 s = ":gameinfo:mutators:LIST";
272 if(cvar("g_grappling_hook"))
273 s = strcat(s, ":grappling_hook");
274 if(!cvar("g_use_ammunition"))
275 s = strcat(s, ":no_use_ammunition");
276 if(!cvar("g_pickup_items"))
277 s = strcat(s, ":no_pickup_items");
278 if(cvar("g_instagib"))
279 s = strcat(s, ":instagib");
280 if(cvar("g_rocketarena"))
281 s = strcat(s, ":rockerarena");
283 s = strcat(s, ":nixnex");
284 if(cvar("g_vampire"))
285 s = strcat(s, ":vampire");
286 if(cvar("g_laserguided_missile"))
287 s = strcat(s, ":laserguided_missile");
288 if(cvar("g_norecoil"))
289 s = strcat(s, ":norecoil");
291 s = strcat(s, ":midair");
292 if(cvar("g_minstagib"))
293 s = strcat(s, ":minstagib");
295 GameLogEcho(":gameinfo:end");
298 cvar_set("nextmap", "");
302 if(cvar("g_campaign"))
309 //initialise globals related to sv_timeout
310 sys_ticrate = cvar("sys_ticrate");
311 orig_slowmo = cvar("slowmo");
314 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
316 //if tourney is used map starts in warmup mode. if this mode shall stay unlimited, reset timelimit, but save the original one
318 timelimit_orig = cvar("timelimit");
319 cvar_set("timelimit", "0");
322 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
324 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
327 while((s = fgets(fd)))
334 print("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
335 print(" cdtrack ", argv(2), "\n");
337 else if(argv(0) == "fog")
339 print("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
340 print(" \"fog\" \"", s, "\"\n");
342 else if(argv(0) == "set")
344 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
345 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
347 else if(argv(0) != "//")
349 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
350 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
357 addstat(STAT_SYS_TICRATE, AS_FLOAT, stat_sys_ticrate);
358 addstat(STAT_WEAPONS, AS_INT, weapons);
359 addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
361 next_pingtime = time + 5;
362 world_initialized = 1;
365 void spawnfunc_light (void)
367 //makestatic (self); // Who the f___ did that?
371 float TryFile( string pFilename )
374 dprint("TryFile(\"", pFilename, "\")\n");
375 lHandle = fopen( pFilename, FILE_READ );
376 if( lHandle != -1 ) {
386 return GametypeNameFromType(game);
389 string getmapname_stored;
395 float Map_Count, Map_Current;
396 string Map_Current_Name;
398 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
399 float GetMaplistPosition()
405 idx = cvar("g_maplist_index");
412 for(pos = 0; pos < Map_Count; ++pos)
416 // resume normal maplist rotation if current map is not in g_maplist
420 float MapHasRightSize(string map)
423 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
424 if(cvar("g_maplist_check_waypoints"))
426 dprint("checkwp "); dprint(map);
427 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
430 dprint(": no waypoints\n");
433 dprint(": has waypoints\n");
437 // open map size restriction file
438 dprint("opensize "); dprint(map);
439 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
442 float mapmin, mapmax;
444 mapmin = stof(fgets(fh));
445 mapmax = stof(fgets(fh));
447 if(player_count < mapmin)
449 dprint("not enough\n");
452 if(player_count > mapmax)
454 dprint("too many\n");
457 dprint("right size\n");
460 dprint(": not found\n");
464 string Map_Filename(float position)
466 return strcat("maps/", argv(position), ".bsp");
469 string strwords(string s, float w)
472 for(endpos = 0; w && endpos >= 0; --w)
473 endpos = strstrofs(s, " ", endpos + 1);
477 return substring(s, 0, endpos);
480 float strhasword(string s, string w)
482 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
485 void Map_MarkAsRecent(string m)
487 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
490 float Map_IsRecent(string m)
492 return strhasword(cvar_string("g_maplist_mostrecent"), m);
495 float Map_Check(float position, float pass)
499 map_next = argv(position);
502 if(map_next == Map_Current_Name) // same map again in first pass?
504 if(Map_IsRecent(map_next))
507 filename = Map_Filename(position);
508 if(MapInfo_CheckMap(map_next))
512 if(MapHasRightSize(map_next))
517 dprint( "Couldn't select '", filename, "'..\n" );
522 void Map_Goto_SetStr(string nextmapname)
524 if(getmapname_stored != "")
525 strunzone(getmapname_stored);
526 if(nextmapname == "")
527 getmapname_stored = "";
529 getmapname_stored = strzone(nextmapname);
532 void Map_Goto_SetFloat(float position)
534 cvar_set("g_maplist_index", ftos(position));
535 Map_Goto_SetStr(argv(position));
540 // settings persist, except...
541 if(cvar("g_campaign"))
542 localcmd("\nexec mutator_reset.cfg\n");
543 localcmd("\nsettemp_restore\n");
548 Map_MarkAsRecent(getmapname_stored);
550 MapInfo_LoadMap(getmapname_stored);
553 // return codes of map selectors:
554 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
555 // -2 = permanent failure
556 float() MaplistMethod_Iterate = // usual method
560 for(pass = 1; pass <= 2; ++pass)
562 for(i = 1; i < Map_Count; ++i)
565 mapindex = mod(i + Map_Current, Map_Count);
566 if(Map_Check(mapindex, pass))
573 float() MaplistMethod_Repeat = // fallback method
575 if(Map_Check(Map_Current, 2))
580 float() MaplistMethod_Random = // random map selection
586 for(i = 0; i <= imax; ++i)
589 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
590 if(Map_Check(mapindex, 1))
596 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
597 // the exponent sets a bias on the map selection:
598 // the higher the exponent, the less likely "shortly repeated" same maps are
600 float i, j, imax, insertpos;
604 for(i = 0; i <= imax; ++i)
608 // now reinsert this at another position
609 insertpos = pow(random(), 1 / exponent); // ]0, 1]
610 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
611 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
612 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
614 // insert the current map there
616 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
617 newlist = strcat(newlist, " ", argv(j));
618 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
619 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
620 newlist = strcat(newlist, " ", argv(j));
621 newlist = substring(newlist, 1, strlen(newlist) - 1);
622 cvar_set("g_maplist", newlist);
623 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
625 // NOTE: the selected map has just been inserted at (insertpos-1)th position
626 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
627 if(Map_Check(Map_Current, 1))
636 temp = cvar_string("g_maplist");
637 Map_Count = tokenizebyseparator(temp, " ");
640 bprint( "Maplist is empty! Resetting it to default map list.\n" );
641 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
642 localcmd("\nmenu_cmd sync\n");
643 Map_Count = tokenizebyseparator(temp, " ");
646 error("empty maplist, cannot select a new map");
647 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
650 strunzone(Map_Current_Name);
651 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
652 // this may or may not be correct, but who cares, in the worst case a map
653 // isn't chosen in the first pass that should have been
664 if(cvar("g_maplist_shuffle") > 0)
665 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
668 if(cvar("g_maplist_selectrandom"))
669 nextMap = MaplistMethod_Random();
672 nextMap = MaplistMethod_Iterate();
675 nextMap = MaplistMethod_Repeat();
679 Map_Goto_SetFloat(nextMap);
680 return getmapname_stored;
686 float DoNextMapOverride()
688 if(cvar("g_campaign"))
690 CampaignPostIntermission();
691 alreadychangedlevel = TRUE;
694 if(cvar("quit_when_empty"))
696 if(player_count <= currentbots)
699 alreadychangedlevel = TRUE;
703 if(cvar_string("quit_and_redirect") != "")
705 redirection_target = strzone(cvar_string("quit_and_redirect"));
706 alreadychangedlevel = TRUE;
709 if (cvar("samelevel")) // if samelevel is set, stay on same level
711 // 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)
712 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
713 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
714 localcmd("restart\n");
715 //changelevel (mapname);
716 alreadychangedlevel = TRUE;
719 if(cvar_string("nextmap") != "")
720 if(MapInfo_CheckMap(cvar_string("nextmap")))
722 Map_Goto_SetStr(cvar_string("nextmap"));
724 alreadychangedlevel = TRUE;
727 if(cvar("lastlevel"))
730 localcmd("set lastlevel 0\ntogglemenu\n");
731 alreadychangedlevel = TRUE;
739 //local string nextmap;
740 //local float n, nummaps;
742 if (alreadychangedlevel)
744 alreadychangedlevel = TRUE;
750 for(allowReset = 1; allowReset >= 0; --allowReset)
752 nextMap = GetNextMap();
758 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
759 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
760 localcmd("\nmenu_cmd sync\n");
764 error("Everything is broken - not even the default map list works. Please report this to the developers.");
776 When the player presses attack or jump, change to the next level
779 .float autoscreenshot;
780 void() MapVote_Start;
781 void() MapVote_Think;
782 float mapvote_initialized;
783 void IntermissionThink()
785 FixIntermissionClient(self);
787 if(cvar("sv_autoscreenshot"))
788 if(self.autoscreenshot > 0)
789 if(time > self.autoscreenshot)
791 self.autoscreenshot = -1;
792 if(clienttype(self) == CLIENTTYPE_REAL)
793 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
797 if (time < intermission_exittime)
800 if(!mapvote_initialized)
801 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
811 Returns the entity to view from
815 entity FindIntermission()
820 // look for info_intermission first
821 spot = find (world, classname, "info_intermission");
823 { // pick a random one
827 spot = find (spot, classname, "info_intermission");
829 spot = find (spot, classname, "info_intermission");
835 // then look for the start position
836 spot = find (world, classname, "info_player_start");
840 // testinfo_player_start is only found in regioned levels
841 spot = find (world, classname, "testplayerstart");
845 // then look for the start position
846 spot = find (world, classname, "info_player_deathmatch");
850 //objerror ("FindIntermission: no spot");
856 ===============================================================================
860 ===============================================================================
863 void DumpStats(float final)
867 local float to_console;
868 local float to_eventlog;
872 to_console = cvar("sv_logscores_console");
873 to_eventlog = cvar("sv_eventlog");
874 to_file = cvar("sv_logscores_file");
878 to_console = TRUE; // always print printstats replies
879 to_eventlog = FALSE; // but never print them to the event log
883 if(cvar("sv_eventlog_console"))
884 to_console = FALSE; // otherwise we get the output twice
890 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
898 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
902 fputs(file, strcat(s, "\n"));
905 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
910 fputs(file, strcat(s, "\n"));
912 FOR_EACH_CLIENT(other)
914 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
916 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
917 s = strcat(s, ftos(rint(time - other.jointime)), ":");
918 if(other.classname == "player" || g_arena || g_lms)
919 s = strcat(s, ftos(other.team), ":");
921 s = strcat(s, "spectator:");
924 print(s, other.netname, "\n");
926 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
928 fputs(file, strcat(s, other.netname, "\n"));
934 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
940 fputs(file, strcat(s, "\n"));
942 for(i = 1; i < 16; ++i)
944 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
945 s = strcat(s, ":", ftos(i));
951 fputs(file, strcat(s, "\n"));
961 fputs(file, ":end\n");
966 void FixIntermissionClient(entity e)
969 if(!e.autoscreenshot) // initial call
971 e.angles = e.v_angle;
972 e.angles_x = -e.angles_x;
973 e.autoscreenshot = time + 0.8; // used for autoscreenshot
975 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
977 e.movetype = MOVETYPE_NONE;
978 e.takedamage = DAMAGE_NO;
980 e.weaponentity.effects = EF_NODRAW;
981 if(clienttype(e) == CLIENTTYPE_REAL)
983 stuffcmd(e, "\nscr_printspeed 1000000\n");
984 s = cvar_string("sv_intermission_cdtrack");
986 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
988 WriteByte(MSG_ONE, SVC_INTERMISSION);
992 //e.velocity = '0 0 0';
995 // TODO halt weapon animation
1000 go to the next level for deathmatch
1001 only called if a time or frag limit has expired
1005 float minTotalFrags;
1006 float maxTotalFrags;
1012 intermission_running = 1;
1014 // enforce a wait time before allowing changelevel
1015 if(player_count > 0)
1016 intermission_exittime = time + cvar("sv_mapchange_delay");
1018 intermission_exittime = -1;
1021 WriteByte (MSG_ALL, SVC_CDTRACK);
1022 WriteByte (MSG_ALL, 3);
1023 WriteByte (MSG_ALL, 3);
1024 // done in FixIntermission
1027 //pos = FindIntermission ();
1033 if(cvar("sv_eventlog"))
1034 GameLogEcho(":gameover");
1038 FOR_EACH_CLIENT(other)
1040 FixIntermissionClient(other);
1043 bprint(other.netname, " ^7wins.\n");
1048 FOR_EACH_PLAYER(other)
1050 if(maxTotalFrags < other.totalfrags)
1051 maxTotalFrags = other.totalfrags;
1052 if(minTotalFrags > other.totalfrags)
1053 minTotalFrags = other.totalfrags;
1058 FOR_EACH_PLAYER(other)
1060 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1061 f = bound(0, other.play_time / max(time, 1), 1);
1062 // store some statistics?
1066 if(cvar("g_campaign"))
1067 CampaignPreIntermission();
1069 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1076 Exit deathmatch games upon conditions
1079 void CheckRules_Player()
1081 if (gameover) // someone else quit the game already
1084 if(self.deadflag == DEAD_NO)
1085 self.play_time += frametime;
1087 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1088 // (div0: and that in CheckRules_World please)
1091 float checkrules_oneminutewarning;
1093 float checkrules_equality;
1094 float checkrules_overtimewarning;
1095 float checkrules_overtimeend;
1097 void InitiateOvertime()
1099 if(!checkrules_overtimeend)
1100 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1103 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1104 float WINNING_YES = 1; // winner found
1105 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1106 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1108 float GetWinningCode(float fraglimitreached, float equality)
1111 if(fraglimitreached)
1112 return WINNING_STARTOVERTIME;
1114 return WINNING_NEVER;
1116 if(fraglimitreached)
1122 // set the .winning flag for exactly those players with a given field value
1123 void SetWinners(.float field, float value)
1126 FOR_EACH_PLAYER(head)
1127 head.winning = (head.field == value);
1130 // set the .winning flag for those players with a given field value
1131 void AddWinners(.float field, float value)
1134 FOR_EACH_PLAYER(head)
1135 if(head.field == value)
1139 // clear the .winning flags
1140 void ClearWinners(void)
1143 FOR_EACH_PLAYER(head)
1147 // Onslaught winning condition:
1148 // game terminates if only one team has a working generator (or none)
1149 float WinningCondition_Onslaught()
1152 local float t1, t2, t3, t4;
1153 // first check if the game has ended
1154 t1 = t2 = t3 = t4 = 0;
1155 head = find(world, classname, "onslaught_generator");
1158 if (head.health > 0)
1160 if (head.team == COLOR_TEAM1) t1 = 1;
1161 if (head.team == COLOR_TEAM2) t2 = 1;
1162 if (head.team == COLOR_TEAM3) t3 = 1;
1163 if (head.team == COLOR_TEAM4) t4 = 1;
1165 head = find(head, classname, "onslaught_generator");
1167 if (t1 + t2 + t3 + t4 < 2)
1169 // game over, only one team remains (or none)
1171 if (t1) SetWinners(team, COLOR_TEAM1);
1172 if (t2) SetWinners(team, COLOR_TEAM2);
1173 if (t3) SetWinners(team, COLOR_TEAM3);
1174 if (t4) SetWinners(team, COLOR_TEAM4);
1175 dprint("Have a winner, ending game.\n");
1179 // Two or more teams remain
1183 float LMS_NewPlayerLives()
1186 fl = cvar("fraglimit");
1190 // first player has left the game for dying too much? Nobody else can get in.
1191 if(lms_lowest_lives < 1)
1194 if(!cvar("g_lms_join_anytime"))
1195 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1198 return bound(1, lms_lowest_lives, fl);
1201 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1202 // they win. Otherwise the defending team wins once the timelimit passes.
1203 void assault_new_round();
1204 float WinningCondition_Assault()
1207 status = WINNING_NO;
1209 // as the timelimit has not yet passed just assume the defending team will win
1210 if(assault_attacker_team == COLOR_TEAM1)
1212 SetWinners(team, COLOR_TEAM2);
1216 SetWinners(team, COLOR_TEAM1);
1220 ent = find(world, classname, "target_assault_roundend");
1223 if(ent.winning) // round end has been triggered by attacking team
1225 SetWinners(team, assault_attacker_team);
1226 if(assault_attacker_team == COLOR_TEAM1)
1228 team1_score = team1_score + 50;
1232 team2_score = team2_score + 50;
1235 if(ent.cnt == 1) // this was the second round
1237 status = WINNING_YES;
1241 local entity oldself;
1244 cvar_set("timelimit", ftos((2*time)/60));
1245 assault_new_round();
1255 // LMS winning condition: game terminates if and only if there's at most one
1256 // one player who's living lives. Top two scores being equal cancels the time
1258 float WinningCondition_LMS()
1265 have_player = FALSE;
1266 have_players = FALSE;
1267 l = LMS_NewPlayerLives();
1269 head = find(world, classname, "player");
1272 head2 = find(head, classname, "player");
1274 have_players = TRUE;
1278 // we have at least one player
1281 // two or more active players - continue with the game
1285 // exactly one player?
1288 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1292 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1298 // and assign him his first place
1299 PlayerScore_Add(head, SP_LMS_RANK, 1);
1306 // nobody is playing at all...
1309 // wait for players...
1313 // SNAFU (maybe a draw game?)
1315 dprint("No players, ending game.\n");
1320 // When we get here, we have at least two players who are actually LIVING,
1321 // now check if the top two players have equal score.
1322 WinningConditionHelper();
1325 if(WinningConditionHelper_winner)
1326 WinningConditionHelper_winner.winning = TRUE;
1327 if(WinningConditionHelper_equality)
1328 return WINNING_NEVER;
1330 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1334 void print_to(entity e, string s)
1337 sprint(e, strcat(s, "\n"));
1342 void ShuffleMaplist()
1350 result = cvar_string("g_maplist");
1351 litems = tokenizebyseparator(result, " ");
1353 for(start = 0; start < litems - 1; ++start)
1357 // select a random item
1358 selected = ceil(random() * (litems - start) + start) - 1;
1360 // shift this item to the place start
1361 for(i = 0; i < start; ++i)
1362 result = strcat(result, " ", argv(i));
1363 result = strcat(result, " ", argv(selected));
1364 for(i = start; i < litems; ++i)
1366 result = strcat(result, " ", argv(i));
1367 result = substring(result, 1, strlen(result) - 1);
1369 litems = tokenizebyseparator(result, " ");
1371 //dprint(result, "\n");
1374 cvar_set("g_maplist", result);
1377 float WinningCondition_Scores(float limit)
1379 // TODO make everything use THIS winning condition (except LMS)
1380 WinningConditionHelper();
1384 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1385 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1386 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1387 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1391 if(WinningConditionHelper_winner)
1392 WinningConditionHelper_winner.winning = 1;
1393 if(WinningConditionHelper_winnerteam >= 0)
1394 SetWinners(team, WinningConditionHelper_winnerteam);
1396 if(WinningConditionHelper_lowerisbetter)
1398 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1402 return GetWinningCode(limit && WinningConditionHelper_topscore && (WinningConditionHelper_topscore >= limit), WinningConditionHelper_equality);
1405 float WinningCondition_Race(float fraglimit)
1409 wc = WinningCondition_Scores(fraglimit);
1411 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1412 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1413 // do NOT support equality when the laps are all raced!
1416 if not(p.race_completed)
1417 return WINNING_STARTOVERTIME;
1423 void ReadyRestart();
1424 float WinningCondition_QualifyingThenRace(float limit)
1427 wc = WinningCondition_Scores(limit);
1429 // NEVER initiate overtime
1430 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1431 // do NOT support equality when the laps are all raced!
1434 float playerswithlaps;
1437 totalplayers = playerswithlaps = readyplayers = 0;
1438 FOR_EACH_PLAYER(head)
1441 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
1447 // at least 2/3 of the players have completed a lap: start the RACE
1448 // otherwise, the players should end the qualifying on their own
1449 if(readyplayers || ((totalplayers >= 3) && (playerswithlaps * 3 >= totalplayers * 2)))
1451 checkrules_overtimeend = 0;
1453 return WINNING_NEVER;
1462 float WinningCondition_RanOutOfSpawns()
1466 if(!have_team_spawns)
1469 if(!some_spawn_has_been_used)
1472 team1_score = team2_score = team3_score = team4_score = 0;
1474 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1476 if(head.team == COLOR_TEAM1)
1478 else if(head.team == COLOR_TEAM2)
1480 else if(head.team == COLOR_TEAM3)
1482 else if(head.team == COLOR_TEAM4)
1486 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
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)
1499 if(team1_score + team2_score + team3_score + team4_score == 0)
1501 checkrules_equality = TRUE;
1504 else if(team1_score + team2_score + team3_score + team4_score == 1)
1507 if(team1_score) t = COLOR_TEAM1;
1508 if(team2_score) t = COLOR_TEAM2;
1509 if(team3_score) t = COLOR_TEAM3;
1510 if(team4_score) t = COLOR_TEAM4;
1511 CheckAllowedTeams(world);
1512 for(i = 0; i < MAX_TEAMSCORE; ++i)
1514 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
1515 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
1516 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
1517 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
1520 AddWinners(team, t);
1531 Exit deathmatch games upon conditions
1534 void CheckRules_World()
1537 local float timelimit;
1538 local float fraglimit;
1546 MapVote_Think should now do that part
1547 if (intermission_running)
1548 if (time >= intermission_exittime + 60)
1550 if(!DoNextMapOverride())
1556 if (gameover) // someone else quit the game already
1558 if(player_count == 0) // Nobody there? Then let's go to the next map
1560 // this will actually check the player count in the next frame
1561 // again, but this shouldn't hurt
1565 timelimit = cvar("timelimit") * 60;
1566 fraglimit = cvar("fraglimit");
1569 fraglimit = 0; // no fraglimit for now
1571 if(checkrules_overtimeend)
1573 if(!checkrules_overtimewarning)
1575 checkrules_overtimewarning = TRUE;
1576 //announceall("announcer/robotic/1minuteremains.wav");
1577 if(!g_race_qualifying)
1578 bcenterprint("^3Everyone, finish your lap! The race is over!");
1580 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1585 if (timelimit && time >= timelimit)
1589 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1595 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1597 checkrules_oneminutewarning = TRUE;
1598 play2all("announcer/robotic/1minuteremains.wav");
1601 status = WinningCondition_RanOutOfSpawns();
1602 if(status == WINNING_YES)
1604 bprint("Hey! Someone ran out of spawns!\n");
1606 else if(g_race && !g_race_qualifying && timelimit >= 0)
1608 status = WinningCondition_Race(fraglimit);
1610 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
1612 status = WinningCondition_QualifyingThenRace(fraglimit);
1616 status = WinningCondition_Assault(); // TODO remove this?
1620 status = WinningCondition_LMS();
1622 else if (g_onslaught)
1624 status = WinningCondition_Onslaught(); // TODO remove this?
1628 status = WinningCondition_Scores(fraglimit);
1631 if(status == WINNING_STARTOVERTIME)
1633 status = WINNING_NEVER;
1637 if(status == WINNING_NEVER)
1638 // equality cases! Nobody wins if the overtime ends in a draw.
1641 if(checkrules_overtimeend)
1642 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1643 status = WINNING_YES;
1645 if(status == WINNING_YES)
1649 float mapvote_nextthink;
1650 float mapvote_initialized;
1651 float mapvote_keeptwotime;
1652 float mapvote_timeout;
1653 string mapvote_message;
1654 string mapvote_screenshot_dir;
1656 float mapvote_count;
1657 float mapvote_count_real;
1658 string mapvote_maps[MAPVOTE_COUNT];
1659 float mapvote_maps_suggested[MAPVOTE_COUNT];
1660 string mapvote_suggestions[MAPVOTE_COUNT];
1661 float mapvote_suggestion_ptr;
1662 float mapvote_maxlen;
1663 float mapvote_voters;
1664 float mapvote_votes[MAPVOTE_COUNT];
1666 float mapvote_detail;
1667 float mapvote_abstain;
1668 float mapvote_dirty;
1671 void MapVote_ClearAllVotes()
1673 FOR_EACH_CLIENT(other)
1677 string MapVote_Suggest(string m)
1681 return "That's not how to use this command.";
1682 if(!cvar("g_maplist_votable_suggestions"))
1683 return "Suggestions are not accepted on this server.";
1684 if(mapvote_initialized)
1685 return "Can't suggest - voting is already in progress!";
1686 m = MapInfo_FixName(m);
1688 return "The map you suggested is not available on this server.";
1689 if(!cvar("g_maplist_votable_override_mostrecent"))
1691 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1693 if(!MapInfo_CheckMap(m))
1694 return "The map you suggested does not support the current game mode.";
1695 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1696 if(mapvote_suggestions[i] == m)
1697 return "This map was already suggested.";
1698 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1700 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1704 i = mapvote_suggestion_ptr;
1705 mapvote_suggestion_ptr += 1;
1707 if(mapvote_suggestions[i] != "")
1708 strunzone(mapvote_suggestions[i]);
1709 mapvote_suggestions[i] = strzone(m);
1710 if(cvar("sv_eventlog"))
1711 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
1712 return strcat("Suggestion of ", m, " accepted.");
1715 void MapVote_AddVotable(string nextMap, float isSuggestion)
1720 for(j = 0; j < mapvote_count; ++j)
1721 if(mapvote_maps[j] == nextMap)
1723 if(strlen(nextMap) > mapvote_maxlen)
1724 mapvote_maxlen = strlen(nextMap);
1725 mapvote_maps[mapvote_count] = strzone(nextMap);
1726 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1730 void MapVote_SendData(float target);
1736 MapVote_ClearAllVotes();
1739 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1740 mapvote_abstain = cvar("g_maplist_votable_abstain");
1743 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1745 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1746 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
1748 if(mapvote_suggestion_ptr)
1749 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1750 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1752 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1753 MapVote_AddVotable(GetNextMap(), FALSE);
1755 if(mapvote_count == 0)
1757 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1758 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1759 localcmd("\nmenu_cmd sync\n");
1760 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1761 MapVote_AddVotable(GetNextMap(), FALSE);
1764 mapvote_count_real = mapvote_count;
1766 MapVote_AddVotable("don't care", 0);
1768 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1770 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1771 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1772 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1773 mapvote_keeptwotime = 0;
1774 mapvote_message = "Choose a map and press its key!";
1776 mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
1777 if(mapvote_screenshot_dir == "")
1778 mapvote_screenshot_dir = "maps";
1779 mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
1781 if(!cvar("g_maplist_textonly"))
1782 MapVote_SendData(MSG_ALL);
1785 void MapVote_SendPicture(float id)
1788 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1789 WriteByte(MSG_ONE, TE_CSQC_MAPVOTE);
1790 WriteByte(MSG_ONE, MAPVOTE_NET_PIC);
1791 WriteByte(MSG_ONE, id);
1792 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 3072);
1795 float GameCommand_MapVote(string cmd)
1797 if(!intermission_running)
1799 if(!cvar("g_maplist_textonly"))
1801 if(cmd == "mv_getpic")
1803 MapVote_SendPicture(stof(argv(1)));
1811 float MapVote_GetMapMask()
1813 float mask, i, power;
1815 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
1816 if(mapvote_maps[i] != "")
1821 void MapVote_SendData(float targ)
1823 string mapfile, pakfile;
1825 WriteByte(targ, SVC_TEMPENTITY);
1826 WriteByte(targ, TE_CSQC_CONFIG);
1827 WriteString(targ, "mv_screenshot_dir");
1828 WriteString(targ, mapvote_screenshot_dir);
1830 WriteByte(targ, SVC_TEMPENTITY);
1831 WriteByte(targ, TE_CSQC_MAPVOTE);
1832 WriteByte(targ, MAPVOTE_NET_INIT);
1834 WriteByte(targ, mapvote_count);
1835 WriteByte(targ, mapvote_abstain);
1836 WriteByte(targ, mapvote_detail);
1837 WriteCoord(targ, mapvote_timeout);
1838 if(mapvote_count <= 8)
1839 WriteByte(targ, MapVote_GetMapMask());
1841 WriteShort(targ, MapVote_GetMapMask());
1842 for(i = 0; i < mapvote_count; ++i)
1843 if(mapvote_maps[i] != "")
1845 WriteString(targ, mapvote_maps[i]);
1846 mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
1847 pakfile = whichpack(strcat(mapfile, ".tga"));
1849 pakfile = whichpack(strcat(mapfile, ".jpg"));
1851 pakfile = whichpack(strcat(mapfile, ".png"));
1852 print("pakfile is ", pakfile, "\n");
1853 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
1854 pakfile = substring(pakfile, o, 999);
1855 WriteString(targ, pakfile);
1859 void MapVote_UpdateData(float targ)
1862 WriteByte(targ, SVC_TEMPENTITY);
1863 WriteByte(targ, TE_CSQC_MAPVOTE);
1864 WriteByte(targ, MAPVOTE_NET_UPDATE);
1865 if(mapvote_count <= 8)
1866 WriteByte(targ, MapVote_GetMapMask());
1868 WriteShort(targ, MapVote_GetMapMask());
1870 for(i = 0; i < mapvote_count; ++i)
1871 if(mapvote_maps[i] != "")
1872 WriteByte(targ, mapvote_votes[i]);
1875 void MapVote_TellVote(float targ, float vote)
1877 WriteByte(targ, SVC_TEMPENTITY);
1878 WriteByte(targ, TE_CSQC_MAPVOTE);
1879 WriteByte(targ, MAPVOTE_NET_OWNVOTE);
1880 WriteByte(targ, vote);
1883 float MapVote_Finished(float mappos)
1889 if(cvar("sv_eventlog"))
1891 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1892 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1893 didntvote = mapvote_voters;
1894 for(i = 0; i < mapvote_count; ++i)
1895 if(mapvote_maps[i] != "")
1897 didntvote -= mapvote_votes[i];
1900 result = strcat(result, ":", mapvote_maps[i]);
1901 result = strcat(result, ":", ftos(mapvote_votes[i]));
1904 result = strcat(result, ":didn't vote:", ftos(didntvote));
1906 GameLogEcho(result);
1907 if(mapvote_maps_suggested[mappos])
1908 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
1911 FOR_EACH_REALCLIENT(other)
1912 FixClientCvars(other);
1914 Map_Goto_SetStr(mapvote_maps[mappos]);
1916 alreadychangedlevel = TRUE;
1919 void MapVote_CheckRules_1()
1923 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1925 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1926 mapvote_votes[i] = 0;
1930 FOR_EACH_REALCLIENT(other)
1935 i = other.mapvote - 1;
1936 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1937 mapvote_votes[i] = mapvote_votes[i] + 1;
1942 float MapVote_CheckRules_2()
1945 float firstPlace, secondPlace;
1946 float firstPlaceVotes, secondPlaceVotes;
1947 float mapvote_voters_real;
1950 mapvote_voters_real = mapvote_voters;
1952 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
1954 RandomSelection_Init();
1955 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1956 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
1957 firstPlace = RandomSelection_chosen_float;
1958 firstPlaceVotes = RandomSelection_best_priority;
1959 //dprint("First place: ", ftos(firstPlace), "\n");
1960 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1962 RandomSelection_Init();
1963 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1965 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
1966 secondPlace = RandomSelection_chosen_float;
1967 secondPlaceVotes = RandomSelection_best_priority;
1968 //dprint("Second place: ", ftos(secondPlace), "\n");
1969 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1971 if(firstPlace == -1)
1972 error("No first place in map vote... WTF?");
1974 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
1975 return MapVote_Finished(firstPlace);
1977 if(mapvote_keeptwotime)
1978 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
1981 mapvote_dirty = TRUE;
1982 mapvote_message = "Now decide between the TOP TWO!";
1983 mapvote_keeptwotime = 0;
1984 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
1985 result = strcat(result, ":", ftos(firstPlaceVotes));
1986 result = strcat(result, ":", mapvote_maps[secondPlace]);
1987 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
1988 didntvote = mapvote_voters;
1989 for(i = 0; i < mapvote_count; ++i)
1990 if(mapvote_maps[i] != "")
1992 didntvote -= mapvote_votes[i];
1994 if(i != secondPlace)
1996 result = strcat(result, ":", mapvote_maps[i]);
1997 result = strcat(result, ":", ftos(mapvote_votes[i]));
1998 if(i < mapvote_count_real)
2000 strunzone(mapvote_maps[i]);
2001 mapvote_maps[i] = "";
2005 result = strcat(result, ":didn't vote:", ftos(didntvote));
2006 if(cvar("sv_eventlog"))
2007 GameLogEcho(result);
2020 keeptwo = mapvote_keeptwotime;
2021 MapVote_CheckRules_1(); // count
2022 if(MapVote_CheckRules_2()) // decide
2026 FOR_EACH_REALCLIENT(other)
2028 // hide scoreboard again
2029 if(other.health != 2342)
2031 other.health = 2342;
2033 if(clienttype(other) == CLIENTTYPE_REAL)
2035 if(cvar("g_maplist_textonly"))
2036 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");
2039 WriteByte(MSG_ONE, SVC_FINALE);
2040 WriteString(MSG_ONE, "");
2044 // notify about keep-two
2045 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2046 play2(other, "misc/invshot.wav");
2048 // clear possibly invalid votes
2049 if(mapvote_maps[other.mapvote - 1] == "")
2051 // use impulses as new vote
2052 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2053 if(mapvote_maps[other.impulse - 1] != "")
2055 other.mapvote = other.impulse;
2057 mapvote_dirty = TRUE;
2060 MapVote_TellVote(MSG_ONE, other.mapvote);
2068 MapVote_CheckRules_1(); // just count
2070 if(!cvar("g_maplist_textonly"))
2071 if(mapvote_dirty) // 1 if "keeptwo" or "impulse" happened before
2073 MapVote_UpdateData(MSG_BROADCAST);
2074 mapvote_dirty = FALSE;
2077 if(cvar("g_maplist_textonly"))
2079 FOR_EACH_REALCLIENT(other)
2081 // display voting screen
2082 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2083 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2085 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2086 msgstr = strcat(msgstr, mapvote_message);
2087 msgstr = strcat(msgstr, "\n\n");
2088 for(i = 0; i < mapvote_count; ++i)
2089 if(mapvote_maps[i] == "")
2090 msgstr = strcat(msgstr, "\n");
2093 tmp = mapvote_maps[i];
2094 tmp = strpad(mapvote_maxlen, tmp);
2095 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2098 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2099 if(mapvote_votes[i] != 1)
2100 tmp = strcat(tmp, "s");
2101 tmp = strcat(tmp, ")");
2102 tmp = strpad(mapvote_maxlen + 15, tmp);
2105 if(i == mapvote_count - 1)
2106 msgstr = strcat(msgstr, "\n");
2107 if(other.mapvote == i + 1)
2108 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2110 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2113 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2115 msgstr = strcat(msgstr, "s");
2116 msgstr = strcat(msgstr, " cast");
2117 i = ceil(mapvote_timeout - time);
2118 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2120 msgstr = strcat(msgstr, "s");
2121 msgstr = strcat(msgstr, " left");
2123 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2127 void MapVote_Start()
2132 MapInfo_Enumerate();
2133 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2136 void MapVote_Think()
2141 if(alreadychangedlevel)
2144 if(time < mapvote_nextthink)
2148 mapvote_nextthink = time + 0.5;
2150 if(!mapvote_initialized)
2152 mapvote_initialized = TRUE;
2153 if(DoNextMapOverride())
2155 if(!cvar("g_maplist_votable") || player_count <= 0)
2166 string GotoMap(string m)
2168 if(!MapInfo_CheckMap(m))
2169 return "The map you chose is not available on this server.";
2170 cvar_set("nextmap", m);
2171 cvar_set("timelimit", "-1");
2172 if(mapvote_initialized || alreadychangedlevel)
2174 if(DoNextMapOverride())
2175 return "Map switch initiated.";
2177 return "Hm... no. For some reason I like THIS map more.";
2180 return "Map switch will happen after scoreboard.";
2186 FOR_EACH_REALCLIENT(self)
2188 if(self.classname == "spectator")
2190 if(self.enemy.hitsound)
2191 play2(self, "misc/hit.wav");
2196 play2(self, "misc/hit.wav");
2199 FOR_EACH_CLIENT(self)
2200 self.hitsound = FALSE;
2206 * returns TRUE if redirecting
2208 float redirection_timeout;
2209 float redirection_nextthink;
2210 float RedirectionThink()
2212 float clients_found;
2214 if(redirection_target == "")
2217 if(!redirection_timeout)
2219 cvar_set("sv_public", "-2");
2220 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2221 if(redirection_target == "self")
2222 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2224 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2227 if(time < redirection_nextthink)
2230 redirection_nextthink = time + 1;
2233 FOR_EACH_REALCLIENT(self)
2235 print("Redirecting: sending connect command to ", self.netname, "\n");
2236 if(redirection_target == "self")
2237 stuffcmd(self, "\ndisconnect; reconnect\n");
2239 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2243 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2245 if(time > redirection_timeout || clients_found == 0)
2246 localcmd("\nwait; wait; wait; quit\n");
2253 // Loaded from a save game
2254 // some things then break, so let's work around them...
2256 // Progs DB (capture records)
2258 ServerProgsDB = db_create();
2260 ServerProgsDB = db_load("server.db");
2264 MapInfo_Enumerate();
2265 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
2270 if(world_initialized)
2272 world_initialized = 0;
2273 print("Saving persistent data...\n");
2276 db_save(ServerProgsDB, "server.db");
2277 db_close(ServerProgsDB);
2279 // tell the bot system the game is ending now
2286 print("NOTE: crashed before even initializing the world, not saving persistent data\n");