1 float SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS = 1;
2 string redirection_target;
3 float world_initialized;
9 float() DoNextMapOverride;
13 void SetDefaultAlpha()
15 if(cvar("g_running_guns"))
17 default_player_alpha = -1;
18 default_weapon_alpha = +1;
22 default_player_alpha = cvar("g_balance_cloaked_alpha");
23 default_weapon_alpha = default_player_alpha;
27 default_player_alpha = cvar("g_player_alpha");
28 if(default_player_alpha <= 0)
29 default_player_alpha = 1;
30 default_weapon_alpha = default_player_alpha;
34 void fteqcc_testbugs()
38 if(!cvar("developer_fteqccbugs"))
41 dprint("*** fteqcc test: checking for bugs...\n");
45 if(sqrt(a) - sqrt(b - a) == 0)
46 dprint("*** fteqcc test: found same-function-twice bug\n");
48 dprint("*** fteqcc test: same-function-twice bug got FINALLY FIXED! HOORAY!\n");
52 world.enemy.cnt += 10;
53 if(world.cnt > 0.2 || world.cnt < -0.2) // don't error out if it's just roundoff errors
54 dprint("*** fteqcc test: found += bug\n");
56 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
61 * Takes care of pausing and unpausing the game.
62 * Centerprints the information about an upcoming or active timeout to all active
63 * players. Also plays reminder sounds.
65 void timeoutHandler_Think() {
68 if (timeoutStatus == 1) {
69 if (remainingLeadTime > 0) {
70 //centerprint the information to every player
71 timeStr = getTimeoutText(0);
72 FOR_EACH_REALCLIENT(plr) {
73 if(plr.classname == "player") {
74 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
77 remainingLeadTime -= 1;
78 //think again in 1 second:
79 self.nextthink = time + 1;
84 cvar_set("slowmo", ftos(TIMEOUT_SLOWMO_VALUE));
85 //copy .v_angle to .lastV_angle for every player in order to fix their view during pause (see PlayerPreThink)
86 FOR_EACH_REALPLAYER(plr) {
87 plr.lastV_angle = plr.v_angle;
89 self.nextthink = time;
92 else if (timeoutStatus == 2) {
93 if (remainingTimeoutTime > 0) {
94 timeStr = getTimeoutText(0);
95 FOR_EACH_REALCLIENT(plr) {
96 if(plr.classname == "player") {
97 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
100 if(remainingTimeoutTime == cvar("sv_timeout_resumetime")) { //play a warning sound when only <sv_timeout_resumetime> seconds are left
101 play2all("announcer/robotic/prepareforbattle.wav");
103 remainingTimeoutTime -= 1;
104 self.nextthink = time + TIMEOUT_SLOWMO_VALUE;
107 //unpause the game again
108 remainingTimeoutTime = timeoutStatus = 0;
109 cvar_set("slowmo", ftos(orig_slowmo));
110 //and unlock the fixed view again once there is no timeout active anymore
111 FOR_EACH_REALPLAYER(plr) {
112 plr.fixangle = FALSE;
114 //get rid of the countdown message
115 FOR_EACH_REALCLIENT(plr) {
116 if(plr.classname == "player") {
117 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
125 else if (timeoutStatus == 0) { //if a player called the resumegame command (which set timeoutStatus to 0 already)
126 FOR_EACH_REALCLIENT(plr) {
127 if(plr.classname == "player") {
128 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
140 cvar_set("_sv_init", "0");
141 if(cvar("g_maplist_shuffle"))
143 tokenizebyseparator(cvar_string("g_maplist"), " ");
145 cvar_set("nextmap", argv(0));
148 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
150 if(!DoNextMapOverride())
159 float world_already_spawned;
160 void RegisterWeapons();
161 void spawnfunc_worldspawn (void)
166 dprint_load(); // load dprint status from cvar
168 if(world_already_spawned)
169 error("world already spawned - you may have EXACTLY ONE worldspawn!");
170 world_already_spawned = TRUE;
172 compressShortVector_init();
175 head = nextent(world);
180 head = nextent(head);
183 // needs to be done so early as they would still spawn
190 ServerProgsDB = db_create();
192 ServerProgsDB = db_load("server.db");
195 TODO sound pack system
196 // initialize sound pack system
197 soundpack = cvar_string("g_soundpack");
199 soundpack = strcat(soundpack, "/");
200 soundpack = strzone(soundpack);
206 // 1 FLICKER (first variety)
207 lightstyle(1, "mmnmmommommnonmmonqnmmo");
209 // 2 SLOW STRONG PULSE
210 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
212 // 3 CANDLE (first variety)
213 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
216 lightstyle(4, "mamamamamama");
219 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
221 // 6 FLICKER (second variety)
222 lightstyle(6, "nmonqnmomnmomomno");
224 // 7 CANDLE (second variety)
225 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
227 // 8 CANDLE (third variety)
228 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
230 // 9 SLOW STROBE (fourth variety)
231 lightstyle(9, "aaaaaaaazzzzzzzz");
233 // 10 FLUORESCENT FLICKER
234 lightstyle(10, "mmamammmmammamamaaamammma");
236 // 11 SLOW PULSE NOT FADE TO BLACK
237 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
239 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
244 if(cvar("g_campaign"))
251 bot_waypoints_for_items = cvar("g_waypoints_for_items");
252 if(bot_waypoints_for_items == 1)
253 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
254 bot_waypoints_for_items = 0;
256 // for setting by mapinfo
257 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
258 cvar_set("sv_q3acompat_machineshotgunswap", "0");
262 WaypointSprite_Init();
267 GameLogInit(); // prepare everything
268 if(cvar("sv_eventlog"))
270 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
271 s = strcat(s, ftos(random()));
272 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
273 s = ":gameinfo:mutators:LIST";
274 if(cvar("g_grappling_hook"))
275 s = strcat(s, ":grappling_hook");
276 if(!cvar("g_use_ammunition"))
277 s = strcat(s, ":no_use_ammunition");
278 if(!cvar("g_pickup_items"))
279 s = strcat(s, ":no_pickup_items");
280 if(cvar("g_instagib"))
281 s = strcat(s, ":instagib");
282 if(cvar("g_rocketarena"))
283 s = strcat(s, ":rockerarena");
285 s = strcat(s, ":nixnex");
286 if(cvar("g_vampire"))
287 s = strcat(s, ":vampire");
288 if(cvar("g_laserguided_missile"))
289 s = strcat(s, ":laserguided_missile");
290 if(cvar("g_norecoil"))
291 s = strcat(s, ":norecoil");
293 s = strcat(s, ":midair");
294 if(cvar("g_minstagib"))
295 s = strcat(s, ":minstagib");
297 GameLogEcho(":gameinfo:end");
300 cvar_set("nextmap", "");
304 if(cvar("g_campaign"))
311 //initialise globals related to sv_timeout
312 sys_ticrate = cvar("sys_ticrate");
313 orig_slowmo = cvar("slowmo");
316 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
318 //if tourney is used map starts in warmup mode. if this mode shall stay unlimited, reset timelimit, but save the original one
320 timelimit_orig = cvar("timelimit");
321 cvar_set("timelimit", "0");
324 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
326 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
329 while((s = fgets(fd)))
336 print("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
337 print(" cdtrack ", argv(2), "\n");
339 else if(argv(0) == "fog")
341 print("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
342 print(" \"fog\" \"", s, "\"\n");
344 else if(argv(0) == "set")
346 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
347 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
349 else if(argv(0) != "//")
351 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
352 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
359 addstat(STAT_SYS_TICRATE, AS_FLOAT, stat_sys_ticrate);
360 addstat(STAT_WEAPONS, AS_INT, weapons);
361 addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
363 next_pingtime = time + 5;
364 world_initialized = 1;
367 void spawnfunc_light (void)
369 //makestatic (self); // Who the f___ did that?
373 float TryFile( string pFilename )
376 dprint("TryFile(\"", pFilename, "\")\n");
377 lHandle = fopen( pFilename, FILE_READ );
378 if( lHandle != -1 ) {
388 return GametypeNameFromType(game);
391 string getmapname_stored;
397 float Map_Count, Map_Current;
398 string Map_Current_Name;
400 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
401 float GetMaplistPosition()
407 idx = cvar("g_maplist_index");
414 for(pos = 0; pos < Map_Count; ++pos)
418 // resume normal maplist rotation if current map is not in g_maplist
422 float MapHasRightSize(string map)
425 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
426 if(cvar("g_maplist_check_waypoints"))
428 dprint("checkwp "); dprint(map);
429 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
432 dprint(": no waypoints\n");
435 dprint(": has waypoints\n");
439 // open map size restriction file
440 dprint("opensize "); dprint(map);
441 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
444 float mapmin, mapmax;
446 mapmin = stof(fgets(fh));
447 mapmax = stof(fgets(fh));
449 if(player_count < mapmin)
451 dprint("not enough\n");
454 if(player_count > mapmax)
456 dprint("too many\n");
459 dprint("right size\n");
462 dprint(": not found\n");
466 string Map_Filename(float position)
468 return strcat("maps/", argv(position), ".bsp");
471 string strwords(string s, float w)
474 for(endpos = 0; w && endpos >= 0; --w)
475 endpos = strstrofs(s, " ", endpos + 1);
479 return substring(s, 0, endpos);
482 float strhasword(string s, string w)
484 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
487 void Map_MarkAsRecent(string m)
489 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
492 float Map_IsRecent(string m)
494 return strhasword(cvar_string("g_maplist_mostrecent"), m);
497 float Map_Check(float position, float pass)
501 map_next = argv(position);
504 if(map_next == Map_Current_Name) // same map again in first pass?
506 if(Map_IsRecent(map_next))
509 filename = Map_Filename(position);
510 if(MapInfo_CheckMap(map_next))
514 if(MapHasRightSize(map_next))
519 dprint( "Couldn't select '", filename, "'..\n" );
524 void Map_Goto_SetStr(string nextmapname)
526 if(getmapname_stored != "")
527 strunzone(getmapname_stored);
528 if(nextmapname == "")
529 getmapname_stored = "";
531 getmapname_stored = strzone(nextmapname);
534 void Map_Goto_SetFloat(float position)
536 cvar_set("g_maplist_index", ftos(position));
537 Map_Goto_SetStr(argv(position));
542 // settings persist, except...
543 if(cvar("g_campaign"))
544 localcmd("\nexec mutator_reset.cfg\n");
545 localcmd("\nsettemp_restore\n");
550 Map_MarkAsRecent(getmapname_stored);
552 MapInfo_LoadMap(getmapname_stored);
555 // return codes of map selectors:
556 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
557 // -2 = permanent failure
558 float() MaplistMethod_Iterate = // usual method
562 for(pass = 1; pass <= 2; ++pass)
564 for(i = 1; i < Map_Count; ++i)
567 mapindex = mod(i + Map_Current, Map_Count);
568 if(Map_Check(mapindex, pass))
575 float() MaplistMethod_Repeat = // fallback method
577 if(Map_Check(Map_Current, 2))
582 float() MaplistMethod_Random = // random map selection
588 for(i = 0; i <= imax; ++i)
591 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
592 if(Map_Check(mapindex, 1))
598 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
599 // the exponent sets a bias on the map selection:
600 // the higher the exponent, the less likely "shortly repeated" same maps are
602 float i, j, imax, insertpos;
606 for(i = 0; i <= imax; ++i)
610 // now reinsert this at another position
611 insertpos = pow(random(), 1 / exponent); // ]0, 1]
612 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
613 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
614 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
616 // insert the current map there
618 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
619 newlist = strcat(newlist, " ", argv(j));
620 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
621 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
622 newlist = strcat(newlist, " ", argv(j));
623 newlist = substring(newlist, 1, strlen(newlist) - 1);
624 cvar_set("g_maplist", newlist);
625 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
627 // NOTE: the selected map has just been inserted at (insertpos-1)th position
628 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
629 if(Map_Check(Map_Current, 1))
638 temp = cvar_string("g_maplist");
639 Map_Count = tokenizebyseparator(temp, " ");
642 bprint( "Maplist is empty! Resetting it to default map list.\n" );
643 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
644 localcmd("\nmenu_cmd sync\n");
645 Map_Count = tokenizebyseparator(temp, " ");
648 error("empty maplist, cannot select a new map");
649 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
652 strunzone(Map_Current_Name);
653 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
654 // this may or may not be correct, but who cares, in the worst case a map
655 // isn't chosen in the first pass that should have been
666 if(cvar("g_maplist_shuffle") > 0)
667 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
670 if(cvar("g_maplist_selectrandom"))
671 nextMap = MaplistMethod_Random();
674 nextMap = MaplistMethod_Iterate();
677 nextMap = MaplistMethod_Repeat();
681 Map_Goto_SetFloat(nextMap);
682 return getmapname_stored;
688 float DoNextMapOverride()
690 if(cvar("g_campaign"))
692 CampaignPostIntermission();
693 alreadychangedlevel = TRUE;
696 if(cvar("quit_when_empty"))
698 if(player_count <= currentbots)
701 alreadychangedlevel = TRUE;
705 if(cvar_string("quit_and_redirect") != "")
707 redirection_target = strzone(cvar_string("quit_and_redirect"));
708 alreadychangedlevel = TRUE;
711 if (cvar("samelevel")) // if samelevel is set, stay on same level
713 // this does not work because it tries to exec maps/nexdm01.mapcfg (which doesn't exist, it should be trying maps/dm_nexdm01.mapcfg for example)
714 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
715 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
716 localcmd("restart\n");
717 //changelevel (mapname);
718 alreadychangedlevel = TRUE;
721 if(cvar_string("nextmap") != "")
722 if(MapInfo_CheckMap(cvar_string("nextmap")))
724 Map_Goto_SetStr(cvar_string("nextmap"));
726 alreadychangedlevel = TRUE;
729 if(cvar("lastlevel"))
732 localcmd("set lastlevel 0\ntogglemenu\n");
733 alreadychangedlevel = TRUE;
741 //local string nextmap;
742 //local float n, nummaps;
744 if (alreadychangedlevel)
746 alreadychangedlevel = TRUE;
752 for(allowReset = 1; allowReset >= 0; --allowReset)
754 nextMap = GetNextMap();
760 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
761 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
762 localcmd("\nmenu_cmd sync\n");
766 error("Everything is broken - not even the default map list works. Please report this to the developers.");
778 When the player presses attack or jump, change to the next level
781 .float autoscreenshot;
782 void() MapVote_Start;
783 void() MapVote_Think;
784 float mapvote_initialized;
785 void IntermissionThink()
787 FixIntermissionClient(self);
789 if(cvar("sv_autoscreenshot"))
790 if(self.autoscreenshot > 0)
791 if(time > self.autoscreenshot)
793 self.autoscreenshot = -1;
794 if(clienttype(self) == CLIENTTYPE_REAL)
795 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
799 if (time < intermission_exittime)
802 if(!mapvote_initialized)
803 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
813 Returns the entity to view from
817 entity FindIntermission()
822 // look for info_intermission first
823 spot = find (world, classname, "info_intermission");
825 { // pick a random one
829 spot = find (spot, classname, "info_intermission");
831 spot = find (spot, classname, "info_intermission");
837 // then look for the start position
838 spot = find (world, classname, "info_player_start");
842 // testinfo_player_start is only found in regioned levels
843 spot = find (world, classname, "testplayerstart");
847 // then look for the start position
848 spot = find (world, classname, "info_player_deathmatch");
852 //objerror ("FindIntermission: no spot");
858 ===============================================================================
862 ===============================================================================
865 void DumpStats(float final)
869 local float to_console;
870 local float to_eventlog;
874 to_console = cvar("sv_logscores_console");
875 to_eventlog = cvar("sv_eventlog");
876 to_file = cvar("sv_logscores_file");
880 to_console = TRUE; // always print printstats replies
881 to_eventlog = FALSE; // but never print them to the event log
885 if(cvar("sv_eventlog_console"))
886 to_console = FALSE; // otherwise we get the output twice
892 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
900 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
904 fputs(file, strcat(s, "\n"));
907 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
912 fputs(file, strcat(s, "\n"));
914 FOR_EACH_CLIENT(other)
916 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
918 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
919 s = strcat(s, ftos(rint(time - other.jointime)), ":");
920 if(other.classname == "player" || g_arena || g_lms)
921 s = strcat(s, ftos(other.team), ":");
923 s = strcat(s, "spectator:");
926 print(s, other.netname, "\n");
928 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
930 fputs(file, strcat(s, other.netname, "\n"));
936 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
942 fputs(file, strcat(s, "\n"));
944 for(i = 1; i < 16; ++i)
946 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
947 s = strcat(s, ":", ftos(i));
953 fputs(file, strcat(s, "\n"));
963 fputs(file, ":end\n");
968 void FixIntermissionClient(entity e)
971 if(!e.autoscreenshot) // initial call
973 e.angles = e.v_angle;
974 e.angles_x = -e.angles_x;
975 e.autoscreenshot = time + 0.8; // used for autoscreenshot
977 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
979 e.movetype = MOVETYPE_NONE;
980 e.takedamage = DAMAGE_NO;
982 e.weaponentity.effects = EF_NODRAW;
983 if(clienttype(e) == CLIENTTYPE_REAL)
985 stuffcmd(e, "\nscr_printspeed 1000000\n");
986 s = cvar_string("sv_intermission_cdtrack");
988 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
990 WriteByte(MSG_ONE, SVC_INTERMISSION);
994 //e.velocity = '0 0 0';
997 // TODO halt weapon animation
1002 go to the next level for deathmatch
1003 only called if a time or frag limit has expired
1007 float minTotalFrags;
1008 float maxTotalFrags;
1014 intermission_running = 1;
1016 // enforce a wait time before allowing changelevel
1017 if(player_count > 0)
1018 intermission_exittime = time + cvar("sv_mapchange_delay");
1020 intermission_exittime = -1;
1023 WriteByte (MSG_ALL, SVC_CDTRACK);
1024 WriteByte (MSG_ALL, 3);
1025 WriteByte (MSG_ALL, 3);
1026 // done in FixIntermission
1029 //pos = FindIntermission ();
1035 if(cvar("sv_eventlog"))
1036 GameLogEcho(":gameover");
1040 FOR_EACH_CLIENT(other)
1042 FixIntermissionClient(other);
1045 bprint(other.netname, " ^7wins.\n");
1050 FOR_EACH_PLAYER(other)
1052 if(maxTotalFrags < other.totalfrags)
1053 maxTotalFrags = other.totalfrags;
1054 if(minTotalFrags > other.totalfrags)
1055 minTotalFrags = other.totalfrags;
1060 FOR_EACH_PLAYER(other)
1062 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1063 f = bound(0, other.play_time / max(time, 1), 1);
1064 // store some statistics?
1068 if(cvar("g_campaign"))
1069 CampaignPreIntermission();
1071 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1078 Exit deathmatch games upon conditions
1082 void CheckRules_Player()
1084 if (gameover) // someone else quit the game already
1087 if(self.deadflag == DEAD_NO)
1088 self.play_time += frametime;
1092 if(time > self.fogtime)
1094 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1095 self.fogtime = time + sv_foginterval;
1098 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1099 // (div0: and that in CheckRules_World please)
1102 float checkrules_oneminutewarning;
1104 float checkrules_equality;
1105 float checkrules_overtimewarning;
1106 float checkrules_overtimeend;
1108 void InitiateOvertime()
1110 if(!checkrules_overtimeend)
1111 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1114 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1115 float WINNING_YES = 1; // winner found
1116 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1117 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1119 float GetWinningCode(float fraglimitreached, float equality)
1122 if(fraglimitreached)
1123 return WINNING_STARTOVERTIME;
1125 return WINNING_NEVER;
1127 if(fraglimitreached)
1133 // set the .winning flag for exactly those players with a given field value
1134 void SetWinners(.float field, float value)
1137 FOR_EACH_PLAYER(head)
1138 head.winning = (head.field == value);
1141 // set the .winning flag for those players with a given field value
1142 void AddWinners(.float field, float value)
1145 FOR_EACH_PLAYER(head)
1146 if(head.field == value)
1150 // clear the .winning flags
1151 void ClearWinners(void)
1154 FOR_EACH_PLAYER(head)
1158 // Onslaught winning condition:
1159 // game terminates if only one team has a working generator (or none)
1160 float WinningCondition_Onslaught()
1163 local float t1, t2, t3, t4;
1164 // first check if the game has ended
1165 t1 = t2 = t3 = t4 = 0;
1166 head = find(world, classname, "onslaught_generator");
1169 if (head.health > 0)
1171 if (head.team == COLOR_TEAM1) t1 = 1;
1172 if (head.team == COLOR_TEAM2) t2 = 1;
1173 if (head.team == COLOR_TEAM3) t3 = 1;
1174 if (head.team == COLOR_TEAM4) t4 = 1;
1176 head = find(head, classname, "onslaught_generator");
1178 if (t1 + t2 + t3 + t4 < 2)
1180 // game over, only one team remains (or none)
1182 if (t1) SetWinners(team, COLOR_TEAM1);
1183 if (t2) SetWinners(team, COLOR_TEAM2);
1184 if (t3) SetWinners(team, COLOR_TEAM3);
1185 if (t4) SetWinners(team, COLOR_TEAM4);
1186 dprint("Have a winner, ending game.\n");
1190 // Two or more teams remain
1194 float LMS_NewPlayerLives()
1197 fl = cvar("fraglimit");
1201 // first player has left the game for dying too much? Nobody else can get in.
1202 if(lms_lowest_lives < 1)
1205 if(!cvar("g_lms_join_anytime"))
1206 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1209 return bound(1, lms_lowest_lives, fl);
1212 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1213 // they win. Otherwise the defending team wins once the timelimit passes.
1214 void assault_new_round();
1215 float WinningCondition_Assault()
1218 status = WINNING_NO;
1220 // as the timelimit has not yet passed just assume the defending team will win
1221 if(assault_attacker_team == COLOR_TEAM1)
1223 SetWinners(team, COLOR_TEAM2);
1227 SetWinners(team, COLOR_TEAM1);
1231 ent = find(world, classname, "target_assault_roundend");
1234 if(ent.winning) // round end has been triggered by attacking team
1236 SetWinners(team, assault_attacker_team);
1237 if(assault_attacker_team == COLOR_TEAM1)
1239 team1_score = team1_score + 50;
1243 team2_score = team2_score + 50;
1246 if(ent.cnt == 1) // this was the second round
1248 status = WINNING_YES;
1252 local entity oldself;
1255 cvar_set("timelimit", ftos((2*time)/60));
1256 assault_new_round();
1266 // LMS winning condition: game terminates if and only if there's at most one
1267 // one player who's living lives. Top two scores being equal cancels the time
1269 float WinningCondition_LMS()
1276 have_player = FALSE;
1277 have_players = FALSE;
1278 l = LMS_NewPlayerLives();
1280 head = find(world, classname, "player");
1283 head2 = find(head, classname, "player");
1285 have_players = TRUE;
1289 // we have at least one player
1292 // two or more active players - continue with the game
1296 // exactly one player?
1299 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1303 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1309 // and assign him his first place
1310 PlayerScore_Add(head, SP_LMS_RANK, 1);
1317 // nobody is playing at all...
1320 // wait for players...
1324 // SNAFU (maybe a draw game?)
1326 dprint("No players, ending game.\n");
1331 // When we get here, we have at least two players who are actually LIVING,
1332 // now check if the top two players have equal score.
1333 WinningConditionHelper();
1336 if(WinningConditionHelper_winner)
1337 WinningConditionHelper_winner.winning = TRUE;
1338 if(WinningConditionHelper_equality)
1339 return WINNING_NEVER;
1341 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1345 void print_to(entity e, string s)
1348 sprint(e, strcat(s, "\n"));
1353 void ShuffleMaplist()
1361 result = cvar_string("g_maplist");
1362 litems = tokenizebyseparator(result, " ");
1364 for(start = 0; start < litems - 1; ++start)
1368 // select a random item
1369 selected = ceil(random() * (litems - start) + start) - 1;
1371 // shift this item to the place start
1372 for(i = 0; i < start; ++i)
1373 result = strcat(result, " ", argv(i));
1374 result = strcat(result, " ", argv(selected));
1375 for(i = start; i < litems; ++i)
1377 result = strcat(result, " ", argv(i));
1378 result = substring(result, 1, strlen(result) - 1);
1380 litems = tokenizebyseparator(result, " ");
1382 //dprint(result, "\n");
1385 cvar_set("g_maplist", result);
1388 float WinningCondition_Scores(float limit)
1390 // TODO make everything use THIS winning condition (except LMS)
1391 WinningConditionHelper();
1395 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1396 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1397 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1398 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1402 if(WinningConditionHelper_winner)
1403 WinningConditionHelper_winner.winning = 1;
1404 if(WinningConditionHelper_winnerteam >= 0)
1405 SetWinners(team, WinningConditionHelper_winnerteam);
1407 if(WinningConditionHelper_lowerisbetter)
1409 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1413 return GetWinningCode(limit && WinningConditionHelper_topscore && (WinningConditionHelper_topscore >= limit), WinningConditionHelper_equality);
1416 float WinningCondition_Race(float fraglimit)
1420 wc = WinningCondition_Scores(fraglimit);
1422 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1423 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1424 // do NOT support equality when the laps are all raced!
1427 if not(p.race_completed)
1428 return WINNING_STARTOVERTIME;
1434 void ReadyRestart();
1435 float WinningCondition_QualifyingThenRace(float limit)
1438 wc = WinningCondition_Scores(limit);
1440 // NEVER initiate overtime
1441 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1442 // do NOT support equality when the laps are all raced!
1445 float playerswithlaps;
1447 totalplayers = playerswithlaps = 0;
1448 FOR_EACH_PLAYER(head)
1451 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
1455 // at least 2/3 of the players have completed a lap: start the RACE
1456 // otherwise, the players should end the qualifying on their own
1457 if(totalplayers >= 3)
1458 if(playerswithlaps >= totalplayers * 2 / 3)
1460 checkrules_overtimeend = 0;
1462 return WINNING_NEVER;
1471 float WinningCondition_RanOutOfSpawns()
1475 if(!have_team_spawns)
1478 if(!some_spawn_has_been_used)
1481 team1_score = team2_score = team3_score = team4_score = 0;
1483 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1485 if(head.team == COLOR_TEAM1)
1487 else if(head.team == COLOR_TEAM2)
1489 else if(head.team == COLOR_TEAM3)
1491 else if(head.team == COLOR_TEAM4)
1495 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1497 if(head.team == COLOR_TEAM1)
1499 else if(head.team == COLOR_TEAM2)
1501 else if(head.team == COLOR_TEAM3)
1503 else if(head.team == COLOR_TEAM4)
1508 if(team1_score + team2_score + team3_score + team4_score == 0)
1510 checkrules_equality = TRUE;
1513 else if(team1_score + team2_score + team3_score + team4_score == 1)
1516 if(team1_score) t = COLOR_TEAM1;
1517 if(team2_score) t = COLOR_TEAM2;
1518 if(team3_score) t = COLOR_TEAM3;
1519 if(team4_score) t = COLOR_TEAM4;
1520 CheckAllowedTeams(world);
1521 for(i = 0; i < MAX_TEAMSCORE; ++i)
1523 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
1524 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
1525 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
1526 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
1529 AddWinners(team, t);
1540 Exit deathmatch games upon conditions
1543 void CheckRules_World()
1546 local float timelimit;
1547 local float fraglimit;
1555 MapVote_Think should now do that part
1556 if (intermission_running)
1557 if (time >= intermission_exittime + 60)
1559 if(!DoNextMapOverride())
1565 if (gameover) // someone else quit the game already
1567 if(player_count == 0) // Nobody there? Then let's go to the next map
1569 // this will actually check the player count in the next frame
1570 // again, but this shouldn't hurt
1574 timelimit = cvar("timelimit") * 60;
1575 fraglimit = cvar("fraglimit");
1578 fraglimit = 0; // no fraglimit for now
1580 if(checkrules_overtimeend)
1582 if(!checkrules_overtimewarning)
1584 checkrules_overtimewarning = TRUE;
1585 //announceall("announcer/robotic/1minuteremains.wav");
1586 if(!g_race_qualifying)
1587 bcenterprint("^3Everyone, finish your lap! The race is over!");
1589 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1594 if (timelimit && time >= timelimit)
1598 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1604 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1606 checkrules_oneminutewarning = TRUE;
1607 play2all("announcer/robotic/1minuteremains.wav");
1610 status = WinningCondition_RanOutOfSpawns();
1611 if(status == WINNING_YES)
1613 bprint("Hey! Someone ran out of spawns!\n");
1615 else if(g_race && !g_race_qualifying && timelimit >= 0)
1617 status = WinningCondition_Race(fraglimit);
1619 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
1621 status = WinningCondition_QualifyingThenRace(fraglimit);
1625 status = WinningCondition_Assault(); // TODO remove this?
1629 status = WinningCondition_LMS();
1631 else if (g_onslaught)
1633 status = WinningCondition_Onslaught(); // TODO remove this?
1637 status = WinningCondition_Scores(fraglimit);
1640 if(status == WINNING_STARTOVERTIME)
1642 status = WINNING_NEVER;
1646 if(status == WINNING_NEVER)
1647 // equality cases! Nobody wins if the overtime ends in a draw.
1650 if(checkrules_overtimeend)
1651 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1652 status = WINNING_YES;
1654 if(status == WINNING_YES)
1658 float mapvote_nextthink;
1659 float mapvote_initialized;
1660 float mapvote_keeptwotime;
1661 float mapvote_timeout;
1662 string mapvote_message;
1663 string mapvote_screenshot_dir;
1665 float mapvote_count;
1666 float mapvote_count_real;
1667 string mapvote_maps[MAPVOTE_COUNT];
1668 float mapvote_maps_suggested[MAPVOTE_COUNT];
1669 string mapvote_suggestions[MAPVOTE_COUNT];
1670 float mapvote_suggestion_ptr;
1671 float mapvote_maxlen;
1672 float mapvote_voters;
1673 float mapvote_votes[MAPVOTE_COUNT];
1675 float mapvote_detail;
1676 float mapvote_abstain;
1677 float mapvote_dirty;
1680 void MapVote_ClearAllVotes()
1682 FOR_EACH_CLIENT(other)
1686 string MapVote_Suggest(string m)
1690 return "That's not how to use this command.";
1691 if(!cvar("g_maplist_votable_suggestions"))
1692 return "Suggestions are not accepted on this server.";
1693 if(mapvote_initialized)
1694 return "Can't suggest - voting is already in progress!";
1695 m = MapInfo_FixName(m);
1697 return "The map you suggested is not available on this server.";
1698 if(!cvar("g_maplist_votable_override_mostrecent"))
1700 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1702 if(!MapInfo_CheckMap(m))
1703 return "The map you suggested does not support the current game mode.";
1704 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1705 if(mapvote_suggestions[i] == m)
1706 return "This map was already suggested.";
1707 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1709 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1713 i = mapvote_suggestion_ptr;
1714 mapvote_suggestion_ptr += 1;
1716 if(mapvote_suggestions[i] != "")
1717 strunzone(mapvote_suggestions[i]);
1718 mapvote_suggestions[i] = strzone(m);
1719 if(cvar("sv_eventlog"))
1720 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
1721 return strcat("Suggestion of ", m, " accepted.");
1724 void MapVote_AddVotable(string nextMap, float isSuggestion)
1729 for(j = 0; j < mapvote_count; ++j)
1730 if(mapvote_maps[j] == nextMap)
1732 if(strlen(nextMap) > mapvote_maxlen)
1733 mapvote_maxlen = strlen(nextMap);
1734 mapvote_maps[mapvote_count] = strzone(nextMap);
1735 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1739 void MapVote_SendData(float target);
1745 MapVote_ClearAllVotes();
1748 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1749 mapvote_abstain = cvar("g_maplist_votable_abstain");
1752 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1754 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1755 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
1757 if(mapvote_suggestion_ptr)
1758 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1759 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1761 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1762 MapVote_AddVotable(GetNextMap(), FALSE);
1764 if(mapvote_count == 0)
1766 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1767 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1768 localcmd("\nmenu_cmd sync\n");
1769 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1770 MapVote_AddVotable(GetNextMap(), FALSE);
1773 mapvote_count_real = mapvote_count;
1775 MapVote_AddVotable("don't care", 0);
1777 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1779 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1780 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1781 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1782 mapvote_keeptwotime = 0;
1783 mapvote_message = "Choose a map and press its key!";
1785 mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
1786 if(mapvote_screenshot_dir == "")
1787 mapvote_screenshot_dir = "maps";
1788 mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
1790 if(!cvar("g_maplist_textonly"))
1791 MapVote_SendData(MSG_ALL);
1794 void MapVote_SendPicture(float id)
1797 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1798 WriteByte(MSG_ONE, TE_CSQC_MAPVOTE);
1799 WriteByte(MSG_ONE, MAPVOTE_NET_PIC);
1800 WriteByte(MSG_ONE, id);
1801 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 3072);
1804 float GameCommand_MapVote(string cmd)
1806 if(!intermission_running)
1808 if(!cvar("g_maplist_textonly"))
1810 if(cmd == "mv_getpic")
1812 MapVote_SendPicture(stof(argv(1)));
1820 float MapVote_GetMapMask()
1822 float mask, i, power;
1824 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
1825 if(mapvote_maps[i] != "")
1830 void MapVote_SendData(float targ)
1832 string mapfile, pakfile;
1834 WriteByte(targ, SVC_TEMPENTITY);
1835 WriteByte(targ, TE_CSQC_CONFIG);
1836 WriteString(targ, "mv_screenshot_dir");
1837 WriteString(targ, mapvote_screenshot_dir);
1839 WriteByte(targ, SVC_TEMPENTITY);
1840 WriteByte(targ, TE_CSQC_MAPVOTE);
1841 WriteByte(targ, MAPVOTE_NET_INIT);
1843 WriteByte(targ, mapvote_count);
1844 WriteByte(targ, mapvote_abstain);
1845 WriteByte(targ, mapvote_detail);
1846 WriteCoord(targ, mapvote_timeout);
1847 if(mapvote_count <= 8)
1848 WriteByte(targ, MapVote_GetMapMask());
1850 WriteShort(targ, MapVote_GetMapMask());
1851 for(i = 0; i < mapvote_count; ++i)
1852 if(mapvote_maps[i] != "")
1854 WriteString(targ, mapvote_maps[i]);
1855 mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
1856 pakfile = whichpack(strcat(mapfile, ".tga"));
1858 pakfile = whichpack(strcat(mapfile, ".jpg"));
1860 pakfile = whichpack(strcat(mapfile, ".png"));
1861 print("pakfile is ", pakfile, "\n");
1862 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
1863 pakfile = substring(pakfile, o, 999);
1864 WriteString(targ, pakfile);
1868 void MapVote_UpdateData(float targ)
1871 WriteByte(targ, SVC_TEMPENTITY);
1872 WriteByte(targ, TE_CSQC_MAPVOTE);
1873 WriteByte(targ, MAPVOTE_NET_UPDATE);
1874 if(mapvote_count <= 8)
1875 WriteByte(targ, MapVote_GetMapMask());
1877 WriteShort(targ, MapVote_GetMapMask());
1879 for(i = 0; i < mapvote_count; ++i)
1880 if(mapvote_maps[i] != "")
1881 WriteByte(targ, mapvote_votes[i]);
1884 void MapVote_TellVote(float targ, float vote)
1886 WriteByte(targ, SVC_TEMPENTITY);
1887 WriteByte(targ, TE_CSQC_MAPVOTE);
1888 WriteByte(targ, MAPVOTE_NET_OWNVOTE);
1889 WriteByte(targ, vote);
1892 float MapVote_Finished(float mappos)
1898 if(cvar("sv_eventlog"))
1900 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1901 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1902 didntvote = mapvote_voters;
1903 for(i = 0; i < mapvote_count; ++i)
1904 if(mapvote_maps[i] != "")
1906 didntvote -= mapvote_votes[i];
1909 result = strcat(result, ":", mapvote_maps[i]);
1910 result = strcat(result, ":", ftos(mapvote_votes[i]));
1913 result = strcat(result, ":didn't vote:", ftos(didntvote));
1915 GameLogEcho(result);
1916 if(mapvote_maps_suggested[mappos])
1917 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
1920 FOR_EACH_REALCLIENT(other)
1921 FixClientCvars(other);
1923 Map_Goto_SetStr(mapvote_maps[mappos]);
1925 alreadychangedlevel = TRUE;
1928 void MapVote_CheckRules_1()
1932 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1934 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1935 mapvote_votes[i] = 0;
1939 FOR_EACH_REALCLIENT(other)
1944 i = other.mapvote - 1;
1945 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1946 mapvote_votes[i] = mapvote_votes[i] + 1;
1951 float MapVote_CheckRules_2()
1954 float firstPlace, secondPlace;
1955 float firstPlaceVotes, secondPlaceVotes;
1956 float mapvote_voters_real;
1959 mapvote_voters_real = mapvote_voters;
1961 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
1963 RandomSelection_Init();
1964 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1965 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
1966 firstPlace = RandomSelection_chosen_float;
1967 firstPlaceVotes = RandomSelection_best_priority;
1968 //dprint("First place: ", ftos(firstPlace), "\n");
1969 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1971 RandomSelection_Init();
1972 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1974 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
1975 secondPlace = RandomSelection_chosen_float;
1976 secondPlaceVotes = RandomSelection_best_priority;
1977 //dprint("Second place: ", ftos(secondPlace), "\n");
1978 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1980 if(firstPlace == -1)
1981 error("No first place in map vote... WTF?");
1983 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
1984 return MapVote_Finished(firstPlace);
1986 if(mapvote_keeptwotime)
1987 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
1990 mapvote_dirty = TRUE;
1991 mapvote_message = "Now decide between the TOP TWO!";
1992 mapvote_keeptwotime = 0;
1993 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
1994 result = strcat(result, ":", ftos(firstPlaceVotes));
1995 result = strcat(result, ":", mapvote_maps[secondPlace]);
1996 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
1997 didntvote = mapvote_voters;
1998 for(i = 0; i < mapvote_count; ++i)
1999 if(mapvote_maps[i] != "")
2001 didntvote -= mapvote_votes[i];
2003 if(i != secondPlace)
2005 result = strcat(result, ":", mapvote_maps[i]);
2006 result = strcat(result, ":", ftos(mapvote_votes[i]));
2007 if(i < mapvote_count_real)
2009 strunzone(mapvote_maps[i]);
2010 mapvote_maps[i] = "";
2014 result = strcat(result, ":didn't vote:", ftos(didntvote));
2015 if(cvar("sv_eventlog"))
2016 GameLogEcho(result);
2029 keeptwo = mapvote_keeptwotime;
2030 MapVote_CheckRules_1(); // count
2031 if(MapVote_CheckRules_2()) // decide
2035 FOR_EACH_REALCLIENT(other)
2037 // hide scoreboard again
2038 if(other.health != 2342)
2040 other.health = 2342;
2042 if(clienttype(other) == CLIENTTYPE_REAL)
2044 if(cvar("g_maplist_textonly"))
2045 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");
2048 WriteByte(MSG_ONE, SVC_FINALE);
2049 WriteString(MSG_ONE, "");
2053 // notify about keep-two
2054 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2055 play2(other, "misc/invshot.wav");
2057 // clear possibly invalid votes
2058 if(mapvote_maps[other.mapvote - 1] == "")
2060 // use impulses as new vote
2061 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2062 if(mapvote_maps[other.impulse - 1] != "")
2064 other.mapvote = other.impulse;
2066 mapvote_dirty = TRUE;
2069 MapVote_TellVote(MSG_ONE, other.mapvote);
2077 MapVote_CheckRules_1(); // just count
2079 if(!cvar("g_maplist_textonly"))
2080 if(mapvote_dirty) // 1 if "keeptwo" or "impulse" happened before
2082 MapVote_UpdateData(MSG_BROADCAST);
2083 mapvote_dirty = FALSE;
2086 if(cvar("g_maplist_textonly"))
2088 FOR_EACH_REALCLIENT(other)
2090 // display voting screen
2091 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2092 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2094 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2095 msgstr = strcat(msgstr, mapvote_message);
2096 msgstr = strcat(msgstr, "\n\n");
2097 for(i = 0; i < mapvote_count; ++i)
2098 if(mapvote_maps[i] == "")
2099 msgstr = strcat(msgstr, "\n");
2102 tmp = mapvote_maps[i];
2103 tmp = strpad(mapvote_maxlen, tmp);
2104 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2107 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2108 if(mapvote_votes[i] != 1)
2109 tmp = strcat(tmp, "s");
2110 tmp = strcat(tmp, ")");
2111 tmp = strpad(mapvote_maxlen + 15, tmp);
2114 if(i == mapvote_count - 1)
2115 msgstr = strcat(msgstr, "\n");
2116 if(other.mapvote == i + 1)
2117 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2119 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2122 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2124 msgstr = strcat(msgstr, "s");
2125 msgstr = strcat(msgstr, " cast");
2126 i = ceil(mapvote_timeout - time);
2127 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2129 msgstr = strcat(msgstr, "s");
2130 msgstr = strcat(msgstr, " left");
2132 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2136 void MapVote_Start()
2141 MapInfo_Enumerate();
2142 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2145 void MapVote_Think()
2150 if(alreadychangedlevel)
2153 if(time < mapvote_nextthink)
2157 mapvote_nextthink = time + 0.5;
2159 if(!mapvote_initialized)
2161 mapvote_initialized = TRUE;
2162 if(DoNextMapOverride())
2164 if(!cvar("g_maplist_votable") || player_count <= 0)
2175 string GotoMap(string m)
2177 if(!MapInfo_CheckMap(m))
2178 return "The map you chose is not available on this server.";
2179 cvar_set("nextmap", m);
2180 cvar_set("timelimit", "-1");
2181 if(mapvote_initialized || alreadychangedlevel)
2183 if(DoNextMapOverride())
2184 return "Map switch initiated.";
2186 return "Hm... no. For some reason I like THIS map more.";
2189 return "Map switch will happen after scoreboard.";
2195 FOR_EACH_REALCLIENT(self)
2197 if(self.classname == "spectator")
2199 if(self.enemy.hitsound)
2200 play2(self, "misc/hit.wav");
2205 play2(self, "misc/hit.wav");
2208 FOR_EACH_CLIENT(self)
2209 self.hitsound = FALSE;
2215 * returns TRUE if redirecting
2217 float redirection_timeout;
2218 float redirection_nextthink;
2219 float RedirectionThink()
2221 float clients_found;
2223 if(redirection_target == "")
2226 if(!redirection_timeout)
2228 cvar_set("sv_public", "-2");
2229 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2230 if(redirection_target == "self")
2231 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2233 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2236 if(time < redirection_nextthink)
2239 redirection_nextthink = time + 1;
2242 FOR_EACH_REALCLIENT(self)
2244 print("Redirecting: sending connect command to ", self.netname, "\n");
2245 if(redirection_target == "self")
2246 stuffcmd(self, "\ndisconnect; reconnect\n");
2248 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2252 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2254 if(time > redirection_timeout || clients_found == 0)
2255 localcmd("\nwait; wait; wait; quit\n");
2262 // Loaded from a save game
2263 // some things then break, so let's work around them...
2265 // Progs DB (capture records)
2267 ServerProgsDB = db_create();
2269 ServerProgsDB = db_load("server.db");
2273 MapInfo_Enumerate();
2274 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
2279 if(world_initialized)
2281 world_initialized = 0;
2282 print("Saving persistent data...\n");
2285 db_save(ServerProgsDB, "server.db");
2286 db_close(ServerProgsDB);
2288 // tell the bot system the game is ending now
2295 print("NOTE: crashed before even initializing the world, not saving persistent data\n");