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;
179 head = nextent(world);
184 head = nextent(head);
191 MapInfo_LoadMapSettings(mapname);
192 clientstuff = strzone(MapInfo_Map_clientstuff);
193 MapInfo_ClearTemps();
197 ServerProgsDB = db_create();
199 ServerProgsDB = db_load("server.db");
202 TODO sound pack system
203 // initialize sound pack system
204 soundpack = cvar_string("g_soundpack");
206 soundpack = strcat(soundpack, "/");
207 soundpack = strzone(soundpack);
213 // 1 FLICKER (first variety)
214 lightstyle(1, "mmnmmommommnonmmonqnmmo");
216 // 2 SLOW STRONG PULSE
217 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
219 // 3 CANDLE (first variety)
220 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
223 lightstyle(4, "mamamamamama");
226 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
228 // 6 FLICKER (second variety)
229 lightstyle(6, "nmonqnmomnmomomno");
231 // 7 CANDLE (second variety)
232 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
234 // 8 CANDLE (third variety)
235 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
237 // 9 SLOW STROBE (fourth variety)
238 lightstyle(9, "aaaaaaaazzzzzzzz");
240 // 10 FLUORESCENT FLICKER
241 lightstyle(10, "mmamammmmammamamaaamammma");
243 // 11 SLOW PULSE NOT FADE TO BLACK
244 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
246 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
251 // for setting by mapinfo
252 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
253 cvar_set("sv_q3acompat_machineshotgunswap", "0");
256 lms_lowest_lives = 0;
259 bot_waypoints_for_items = cvar("g_waypoints_for_items");
260 if(bot_waypoints_for_items == 1)
261 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
262 bot_waypoints_for_items = 0;
264 if(cvar("g_campaign"))
271 WaypointSprite_Init();
276 GameLogInit(); // prepare everything
277 if(cvar("sv_eventlog"))
279 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
280 s = strcat(s, ftos(random()));
282 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s), FALSE);
284 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
286 s = ":gameinfo:mutators:LIST";
287 if(cvar("g_grappling_hook"))
288 s = strcat(s, ":grappling_hook");
289 if(!cvar("g_use_ammunition"))
290 s = strcat(s, ":no_use_ammunition");
291 if(!cvar("g_pickup_items"))
292 s = strcat(s, ":no_pickup_items");
293 if(cvar("g_instagib"))
294 s = strcat(s, ":instagib");
295 if(cvar("g_rocketarena"))
296 s = strcat(s, ":rockerarena");
298 s = strcat(s, ":nixnex");
299 if(cvar("g_vampire"))
300 s = strcat(s, ":vampire");
301 if(cvar("g_laserguided_missile"))
302 s = strcat(s, ":laserguided_missile");
303 if(cvar("g_norecoil"))
304 s = strcat(s, ":norecoil");
306 s = strcat(s, ":midair");
307 if(cvar("g_minstagib"))
308 s = strcat(s, ":minstagib");
309 GameLogEcho(s, FALSE);
310 GameLogEcho(":gameinfo:end", FALSE);
313 cvar_set("nextmap", "");
317 if(cvar("g_campaign"))
324 //initialise globals related to sv_timeout
325 sys_ticrate = cvar("sys_ticrate");
326 orig_slowmo = cvar("slowmo");
330 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
333 //if tourney is used map starts in warmup mode. if this mode shall stay unlimited, reset timelimit, but save the original one
334 if(g_tourney && cvar("g_tourney_warmup_unlimited_time")) {
335 timelimit_orig = cvar("timelimit");
336 cvar_set("timelimit", "0");
339 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
341 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
344 while((s = fgets(fd)))
351 print("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
352 print(" cdtrack ", argv(2), "\n");
354 else if(argv(0) == "fog")
356 print("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
357 print(" \"fog\" \"", s, "\"\n");
359 else if(argv(0) == "set")
361 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
362 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
364 else if(argv(0) != "//")
366 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
367 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
374 next_pingtime = time + 5;
375 world_initialized = 1;
378 void spawnfunc_light (void)
380 //makestatic (self); // Who the f___ did that?
384 float TryFile( string pFilename )
387 dprint("TryFile(\"", pFilename, "\")\n");
388 lHandle = fopen( pFilename, FILE_READ );
389 if( lHandle != -1 ) {
399 return GametypeNameFromType(game);
402 float IsSameGametype(string mapcfgname)
405 return TRUE; // can't change game type by map name here
409 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
415 string getmapname_stored;
421 if(getmapname_stored == "")
422 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
423 return getmapname_stored;
427 float Map_Count, Map_Current;
428 string Map_Current_Name;
430 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
431 float GetMaplistPosition()
437 idx = cvar("g_maplist_index");
444 for(pos = 0; pos < Map_Count; ++pos)
448 // resume normal maplist rotation if current map is not in g_maplist
452 float MapHasRightSize(string map)
455 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
456 if(cvar("g_maplist_check_waypoints"))
458 dprint("checkwp "); dprint(map);
459 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
462 dprint(": no waypoints\n");
465 dprint(": has waypoints\n");
469 // open map size restriction file
470 dprint("opensize "); dprint(map);
471 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
474 float mapmin, mapmax;
476 mapmin = stof(fgets(fh));
477 mapmax = stof(fgets(fh));
479 if(player_count < mapmin)
481 dprint("not enough\n");
484 if(player_count > mapmax)
486 dprint("too many\n");
489 dprint("right size\n");
492 dprint(": not found\n");
496 string Map_Filename(float position)
499 return strcat("maps/", argv(position), ".bsp");
501 return strcat("maps/", argv(position), ".mapcfg");
505 string strwords(string s, float w)
508 for(endpos = 0; w && endpos >= 0; --w)
509 endpos = strstrofs(s, " ", endpos + 1);
513 return substring(s, 0, endpos);
516 float strhasword(string s, string w)
518 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
521 void Map_MarkAsRecent(string m)
523 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
526 float Map_IsRecent(string m)
528 return strhasword(cvar_string("g_maplist_mostrecent"), m);
531 float Map_Check(float position, float pass)
535 map_next = argv(position);
538 if(map_next == Map_Current_Name) // same map again in first pass?
540 if(Map_IsRecent(map_next))
543 filename = Map_Filename(position);
545 if(MapInfo_CheckMap(map_next))
547 if(TryFile(filename))
552 if(MapHasRightSize(map_next))
557 dprint( "Couldn't select '", filename, "'..\n" );
562 void Map_Goto_SetStr(string nextmapname)
564 if(getmapname_stored != "")
565 strunzone(getmapname_stored);
566 if(nextmapname == "")
567 getmapname_stored = "";
569 getmapname_stored = strzone(nextmapname);
572 void Map_Goto_SetFloat(float position)
574 cvar_set("g_maplist_index", ftos(position));
575 Map_Goto_SetStr(argv(position));
581 // settings persist, except...
582 if(cvar("g_campaign"))
583 localcmd("\nexec mutator_reset.cfg\n");
584 localcmd("\nsettemp_restore\n");
586 // if an exit cfg is defined by exiting map, exec it.
588 exit_cfg = cvar_string("exit_cfg");
590 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
592 localcmd("exec game_reset.cfg\n");
598 Map_MarkAsRecent(getmapname_stored);
601 MapInfo_LoadMap(getmapname_stored);
603 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
607 // return codes of map selectors:
608 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
609 // -2 = permanent failure
610 float() MaplistMethod_Iterate = // usual method
614 for(pass = 1; pass <= 2; ++pass)
616 for(i = 1; i < Map_Count; ++i)
619 mapindex = mod(i + Map_Current, Map_Count);
620 if(Map_Check(mapindex, pass))
627 float() MaplistMethod_Repeat = // fallback method
629 if(Map_Check(Map_Current, 2))
634 float() MaplistMethod_Random = // random map selection
640 for(i = 0; i <= imax; ++i)
643 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
644 if(Map_Check(mapindex, 1))
650 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
651 // the exponent sets a bias on the map selection:
652 // the higher the exponent, the less likely "shortly repeated" same maps are
654 float i, j, imax, insertpos;
658 for(i = 0; i <= imax; ++i)
662 // now reinsert this at another position
663 insertpos = pow(random(), 1 / exponent); // ]0, 1]
664 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
665 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
666 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
668 // insert the current map there
671 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
672 newlist = strcat(newlist, " ", argv(j));
673 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
674 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
675 newlist = strcat(newlist, " ", argv(j));
676 newlist = substring(newlist, 1, strlen(newlist) - 1);
678 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
679 newlist = strcat(newlist, "'", argv(j), "'");
680 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
681 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
682 newlist = strcat(newlist, "'", argv(j), "'");
684 cvar_set("g_maplist", newlist);
686 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
688 Map_Count = tokenize(newlist);
691 // NOTE: the selected map has just been inserted at (insertpos-1)th position
692 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
693 if(Map_Check(Map_Current, 1))
702 temp = cvar_string("g_maplist");
704 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
706 Map_Count = tokenize(temp);
710 bprint( "Maplist is empty! Resetting it to default map list.\n" );
712 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
713 localcmd("\nmenu_cmd sync\n");
714 Map_Count = tokenizebyseparator(temp, " ");
716 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
717 Map_Count = tokenize(temp);
721 error("empty maplist, cannot select a new map");
722 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
725 strunzone(Map_Current_Name);
726 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
727 // this may or may not be correct, but who cares, in the worst case a map
728 // isn't chosen in the first pass that should have been
739 if(cvar("g_maplist_shuffle") > 0)
740 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
743 if(cvar("g_maplist_selectrandom"))
744 nextMap = MaplistMethod_Random();
747 nextMap = MaplistMethod_Iterate();
750 nextMap = MaplistMethod_Repeat();
754 Map_Goto_SetFloat(nextMap);
755 return getmapname_stored;
761 float DoNextMapOverride()
763 if(cvar("g_campaign"))
765 CampaignPostIntermission();
766 alreadychangedlevel = TRUE;
769 if(cvar("quit_when_empty"))
771 if(player_count <= currentbots)
774 alreadychangedlevel = TRUE;
778 if(cvar_string("quit_and_redirect") != "")
780 redirection_target = strzone(cvar_string("quit_and_redirect"));
781 alreadychangedlevel = TRUE;
784 if (cvar("samelevel")) // if samelevel is set, stay on same level
786 // 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)
787 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
788 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
789 localcmd("restart\n");
790 //changelevel (mapname);
791 alreadychangedlevel = TRUE;
794 if(cvar_string("nextmap") != "")
796 if(MapInfo_CheckMap(cvar_string("nextmap")))
798 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
801 Map_Goto_SetStr(cvar_string("nextmap"));
803 alreadychangedlevel = TRUE;
806 if(cvar("lastlevel"))
809 localcmd("set lastlevel 0\ntogglemenu\n");
810 alreadychangedlevel = TRUE;
818 //local string nextmap;
819 //local float n, nummaps;
821 if (alreadychangedlevel)
823 alreadychangedlevel = TRUE;
829 for(allowReset = 1; allowReset >= 0; --allowReset)
831 nextMap = GetNextMap();
837 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
839 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
840 localcmd("\nmenu_cmd sync\n");
842 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
847 error("Everything is broken - not even the default map list works. Please report this to the developers.");
859 When the player presses attack or jump, change to the next level
862 .float autoscreenshot;
863 void() MapVote_Start;
864 void() MapVote_Think;
865 float mapvote_initialized;
866 void IntermissionThink()
868 FixIntermissionClient(self);
870 if(cvar("sv_autoscreenshot"))
871 if(self.autoscreenshot > 0)
872 if(time > self.autoscreenshot)
874 self.autoscreenshot = -1;
875 if(clienttype(self) == CLIENTTYPE_REAL)
876 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
880 if (time < intermission_exittime)
883 if(!mapvote_initialized)
884 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
894 Returns the entity to view from
898 entity FindIntermission()
903 // look for info_intermission first
904 spot = find (world, classname, "info_intermission");
906 { // pick a random one
910 spot = find (spot, classname, "info_intermission");
912 spot = find (spot, classname, "info_intermission");
918 // then look for the start position
919 spot = find (world, classname, "info_player_start");
923 // testinfo_player_start is only found in regioned levels
924 spot = find (world, classname, "testplayerstart");
928 // then look for the start position
929 spot = find (world, classname, "info_player_deathmatch");
933 //objerror ("FindIntermission: no spot");
939 ===============================================================================
943 ===============================================================================
946 void DumpStats(float final)
950 local float to_console;
951 local float to_eventlog;
955 to_console = cvar("sv_logscores_console");
956 to_eventlog = cvar("sv_eventlog");
957 to_file = cvar("sv_logscores_file");
961 to_console = TRUE; // always print printstats replies
962 to_eventlog = FALSE; // but never print them to the event log
966 if(cvar("sv_eventlog_console"))
967 to_console = FALSE; // otherwise we get the output twice
974 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
976 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
980 ServerConsoleEcho(s, FALSE);
982 GameLogEcho(s, FALSE);
985 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
989 fputs(file, strcat(s, "\n"));
992 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
994 ServerConsoleEcho(s, TRUE);
996 GameLogEcho(s, TRUE);
998 fputs(file, strcat(s, "\n"));
1000 FOR_EACH_CLIENT(other)
1002 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
1004 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
1005 s = strcat(s, ftos(rint(time - other.jointime)), ":");
1006 if(other.classname == "player" || g_arena || g_lms)
1007 s = strcat(s, ftos(other.team), ":");
1009 s = strcat(s, "spectator:");
1012 ServerConsoleEcho(strcat(s, other.netname), TRUE);
1014 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
1016 fputs(file, strcat(s, other.netname, "\n"));
1022 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
1024 ServerConsoleEcho(s, TRUE);
1026 GameLogEcho(s, TRUE);
1028 fputs(file, strcat(s, "\n"));
1030 for(i = 1; i < 16; ++i)
1032 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
1033 s = strcat(s, ":", ftos(i));
1035 ServerConsoleEcho(s, TRUE);
1037 GameLogEcho(s, TRUE);
1039 fputs(file, strcat(s, "\n"));
1044 ServerConsoleEcho(":end", FALSE);
1046 GameLogEcho(":end", FALSE);
1049 fputs(file, ":end\n");
1054 void FixIntermissionClient(entity e)
1057 if(!e.autoscreenshot) // initial call
1059 e.angles = e.v_angle;
1060 e.angles_x = -e.angles_x;
1061 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1063 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1064 e.solid = SOLID_NOT;
1065 e.movetype = MOVETYPE_NONE;
1066 e.takedamage = DAMAGE_NO;
1068 e.weaponentity.effects = EF_NODRAW;
1069 if(clienttype(e) == CLIENTTYPE_REAL)
1071 stuffcmd(e, "\nscr_printspeed 1000000\n");
1072 s = cvar_string("sv_intermission_cdtrack");
1074 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1076 WriteByte(MSG_ONE, SVC_INTERMISSION);
1080 //e.velocity = '0 0 0';
1081 //e.fixangle = TRUE;
1083 // TODO halt weapon animation
1088 go to the next level for deathmatch
1089 only called if a time or frag limit has expired
1093 float minTotalFrags;
1094 float maxTotalFrags;
1100 intermission_running = 1;
1102 // enforce a wait time before allowing changelevel
1103 if(player_count > 0)
1104 intermission_exittime = time + cvar("sv_mapchange_delay");
1106 intermission_exittime = -1;
1109 WriteByte (MSG_ALL, SVC_CDTRACK);
1110 WriteByte (MSG_ALL, 3);
1111 WriteByte (MSG_ALL, 3);
1112 // done in FixIntermission
1115 //pos = FindIntermission ();
1121 if(cvar("sv_eventlog"))
1122 GameLogEcho(":gameover", FALSE);
1126 FOR_EACH_CLIENT(other)
1128 FixIntermissionClient(other);
1131 bprint(other.netname, " ^7wins.\n");
1136 FOR_EACH_PLAYER(other)
1138 if(maxTotalFrags < other.totalfrags)
1139 maxTotalFrags = other.totalfrags;
1140 if(minTotalFrags > other.totalfrags)
1141 minTotalFrags = other.totalfrags;
1146 FOR_EACH_PLAYER(other)
1148 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1149 f = bound(0, other.play_time / max(time, 1), 1);
1150 // store some statistics?
1154 if(cvar("g_campaign"))
1155 CampaignPreIntermission();
1157 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1164 Exit deathmatch games upon conditions
1168 void CheckRules_Player()
1170 if (gameover) // someone else quit the game already
1173 if(self.deadflag == DEAD_NO)
1174 self.play_time += frametime;
1178 if(time > self.fogtime)
1180 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1181 self.fogtime = time + sv_foginterval;
1184 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1185 // (div0: and that in CheckRules_World please)
1188 float checkrules_oneminutewarning;
1190 float checkrules_equality;
1191 float checkrules_overtimewarning;
1192 float checkrules_overtimeend;
1194 void InitiateOvertime()
1196 if(!checkrules_overtimeend)
1197 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1200 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1201 float WINNING_YES = 1; // winner found
1202 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1203 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1205 float GetWinningCode(float fraglimitreached, float equality)
1208 if(fraglimitreached)
1209 return WINNING_STARTOVERTIME;
1211 return WINNING_NEVER;
1213 if(fraglimitreached)
1219 // set the .winning flag for exactly those players with a given field value
1220 void SetWinners(.float field, float value)
1223 FOR_EACH_PLAYER(head)
1224 head.winning = (head.field == value);
1227 // set the .winning flag for those players with a given field value
1228 void AddWinners(.float field, float value)
1231 FOR_EACH_PLAYER(head)
1232 if(head.field == value)
1236 // clear the .winning flags
1237 void ClearWinners(void)
1240 FOR_EACH_PLAYER(head)
1244 // Onslaught winning condition:
1245 // game terminates if only one team has a working generator (or none)
1246 float WinningCondition_Onslaught()
1249 local float t1, t2, t3, t4;
1250 // first check if the game has ended
1251 t1 = t2 = t3 = t4 = 0;
1252 head = find(world, classname, "onslaught_generator");
1255 if (head.health > 0)
1257 if (head.team == COLOR_TEAM1) t1 = 1;
1258 if (head.team == COLOR_TEAM2) t2 = 1;
1259 if (head.team == COLOR_TEAM3) t3 = 1;
1260 if (head.team == COLOR_TEAM4) t4 = 1;
1262 head = find(head, classname, "onslaught_generator");
1264 if (t1 + t2 + t3 + t4 < 2)
1266 // game over, only one team remains (or none)
1268 if (t1) SetWinners(team, COLOR_TEAM1);
1269 if (t2) SetWinners(team, COLOR_TEAM2);
1270 if (t3) SetWinners(team, COLOR_TEAM3);
1271 if (t4) SetWinners(team, COLOR_TEAM4);
1272 dprint("Have a winner, ending game.\n");
1276 // Two or more teams remain
1280 float LMS_NewPlayerLives()
1283 fl = cvar("fraglimit");
1287 // first player has left the game for dying too much? Nobody else can get in.
1288 if(lms_lowest_lives < 1)
1291 if(!cvar("g_lms_join_anytime"))
1292 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1295 return bound(1, lms_lowest_lives, fl);
1298 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1299 // they win. Otherwise the defending team wins once the timelimit passes.
1300 void assault_new_round();
1301 float WinningCondition_Assault()
1304 status = WINNING_NO;
1306 // as the timelimit has not yet passed just assume the defending team will win
1307 if(assault_attacker_team == COLOR_TEAM1)
1309 SetWinners(team, COLOR_TEAM2);
1313 SetWinners(team, COLOR_TEAM1);
1317 ent = find(world, classname, "target_assault_roundend");
1320 if(ent.winning) // round end has been triggered by attacking team
1322 SetWinners(team, assault_attacker_team);
1323 if(assault_attacker_team == COLOR_TEAM1)
1325 team1_score = team1_score + 50;
1329 team2_score = team2_score + 50;
1332 if(ent.cnt == 1) // this was the second round
1334 status = WINNING_YES;
1338 local entity oldself;
1341 cvar_set("timelimit", ftos((2*time)/60));
1342 assault_new_round();
1352 // LMS winning condition: game terminates if and only if there's at most one
1353 // one player who's living lives. Top two scores being equal cancels the time
1355 float WinningCondition_LMS()
1362 have_player = FALSE;
1363 have_players = FALSE;
1364 l = LMS_NewPlayerLives();
1366 head = find(world, classname, "player");
1369 head2 = find(head, classname, "player");
1371 have_players = TRUE;
1375 // we have at least one player
1378 // two or more active players - continue with the game
1382 // exactly one player?
1385 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1389 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1395 // and assign him his first place
1396 PlayerScore_Add(head, SP_LMS_RANK, 1);
1403 // nobody is playing at all...
1406 // wait for players...
1410 // SNAFU (maybe a draw game?)
1412 dprint("No players, ending game.\n");
1417 // When we get here, we have at least two players who are actually LIVING,
1418 // now check if the top two players have equal score.
1419 WinningConditionHelper();
1422 if(WinningConditionHelper_winner)
1423 WinningConditionHelper_winner.winning = TRUE;
1424 if(WinningConditionHelper_equality)
1425 return WINNING_NEVER;
1427 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1431 void print_to(entity e, string s)
1434 sprint(e, strcat(s, "\n"));
1436 ServerConsoleEcho(s, TRUE);
1439 void ShuffleMaplist()
1447 result = cvar_string("g_maplist");
1449 litems = tokenizebyseparator(result, " ");
1451 litems = tokenize(result);
1454 for(start = 0; start < litems - 1; ++start)
1458 // select a random item
1459 selected = ceil(random() * (litems - start) + start) - 1;
1461 // shift this item to the place start
1463 for(i = 0; i < start; ++i)
1464 result = strcat(result, " ", argv(i));
1465 result = strcat(result, " ", argv(selected));
1466 for(i = start; i < litems; ++i)
1468 result = strcat(result, " ", argv(i));
1469 result = substring(result, 1, strlen(result) - 1);
1471 litems = tokenizebyseparator(result, " ");
1473 for(i = 0; i < start; ++i)
1474 result = strcat(result, "'", argv(i), "'");
1475 result = strcat(result, "'", argv(selected), "'");
1476 for(i = start; i < litems; ++i)
1478 result = strcat(result, "'", argv(i), "'");
1480 litems = tokenize(result);
1483 //dprint(result, "\n");
1486 cvar_set("g_maplist", result);
1489 float WinningCondition_Scores(float limit)
1491 // TODO make everything use THIS winning condition (except LMS)
1492 WinningConditionHelper();
1496 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1497 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1498 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1499 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1503 if(WinningConditionHelper_winner)
1504 WinningConditionHelper_winner.winning = 1;
1505 if(WinningConditionHelper_winnerteam >= 0)
1506 SetWinners(team, WinningConditionHelper_winnerteam);
1508 if(WinningConditionHelper_topscore == 0)
1509 WinningConditionHelper_equality = 0;
1511 if(WinningConditionHelper_lowerisbetter)
1513 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1517 return GetWinningCode(limit && WinningConditionHelper_topscore && (WinningConditionHelper_topscore >= limit), WinningConditionHelper_equality);
1520 float WinningCondition_Race(float fraglimit)
1524 wc = WinningCondition_Scores(fraglimit);
1526 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1527 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1528 // do NOT support equality when the laps are all raced!
1531 if not(p.race_completed)
1532 return WINNING_STARTOVERTIME;
1538 void ReadyRestart();
1539 float WinningCondition_QualifyingThenRace()
1542 wc = WinningCondition_Scores(0);
1544 // NEVER initiate overtime
1545 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1546 // do NOT support equality when the laps are all raced!
1549 float playerswithlaps;
1551 totalplayers = playerswithlaps = 0;
1552 FOR_EACH_PLAYER(head)
1555 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
1559 // at least 2/3 of the players have completed a lap: start the RACE
1560 // otherwise, the players should end the qualifying on their own
1561 if(totalplayers >= 3)
1562 if(playerswithlaps >= totalplayers * 2 / 3)
1564 checkrules_overtimeend = 0;
1566 return WINNING_NEVER;
1575 float WinningCondition_RanOutOfSpawns()
1579 if(!have_team_spawns)
1582 if(!some_spawn_has_been_used)
1585 team1_score = team2_score = team3_score = team4_score = 0;
1587 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1589 if(head.team == COLOR_TEAM1)
1591 else if(head.team == COLOR_TEAM2)
1593 else if(head.team == COLOR_TEAM3)
1595 else if(head.team == COLOR_TEAM4)
1599 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1601 if(head.team == COLOR_TEAM1)
1603 else if(head.team == COLOR_TEAM2)
1605 else if(head.team == COLOR_TEAM3)
1607 else if(head.team == COLOR_TEAM4)
1612 if(team1_score + team2_score + team3_score + team4_score == 0)
1614 checkrules_equality = TRUE;
1617 else if(team1_score + team2_score + team3_score + team4_score == 1)
1620 if(team1_score) t = COLOR_TEAM1;
1621 if(team2_score) t = COLOR_TEAM2;
1622 if(team3_score) t = COLOR_TEAM3;
1623 if(team4_score) t = COLOR_TEAM4;
1624 CheckAllowedTeams(world);
1625 for(i = 0; i < MAX_TEAMSCORE; ++i)
1627 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
1628 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
1629 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
1630 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
1633 AddWinners(team, t);
1644 Exit deathmatch games upon conditions
1647 void CheckRules_World()
1650 local float timelimit;
1651 local float fraglimit;
1659 MapVote_Think should now do that part
1660 if (intermission_running)
1661 if (time >= intermission_exittime + 60)
1663 if(!DoNextMapOverride())
1669 if (gameover) // someone else quit the game already
1671 if(player_count == 0) // Nobody there? Then let's go to the next map
1673 // this will actually check the player count in the next frame
1674 // again, but this shouldn't hurt
1678 timelimit = cvar("timelimit") * 60;
1679 fraglimit = cvar("fraglimit");
1681 if(checkrules_overtimeend)
1683 if(!checkrules_overtimewarning)
1685 checkrules_overtimewarning = TRUE;
1686 //announceall("announcer/robotic/1minuteremains.wav");
1687 if(!g_race_qualifying)
1688 bcenterprint("^3Everyone, finish your lap! The race is over!");
1690 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1695 if (timelimit && time >= timelimit)
1699 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1705 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1707 checkrules_oneminutewarning = TRUE;
1708 play2all("announcer/robotic/1minuteremains.wav");
1711 status = WinningCondition_RanOutOfSpawns();
1712 if(status == WINNING_YES)
1714 bprint("Hey! Someone ran out of spawns!\n");
1716 else if(g_race && !g_race_qualifying && timelimit >= 0)
1718 status = WinningCondition_Race(fraglimit);
1720 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
1722 status = WinningCondition_QualifyingThenRace();
1726 status = WinningCondition_Assault(); // TODO remove this?
1730 status = WinningCondition_LMS();
1732 else if (g_onslaught)
1734 status = WinningCondition_Onslaught(); // TODO remove this?
1738 status = WinningCondition_Scores(fraglimit);
1741 if(status == WINNING_STARTOVERTIME)
1743 status = WINNING_NEVER;
1747 if(status == WINNING_NEVER)
1748 // equality cases! Nobody wins if the overtime ends in a draw.
1751 if(checkrules_overtimeend)
1752 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1753 status = WINNING_YES;
1755 if(status == WINNING_YES)
1759 float mapvote_nextthink;
1760 float mapvote_initialized;
1761 float mapvote_keeptwotime;
1762 float mapvote_timeout;
1763 string mapvote_message;
1764 string mapvote_screenshot_dir;
1766 float mapvote_count;
1767 float mapvote_count_real;
1768 string mapvote_maps[MAPVOTE_COUNT];
1769 float mapvote_maps_suggested[MAPVOTE_COUNT];
1770 string mapvote_suggestions[MAPVOTE_COUNT];
1771 float mapvote_suggestion_ptr;
1772 float mapvote_maxlen;
1773 float mapvote_voters;
1774 float mapvote_votes[MAPVOTE_COUNT];
1776 float mapvote_detail;
1777 float mapvote_abstain;
1778 float mapvote_dirty;
1781 void MapVote_ClearAllVotes()
1783 FOR_EACH_CLIENT(other)
1787 string MapVote_Suggest(string m)
1791 return "That's not how to use this command.";
1792 if(!cvar("g_maplist_votable_suggestions"))
1793 return "Suggestions are not accepted on this server.";
1794 if(mapvote_initialized)
1795 return "Can't suggest - voting is already in progress!";
1797 m = MapInfo_FixName(m);
1799 return "The map you suggested is not available on this server.";
1801 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1802 if(!IsSameGametype(m))
1803 return "This server does not allow changing the game type by map suggestions.";
1805 if(!cvar("g_maplist_votable_override_mostrecent"))
1807 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1810 if(!MapInfo_CheckMap(m))
1811 return "The map you suggested does not support the current game mode.";
1813 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1814 return "The map you suggested is not available on this server.";
1816 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1817 if(mapvote_suggestions[i] == m)
1818 return "This map was already suggested.";
1819 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1821 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1825 i = mapvote_suggestion_ptr;
1826 mapvote_suggestion_ptr += 1;
1828 if(mapvote_suggestions[i] != "")
1829 strunzone(mapvote_suggestions[i]);
1830 mapvote_suggestions[i] = strzone(m);
1831 if(cvar("sv_eventlog"))
1832 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)), TRUE);
1833 return strcat("Suggestion of ", m, " accepted.");
1836 void MapVote_AddVotable(string nextMap, float isSuggestion)
1841 for(j = 0; j < mapvote_count; ++j)
1842 if(mapvote_maps[j] == nextMap)
1844 if(strlen(nextMap) > mapvote_maxlen)
1845 mapvote_maxlen = strlen(nextMap);
1846 mapvote_maps[mapvote_count] = strzone(nextMap);
1847 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1851 void MapVote_SendData(float target);
1857 MapVote_ClearAllVotes();
1860 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1861 mapvote_abstain = cvar("g_maplist_votable_abstain");
1864 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1866 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1867 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
1869 if(mapvote_suggestion_ptr)
1870 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1871 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1873 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1874 MapVote_AddVotable(GetNextMap(), FALSE);
1876 if(mapvote_count == 0)
1878 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1880 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1881 localcmd("\nmenu_cmd sync\n");
1883 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1885 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1886 MapVote_AddVotable(GetNextMap(), FALSE);
1889 mapvote_count_real = mapvote_count;
1891 MapVote_AddVotable("don't care", 0);
1893 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1895 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1896 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1897 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1898 mapvote_keeptwotime = 0;
1899 mapvote_message = "Choose a map and press its key!";
1901 mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
1902 if(mapvote_screenshot_dir == "")
1903 mapvote_screenshot_dir = "maps";
1904 mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
1906 if(!cvar("g_maplist_textonly"))
1907 MapVote_SendData(MSG_ALL);
1910 void MapVote_SendPicture(float id)
1913 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1914 WriteByte(MSG_ONE, TE_CSQC_MAPVOTE);
1915 WriteByte(MSG_ONE, MAPVOTE_NET_PIC);
1916 WriteByte(MSG_ONE, id);
1917 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 3072);
1920 float GameCommand_MapVote(string cmd)
1922 if(!intermission_running)
1924 if(!cvar("g_maplist_textonly"))
1926 if(cmd == "mv_getpic")
1928 MapVote_SendPicture(stof(argv(1)));
1936 float MapVote_GetMapMask()
1938 float mask, i, power;
1940 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
1941 if(mapvote_maps[i] != "")
1946 void MapVote_SendData(float targ)
1948 string mapfile, pakfile;
1950 WriteByte(targ, SVC_TEMPENTITY);
1951 WriteByte(targ, TE_CSQC_CONFIG);
1952 WriteString(targ, "mv_screenshot_dir");
1953 WriteString(targ, mapvote_screenshot_dir);
1955 WriteByte(targ, SVC_TEMPENTITY);
1956 WriteByte(targ, TE_CSQC_MAPVOTE);
1957 WriteByte(targ, MAPVOTE_NET_INIT);
1959 WriteByte(targ, mapvote_count);
1960 WriteByte(targ, mapvote_abstain);
1961 WriteByte(targ, mapvote_detail);
1962 WriteCoord(targ, mapvote_timeout);
1963 if(mapvote_count <= 8)
1964 WriteByte(targ, MapVote_GetMapMask());
1966 WriteShort(targ, MapVote_GetMapMask());
1967 for(i = 0; i < mapvote_count; ++i)
1968 if(mapvote_maps[i] != "")
1970 WriteString(targ, mapvote_maps[i]);
1971 mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
1972 pakfile = whichpack(strcat(mapfile, ".tga"));
1974 pakfile = whichpack(strcat(mapfile, ".jpg"));
1976 pakfile = whichpack(strcat(mapfile, ".png"));
1977 print("pakfile is ", pakfile, "\n");
1978 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
1979 pakfile = substring(pakfile, o, 999);
1980 WriteString(targ, pakfile);
1984 void MapVote_UpdateData(float targ)
1987 WriteByte(targ, SVC_TEMPENTITY);
1988 WriteByte(targ, TE_CSQC_MAPVOTE);
1989 WriteByte(targ, MAPVOTE_NET_UPDATE);
1990 if(mapvote_count <= 8)
1991 WriteByte(targ, MapVote_GetMapMask());
1993 WriteShort(targ, MapVote_GetMapMask());
1995 for(i = 0; i < mapvote_count; ++i)
1996 if(mapvote_maps[i] != "")
1997 WriteByte(targ, mapvote_votes[i]);
2000 void MapVote_TellVote(float targ, float vote)
2002 WriteByte(targ, SVC_TEMPENTITY);
2003 WriteByte(targ, TE_CSQC_MAPVOTE);
2004 WriteByte(targ, MAPVOTE_NET_OWNVOTE);
2005 WriteByte(targ, vote);
2008 float MapVote_Finished(float mappos)
2014 if(cvar("sv_eventlog"))
2016 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2017 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
2018 didntvote = mapvote_voters;
2019 for(i = 0; i < mapvote_count; ++i)
2020 if(mapvote_maps[i] != "")
2022 didntvote -= mapvote_votes[i];
2025 result = strcat(result, ":", mapvote_maps[i]);
2026 result = strcat(result, ":", ftos(mapvote_votes[i]));
2029 result = strcat(result, ":didn't vote:", ftos(didntvote));
2031 GameLogEcho(result, FALSE);
2032 if(mapvote_maps_suggested[mappos])
2033 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
2036 FOR_EACH_REALCLIENT(other)
2037 FixClientCvars(other);
2039 Map_Goto_SetStr(mapvote_maps[mappos]);
2041 alreadychangedlevel = TRUE;
2044 void MapVote_CheckRules_1()
2048 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2050 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2051 mapvote_votes[i] = 0;
2055 FOR_EACH_REALCLIENT(other)
2060 i = other.mapvote - 1;
2061 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2062 mapvote_votes[i] = mapvote_votes[i] + 1;
2067 float MapVote_CheckRules_2()
2070 float firstPlace, secondPlace;
2071 float firstPlaceVotes, secondPlaceVotes;
2072 float mapvote_voters_real;
2075 mapvote_voters_real = mapvote_voters;
2077 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2079 RandomSelection_Init();
2080 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2081 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2082 firstPlace = RandomSelection_chosen_float;
2083 firstPlaceVotes = RandomSelection_best_priority;
2084 //dprint("First place: ", ftos(firstPlace), "\n");
2085 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2087 RandomSelection_Init();
2088 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2090 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2091 secondPlace = RandomSelection_chosen_float;
2092 secondPlaceVotes = RandomSelection_best_priority;
2093 //dprint("Second place: ", ftos(secondPlace), "\n");
2094 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2096 if(firstPlace == -1)
2097 error("No first place in map vote... WTF?");
2099 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2100 return MapVote_Finished(firstPlace);
2102 if(mapvote_keeptwotime)
2103 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2106 mapvote_dirty = TRUE;
2107 mapvote_message = "Now decide between the TOP TWO!";
2108 mapvote_keeptwotime = 0;
2109 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2110 result = strcat(result, ":", ftos(firstPlaceVotes));
2111 result = strcat(result, ":", mapvote_maps[secondPlace]);
2112 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2113 didntvote = mapvote_voters;
2114 for(i = 0; i < mapvote_count; ++i)
2115 if(mapvote_maps[i] != "")
2117 didntvote -= mapvote_votes[i];
2119 if(i != secondPlace)
2121 result = strcat(result, ":", mapvote_maps[i]);
2122 result = strcat(result, ":", ftos(mapvote_votes[i]));
2123 if(i < mapvote_count_real)
2125 strunzone(mapvote_maps[i]);
2126 mapvote_maps[i] = "";
2130 result = strcat(result, ":didn't vote:", ftos(didntvote));
2131 if(cvar("sv_eventlog"))
2132 GameLogEcho(result, FALSE);
2145 keeptwo = mapvote_keeptwotime;
2146 MapVote_CheckRules_1(); // count
2147 if(MapVote_CheckRules_2()) // decide
2151 FOR_EACH_REALCLIENT(other)
2153 // hide scoreboard again
2154 if(other.health != 2342)
2156 other.health = 2342;
2158 if(clienttype(other) == CLIENTTYPE_REAL)
2160 if(cvar("g_maplist_textonly"))
2161 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");
2164 WriteByte(MSG_ONE, SVC_FINALE);
2165 WriteString(MSG_ONE, "");
2169 // notify about keep-two
2170 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2171 play2(other, "misc/invshot.wav");
2173 // clear possibly invalid votes
2174 if(mapvote_maps[other.mapvote - 1] == "")
2176 // use impulses as new vote
2177 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2178 if(mapvote_maps[other.impulse - 1] != "")
2180 other.mapvote = other.impulse;
2182 mapvote_dirty = TRUE;
2185 MapVote_TellVote(MSG_ONE, other.mapvote);
2193 MapVote_CheckRules_1(); // just count
2195 if(!cvar("g_maplist_textonly"))
2196 if(mapvote_dirty) // 1 if "keeptwo" or "impulse" happened before
2198 MapVote_UpdateData(MSG_BROADCAST);
2199 mapvote_dirty = FALSE;
2202 if(cvar("g_maplist_textonly"))
2204 FOR_EACH_REALCLIENT(other)
2206 // display voting screen
2207 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2208 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2210 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2211 msgstr = strcat(msgstr, mapvote_message);
2212 msgstr = strcat(msgstr, "\n\n");
2213 for(i = 0; i < mapvote_count; ++i)
2214 if(mapvote_maps[i] == "")
2215 msgstr = strcat(msgstr, "\n");
2218 tmp = mapvote_maps[i];
2219 tmp = strpad(mapvote_maxlen, tmp);
2220 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2223 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2224 if(mapvote_votes[i] != 1)
2225 tmp = strcat(tmp, "s");
2226 tmp = strcat(tmp, ")");
2227 tmp = strpad(mapvote_maxlen + 15, tmp);
2230 if(i == mapvote_count - 1)
2231 msgstr = strcat(msgstr, "\n");
2232 if(other.mapvote == i + 1)
2233 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2235 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2238 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2240 msgstr = strcat(msgstr, "s");
2241 msgstr = strcat(msgstr, " cast");
2242 i = ceil(mapvote_timeout - time);
2243 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2245 msgstr = strcat(msgstr, "s");
2246 msgstr = strcat(msgstr, " left");
2248 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2252 void MapVote_Start()
2258 MapInfo_Enumerate();
2259 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2263 void MapVote_Think()
2268 if(alreadychangedlevel)
2271 if(time < mapvote_nextthink)
2275 mapvote_nextthink = time + 0.5;
2277 if(!mapvote_initialized)
2279 mapvote_initialized = TRUE;
2280 if(DoNextMapOverride())
2282 if(!cvar("g_maplist_votable") || player_count <= 0)
2293 string GotoMap(string m)
2296 if(!MapInfo_CheckMap(m))
2298 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2300 return "The map you chose is not available on this server.";
2301 cvar_set("nextmap", m);
2302 cvar_set("timelimit", "-1");
2303 if(mapvote_initialized || alreadychangedlevel)
2305 if(DoNextMapOverride())
2306 return "Map switch initiated.";
2308 return "Hm... no. For some reason I like THIS map more.";
2311 return "Map switch will happen after scoreboard.";
2317 FOR_EACH_REALCLIENT(self)
2319 if(self.classname == "spectator")
2321 if(self.enemy.hitsound)
2322 play2(self, "misc/hit.wav");
2327 play2(self, "misc/hit.wav");
2330 FOR_EACH_CLIENT(self)
2331 self.hitsound = FALSE;
2337 * returns TRUE if redirecting
2339 float redirection_timeout;
2340 float redirection_nextthink;
2341 float RedirectionThink()
2343 float clients_found;
2345 if(redirection_target == "")
2348 if(!redirection_timeout)
2350 cvar_set("sv_public", "-2");
2351 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2352 if(redirection_target == "self")
2353 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2355 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2358 if(time < redirection_nextthink)
2361 redirection_nextthink = time + 1;
2364 FOR_EACH_REALCLIENT(self)
2366 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2367 if(redirection_target == "self")
2368 stuffcmd(self, "\ndisconnect; reconnect\n");
2370 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2374 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2376 if(time > redirection_timeout || clients_found == 0)
2377 localcmd("\nwait; wait; wait; quit\n");
2384 // Loaded from a save game
2385 // some things then break, so let's work around them...
2387 // Progs DB (capture records)
2389 ServerProgsDB = db_create();
2391 ServerProgsDB = db_load("server.db");
2396 MapInfo_Enumerate();
2397 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
2403 if(world_initialized)
2405 world_initialized = 0;
2406 print("Saving persistent data...\n");
2409 db_save(ServerProgsDB, "server.db");
2410 db_close(ServerProgsDB);
2412 // tell the bot system the game is ending now
2419 print("NOTE: crashed before even initializing the world, not saving persistent data\n");