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 print_to(entity e, string s)
1421 sprint(e, strcat(s, "\n"));
1426 void ShuffleMaplist()
1434 result = cvar_string("g_maplist");
1435 litems = tokenizebyseparator(result, " ");
1437 for(start = 0; start < litems - 1; ++start)
1441 // select a random item
1442 selected = floor(random() * (litems - start) + start);
1444 // shift this item to the place start
1445 for(i = 0; i < start; ++i)
1446 result = strcat(result, " ", argv(i));
1447 result = strcat(result, " ", argv(selected));
1448 for(i = start; i < litems; ++i)
1450 result = strcat(result, " ", argv(i));
1451 result = substring(result, 1, strlen(result) - 1);
1453 litems = tokenizebyseparator(result, " ");
1455 //dprint(result, "\n");
1458 cvar_set("g_maplist", result);
1461 float WinningCondition_Scores(float limit)
1463 // TODO make everything use THIS winning condition (except LMS)
1464 WinningConditionHelper();
1468 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1469 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1470 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1471 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1475 if(WinningConditionHelper_winner)
1476 WinningConditionHelper_winner.winning = 1;
1477 if(WinningConditionHelper_winnerteam >= 0)
1478 SetWinners(team, WinningConditionHelper_winnerteam);
1480 if(WinningConditionHelper_lowerisbetter)
1482 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1486 return GetWinningCode(limit && WinningConditionHelper_topscore && (WinningConditionHelper_topscore >= limit), WinningConditionHelper_equality);
1489 float WinningCondition_Race(float fraglimit)
1493 wc = WinningCondition_Scores(fraglimit);
1495 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1496 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1497 // do NOT support equality when the laps are all raced!
1500 if not(p.race_completed)
1501 return WINNING_STARTOVERTIME;
1507 void ReadyRestart();
1508 float WinningCondition_QualifyingThenRace(float limit)
1511 wc = WinningCondition_Scores(limit);
1513 // NEVER initiate overtime
1514 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1522 float WinningCondition_RanOutOfSpawns()
1526 if(!have_team_spawns)
1529 if(!some_spawn_has_been_used)
1532 team1_score = team2_score = team3_score = team4_score = 0;
1534 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1536 if(head.team == COLOR_TEAM1)
1538 else if(head.team == COLOR_TEAM2)
1540 else if(head.team == COLOR_TEAM3)
1542 else if(head.team == COLOR_TEAM4)
1546 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1548 if(head.team == COLOR_TEAM1)
1550 else if(head.team == COLOR_TEAM2)
1552 else if(head.team == COLOR_TEAM3)
1554 else if(head.team == COLOR_TEAM4)
1559 if(team1_score + team2_score + team3_score + team4_score == 0)
1561 checkrules_equality = TRUE;
1564 else if(team1_score + team2_score + team3_score + team4_score == 1)
1567 if(team1_score) t = COLOR_TEAM1;
1568 if(team2_score) t = COLOR_TEAM2;
1569 if(team3_score) t = COLOR_TEAM3;
1570 if(team4_score) t = COLOR_TEAM4;
1571 CheckAllowedTeams(world);
1572 for(i = 0; i < MAX_TEAMSCORE; ++i)
1574 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
1575 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
1576 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
1577 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
1580 AddWinners(team, t);
1591 Exit deathmatch games upon conditions
1594 void CheckRules_World()
1597 local float timelimit;
1598 local float fraglimit;
1606 MapVote_Think should now do that part
1607 if (intermission_running)
1608 if (time >= intermission_exittime + 60)
1610 if(!DoNextMapOverride())
1616 if (gameover) // someone else quit the game already
1618 if(player_count == 0) // Nobody there? Then let's go to the next map
1620 // this will actually check the player count in the next frame
1621 // again, but this shouldn't hurt
1625 timelimit = cvar("timelimit") * 60;
1626 fraglimit = cvar("fraglimit");
1628 if(inWarmupStage || time <= game_starttime) // NOTE: this is <= to prevent problems in the very tic where the game starts
1631 timelimit = 0; // timelimit is not made for warmup
1633 fraglimit = 0; // no fraglimit for now
1637 timelimit += game_starttime;
1639 if(checkrules_overtimeend)
1641 if(!checkrules_overtimewarning)
1643 checkrules_overtimewarning = TRUE;
1644 //announceall("announcer/robotic/1minuteremains.wav");
1645 if(g_race && !g_race_qualifying)
1646 bcenterprint("^3Everyone, finish your lap! The race is over!");
1648 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1653 if (timelimit && time >= timelimit)
1655 if(g_race && g_race_qualifying == 2 && timelimit > 0)
1658 float playerswithlaps;
1661 totalplayers = playerswithlaps = readyplayers = 0;
1662 FOR_EACH_PLAYER(head)
1665 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
1671 // at least 2/3 of the players have completed a lap: start the RACE
1672 // otherwise, the players should end the qualifying on their own
1673 if(readyplayers || ((totalplayers >= 3) && (playerswithlaps * 3 >= totalplayers * 2)))
1675 checkrules_overtimeend = 0;
1676 ReadyRestart(); // go to race
1686 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1692 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1694 checkrules_oneminutewarning = TRUE;
1695 play2all("announcer/robotic/1minuteremains.wav");
1698 status = WinningCondition_RanOutOfSpawns();
1699 if(status == WINNING_YES)
1701 bprint("Hey! Someone ran out of spawns!\n");
1703 else if(g_race && !g_race_qualifying && timelimit >= 0)
1705 status = WinningCondition_Race(fraglimit);
1707 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
1709 status = WinningCondition_QualifyingThenRace(fraglimit);
1713 status = WinningCondition_Assault(); // TODO remove this?
1717 status = WinningCondition_LMS();
1719 else if (g_onslaught)
1721 status = WinningCondition_Onslaught(); // TODO remove this?
1725 status = WinningCondition_Scores(fraglimit);
1728 if(status == WINNING_STARTOVERTIME)
1730 status = WINNING_NEVER;
1734 if(status == WINNING_NEVER)
1735 // equality cases! Nobody wins if the overtime ends in a draw.
1738 if(checkrules_overtimeend)
1739 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1740 status = WINNING_YES;
1742 if(status == WINNING_YES)
1746 float mapvote_nextthink;
1747 float mapvote_initialized;
1748 float mapvote_keeptwotime;
1749 float mapvote_timeout;
1750 string mapvote_message;
1751 string mapvote_screenshot_dir;
1753 float mapvote_count;
1754 float mapvote_count_real;
1755 string mapvote_maps[MAPVOTE_COUNT];
1756 float mapvote_maps_suggested[MAPVOTE_COUNT];
1757 string mapvote_suggestions[MAPVOTE_COUNT];
1758 float mapvote_suggestion_ptr;
1759 float mapvote_maxlen;
1760 float mapvote_voters;
1761 float mapvote_votes[MAPVOTE_COUNT];
1763 float mapvote_detail;
1764 float mapvote_abstain;
1765 float mapvote_dirty;
1768 void MapVote_ClearAllVotes()
1770 FOR_EACH_CLIENT(other)
1774 string MapVote_Suggest(string m)
1778 return "That's not how to use this command.";
1779 if(!cvar("g_maplist_votable_suggestions"))
1780 return "Suggestions are not accepted on this server.";
1781 if(mapvote_initialized)
1782 return "Can't suggest - voting is already in progress!";
1783 m = MapInfo_FixName(m);
1785 return "The map you suggested is not available on this server.";
1786 if(!cvar("g_maplist_votable_override_mostrecent"))
1788 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1790 if(!MapInfo_CheckMap(m))
1791 return "The map you suggested does not support the current game mode.";
1792 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1793 if(mapvote_suggestions[i] == m)
1794 return "This map was already suggested.";
1795 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1797 i = floor(random() * mapvote_suggestion_ptr);
1801 i = mapvote_suggestion_ptr;
1802 mapvote_suggestion_ptr += 1;
1804 if(mapvote_suggestions[i] != "")
1805 strunzone(mapvote_suggestions[i]);
1806 mapvote_suggestions[i] = strzone(m);
1807 if(cvar("sv_eventlog"))
1808 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
1809 return strcat("Suggestion of ", m, " accepted.");
1812 void MapVote_AddVotable(string nextMap, float isSuggestion)
1817 for(j = 0; j < mapvote_count; ++j)
1818 if(mapvote_maps[j] == nextMap)
1820 if(strlen(nextMap) > mapvote_maxlen)
1821 mapvote_maxlen = strlen(nextMap);
1822 mapvote_maps[mapvote_count] = strzone(nextMap);
1823 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1827 void MapVote_SendData(float target);
1833 MapVote_ClearAllVotes();
1836 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1837 mapvote_abstain = cvar("g_maplist_votable_abstain");
1840 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1842 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1843 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
1845 if(mapvote_suggestion_ptr)
1846 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1847 MapVote_AddVotable(mapvote_suggestions[floor(random() * mapvote_suggestion_ptr)], TRUE);
1849 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1850 MapVote_AddVotable(GetNextMap(), FALSE);
1852 if(mapvote_count == 0)
1854 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1855 cvar_set("g_maplist", MapInfo_ListAllowedMaps(0, MAPINFO_FLAG_HIDDEN));
1856 localcmd("\nmenu_cmd sync\n");
1857 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1858 MapVote_AddVotable(GetNextMap(), FALSE);
1861 mapvote_count_real = mapvote_count;
1863 MapVote_AddVotable("don't care", 0);
1865 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1867 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1868 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1869 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1870 mapvote_keeptwotime = 0;
1871 mapvote_message = "Choose a map and press its key!";
1873 mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
1874 if(mapvote_screenshot_dir == "")
1875 mapvote_screenshot_dir = "maps";
1876 mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
1878 if(!cvar("g_maplist_textonly"))
1879 MapVote_SendData(MSG_ALL);
1882 void MapVote_SendPicture(float id)
1885 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1886 WriteByte(MSG_ONE, TE_CSQC_MAPVOTE);
1887 WriteByte(MSG_ONE, MAPVOTE_NET_PIC);
1888 WriteByte(MSG_ONE, id);
1889 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 3072);
1892 float GameCommand_MapVote(string cmd)
1894 if(!intermission_running)
1896 if(!cvar("g_maplist_textonly"))
1898 if(cmd == "mv_getpic")
1900 MapVote_SendPicture(stof(argv(1)));
1908 float MapVote_GetMapMask()
1910 float mask, i, power;
1912 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
1913 if(mapvote_maps[i] != "")
1918 void MapVote_SendData(float targ)
1920 string mapfile, pakfile;
1922 WriteByte(targ, SVC_TEMPENTITY);
1923 WriteByte(targ, TE_CSQC_CONFIG);
1924 WriteString(targ, "mv_screenshot_dir");
1925 WriteString(targ, mapvote_screenshot_dir);
1927 WriteByte(targ, SVC_TEMPENTITY);
1928 WriteByte(targ, TE_CSQC_MAPVOTE);
1929 WriteByte(targ, MAPVOTE_NET_INIT);
1931 WriteByte(targ, mapvote_count);
1932 WriteByte(targ, mapvote_abstain);
1933 WriteByte(targ, mapvote_detail);
1934 WriteCoord(targ, mapvote_timeout);
1935 if(mapvote_count <= 8)
1936 WriteByte(targ, MapVote_GetMapMask());
1938 WriteShort(targ, MapVote_GetMapMask());
1939 for(i = 0; i < mapvote_count; ++i)
1940 if(mapvote_maps[i] != "")
1942 WriteString(targ, mapvote_maps[i]);
1943 mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
1944 pakfile = whichpack(strcat(mapfile, ".tga"));
1946 pakfile = whichpack(strcat(mapfile, ".jpg"));
1948 pakfile = whichpack(strcat(mapfile, ".png"));
1949 print("pakfile is ", pakfile, "\n");
1950 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
1951 pakfile = substring(pakfile, o, 999);
1952 WriteString(targ, pakfile);
1956 void MapVote_UpdateData(float targ)
1959 WriteByte(targ, SVC_TEMPENTITY);
1960 WriteByte(targ, TE_CSQC_MAPVOTE);
1961 WriteByte(targ, MAPVOTE_NET_UPDATE);
1962 if(mapvote_count <= 8)
1963 WriteByte(targ, MapVote_GetMapMask());
1965 WriteShort(targ, MapVote_GetMapMask());
1967 for(i = 0; i < mapvote_count; ++i)
1968 if(mapvote_maps[i] != "")
1969 WriteByte(targ, mapvote_votes[i]);
1972 void MapVote_TellVote(float targ, float vote)
1974 WriteByte(targ, SVC_TEMPENTITY);
1975 WriteByte(targ, TE_CSQC_MAPVOTE);
1976 WriteByte(targ, MAPVOTE_NET_OWNVOTE);
1977 WriteByte(targ, vote);
1980 float MapVote_Finished(float mappos)
1986 if(cvar("sv_eventlog"))
1988 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1989 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1990 didntvote = mapvote_voters;
1991 for(i = 0; i < mapvote_count; ++i)
1992 if(mapvote_maps[i] != "")
1994 didntvote -= mapvote_votes[i];
1997 result = strcat(result, ":", mapvote_maps[i]);
1998 result = strcat(result, ":", ftos(mapvote_votes[i]));
2001 result = strcat(result, ":didn't vote:", ftos(didntvote));
2003 GameLogEcho(result);
2004 if(mapvote_maps_suggested[mappos])
2005 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
2008 FOR_EACH_REALCLIENT(other)
2009 FixClientCvars(other);
2011 Map_Goto_SetStr(mapvote_maps[mappos]);
2013 alreadychangedlevel = TRUE;
2016 void MapVote_CheckRules_1()
2020 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2022 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2023 mapvote_votes[i] = 0;
2027 FOR_EACH_REALCLIENT(other)
2032 i = other.mapvote - 1;
2033 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2034 mapvote_votes[i] = mapvote_votes[i] + 1;
2039 float MapVote_CheckRules_2()
2042 float firstPlace, secondPlace;
2043 float firstPlaceVotes, secondPlaceVotes;
2044 float mapvote_voters_real;
2047 mapvote_voters_real = mapvote_voters;
2049 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2051 RandomSelection_Init();
2052 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2053 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2054 firstPlace = RandomSelection_chosen_float;
2055 firstPlaceVotes = RandomSelection_best_priority;
2056 //dprint("First place: ", ftos(firstPlace), "\n");
2057 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2059 RandomSelection_Init();
2060 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2062 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2063 secondPlace = RandomSelection_chosen_float;
2064 secondPlaceVotes = RandomSelection_best_priority;
2065 //dprint("Second place: ", ftos(secondPlace), "\n");
2066 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2068 if(firstPlace == -1)
2069 error("No first place in map vote... WTF?");
2071 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2072 return MapVote_Finished(firstPlace);
2074 if(mapvote_keeptwotime)
2075 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2078 mapvote_dirty = TRUE;
2079 mapvote_message = "Now decide between the TOP TWO!";
2080 mapvote_keeptwotime = 0;
2081 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2082 result = strcat(result, ":", ftos(firstPlaceVotes));
2083 result = strcat(result, ":", mapvote_maps[secondPlace]);
2084 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2085 didntvote = mapvote_voters;
2086 for(i = 0; i < mapvote_count; ++i)
2087 if(mapvote_maps[i] != "")
2089 didntvote -= mapvote_votes[i];
2091 if(i != secondPlace)
2093 result = strcat(result, ":", mapvote_maps[i]);
2094 result = strcat(result, ":", ftos(mapvote_votes[i]));
2095 if(i < mapvote_count_real)
2097 strunzone(mapvote_maps[i]);
2098 mapvote_maps[i] = "";
2102 result = strcat(result, ":didn't vote:", ftos(didntvote));
2103 if(cvar("sv_eventlog"))
2104 GameLogEcho(result);
2117 keeptwo = mapvote_keeptwotime;
2118 MapVote_CheckRules_1(); // count
2119 if(MapVote_CheckRules_2()) // decide
2123 FOR_EACH_REALCLIENT(other)
2125 // hide scoreboard again
2126 if(other.health != 2342)
2128 other.health = 2342;
2130 if(clienttype(other) == CLIENTTYPE_REAL)
2132 if(cvar("g_maplist_textonly"))
2133 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");
2136 WriteByte(MSG_ONE, SVC_FINALE);
2137 WriteString(MSG_ONE, "");
2141 // notify about keep-two
2142 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2143 play2(other, "misc/invshot.wav");
2145 // clear possibly invalid votes
2146 if(mapvote_maps[other.mapvote - 1] == "")
2148 // use impulses as new vote
2149 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2150 if(mapvote_maps[other.impulse - 1] != "")
2152 other.mapvote = other.impulse;
2154 mapvote_dirty = TRUE;
2157 MapVote_TellVote(MSG_ONE, other.mapvote);
2165 MapVote_CheckRules_1(); // just count
2167 if(!cvar("g_maplist_textonly"))
2168 if(mapvote_dirty) // 1 if "keeptwo" or "impulse" happened before
2170 MapVote_UpdateData(MSG_BROADCAST);
2171 mapvote_dirty = FALSE;
2174 if(cvar("g_maplist_textonly"))
2176 FOR_EACH_REALCLIENT(other)
2178 // display voting screen
2179 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2180 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2182 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2183 msgstr = strcat(msgstr, mapvote_message);
2184 msgstr = strcat(msgstr, "\n\n");
2185 for(i = 0; i < mapvote_count; ++i)
2186 if(mapvote_maps[i] == "")
2187 msgstr = strcat(msgstr, "\n");
2190 tmp = mapvote_maps[i];
2191 tmp = strpad(mapvote_maxlen, tmp);
2192 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2195 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2196 if(mapvote_votes[i] != 1)
2197 tmp = strcat(tmp, "s");
2198 tmp = strcat(tmp, ")");
2199 tmp = strpad(mapvote_maxlen + 15, tmp);
2202 if(i == mapvote_count - 1)
2203 msgstr = strcat(msgstr, "\n");
2204 if(other.mapvote == i + 1)
2205 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2207 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2210 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2212 msgstr = strcat(msgstr, "s");
2213 msgstr = strcat(msgstr, " cast");
2214 i = ceil(mapvote_timeout - time);
2215 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2217 msgstr = strcat(msgstr, "s");
2218 msgstr = strcat(msgstr, " left");
2220 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2224 void MapVote_Start()
2229 MapInfo_Enumerate();
2230 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0, (g_maplist_allow_hidden ? MAPINFO_FLAG_HIDDEN : 0), 1))
2233 void MapVote_Think()
2238 if(alreadychangedlevel)
2241 if(time < mapvote_nextthink)
2245 mapvote_nextthink = time + 0.5;
2247 if(!mapvote_initialized)
2249 mapvote_initialized = TRUE;
2250 if(DoNextMapOverride())
2252 if(!cvar("g_maplist_votable") || player_count <= 0)
2263 string GotoMap(string m)
2265 if(!MapInfo_CheckMap(m))
2266 return "The map you chose is not available on this server.";
2267 cvar_set("nextmap", m);
2268 cvar_set("timelimit", "-1");
2269 if(mapvote_initialized || alreadychangedlevel)
2271 if(DoNextMapOverride())
2272 return "Map switch initiated.";
2274 return "Hm... no. For some reason I like THIS map more.";
2277 return "Map switch will happen after scoreboard.";
2283 FOR_EACH_REALCLIENT(self)
2285 if(self.classname == "spectator")
2287 if(self.enemy.typehitsound)
2288 play2(self, "misc/typehit.wav");
2289 else if(self.enemy.hitsound)
2290 play2(self, "misc/hit.wav");
2294 if(self.typehitsound)
2295 play2(self, "misc/typehit.wav");
2296 else if(self.hitsound)
2297 play2(self, "misc/hit.wav");
2300 FOR_EACH_CLIENT(self)
2302 self.hitsound = FALSE;
2303 self.typehitsound = FALSE;
2310 * returns TRUE if redirecting
2312 float redirection_timeout;
2313 float redirection_nextthink;
2314 float RedirectionThink()
2316 float clients_found;
2318 if(redirection_target == "")
2321 if(!redirection_timeout)
2323 cvar_set("sv_public", "-2");
2324 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2325 if(redirection_target == "self")
2326 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2328 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2331 if(time < redirection_nextthink)
2334 redirection_nextthink = time + 1;
2337 FOR_EACH_REALCLIENT(self)
2339 print("Redirecting: sending connect command to ", self.netname, "\n");
2340 if(redirection_target == "self")
2341 stuffcmd(self, "\ndisconnect; reconnect\n");
2343 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2347 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2349 if(time > redirection_timeout || clients_found == 0)
2350 localcmd("\nwait; wait; wait; quit\n");
2357 // Loaded from a save game
2358 // some things then break, so let's work around them...
2360 // Progs DB (capture records)
2362 ServerProgsDB = db_create();
2364 ServerProgsDB = db_load("server.db");
2368 MapInfo_Enumerate();
2369 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0, (g_maplist_allow_hidden ? MAPINFO_FLAG_HIDDEN : 0), 1);
2374 if(world_initialized > 0)
2376 world_initialized = 0;
2377 print("Saving persistent data...\n");
2380 db_save(ServerProgsDB, "server.db");
2381 if(cvar("developer"))
2382 db_save(TemporaryDB, "server-temp.db");
2383 db_close(ServerProgsDB);
2384 db_close(TemporaryDB);
2386 // tell the bot system the game is ending now
2391 else if(world_initialized == 0)
2393 print("NOTE: crashed before even initializing the world, not saving persistent data\n");