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 spawnfunc_worldspawn (void)
165 dprint_load(); // load dprint status from cvar
167 if(world_already_spawned)
168 error("world already spawned - you may have EXACTLY ONE worldspawn!");
169 world_already_spawned = TRUE;
171 compressShortVector_init();
174 head = nextent(world);
179 head = nextent(head);
186 ServerProgsDB = db_create();
188 ServerProgsDB = db_load("server.db");
191 TODO sound pack system
192 // initialize sound pack system
193 soundpack = cvar_string("g_soundpack");
195 soundpack = strcat(soundpack, "/");
196 soundpack = strzone(soundpack);
202 // 1 FLICKER (first variety)
203 lightstyle(1, "mmnmmommommnonmmonqnmmo");
205 // 2 SLOW STRONG PULSE
206 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
208 // 3 CANDLE (first variety)
209 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
212 lightstyle(4, "mamamamamama");
215 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
217 // 6 FLICKER (second variety)
218 lightstyle(6, "nmonqnmomnmomomno");
220 // 7 CANDLE (second variety)
221 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
223 // 8 CANDLE (third variety)
224 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
226 // 9 SLOW STROBE (fourth variety)
227 lightstyle(9, "aaaaaaaazzzzzzzz");
229 // 10 FLUORESCENT FLICKER
230 lightstyle(10, "mmamammmmammamamaaamammma");
232 // 11 SLOW PULSE NOT FADE TO BLACK
233 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
235 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
240 if(cvar("g_campaign"))
247 bot_waypoints_for_items = cvar("g_waypoints_for_items");
248 if(bot_waypoints_for_items == 1)
249 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
250 bot_waypoints_for_items = 0;
252 // for setting by mapinfo
253 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
254 cvar_set("sv_q3acompat_machineshotgunswap", "0");
258 WaypointSprite_Init();
263 GameLogInit(); // prepare everything
264 if(cvar("sv_eventlog"))
266 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
267 s = strcat(s, ftos(random()));
268 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
269 s = ":gameinfo:mutators:LIST";
270 if(cvar("g_grappling_hook"))
271 s = strcat(s, ":grappling_hook");
272 if(!cvar("g_use_ammunition"))
273 s = strcat(s, ":no_use_ammunition");
274 if(!cvar("g_pickup_items"))
275 s = strcat(s, ":no_pickup_items");
276 if(cvar("g_instagib"))
277 s = strcat(s, ":instagib");
278 if(cvar("g_rocketarena"))
279 s = strcat(s, ":rockerarena");
281 s = strcat(s, ":nixnex");
282 if(cvar("g_vampire"))
283 s = strcat(s, ":vampire");
284 if(cvar("g_laserguided_missile"))
285 s = strcat(s, ":laserguided_missile");
286 if(cvar("g_norecoil"))
287 s = strcat(s, ":norecoil");
289 s = strcat(s, ":midair");
290 if(cvar("g_minstagib"))
291 s = strcat(s, ":minstagib");
293 GameLogEcho(":gameinfo:end");
296 cvar_set("nextmap", "");
300 if(cvar("g_campaign"))
307 //initialise globals related to sv_timeout
308 sys_ticrate = cvar("sys_ticrate");
309 orig_slowmo = cvar("slowmo");
312 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
314 //if tourney is used map starts in warmup mode. if this mode shall stay unlimited, reset timelimit, but save the original one
315 if(g_tourney && cvar("g_tourney_warmup_unlimited_time")) {
316 timelimit_orig = cvar("timelimit");
317 cvar_set("timelimit", "0");
320 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
322 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
325 while((s = fgets(fd)))
332 print("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
333 print(" cdtrack ", argv(2), "\n");
335 else if(argv(0) == "fog")
337 print("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
338 print(" \"fog\" \"", s, "\"\n");
340 else if(argv(0) == "set")
342 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
343 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
345 else if(argv(0) != "//")
347 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
348 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
355 addstat(STAT_SYS_TICRATE, AS_FLOAT, stat_sys_ticrate);
356 addstat(STAT_WEAPONS, AS_INT, weapons);
358 next_pingtime = time + 5;
359 world_initialized = 1;
362 void spawnfunc_light (void)
364 //makestatic (self); // Who the f___ did that?
368 float TryFile( string pFilename )
371 dprint("TryFile(\"", pFilename, "\")\n");
372 lHandle = fopen( pFilename, FILE_READ );
373 if( lHandle != -1 ) {
383 return GametypeNameFromType(game);
386 string getmapname_stored;
392 float Map_Count, Map_Current;
393 string Map_Current_Name;
395 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
396 float GetMaplistPosition()
402 idx = cvar("g_maplist_index");
409 for(pos = 0; pos < Map_Count; ++pos)
413 // resume normal maplist rotation if current map is not in g_maplist
417 float MapHasRightSize(string map)
420 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
421 if(cvar("g_maplist_check_waypoints"))
423 dprint("checkwp "); dprint(map);
424 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
427 dprint(": no waypoints\n");
430 dprint(": has waypoints\n");
434 // open map size restriction file
435 dprint("opensize "); dprint(map);
436 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
439 float mapmin, mapmax;
441 mapmin = stof(fgets(fh));
442 mapmax = stof(fgets(fh));
444 if(player_count < mapmin)
446 dprint("not enough\n");
449 if(player_count > mapmax)
451 dprint("too many\n");
454 dprint("right size\n");
457 dprint(": not found\n");
461 string Map_Filename(float position)
463 return strcat("maps/", argv(position), ".bsp");
466 string strwords(string s, float w)
469 for(endpos = 0; w && endpos >= 0; --w)
470 endpos = strstrofs(s, " ", endpos + 1);
474 return substring(s, 0, endpos);
477 float strhasword(string s, string w)
479 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
482 void Map_MarkAsRecent(string m)
484 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
487 float Map_IsRecent(string m)
489 return strhasword(cvar_string("g_maplist_mostrecent"), m);
492 float Map_Check(float position, float pass)
496 map_next = argv(position);
499 if(map_next == Map_Current_Name) // same map again in first pass?
501 if(Map_IsRecent(map_next))
504 filename = Map_Filename(position);
505 if(MapInfo_CheckMap(map_next))
509 if(MapHasRightSize(map_next))
514 dprint( "Couldn't select '", filename, "'..\n" );
519 void Map_Goto_SetStr(string nextmapname)
521 if(getmapname_stored != "")
522 strunzone(getmapname_stored);
523 if(nextmapname == "")
524 getmapname_stored = "";
526 getmapname_stored = strzone(nextmapname);
529 void Map_Goto_SetFloat(float position)
531 cvar_set("g_maplist_index", ftos(position));
532 Map_Goto_SetStr(argv(position));
537 // settings persist, except...
538 if(cvar("g_campaign"))
539 localcmd("\nexec mutator_reset.cfg\n");
540 localcmd("\nsettemp_restore\n");
545 Map_MarkAsRecent(getmapname_stored);
547 MapInfo_LoadMap(getmapname_stored);
550 // return codes of map selectors:
551 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
552 // -2 = permanent failure
553 float() MaplistMethod_Iterate = // usual method
557 for(pass = 1; pass <= 2; ++pass)
559 for(i = 1; i < Map_Count; ++i)
562 mapindex = mod(i + Map_Current, Map_Count);
563 if(Map_Check(mapindex, pass))
570 float() MaplistMethod_Repeat = // fallback method
572 if(Map_Check(Map_Current, 2))
577 float() MaplistMethod_Random = // random map selection
583 for(i = 0; i <= imax; ++i)
586 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
587 if(Map_Check(mapindex, 1))
593 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
594 // the exponent sets a bias on the map selection:
595 // the higher the exponent, the less likely "shortly repeated" same maps are
597 float i, j, imax, insertpos;
601 for(i = 0; i <= imax; ++i)
605 // now reinsert this at another position
606 insertpos = pow(random(), 1 / exponent); // ]0, 1]
607 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
608 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
609 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
611 // insert the current map there
613 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
614 newlist = strcat(newlist, " ", argv(j));
615 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
616 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
617 newlist = strcat(newlist, " ", argv(j));
618 newlist = substring(newlist, 1, strlen(newlist) - 1);
619 cvar_set("g_maplist", newlist);
620 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
622 // NOTE: the selected map has just been inserted at (insertpos-1)th position
623 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
624 if(Map_Check(Map_Current, 1))
633 temp = cvar_string("g_maplist");
634 Map_Count = tokenizebyseparator(temp, " ");
637 bprint( "Maplist is empty! Resetting it to default map list.\n" );
638 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
639 localcmd("\nmenu_cmd sync\n");
640 Map_Count = tokenizebyseparator(temp, " ");
643 error("empty maplist, cannot select a new map");
644 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
647 strunzone(Map_Current_Name);
648 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
649 // this may or may not be correct, but who cares, in the worst case a map
650 // isn't chosen in the first pass that should have been
661 if(cvar("g_maplist_shuffle") > 0)
662 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
665 if(cvar("g_maplist_selectrandom"))
666 nextMap = MaplistMethod_Random();
669 nextMap = MaplistMethod_Iterate();
672 nextMap = MaplistMethod_Repeat();
676 Map_Goto_SetFloat(nextMap);
677 return getmapname_stored;
683 float DoNextMapOverride()
685 if(cvar("g_campaign"))
687 CampaignPostIntermission();
688 alreadychangedlevel = TRUE;
691 if(cvar("quit_when_empty"))
693 if(player_count <= currentbots)
696 alreadychangedlevel = TRUE;
700 if(cvar_string("quit_and_redirect") != "")
702 redirection_target = strzone(cvar_string("quit_and_redirect"));
703 alreadychangedlevel = TRUE;
706 if (cvar("samelevel")) // if samelevel is set, stay on same level
708 // 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)
709 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
710 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
711 localcmd("restart\n");
712 //changelevel (mapname);
713 alreadychangedlevel = TRUE;
716 if(cvar_string("nextmap") != "")
717 if(MapInfo_CheckMap(cvar_string("nextmap")))
719 Map_Goto_SetStr(cvar_string("nextmap"));
721 alreadychangedlevel = TRUE;
724 if(cvar("lastlevel"))
727 localcmd("set lastlevel 0\ntogglemenu\n");
728 alreadychangedlevel = TRUE;
736 //local string nextmap;
737 //local float n, nummaps;
739 if (alreadychangedlevel)
741 alreadychangedlevel = TRUE;
747 for(allowReset = 1; allowReset >= 0; --allowReset)
749 nextMap = GetNextMap();
755 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
756 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
757 localcmd("\nmenu_cmd sync\n");
761 error("Everything is broken - not even the default map list works. Please report this to the developers.");
773 When the player presses attack or jump, change to the next level
776 .float autoscreenshot;
777 void() MapVote_Start;
778 void() MapVote_Think;
779 float mapvote_initialized;
780 void IntermissionThink()
782 FixIntermissionClient(self);
784 if(cvar("sv_autoscreenshot"))
785 if(self.autoscreenshot > 0)
786 if(time > self.autoscreenshot)
788 self.autoscreenshot = -1;
789 if(clienttype(self) == CLIENTTYPE_REAL)
790 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
794 if (time < intermission_exittime)
797 if(!mapvote_initialized)
798 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
808 Returns the entity to view from
812 entity FindIntermission()
817 // look for info_intermission first
818 spot = find (world, classname, "info_intermission");
820 { // pick a random one
824 spot = find (spot, classname, "info_intermission");
826 spot = find (spot, classname, "info_intermission");
832 // then look for the start position
833 spot = find (world, classname, "info_player_start");
837 // testinfo_player_start is only found in regioned levels
838 spot = find (world, classname, "testplayerstart");
842 // then look for the start position
843 spot = find (world, classname, "info_player_deathmatch");
847 //objerror ("FindIntermission: no spot");
853 ===============================================================================
857 ===============================================================================
860 void DumpStats(float final)
864 local float to_console;
865 local float to_eventlog;
869 to_console = cvar("sv_logscores_console");
870 to_eventlog = cvar("sv_eventlog");
871 to_file = cvar("sv_logscores_file");
875 to_console = TRUE; // always print printstats replies
876 to_eventlog = FALSE; // but never print them to the event log
880 if(cvar("sv_eventlog_console"))
881 to_console = FALSE; // otherwise we get the output twice
887 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
895 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
899 fputs(file, strcat(s, "\n"));
902 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
907 fputs(file, strcat(s, "\n"));
909 FOR_EACH_CLIENT(other)
911 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
913 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
914 s = strcat(s, ftos(rint(time - other.jointime)), ":");
915 if(other.classname == "player" || g_arena || g_lms)
916 s = strcat(s, ftos(other.team), ":");
918 s = strcat(s, "spectator:");
921 print(s, other.netname, "\n");
923 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
925 fputs(file, strcat(s, other.netname, "\n"));
931 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
937 fputs(file, strcat(s, "\n"));
939 for(i = 1; i < 16; ++i)
941 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
942 s = strcat(s, ":", ftos(i));
948 fputs(file, strcat(s, "\n"));
958 fputs(file, ":end\n");
963 void FixIntermissionClient(entity e)
966 if(!e.autoscreenshot) // initial call
968 e.angles = e.v_angle;
969 e.angles_x = -e.angles_x;
970 e.autoscreenshot = time + 0.8; // used for autoscreenshot
972 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
974 e.movetype = MOVETYPE_NONE;
975 e.takedamage = DAMAGE_NO;
977 e.weaponentity.effects = EF_NODRAW;
978 if(clienttype(e) == CLIENTTYPE_REAL)
980 stuffcmd(e, "\nscr_printspeed 1000000\n");
981 s = cvar_string("sv_intermission_cdtrack");
983 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
985 WriteByte(MSG_ONE, SVC_INTERMISSION);
989 //e.velocity = '0 0 0';
992 // TODO halt weapon animation
997 go to the next level for deathmatch
998 only called if a time or frag limit has expired
1002 float minTotalFrags;
1003 float maxTotalFrags;
1009 intermission_running = 1;
1011 // enforce a wait time before allowing changelevel
1012 if(player_count > 0)
1013 intermission_exittime = time + cvar("sv_mapchange_delay");
1015 intermission_exittime = -1;
1018 WriteByte (MSG_ALL, SVC_CDTRACK);
1019 WriteByte (MSG_ALL, 3);
1020 WriteByte (MSG_ALL, 3);
1021 // done in FixIntermission
1024 //pos = FindIntermission ();
1030 if(cvar("sv_eventlog"))
1031 GameLogEcho(":gameover");
1035 FOR_EACH_CLIENT(other)
1037 FixIntermissionClient(other);
1040 bprint(other.netname, " ^7wins.\n");
1045 FOR_EACH_PLAYER(other)
1047 if(maxTotalFrags < other.totalfrags)
1048 maxTotalFrags = other.totalfrags;
1049 if(minTotalFrags > other.totalfrags)
1050 minTotalFrags = other.totalfrags;
1055 FOR_EACH_PLAYER(other)
1057 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1058 f = bound(0, other.play_time / max(time, 1), 1);
1059 // store some statistics?
1063 if(cvar("g_campaign"))
1064 CampaignPreIntermission();
1066 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1073 Exit deathmatch games upon conditions
1077 void CheckRules_Player()
1079 if (gameover) // someone else quit the game already
1082 if(self.deadflag == DEAD_NO)
1083 self.play_time += frametime;
1087 if(time > self.fogtime)
1089 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1090 self.fogtime = time + sv_foginterval;
1093 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1094 // (div0: and that in CheckRules_World please)
1097 float checkrules_oneminutewarning;
1099 float checkrules_equality;
1100 float checkrules_overtimewarning;
1101 float checkrules_overtimeend;
1103 void InitiateOvertime()
1105 if(!checkrules_overtimeend)
1106 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1109 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1110 float WINNING_YES = 1; // winner found
1111 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1112 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1114 float GetWinningCode(float fraglimitreached, float equality)
1117 if(fraglimitreached)
1118 return WINNING_STARTOVERTIME;
1120 return WINNING_NEVER;
1122 if(fraglimitreached)
1128 // set the .winning flag for exactly those players with a given field value
1129 void SetWinners(.float field, float value)
1132 FOR_EACH_PLAYER(head)
1133 head.winning = (head.field == value);
1136 // set the .winning flag for those players with a given field value
1137 void AddWinners(.float field, float value)
1140 FOR_EACH_PLAYER(head)
1141 if(head.field == value)
1145 // clear the .winning flags
1146 void ClearWinners(void)
1149 FOR_EACH_PLAYER(head)
1153 // Onslaught winning condition:
1154 // game terminates if only one team has a working generator (or none)
1155 float WinningCondition_Onslaught()
1158 local float t1, t2, t3, t4;
1159 // first check if the game has ended
1160 t1 = t2 = t3 = t4 = 0;
1161 head = find(world, classname, "onslaught_generator");
1164 if (head.health > 0)
1166 if (head.team == COLOR_TEAM1) t1 = 1;
1167 if (head.team == COLOR_TEAM2) t2 = 1;
1168 if (head.team == COLOR_TEAM3) t3 = 1;
1169 if (head.team == COLOR_TEAM4) t4 = 1;
1171 head = find(head, classname, "onslaught_generator");
1173 if (t1 + t2 + t3 + t4 < 2)
1175 // game over, only one team remains (or none)
1177 if (t1) SetWinners(team, COLOR_TEAM1);
1178 if (t2) SetWinners(team, COLOR_TEAM2);
1179 if (t3) SetWinners(team, COLOR_TEAM3);
1180 if (t4) SetWinners(team, COLOR_TEAM4);
1181 dprint("Have a winner, ending game.\n");
1185 // Two or more teams remain
1189 float LMS_NewPlayerLives()
1192 fl = cvar("fraglimit");
1196 // first player has left the game for dying too much? Nobody else can get in.
1197 if(lms_lowest_lives < 1)
1200 if(!cvar("g_lms_join_anytime"))
1201 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1204 return bound(1, lms_lowest_lives, fl);
1207 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1208 // they win. Otherwise the defending team wins once the timelimit passes.
1209 void assault_new_round();
1210 float WinningCondition_Assault()
1213 status = WINNING_NO;
1215 // as the timelimit has not yet passed just assume the defending team will win
1216 if(assault_attacker_team == COLOR_TEAM1)
1218 SetWinners(team, COLOR_TEAM2);
1222 SetWinners(team, COLOR_TEAM1);
1226 ent = find(world, classname, "target_assault_roundend");
1229 if(ent.winning) // round end has been triggered by attacking team
1231 SetWinners(team, assault_attacker_team);
1232 if(assault_attacker_team == COLOR_TEAM1)
1234 team1_score = team1_score + 50;
1238 team2_score = team2_score + 50;
1241 if(ent.cnt == 1) // this was the second round
1243 status = WINNING_YES;
1247 local entity oldself;
1250 cvar_set("timelimit", ftos((2*time)/60));
1251 assault_new_round();
1261 // LMS winning condition: game terminates if and only if there's at most one
1262 // one player who's living lives. Top two scores being equal cancels the time
1264 float WinningCondition_LMS()
1271 have_player = FALSE;
1272 have_players = FALSE;
1273 l = LMS_NewPlayerLives();
1275 head = find(world, classname, "player");
1278 head2 = find(head, classname, "player");
1280 have_players = TRUE;
1284 // we have at least one player
1287 // two or more active players - continue with the game
1291 // exactly one player?
1294 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1298 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1304 // and assign him his first place
1305 PlayerScore_Add(head, SP_LMS_RANK, 1);
1312 // nobody is playing at all...
1315 // wait for players...
1319 // SNAFU (maybe a draw game?)
1321 dprint("No players, ending game.\n");
1326 // When we get here, we have at least two players who are actually LIVING,
1327 // now check if the top two players have equal score.
1328 WinningConditionHelper();
1331 if(WinningConditionHelper_winner)
1332 WinningConditionHelper_winner.winning = TRUE;
1333 if(WinningConditionHelper_equality)
1334 return WINNING_NEVER;
1336 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1340 void print_to(entity e, string s)
1343 sprint(e, strcat(s, "\n"));
1348 void ShuffleMaplist()
1356 result = cvar_string("g_maplist");
1357 litems = tokenizebyseparator(result, " ");
1359 for(start = 0; start < litems - 1; ++start)
1363 // select a random item
1364 selected = ceil(random() * (litems - start) + start) - 1;
1366 // shift this item to the place start
1367 for(i = 0; i < start; ++i)
1368 result = strcat(result, " ", argv(i));
1369 result = strcat(result, " ", argv(selected));
1370 for(i = start; i < litems; ++i)
1372 result = strcat(result, " ", argv(i));
1373 result = substring(result, 1, strlen(result) - 1);
1375 litems = tokenizebyseparator(result, " ");
1377 //dprint(result, "\n");
1380 cvar_set("g_maplist", result);
1383 float WinningCondition_Scores(float limit)
1385 // TODO make everything use THIS winning condition (except LMS)
1386 WinningConditionHelper();
1390 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1391 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1392 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1393 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1397 if(WinningConditionHelper_winner)
1398 WinningConditionHelper_winner.winning = 1;
1399 if(WinningConditionHelper_winnerteam >= 0)
1400 SetWinners(team, WinningConditionHelper_winnerteam);
1402 if(WinningConditionHelper_topscore == 0)
1403 WinningConditionHelper_equality = 0;
1405 if(WinningConditionHelper_lowerisbetter)
1407 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1411 return GetWinningCode(limit && WinningConditionHelper_topscore && (WinningConditionHelper_topscore >= limit), WinningConditionHelper_equality);
1414 float WinningCondition_Race(float fraglimit)
1418 wc = WinningCondition_Scores(fraglimit);
1420 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1421 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1422 // do NOT support equality when the laps are all raced!
1425 if not(p.race_completed)
1426 return WINNING_STARTOVERTIME;
1432 void ReadyRestart();
1433 float WinningCondition_QualifyingThenRace(float limit)
1436 wc = WinningCondition_Scores(limit);
1438 // NEVER initiate overtime
1439 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1440 // do NOT support equality when the laps are all raced!
1443 float playerswithlaps;
1445 totalplayers = playerswithlaps = 0;
1446 FOR_EACH_PLAYER(head)
1449 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
1453 // at least 2/3 of the players have completed a lap: start the RACE
1454 // otherwise, the players should end the qualifying on their own
1455 if(totalplayers >= 3)
1456 if(playerswithlaps >= totalplayers * 2 / 3)
1458 checkrules_overtimeend = 0;
1460 return WINNING_NEVER;
1469 float WinningCondition_RanOutOfSpawns()
1473 if(!have_team_spawns)
1476 if(!some_spawn_has_been_used)
1479 team1_score = team2_score = team3_score = team4_score = 0;
1481 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1483 if(head.team == COLOR_TEAM1)
1485 else if(head.team == COLOR_TEAM2)
1487 else if(head.team == COLOR_TEAM3)
1489 else if(head.team == COLOR_TEAM4)
1493 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1495 if(head.team == COLOR_TEAM1)
1497 else if(head.team == COLOR_TEAM2)
1499 else if(head.team == COLOR_TEAM3)
1501 else if(head.team == COLOR_TEAM4)
1506 if(team1_score + team2_score + team3_score + team4_score == 0)
1508 checkrules_equality = TRUE;
1511 else if(team1_score + team2_score + team3_score + team4_score == 1)
1514 if(team1_score) t = COLOR_TEAM1;
1515 if(team2_score) t = COLOR_TEAM2;
1516 if(team3_score) t = COLOR_TEAM3;
1517 if(team4_score) t = COLOR_TEAM4;
1518 CheckAllowedTeams(world);
1519 for(i = 0; i < MAX_TEAMSCORE; ++i)
1521 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
1522 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
1523 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
1524 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
1527 AddWinners(team, t);
1538 Exit deathmatch games upon conditions
1541 void CheckRules_World()
1544 local float timelimit;
1545 local float fraglimit;
1553 MapVote_Think should now do that part
1554 if (intermission_running)
1555 if (time >= intermission_exittime + 60)
1557 if(!DoNextMapOverride())
1563 if (gameover) // someone else quit the game already
1565 if(player_count == 0) // Nobody there? Then let's go to the next map
1567 // this will actually check the player count in the next frame
1568 // again, but this shouldn't hurt
1572 timelimit = cvar("timelimit") * 60;
1573 fraglimit = cvar("fraglimit");
1575 if(checkrules_overtimeend)
1577 if(!checkrules_overtimewarning)
1579 checkrules_overtimewarning = TRUE;
1580 //announceall("announcer/robotic/1minuteremains.wav");
1581 if(!g_race_qualifying)
1582 bcenterprint("^3Everyone, finish your lap! The race is over!");
1584 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1589 if (timelimit && time >= timelimit)
1593 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1599 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1601 checkrules_oneminutewarning = TRUE;
1602 play2all("announcer/robotic/1minuteremains.wav");
1605 status = WinningCondition_RanOutOfSpawns();
1606 if(status == WINNING_YES)
1608 bprint("Hey! Someone ran out of spawns!\n");
1610 else if(g_race && !g_race_qualifying && timelimit >= 0)
1612 status = WinningCondition_Race(fraglimit);
1614 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
1616 status = WinningCondition_QualifyingThenRace(fraglimit);
1620 status = WinningCondition_Assault(); // TODO remove this?
1624 status = WinningCondition_LMS();
1626 else if (g_onslaught)
1628 status = WinningCondition_Onslaught(); // TODO remove this?
1632 status = WinningCondition_Scores(fraglimit);
1635 if(status == WINNING_STARTOVERTIME)
1637 status = WINNING_NEVER;
1641 if(status == WINNING_NEVER)
1642 // equality cases! Nobody wins if the overtime ends in a draw.
1645 if(checkrules_overtimeend)
1646 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1647 status = WINNING_YES;
1649 if(status == WINNING_YES)
1653 float mapvote_nextthink;
1654 float mapvote_initialized;
1655 float mapvote_keeptwotime;
1656 float mapvote_timeout;
1657 string mapvote_message;
1658 string mapvote_screenshot_dir;
1660 float mapvote_count;
1661 float mapvote_count_real;
1662 string mapvote_maps[MAPVOTE_COUNT];
1663 float mapvote_maps_suggested[MAPVOTE_COUNT];
1664 string mapvote_suggestions[MAPVOTE_COUNT];
1665 float mapvote_suggestion_ptr;
1666 float mapvote_maxlen;
1667 float mapvote_voters;
1668 float mapvote_votes[MAPVOTE_COUNT];
1670 float mapvote_detail;
1671 float mapvote_abstain;
1672 float mapvote_dirty;
1675 void MapVote_ClearAllVotes()
1677 FOR_EACH_CLIENT(other)
1681 string MapVote_Suggest(string m)
1685 return "That's not how to use this command.";
1686 if(!cvar("g_maplist_votable_suggestions"))
1687 return "Suggestions are not accepted on this server.";
1688 if(mapvote_initialized)
1689 return "Can't suggest - voting is already in progress!";
1690 m = MapInfo_FixName(m);
1692 return "The map you suggested is not available on this server.";
1693 if(!cvar("g_maplist_votable_override_mostrecent"))
1695 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1697 if(!MapInfo_CheckMap(m))
1698 return "The map you suggested does not support the current game mode.";
1699 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1700 if(mapvote_suggestions[i] == m)
1701 return "This map was already suggested.";
1702 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1704 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1708 i = mapvote_suggestion_ptr;
1709 mapvote_suggestion_ptr += 1;
1711 if(mapvote_suggestions[i] != "")
1712 strunzone(mapvote_suggestions[i]);
1713 mapvote_suggestions[i] = strzone(m);
1714 if(cvar("sv_eventlog"))
1715 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
1716 return strcat("Suggestion of ", m, " accepted.");
1719 void MapVote_AddVotable(string nextMap, float isSuggestion)
1724 for(j = 0; j < mapvote_count; ++j)
1725 if(mapvote_maps[j] == nextMap)
1727 if(strlen(nextMap) > mapvote_maxlen)
1728 mapvote_maxlen = strlen(nextMap);
1729 mapvote_maps[mapvote_count] = strzone(nextMap);
1730 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1734 void MapVote_SendData(float target);
1740 MapVote_ClearAllVotes();
1743 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1744 mapvote_abstain = cvar("g_maplist_votable_abstain");
1747 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1749 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1750 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
1752 if(mapvote_suggestion_ptr)
1753 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1754 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1756 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1757 MapVote_AddVotable(GetNextMap(), FALSE);
1759 if(mapvote_count == 0)
1761 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1762 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1763 localcmd("\nmenu_cmd sync\n");
1764 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1765 MapVote_AddVotable(GetNextMap(), FALSE);
1768 mapvote_count_real = mapvote_count;
1770 MapVote_AddVotable("don't care", 0);
1772 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1774 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1775 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1776 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1777 mapvote_keeptwotime = 0;
1778 mapvote_message = "Choose a map and press its key!";
1780 mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
1781 if(mapvote_screenshot_dir == "")
1782 mapvote_screenshot_dir = "maps";
1783 mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
1785 if(!cvar("g_maplist_textonly"))
1786 MapVote_SendData(MSG_ALL);
1789 void MapVote_SendPicture(float id)
1792 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1793 WriteByte(MSG_ONE, TE_CSQC_MAPVOTE);
1794 WriteByte(MSG_ONE, MAPVOTE_NET_PIC);
1795 WriteByte(MSG_ONE, id);
1796 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 3072);
1799 float GameCommand_MapVote(string cmd)
1801 if(!intermission_running)
1803 if(!cvar("g_maplist_textonly"))
1805 if(cmd == "mv_getpic")
1807 MapVote_SendPicture(stof(argv(1)));
1815 float MapVote_GetMapMask()
1817 float mask, i, power;
1819 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
1820 if(mapvote_maps[i] != "")
1825 void MapVote_SendData(float targ)
1827 string mapfile, pakfile;
1829 WriteByte(targ, SVC_TEMPENTITY);
1830 WriteByte(targ, TE_CSQC_CONFIG);
1831 WriteString(targ, "mv_screenshot_dir");
1832 WriteString(targ, mapvote_screenshot_dir);
1834 WriteByte(targ, SVC_TEMPENTITY);
1835 WriteByte(targ, TE_CSQC_MAPVOTE);
1836 WriteByte(targ, MAPVOTE_NET_INIT);
1838 WriteByte(targ, mapvote_count);
1839 WriteByte(targ, mapvote_abstain);
1840 WriteByte(targ, mapvote_detail);
1841 WriteCoord(targ, mapvote_timeout);
1842 if(mapvote_count <= 8)
1843 WriteByte(targ, MapVote_GetMapMask());
1845 WriteShort(targ, MapVote_GetMapMask());
1846 for(i = 0; i < mapvote_count; ++i)
1847 if(mapvote_maps[i] != "")
1849 WriteString(targ, mapvote_maps[i]);
1850 mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
1851 pakfile = whichpack(strcat(mapfile, ".tga"));
1853 pakfile = whichpack(strcat(mapfile, ".jpg"));
1855 pakfile = whichpack(strcat(mapfile, ".png"));
1856 print("pakfile is ", pakfile, "\n");
1857 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
1858 pakfile = substring(pakfile, o, 999);
1859 WriteString(targ, pakfile);
1863 void MapVote_UpdateData(float targ)
1866 WriteByte(targ, SVC_TEMPENTITY);
1867 WriteByte(targ, TE_CSQC_MAPVOTE);
1868 WriteByte(targ, MAPVOTE_NET_UPDATE);
1869 if(mapvote_count <= 8)
1870 WriteByte(targ, MapVote_GetMapMask());
1872 WriteShort(targ, MapVote_GetMapMask());
1874 for(i = 0; i < mapvote_count; ++i)
1875 if(mapvote_maps[i] != "")
1876 WriteByte(targ, mapvote_votes[i]);
1879 void MapVote_TellVote(float targ, float vote)
1881 WriteByte(targ, SVC_TEMPENTITY);
1882 WriteByte(targ, TE_CSQC_MAPVOTE);
1883 WriteByte(targ, MAPVOTE_NET_OWNVOTE);
1884 WriteByte(targ, vote);
1887 float MapVote_Finished(float mappos)
1893 if(cvar("sv_eventlog"))
1895 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1896 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1897 didntvote = mapvote_voters;
1898 for(i = 0; i < mapvote_count; ++i)
1899 if(mapvote_maps[i] != "")
1901 didntvote -= mapvote_votes[i];
1904 result = strcat(result, ":", mapvote_maps[i]);
1905 result = strcat(result, ":", ftos(mapvote_votes[i]));
1908 result = strcat(result, ":didn't vote:", ftos(didntvote));
1910 GameLogEcho(result);
1911 if(mapvote_maps_suggested[mappos])
1912 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
1915 FOR_EACH_REALCLIENT(other)
1916 FixClientCvars(other);
1918 Map_Goto_SetStr(mapvote_maps[mappos]);
1920 alreadychangedlevel = TRUE;
1923 void MapVote_CheckRules_1()
1927 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1929 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1930 mapvote_votes[i] = 0;
1934 FOR_EACH_REALCLIENT(other)
1939 i = other.mapvote - 1;
1940 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1941 mapvote_votes[i] = mapvote_votes[i] + 1;
1946 float MapVote_CheckRules_2()
1949 float firstPlace, secondPlace;
1950 float firstPlaceVotes, secondPlaceVotes;
1951 float mapvote_voters_real;
1954 mapvote_voters_real = mapvote_voters;
1956 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
1958 RandomSelection_Init();
1959 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1960 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
1961 firstPlace = RandomSelection_chosen_float;
1962 firstPlaceVotes = RandomSelection_best_priority;
1963 //dprint("First place: ", ftos(firstPlace), "\n");
1964 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1966 RandomSelection_Init();
1967 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1969 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
1970 secondPlace = RandomSelection_chosen_float;
1971 secondPlaceVotes = RandomSelection_best_priority;
1972 //dprint("Second place: ", ftos(secondPlace), "\n");
1973 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1975 if(firstPlace == -1)
1976 error("No first place in map vote... WTF?");
1978 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
1979 return MapVote_Finished(firstPlace);
1981 if(mapvote_keeptwotime)
1982 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
1985 mapvote_dirty = TRUE;
1986 mapvote_message = "Now decide between the TOP TWO!";
1987 mapvote_keeptwotime = 0;
1988 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
1989 result = strcat(result, ":", ftos(firstPlaceVotes));
1990 result = strcat(result, ":", mapvote_maps[secondPlace]);
1991 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
1992 didntvote = mapvote_voters;
1993 for(i = 0; i < mapvote_count; ++i)
1994 if(mapvote_maps[i] != "")
1996 didntvote -= mapvote_votes[i];
1998 if(i != secondPlace)
2000 result = strcat(result, ":", mapvote_maps[i]);
2001 result = strcat(result, ":", ftos(mapvote_votes[i]));
2002 if(i < mapvote_count_real)
2004 strunzone(mapvote_maps[i]);
2005 mapvote_maps[i] = "";
2009 result = strcat(result, ":didn't vote:", ftos(didntvote));
2010 if(cvar("sv_eventlog"))
2011 GameLogEcho(result);
2024 keeptwo = mapvote_keeptwotime;
2025 MapVote_CheckRules_1(); // count
2026 if(MapVote_CheckRules_2()) // decide
2030 FOR_EACH_REALCLIENT(other)
2032 // hide scoreboard again
2033 if(other.health != 2342)
2035 other.health = 2342;
2037 if(clienttype(other) == CLIENTTYPE_REAL)
2039 if(cvar("g_maplist_textonly"))
2040 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");
2043 WriteByte(MSG_ONE, SVC_FINALE);
2044 WriteString(MSG_ONE, "");
2048 // notify about keep-two
2049 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2050 play2(other, "misc/invshot.wav");
2052 // clear possibly invalid votes
2053 if(mapvote_maps[other.mapvote - 1] == "")
2055 // use impulses as new vote
2056 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2057 if(mapvote_maps[other.impulse - 1] != "")
2059 other.mapvote = other.impulse;
2061 mapvote_dirty = TRUE;
2064 MapVote_TellVote(MSG_ONE, other.mapvote);
2072 MapVote_CheckRules_1(); // just count
2074 if(!cvar("g_maplist_textonly"))
2075 if(mapvote_dirty) // 1 if "keeptwo" or "impulse" happened before
2077 MapVote_UpdateData(MSG_BROADCAST);
2078 mapvote_dirty = FALSE;
2081 if(cvar("g_maplist_textonly"))
2083 FOR_EACH_REALCLIENT(other)
2085 // display voting screen
2086 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2087 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2089 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2090 msgstr = strcat(msgstr, mapvote_message);
2091 msgstr = strcat(msgstr, "\n\n");
2092 for(i = 0; i < mapvote_count; ++i)
2093 if(mapvote_maps[i] == "")
2094 msgstr = strcat(msgstr, "\n");
2097 tmp = mapvote_maps[i];
2098 tmp = strpad(mapvote_maxlen, tmp);
2099 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2102 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2103 if(mapvote_votes[i] != 1)
2104 tmp = strcat(tmp, "s");
2105 tmp = strcat(tmp, ")");
2106 tmp = strpad(mapvote_maxlen + 15, tmp);
2109 if(i == mapvote_count - 1)
2110 msgstr = strcat(msgstr, "\n");
2111 if(other.mapvote == i + 1)
2112 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2114 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2117 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2119 msgstr = strcat(msgstr, "s");
2120 msgstr = strcat(msgstr, " cast");
2121 i = ceil(mapvote_timeout - time);
2122 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2124 msgstr = strcat(msgstr, "s");
2125 msgstr = strcat(msgstr, " left");
2127 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2131 void MapVote_Start()
2136 MapInfo_Enumerate();
2137 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2140 void MapVote_Think()
2145 if(alreadychangedlevel)
2148 if(time < mapvote_nextthink)
2152 mapvote_nextthink = time + 0.5;
2154 if(!mapvote_initialized)
2156 mapvote_initialized = TRUE;
2157 if(DoNextMapOverride())
2159 if(!cvar("g_maplist_votable") || player_count <= 0)
2170 string GotoMap(string m)
2172 if(!MapInfo_CheckMap(m))
2173 return "The map you chose is not available on this server.";
2174 cvar_set("nextmap", m);
2175 cvar_set("timelimit", "-1");
2176 if(mapvote_initialized || alreadychangedlevel)
2178 if(DoNextMapOverride())
2179 return "Map switch initiated.";
2181 return "Hm... no. For some reason I like THIS map more.";
2184 return "Map switch will happen after scoreboard.";
2190 FOR_EACH_REALCLIENT(self)
2192 if(self.classname == "spectator")
2194 if(self.enemy.hitsound)
2195 play2(self, "misc/hit.wav");
2200 play2(self, "misc/hit.wav");
2203 FOR_EACH_CLIENT(self)
2204 self.hitsound = FALSE;
2210 * returns TRUE if redirecting
2212 float redirection_timeout;
2213 float redirection_nextthink;
2214 float RedirectionThink()
2216 float clients_found;
2218 if(redirection_target == "")
2221 if(!redirection_timeout)
2223 cvar_set("sv_public", "-2");
2224 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2225 if(redirection_target == "self")
2226 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2228 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2231 if(time < redirection_nextthink)
2234 redirection_nextthink = time + 1;
2237 FOR_EACH_REALCLIENT(self)
2239 print("Redirecting: sending connect command to ", self.netname, "\n");
2240 if(redirection_target == "self")
2241 stuffcmd(self, "\ndisconnect; reconnect\n");
2243 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2247 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2249 if(time > redirection_timeout || clients_found == 0)
2250 localcmd("\nwait; wait; wait; quit\n");
2257 // Loaded from a save game
2258 // some things then break, so let's work around them...
2260 // Progs DB (capture records)
2262 ServerProgsDB = db_create();
2264 ServerProgsDB = db_load("server.db");
2268 MapInfo_Enumerate();
2269 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
2274 if(world_initialized)
2276 world_initialized = 0;
2277 print("Saving persistent data...\n");
2280 db_save(ServerProgsDB, "server.db");
2281 db_close(ServerProgsDB);
2283 // tell the bot system the game is ending now
2290 print("NOTE: crashed before even initializing the world, not saving persistent data\n");