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;
168 buf_cvarlist(h, "", "_"); // exclude all _ cvars as they are temporary
171 for(i = 0; i < n; ++i)
173 k = bufstr_get(h, i);
175 #define BADPREFIX(p) if(substring(k, 0, strlen(p)) == p) continue
176 #define BADCVAR(p) if(k == p) continue
179 BADPREFIX("cvar_check_");
181 BADCVAR("g_configversion");
182 BADCVAR("g_maplist_index");
183 BADCVAR("halflifebsp");
188 BADPREFIX("g_campaign");
192 BADPREFIX("net_slist_");
196 BADPREFIX("userbind");
199 BADCVAR("mod_q3bsp_lightmapmergepower");
200 BADCVAR("mod_q3bsp_nolightmaps");
204 BADPREFIX("g_chat_flood_");
206 BADPREFIX("settemp_");
207 BADPREFIX("sv_allowdownloads_");
208 BADPREFIX("sv_autodemo");
209 BADPREFIX("sv_curl_");
210 BADPREFIX("sv_eventlog");
211 BADPREFIX("sv_logscores_");
212 BADPREFIX("sv_master");
213 BADCVAR("g_banned_list");
214 BADCVAR("log_dest_udp");
216 BADCVAR("net_address");
218 BADCVAR("savedgamecfg");
219 BADCVAR("sv_heartbeatperoid");
220 BADCVAR("sv_vote_master_password");
221 BADCVAR("sys_colortranslation");
222 BADCVAR("sys_specialcharactertranslation");
223 BADCVAR("timestamps");
226 BADCVAR("timelimit");
227 BADCVAR("fraglimit");
229 BADCVAR("g_assault");
232 BADCVAR("g_domination");
233 BADCVAR("g_keyhunt");
234 BADCVAR("g_keyhunt_teams");
235 BADCVAR("g_onslaught");
237 BADCVAR("g_runematch");
243 BADCVAR("g_maplist");
244 BADCVAR("g_maplist_mostrecent");
250 d = cvar_defstring(k);
253 cvar_changes = strcat(cvar_changes, k, " \"", v, "\" // \"", d, "\"\n");
254 if(strlen(cvar_changes) > 16384)
256 cvar_changes = "// too many settings have been changed to show them here\n";
262 if(cvar_changes == "")
263 cvar_changes = "// this server runs at default settings\n";
265 cvar_changes = strcat("// this server runs at modified settings:\n", cvar_changes);
266 cvar_changes = strzone(cvar_changes);
269 void detect_maptype()
278 o_x += random() * (world.maxs_x - world.mins_x);
279 o_y += random() * (world.maxs_y - world.mins_y);
280 o_z += random() * (world.maxs_z - world.mins_z);
282 tracebox(o, PL_MIN, PL_MAX, o - '0 0 32768', MOVE_WORLDONLY, world);
283 if(trace_fraction == 1)
288 for(i = 0; i < 64; i += 4)
290 tracebox(o, '-1 -1 -1' * i, '1 1 1' * i, o - '0 0 32768', MOVE_WORLDONLY, world);
291 if(trace_fraction == 1)
293 print(ftos(i), " -> ", vtos(trace_endpos), "\n");
301 float world_already_spawned;
302 void RegisterWeapons();
304 void ClientInit_Spawn();
305 void spawnfunc_worldspawn (void)
307 float fd, l, i, j, n;
310 dprint_load(); // load dprint status from cvar
312 if(world_already_spawned)
313 error("world already spawned - you may have EXACTLY ONE worldspawn!");
314 world_already_spawned = TRUE;
316 remove = remove_safely; // during spawning, watch what you remove!
318 if(cvar_string("cvar_check_default") != "bypass")
320 if(cvar_string("cvar_check_default") != CVAR_CHECK_DEFAULT)
321 error("Config file mismatch! Please update defaultNexuiz.cfg to match the QuakeC code!");
323 if(cvar_string("cvar_check_weapons") != CVAR_CHECK_WEAPONS)
324 error("Config file mismatch! Please update weapons.cfg and weaponsPro.cfg to match the QuakeC code!");
327 compressShortVector_init();
330 head = nextent(world);
335 head = nextent(head);
338 // needs to be done so early as they would still spawn
343 world_initialized = -1; // don't complain
348 ServerProgsDB = db_create();
350 ServerProgsDB = db_load("server.db");
352 TemporaryDB = db_create();
355 TODO sound pack system
356 // initialize sound pack system
357 soundpack = cvar_string("g_soundpack");
359 soundpack = strcat(soundpack, "/");
360 soundpack = strzone(soundpack);
366 // 1 FLICKER (first variety)
367 lightstyle(1, "mmnmmommommnonmmonqnmmo");
369 // 2 SLOW STRONG PULSE
370 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
372 // 3 CANDLE (first variety)
373 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
376 lightstyle(4, "mamamamamama");
379 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
381 // 6 FLICKER (second variety)
382 lightstyle(6, "nmonqnmomnmomomno");
384 // 7 CANDLE (second variety)
385 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
387 // 8 CANDLE (third variety)
388 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
390 // 9 SLOW STROBE (fourth variety)
391 lightstyle(9, "aaaaaaaazzzzzzzz");
393 // 10 FLUORESCENT FLICKER
394 lightstyle(10, "mmamammmmammamamaaamammma");
396 // 11 SLOW PULSE NOT FADE TO BLACK
397 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
399 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
404 if(cvar("g_campaign"))
412 bot_waypoints_for_items = cvar("g_waypoints_for_items");
413 if(bot_waypoints_for_items == 1)
414 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
415 bot_waypoints_for_items = 0;
417 // for setting by mapinfo
418 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
419 cvar_set("sv_q3acompat_machineshotgunswap", "0");
423 WaypointSprite_Init();
428 GameLogInit(); // prepare everything
429 if(cvar("sv_eventlog"))
431 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
432 s = strcat(s, ftos(random()));
433 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
434 s = ":gameinfo:mutators:LIST";
435 if(cvar("g_grappling_hook"))
436 s = strcat(s, ":grappling_hook");
437 if(!cvar("g_use_ammunition"))
438 s = strcat(s, ":no_use_ammunition");
439 if(!cvar("g_pickup_items"))
440 s = strcat(s, ":no_pickup_items");
441 if(cvar("g_instagib"))
442 s = strcat(s, ":instagib");
443 if(cvar_string("g_weaponarena") != "0")
444 s = strcat(s, ":", cvar_string("g_weaponarena"), " arena");
446 s = strcat(s, ":nixnex");
447 if(cvar("g_vampire"))
448 s = strcat(s, ":vampire");
449 if(cvar("g_laserguided_missile"))
450 s = strcat(s, ":laserguided_missile");
451 if(cvar("g_norecoil"))
452 s = strcat(s, ":norecoil");
454 s = strcat(s, ":midair");
455 if(cvar("g_minstagib"))
456 s = strcat(s, ":minstagib");
458 GameLogEcho(":gameinfo:end");
461 cvar_set("nextmap", "");
465 if(cvar("g_campaign"))
472 //initialise globals related to sv_timeout
473 sys_ticrate = cvar("sys_ticrate");
474 orig_slowmo = cvar("slowmo");
477 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0, (g_maplist_allow_hidden ? MAPINFO_FLAG_HIDDEN : 0), 1);
479 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
481 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
484 while((s = fgets(fd)))
486 l = tokenize_sane(s);
491 print("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
492 print(" cdtrack ", argv(2), "\n");
494 else if(argv(0) == "fog")
496 print("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
497 print(" \"fog\" \"", s, "\"\n");
499 else if(argv(0) == "set")
501 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
502 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
504 else if(argv(0) != "//")
506 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
507 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
514 addstat(STAT_SYS_TICRATE, AS_FLOAT, stat_sys_ticrate);
515 addstat(STAT_WEAPONS, AS_INT, weapons);
516 addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
517 addstat(STAT_GAMESTARTTIME, AS_FLOAT, stat_game_starttime);
520 next_pingtime = time + 5;
521 InitializeEntity(self, cvar_changes_init, INITPRIO_CVARS);
525 lsmaps_reply = "^7Maps available: ";
526 for(i = 0, j = 0; i < MapInfo_count; ++i)
528 if(MapInfo_Get_ByID(i))
529 if not(MapInfo_Map_flags & MAPINFO_FLAG_HIDDEN)
536 lsmaps_reply = strcat(lsmaps_reply, col, MapInfo_Map_bspname, " ");
539 lsmaps_reply = strzone(strcat(lsmaps_reply, "\n"));
541 maplist_reply = "^7Maps in list: ";
542 n = tokenize_sane(cvar_string("g_maplist"));
543 for(i = 0, j = 0; i < n; ++i)
545 if(MapInfo_CheckMap(argv(i)))
551 maplist_reply = strcat(maplist_reply, col, argv(i), " ");
555 maplist_reply = strzone(strcat(maplist_reply, "\n"));
557 records_reply = strzone(getrecords());
561 world_initialized = 1;
564 void spawnfunc_light (void)
566 //makestatic (self); // Who the f___ did that?
570 float TryFile( string pFilename )
573 dprint("TryFile(\"", pFilename, "\")\n");
574 lHandle = fopen( pFilename, FILE_READ );
575 if( lHandle != -1 ) {
585 return GametypeNameFromType(game);
588 string getmapname_stored;
594 float Map_Count, Map_Current;
595 string Map_Current_Name;
597 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
598 float GetMaplistPosition()
604 idx = cvar("g_maplist_index");
611 for(pos = 0; pos < Map_Count; ++pos)
615 // resume normal maplist rotation if current map is not in g_maplist
619 float MapHasRightSize(string map)
622 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
623 if(cvar("g_maplist_check_waypoints"))
625 dprint("checkwp "); dprint(map);
626 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
629 dprint(": no waypoints\n");
632 dprint(": has waypoints\n");
636 // open map size restriction file
637 dprint("opensize "); dprint(map);
638 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
641 float mapmin, mapmax;
643 mapmin = stof(fgets(fh));
644 mapmax = stof(fgets(fh));
646 if(player_count < mapmin)
648 dprint("not enough\n");
651 if(player_count > mapmax)
653 dprint("too many\n");
656 dprint("right size\n");
659 dprint(": not found\n");
663 string Map_Filename(float position)
665 return strcat("maps/", argv(position), ".bsp");
668 string strwords(string s, float w)
671 for(endpos = 0; w && endpos >= 0; --w)
672 endpos = strstrofs(s, " ", endpos + 1);
676 return substring(s, 0, endpos);
679 float strhasword(string s, string w)
681 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
684 void Map_MarkAsRecent(string m)
686 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
689 float Map_IsRecent(string m)
691 return strhasword(cvar_string("g_maplist_mostrecent"), m);
694 float Map_Check(float position, float pass)
698 map_next = argv(position);
701 if(map_next == Map_Current_Name) // same map again in first pass?
703 if(Map_IsRecent(map_next))
706 filename = Map_Filename(position);
707 if(MapInfo_CheckMap(map_next))
711 if(MapHasRightSize(map_next))
716 dprint( "Couldn't select '", filename, "'..\n" );
721 void Map_Goto_SetStr(string nextmapname)
723 if(getmapname_stored != "")
724 strunzone(getmapname_stored);
725 if(nextmapname == "")
726 getmapname_stored = "";
728 getmapname_stored = strzone(nextmapname);
731 void Map_Goto_SetFloat(float position)
733 cvar_set("g_maplist_index", ftos(position));
734 Map_Goto_SetStr(argv(position));
739 // settings persist, except...
740 if(cvar("g_campaign"))
741 localcmd("\nexec mutator_reset.cfg\n");
742 localcmd("\nsettemp_restore\n");
747 Map_MarkAsRecent(getmapname_stored);
749 MapInfo_LoadMap(getmapname_stored);
752 // return codes of map selectors:
753 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
754 // -2 = permanent failure
755 float() MaplistMethod_Iterate = // usual method
759 for(pass = 1; pass <= 2; ++pass)
761 for(i = 1; i < Map_Count; ++i)
764 mapindex = mod(i + Map_Current, Map_Count);
765 if(Map_Check(mapindex, pass))
772 float() MaplistMethod_Repeat = // fallback method
774 if(Map_Check(Map_Current, 2))
779 float() MaplistMethod_Random = // random map selection
785 for(i = 0; i <= imax; ++i)
788 mapindex = mod(Map_Current + floor(random() * (Map_Count - 1) + 1), Map_Count); // any OTHER map
789 if(Map_Check(mapindex, 1))
795 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
796 // the exponent sets a bias on the map selection:
797 // the higher the exponent, the less likely "shortly repeated" same maps are
799 float i, j, imax, insertpos;
803 for(i = 0; i <= imax; ++i)
807 // now reinsert this at another position
808 insertpos = pow(random(), 1 / exponent); // ]0, 1]
809 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
810 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
811 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
813 // insert the current map there
815 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
816 newlist = strcat(newlist, " ", argv(j));
817 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
818 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
819 newlist = strcat(newlist, " ", argv(j));
820 newlist = substring(newlist, 1, strlen(newlist) - 1);
821 cvar_set("g_maplist", newlist);
822 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
824 // NOTE: the selected map has just been inserted at (insertpos-1)th position
825 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
826 if(Map_Check(Map_Current, 1))
834 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
837 bprint( "Maplist is empty! Resetting it to default map list.\n" );
838 cvar_set("g_maplist", MapInfo_ListAllowedMaps(0, MAPINFO_FLAG_HIDDEN));
839 if(cvar("g_maplist_shuffle"))
841 localcmd("\nmenu_cmd sync\n");
842 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
845 error("empty maplist, cannot select a new map");
846 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
849 strunzone(Map_Current_Name);
850 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
851 // this may or may not be correct, but who cares, in the worst case a map
852 // isn't chosen in the first pass that should have been
863 if(cvar("g_maplist_shuffle") > 0)
864 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
867 if(cvar("g_maplist_selectrandom"))
868 nextMap = MaplistMethod_Random();
871 nextMap = MaplistMethod_Iterate();
874 nextMap = MaplistMethod_Repeat();
878 Map_Goto_SetFloat(nextMap);
879 return getmapname_stored;
885 float DoNextMapOverride()
887 if(cvar("g_campaign"))
889 CampaignPostIntermission();
890 alreadychangedlevel = TRUE;
893 if(cvar("quit_when_empty"))
895 if(player_count <= currentbots)
898 alreadychangedlevel = TRUE;
902 if(cvar_string("quit_and_redirect") != "")
904 redirection_target = strzone(cvar_string("quit_and_redirect"));
905 alreadychangedlevel = TRUE;
908 if (cvar("samelevel")) // if samelevel is set, stay on same level
910 // 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)
911 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
912 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
913 localcmd("restart\n");
914 //changelevel (mapname);
915 alreadychangedlevel = TRUE;
918 if(cvar_string("nextmap") != "")
919 if(MapInfo_CheckMap(cvar_string("nextmap")))
921 Map_Goto_SetStr(cvar_string("nextmap"));
923 alreadychangedlevel = TRUE;
926 if(cvar("lastlevel"))
929 localcmd("set lastlevel 0\ntogglemenu\n");
930 alreadychangedlevel = TRUE;
938 //local string nextmap;
939 //local float n, nummaps;
941 if (alreadychangedlevel)
943 alreadychangedlevel = TRUE;
949 for(allowReset = 1; allowReset >= 0; --allowReset)
951 nextMap = GetNextMap();
957 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
958 cvar_set("g_maplist", MapInfo_ListAllowedMaps(0, MAPINFO_FLAG_HIDDEN));
959 if(cvar("g_maplist_shuffle"))
961 localcmd("\nmenu_cmd sync\n");
965 error("Everything is broken - not even the default map list works. Please report this to the developers.");
977 When the player presses attack or jump, change to the next level
980 .float autoscreenshot;
981 void() MapVote_Start;
982 void() MapVote_Think;
983 float mapvote_initialized;
984 void IntermissionThink()
986 FixIntermissionClient(self);
988 if(cvar("sv_autoscreenshot"))
989 if(self.autoscreenshot > 0)
990 if(time > self.autoscreenshot)
992 self.autoscreenshot = -1;
993 if(clienttype(self) == CLIENTTYPE_REAL)
994 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
998 if (time < intermission_exittime)
1001 if(!mapvote_initialized)
1002 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
1012 Returns the entity to view from
1016 entity FindIntermission()
1021 // look for info_intermission first
1022 spot = find (world, classname, "info_intermission");
1024 { // pick a random one
1028 spot = find (spot, classname, "info_intermission");
1030 spot = find (spot, classname, "info_intermission");
1036 // then look for the start position
1037 spot = find (world, classname, "info_player_start");
1041 // testinfo_player_start is only found in regioned levels
1042 spot = find (world, classname, "testplayerstart");
1046 // then look for the start position
1047 spot = find (world, classname, "info_player_deathmatch");
1051 //objerror ("FindIntermission: no spot");
1057 ===============================================================================
1061 ===============================================================================
1064 void DumpStats(float final)
1068 local float to_console;
1069 local float to_eventlog;
1070 local float to_file;
1073 to_console = cvar("sv_logscores_console");
1074 to_eventlog = cvar("sv_eventlog");
1075 to_file = cvar("sv_logscores_file");
1079 to_console = TRUE; // always print printstats replies
1080 to_eventlog = FALSE; // but never print them to the event log
1084 if(cvar("sv_eventlog_console"))
1085 to_console = FALSE; // otherwise we get the output twice
1091 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
1099 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
1103 fputs(file, strcat(s, "\n"));
1106 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
1112 fputs(file, strcat(s, "\n"));
1114 FOR_EACH_CLIENT(other)
1116 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
1118 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
1119 s = strcat(s, ftos(rint(time - other.jointime)), ":");
1120 if(other.classname == "player" || g_arena || g_lms)
1121 s = strcat(s, ftos(other.team), ":");
1123 s = strcat(s, "spectator:");
1126 print(s, other.netname, "\n");
1128 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
1130 fputs(file, strcat(s, other.netname, "\n"));
1136 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
1142 fputs(file, strcat(s, "\n"));
1144 for(i = 1; i < 16; ++i)
1146 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
1147 s = strcat(s, ":", ftos(i));
1153 fputs(file, strcat(s, "\n"));
1160 GameLogEcho(":end");
1163 fputs(file, ":end\n");
1168 void FixIntermissionClient(entity e)
1171 if(!e.autoscreenshot) // initial call
1173 e.angles = e.v_angle;
1174 e.angles_x = -e.angles_x;
1175 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1177 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1178 e.solid = SOLID_NOT;
1179 e.movetype = MOVETYPE_NONE;
1180 e.takedamage = DAMAGE_NO;
1182 e.weaponentity.effects = EF_NODRAW;
1183 if(clienttype(e) == CLIENTTYPE_REAL)
1185 stuffcmd(e, "\nscr_printspeed 1000000\n");
1186 s = cvar_string("sv_intermission_cdtrack");
1188 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1190 WriteByte(MSG_ONE, SVC_INTERMISSION);
1194 //e.velocity = '0 0 0';
1195 //e.fixangle = TRUE;
1197 // TODO halt weapon animation
1202 go to the next level for deathmatch
1203 only called if a time or frag limit has expired
1207 float minTotalFrags;
1208 float maxTotalFrags;
1214 intermission_running = 1;
1216 // enforce a wait time before allowing changelevel
1217 if(player_count > 0)
1218 intermission_exittime = time + cvar("sv_mapchange_delay");
1220 intermission_exittime = -1;
1223 WriteByte (MSG_ALL, SVC_CDTRACK);
1224 WriteByte (MSG_ALL, 3);
1225 WriteByte (MSG_ALL, 3);
1226 // done in FixIntermission
1229 //pos = FindIntermission ();
1235 if(cvar("sv_eventlog"))
1236 GameLogEcho(":gameover");
1240 FOR_EACH_CLIENT(other)
1242 FixIntermissionClient(other);
1245 bprint(other.netname, " ^7wins.\n");
1250 FOR_EACH_PLAYER(other)
1252 if(maxTotalFrags < other.totalfrags)
1253 maxTotalFrags = other.totalfrags;
1254 if(minTotalFrags > other.totalfrags)
1255 minTotalFrags = other.totalfrags;
1260 FOR_EACH_PLAYER(other)
1262 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1263 f = bound(0, other.play_time / max(time, 1), 1);
1264 // store some statistics?
1268 if(cvar("g_campaign"))
1269 CampaignPreIntermission();
1271 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1278 Exit deathmatch games upon conditions
1281 void CheckRules_Player()
1283 if (gameover) // someone else quit the game already
1286 if(self.deadflag == DEAD_NO)
1287 self.play_time += frametime;
1289 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1290 // (div0: and that in CheckRules_World please)
1293 float checkrules_oneminutewarning;
1295 float checkrules_equality;
1296 float checkrules_overtimewarning;
1297 float checkrules_overtimeend;
1299 void InitiateOvertime()
1301 if(!checkrules_overtimeend)
1302 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1305 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1306 float WINNING_YES = 1; // winner found
1307 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1308 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1310 float GetWinningCode(float fraglimitreached, float equality)
1313 if(fraglimitreached)
1314 return WINNING_STARTOVERTIME;
1316 return WINNING_NEVER;
1318 if(fraglimitreached)
1324 // set the .winning flag for exactly those players with a given field value
1325 void SetWinners(.float field, float value)
1328 FOR_EACH_PLAYER(head)
1329 head.winning = (head.field == value);
1332 // set the .winning flag for those players with a given field value
1333 void AddWinners(.float field, float value)
1336 FOR_EACH_PLAYER(head)
1337 if(head.field == value)
1341 // clear the .winning flags
1342 void ClearWinners(void)
1345 FOR_EACH_PLAYER(head)
1349 // Onslaught winning condition:
1350 // game terminates if only one team has a working generator (or none)
1351 float WinningCondition_Onslaught()
1354 local float t1, t2, t3, t4;
1356 WinningConditionHelper(); // set worldstatus
1358 // first check if the game has ended
1359 t1 = t2 = t3 = t4 = 0;
1360 head = find(world, classname, "onslaught_generator");
1363 if (head.health > 0)
1365 if (head.team == COLOR_TEAM1) t1 = 1;
1366 if (head.team == COLOR_TEAM2) t2 = 1;
1367 if (head.team == COLOR_TEAM3) t3 = 1;
1368 if (head.team == COLOR_TEAM4) t4 = 1;
1370 head = find(head, classname, "onslaught_generator");
1372 if (t1 + t2 + t3 + t4 < 2)
1374 // game over, only one team remains (or none)
1376 if (t1) SetWinners(team, COLOR_TEAM1);
1377 if (t2) SetWinners(team, COLOR_TEAM2);
1378 if (t3) SetWinners(team, COLOR_TEAM3);
1379 if (t4) SetWinners(team, COLOR_TEAM4);
1380 dprint("Have a winner, ending game.\n");
1384 // Two or more teams remain
1388 float LMS_NewPlayerLives()
1391 fl = cvar("fraglimit");
1395 // first player has left the game for dying too much? Nobody else can get in.
1396 if(lms_lowest_lives < 1)
1399 if(!cvar("g_lms_join_anytime"))
1400 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1403 return bound(1, lms_lowest_lives, fl);
1406 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1407 // they win. Otherwise the defending team wins once the timelimit passes.
1408 void assault_new_round();
1409 float WinningCondition_Assault()
1413 WinningConditionHelper(); // set worldstatus
1415 status = WINNING_NO;
1416 // as the timelimit has not yet passed just assume the defending team will win
1417 if(assault_attacker_team == COLOR_TEAM1)
1419 SetWinners(team, COLOR_TEAM2);
1423 SetWinners(team, COLOR_TEAM1);
1427 ent = find(world, classname, "target_assault_roundend");
1430 if(ent.winning) // round end has been triggered by attacking team
1432 bprint("ASSAULT: round completed...\n");
1433 SetWinners(team, assault_attacker_team);
1435 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
1437 if(ent.cnt == 1) // this was the second round
1439 status = WINNING_YES;
1443 local entity oldself;
1446 assault_new_round();
1455 // LMS winning condition: game terminates if and only if there's at most one
1456 // one player who's living lives. Top two scores being equal cancels the time
1458 float WinningCondition_LMS()
1465 have_player = FALSE;
1466 have_players = FALSE;
1467 l = LMS_NewPlayerLives();
1469 head = find(world, classname, "player");
1472 head2 = find(head, classname, "player");
1474 have_players = TRUE;
1478 // we have at least one player
1481 // two or more active players - continue with the game
1485 // exactly one player?
1488 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1492 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1498 // and assign him his first place
1499 PlayerScore_Add(head, SP_LMS_RANK, 1);
1506 // nobody is playing at all...
1509 // wait for players...
1513 // SNAFU (maybe a draw game?)
1515 dprint("No players, ending game.\n");
1520 // When we get here, we have at least two players who are actually LIVING,
1521 // now check if the top two players have equal score.
1522 WinningConditionHelper();
1525 if(WinningConditionHelper_winner)
1526 WinningConditionHelper_winner.winning = TRUE;
1527 if(WinningConditionHelper_equality)
1528 return WINNING_NEVER;
1530 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1534 void ShuffleMaplist()
1542 result = cvar_string("g_maplist");
1543 litems = tokenizebyseparator(result, " ");
1545 for(start = 0; start < litems - 1; ++start)
1549 // select a random item
1550 selected = floor(random() * (litems - start) + start);
1552 // shift this item to the place start
1553 for(i = 0; i < start; ++i)
1554 result = strcat(result, " ", argv(i));
1555 result = strcat(result, " ", argv(selected));
1556 for(i = start; i < litems; ++i)
1558 result = strcat(result, " ", argv(i));
1559 result = substring(result, 1, strlen(result) - 1);
1561 litems = tokenizebyseparator(result, " ");
1563 //dprint(result, "\n");
1566 cvar_set("g_maplist", result);
1570 float WinningCondition_Scores(float limit)
1572 // TODO make everything use THIS winning condition (except LMS)
1573 WinningConditionHelper();
1577 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1578 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1579 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1580 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1584 if(WinningConditionHelper_winner)
1585 WinningConditionHelper_winner.winning = 1;
1586 if(WinningConditionHelper_winnerteam >= 0)
1587 SetWinners(team, WinningConditionHelper_winnerteam);
1589 if(WinningConditionHelper_lowerisbetter)
1591 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1595 if(g_dm || g_tdm || g_arena || (g_race && !g_race_qualifying))
1596 // these modes always score in increments of 1, thus this makes sense
1598 if(leaderfrags != WinningConditionHelper_topscore)
1600 leaderfrags = WinningConditionHelper_topscore;
1603 if (leaderfrags == limit - 1)
1604 play2all("announcer/robotic/1fragleft.wav");
1605 else if (leaderfrags == limit - 2)
1606 play2all("announcer/robotic/2fragsleft.wav");
1607 else if (leaderfrags == limit - 3)
1608 play2all("announcer/robotic/3fragsleft.wav");
1612 return GetWinningCode(limit && WinningConditionHelper_topscore && (WinningConditionHelper_topscore >= limit), WinningConditionHelper_equality);
1615 float WinningCondition_Race(float fraglimit)
1619 wc = WinningCondition_Scores(fraglimit);
1621 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1622 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1623 // do NOT support equality when the laps are all raced!
1626 if not(p.race_completed)
1627 return WINNING_STARTOVERTIME;
1633 void ReadyRestart();
1634 float WinningCondition_QualifyingThenRace(float limit)
1637 wc = WinningCondition_Scores(limit);
1639 // NEVER initiate overtime
1640 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1648 float WinningCondition_RanOutOfSpawns()
1652 if(!have_team_spawns)
1655 if(!some_spawn_has_been_used)
1658 team1_score = team2_score = team3_score = team4_score = 0;
1660 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1662 if(head.team == COLOR_TEAM1)
1664 else if(head.team == COLOR_TEAM2)
1666 else if(head.team == COLOR_TEAM3)
1668 else if(head.team == COLOR_TEAM4)
1672 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1674 if(head.team == COLOR_TEAM1)
1676 else if(head.team == COLOR_TEAM2)
1678 else if(head.team == COLOR_TEAM3)
1680 else if(head.team == COLOR_TEAM4)
1685 if(team1_score + team2_score + team3_score + team4_score == 0)
1687 checkrules_equality = TRUE;
1690 else if(team1_score + team2_score + team3_score + team4_score == 1)
1693 if(team1_score) t = COLOR_TEAM1;
1694 if(team2_score) t = COLOR_TEAM2;
1695 if(team3_score) t = COLOR_TEAM3;
1696 if(team4_score) t = COLOR_TEAM4;
1697 CheckAllowedTeams(world);
1698 for(i = 0; i < MAX_TEAMSCORE; ++i)
1700 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
1701 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
1702 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
1703 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
1706 AddWinners(team, t);
1717 Exit deathmatch games upon conditions
1720 void CheckRules_World()
1723 local float timelimit;
1724 local float fraglimit;
1732 MapVote_Think should now do that part
1733 if (intermission_running)
1734 if (time >= intermission_exittime + 60)
1736 if(!DoNextMapOverride())
1742 if (gameover) // someone else quit the game already
1744 if(player_count == 0) // Nobody there? Then let's go to the next map
1746 // this will actually check the player count in the next frame
1747 // again, but this shouldn't hurt
1751 timelimit = cvar("timelimit") * 60;
1752 fraglimit = cvar("fraglimit");
1754 if(inWarmupStage || time <= game_starttime) // NOTE: this is <= to prevent problems in the very tic where the game starts
1757 timelimit = 0; // timelimit is not made for warmup
1759 fraglimit = 0; // no fraglimit for now
1764 timelimit += game_starttime;
1766 else if (timelimit < 0)
1773 if(checkrules_overtimeend)
1775 if(!checkrules_overtimewarning)
1777 checkrules_overtimewarning = TRUE;
1778 //announceall("announcer/robotic/1minuteremains.wav");
1779 if(g_race && !g_race_qualifying)
1780 bcenterprint("^3Everyone, finish your lap! The race is over!");
1782 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1787 if (timelimit && time >= timelimit)
1789 if(g_race && g_race_qualifying == 2 && timelimit > 0)
1792 float playerswithlaps;
1795 totalplayers = playerswithlaps = readyplayers = 0;
1796 FOR_EACH_PLAYER(head)
1799 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
1805 // at least 2/3 of the players have completed a lap: start the RACE
1806 // otherwise, the players should end the qualifying on their own
1807 if(readyplayers || ((totalplayers >= 3) && (playerswithlaps * 3 >= totalplayers * 2)))
1809 checkrules_overtimeend = 0;
1810 ReadyRestart(); // go to race
1820 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1826 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1828 checkrules_oneminutewarning = TRUE;
1829 play2all("announcer/robotic/1minuteremains.wav");
1832 status = WinningCondition_RanOutOfSpawns();
1833 if(status == WINNING_YES)
1835 bprint("Hey! Someone ran out of spawns!\n");
1837 else if(g_race && !g_race_qualifying && timelimit >= 0)
1839 status = WinningCondition_Race(fraglimit);
1841 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
1843 status = WinningCondition_QualifyingThenRace(fraglimit);
1847 status = WinningCondition_Assault(); // TODO remove this?
1851 status = WinningCondition_LMS();
1853 else if (g_onslaught)
1855 status = WinningCondition_Onslaught(); // TODO remove this?
1859 status = WinningCondition_Scores(fraglimit);
1862 if(status == WINNING_STARTOVERTIME)
1864 status = WINNING_NEVER;
1868 if(status == WINNING_NEVER)
1869 // equality cases! Nobody wins if the overtime ends in a draw.
1872 if(checkrules_overtimeend)
1873 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1874 status = WINNING_YES;
1876 if(status == WINNING_YES)
1880 float mapvote_nextthink;
1881 float mapvote_initialized;
1882 float mapvote_keeptwotime;
1883 float mapvote_timeout;
1884 string mapvote_message;
1885 string mapvote_screenshot_dir;
1887 float mapvote_count;
1888 float mapvote_count_real;
1889 string mapvote_maps[MAPVOTE_COUNT];
1890 float mapvote_maps_suggested[MAPVOTE_COUNT];
1891 string mapvote_suggestions[MAPVOTE_COUNT];
1892 float mapvote_suggestion_ptr;
1893 float mapvote_maxlen;
1894 float mapvote_voters;
1895 float mapvote_votes[MAPVOTE_COUNT];
1897 float mapvote_detail;
1898 float mapvote_abstain;
1901 void MapVote_ClearAllVotes()
1903 FOR_EACH_CLIENT(other)
1907 string MapVote_Suggest(string m)
1911 return "That's not how to use this command.";
1912 if(!cvar("g_maplist_votable_suggestions"))
1913 return "Suggestions are not accepted on this server.";
1914 if(mapvote_initialized)
1915 return "Can't suggest - voting is already in progress!";
1916 m = MapInfo_FixName(m);
1918 return "The map you suggested is not available on this server.";
1919 if(!cvar("g_maplist_votable_override_mostrecent"))
1921 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1923 if(!MapInfo_CheckMap(m))
1924 return "The map you suggested does not support the current game mode.";
1925 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1926 if(mapvote_suggestions[i] == m)
1927 return "This map was already suggested.";
1928 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1930 i = floor(random() * mapvote_suggestion_ptr);
1934 i = mapvote_suggestion_ptr;
1935 mapvote_suggestion_ptr += 1;
1937 if(mapvote_suggestions[i] != "")
1938 strunzone(mapvote_suggestions[i]);
1939 mapvote_suggestions[i] = strzone(m);
1940 if(cvar("sv_eventlog"))
1941 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
1942 return strcat("Suggestion of ", m, " accepted.");
1945 void MapVote_AddVotable(string nextMap, float isSuggestion)
1950 for(j = 0; j < mapvote_count; ++j)
1951 if(mapvote_maps[j] == nextMap)
1953 if(strlen(nextMap) > mapvote_maxlen)
1954 mapvote_maxlen = strlen(nextMap);
1955 mapvote_maps[mapvote_count] = strzone(nextMap);
1956 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1960 void MapVote_Spawn();
1966 MapVote_ClearAllVotes();
1969 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1970 mapvote_abstain = cvar("g_maplist_votable_abstain");
1973 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1975 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1976 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
1978 if(mapvote_suggestion_ptr)
1979 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1980 MapVote_AddVotable(mapvote_suggestions[floor(random() * mapvote_suggestion_ptr)], TRUE);
1982 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1983 MapVote_AddVotable(GetNextMap(), FALSE);
1985 if(mapvote_count == 0)
1987 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1988 cvar_set("g_maplist", MapInfo_ListAllowedMaps(0, MAPINFO_FLAG_HIDDEN));
1989 if(cvar("g_maplist_shuffle"))
1991 localcmd("\nmenu_cmd sync\n");
1992 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1993 MapVote_AddVotable(GetNextMap(), FALSE);
1996 mapvote_count_real = mapvote_count;
1998 MapVote_AddVotable("don't care", 0);
2000 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
2002 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
2003 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
2004 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
2005 mapvote_keeptwotime = 0;
2006 mapvote_message = "Choose a map and press its key!";
2008 mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
2009 if(mapvote_screenshot_dir == "")
2010 mapvote_screenshot_dir = "maps";
2011 mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
2016 void MapVote_SendPicture(float id)
2019 WriteByte(MSG_ONE, SVC_TEMPENTITY);
2020 WriteByte(MSG_ONE, TE_CSQC_PICTURE);
2021 WriteByte(MSG_ONE, id);
2022 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 3072);
2025 float GameCommand_MapVote(string cmd)
2027 if(!intermission_running)
2030 if(cmd == "mv_getpic")
2032 MapVote_SendPicture(stof(argv(1)));
2039 float MapVote_GetMapMask()
2041 float mask, i, power;
2043 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
2044 if(mapvote_maps[i] != "")
2050 float MapVote_SendEntity(entity to, float sf)
2052 string mapfile, pakfile;
2055 WriteByte(MSG_ENTITY, ENT_CLIENT_MAPVOTE);
2056 WriteByte(MSG_ENTITY, sf);
2060 // flag 1 == initialization
2061 WriteString(MSG_ENTITY, mapvote_screenshot_dir);
2062 WriteByte(MSG_ENTITY, mapvote_count);
2063 WriteByte(MSG_ENTITY, mapvote_abstain);
2064 WriteByte(MSG_ENTITY, mapvote_detail);
2065 WriteCoord(MSG_ENTITY, mapvote_timeout);
2066 if(mapvote_count <= 8)
2067 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2069 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2070 for(i = 0; i < mapvote_count; ++i)
2071 if(mapvote_maps[i] != "")
2073 WriteString(MSG_ENTITY, mapvote_maps[i]);
2074 mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
2075 pakfile = whichpack(strcat(mapfile, ".tga"));
2077 pakfile = whichpack(strcat(mapfile, ".jpg"));
2079 pakfile = whichpack(strcat(mapfile, ".png"));
2080 print("pakfile is ", pakfile, "\n");
2081 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
2082 pakfile = substring(pakfile, o, 999);
2083 WriteString(MSG_ENTITY, pakfile);
2089 // flag 2 == update of mask
2090 if(mapvote_count <= 8)
2091 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2093 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2099 for(i = 0; i < mapvote_count; ++i)
2100 if(mapvote_maps[i] != "")
2101 WriteByte(MSG_ENTITY, mapvote_votes[i]);
2103 WriteByte(MSG_ENTITY, to.mapvote);
2109 void MapVote_Spawn()
2111 Net_LinkEntity(mapvote_ent = spawn(), FALSE, 0, MapVote_SendEntity);
2114 void MapVote_TouchMask()
2116 mapvote_ent.SendFlags |= 2;
2119 void MapVote_TouchVotes(entity voter)
2121 mapvote_ent.SendFlags |= 4;
2124 float MapVote_Finished(float mappos)
2130 if(cvar("sv_eventlog"))
2132 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2133 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
2134 didntvote = mapvote_voters;
2135 for(i = 0; i < mapvote_count; ++i)
2136 if(mapvote_maps[i] != "")
2138 didntvote -= mapvote_votes[i];
2141 result = strcat(result, ":", mapvote_maps[i]);
2142 result = strcat(result, ":", ftos(mapvote_votes[i]));
2145 result = strcat(result, ":didn't vote:", ftos(didntvote));
2147 GameLogEcho(result);
2148 if(mapvote_maps_suggested[mappos])
2149 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
2152 FOR_EACH_REALCLIENT(other)
2153 FixClientCvars(other);
2155 Map_Goto_SetStr(mapvote_maps[mappos]);
2157 alreadychangedlevel = TRUE;
2160 void MapVote_CheckRules_1()
2164 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2166 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2167 mapvote_votes[i] = 0;
2171 FOR_EACH_REALCLIENT(other)
2176 i = other.mapvote - 1;
2177 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2178 mapvote_votes[i] = mapvote_votes[i] + 1;
2183 float MapVote_CheckRules_2()
2186 float firstPlace, secondPlace;
2187 float firstPlaceVotes, secondPlaceVotes;
2188 float mapvote_voters_real;
2191 mapvote_voters_real = mapvote_voters;
2193 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2195 RandomSelection_Init();
2196 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2197 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2198 firstPlace = RandomSelection_chosen_float;
2199 firstPlaceVotes = RandomSelection_best_priority;
2200 //dprint("First place: ", ftos(firstPlace), "\n");
2201 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2203 RandomSelection_Init();
2204 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2206 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2207 secondPlace = RandomSelection_chosen_float;
2208 secondPlaceVotes = RandomSelection_best_priority;
2209 //dprint("Second place: ", ftos(secondPlace), "\n");
2210 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2212 if(firstPlace == -1)
2213 error("No first place in map vote... WTF?");
2215 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2216 return MapVote_Finished(firstPlace);
2218 if(mapvote_keeptwotime)
2219 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2222 MapVote_TouchMask();
2223 mapvote_message = "Now decide between the TOP TWO!";
2224 mapvote_keeptwotime = 0;
2225 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2226 result = strcat(result, ":", ftos(firstPlaceVotes));
2227 result = strcat(result, ":", mapvote_maps[secondPlace]);
2228 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2229 didntvote = mapvote_voters;
2230 for(i = 0; i < mapvote_count; ++i)
2231 if(mapvote_maps[i] != "")
2233 didntvote -= mapvote_votes[i];
2235 if(i != secondPlace)
2237 result = strcat(result, ":", mapvote_maps[i]);
2238 result = strcat(result, ":", ftos(mapvote_votes[i]));
2239 if(i < mapvote_count_real)
2241 strunzone(mapvote_maps[i]);
2242 mapvote_maps[i] = "";
2246 result = strcat(result, ":didn't vote:", ftos(didntvote));
2247 if(cvar("sv_eventlog"))
2248 GameLogEcho(result);
2258 keeptwo = mapvote_keeptwotime;
2259 MapVote_CheckRules_1(); // count
2260 if(MapVote_CheckRules_2()) // decide
2264 FOR_EACH_REALCLIENT(other)
2266 // hide scoreboard again
2267 if(other.health != 2342)
2269 other.health = 2342;
2271 if(clienttype(other) == CLIENTTYPE_REAL)
2274 WriteByte(MSG_ONE, SVC_FINALE);
2275 WriteString(MSG_ONE, "");
2279 // notify about keep-two
2280 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2281 play2(other, "misc/invshot.wav");
2283 // clear possibly invalid votes
2284 if(mapvote_maps[other.mapvote - 1] == "")
2286 // use impulses as new vote
2287 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2288 if(mapvote_maps[other.impulse - 1] != "")
2290 other.mapvote = other.impulse;
2291 MapVote_TouchVotes(other);
2299 MapVote_CheckRules_1(); // just count
2301 void MapVote_Start()
2306 MapInfo_Enumerate();
2307 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0, (g_maplist_allow_hidden ? MAPINFO_FLAG_HIDDEN : 0), 1))
2310 void MapVote_Think()
2315 if(alreadychangedlevel)
2318 if(time < mapvote_nextthink)
2322 mapvote_nextthink = time + 0.5;
2324 if(!mapvote_initialized)
2326 mapvote_initialized = TRUE;
2327 if(DoNextMapOverride())
2329 if(!cvar("g_maplist_votable") || player_count <= 0)
2340 string GotoMap(string m)
2342 if(!MapInfo_CheckMap(m))
2343 return "The map you chose is not available on this server.";
2344 cvar_set("nextmap", m);
2345 cvar_set("timelimit", "-1");
2346 if(mapvote_initialized || alreadychangedlevel)
2348 if(DoNextMapOverride())
2349 return "Map switch initiated.";
2351 return "Hm... no. For some reason I like THIS map more.";
2354 return "Map switch will happen after scoreboard.";
2360 FOR_EACH_REALCLIENT(self)
2362 if(self.classname == "spectator")
2364 if(self.enemy.typehitsound)
2365 play2(self, "misc/typehit.wav");
2366 else if(self.enemy.hitsound && self.cvar_cl_hitsound)
2367 play2(self, "misc/hit.wav");
2371 if(self.typehitsound)
2372 play2(self, "misc/typehit.wav");
2373 else if(self.hitsound && self.cvar_cl_hitsound)
2374 play2(self, "misc/hit.wav");
2377 FOR_EACH_CLIENT(self)
2379 self.hitsound = FALSE;
2380 self.typehitsound = FALSE;
2387 * returns TRUE if redirecting
2389 float redirection_timeout;
2390 float redirection_nextthink;
2391 float RedirectionThink()
2393 float clients_found;
2395 if(redirection_target == "")
2398 if(!redirection_timeout)
2400 cvar_set("sv_public", "-2");
2401 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2402 if(redirection_target == "self")
2403 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2405 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2408 if(time < redirection_nextthink)
2411 redirection_nextthink = time + 1;
2414 FOR_EACH_REALCLIENT(self)
2416 print("Redirecting: sending connect command to ", self.netname, "\n");
2417 if(redirection_target == "self")
2418 stuffcmd(self, "\ndisconnect; reconnect\n");
2420 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2424 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2426 if(time > redirection_timeout || clients_found == 0)
2427 localcmd("\nwait; wait; wait; quit\n");
2434 // Loaded from a save game
2435 // some things then break, so let's work around them...
2437 // Progs DB (capture records)
2439 ServerProgsDB = db_create();
2441 ServerProgsDB = db_load("server.db");
2445 MapInfo_Enumerate();
2446 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0, (g_maplist_allow_hidden ? MAPINFO_FLAG_HIDDEN : 0), 1);
2451 if(world_initialized > 0)
2453 world_initialized = 0;
2454 print("Saving persistent data...\n");
2457 db_save(ServerProgsDB, "server.db");
2458 if(cvar("developer"))
2459 db_save(TemporaryDB, "server-temp.db");
2460 db_close(ServerProgsDB);
2461 db_close(TemporaryDB);
2463 // tell the bot system the game is ending now
2468 else if(world_initialized == 0)
2470 print("NOTE: crashed before even initializing the world, not saving persistent data\n");