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.cnt += 10;
51 if(world.cnt > 0.2 || world.cnt < -0.2) // don't error out if it's just roundoff errors
52 dprint("*** fteqcc test: found += bug\n");
54 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
59 * Takes care of pausing and unpausing the game.
60 * Centerprints the information about an upcoming or active timeout to all active
61 * players. Also plays reminder sounds.
63 void timeoutHandler_Think() {
66 if (timeoutStatus == 1) {
67 if (remainingLeadTime > 0) {
68 //centerprint the information to every player
69 timeStr = getTimeoutText(0);
70 FOR_EACH_REALCLIENT(plr) {
71 if(plr.classname == "player") {
72 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
75 remainingLeadTime -= 1;
76 //think again in 1 second:
77 self.nextthink = time + 1;
82 cvar_set("slowmo", ftos(TIMEOUT_SLOWMO_VALUE));
83 //copy .v_angle to .lastV_angle for every player in order to fix their view during pause (see PlayerPreThink)
84 FOR_EACH_REALPLAYER(plr) {
85 plr.lastV_angle = plr.v_angle;
87 self.nextthink = time;
90 else if (timeoutStatus == 2) {
91 if (remainingTimeoutTime > 0) {
92 timeStr = getTimeoutText(0);
93 FOR_EACH_REALCLIENT(plr) {
94 if(plr.classname == "player") {
95 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
98 if(remainingTimeoutTime == cvar("sv_timeout_resumetime")) { //play a warning sound when only <sv_timeout_resumetime> seconds are left
99 play2all("announcer/robotic/prepareforbattle.wav");
101 remainingTimeoutTime -= 1;
102 self.nextthink = time + TIMEOUT_SLOWMO_VALUE;
105 //unpause the game again
106 remainingTimeoutTime = timeoutStatus = 0;
107 cvar_set("slowmo", ftos(orig_slowmo));
108 //and unlock the fixed view again once there is no timeout active anymore
109 FOR_EACH_REALPLAYER(plr) {
110 plr.fixangle = FALSE;
112 //get rid of the countdown message
113 FOR_EACH_REALCLIENT(plr) {
114 if(plr.classname == "player") {
115 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
123 else if (timeoutStatus == 0) { //if a player called the resumegame command (which set timeoutStatus to 0 already)
124 FOR_EACH_REALCLIENT(plr) {
125 if(plr.classname == "player") {
126 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
138 cvar_set("_sv_init", "0");
139 if(cvar("g_maplist_shuffle"))
141 tokenizebyseparator(cvar_string("g_maplist"), " ");
143 cvar_set("nextmap", argv(0));
146 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0);
148 if(!DoNextMapOverride())
157 void cvar_changes_init()
164 strunzone(cvar_changes);
165 cvar_changes = string_null;
166 fh = fopen("cvars.txt", FILE_READ);
169 while((s = fgets(fh)))
171 n = tokenize_sane(s);
178 d = cvar_defstring(k);
181 cvar_changes = strcat(cvar_changes, k, " \"", v, "\" // \"", d, "\"\n");
182 if(strlen(cvar_changes) > 16384)
184 cvar_changes = "// too many settings have been changed to show them here\n";
190 if(cvar_changes == "")
191 cvar_changes = "// this server runs at default settings\n";
193 cvar_changes = strcat("// this server runs at modified settings:\n", cvar_changes);
194 cvar_changes = strzone(cvar_changes);
197 float world_already_spawned;
198 void RegisterWeapons();
200 void spawnfunc_worldspawn (void)
205 dprint_load(); // load dprint status from cvar
207 if(world_already_spawned)
208 error("world already spawned - you may have EXACTLY ONE worldspawn!");
209 world_already_spawned = TRUE;
211 remove = remove_safely; // during spawning, watch what you remove!
213 compressShortVector_init();
216 head = nextent(world);
221 head = nextent(head);
224 // needs to be done so early as they would still spawn
231 ServerProgsDB = db_create();
233 ServerProgsDB = db_load("server.db");
235 TemporaryDB = db_create();
238 TODO sound pack system
239 // initialize sound pack system
240 soundpack = cvar_string("g_soundpack");
242 soundpack = strcat(soundpack, "/");
243 soundpack = strzone(soundpack);
249 // 1 FLICKER (first variety)
250 lightstyle(1, "mmnmmommommnonmmonqnmmo");
252 // 2 SLOW STRONG PULSE
253 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
255 // 3 CANDLE (first variety)
256 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
259 lightstyle(4, "mamamamamama");
262 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
264 // 6 FLICKER (second variety)
265 lightstyle(6, "nmonqnmomnmomomno");
267 // 7 CANDLE (second variety)
268 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
270 // 8 CANDLE (third variety)
271 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
273 // 9 SLOW STROBE (fourth variety)
274 lightstyle(9, "aaaaaaaazzzzzzzz");
276 // 10 FLUORESCENT FLICKER
277 lightstyle(10, "mmamammmmammamamaaamammma");
279 // 11 SLOW PULSE NOT FADE TO BLACK
280 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
282 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
287 if(cvar("g_campaign"))
294 bot_waypoints_for_items = cvar("g_waypoints_for_items");
295 if(bot_waypoints_for_items == 1)
296 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
297 bot_waypoints_for_items = 0;
299 // for setting by mapinfo
300 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
301 cvar_set("sv_q3acompat_machineshotgunswap", "0");
305 WaypointSprite_Init();
310 GameLogInit(); // prepare everything
311 if(cvar("sv_eventlog"))
313 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
314 s = strcat(s, ftos(random()));
315 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
316 s = ":gameinfo:mutators:LIST";
317 if(cvar("g_grappling_hook"))
318 s = strcat(s, ":grappling_hook");
319 if(!cvar("g_use_ammunition"))
320 s = strcat(s, ":no_use_ammunition");
321 if(!cvar("g_pickup_items"))
322 s = strcat(s, ":no_pickup_items");
323 if(cvar("g_instagib"))
324 s = strcat(s, ":instagib");
325 if(cvar("g_rocketarena"))
326 s = strcat(s, ":rockerarena");
328 s = strcat(s, ":nixnex");
329 if(cvar("g_vampire"))
330 s = strcat(s, ":vampire");
331 if(cvar("g_laserguided_missile"))
332 s = strcat(s, ":laserguided_missile");
333 if(cvar("g_norecoil"))
334 s = strcat(s, ":norecoil");
336 s = strcat(s, ":midair");
337 if(cvar("g_minstagib"))
338 s = strcat(s, ":minstagib");
340 GameLogEcho(":gameinfo:end");
343 cvar_set("nextmap", "");
347 if(cvar("g_campaign"))
354 //initialise globals related to sv_timeout
355 sys_ticrate = cvar("sys_ticrate");
356 orig_slowmo = cvar("slowmo");
359 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
361 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
363 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
366 while((s = fgets(fd)))
368 l = tokenize_sane(s);
373 print("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
374 print(" cdtrack ", argv(2), "\n");
376 else if(argv(0) == "fog")
378 print("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
379 print(" \"fog\" \"", s, "\"\n");
381 else if(argv(0) == "set")
383 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
384 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
386 else if(argv(0) != "//")
388 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
389 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
396 addstat(STAT_SYS_TICRATE, AS_FLOAT, stat_sys_ticrate);
397 addstat(STAT_WEAPONS, AS_INT, weapons);
398 addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
399 addstat(STAT_GAMESTARTTIME, AS_FLOAT, stat_game_starttime);
402 next_pingtime = time + 5;
403 world_initialized = 1;
405 InitializeEntity(self, cvar_changes_init, INITPRIO_CVARS);
408 void spawnfunc_light (void)
410 //makestatic (self); // Who the f___ did that?
414 float TryFile( string pFilename )
417 dprint("TryFile(\"", pFilename, "\")\n");
418 lHandle = fopen( pFilename, FILE_READ );
419 if( lHandle != -1 ) {
429 return GametypeNameFromType(game);
432 string getmapname_stored;
438 float Map_Count, Map_Current;
439 string Map_Current_Name;
441 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
442 float GetMaplistPosition()
448 idx = cvar("g_maplist_index");
455 for(pos = 0; pos < Map_Count; ++pos)
459 // resume normal maplist rotation if current map is not in g_maplist
463 float MapHasRightSize(string map)
466 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
467 if(cvar("g_maplist_check_waypoints"))
469 dprint("checkwp "); dprint(map);
470 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
473 dprint(": no waypoints\n");
476 dprint(": has waypoints\n");
480 // open map size restriction file
481 dprint("opensize "); dprint(map);
482 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
485 float mapmin, mapmax;
487 mapmin = stof(fgets(fh));
488 mapmax = stof(fgets(fh));
490 if(player_count < mapmin)
492 dprint("not enough\n");
495 if(player_count > mapmax)
497 dprint("too many\n");
500 dprint("right size\n");
503 dprint(": not found\n");
507 string Map_Filename(float position)
509 return strcat("maps/", argv(position), ".bsp");
512 string strwords(string s, float w)
515 for(endpos = 0; w && endpos >= 0; --w)
516 endpos = strstrofs(s, " ", endpos + 1);
520 return substring(s, 0, endpos);
523 float strhasword(string s, string w)
525 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
528 void Map_MarkAsRecent(string m)
530 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
533 float Map_IsRecent(string m)
535 return strhasword(cvar_string("g_maplist_mostrecent"), m);
538 float Map_Check(float position, float pass)
542 map_next = argv(position);
545 if(map_next == Map_Current_Name) // same map again in first pass?
547 if(Map_IsRecent(map_next))
550 filename = Map_Filename(position);
551 if(MapInfo_CheckMap(map_next))
555 if(MapHasRightSize(map_next))
560 dprint( "Couldn't select '", filename, "'..\n" );
565 void Map_Goto_SetStr(string nextmapname)
567 if(getmapname_stored != "")
568 strunzone(getmapname_stored);
569 if(nextmapname == "")
570 getmapname_stored = "";
572 getmapname_stored = strzone(nextmapname);
575 void Map_Goto_SetFloat(float position)
577 cvar_set("g_maplist_index", ftos(position));
578 Map_Goto_SetStr(argv(position));
583 // settings persist, except...
584 if(cvar("g_campaign"))
585 localcmd("\nexec mutator_reset.cfg\n");
586 localcmd("\nsettemp_restore\n");
591 Map_MarkAsRecent(getmapname_stored);
593 MapInfo_LoadMap(getmapname_stored);
596 // return codes of map selectors:
597 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
598 // -2 = permanent failure
599 float() MaplistMethod_Iterate = // usual method
603 for(pass = 1; pass <= 2; ++pass)
605 for(i = 1; i < Map_Count; ++i)
608 mapindex = mod(i + Map_Current, Map_Count);
609 if(Map_Check(mapindex, pass))
616 float() MaplistMethod_Repeat = // fallback method
618 if(Map_Check(Map_Current, 2))
623 float() MaplistMethod_Random = // random map selection
629 for(i = 0; i <= imax; ++i)
632 mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
633 if(Map_Check(mapindex, 1))
639 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
640 // the exponent sets a bias on the map selection:
641 // the higher the exponent, the less likely "shortly repeated" same maps are
643 float i, j, imax, insertpos;
647 for(i = 0; i <= imax; ++i)
651 // now reinsert this at another position
652 insertpos = pow(random(), 1 / exponent); // ]0, 1]
653 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
654 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
655 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
657 // insert the current map there
659 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
660 newlist = strcat(newlist, " ", argv(j));
661 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
662 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
663 newlist = strcat(newlist, " ", argv(j));
664 newlist = substring(newlist, 1, strlen(newlist) - 1);
665 cvar_set("g_maplist", newlist);
666 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
668 // NOTE: the selected map has just been inserted at (insertpos-1)th position
669 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
670 if(Map_Check(Map_Current, 1))
679 temp = cvar_string("g_maplist");
680 Map_Count = tokenizebyseparator(temp, " ");
683 bprint( "Maplist is empty! Resetting it to default map list.\n" );
684 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
685 localcmd("\nmenu_cmd sync\n");
686 Map_Count = tokenizebyseparator(temp, " ");
689 error("empty maplist, cannot select a new map");
690 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
693 strunzone(Map_Current_Name);
694 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
695 // this may or may not be correct, but who cares, in the worst case a map
696 // isn't chosen in the first pass that should have been
707 if(cvar("g_maplist_shuffle") > 0)
708 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
711 if(cvar("g_maplist_selectrandom"))
712 nextMap = MaplistMethod_Random();
715 nextMap = MaplistMethod_Iterate();
718 nextMap = MaplistMethod_Repeat();
722 Map_Goto_SetFloat(nextMap);
723 return getmapname_stored;
729 float DoNextMapOverride()
731 if(cvar("g_campaign"))
733 CampaignPostIntermission();
734 alreadychangedlevel = TRUE;
737 if(cvar("quit_when_empty"))
739 if(player_count <= currentbots)
742 alreadychangedlevel = TRUE;
746 if(cvar_string("quit_and_redirect") != "")
748 redirection_target = strzone(cvar_string("quit_and_redirect"));
749 alreadychangedlevel = TRUE;
752 if (cvar("samelevel")) // if samelevel is set, stay on same level
754 // 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)
755 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
756 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
757 localcmd("restart\n");
758 //changelevel (mapname);
759 alreadychangedlevel = TRUE;
762 if(cvar_string("nextmap") != "")
763 if(MapInfo_CheckMap(cvar_string("nextmap")))
765 Map_Goto_SetStr(cvar_string("nextmap"));
767 alreadychangedlevel = TRUE;
770 if(cvar("lastlevel"))
773 localcmd("set lastlevel 0\ntogglemenu\n");
774 alreadychangedlevel = TRUE;
782 //local string nextmap;
783 //local float n, nummaps;
785 if (alreadychangedlevel)
787 alreadychangedlevel = TRUE;
793 for(allowReset = 1; allowReset >= 0; --allowReset)
795 nextMap = GetNextMap();
801 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
802 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
803 localcmd("\nmenu_cmd sync\n");
807 error("Everything is broken - not even the default map list works. Please report this to the developers.");
819 When the player presses attack or jump, change to the next level
822 .float autoscreenshot;
823 void() MapVote_Start;
824 void() MapVote_Think;
825 float mapvote_initialized;
826 void IntermissionThink()
828 FixIntermissionClient(self);
830 if(cvar("sv_autoscreenshot"))
831 if(self.autoscreenshot > 0)
832 if(time > self.autoscreenshot)
834 self.autoscreenshot = -1;
835 if(clienttype(self) == CLIENTTYPE_REAL)
836 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
840 if (time < intermission_exittime)
843 if(!mapvote_initialized)
844 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
854 Returns the entity to view from
858 entity FindIntermission()
863 // look for info_intermission first
864 spot = find (world, classname, "info_intermission");
866 { // pick a random one
870 spot = find (spot, classname, "info_intermission");
872 spot = find (spot, classname, "info_intermission");
878 // then look for the start position
879 spot = find (world, classname, "info_player_start");
883 // testinfo_player_start is only found in regioned levels
884 spot = find (world, classname, "testplayerstart");
888 // then look for the start position
889 spot = find (world, classname, "info_player_deathmatch");
893 //objerror ("FindIntermission: no spot");
899 ===============================================================================
903 ===============================================================================
906 void DumpStats(float final)
910 local float to_console;
911 local float to_eventlog;
915 to_console = cvar("sv_logscores_console");
916 to_eventlog = cvar("sv_eventlog");
917 to_file = cvar("sv_logscores_file");
921 to_console = TRUE; // always print printstats replies
922 to_eventlog = FALSE; // but never print them to the event log
926 if(cvar("sv_eventlog_console"))
927 to_console = FALSE; // otherwise we get the output twice
933 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
941 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
945 fputs(file, strcat(s, "\n"));
948 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
954 fputs(file, strcat(s, "\n"));
956 FOR_EACH_CLIENT(other)
958 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
960 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
961 s = strcat(s, ftos(rint(time - other.jointime)), ":");
962 if(other.classname == "player" || g_arena || g_lms)
963 s = strcat(s, ftos(other.team), ":");
965 s = strcat(s, "spectator:");
968 print(s, other.netname, "\n");
970 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
972 fputs(file, strcat(s, other.netname, "\n"));
978 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
984 fputs(file, strcat(s, "\n"));
986 for(i = 1; i < 16; ++i)
988 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
989 s = strcat(s, ":", ftos(i));
995 fputs(file, strcat(s, "\n"));
1002 GameLogEcho(":end");
1005 fputs(file, ":end\n");
1010 void FixIntermissionClient(entity e)
1013 if(!e.autoscreenshot) // initial call
1015 e.angles = e.v_angle;
1016 e.angles_x = -e.angles_x;
1017 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1019 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1020 e.solid = SOLID_NOT;
1021 e.movetype = MOVETYPE_NONE;
1022 e.takedamage = DAMAGE_NO;
1024 e.weaponentity.effects = EF_NODRAW;
1025 if(clienttype(e) == CLIENTTYPE_REAL)
1027 stuffcmd(e, "\nscr_printspeed 1000000\n");
1028 s = cvar_string("sv_intermission_cdtrack");
1030 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1032 WriteByte(MSG_ONE, SVC_INTERMISSION);
1036 //e.velocity = '0 0 0';
1037 //e.fixangle = TRUE;
1039 // TODO halt weapon animation
1044 go to the next level for deathmatch
1045 only called if a time or frag limit has expired
1049 float minTotalFrags;
1050 float maxTotalFrags;
1056 intermission_running = 1;
1058 // enforce a wait time before allowing changelevel
1059 if(player_count > 0)
1060 intermission_exittime = time + cvar("sv_mapchange_delay");
1062 intermission_exittime = -1;
1065 WriteByte (MSG_ALL, SVC_CDTRACK);
1066 WriteByte (MSG_ALL, 3);
1067 WriteByte (MSG_ALL, 3);
1068 // done in FixIntermission
1071 //pos = FindIntermission ();
1077 if(cvar("sv_eventlog"))
1078 GameLogEcho(":gameover");
1082 FOR_EACH_CLIENT(other)
1084 FixIntermissionClient(other);
1087 bprint(other.netname, " ^7wins.\n");
1092 FOR_EACH_PLAYER(other)
1094 if(maxTotalFrags < other.totalfrags)
1095 maxTotalFrags = other.totalfrags;
1096 if(minTotalFrags > other.totalfrags)
1097 minTotalFrags = other.totalfrags;
1102 FOR_EACH_PLAYER(other)
1104 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1105 f = bound(0, other.play_time / max(time, 1), 1);
1106 // store some statistics?
1110 if(cvar("g_campaign"))
1111 CampaignPreIntermission();
1113 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1120 Exit deathmatch games upon conditions
1123 void CheckRules_Player()
1125 if (gameover) // someone else quit the game already
1128 if(self.deadflag == DEAD_NO)
1129 self.play_time += frametime;
1131 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1132 // (div0: and that in CheckRules_World please)
1135 float checkrules_oneminutewarning;
1137 float checkrules_equality;
1138 float checkrules_overtimewarning;
1139 float checkrules_overtimeend;
1141 void InitiateOvertime()
1143 if(!checkrules_overtimeend)
1144 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1147 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1148 float WINNING_YES = 1; // winner found
1149 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1150 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1152 float GetWinningCode(float fraglimitreached, float equality)
1155 if(fraglimitreached)
1156 return WINNING_STARTOVERTIME;
1158 return WINNING_NEVER;
1160 if(fraglimitreached)
1166 // set the .winning flag for exactly those players with a given field value
1167 void SetWinners(.float field, float value)
1170 FOR_EACH_PLAYER(head)
1171 head.winning = (head.field == value);
1174 // set the .winning flag for those players with a given field value
1175 void AddWinners(.float field, float value)
1178 FOR_EACH_PLAYER(head)
1179 if(head.field == value)
1183 // clear the .winning flags
1184 void ClearWinners(void)
1187 FOR_EACH_PLAYER(head)
1191 // Onslaught winning condition:
1192 // game terminates if only one team has a working generator (or none)
1193 float WinningCondition_Onslaught()
1196 local float t1, t2, t3, t4;
1197 // first check if the game has ended
1198 t1 = t2 = t3 = t4 = 0;
1199 head = find(world, classname, "onslaught_generator");
1202 if (head.health > 0)
1204 if (head.team == COLOR_TEAM1) t1 = 1;
1205 if (head.team == COLOR_TEAM2) t2 = 1;
1206 if (head.team == COLOR_TEAM3) t3 = 1;
1207 if (head.team == COLOR_TEAM4) t4 = 1;
1209 head = find(head, classname, "onslaught_generator");
1211 if (t1 + t2 + t3 + t4 < 2)
1213 // game over, only one team remains (or none)
1215 if (t1) SetWinners(team, COLOR_TEAM1);
1216 if (t2) SetWinners(team, COLOR_TEAM2);
1217 if (t3) SetWinners(team, COLOR_TEAM3);
1218 if (t4) SetWinners(team, COLOR_TEAM4);
1219 dprint("Have a winner, ending game.\n");
1223 // Two or more teams remain
1227 float LMS_NewPlayerLives()
1230 fl = cvar("fraglimit");
1234 // first player has left the game for dying too much? Nobody else can get in.
1235 if(lms_lowest_lives < 1)
1238 if(!cvar("g_lms_join_anytime"))
1239 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1242 return bound(1, lms_lowest_lives, fl);
1245 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1246 // they win. Otherwise the defending team wins once the timelimit passes.
1247 void assault_new_round();
1248 float WinningCondition_Assault()
1251 status = WINNING_NO;
1253 // as the timelimit has not yet passed just assume the defending team will win
1254 if(assault_attacker_team == COLOR_TEAM1)
1256 SetWinners(team, COLOR_TEAM2);
1260 SetWinners(team, COLOR_TEAM1);
1264 ent = find(world, classname, "target_assault_roundend");
1267 if(ent.winning) // round end has been triggered by attacking team
1269 SetWinners(team, assault_attacker_team);
1270 if(assault_attacker_team == COLOR_TEAM1)
1272 team1_score = team1_score + 50;
1276 team2_score = team2_score + 50;
1279 if(ent.cnt == 1) // this was the second round
1281 status = WINNING_YES;
1285 local entity oldself;
1288 cvar_set("timelimit", ftos((2*time)/60)); // FIXME use game_starttime here
1289 assault_new_round();
1299 // LMS winning condition: game terminates if and only if there's at most one
1300 // one player who's living lives. Top two scores being equal cancels the time
1302 float WinningCondition_LMS()
1309 have_player = FALSE;
1310 have_players = FALSE;
1311 l = LMS_NewPlayerLives();
1313 head = find(world, classname, "player");
1316 head2 = find(head, classname, "player");
1318 have_players = TRUE;
1322 // we have at least one player
1325 // two or more active players - continue with the game
1329 // exactly one player?
1332 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1336 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1342 // and assign him his first place
1343 PlayerScore_Add(head, SP_LMS_RANK, 1);
1350 // nobody is playing at all...
1353 // wait for players...
1357 // SNAFU (maybe a draw game?)
1359 dprint("No players, ending game.\n");
1364 // When we get here, we have at least two players who are actually LIVING,
1365 // now check if the top two players have equal score.
1366 WinningConditionHelper();
1369 if(WinningConditionHelper_winner)
1370 WinningConditionHelper_winner.winning = TRUE;
1371 if(WinningConditionHelper_equality)
1372 return WINNING_NEVER;
1374 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1378 void print_to(entity e, string s)
1381 sprint(e, strcat(s, "\n"));
1386 void ShuffleMaplist()
1394 result = cvar_string("g_maplist");
1395 litems = tokenizebyseparator(result, " ");
1397 for(start = 0; start < litems - 1; ++start)
1401 // select a random item
1402 selected = ceil(random() * (litems - start) + start) - 1;
1404 // shift this item to the place start
1405 for(i = 0; i < start; ++i)
1406 result = strcat(result, " ", argv(i));
1407 result = strcat(result, " ", argv(selected));
1408 for(i = start; i < litems; ++i)
1410 result = strcat(result, " ", argv(i));
1411 result = substring(result, 1, strlen(result) - 1);
1413 litems = tokenizebyseparator(result, " ");
1415 //dprint(result, "\n");
1418 cvar_set("g_maplist", result);
1421 float WinningCondition_Scores(float limit)
1423 // TODO make everything use THIS winning condition (except LMS)
1424 WinningConditionHelper();
1428 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1429 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1430 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1431 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1435 if(WinningConditionHelper_winner)
1436 WinningConditionHelper_winner.winning = 1;
1437 if(WinningConditionHelper_winnerteam >= 0)
1438 SetWinners(team, WinningConditionHelper_winnerteam);
1440 if(WinningConditionHelper_lowerisbetter)
1442 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1446 return GetWinningCode(limit && WinningConditionHelper_topscore && (WinningConditionHelper_topscore >= limit), WinningConditionHelper_equality);
1449 float WinningCondition_Race(float fraglimit)
1453 wc = WinningCondition_Scores(fraglimit);
1455 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1456 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1457 // do NOT support equality when the laps are all raced!
1460 if not(p.race_completed)
1461 return WINNING_STARTOVERTIME;
1467 void ReadyRestart();
1468 float WinningCondition_QualifyingThenRace(float limit)
1471 wc = WinningCondition_Scores(limit);
1473 // NEVER initiate overtime
1474 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1475 // do NOT support equality when the laps are all raced!
1478 float playerswithlaps;
1481 totalplayers = playerswithlaps = readyplayers = 0;
1482 FOR_EACH_PLAYER(head)
1485 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
1491 // at least 2/3 of the players have completed a lap: start the RACE
1492 // otherwise, the players should end the qualifying on their own
1493 if(readyplayers || ((totalplayers >= 3) && (playerswithlaps * 3 >= totalplayers * 2)))
1495 checkrules_overtimeend = 0;
1497 return WINNING_NEVER;
1506 float WinningCondition_RanOutOfSpawns()
1510 if(!have_team_spawns)
1513 if(!some_spawn_has_been_used)
1516 team1_score = team2_score = team3_score = team4_score = 0;
1518 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1520 if(head.team == COLOR_TEAM1)
1522 else if(head.team == COLOR_TEAM2)
1524 else if(head.team == COLOR_TEAM3)
1526 else if(head.team == COLOR_TEAM4)
1530 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1532 if(head.team == COLOR_TEAM1)
1534 else if(head.team == COLOR_TEAM2)
1536 else if(head.team == COLOR_TEAM3)
1538 else if(head.team == COLOR_TEAM4)
1543 if(team1_score + team2_score + team3_score + team4_score == 0)
1545 checkrules_equality = TRUE;
1548 else if(team1_score + team2_score + team3_score + team4_score == 1)
1551 if(team1_score) t = COLOR_TEAM1;
1552 if(team2_score) t = COLOR_TEAM2;
1553 if(team3_score) t = COLOR_TEAM3;
1554 if(team4_score) t = COLOR_TEAM4;
1555 CheckAllowedTeams(world);
1556 for(i = 0; i < MAX_TEAMSCORE; ++i)
1558 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
1559 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
1560 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
1561 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
1564 AddWinners(team, t);
1575 Exit deathmatch games upon conditions
1578 void CheckRules_World()
1581 local float timelimit;
1582 local float fraglimit;
1590 MapVote_Think should now do that part
1591 if (intermission_running)
1592 if (time >= intermission_exittime + 60)
1594 if(!DoNextMapOverride())
1600 if (gameover) // someone else quit the game already
1602 if(player_count == 0) // Nobody there? Then let's go to the next map
1604 // this will actually check the player count in the next frame
1605 // again, but this shouldn't hurt
1609 timelimit = cvar("timelimit") * 60;
1610 fraglimit = cvar("fraglimit");
1612 if(inWarmupStage || time <= game_starttime) // NOTE: this is <= to prevent problems in the very tic where the game starts
1614 timelimit = 0; // timelimit is not made for warmup
1615 fraglimit = 0; // no fraglimit for now
1619 timelimit += game_starttime;
1621 if(checkrules_overtimeend)
1623 if(!checkrules_overtimewarning)
1625 checkrules_overtimewarning = TRUE;
1626 //announceall("announcer/robotic/1minuteremains.wav");
1627 if(g_race && !g_race_qualifying)
1628 bcenterprint("^3Everyone, finish your lap! The race is over!");
1630 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1635 if (timelimit && time >= timelimit)
1639 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1645 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1647 checkrules_oneminutewarning = TRUE;
1648 play2all("announcer/robotic/1minuteremains.wav");
1651 status = WinningCondition_RanOutOfSpawns();
1652 if(status == WINNING_YES)
1654 bprint("Hey! Someone ran out of spawns!\n");
1656 else if(g_race && !g_race_qualifying && timelimit >= 0)
1658 status = WinningCondition_Race(fraglimit);
1660 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
1662 status = WinningCondition_QualifyingThenRace(fraglimit);
1666 status = WinningCondition_Assault(); // TODO remove this?
1670 status = WinningCondition_LMS();
1672 else if (g_onslaught)
1674 status = WinningCondition_Onslaught(); // TODO remove this?
1678 status = WinningCondition_Scores(fraglimit);
1681 if(status == WINNING_STARTOVERTIME)
1683 status = WINNING_NEVER;
1687 if(status == WINNING_NEVER)
1688 // equality cases! Nobody wins if the overtime ends in a draw.
1691 if(checkrules_overtimeend)
1692 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1693 status = WINNING_YES;
1695 if(status == WINNING_YES)
1699 float mapvote_nextthink;
1700 float mapvote_initialized;
1701 float mapvote_keeptwotime;
1702 float mapvote_timeout;
1703 string mapvote_message;
1704 string mapvote_screenshot_dir;
1706 float mapvote_count;
1707 float mapvote_count_real;
1708 string mapvote_maps[MAPVOTE_COUNT];
1709 float mapvote_maps_suggested[MAPVOTE_COUNT];
1710 string mapvote_suggestions[MAPVOTE_COUNT];
1711 float mapvote_suggestion_ptr;
1712 float mapvote_maxlen;
1713 float mapvote_voters;
1714 float mapvote_votes[MAPVOTE_COUNT];
1716 float mapvote_detail;
1717 float mapvote_abstain;
1718 float mapvote_dirty;
1721 void MapVote_ClearAllVotes()
1723 FOR_EACH_CLIENT(other)
1727 string MapVote_Suggest(string m)
1731 return "That's not how to use this command.";
1732 if(!cvar("g_maplist_votable_suggestions"))
1733 return "Suggestions are not accepted on this server.";
1734 if(mapvote_initialized)
1735 return "Can't suggest - voting is already in progress!";
1736 m = MapInfo_FixName(m);
1738 return "The map you suggested is not available on this server.";
1739 if(!cvar("g_maplist_votable_override_mostrecent"))
1741 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1743 if(!MapInfo_CheckMap(m))
1744 return "The map you suggested does not support the current game mode.";
1745 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1746 if(mapvote_suggestions[i] == m)
1747 return "This map was already suggested.";
1748 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1750 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1754 i = mapvote_suggestion_ptr;
1755 mapvote_suggestion_ptr += 1;
1757 if(mapvote_suggestions[i] != "")
1758 strunzone(mapvote_suggestions[i]);
1759 mapvote_suggestions[i] = strzone(m);
1760 if(cvar("sv_eventlog"))
1761 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
1762 return strcat("Suggestion of ", m, " accepted.");
1765 void MapVote_AddVotable(string nextMap, float isSuggestion)
1770 for(j = 0; j < mapvote_count; ++j)
1771 if(mapvote_maps[j] == nextMap)
1773 if(strlen(nextMap) > mapvote_maxlen)
1774 mapvote_maxlen = strlen(nextMap);
1775 mapvote_maps[mapvote_count] = strzone(nextMap);
1776 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1780 void MapVote_SendData(float target);
1786 MapVote_ClearAllVotes();
1789 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1790 mapvote_abstain = cvar("g_maplist_votable_abstain");
1793 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1795 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1796 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
1798 if(mapvote_suggestion_ptr)
1799 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1800 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1802 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1803 MapVote_AddVotable(GetNextMap(), FALSE);
1805 if(mapvote_count == 0)
1807 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1808 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1809 localcmd("\nmenu_cmd sync\n");
1810 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1811 MapVote_AddVotable(GetNextMap(), FALSE);
1814 mapvote_count_real = mapvote_count;
1816 MapVote_AddVotable("don't care", 0);
1818 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1820 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1821 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1822 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1823 mapvote_keeptwotime = 0;
1824 mapvote_message = "Choose a map and press its key!";
1826 mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
1827 if(mapvote_screenshot_dir == "")
1828 mapvote_screenshot_dir = "maps";
1829 mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
1831 if(!cvar("g_maplist_textonly"))
1832 MapVote_SendData(MSG_ALL);
1835 void MapVote_SendPicture(float id)
1838 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1839 WriteByte(MSG_ONE, TE_CSQC_MAPVOTE);
1840 WriteByte(MSG_ONE, MAPVOTE_NET_PIC);
1841 WriteByte(MSG_ONE, id);
1842 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 3072);
1845 float GameCommand_MapVote(string cmd)
1847 if(!intermission_running)
1849 if(!cvar("g_maplist_textonly"))
1851 if(cmd == "mv_getpic")
1853 MapVote_SendPicture(stof(argv(1)));
1861 float MapVote_GetMapMask()
1863 float mask, i, power;
1865 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
1866 if(mapvote_maps[i] != "")
1871 void MapVote_SendData(float targ)
1873 string mapfile, pakfile;
1875 WriteByte(targ, SVC_TEMPENTITY);
1876 WriteByte(targ, TE_CSQC_CONFIG);
1877 WriteString(targ, "mv_screenshot_dir");
1878 WriteString(targ, mapvote_screenshot_dir);
1880 WriteByte(targ, SVC_TEMPENTITY);
1881 WriteByte(targ, TE_CSQC_MAPVOTE);
1882 WriteByte(targ, MAPVOTE_NET_INIT);
1884 WriteByte(targ, mapvote_count);
1885 WriteByte(targ, mapvote_abstain);
1886 WriteByte(targ, mapvote_detail);
1887 WriteCoord(targ, mapvote_timeout);
1888 if(mapvote_count <= 8)
1889 WriteByte(targ, MapVote_GetMapMask());
1891 WriteShort(targ, MapVote_GetMapMask());
1892 for(i = 0; i < mapvote_count; ++i)
1893 if(mapvote_maps[i] != "")
1895 WriteString(targ, mapvote_maps[i]);
1896 mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
1897 pakfile = whichpack(strcat(mapfile, ".tga"));
1899 pakfile = whichpack(strcat(mapfile, ".jpg"));
1901 pakfile = whichpack(strcat(mapfile, ".png"));
1902 print("pakfile is ", pakfile, "\n");
1903 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
1904 pakfile = substring(pakfile, o, 999);
1905 WriteString(targ, pakfile);
1909 void MapVote_UpdateData(float targ)
1912 WriteByte(targ, SVC_TEMPENTITY);
1913 WriteByte(targ, TE_CSQC_MAPVOTE);
1914 WriteByte(targ, MAPVOTE_NET_UPDATE);
1915 if(mapvote_count <= 8)
1916 WriteByte(targ, MapVote_GetMapMask());
1918 WriteShort(targ, MapVote_GetMapMask());
1920 for(i = 0; i < mapvote_count; ++i)
1921 if(mapvote_maps[i] != "")
1922 WriteByte(targ, mapvote_votes[i]);
1925 void MapVote_TellVote(float targ, float vote)
1927 WriteByte(targ, SVC_TEMPENTITY);
1928 WriteByte(targ, TE_CSQC_MAPVOTE);
1929 WriteByte(targ, MAPVOTE_NET_OWNVOTE);
1930 WriteByte(targ, vote);
1933 float MapVote_Finished(float mappos)
1939 if(cvar("sv_eventlog"))
1941 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1942 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1943 didntvote = mapvote_voters;
1944 for(i = 0; i < mapvote_count; ++i)
1945 if(mapvote_maps[i] != "")
1947 didntvote -= mapvote_votes[i];
1950 result = strcat(result, ":", mapvote_maps[i]);
1951 result = strcat(result, ":", ftos(mapvote_votes[i]));
1954 result = strcat(result, ":didn't vote:", ftos(didntvote));
1956 GameLogEcho(result);
1957 if(mapvote_maps_suggested[mappos])
1958 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
1961 FOR_EACH_REALCLIENT(other)
1962 FixClientCvars(other);
1964 Map_Goto_SetStr(mapvote_maps[mappos]);
1966 alreadychangedlevel = TRUE;
1969 void MapVote_CheckRules_1()
1973 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1975 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1976 mapvote_votes[i] = 0;
1980 FOR_EACH_REALCLIENT(other)
1985 i = other.mapvote - 1;
1986 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1987 mapvote_votes[i] = mapvote_votes[i] + 1;
1992 float MapVote_CheckRules_2()
1995 float firstPlace, secondPlace;
1996 float firstPlaceVotes, secondPlaceVotes;
1997 float mapvote_voters_real;
2000 mapvote_voters_real = mapvote_voters;
2002 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2004 RandomSelection_Init();
2005 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2006 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2007 firstPlace = RandomSelection_chosen_float;
2008 firstPlaceVotes = RandomSelection_best_priority;
2009 //dprint("First place: ", ftos(firstPlace), "\n");
2010 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2012 RandomSelection_Init();
2013 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2015 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2016 secondPlace = RandomSelection_chosen_float;
2017 secondPlaceVotes = RandomSelection_best_priority;
2018 //dprint("Second place: ", ftos(secondPlace), "\n");
2019 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2021 if(firstPlace == -1)
2022 error("No first place in map vote... WTF?");
2024 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2025 return MapVote_Finished(firstPlace);
2027 if(mapvote_keeptwotime)
2028 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2031 mapvote_dirty = TRUE;
2032 mapvote_message = "Now decide between the TOP TWO!";
2033 mapvote_keeptwotime = 0;
2034 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2035 result = strcat(result, ":", ftos(firstPlaceVotes));
2036 result = strcat(result, ":", mapvote_maps[secondPlace]);
2037 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2038 didntvote = mapvote_voters;
2039 for(i = 0; i < mapvote_count; ++i)
2040 if(mapvote_maps[i] != "")
2042 didntvote -= mapvote_votes[i];
2044 if(i != secondPlace)
2046 result = strcat(result, ":", mapvote_maps[i]);
2047 result = strcat(result, ":", ftos(mapvote_votes[i]));
2048 if(i < mapvote_count_real)
2050 strunzone(mapvote_maps[i]);
2051 mapvote_maps[i] = "";
2055 result = strcat(result, ":didn't vote:", ftos(didntvote));
2056 if(cvar("sv_eventlog"))
2057 GameLogEcho(result);
2070 keeptwo = mapvote_keeptwotime;
2071 MapVote_CheckRules_1(); // count
2072 if(MapVote_CheckRules_2()) // decide
2076 FOR_EACH_REALCLIENT(other)
2078 // hide scoreboard again
2079 if(other.health != 2342)
2081 other.health = 2342;
2083 if(clienttype(other) == CLIENTTYPE_REAL)
2085 if(cvar("g_maplist_textonly"))
2086 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");
2089 WriteByte(MSG_ONE, SVC_FINALE);
2090 WriteString(MSG_ONE, "");
2094 // notify about keep-two
2095 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2096 play2(other, "misc/invshot.wav");
2098 // clear possibly invalid votes
2099 if(mapvote_maps[other.mapvote - 1] == "")
2101 // use impulses as new vote
2102 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2103 if(mapvote_maps[other.impulse - 1] != "")
2105 other.mapvote = other.impulse;
2107 mapvote_dirty = TRUE;
2110 MapVote_TellVote(MSG_ONE, other.mapvote);
2118 MapVote_CheckRules_1(); // just count
2120 if(!cvar("g_maplist_textonly"))
2121 if(mapvote_dirty) // 1 if "keeptwo" or "impulse" happened before
2123 MapVote_UpdateData(MSG_BROADCAST);
2124 mapvote_dirty = FALSE;
2127 if(cvar("g_maplist_textonly"))
2129 FOR_EACH_REALCLIENT(other)
2131 // display voting screen
2132 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2133 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2135 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2136 msgstr = strcat(msgstr, mapvote_message);
2137 msgstr = strcat(msgstr, "\n\n");
2138 for(i = 0; i < mapvote_count; ++i)
2139 if(mapvote_maps[i] == "")
2140 msgstr = strcat(msgstr, "\n");
2143 tmp = mapvote_maps[i];
2144 tmp = strpad(mapvote_maxlen, tmp);
2145 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2148 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2149 if(mapvote_votes[i] != 1)
2150 tmp = strcat(tmp, "s");
2151 tmp = strcat(tmp, ")");
2152 tmp = strpad(mapvote_maxlen + 15, tmp);
2155 if(i == mapvote_count - 1)
2156 msgstr = strcat(msgstr, "\n");
2157 if(other.mapvote == i + 1)
2158 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2160 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2163 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2165 msgstr = strcat(msgstr, "s");
2166 msgstr = strcat(msgstr, " cast");
2167 i = ceil(mapvote_timeout - time);
2168 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2170 msgstr = strcat(msgstr, "s");
2171 msgstr = strcat(msgstr, " left");
2173 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2177 void MapVote_Start()
2182 MapInfo_Enumerate();
2183 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1))
2186 void MapVote_Think()
2191 if(alreadychangedlevel)
2194 if(time < mapvote_nextthink)
2198 mapvote_nextthink = time + 0.5;
2200 if(!mapvote_initialized)
2202 mapvote_initialized = TRUE;
2203 if(DoNextMapOverride())
2205 if(!cvar("g_maplist_votable") || player_count <= 0)
2216 string GotoMap(string m)
2218 if(!MapInfo_CheckMap(m))
2219 return "The map you chose is not available on this server.";
2220 cvar_set("nextmap", m);
2221 cvar_set("timelimit", "-1");
2222 if(mapvote_initialized || alreadychangedlevel)
2224 if(DoNextMapOverride())
2225 return "Map switch initiated.";
2227 return "Hm... no. For some reason I like THIS map more.";
2230 return "Map switch will happen after scoreboard.";
2236 FOR_EACH_REALCLIENT(self)
2238 if(self.classname == "spectator")
2240 if(self.enemy.hitsound)
2241 play2(self, "misc/hit.wav");
2246 play2(self, "misc/hit.wav");
2249 FOR_EACH_CLIENT(self)
2250 self.hitsound = FALSE;
2256 * returns TRUE if redirecting
2258 float redirection_timeout;
2259 float redirection_nextthink;
2260 float RedirectionThink()
2262 float clients_found;
2264 if(redirection_target == "")
2267 if(!redirection_timeout)
2269 cvar_set("sv_public", "-2");
2270 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2271 if(redirection_target == "self")
2272 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2274 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2277 if(time < redirection_nextthink)
2280 redirection_nextthink = time + 1;
2283 FOR_EACH_REALCLIENT(self)
2285 print("Redirecting: sending connect command to ", self.netname, "\n");
2286 if(redirection_target == "self")
2287 stuffcmd(self, "\ndisconnect; reconnect\n");
2289 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2293 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2295 if(time > redirection_timeout || clients_found == 0)
2296 localcmd("\nwait; wait; wait; quit\n");
2303 // Loaded from a save game
2304 // some things then break, so let's work around them...
2306 // Progs DB (capture records)
2308 ServerProgsDB = db_create();
2310 ServerProgsDB = db_load("server.db");
2314 MapInfo_Enumerate();
2315 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 1);
2320 if(world_initialized)
2322 world_initialized = 0;
2323 print("Saving persistent data...\n");
2326 db_save(ServerProgsDB, "server.db");
2327 if(cvar("developer"))
2328 db_save(TemporaryDB, "server-temp.db");
2329 db_close(ServerProgsDB);
2330 db_close(TemporaryDB);
2332 // tell the bot system the game is ending now
2339 print("NOTE: crashed before even initializing the world, not saving persistent data\n");