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(autocvar_g_running_guns)
55 default_player_alpha = -1;
56 default_weapon_alpha = +1;
60 default_player_alpha = autocvar_g_balance_cloaked_alpha;
61 default_weapon_alpha = default_player_alpha;
65 default_player_alpha = autocvar_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(!autocvar_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 == autocvar_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, "");
181 if(autocvar__sv_init)
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(autocvar_g_maplist_shuffle)
189 n = tokenizebyseparator(autocvar_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 BADPRESUFFIX(p,s) if(substring(k, 0, strlen(p)) == p && substring(k, -strlen(s), -1) == s) continue
239 #define BADCVAR(p) if(k == p) continue
242 BADPREFIX("cvar_check_");
244 BADCVAR("g_configversion");
245 BADCVAR("g_maplist_index");
246 BADCVAR("halflifebsp");
247 BADPREFIX("sv_world");
253 BADPREFIX("scoreboard_");
254 BADPREFIX("g_campaign");
259 BADPREFIX("net_slist_");
264 BADPREFIX("userbind");
267 BADPREFIX("crosshair");
268 BADCVAR("mod_q3bsp_lightmapmergepower");
269 BADCVAR("mod_q3bsp_nolightmaps");
271 BADCVAR("mastervolume");
273 BADCVAR("bgmvolume");
276 BADCVAR("developer");
277 BADCVAR("g_banned_list");
278 BADCVAR("log_dest_udp");
280 BADCVAR("net_address");
281 BADCVAR("net_address_ipv6");
283 BADCVAR("savedgamecfg");
284 BADCVAR("serverconfig");
285 BADCVAR("sv_heartbeatperiod");
286 BADCVAR("sv_vote_master_password");
287 BADCVAR("sys_colortranslation");
288 BADCVAR("sys_specialcharactertranslation");
289 BADCVAR("timestamps");
290 BADPREFIX("developer_");
292 BADPREFIX("g_chat_flood_");
293 BADPREFIX("g_voice_flood_");
295 BADPREFIX("settemp_");
296 BADPREFIX("sv_allowdownloads_");
297 BADPREFIX("sv_autodemo");
298 BADPREFIX("sv_curl_");
299 BADPREFIX("sv_eventlog");
300 BADPREFIX("sv_logscores_");
301 BADPREFIX("sv_master");
302 BADPREFIX("sv_weaponstats_");
304 // these can contain player IDs, so better hide
305 BADCVAR("g_forced_team_red");
306 BADCVAR("g_forced_team_blue");
307 BADCVAR("g_forced_team_yellow");
308 BADCVAR("g_forced_team_pink");
311 BADCVAR("timelimit");
312 BADCVAR("fraglimit");
313 BADCVAR("leadlimit");
314 BADCVAR("g_tdm_teams");
315 BADCVAR("g_keyhunt_teams");
316 BADCVAR("g_domination_default_teams");
317 BADCVAR("g_race_qualifying_timelimit");
321 BADCVAR("g_assault");
324 BADCVAR("g_domination");
325 BADCVAR("g_keyhunt");
326 BADCVAR("g_keyhunt_teams");
327 BADCVAR("g_onslaught");
330 BADCVAR("g_runematch");
332 BADCVAR("g_nexball");
333 BADCVAR("g_keepaway");
338 BADCVAR("g_maplist");
339 BADCVAR("g_maplist_mostrecent");
343 d = cvar_defstring(k);
349 cvar_changes = strcat(cvar_changes, k, " \"", v, "\" // \"", d, "\"\n");
350 if(strlen(cvar_changes) > 16384)
352 cvar_changes = "// too many settings have been changed to show them here\n";
357 // now check if the changes are actually gameplay relevant
359 // does nothing visible
360 BADCVAR("captureleadlimit_override");
361 BADCVAR("g_arena_point_leadlimit");
362 BADCVAR("g_ca_point_leadlimit");
363 BADCVAR("g_ctf_capture_leadlimit");
364 BADCVAR("g_domination_point_leadlimit");
365 BADCVAR("g_keyhunt_point_leadlimit");
366 BADCVAR("g_nexball_goalleadlimit");
367 BADCVAR("g_runematch_point_leadlimit");
368 BADCVAR("leadlimit_and_fraglimit");
369 BADCVAR("leadlimit_override");
370 BADCVAR("sv_checkforpacketsduringsleep");
371 BADPREFIX("crypto_");
372 BADPREFIX("g_chat_");
375 BADPREFIX("sv_fragmessage_");
376 BADPREFIX("sv_vote_");
377 BADPREFIX("timelimit_");
379 // allowed changes to server admins (please sync this to server.cfg)
383 // :%s,//\([^ ]*\).*,BADCVAR("\1");,
385 // yes, this does contain some redundant stuff, don't really care
386 BADCVAR("bot_number");
387 BADCVAR("bot_prefix");
388 BADCVAR("bot_suffix");
389 BADCVAR("capturelimit_override");
390 BADCVAR("fraglimit_override");
392 BADCVAR("g_antilag");
393 BADCVAR("g_balance_teams");
394 BADCVAR("g_balance_teams_force");
395 BADCVAR("g_ban_sync_trusted_servers");
396 BADCVAR("g_ban_sync_uri");
397 BADCVAR("g_ctf_capture_limit");
398 BADCVAR("g_ctf_ignore_frags");
399 BADCVAR("g_ctf_win_mode");
400 BADCVAR("g_domination_point_limit");
401 BADCVAR("g_fullbrightitems");
402 BADCVAR("g_fullbrightplayers");
403 BADCVAR("g_keyhunt_point_limit");
404 BADCVAR("g_keyhunt_teams_override");
405 BADCVAR("g_lms_lives_override");
406 BADCVAR("g_maplist");
407 BADCVAR("g_maplist_check_waypoints");
408 BADCVAR("g_maplist_mostrecent_count");
409 BADCVAR("g_maplist_shuffle");
410 BADCVAR("g_maplist_votable");
411 BADCVAR("g_maplist_votable_abstain");
412 BADCVAR("g_maplist_votable_nodetail");
413 BADCVAR("g_maplist_votable_suggestions");
414 BADCVAR("g_minstagib");
415 BADCVAR("g_nexball_goallimit");
416 BADCVAR("g_runematch_point_limit");
417 BADCVAR("g_start_delay");
418 BADCVAR("g_weapon_stay"); BADPRESUFFIX("g_", "_weapon_stay");
421 BADCVAR("maxplayers");
422 BADCVAR("minplayers");
423 BADCVAR("net_address");
425 BADCVAR("rcon_password");
426 BADCVAR("rcon_restricted_commands");
427 BADCVAR("rcon_restricted_password");
429 BADCVAR("sv_adminnick");
430 BADCVAR("sv_autoscreenshot");
431 BADCVAR("sv_curl_defaulturl");
432 BADCVAR("sv_defaultcharacter");
433 BADCVAR("sv_defaultplayercolors");
434 BADCVAR("sv_defaultplayermodel");
435 BADCVAR("sv_defaultplayerskin");
436 BADCVAR("sv_maxidle");
437 BADCVAR("sv_maxrate");
439 BADCVAR("sv_public");
440 BADCVAR("sv_ready_restart");
441 BADCVAR("sv_status_privacy");
442 BADCVAR("sv_vote_call");
443 BADCVAR("sv_vote_commands");
444 BADCVAR("sv_vote_majority_factor");
445 BADCVAR("sv_vote_master");
446 BADCVAR("sv_vote_master_commands");
447 BADCVAR("sv_vote_master_password");
448 BADCVAR("sv_vote_simple_majority_factor");
449 BADCVAR("timelimit_override");
451 if(autocvar_g_minstagib)
453 BADCVAR("g_grappling_hook");
454 BADCVAR("g_jetpack");
461 cvar_purechanges = strcat(cvar_purechanges, k, " \"", v, "\" // \"", d, "\"\n");
462 if(strlen(cvar_purechanges) > 16384)
464 cvar_purechanges = "// too many settings have been changed to show them here\n";
468 ++cvar_purechanges_count;
469 // WARNING: this variable is used for the server list
470 // NEVER dare to skip this code!
471 // Hacks to intentionally appearing as "pure server" even though you DO have
472 // modified settings may be punished by removal from the server list.
473 // You can do to the variables cvar_changes and cvar_purechanges all you want,
477 if(cvar_changes == "")
478 cvar_changes = "// this server runs at default server settings\n";
480 cvar_changes = strcat("// this server runs at modified server settings:\n", cvar_changes);
481 cvar_changes = strzone(cvar_changes);
482 if(cvar_purechanges == "")
483 cvar_purechanges = "// this server runs at default gameplay settings\n";
485 cvar_purechanges = strcat("// this server runs at modified gameplay settings:\n", cvar_purechanges);
486 cvar_purechanges = strzone(cvar_purechanges);
489 void detect_maptype()
498 o_x += random() * (world.maxs_x - world.mins_x);
499 o_y += random() * (world.maxs_y - world.mins_y);
500 o_z += random() * (world.maxs_z - world.mins_z);
502 tracebox(o, PL_MIN, PL_MAX, o - '0 0 32768', MOVE_WORLDONLY, world);
503 if(trace_fraction == 1)
508 for(i = 0; i < 64; i += 4)
510 tracebox(o, '-1 -1 -1' * i, '1 1 1' * i, o - '0 0 32768', MOVE_WORLDONLY, world);
511 if(trace_fraction == 1)
513 print(ftos(i), " -> ", vtos(trace_endpos), "\n");
522 float RandomSeed_Send(entity to, float sf)
524 WriteByte(MSG_ENTITY, ENT_CLIENT_RANDOMSEED);
525 WriteShort(MSG_ENTITY, self.cnt);
528 void RandomSeed_Think()
530 self.cnt = bound(0, floor(random() * 65536), 65535);
531 self.nextthink = time + 5;
535 void RandomSeed_Spawn()
537 randomseed = spawn();
538 randomseed.think = RandomSeed_Think;
539 Net_LinkEntity(randomseed, FALSE, 0, RandomSeed_Send);
544 self.think(); // sets random seed and nextthink
548 void spawnfunc___init_dedicated_server(void)
550 // handler for _init/_init map (only for dedicated server initialization)
552 world_initialized = -1; // don't complain
554 cvar_string = cvar_string_normal;
555 cvar_set = cvar_set_normal;
557 remove = remove_unsafely;
561 e.think = GotoFirstMap;
562 e.nextthink = time; // this is usually 1 at this point
565 e.classname = "info_player_deathmatch"; // safeguard against player joining
567 self.classname = "worldspawn"; // safeguard against various stuff ;)
570 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
573 void Map_MarkAsRecent(string m);
574 float world_already_spawned;
575 void RegisterWeapons();
577 void ClientInit_Spawn();
578 void WeaponStats_Init();
579 void WeaponStats_Shutdown();
580 void spawnfunc_worldspawn (void)
582 float fd, l, i, j, n;
586 cvar_string = cvar_string_normal;
587 cvar_set = cvar_set_normal;
589 if(world_already_spawned)
590 error("world already spawned - you may have EXACTLY ONE worldspawn!");
591 world_already_spawned = TRUE;
593 remove = remove_safely; // during spawning, watch what you remove!
595 check_unacceptable_compiler_bugs();
597 cvar_changes_init(); // do this very early now so it REALLY matches the server config
599 compressShortVector_init();
601 allowed_to_spawn = TRUE;
604 head = nextent(world);
609 head = nextent(head);
612 // needs to be done so early as they would still spawn
615 ServerProgsDB = db_load("server.db");
617 TemporaryDB = db_create();
622 // 1 FLICKER (first variety)
623 lightstyle(1, "mmnmmommommnonmmonqnmmo");
625 // 2 SLOW STRONG PULSE
626 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
628 // 3 CANDLE (first variety)
629 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
632 lightstyle(4, "mamamamamama");
635 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
637 // 6 FLICKER (second variety)
638 lightstyle(6, "nmonqnmomnmomomno");
640 // 7 CANDLE (second variety)
641 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
643 // 8 CANDLE (third variety)
644 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
646 // 9 SLOW STROBE (fourth variety)
647 lightstyle(9, "aaaaaaaazzzzzzzz");
649 // 10 FLUORESCENT FLICKER
650 lightstyle(10, "mmamammmmammamamaaamammma");
652 // 11 SLOW PULSE NOT FADE TO BLACK
653 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
655 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
660 if(autocvar_g_campaign)
663 Map_MarkAsRecent(mapname);
665 precache_model ("null"); // we need this one before InitGameplayMode
673 bot_waypoints_for_items = autocvar_g_waypoints_for_items;
674 if(bot_waypoints_for_items == 1)
675 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
676 bot_waypoints_for_items = 0;
678 // for setting by mapinfo
679 q3acompat_machineshotgunswap = autocvar_sv_q3acompat_machineshotgunswap;
680 cvar_set("sv_q3acompat_machineshotgunswap", "0");
684 WaypointSprite_Init();
689 GameLogInit(); // prepare everything
690 if(autocvar_sv_eventlog)
692 s = strcat(ftos(autocvar_sv_eventlog_files_counter), ".");
693 s = strcat(s, ftos(random()));
694 matchid = strzone(s);
696 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
697 s = ":gameinfo:mutators:LIST";
700 MUTATOR_CALLHOOK(BuildMutatorsString);
703 // simple, probably not good in the mutator system
704 if(autocvar_g_grappling_hook)
705 s = strcat(s, ":grappling_hook");
707 // initialiation stuff, not good in the mutator system
708 if(!autocvar_g_use_ammunition)
709 s = strcat(s, ":no_use_ammunition");
711 // initialiation stuff, not good in the mutator system
712 if(!autocvar_g_pickup_items)
713 s = strcat(s, ":no_pickup_items");
715 // initialiation stuff, not good in the mutator system
716 if(autocvar_g_weaponarena != "0")
717 s = strcat(s, ":", autocvar_g_weaponarena, " arena");
719 // TODO to mutator system
720 if(autocvar_g_norecoil)
721 s = strcat(s, ":norecoil");
723 // TODO to mutator system
724 if(autocvar_g_midair)
725 s = strcat(s, ":midair");
727 // TODO to mutator system
728 if(autocvar_g_minstagib)
729 s = strcat(s, ":minstagib");
732 GameLogEcho(":gameinfo:end");
735 matchid = strzone(ftos(random()));
737 cvar_set("nextmap", "");
741 if(autocvar_g_campaign)
749 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
751 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
753 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
756 while((s = fgets(fd)))
758 l = tokenize_console(s);
763 print("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
764 print(" cdtrack ", argv(2), "\n");
766 else if(argv(0) == "fog")
768 print("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
769 print(" \"fog\" \"", s, "\"\n");
771 else if(argv(0) == "set")
773 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
774 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
776 else if(argv(0) != "//")
778 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
779 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
788 addstat(STAT_WEAPONS, AS_INT, weapons);
789 addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
790 addstat(STAT_GAMESTARTTIME, AS_FLOAT, stat_game_starttime);
791 addstat(STAT_ALLOW_OLDNEXBEAM, AS_INT, stat_allow_oldnexbeam);
794 addstat(STAT_STRENGTH_FINISHED, AS_FLOAT, strength_finished);
795 addstat(STAT_INVINCIBLE_FINISHED, AS_FLOAT, invincible_finished);
796 addstat(STAT_PRESSED_KEYS, AS_FLOAT, pressedkeys);
797 addstat(STAT_FUEL, AS_INT, ammo_fuel);
798 addstat(STAT_SHOTORG, AS_INT, stat_shotorg);
799 addstat(STAT_LEADLIMIT, AS_FLOAT, stat_leadlimit);
800 addstat(STAT_BULLETS_LOADED, AS_INT, campingrifle_bulletcounter);
801 addstat(STAT_LAST_PICKUP, AS_FLOAT, last_pickup);
803 addstat(STAT_NEX_CHARGE, AS_FLOAT, nex_charge);
804 addstat(STAT_NEX_CHARGEPOOL, AS_FLOAT, nex_chargepool_ammo);
806 if(g_ca || g_freezetag)
808 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
809 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
810 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
811 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
815 addstat(STAT_FROZEN, AS_INT, freezetag_frozen);
816 addstat(STAT_REVIVE_PROGRESS, AS_FLOAT, freezetag_revive_progress);
819 // g_movementspeed hack
820 addstat(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW, AS_FLOAT, stat_sv_airspeedlimit_nonqw);
821 addstat(STAT_MOVEVARS_MAXSPEED, AS_FLOAT, stat_sv_maxspeed);
822 addstat(STAT_MOVEVARS_AIRACCEL_QW, AS_FLOAT, stat_sv_airaccel_qw);
823 addstat(STAT_MOVEVARS_AIRSTRAFEACCEL_QW, AS_FLOAT, stat_sv_airstrafeaccel_qw);
825 next_pingtime = time + 5;
829 lsmaps_reply = "^7Maps available: ";
830 lsnewmaps_reply = "^7Maps without a record set: ";
831 for(i = 0, j = 0; i < MapInfo_count; ++i)
833 if(MapInfo_Get_ByID(i))
834 if not(MapInfo_Map_flags & (MAPINFO_FLAG_HIDDEN | MAPINFO_FLAG_FORBIDDEN))
841 lsmaps_reply = strcat(lsmaps_reply, col, MapInfo_Map_bspname, " ");
842 if(g_race && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "time"))))
843 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
844 else if(g_cts && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "time"))))
845 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
848 lsmaps_reply = strzone(strcat(lsmaps_reply, "\n"));
849 if (!g_race && !g_cts)
850 lsnewmaps_reply = "Need to be playing race or CTS for lsnewmaps to work.";
851 lsnewmaps_reply = strzone(strcat(lsnewmaps_reply, "\n"));
853 maplist_reply = "^7Maps in list: ";
854 n = tokenize_console(autocvar_g_maplist);
855 for(i = 0, j = 0; i < n; ++i)
857 if(MapInfo_CheckMap(argv(i)))
863 maplist_reply = strcat(maplist_reply, col, argv(i), " ");
867 maplist_reply = strzone(strcat(maplist_reply, "\n"));
868 MapInfo_ClearTemps();
870 for(i = 0; i < 10; ++i)
872 records_reply[i] = strzone(getrecords(i));
875 ladder_reply = strzone(getladder());
877 rankings_reply = strzone(getrankings());
881 PingPLReport_Spawn();
885 localcmd("\n_sv_hook_gamestart ", GetGametype(), "\n");
887 // fill sv_curl_serverpackages from .serverpackage files
888 if(autocvar_sv_curl_serverpackages_auto)
890 fd = search_begin("*.serverpackage", TRUE, FALSE);
894 j = search_getsize(fd);
895 for(i = 0; i < j; ++i)
896 s = strcat(s, " ", search_getfilename(fd, i));
899 cvar_set("sv_curl_serverpackages", substring(s, 1, -1));
904 world_initialized = 1;
907 void spawnfunc_light (void)
909 //makestatic (self); // Who the f___ did that?
913 float TryFile( string pFilename )
916 dprint("TryFile(\"", pFilename, "\")\n");
917 lHandle = fopen( pFilename, FILE_READ );
918 if( lHandle != -1 ) {
928 return GametypeNameFromType(game);
931 string getmapname_stored;
937 float Map_Count, Map_Current;
938 string Map_Current_Name;
940 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
941 float GetMaplistPosition()
947 idx = autocvar_g_maplist_index;
954 for(pos = 0; pos < Map_Count; ++pos)
958 // resume normal maplist rotation if current map is not in g_maplist
962 float MapHasRightSize(string map)
965 if(currentbots || autocvar_bot_number || player_count < autocvar_minplayers)
966 if(autocvar_g_maplist_check_waypoints)
968 dprint("checkwp "); dprint(map);
969 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
972 dprint(": no waypoints\n");
975 dprint(": has waypoints\n");
979 // open map size restriction file
980 dprint("opensize "); dprint(map);
981 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
984 float mapmin, mapmax;
986 mapmin = stof(fgets(fh));
987 mapmax = stof(fgets(fh));
989 if(player_count < mapmin)
991 dprint("not enough\n");
994 if(player_count > mapmax)
996 dprint("too many\n");
999 dprint("right size\n");
1002 dprint(": not found\n");
1006 string Map_Filename(float position)
1008 return strcat("maps/", argv(position), ".bsp");
1011 string strwords(string s, float w)
1014 for(endpos = 0; w && endpos >= 0; --w)
1015 endpos = strstrofs(s, " ", endpos + 1);
1019 return substring(s, 0, endpos);
1022 float strhasword(string s, string w)
1024 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
1027 void Map_MarkAsRecent(string m)
1029 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", autocvar_g_maplist_mostrecent), max(0, autocvar_g_maplist_mostrecent_count)));
1032 float Map_IsRecent(string m)
1034 return strhasword(autocvar_g_maplist_mostrecent, m);
1037 float Map_Check(float position, float pass)
1041 map_next = argv(position);
1044 if(Map_IsRecent(map_next))
1047 filename = Map_Filename(position);
1048 if(MapInfo_CheckMap(map_next))
1052 if(MapHasRightSize(map_next))
1057 dprint( "Couldn't select '", filename, "'..\n" );
1062 void Map_Goto_SetStr(string nextmapname)
1064 if(getmapname_stored != "")
1065 strunzone(getmapname_stored);
1066 if(nextmapname == "")
1067 getmapname_stored = "";
1069 getmapname_stored = strzone(nextmapname);
1072 void Map_Goto_SetFloat(float position)
1074 cvar_set("g_maplist_index", ftos(position));
1075 Map_Goto_SetStr(argv(position));
1080 // settings persist, except...
1081 localcmd("\nsettemp_restore\n");
1087 MapInfo_LoadMap(getmapname_stored);
1090 // return codes of map selectors:
1091 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
1092 // -2 = permanent failure
1093 float() MaplistMethod_Iterate = // usual method
1097 for(pass = 1; pass <= 2; ++pass)
1099 for(i = 1; i < Map_Count; ++i)
1102 mapindex = mod(i + Map_Current, Map_Count);
1103 if(Map_Check(mapindex, pass))
1110 float() MaplistMethod_Repeat = // fallback method
1112 if(Map_Check(Map_Current, 2))
1117 float() MaplistMethod_Random = // random map selection
1123 for(i = 0; i <= imax; ++i)
1126 mapindex = mod(Map_Current + floor(random() * (Map_Count - 1) + 1), Map_Count); // any OTHER map
1127 if(Map_Check(mapindex, 1))
1133 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
1134 // the exponent sets a bias on the map selection:
1135 // the higher the exponent, the less likely "shortly repeated" same maps are
1137 float i, j, imax, insertpos;
1141 for(i = 0; i <= imax; ++i)
1145 // now reinsert this at another position
1146 insertpos = pow(random(), 1 / exponent); // ]0, 1]
1147 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
1148 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
1149 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
1151 // insert the current map there
1153 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
1154 newlist = strcat(newlist, " ", argv(j));
1155 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
1156 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
1157 newlist = strcat(newlist, " ", argv(j));
1158 newlist = substring(newlist, 1, strlen(newlist) - 1);
1159 cvar_set("g_maplist", newlist);
1160 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1162 // NOTE: the selected map has just been inserted at (insertpos-1)th position
1163 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
1164 if(Map_Check(Map_Current, 1))
1172 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1175 bprint( "Maplist is empty! Resetting it to default map list.\n" );
1176 cvar_set("g_maplist", MapInfo_ListAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
1177 if(autocvar_g_maplist_shuffle)
1179 localcmd("\nmenu_cmd sync\n");
1180 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1183 error("empty maplist, cannot select a new map");
1184 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
1186 if(Map_Current_Name)
1187 strunzone(Map_Current_Name);
1188 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
1189 // this may or may not be correct, but who cares, in the worst case a map
1190 // isn't chosen in the first pass that should have been
1201 if(autocvar_g_maplist_shuffle > 0)
1202 nextMap = MaplistMethod_Shuffle(autocvar_g_maplist_shuffle + 1);
1205 if(autocvar_g_maplist_selectrandom)
1206 nextMap = MaplistMethod_Random();
1209 nextMap = MaplistMethod_Iterate();
1212 nextMap = MaplistMethod_Repeat();
1216 Map_Goto_SetFloat(nextMap);
1217 return getmapname_stored;
1223 float DoNextMapOverride()
1225 if(autocvar_g_campaign)
1227 CampaignPostIntermission();
1228 alreadychangedlevel = TRUE;
1231 if(autocvar_quit_when_empty)
1233 if(player_count <= currentbots)
1236 alreadychangedlevel = TRUE;
1240 if(autocvar_quit_and_redirect != "")
1242 redirection_target = strzone(autocvar_quit_and_redirect);
1243 alreadychangedlevel = TRUE;
1246 if (autocvar_samelevel) // if samelevel is set, stay on same level
1248 // 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)
1249 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
1250 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
1251 localcmd("restart\n");
1252 //changelevel (mapname);
1253 alreadychangedlevel = TRUE;
1256 if(autocvar_nextmap != "")
1257 if(MapInfo_CheckMap(autocvar_nextmap))
1259 Map_Goto_SetStr(autocvar_nextmap);
1261 alreadychangedlevel = TRUE;
1264 if(autocvar_lastlevel)
1267 localcmd("set lastlevel 0\ntogglemenu\n");
1268 alreadychangedlevel = TRUE;
1276 //local string nextmap;
1277 //local float n, nummaps;
1279 if (alreadychangedlevel)
1281 alreadychangedlevel = TRUE;
1287 for(allowReset = 1; allowReset >= 0; --allowReset)
1289 nextMap = GetNextMap();
1295 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1296 cvar_set("g_maplist", MapInfo_ListAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
1297 if(autocvar_g_maplist_shuffle)
1299 localcmd("\nmenu_cmd sync\n");
1303 error("Everything is broken - not even the default map list works. Please report this to the developers.");
1315 When the player presses attack or jump, change to the next level
1318 .float autoscreenshot;
1319 void() MapVote_Start;
1320 void() MapVote_Think;
1321 float mapvote_initialized;
1322 void IntermissionThink()
1324 FixIntermissionClient(self);
1326 if(autocvar_sv_autoscreenshot)
1327 if(self.autoscreenshot > 0)
1328 if(time > self.autoscreenshot)
1330 self.autoscreenshot = -1;
1331 if(clienttype(self) == CLIENTTYPE_REAL)
1332 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
1336 if (time < intermission_exittime)
1339 if(!mapvote_initialized)
1340 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
1350 Returns the entity to view from
1354 entity FindIntermission()
1359 // look for info_intermission first
1360 spot = find (world, classname, "info_intermission");
1362 { // pick a random one
1366 spot = find (spot, classname, "info_intermission");
1368 spot = find (spot, classname, "info_intermission");
1374 // then look for the start position
1375 spot = find (world, classname, "info_player_start");
1379 // testinfo_player_start is only found in regioned levels
1380 spot = find (world, classname, "testplayerstart");
1384 // then look for the start position
1385 spot = find (world, classname, "info_player_deathmatch");
1389 //objerror ("FindIntermission: no spot");
1395 ===============================================================================
1399 ===============================================================================
1402 void DumpStats(float final)
1412 to_console = autocvar_sv_logscores_console;
1413 to_eventlog = autocvar_sv_eventlog;
1414 to_file = autocvar_sv_logscores_file;
1418 to_console = TRUE; // always print printstats replies
1419 to_eventlog = FALSE; // but never print them to the event log
1423 if(autocvar_sv_eventlog_console)
1424 to_console = FALSE; // otherwise we get the output twice
1430 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
1438 file = fopen(autocvar_sv_logscores_filename, FILE_APPEND);
1442 fputs(file, strcat(s, "\n"));
1445 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
1451 fputs(file, strcat(s, "\n"));
1453 FOR_EACH_CLIENT(other)
1455 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && autocvar_sv_logscores_bots))
1457 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
1458 s = strcat(s, ftos(rint(time - other.jointime)), ":");
1459 if(other.classname == "player" || g_arena || g_ca || g_lms)
1460 s = strcat(s, ftos(other.team), ":");
1462 s = strcat(s, "spectator:");
1465 print(s, other.netname, "\n");
1467 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
1469 fputs(file, strcat(s, other.netname, "\n"));
1475 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
1481 fputs(file, strcat(s, "\n"));
1483 for(i = 1; i < 16; ++i)
1485 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
1486 s = strcat(s, ":", ftos(i));
1492 fputs(file, strcat(s, "\n"));
1499 GameLogEcho(":end");
1502 fputs(file, ":end\n");
1508 PlayerStats_AddGlobalInfo(e);
1509 PlayerStats_Shutdown();
1512 void FixIntermissionClient(entity e)
1515 if(!e.autoscreenshot) // initial call
1517 e.angles = e.v_angle;
1518 e.angles_x = -e.angles_x;
1519 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1521 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1522 e.solid = SOLID_NOT;
1523 e.movetype = MOVETYPE_NONE;
1524 e.takedamage = DAMAGE_NO;
1527 e.weaponentity.effects = EF_NODRAW;
1528 if (e.weaponentity.weaponentity)
1529 e.weaponentity.weaponentity.effects = EF_NODRAW;
1531 if(clienttype(e) == CLIENTTYPE_REAL)
1533 stuffcmd(e, "\nscr_printspeed 1000000\n");
1534 s = autocvar_sv_intermission_cdtrack;
1536 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1538 WriteByte(MSG_ONE, SVC_INTERMISSION);
1542 //e.velocity = '0 0 0';
1543 //e.fixangle = TRUE;
1545 // TODO halt weapon animation
1550 go to the next level for deathmatch
1551 only called if a time or frag limit has expired
1557 intermission_running = 1;
1559 // enforce a wait time before allowing changelevel
1560 if(player_count > 0)
1561 intermission_exittime = time + autocvar_sv_mapchange_delay;
1563 intermission_exittime = -1;
1566 WriteByte (MSG_ALL, SVC_CDTRACK);
1567 WriteByte (MSG_ALL, 3);
1568 WriteByte (MSG_ALL, 3);
1569 // done in FixIntermission
1572 //pos = FindIntermission ();
1578 if(autocvar_sv_eventlog)
1579 GameLogEcho(":gameover");
1583 FOR_EACH_PLAYER(other) {
1584 FixIntermissionClient(other);
1586 bprint(other.netname, " ^7wins.\n");
1589 if(autocvar_g_campaign)
1590 CampaignPreIntermission();
1592 localcmd("\nsv_hook_gameend\n");
1599 Exit deathmatch games upon conditions
1602 void CheckRules_Player()
1604 if (gameover) // someone else quit the game already
1607 if(self.deadflag == DEAD_NO)
1608 self.play_time += frametime;
1610 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1611 // (div0: and that in CheckRules_World please)
1614 float checkrules_equality;
1615 float checkrules_suddendeathwarning;
1616 float checkrules_suddendeathend;
1617 float checkrules_overtimesadded; //how many overtimes have been already added
1619 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1620 float WINNING_YES = 1; // winner found
1621 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1622 float WINNING_STARTSUDDENDEATHOVERTIME = 3; // no winner, enter suddendeath overtime NOW
1624 float InitiateSuddenDeath()
1626 // Check first whether normal overtimes could be added before initiating suddendeath mode
1627 // - for this timelimit_overtime needs to be >0 of course
1628 // - also check the winning condition calculated in the previous frame and only add normal overtime
1629 // again, if at the point at which timelimit would be extended again, still no winner was found
1630 if ((checkrules_overtimesadded >= 0) && (checkrules_overtimesadded < autocvar_timelimit_overtimes) && autocvar_timelimit_overtime && !(g_race && !g_race_qualifying))
1632 return 1; // need to call InitiateOvertime later
1636 if(!checkrules_suddendeathend)
1638 checkrules_suddendeathend = time + 60 * autocvar_timelimit_suddendeath;
1639 if(g_race && !g_race_qualifying)
1640 race_StartCompleting();
1646 void InitiateOvertime() // ONLY call this if InitiateSuddenDeath returned true
1648 ++checkrules_overtimesadded;
1649 //add one more overtime by simply extending the timelimit
1651 tl = autocvar_timelimit;
1652 tl += autocvar_timelimit_overtime;
1653 cvar_set("timelimit", ftos(tl));
1654 string minutesPlural;
1655 if (autocvar_timelimit_overtime == 1)
1656 minutesPlural = " ^3minute";
1658 minutesPlural = " ^3minutes";
1662 "^3Now playing ^1OVERTIME^3!\n\n^3Added ^1",
1663 ftos(autocvar_timelimit_overtime),
1670 float GetWinningCode(float fraglimitreached, float equality)
1672 if(autocvar_g_campaign == 1)
1673 if(fraglimitreached)
1680 if(fraglimitreached)
1681 return WINNING_STARTSUDDENDEATHOVERTIME;
1683 return WINNING_NEVER;
1685 if(fraglimitreached)
1691 // set the .winning flag for exactly those players with a given field value
1692 void SetWinners(.float field, float value)
1695 FOR_EACH_PLAYER(head)
1696 head.winning = (head.field == value);
1699 // set the .winning flag for those players with a given field value
1700 void AddWinners(.float field, float value)
1703 FOR_EACH_PLAYER(head)
1704 if(head.field == value)
1708 // clear the .winning flags
1709 void ClearWinners(void)
1712 FOR_EACH_PLAYER(head)
1716 // Onslaught winning condition:
1717 // game terminates if only one team has a working generator (or none)
1718 float WinningCondition_Onslaught()
1721 local float t1, t2, t3, t4;
1723 WinningConditionHelper(); // set worldstatus
1728 // first check if the game has ended
1729 t1 = t2 = t3 = t4 = 0;
1730 head = find(world, classname, "onslaught_generator");
1733 if (head.health > 0)
1735 if (head.team == COLOR_TEAM1) t1 = 1;
1736 if (head.team == COLOR_TEAM2) t2 = 1;
1737 if (head.team == COLOR_TEAM3) t3 = 1;
1738 if (head.team == COLOR_TEAM4) t4 = 1;
1740 head = find(head, classname, "onslaught_generator");
1742 if (t1 + t2 + t3 + t4 < 2)
1744 // game over, only one team remains (or none)
1746 if (t1) SetWinners(team, COLOR_TEAM1);
1747 if (t2) SetWinners(team, COLOR_TEAM2);
1748 if (t3) SetWinners(team, COLOR_TEAM3);
1749 if (t4) SetWinners(team, COLOR_TEAM4);
1750 dprint("Have a winner, ending game.\n");
1754 // Two or more teams remain
1758 float LMS_NewPlayerLives()
1761 fl = autocvar_fraglimit;
1765 // first player has left the game for dying too much? Nobody else can get in.
1766 if(lms_lowest_lives < 1)
1769 if(!autocvar_g_lms_join_anytime)
1770 if(lms_lowest_lives < fl - autocvar_g_lms_last_join)
1773 return bound(1, lms_lowest_lives, fl);
1776 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1777 // they win. Otherwise the defending team wins once the timelimit passes.
1778 void assault_new_round();
1779 float WinningCondition_Assault()
1783 WinningConditionHelper(); // set worldstatus
1785 status = WINNING_NO;
1786 // as the timelimit has not yet passed just assume the defending team will win
1787 if(assault_attacker_team == COLOR_TEAM1)
1789 SetWinners(team, COLOR_TEAM2);
1793 SetWinners(team, COLOR_TEAM1);
1797 ent = find(world, classname, "target_assault_roundend");
1800 if(ent.winning) // round end has been triggered by attacking team
1802 bprint("ASSAULT: round completed...\n");
1803 SetWinners(team, assault_attacker_team);
1805 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
1807 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
1809 status = WINNING_YES;
1813 local entity oldself;
1816 assault_new_round();
1825 // LMS winning condition: game terminates if and only if there's at most one
1826 // one player who's living lives. Top two scores being equal cancels the time
1828 float WinningCondition_LMS()
1835 have_player = FALSE;
1836 have_players = FALSE;
1837 l = LMS_NewPlayerLives();
1839 head = find(world, classname, "player");
1842 head2 = find(head, classname, "player");
1844 have_players = TRUE;
1848 // we have at least one player
1851 // two or more active players - continue with the game
1855 // exactly one player?
1858 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1862 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1868 // and assign him his first place
1869 PlayerScore_Add(head, SP_LMS_RANK, 1);
1876 // nobody is playing at all...
1879 // wait for players...
1883 // SNAFU (maybe a draw game?)
1885 dprint("No players, ending game.\n");
1890 // When we get here, we have at least two players who are actually LIVING,
1891 // now check if the top two players have equal score.
1892 WinningConditionHelper();
1895 if(WinningConditionHelper_winner)
1896 WinningConditionHelper_winner.winning = TRUE;
1897 if(WinningConditionHelper_topscore == WinningConditionHelper_secondscore)
1898 return WINNING_NEVER;
1900 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1904 void ShuffleMaplist()
1906 cvar_set("g_maplist", shufflewords(autocvar_g_maplist));
1910 float WinningCondition_Scores(float limit, float leadlimit)
1914 // TODO make everything use THIS winning condition (except LMS)
1915 WinningConditionHelper();
1919 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1920 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1921 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1922 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1926 if(WinningConditionHelper_winner)
1927 WinningConditionHelper_winner.winning = 1;
1928 if(WinningConditionHelper_winnerteam >= 0)
1929 SetWinners(team, WinningConditionHelper_winnerteam);
1931 if(WinningConditionHelper_lowerisbetter)
1933 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1934 WinningConditionHelper_secondscore = -WinningConditionHelper_secondscore;
1938 if(WinningConditionHelper_zeroisworst)
1939 leadlimit = 0; // not supported in this mode
1941 if(g_dm || g_tdm || g_arena || g_ca || (g_race && !g_race_qualifying) || g_nexball)
1942 // these modes always score in increments of 1, thus this makes sense
1944 if(leaderfrags != WinningConditionHelper_topscore)
1946 leaderfrags = WinningConditionHelper_topscore;
1949 if (leaderfrags == limit - 1)
1950 Announce("1fragleft");
1951 else if (leaderfrags == limit - 2)
1952 Announce("2fragsleft");
1953 else if (leaderfrags == limit - 3)
1954 Announce("3fragsleft");
1958 limitreached = FALSE;
1960 if(WinningConditionHelper_topscore >= limit)
1961 limitreached = TRUE;
1964 float leadlimitreached;
1965 leadlimitreached = (WinningConditionHelper_topscore - WinningConditionHelper_secondscore >= leadlimit);
1966 if(autocvar_leadlimit_and_fraglimit)
1967 limitreached = (limitreached && leadlimitreached);
1969 limitreached = (limitreached || leadlimitreached);
1972 return GetWinningCode(
1973 WinningConditionHelper_topscore && limitreached,
1974 WinningConditionHelper_equality
1978 float WinningCondition_Race(float fraglimit)
1989 if(p.race_completed)
1994 wc = WinningCondition_Scores(fraglimit, 0);
1996 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1997 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
1998 // do NOT support equality when the laps are all raced!
1999 return WINNING_STARTSUDDENDEATHOVERTIME;
2001 return WINNING_NEVER;
2005 void ReadyRestart();
2006 float WinningCondition_QualifyingThenRace(float limit)
2009 wc = WinningCondition_Scores(limit, 0);
2011 // NEVER initiate overtime
2012 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
2020 float WinningCondition_RanOutOfSpawns()
2024 if(have_team_spawns <= 0)
2027 if(!some_spawn_has_been_used)
2030 team1_score = team2_score = team3_score = team4_score = 0;
2032 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
2034 if(head.team == COLOR_TEAM1)
2036 else if(head.team == COLOR_TEAM2)
2038 else if(head.team == COLOR_TEAM3)
2040 else if(head.team == COLOR_TEAM4)
2044 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
2046 if(head.team == COLOR_TEAM1)
2048 else if(head.team == COLOR_TEAM2)
2050 else if(head.team == COLOR_TEAM3)
2052 else if(head.team == COLOR_TEAM4)
2057 if(team1_score + team2_score + team3_score + team4_score == 0)
2059 checkrules_equality = TRUE;
2062 else if(team1_score + team2_score + team3_score + team4_score == 1)
2065 if(team1_score) t = COLOR_TEAM1;
2066 if(team2_score) t = COLOR_TEAM2;
2067 if(team3_score) t = COLOR_TEAM3;
2068 if(team4_score) t = COLOR_TEAM4;
2069 CheckAllowedTeams(world);
2070 for(i = 0; i < MAX_TEAMSCORE; ++i)
2072 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
2073 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
2074 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
2075 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
2078 AddWinners(team, t);
2089 Exit deathmatch games upon conditions
2092 void CheckRules_World()
2104 MapVote_Think should now do that part
2105 if (intermission_running)
2106 if (time >= intermission_exittime + 60)
2108 if(!DoNextMapOverride())
2114 if (gameover) // someone else quit the game already
2116 if(player_count == 0) // Nobody there? Then let's go to the next map
2118 // this will actually check the player count in the next frame
2119 // again, but this shouldn't hurt
2123 timelimit = autocvar_timelimit * 60;
2124 fraglimit = autocvar_fraglimit;
2125 leadlimit = autocvar_leadlimit;
2127 if(inWarmupStage || time <= game_starttime) // NOTE: this is <= to prevent problems in the very tic where the game starts
2130 timelimit = 0; // timelimit is not made for warmup
2132 fraglimit = 0; // no fraglimit for now
2133 leadlimit = 0; // no leadlimit for now
2137 timelimit = 0; // ONS has its own overtime rule
2141 timelimit += game_starttime;
2143 else if (timelimit < 0)
2153 if(checkrules_suddendeathend)
2155 if(!checkrules_suddendeathwarning)
2157 checkrules_suddendeathwarning = TRUE;
2158 if(g_race && !g_race_qualifying)
2159 bcenterprint("^3Everyone, finish your lap! The race is over!");
2161 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
2166 if (timelimit && time >= timelimit)
2168 if(g_race && (g_race_qualifying == 2) && timelimit > 0)
2171 float playerswithlaps;
2174 totalplayers = playerswithlaps = readyplayers = 0;
2175 FOR_EACH_PLAYER(head)
2178 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
2184 // at least 2 of the players have completed a lap: start the RACE
2185 // otherwise, the players should end the qualifying on their own
2186 if(readyplayers || playerswithlaps >= 2)
2188 checkrules_suddendeathend = 0;
2189 ReadyRestart(); // go to race
2193 wantovertime |= InitiateSuddenDeath();
2196 wantovertime |= InitiateSuddenDeath();
2200 if (checkrules_suddendeathend && time >= checkrules_suddendeathend)
2206 float checkrules_status;
2207 checkrules_status = WinningCondition_RanOutOfSpawns();
2208 if(checkrules_status == WINNING_YES)
2210 bprint("Hey! Someone ran out of spawns!\n");
2212 else if(g_race && !g_race_qualifying && timelimit >= 0)
2214 checkrules_status = WinningCondition_Race(fraglimit);
2215 //print("WC_RACE yields ", ftos(checkrules_status), "\n");
2217 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
2219 checkrules_status = WinningCondition_QualifyingThenRace(fraglimit);
2220 //print("WC_QUALIFYING_THEN_RACE yields ", ftos(checkrules_status), "\n");
2224 checkrules_status = WinningCondition_Assault(); // TODO remove this?
2228 checkrules_status = WinningCondition_LMS();
2230 else if (g_onslaught)
2232 checkrules_status = WinningCondition_Onslaught(); // TODO remove this?
2236 checkrules_status = WinningCondition_Scores(fraglimit, leadlimit);
2237 //print("WC_SCORES yields ", ftos(checkrules_status), "\n");
2240 if(checkrules_status == WINNING_STARTSUDDENDEATHOVERTIME)
2242 checkrules_status = WINNING_NEVER;
2243 checkrules_overtimesadded = -1;
2244 wantovertime |= InitiateSuddenDeath();
2247 if(checkrules_status == WINNING_NEVER)
2248 // equality cases! Nobody wins if the overtime ends in a draw.
2253 if(checkrules_status == WINNING_NEVER)
2256 checkrules_status = WINNING_YES;
2259 if(checkrules_suddendeathend)
2260 if(checkrules_status != WINNING_NEVER || time >= checkrules_suddendeathend)
2261 checkrules_status = WINNING_YES;
2263 if(checkrules_status == WINNING_YES)
2265 //print("WINNING\n");
2270 float mapvote_nextthink;
2271 float mapvote_initialized;
2272 float mapvote_keeptwotime;
2273 float mapvote_timeout;
2274 string mapvote_message;
2275 #define MAPVOTE_SCREENSHOT_DIRS_COUNT 4
2276 string mapvote_screenshot_dirs[MAPVOTE_SCREENSHOT_DIRS_COUNT];
2277 float mapvote_screenshot_dirs_count;
2279 float mapvote_count;
2280 float mapvote_count_real;
2281 string mapvote_maps[MAPVOTE_COUNT];
2282 float mapvote_maps_screenshot_dir[MAPVOTE_COUNT];
2283 string mapvote_maps_pakfile[MAPVOTE_COUNT];
2284 float mapvote_maps_suggested[MAPVOTE_COUNT];
2285 string mapvote_suggestions[MAPVOTE_COUNT];
2286 float mapvote_suggestion_ptr;
2287 float mapvote_maxlen;
2288 float mapvote_voters;
2289 float mapvote_votes[MAPVOTE_COUNT];
2291 float mapvote_detail;
2292 float mapvote_abstain;
2295 void MapVote_ClearAllVotes()
2297 FOR_EACH_CLIENT(other)
2301 string MapVote_Suggest(string m)
2305 return "That's not how to use this command.";
2306 if(!autocvar_g_maplist_votable_suggestions)
2307 return "Suggestions are not accepted on this server.";
2308 if(mapvote_initialized)
2309 return "Can't suggest - voting is already in progress!";
2310 m = MapInfo_FixName(m);
2312 return "The map you suggested is not available on this server.";
2313 if(!autocvar_g_maplist_votable_suggestions_override_mostrecent)
2315 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
2317 if(!MapInfo_CheckMap(m))
2318 return "The map you suggested does not support the current game mode.";
2319 for(i = 0; i < mapvote_suggestion_ptr; ++i)
2320 if(mapvote_suggestions[i] == m)
2321 return "This map was already suggested.";
2322 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
2324 i = floor(random() * mapvote_suggestion_ptr);
2328 i = mapvote_suggestion_ptr;
2329 mapvote_suggestion_ptr += 1;
2331 if(mapvote_suggestions[i] != "")
2332 strunzone(mapvote_suggestions[i]);
2333 mapvote_suggestions[i] = strzone(m);
2334 if(autocvar_sv_eventlog)
2335 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
2336 return strcat("Suggestion of ", m, " accepted.");
2339 void MapVote_AddVotable(string nextMap, float isSuggestion)
2342 string pakfile, mapfile;
2346 for(j = 0; j < mapvote_count; ++j)
2347 if(mapvote_maps[j] == nextMap)
2349 if(strlen(nextMap) > mapvote_maxlen)
2350 mapvote_maxlen = strlen(nextMap);
2351 mapvote_maps[mapvote_count] = strzone(nextMap);
2352 mapvote_maps_suggested[mapvote_count] = isSuggestion;
2354 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2356 mapfile = strcat(mapvote_screenshot_dirs[i], "/", mapvote_maps[i]);
2357 pakfile = whichpack(strcat(mapfile, ".tga"));
2359 pakfile = whichpack(strcat(mapfile, ".jpg"));
2361 pakfile = whichpack(strcat(mapfile, ".png"));
2365 if(i >= mapvote_screenshot_dirs_count)
2366 i = 0; // FIXME maybe network this error case, as that means there is no mapshot on the server?
2367 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
2368 pakfile = substring(pakfile, o, -1);
2370 mapvote_maps_screenshot_dir[mapvote_count] = i;
2371 mapvote_maps_pakfile[mapvote_count] = strzone(pakfile);
2376 void MapVote_Spawn();
2382 MapVote_ClearAllVotes();
2385 mapvote_detail = !autocvar_g_maplist_votable_nodetail;
2386 mapvote_abstain = autocvar_g_maplist_votable_abstain;
2389 nmax = min(MAPVOTE_COUNT - 1, autocvar_g_maplist_votable);
2391 nmax = min(MAPVOTE_COUNT, autocvar_g_maplist_votable);
2392 smax = min3(nmax, autocvar_g_maplist_votable_suggestions, mapvote_suggestion_ptr);
2394 // we need this for AddVotable, as that cycles through the screenshot dirs
2395 mapvote_screenshot_dirs_count = tokenize_console(autocvar_g_maplist_votable_screenshot_dir);
2396 if(mapvote_screenshot_dirs_count == 0)
2397 mapvote_screenshot_dirs_count = tokenize_console("maps levelshots");
2398 mapvote_screenshot_dirs_count = min(mapvote_screenshot_dirs_count, MAPVOTE_SCREENSHOT_DIRS_COUNT);
2399 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2400 mapvote_screenshot_dirs[i] = strzone(argv(i));
2402 if(mapvote_suggestion_ptr)
2403 for(i = 0; i < 100 && mapvote_count < smax; ++i)
2404 MapVote_AddVotable(mapvote_suggestions[floor(random() * mapvote_suggestion_ptr)], TRUE);
2406 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2407 MapVote_AddVotable(GetNextMap(), FALSE);
2409 if(mapvote_count == 0)
2411 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
2412 cvar_set("g_maplist", MapInfo_ListAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
2413 if(autocvar_g_maplist_shuffle)
2415 localcmd("\nmenu_cmd sync\n");
2416 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2417 MapVote_AddVotable(GetNextMap(), FALSE);
2420 mapvote_count_real = mapvote_count;
2422 MapVote_AddVotable("don't care", 0);
2424 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
2426 mapvote_keeptwotime = time + autocvar_g_maplist_votable_keeptwotime;
2427 mapvote_timeout = time + autocvar_g_maplist_votable_timeout;
2428 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
2429 mapvote_keeptwotime = 0;
2430 mapvote_message = "Choose a map and press its key!";
2435 void MapVote_SendPicture(float id)
2438 WriteByte(MSG_ONE, SVC_TEMPENTITY);
2439 WriteByte(MSG_ONE, TE_CSQC_PICTURE);
2440 WriteByte(MSG_ONE, id);
2441 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dirs[mapvote_maps_screenshot_dir[id]], "/", mapvote_maps[id]), 3072);
2444 float GameCommand_MapVote(string cmd)
2446 if(!intermission_running)
2449 if(cmd == "mv_getpic")
2451 MapVote_SendPicture(stof(argv(1)));
2458 float MapVote_GetMapMask()
2460 float mask, i, power;
2462 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
2463 if(mapvote_maps[i] != "")
2469 float MapVote_SendEntity(entity to, float sf)
2474 sf &~= 2; // if we send 1, we don't need to also send 2
2476 WriteByte(MSG_ENTITY, ENT_CLIENT_MAPVOTE);
2477 WriteByte(MSG_ENTITY, sf);
2481 // flag 1 == initialization
2482 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2483 WriteString(MSG_ENTITY, mapvote_screenshot_dirs[i]);
2484 WriteString(MSG_ENTITY, "");
2485 WriteByte(MSG_ENTITY, mapvote_count);
2486 WriteByte(MSG_ENTITY, mapvote_abstain);
2487 WriteByte(MSG_ENTITY, mapvote_detail);
2488 WriteCoord(MSG_ENTITY, mapvote_timeout);
2489 if(mapvote_count <= 8)
2490 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2492 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2493 for(i = 0; i < mapvote_count; ++i)
2494 if(mapvote_maps[i] != "")
2496 if(mapvote_abstain && i == mapvote_count - 1)
2498 WriteString(MSG_ENTITY, ""); // abstain needs no text
2499 WriteString(MSG_ENTITY, ""); // abstain needs no pack
2500 WriteByte(MSG_ENTITY, 0); // abstain needs no screenshot dir
2504 WriteString(MSG_ENTITY, mapvote_maps[i]);
2505 WriteString(MSG_ENTITY, mapvote_maps_pakfile[i]);
2506 WriteByte(MSG_ENTITY, mapvote_maps_screenshot_dir[i]);
2513 // flag 2 == update of mask
2514 if(mapvote_count <= 8)
2515 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2517 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2523 for(i = 0; i < mapvote_count; ++i)
2524 if(mapvote_maps[i] != "")
2525 WriteByte(MSG_ENTITY, mapvote_votes[i]);
2527 WriteByte(MSG_ENTITY, to.mapvote);
2533 void MapVote_Spawn()
2535 Net_LinkEntity(mapvote_ent = spawn(), FALSE, 0, MapVote_SendEntity);
2538 void MapVote_TouchMask()
2540 mapvote_ent.SendFlags |= 2;
2543 void MapVote_TouchVotes(entity voter)
2545 mapvote_ent.SendFlags |= 4;
2548 float MapVote_Finished(float mappos)
2554 if(autocvar_sv_eventlog)
2556 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2557 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
2558 didntvote = mapvote_voters;
2559 for(i = 0; i < mapvote_count; ++i)
2560 if(mapvote_maps[i] != "")
2562 didntvote -= mapvote_votes[i];
2565 result = strcat(result, ":", mapvote_maps[i]);
2566 result = strcat(result, ":", ftos(mapvote_votes[i]));
2569 result = strcat(result, ":didn't vote:", ftos(didntvote));
2571 GameLogEcho(result);
2572 if(mapvote_maps_suggested[mappos])
2573 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
2576 FOR_EACH_REALCLIENT(other)
2577 FixClientCvars(other);
2579 Map_Goto_SetStr(mapvote_maps[mappos]);
2581 alreadychangedlevel = TRUE;
2584 void MapVote_CheckRules_1()
2588 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2590 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2591 mapvote_votes[i] = 0;
2595 FOR_EACH_REALCLIENT(other)
2600 i = other.mapvote - 1;
2601 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2602 mapvote_votes[i] = mapvote_votes[i] + 1;
2607 float MapVote_CheckRules_2()
2610 float firstPlace, secondPlace;
2611 float firstPlaceVotes, secondPlaceVotes;
2612 float mapvote_voters_real;
2615 if(mapvote_count_real == 1)
2616 return MapVote_Finished(0);
2618 mapvote_voters_real = mapvote_voters;
2620 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2622 RandomSelection_Init();
2623 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2624 RandomSelection_Add(world, i, string_null, 1, mapvote_votes[i]);
2625 firstPlace = RandomSelection_chosen_float;
2626 firstPlaceVotes = RandomSelection_best_priority;
2627 //dprint("First place: ", ftos(firstPlace), "\n");
2628 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2630 RandomSelection_Init();
2631 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2633 RandomSelection_Add(world, i, string_null, 1, mapvote_votes[i]);
2634 secondPlace = RandomSelection_chosen_float;
2635 secondPlaceVotes = RandomSelection_best_priority;
2636 //dprint("Second place: ", ftos(secondPlace), "\n");
2637 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2639 if(firstPlace == -1)
2640 error("No first place in map vote... WTF?");
2642 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2643 return MapVote_Finished(firstPlace);
2645 if(mapvote_keeptwotime)
2646 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2649 MapVote_TouchMask();
2650 mapvote_message = "Now decide between the TOP TWO!";
2651 mapvote_keeptwotime = 0;
2652 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2653 result = strcat(result, ":", ftos(firstPlaceVotes));
2654 result = strcat(result, ":", mapvote_maps[secondPlace]);
2655 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2656 didntvote = mapvote_voters;
2657 for(i = 0; i < mapvote_count; ++i)
2658 if(mapvote_maps[i] != "")
2660 didntvote -= mapvote_votes[i];
2662 if(i != secondPlace)
2664 result = strcat(result, ":", mapvote_maps[i]);
2665 result = strcat(result, ":", ftos(mapvote_votes[i]));
2666 if(i < mapvote_count_real)
2668 strunzone(mapvote_maps[i]);
2669 mapvote_maps[i] = "";
2670 strunzone(mapvote_maps_pakfile[i]);
2671 mapvote_maps_pakfile[i] = "";
2675 result = strcat(result, ":didn't vote:", ftos(didntvote));
2676 if(autocvar_sv_eventlog)
2677 GameLogEcho(result);
2687 keeptwo = mapvote_keeptwotime;
2688 MapVote_CheckRules_1(); // count
2689 if(MapVote_CheckRules_2()) // decide
2693 FOR_EACH_REALCLIENT(other)
2695 // hide scoreboard again
2696 if(other.health != 2342)
2698 other.health = 2342;
2700 if(clienttype(other) == CLIENTTYPE_REAL)
2703 WriteByte(MSG_ONE, SVC_FINALE);
2704 WriteString(MSG_ONE, "");
2708 // clear possibly invalid votes
2709 if(mapvote_maps[other.mapvote - 1] == "")
2711 // use impulses as new vote
2712 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2713 if(mapvote_maps[other.impulse - 1] != "")
2715 other.mapvote = other.impulse;
2716 MapVote_TouchVotes(other);
2724 MapVote_CheckRules_1(); // just count
2726 void MapVote_Start()
2731 // wait for stats to be sent first
2732 if(!playerstats_waitforme)
2735 MapInfo_Enumerate();
2736 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
2739 void MapVote_Think()
2744 if(alreadychangedlevel)
2747 if(time < mapvote_nextthink)
2751 mapvote_nextthink = time + 0.5;
2753 if(!mapvote_initialized)
2755 if(autocvar_rescan_pending == 1)
2757 cvar_set("rescan_pending", "2");
2758 localcmd("fs_rescan\nrescan_pending 3\n");
2761 else if(autocvar_rescan_pending == 2)
2765 else if(autocvar_rescan_pending == 3)
2767 // now build missing mapinfo files
2768 if(!MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
2771 // we're done, start the timer
2772 cvar_set("rescan_pending", "0");
2775 mapvote_initialized = TRUE;
2776 if(DoNextMapOverride())
2778 if(!autocvar_g_maplist_votable || player_count <= 0)
2789 string GotoMap(string m)
2791 if(!MapInfo_CheckMap(m))
2792 return "The map you chose is not available on this server.";
2793 cvar_set("nextmap", m);
2794 cvar_set("timelimit", "-1");
2795 if(mapvote_initialized || alreadychangedlevel)
2797 if(DoNextMapOverride())
2798 return "Map switch initiated.";
2800 return "Hm... no. For some reason I like THIS map more.";
2803 return "Map switch will happen after scoreboard.";
2810 FOR_EACH_REALCLIENT(self)
2812 if(self.classname == "spectator")
2814 if(self.enemy.typehitsound)
2815 play2(self, "misc/typehit.wav");
2816 else if(self.enemy.hitsound && self.cvar_cl_hitsound)
2817 play2(self, "misc/hit.wav");
2821 if(self.typehitsound)
2822 play2(self, "misc/typehit.wav");
2823 else if(self.hitsound && self.cvar_cl_hitsound)
2824 play2(self, "misc/hit.wav");
2827 altime = time + frametime * (1 + autocvar_g_antilag_nudge);
2828 // add 1 frametime because after this, engine SV_Physics
2829 // increases time by a frametime and then networks the frame
2830 // add another frametime because client shows everything with
2831 // 1 frame of lag (cl_nolerp 0). The last +1 however should not be
2833 FOR_EACH_CLIENT(self)
2835 self.hitsound = FALSE;
2836 self.typehitsound = FALSE;
2837 antilag_record(self, altime);
2844 * returns TRUE if redirecting
2846 float redirection_timeout;
2847 float redirection_nextthink;
2848 float RedirectionThink()
2850 float clients_found;
2852 if(redirection_target == "")
2855 if(!redirection_timeout)
2857 cvar_set("sv_public", "-2");
2858 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2859 if(redirection_target == "self")
2860 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2862 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2865 if(time < redirection_nextthink)
2868 redirection_nextthink = time + 1;
2871 FOR_EACH_REALCLIENT(self)
2873 print("Redirecting: sending connect command to ", self.netname, "\n");
2874 if(redirection_target == "self")
2875 stuffcmd(self, "\ndisconnect; reconnect\n");
2877 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2881 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2883 if(time > redirection_timeout || clients_found == 0)
2884 localcmd("\nwait; wait; wait; quit\n");
2889 void TargetMusic_RestoreGame();
2892 // Loaded from a save game
2893 // some things then break, so let's work around them...
2895 // Progs DB (capture records)
2896 ServerProgsDB = db_load("server.db");
2900 MapInfo_Enumerate();
2901 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
2904 TargetMusic_RestoreGame();
2911 if(gameover > 1) // shutting down already?
2914 gameover = 2; // 2 = server shutting down
2916 if(world_initialized > 0)
2918 world_initialized = 0;
2919 print("Saving persistent data...\n");
2923 PlayerStats_AddGlobalInfo(e);
2924 PlayerStats_Shutdown();
2926 if(!cheatcount_total)
2928 if(autocvar_sv_db_saveasdump)
2929 db_dump(ServerProgsDB, "server.db");
2931 db_save(ServerProgsDB, "server.db");
2933 if(autocvar_developer)
2935 if(autocvar_sv_db_saveasdump)
2936 db_dump(TemporaryDB, "server-temp.db");
2938 db_save(TemporaryDB, "server-temp.db");
2940 CheatShutdown(); // must be after cheatcount check
2941 db_close(ServerProgsDB);
2942 db_close(TemporaryDB);
2944 // tell the bot system the game is ending now
2947 WeaponStats_Shutdown();
2950 else if(world_initialized == 0)
2952 print("NOTE: crashed before even initializing the world, not saving persistent data\n");