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");
62 cvar_set("_sv_init", "0");
63 if(cvar("g_maplist_shuffle"))
66 tokenizebyseparator(cvar_string("g_maplist"), " ");
68 tokenize(cvar_string("g_maplist"));
69 if(argv(0) != GetMapname())
72 cvar_set("nextmap", argv(0));
76 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
79 if(!DoNextMapOverride())
88 float world_already_spawned;
89 void worldspawn (void)
91 dprint_load(); // load dprint status from cvar
93 if(world_already_spawned)
94 error("world already spawned - you may have EXACTLY ONE worldspawn!");
95 world_already_spawned = TRUE;
101 MapInfo_LoadMapSettings(mapname);
105 ServerProgsDB = db_create();
107 ServerProgsDB = db_load("server.db");
110 TODO sound pack system
111 // initialize sound pack system
112 soundpack = cvar_string("g_soundpack");
114 soundpack = strcat(soundpack, "/");
115 soundpack = strzone(soundpack);
121 // 1 FLICKER (first variety)
122 lightstyle(1, "mmnmmommommnonmmonqnmmo");
124 // 2 SLOW STRONG PULSE
125 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
127 // 3 CANDLE (first variety)
128 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
131 lightstyle(4, "mamamamamama");
134 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
136 // 6 FLICKER (second variety)
137 lightstyle(6, "nmonqnmomnmomomno");
139 // 7 CANDLE (second variety)
140 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
142 // 8 CANDLE (third variety)
143 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
145 // 9 SLOW STROBE (fourth variety)
146 lightstyle(9, "aaaaaaaazzzzzzzz");
148 // 10 FLUORESCENT FLICKER
149 lightstyle(10, "mmamammmmammamamaaamammma");
151 // 11 SLOW PULSE NOT FADE TO BLACK
152 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
154 // styles 32-62 are assigned by the light program for switchable lights
159 // for setting by mapinfo
160 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
161 cvar_set("sv_q3acompat_machineshotgunswap", "0");
164 lms_lowest_lives = 0;
167 bot_waypoints_for_items = cvar("g_waypoints_for_items");
168 if(bot_waypoints_for_items == 1)
169 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
170 bot_waypoints_for_items = 0;
172 if(cvar("g_campaign"))
179 WaypointSprite_Init();
185 head = nextent(world);
190 head = nextent(head);
193 GameLogInit(); // prepare everything
194 if(cvar("sv_eventlog"))
197 GameLogEcho(":logversion:2", FALSE);
198 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
199 s = strcat(s, ftos(random()));
201 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s), FALSE);
203 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
205 s = ":gameinfo:mutators:LIST";
206 if(cvar("g_grappling_hook"))
207 s = strcat(s, ":grappling_hook");
208 if(!cvar("g_use_ammunition"))
209 s = strcat(s, ":no_use_ammunition");
210 if(!cvar("g_pickup_items"))
211 s = strcat(s, ":no_pickup_items");
212 if(cvar("g_instagib"))
213 s = strcat(s, ":instagib");
214 if(cvar("g_rocketarena"))
215 s = strcat(s, ":rockerarena");
217 s = strcat(s, ":nixnex");
218 if(cvar("g_vampire"))
219 s = strcat(s, ":vampire");
220 if(cvar("g_laserguided_missile"))
221 s = strcat(s, ":laserguided_missile");
222 if(cvar("g_norecoil"))
223 s = strcat(s, ":norecoil");
225 s = strcat(s, ":midair");
226 if(cvar("g_minstagib"))
227 s = strcat(s, ":minstagib");
228 GameLogEcho(s, FALSE);
229 GameLogEcho(":gameinfo:end", FALSE);
232 cvar_set("nextmap", "");
236 if(cvar("g_campaign"))
245 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
248 world_initialized = 1;
253 //makestatic (self); // Who the f___ did that?
257 float( string pFilename ) TryFile =
260 dprint("TryFile(\"", pFilename, "\")\n");
261 lHandle = fopen( pFilename, FILE_READ );
262 if( lHandle != -1 ) {
272 if (game == GAME_DEATHMATCH)
274 else if (game == GAME_TEAM_DEATHMATCH)
276 else if (game == GAME_DOMINATION)
278 else if (game == GAME_CTF)
280 else if (game == GAME_RUNEMATCH)
282 else if (game == GAME_LMS)
284 else if (game == GAME_KEYHUNT)
286 else if (game == GAME_ONSLAUGHT)
288 else if (game == GAME_ASSAULT)
293 float IsSameGametype(string mapcfgname)
296 return TRUE; // can't change game type by map name here
300 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
306 string getmapname_stored;
312 if(getmapname_stored == "")
313 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
314 return getmapname_stored;
318 float Map_Count, Map_Current;
319 string Map_Current_Name;
321 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
322 float GetMaplistPosition()
328 idx = cvar("g_maplist_index");
335 for(pos = 0; pos < Map_Count; ++pos)
339 // resume normal maplist rotation if current map is not in g_maplist
343 float MapHasRightSize(string map)
345 // open map size restriction file
347 dprint("opensize "); dprint(map);
348 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
351 float mapmin, mapmax;
353 mapmin = stof(fgets(fh));
354 mapmax = stof(fgets(fh));
356 if(player_count < mapmin)
358 dprint("not enough\n");
361 if(player_count > mapmax)
363 dprint("too many\n");
366 dprint("right size\n");
369 dprint(": not found\n");
373 string Map_Filename(float position)
376 return strcat("maps/", argv(position), ".bsp");
378 return strcat("maps/", argv(position), ".mapcfg");
382 string strwords(string s, float w)
385 for(endpos = 0; w && endpos >= 0; --w)
386 endpos = strstrofs(s, " ", endpos + 1);
390 return substring(s, 0, endpos);
393 float strhasword(string s, string w)
395 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
398 void Map_MarkAsRecent(string m)
400 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
403 float Map_IsRecent(string m)
405 return strhasword(cvar_string("g_maplist_mostrecent"), m);
408 float(float position, float pass) Map_Check =
412 map_next = argv(position);
415 if(map_next == Map_Current_Name) // same map again in first pass?
417 if(Map_IsRecent(map_next))
420 filename = Map_Filename(position);
422 if(MapInfo_CheckMap(map_next))
424 if(TryFile(filename))
429 if(MapHasRightSize(map_next))
434 dprint( "Couldn't find '", filename, "'..\n" );
439 void(string nextmapname) Map_Goto_SetStr =
441 if(getmapname_stored != "")
442 strunzone(getmapname_stored);
443 if(nextmapname == "")
444 getmapname_stored = "";
446 getmapname_stored = strzone(nextmapname);
449 void(float position) Map_Goto_SetFloat =
451 cvar_set("g_maplist_index", ftos(position));
452 Map_Goto_SetStr(argv(position));
455 void() GameResetCfg =
458 // settings persist, except...
459 if(cvar("g_campaign"))
460 localcmd("\nexec mutator_reset.cfg\n");
461 localcmd("\nsettemp_restore\n");
463 // if an exit cfg is defined by exiting map, exec it.
465 exit_cfg = cvar_string("exit_cfg");
467 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
469 localcmd("exec game_reset.cfg\n");
475 Map_MarkAsRecent(getmapname_stored);
478 MapInfo_LoadMap(getmapname_stored);
480 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
484 // return codes of map selectors:
485 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
486 // -2 = permanent failure
487 float() MaplistMethod_Iterate = // usual method
491 for(pass = 1; pass <= 2; ++pass)
493 for(i = 1; i < Map_Count; ++i)
496 mapindex = mod(i + Map_Current, Map_Count);
497 if(Map_Check(mapindex, pass))
504 float() MaplistMethod_Repeat = // fallback method
506 if(Map_Check(Map_Current, 2))
511 float() MaplistMethod_Random = // random map selection
517 for(i = 0; i <= imax; ++i)
520 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
521 if(Map_Check(mapindex, 1))
527 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
528 // the exponent sets a bias on the map selection:
529 // the higher the exponent, the less likely "shortly repeated" same maps are
531 float i, j, imax, insertpos;
535 for(i = 0; i <= imax; ++i)
539 // now reinsert this at another position
540 insertpos = pow(random(), 1 / exponent); // ]0, 1]
541 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
542 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
543 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
545 // insert the current map there
548 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
549 newlist = strcat(newlist, " ", argv(j));
550 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
551 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
552 newlist = strcat(newlist, " ", argv(j));
553 newlist = substring(newlist, 1, strlen(newlist) - 1);
555 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
556 newlist = strcat(newlist, "'", argv(j), "'");
557 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
558 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
559 newlist = strcat(newlist, "'", argv(j), "'");
561 cvar_set("g_maplist", newlist);
563 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
565 Map_Count = tokenize(newlist);
568 // NOTE: the selected map has just been inserted at (insertpos-1)th position
569 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
570 if(Map_Check(Map_Current, 1))
576 void() Maplist_Init =
579 temp = cvar_string("g_maplist");
581 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
583 Map_Count = tokenize(temp);
587 bprint( "Maplist is empty! Resetting it to default map list.\n" );
589 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
590 localcmd("\nmenu_cmd sync\n");
591 Map_Count = tokenizebyseparator(temp, " ");
593 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
594 Map_Count = tokenize(temp);
598 error("empty maplist, cannot select a new map");
599 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
601 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
602 // this may or may not be correct, but who cares, in the worst case a map
603 // isn't chosen in the first pass that should have been
606 string() GetNextMap =
614 if(cvar("g_maplist_shuffle") > 0)
615 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
618 if(cvar("g_maplist_selectrandom"))
619 nextMap = MaplistMethod_Random();
622 nextMap = MaplistMethod_Iterate();
625 nextMap = MaplistMethod_Repeat();
629 Map_Goto_SetFloat(nextMap);
630 return getmapname_stored;
636 float() DoNextMapOverride =
638 if(cvar("g_campaign"))
640 CampaignPostIntermission();
641 alreadychangedlevel = TRUE;
644 if(cvar("quit_when_empty"))
646 if(player_count <= currentbots)
649 alreadychangedlevel = TRUE;
653 if(cvar_string("quit_and_redirect") != "")
655 redirection_target = strzone(cvar_string("quit_and_redirect"));
656 alreadychangedlevel = TRUE;
659 if (cvar("samelevel")) // if samelevel is set, stay on same level
661 // 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)
662 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
663 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
664 localcmd("restart\n");
665 //changelevel (mapname);
666 alreadychangedlevel = TRUE;
669 if(cvar_string("nextmap") != "")
671 if(MapInfo_CheckMap(cvar_string("nextmap")))
673 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
676 Map_Goto_SetStr(cvar_string("nextmap"));
678 alreadychangedlevel = TRUE;
681 if(cvar("lastlevel"))
684 localcmd("set lastlevel 0\ntogglemenu\n");
685 alreadychangedlevel = TRUE;
693 //local string nextmap;
694 //local float n, nummaps;
696 if (alreadychangedlevel)
698 alreadychangedlevel = TRUE;
704 for(allowReset = 1; allowReset >= 0; --allowReset)
706 nextMap = GetNextMap();
712 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
714 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
715 localcmd("\nmenu_cmd sync\n");
717 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
722 error("Everything is broken - not even the default map list works. Please report this to the developers.");
734 When the player presses attack or jump, change to the next level
737 .float autoscreenshot;
738 void() MapVote_Start;
739 void() MapVote_Think;
740 float mapvote_initialized;
741 void() IntermissionThink =
743 FixIntermissionClient(self);
745 if(cvar("sv_autoscreenshot"))
746 if(self.autoscreenshot > 0)
747 if(time > self.autoscreenshot)
749 self.autoscreenshot = -1;
750 if(clienttype(self) == CLIENTTYPE_REAL)
751 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
755 if (time < intermission_exittime)
758 if(!mapvote_initialized)
759 if (time < intermission_exittime + 10 && !self.button0 && !self.button2 && !self.button3 && !self.button6 && !self.buttonuse)
769 Returns the entity to view from
773 entity() FindIntermission =
778 // look for info_intermission first
779 spot = find (world, classname, "info_intermission");
781 { // pick a random one
785 spot = find (spot, classname, "info_intermission");
787 spot = find (spot, classname, "info_intermission");
793 // then look for the start position
794 spot = find (world, classname, "info_player_start");
798 // testinfo_player_start is only found in regioned levels
799 spot = find (world, classname, "testplayerstart");
803 // then look for the start position
804 spot = find (world, classname, "info_player_deathmatch");
808 //objerror ("FindIntermission: no spot");
814 ===============================================================================
818 ===============================================================================
821 void(float final) DumpStats =
825 local float to_console;
826 local float to_eventlog;
829 to_console = cvar("sv_logscores_console");
830 to_eventlog = cvar("sv_eventlog");
831 to_file = cvar("sv_logscores_file");
835 to_console = TRUE; // always print printstats replies
836 to_eventlog = FALSE; // but never print them to the event log
840 if(cvar("sv_eventlog_console"))
841 to_console = FALSE; // otherwise we get the output twice
848 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
850 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
854 ServerConsoleEcho(s, FALSE);
856 GameLogEcho(s, FALSE);
859 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
863 fputs(file, strcat(s, "\n"));
866 FOR_EACH_CLIENT(other)
868 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
870 s = strcat(":player:", ftos(other.frags), ":");
871 s = strcat(s, ftos(other.deaths), ":");
872 s = strcat(s, ftos(rint(time - other.jointime)), ":");
873 s = strcat(s, ftos(other.team), ":");
876 ServerConsoleEcho(strcat(s, other.netname), TRUE);
878 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
880 fputs(file, strcat(s, other.netname, "\n"));
885 ServerConsoleEcho(":end", FALSE);
887 GameLogEcho(":end", FALSE);
890 fputs(file, ":end\n");
895 void FixIntermissionClient(entity e)
897 if(!e.autoscreenshot) // initial call
899 e.angles = e.v_angle;
900 e.angles_x = -e.angles_x;
901 e.autoscreenshot = time + 0.8; // used for autoscreenshot
903 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
905 e.movetype = MOVETYPE_NONE;
906 e.takedamage = DAMAGE_NO;
908 e.weaponentity.effects = EF_NODRAW;
909 stuffcmd(e, "\nscr_printspeed 1000000\n");
910 if(clienttype(e) == CLIENTTYPE_REAL)
913 WriteByte(MSG_ONE, SVC_INTERMISSION);
917 //e.velocity = '0 0 0';
920 // TODO halt weapon animation
925 go to the next level for deathmatch
926 only called if a time or frag limit has expired
937 intermission_running = 1;
939 // enforce a wait time before allowing changelevel
941 intermission_exittime = time + cvar("sv_mapchange_delay");
943 intermission_exittime = -1;
945 WriteByte (MSG_ALL, SVC_CDTRACK);
946 WriteByte (MSG_ALL, 3);
947 WriteByte (MSG_ALL, 3);
949 //pos = FindIntermission ();
955 if(cvar("sv_eventlog"))
956 GameLogEcho(":gameover", FALSE);
960 FOR_EACH_CLIENT(other)
962 FixIntermissionClient(other);
965 bprint(other.netname, " ^7wins.\n");
970 FOR_EACH_PLAYER(other)
972 if(maxTotalFrags < other.totalfrags)
973 maxTotalFrags = other.totalfrags;
974 if(minTotalFrags > other.totalfrags)
975 minTotalFrags = other.totalfrags;
980 FOR_EACH_PLAYER(other)
982 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
983 f = bound(0, other.play_time / max(time, 1), 1);
984 // store some statistics?
988 if(cvar("g_campaign"))
989 CampaignPreIntermission();
991 // WriteByte (MSG_ALL, SVC_INTERMISSION);
998 Exit deathmatch games upon conditions
1001 void() CheckRules_Player =
1003 if (gameover) // someone else quit the game already
1006 if(self.deadflag == DEAD_NO)
1007 self.play_time += frametime;
1009 // fixme: don't check players; instead check dom_team and ctf_team entities
1010 // (div0: and that in CheckRules_World please)
1013 float checkrules_oneminutewarning;
1014 float checkrules_leaderfrags;
1015 float tdm_max_score, tdm_old_score;
1017 float checkrules_equality;
1018 float checkrules_overtimewarning;
1019 float checkrules_overtimeend;
1021 void() InitiateOvertime =
1023 if(!checkrules_overtimeend)
1024 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1027 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1028 float WINNING_YES = 1; // winner found
1029 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1030 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1032 float(float fraglimitreached, float equality) GetWinningCode =
1035 if(fraglimitreached)
1036 return WINNING_STARTOVERTIME;
1038 return WINNING_NEVER;
1040 if(fraglimitreached)
1046 // set the .winning flag for exactly those players with a given field value
1047 void(.float field, float value) SetWinners =
1050 FOR_EACH_PLAYER(head)
1051 head.winning = (head.field == value);
1054 // set the .winning flag for those players with a given field value
1055 void(.float field, float value) AddWinners =
1058 FOR_EACH_PLAYER(head)
1059 if(head.field == value)
1063 // clear frags for all players but the team given (when they ran out of spawnpoints)
1064 void(.float field, float value) ClearFragsForEveryoneBut =
1067 FOR_EACH_PLAYER(head)
1068 if(head.field != value)
1069 head.frags = max(head.frags, 0);
1072 // clear the .winning flags
1073 void(void) ClearWinners =
1076 FOR_EACH_PLAYER(head)
1080 // Onslaught winning condition:
1081 // game terminates if only one team has a working generator (or none)
1082 float() WinningCondition_Onslaught =
1085 local float t1, t2, t3, t4;
1086 // first check if the game has ended
1087 t1 = t2 = t3 = t4 = 0;
1088 head = find(world, classname, "onslaught_generator");
1091 if (head.health > 0)
1093 if (head.team == COLOR_TEAM1) t1 = 1;
1094 if (head.team == COLOR_TEAM2) t2 = 1;
1095 if (head.team == COLOR_TEAM3) t3 = 1;
1096 if (head.team == COLOR_TEAM4) t4 = 1;
1098 head = find(head, classname, "onslaught_generator");
1100 if (t1 + t2 + t3 + t4 < 2)
1102 // game over, only one team remains (or none)
1104 if (t1) SetWinners(team, COLOR_TEAM1);
1105 if (t2) SetWinners(team, COLOR_TEAM2);
1106 if (t3) SetWinners(team, COLOR_TEAM3);
1107 if (t4) SetWinners(team, COLOR_TEAM4);
1108 dprint("Have a winner, ending game.\n");
1112 // Two or more teams remain
1116 float() LMS_NewPlayerLives =
1119 fl = cvar("fraglimit");
1123 // first player has left the game for dying too much? Nobody else can get in.
1124 if(lms_lowest_lives < 1)
1127 if(!cvar("g_lms_join_anytime"))
1128 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1131 return bound(1, lms_lowest_lives, fl);
1134 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1135 // they win. Otherwise the defending team wins once the timelimit passes.
1136 void assault_new_round();
1137 float() WinningCondition_Assault =
1140 status = WINNING_NO;
1142 // as the timelimit has not yet passed just assume the defending team will win
1143 if(assault_attacker_team == COLOR_TEAM1)
1145 SetWinners(team, COLOR_TEAM2);
1149 SetWinners(team, COLOR_TEAM1);
1153 ent = find(world, classname, "target_assault_roundend");
1156 if(ent.winning) // round end has been triggered by attacking team
1158 SetWinners(team, assault_attacker_team);
1159 if(assault_attacker_team == COLOR_TEAM1)
1161 team1_score = team1_score + 50;
1165 team2_score = team2_score + 50;
1168 if(ent.cnt == 1) // this was the second round
1170 status = WINNING_YES;
1174 cvar_set("timelimit", ftos((2*time)/60));
1175 assault_new_round();
1185 // LMS winning condition: game terminates if and only if there's at most one
1186 // one player who's living lives. Top two scores being equal cancels the time
1188 float() WinningCondition_LMS =
1195 have_player = FALSE;
1196 have_players = FALSE;
1197 l = LMS_NewPlayerLives();
1199 head = find(world, classname, "player");
1202 head = find(head, classname, "player");
1204 have_players = TRUE;
1208 // we have at least one player
1211 // two or more active players - continue with the game
1215 // exactly one player?
1218 // but no game has taken place yet
1223 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1224 dprint("Have a winner, ending game.\n");
1231 // nobody is playing at all...
1234 // wait for players...
1238 // SNAFU (maybe a draw game?)
1240 dprint("No players, ending game.\n");
1245 // When we get here, we have at least two players who are actually LIVING,
1246 // or one player who is still waiting for a victim to join the server. Now
1247 // check if the top two players have equal score.
1249 checkrules_leaderfrags = 0;
1250 checkrules_equality = FALSE;
1251 FOR_EACH_PLAYER(head)
1253 if(head.frags > checkrules_leaderfrags)
1255 checkrules_leaderfrags = head.frags;
1256 checkrules_equality = FALSE;
1258 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1259 checkrules_equality = TRUE;
1262 SetWinners(frags, checkrules_leaderfrags);
1264 // The top two players have the same amount of lives? No timelimit then,
1265 // enter overtime...
1267 if(checkrules_equality)
1268 return WINNING_NEVER;
1270 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1274 // DM winning condition: game terminates if a player reached the fraglimit,
1275 // unless the first two players have the same score. The latter case also
1276 // breaks the time limit.
1277 float(float fraglimit) WinningCondition_MaxIndividualScore =
1279 float checkrules_oldleaderfrags;
1282 checkrules_oldleaderfrags = checkrules_leaderfrags;
1283 checkrules_leaderfrags = 0;
1284 checkrules_equality = FALSE;
1285 FOR_EACH_PLAYER(head)
1287 if(head.frags > checkrules_leaderfrags)
1289 checkrules_leaderfrags = head.frags;
1290 checkrules_equality = FALSE;
1292 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1293 checkrules_equality = TRUE;
1296 if(checkrules_leaderfrags > 0)
1297 SetWinners(frags, checkrules_leaderfrags);
1302 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1304 if (checkrules_leaderfrags == fraglimit - 1)
1305 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1306 else if (checkrules_leaderfrags == fraglimit - 2)
1307 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1308 else if (checkrules_leaderfrags == fraglimit - 3)
1309 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1312 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1315 float(float fraglimit) WinningConditionBase_Teamplay =
1317 tdm_old_score = tdm_max_score;
1318 tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1320 checkrules_equality =
1325 (team1_score == tdm_max_score)
1326 + (team2_score == tdm_max_score)
1327 + (team3_score == tdm_max_score)
1328 + (team4_score == tdm_max_score)
1332 if(tdm_max_score > 0)
1334 if(team1_score == tdm_max_score)
1335 AddWinners(team, COLOR_TEAM1);
1336 if(team2_score == tdm_max_score)
1337 AddWinners(team, COLOR_TEAM2);
1338 if(team3_score == tdm_max_score)
1339 AddWinners(team, COLOR_TEAM3);
1340 if(team4_score == tdm_max_score)
1341 AddWinners(team, COLOR_TEAM4);
1344 if(!g_runematch && !g_domination)
1345 if(tdm_max_score != tdm_old_score)
1347 if(tdm_max_score == fraglimit - 1)
1348 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1349 else if(tdm_max_score == fraglimit - 2)
1350 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1351 else if(tdm_max_score == fraglimit - 3)
1352 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1355 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1358 // TDM winning condition: game terminates if a team's score sum reached the
1359 // fraglimit, unless the first two teams have the same total score. The latter
1360 // case also breaks the time limit.
1361 float(float fraglimit) WinningCondition_MaxTeamSum =
1365 team1_score = team2_score = team3_score = team4_score = 0;
1367 FOR_EACH_PLAYER(head)
1369 if(head.team == COLOR_TEAM1)
1370 team1_score += head.frags;
1371 else if(head.team == COLOR_TEAM2)
1372 team2_score += head.frags;
1373 else if(head.team == COLOR_TEAM3)
1374 team3_score += head.frags;
1375 else if(head.team == COLOR_TEAM4)
1376 team4_score += head.frags;
1379 return WinningConditionBase_Teamplay(fraglimit);
1382 // DOM/CTF winning condition: game terminates if the max of a team's players'
1383 // score reached the fraglimit, unless the first two teams have the same
1384 // maximum score. The latter case also breaks the time limit.
1385 float(float fraglimit) WinningCondition_MaxTeamMax =
1389 team1_score = team2_score = team3_score = team4_score = 0;
1391 FOR_EACH_PLAYER(head)
1393 if(head.team == COLOR_TEAM1)
1395 if(head.frags > team1_score)
1396 team1_score = head.frags;
1398 else if(head.team == COLOR_TEAM2)
1400 if(head.frags > team2_score)
1401 team2_score = head.frags;
1403 else if(head.team == COLOR_TEAM3)
1405 if(head.frags > team3_score)
1406 team3_score = head.frags;
1408 else if(head.team == COLOR_TEAM4)
1410 if(head.frags > team4_score)
1411 team4_score = head.frags;
1415 return WinningConditionBase_Teamplay(fraglimit);
1418 void print_to(entity e, string s)
1421 sprint(e, strcat(s, "\n"));
1423 ServerConsoleEcho(s, TRUE);
1426 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1436 FOR_EACH_PLAYER(head)
1438 if(!whichteam || head.team == whichteam)
1442 print_to(e, strcat(" ", colorcode, name, ":"));
1444 fragtotal = fragtotal + head.frags;
1445 s = ftos(head.frags);
1446 s = strcat(s, "/", ftos(head.deaths));
1447 s = strcat(s, " @ ", ftos(head.ping));
1448 if(clienttype(head) == CLIENTTYPE_BOT)
1449 s = strcat(s, "botms");
1451 s = strcat(s, "ms");
1452 v = PlayerValue(head);
1454 s = strcat(s, " / ", ftos(v));
1455 print_to(e, strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"));
1458 if(whichteam && found)
1460 s = ftos(fragtotal);
1461 s = strcat(s, " / ", ftos(teamvalue));
1462 print_to(e, strcat(colorcode, " (total: ", s, ")"));
1466 void PrintScoreboard(entity e)
1468 print_to(e, strcat("Time: ", ftos(time / 60)));
1469 print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1470 print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1471 print_to(e, "Scoreboard:");
1474 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1475 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1476 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM3);
1477 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM4);
1481 PrintScoreboardFor(e, "", "^7", 0);
1486 void ShuffleMaplist()
1494 result = cvar_string("g_maplist");
1496 litems = tokenizebyseparator(result, " ");
1498 litems = tokenize(result);
1501 for(start = 0; start < litems - 1; ++start)
1505 // select a random item
1506 selected = ceil(random() * (litems - start) + start) - 1;
1508 // shift this item to the place start
1510 for(i = 0; i < start; ++i)
1511 result = strcat(result, " ", argv(i));
1512 result = strcat(result, " ", argv(selected));
1513 for(i = start; i < litems; ++i)
1515 result = strcat(result, " ", argv(i));
1516 result = substring(result, 1, strlen(result) - 1);
1518 litems = tokenizebyseparator(result, " ");
1520 for(i = 0; i < start; ++i)
1521 result = strcat(result, "'", argv(i), "'");
1522 result = strcat(result, "'", argv(selected), "'");
1523 for(i = start; i < litems; ++i)
1525 result = strcat(result, "'", argv(i), "'");
1527 litems = tokenize(result);
1530 //dprint(result, "\n");
1533 cvar_set("g_maplist", result);
1536 float WinningCondition_RanOutOfSpawns()
1540 if(!have_team_spawns)
1543 if(!some_spawn_has_been_used)
1546 team1_score = team2_score = team3_score = team4_score = 0;
1548 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1550 if(head.team == COLOR_TEAM1)
1552 else if(head.team == COLOR_TEAM2)
1554 else if(head.team == COLOR_TEAM3)
1556 else if(head.team == COLOR_TEAM4)
1560 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1562 if(head.team == COLOR_TEAM1)
1564 else if(head.team == COLOR_TEAM2)
1566 else if(head.team == COLOR_TEAM3)
1568 else if(head.team == COLOR_TEAM4)
1573 if(team1_score + team2_score + team3_score + team4_score == 0)
1575 checkrules_equality = TRUE;
1578 else if(team1_score + team2_score + team3_score + team4_score == 1)
1582 AddWinners(team, COLOR_TEAM1);
1583 ClearFragsForEveryoneBut(team, COLOR_TEAM1);
1587 AddWinners(team, COLOR_TEAM2);
1588 ClearFragsForEveryoneBut(team, COLOR_TEAM2);
1592 AddWinners(team, COLOR_TEAM3);
1593 ClearFragsForEveryoneBut(team, COLOR_TEAM3);
1597 AddWinners(team, COLOR_TEAM4);
1598 ClearFragsForEveryoneBut(team, COLOR_TEAM4);
1610 Exit deathmatch games upon conditions
1613 void() CheckRules_World =
1616 local float timelimit;
1617 local float fraglimit;
1625 MapVote_Think should now do that part
1626 if (intermission_running)
1627 if (time >= intermission_exittime + 60)
1629 if(!DoNextMapOverride())
1635 if (gameover) // someone else quit the game already
1637 if(player_count == 0) // Nobody there? Then let's go to the next map
1639 // this will actually check the player count in the next frame
1640 // again, but this shouldn't hurt
1644 timelimit = cvar("timelimit") * 60;
1645 fraglimit = cvar("fraglimit");
1647 if(checkrules_overtimeend)
1649 if(!checkrules_overtimewarning)
1651 checkrules_overtimewarning = TRUE;
1652 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1653 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1658 if (timelimit && time >= timelimit)
1662 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1668 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1670 checkrules_oneminutewarning = TRUE;
1671 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1674 status = WinningCondition_RanOutOfSpawns();
1675 if(status == WINNING_YES)
1677 bprint("Hey! Someone ran out of spawns!\n");
1681 status = WinningCondition_Assault();
1685 status = WinningCondition_LMS();
1687 else if (g_onslaught)
1689 status = WinningCondition_Onslaught();
1695 if(g_tdm || g_runematch || g_ctf || g_domination || g_keyhunt)
1696 status = WinningCondition_MaxTeamSum(fraglimit);
1698 // status = WinningCondition_MaxTeamMax(fraglimit);
1701 dprint("div0: How can this happen?\n");
1702 status = WinningCondition_MaxTeamMax(fraglimit);
1706 status = WinningCondition_MaxIndividualScore(fraglimit);
1709 if(status == WINNING_STARTOVERTIME)
1711 status = WINNING_NEVER;
1715 if(status == WINNING_NEVER)
1716 // equality cases! Nobody wins if the overtime ends in a draw.
1719 if(checkrules_overtimeend)
1720 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1721 status = WINNING_YES;
1723 if(status == WINNING_YES)
1727 float randsel_value;
1728 float randsel_priority;
1729 float randsel_count;
1733 randsel_priority = -1;
1736 void RandSel_Add(float priority, float value)
1738 if(priority > randsel_priority)
1740 randsel_priority = priority;
1741 randsel_value = value;
1744 else if(priority == randsel_priority)
1747 if(ceil(random() * randsel_count) == 1)
1748 randsel_value = value;
1752 float mapvote_nextthink;
1753 float mapvote_initialized;
1754 float mapvote_keeptwotime;
1755 float mapvote_timeout;
1756 string mapvote_message;
1758 #define MAPVOTE_COUNT 10
1759 float mapvote_count;
1760 float mapvote_count_real;
1761 string mapvote_maps[MAPVOTE_COUNT];
1762 float mapvote_maps_suggested[MAPVOTE_COUNT];
1763 string mapvote_suggestions[MAPVOTE_COUNT];
1764 float mapvote_suggestion_ptr;
1765 float mapvote_maxlen;
1766 float mapvote_voters;
1767 float mapvote_votes[MAPVOTE_COUNT];
1769 float mapvote_detail;
1770 float mapvote_abstain;
1773 void MapVote_ClearAllVotes()
1775 FOR_EACH_CLIENT(other)
1779 string MapVote_Suggest(string m)
1783 return "That's not how to use this command.";
1784 if(!cvar("g_maplist_votable_suggestions"))
1785 return "Suggestions are not accepted on this server.";
1786 if(mapvote_initialized)
1787 return "Can't suggest - voting is already in progress!";
1789 m = MapInfo_FixName(m);
1791 return "The map you suggested is not available on this server.";
1793 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1794 if(!IsSameGametype(m))
1795 return "This server does not allow changing the game type by map suggestions.";
1797 if(!cvar("g_maplist_votable_override_mostrecent"))
1799 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1802 if(!MapInfo_CheckMap(m))
1803 return "The map you suggested does not support the current game mode.";
1805 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1806 return "The map you suggested is not available on this server.";
1808 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1809 if(mapvote_suggestions[i] == m)
1810 return "This map was already suggested.";
1811 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1813 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1817 i = mapvote_suggestion_ptr;
1818 mapvote_suggestion_ptr += 1;
1820 if(mapvote_suggestions[i] != "")
1821 strunzone(mapvote_suggestions[i]);
1822 mapvote_suggestions[i] = strzone(m);
1823 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid), ":", self.netname), TRUE);
1824 return strcat("Suggestion of ", m, " accepted.");
1827 void MapVote_AddVotable(string nextMap, float isSuggestion)
1832 for(j = 0; j < mapvote_count; ++j)
1833 if(mapvote_maps[j] == nextMap)
1835 if(strlen(nextMap) > mapvote_maxlen)
1836 mapvote_maxlen = strlen(nextMap);
1837 mapvote_maps[mapvote_count] = strzone(nextMap);
1838 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1847 MapVote_ClearAllVotes();
1850 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1851 mapvote_abstain = cvar("g_maplist_votable_abstain");
1854 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1856 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1857 smax = min(nmax, cvar("g_maplist_votable_suggestions"));
1859 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1860 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1862 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1863 MapVote_AddVotable(GetNextMap(), FALSE);
1865 if(mapvote_count == 0)
1867 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1869 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1870 localcmd("\nmenu_cmd sync\n");
1872 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1874 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1875 MapVote_AddVotable(GetNextMap(), FALSE);
1878 mapvote_count_real = mapvote_count;
1880 MapVote_AddVotable("don't care", 0);
1882 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1884 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1885 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1886 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1887 mapvote_keeptwotime = 0;
1888 mapvote_message = "Choose a map and press its key!";
1890 float MapVote_Finished(float mappos)
1896 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1897 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1898 didntvote = mapvote_voters;
1899 for(i = 0; i < mapvote_count; ++i)
1900 if(mapvote_maps[i] != "")
1902 didntvote -= mapvote_votes[i];
1905 result = strcat(result, ":", mapvote_maps[i]);
1906 result = strcat(result, ":", ftos(mapvote_votes[i]));
1909 result = strcat(result, ":didn't vote:", ftos(didntvote));
1911 GameLogEcho(result, FALSE);
1912 if(mapvote_maps_suggested[mappos])
1913 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
1915 FOR_EACH_REALCLIENT(other)
1916 FixClientCvars(other);
1918 Map_Goto_SetStr(mapvote_maps[mappos]);
1920 alreadychangedlevel = TRUE;
1923 void MapVote_CheckRules_1()
1927 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1929 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1930 mapvote_votes[i] = 0;
1934 FOR_EACH_REALCLIENT(other)
1939 i = other.mapvote - 1;
1940 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1941 mapvote_votes[i] = mapvote_votes[i] + 1;
1946 float MapVote_CheckRules_2()
1949 float firstPlace, secondPlace;
1950 float firstPlaceVotes, secondPlaceVotes;
1951 float mapvote_voters_real;
1954 mapvote_voters_real = mapvote_voters;
1956 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
1959 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1960 RandSel_Add(mapvote_votes[i], i);
1961 firstPlace = randsel_value;
1962 firstPlaceVotes = randsel_priority;
1963 //dprint("First place: ", ftos(firstPlace), "\n");
1964 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1967 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1969 RandSel_Add(mapvote_votes[i], i);
1970 secondPlace = randsel_value;
1971 secondPlaceVotes = randsel_priority;
1972 //dprint("Second place: ", ftos(secondPlace), "\n");
1973 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1975 if(firstPlace == -1)
1976 error("No first place in map vote... WTF?");
1978 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
1979 return MapVote_Finished(firstPlace);
1981 if(mapvote_keeptwotime)
1982 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
1985 mapvote_message = "Now decide between the TOP TWO!";
1986 mapvote_keeptwotime = 0;
1987 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
1988 result = strcat(result, ":", ftos(firstPlaceVotes));
1989 result = strcat(result, ":", mapvote_maps[secondPlace]);
1990 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
1991 didntvote = mapvote_voters;
1992 for(i = 0; i < mapvote_count; ++i)
1993 if(mapvote_maps[i] != "")
1995 didntvote -= mapvote_votes[i];
1997 if(i != secondPlace)
1999 result = strcat(result, ":", mapvote_maps[i]);
2000 result = strcat(result, ":", ftos(mapvote_votes[i]));
2001 if(i < mapvote_count_real)
2003 strunzone(mapvote_maps[i]);
2004 mapvote_maps[i] = "";
2008 result = strcat(result, ":didn't vote:", ftos(didntvote));
2009 GameLogEcho(result, FALSE);
2022 keeptwo = mapvote_keeptwotime;
2023 MapVote_CheckRules_1(); // count
2024 if(MapVote_CheckRules_2()) // decide
2028 FOR_EACH_REALCLIENT(other)
2030 // hide scoreboard again
2031 if(other.health != 2342)
2033 other.health = 2342;
2035 if(clienttype(other) == CLIENTTYPE_REAL)
2037 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");
2039 WriteByte(MSG_ONE, SVC_FINALE);
2040 WriteString(MSG_ONE, "");
2044 // notify about keep-two
2045 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2046 play2(other, "misc/invshot.wav");
2048 // clear possibly invalid votes
2049 if(mapvote_maps[other.mapvote - 1] == "")
2051 // use impulses as new vote
2052 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2053 if(mapvote_maps[other.impulse - 1] != "")
2054 other.mapvote = other.impulse;
2061 MapVote_CheckRules_1(); // just count
2063 FOR_EACH_REALCLIENT(other)
2065 // display voting screen
2066 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2067 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2069 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2070 msgstr = strcat(msgstr, mapvote_message);
2071 msgstr = strcat(msgstr, "\n\n");
2072 for(i = 0; i < mapvote_count; ++i)
2073 if(mapvote_maps[i] == "")
2074 msgstr = strcat(msgstr, "\n");
2077 tmp = mapvote_maps[i];
2078 tmp = strpad(mapvote_maxlen, tmp);
2079 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2082 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2083 if(mapvote_votes[i] != 1)
2084 tmp = strcat(tmp, "s");
2085 tmp = strcat(tmp, ")");
2086 tmp = strpad(mapvote_maxlen + 15, tmp);
2089 if(i == mapvote_count - 1)
2090 msgstr = strcat(msgstr, "\n");
2091 if(other.mapvote == i + 1)
2092 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2094 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2097 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2099 msgstr = strcat(msgstr, "s");
2100 msgstr = strcat(msgstr, " cast");
2101 i = ceil(mapvote_timeout - time);
2102 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2104 msgstr = strcat(msgstr, "s");
2105 msgstr = strcat(msgstr, " left");
2107 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2110 void MapVote_Start()
2116 MapInfo_Enumerate();
2117 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2121 void MapVote_Think()
2126 if(alreadychangedlevel)
2129 if(time < mapvote_nextthink)
2133 mapvote_nextthink = time + 0.5;
2135 if(!mapvote_initialized)
2137 mapvote_initialized = TRUE;
2138 if(DoNextMapOverride())
2140 if(!cvar("g_maplist_votable") || player_count <= 0)
2151 string GotoMap(string m)
2154 if(!MapInfo_CheckMap(m))
2156 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2158 return "The map you chose is not available on this server.";
2159 cvar_set("nextmap", m);
2160 cvar_set("timelimit", "-1");
2161 if(mapvote_initialized || alreadychangedlevel)
2163 if(DoNextMapOverride())
2164 return "Map switch initiated.";
2166 return "Hm... no. For some reason I like THIS map more.";
2169 return "Map switch will happen after scoreboard.";
2175 FOR_EACH_REALCLIENT(self)
2177 if(self.classname == "spectator")
2179 if(self.enemy.hitsound)
2180 play2(self, "misc/hit.wav");
2185 play2(self, "misc/hit.wav");
2188 FOR_EACH_CLIENT(self)
2189 self.hitsound = FALSE;
2195 * returns TRUE if redirecting
2197 float redirection_timeout;
2198 float redirection_nextthink;
2199 float RedirectionThink()
2201 float clients_found;
2203 if(redirection_target == "")
2206 if(!redirection_timeout)
2208 cvar_set("sv_public", "-2");
2209 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2210 if(redirection_target == "self")
2211 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2213 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2216 if(time < redirection_nextthink)
2219 redirection_nextthink = time + 1;
2222 FOR_EACH_REALCLIENT(self)
2224 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2225 if(redirection_target == "self")
2226 stuffcmd(self, "\ndisconnect; reconnect\n");
2228 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2232 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2234 if(time > redirection_timeout || clients_found == 0)
2235 localcmd("\nwait; wait; wait; quit\n");
2242 if(world_initialized)
2244 world_initialized = 0;
2245 print("Saving persistent data...\n");
2248 db_save(ServerProgsDB, "server.db");
2250 // tell the bot system the game is ending now
2255 print("NOTE: crashed before even initializing the world, not saving persistent data\n");