2 void PingPLReport_Think()
7 delta = 3 / maxclients;
8 if(delta < sys_frametime)
10 self.nextthink = time + delta;
12 e = edict_num(self.cnt + 1);
13 if(clienttype(e) == CLIENTTYPE_REAL)
15 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
16 WriteByte(MSG_BROADCAST, TE_CSQC_PINGPLREPORT);
17 WriteByte(MSG_BROADCAST, self.cnt);
18 WriteShort(MSG_BROADCAST, max(1, e.ping));
19 WriteByte(MSG_BROADCAST, ceil(e.ping_packetloss * 255));
20 WriteByte(MSG_BROADCAST, ceil(e.ping_movementloss * 255));
24 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
25 WriteByte(MSG_BROADCAST, TE_CSQC_PINGPLREPORT);
26 WriteByte(MSG_BROADCAST, self.cnt);
27 WriteShort(MSG_BROADCAST, 0);
28 WriteByte(MSG_BROADCAST, 0);
29 WriteByte(MSG_BROADCAST, 0);
31 self.cnt = mod(self.cnt + 1, maxclients);
33 void PingPLReport_Spawn()
35 pingplreport = spawn();
36 pingplreport.classname = "pingplreport";
37 pingplreport.think = PingPLReport_Think;
38 pingplreport.nextthink = time;
41 float SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS = 1;
42 string redirection_target;
43 float world_initialized;
49 float() DoNextMapOverride;
51 void SetDefaultAlpha()
53 if(cvar("g_running_guns"))
55 default_player_alpha = -1;
56 default_weapon_alpha = +1;
60 default_player_alpha = cvar("g_balance_cloaked_alpha");
61 default_weapon_alpha = default_player_alpha;
65 default_player_alpha = cvar("g_player_alpha");
66 if(default_player_alpha == 0)
67 default_player_alpha = 1;
68 default_weapon_alpha = default_player_alpha;
72 void fteqcc_testbugs()
76 if(!cvar("developer_fteqccbugs"))
79 dprint("*** fteqcc test: checking for bugs...\n");
83 if(sqrt(a) - sqrt(b - a) == 0)
84 dprint("*** fteqcc test: found same-function-twice bug\n");
86 dprint("*** fteqcc test: same-function-twice bug got FINALLY FIXED! HOORAY!\n");
90 world.enemy.cnt += 10;
91 if(world.cnt > 0.2 || world.cnt < -0.2) // don't error out if it's just roundoff errors
92 dprint("*** fteqcc test: found += bug\n");
94 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
99 * Takes care of pausing and unpausing the game.
100 * Centerprints the information about an upcoming or active timeout to all active
101 * players. Also plays reminder sounds.
103 void timeoutHandler_Think() {
104 local string timeStr;
106 if (timeoutStatus == 1) {
107 if (remainingLeadTime > 0) {
108 //centerprint the information to every player
109 timeStr = getTimeoutText(0);
110 FOR_EACH_REALCLIENT(plr) {
111 if(plr.classname == "player") {
112 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
115 remainingLeadTime -= 1;
116 //think again in 1 second:
117 self.nextthink = time + 1;
120 //now pause the game:
122 //reset all the flood variables
123 FOR_EACH_CLIENT(plr) {
124 plr.nickspamcount = plr.nickspamtime = plr.floodcontrol_chat = plr.floodcontrol_chatteam = plr.floodcontrol_chattell = plr.floodcontrol_voice = plr.floodcontrol_voiceteam = 0;
126 cvar_set("slowmo", ftos(TIMEOUT_SLOWMO_VALUE));
127 //copy .v_angle to .lastV_angle for every player in order to fix their view during pause (see PlayerPreThink)
128 FOR_EACH_REALPLAYER(plr) {
129 plr.lastV_angle = plr.v_angle;
131 self.nextthink = time;
134 else if (timeoutStatus == 2) {
135 if (remainingTimeoutTime > 0) {
136 timeStr = getTimeoutText(0);
137 FOR_EACH_REALCLIENT(plr) {
138 if(plr.classname == "player") {
139 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
142 if(remainingTimeoutTime == cvar("sv_timeout_resumetime")) { //play a warning sound when only <sv_timeout_resumetime> seconds are left
143 Announce("prepareforbattle");
145 remainingTimeoutTime -= 1;
146 self.nextthink = time + TIMEOUT_SLOWMO_VALUE;
149 //unpause the game again
150 remainingTimeoutTime = timeoutStatus = 0;
151 cvar_set("slowmo", ftos(orig_slowmo));
152 //and unlock the fixed view again once there is no timeout active anymore
153 FOR_EACH_REALPLAYER(plr) {
154 plr.fixangle = FALSE;
156 //get rid of the countdown message
157 FOR_EACH_REALCLIENT(plr) {
158 if(plr.classname == "player") {
159 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
167 else if (timeoutStatus == 0) { //if a player called the resumegame command (which set timeoutStatus to 0 already)
168 FOR_EACH_REALCLIENT(plr) {
169 if(plr.classname == "player") {
170 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
183 // cvar_set("_sv_init", "0");
184 // we do NOT set this to 0 any more, so someone "accidentally" changing
185 // to this "init" map on a dedicated server will cause no permanent
187 if(cvar("g_maplist_shuffle"))
189 n = tokenizebyseparator(cvar_string("g_maplist"), " ");
190 cvar_set("g_maplist_index", ftos(n - 1)); // jump to map 0 in GotoNextMap
193 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
195 if(!DoNextMapOverride())
203 self.nextthink = time;
207 self.nextthink = time + 1;
208 print("Waiting for _sv_init being set to 1 by initialization scripts...\n");
212 void cvar_changes_init()
216 float n, i, adding, pureadding;
219 strunzone(cvar_changes);
220 cvar_changes = string_null;
222 strunzone(cvar_purechanges);
223 cvar_purechanges = string_null;
224 cvar_purechanges_count = 0;
227 buf_cvarlist(h, "", "_"); // exclude all _ cvars as they are temporary
233 for(i = 0; i < n; ++i)
235 k = bufstr_get(h, i);
237 #define BADPREFIX(p) if(substring(k, 0, strlen(p)) == p) continue
238 #define BADCVAR(p) if(k == p) continue
241 BADPREFIX("cvar_check_");
243 BADCVAR("g_configversion");
244 BADCVAR("g_maplist_index");
245 BADCVAR("halflifebsp");
246 BADPREFIX("sv_world");
252 BADPREFIX("scoreboard_");
253 BADPREFIX("g_campaign");
258 BADPREFIX("net_slist_");
262 BADPREFIX("userbind");
265 BADPREFIX("crosshair");
266 BADCVAR("mod_q3bsp_lightmapmergepower");
267 BADCVAR("mod_q3bsp_nolightmaps");
270 BADCVAR("serverconfig");
272 BADPREFIX("g_chat_flood_");
273 BADPREFIX("g_voice_flood_");
275 BADPREFIX("settemp_");
276 BADPREFIX("sv_allowdownloads_");
277 BADPREFIX("sv_autodemo");
278 BADPREFIX("sv_curl_");
279 BADPREFIX("sv_eventlog");
280 BADPREFIX("sv_logscores_");
281 BADPREFIX("sv_master");
282 BADCVAR("g_banned_list");
283 BADCVAR("log_dest_udp");
285 BADCVAR("net_address");
287 BADCVAR("savedgamecfg");
288 BADCVAR("sv_heartbeatperiod");
289 BADCVAR("sv_vote_master_password");
290 BADCVAR("sys_colortranslation");
291 BADCVAR("sys_specialcharactertranslation");
292 BADCVAR("timestamps");
293 BADCVAR("net_address");
294 BADCVAR("net_address_ipv6");
295 BADPREFIX("sv_weaponstats_");
296 BADCVAR("developer");
297 BADPREFIX("developer_");
300 BADCVAR("timelimit");
301 BADCVAR("fraglimit");
304 BADCVAR("g_assault");
307 BADCVAR("g_domination");
308 BADCVAR("g_keyhunt");
309 BADCVAR("g_keyhunt_teams");
310 BADCVAR("g_onslaught");
313 BADCVAR("g_runematch");
315 BADCVAR("g_nexball");
320 BADCVAR("g_maplist");
321 BADCVAR("g_maplist_mostrecent");
325 d = cvar_defstring(k);
331 cvar_changes = strcat(cvar_changes, k, " \"", v, "\" // \"", d, "\"\n");
332 if(strlen(cvar_changes) > 16384)
334 cvar_changes = "// too many settings have been changed to show them here\n";
339 // now check if the changes are actually gameplay relevant
341 // does nothing visible
344 // allowed changes to server admins (please sync this to server.cfg)
348 // :%s,//\([^ ]*\).*,BADCVAR("\1");,
350 // yes, this does contain some redundant stuff, don't really care
351 BADCVAR("bot_number");
352 BADCVAR("bot_prefix");
353 BADCVAR("bot_suffix");
354 BADCVAR("capturelimit_override");
355 BADCVAR("fraglimit_override");
357 BADCVAR("g_antilag");
358 BADCVAR("g_balance_teams");
359 BADCVAR("g_balance_teams_force");
360 BADCVAR("g_ban_sync_trusted_servers");
361 BADCVAR("g_ban_sync_uri");
362 BADCVAR("g_ctf_capture_limit");
363 BADCVAR("g_ctf_ignore_frags");
364 BADCVAR("g_ctf_win_mode");
365 BADCVAR("g_domination_point_limit");
366 BADCVAR("g_fullbrightitems");
367 BADCVAR("g_fullbrightplayers");
368 BADCVAR("g_keyhunt_point_limit");
369 BADCVAR("g_keyhunt_teams_override");
370 BADCVAR("g_lms_lives_override");
371 BADCVAR("g_maplist");
372 BADCVAR("g_maplist_check_waypoints");
373 BADCVAR("g_maplist_mostrecent_count");
374 BADCVAR("g_maplist_shuffle");
375 BADCVAR("g_maplist_votable");
376 BADCVAR("g_maplist_votable_abstain");
377 BADCVAR("g_maplist_votable_nodetail");
378 BADCVAR("g_maplist_votable_suggestions");
379 BADCVAR("g_nexball_goallimit");
380 BADCVAR("g_runematch_point_limit");
381 BADCVAR("g_start_delay");
384 BADCVAR("maxplayers");
385 BADCVAR("minplayers");
386 BADCVAR("net_address");
388 BADCVAR("rcon_password");
389 BADCVAR("rcon_restricted_commands");
390 BADCVAR("rcon_restricted_password");
392 BADCVAR("sv_autoscreenshot");
393 BADCVAR("sv_curl_defaulturl");
394 BADCVAR("sv_defaultcharacter");
395 BADCVAR("sv_defaultplayermodel");
396 BADCVAR("sv_defaultplayerskin");
397 BADCVAR("sv_maxrate");
398 BADCVAR("sv_maxidle");
400 BADCVAR("sv_public");
401 BADCVAR("sv_ready_restart");
402 BADCVAR("sv_status_privacy");
403 BADCVAR("sv_vote_call");
404 BADCVAR("sv_vote_commands");
405 BADCVAR("sv_vote_majority_factor");
406 BADCVAR("sv_vote_master");
407 BADCVAR("sv_vote_master_commands");
408 BADCVAR("sv_vote_master_password");
409 BADCVAR("sv_vote_simple_majority_factor");
410 BADCVAR("timelimit_override");
416 cvar_purechanges = strcat(cvar_purechanges, k, " \"", v, "\" // \"", d, "\"\n");
417 if(strlen(cvar_purechanges) > 16384)
419 cvar_purechanges = "// too many settings have been changed to show them here\n";
423 ++cvar_purechanges_count;
426 if(cvar_changes == "")
427 cvar_changes = "// this server runs at default server settings\n";
429 cvar_changes = strcat("// this server runs at modified server settings:\n", cvar_changes);
430 cvar_changes = strzone(cvar_changes);
431 if(cvar_purechanges == "")
432 cvar_purechanges = "// this server runs at default gameplay settings\n";
434 cvar_purechanges = strcat("// this server runs at modified gameplay settings:\n", cvar_purechanges);
435 cvar_purechanges = strzone(cvar_purechanges);
438 void detect_maptype()
447 o_x += random() * (world.maxs_x - world.mins_x);
448 o_y += random() * (world.maxs_y - world.mins_y);
449 o_z += random() * (world.maxs_z - world.mins_z);
451 tracebox(o, PL_MIN, PL_MAX, o - '0 0 32768', MOVE_WORLDONLY, world);
452 if(trace_fraction == 1)
457 for(i = 0; i < 64; i += 4)
459 tracebox(o, '-1 -1 -1' * i, '1 1 1' * i, o - '0 0 32768', MOVE_WORLDONLY, world);
460 if(trace_fraction == 1)
462 print(ftos(i), " -> ", vtos(trace_endpos), "\n");
471 float RandomSeed_Send(entity to, float sf)
473 WriteByte(MSG_ENTITY, ENT_CLIENT_RANDOMSEED);
474 WriteShort(MSG_ENTITY, self.cnt);
477 void RandomSeed_Think()
479 self.cnt = bound(0, floor(random() * 65536), 65535);
480 self.nextthink = time + 5;
484 void RandomSeed_Spawn()
486 randomseed = spawn();
487 randomseed.think = RandomSeed_Think;
488 Net_LinkEntity(randomseed, FALSE, 0, RandomSeed_Send);
493 self.think(); // sets random seed and nextthink
497 void spawnfunc___init_dedicated_server(void)
499 // handler for _init/_init map (only for dedicated server initialization)
501 world_initialized = -1; // don't complain
503 cvar_string = cvar_string_normal;
504 cvar_set = cvar_set_normal;
506 remove = remove_unsafely;
510 e.think = GotoFirstMap;
511 e.nextthink = time; // this is usually 1 at this point
514 e.classname = "info_player_deathmatch"; // safeguard against player joining
516 self.classname = "worldspawn"; // safeguard against various stuff ;)
519 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
522 void Map_MarkAsRecent(string m);
523 float world_already_spawned;
524 void RegisterWeapons();
526 void ClientInit_Spawn();
527 void WeaponStats_Init();
528 void WeaponStats_Shutdown();
529 void spawnfunc_worldspawn (void)
531 float fd, l, i, j, n;
535 cvar_string = cvar_string_normal;
536 cvar_set = cvar_set_normal;
538 if(world_already_spawned)
539 error("world already spawned - you may have EXACTLY ONE worldspawn!");
540 world_already_spawned = TRUE;
542 remove = remove_safely; // during spawning, watch what you remove!
544 check_unacceptable_compiler_bugs();
546 cvar_changes_init(); // do this very early now so it REALLY matches the server config
548 compressShortVector_init();
550 allowed_to_spawn = TRUE;
553 head = nextent(world);
558 head = nextent(head);
561 // needs to be done so early as they would still spawn
564 ServerProgsDB = db_load("server.db");
566 TemporaryDB = db_create();
569 TODO sound pack system
570 // initialize sound pack system
571 soundpack = cvar_string("g_soundpack");
573 soundpack = strcat(soundpack, "/");
574 soundpack = strzone(soundpack);
580 // 1 FLICKER (first variety)
581 lightstyle(1, "mmnmmommommnonmmonqnmmo");
583 // 2 SLOW STRONG PULSE
584 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
586 // 3 CANDLE (first variety)
587 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
590 lightstyle(4, "mamamamamama");
593 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
595 // 6 FLICKER (second variety)
596 lightstyle(6, "nmonqnmomnmomomno");
598 // 7 CANDLE (second variety)
599 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
601 // 8 CANDLE (third variety)
602 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
604 // 9 SLOW STROBE (fourth variety)
605 lightstyle(9, "aaaaaaaazzzzzzzz");
607 // 10 FLUORESCENT FLICKER
608 lightstyle(10, "mmamammmmammamamaaamammma");
610 // 11 SLOW PULSE NOT FADE TO BLACK
611 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
613 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
618 if(cvar("g_campaign"))
621 Map_MarkAsRecent(mapname);
623 precache_model ("null"); // we need this one before InitGameplayMode
631 bot_waypoints_for_items = cvar("g_waypoints_for_items");
632 if(bot_waypoints_for_items == 1)
633 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
634 bot_waypoints_for_items = 0;
636 // for setting by mapinfo
637 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
638 cvar_set("sv_q3acompat_machineshotgunswap", "0");
642 WaypointSprite_Init();
647 GameLogInit(); // prepare everything
648 if(cvar("sv_eventlog"))
650 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
651 s = strcat(s, ftos(random()));
652 matchid = strzone(s);
654 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
655 s = ":gameinfo:mutators:LIST";
658 MUTATOR_CALLHOOK(BuildMutatorsString);
661 if(cvar("g_grappling_hook"))
662 s = strcat(s, ":grappling_hook");
663 if(!cvar("g_use_ammunition"))
664 s = strcat(s, ":no_use_ammunition");
665 if(!cvar("g_pickup_items"))
666 s = strcat(s, ":no_pickup_items");
667 if(cvar_string("g_weaponarena") != "0")
668 s = strcat(s, ":", cvar_string("g_weaponarena"), " arena");
669 if(cvar("g_vampire"))
670 s = strcat(s, ":vampire");
671 if(cvar("g_laserguided_missile"))
672 s = strcat(s, ":laserguided_missile");
673 if(cvar("g_norecoil"))
674 s = strcat(s, ":norecoil");
676 s = strcat(s, ":midair");
677 if(cvar("g_minstagib"))
678 s = strcat(s, ":minstagib");
680 GameLogEcho(":gameinfo:end");
683 matchid = strzone(ftos(random()));
685 cvar_set("nextmap", "");
689 if(cvar("g_campaign"))
697 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
699 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
701 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
704 while((s = fgets(fd)))
706 l = tokenize_console(s);
711 print("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
712 print(" cdtrack ", argv(2), "\n");
714 else if(argv(0) == "fog")
716 print("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
717 print(" \"fog\" \"", s, "\"\n");
719 else if(argv(0) == "set")
721 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
722 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
724 else if(argv(0) != "//")
726 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
727 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
736 addstat(STAT_WEAPONS, AS_INT, weapons);
737 addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
738 addstat(STAT_GAMESTARTTIME, AS_FLOAT, stat_game_starttime);
739 addstat(STAT_ALLOW_OLDNEXBEAM, AS_INT, stat_allow_oldnexbeam);
742 addstat(STAT_STRENGTH_FINISHED, AS_FLOAT, strength_finished);
743 addstat(STAT_INVINCIBLE_FINISHED, AS_FLOAT, invincible_finished);
744 addstat(STAT_PRESSED_KEYS, AS_FLOAT, pressedkeys);
745 addstat(STAT_FUEL, AS_INT, ammo_fuel);
746 addstat(STAT_DAMAGE_HITS, AS_INT, stat_hit);
747 addstat(STAT_DAMAGE_FIRED, AS_INT, stat_fired);
748 addstat(STAT_SHOTORG, AS_INT, stat_shotorg);
749 addstat(STAT_LEADLIMIT, AS_FLOAT, stat_leadlimit);
750 addstat(STAT_BULLETS_LOADED, AS_INT, campingrifle_bulletcounter);
751 addstat(STAT_LAST_PICKUP, AS_FLOAT, last_pickup);
753 addstat(STAT_NEX_CHARGE, AS_FLOAT, nex_charge);
757 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
758 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
760 // g_movementspeed hack
761 addstat(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW, AS_FLOAT, stat_sv_airspeedlimit_nonqw);
762 addstat(STAT_MOVEVARS_AIRACCEL_QW, AS_FLOAT, stat_sv_airaccel_qw);
763 addstat(STAT_MOVEVARS_AIRSTRAFEACCEL_QW, AS_FLOAT, stat_sv_airstrafeaccel_qw);
765 next_pingtime = time + 5;
769 lsmaps_reply = "^7Maps available: ";
770 lsnewmaps_reply = "^7Maps without a record set: ";
771 for(i = 0, j = 0; i < MapInfo_count; ++i)
773 if(MapInfo_Get_ByID(i))
774 if not(MapInfo_Map_flags & (MAPINFO_FLAG_HIDDEN | MAPINFO_FLAG_FORBIDDEN))
781 lsmaps_reply = strcat(lsmaps_reply, col, MapInfo_Map_bspname, " ");
782 if(g_race && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "time"))))
783 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
784 else if(g_cts && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "time"))))
785 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
788 lsmaps_reply = strzone(strcat(lsmaps_reply, "\n"));
789 if (!g_race && !g_cts)
790 lsnewmaps_reply = "Need to be playing race or CTS for lsnewmaps to work.";
791 lsnewmaps_reply = strzone(strcat(lsnewmaps_reply, "\n"));
793 maplist_reply = "^7Maps in list: ";
794 n = tokenize_console(cvar_string("g_maplist"));
795 for(i = 0, j = 0; i < n; ++i)
797 if(MapInfo_CheckMap(argv(i)))
803 maplist_reply = strcat(maplist_reply, col, argv(i), " ");
807 maplist_reply = strzone(strcat(maplist_reply, "\n"));
808 MapInfo_ClearTemps();
810 for(i = 0; i < 10; ++i)
812 records_reply[i] = strzone(getrecords(i));
815 rankings_reply = strzone(getrankings());
819 PingPLReport_Spawn();
823 localcmd("\n_sv_hook_gamestart ", GetGametype(), "\n");
825 // fill sv_curl_serverpackages from .serverpackage files
826 if(cvar("sv_curl_serverpackages_auto"))
828 fd = search_begin("*.serverpackage", TRUE, FALSE);
832 j = search_getsize(fd);
833 for(i = 0; i < j; ++i)
834 s = strcat(s, " ", search_getfilename(fd, i));
837 cvar_set("sv_curl_serverpackages", substring(s, 1, -1));
840 world_initialized = 1;
843 void spawnfunc_light (void)
845 //makestatic (self); // Who the f___ did that?
849 float TryFile( string pFilename )
852 dprint("TryFile(\"", pFilename, "\")\n");
853 lHandle = fopen( pFilename, FILE_READ );
854 if( lHandle != -1 ) {
864 return GametypeNameFromType(game);
867 string getmapname_stored;
873 float Map_Count, Map_Current;
874 string Map_Current_Name;
876 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
877 float GetMaplistPosition()
883 idx = cvar("g_maplist_index");
890 for(pos = 0; pos < Map_Count; ++pos)
894 // resume normal maplist rotation if current map is not in g_maplist
898 float MapHasRightSize(string map)
901 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
902 if(cvar("g_maplist_check_waypoints"))
904 dprint("checkwp "); dprint(map);
905 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
908 dprint(": no waypoints\n");
911 dprint(": has waypoints\n");
915 // open map size restriction file
916 dprint("opensize "); dprint(map);
917 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
920 float mapmin, mapmax;
922 mapmin = stof(fgets(fh));
923 mapmax = stof(fgets(fh));
925 if(player_count < mapmin)
927 dprint("not enough\n");
930 if(player_count > mapmax)
932 dprint("too many\n");
935 dprint("right size\n");
938 dprint(": not found\n");
942 string Map_Filename(float position)
944 return strcat("maps/", argv(position), ".bsp");
947 string strwords(string s, float w)
950 for(endpos = 0; w && endpos >= 0; --w)
951 endpos = strstrofs(s, " ", endpos + 1);
955 return substring(s, 0, endpos);
958 float strhasword(string s, string w)
960 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
963 void Map_MarkAsRecent(string m)
965 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), max(0, cvar("g_maplist_mostrecent_count"))));
968 float Map_IsRecent(string m)
970 return strhasword(cvar_string("g_maplist_mostrecent"), m);
973 float Map_Check(float position, float pass)
977 map_next = argv(position);
980 if(Map_IsRecent(map_next))
983 filename = Map_Filename(position);
984 if(MapInfo_CheckMap(map_next))
988 if(MapHasRightSize(map_next))
993 dprint( "Couldn't select '", filename, "'..\n" );
998 void Map_Goto_SetStr(string nextmapname)
1000 if(getmapname_stored != "")
1001 strunzone(getmapname_stored);
1002 if(nextmapname == "")
1003 getmapname_stored = "";
1005 getmapname_stored = strzone(nextmapname);
1008 void Map_Goto_SetFloat(float position)
1010 cvar_set("g_maplist_index", ftos(position));
1011 Map_Goto_SetStr(argv(position));
1016 // settings persist, except...
1017 localcmd("\nsettemp_restore\n");
1023 MapInfo_LoadMap(getmapname_stored);
1026 // return codes of map selectors:
1027 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
1028 // -2 = permanent failure
1029 float() MaplistMethod_Iterate = // usual method
1033 for(pass = 1; pass <= 2; ++pass)
1035 for(i = 1; i < Map_Count; ++i)
1038 mapindex = mod(i + Map_Current, Map_Count);
1039 if(Map_Check(mapindex, pass))
1046 float() MaplistMethod_Repeat = // fallback method
1048 if(Map_Check(Map_Current, 2))
1053 float() MaplistMethod_Random = // random map selection
1059 for(i = 0; i <= imax; ++i)
1062 mapindex = mod(Map_Current + floor(random() * (Map_Count - 1) + 1), Map_Count); // any OTHER map
1063 if(Map_Check(mapindex, 1))
1069 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
1070 // the exponent sets a bias on the map selection:
1071 // the higher the exponent, the less likely "shortly repeated" same maps are
1073 float i, j, imax, insertpos;
1077 for(i = 0; i <= imax; ++i)
1081 // now reinsert this at another position
1082 insertpos = pow(random(), 1 / exponent); // ]0, 1]
1083 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
1084 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
1085 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
1087 // insert the current map there
1089 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
1090 newlist = strcat(newlist, " ", argv(j));
1091 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
1092 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
1093 newlist = strcat(newlist, " ", argv(j));
1094 newlist = substring(newlist, 1, strlen(newlist) - 1);
1095 cvar_set("g_maplist", newlist);
1096 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
1098 // NOTE: the selected map has just been inserted at (insertpos-1)th position
1099 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
1100 if(Map_Check(Map_Current, 1))
1108 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
1111 bprint( "Maplist is empty! Resetting it to default map list.\n" );
1112 cvar_set("g_maplist", MapInfo_ListAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
1113 if(cvar("g_maplist_shuffle"))
1115 localcmd("\nmenu_cmd sync\n");
1116 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
1119 error("empty maplist, cannot select a new map");
1120 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
1122 if(Map_Current_Name)
1123 strunzone(Map_Current_Name);
1124 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
1125 // this may or may not be correct, but who cares, in the worst case a map
1126 // isn't chosen in the first pass that should have been
1137 if(cvar("g_maplist_shuffle") > 0)
1138 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
1141 if(cvar("g_maplist_selectrandom"))
1142 nextMap = MaplistMethod_Random();
1145 nextMap = MaplistMethod_Iterate();
1148 nextMap = MaplistMethod_Repeat();
1152 Map_Goto_SetFloat(nextMap);
1153 return getmapname_stored;
1159 float DoNextMapOverride()
1161 if(cvar("g_campaign"))
1163 CampaignPostIntermission();
1164 alreadychangedlevel = TRUE;
1167 if(cvar("quit_when_empty"))
1169 if(player_count <= currentbots)
1172 alreadychangedlevel = TRUE;
1176 if(cvar_string("quit_and_redirect") != "")
1178 redirection_target = strzone(cvar_string("quit_and_redirect"));
1179 alreadychangedlevel = TRUE;
1182 if (cvar("samelevel")) // if samelevel is set, stay on same level
1184 // 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)
1185 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
1186 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
1187 localcmd("restart\n");
1188 //changelevel (mapname);
1189 alreadychangedlevel = TRUE;
1192 if(cvar_string("nextmap") != "")
1193 if(MapInfo_CheckMap(cvar_string("nextmap")))
1195 Map_Goto_SetStr(cvar_string("nextmap"));
1197 alreadychangedlevel = TRUE;
1200 if(cvar("lastlevel"))
1203 localcmd("set lastlevel 0\ntogglemenu\n");
1204 alreadychangedlevel = TRUE;
1212 //local string nextmap;
1213 //local float n, nummaps;
1215 if (alreadychangedlevel)
1217 alreadychangedlevel = TRUE;
1223 for(allowReset = 1; allowReset >= 0; --allowReset)
1225 nextMap = GetNextMap();
1231 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1232 cvar_set("g_maplist", MapInfo_ListAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
1233 if(cvar("g_maplist_shuffle"))
1235 localcmd("\nmenu_cmd sync\n");
1239 error("Everything is broken - not even the default map list works. Please report this to the developers.");
1251 When the player presses attack or jump, change to the next level
1254 .float autoscreenshot;
1255 void() MapVote_Start;
1256 void() MapVote_Think;
1257 float mapvote_initialized;
1258 void IntermissionThink()
1260 FixIntermissionClient(self);
1262 if(cvar("sv_autoscreenshot"))
1263 if(self.autoscreenshot > 0)
1264 if(time > self.autoscreenshot)
1266 self.autoscreenshot = -1;
1267 if(clienttype(self) == CLIENTTYPE_REAL)
1268 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
1272 if (time < intermission_exittime)
1275 if(!mapvote_initialized)
1276 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
1286 Returns the entity to view from
1290 entity FindIntermission()
1295 // look for info_intermission first
1296 spot = find (world, classname, "info_intermission");
1298 { // pick a random one
1302 spot = find (spot, classname, "info_intermission");
1304 spot = find (spot, classname, "info_intermission");
1310 // then look for the start position
1311 spot = find (world, classname, "info_player_start");
1315 // testinfo_player_start is only found in regioned levels
1316 spot = find (world, classname, "testplayerstart");
1320 // then look for the start position
1321 spot = find (world, classname, "info_player_deathmatch");
1325 //objerror ("FindIntermission: no spot");
1331 ===============================================================================
1335 ===============================================================================
1338 void DumpStats(float final)
1342 local float to_console;
1343 local float to_eventlog;
1344 local float to_file;
1347 to_console = cvar("sv_logscores_console");
1348 to_eventlog = cvar("sv_eventlog");
1349 to_file = cvar("sv_logscores_file");
1353 to_console = TRUE; // always print printstats replies
1354 to_eventlog = FALSE; // but never print them to the event log
1358 if(cvar("sv_eventlog_console"))
1359 to_console = FALSE; // otherwise we get the output twice
1365 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
1373 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
1377 fputs(file, strcat(s, "\n"));
1380 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
1386 fputs(file, strcat(s, "\n"));
1388 FOR_EACH_CLIENT(other)
1390 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
1392 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
1393 s = strcat(s, ftos(rint(time - other.jointime)), ":");
1394 if(other.classname == "player" || g_arena || g_ca || g_lms)
1395 s = strcat(s, ftos(other.team), ":");
1397 s = strcat(s, "spectator:");
1400 print(s, other.netname, "\n");
1402 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
1404 fputs(file, strcat(s, other.netname, "\n"));
1410 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
1416 fputs(file, strcat(s, "\n"));
1418 for(i = 1; i < 16; ++i)
1420 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
1421 s = strcat(s, ":", ftos(i));
1427 fputs(file, strcat(s, "\n"));
1434 GameLogEcho(":end");
1437 fputs(file, ":end\n");
1442 void FixIntermissionClient(entity e)
1445 if(!e.autoscreenshot) // initial call
1447 e.angles = e.v_angle;
1448 e.angles_x = -e.angles_x;
1449 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1451 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1452 e.solid = SOLID_NOT;
1453 e.movetype = MOVETYPE_NONE;
1454 e.takedamage = DAMAGE_NO;
1457 e.weaponentity.effects = EF_NODRAW;
1458 if (e.weaponentity.weaponentity)
1459 e.weaponentity.weaponentity.effects = EF_NODRAW;
1461 if(clienttype(e) == CLIENTTYPE_REAL)
1463 stuffcmd(e, "\nscr_printspeed 1000000\n");
1464 s = cvar_string("sv_intermission_cdtrack");
1466 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1468 WriteByte(MSG_ONE, SVC_INTERMISSION);
1472 //e.velocity = '0 0 0';
1473 //e.fixangle = TRUE;
1475 // TODO halt weapon animation
1480 go to the next level for deathmatch
1481 only called if a time or frag limit has expired
1489 intermission_running = 1;
1491 // enforce a wait time before allowing changelevel
1492 if(player_count > 0)
1493 intermission_exittime = time + cvar("sv_mapchange_delay");
1495 intermission_exittime = -1;
1498 WriteByte (MSG_ALL, SVC_CDTRACK);
1499 WriteByte (MSG_ALL, 3);
1500 WriteByte (MSG_ALL, 3);
1501 // done in FixIntermission
1504 //pos = FindIntermission ();
1510 if(cvar("sv_eventlog"))
1511 GameLogEcho(":gameover");
1517 // save the stats to a text file on the client
1518 // stuffcmd(other, log_stats "stats/file_name");
1520 // stuffcmd(other, log_stats "");
1521 // use a filename similar to the demo name
1522 // string file_name;
1523 // file_name = strcat("\nlog_file \"stats/", strftime(TRUE, "%Y-%m-%d_%H-%M"), "_", mapname, ".txt\""); // open the log file
1525 // write a stats parser for the menu
1527 if(cvar("sv_accuracy_data_send")) {
1528 string stats_to_send;
1530 FOR_EACH_CLIENT(other) { // make the string to send
1531 FixIntermissionClient(other);
1533 if(other.cvar_cl_accuracy_data_share) {
1534 stats_to_send = strcat(stats_to_send, ":hits:", other.netname);
1536 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1537 stats_to_send = strcat(stats_to_send, ":", ftos(other.stats_hit[i-1]));
1539 stats_to_send = strcat(stats_to_send, "\n:fired:", other.netname);
1541 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1542 stats_to_send = strcat(stats_to_send, ":", ftos(other.stats_fired[i-1]));
1544 stats_to_send = strcat(stats_to_send, "\n");
1548 FOR_EACH_REALCLIENT(other) { // only spam humans
1549 Score_NicePrint(other); // print the score
1551 if(other.cvar_cl_accuracy_data_receive) // send the stats string to all the willing clients
1552 bprint(stats_to_send);
1554 } else { // ye olde message
1555 FOR_EACH_PLAYER(other) {
1556 FixIntermissionClient(other);
1559 bprint(other.netname, " ^7wins.\n");
1563 if(cvar("g_campaign"))
1564 CampaignPreIntermission();
1566 localcmd("\nsv_hook_gameend\n");
1573 Exit deathmatch games upon conditions
1576 void CheckRules_Player()
1578 if (gameover) // someone else quit the game already
1581 if(self.deadflag == DEAD_NO)
1582 self.play_time += frametime;
1584 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1585 // (div0: and that in CheckRules_World please)
1588 float checkrules_equality;
1589 float checkrules_suddendeathwarning;
1590 float checkrules_suddendeathend;
1591 float checkrules_overtimesadded; //how many overtimes have been already added
1593 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1594 float WINNING_YES = 1; // winner found
1595 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1596 float WINNING_STARTSUDDENDEATHOVERTIME = 3; // no winner, enter suddendeath overtime NOW
1598 float InitiateSuddenDeath()
1600 // Check first whether normal overtimes could be added before initiating suddendeath mode
1601 // - for this timelimit_overtime needs to be >0 of course
1602 // - also check the winning condition calculated in the previous frame and only add normal overtime
1603 // again, if at the point at which timelimit would be extended again, still no winner was found
1604 if ((checkrules_overtimesadded >= 0) && (checkrules_overtimesadded < cvar("timelimit_overtimes")) && cvar("timelimit_overtime") && !(g_race && !g_race_qualifying))
1606 return 1; // need to call InitiateOvertime later
1610 if(!checkrules_suddendeathend)
1612 checkrules_suddendeathend = time + 60 * cvar("timelimit_suddendeath");
1613 if(g_race && !g_race_qualifying)
1614 race_StartCompleting();
1620 void InitiateOvertime() // ONLY call this if InitiateSuddenDeath returned true
1622 ++checkrules_overtimesadded;
1623 //add one more overtime by simply extending the timelimit
1625 tl = cvar("timelimit");
1626 tl += cvar("timelimit_overtime");
1627 cvar_set("timelimit", ftos(tl));
1628 string minutesPlural;
1629 if (cvar("timelimit_overtime") == 1)
1630 minutesPlural = " ^3minute";
1632 minutesPlural = " ^3minutes";
1636 "^3Now playing ^1OVERTIME^3!\n\n^3Added ^1",
1637 ftos(cvar("timelimit_overtime")),
1644 float GetWinningCode(float fraglimitreached, float equality)
1646 if(cvar("g_campaign") == 1)
1647 if(fraglimitreached)
1654 if(fraglimitreached)
1655 return WINNING_STARTSUDDENDEATHOVERTIME;
1657 return WINNING_NEVER;
1659 if(fraglimitreached)
1665 // set the .winning flag for exactly those players with a given field value
1666 void SetWinners(.float field, float value)
1669 FOR_EACH_PLAYER(head)
1670 head.winning = (head.field == value);
1673 // set the .winning flag for those players with a given field value
1674 void AddWinners(.float field, float value)
1677 FOR_EACH_PLAYER(head)
1678 if(head.field == value)
1682 // clear the .winning flags
1683 void ClearWinners(void)
1686 FOR_EACH_PLAYER(head)
1690 // Onslaught winning condition:
1691 // game terminates if only one team has a working generator (or none)
1692 float WinningCondition_Onslaught()
1695 local float t1, t2, t3, t4;
1697 WinningConditionHelper(); // set worldstatus
1702 // first check if the game has ended
1703 t1 = t2 = t3 = t4 = 0;
1704 head = find(world, classname, "onslaught_generator");
1707 if (head.health > 0)
1709 if (head.team == COLOR_TEAM1) t1 = 1;
1710 if (head.team == COLOR_TEAM2) t2 = 1;
1711 if (head.team == COLOR_TEAM3) t3 = 1;
1712 if (head.team == COLOR_TEAM4) t4 = 1;
1714 head = find(head, classname, "onslaught_generator");
1716 if (t1 + t2 + t3 + t4 < 2)
1718 // game over, only one team remains (or none)
1720 if (t1) SetWinners(team, COLOR_TEAM1);
1721 if (t2) SetWinners(team, COLOR_TEAM2);
1722 if (t3) SetWinners(team, COLOR_TEAM3);
1723 if (t4) SetWinners(team, COLOR_TEAM4);
1724 dprint("Have a winner, ending game.\n");
1728 // Two or more teams remain
1732 float LMS_NewPlayerLives()
1735 fl = cvar("fraglimit");
1739 // first player has left the game for dying too much? Nobody else can get in.
1740 if(lms_lowest_lives < 1)
1743 if(!cvar("g_lms_join_anytime"))
1744 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1747 return bound(1, lms_lowest_lives, fl);
1750 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1751 // they win. Otherwise the defending team wins once the timelimit passes.
1752 void assault_new_round();
1753 float WinningCondition_Assault()
1757 WinningConditionHelper(); // set worldstatus
1759 status = WINNING_NO;
1760 // as the timelimit has not yet passed just assume the defending team will win
1761 if(assault_attacker_team == COLOR_TEAM1)
1763 SetWinners(team, COLOR_TEAM2);
1767 SetWinners(team, COLOR_TEAM1);
1771 ent = find(world, classname, "target_assault_roundend");
1774 if(ent.winning) // round end has been triggered by attacking team
1776 bprint("ASSAULT: round completed...\n");
1777 SetWinners(team, assault_attacker_team);
1779 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
1781 if(ent.cnt == 1 || cvar("g_campaign")) // this was the second round
1783 status = WINNING_YES;
1787 local entity oldself;
1790 assault_new_round();
1799 // LMS winning condition: game terminates if and only if there's at most one
1800 // one player who's living lives. Top two scores being equal cancels the time
1802 float WinningCondition_LMS()
1809 have_player = FALSE;
1810 have_players = FALSE;
1811 l = LMS_NewPlayerLives();
1813 head = find(world, classname, "player");
1816 head2 = find(head, classname, "player");
1818 have_players = TRUE;
1822 // we have at least one player
1825 // two or more active players - continue with the game
1829 // exactly one player?
1832 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1836 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1842 // and assign him his first place
1843 PlayerScore_Add(head, SP_LMS_RANK, 1);
1850 // nobody is playing at all...
1853 // wait for players...
1857 // SNAFU (maybe a draw game?)
1859 dprint("No players, ending game.\n");
1864 // When we get here, we have at least two players who are actually LIVING,
1865 // now check if the top two players have equal score.
1866 WinningConditionHelper();
1869 if(WinningConditionHelper_winner)
1870 WinningConditionHelper_winner.winning = TRUE;
1871 if(WinningConditionHelper_topscore == WinningConditionHelper_secondscore)
1872 return WINNING_NEVER;
1874 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1878 void ShuffleMaplist()
1880 cvar_set("g_maplist", shufflewords(cvar_string("g_maplist")));
1884 float WinningCondition_Scores(float limit, float leadlimit)
1888 // TODO make everything use THIS winning condition (except LMS)
1889 WinningConditionHelper();
1893 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1894 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1895 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1896 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1900 if(WinningConditionHelper_winner)
1901 WinningConditionHelper_winner.winning = 1;
1902 if(WinningConditionHelper_winnerteam >= 0)
1903 SetWinners(team, WinningConditionHelper_winnerteam);
1905 if(WinningConditionHelper_lowerisbetter)
1907 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1908 WinningConditionHelper_secondscore = -WinningConditionHelper_secondscore;
1912 if(WinningConditionHelper_zeroisworst)
1913 leadlimit = 0; // not supported in this mode
1915 if(g_dm || g_tdm || g_arena || g_ca || (g_race && !g_race_qualifying) || g_nexball)
1916 // these modes always score in increments of 1, thus this makes sense
1918 if(leaderfrags != WinningConditionHelper_topscore)
1920 leaderfrags = WinningConditionHelper_topscore;
1923 if (leaderfrags == limit - 1)
1924 Announce("1fragleft");
1925 else if (leaderfrags == limit - 2)
1926 Announce("2fragsleft");
1927 else if (leaderfrags == limit - 3)
1928 Announce("3fragsleft");
1932 limitreached = FALSE;
1934 if(WinningConditionHelper_topscore >= limit)
1935 limitreached = TRUE;
1938 float leadlimitreached;
1939 leadlimitreached = (WinningConditionHelper_topscore - WinningConditionHelper_secondscore >= leadlimit);
1940 if(cvar("leadlimit_and_fraglimit"))
1941 limitreached = (limitreached && leadlimitreached);
1943 limitreached = (limitreached || leadlimitreached);
1946 return GetWinningCode(
1947 WinningConditionHelper_topscore && limitreached,
1948 WinningConditionHelper_equality
1952 float WinningCondition_Race(float fraglimit)
1963 if(p.race_completed)
1968 wc = WinningCondition_Scores(fraglimit, 0);
1970 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1971 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
1972 // do NOT support equality when the laps are all raced!
1973 return WINNING_STARTSUDDENDEATHOVERTIME;
1975 return WINNING_NEVER;
1979 void ReadyRestart();
1980 float WinningCondition_QualifyingThenRace(float limit)
1983 wc = WinningCondition_Scores(limit, 0);
1985 // NEVER initiate overtime
1986 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
1994 float WinningCondition_RanOutOfSpawns()
1998 if(have_team_spawns <= 0)
2001 if(!some_spawn_has_been_used)
2004 team1_score = team2_score = team3_score = team4_score = 0;
2006 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
2008 if(head.team == COLOR_TEAM1)
2010 else if(head.team == COLOR_TEAM2)
2012 else if(head.team == COLOR_TEAM3)
2014 else if(head.team == COLOR_TEAM4)
2018 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
2020 if(head.team == COLOR_TEAM1)
2022 else if(head.team == COLOR_TEAM2)
2024 else if(head.team == COLOR_TEAM3)
2026 else if(head.team == COLOR_TEAM4)
2031 if(team1_score + team2_score + team3_score + team4_score == 0)
2033 checkrules_equality = TRUE;
2036 else if(team1_score + team2_score + team3_score + team4_score == 1)
2039 if(team1_score) t = COLOR_TEAM1;
2040 if(team2_score) t = COLOR_TEAM2;
2041 if(team3_score) t = COLOR_TEAM3;
2042 if(team4_score) t = COLOR_TEAM4;
2043 CheckAllowedTeams(world);
2044 for(i = 0; i < MAX_TEAMSCORE; ++i)
2046 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
2047 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
2048 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
2049 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
2052 AddWinners(team, t);
2063 Exit deathmatch games upon conditions
2066 void CheckRules_World()
2078 MapVote_Think should now do that part
2079 if (intermission_running)
2080 if (time >= intermission_exittime + 60)
2082 if(!DoNextMapOverride())
2088 if (gameover) // someone else quit the game already
2090 if(player_count == 0) // Nobody there? Then let's go to the next map
2092 // this will actually check the player count in the next frame
2093 // again, but this shouldn't hurt
2097 timelimit = cvar("timelimit") * 60;
2098 fraglimit = cvar("fraglimit");
2099 leadlimit = cvar("leadlimit");
2101 if(inWarmupStage || time <= game_starttime) // NOTE: this is <= to prevent problems in the very tic where the game starts
2104 timelimit = 0; // timelimit is not made for warmup
2106 fraglimit = 0; // no fraglimit for now
2107 leadlimit = 0; // no leadlimit for now
2111 timelimit = 0; // ONS has its own overtime rule
2115 timelimit += game_starttime;
2117 else if (timelimit < 0)
2127 if(checkrules_suddendeathend)
2129 if(!checkrules_suddendeathwarning)
2131 checkrules_suddendeathwarning = TRUE;
2132 if(g_race && !g_race_qualifying)
2133 bcenterprint("^3Everyone, finish your lap! The race is over!");
2135 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
2140 if (timelimit && time >= timelimit)
2142 if(g_race && (g_race_qualifying == 2) && timelimit > 0)
2145 float playerswithlaps;
2148 totalplayers = playerswithlaps = readyplayers = 0;
2149 FOR_EACH_PLAYER(head)
2152 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
2158 // at least 2 of the players have completed a lap: start the RACE
2159 // otherwise, the players should end the qualifying on their own
2160 if(readyplayers || playerswithlaps >= 2)
2162 checkrules_suddendeathend = 0;
2163 ReadyRestart(); // go to race
2167 wantovertime |= InitiateSuddenDeath();
2170 wantovertime |= InitiateSuddenDeath();
2174 if (checkrules_suddendeathend && time >= checkrules_suddendeathend)
2180 float checkrules_status;
2181 checkrules_status = WinningCondition_RanOutOfSpawns();
2182 if(checkrules_status == WINNING_YES)
2184 bprint("Hey! Someone ran out of spawns!\n");
2186 else if(g_race && !g_race_qualifying && timelimit >= 0)
2188 checkrules_status = WinningCondition_Race(fraglimit);
2189 //print("WC_RACE yields ", ftos(checkrules_status), "\n");
2191 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
2193 checkrules_status = WinningCondition_QualifyingThenRace(fraglimit);
2194 //print("WC_QUALIFYING_THEN_RACE yields ", ftos(checkrules_status), "\n");
2198 checkrules_status = WinningCondition_Assault(); // TODO remove this?
2202 checkrules_status = WinningCondition_LMS();
2204 else if (g_onslaught)
2206 checkrules_status = WinningCondition_Onslaught(); // TODO remove this?
2210 checkrules_status = WinningCondition_Scores(fraglimit, leadlimit);
2211 //print("WC_SCORES yields ", ftos(checkrules_status), "\n");
2214 if(checkrules_status == WINNING_STARTSUDDENDEATHOVERTIME)
2216 checkrules_status = WINNING_NEVER;
2217 checkrules_overtimesadded = -1;
2218 wantovertime |= InitiateSuddenDeath();
2221 if(checkrules_status == WINNING_NEVER)
2222 // equality cases! Nobody wins if the overtime ends in a draw.
2227 if(checkrules_status == WINNING_NEVER)
2230 checkrules_status = WINNING_YES;
2233 if(checkrules_suddendeathend)
2234 if(checkrules_status != WINNING_NEVER || time >= checkrules_suddendeathend)
2235 checkrules_status = WINNING_YES;
2237 if(checkrules_status == WINNING_YES)
2239 //print("WINNING\n");
2244 float mapvote_nextthink;
2245 float mapvote_initialized;
2246 float mapvote_keeptwotime;
2247 float mapvote_timeout;
2248 string mapvote_message;
2249 #define MAPVOTE_SCREENSHOT_DIRS_COUNT 4
2250 string mapvote_screenshot_dirs[MAPVOTE_SCREENSHOT_DIRS_COUNT];
2251 float mapvote_screenshot_dirs_count;
2253 float mapvote_count;
2254 float mapvote_count_real;
2255 string mapvote_maps[MAPVOTE_COUNT];
2256 float mapvote_maps_screenshot_dir[MAPVOTE_COUNT];
2257 string mapvote_maps_pakfile[MAPVOTE_COUNT];
2258 float mapvote_maps_suggested[MAPVOTE_COUNT];
2259 string mapvote_suggestions[MAPVOTE_COUNT];
2260 float mapvote_suggestion_ptr;
2261 float mapvote_maxlen;
2262 float mapvote_voters;
2263 float mapvote_votes[MAPVOTE_COUNT];
2265 float mapvote_detail;
2266 float mapvote_abstain;
2269 void MapVote_ClearAllVotes()
2271 FOR_EACH_CLIENT(other)
2275 string MapVote_Suggest(string m)
2279 return "That's not how to use this command.";
2280 if(!cvar("g_maplist_votable_suggestions"))
2281 return "Suggestions are not accepted on this server.";
2282 if(mapvote_initialized)
2283 return "Can't suggest - voting is already in progress!";
2284 m = MapInfo_FixName(m);
2286 return "The map you suggested is not available on this server.";
2287 if(!cvar("g_maplist_votable_suggestions_override_mostrecent"))
2289 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
2291 if(!MapInfo_CheckMap(m))
2292 return "The map you suggested does not support the current game mode.";
2293 for(i = 0; i < mapvote_suggestion_ptr; ++i)
2294 if(mapvote_suggestions[i] == m)
2295 return "This map was already suggested.";
2296 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
2298 i = floor(random() * mapvote_suggestion_ptr);
2302 i = mapvote_suggestion_ptr;
2303 mapvote_suggestion_ptr += 1;
2305 if(mapvote_suggestions[i] != "")
2306 strunzone(mapvote_suggestions[i]);
2307 mapvote_suggestions[i] = strzone(m);
2308 if(cvar("sv_eventlog"))
2309 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
2310 return strcat("Suggestion of ", m, " accepted.");
2313 void MapVote_AddVotable(string nextMap, float isSuggestion)
2316 string pakfile, mapfile;
2320 for(j = 0; j < mapvote_count; ++j)
2321 if(mapvote_maps[j] == nextMap)
2323 if(strlen(nextMap) > mapvote_maxlen)
2324 mapvote_maxlen = strlen(nextMap);
2325 mapvote_maps[mapvote_count] = strzone(nextMap);
2326 mapvote_maps_suggested[mapvote_count] = isSuggestion;
2328 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2330 mapfile = strcat(mapvote_screenshot_dirs[i], "/", mapvote_maps[i]);
2331 pakfile = whichpack(strcat(mapfile, ".tga"));
2333 pakfile = whichpack(strcat(mapfile, ".jpg"));
2335 pakfile = whichpack(strcat(mapfile, ".png"));
2339 if(i >= mapvote_screenshot_dirs_count)
2340 i = 0; // FIXME maybe network this error case, as that means there is no mapshot on the server?
2341 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
2342 pakfile = substring(pakfile, o, -1);
2344 mapvote_maps_screenshot_dir[mapvote_count] = i;
2345 mapvote_maps_pakfile[mapvote_count] = strzone(pakfile);
2350 void MapVote_Spawn();
2356 MapVote_ClearAllVotes();
2359 mapvote_detail = !cvar("g_maplist_votable_nodetail");
2360 mapvote_abstain = cvar("g_maplist_votable_abstain");
2363 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
2365 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
2366 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
2368 // we need this for AddVotable, as that cycles through the screenshot dirs
2369 mapvote_screenshot_dirs_count = tokenize_console(cvar_string("g_maplist_votable_screenshot_dir"));
2370 if(mapvote_screenshot_dirs_count == 0)
2371 mapvote_screenshot_dirs_count = tokenize_console("maps levelshots");
2372 mapvote_screenshot_dirs_count = min(mapvote_screenshot_dirs_count, MAPVOTE_SCREENSHOT_DIRS_COUNT);
2373 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2374 mapvote_screenshot_dirs[i] = strzone(argv(i));
2376 if(mapvote_suggestion_ptr)
2377 for(i = 0; i < 100 && mapvote_count < smax; ++i)
2378 MapVote_AddVotable(mapvote_suggestions[floor(random() * mapvote_suggestion_ptr)], TRUE);
2380 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2381 MapVote_AddVotable(GetNextMap(), FALSE);
2383 if(mapvote_count == 0)
2385 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
2386 cvar_set("g_maplist", MapInfo_ListAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
2387 if(cvar("g_maplist_shuffle"))
2389 localcmd("\nmenu_cmd sync\n");
2390 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2391 MapVote_AddVotable(GetNextMap(), FALSE);
2394 mapvote_count_real = mapvote_count;
2396 MapVote_AddVotable("don't care", 0);
2398 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
2400 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
2401 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
2402 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
2403 mapvote_keeptwotime = 0;
2404 mapvote_message = "Choose a map and press its key!";
2409 void MapVote_SendPicture(float id)
2412 WriteByte(MSG_ONE, SVC_TEMPENTITY);
2413 WriteByte(MSG_ONE, TE_CSQC_PICTURE);
2414 WriteByte(MSG_ONE, id);
2415 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dirs[mapvote_maps_screenshot_dir[id]], "/", mapvote_maps[id]), 3072);
2418 float GameCommand_MapVote(string cmd)
2420 if(!intermission_running)
2423 if(cmd == "mv_getpic")
2425 MapVote_SendPicture(stof(argv(1)));
2432 float MapVote_GetMapMask()
2434 float mask, i, power;
2436 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
2437 if(mapvote_maps[i] != "")
2443 float MapVote_SendEntity(entity to, float sf)
2448 sf &~= 2; // if we send 1, we don't need to also send 2
2450 WriteByte(MSG_ENTITY, ENT_CLIENT_MAPVOTE);
2451 WriteByte(MSG_ENTITY, sf);
2455 // flag 1 == initialization
2456 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2457 WriteString(MSG_ENTITY, mapvote_screenshot_dirs[i]);
2458 WriteString(MSG_ENTITY, "");
2459 WriteByte(MSG_ENTITY, mapvote_count);
2460 WriteByte(MSG_ENTITY, mapvote_abstain);
2461 WriteByte(MSG_ENTITY, mapvote_detail);
2462 WriteCoord(MSG_ENTITY, mapvote_timeout);
2463 if(mapvote_count <= 8)
2464 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2466 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2467 for(i = 0; i < mapvote_count; ++i)
2468 if(mapvote_maps[i] != "")
2470 if(mapvote_abstain && i == mapvote_count - 1)
2472 WriteString(MSG_ENTITY, ""); // abstain needs no text
2473 WriteString(MSG_ENTITY, ""); // abstain needs no pack
2474 WriteByte(MSG_ENTITY, 0); // abstain needs no screenshot dir
2478 WriteString(MSG_ENTITY, mapvote_maps[i]);
2479 WriteString(MSG_ENTITY, mapvote_maps_pakfile[i]);
2480 WriteByte(MSG_ENTITY, mapvote_maps_screenshot_dir[i]);
2487 // flag 2 == update of mask
2488 if(mapvote_count <= 8)
2489 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2491 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2497 for(i = 0; i < mapvote_count; ++i)
2498 if(mapvote_maps[i] != "")
2499 WriteByte(MSG_ENTITY, mapvote_votes[i]);
2501 WriteByte(MSG_ENTITY, to.mapvote);
2507 void MapVote_Spawn()
2509 Net_LinkEntity(mapvote_ent = spawn(), FALSE, 0, MapVote_SendEntity);
2512 void MapVote_TouchMask()
2514 mapvote_ent.SendFlags |= 2;
2517 void MapVote_TouchVotes(entity voter)
2519 mapvote_ent.SendFlags |= 4;
2522 float MapVote_Finished(float mappos)
2528 if(cvar("sv_eventlog"))
2530 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2531 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
2532 didntvote = mapvote_voters;
2533 for(i = 0; i < mapvote_count; ++i)
2534 if(mapvote_maps[i] != "")
2536 didntvote -= mapvote_votes[i];
2539 result = strcat(result, ":", mapvote_maps[i]);
2540 result = strcat(result, ":", ftos(mapvote_votes[i]));
2543 result = strcat(result, ":didn't vote:", ftos(didntvote));
2545 GameLogEcho(result);
2546 if(mapvote_maps_suggested[mappos])
2547 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
2550 FOR_EACH_REALCLIENT(other)
2551 FixClientCvars(other);
2553 Map_Goto_SetStr(mapvote_maps[mappos]);
2555 alreadychangedlevel = TRUE;
2558 void MapVote_CheckRules_1()
2562 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2564 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2565 mapvote_votes[i] = 0;
2569 FOR_EACH_REALCLIENT(other)
2574 i = other.mapvote - 1;
2575 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2576 mapvote_votes[i] = mapvote_votes[i] + 1;
2581 float MapVote_CheckRules_2()
2584 float firstPlace, secondPlace;
2585 float firstPlaceVotes, secondPlaceVotes;
2586 float mapvote_voters_real;
2589 if(mapvote_count_real == 1)
2590 return MapVote_Finished(0);
2592 mapvote_voters_real = mapvote_voters;
2594 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2596 RandomSelection_Init();
2597 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2598 RandomSelection_Add(world, i, string_null, 1, mapvote_votes[i]);
2599 firstPlace = RandomSelection_chosen_float;
2600 firstPlaceVotes = RandomSelection_best_priority;
2601 //dprint("First place: ", ftos(firstPlace), "\n");
2602 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2604 RandomSelection_Init();
2605 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2607 RandomSelection_Add(world, i, string_null, 1, mapvote_votes[i]);
2608 secondPlace = RandomSelection_chosen_float;
2609 secondPlaceVotes = RandomSelection_best_priority;
2610 //dprint("Second place: ", ftos(secondPlace), "\n");
2611 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2613 if(firstPlace == -1)
2614 error("No first place in map vote... WTF?");
2616 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2617 return MapVote_Finished(firstPlace);
2619 if(mapvote_keeptwotime)
2620 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2623 MapVote_TouchMask();
2624 mapvote_message = "Now decide between the TOP TWO!";
2625 mapvote_keeptwotime = 0;
2626 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2627 result = strcat(result, ":", ftos(firstPlaceVotes));
2628 result = strcat(result, ":", mapvote_maps[secondPlace]);
2629 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2630 didntvote = mapvote_voters;
2631 for(i = 0; i < mapvote_count; ++i)
2632 if(mapvote_maps[i] != "")
2634 didntvote -= mapvote_votes[i];
2636 if(i != secondPlace)
2638 result = strcat(result, ":", mapvote_maps[i]);
2639 result = strcat(result, ":", ftos(mapvote_votes[i]));
2640 if(i < mapvote_count_real)
2642 strunzone(mapvote_maps[i]);
2643 mapvote_maps[i] = "";
2644 strunzone(mapvote_maps_pakfile[i]);
2645 mapvote_maps_pakfile[i] = "";
2649 result = strcat(result, ":didn't vote:", ftos(didntvote));
2650 if(cvar("sv_eventlog"))
2651 GameLogEcho(result);
2661 keeptwo = mapvote_keeptwotime;
2662 MapVote_CheckRules_1(); // count
2663 if(MapVote_CheckRules_2()) // decide
2667 FOR_EACH_REALCLIENT(other)
2669 // hide scoreboard again
2670 if(other.health != 2342)
2672 other.health = 2342;
2674 if(clienttype(other) == CLIENTTYPE_REAL)
2677 WriteByte(MSG_ONE, SVC_FINALE);
2678 WriteString(MSG_ONE, "");
2682 // clear possibly invalid votes
2683 if(mapvote_maps[other.mapvote - 1] == "")
2685 // use impulses as new vote
2686 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2687 if(mapvote_maps[other.impulse - 1] != "")
2689 other.mapvote = other.impulse;
2690 MapVote_TouchVotes(other);
2698 MapVote_CheckRules_1(); // just count
2700 void MapVote_Start()
2705 MapInfo_Enumerate();
2706 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
2709 void MapVote_Think()
2714 if(alreadychangedlevel)
2717 if(time < mapvote_nextthink)
2721 mapvote_nextthink = time + 0.5;
2723 if(!mapvote_initialized)
2725 if(cvar("rescan_pending") == 1)
2727 cvar_set("rescan_pending", "2");
2728 localcmd("fs_rescan\nrescan_pending 3\n");
2731 else if(cvar("rescan_pending") == 2)
2735 else if(cvar("rescan_pending") == 3)
2737 // now build missing mapinfo files
2738 if(!MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
2741 // we're done, start the timer
2742 cvar_set("rescan_pending", "0");
2745 mapvote_initialized = TRUE;
2746 if(DoNextMapOverride())
2748 if(!cvar("g_maplist_votable") || player_count <= 0)
2759 string GotoMap(string m)
2761 if(!MapInfo_CheckMap(m))
2762 return "The map you chose is not available on this server.";
2763 cvar_set("nextmap", m);
2764 cvar_set("timelimit", "-1");
2765 if(mapvote_initialized || alreadychangedlevel)
2767 if(DoNextMapOverride())
2768 return "Map switch initiated.";
2770 return "Hm... no. For some reason I like THIS map more.";
2773 return "Map switch will happen after scoreboard.";
2780 FOR_EACH_REALCLIENT(self)
2782 if(self.classname == "spectator")
2784 if(self.enemy.typehitsound)
2785 play2(self, "misc/typehit.wav");
2786 else if(self.enemy.hitsound && self.cvar_cl_hitsound)
2787 play2(self, "misc/hit.wav");
2791 if(self.typehitsound)
2792 play2(self, "misc/typehit.wav");
2793 else if(self.hitsound && self.cvar_cl_hitsound)
2794 play2(self, "misc/hit.wav");
2797 altime = time + frametime * (1 + cvar("g_antilag_nudge"));
2798 // add 1 frametime because after this, engine SV_Physics
2799 // increases time by a frametime and then networks the frame
2800 // add another frametime because client shows everything with
2801 // 1 frame of lag (cl_nolerp 0). The last +1 however should not be
2803 FOR_EACH_CLIENT(self)
2805 self.hitsound = FALSE;
2806 self.typehitsound = FALSE;
2807 antilag_record(self, altime);
2814 * returns TRUE if redirecting
2816 float redirection_timeout;
2817 float redirection_nextthink;
2818 float RedirectionThink()
2820 float clients_found;
2822 if(redirection_target == "")
2825 if(!redirection_timeout)
2827 cvar_set("sv_public", "-2");
2828 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2829 if(redirection_target == "self")
2830 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2832 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2835 if(time < redirection_nextthink)
2838 redirection_nextthink = time + 1;
2841 FOR_EACH_REALCLIENT(self)
2843 print("Redirecting: sending connect command to ", self.netname, "\n");
2844 if(redirection_target == "self")
2845 stuffcmd(self, "\ndisconnect; reconnect\n");
2847 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2851 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2853 if(time > redirection_timeout || clients_found == 0)
2854 localcmd("\nwait; wait; wait; quit\n");
2859 void TargetMusic_RestoreGame();
2862 // Loaded from a save game
2863 // some things then break, so let's work around them...
2865 // Progs DB (capture records)
2866 ServerProgsDB = db_load("server.db");
2870 MapInfo_Enumerate();
2871 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
2874 TargetMusic_RestoreGame();
2879 if(gameover > 1) // shutting down already?
2882 gameover = 2; // 2 = server shutting down
2884 if(world_initialized > 0)
2886 world_initialized = 0;
2887 print("Saving persistent data...\n");
2889 if(!cheatcount_total)
2891 if(cvar("sv_db_saveasdump"))
2892 db_dump(ServerProgsDB, "server.db");
2894 db_save(ServerProgsDB, "server.db");
2896 if(cvar("developer"))
2898 if(cvar("sv_db_saveasdump"))
2899 db_dump(TemporaryDB, "server-temp.db");
2901 db_save(TemporaryDB, "server-temp.db");
2903 CheatShutdown(); // must be after cheatcount check
2904 db_close(ServerProgsDB);
2905 db_close(TemporaryDB);
2907 // tell the bot system the game is ending now
2910 WeaponStats_Shutdown();
2913 else if(world_initialized == 0)
2915 print("NOTE: crashed before even initializing the world, not saving persistent data\n");