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);
357 next_pingtime = time + 5;
358 world_initialized = 1;
361 void spawnfunc_light (void)
363 //makestatic (self); // Who the f___ did that?
367 float TryFile( string pFilename )
370 dprint("TryFile(\"", pFilename, "\")\n");
371 lHandle = fopen( pFilename, FILE_READ );
372 if( lHandle != -1 ) {
382 return GametypeNameFromType(game);
385 string getmapname_stored;
391 float Map_Count, Map_Current;
392 string Map_Current_Name;
394 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
395 float GetMaplistPosition()
401 idx = cvar("g_maplist_index");
408 for(pos = 0; pos < Map_Count; ++pos)
412 // resume normal maplist rotation if current map is not in g_maplist
416 float MapHasRightSize(string map)
419 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
420 if(cvar("g_maplist_check_waypoints"))
422 dprint("checkwp "); dprint(map);
423 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
426 dprint(": no waypoints\n");
429 dprint(": has waypoints\n");
433 // open map size restriction file
434 dprint("opensize "); dprint(map);
435 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
438 float mapmin, mapmax;
440 mapmin = stof(fgets(fh));
441 mapmax = stof(fgets(fh));
443 if(player_count < mapmin)
445 dprint("not enough\n");
448 if(player_count > mapmax)
450 dprint("too many\n");
453 dprint("right size\n");
456 dprint(": not found\n");
460 string Map_Filename(float position)
462 return strcat("maps/", argv(position), ".bsp");
465 string strwords(string s, float w)
468 for(endpos = 0; w && endpos >= 0; --w)
469 endpos = strstrofs(s, " ", endpos + 1);
473 return substring(s, 0, endpos);
476 float strhasword(string s, string w)
478 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
481 void Map_MarkAsRecent(string m)
483 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
486 float Map_IsRecent(string m)
488 return strhasword(cvar_string("g_maplist_mostrecent"), m);
491 float Map_Check(float position, float pass)
495 map_next = argv(position);
498 if(map_next == Map_Current_Name) // same map again in first pass?
500 if(Map_IsRecent(map_next))
503 filename = Map_Filename(position);
504 if(MapInfo_CheckMap(map_next))
508 if(MapHasRightSize(map_next))
513 dprint( "Couldn't select '", filename, "'..\n" );
518 void Map_Goto_SetStr(string nextmapname)
520 if(getmapname_stored != "")
521 strunzone(getmapname_stored);
522 if(nextmapname == "")
523 getmapname_stored = "";
525 getmapname_stored = strzone(nextmapname);
528 void Map_Goto_SetFloat(float position)
530 cvar_set("g_maplist_index", ftos(position));
531 Map_Goto_SetStr(argv(position));
536 // settings persist, except...
537 if(cvar("g_campaign"))
538 localcmd("\nexec mutator_reset.cfg\n");
539 localcmd("\nsettemp_restore\n");
544 Map_MarkAsRecent(getmapname_stored);
546 MapInfo_LoadMap(getmapname_stored);
549 // return codes of map selectors:
550 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
551 // -2 = permanent failure
552 float() MaplistMethod_Iterate = // usual method
556 for(pass = 1; pass <= 2; ++pass)
558 for(i = 1; i < Map_Count; ++i)
561 mapindex = mod(i + Map_Current, Map_Count);
562 if(Map_Check(mapindex, pass))
569 float() MaplistMethod_Repeat = // fallback method
571 if(Map_Check(Map_Current, 2))
576 float() MaplistMethod_Random = // random map selection
582 for(i = 0; i <= imax; ++i)
585 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
586 if(Map_Check(mapindex, 1))
592 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
593 // the exponent sets a bias on the map selection:
594 // the higher the exponent, the less likely "shortly repeated" same maps are
596 float i, j, imax, insertpos;
600 for(i = 0; i <= imax; ++i)
604 // now reinsert this at another position
605 insertpos = pow(random(), 1 / exponent); // ]0, 1]
606 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
607 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
608 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
610 // insert the current map there
612 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
613 newlist = strcat(newlist, " ", argv(j));
614 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
615 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
616 newlist = strcat(newlist, " ", argv(j));
617 newlist = substring(newlist, 1, strlen(newlist) - 1);
618 cvar_set("g_maplist", newlist);
619 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
621 // NOTE: the selected map has just been inserted at (insertpos-1)th position
622 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
623 if(Map_Check(Map_Current, 1))
632 temp = cvar_string("g_maplist");
633 Map_Count = tokenizebyseparator(temp, " ");
636 bprint( "Maplist is empty! Resetting it to default map list.\n" );
637 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
638 localcmd("\nmenu_cmd sync\n");
639 Map_Count = tokenizebyseparator(temp, " ");
642 error("empty maplist, cannot select a new map");
643 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
646 strunzone(Map_Current_Name);
647 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
648 // this may or may not be correct, but who cares, in the worst case a map
649 // isn't chosen in the first pass that should have been
660 if(cvar("g_maplist_shuffle") > 0)
661 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
664 if(cvar("g_maplist_selectrandom"))
665 nextMap = MaplistMethod_Random();
668 nextMap = MaplistMethod_Iterate();
671 nextMap = MaplistMethod_Repeat();
675 Map_Goto_SetFloat(nextMap);
676 return getmapname_stored;
682 float DoNextMapOverride()
684 if(cvar("g_campaign"))
686 CampaignPostIntermission();
687 alreadychangedlevel = TRUE;
690 if(cvar("quit_when_empty"))
692 if(player_count <= currentbots)
695 alreadychangedlevel = TRUE;
699 if(cvar_string("quit_and_redirect") != "")
701 redirection_target = strzone(cvar_string("quit_and_redirect"));
702 alreadychangedlevel = TRUE;
705 if (cvar("samelevel")) // if samelevel is set, stay on same level
707 // 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)
708 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
709 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
710 localcmd("restart\n");
711 //changelevel (mapname);
712 alreadychangedlevel = TRUE;
715 if(cvar_string("nextmap") != "")
716 if(MapInfo_CheckMap(cvar_string("nextmap")))
718 Map_Goto_SetStr(cvar_string("nextmap"));
720 alreadychangedlevel = TRUE;
723 if(cvar("lastlevel"))
726 localcmd("set lastlevel 0\ntogglemenu\n");
727 alreadychangedlevel = TRUE;
735 //local string nextmap;
736 //local float n, nummaps;
738 if (alreadychangedlevel)
740 alreadychangedlevel = TRUE;
746 for(allowReset = 1; allowReset >= 0; --allowReset)
748 nextMap = GetNextMap();
754 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
755 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
756 localcmd("\nmenu_cmd sync\n");
760 error("Everything is broken - not even the default map list works. Please report this to the developers.");
772 When the player presses attack or jump, change to the next level
775 .float autoscreenshot;
776 void() MapVote_Start;
777 void() MapVote_Think;
778 float mapvote_initialized;
779 void IntermissionThink()
781 FixIntermissionClient(self);
783 if(cvar("sv_autoscreenshot"))
784 if(self.autoscreenshot > 0)
785 if(time > self.autoscreenshot)
787 self.autoscreenshot = -1;
788 if(clienttype(self) == CLIENTTYPE_REAL)
789 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
793 if (time < intermission_exittime)
796 if(!mapvote_initialized)
797 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
807 Returns the entity to view from
811 entity FindIntermission()
816 // look for info_intermission first
817 spot = find (world, classname, "info_intermission");
819 { // pick a random one
823 spot = find (spot, classname, "info_intermission");
825 spot = find (spot, classname, "info_intermission");
831 // then look for the start position
832 spot = find (world, classname, "info_player_start");
836 // testinfo_player_start is only found in regioned levels
837 spot = find (world, classname, "testplayerstart");
841 // then look for the start position
842 spot = find (world, classname, "info_player_deathmatch");
846 //objerror ("FindIntermission: no spot");
852 ===============================================================================
856 ===============================================================================
859 void DumpStats(float final)
863 local float to_console;
864 local float to_eventlog;
868 to_console = cvar("sv_logscores_console");
869 to_eventlog = cvar("sv_eventlog");
870 to_file = cvar("sv_logscores_file");
874 to_console = TRUE; // always print printstats replies
875 to_eventlog = FALSE; // but never print them to the event log
879 if(cvar("sv_eventlog_console"))
880 to_console = FALSE; // otherwise we get the output twice
886 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
894 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
898 fputs(file, strcat(s, "\n"));
901 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
906 fputs(file, strcat(s, "\n"));
908 FOR_EACH_CLIENT(other)
910 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
912 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
913 s = strcat(s, ftos(rint(time - other.jointime)), ":");
914 if(other.classname == "player" || g_arena || g_lms)
915 s = strcat(s, ftos(other.team), ":");
917 s = strcat(s, "spectator:");
920 print(s, other.netname, "\n");
922 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
924 fputs(file, strcat(s, other.netname, "\n"));
930 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
936 fputs(file, strcat(s, "\n"));
938 for(i = 1; i < 16; ++i)
940 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
941 s = strcat(s, ":", ftos(i));
947 fputs(file, strcat(s, "\n"));
957 fputs(file, ":end\n");
962 void FixIntermissionClient(entity e)
965 if(!e.autoscreenshot) // initial call
967 e.angles = e.v_angle;
968 e.angles_x = -e.angles_x;
969 e.autoscreenshot = time + 0.8; // used for autoscreenshot
971 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
973 e.movetype = MOVETYPE_NONE;
974 e.takedamage = DAMAGE_NO;
976 e.weaponentity.effects = EF_NODRAW;
977 if(clienttype(e) == CLIENTTYPE_REAL)
979 stuffcmd(e, "\nscr_printspeed 1000000\n");
980 s = cvar_string("sv_intermission_cdtrack");
982 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
984 WriteByte(MSG_ONE, SVC_INTERMISSION);
988 //e.velocity = '0 0 0';
991 // TODO halt weapon animation
996 go to the next level for deathmatch
997 only called if a time or frag limit has expired
1001 float minTotalFrags;
1002 float maxTotalFrags;
1008 intermission_running = 1;
1010 // enforce a wait time before allowing changelevel
1011 if(player_count > 0)
1012 intermission_exittime = time + cvar("sv_mapchange_delay");
1014 intermission_exittime = -1;
1017 WriteByte (MSG_ALL, SVC_CDTRACK);
1018 WriteByte (MSG_ALL, 3);
1019 WriteByte (MSG_ALL, 3);
1020 // done in FixIntermission
1023 //pos = FindIntermission ();
1029 if(cvar("sv_eventlog"))
1030 GameLogEcho(":gameover");
1034 FOR_EACH_CLIENT(other)
1036 FixIntermissionClient(other);
1039 bprint(other.netname, " ^7wins.\n");
1044 FOR_EACH_PLAYER(other)
1046 if(maxTotalFrags < other.totalfrags)
1047 maxTotalFrags = other.totalfrags;
1048 if(minTotalFrags > other.totalfrags)
1049 minTotalFrags = other.totalfrags;
1054 FOR_EACH_PLAYER(other)
1056 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1057 f = bound(0, other.play_time / max(time, 1), 1);
1058 // store some statistics?
1062 if(cvar("g_campaign"))
1063 CampaignPreIntermission();
1065 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1072 Exit deathmatch games upon conditions
1076 void CheckRules_Player()
1078 if (gameover) // someone else quit the game already
1081 if(self.deadflag == DEAD_NO)
1082 self.play_time += frametime;
1086 if(time > self.fogtime)
1088 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1089 self.fogtime = time + sv_foginterval;
1092 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1093 // (div0: and that in CheckRules_World please)
1096 float checkrules_oneminutewarning;
1098 float checkrules_equality;
1099 float checkrules_overtimewarning;
1100 float checkrules_overtimeend;
1102 void InitiateOvertime()
1104 if(!checkrules_overtimeend)
1105 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1108 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1109 float WINNING_YES = 1; // winner found
1110 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1111 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1113 float GetWinningCode(float fraglimitreached, float equality)
1116 if(fraglimitreached)
1117 return WINNING_STARTOVERTIME;
1119 return WINNING_NEVER;
1121 if(fraglimitreached)
1127 // set the .winning flag for exactly those players with a given field value
1128 void SetWinners(.float field, float value)
1131 FOR_EACH_PLAYER(head)
1132 head.winning = (head.field == value);
1135 // set the .winning flag for those players with a given field value
1136 void AddWinners(.float field, float value)
1139 FOR_EACH_PLAYER(head)
1140 if(head.field == value)
1144 // clear the .winning flags
1145 void ClearWinners(void)
1148 FOR_EACH_PLAYER(head)
1152 // Onslaught winning condition:
1153 // game terminates if only one team has a working generator (or none)
1154 float WinningCondition_Onslaught()
1157 local float t1, t2, t3, t4;
1158 // first check if the game has ended
1159 t1 = t2 = t3 = t4 = 0;
1160 head = find(world, classname, "onslaught_generator");
1163 if (head.health > 0)
1165 if (head.team == COLOR_TEAM1) t1 = 1;
1166 if (head.team == COLOR_TEAM2) t2 = 1;
1167 if (head.team == COLOR_TEAM3) t3 = 1;
1168 if (head.team == COLOR_TEAM4) t4 = 1;
1170 head = find(head, classname, "onslaught_generator");
1172 if (t1 + t2 + t3 + t4 < 2)
1174 // game over, only one team remains (or none)
1176 if (t1) SetWinners(team, COLOR_TEAM1);
1177 if (t2) SetWinners(team, COLOR_TEAM2);
1178 if (t3) SetWinners(team, COLOR_TEAM3);
1179 if (t4) SetWinners(team, COLOR_TEAM4);
1180 dprint("Have a winner, ending game.\n");
1184 // Two or more teams remain
1188 float LMS_NewPlayerLives()
1191 fl = cvar("fraglimit");
1195 // first player has left the game for dying too much? Nobody else can get in.
1196 if(lms_lowest_lives < 1)
1199 if(!cvar("g_lms_join_anytime"))
1200 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1203 return bound(1, lms_lowest_lives, fl);
1206 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1207 // they win. Otherwise the defending team wins once the timelimit passes.
1208 void assault_new_round();
1209 float WinningCondition_Assault()
1212 status = WINNING_NO;
1214 // as the timelimit has not yet passed just assume the defending team will win
1215 if(assault_attacker_team == COLOR_TEAM1)
1217 SetWinners(team, COLOR_TEAM2);
1221 SetWinners(team, COLOR_TEAM1);
1225 ent = find(world, classname, "target_assault_roundend");
1228 if(ent.winning) // round end has been triggered by attacking team
1230 SetWinners(team, assault_attacker_team);
1231 if(assault_attacker_team == COLOR_TEAM1)
1233 team1_score = team1_score + 50;
1237 team2_score = team2_score + 50;
1240 if(ent.cnt == 1) // this was the second round
1242 status = WINNING_YES;
1246 local entity oldself;
1249 cvar_set("timelimit", ftos((2*time)/60));
1250 assault_new_round();
1260 // LMS winning condition: game terminates if and only if there's at most one
1261 // one player who's living lives. Top two scores being equal cancels the time
1263 float WinningCondition_LMS()
1270 have_player = FALSE;
1271 have_players = FALSE;
1272 l = LMS_NewPlayerLives();
1274 head = find(world, classname, "player");
1277 head2 = find(head, classname, "player");
1279 have_players = TRUE;
1283 // we have at least one player
1286 // two or more active players - continue with the game
1290 // exactly one player?
1293 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1297 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1303 // and assign him his first place
1304 PlayerScore_Add(head, SP_LMS_RANK, 1);
1311 // nobody is playing at all...
1314 // wait for players...
1318 // SNAFU (maybe a draw game?)
1320 dprint("No players, ending game.\n");
1325 // When we get here, we have at least two players who are actually LIVING,
1326 // now check if the top two players have equal score.
1327 WinningConditionHelper();
1330 if(WinningConditionHelper_winner)
1331 WinningConditionHelper_winner.winning = TRUE;
1332 if(WinningConditionHelper_equality)
1333 return WINNING_NEVER;
1335 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1339 void print_to(entity e, string s)
1342 sprint(e, strcat(s, "\n"));
1347 void ShuffleMaplist()
1355 result = cvar_string("g_maplist");
1356 litems = tokenizebyseparator(result, " ");
1358 for(start = 0; start < litems - 1; ++start)
1362 // select a random item
1363 selected = ceil(random() * (litems - start) + start) - 1;
1365 // shift this item to the place start
1366 for(i = 0; i < start; ++i)
1367 result = strcat(result, " ", argv(i));
1368 result = strcat(result, " ", argv(selected));
1369 for(i = start; i < litems; ++i)
1371 result = strcat(result, " ", argv(i));
1372 result = substring(result, 1, strlen(result) - 1);
1374 litems = tokenizebyseparator(result, " ");
1376 //dprint(result, "\n");
1379 cvar_set("g_maplist", result);
1382 float WinningCondition_Scores(float limit)
1384 // TODO make everything use THIS winning condition (except LMS)
1385 WinningConditionHelper();
1389 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1390 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1391 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1392 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1396 if(WinningConditionHelper_winner)
1397 WinningConditionHelper_winner.winning = 1;
1398 if(WinningConditionHelper_winnerteam >= 0)
1399 SetWinners(team, WinningConditionHelper_winnerteam);
1401 if(WinningConditionHelper_topscore == 0)
1402 WinningConditionHelper_equality = 0;
1404 if(WinningConditionHelper_lowerisbetter)
1406 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1410 return GetWinningCode(limit && WinningConditionHelper_topscore && (WinningConditionHelper_topscore >= limit), WinningConditionHelper_equality);
1413 float WinningCondition_Race(float fraglimit)
1417 wc = WinningCondition_Scores(fraglimit);
1419 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1420 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1421 // do NOT support equality when the laps are all raced!
1424 if not(p.race_completed)
1425 return WINNING_STARTOVERTIME;
1431 void ReadyRestart();
1432 float WinningCondition_QualifyingThenRace(float limit)
1435 wc = WinningCondition_Scores(limit);
1437 // NEVER initiate overtime
1438 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1439 // do NOT support equality when the laps are all raced!
1442 float playerswithlaps;
1444 totalplayers = playerswithlaps = 0;
1445 FOR_EACH_PLAYER(head)
1448 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
1452 // at least 2/3 of the players have completed a lap: start the RACE
1453 // otherwise, the players should end the qualifying on their own
1454 if(totalplayers >= 3)
1455 if(playerswithlaps >= totalplayers * 2 / 3)
1457 checkrules_overtimeend = 0;
1459 return WINNING_NEVER;
1468 float WinningCondition_RanOutOfSpawns()
1472 if(!have_team_spawns)
1475 if(!some_spawn_has_been_used)
1478 team1_score = team2_score = team3_score = team4_score = 0;
1480 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1482 if(head.team == COLOR_TEAM1)
1484 else if(head.team == COLOR_TEAM2)
1486 else if(head.team == COLOR_TEAM3)
1488 else if(head.team == COLOR_TEAM4)
1492 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1494 if(head.team == COLOR_TEAM1)
1496 else if(head.team == COLOR_TEAM2)
1498 else if(head.team == COLOR_TEAM3)
1500 else if(head.team == COLOR_TEAM4)
1505 if(team1_score + team2_score + team3_score + team4_score == 0)
1507 checkrules_equality = TRUE;
1510 else if(team1_score + team2_score + team3_score + team4_score == 1)
1513 if(team1_score) t = COLOR_TEAM1;
1514 if(team2_score) t = COLOR_TEAM2;
1515 if(team3_score) t = COLOR_TEAM3;
1516 if(team4_score) t = COLOR_TEAM4;
1517 CheckAllowedTeams(world);
1518 for(i = 0; i < MAX_TEAMSCORE; ++i)
1520 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
1521 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
1522 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
1523 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
1526 AddWinners(team, t);
1537 Exit deathmatch games upon conditions
1540 void CheckRules_World()
1543 local float timelimit;
1544 local float fraglimit;
1552 MapVote_Think should now do that part
1553 if (intermission_running)
1554 if (time >= intermission_exittime + 60)
1556 if(!DoNextMapOverride())
1562 if (gameover) // someone else quit the game already
1564 if(player_count == 0) // Nobody there? Then let's go to the next map
1566 // this will actually check the player count in the next frame
1567 // again, but this shouldn't hurt
1571 timelimit = cvar("timelimit") * 60;
1572 fraglimit = cvar("fraglimit");
1574 if(checkrules_overtimeend)
1576 if(!checkrules_overtimewarning)
1578 checkrules_overtimewarning = TRUE;
1579 //announceall("announcer/robotic/1minuteremains.wav");
1580 if(!g_race_qualifying)
1581 bcenterprint("^3Everyone, finish your lap! The race is over!");
1583 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1588 if (timelimit && time >= timelimit)
1592 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1598 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1600 checkrules_oneminutewarning = TRUE;
1601 play2all("announcer/robotic/1minuteremains.wav");
1604 status = WinningCondition_RanOutOfSpawns();
1605 if(status == WINNING_YES)
1607 bprint("Hey! Someone ran out of spawns!\n");
1609 else if(g_race && !g_race_qualifying && timelimit >= 0)
1611 status = WinningCondition_Race(fraglimit);
1613 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
1615 status = WinningCondition_QualifyingThenRace(fraglimit);
1619 status = WinningCondition_Assault(); // TODO remove this?
1623 status = WinningCondition_LMS();
1625 else if (g_onslaught)
1627 status = WinningCondition_Onslaught(); // TODO remove this?
1631 status = WinningCondition_Scores(fraglimit);
1634 if(status == WINNING_STARTOVERTIME)
1636 status = WINNING_NEVER;
1640 if(status == WINNING_NEVER)
1641 // equality cases! Nobody wins if the overtime ends in a draw.
1644 if(checkrules_overtimeend)
1645 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1646 status = WINNING_YES;
1648 if(status == WINNING_YES)
1652 float mapvote_nextthink;
1653 float mapvote_initialized;
1654 float mapvote_keeptwotime;
1655 float mapvote_timeout;
1656 string mapvote_message;
1657 string mapvote_screenshot_dir;
1659 float mapvote_count;
1660 float mapvote_count_real;
1661 string mapvote_maps[MAPVOTE_COUNT];
1662 float mapvote_maps_suggested[MAPVOTE_COUNT];
1663 string mapvote_suggestions[MAPVOTE_COUNT];
1664 float mapvote_suggestion_ptr;
1665 float mapvote_maxlen;
1666 float mapvote_voters;
1667 float mapvote_votes[MAPVOTE_COUNT];
1669 float mapvote_detail;
1670 float mapvote_abstain;
1671 float mapvote_dirty;
1674 void MapVote_ClearAllVotes()
1676 FOR_EACH_CLIENT(other)
1680 string MapVote_Suggest(string m)
1684 return "That's not how to use this command.";
1685 if(!cvar("g_maplist_votable_suggestions"))
1686 return "Suggestions are not accepted on this server.";
1687 if(mapvote_initialized)
1688 return "Can't suggest - voting is already in progress!";
1689 m = MapInfo_FixName(m);
1691 return "The map you suggested is not available on this server.";
1692 if(!cvar("g_maplist_votable_override_mostrecent"))
1694 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1696 if(!MapInfo_CheckMap(m))
1697 return "The map you suggested does not support the current game mode.";
1698 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1699 if(mapvote_suggestions[i] == m)
1700 return "This map was already suggested.";
1701 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1703 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1707 i = mapvote_suggestion_ptr;
1708 mapvote_suggestion_ptr += 1;
1710 if(mapvote_suggestions[i] != "")
1711 strunzone(mapvote_suggestions[i]);
1712 mapvote_suggestions[i] = strzone(m);
1713 if(cvar("sv_eventlog"))
1714 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
1715 return strcat("Suggestion of ", m, " accepted.");
1718 void MapVote_AddVotable(string nextMap, float isSuggestion)
1723 for(j = 0; j < mapvote_count; ++j)
1724 if(mapvote_maps[j] == nextMap)
1726 if(strlen(nextMap) > mapvote_maxlen)
1727 mapvote_maxlen = strlen(nextMap);
1728 mapvote_maps[mapvote_count] = strzone(nextMap);
1729 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1733 void MapVote_SendData(float target);
1739 MapVote_ClearAllVotes();
1742 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1743 mapvote_abstain = cvar("g_maplist_votable_abstain");
1746 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1748 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1749 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
1751 if(mapvote_suggestion_ptr)
1752 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1753 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1755 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1756 MapVote_AddVotable(GetNextMap(), FALSE);
1758 if(mapvote_count == 0)
1760 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1761 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1762 localcmd("\nmenu_cmd sync\n");
1763 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1764 MapVote_AddVotable(GetNextMap(), FALSE);
1767 mapvote_count_real = mapvote_count;
1769 MapVote_AddVotable("don't care", 0);
1771 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1773 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1774 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1775 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1776 mapvote_keeptwotime = 0;
1777 mapvote_message = "Choose a map and press its key!";
1779 mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
1780 if(mapvote_screenshot_dir == "")
1781 mapvote_screenshot_dir = "maps";
1782 mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
1784 if(!cvar("g_maplist_textonly"))
1785 MapVote_SendData(MSG_ALL);
1788 void MapVote_SendPicture(float id)
1791 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1792 WriteByte(MSG_ONE, TE_CSQC_MAPVOTE);
1793 WriteByte(MSG_ONE, MAPVOTE_NET_PIC);
1794 WriteByte(MSG_ONE, id);
1795 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 3072);
1798 float GameCommand_MapVote(string cmd)
1800 if(!intermission_running)
1802 if(!cvar("g_maplist_textonly"))
1804 if(cmd == "mv_getpic")
1806 MapVote_SendPicture(stof(argv(1)));
1814 float MapVote_GetMapMask()
1816 float mask, i, power;
1818 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
1819 if(mapvote_maps[i] != "")
1824 void MapVote_SendData(float targ)
1826 string mapfile, pakfile;
1828 WriteByte(targ, SVC_TEMPENTITY);
1829 WriteByte(targ, TE_CSQC_CONFIG);
1830 WriteString(targ, "mv_screenshot_dir");
1831 WriteString(targ, mapvote_screenshot_dir);
1833 WriteByte(targ, SVC_TEMPENTITY);
1834 WriteByte(targ, TE_CSQC_MAPVOTE);
1835 WriteByte(targ, MAPVOTE_NET_INIT);
1837 WriteByte(targ, mapvote_count);
1838 WriteByte(targ, mapvote_abstain);
1839 WriteByte(targ, mapvote_detail);
1840 WriteCoord(targ, mapvote_timeout);
1841 if(mapvote_count <= 8)
1842 WriteByte(targ, MapVote_GetMapMask());
1844 WriteShort(targ, MapVote_GetMapMask());
1845 for(i = 0; i < mapvote_count; ++i)
1846 if(mapvote_maps[i] != "")
1848 WriteString(targ, mapvote_maps[i]);
1849 mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
1850 pakfile = whichpack(strcat(mapfile, ".tga"));
1852 pakfile = whichpack(strcat(mapfile, ".jpg"));
1854 pakfile = whichpack(strcat(mapfile, ".png"));
1855 print("pakfile is ", pakfile, "\n");
1856 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
1857 pakfile = substring(pakfile, o, 999);
1858 WriteString(targ, pakfile);
1862 void MapVote_UpdateData(float targ)
1865 WriteByte(targ, SVC_TEMPENTITY);
1866 WriteByte(targ, TE_CSQC_MAPVOTE);
1867 WriteByte(targ, MAPVOTE_NET_UPDATE);
1868 if(mapvote_count <= 8)
1869 WriteByte(targ, MapVote_GetMapMask());
1871 WriteShort(targ, MapVote_GetMapMask());
1873 for(i = 0; i < mapvote_count; ++i)
1874 if(mapvote_maps[i] != "")
1875 WriteByte(targ, mapvote_votes[i]);
1878 void MapVote_TellVote(float targ, float vote)
1880 WriteByte(targ, SVC_TEMPENTITY);
1881 WriteByte(targ, TE_CSQC_MAPVOTE);
1882 WriteByte(targ, MAPVOTE_NET_OWNVOTE);
1883 WriteByte(targ, vote);
1886 float MapVote_Finished(float mappos)
1892 if(cvar("sv_eventlog"))
1894 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1895 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1896 didntvote = mapvote_voters;
1897 for(i = 0; i < mapvote_count; ++i)
1898 if(mapvote_maps[i] != "")
1900 didntvote -= mapvote_votes[i];
1903 result = strcat(result, ":", mapvote_maps[i]);
1904 result = strcat(result, ":", ftos(mapvote_votes[i]));
1907 result = strcat(result, ":didn't vote:", ftos(didntvote));
1909 GameLogEcho(result);
1910 if(mapvote_maps_suggested[mappos])
1911 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
1914 FOR_EACH_REALCLIENT(other)
1915 FixClientCvars(other);
1917 Map_Goto_SetStr(mapvote_maps[mappos]);
1919 alreadychangedlevel = TRUE;
1922 void MapVote_CheckRules_1()
1926 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1928 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1929 mapvote_votes[i] = 0;
1933 FOR_EACH_REALCLIENT(other)
1938 i = other.mapvote - 1;
1939 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1940 mapvote_votes[i] = mapvote_votes[i] + 1;
1945 float MapVote_CheckRules_2()
1948 float firstPlace, secondPlace;
1949 float firstPlaceVotes, secondPlaceVotes;
1950 float mapvote_voters_real;
1953 mapvote_voters_real = mapvote_voters;
1955 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
1957 RandomSelection_Init();
1958 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1959 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
1960 firstPlace = RandomSelection_chosen_float;
1961 firstPlaceVotes = RandomSelection_best_priority;
1962 //dprint("First place: ", ftos(firstPlace), "\n");
1963 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1965 RandomSelection_Init();
1966 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1968 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
1969 secondPlace = RandomSelection_chosen_float;
1970 secondPlaceVotes = RandomSelection_best_priority;
1971 //dprint("Second place: ", ftos(secondPlace), "\n");
1972 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1974 if(firstPlace == -1)
1975 error("No first place in map vote... WTF?");
1977 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
1978 return MapVote_Finished(firstPlace);
1980 if(mapvote_keeptwotime)
1981 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
1984 mapvote_dirty = TRUE;
1985 mapvote_message = "Now decide between the TOP TWO!";
1986 mapvote_keeptwotime = 0;
1987 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
1988 result = strcat(result, ":", ftos(firstPlaceVotes));
1989 result = strcat(result, ":", mapvote_maps[secondPlace]);
1990 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
1991 didntvote = mapvote_voters;
1992 for(i = 0; i < mapvote_count; ++i)
1993 if(mapvote_maps[i] != "")
1995 didntvote -= mapvote_votes[i];
1997 if(i != secondPlace)
1999 result = strcat(result, ":", mapvote_maps[i]);
2000 result = strcat(result, ":", ftos(mapvote_votes[i]));
2001 if(i < mapvote_count_real)
2003 strunzone(mapvote_maps[i]);
2004 mapvote_maps[i] = "";
2008 result = strcat(result, ":didn't vote:", ftos(didntvote));
2009 if(cvar("sv_eventlog"))
2010 GameLogEcho(result);
2023 keeptwo = mapvote_keeptwotime;
2024 MapVote_CheckRules_1(); // count
2025 if(MapVote_CheckRules_2()) // decide
2029 FOR_EACH_REALCLIENT(other)
2031 // hide scoreboard again
2032 if(other.health != 2342)
2034 other.health = 2342;
2036 if(clienttype(other) == CLIENTTYPE_REAL)
2038 if(cvar("g_maplist_textonly"))
2039 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");
2042 WriteByte(MSG_ONE, SVC_FINALE);
2043 WriteString(MSG_ONE, "");
2047 // notify about keep-two
2048 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2049 play2(other, "misc/invshot.wav");
2051 // clear possibly invalid votes
2052 if(mapvote_maps[other.mapvote - 1] == "")
2054 // use impulses as new vote
2055 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2056 if(mapvote_maps[other.impulse - 1] != "")
2058 other.mapvote = other.impulse;
2060 mapvote_dirty = TRUE;
2063 MapVote_TellVote(MSG_ONE, other.mapvote);
2071 MapVote_CheckRules_1(); // just count
2073 if(!cvar("g_maplist_textonly"))
2074 if(mapvote_dirty) // 1 if "keeptwo" or "impulse" happened before
2076 MapVote_UpdateData(MSG_BROADCAST);
2077 mapvote_dirty = FALSE;
2080 if(cvar("g_maplist_textonly"))
2082 FOR_EACH_REALCLIENT(other)
2084 // display voting screen
2085 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2086 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2088 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2089 msgstr = strcat(msgstr, mapvote_message);
2090 msgstr = strcat(msgstr, "\n\n");
2091 for(i = 0; i < mapvote_count; ++i)
2092 if(mapvote_maps[i] == "")
2093 msgstr = strcat(msgstr, "\n");
2096 tmp = mapvote_maps[i];
2097 tmp = strpad(mapvote_maxlen, tmp);
2098 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2101 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2102 if(mapvote_votes[i] != 1)
2103 tmp = strcat(tmp, "s");
2104 tmp = strcat(tmp, ")");
2105 tmp = strpad(mapvote_maxlen + 15, tmp);
2108 if(i == mapvote_count - 1)
2109 msgstr = strcat(msgstr, "\n");
2110 if(other.mapvote == i + 1)
2111 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2113 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2116 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2118 msgstr = strcat(msgstr, "s");
2119 msgstr = strcat(msgstr, " cast");
2120 i = ceil(mapvote_timeout - time);
2121 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2123 msgstr = strcat(msgstr, "s");
2124 msgstr = strcat(msgstr, " left");
2126 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2130 void MapVote_Start()
2135 MapInfo_Enumerate();
2136 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2139 void MapVote_Think()
2144 if(alreadychangedlevel)
2147 if(time < mapvote_nextthink)
2151 mapvote_nextthink = time + 0.5;
2153 if(!mapvote_initialized)
2155 mapvote_initialized = TRUE;
2156 if(DoNextMapOverride())
2158 if(!cvar("g_maplist_votable") || player_count <= 0)
2169 string GotoMap(string m)
2171 if(!MapInfo_CheckMap(m))
2172 return "The map you chose is not available on this server.";
2173 cvar_set("nextmap", m);
2174 cvar_set("timelimit", "-1");
2175 if(mapvote_initialized || alreadychangedlevel)
2177 if(DoNextMapOverride())
2178 return "Map switch initiated.";
2180 return "Hm... no. For some reason I like THIS map more.";
2183 return "Map switch will happen after scoreboard.";
2189 FOR_EACH_REALCLIENT(self)
2191 if(self.classname == "spectator")
2193 if(self.enemy.hitsound)
2194 play2(self, "misc/hit.wav");
2199 play2(self, "misc/hit.wav");
2202 FOR_EACH_CLIENT(self)
2203 self.hitsound = FALSE;
2209 * returns TRUE if redirecting
2211 float redirection_timeout;
2212 float redirection_nextthink;
2213 float RedirectionThink()
2215 float clients_found;
2217 if(redirection_target == "")
2220 if(!redirection_timeout)
2222 cvar_set("sv_public", "-2");
2223 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2224 if(redirection_target == "self")
2225 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2227 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2230 if(time < redirection_nextthink)
2233 redirection_nextthink = time + 1;
2236 FOR_EACH_REALCLIENT(self)
2238 print("Redirecting: sending connect command to ", self.netname, "\n");
2239 if(redirection_target == "self")
2240 stuffcmd(self, "\ndisconnect; reconnect\n");
2242 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2246 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2248 if(time > redirection_timeout || clients_found == 0)
2249 localcmd("\nwait; wait; wait; quit\n");
2256 // Loaded from a save game
2257 // some things then break, so let's work around them...
2259 // Progs DB (capture records)
2261 ServerProgsDB = db_create();
2263 ServerProgsDB = db_load("server.db");
2267 MapInfo_Enumerate();
2268 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
2273 if(world_initialized)
2275 world_initialized = 0;
2276 print("Saving persistent data...\n");
2279 db_save(ServerProgsDB, "server.db");
2280 db_close(ServerProgsDB);
2282 // tell the bot system the game is ending now
2289 print("NOTE: crashed before even initializing the world, not saving persistent data\n");