1 float SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS = 1;
2 string redirection_target;
3 float world_initialized;
9 float() DoNextMapOverride;
11 void SetDefaultAlpha()
13 if(cvar("g_running_guns"))
15 default_player_alpha = -1;
16 default_weapon_alpha = +1;
20 default_player_alpha = cvar("g_balance_cloaked_alpha");
21 default_weapon_alpha = default_player_alpha;
25 default_player_alpha = cvar("g_player_alpha");
26 if(default_player_alpha <= 0)
27 default_player_alpha = 1;
28 default_weapon_alpha = default_player_alpha;
32 void fteqcc_testbugs()
36 if(!cvar("developer_fteqccbugs"))
39 dprint("*** fteqcc test: checking for bugs...\n");
43 if(sqrt(a) - sqrt(b - a) == 0)
44 dprint("*** fteqcc test: found same-function-twice bug\n");
46 dprint("*** fteqcc test: same-function-twice bug got FINALLY FIXED! HOORAY!\n");
50 world.enemy.frags += 10;
51 if(world.frags > 0.2 || world.frags < -0.2) // don't error out if it's just roundoff errors
52 dprint("*** fteqcc test: found += bug\n");
54 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
59 * Takes care of pausing and unpausing the game.
60 * Centerprints the information about an upcoming or active timeout to all active
61 * players. Also plays reminder sounds.
63 void timeoutHandler_Think() {
66 if (timeoutStatus == 1) {
67 if (remainingLeadTime > 0) {
68 //centerprint the information to every player
69 timeStr = getTimeoutText(0);
70 FOR_EACH_REALCLIENT(plr) {
71 if(plr.classname == "player") {
72 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
75 remainingLeadTime -= 1;
76 //think again in 1 second:
77 self.nextthink = time + 1;
82 cvar_set("slowmo", ftos(TIMEOUT_SLOWMO_VALUE));
83 //copy .v_angle to .lastV_angle for every player in order to fix their view during pause (see PlayerPreThink)
84 FOR_EACH_REALPLAYER(plr) {
85 plr.lastV_angle = plr.v_angle;
87 self.nextthink = time;
90 else if (timeoutStatus == 2) {
91 if (remainingTimeoutTime > 0) {
92 timeStr = getTimeoutText(0);
93 FOR_EACH_REALCLIENT(plr) {
94 if(plr.classname == "player") {
95 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
98 if(remainingTimeoutTime == cvar("sv_timeout_resumetime")) { //play a warning sound when only <sv_timeout_resumetime> seconds are left
99 sound(world, CHAN_AUTO, "announcer/robotic/prepareforbattle.wav", 1, ATTN_NONE);
101 remainingTimeoutTime -= 1;
102 self.nextthink = time + TIMEOUT_SLOWMO_VALUE;
105 //unpause the game again
106 remainingTimeoutTime = timeoutStatus = 0;
107 cvar_set("slowmo", ftos(orig_slowmo));
108 //and unlock the fixed view again once there is no timeout active anymore
109 FOR_EACH_REALPLAYER(plr) {
110 plr.fixangle = FALSE;
112 //get rid of the countdown message
113 FOR_EACH_REALCLIENT(plr) {
114 if(plr.classname == "player") {
115 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
123 else if (timeoutStatus == 0) { //if a player called the resumegame command (which set timeoutStatus to 0 already)
124 FOR_EACH_REALCLIENT(plr) {
125 if(plr.classname == "player") {
126 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
138 cvar_set("_sv_init", "0");
139 if(cvar("g_maplist_shuffle"))
142 tokenizebyseparator(cvar_string("g_maplist"), " ");
144 tokenize(cvar_string("g_maplist"));
145 if(argv(0) != GetMapname())
148 cvar_set("nextmap", argv(0));
152 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
155 if(!DoNextMapOverride())
164 float world_already_spawned;
165 void spawnfunc_worldspawn (void)
167 dprint_load(); // load dprint status from cvar
169 if(world_already_spawned)
170 error("world already spawned - you may have EXACTLY ONE spawnfunc_worldspawn!");
171 world_already_spawned = TRUE;
177 MapInfo_LoadMapSettings(mapname);
181 ServerProgsDB = db_create();
183 ServerProgsDB = db_load("server.db");
186 TODO sound pack system
187 // initialize sound pack system
188 soundpack = cvar_string("g_soundpack");
190 soundpack = strcat(soundpack, "/");
191 soundpack = strzone(soundpack);
197 // 1 FLICKER (first variety)
198 lightstyle(1, "mmnmmommommnonmmonqnmmo");
200 // 2 SLOW STRONG PULSE
201 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
203 // 3 CANDLE (first variety)
204 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
207 lightstyle(4, "mamamamamama");
210 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
212 // 6 FLICKER (second variety)
213 lightstyle(6, "nmonqnmomnmomomno");
215 // 7 CANDLE (second variety)
216 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
218 // 8 CANDLE (third variety)
219 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
221 // 9 SLOW STROBE (fourth variety)
222 lightstyle(9, "aaaaaaaazzzzzzzz");
224 // 10 FLUORESCENT FLICKER
225 lightstyle(10, "mmamammmmammamamaaamammma");
227 // 11 SLOW PULSE NOT FADE TO BLACK
228 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
230 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
235 // for setting by mapinfo
236 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
237 cvar_set("sv_q3acompat_machineshotgunswap", "0");
240 lms_lowest_lives = 0;
243 bot_waypoints_for_items = cvar("g_waypoints_for_items");
244 if(bot_waypoints_for_items == 1)
245 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
246 bot_waypoints_for_items = 0;
248 if(cvar("g_campaign"))
255 WaypointSprite_Init();
261 head = nextent(world);
266 head = nextent(head);
269 GameLogInit(); // prepare everything
270 if(cvar("sv_eventlog"))
273 GameLogEcho(":logversion:2", FALSE);
274 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
275 s = strcat(s, ftos(random()));
277 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s), FALSE);
279 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
281 s = ":gameinfo:mutators:LIST";
282 if(cvar("g_grappling_hook"))
283 s = strcat(s, ":grappling_hook");
284 if(!cvar("g_use_ammunition"))
285 s = strcat(s, ":no_use_ammunition");
286 if(!cvar("g_pickup_items"))
287 s = strcat(s, ":no_pickup_items");
288 if(cvar("g_instagib"))
289 s = strcat(s, ":instagib");
290 if(cvar("g_rocketarena"))
291 s = strcat(s, ":rockerarena");
293 s = strcat(s, ":nixnex");
294 if(cvar("g_vampire"))
295 s = strcat(s, ":vampire");
296 if(cvar("g_laserguided_missile"))
297 s = strcat(s, ":laserguided_missile");
298 if(cvar("g_norecoil"))
299 s = strcat(s, ":norecoil");
301 s = strcat(s, ":midair");
302 if(cvar("g_minstagib"))
303 s = strcat(s, ":minstagib");
304 GameLogEcho(s, FALSE);
305 GameLogEcho(":gameinfo:end", FALSE);
308 cvar_set("nextmap", "");
312 if(cvar("g_campaign"))
319 //initialise globals related to sv_timeout
320 sys_ticrate = cvar("sys_ticrate");
321 orig_slowmo = cvar("slowmo");
325 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
328 //if tourney is used map starts in warmup mode. if this mode shall stay unlimited, reset timelimit, but save the original one
329 if(g_tourney && cvar("g_tourney_warmup_unlimited_time")) {
330 timelimit_orig = cvar("timelimit");
331 cvar_set("timelimit", "0");
334 world_initialized = 1;
337 void spawnfunc_light (void)
339 //makestatic (self); // Who the f___ did that?
343 float( string pFilename ) TryFile =
346 dprint("TryFile(\"", pFilename, "\")\n");
347 lHandle = fopen( pFilename, FILE_READ );
348 if( lHandle != -1 ) {
358 if (game == GAME_DEATHMATCH)
360 else if (game == GAME_TEAM_DEATHMATCH)
362 else if (game == GAME_DOMINATION)
364 else if (game == GAME_CTF)
366 else if (game == GAME_RUNEMATCH)
368 else if (game == GAME_LMS)
370 else if (game == GAME_KEYHUNT)
372 else if (game == GAME_ONSLAUGHT)
374 else if (game == GAME_ASSAULT)
379 float IsSameGametype(string mapcfgname)
382 return TRUE; // can't change game type by map name here
386 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
392 string getmapname_stored;
398 if(getmapname_stored == "")
399 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
400 return getmapname_stored;
404 float Map_Count, Map_Current;
405 string Map_Current_Name;
407 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
408 float GetMaplistPosition()
414 idx = cvar("g_maplist_index");
421 for(pos = 0; pos < Map_Count; ++pos)
425 // resume normal maplist rotation if current map is not in g_maplist
429 float MapHasRightSize(string map)
432 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
433 if(cvar("g_maplist_check_waypoints"))
435 dprint("checkwp "); dprint(map);
436 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
439 dprint(": no waypoints\n");
442 dprint(": has waypoints\n");
446 // open map size restriction file
447 dprint("opensize "); dprint(map);
448 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
451 float mapmin, mapmax;
453 mapmin = stof(fgets(fh));
454 mapmax = stof(fgets(fh));
456 if(player_count < mapmin)
458 dprint("not enough\n");
461 if(player_count > mapmax)
463 dprint("too many\n");
466 dprint("right size\n");
469 dprint(": not found\n");
473 string Map_Filename(float position)
476 return strcat("maps/", argv(position), ".bsp");
478 return strcat("maps/", argv(position), ".mapcfg");
482 string strwords(string s, float w)
485 for(endpos = 0; w && endpos >= 0; --w)
486 endpos = strstrofs(s, " ", endpos + 1);
490 return substring(s, 0, endpos);
493 float strhasword(string s, string w)
495 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
498 void Map_MarkAsRecent(string m)
500 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
503 float Map_IsRecent(string m)
505 return strhasword(cvar_string("g_maplist_mostrecent"), m);
508 float(float position, float pass) Map_Check =
512 map_next = argv(position);
515 if(map_next == Map_Current_Name) // same map again in first pass?
517 if(Map_IsRecent(map_next))
520 filename = Map_Filename(position);
522 if(MapInfo_CheckMap(map_next))
524 if(TryFile(filename))
529 if(MapHasRightSize(map_next))
534 dprint( "Couldn't select '", filename, "'..\n" );
539 void(string nextmapname) Map_Goto_SetStr =
541 if(getmapname_stored != "")
542 strunzone(getmapname_stored);
543 if(nextmapname == "")
544 getmapname_stored = "";
546 getmapname_stored = strzone(nextmapname);
549 void(float position) Map_Goto_SetFloat =
551 cvar_set("g_maplist_index", ftos(position));
552 Map_Goto_SetStr(argv(position));
555 void() GameResetCfg =
558 // settings persist, except...
559 if(cvar("g_campaign"))
560 localcmd("\nexec mutator_reset.cfg\n");
561 localcmd("\nsettemp_restore\n");
563 // if an exit cfg is defined by exiting map, exec it.
565 exit_cfg = cvar_string("exit_cfg");
567 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
569 localcmd("exec game_reset.cfg\n");
575 Map_MarkAsRecent(getmapname_stored);
578 MapInfo_LoadMap(getmapname_stored);
580 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
584 // return codes of map selectors:
585 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
586 // -2 = permanent failure
587 float() MaplistMethod_Iterate = // usual method
591 for(pass = 1; pass <= 2; ++pass)
593 for(i = 1; i < Map_Count; ++i)
596 mapindex = mod(i + Map_Current, Map_Count);
597 if(Map_Check(mapindex, pass))
604 float() MaplistMethod_Repeat = // fallback method
606 if(Map_Check(Map_Current, 2))
611 float() MaplistMethod_Random = // random map selection
617 for(i = 0; i <= imax; ++i)
620 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
621 if(Map_Check(mapindex, 1))
627 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
628 // the exponent sets a bias on the map selection:
629 // the higher the exponent, the less likely "shortly repeated" same maps are
631 float i, j, imax, insertpos;
635 for(i = 0; i <= imax; ++i)
639 // now reinsert this at another position
640 insertpos = pow(random(), 1 / exponent); // ]0, 1]
641 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
642 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
643 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
645 // insert the current map there
648 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
649 newlist = strcat(newlist, " ", argv(j));
650 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
651 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
652 newlist = strcat(newlist, " ", argv(j));
653 newlist = substring(newlist, 1, strlen(newlist) - 1);
655 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
656 newlist = strcat(newlist, "'", argv(j), "'");
657 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
658 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
659 newlist = strcat(newlist, "'", argv(j), "'");
661 cvar_set("g_maplist", newlist);
663 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
665 Map_Count = tokenize(newlist);
668 // NOTE: the selected map has just been inserted at (insertpos-1)th position
669 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
670 if(Map_Check(Map_Current, 1))
676 void() Maplist_Init =
679 temp = cvar_string("g_maplist");
681 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
683 Map_Count = tokenize(temp);
687 bprint( "Maplist is empty! Resetting it to default map list.\n" );
689 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
690 localcmd("\nmenu_cmd sync\n");
691 Map_Count = tokenizebyseparator(temp, " ");
693 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
694 Map_Count = tokenize(temp);
698 error("empty maplist, cannot select a new map");
699 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
701 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
702 // this may or may not be correct, but who cares, in the worst case a map
703 // isn't chosen in the first pass that should have been
706 string() GetNextMap =
714 if(cvar("g_maplist_shuffle") > 0)
715 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
718 if(cvar("g_maplist_selectrandom"))
719 nextMap = MaplistMethod_Random();
722 nextMap = MaplistMethod_Iterate();
725 nextMap = MaplistMethod_Repeat();
729 Map_Goto_SetFloat(nextMap);
730 return getmapname_stored;
736 float() DoNextMapOverride =
738 if(cvar("g_campaign"))
740 CampaignPostIntermission();
741 alreadychangedlevel = TRUE;
744 if(cvar("quit_when_empty"))
746 if(player_count <= currentbots)
749 alreadychangedlevel = TRUE;
753 if(cvar_string("quit_and_redirect") != "")
755 redirection_target = strzone(cvar_string("quit_and_redirect"));
756 alreadychangedlevel = TRUE;
759 if (cvar("samelevel")) // if samelevel is set, stay on same level
761 // 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)
762 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
763 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
764 localcmd("restart\n");
765 //changelevel (mapname);
766 alreadychangedlevel = TRUE;
769 if(cvar_string("nextmap") != "")
771 if(MapInfo_CheckMap(cvar_string("nextmap")))
773 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
776 Map_Goto_SetStr(cvar_string("nextmap"));
778 alreadychangedlevel = TRUE;
781 if(cvar("lastlevel"))
784 localcmd("set lastlevel 0\ntogglemenu\n");
785 alreadychangedlevel = TRUE;
793 //local string nextmap;
794 //local float n, nummaps;
796 if (alreadychangedlevel)
798 alreadychangedlevel = TRUE;
804 for(allowReset = 1; allowReset >= 0; --allowReset)
806 nextMap = GetNextMap();
812 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
814 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
815 localcmd("\nmenu_cmd sync\n");
817 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
822 error("Everything is broken - not even the default map list works. Please report this to the developers.");
834 When the player presses attack or jump, change to the next level
837 .float autoscreenshot;
838 void() MapVote_Start;
839 void() MapVote_Think;
840 float mapvote_initialized;
841 void() IntermissionThink =
843 FixIntermissionClient(self);
845 if(cvar("sv_autoscreenshot"))
846 if(self.autoscreenshot > 0)
847 if(time > self.autoscreenshot)
849 self.autoscreenshot = -1;
850 if(clienttype(self) == CLIENTTYPE_REAL)
851 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
855 if (time < intermission_exittime)
858 if(!mapvote_initialized)
859 if (time < intermission_exittime + 10 && !self.button0 && !self.button2 && !self.button3 && !self.button6 && !self.buttonuse)
869 Returns the entity to view from
873 entity() FindIntermission =
878 // look for info_intermission first
879 spot = find (world, classname, "info_intermission");
881 { // pick a random one
885 spot = find (spot, classname, "info_intermission");
887 spot = find (spot, classname, "info_intermission");
893 // then look for the start position
894 spot = find (world, classname, "spawnfunc_info_player_start");
898 // testinfo_player_start is only found in regioned levels
899 spot = find (world, classname, "testplayerstart");
903 // then look for the start position
904 spot = find (world, classname, "spawnfunc_info_player_deathmatch");
908 //objerror ("FindIntermission: no spot");
914 ===============================================================================
918 ===============================================================================
921 void(float final) DumpStats =
925 local float to_console;
926 local float to_eventlog;
929 to_console = cvar("sv_logscores_console");
930 to_eventlog = cvar("sv_eventlog");
931 to_file = cvar("sv_logscores_file");
935 to_console = TRUE; // always print printstats replies
936 to_eventlog = FALSE; // but never print them to the event log
940 if(cvar("sv_eventlog_console"))
941 to_console = FALSE; // otherwise we get the output twice
948 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
950 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
954 ServerConsoleEcho(s, FALSE);
956 GameLogEcho(s, FALSE);
959 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
963 fputs(file, strcat(s, "\n"));
966 FOR_EACH_CLIENT(other)
968 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
970 s = strcat(":player:", ftos(other.frags), ":");
971 s = strcat(s, ftos(other.deaths), ":");
972 s = strcat(s, ftos(rint(time - other.jointime)), ":");
973 s = strcat(s, ftos(other.team), ":");
976 ServerConsoleEcho(strcat(s, other.netname), TRUE);
978 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
980 fputs(file, strcat(s, other.netname, "\n"));
985 ServerConsoleEcho(":end", FALSE);
987 GameLogEcho(":end", FALSE);
990 fputs(file, ":end\n");
995 void FixIntermissionClient(entity e)
997 if(!e.autoscreenshot) // initial call
999 e.angles = e.v_angle;
1000 e.angles_x = -e.angles_x;
1001 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1003 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1004 e.solid = SOLID_NOT;
1005 e.movetype = MOVETYPE_NONE;
1006 e.takedamage = DAMAGE_NO;
1008 e.weaponentity.effects = EF_NODRAW;
1009 stuffcmd(e, "\nscr_printspeed 1000000\n");
1010 if(clienttype(e) == CLIENTTYPE_REAL)
1013 WriteByte(MSG_ONE, SVC_INTERMISSION);
1017 //e.velocity = '0 0 0';
1018 //e.fixangle = TRUE;
1020 // TODO halt weapon animation
1025 go to the next level for deathmatch
1026 only called if a time or frag limit has expired
1030 float minTotalFrags;
1031 float maxTotalFrags;
1037 intermission_running = 1;
1039 // enforce a wait time before allowing changelevel
1040 if(player_count > 0)
1041 intermission_exittime = time + cvar("sv_mapchange_delay");
1043 intermission_exittime = -1;
1045 WriteByte (MSG_ALL, SVC_CDTRACK);
1046 WriteByte (MSG_ALL, 3);
1047 WriteByte (MSG_ALL, 3);
1049 //pos = FindIntermission ();
1055 if(cvar("sv_eventlog"))
1056 GameLogEcho(":gameover", FALSE);
1060 FOR_EACH_CLIENT(other)
1062 FixIntermissionClient(other);
1065 bprint(other.netname, " ^7wins.\n");
1070 FOR_EACH_PLAYER(other)
1072 if(maxTotalFrags < other.totalfrags)
1073 maxTotalFrags = other.totalfrags;
1074 if(minTotalFrags > other.totalfrags)
1075 minTotalFrags = other.totalfrags;
1080 FOR_EACH_PLAYER(other)
1082 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1083 f = bound(0, other.play_time / max(time, 1), 1);
1084 // store some statistics?
1088 if(cvar("g_campaign"))
1089 CampaignPreIntermission();
1091 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1098 Exit deathmatch games upon conditions
1101 void() CheckRules_Player =
1103 if (gameover) // someone else quit the game already
1106 if(self.deadflag == DEAD_NO)
1107 self.play_time += frametime;
1109 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1110 // (div0: and that in CheckRules_World please)
1113 float checkrules_oneminutewarning;
1114 float checkrules_leaderfrags;
1115 float tdm_max_score, tdm_old_score;
1117 float checkrules_equality;
1118 float checkrules_overtimewarning;
1119 float checkrules_overtimeend;
1121 void() InitiateOvertime =
1123 if(!checkrules_overtimeend)
1124 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1127 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1128 float WINNING_YES = 1; // winner found
1129 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1130 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1132 float(float fraglimitreached, float equality) GetWinningCode =
1135 if(fraglimitreached)
1136 return WINNING_STARTOVERTIME;
1138 return WINNING_NEVER;
1140 if(fraglimitreached)
1146 // set the .winning flag for exactly those players with a given field value
1147 void(.float field, float value) SetWinners =
1150 FOR_EACH_PLAYER(head)
1151 head.winning = (head.field == value);
1154 // set the .winning flag for those players with a given field value
1155 void(.float field, float value) AddWinners =
1158 FOR_EACH_PLAYER(head)
1159 if(head.field == value)
1163 // clear frags for all players but the team given (when they ran out of spawnpoints)
1164 void(.float field, float value) ClearFragsForEveryoneBut =
1167 FOR_EACH_PLAYER(head)
1168 if(head.field != value)
1169 head.frags = max(head.frags, 0);
1172 // clear the .winning flags
1173 void(void) ClearWinners =
1176 FOR_EACH_PLAYER(head)
1180 // Onslaught winning condition:
1181 // game terminates if only one team has a working generator (or none)
1182 float() WinningCondition_Onslaught =
1185 local float t1, t2, t3, t4;
1186 // first check if the game has ended
1187 t1 = t2 = t3 = t4 = 0;
1188 head = find(world, classname, "spawnfunc_onslaught_generator");
1191 if (head.health > 0)
1193 if (head.team == COLOR_TEAM1) t1 = 1;
1194 if (head.team == COLOR_TEAM2) t2 = 1;
1195 if (head.team == COLOR_TEAM3) t3 = 1;
1196 if (head.team == COLOR_TEAM4) t4 = 1;
1198 head = find(head, classname, "spawnfunc_onslaught_generator");
1200 if (t1 + t2 + t3 + t4 < 2)
1202 // game over, only one team remains (or none)
1204 if (t1) SetWinners(team, COLOR_TEAM1);
1205 if (t2) SetWinners(team, COLOR_TEAM2);
1206 if (t3) SetWinners(team, COLOR_TEAM3);
1207 if (t4) SetWinners(team, COLOR_TEAM4);
1208 dprint("Have a winner, ending game.\n");
1212 // Two or more teams remain
1216 float() LMS_NewPlayerLives =
1219 fl = cvar("fraglimit");
1223 // first player has left the game for dying too much? Nobody else can get in.
1224 if(lms_lowest_lives < 1)
1227 if(!cvar("g_lms_join_anytime"))
1228 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1231 return bound(1, lms_lowest_lives, fl);
1234 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1235 // they win. Otherwise the defending team wins once the timelimit passes.
1236 void assault_new_round();
1237 float() WinningCondition_Assault =
1240 status = WINNING_NO;
1242 // as the timelimit has not yet passed just assume the defending team will win
1243 if(assault_attacker_team == COLOR_TEAM1)
1245 SetWinners(team, COLOR_TEAM2);
1249 SetWinners(team, COLOR_TEAM1);
1253 ent = find(world, classname, "spawnfunc_target_assault_roundend");
1256 if(ent.winning) // round end has been triggered by attacking team
1258 SetWinners(team, assault_attacker_team);
1259 if(assault_attacker_team == COLOR_TEAM1)
1261 team1_score = team1_score + 50;
1265 team2_score = team2_score + 50;
1268 if(ent.cnt == 1) // this was the second round
1270 status = WINNING_YES;
1274 cvar_set("timelimit", ftos((2*time)/60));
1275 assault_new_round();
1285 // LMS winning condition: game terminates if and only if there's at most one
1286 // one player who's living lives. Top two scores being equal cancels the time
1288 float() WinningCondition_LMS =
1295 have_player = FALSE;
1296 have_players = FALSE;
1297 l = LMS_NewPlayerLives();
1299 head = find(world, classname, "player");
1302 head = find(head, classname, "player");
1304 have_players = TRUE;
1308 // we have at least one player
1311 // two or more active players - continue with the game
1315 // exactly one player?
1318 // but no game has taken place yet
1323 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1324 dprint("Have a winner, ending game.\n");
1331 // nobody is playing at all...
1334 // wait for players...
1338 // SNAFU (maybe a draw game?)
1340 dprint("No players, ending game.\n");
1345 // When we get here, we have at least two players who are actually LIVING,
1346 // or one player who is still waiting for a victim to join the server. Now
1347 // check if the top two players have equal score.
1349 checkrules_leaderfrags = 0;
1350 checkrules_equality = FALSE;
1351 FOR_EACH_PLAYER(head)
1353 if(head.frags > checkrules_leaderfrags)
1355 checkrules_leaderfrags = head.frags;
1356 checkrules_equality = FALSE;
1358 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1359 checkrules_equality = TRUE;
1362 SetWinners(frags, checkrules_leaderfrags);
1364 // The top two players have the same amount of lives? No timelimit then,
1365 // enter overtime...
1367 if(checkrules_equality)
1368 return WINNING_NEVER;
1370 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1374 // DM winning condition: game terminates if a player reached the fraglimit,
1375 // unless the first two players have the same score. The latter case also
1376 // breaks the time limit.
1377 float(float fraglimit) WinningCondition_MaxIndividualScore =
1379 float checkrules_oldleaderfrags;
1382 checkrules_oldleaderfrags = checkrules_leaderfrags;
1383 checkrules_leaderfrags = 0;
1384 checkrules_equality = FALSE;
1385 FOR_EACH_PLAYER(head)
1387 if(head.frags > checkrules_leaderfrags)
1389 checkrules_leaderfrags = head.frags;
1390 checkrules_equality = FALSE;
1392 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1393 checkrules_equality = TRUE;
1396 if(checkrules_leaderfrags > 0)
1397 SetWinners(frags, checkrules_leaderfrags);
1402 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1404 if (checkrules_leaderfrags == fraglimit - 1)
1405 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1406 else if (checkrules_leaderfrags == fraglimit - 2)
1407 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1408 else if (checkrules_leaderfrags == fraglimit - 3)
1409 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1412 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1415 float(float fraglimit) WinningConditionBase_Teamplay =
1417 tdm_old_score = tdm_max_score;
1418 tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1420 checkrules_equality =
1425 (team1_score == tdm_max_score)
1426 + (team2_score == tdm_max_score)
1427 + (team3_score == tdm_max_score)
1428 + (team4_score == tdm_max_score)
1432 if(tdm_max_score > 0)
1434 if(team1_score == tdm_max_score)
1435 AddWinners(team, COLOR_TEAM1);
1436 if(team2_score == tdm_max_score)
1437 AddWinners(team, COLOR_TEAM2);
1438 if(team3_score == tdm_max_score)
1439 AddWinners(team, COLOR_TEAM3);
1440 if(team4_score == tdm_max_score)
1441 AddWinners(team, COLOR_TEAM4);
1444 if(!g_runematch && !g_domination)
1445 if(tdm_max_score != tdm_old_score)
1447 if(tdm_max_score == fraglimit - 1)
1448 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1449 else if(tdm_max_score == fraglimit - 2)
1450 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1451 else if(tdm_max_score == fraglimit - 3)
1452 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1455 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1458 // TDM winning condition: game terminates if a team's score sum reached the
1459 // fraglimit, unless the first two teams have the same total score. The latter
1460 // case also breaks the time limit.
1461 float(float fraglimit) WinningCondition_MaxTeamSum =
1465 team1_score = team2_score = team3_score = team4_score = 0;
1467 FOR_EACH_PLAYER(head)
1469 if(head.team == COLOR_TEAM1)
1470 team1_score += head.frags;
1471 else if(head.team == COLOR_TEAM2)
1472 team2_score += head.frags;
1473 else if(head.team == COLOR_TEAM3)
1474 team3_score += head.frags;
1475 else if(head.team == COLOR_TEAM4)
1476 team4_score += head.frags;
1479 return WinningConditionBase_Teamplay(fraglimit);
1482 // DOM/CTF winning condition: game terminates if the max of a team's players'
1483 // score reached the fraglimit, unless the first two teams have the same
1484 // maximum score. The latter case also breaks the time limit.
1485 float(float fraglimit) WinningCondition_MaxTeamMax =
1489 team1_score = team2_score = team3_score = team4_score = 0;
1491 FOR_EACH_PLAYER(head)
1493 if(head.team == COLOR_TEAM1)
1495 if(head.frags > team1_score)
1496 team1_score = head.frags;
1498 else if(head.team == COLOR_TEAM2)
1500 if(head.frags > team2_score)
1501 team2_score = head.frags;
1503 else if(head.team == COLOR_TEAM3)
1505 if(head.frags > team3_score)
1506 team3_score = head.frags;
1508 else if(head.team == COLOR_TEAM4)
1510 if(head.frags > team4_score)
1511 team4_score = head.frags;
1515 return WinningConditionBase_Teamplay(fraglimit);
1518 void print_to(entity e, string s)
1521 sprint(e, strcat(s, "\n"));
1523 ServerConsoleEcho(s, TRUE);
1526 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1536 FOR_EACH_PLAYER(head)
1538 if(!whichteam || head.team == whichteam)
1542 print_to(e, strcat(" ", colorcode, name, ":"));
1544 fragtotal = fragtotal + head.frags;
1545 s = ftos(head.frags);
1546 s = strcat(s, "/", ftos(head.deaths));
1547 s = strcat(s, " @ ", ftos(head.ping));
1548 if(clienttype(head) == CLIENTTYPE_BOT)
1549 s = strcat(s, "botms");
1551 s = strcat(s, "ms");
1552 v = PlayerValue(head);
1554 s = strcat(s, " / ", ftos(v));
1555 print_to(e, strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"));
1558 if(whichteam && found)
1560 s = ftos(fragtotal);
1561 s = strcat(s, " / ", ftos(teamvalue));
1562 print_to(e, strcat(colorcode, " (total: ", s, ")"));
1566 void PrintScoreboard(entity e)
1568 print_to(e, strcat("Time: ", ftos(time / 60)));
1569 print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1570 print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1571 print_to(e, "Scoreboard:");
1574 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1575 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1576 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM3);
1577 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM4);
1581 PrintScoreboardFor(e, "", "^7", 0);
1586 void ShuffleMaplist()
1594 result = cvar_string("g_maplist");
1596 litems = tokenizebyseparator(result, " ");
1598 litems = tokenize(result);
1601 for(start = 0; start < litems - 1; ++start)
1605 // select a random item
1606 selected = ceil(random() * (litems - start) + start) - 1;
1608 // shift this item to the place start
1610 for(i = 0; i < start; ++i)
1611 result = strcat(result, " ", argv(i));
1612 result = strcat(result, " ", argv(selected));
1613 for(i = start; i < litems; ++i)
1615 result = strcat(result, " ", argv(i));
1616 result = substring(result, 1, strlen(result) - 1);
1618 litems = tokenizebyseparator(result, " ");
1620 for(i = 0; i < start; ++i)
1621 result = strcat(result, "'", argv(i), "'");
1622 result = strcat(result, "'", argv(selected), "'");
1623 for(i = start; i < litems; ++i)
1625 result = strcat(result, "'", argv(i), "'");
1627 litems = tokenize(result);
1630 //dprint(result, "\n");
1633 cvar_set("g_maplist", result);
1636 float WinningCondition_RanOutOfSpawns()
1640 if(!have_team_spawns)
1643 if(!some_spawn_has_been_used)
1646 team1_score = team2_score = team3_score = team4_score = 0;
1648 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1650 if(head.team == COLOR_TEAM1)
1652 else if(head.team == COLOR_TEAM2)
1654 else if(head.team == COLOR_TEAM3)
1656 else if(head.team == COLOR_TEAM4)
1660 for(head = world; (head = find(head, classname, "spawnfunc_info_player_deathmatch")) != world; )
1662 if(head.team == COLOR_TEAM1)
1664 else if(head.team == COLOR_TEAM2)
1666 else if(head.team == COLOR_TEAM3)
1668 else if(head.team == COLOR_TEAM4)
1673 if(team1_score + team2_score + team3_score + team4_score == 0)
1675 checkrules_equality = TRUE;
1678 else if(team1_score + team2_score + team3_score + team4_score == 1)
1682 AddWinners(team, COLOR_TEAM1);
1683 ClearFragsForEveryoneBut(team, COLOR_TEAM1);
1687 AddWinners(team, COLOR_TEAM2);
1688 ClearFragsForEveryoneBut(team, COLOR_TEAM2);
1692 AddWinners(team, COLOR_TEAM3);
1693 ClearFragsForEveryoneBut(team, COLOR_TEAM3);
1697 AddWinners(team, COLOR_TEAM4);
1698 ClearFragsForEveryoneBut(team, COLOR_TEAM4);
1710 Exit deathmatch games upon conditions
1713 void() CheckRules_World =
1716 local float timelimit;
1717 local float fraglimit;
1725 MapVote_Think should now do that part
1726 if (intermission_running)
1727 if (time >= intermission_exittime + 60)
1729 if(!DoNextMapOverride())
1735 if (gameover) // someone else quit the game already
1737 if(player_count == 0) // Nobody there? Then let's go to the next map
1739 // this will actually check the player count in the next frame
1740 // again, but this shouldn't hurt
1744 timelimit = cvar("timelimit") * 60;
1745 fraglimit = cvar("fraglimit");
1747 if(checkrules_overtimeend)
1749 if(!checkrules_overtimewarning)
1751 checkrules_overtimewarning = TRUE;
1752 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1753 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1758 if (timelimit && time >= timelimit)
1762 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1768 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1770 checkrules_oneminutewarning = TRUE;
1771 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1774 status = WinningCondition_RanOutOfSpawns();
1775 if(status == WINNING_YES)
1777 bprint("Hey! Someone ran out of spawns!\n");
1781 status = WinningCondition_Assault();
1785 status = WinningCondition_LMS();
1787 else if (g_onslaught)
1789 status = WinningCondition_Onslaught();
1795 if(g_tdm || g_runematch || g_ctf || g_domination || g_keyhunt)
1796 status = WinningCondition_MaxTeamSum(fraglimit);
1798 // status = WinningCondition_MaxTeamMax(fraglimit);
1801 dprint("div0: How can this happen?\n");
1802 status = WinningCondition_MaxTeamMax(fraglimit);
1806 status = WinningCondition_MaxIndividualScore(fraglimit);
1809 if(status == WINNING_STARTOVERTIME)
1811 status = WINNING_NEVER;
1815 if(status == WINNING_NEVER)
1816 // equality cases! Nobody wins if the overtime ends in a draw.
1819 if(checkrules_overtimeend)
1820 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1821 status = WINNING_YES;
1823 if(status == WINNING_YES)
1827 float randsel_value;
1828 float randsel_priority;
1829 float randsel_count;
1833 randsel_priority = -1;
1836 void RandSel_Add(float priority, float value)
1838 if(priority > randsel_priority)
1840 randsel_priority = priority;
1841 randsel_value = value;
1844 else if(priority == randsel_priority)
1847 if(ceil(random() * randsel_count) == 1)
1848 randsel_value = value;
1852 float mapvote_nextthink;
1853 float mapvote_initialized;
1854 float mapvote_keeptwotime;
1855 float mapvote_timeout;
1856 string mapvote_message;
1858 #define MAPVOTE_COUNT 10
1859 float mapvote_count;
1860 float mapvote_count_real;
1861 string mapvote_maps[MAPVOTE_COUNT];
1862 float mapvote_maps_suggested[MAPVOTE_COUNT];
1863 string mapvote_suggestions[MAPVOTE_COUNT];
1864 float mapvote_suggestion_ptr;
1865 float mapvote_maxlen;
1866 float mapvote_voters;
1867 float mapvote_votes[MAPVOTE_COUNT];
1869 float mapvote_detail;
1870 float mapvote_abstain;
1873 void MapVote_ClearAllVotes()
1875 FOR_EACH_CLIENT(other)
1879 string MapVote_Suggest(string m)
1883 return "That's not how to use this command.";
1884 if(!cvar("g_maplist_votable_suggestions"))
1885 return "Suggestions are not accepted on this server.";
1886 if(mapvote_initialized)
1887 return "Can't suggest - voting is already in progress!";
1889 m = MapInfo_FixName(m);
1891 return "The map you suggested is not available on this server.";
1893 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1894 if(!IsSameGametype(m))
1895 return "This server does not allow changing the game type by map suggestions.";
1897 if(!cvar("g_maplist_votable_override_mostrecent"))
1899 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1902 if(!MapInfo_CheckMap(m))
1903 return "The map you suggested does not support the current game mode.";
1905 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1906 return "The map you suggested is not available on this server.";
1908 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1909 if(mapvote_suggestions[i] == m)
1910 return "This map was already suggested.";
1911 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1913 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1917 i = mapvote_suggestion_ptr;
1918 mapvote_suggestion_ptr += 1;
1920 if(mapvote_suggestions[i] != "")
1921 strunzone(mapvote_suggestions[i]);
1922 mapvote_suggestions[i] = strzone(m);
1923 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)), TRUE);
1924 return strcat("Suggestion of ", m, " accepted.");
1927 void MapVote_AddVotable(string nextMap, float isSuggestion)
1932 for(j = 0; j < mapvote_count; ++j)
1933 if(mapvote_maps[j] == nextMap)
1935 if(strlen(nextMap) > mapvote_maxlen)
1936 mapvote_maxlen = strlen(nextMap);
1937 mapvote_maps[mapvote_count] = strzone(nextMap);
1938 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1947 MapVote_ClearAllVotes();
1950 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1951 mapvote_abstain = cvar("g_maplist_votable_abstain");
1954 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1956 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1957 smax = min(nmax, cvar("g_maplist_votable_suggestions"));
1959 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1960 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1962 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1963 MapVote_AddVotable(GetNextMap(), FALSE);
1965 if(mapvote_count == 0)
1967 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1969 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1970 localcmd("\nmenu_cmd sync\n");
1972 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1974 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1975 MapVote_AddVotable(GetNextMap(), FALSE);
1978 mapvote_count_real = mapvote_count;
1980 MapVote_AddVotable("don't care", 0);
1982 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1984 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1985 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1986 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1987 mapvote_keeptwotime = 0;
1988 mapvote_message = "Choose a map and press its key!";
1990 float MapVote_Finished(float mappos)
1996 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1997 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1998 didntvote = mapvote_voters;
1999 for(i = 0; i < mapvote_count; ++i)
2000 if(mapvote_maps[i] != "")
2002 didntvote -= mapvote_votes[i];
2005 result = strcat(result, ":", mapvote_maps[i]);
2006 result = strcat(result, ":", ftos(mapvote_votes[i]));
2009 result = strcat(result, ":didn't vote:", ftos(didntvote));
2011 GameLogEcho(result, FALSE);
2012 if(mapvote_maps_suggested[mappos])
2013 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
2015 FOR_EACH_REALCLIENT(other)
2016 FixClientCvars(other);
2018 Map_Goto_SetStr(mapvote_maps[mappos]);
2020 alreadychangedlevel = TRUE;
2023 void MapVote_CheckRules_1()
2027 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2029 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2030 mapvote_votes[i] = 0;
2034 FOR_EACH_REALCLIENT(other)
2039 i = other.mapvote - 1;
2040 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2041 mapvote_votes[i] = mapvote_votes[i] + 1;
2046 float MapVote_CheckRules_2()
2049 float firstPlace, secondPlace;
2050 float firstPlaceVotes, secondPlaceVotes;
2051 float mapvote_voters_real;
2054 mapvote_voters_real = mapvote_voters;
2056 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2059 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2060 RandSel_Add(mapvote_votes[i], i);
2061 firstPlace = randsel_value;
2062 firstPlaceVotes = randsel_priority;
2063 //dprint("First place: ", ftos(firstPlace), "\n");
2064 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2067 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2069 RandSel_Add(mapvote_votes[i], i);
2070 secondPlace = randsel_value;
2071 secondPlaceVotes = randsel_priority;
2072 //dprint("Second place: ", ftos(secondPlace), "\n");
2073 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2075 if(firstPlace == -1)
2076 error("No first place in map vote... WTF?");
2078 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2079 return MapVote_Finished(firstPlace);
2081 if(mapvote_keeptwotime)
2082 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2085 mapvote_message = "Now decide between the TOP TWO!";
2086 mapvote_keeptwotime = 0;
2087 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2088 result = strcat(result, ":", ftos(firstPlaceVotes));
2089 result = strcat(result, ":", mapvote_maps[secondPlace]);
2090 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2091 didntvote = mapvote_voters;
2092 for(i = 0; i < mapvote_count; ++i)
2093 if(mapvote_maps[i] != "")
2095 didntvote -= mapvote_votes[i];
2097 if(i != secondPlace)
2099 result = strcat(result, ":", mapvote_maps[i]);
2100 result = strcat(result, ":", ftos(mapvote_votes[i]));
2101 if(i < mapvote_count_real)
2103 strunzone(mapvote_maps[i]);
2104 mapvote_maps[i] = "";
2108 result = strcat(result, ":didn't vote:", ftos(didntvote));
2109 GameLogEcho(result, FALSE);
2122 keeptwo = mapvote_keeptwotime;
2123 MapVote_CheckRules_1(); // count
2124 if(MapVote_CheckRules_2()) // decide
2128 FOR_EACH_REALCLIENT(other)
2130 // hide scoreboard again
2131 if(other.health != 2342)
2133 other.health = 2342;
2135 if(clienttype(other) == CLIENTTYPE_REAL)
2137 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");
2139 WriteByte(MSG_ONE, SVC_FINALE);
2140 WriteString(MSG_ONE, "");
2144 // notify about keep-two
2145 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2146 play2(other, "misc/invshot.wav");
2148 // clear possibly invalid votes
2149 if(mapvote_maps[other.mapvote - 1] == "")
2151 // use impulses as new vote
2152 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2153 if(mapvote_maps[other.impulse - 1] != "")
2154 other.mapvote = other.impulse;
2161 MapVote_CheckRules_1(); // just count
2163 FOR_EACH_REALCLIENT(other)
2165 // display voting screen
2166 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2167 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2169 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2170 msgstr = strcat(msgstr, mapvote_message);
2171 msgstr = strcat(msgstr, "\n\n");
2172 for(i = 0; i < mapvote_count; ++i)
2173 if(mapvote_maps[i] == "")
2174 msgstr = strcat(msgstr, "\n");
2177 tmp = mapvote_maps[i];
2178 tmp = strpad(mapvote_maxlen, tmp);
2179 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2182 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2183 if(mapvote_votes[i] != 1)
2184 tmp = strcat(tmp, "s");
2185 tmp = strcat(tmp, ")");
2186 tmp = strpad(mapvote_maxlen + 15, tmp);
2189 if(i == mapvote_count - 1)
2190 msgstr = strcat(msgstr, "\n");
2191 if(other.mapvote == i + 1)
2192 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2194 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2197 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2199 msgstr = strcat(msgstr, "s");
2200 msgstr = strcat(msgstr, " cast");
2201 i = ceil(mapvote_timeout - time);
2202 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2204 msgstr = strcat(msgstr, "s");
2205 msgstr = strcat(msgstr, " left");
2207 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2210 void MapVote_Start()
2216 MapInfo_Enumerate();
2217 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2221 void MapVote_Think()
2226 if(alreadychangedlevel)
2229 if(time < mapvote_nextthink)
2233 mapvote_nextthink = time + 0.5;
2235 if(!mapvote_initialized)
2237 mapvote_initialized = TRUE;
2238 if(DoNextMapOverride())
2240 if(!cvar("g_maplist_votable") || player_count <= 0)
2251 string GotoMap(string m)
2254 if(!MapInfo_CheckMap(m))
2256 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2258 return "The map you chose is not available on this server.";
2259 cvar_set("nextmap", m);
2260 cvar_set("timelimit", "-1");
2261 if(mapvote_initialized || alreadychangedlevel)
2263 if(DoNextMapOverride())
2264 return "Map switch initiated.";
2266 return "Hm... no. For some reason I like THIS map more.";
2269 return "Map switch will happen after scoreboard.";
2275 FOR_EACH_REALCLIENT(self)
2277 if(self.classname == "spectator")
2279 if(self.enemy.hitsound)
2280 play2(self, "misc/hit.wav");
2285 play2(self, "misc/hit.wav");
2288 FOR_EACH_CLIENT(self)
2289 self.hitsound = FALSE;
2295 * returns TRUE if redirecting
2297 float redirection_timeout;
2298 float redirection_nextthink;
2299 float RedirectionThink()
2301 float clients_found;
2303 if(redirection_target == "")
2306 if(!redirection_timeout)
2308 cvar_set("sv_public", "-2");
2309 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2310 if(redirection_target == "self")
2311 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2313 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2316 if(time < redirection_nextthink)
2319 redirection_nextthink = time + 1;
2322 FOR_EACH_REALCLIENT(self)
2324 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2325 if(redirection_target == "self")
2326 stuffcmd(self, "\ndisconnect; reconnect\n");
2328 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2332 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2334 if(time > redirection_timeout || clients_found == 0)
2335 localcmd("\nwait; wait; wait; quit\n");
2342 if(world_initialized)
2344 world_initialized = 0;
2345 print("Saving persistent data...\n");
2348 db_save(ServerProgsDB, "server.db");
2350 // tell the bot system the game is ending now
2355 print("NOTE: crashed before even initializing the world, not saving persistent data\n");