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 //if tourney is used map starts in warmup mode. if this mode shall stay unlimited, reset timelimit, but save the original one
249 if(g_tourney && cvar("g_tourney_warmup_unlimited_time")) {
250 timelimit_orig = cvar("timelimit");
251 cvar_set("timelimit", "0");
254 world_initialized = 1;
259 //makestatic (self); // Who the f___ did that?
263 float( string pFilename ) TryFile =
266 dprint("TryFile(\"", pFilename, "\")\n");
267 lHandle = fopen( pFilename, FILE_READ );
268 if( lHandle != -1 ) {
278 if (game == GAME_DEATHMATCH)
280 else if (game == GAME_TEAM_DEATHMATCH)
282 else if (game == GAME_DOMINATION)
284 else if (game == GAME_CTF)
286 else if (game == GAME_RUNEMATCH)
288 else if (game == GAME_LMS)
290 else if (game == GAME_KEYHUNT)
292 else if (game == GAME_ONSLAUGHT)
294 else if (game == GAME_ASSAULT)
299 float IsSameGametype(string mapcfgname)
302 return TRUE; // can't change game type by map name here
306 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
312 string getmapname_stored;
318 if(getmapname_stored == "")
319 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
320 return getmapname_stored;
324 float Map_Count, Map_Current;
325 string Map_Current_Name;
327 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
328 float GetMaplistPosition()
334 idx = cvar("g_maplist_index");
341 for(pos = 0; pos < Map_Count; ++pos)
345 // resume normal maplist rotation if current map is not in g_maplist
349 float MapHasRightSize(string map)
352 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
353 if(cvar("g_maplist_check_waypoints"))
355 dprint("checkwp "); dprint(map);
356 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
359 dprint(": no waypoints\n");
362 dprint(": has waypoints\n");
366 // open map size restriction file
367 dprint("opensize "); dprint(map);
368 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
371 float mapmin, mapmax;
373 mapmin = stof(fgets(fh));
374 mapmax = stof(fgets(fh));
376 if(player_count < mapmin)
378 dprint("not enough\n");
381 if(player_count > mapmax)
383 dprint("too many\n");
386 dprint("right size\n");
389 dprint(": not found\n");
393 string Map_Filename(float position)
396 return strcat("maps/", argv(position), ".bsp");
398 return strcat("maps/", argv(position), ".mapcfg");
402 string strwords(string s, float w)
405 for(endpos = 0; w && endpos >= 0; --w)
406 endpos = strstrofs(s, " ", endpos + 1);
410 return substring(s, 0, endpos);
413 float strhasword(string s, string w)
415 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
418 void Map_MarkAsRecent(string m)
420 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
423 float Map_IsRecent(string m)
425 return strhasword(cvar_string("g_maplist_mostrecent"), m);
428 float(float position, float pass) Map_Check =
432 map_next = argv(position);
435 if(map_next == Map_Current_Name) // same map again in first pass?
437 if(Map_IsRecent(map_next))
440 filename = Map_Filename(position);
442 if(MapInfo_CheckMap(map_next))
444 if(TryFile(filename))
449 if(MapHasRightSize(map_next))
454 dprint( "Couldn't select '", filename, "'..\n" );
459 void(string nextmapname) Map_Goto_SetStr =
461 if(getmapname_stored != "")
462 strunzone(getmapname_stored);
463 if(nextmapname == "")
464 getmapname_stored = "";
466 getmapname_stored = strzone(nextmapname);
469 void(float position) Map_Goto_SetFloat =
471 cvar_set("g_maplist_index", ftos(position));
472 Map_Goto_SetStr(argv(position));
475 void() GameResetCfg =
478 // settings persist, except...
479 if(cvar("g_campaign"))
480 localcmd("\nexec mutator_reset.cfg\n");
481 localcmd("\nsettemp_restore\n");
483 // if an exit cfg is defined by exiting map, exec it.
485 exit_cfg = cvar_string("exit_cfg");
487 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
489 localcmd("exec game_reset.cfg\n");
495 Map_MarkAsRecent(getmapname_stored);
498 MapInfo_LoadMap(getmapname_stored);
500 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
504 // return codes of map selectors:
505 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
506 // -2 = permanent failure
507 float() MaplistMethod_Iterate = // usual method
511 for(pass = 1; pass <= 2; ++pass)
513 for(i = 1; i < Map_Count; ++i)
516 mapindex = mod(i + Map_Current, Map_Count);
517 if(Map_Check(mapindex, pass))
524 float() MaplistMethod_Repeat = // fallback method
526 if(Map_Check(Map_Current, 2))
531 float() MaplistMethod_Random = // random map selection
537 for(i = 0; i <= imax; ++i)
540 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
541 if(Map_Check(mapindex, 1))
547 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
548 // the exponent sets a bias on the map selection:
549 // the higher the exponent, the less likely "shortly repeated" same maps are
551 float i, j, imax, insertpos;
555 for(i = 0; i <= imax; ++i)
559 // now reinsert this at another position
560 insertpos = pow(random(), 1 / exponent); // ]0, 1]
561 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
562 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
563 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
565 // insert the current map there
568 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
569 newlist = strcat(newlist, " ", argv(j));
570 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
571 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
572 newlist = strcat(newlist, " ", argv(j));
573 newlist = substring(newlist, 1, strlen(newlist) - 1);
575 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
576 newlist = strcat(newlist, "'", argv(j), "'");
577 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
578 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
579 newlist = strcat(newlist, "'", argv(j), "'");
581 cvar_set("g_maplist", newlist);
583 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
585 Map_Count = tokenize(newlist);
588 // NOTE: the selected map has just been inserted at (insertpos-1)th position
589 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
590 if(Map_Check(Map_Current, 1))
596 void() Maplist_Init =
599 temp = cvar_string("g_maplist");
601 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
603 Map_Count = tokenize(temp);
607 bprint( "Maplist is empty! Resetting it to default map list.\n" );
609 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
610 localcmd("\nmenu_cmd sync\n");
611 Map_Count = tokenizebyseparator(temp, " ");
613 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
614 Map_Count = tokenize(temp);
618 error("empty maplist, cannot select a new map");
619 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
621 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
622 // this may or may not be correct, but who cares, in the worst case a map
623 // isn't chosen in the first pass that should have been
626 string() GetNextMap =
634 if(cvar("g_maplist_shuffle") > 0)
635 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
638 if(cvar("g_maplist_selectrandom"))
639 nextMap = MaplistMethod_Random();
642 nextMap = MaplistMethod_Iterate();
645 nextMap = MaplistMethod_Repeat();
649 Map_Goto_SetFloat(nextMap);
650 return getmapname_stored;
656 float() DoNextMapOverride =
658 if(cvar("g_campaign"))
660 CampaignPostIntermission();
661 alreadychangedlevel = TRUE;
664 if(cvar("quit_when_empty"))
666 if(player_count <= currentbots)
669 alreadychangedlevel = TRUE;
673 if(cvar_string("quit_and_redirect") != "")
675 redirection_target = strzone(cvar_string("quit_and_redirect"));
676 alreadychangedlevel = TRUE;
679 if (cvar("samelevel")) // if samelevel is set, stay on same level
681 // 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)
682 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
683 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
684 localcmd("restart\n");
685 //changelevel (mapname);
686 alreadychangedlevel = TRUE;
689 if(cvar_string("nextmap") != "")
691 if(MapInfo_CheckMap(cvar_string("nextmap")))
693 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
696 Map_Goto_SetStr(cvar_string("nextmap"));
698 alreadychangedlevel = TRUE;
701 if(cvar("lastlevel"))
704 localcmd("set lastlevel 0\ntogglemenu\n");
705 alreadychangedlevel = TRUE;
713 //local string nextmap;
714 //local float n, nummaps;
716 if (alreadychangedlevel)
718 alreadychangedlevel = TRUE;
724 for(allowReset = 1; allowReset >= 0; --allowReset)
726 nextMap = GetNextMap();
732 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
734 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
735 localcmd("\nmenu_cmd sync\n");
737 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
742 error("Everything is broken - not even the default map list works. Please report this to the developers.");
754 When the player presses attack or jump, change to the next level
757 .float autoscreenshot;
758 void() MapVote_Start;
759 void() MapVote_Think;
760 float mapvote_initialized;
761 void() IntermissionThink =
763 FixIntermissionClient(self);
765 if(cvar("sv_autoscreenshot"))
766 if(self.autoscreenshot > 0)
767 if(time > self.autoscreenshot)
769 self.autoscreenshot = -1;
770 if(clienttype(self) == CLIENTTYPE_REAL)
771 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
775 if (time < intermission_exittime)
778 if(!mapvote_initialized)
779 if (time < intermission_exittime + 10 && !self.button0 && !self.button2 && !self.button3 && !self.button6 && !self.buttonuse)
789 Returns the entity to view from
793 entity() FindIntermission =
798 // look for info_intermission first
799 spot = find (world, classname, "info_intermission");
801 { // pick a random one
805 spot = find (spot, classname, "info_intermission");
807 spot = find (spot, classname, "info_intermission");
813 // then look for the start position
814 spot = find (world, classname, "info_player_start");
818 // testinfo_player_start is only found in regioned levels
819 spot = find (world, classname, "testplayerstart");
823 // then look for the start position
824 spot = find (world, classname, "info_player_deathmatch");
828 //objerror ("FindIntermission: no spot");
834 ===============================================================================
838 ===============================================================================
841 void(float final) DumpStats =
845 local float to_console;
846 local float to_eventlog;
849 to_console = cvar("sv_logscores_console");
850 to_eventlog = cvar("sv_eventlog");
851 to_file = cvar("sv_logscores_file");
855 to_console = TRUE; // always print printstats replies
856 to_eventlog = FALSE; // but never print them to the event log
860 if(cvar("sv_eventlog_console"))
861 to_console = FALSE; // otherwise we get the output twice
868 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
870 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
874 ServerConsoleEcho(s, FALSE);
876 GameLogEcho(s, FALSE);
879 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
883 fputs(file, strcat(s, "\n"));
886 FOR_EACH_CLIENT(other)
888 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
890 s = strcat(":player:", ftos(other.frags), ":");
891 s = strcat(s, ftos(other.deaths), ":");
892 s = strcat(s, ftos(rint(time - other.jointime)), ":");
893 s = strcat(s, ftos(other.team), ":");
896 ServerConsoleEcho(strcat(s, other.netname), TRUE);
898 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
900 fputs(file, strcat(s, other.netname, "\n"));
905 ServerConsoleEcho(":end", FALSE);
907 GameLogEcho(":end", FALSE);
910 fputs(file, ":end\n");
915 void FixIntermissionClient(entity e)
917 if(!e.autoscreenshot) // initial call
919 e.angles = e.v_angle;
920 e.angles_x = -e.angles_x;
921 e.autoscreenshot = time + 0.8; // used for autoscreenshot
923 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
925 e.movetype = MOVETYPE_NONE;
926 e.takedamage = DAMAGE_NO;
928 e.weaponentity.effects = EF_NODRAW;
929 stuffcmd(e, "\nscr_printspeed 1000000\n");
930 if(clienttype(e) == CLIENTTYPE_REAL)
933 WriteByte(MSG_ONE, SVC_INTERMISSION);
937 //e.velocity = '0 0 0';
940 // TODO halt weapon animation
945 go to the next level for deathmatch
946 only called if a time or frag limit has expired
957 intermission_running = 1;
959 // enforce a wait time before allowing changelevel
961 intermission_exittime = time + cvar("sv_mapchange_delay");
963 intermission_exittime = -1;
965 WriteByte (MSG_ALL, SVC_CDTRACK);
966 WriteByte (MSG_ALL, 3);
967 WriteByte (MSG_ALL, 3);
969 //pos = FindIntermission ();
975 if(cvar("sv_eventlog"))
976 GameLogEcho(":gameover", FALSE);
980 FOR_EACH_CLIENT(other)
982 FixIntermissionClient(other);
985 bprint(other.netname, " ^7wins.\n");
990 FOR_EACH_PLAYER(other)
992 if(maxTotalFrags < other.totalfrags)
993 maxTotalFrags = other.totalfrags;
994 if(minTotalFrags > other.totalfrags)
995 minTotalFrags = other.totalfrags;
1000 FOR_EACH_PLAYER(other)
1002 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1003 f = bound(0, other.play_time / max(time, 1), 1);
1004 // store some statistics?
1008 if(cvar("g_campaign"))
1009 CampaignPreIntermission();
1011 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1018 Exit deathmatch games upon conditions
1021 void() CheckRules_Player =
1023 if (gameover) // someone else quit the game already
1026 if(self.deadflag == DEAD_NO)
1027 self.play_time += frametime;
1029 // fixme: don't check players; instead check dom_team and ctf_team entities
1030 // (div0: and that in CheckRules_World please)
1033 float checkrules_oneminutewarning;
1034 float checkrules_leaderfrags;
1035 float tdm_max_score, tdm_old_score;
1037 float checkrules_equality;
1038 float checkrules_overtimewarning;
1039 float checkrules_overtimeend;
1041 void() InitiateOvertime =
1043 if(!checkrules_overtimeend)
1044 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1047 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1048 float WINNING_YES = 1; // winner found
1049 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1050 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1052 float(float fraglimitreached, float equality) GetWinningCode =
1055 if(fraglimitreached)
1056 return WINNING_STARTOVERTIME;
1058 return WINNING_NEVER;
1060 if(fraglimitreached)
1066 // set the .winning flag for exactly those players with a given field value
1067 void(.float field, float value) SetWinners =
1070 FOR_EACH_PLAYER(head)
1071 head.winning = (head.field == value);
1074 // set the .winning flag for those players with a given field value
1075 void(.float field, float value) AddWinners =
1078 FOR_EACH_PLAYER(head)
1079 if(head.field == value)
1083 // clear frags for all players but the team given (when they ran out of spawnpoints)
1084 void(.float field, float value) ClearFragsForEveryoneBut =
1087 FOR_EACH_PLAYER(head)
1088 if(head.field != value)
1089 head.frags = max(head.frags, 0);
1092 // clear the .winning flags
1093 void(void) ClearWinners =
1096 FOR_EACH_PLAYER(head)
1100 // Onslaught winning condition:
1101 // game terminates if only one team has a working generator (or none)
1102 float() WinningCondition_Onslaught =
1105 local float t1, t2, t3, t4;
1106 // first check if the game has ended
1107 t1 = t2 = t3 = t4 = 0;
1108 head = find(world, classname, "onslaught_generator");
1111 if (head.health > 0)
1113 if (head.team == COLOR_TEAM1) t1 = 1;
1114 if (head.team == COLOR_TEAM2) t2 = 1;
1115 if (head.team == COLOR_TEAM3) t3 = 1;
1116 if (head.team == COLOR_TEAM4) t4 = 1;
1118 head = find(head, classname, "onslaught_generator");
1120 if (t1 + t2 + t3 + t4 < 2)
1122 // game over, only one team remains (or none)
1124 if (t1) SetWinners(team, COLOR_TEAM1);
1125 if (t2) SetWinners(team, COLOR_TEAM2);
1126 if (t3) SetWinners(team, COLOR_TEAM3);
1127 if (t4) SetWinners(team, COLOR_TEAM4);
1128 dprint("Have a winner, ending game.\n");
1132 // Two or more teams remain
1136 float() LMS_NewPlayerLives =
1139 fl = cvar("fraglimit");
1143 // first player has left the game for dying too much? Nobody else can get in.
1144 if(lms_lowest_lives < 1)
1147 if(!cvar("g_lms_join_anytime"))
1148 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1151 return bound(1, lms_lowest_lives, fl);
1154 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1155 // they win. Otherwise the defending team wins once the timelimit passes.
1156 void assault_new_round();
1157 float() WinningCondition_Assault =
1160 status = WINNING_NO;
1162 // as the timelimit has not yet passed just assume the defending team will win
1163 if(assault_attacker_team == COLOR_TEAM1)
1165 SetWinners(team, COLOR_TEAM2);
1169 SetWinners(team, COLOR_TEAM1);
1173 ent = find(world, classname, "target_assault_roundend");
1176 if(ent.winning) // round end has been triggered by attacking team
1178 SetWinners(team, assault_attacker_team);
1179 if(assault_attacker_team == COLOR_TEAM1)
1181 team1_score = team1_score + 50;
1185 team2_score = team2_score + 50;
1188 if(ent.cnt == 1) // this was the second round
1190 status = WINNING_YES;
1194 cvar_set("timelimit", ftos((2*time)/60));
1195 assault_new_round();
1205 // LMS winning condition: game terminates if and only if there's at most one
1206 // one player who's living lives. Top two scores being equal cancels the time
1208 float() WinningCondition_LMS =
1215 have_player = FALSE;
1216 have_players = FALSE;
1217 l = LMS_NewPlayerLives();
1219 head = find(world, classname, "player");
1222 head = find(head, classname, "player");
1224 have_players = TRUE;
1228 // we have at least one player
1231 // two or more active players - continue with the game
1235 // exactly one player?
1238 // but no game has taken place yet
1243 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1244 dprint("Have a winner, ending game.\n");
1251 // nobody is playing at all...
1254 // wait for players...
1258 // SNAFU (maybe a draw game?)
1260 dprint("No players, ending game.\n");
1265 // When we get here, we have at least two players who are actually LIVING,
1266 // or one player who is still waiting for a victim to join the server. Now
1267 // check if the top two players have equal score.
1269 checkrules_leaderfrags = 0;
1270 checkrules_equality = FALSE;
1271 FOR_EACH_PLAYER(head)
1273 if(head.frags > checkrules_leaderfrags)
1275 checkrules_leaderfrags = head.frags;
1276 checkrules_equality = FALSE;
1278 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1279 checkrules_equality = TRUE;
1282 SetWinners(frags, checkrules_leaderfrags);
1284 // The top two players have the same amount of lives? No timelimit then,
1285 // enter overtime...
1287 if(checkrules_equality)
1288 return WINNING_NEVER;
1290 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1294 // DM winning condition: game terminates if a player reached the fraglimit,
1295 // unless the first two players have the same score. The latter case also
1296 // breaks the time limit.
1297 float(float fraglimit) WinningCondition_MaxIndividualScore =
1299 float checkrules_oldleaderfrags;
1302 checkrules_oldleaderfrags = checkrules_leaderfrags;
1303 checkrules_leaderfrags = 0;
1304 checkrules_equality = FALSE;
1305 FOR_EACH_PLAYER(head)
1307 if(head.frags > checkrules_leaderfrags)
1309 checkrules_leaderfrags = head.frags;
1310 checkrules_equality = FALSE;
1312 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1313 checkrules_equality = TRUE;
1316 if(checkrules_leaderfrags > 0)
1317 SetWinners(frags, checkrules_leaderfrags);
1322 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1324 if (checkrules_leaderfrags == fraglimit - 1)
1325 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1326 else if (checkrules_leaderfrags == fraglimit - 2)
1327 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1328 else if (checkrules_leaderfrags == fraglimit - 3)
1329 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1332 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1335 float(float fraglimit) WinningConditionBase_Teamplay =
1337 tdm_old_score = tdm_max_score;
1338 tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1340 checkrules_equality =
1345 (team1_score == tdm_max_score)
1346 + (team2_score == tdm_max_score)
1347 + (team3_score == tdm_max_score)
1348 + (team4_score == tdm_max_score)
1352 if(tdm_max_score > 0)
1354 if(team1_score == tdm_max_score)
1355 AddWinners(team, COLOR_TEAM1);
1356 if(team2_score == tdm_max_score)
1357 AddWinners(team, COLOR_TEAM2);
1358 if(team3_score == tdm_max_score)
1359 AddWinners(team, COLOR_TEAM3);
1360 if(team4_score == tdm_max_score)
1361 AddWinners(team, COLOR_TEAM4);
1364 if(!g_runematch && !g_domination)
1365 if(tdm_max_score != tdm_old_score)
1367 if(tdm_max_score == fraglimit - 1)
1368 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1369 else if(tdm_max_score == fraglimit - 2)
1370 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1371 else if(tdm_max_score == fraglimit - 3)
1372 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1375 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1378 // TDM winning condition: game terminates if a team's score sum reached the
1379 // fraglimit, unless the first two teams have the same total score. The latter
1380 // case also breaks the time limit.
1381 float(float fraglimit) WinningCondition_MaxTeamSum =
1385 team1_score = team2_score = team3_score = team4_score = 0;
1387 FOR_EACH_PLAYER(head)
1389 if(head.team == COLOR_TEAM1)
1390 team1_score += head.frags;
1391 else if(head.team == COLOR_TEAM2)
1392 team2_score += head.frags;
1393 else if(head.team == COLOR_TEAM3)
1394 team3_score += head.frags;
1395 else if(head.team == COLOR_TEAM4)
1396 team4_score += head.frags;
1399 return WinningConditionBase_Teamplay(fraglimit);
1402 // DOM/CTF winning condition: game terminates if the max of a team's players'
1403 // score reached the fraglimit, unless the first two teams have the same
1404 // maximum score. The latter case also breaks the time limit.
1405 float(float fraglimit) WinningCondition_MaxTeamMax =
1409 team1_score = team2_score = team3_score = team4_score = 0;
1411 FOR_EACH_PLAYER(head)
1413 if(head.team == COLOR_TEAM1)
1415 if(head.frags > team1_score)
1416 team1_score = head.frags;
1418 else if(head.team == COLOR_TEAM2)
1420 if(head.frags > team2_score)
1421 team2_score = head.frags;
1423 else if(head.team == COLOR_TEAM3)
1425 if(head.frags > team3_score)
1426 team3_score = head.frags;
1428 else if(head.team == COLOR_TEAM4)
1430 if(head.frags > team4_score)
1431 team4_score = head.frags;
1435 return WinningConditionBase_Teamplay(fraglimit);
1438 void print_to(entity e, string s)
1441 sprint(e, strcat(s, "\n"));
1443 ServerConsoleEcho(s, TRUE);
1446 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1456 FOR_EACH_PLAYER(head)
1458 if(!whichteam || head.team == whichteam)
1462 print_to(e, strcat(" ", colorcode, name, ":"));
1464 fragtotal = fragtotal + head.frags;
1465 s = ftos(head.frags);
1466 s = strcat(s, "/", ftos(head.deaths));
1467 s = strcat(s, " @ ", ftos(head.ping));
1468 if(clienttype(head) == CLIENTTYPE_BOT)
1469 s = strcat(s, "botms");
1471 s = strcat(s, "ms");
1472 v = PlayerValue(head);
1474 s = strcat(s, " / ", ftos(v));
1475 print_to(e, strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"));
1478 if(whichteam && found)
1480 s = ftos(fragtotal);
1481 s = strcat(s, " / ", ftos(teamvalue));
1482 print_to(e, strcat(colorcode, " (total: ", s, ")"));
1486 void PrintScoreboard(entity e)
1488 print_to(e, strcat("Time: ", ftos(time / 60)));
1489 print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1490 print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1491 print_to(e, "Scoreboard:");
1494 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1495 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1496 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM3);
1497 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM4);
1501 PrintScoreboardFor(e, "", "^7", 0);
1506 void ShuffleMaplist()
1514 result = cvar_string("g_maplist");
1516 litems = tokenizebyseparator(result, " ");
1518 litems = tokenize(result);
1521 for(start = 0; start < litems - 1; ++start)
1525 // select a random item
1526 selected = ceil(random() * (litems - start) + start) - 1;
1528 // shift this item to the place start
1530 for(i = 0; i < start; ++i)
1531 result = strcat(result, " ", argv(i));
1532 result = strcat(result, " ", argv(selected));
1533 for(i = start; i < litems; ++i)
1535 result = strcat(result, " ", argv(i));
1536 result = substring(result, 1, strlen(result) - 1);
1538 litems = tokenizebyseparator(result, " ");
1540 for(i = 0; i < start; ++i)
1541 result = strcat(result, "'", argv(i), "'");
1542 result = strcat(result, "'", argv(selected), "'");
1543 for(i = start; i < litems; ++i)
1545 result = strcat(result, "'", argv(i), "'");
1547 litems = tokenize(result);
1550 //dprint(result, "\n");
1553 cvar_set("g_maplist", result);
1556 float WinningCondition_RanOutOfSpawns()
1560 if(!have_team_spawns)
1563 if(!some_spawn_has_been_used)
1566 team1_score = team2_score = team3_score = team4_score = 0;
1568 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1570 if(head.team == COLOR_TEAM1)
1572 else if(head.team == COLOR_TEAM2)
1574 else if(head.team == COLOR_TEAM3)
1576 else if(head.team == COLOR_TEAM4)
1580 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1582 if(head.team == COLOR_TEAM1)
1584 else if(head.team == COLOR_TEAM2)
1586 else if(head.team == COLOR_TEAM3)
1588 else if(head.team == COLOR_TEAM4)
1593 if(team1_score + team2_score + team3_score + team4_score == 0)
1595 checkrules_equality = TRUE;
1598 else if(team1_score + team2_score + team3_score + team4_score == 1)
1602 AddWinners(team, COLOR_TEAM1);
1603 ClearFragsForEveryoneBut(team, COLOR_TEAM1);
1607 AddWinners(team, COLOR_TEAM2);
1608 ClearFragsForEveryoneBut(team, COLOR_TEAM2);
1612 AddWinners(team, COLOR_TEAM3);
1613 ClearFragsForEveryoneBut(team, COLOR_TEAM3);
1617 AddWinners(team, COLOR_TEAM4);
1618 ClearFragsForEveryoneBut(team, COLOR_TEAM4);
1630 Exit deathmatch games upon conditions
1633 void() CheckRules_World =
1636 local float timelimit;
1637 local float fraglimit;
1645 MapVote_Think should now do that part
1646 if (intermission_running)
1647 if (time >= intermission_exittime + 60)
1649 if(!DoNextMapOverride())
1655 if (gameover) // someone else quit the game already
1657 if(player_count == 0) // Nobody there? Then let's go to the next map
1659 // this will actually check the player count in the next frame
1660 // again, but this shouldn't hurt
1664 timelimit = cvar("timelimit") * 60;
1665 fraglimit = cvar("fraglimit");
1667 if(checkrules_overtimeend)
1669 if(!checkrules_overtimewarning)
1671 checkrules_overtimewarning = TRUE;
1672 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1673 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1678 if (timelimit && time >= timelimit)
1682 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1688 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1690 checkrules_oneminutewarning = TRUE;
1691 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1694 status = WinningCondition_RanOutOfSpawns();
1695 if(status == WINNING_YES)
1697 bprint("Hey! Someone ran out of spawns!\n");
1701 status = WinningCondition_Assault();
1705 status = WinningCondition_LMS();
1707 else if (g_onslaught)
1709 status = WinningCondition_Onslaught();
1715 if(g_tdm || g_runematch || g_ctf || g_domination || g_keyhunt)
1716 status = WinningCondition_MaxTeamSum(fraglimit);
1718 // status = WinningCondition_MaxTeamMax(fraglimit);
1721 dprint("div0: How can this happen?\n");
1722 status = WinningCondition_MaxTeamMax(fraglimit);
1726 status = WinningCondition_MaxIndividualScore(fraglimit);
1729 if(status == WINNING_STARTOVERTIME)
1731 status = WINNING_NEVER;
1735 if(status == WINNING_NEVER)
1736 // equality cases! Nobody wins if the overtime ends in a draw.
1739 if(checkrules_overtimeend)
1740 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1741 status = WINNING_YES;
1743 if(status == WINNING_YES)
1747 float randsel_value;
1748 float randsel_priority;
1749 float randsel_count;
1753 randsel_priority = -1;
1756 void RandSel_Add(float priority, float value)
1758 if(priority > randsel_priority)
1760 randsel_priority = priority;
1761 randsel_value = value;
1764 else if(priority == randsel_priority)
1767 if(ceil(random() * randsel_count) == 1)
1768 randsel_value = value;
1772 float mapvote_nextthink;
1773 float mapvote_initialized;
1774 float mapvote_keeptwotime;
1775 float mapvote_timeout;
1776 string mapvote_message;
1778 #define MAPVOTE_COUNT 10
1779 float mapvote_count;
1780 float mapvote_count_real;
1781 string mapvote_maps[MAPVOTE_COUNT];
1782 float mapvote_maps_suggested[MAPVOTE_COUNT];
1783 string mapvote_suggestions[MAPVOTE_COUNT];
1784 float mapvote_suggestion_ptr;
1785 float mapvote_maxlen;
1786 float mapvote_voters;
1787 float mapvote_votes[MAPVOTE_COUNT];
1789 float mapvote_detail;
1790 float mapvote_abstain;
1793 void MapVote_ClearAllVotes()
1795 FOR_EACH_CLIENT(other)
1799 string MapVote_Suggest(string m)
1803 return "That's not how to use this command.";
1804 if(!cvar("g_maplist_votable_suggestions"))
1805 return "Suggestions are not accepted on this server.";
1806 if(mapvote_initialized)
1807 return "Can't suggest - voting is already in progress!";
1809 m = MapInfo_FixName(m);
1811 return "The map you suggested is not available on this server.";
1813 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1814 if(!IsSameGametype(m))
1815 return "This server does not allow changing the game type by map suggestions.";
1817 if(!cvar("g_maplist_votable_override_mostrecent"))
1819 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1822 if(!MapInfo_CheckMap(m))
1823 return "The map you suggested does not support the current game mode.";
1825 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1826 return "The map you suggested is not available on this server.";
1828 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1829 if(mapvote_suggestions[i] == m)
1830 return "This map was already suggested.";
1831 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1833 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1837 i = mapvote_suggestion_ptr;
1838 mapvote_suggestion_ptr += 1;
1840 if(mapvote_suggestions[i] != "")
1841 strunzone(mapvote_suggestions[i]);
1842 mapvote_suggestions[i] = strzone(m);
1843 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid), ":", self.netname), TRUE);
1844 return strcat("Suggestion of ", m, " accepted.");
1847 void MapVote_AddVotable(string nextMap, float isSuggestion)
1852 for(j = 0; j < mapvote_count; ++j)
1853 if(mapvote_maps[j] == nextMap)
1855 if(strlen(nextMap) > mapvote_maxlen)
1856 mapvote_maxlen = strlen(nextMap);
1857 mapvote_maps[mapvote_count] = strzone(nextMap);
1858 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1867 MapVote_ClearAllVotes();
1870 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1871 mapvote_abstain = cvar("g_maplist_votable_abstain");
1874 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1876 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1877 smax = min(nmax, cvar("g_maplist_votable_suggestions"));
1879 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1880 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1882 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1883 MapVote_AddVotable(GetNextMap(), FALSE);
1885 if(mapvote_count == 0)
1887 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1889 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1890 localcmd("\nmenu_cmd sync\n");
1892 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1894 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1895 MapVote_AddVotable(GetNextMap(), FALSE);
1898 mapvote_count_real = mapvote_count;
1900 MapVote_AddVotable("don't care", 0);
1902 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1904 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1905 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1906 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1907 mapvote_keeptwotime = 0;
1908 mapvote_message = "Choose a map and press its key!";
1910 float MapVote_Finished(float mappos)
1916 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1917 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1918 didntvote = mapvote_voters;
1919 for(i = 0; i < mapvote_count; ++i)
1920 if(mapvote_maps[i] != "")
1922 didntvote -= mapvote_votes[i];
1925 result = strcat(result, ":", mapvote_maps[i]);
1926 result = strcat(result, ":", ftos(mapvote_votes[i]));
1929 result = strcat(result, ":didn't vote:", ftos(didntvote));
1931 GameLogEcho(result, FALSE);
1932 if(mapvote_maps_suggested[mappos])
1933 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
1935 FOR_EACH_REALCLIENT(other)
1936 FixClientCvars(other);
1938 Map_Goto_SetStr(mapvote_maps[mappos]);
1940 alreadychangedlevel = TRUE;
1943 void MapVote_CheckRules_1()
1947 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1949 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1950 mapvote_votes[i] = 0;
1954 FOR_EACH_REALCLIENT(other)
1959 i = other.mapvote - 1;
1960 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1961 mapvote_votes[i] = mapvote_votes[i] + 1;
1966 float MapVote_CheckRules_2()
1969 float firstPlace, secondPlace;
1970 float firstPlaceVotes, secondPlaceVotes;
1971 float mapvote_voters_real;
1974 mapvote_voters_real = mapvote_voters;
1976 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
1979 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1980 RandSel_Add(mapvote_votes[i], i);
1981 firstPlace = randsel_value;
1982 firstPlaceVotes = randsel_priority;
1983 //dprint("First place: ", ftos(firstPlace), "\n");
1984 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1987 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
1989 RandSel_Add(mapvote_votes[i], i);
1990 secondPlace = randsel_value;
1991 secondPlaceVotes = randsel_priority;
1992 //dprint("Second place: ", ftos(secondPlace), "\n");
1993 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1995 if(firstPlace == -1)
1996 error("No first place in map vote... WTF?");
1998 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
1999 return MapVote_Finished(firstPlace);
2001 if(mapvote_keeptwotime)
2002 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2005 mapvote_message = "Now decide between the TOP TWO!";
2006 mapvote_keeptwotime = 0;
2007 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2008 result = strcat(result, ":", ftos(firstPlaceVotes));
2009 result = strcat(result, ":", mapvote_maps[secondPlace]);
2010 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2011 didntvote = mapvote_voters;
2012 for(i = 0; i < mapvote_count; ++i)
2013 if(mapvote_maps[i] != "")
2015 didntvote -= mapvote_votes[i];
2017 if(i != secondPlace)
2019 result = strcat(result, ":", mapvote_maps[i]);
2020 result = strcat(result, ":", ftos(mapvote_votes[i]));
2021 if(i < mapvote_count_real)
2023 strunzone(mapvote_maps[i]);
2024 mapvote_maps[i] = "";
2028 result = strcat(result, ":didn't vote:", ftos(didntvote));
2029 GameLogEcho(result, FALSE);
2042 keeptwo = mapvote_keeptwotime;
2043 MapVote_CheckRules_1(); // count
2044 if(MapVote_CheckRules_2()) // decide
2048 FOR_EACH_REALCLIENT(other)
2050 // hide scoreboard again
2051 if(other.health != 2342)
2053 other.health = 2342;
2055 if(clienttype(other) == CLIENTTYPE_REAL)
2057 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");
2059 WriteByte(MSG_ONE, SVC_FINALE);
2060 WriteString(MSG_ONE, "");
2064 // notify about keep-two
2065 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2066 play2(other, "misc/invshot.wav");
2068 // clear possibly invalid votes
2069 if(mapvote_maps[other.mapvote - 1] == "")
2071 // use impulses as new vote
2072 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2073 if(mapvote_maps[other.impulse - 1] != "")
2074 other.mapvote = other.impulse;
2081 MapVote_CheckRules_1(); // just count
2083 FOR_EACH_REALCLIENT(other)
2085 // display voting screen
2086 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2087 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2089 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2090 msgstr = strcat(msgstr, mapvote_message);
2091 msgstr = strcat(msgstr, "\n\n");
2092 for(i = 0; i < mapvote_count; ++i)
2093 if(mapvote_maps[i] == "")
2094 msgstr = strcat(msgstr, "\n");
2097 tmp = mapvote_maps[i];
2098 tmp = strpad(mapvote_maxlen, tmp);
2099 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2102 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2103 if(mapvote_votes[i] != 1)
2104 tmp = strcat(tmp, "s");
2105 tmp = strcat(tmp, ")");
2106 tmp = strpad(mapvote_maxlen + 15, tmp);
2109 if(i == mapvote_count - 1)
2110 msgstr = strcat(msgstr, "\n");
2111 if(other.mapvote == i + 1)
2112 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2114 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2117 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2119 msgstr = strcat(msgstr, "s");
2120 msgstr = strcat(msgstr, " cast");
2121 i = ceil(mapvote_timeout - time);
2122 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2124 msgstr = strcat(msgstr, "s");
2125 msgstr = strcat(msgstr, " left");
2127 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2130 void MapVote_Start()
2136 MapInfo_Enumerate();
2137 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2141 void MapVote_Think()
2146 if(alreadychangedlevel)
2149 if(time < mapvote_nextthink)
2153 mapvote_nextthink = time + 0.5;
2155 if(!mapvote_initialized)
2157 mapvote_initialized = TRUE;
2158 if(DoNextMapOverride())
2160 if(!cvar("g_maplist_votable") || player_count <= 0)
2171 string GotoMap(string m)
2174 if(!MapInfo_CheckMap(m))
2176 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2178 return "The map you chose is not available on this server.";
2179 cvar_set("nextmap", m);
2180 cvar_set("timelimit", "-1");
2181 if(mapvote_initialized || alreadychangedlevel)
2183 if(DoNextMapOverride())
2184 return "Map switch initiated.";
2186 return "Hm... no. For some reason I like THIS map more.";
2189 return "Map switch will happen after scoreboard.";
2195 FOR_EACH_REALCLIENT(self)
2197 if(self.classname == "spectator")
2199 if(self.enemy.hitsound)
2200 play2(self, "misc/hit.wav");
2205 play2(self, "misc/hit.wav");
2208 FOR_EACH_CLIENT(self)
2209 self.hitsound = FALSE;
2215 * returns TRUE if redirecting
2217 float redirection_timeout;
2218 float redirection_nextthink;
2219 float RedirectionThink()
2221 float clients_found;
2223 if(redirection_target == "")
2226 if(!redirection_timeout)
2228 cvar_set("sv_public", "-2");
2229 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2230 if(redirection_target == "self")
2231 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2233 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2236 if(time < redirection_nextthink)
2239 redirection_nextthink = time + 1;
2242 FOR_EACH_REALCLIENT(self)
2244 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2245 if(redirection_target == "self")
2246 stuffcmd(self, "\ndisconnect; reconnect\n");
2248 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2252 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2254 if(time > redirection_timeout || clients_found == 0)
2255 localcmd("\nwait; wait; wait; quit\n");
2262 if(world_initialized)
2264 world_initialized = 0;
2265 print("Saving persistent data...\n");
2268 db_save(ServerProgsDB, "server.db");
2270 // tell the bot system the game is ending now
2275 print("NOTE: crashed before even initializing the world, not saving persistent data\n");