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, (g_maplist_allow_hidden ? MAPINFO_FLAG_HIDDEN : 0), 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 void detect_maptype()
205 o_x += random() * (world.maxs_x - world.mins_x);
206 o_y += random() * (world.maxs_y - world.mins_y);
207 o_z += random() * (world.maxs_z - world.mins_z);
209 tracebox(o, PL_MIN, PL_MAX, o - '0 0 32768', MOVE_WORLDONLY, world);
210 if(trace_fraction == 1)
215 for(i = 0; i < 64; i += 4)
217 tracebox(o, '-1 -1 -1' * i, '1 1 1' * i, o - '0 0 32768', MOVE_WORLDONLY, world);
218 if(trace_fraction == 1)
220 print(ftos(i), " -> ", vtos(trace_endpos), "\n");
227 float world_already_spawned;
228 void RegisterWeapons();
230 void spawnfunc_worldspawn (void)
235 dprint_load(); // load dprint status from cvar
237 if(world_already_spawned)
238 error("world already spawned - you may have EXACTLY ONE worldspawn!");
239 world_already_spawned = TRUE;
241 remove = remove_safely; // during spawning, watch what you remove!
243 if(cvar_string("cvar_check_default") != CVAR_CHECK_DEFAULT)
244 error("Config file mismatch! Please update defaultNexuiz.cfg to match the QuakeC code!");
246 if(cvar_string("cvar_check_weapons") != CVAR_CHECK_WEAPONS)
247 error("Config file mismatch! Please update weapons.cfg and weaponsPro.cfg to match the QuakeC code!");
249 compressShortVector_init();
252 head = nextent(world);
257 head = nextent(head);
260 // needs to be done so early as they would still spawn
265 world_initialized = -1; // don't complain
270 ServerProgsDB = db_create();
272 ServerProgsDB = db_load("server.db");
274 TemporaryDB = db_create();
277 TODO sound pack system
278 // initialize sound pack system
279 soundpack = cvar_string("g_soundpack");
281 soundpack = strcat(soundpack, "/");
282 soundpack = strzone(soundpack);
288 // 1 FLICKER (first variety)
289 lightstyle(1, "mmnmmommommnonmmonqnmmo");
291 // 2 SLOW STRONG PULSE
292 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
294 // 3 CANDLE (first variety)
295 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
298 lightstyle(4, "mamamamamama");
301 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
303 // 6 FLICKER (second variety)
304 lightstyle(6, "nmonqnmomnmomomno");
306 // 7 CANDLE (second variety)
307 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
309 // 8 CANDLE (third variety)
310 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
312 // 9 SLOW STROBE (fourth variety)
313 lightstyle(9, "aaaaaaaazzzzzzzz");
315 // 10 FLUORESCENT FLICKER
316 lightstyle(10, "mmamammmmammamamaaamammma");
318 // 11 SLOW PULSE NOT FADE TO BLACK
319 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
321 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
326 if(cvar("g_campaign"))
334 bot_waypoints_for_items = cvar("g_waypoints_for_items");
335 if(bot_waypoints_for_items == 1)
336 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
337 bot_waypoints_for_items = 0;
339 // for setting by mapinfo
340 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
341 cvar_set("sv_q3acompat_machineshotgunswap", "0");
345 WaypointSprite_Init();
350 GameLogInit(); // prepare everything
351 if(cvar("sv_eventlog"))
353 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
354 s = strcat(s, ftos(random()));
355 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
356 s = ":gameinfo:mutators:LIST";
357 if(cvar("g_grappling_hook"))
358 s = strcat(s, ":grappling_hook");
359 if(!cvar("g_use_ammunition"))
360 s = strcat(s, ":no_use_ammunition");
361 if(!cvar("g_pickup_items"))
362 s = strcat(s, ":no_pickup_items");
363 if(cvar("g_instagib"))
364 s = strcat(s, ":instagib");
365 if(cvar_string("g_weaponarena") != "0")
366 s = strcat(s, ":", cvar_string("g_weaponarena"), " arena");
368 s = strcat(s, ":nixnex");
369 if(cvar("g_vampire"))
370 s = strcat(s, ":vampire");
371 if(cvar("g_laserguided_missile"))
372 s = strcat(s, ":laserguided_missile");
373 if(cvar("g_norecoil"))
374 s = strcat(s, ":norecoil");
376 s = strcat(s, ":midair");
377 if(cvar("g_minstagib"))
378 s = strcat(s, ":minstagib");
380 GameLogEcho(":gameinfo:end");
383 cvar_set("nextmap", "");
387 if(cvar("g_campaign"))
394 //initialise globals related to sv_timeout
395 sys_ticrate = cvar("sys_ticrate");
396 orig_slowmo = cvar("slowmo");
399 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0, (g_maplist_allow_hidden ? MAPINFO_FLAG_HIDDEN : 0), 1);
401 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
403 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
406 while((s = fgets(fd)))
408 l = tokenize_sane(s);
413 print("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
414 print(" cdtrack ", argv(2), "\n");
416 else if(argv(0) == "fog")
418 print("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
419 print(" \"fog\" \"", s, "\"\n");
421 else if(argv(0) == "set")
423 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
424 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
426 else if(argv(0) != "//")
428 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
429 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
436 addstat(STAT_SYS_TICRATE, AS_FLOAT, stat_sys_ticrate);
437 addstat(STAT_WEAPONS, AS_INT, weapons);
438 addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
439 addstat(STAT_GAMESTARTTIME, AS_FLOAT, stat_game_starttime);
442 next_pingtime = time + 5;
443 InitializeEntity(self, cvar_changes_init, INITPRIO_CVARS);
447 world_initialized = 1;
450 void spawnfunc_light (void)
452 //makestatic (self); // Who the f___ did that?
456 float TryFile( string pFilename )
459 dprint("TryFile(\"", pFilename, "\")\n");
460 lHandle = fopen( pFilename, FILE_READ );
461 if( lHandle != -1 ) {
471 return GametypeNameFromType(game);
474 string getmapname_stored;
480 float Map_Count, Map_Current;
481 string Map_Current_Name;
483 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
484 float GetMaplistPosition()
490 idx = cvar("g_maplist_index");
497 for(pos = 0; pos < Map_Count; ++pos)
501 // resume normal maplist rotation if current map is not in g_maplist
505 float MapHasRightSize(string map)
508 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
509 if(cvar("g_maplist_check_waypoints"))
511 dprint("checkwp "); dprint(map);
512 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
515 dprint(": no waypoints\n");
518 dprint(": has waypoints\n");
522 // open map size restriction file
523 dprint("opensize "); dprint(map);
524 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
527 float mapmin, mapmax;
529 mapmin = stof(fgets(fh));
530 mapmax = stof(fgets(fh));
532 if(player_count < mapmin)
534 dprint("not enough\n");
537 if(player_count > mapmax)
539 dprint("too many\n");
542 dprint("right size\n");
545 dprint(": not found\n");
549 string Map_Filename(float position)
551 return strcat("maps/", argv(position), ".bsp");
554 string strwords(string s, float w)
557 for(endpos = 0; w && endpos >= 0; --w)
558 endpos = strstrofs(s, " ", endpos + 1);
562 return substring(s, 0, endpos);
565 float strhasword(string s, string w)
567 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
570 void Map_MarkAsRecent(string m)
572 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
575 float Map_IsRecent(string m)
577 return strhasword(cvar_string("g_maplist_mostrecent"), m);
580 float Map_Check(float position, float pass)
584 map_next = argv(position);
587 if(map_next == Map_Current_Name) // same map again in first pass?
589 if(Map_IsRecent(map_next))
592 filename = Map_Filename(position);
593 if(MapInfo_CheckMap(map_next))
597 if(MapHasRightSize(map_next))
602 dprint( "Couldn't select '", filename, "'..\n" );
607 void Map_Goto_SetStr(string nextmapname)
609 if(getmapname_stored != "")
610 strunzone(getmapname_stored);
611 if(nextmapname == "")
612 getmapname_stored = "";
614 getmapname_stored = strzone(nextmapname);
617 void Map_Goto_SetFloat(float position)
619 cvar_set("g_maplist_index", ftos(position));
620 Map_Goto_SetStr(argv(position));
625 // settings persist, except...
626 if(cvar("g_campaign"))
627 localcmd("\nexec mutator_reset.cfg\n");
628 localcmd("\nsettemp_restore\n");
633 Map_MarkAsRecent(getmapname_stored);
635 MapInfo_LoadMap(getmapname_stored);
638 // return codes of map selectors:
639 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
640 // -2 = permanent failure
641 float() MaplistMethod_Iterate = // usual method
645 for(pass = 1; pass <= 2; ++pass)
647 for(i = 1; i < Map_Count; ++i)
650 mapindex = mod(i + Map_Current, Map_Count);
651 if(Map_Check(mapindex, pass))
658 float() MaplistMethod_Repeat = // fallback method
660 if(Map_Check(Map_Current, 2))
665 float() MaplistMethod_Random = // random map selection
671 for(i = 0; i <= imax; ++i)
674 mapindex = mod(Map_Current + floor(random() * (Map_Count - 1) + 1), Map_Count); // any OTHER map
675 if(Map_Check(mapindex, 1))
681 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
682 // the exponent sets a bias on the map selection:
683 // the higher the exponent, the less likely "shortly repeated" same maps are
685 float i, j, imax, insertpos;
689 for(i = 0; i <= imax; ++i)
693 // now reinsert this at another position
694 insertpos = pow(random(), 1 / exponent); // ]0, 1]
695 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
696 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
697 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
699 // insert the current map there
701 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
702 newlist = strcat(newlist, " ", argv(j));
703 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
704 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
705 newlist = strcat(newlist, " ", argv(j));
706 newlist = substring(newlist, 1, strlen(newlist) - 1);
707 cvar_set("g_maplist", newlist);
708 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
710 // NOTE: the selected map has just been inserted at (insertpos-1)th position
711 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
712 if(Map_Check(Map_Current, 1))
721 temp = cvar_string("g_maplist");
722 Map_Count = tokenizebyseparator(temp, " ");
725 bprint( "Maplist is empty! Resetting it to default map list.\n" );
726 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps(0, MAPINFO_FLAG_HIDDEN));
727 localcmd("\nmenu_cmd sync\n");
728 Map_Count = tokenizebyseparator(temp, " ");
731 error("empty maplist, cannot select a new map");
732 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
735 strunzone(Map_Current_Name);
736 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
737 // this may or may not be correct, but who cares, in the worst case a map
738 // isn't chosen in the first pass that should have been
749 if(cvar("g_maplist_shuffle") > 0)
750 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
753 if(cvar("g_maplist_selectrandom"))
754 nextMap = MaplistMethod_Random();
757 nextMap = MaplistMethod_Iterate();
760 nextMap = MaplistMethod_Repeat();
764 Map_Goto_SetFloat(nextMap);
765 return getmapname_stored;
771 float DoNextMapOverride()
773 if(cvar("g_campaign"))
775 CampaignPostIntermission();
776 alreadychangedlevel = TRUE;
779 if(cvar("quit_when_empty"))
781 if(player_count <= currentbots)
784 alreadychangedlevel = TRUE;
788 if(cvar_string("quit_and_redirect") != "")
790 redirection_target = strzone(cvar_string("quit_and_redirect"));
791 alreadychangedlevel = TRUE;
794 if (cvar("samelevel")) // if samelevel is set, stay on same level
796 // 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)
797 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
798 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
799 localcmd("restart\n");
800 //changelevel (mapname);
801 alreadychangedlevel = TRUE;
804 if(cvar_string("nextmap") != "")
805 if(MapInfo_CheckMap(cvar_string("nextmap")))
807 Map_Goto_SetStr(cvar_string("nextmap"));
809 alreadychangedlevel = TRUE;
812 if(cvar("lastlevel"))
815 localcmd("set lastlevel 0\ntogglemenu\n");
816 alreadychangedlevel = TRUE;
824 //local string nextmap;
825 //local float n, nummaps;
827 if (alreadychangedlevel)
829 alreadychangedlevel = TRUE;
835 for(allowReset = 1; allowReset >= 0; --allowReset)
837 nextMap = GetNextMap();
843 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
844 cvar_set("g_maplist", MapInfo_ListAllowedMaps(0, MAPINFO_FLAG_HIDDEN));
845 localcmd("\nmenu_cmd sync\n");
849 error("Everything is broken - not even the default map list works. Please report this to the developers.");
861 When the player presses attack or jump, change to the next level
864 .float autoscreenshot;
865 void() MapVote_Start;
866 void() MapVote_Think;
867 float mapvote_initialized;
868 void IntermissionThink()
870 FixIntermissionClient(self);
872 if(cvar("sv_autoscreenshot"))
873 if(self.autoscreenshot > 0)
874 if(time > self.autoscreenshot)
876 self.autoscreenshot = -1;
877 if(clienttype(self) == CLIENTTYPE_REAL)
878 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
882 if (time < intermission_exittime)
885 if(!mapvote_initialized)
886 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
896 Returns the entity to view from
900 entity FindIntermission()
905 // look for info_intermission first
906 spot = find (world, classname, "info_intermission");
908 { // pick a random one
912 spot = find (spot, classname, "info_intermission");
914 spot = find (spot, classname, "info_intermission");
920 // then look for the start position
921 spot = find (world, classname, "info_player_start");
925 // testinfo_player_start is only found in regioned levels
926 spot = find (world, classname, "testplayerstart");
930 // then look for the start position
931 spot = find (world, classname, "info_player_deathmatch");
935 //objerror ("FindIntermission: no spot");
941 ===============================================================================
945 ===============================================================================
948 void DumpStats(float final)
952 local float to_console;
953 local float to_eventlog;
957 to_console = cvar("sv_logscores_console");
958 to_eventlog = cvar("sv_eventlog");
959 to_file = cvar("sv_logscores_file");
963 to_console = TRUE; // always print printstats replies
964 to_eventlog = FALSE; // but never print them to the event log
968 if(cvar("sv_eventlog_console"))
969 to_console = FALSE; // otherwise we get the output twice
975 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
983 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
987 fputs(file, strcat(s, "\n"));
990 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
996 fputs(file, strcat(s, "\n"));
998 FOR_EACH_CLIENT(other)
1000 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
1002 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
1003 s = strcat(s, ftos(rint(time - other.jointime)), ":");
1004 if(other.classname == "player" || g_arena || g_lms)
1005 s = strcat(s, ftos(other.team), ":");
1007 s = strcat(s, "spectator:");
1010 print(s, other.netname, "\n");
1012 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
1014 fputs(file, strcat(s, other.netname, "\n"));
1020 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
1026 fputs(file, strcat(s, "\n"));
1028 for(i = 1; i < 16; ++i)
1030 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
1031 s = strcat(s, ":", ftos(i));
1037 fputs(file, strcat(s, "\n"));
1044 GameLogEcho(":end");
1047 fputs(file, ":end\n");
1052 void FixIntermissionClient(entity e)
1055 if(!e.autoscreenshot) // initial call
1057 e.angles = e.v_angle;
1058 e.angles_x = -e.angles_x;
1059 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1061 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1062 e.solid = SOLID_NOT;
1063 e.movetype = MOVETYPE_NONE;
1064 e.takedamage = DAMAGE_NO;
1066 e.weaponentity.effects = EF_NODRAW;
1067 if(clienttype(e) == CLIENTTYPE_REAL)
1069 stuffcmd(e, "\nscr_printspeed 1000000\n");
1070 s = cvar_string("sv_intermission_cdtrack");
1072 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1074 WriteByte(MSG_ONE, SVC_INTERMISSION);
1078 //e.velocity = '0 0 0';
1079 //e.fixangle = TRUE;
1081 // TODO halt weapon animation
1086 go to the next level for deathmatch
1087 only called if a time or frag limit has expired
1091 float minTotalFrags;
1092 float maxTotalFrags;
1098 intermission_running = 1;
1100 // enforce a wait time before allowing changelevel
1101 if(player_count > 0)
1102 intermission_exittime = time + cvar("sv_mapchange_delay");
1104 intermission_exittime = -1;
1107 WriteByte (MSG_ALL, SVC_CDTRACK);
1108 WriteByte (MSG_ALL, 3);
1109 WriteByte (MSG_ALL, 3);
1110 // done in FixIntermission
1113 //pos = FindIntermission ();
1119 if(cvar("sv_eventlog"))
1120 GameLogEcho(":gameover");
1124 FOR_EACH_CLIENT(other)
1126 FixIntermissionClient(other);
1129 bprint(other.netname, " ^7wins.\n");
1134 FOR_EACH_PLAYER(other)
1136 if(maxTotalFrags < other.totalfrags)
1137 maxTotalFrags = other.totalfrags;
1138 if(minTotalFrags > other.totalfrags)
1139 minTotalFrags = other.totalfrags;
1144 FOR_EACH_PLAYER(other)
1146 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1147 f = bound(0, other.play_time / max(time, 1), 1);
1148 // store some statistics?
1152 if(cvar("g_campaign"))
1153 CampaignPreIntermission();
1155 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1162 Exit deathmatch games upon conditions
1165 void CheckRules_Player()
1167 if (gameover) // someone else quit the game already
1170 if(self.deadflag == DEAD_NO)
1171 self.play_time += frametime;
1173 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1174 // (div0: and that in CheckRules_World please)
1177 float checkrules_oneminutewarning;
1179 float checkrules_equality;
1180 float checkrules_overtimewarning;
1181 float checkrules_overtimeend;
1183 void InitiateOvertime()
1185 if(!checkrules_overtimeend)
1186 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1189 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1190 float WINNING_YES = 1; // winner found
1191 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1192 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1194 float GetWinningCode(float fraglimitreached, float equality)
1197 if(fraglimitreached)
1198 return WINNING_STARTOVERTIME;
1200 return WINNING_NEVER;
1202 if(fraglimitreached)
1208 // set the .winning flag for exactly those players with a given field value
1209 void SetWinners(.float field, float value)
1212 FOR_EACH_PLAYER(head)
1213 head.winning = (head.field == value);
1216 // set the .winning flag for those players with a given field value
1217 void AddWinners(.float field, float value)
1220 FOR_EACH_PLAYER(head)
1221 if(head.field == value)
1225 // clear the .winning flags
1226 void ClearWinners(void)
1229 FOR_EACH_PLAYER(head)
1233 // Onslaught winning condition:
1234 // game terminates if only one team has a working generator (or none)
1235 float WinningCondition_Onslaught()
1238 local float t1, t2, t3, t4;
1240 WinningConditionHelper(); // set worldstatus
1242 // first check if the game has ended
1243 t1 = t2 = t3 = t4 = 0;
1244 head = find(world, classname, "onslaught_generator");
1247 if (head.health > 0)
1249 if (head.team == COLOR_TEAM1) t1 = 1;
1250 if (head.team == COLOR_TEAM2) t2 = 1;
1251 if (head.team == COLOR_TEAM3) t3 = 1;
1252 if (head.team == COLOR_TEAM4) t4 = 1;
1254 head = find(head, classname, "onslaught_generator");
1256 if (t1 + t2 + t3 + t4 < 2)
1258 // game over, only one team remains (or none)
1260 if (t1) SetWinners(team, COLOR_TEAM1);
1261 if (t2) SetWinners(team, COLOR_TEAM2);
1262 if (t3) SetWinners(team, COLOR_TEAM3);
1263 if (t4) SetWinners(team, COLOR_TEAM4);
1264 dprint("Have a winner, ending game.\n");
1268 // Two or more teams remain
1272 float LMS_NewPlayerLives()
1275 fl = cvar("fraglimit");
1279 // first player has left the game for dying too much? Nobody else can get in.
1280 if(lms_lowest_lives < 1)
1283 if(!cvar("g_lms_join_anytime"))
1284 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1287 return bound(1, lms_lowest_lives, fl);
1290 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1291 // they win. Otherwise the defending team wins once the timelimit passes.
1292 void assault_new_round();
1293 float WinningCondition_Assault()
1297 WinningConditionHelper(); // set worldstatus
1299 status = WINNING_NO;
1300 // as the timelimit has not yet passed just assume the defending team will win
1301 if(assault_attacker_team == COLOR_TEAM1)
1303 SetWinners(team, COLOR_TEAM2);
1307 SetWinners(team, COLOR_TEAM1);
1311 ent = find(world, classname, "target_assault_roundend");
1314 if(ent.winning) // round end has been triggered by attacking team
1316 bprint("ASSAULT: round completed...\n");
1317 SetWinners(team, assault_attacker_team);
1319 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
1321 if(ent.cnt == 1) // this was the second round
1323 status = WINNING_YES;
1327 local entity oldself;
1330 assault_new_round();
1339 // LMS winning condition: game terminates if and only if there's at most one
1340 // one player who's living lives. Top two scores being equal cancels the time
1342 float WinningCondition_LMS()
1349 have_player = FALSE;
1350 have_players = FALSE;
1351 l = LMS_NewPlayerLives();
1353 head = find(world, classname, "player");
1356 head2 = find(head, classname, "player");
1358 have_players = TRUE;
1362 // we have at least one player
1365 // two or more active players - continue with the game
1369 // exactly one player?
1372 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1376 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1382 // and assign him his first place
1383 PlayerScore_Add(head, SP_LMS_RANK, 1);
1390 // nobody is playing at all...
1393 // wait for players...
1397 // SNAFU (maybe a draw game?)
1399 dprint("No players, ending game.\n");
1404 // When we get here, we have at least two players who are actually LIVING,
1405 // now check if the top two players have equal score.
1406 WinningConditionHelper();
1409 if(WinningConditionHelper_winner)
1410 WinningConditionHelper_winner.winning = TRUE;
1411 if(WinningConditionHelper_equality)
1412 return WINNING_NEVER;
1414 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1418 void ShuffleMaplist()
1426 result = cvar_string("g_maplist");
1427 litems = tokenizebyseparator(result, " ");
1429 for(start = 0; start < litems - 1; ++start)
1433 // select a random item
1434 selected = floor(random() * (litems - start) + start);
1436 // shift this item to the place start
1437 for(i = 0; i < start; ++i)
1438 result = strcat(result, " ", argv(i));
1439 result = strcat(result, " ", argv(selected));
1440 for(i = start; i < litems; ++i)
1442 result = strcat(result, " ", argv(i));
1443 result = substring(result, 1, strlen(result) - 1);
1445 litems = tokenizebyseparator(result, " ");
1447 //dprint(result, "\n");
1450 cvar_set("g_maplist", result);
1454 float WinningCondition_Scores(float limit)
1456 // TODO make everything use THIS winning condition (except LMS)
1457 WinningConditionHelper();
1461 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1462 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1463 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1464 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1468 if(WinningConditionHelper_winner)
1469 WinningConditionHelper_winner.winning = 1;
1470 if(WinningConditionHelper_winnerteam >= 0)
1471 SetWinners(team, WinningConditionHelper_winnerteam);
1473 if(WinningConditionHelper_lowerisbetter)
1475 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1479 if(g_dm || (g_ctf && g_ctf_win_mode != 2) || g_tdm || g_arena || (g_race && !g_race_qualifying))
1480 // these modes always score in increments of 1, thus this makes sense
1482 if(leaderfrags != WinningConditionHelper_topscore)
1484 leaderfrags = WinningConditionHelper_topscore;
1486 if (leaderfrags == limit - 1)
1487 play2all("announcer/robotic/1fragleft.wav");
1488 else if (leaderfrags == limit - 2)
1489 play2all("announcer/robotic/2fragsleft.wav");
1490 else if (leaderfrags == limit - 3)
1491 play2all("announcer/robotic/3fragsleft.wav");
1495 return GetWinningCode(limit && WinningConditionHelper_topscore && (WinningConditionHelper_topscore >= limit), WinningConditionHelper_equality);
1498 float WinningCondition_Race(float fraglimit)
1502 wc = WinningCondition_Scores(fraglimit);
1504 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1505 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1506 // do NOT support equality when the laps are all raced!
1509 if not(p.race_completed)
1510 return WINNING_STARTOVERTIME;
1516 void ReadyRestart();
1517 float WinningCondition_QualifyingThenRace(float limit)
1520 wc = WinningCondition_Scores(limit);
1522 // NEVER initiate overtime
1523 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1531 float WinningCondition_RanOutOfSpawns()
1535 if(!have_team_spawns)
1538 if(!some_spawn_has_been_used)
1541 team1_score = team2_score = team3_score = team4_score = 0;
1543 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1545 if(head.team == COLOR_TEAM1)
1547 else if(head.team == COLOR_TEAM2)
1549 else if(head.team == COLOR_TEAM3)
1551 else if(head.team == COLOR_TEAM4)
1555 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1557 if(head.team == COLOR_TEAM1)
1559 else if(head.team == COLOR_TEAM2)
1561 else if(head.team == COLOR_TEAM3)
1563 else if(head.team == COLOR_TEAM4)
1568 if(team1_score + team2_score + team3_score + team4_score == 0)
1570 checkrules_equality = TRUE;
1573 else if(team1_score + team2_score + team3_score + team4_score == 1)
1576 if(team1_score) t = COLOR_TEAM1;
1577 if(team2_score) t = COLOR_TEAM2;
1578 if(team3_score) t = COLOR_TEAM3;
1579 if(team4_score) t = COLOR_TEAM4;
1580 CheckAllowedTeams(world);
1581 for(i = 0; i < MAX_TEAMSCORE; ++i)
1583 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
1584 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
1585 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
1586 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
1589 AddWinners(team, t);
1600 Exit deathmatch games upon conditions
1603 void CheckRules_World()
1606 local float timelimit;
1607 local float fraglimit;
1615 MapVote_Think should now do that part
1616 if (intermission_running)
1617 if (time >= intermission_exittime + 60)
1619 if(!DoNextMapOverride())
1625 if (gameover) // someone else quit the game already
1627 if(player_count == 0) // Nobody there? Then let's go to the next map
1629 // this will actually check the player count in the next frame
1630 // again, but this shouldn't hurt
1634 timelimit = cvar("timelimit") * 60;
1635 fraglimit = cvar("fraglimit");
1637 if(inWarmupStage || time <= game_starttime) // NOTE: this is <= to prevent problems in the very tic where the game starts
1640 timelimit = 0; // timelimit is not made for warmup
1642 fraglimit = 0; // no fraglimit for now
1646 timelimit += game_starttime;
1648 if(checkrules_overtimeend)
1650 if(!checkrules_overtimewarning)
1652 checkrules_overtimewarning = TRUE;
1653 //announceall("announcer/robotic/1minuteremains.wav");
1654 if(g_race && !g_race_qualifying)
1655 bcenterprint("^3Everyone, finish your lap! The race is over!");
1657 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1662 if (timelimit && time >= timelimit)
1664 if(g_race && g_race_qualifying == 2 && timelimit > 0)
1667 float playerswithlaps;
1670 totalplayers = playerswithlaps = readyplayers = 0;
1671 FOR_EACH_PLAYER(head)
1674 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
1680 // at least 2/3 of the players have completed a lap: start the RACE
1681 // otherwise, the players should end the qualifying on their own
1682 if(readyplayers || ((totalplayers >= 3) && (playerswithlaps * 3 >= totalplayers * 2)))
1684 checkrules_overtimeend = 0;
1685 ReadyRestart(); // go to race
1695 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1701 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1703 checkrules_oneminutewarning = TRUE;
1704 play2all("announcer/robotic/1minuteremains.wav");
1707 status = WinningCondition_RanOutOfSpawns();
1708 if(status == WINNING_YES)
1710 bprint("Hey! Someone ran out of spawns!\n");
1712 else if(g_race && !g_race_qualifying && timelimit >= 0)
1714 status = WinningCondition_Race(fraglimit);
1716 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
1718 status = WinningCondition_QualifyingThenRace(fraglimit);
1722 status = WinningCondition_Assault(); // TODO remove this?
1726 status = WinningCondition_LMS();
1728 else if (g_onslaught)
1730 status = WinningCondition_Onslaught(); // TODO remove this?
1734 status = WinningCondition_Scores(fraglimit);
1737 if(status == WINNING_STARTOVERTIME)
1739 status = WINNING_NEVER;
1743 if(status == WINNING_NEVER)
1744 // equality cases! Nobody wins if the overtime ends in a draw.
1747 if(checkrules_overtimeend)
1748 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1749 status = WINNING_YES;
1751 if(status == WINNING_YES)
1755 float mapvote_nextthink;
1756 float mapvote_initialized;
1757 float mapvote_keeptwotime;
1758 float mapvote_timeout;
1759 string mapvote_message;
1760 string mapvote_screenshot_dir;
1762 float mapvote_count;
1763 float mapvote_count_real;
1764 string mapvote_maps[MAPVOTE_COUNT];
1765 float mapvote_maps_suggested[MAPVOTE_COUNT];
1766 string mapvote_suggestions[MAPVOTE_COUNT];
1767 float mapvote_suggestion_ptr;
1768 float mapvote_maxlen;
1769 float mapvote_voters;
1770 float mapvote_votes[MAPVOTE_COUNT];
1772 float mapvote_detail;
1773 float mapvote_abstain;
1774 float mapvote_dirty;
1777 void MapVote_ClearAllVotes()
1779 FOR_EACH_CLIENT(other)
1783 string MapVote_Suggest(string m)
1787 return "That's not how to use this command.";
1788 if(!cvar("g_maplist_votable_suggestions"))
1789 return "Suggestions are not accepted on this server.";
1790 if(mapvote_initialized)
1791 return "Can't suggest - voting is already in progress!";
1792 m = MapInfo_FixName(m);
1794 return "The map you suggested is not available on this server.";
1795 if(!cvar("g_maplist_votable_override_mostrecent"))
1797 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1799 if(!MapInfo_CheckMap(m))
1800 return "The map you suggested does not support the current game mode.";
1801 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1802 if(mapvote_suggestions[i] == m)
1803 return "This map was already suggested.";
1804 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1806 i = floor(random() * mapvote_suggestion_ptr);
1810 i = mapvote_suggestion_ptr;
1811 mapvote_suggestion_ptr += 1;
1813 if(mapvote_suggestions[i] != "")
1814 strunzone(mapvote_suggestions[i]);
1815 mapvote_suggestions[i] = strzone(m);
1816 if(cvar("sv_eventlog"))
1817 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
1818 return strcat("Suggestion of ", m, " accepted.");
1821 void MapVote_AddVotable(string nextMap, float isSuggestion)
1826 for(j = 0; j < mapvote_count; ++j)
1827 if(mapvote_maps[j] == nextMap)
1829 if(strlen(nextMap) > mapvote_maxlen)
1830 mapvote_maxlen = strlen(nextMap);
1831 mapvote_maps[mapvote_count] = strzone(nextMap);
1832 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1836 void MapVote_SendData(float target);
1842 MapVote_ClearAllVotes();
1845 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1846 mapvote_abstain = cvar("g_maplist_votable_abstain");
1849 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1851 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1852 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
1854 if(mapvote_suggestion_ptr)
1855 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1856 MapVote_AddVotable(mapvote_suggestions[floor(random() * mapvote_suggestion_ptr)], TRUE);
1858 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1859 MapVote_AddVotable(GetNextMap(), FALSE);
1861 if(mapvote_count == 0)
1863 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1864 cvar_set("g_maplist", MapInfo_ListAllowedMaps(0, MAPINFO_FLAG_HIDDEN));
1865 localcmd("\nmenu_cmd sync\n");
1866 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1867 MapVote_AddVotable(GetNextMap(), FALSE);
1870 mapvote_count_real = mapvote_count;
1872 MapVote_AddVotable("don't care", 0);
1874 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1876 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1877 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1878 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1879 mapvote_keeptwotime = 0;
1880 mapvote_message = "Choose a map and press its key!";
1882 mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
1883 if(mapvote_screenshot_dir == "")
1884 mapvote_screenshot_dir = "maps";
1885 mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
1887 if(!cvar("g_maplist_textonly"))
1888 MapVote_SendData(MSG_ALL);
1891 void MapVote_SendPicture(float id)
1894 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1895 WriteByte(MSG_ONE, TE_CSQC_MAPVOTE);
1896 WriteByte(MSG_ONE, MAPVOTE_NET_PIC);
1897 WriteByte(MSG_ONE, id);
1898 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 3072);
1901 float GameCommand_MapVote(string cmd)
1903 if(!intermission_running)
1905 if(!cvar("g_maplist_textonly"))
1907 if(cmd == "mv_getpic")
1909 MapVote_SendPicture(stof(argv(1)));
1917 float MapVote_GetMapMask()
1919 float mask, i, power;
1921 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
1922 if(mapvote_maps[i] != "")
1927 void MapVote_SendData(float targ)
1929 string mapfile, pakfile;
1931 WriteByte(targ, SVC_TEMPENTITY);
1932 WriteByte(targ, TE_CSQC_CONFIG);
1933 WriteString(targ, "mv_screenshot_dir");
1934 WriteString(targ, mapvote_screenshot_dir);
1936 WriteByte(targ, SVC_TEMPENTITY);
1937 WriteByte(targ, TE_CSQC_MAPVOTE);
1938 WriteByte(targ, MAPVOTE_NET_INIT);
1940 WriteByte(targ, mapvote_count);
1941 WriteByte(targ, mapvote_abstain);
1942 WriteByte(targ, mapvote_detail);
1943 WriteCoord(targ, mapvote_timeout);
1944 if(mapvote_count <= 8)
1945 WriteByte(targ, MapVote_GetMapMask());
1947 WriteShort(targ, MapVote_GetMapMask());
1948 for(i = 0; i < mapvote_count; ++i)
1949 if(mapvote_maps[i] != "")
1951 WriteString(targ, mapvote_maps[i]);
1952 mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
1953 pakfile = whichpack(strcat(mapfile, ".tga"));
1955 pakfile = whichpack(strcat(mapfile, ".jpg"));
1957 pakfile = whichpack(strcat(mapfile, ".png"));
1958 print("pakfile is ", pakfile, "\n");
1959 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
1960 pakfile = substring(pakfile, o, 999);
1961 WriteString(targ, pakfile);
1965 void MapVote_UpdateData(float targ)
1968 WriteByte(targ, SVC_TEMPENTITY);
1969 WriteByte(targ, TE_CSQC_MAPVOTE);
1970 WriteByte(targ, MAPVOTE_NET_UPDATE);
1971 if(mapvote_count <= 8)
1972 WriteByte(targ, MapVote_GetMapMask());
1974 WriteShort(targ, MapVote_GetMapMask());
1976 for(i = 0; i < mapvote_count; ++i)
1977 if(mapvote_maps[i] != "")
1978 WriteByte(targ, mapvote_votes[i]);
1981 void MapVote_TellVote(float targ, float vote)
1983 WriteByte(targ, SVC_TEMPENTITY);
1984 WriteByte(targ, TE_CSQC_MAPVOTE);
1985 WriteByte(targ, MAPVOTE_NET_OWNVOTE);
1986 WriteByte(targ, vote);
1989 float MapVote_Finished(float mappos)
1995 if(cvar("sv_eventlog"))
1997 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1998 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1999 didntvote = mapvote_voters;
2000 for(i = 0; i < mapvote_count; ++i)
2001 if(mapvote_maps[i] != "")
2003 didntvote -= mapvote_votes[i];
2006 result = strcat(result, ":", mapvote_maps[i]);
2007 result = strcat(result, ":", ftos(mapvote_votes[i]));
2010 result = strcat(result, ":didn't vote:", ftos(didntvote));
2012 GameLogEcho(result);
2013 if(mapvote_maps_suggested[mappos])
2014 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
2017 FOR_EACH_REALCLIENT(other)
2018 FixClientCvars(other);
2020 Map_Goto_SetStr(mapvote_maps[mappos]);
2022 alreadychangedlevel = TRUE;
2025 void MapVote_CheckRules_1()
2029 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2031 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2032 mapvote_votes[i] = 0;
2036 FOR_EACH_REALCLIENT(other)
2041 i = other.mapvote - 1;
2042 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2043 mapvote_votes[i] = mapvote_votes[i] + 1;
2048 float MapVote_CheckRules_2()
2051 float firstPlace, secondPlace;
2052 float firstPlaceVotes, secondPlaceVotes;
2053 float mapvote_voters_real;
2056 mapvote_voters_real = mapvote_voters;
2058 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2060 RandomSelection_Init();
2061 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2062 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2063 firstPlace = RandomSelection_chosen_float;
2064 firstPlaceVotes = RandomSelection_best_priority;
2065 //dprint("First place: ", ftos(firstPlace), "\n");
2066 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2068 RandomSelection_Init();
2069 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2071 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2072 secondPlace = RandomSelection_chosen_float;
2073 secondPlaceVotes = RandomSelection_best_priority;
2074 //dprint("Second place: ", ftos(secondPlace), "\n");
2075 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2077 if(firstPlace == -1)
2078 error("No first place in map vote... WTF?");
2080 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2081 return MapVote_Finished(firstPlace);
2083 if(mapvote_keeptwotime)
2084 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2087 mapvote_dirty = TRUE;
2088 mapvote_message = "Now decide between the TOP TWO!";
2089 mapvote_keeptwotime = 0;
2090 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2091 result = strcat(result, ":", ftos(firstPlaceVotes));
2092 result = strcat(result, ":", mapvote_maps[secondPlace]);
2093 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2094 didntvote = mapvote_voters;
2095 for(i = 0; i < mapvote_count; ++i)
2096 if(mapvote_maps[i] != "")
2098 didntvote -= mapvote_votes[i];
2100 if(i != secondPlace)
2102 result = strcat(result, ":", mapvote_maps[i]);
2103 result = strcat(result, ":", ftos(mapvote_votes[i]));
2104 if(i < mapvote_count_real)
2106 strunzone(mapvote_maps[i]);
2107 mapvote_maps[i] = "";
2111 result = strcat(result, ":didn't vote:", ftos(didntvote));
2112 if(cvar("sv_eventlog"))
2113 GameLogEcho(result);
2126 keeptwo = mapvote_keeptwotime;
2127 MapVote_CheckRules_1(); // count
2128 if(MapVote_CheckRules_2()) // decide
2132 FOR_EACH_REALCLIENT(other)
2134 // hide scoreboard again
2135 if(other.health != 2342)
2137 other.health = 2342;
2139 if(clienttype(other) == CLIENTTYPE_REAL)
2141 if(cvar("g_maplist_textonly"))
2142 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");
2145 WriteByte(MSG_ONE, SVC_FINALE);
2146 WriteString(MSG_ONE, "");
2150 // notify about keep-two
2151 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2152 play2(other, "misc/invshot.wav");
2154 // clear possibly invalid votes
2155 if(mapvote_maps[other.mapvote - 1] == "")
2157 // use impulses as new vote
2158 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2159 if(mapvote_maps[other.impulse - 1] != "")
2161 other.mapvote = other.impulse;
2163 mapvote_dirty = TRUE;
2166 MapVote_TellVote(MSG_ONE, other.mapvote);
2174 MapVote_CheckRules_1(); // just count
2176 if(!cvar("g_maplist_textonly"))
2177 if(mapvote_dirty) // 1 if "keeptwo" or "impulse" happened before
2179 MapVote_UpdateData(MSG_BROADCAST);
2180 mapvote_dirty = FALSE;
2183 if(cvar("g_maplist_textonly"))
2185 FOR_EACH_REALCLIENT(other)
2187 // display voting screen
2188 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2189 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2191 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2192 msgstr = strcat(msgstr, mapvote_message);
2193 msgstr = strcat(msgstr, "\n\n");
2194 for(i = 0; i < mapvote_count; ++i)
2195 if(mapvote_maps[i] == "")
2196 msgstr = strcat(msgstr, "\n");
2199 tmp = mapvote_maps[i];
2200 tmp = strpad(mapvote_maxlen, tmp);
2201 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2204 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2205 if(mapvote_votes[i] != 1)
2206 tmp = strcat(tmp, "s");
2207 tmp = strcat(tmp, ")");
2208 tmp = strpad(mapvote_maxlen + 15, tmp);
2211 if(i == mapvote_count - 1)
2212 msgstr = strcat(msgstr, "\n");
2213 if(other.mapvote == i + 1)
2214 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2216 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2219 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2221 msgstr = strcat(msgstr, "s");
2222 msgstr = strcat(msgstr, " cast");
2223 i = ceil(mapvote_timeout - time);
2224 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2226 msgstr = strcat(msgstr, "s");
2227 msgstr = strcat(msgstr, " left");
2229 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2233 void MapVote_Start()
2238 MapInfo_Enumerate();
2239 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0, (g_maplist_allow_hidden ? MAPINFO_FLAG_HIDDEN : 0), 1))
2242 void MapVote_Think()
2247 if(alreadychangedlevel)
2250 if(time < mapvote_nextthink)
2254 mapvote_nextthink = time + 0.5;
2256 if(!mapvote_initialized)
2258 mapvote_initialized = TRUE;
2259 if(DoNextMapOverride())
2261 if(!cvar("g_maplist_votable") || player_count <= 0)
2272 string GotoMap(string m)
2274 if(!MapInfo_CheckMap(m))
2275 return "The map you chose is not available on this server.";
2276 cvar_set("nextmap", m);
2277 cvar_set("timelimit", "-1");
2278 if(mapvote_initialized || alreadychangedlevel)
2280 if(DoNextMapOverride())
2281 return "Map switch initiated.";
2283 return "Hm... no. For some reason I like THIS map more.";
2286 return "Map switch will happen after scoreboard.";
2292 FOR_EACH_REALCLIENT(self)
2294 if(self.classname == "spectator")
2296 if(self.enemy.typehitsound)
2297 play2(self, "misc/typehit.wav");
2298 else if(self.enemy.hitsound)
2299 play2(self, "misc/hit.wav");
2303 if(self.typehitsound)
2304 play2(self, "misc/typehit.wav");
2305 else if(self.hitsound)
2306 play2(self, "misc/hit.wav");
2309 FOR_EACH_CLIENT(self)
2311 self.hitsound = FALSE;
2312 self.typehitsound = FALSE;
2319 * returns TRUE if redirecting
2321 float redirection_timeout;
2322 float redirection_nextthink;
2323 float RedirectionThink()
2325 float clients_found;
2327 if(redirection_target == "")
2330 if(!redirection_timeout)
2332 cvar_set("sv_public", "-2");
2333 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2334 if(redirection_target == "self")
2335 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2337 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2340 if(time < redirection_nextthink)
2343 redirection_nextthink = time + 1;
2346 FOR_EACH_REALCLIENT(self)
2348 print("Redirecting: sending connect command to ", self.netname, "\n");
2349 if(redirection_target == "self")
2350 stuffcmd(self, "\ndisconnect; reconnect\n");
2352 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2356 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2358 if(time > redirection_timeout || clients_found == 0)
2359 localcmd("\nwait; wait; wait; quit\n");
2366 // Loaded from a save game
2367 // some things then break, so let's work around them...
2369 // Progs DB (capture records)
2371 ServerProgsDB = db_create();
2373 ServerProgsDB = db_load("server.db");
2377 MapInfo_Enumerate();
2378 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0, (g_maplist_allow_hidden ? MAPINFO_FLAG_HIDDEN : 0), 1);
2383 if(world_initialized > 0)
2385 world_initialized = 0;
2386 print("Saving persistent data...\n");
2389 db_save(ServerProgsDB, "server.db");
2390 if(cvar("developer"))
2391 db_save(TemporaryDB, "server-temp.db");
2392 db_close(ServerProgsDB);
2393 db_close(TemporaryDB);
2395 // tell the bot system the game is ending now
2400 else if(world_initialized == 0)
2402 print("NOTE: crashed before even initializing the world, not saving persistent data\n");