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"))
144 tokenizebyseparator(cvar_string("g_maplist"), " ");
146 tokenize(cvar_string("g_maplist"));
147 if(argv(0) != GetMapname())
150 cvar_set("nextmap", argv(0));
154 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
157 if(!DoNextMapOverride())
166 float world_already_spawned;
167 void spawnfunc_worldspawn (void)
172 dprint_load(); // load dprint status from cvar
174 if(world_already_spawned)
175 error("world already spawned - you may have EXACTLY ONE worldspawn!");
176 world_already_spawned = TRUE;
178 compressShortVector_init();
181 head = nextent(world);
186 head = nextent(head);
193 ServerProgsDB = db_create();
195 ServerProgsDB = db_load("server.db");
198 TODO sound pack system
199 // initialize sound pack system
200 soundpack = cvar_string("g_soundpack");
202 soundpack = strcat(soundpack, "/");
203 soundpack = strzone(soundpack);
209 // 1 FLICKER (first variety)
210 lightstyle(1, "mmnmmommommnonmmonqnmmo");
212 // 2 SLOW STRONG PULSE
213 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
215 // 3 CANDLE (first variety)
216 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
219 lightstyle(4, "mamamamamama");
222 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
224 // 6 FLICKER (second variety)
225 lightstyle(6, "nmonqnmomnmomomno");
227 // 7 CANDLE (second variety)
228 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
230 // 8 CANDLE (third variety)
231 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
233 // 9 SLOW STROBE (fourth variety)
234 lightstyle(9, "aaaaaaaazzzzzzzz");
236 // 10 FLUORESCENT FLICKER
237 lightstyle(10, "mmamammmmammamamaaamammma");
239 // 11 SLOW PULSE NOT FADE TO BLACK
240 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
242 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
247 if(cvar("g_campaign"))
254 bot_waypoints_for_items = cvar("g_waypoints_for_items");
255 if(bot_waypoints_for_items == 1)
256 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
257 bot_waypoints_for_items = 0;
259 // for setting by mapinfo
260 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
261 cvar_set("sv_q3acompat_machineshotgunswap", "0");
265 WaypointSprite_Init();
270 GameLogInit(); // prepare everything
271 if(cvar("sv_eventlog"))
273 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
274 s = strcat(s, ftos(random()));
276 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s), FALSE);
278 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
280 s = ":gameinfo:mutators:LIST";
281 if(cvar("g_grappling_hook"))
282 s = strcat(s, ":grappling_hook");
283 if(!cvar("g_use_ammunition"))
284 s = strcat(s, ":no_use_ammunition");
285 if(!cvar("g_pickup_items"))
286 s = strcat(s, ":no_pickup_items");
287 if(cvar("g_instagib"))
288 s = strcat(s, ":instagib");
289 if(cvar("g_rocketarena"))
290 s = strcat(s, ":rockerarena");
292 s = strcat(s, ":nixnex");
293 if(cvar("g_vampire"))
294 s = strcat(s, ":vampire");
295 if(cvar("g_laserguided_missile"))
296 s = strcat(s, ":laserguided_missile");
297 if(cvar("g_norecoil"))
298 s = strcat(s, ":norecoil");
300 s = strcat(s, ":midair");
301 if(cvar("g_minstagib"))
302 s = strcat(s, ":minstagib");
303 GameLogEcho(s, FALSE);
304 GameLogEcho(":gameinfo:end", FALSE);
307 cvar_set("nextmap", "");
311 if(cvar("g_campaign"))
318 //initialise globals related to sv_timeout
319 sys_ticrate = cvar("sys_ticrate");
320 orig_slowmo = cvar("slowmo");
324 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
327 //if tourney is used map starts in warmup mode. if this mode shall stay unlimited, reset timelimit, but save the original one
328 if(g_tourney && cvar("g_tourney_warmup_unlimited_time")) {
329 timelimit_orig = cvar("timelimit");
330 cvar_set("timelimit", "0");
333 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
335 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
338 while((s = fgets(fd)))
345 print("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
346 print(" cdtrack ", argv(2), "\n");
348 else if(argv(0) == "fog")
350 print("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
351 print(" \"fog\" \"", s, "\"\n");
353 else if(argv(0) == "set")
355 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
356 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
358 else if(argv(0) != "//")
360 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
361 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
368 addstat(STAT_SYS_TICRATE, AS_FLOAT, stat_sys_ticrate);
370 next_pingtime = time + 5;
371 world_initialized = 1;
374 void spawnfunc_light (void)
376 //makestatic (self); // Who the f___ did that?
380 float TryFile( string pFilename )
383 dprint("TryFile(\"", pFilename, "\")\n");
384 lHandle = fopen( pFilename, FILE_READ );
385 if( lHandle != -1 ) {
395 return GametypeNameFromType(game);
398 float IsSameGametype(string mapcfgname)
401 return TRUE; // can't change game type by map name here
405 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
411 string getmapname_stored;
417 if(getmapname_stored == "")
418 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
419 return getmapname_stored;
423 float Map_Count, Map_Current;
424 string Map_Current_Name;
426 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
427 float GetMaplistPosition()
433 idx = cvar("g_maplist_index");
440 for(pos = 0; pos < Map_Count; ++pos)
444 // resume normal maplist rotation if current map is not in g_maplist
448 float MapHasRightSize(string map)
451 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
452 if(cvar("g_maplist_check_waypoints"))
454 dprint("checkwp "); dprint(map);
455 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
458 dprint(": no waypoints\n");
461 dprint(": has waypoints\n");
465 // open map size restriction file
466 dprint("opensize "); dprint(map);
467 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
470 float mapmin, mapmax;
472 mapmin = stof(fgets(fh));
473 mapmax = stof(fgets(fh));
475 if(player_count < mapmin)
477 dprint("not enough\n");
480 if(player_count > mapmax)
482 dprint("too many\n");
485 dprint("right size\n");
488 dprint(": not found\n");
492 string Map_Filename(float position)
495 return strcat("maps/", argv(position), ".bsp");
497 return strcat("maps/", argv(position), ".mapcfg");
501 string strwords(string s, float w)
504 for(endpos = 0; w && endpos >= 0; --w)
505 endpos = strstrofs(s, " ", endpos + 1);
509 return substring(s, 0, endpos);
512 float strhasword(string s, string w)
514 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
517 void Map_MarkAsRecent(string m)
519 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
522 float Map_IsRecent(string m)
524 return strhasword(cvar_string("g_maplist_mostrecent"), m);
527 float Map_Check(float position, float pass)
531 map_next = argv(position);
534 if(map_next == Map_Current_Name) // same map again in first pass?
536 if(Map_IsRecent(map_next))
539 filename = Map_Filename(position);
541 if(MapInfo_CheckMap(map_next))
543 if(TryFile(filename))
548 if(MapHasRightSize(map_next))
553 dprint( "Couldn't select '", filename, "'..\n" );
558 void Map_Goto_SetStr(string nextmapname)
560 if(getmapname_stored != "")
561 strunzone(getmapname_stored);
562 if(nextmapname == "")
563 getmapname_stored = "";
565 getmapname_stored = strzone(nextmapname);
568 void Map_Goto_SetFloat(float position)
570 cvar_set("g_maplist_index", ftos(position));
571 Map_Goto_SetStr(argv(position));
577 // settings persist, except...
578 if(cvar("g_campaign"))
579 localcmd("\nexec mutator_reset.cfg\n");
580 localcmd("\nsettemp_restore\n");
582 // if an exit cfg is defined by exiting map, exec it.
584 exit_cfg = cvar_string("exit_cfg");
586 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
588 localcmd("exec game_reset.cfg\n");
594 Map_MarkAsRecent(getmapname_stored);
597 MapInfo_LoadMap(getmapname_stored);
599 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
603 // return codes of map selectors:
604 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
605 // -2 = permanent failure
606 float() MaplistMethod_Iterate = // usual method
610 for(pass = 1; pass <= 2; ++pass)
612 for(i = 1; i < Map_Count; ++i)
615 mapindex = mod(i + Map_Current, Map_Count);
616 if(Map_Check(mapindex, pass))
623 float() MaplistMethod_Repeat = // fallback method
625 if(Map_Check(Map_Current, 2))
630 float() MaplistMethod_Random = // random map selection
636 for(i = 0; i <= imax; ++i)
639 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
640 if(Map_Check(mapindex, 1))
646 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
647 // the exponent sets a bias on the map selection:
648 // the higher the exponent, the less likely "shortly repeated" same maps are
650 float i, j, imax, insertpos;
654 for(i = 0; i <= imax; ++i)
658 // now reinsert this at another position
659 insertpos = pow(random(), 1 / exponent); // ]0, 1]
660 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
661 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
662 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
664 // insert the current map there
667 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
668 newlist = strcat(newlist, " ", argv(j));
669 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
670 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
671 newlist = strcat(newlist, " ", argv(j));
672 newlist = substring(newlist, 1, strlen(newlist) - 1);
674 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
675 newlist = strcat(newlist, "'", argv(j), "'");
676 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
677 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
678 newlist = strcat(newlist, "'", argv(j), "'");
680 cvar_set("g_maplist", newlist);
682 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
684 Map_Count = tokenize(newlist);
687 // NOTE: the selected map has just been inserted at (insertpos-1)th position
688 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
689 if(Map_Check(Map_Current, 1))
698 temp = cvar_string("g_maplist");
700 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
702 Map_Count = tokenize(temp);
706 bprint( "Maplist is empty! Resetting it to default map list.\n" );
708 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
709 localcmd("\nmenu_cmd sync\n");
710 Map_Count = tokenizebyseparator(temp, " ");
712 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
713 Map_Count = tokenize(temp);
717 error("empty maplist, cannot select a new map");
718 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
721 strunzone(Map_Current_Name);
722 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
723 // this may or may not be correct, but who cares, in the worst case a map
724 // isn't chosen in the first pass that should have been
735 if(cvar("g_maplist_shuffle") > 0)
736 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
739 if(cvar("g_maplist_selectrandom"))
740 nextMap = MaplistMethod_Random();
743 nextMap = MaplistMethod_Iterate();
746 nextMap = MaplistMethod_Repeat();
750 Map_Goto_SetFloat(nextMap);
751 return getmapname_stored;
757 float DoNextMapOverride()
759 if(cvar("g_campaign"))
761 CampaignPostIntermission();
762 alreadychangedlevel = TRUE;
765 if(cvar("quit_when_empty"))
767 if(player_count <= currentbots)
770 alreadychangedlevel = TRUE;
774 if(cvar_string("quit_and_redirect") != "")
776 redirection_target = strzone(cvar_string("quit_and_redirect"));
777 alreadychangedlevel = TRUE;
780 if (cvar("samelevel")) // if samelevel is set, stay on same level
782 // 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)
783 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
784 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
785 localcmd("restart\n");
786 //changelevel (mapname);
787 alreadychangedlevel = TRUE;
790 if(cvar_string("nextmap") != "")
792 if(MapInfo_CheckMap(cvar_string("nextmap")))
794 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
797 Map_Goto_SetStr(cvar_string("nextmap"));
799 alreadychangedlevel = TRUE;
802 if(cvar("lastlevel"))
805 localcmd("set lastlevel 0\ntogglemenu\n");
806 alreadychangedlevel = TRUE;
814 //local string nextmap;
815 //local float n, nummaps;
817 if (alreadychangedlevel)
819 alreadychangedlevel = TRUE;
825 for(allowReset = 1; allowReset >= 0; --allowReset)
827 nextMap = GetNextMap();
833 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
835 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
836 localcmd("\nmenu_cmd sync\n");
838 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
843 error("Everything is broken - not even the default map list works. Please report this to the developers.");
855 When the player presses attack or jump, change to the next level
858 .float autoscreenshot;
859 void() MapVote_Start;
860 void() MapVote_Think;
861 float mapvote_initialized;
862 void IntermissionThink()
864 FixIntermissionClient(self);
866 if(cvar("sv_autoscreenshot"))
867 if(self.autoscreenshot > 0)
868 if(time > self.autoscreenshot)
870 self.autoscreenshot = -1;
871 if(clienttype(self) == CLIENTTYPE_REAL)
872 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
876 if (time < intermission_exittime)
879 if(!mapvote_initialized)
880 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
890 Returns the entity to view from
894 entity FindIntermission()
899 // look for info_intermission first
900 spot = find (world, classname, "info_intermission");
902 { // pick a random one
906 spot = find (spot, classname, "info_intermission");
908 spot = find (spot, classname, "info_intermission");
914 // then look for the start position
915 spot = find (world, classname, "info_player_start");
919 // testinfo_player_start is only found in regioned levels
920 spot = find (world, classname, "testplayerstart");
924 // then look for the start position
925 spot = find (world, classname, "info_player_deathmatch");
929 //objerror ("FindIntermission: no spot");
935 ===============================================================================
939 ===============================================================================
942 void DumpStats(float final)
946 local float to_console;
947 local float to_eventlog;
951 to_console = cvar("sv_logscores_console");
952 to_eventlog = cvar("sv_eventlog");
953 to_file = cvar("sv_logscores_file");
957 to_console = TRUE; // always print printstats replies
958 to_eventlog = FALSE; // but never print them to the event log
962 if(cvar("sv_eventlog_console"))
963 to_console = FALSE; // otherwise we get the output twice
970 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
972 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
976 ServerConsoleEcho(s, FALSE);
978 GameLogEcho(s, FALSE);
981 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
985 fputs(file, strcat(s, "\n"));
988 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
990 ServerConsoleEcho(s, TRUE);
992 GameLogEcho(s, TRUE);
994 fputs(file, strcat(s, "\n"));
996 FOR_EACH_CLIENT(other)
998 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
1000 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
1001 s = strcat(s, ftos(rint(time - other.jointime)), ":");
1002 if(other.classname == "player" || g_arena || g_lms)
1003 s = strcat(s, ftos(other.team), ":");
1005 s = strcat(s, "spectator:");
1008 ServerConsoleEcho(strcat(s, other.netname), TRUE);
1010 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
1012 fputs(file, strcat(s, other.netname, "\n"));
1018 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
1020 ServerConsoleEcho(s, TRUE);
1022 GameLogEcho(s, TRUE);
1024 fputs(file, strcat(s, "\n"));
1026 for(i = 1; i < 16; ++i)
1028 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
1029 s = strcat(s, ":", ftos(i));
1031 ServerConsoleEcho(s, TRUE);
1033 GameLogEcho(s, TRUE);
1035 fputs(file, strcat(s, "\n"));
1040 ServerConsoleEcho(":end", FALSE);
1042 GameLogEcho(":end", FALSE);
1045 fputs(file, ":end\n");
1050 void FixIntermissionClient(entity e)
1053 if(!e.autoscreenshot) // initial call
1055 e.angles = e.v_angle;
1056 e.angles_x = -e.angles_x;
1057 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1059 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1060 e.solid = SOLID_NOT;
1061 e.movetype = MOVETYPE_NONE;
1062 e.takedamage = DAMAGE_NO;
1064 e.weaponentity.effects = EF_NODRAW;
1065 if(clienttype(e) == CLIENTTYPE_REAL)
1067 stuffcmd(e, "\nscr_printspeed 1000000\n");
1068 s = cvar_string("sv_intermission_cdtrack");
1070 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1072 WriteByte(MSG_ONE, SVC_INTERMISSION);
1076 //e.velocity = '0 0 0';
1077 //e.fixangle = TRUE;
1079 // TODO halt weapon animation
1084 go to the next level for deathmatch
1085 only called if a time or frag limit has expired
1089 float minTotalFrags;
1090 float maxTotalFrags;
1096 intermission_running = 1;
1098 // enforce a wait time before allowing changelevel
1099 if(player_count > 0)
1100 intermission_exittime = time + cvar("sv_mapchange_delay");
1102 intermission_exittime = -1;
1105 WriteByte (MSG_ALL, SVC_CDTRACK);
1106 WriteByte (MSG_ALL, 3);
1107 WriteByte (MSG_ALL, 3);
1108 // done in FixIntermission
1111 //pos = FindIntermission ();
1117 if(cvar("sv_eventlog"))
1118 GameLogEcho(":gameover", FALSE);
1122 FOR_EACH_CLIENT(other)
1124 FixIntermissionClient(other);
1127 bprint(other.netname, " ^7wins.\n");
1132 FOR_EACH_PLAYER(other)
1134 if(maxTotalFrags < other.totalfrags)
1135 maxTotalFrags = other.totalfrags;
1136 if(minTotalFrags > other.totalfrags)
1137 minTotalFrags = other.totalfrags;
1142 FOR_EACH_PLAYER(other)
1144 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1145 f = bound(0, other.play_time / max(time, 1), 1);
1146 // store some statistics?
1150 if(cvar("g_campaign"))
1151 CampaignPreIntermission();
1153 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1160 Exit deathmatch games upon conditions
1164 void CheckRules_Player()
1166 if (gameover) // someone else quit the game already
1169 if(self.deadflag == DEAD_NO)
1170 self.play_time += frametime;
1174 if(time > self.fogtime)
1176 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1177 self.fogtime = time + sv_foginterval;
1180 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1181 // (div0: and that in CheckRules_World please)
1184 float checkrules_oneminutewarning;
1186 float checkrules_equality;
1187 float checkrules_overtimewarning;
1188 float checkrules_overtimeend;
1190 void InitiateOvertime()
1192 if(!checkrules_overtimeend)
1193 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1196 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1197 float WINNING_YES = 1; // winner found
1198 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1199 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1201 float GetWinningCode(float fraglimitreached, float equality)
1204 if(fraglimitreached)
1205 return WINNING_STARTOVERTIME;
1207 return WINNING_NEVER;
1209 if(fraglimitreached)
1215 // set the .winning flag for exactly those players with a given field value
1216 void SetWinners(.float field, float value)
1219 FOR_EACH_PLAYER(head)
1220 head.winning = (head.field == value);
1223 // set the .winning flag for those players with a given field value
1224 void AddWinners(.float field, float value)
1227 FOR_EACH_PLAYER(head)
1228 if(head.field == value)
1232 // clear the .winning flags
1233 void ClearWinners(void)
1236 FOR_EACH_PLAYER(head)
1240 // Onslaught winning condition:
1241 // game terminates if only one team has a working generator (or none)
1242 float WinningCondition_Onslaught()
1245 local float t1, t2, t3, t4;
1246 // first check if the game has ended
1247 t1 = t2 = t3 = t4 = 0;
1248 head = find(world, classname, "onslaught_generator");
1251 if (head.health > 0)
1253 if (head.team == COLOR_TEAM1) t1 = 1;
1254 if (head.team == COLOR_TEAM2) t2 = 1;
1255 if (head.team == COLOR_TEAM3) t3 = 1;
1256 if (head.team == COLOR_TEAM4) t4 = 1;
1258 head = find(head, classname, "onslaught_generator");
1260 if (t1 + t2 + t3 + t4 < 2)
1262 // game over, only one team remains (or none)
1264 if (t1) SetWinners(team, COLOR_TEAM1);
1265 if (t2) SetWinners(team, COLOR_TEAM2);
1266 if (t3) SetWinners(team, COLOR_TEAM3);
1267 if (t4) SetWinners(team, COLOR_TEAM4);
1268 dprint("Have a winner, ending game.\n");
1272 // Two or more teams remain
1276 float LMS_NewPlayerLives()
1279 fl = cvar("fraglimit");
1283 // first player has left the game for dying too much? Nobody else can get in.
1284 if(lms_lowest_lives < 1)
1287 if(!cvar("g_lms_join_anytime"))
1288 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1291 return bound(1, lms_lowest_lives, fl);
1294 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1295 // they win. Otherwise the defending team wins once the timelimit passes.
1296 void assault_new_round();
1297 float WinningCondition_Assault()
1300 status = WINNING_NO;
1302 // as the timelimit has not yet passed just assume the defending team will win
1303 if(assault_attacker_team == COLOR_TEAM1)
1305 SetWinners(team, COLOR_TEAM2);
1309 SetWinners(team, COLOR_TEAM1);
1313 ent = find(world, classname, "target_assault_roundend");
1316 if(ent.winning) // round end has been triggered by attacking team
1318 SetWinners(team, assault_attacker_team);
1319 if(assault_attacker_team == COLOR_TEAM1)
1321 team1_score = team1_score + 50;
1325 team2_score = team2_score + 50;
1328 if(ent.cnt == 1) // this was the second round
1330 status = WINNING_YES;
1334 local entity oldself;
1337 cvar_set("timelimit", ftos((2*time)/60));
1338 assault_new_round();
1348 // LMS winning condition: game terminates if and only if there's at most one
1349 // one player who's living lives. Top two scores being equal cancels the time
1351 float WinningCondition_LMS()
1358 have_player = FALSE;
1359 have_players = FALSE;
1360 l = LMS_NewPlayerLives();
1362 head = find(world, classname, "player");
1365 head2 = find(head, classname, "player");
1367 have_players = TRUE;
1371 // we have at least one player
1374 // two or more active players - continue with the game
1378 // exactly one player?
1381 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1385 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1391 // and assign him his first place
1392 PlayerScore_Add(head, SP_LMS_RANK, 1);
1399 // nobody is playing at all...
1402 // wait for players...
1406 // SNAFU (maybe a draw game?)
1408 dprint("No players, ending game.\n");
1413 // When we get here, we have at least two players who are actually LIVING,
1414 // now check if the top two players have equal score.
1415 WinningConditionHelper();
1418 if(WinningConditionHelper_winner)
1419 WinningConditionHelper_winner.winning = TRUE;
1420 if(WinningConditionHelper_equality)
1421 return WINNING_NEVER;
1423 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1427 void print_to(entity e, string s)
1430 sprint(e, strcat(s, "\n"));
1432 ServerConsoleEcho(s, TRUE);
1435 void ShuffleMaplist()
1443 result = cvar_string("g_maplist");
1445 litems = tokenizebyseparator(result, " ");
1447 litems = tokenize(result);
1450 for(start = 0; start < litems - 1; ++start)
1454 // select a random item
1455 selected = ceil(random() * (litems - start) + start) - 1;
1457 // shift this item to the place start
1459 for(i = 0; i < start; ++i)
1460 result = strcat(result, " ", argv(i));
1461 result = strcat(result, " ", argv(selected));
1462 for(i = start; i < litems; ++i)
1464 result = strcat(result, " ", argv(i));
1465 result = substring(result, 1, strlen(result) - 1);
1467 litems = tokenizebyseparator(result, " ");
1469 for(i = 0; i < start; ++i)
1470 result = strcat(result, "'", argv(i), "'");
1471 result = strcat(result, "'", argv(selected), "'");
1472 for(i = start; i < litems; ++i)
1474 result = strcat(result, "'", argv(i), "'");
1476 litems = tokenize(result);
1479 //dprint(result, "\n");
1482 cvar_set("g_maplist", result);
1485 float WinningCondition_Scores(float limit)
1487 // TODO make everything use THIS winning condition (except LMS)
1488 WinningConditionHelper();
1492 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1493 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1494 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1495 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1499 if(WinningConditionHelper_winner)
1500 WinningConditionHelper_winner.winning = 1;
1501 if(WinningConditionHelper_winnerteam >= 0)
1502 SetWinners(team, WinningConditionHelper_winnerteam);
1504 if(WinningConditionHelper_topscore == 0)
1505 WinningConditionHelper_equality = 0;
1507 if(WinningConditionHelper_lowerisbetter)
1509 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1513 return GetWinningCode(limit && WinningConditionHelper_topscore && (WinningConditionHelper_topscore >= limit), WinningConditionHelper_equality);
1516 float WinningCondition_Race(float fraglimit)
1520 wc = WinningCondition_Scores(fraglimit);
1522 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1523 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1524 // do NOT support equality when the laps are all raced!
1527 if not(p.race_completed)
1528 return WINNING_STARTOVERTIME;
1534 void ReadyRestart();
1535 float WinningCondition_QualifyingThenRace(float limit)
1538 wc = WinningCondition_Scores(limit);
1540 // NEVER initiate overtime
1541 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1542 // do NOT support equality when the laps are all raced!
1545 float playerswithlaps;
1547 totalplayers = playerswithlaps = 0;
1548 FOR_EACH_PLAYER(head)
1551 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
1555 // at least 2/3 of the players have completed a lap: start the RACE
1556 // otherwise, the players should end the qualifying on their own
1557 if(totalplayers >= 3)
1558 if(playerswithlaps >= totalplayers * 2 / 3)
1560 checkrules_overtimeend = 0;
1562 return WINNING_NEVER;
1571 float WinningCondition_RanOutOfSpawns()
1575 if(!have_team_spawns)
1578 if(!some_spawn_has_been_used)
1581 team1_score = team2_score = team3_score = team4_score = 0;
1583 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1585 if(head.team == COLOR_TEAM1)
1587 else if(head.team == COLOR_TEAM2)
1589 else if(head.team == COLOR_TEAM3)
1591 else if(head.team == COLOR_TEAM4)
1595 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1597 if(head.team == COLOR_TEAM1)
1599 else if(head.team == COLOR_TEAM2)
1601 else if(head.team == COLOR_TEAM3)
1603 else if(head.team == COLOR_TEAM4)
1608 if(team1_score + team2_score + team3_score + team4_score == 0)
1610 checkrules_equality = TRUE;
1613 else if(team1_score + team2_score + team3_score + team4_score == 1)
1616 if(team1_score) t = COLOR_TEAM1;
1617 if(team2_score) t = COLOR_TEAM2;
1618 if(team3_score) t = COLOR_TEAM3;
1619 if(team4_score) t = COLOR_TEAM4;
1620 CheckAllowedTeams(world);
1621 for(i = 0; i < MAX_TEAMSCORE; ++i)
1623 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
1624 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
1625 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
1626 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
1629 AddWinners(team, t);
1640 Exit deathmatch games upon conditions
1643 void CheckRules_World()
1646 local float timelimit;
1647 local float fraglimit;
1655 MapVote_Think should now do that part
1656 if (intermission_running)
1657 if (time >= intermission_exittime + 60)
1659 if(!DoNextMapOverride())
1665 if (gameover) // someone else quit the game already
1667 if(player_count == 0) // Nobody there? Then let's go to the next map
1669 // this will actually check the player count in the next frame
1670 // again, but this shouldn't hurt
1674 timelimit = cvar("timelimit") * 60;
1675 fraglimit = cvar("fraglimit");
1677 if(checkrules_overtimeend)
1679 if(!checkrules_overtimewarning)
1681 checkrules_overtimewarning = TRUE;
1682 //announceall("announcer/robotic/1minuteremains.wav");
1683 if(!g_race_qualifying)
1684 bcenterprint("^3Everyone, finish your lap! The race is over!");
1686 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1691 if (timelimit && time >= timelimit)
1695 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1701 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1703 checkrules_oneminutewarning = TRUE;
1704 play2all("announcer/robotic/1minuteremains.wav");
1707 status = WinningCondition_RanOutOfSpawns();
1708 if(status == WINNING_YES)
1710 bprint("Hey! Someone ran out of spawns!\n");
1712 else if(g_race && !g_race_qualifying && timelimit >= 0)
1714 status = WinningCondition_Race(fraglimit);
1716 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
1718 status = WinningCondition_QualifyingThenRace(fraglimit);
1722 status = WinningCondition_Assault(); // TODO remove this?
1726 status = WinningCondition_LMS();
1728 else if (g_onslaught)
1730 status = WinningCondition_Onslaught(); // TODO remove this?
1734 status = WinningCondition_Scores(fraglimit);
1737 if(status == WINNING_STARTOVERTIME)
1739 status = WINNING_NEVER;
1743 if(status == WINNING_NEVER)
1744 // equality cases! Nobody wins if the overtime ends in a draw.
1747 if(checkrules_overtimeend)
1748 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1749 status = WINNING_YES;
1751 if(status == WINNING_YES)
1755 float mapvote_nextthink;
1756 float mapvote_initialized;
1757 float mapvote_keeptwotime;
1758 float mapvote_timeout;
1759 string mapvote_message;
1760 string mapvote_screenshot_dir;
1762 float mapvote_count;
1763 float mapvote_count_real;
1764 string mapvote_maps[MAPVOTE_COUNT];
1765 float mapvote_maps_suggested[MAPVOTE_COUNT];
1766 string mapvote_suggestions[MAPVOTE_COUNT];
1767 float mapvote_suggestion_ptr;
1768 float mapvote_maxlen;
1769 float mapvote_voters;
1770 float mapvote_votes[MAPVOTE_COUNT];
1772 float mapvote_detail;
1773 float mapvote_abstain;
1774 float mapvote_dirty;
1777 void MapVote_ClearAllVotes()
1779 FOR_EACH_CLIENT(other)
1783 string MapVote_Suggest(string m)
1787 return "That's not how to use this command.";
1788 if(!cvar("g_maplist_votable_suggestions"))
1789 return "Suggestions are not accepted on this server.";
1790 if(mapvote_initialized)
1791 return "Can't suggest - voting is already in progress!";
1793 m = MapInfo_FixName(m);
1795 return "The map you suggested is not available on this server.";
1797 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1798 if(!IsSameGametype(m))
1799 return "This server does not allow changing the game type by map suggestions.";
1801 if(!cvar("g_maplist_votable_override_mostrecent"))
1803 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1806 if(!MapInfo_CheckMap(m))
1807 return "The map you suggested does not support the current game mode.";
1809 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1810 return "The map you suggested is not available on this server.";
1812 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1813 if(mapvote_suggestions[i] == m)
1814 return "This map was already suggested.";
1815 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1817 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1821 i = mapvote_suggestion_ptr;
1822 mapvote_suggestion_ptr += 1;
1824 if(mapvote_suggestions[i] != "")
1825 strunzone(mapvote_suggestions[i]);
1826 mapvote_suggestions[i] = strzone(m);
1827 if(cvar("sv_eventlog"))
1828 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)), TRUE);
1829 return strcat("Suggestion of ", m, " accepted.");
1832 void MapVote_AddVotable(string nextMap, float isSuggestion)
1837 for(j = 0; j < mapvote_count; ++j)
1838 if(mapvote_maps[j] == nextMap)
1840 if(strlen(nextMap) > mapvote_maxlen)
1841 mapvote_maxlen = strlen(nextMap);
1842 mapvote_maps[mapvote_count] = strzone(nextMap);
1843 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1847 void MapVote_SendData(float target);
1853 MapVote_ClearAllVotes();
1856 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1857 mapvote_abstain = cvar("g_maplist_votable_abstain");
1860 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1862 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1863 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
1865 if(mapvote_suggestion_ptr)
1866 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1867 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1869 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1870 MapVote_AddVotable(GetNextMap(), FALSE);
1872 if(mapvote_count == 0)
1874 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1876 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1877 localcmd("\nmenu_cmd sync\n");
1879 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1881 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1882 MapVote_AddVotable(GetNextMap(), FALSE);
1885 mapvote_count_real = mapvote_count;
1887 MapVote_AddVotable("don't care", 0);
1889 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1891 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1892 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1893 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1894 mapvote_keeptwotime = 0;
1895 mapvote_message = "Choose a map and press its key!";
1897 mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
1898 if(mapvote_screenshot_dir == "")
1899 mapvote_screenshot_dir = "maps";
1900 mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
1902 if(!cvar("g_maplist_textonly"))
1903 MapVote_SendData(MSG_ALL);
1906 void MapVote_SendPicture(float id)
1909 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1910 WriteByte(MSG_ONE, TE_CSQC_MAPVOTE);
1911 WriteByte(MSG_ONE, MAPVOTE_NET_PIC);
1912 WriteByte(MSG_ONE, id);
1913 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 3072);
1916 float GameCommand_MapVote(string cmd)
1918 if(!intermission_running)
1920 if(!cvar("g_maplist_textonly"))
1922 if(cmd == "mv_getpic")
1924 MapVote_SendPicture(stof(argv(1)));
1932 float MapVote_GetMapMask()
1934 float mask, i, power;
1936 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
1937 if(mapvote_maps[i] != "")
1942 void MapVote_SendData(float targ)
1944 string mapfile, pakfile;
1946 WriteByte(targ, SVC_TEMPENTITY);
1947 WriteByte(targ, TE_CSQC_CONFIG);
1948 WriteString(targ, "mv_screenshot_dir");
1949 WriteString(targ, mapvote_screenshot_dir);
1951 WriteByte(targ, SVC_TEMPENTITY);
1952 WriteByte(targ, TE_CSQC_MAPVOTE);
1953 WriteByte(targ, MAPVOTE_NET_INIT);
1955 WriteByte(targ, mapvote_count);
1956 WriteByte(targ, mapvote_abstain);
1957 WriteByte(targ, mapvote_detail);
1958 WriteCoord(targ, mapvote_timeout);
1959 if(mapvote_count <= 8)
1960 WriteByte(targ, MapVote_GetMapMask());
1962 WriteShort(targ, MapVote_GetMapMask());
1963 for(i = 0; i < mapvote_count; ++i)
1964 if(mapvote_maps[i] != "")
1966 WriteString(targ, mapvote_maps[i]);
1967 mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
1968 pakfile = whichpack(strcat(mapfile, ".tga"));
1970 pakfile = whichpack(strcat(mapfile, ".jpg"));
1972 pakfile = whichpack(strcat(mapfile, ".png"));
1973 print("pakfile is ", pakfile, "\n");
1974 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
1975 pakfile = substring(pakfile, o, 999);
1976 WriteString(targ, pakfile);
1980 void MapVote_UpdateData(float targ)
1983 WriteByte(targ, SVC_TEMPENTITY);
1984 WriteByte(targ, TE_CSQC_MAPVOTE);
1985 WriteByte(targ, MAPVOTE_NET_UPDATE);
1986 if(mapvote_count <= 8)
1987 WriteByte(targ, MapVote_GetMapMask());
1989 WriteShort(targ, MapVote_GetMapMask());
1991 for(i = 0; i < mapvote_count; ++i)
1992 if(mapvote_maps[i] != "")
1993 WriteByte(targ, mapvote_votes[i]);
1996 void MapVote_TellVote(float targ, float vote)
1998 WriteByte(targ, SVC_TEMPENTITY);
1999 WriteByte(targ, TE_CSQC_MAPVOTE);
2000 WriteByte(targ, MAPVOTE_NET_OWNVOTE);
2001 WriteByte(targ, vote);
2004 float MapVote_Finished(float mappos)
2010 if(cvar("sv_eventlog"))
2012 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2013 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
2014 didntvote = mapvote_voters;
2015 for(i = 0; i < mapvote_count; ++i)
2016 if(mapvote_maps[i] != "")
2018 didntvote -= mapvote_votes[i];
2021 result = strcat(result, ":", mapvote_maps[i]);
2022 result = strcat(result, ":", ftos(mapvote_votes[i]));
2025 result = strcat(result, ":didn't vote:", ftos(didntvote));
2027 GameLogEcho(result, FALSE);
2028 if(mapvote_maps_suggested[mappos])
2029 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
2032 FOR_EACH_REALCLIENT(other)
2033 FixClientCvars(other);
2035 Map_Goto_SetStr(mapvote_maps[mappos]);
2037 alreadychangedlevel = TRUE;
2040 void MapVote_CheckRules_1()
2044 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2046 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2047 mapvote_votes[i] = 0;
2051 FOR_EACH_REALCLIENT(other)
2056 i = other.mapvote - 1;
2057 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2058 mapvote_votes[i] = mapvote_votes[i] + 1;
2063 float MapVote_CheckRules_2()
2066 float firstPlace, secondPlace;
2067 float firstPlaceVotes, secondPlaceVotes;
2068 float mapvote_voters_real;
2071 mapvote_voters_real = mapvote_voters;
2073 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2075 RandomSelection_Init();
2076 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2077 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2078 firstPlace = RandomSelection_chosen_float;
2079 firstPlaceVotes = RandomSelection_best_priority;
2080 //dprint("First place: ", ftos(firstPlace), "\n");
2081 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2083 RandomSelection_Init();
2084 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2086 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2087 secondPlace = RandomSelection_chosen_float;
2088 secondPlaceVotes = RandomSelection_best_priority;
2089 //dprint("Second place: ", ftos(secondPlace), "\n");
2090 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2092 if(firstPlace == -1)
2093 error("No first place in map vote... WTF?");
2095 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2096 return MapVote_Finished(firstPlace);
2098 if(mapvote_keeptwotime)
2099 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2102 mapvote_dirty = TRUE;
2103 mapvote_message = "Now decide between the TOP TWO!";
2104 mapvote_keeptwotime = 0;
2105 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2106 result = strcat(result, ":", ftos(firstPlaceVotes));
2107 result = strcat(result, ":", mapvote_maps[secondPlace]);
2108 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2109 didntvote = mapvote_voters;
2110 for(i = 0; i < mapvote_count; ++i)
2111 if(mapvote_maps[i] != "")
2113 didntvote -= mapvote_votes[i];
2115 if(i != secondPlace)
2117 result = strcat(result, ":", mapvote_maps[i]);
2118 result = strcat(result, ":", ftos(mapvote_votes[i]));
2119 if(i < mapvote_count_real)
2121 strunzone(mapvote_maps[i]);
2122 mapvote_maps[i] = "";
2126 result = strcat(result, ":didn't vote:", ftos(didntvote));
2127 if(cvar("sv_eventlog"))
2128 GameLogEcho(result, FALSE);
2141 keeptwo = mapvote_keeptwotime;
2142 MapVote_CheckRules_1(); // count
2143 if(MapVote_CheckRules_2()) // decide
2147 FOR_EACH_REALCLIENT(other)
2149 // hide scoreboard again
2150 if(other.health != 2342)
2152 other.health = 2342;
2154 if(clienttype(other) == CLIENTTYPE_REAL)
2156 if(cvar("g_maplist_textonly"))
2157 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");
2160 WriteByte(MSG_ONE, SVC_FINALE);
2161 WriteString(MSG_ONE, "");
2165 // notify about keep-two
2166 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2167 play2(other, "misc/invshot.wav");
2169 // clear possibly invalid votes
2170 if(mapvote_maps[other.mapvote - 1] == "")
2172 // use impulses as new vote
2173 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2174 if(mapvote_maps[other.impulse - 1] != "")
2176 other.mapvote = other.impulse;
2178 mapvote_dirty = TRUE;
2181 MapVote_TellVote(MSG_ONE, other.mapvote);
2189 MapVote_CheckRules_1(); // just count
2191 if(!cvar("g_maplist_textonly"))
2192 if(mapvote_dirty) // 1 if "keeptwo" or "impulse" happened before
2194 MapVote_UpdateData(MSG_BROADCAST);
2195 mapvote_dirty = FALSE;
2198 if(cvar("g_maplist_textonly"))
2200 FOR_EACH_REALCLIENT(other)
2202 // display voting screen
2203 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2204 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2206 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2207 msgstr = strcat(msgstr, mapvote_message);
2208 msgstr = strcat(msgstr, "\n\n");
2209 for(i = 0; i < mapvote_count; ++i)
2210 if(mapvote_maps[i] == "")
2211 msgstr = strcat(msgstr, "\n");
2214 tmp = mapvote_maps[i];
2215 tmp = strpad(mapvote_maxlen, tmp);
2216 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2219 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2220 if(mapvote_votes[i] != 1)
2221 tmp = strcat(tmp, "s");
2222 tmp = strcat(tmp, ")");
2223 tmp = strpad(mapvote_maxlen + 15, tmp);
2226 if(i == mapvote_count - 1)
2227 msgstr = strcat(msgstr, "\n");
2228 if(other.mapvote == i + 1)
2229 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2231 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2234 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2236 msgstr = strcat(msgstr, "s");
2237 msgstr = strcat(msgstr, " cast");
2238 i = ceil(mapvote_timeout - time);
2239 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2241 msgstr = strcat(msgstr, "s");
2242 msgstr = strcat(msgstr, " left");
2244 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2248 void MapVote_Start()
2254 MapInfo_Enumerate();
2255 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2259 void MapVote_Think()
2264 if(alreadychangedlevel)
2267 if(time < mapvote_nextthink)
2271 mapvote_nextthink = time + 0.5;
2273 if(!mapvote_initialized)
2275 mapvote_initialized = TRUE;
2276 if(DoNextMapOverride())
2278 if(!cvar("g_maplist_votable") || player_count <= 0)
2289 string GotoMap(string m)
2292 if(!MapInfo_CheckMap(m))
2294 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2296 return "The map you chose is not available on this server.";
2297 cvar_set("nextmap", m);
2298 cvar_set("timelimit", "-1");
2299 if(mapvote_initialized || alreadychangedlevel)
2301 if(DoNextMapOverride())
2302 return "Map switch initiated.";
2304 return "Hm... no. For some reason I like THIS map more.";
2307 return "Map switch will happen after scoreboard.";
2313 FOR_EACH_REALCLIENT(self)
2315 if(self.classname == "spectator")
2317 if(self.enemy.hitsound)
2318 play2(self, "misc/hit.wav");
2323 play2(self, "misc/hit.wav");
2326 FOR_EACH_CLIENT(self)
2327 self.hitsound = FALSE;
2333 * returns TRUE if redirecting
2335 float redirection_timeout;
2336 float redirection_nextthink;
2337 float RedirectionThink()
2339 float clients_found;
2341 if(redirection_target == "")
2344 if(!redirection_timeout)
2346 cvar_set("sv_public", "-2");
2347 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2348 if(redirection_target == "self")
2349 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2351 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2354 if(time < redirection_nextthink)
2357 redirection_nextthink = time + 1;
2360 FOR_EACH_REALCLIENT(self)
2362 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2363 if(redirection_target == "self")
2364 stuffcmd(self, "\ndisconnect; reconnect\n");
2366 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2370 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2372 if(time > redirection_timeout || clients_found == 0)
2373 localcmd("\nwait; wait; wait; quit\n");
2380 // Loaded from a save game
2381 // some things then break, so let's work around them...
2383 // Progs DB (capture records)
2385 ServerProgsDB = db_create();
2387 ServerProgsDB = db_load("server.db");
2392 MapInfo_Enumerate();
2393 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
2399 if(world_initialized)
2401 world_initialized = 0;
2402 print("Saving persistent data...\n");
2405 db_save(ServerProgsDB, "server.db");
2406 db_close(ServerProgsDB);
2408 // tell the bot system the game is ending now
2415 print("NOTE: crashed before even initializing the world, not saving persistent data\n");