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");
260 BADPREFIX("net_slist_");
266 BADPREFIX("sensitivity");
267 BADPREFIX("userbind");
270 BADPREFIX("crosshair");
271 BADCVAR("mod_q3bsp_lightmapmergepower");
272 BADCVAR("mod_q3bsp_nolightmaps");
274 BADCVAR("mastervolume");
276 BADCVAR("bgmvolume");
279 BADCVAR("developer");
280 BADCVAR("g_banned_list");
281 BADCVAR("log_dest_udp");
283 BADCVAR("net_address");
284 BADCVAR("net_address_ipv6");
286 BADCVAR("savedgamecfg");
287 BADCVAR("serverconfig");
288 BADCVAR("sv_heartbeatperiod");
289 BADCVAR("sv_vote_master_password");
290 BADCVAR("sys_colortranslation");
291 BADCVAR("sys_specialcharactertranslation");
292 BADCVAR("timestamps");
293 BADPREFIX("developer_");
295 BADPREFIX("g_chat_flood_");
296 BADPREFIX("g_voice_flood_");
298 BADPREFIX("settemp_");
299 BADPREFIX("sv_allowdownloads_");
300 BADPREFIX("sv_autodemo");
301 BADPREFIX("sv_curl_");
302 BADPREFIX("sv_eventlog");
303 BADPREFIX("sv_logscores_");
304 BADPREFIX("sv_master");
305 BADPREFIX("sv_weaponstats_");
307 // these can contain player IDs, so better hide
308 BADCVAR("g_forced_team_red");
309 BADCVAR("g_forced_team_blue");
310 BADCVAR("g_forced_team_yellow");
311 BADCVAR("g_forced_team_pink");
314 BADCVAR("timelimit");
315 BADCVAR("fraglimit");
316 BADCVAR("leadlimit");
317 BADCVAR("g_tdm_teams");
318 BADCVAR("g_keyhunt_teams");
319 BADCVAR("g_domination_default_teams");
320 BADCVAR("g_race_qualifying_timelimit");
324 BADCVAR("g_assault");
327 BADCVAR("g_domination");
328 BADCVAR("g_freezetag");
329 BADCVAR("g_keyhunt");
330 BADCVAR("g_keyhunt_teams");
331 BADCVAR("g_onslaught");
334 BADCVAR("g_runematch");
336 BADCVAR("g_nexball");
337 BADCVAR("g_keepaway");
342 BADCVAR("g_maplist");
343 BADCVAR("g_maplist_mostrecent");
347 d = cvar_defstring(k);
353 cvar_changes = strcat(cvar_changes, k, " \"", v, "\" // \"", d, "\"\n");
354 if(strlen(cvar_changes) > 16384)
356 cvar_changes = "// too many settings have been changed to show them here\n";
361 // now check if the changes are actually gameplay relevant
363 // does nothing visible
364 BADCVAR("captureleadlimit_override");
365 BADCVAR("g_arena_point_leadlimit");
366 BADCVAR("g_ca_point_leadlimit");
367 BADCVAR("g_ctf_capture_leadlimit");
368 BADCVAR("g_domination_point_leadlimit");
369 BADCVAR("g_keyhunt_point_leadlimit");
370 BADCVAR("g_nexball_goalleadlimit");
371 BADCVAR("g_runematch_point_leadlimit");
372 BADCVAR("leadlimit_and_fraglimit");
373 BADCVAR("leadlimit_override");
374 BADCVAR("sv_checkforpacketsduringsleep");
376 BADCVAR("sv_timeout");
377 BADPREFIX("crypto_");
378 BADPREFIX("g_chat_");
381 BADPREFIX("sv_fragmessage_");
382 BADPREFIX("sv_vote_");
383 BADPREFIX("timelimit_");
385 // allowed changes to server admins (please sync this to server.cfg)
389 // :%s,//\([^ ]*\).*,BADCVAR("\1");,
391 // yes, this does contain some redundant stuff, don't really care
392 BADCVAR("bot_number");
393 BADCVAR("bot_prefix");
394 BADCVAR("bot_suffix");
395 BADCVAR("capturelimit_override");
396 BADCVAR("fraglimit_override");
398 BADCVAR("g_antilag");
399 BADCVAR("g_balance_teams");
400 BADCVAR("g_balance_teams_force");
401 BADCVAR("g_ban_sync_trusted_servers");
402 BADCVAR("g_ban_sync_uri");
403 BADCVAR("g_ctf_capture_limit");
404 BADCVAR("g_ctf_ignore_frags");
405 BADCVAR("g_ctf_win_mode");
406 BADCVAR("g_domination_point_limit");
407 BADCVAR("g_fullbrightitems");
408 BADCVAR("g_fullbrightplayers");
409 BADCVAR("g_keyhunt_point_limit");
410 BADCVAR("g_keyhunt_teams_override");
411 BADCVAR("g_lms_lives_override");
412 BADCVAR("g_maplist");
413 BADCVAR("g_maplist_check_waypoints");
414 BADCVAR("g_maplist_mostrecent_count");
415 BADCVAR("g_maplist_shuffle");
416 BADCVAR("g_maplist_votable");
417 BADCVAR("g_maplist_votable_abstain");
418 BADCVAR("g_maplist_votable_nodetail");
419 BADCVAR("g_maplist_votable_suggestions");
420 BADCVAR("g_minstagib");
421 BADCVAR("g_nexball_goallimit");
422 BADCVAR("g_runematch_point_limit");
423 BADCVAR("g_start_delay");
424 BADCVAR("g_weapon_stay"); BADPRESUFFIX("g_", "_weapon_stay");
427 BADCVAR("maxplayers");
428 BADCVAR("minplayers");
429 BADCVAR("net_address");
431 BADCVAR("rcon_password");
432 BADCVAR("rcon_restricted_commands");
433 BADCVAR("rcon_restricted_password");
435 BADCVAR("sv_adminnick");
436 BADCVAR("sv_autoscreenshot");
437 BADCVAR("sv_curl_defaulturl");
438 BADCVAR("sv_defaultcharacter");
439 BADCVAR("sv_defaultplayercolors");
440 BADCVAR("sv_defaultplayermodel");
441 BADCVAR("sv_defaultplayerskin");
442 BADCVAR("sv_maxidle");
443 BADCVAR("sv_maxrate");
445 BADCVAR("sv_public");
446 BADCVAR("sv_ready_restart");
447 BADCVAR("sv_status_privacy");
448 BADCVAR("sv_vote_call");
449 BADCVAR("sv_vote_commands");
450 BADCVAR("sv_vote_majority_factor");
451 BADCVAR("sv_vote_master");
452 BADCVAR("sv_vote_master_commands");
453 BADCVAR("sv_vote_master_password");
454 BADCVAR("sv_vote_simple_majority_factor");
455 BADCVAR("timelimit_override");
457 BADPREFIX("g_warmup_");
459 if(autocvar_g_minstagib)
461 BADCVAR("g_grappling_hook");
462 BADCVAR("g_jetpack");
469 cvar_purechanges = strcat(cvar_purechanges, k, " \"", v, "\" // \"", d, "\"\n");
470 if(strlen(cvar_purechanges) > 16384)
472 cvar_purechanges = "// too many settings have been changed to show them here\n";
476 ++cvar_purechanges_count;
477 // WARNING: this variable is used for the server list
478 // NEVER dare to skip this code!
479 // Hacks to intentionally appearing as "pure server" even though you DO have
480 // modified settings may be punished by removal from the server list.
481 // You can do to the variables cvar_changes and cvar_purechanges all you want,
485 if(cvar_changes == "")
486 cvar_changes = "// this server runs at default server settings\n";
488 cvar_changes = strcat("// this server runs at modified server settings:\n", cvar_changes);
489 cvar_changes = strzone(cvar_changes);
490 if(cvar_purechanges == "")
491 cvar_purechanges = "// this server runs at default gameplay settings\n";
493 cvar_purechanges = strcat("// this server runs at modified gameplay settings:\n", cvar_purechanges);
494 cvar_purechanges = strzone(cvar_purechanges);
497 void detect_maptype()
506 o_x += random() * (world.maxs_x - world.mins_x);
507 o_y += random() * (world.maxs_y - world.mins_y);
508 o_z += random() * (world.maxs_z - world.mins_z);
510 tracebox(o, PL_MIN, PL_MAX, o - '0 0 32768', MOVE_WORLDONLY, world);
511 if(trace_fraction == 1)
516 for(i = 0; i < 64; i += 4)
518 tracebox(o, '-1 -1 -1' * i, '1 1 1' * i, o - '0 0 32768', MOVE_WORLDONLY, world);
519 if(trace_fraction == 1)
521 print(ftos(i), " -> ", vtos(trace_endpos), "\n");
530 float RandomSeed_Send(entity to, float sf)
532 WriteByte(MSG_ENTITY, ENT_CLIENT_RANDOMSEED);
533 WriteShort(MSG_ENTITY, self.cnt);
536 void RandomSeed_Think()
538 self.cnt = bound(0, floor(random() * 65536), 65535);
539 self.nextthink = time + 5;
543 void RandomSeed_Spawn()
545 randomseed = spawn();
546 randomseed.think = RandomSeed_Think;
547 Net_LinkEntity(randomseed, FALSE, 0, RandomSeed_Send);
552 self.think(); // sets random seed and nextthink
556 void spawnfunc___init_dedicated_server(void)
558 // handler for _init/_init map (only for dedicated server initialization)
560 world_initialized = -1; // don't complain
562 cvar_string = cvar_string_normal;
563 cvar_set = cvar_set_normal;
565 remove = remove_unsafely;
569 e.think = GotoFirstMap;
570 e.nextthink = time; // this is usually 1 at this point
573 e.classname = "info_player_deathmatch"; // safeguard against player joining
575 self.classname = "worldspawn"; // safeguard against various stuff ;)
578 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
581 void Map_MarkAsRecent(string m);
582 float world_already_spawned;
583 void RegisterWeapons();
585 void ClientInit_Spawn();
586 void WeaponStats_Init();
587 void WeaponStats_Shutdown();
588 void spawnfunc_worldspawn (void)
590 float fd, l, i, j, n;
594 cvar_string = cvar_string_normal;
595 cvar_set = cvar_set_normal;
597 if(world_already_spawned)
598 error("world already spawned - you may have EXACTLY ONE worldspawn!");
599 world_already_spawned = TRUE;
601 remove = remove_safely; // during spawning, watch what you remove!
603 check_unacceptable_compiler_bugs();
605 cvar_changes_init(); // do this very early now so it REALLY matches the server config
607 compressShortVector_init();
609 allowed_to_spawn = TRUE;
612 head = nextent(world);
617 head = nextent(head);
620 // needs to be done so early as they would still spawn
623 ServerProgsDB = db_load("server.db");
625 TemporaryDB = db_create();
630 // 1 FLICKER (first variety)
631 lightstyle(1, "mmnmmommommnonmmonqnmmo");
633 // 2 SLOW STRONG PULSE
634 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
636 // 3 CANDLE (first variety)
637 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
640 lightstyle(4, "mamamamamama");
643 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
645 // 6 FLICKER (second variety)
646 lightstyle(6, "nmonqnmomnmomomno");
648 // 7 CANDLE (second variety)
649 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
651 // 8 CANDLE (third variety)
652 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
654 // 9 SLOW STROBE (fourth variety)
655 lightstyle(9, "aaaaaaaazzzzzzzz");
657 // 10 FLUORESCENT FLICKER
658 lightstyle(10, "mmamammmmammamamaaamammma");
660 // 11 SLOW PULSE NOT FADE TO BLACK
661 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
663 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
668 if(autocvar_g_campaign)
671 Map_MarkAsRecent(mapname);
673 precache_model ("null"); // we need this one before InitGameplayMode
681 bot_waypoints_for_items = autocvar_g_waypoints_for_items;
682 if(bot_waypoints_for_items == 1)
683 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
684 bot_waypoints_for_items = 0;
686 // for setting by mapinfo
687 q3acompat_machineshotgunswap = autocvar_sv_q3acompat_machineshotgunswap;
688 cvar_set("sv_q3acompat_machineshotgunswap", "0");
692 WaypointSprite_Init();
697 GameLogInit(); // prepare everything
698 if(autocvar_sv_eventlog)
700 s = strcat(ftos(autocvar_sv_eventlog_files_counter), ".");
701 s = strcat(s, ftos(random()));
702 matchid = strzone(s);
704 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
705 s = ":gameinfo:mutators:LIST";
708 MUTATOR_CALLHOOK(BuildMutatorsString);
711 // simple, probably not good in the mutator system
712 if(autocvar_g_grappling_hook)
713 s = strcat(s, ":grappling_hook");
715 // initialiation stuff, not good in the mutator system
716 if(!autocvar_g_use_ammunition)
717 s = strcat(s, ":no_use_ammunition");
719 // initialiation stuff, not good in the mutator system
720 if(!autocvar_g_pickup_items)
721 s = strcat(s, ":no_pickup_items");
723 // initialiation stuff, not good in the mutator system
724 if(autocvar_g_weaponarena != "0")
725 s = strcat(s, ":", autocvar_g_weaponarena, " arena");
727 // TODO to mutator system
728 if(autocvar_g_norecoil)
729 s = strcat(s, ":norecoil");
731 // TODO to mutator system
732 if(autocvar_g_midair)
733 s = strcat(s, ":midair");
735 // TODO to mutator system
736 if(autocvar_g_minstagib)
737 s = strcat(s, ":minstagib");
740 GameLogEcho(":gameinfo:end");
743 matchid = strzone(ftos(random()));
745 cvar_set("nextmap", "");
749 if(autocvar_g_campaign)
757 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
759 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
761 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
764 while((s = fgets(fd)))
766 l = tokenize_console(s);
771 print("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
772 print(" cdtrack ", argv(2), "\n");
774 else if(argv(0) == "fog")
776 print("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
777 print(" \"fog\" \"", s, "\"\n");
779 else if(argv(0) == "set")
781 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
782 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
784 else if(argv(0) != "//")
786 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
787 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
796 addstat(STAT_WEAPONS, AS_INT, weapons);
797 addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
798 addstat(STAT_GAMESTARTTIME, AS_FLOAT, stat_game_starttime);
799 addstat(STAT_ALLOW_OLDNEXBEAM, AS_INT, stat_allow_oldnexbeam);
802 addstat(STAT_STRENGTH_FINISHED, AS_FLOAT, strength_finished);
803 addstat(STAT_INVINCIBLE_FINISHED, AS_FLOAT, invincible_finished);
804 addstat(STAT_PRESSED_KEYS, AS_FLOAT, pressedkeys);
805 addstat(STAT_FUEL, AS_INT, ammo_fuel);
806 addstat(STAT_SHOTORG, AS_INT, stat_shotorg);
807 addstat(STAT_LEADLIMIT, AS_FLOAT, stat_leadlimit);
808 addstat(STAT_BULLETS_LOADED, AS_INT, campingrifle_bulletcounter);
809 addstat(STAT_LAST_PICKUP, AS_FLOAT, last_pickup);
811 addstat(STAT_NEX_CHARGE, AS_FLOAT, nex_charge);
812 addstat(STAT_NEX_CHARGEPOOL, AS_FLOAT, nex_chargepool_ammo);
814 if(g_ca || g_freezetag)
816 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
817 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
818 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
819 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
823 addstat(STAT_FROZEN, AS_INT, freezetag_frozen);
824 addstat(STAT_REVIVE_PROGRESS, AS_FLOAT, freezetag_revive_progress);
827 // g_movementspeed hack
828 addstat(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW, AS_FLOAT, stat_sv_airspeedlimit_nonqw);
829 addstat(STAT_MOVEVARS_MAXSPEED, AS_FLOAT, stat_sv_maxspeed);
830 addstat(STAT_MOVEVARS_AIRACCEL_QW, AS_FLOAT, stat_sv_airaccel_qw);
831 addstat(STAT_MOVEVARS_AIRSTRAFEACCEL_QW, AS_FLOAT, stat_sv_airstrafeaccel_qw);
833 next_pingtime = time + 5;
837 lsmaps_reply = "^7Maps available: ";
838 lsnewmaps_reply = "^7Maps without a record set: ";
839 for(i = 0, j = 0; i < MapInfo_count; ++i)
841 if(MapInfo_Get_ByID(i))
842 if not(MapInfo_Map_flags & (MAPINFO_FLAG_HIDDEN | MAPINFO_FLAG_FORBIDDEN))
849 lsmaps_reply = strcat(lsmaps_reply, col, MapInfo_Map_bspname, " ");
850 if(g_race && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "time"))))
851 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
852 else if(g_cts && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "time"))))
853 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
856 lsmaps_reply = strzone(strcat(lsmaps_reply, "\n"));
857 if (!g_race && !g_cts)
858 lsnewmaps_reply = "Need to be playing race or CTS for lsnewmaps to work.";
859 lsnewmaps_reply = strzone(strcat(lsnewmaps_reply, "\n"));
861 maplist_reply = "^7Maps in list: ";
862 n = tokenize_console(autocvar_g_maplist);
863 for(i = 0, j = 0; i < n; ++i)
865 if(MapInfo_CheckMap(argv(i)))
871 maplist_reply = strcat(maplist_reply, col, argv(i), " ");
875 maplist_reply = strzone(strcat(maplist_reply, "\n"));
876 MapInfo_ClearTemps();
878 for(i = 0; i < 10; ++i)
880 records_reply[i] = strzone(getrecords(i));
883 ladder_reply = strzone(getladder());
885 rankings_reply = strzone(getrankings());
889 PingPLReport_Spawn();
893 localcmd("\n_sv_hook_gamestart ", GetGametype(), "\n");
895 // fill sv_curl_serverpackages from .serverpackage files
896 if(autocvar_sv_curl_serverpackages_auto)
898 fd = search_begin("*.serverpackage", TRUE, FALSE);
902 j = search_getsize(fd);
903 for(i = 0; i < j; ++i)
904 s = strcat(s, " ", search_getfilename(fd, i));
907 cvar_set("sv_curl_serverpackages", substring(s, 1, -1));
912 world_initialized = 1;
915 void spawnfunc_light (void)
917 //makestatic (self); // Who the f___ did that?
921 float TryFile( string pFilename )
924 dprint("TryFile(\"", pFilename, "\")\n");
925 lHandle = fopen( pFilename, FILE_READ );
926 if( lHandle != -1 ) {
936 return GametypeNameFromType(game);
939 string getmapname_stored;
945 float Map_Count, Map_Current;
946 string Map_Current_Name;
948 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
949 float GetMaplistPosition()
955 idx = autocvar_g_maplist_index;
962 for(pos = 0; pos < Map_Count; ++pos)
966 // resume normal maplist rotation if current map is not in g_maplist
970 float MapHasRightSize(string map)
973 if(currentbots || autocvar_bot_number || player_count < autocvar_minplayers)
974 if(autocvar_g_maplist_check_waypoints)
976 dprint("checkwp "); dprint(map);
977 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
980 dprint(": no waypoints\n");
983 dprint(": has waypoints\n");
987 // open map size restriction file
988 dprint("opensize "); dprint(map);
989 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
992 float mapmin, mapmax;
994 mapmin = stof(fgets(fh));
995 mapmax = stof(fgets(fh));
997 if(player_count < mapmin)
999 dprint("not enough\n");
1002 if(player_count > mapmax)
1004 dprint("too many\n");
1007 dprint("right size\n");
1010 dprint(": not found\n");
1014 string Map_Filename(float position)
1016 return strcat("maps/", argv(position), ".bsp");
1019 string strwords(string s, float w)
1022 for(endpos = 0; w && endpos >= 0; --w)
1023 endpos = strstrofs(s, " ", endpos + 1);
1027 return substring(s, 0, endpos);
1030 float strhasword(string s, string w)
1032 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
1035 void Map_MarkAsRecent(string m)
1037 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", autocvar_g_maplist_mostrecent), max(0, autocvar_g_maplist_mostrecent_count)));
1040 float Map_IsRecent(string m)
1042 return strhasword(autocvar_g_maplist_mostrecent, m);
1045 float Map_Check(float position, float pass)
1049 map_next = argv(position);
1052 if(Map_IsRecent(map_next))
1055 filename = Map_Filename(position);
1056 if(MapInfo_CheckMap(map_next))
1060 if(MapHasRightSize(map_next))
1065 dprint( "Couldn't select '", filename, "'..\n" );
1070 void Map_Goto_SetStr(string nextmapname)
1072 if(getmapname_stored != "")
1073 strunzone(getmapname_stored);
1074 if(nextmapname == "")
1075 getmapname_stored = "";
1077 getmapname_stored = strzone(nextmapname);
1080 void Map_Goto_SetFloat(float position)
1082 cvar_set("g_maplist_index", ftos(position));
1083 Map_Goto_SetStr(argv(position));
1088 // settings persist, except...
1089 localcmd("\nsettemp_restore\n");
1095 MapInfo_LoadMap(getmapname_stored);
1098 // return codes of map selectors:
1099 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
1100 // -2 = permanent failure
1101 float() MaplistMethod_Iterate = // usual method
1105 for(pass = 1; pass <= 2; ++pass)
1107 for(i = 1; i < Map_Count; ++i)
1110 mapindex = mod(i + Map_Current, Map_Count);
1111 if(Map_Check(mapindex, pass))
1118 float() MaplistMethod_Repeat = // fallback method
1120 if(Map_Check(Map_Current, 2))
1125 float() MaplistMethod_Random = // random map selection
1131 for(i = 0; i <= imax; ++i)
1134 mapindex = mod(Map_Current + floor(random() * (Map_Count - 1) + 1), Map_Count); // any OTHER map
1135 if(Map_Check(mapindex, 1))
1141 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
1142 // the exponent sets a bias on the map selection:
1143 // the higher the exponent, the less likely "shortly repeated" same maps are
1145 float i, j, imax, insertpos;
1149 for(i = 0; i <= imax; ++i)
1153 // now reinsert this at another position
1154 insertpos = pow(random(), 1 / exponent); // ]0, 1]
1155 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
1156 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
1157 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
1159 // insert the current map there
1161 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
1162 newlist = strcat(newlist, " ", argv(j));
1163 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
1164 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
1165 newlist = strcat(newlist, " ", argv(j));
1166 newlist = substring(newlist, 1, strlen(newlist) - 1);
1167 cvar_set("g_maplist", newlist);
1168 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1170 // NOTE: the selected map has just been inserted at (insertpos-1)th position
1171 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
1172 if(Map_Check(Map_Current, 1))
1180 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1183 bprint( "Maplist is empty! Resetting it to default map list.\n" );
1184 cvar_set("g_maplist", MapInfo_ListAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
1185 if(autocvar_g_maplist_shuffle)
1187 localcmd("\nmenu_cmd sync\n");
1188 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1191 error("empty maplist, cannot select a new map");
1192 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
1194 if(Map_Current_Name)
1195 strunzone(Map_Current_Name);
1196 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
1197 // this may or may not be correct, but who cares, in the worst case a map
1198 // isn't chosen in the first pass that should have been
1209 if(autocvar_g_maplist_shuffle > 0)
1210 nextMap = MaplistMethod_Shuffle(autocvar_g_maplist_shuffle + 1);
1213 if(autocvar_g_maplist_selectrandom)
1214 nextMap = MaplistMethod_Random();
1217 nextMap = MaplistMethod_Iterate();
1220 nextMap = MaplistMethod_Repeat();
1224 Map_Goto_SetFloat(nextMap);
1225 return getmapname_stored;
1231 float DoNextMapOverride()
1233 if(autocvar_g_campaign)
1235 CampaignPostIntermission();
1236 alreadychangedlevel = TRUE;
1239 if(autocvar_quit_when_empty)
1241 if(player_count <= currentbots)
1244 alreadychangedlevel = TRUE;
1248 if(autocvar_quit_and_redirect != "")
1250 redirection_target = strzone(autocvar_quit_and_redirect);
1251 alreadychangedlevel = TRUE;
1254 if (autocvar_samelevel) // if samelevel is set, stay on same level
1256 // 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)
1257 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
1258 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
1259 localcmd("restart\n");
1260 //changelevel (mapname);
1261 alreadychangedlevel = TRUE;
1264 if(autocvar_nextmap != "")
1265 if(MapInfo_CheckMap(autocvar_nextmap))
1267 Map_Goto_SetStr(autocvar_nextmap);
1269 alreadychangedlevel = TRUE;
1272 if(autocvar_lastlevel)
1275 localcmd("set lastlevel 0\ntogglemenu\n");
1276 alreadychangedlevel = TRUE;
1284 //local string nextmap;
1285 //local float n, nummaps;
1287 if (alreadychangedlevel)
1289 alreadychangedlevel = TRUE;
1295 for(allowReset = 1; allowReset >= 0; --allowReset)
1297 nextMap = GetNextMap();
1303 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1304 cvar_set("g_maplist", MapInfo_ListAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
1305 if(autocvar_g_maplist_shuffle)
1307 localcmd("\nmenu_cmd sync\n");
1311 error("Everything is broken - not even the default map list works. Please report this to the developers.");
1323 When the player presses attack or jump, change to the next level
1326 .float autoscreenshot;
1327 void() MapVote_Start;
1328 void() MapVote_Think;
1329 float mapvote_initialized;
1330 void IntermissionThink()
1332 FixIntermissionClient(self);
1334 if(autocvar_sv_autoscreenshot)
1335 if(self.autoscreenshot > 0)
1336 if(time > self.autoscreenshot)
1338 self.autoscreenshot = -1;
1339 if(clienttype(self) == CLIENTTYPE_REAL)
1340 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
1344 if (time < intermission_exittime)
1347 if(!mapvote_initialized)
1348 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
1358 Returns the entity to view from
1362 entity FindIntermission()
1367 // look for info_intermission first
1368 spot = find (world, classname, "info_intermission");
1370 { // pick a random one
1374 spot = find (spot, classname, "info_intermission");
1376 spot = find (spot, classname, "info_intermission");
1382 // then look for the start position
1383 spot = find (world, classname, "info_player_start");
1387 // testinfo_player_start is only found in regioned levels
1388 spot = find (world, classname, "testplayerstart");
1392 // then look for the start position
1393 spot = find (world, classname, "info_player_deathmatch");
1397 //objerror ("FindIntermission: no spot");
1403 ===============================================================================
1407 ===============================================================================
1410 void DumpStats(float final)
1420 to_console = autocvar_sv_logscores_console;
1421 to_eventlog = autocvar_sv_eventlog;
1422 to_file = autocvar_sv_logscores_file;
1426 to_console = TRUE; // always print printstats replies
1427 to_eventlog = FALSE; // but never print them to the event log
1431 if(autocvar_sv_eventlog_console)
1432 to_console = FALSE; // otherwise we get the output twice
1438 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
1446 file = fopen(autocvar_sv_logscores_filename, FILE_APPEND);
1450 fputs(file, strcat(s, "\n"));
1453 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
1459 fputs(file, strcat(s, "\n"));
1461 FOR_EACH_CLIENT(other)
1463 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && autocvar_sv_logscores_bots))
1465 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
1466 s = strcat(s, ftos(rint(time - other.jointime)), ":");
1467 if(other.classname == "player" || g_arena || g_ca || g_lms)
1468 s = strcat(s, ftos(other.team), ":");
1470 s = strcat(s, "spectator:");
1473 print(s, other.netname, "\n");
1475 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
1477 fputs(file, strcat(s, other.netname, "\n"));
1483 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
1489 fputs(file, strcat(s, "\n"));
1491 for(i = 1; i < 16; ++i)
1493 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
1494 s = strcat(s, ":", ftos(i));
1500 fputs(file, strcat(s, "\n"));
1507 GameLogEcho(":end");
1510 fputs(file, ":end\n");
1516 PlayerStats_AddGlobalInfo(e);
1517 PlayerStats_Shutdown();
1520 void FixIntermissionClient(entity e)
1523 if(!e.autoscreenshot) // initial call
1525 e.angles = e.v_angle;
1526 e.angles_x = -e.angles_x;
1527 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1529 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1530 e.solid = SOLID_NOT;
1531 e.movetype = MOVETYPE_NONE;
1532 e.takedamage = DAMAGE_NO;
1535 e.weaponentity.effects = EF_NODRAW;
1536 if (e.weaponentity.weaponentity)
1537 e.weaponentity.weaponentity.effects = EF_NODRAW;
1539 if(clienttype(e) == CLIENTTYPE_REAL)
1541 stuffcmd(e, "\nscr_printspeed 1000000\n");
1542 s = autocvar_sv_intermission_cdtrack;
1544 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1546 WriteByte(MSG_ONE, SVC_INTERMISSION);
1550 //e.velocity = '0 0 0';
1551 //e.fixangle = TRUE;
1553 // TODO halt weapon animation
1558 go to the next level for deathmatch
1559 only called if a time or frag limit has expired
1565 intermission_running = 1;
1567 // enforce a wait time before allowing changelevel
1568 if(player_count > 0)
1569 intermission_exittime = time + autocvar_sv_mapchange_delay;
1571 intermission_exittime = -1;
1574 WriteByte (MSG_ALL, SVC_CDTRACK);
1575 WriteByte (MSG_ALL, 3);
1576 WriteByte (MSG_ALL, 3);
1577 // done in FixIntermission
1580 //pos = FindIntermission ();
1586 if(autocvar_sv_eventlog)
1587 GameLogEcho(":gameover");
1591 FOR_EACH_PLAYER(other) {
1592 FixIntermissionClient(other);
1594 bprint(other.netname, " ^7wins.\n");
1597 if(autocvar_g_campaign)
1598 CampaignPreIntermission();
1600 localcmd("\nsv_hook_gameend\n");
1607 Exit deathmatch games upon conditions
1610 void CheckRules_Player()
1612 if (gameover) // someone else quit the game already
1615 if(self.deadflag == DEAD_NO)
1616 self.play_time += frametime;
1618 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1619 // (div0: and that in CheckRules_World please)
1622 float checkrules_equality;
1623 float checkrules_suddendeathwarning;
1624 float checkrules_suddendeathend;
1625 float checkrules_overtimesadded; //how many overtimes have been already added
1627 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1628 float WINNING_YES = 1; // winner found
1629 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1630 float WINNING_STARTSUDDENDEATHOVERTIME = 3; // no winner, enter suddendeath overtime NOW
1632 float InitiateSuddenDeath()
1634 // Check first whether normal overtimes could be added before initiating suddendeath mode
1635 // - for this timelimit_overtime needs to be >0 of course
1636 // - also check the winning condition calculated in the previous frame and only add normal overtime
1637 // again, if at the point at which timelimit would be extended again, still no winner was found
1638 if ((checkrules_overtimesadded >= 0) && (checkrules_overtimesadded < autocvar_timelimit_overtimes) && autocvar_timelimit_overtime && !(g_race && !g_race_qualifying))
1640 return 1; // need to call InitiateOvertime later
1644 if(!checkrules_suddendeathend)
1646 checkrules_suddendeathend = time + 60 * autocvar_timelimit_suddendeath;
1647 if(g_race && !g_race_qualifying)
1648 race_StartCompleting();
1654 void InitiateOvertime() // ONLY call this if InitiateSuddenDeath returned true
1656 ++checkrules_overtimesadded;
1657 //add one more overtime by simply extending the timelimit
1659 tl = autocvar_timelimit;
1660 tl += autocvar_timelimit_overtime;
1661 cvar_set("timelimit", ftos(tl));
1662 string minutesPlural;
1663 if (autocvar_timelimit_overtime == 1)
1664 minutesPlural = " ^3minute";
1666 minutesPlural = " ^3minutes";
1670 "^3Now playing ^1OVERTIME^3!\n\n^3Added ^1",
1671 ftos(autocvar_timelimit_overtime),
1678 float GetWinningCode(float fraglimitreached, float equality)
1680 if(autocvar_g_campaign == 1)
1681 if(fraglimitreached)
1688 if(fraglimitreached)
1689 return WINNING_STARTSUDDENDEATHOVERTIME;
1691 return WINNING_NEVER;
1693 if(fraglimitreached)
1699 // set the .winning flag for exactly those players with a given field value
1700 void SetWinners(.float field, float value)
1703 FOR_EACH_PLAYER(head)
1704 head.winning = (head.field == value);
1707 // set the .winning flag for those players with a given field value
1708 void AddWinners(.float field, float value)
1711 FOR_EACH_PLAYER(head)
1712 if(head.field == value)
1716 // clear the .winning flags
1717 void ClearWinners(void)
1720 FOR_EACH_PLAYER(head)
1724 // Onslaught winning condition:
1725 // game terminates if only one team has a working generator (or none)
1726 float WinningCondition_Onslaught()
1729 local float t1, t2, t3, t4;
1731 WinningConditionHelper(); // set worldstatus
1736 // first check if the game has ended
1737 t1 = t2 = t3 = t4 = 0;
1738 head = find(world, classname, "onslaught_generator");
1741 if (head.health > 0)
1743 if (head.team == COLOR_TEAM1) t1 = 1;
1744 if (head.team == COLOR_TEAM2) t2 = 1;
1745 if (head.team == COLOR_TEAM3) t3 = 1;
1746 if (head.team == COLOR_TEAM4) t4 = 1;
1748 head = find(head, classname, "onslaught_generator");
1750 if (t1 + t2 + t3 + t4 < 2)
1752 // game over, only one team remains (or none)
1754 if (t1) SetWinners(team, COLOR_TEAM1);
1755 if (t2) SetWinners(team, COLOR_TEAM2);
1756 if (t3) SetWinners(team, COLOR_TEAM3);
1757 if (t4) SetWinners(team, COLOR_TEAM4);
1758 dprint("Have a winner, ending game.\n");
1762 // Two or more teams remain
1766 float LMS_NewPlayerLives()
1769 fl = autocvar_fraglimit;
1773 // first player has left the game for dying too much? Nobody else can get in.
1774 if(lms_lowest_lives < 1)
1777 if(!autocvar_g_lms_join_anytime)
1778 if(lms_lowest_lives < fl - autocvar_g_lms_last_join)
1781 return bound(1, lms_lowest_lives, fl);
1784 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1785 // they win. Otherwise the defending team wins once the timelimit passes.
1786 void assault_new_round();
1787 float WinningCondition_Assault()
1791 WinningConditionHelper(); // set worldstatus
1793 status = WINNING_NO;
1794 // as the timelimit has not yet passed just assume the defending team will win
1795 if(assault_attacker_team == COLOR_TEAM1)
1797 SetWinners(team, COLOR_TEAM2);
1801 SetWinners(team, COLOR_TEAM1);
1805 ent = find(world, classname, "target_assault_roundend");
1808 if(ent.winning) // round end has been triggered by attacking team
1810 bprint("ASSAULT: round completed...\n");
1811 SetWinners(team, assault_attacker_team);
1813 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
1815 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
1817 status = WINNING_YES;
1821 local entity oldself;
1824 assault_new_round();
1833 // LMS winning condition: game terminates if and only if there's at most one
1834 // one player who's living lives. Top two scores being equal cancels the time
1836 float WinningCondition_LMS()
1843 have_player = FALSE;
1844 have_players = FALSE;
1845 l = LMS_NewPlayerLives();
1847 head = find(world, classname, "player");
1850 head2 = find(head, classname, "player");
1852 have_players = TRUE;
1856 // we have at least one player
1859 // two or more active players - continue with the game
1863 // exactly one player?
1866 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1870 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1876 // and assign him his first place
1877 PlayerScore_Add(head, SP_LMS_RANK, 1);
1884 // nobody is playing at all...
1887 // wait for players...
1891 // SNAFU (maybe a draw game?)
1893 dprint("No players, ending game.\n");
1898 // When we get here, we have at least two players who are actually LIVING,
1899 // now check if the top two players have equal score.
1900 WinningConditionHelper();
1903 if(WinningConditionHelper_winner)
1904 WinningConditionHelper_winner.winning = TRUE;
1905 if(WinningConditionHelper_topscore == WinningConditionHelper_secondscore)
1906 return WINNING_NEVER;
1908 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1912 void ShuffleMaplist()
1914 cvar_set("g_maplist", shufflewords(autocvar_g_maplist));
1918 float WinningCondition_Scores(float limit, float leadlimit)
1922 // TODO make everything use THIS winning condition (except LMS)
1923 WinningConditionHelper();
1927 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1928 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1929 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1930 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1934 if(WinningConditionHelper_winner)
1935 WinningConditionHelper_winner.winning = 1;
1936 if(WinningConditionHelper_winnerteam >= 0)
1937 SetWinners(team, WinningConditionHelper_winnerteam);
1939 if(WinningConditionHelper_lowerisbetter)
1941 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1942 WinningConditionHelper_secondscore = -WinningConditionHelper_secondscore;
1946 if(WinningConditionHelper_zeroisworst)
1947 leadlimit = 0; // not supported in this mode
1949 if(g_dm || g_tdm || g_arena || g_ca || (g_race && !g_race_qualifying) || g_nexball)
1950 // these modes always score in increments of 1, thus this makes sense
1952 if(leaderfrags != WinningConditionHelper_topscore)
1954 leaderfrags = WinningConditionHelper_topscore;
1957 if (leaderfrags == limit - 1)
1958 Announce("1fragleft");
1959 else if (leaderfrags == limit - 2)
1960 Announce("2fragsleft");
1961 else if (leaderfrags == limit - 3)
1962 Announce("3fragsleft");
1966 limitreached = FALSE;
1968 if(WinningConditionHelper_topscore >= limit)
1969 limitreached = TRUE;
1972 float leadlimitreached;
1973 leadlimitreached = (WinningConditionHelper_topscore - WinningConditionHelper_secondscore >= leadlimit);
1974 if(autocvar_leadlimit_and_fraglimit)
1975 limitreached = (limitreached && leadlimitreached);
1977 limitreached = (limitreached || leadlimitreached);
1980 return GetWinningCode(
1981 WinningConditionHelper_topscore && limitreached,
1982 WinningConditionHelper_equality
1986 float WinningCondition_Race(float fraglimit)
1997 if(p.race_completed)
2002 wc = WinningCondition_Scores(fraglimit, 0);
2004 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
2005 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
2006 // do NOT support equality when the laps are all raced!
2007 return WINNING_STARTSUDDENDEATHOVERTIME;
2009 return WINNING_NEVER;
2013 void ReadyRestart();
2014 float WinningCondition_QualifyingThenRace(float limit)
2017 wc = WinningCondition_Scores(limit, 0);
2019 // NEVER initiate overtime
2020 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
2028 float WinningCondition_RanOutOfSpawns()
2032 if(have_team_spawns <= 0)
2035 if(!some_spawn_has_been_used)
2038 team1_score = team2_score = team3_score = team4_score = 0;
2040 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
2042 if(head.team == COLOR_TEAM1)
2044 else if(head.team == COLOR_TEAM2)
2046 else if(head.team == COLOR_TEAM3)
2048 else if(head.team == COLOR_TEAM4)
2052 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
2054 if(head.team == COLOR_TEAM1)
2056 else if(head.team == COLOR_TEAM2)
2058 else if(head.team == COLOR_TEAM3)
2060 else if(head.team == COLOR_TEAM4)
2065 if(team1_score + team2_score + team3_score + team4_score == 0)
2067 checkrules_equality = TRUE;
2070 else if(team1_score + team2_score + team3_score + team4_score == 1)
2073 if(team1_score) t = COLOR_TEAM1;
2074 if(team2_score) t = COLOR_TEAM2;
2075 if(team3_score) t = COLOR_TEAM3;
2076 if(team4_score) t = COLOR_TEAM4;
2077 CheckAllowedTeams(world);
2078 for(i = 0; i < MAX_TEAMSCORE; ++i)
2080 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
2081 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
2082 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
2083 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
2086 AddWinners(team, t);
2097 Exit deathmatch games upon conditions
2100 void CheckRules_World()
2112 MapVote_Think should now do that part
2113 if (intermission_running)
2114 if (time >= intermission_exittime + 60)
2116 if(!DoNextMapOverride())
2122 if (gameover) // someone else quit the game already
2124 if(player_count == 0) // Nobody there? Then let's go to the next map
2126 // this will actually check the player count in the next frame
2127 // again, but this shouldn't hurt
2131 timelimit = autocvar_timelimit * 60;
2132 fraglimit = autocvar_fraglimit;
2133 leadlimit = autocvar_leadlimit;
2135 if(inWarmupStage || time <= game_starttime) // NOTE: this is <= to prevent problems in the very tic where the game starts
2138 timelimit = 0; // timelimit is not made for warmup
2140 fraglimit = 0; // no fraglimit for now
2141 leadlimit = 0; // no leadlimit for now
2145 timelimit = 0; // ONS has its own overtime rule
2149 timelimit += game_starttime;
2151 else if (timelimit < 0)
2161 if(checkrules_suddendeathend)
2163 if(!checkrules_suddendeathwarning)
2165 checkrules_suddendeathwarning = TRUE;
2166 if(g_race && !g_race_qualifying)
2167 bcenterprint("^3Everyone, finish your lap! The race is over!");
2169 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
2174 if (timelimit && time >= timelimit)
2176 if(g_race && (g_race_qualifying == 2) && timelimit > 0)
2179 float playerswithlaps;
2182 totalplayers = playerswithlaps = readyplayers = 0;
2183 FOR_EACH_PLAYER(head)
2186 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
2192 // at least 2 of the players have completed a lap: start the RACE
2193 // otherwise, the players should end the qualifying on their own
2194 if(readyplayers || playerswithlaps >= 2)
2196 checkrules_suddendeathend = 0;
2197 ReadyRestart(); // go to race
2201 wantovertime |= InitiateSuddenDeath();
2204 wantovertime |= InitiateSuddenDeath();
2208 if (checkrules_suddendeathend && time >= checkrules_suddendeathend)
2214 float checkrules_status;
2215 checkrules_status = WinningCondition_RanOutOfSpawns();
2216 if(checkrules_status == WINNING_YES)
2218 bprint("Hey! Someone ran out of spawns!\n");
2220 else if(g_race && !g_race_qualifying && timelimit >= 0)
2222 checkrules_status = WinningCondition_Race(fraglimit);
2223 //print("WC_RACE yields ", ftos(checkrules_status), "\n");
2225 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
2227 checkrules_status = WinningCondition_QualifyingThenRace(fraglimit);
2228 //print("WC_QUALIFYING_THEN_RACE yields ", ftos(checkrules_status), "\n");
2232 checkrules_status = WinningCondition_Assault(); // TODO remove this?
2236 checkrules_status = WinningCondition_LMS();
2238 else if (g_onslaught)
2240 checkrules_status = WinningCondition_Onslaught(); // TODO remove this?
2244 checkrules_status = WinningCondition_Scores(fraglimit, leadlimit);
2245 //print("WC_SCORES yields ", ftos(checkrules_status), "\n");
2248 if(checkrules_status == WINNING_STARTSUDDENDEATHOVERTIME)
2250 checkrules_status = WINNING_NEVER;
2251 checkrules_overtimesadded = -1;
2252 wantovertime |= InitiateSuddenDeath();
2255 if(checkrules_status == WINNING_NEVER)
2256 // equality cases! Nobody wins if the overtime ends in a draw.
2261 if(checkrules_status == WINNING_NEVER)
2264 checkrules_status = WINNING_YES;
2267 if(checkrules_suddendeathend)
2268 if(checkrules_status != WINNING_NEVER || time >= checkrules_suddendeathend)
2269 checkrules_status = WINNING_YES;
2271 if(checkrules_status == WINNING_YES)
2273 //print("WINNING\n");
2278 float mapvote_nextthink;
2279 float mapvote_initialized;
2280 float mapvote_keeptwotime;
2281 float mapvote_timeout;
2282 string mapvote_message;
2283 #define MAPVOTE_SCREENSHOT_DIRS_COUNT 4
2284 string mapvote_screenshot_dirs[MAPVOTE_SCREENSHOT_DIRS_COUNT];
2285 float mapvote_screenshot_dirs_count;
2287 float mapvote_count;
2288 float mapvote_count_real;
2289 string mapvote_maps[MAPVOTE_COUNT];
2290 float mapvote_maps_screenshot_dir[MAPVOTE_COUNT];
2291 string mapvote_maps_pakfile[MAPVOTE_COUNT];
2292 float mapvote_maps_suggested[MAPVOTE_COUNT];
2293 string mapvote_suggestions[MAPVOTE_COUNT];
2294 float mapvote_suggestion_ptr;
2295 float mapvote_maxlen;
2296 float mapvote_voters;
2297 float mapvote_votes[MAPVOTE_COUNT];
2299 float mapvote_detail;
2300 float mapvote_abstain;
2303 void MapVote_ClearAllVotes()
2305 FOR_EACH_CLIENT(other)
2309 string MapVote_Suggest(string m)
2313 return "That's not how to use this command.";
2314 if(!autocvar_g_maplist_votable_suggestions)
2315 return "Suggestions are not accepted on this server.";
2316 if(mapvote_initialized)
2317 return "Can't suggest - voting is already in progress!";
2318 m = MapInfo_FixName(m);
2320 return "The map you suggested is not available on this server.";
2321 if(!autocvar_g_maplist_votable_suggestions_override_mostrecent)
2323 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
2325 if(!MapInfo_CheckMap(m))
2326 return "The map you suggested does not support the current game mode.";
2327 for(i = 0; i < mapvote_suggestion_ptr; ++i)
2328 if(mapvote_suggestions[i] == m)
2329 return "This map was already suggested.";
2330 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
2332 i = floor(random() * mapvote_suggestion_ptr);
2336 i = mapvote_suggestion_ptr;
2337 mapvote_suggestion_ptr += 1;
2339 if(mapvote_suggestions[i] != "")
2340 strunzone(mapvote_suggestions[i]);
2341 mapvote_suggestions[i] = strzone(m);
2342 if(autocvar_sv_eventlog)
2343 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
2344 return strcat("Suggestion of ", m, " accepted.");
2347 void MapVote_AddVotable(string nextMap, float isSuggestion)
2350 string pakfile, mapfile;
2354 for(j = 0; j < mapvote_count; ++j)
2355 if(mapvote_maps[j] == nextMap)
2357 if(strlen(nextMap) > mapvote_maxlen)
2358 mapvote_maxlen = strlen(nextMap);
2359 mapvote_maps[mapvote_count] = strzone(nextMap);
2360 mapvote_maps_suggested[mapvote_count] = isSuggestion;
2362 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2364 mapfile = strcat(mapvote_screenshot_dirs[i], "/", mapvote_maps[i]);
2365 pakfile = whichpack(strcat(mapfile, ".tga"));
2367 pakfile = whichpack(strcat(mapfile, ".jpg"));
2369 pakfile = whichpack(strcat(mapfile, ".png"));
2373 if(i >= mapvote_screenshot_dirs_count)
2374 i = 0; // FIXME maybe network this error case, as that means there is no mapshot on the server?
2375 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
2376 pakfile = substring(pakfile, o, -1);
2378 mapvote_maps_screenshot_dir[mapvote_count] = i;
2379 mapvote_maps_pakfile[mapvote_count] = strzone(pakfile);
2384 void MapVote_Spawn();
2390 MapVote_ClearAllVotes();
2393 mapvote_detail = !autocvar_g_maplist_votable_nodetail;
2394 mapvote_abstain = autocvar_g_maplist_votable_abstain;
2397 nmax = min(MAPVOTE_COUNT - 1, autocvar_g_maplist_votable);
2399 nmax = min(MAPVOTE_COUNT, autocvar_g_maplist_votable);
2400 smax = min3(nmax, autocvar_g_maplist_votable_suggestions, mapvote_suggestion_ptr);
2402 // we need this for AddVotable, as that cycles through the screenshot dirs
2403 mapvote_screenshot_dirs_count = tokenize_console(autocvar_g_maplist_votable_screenshot_dir);
2404 if(mapvote_screenshot_dirs_count == 0)
2405 mapvote_screenshot_dirs_count = tokenize_console("maps levelshots");
2406 mapvote_screenshot_dirs_count = min(mapvote_screenshot_dirs_count, MAPVOTE_SCREENSHOT_DIRS_COUNT);
2407 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2408 mapvote_screenshot_dirs[i] = strzone(argv(i));
2410 if(mapvote_suggestion_ptr)
2411 for(i = 0; i < 100 && mapvote_count < smax; ++i)
2412 MapVote_AddVotable(mapvote_suggestions[floor(random() * mapvote_suggestion_ptr)], TRUE);
2414 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2415 MapVote_AddVotable(GetNextMap(), FALSE);
2417 if(mapvote_count == 0)
2419 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
2420 cvar_set("g_maplist", MapInfo_ListAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
2421 if(autocvar_g_maplist_shuffle)
2423 localcmd("\nmenu_cmd sync\n");
2424 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2425 MapVote_AddVotable(GetNextMap(), FALSE);
2428 mapvote_count_real = mapvote_count;
2430 MapVote_AddVotable("don't care", 0);
2432 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
2434 mapvote_keeptwotime = time + autocvar_g_maplist_votable_keeptwotime;
2435 mapvote_timeout = time + autocvar_g_maplist_votable_timeout;
2436 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
2437 mapvote_keeptwotime = 0;
2438 mapvote_message = "Choose a map and press its key!";
2443 void MapVote_SendPicture(float id)
2446 WriteByte(MSG_ONE, SVC_TEMPENTITY);
2447 WriteByte(MSG_ONE, TE_CSQC_PICTURE);
2448 WriteByte(MSG_ONE, id);
2449 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dirs[mapvote_maps_screenshot_dir[id]], "/", mapvote_maps[id]), 3072);
2452 float GameCommand_MapVote(string cmd)
2454 if(!intermission_running)
2457 if(cmd == "mv_getpic")
2459 MapVote_SendPicture(stof(argv(1)));
2466 float MapVote_GetMapMask()
2468 float mask, i, power;
2470 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
2471 if(mapvote_maps[i] != "")
2477 float MapVote_SendEntity(entity to, float sf)
2482 sf &~= 2; // if we send 1, we don't need to also send 2
2484 WriteByte(MSG_ENTITY, ENT_CLIENT_MAPVOTE);
2485 WriteByte(MSG_ENTITY, sf);
2489 // flag 1 == initialization
2490 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2491 WriteString(MSG_ENTITY, mapvote_screenshot_dirs[i]);
2492 WriteString(MSG_ENTITY, "");
2493 WriteByte(MSG_ENTITY, mapvote_count);
2494 WriteByte(MSG_ENTITY, mapvote_abstain);
2495 WriteByte(MSG_ENTITY, mapvote_detail);
2496 WriteCoord(MSG_ENTITY, mapvote_timeout);
2497 if(mapvote_count <= 8)
2498 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2500 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2501 for(i = 0; i < mapvote_count; ++i)
2502 if(mapvote_maps[i] != "")
2504 if(mapvote_abstain && i == mapvote_count - 1)
2506 WriteString(MSG_ENTITY, ""); // abstain needs no text
2507 WriteString(MSG_ENTITY, ""); // abstain needs no pack
2508 WriteByte(MSG_ENTITY, 0); // abstain needs no screenshot dir
2512 WriteString(MSG_ENTITY, mapvote_maps[i]);
2513 WriteString(MSG_ENTITY, mapvote_maps_pakfile[i]);
2514 WriteByte(MSG_ENTITY, mapvote_maps_screenshot_dir[i]);
2521 // flag 2 == update of mask
2522 if(mapvote_count <= 8)
2523 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2525 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2531 for(i = 0; i < mapvote_count; ++i)
2532 if(mapvote_maps[i] != "")
2533 WriteByte(MSG_ENTITY, mapvote_votes[i]);
2535 WriteByte(MSG_ENTITY, to.mapvote);
2541 void MapVote_Spawn()
2543 Net_LinkEntity(mapvote_ent = spawn(), FALSE, 0, MapVote_SendEntity);
2546 void MapVote_TouchMask()
2548 mapvote_ent.SendFlags |= 2;
2551 void MapVote_TouchVotes(entity voter)
2553 mapvote_ent.SendFlags |= 4;
2556 float MapVote_Finished(float mappos)
2562 if(autocvar_sv_eventlog)
2564 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2565 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
2566 didntvote = mapvote_voters;
2567 for(i = 0; i < mapvote_count; ++i)
2568 if(mapvote_maps[i] != "")
2570 didntvote -= mapvote_votes[i];
2573 result = strcat(result, ":", mapvote_maps[i]);
2574 result = strcat(result, ":", ftos(mapvote_votes[i]));
2577 result = strcat(result, ":didn't vote:", ftos(didntvote));
2579 GameLogEcho(result);
2580 if(mapvote_maps_suggested[mappos])
2581 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
2584 FOR_EACH_REALCLIENT(other)
2585 FixClientCvars(other);
2587 Map_Goto_SetStr(mapvote_maps[mappos]);
2589 alreadychangedlevel = TRUE;
2592 void MapVote_CheckRules_1()
2596 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2598 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2599 mapvote_votes[i] = 0;
2603 FOR_EACH_REALCLIENT(other)
2608 i = other.mapvote - 1;
2609 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2610 mapvote_votes[i] = mapvote_votes[i] + 1;
2615 float MapVote_CheckRules_2()
2618 float firstPlace, secondPlace;
2619 float firstPlaceVotes, secondPlaceVotes;
2620 float mapvote_voters_real;
2623 if(mapvote_count_real == 1)
2624 return MapVote_Finished(0);
2626 mapvote_voters_real = mapvote_voters;
2628 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2630 RandomSelection_Init();
2631 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2632 RandomSelection_Add(world, i, string_null, 1, mapvote_votes[i]);
2633 firstPlace = RandomSelection_chosen_float;
2634 firstPlaceVotes = RandomSelection_best_priority;
2635 //dprint("First place: ", ftos(firstPlace), "\n");
2636 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2638 RandomSelection_Init();
2639 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2641 RandomSelection_Add(world, i, string_null, 1, mapvote_votes[i]);
2642 secondPlace = RandomSelection_chosen_float;
2643 secondPlaceVotes = RandomSelection_best_priority;
2644 //dprint("Second place: ", ftos(secondPlace), "\n");
2645 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2647 if(firstPlace == -1)
2648 error("No first place in map vote... WTF?");
2650 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2651 return MapVote_Finished(firstPlace);
2653 if(mapvote_keeptwotime)
2654 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2657 MapVote_TouchMask();
2658 mapvote_message = "Now decide between the TOP TWO!";
2659 mapvote_keeptwotime = 0;
2660 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2661 result = strcat(result, ":", ftos(firstPlaceVotes));
2662 result = strcat(result, ":", mapvote_maps[secondPlace]);
2663 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2664 didntvote = mapvote_voters;
2665 for(i = 0; i < mapvote_count; ++i)
2666 if(mapvote_maps[i] != "")
2668 didntvote -= mapvote_votes[i];
2670 if(i != secondPlace)
2672 result = strcat(result, ":", mapvote_maps[i]);
2673 result = strcat(result, ":", ftos(mapvote_votes[i]));
2674 if(i < mapvote_count_real)
2676 strunzone(mapvote_maps[i]);
2677 mapvote_maps[i] = "";
2678 strunzone(mapvote_maps_pakfile[i]);
2679 mapvote_maps_pakfile[i] = "";
2683 result = strcat(result, ":didn't vote:", ftos(didntvote));
2684 if(autocvar_sv_eventlog)
2685 GameLogEcho(result);
2695 keeptwo = mapvote_keeptwotime;
2696 MapVote_CheckRules_1(); // count
2697 if(MapVote_CheckRules_2()) // decide
2701 FOR_EACH_REALCLIENT(other)
2703 // hide scoreboard again
2704 if(other.health != 2342)
2706 other.health = 2342;
2708 if(clienttype(other) == CLIENTTYPE_REAL)
2711 WriteByte(MSG_ONE, SVC_FINALE);
2712 WriteString(MSG_ONE, "");
2716 // clear possibly invalid votes
2717 if(mapvote_maps[other.mapvote - 1] == "")
2719 // use impulses as new vote
2720 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2721 if(mapvote_maps[other.impulse - 1] != "")
2723 other.mapvote = other.impulse;
2724 MapVote_TouchVotes(other);
2732 MapVote_CheckRules_1(); // just count
2734 void MapVote_Start()
2739 // wait for stats to be sent first
2740 if(!playerstats_waitforme)
2743 MapInfo_Enumerate();
2744 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
2747 void MapVote_Think()
2752 if(alreadychangedlevel)
2755 if(time < mapvote_nextthink)
2759 mapvote_nextthink = time + 0.5;
2761 if(!mapvote_initialized)
2763 if(autocvar_rescan_pending == 1)
2765 cvar_set("rescan_pending", "2");
2766 localcmd("fs_rescan\nrescan_pending 3\n");
2769 else if(autocvar_rescan_pending == 2)
2773 else if(autocvar_rescan_pending == 3)
2775 // now build missing mapinfo files
2776 if(!MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
2779 // we're done, start the timer
2780 cvar_set("rescan_pending", "0");
2783 mapvote_initialized = TRUE;
2784 if(DoNextMapOverride())
2786 if(!autocvar_g_maplist_votable || player_count <= 0)
2797 string GotoMap(string m)
2799 if(!MapInfo_CheckMap(m))
2800 return "The map you chose is not available on this server.";
2801 cvar_set("nextmap", m);
2802 cvar_set("timelimit", "-1");
2803 if(mapvote_initialized || alreadychangedlevel)
2805 if(DoNextMapOverride())
2806 return "Map switch initiated.";
2808 return "Hm... no. For some reason I like THIS map more.";
2811 return "Map switch will happen after scoreboard.";
2818 FOR_EACH_REALCLIENT(self)
2820 if(self.classname == "spectator")
2822 if(self.enemy.typehitsound)
2823 play2(self, "misc/typehit.wav");
2824 else if(self.enemy.hitsound && self.cvar_cl_hitsound)
2825 play2(self, "misc/hit.wav");
2829 if(self.typehitsound)
2830 play2(self, "misc/typehit.wav");
2831 else if(self.hitsound && self.cvar_cl_hitsound)
2832 play2(self, "misc/hit.wav");
2835 altime = time + frametime * (1 + autocvar_g_antilag_nudge);
2836 // add 1 frametime because after this, engine SV_Physics
2837 // increases time by a frametime and then networks the frame
2838 // add another frametime because client shows everything with
2839 // 1 frame of lag (cl_nolerp 0). The last +1 however should not be
2841 FOR_EACH_CLIENT(self)
2843 self.hitsound = FALSE;
2844 self.typehitsound = FALSE;
2845 antilag_record(self, altime);
2852 * returns TRUE if redirecting
2854 float redirection_timeout;
2855 float redirection_nextthink;
2856 float RedirectionThink()
2858 float clients_found;
2860 if(redirection_target == "")
2863 if(!redirection_timeout)
2865 cvar_set("sv_public", "-2");
2866 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2867 if(redirection_target == "self")
2868 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2870 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2873 if(time < redirection_nextthink)
2876 redirection_nextthink = time + 1;
2879 FOR_EACH_REALCLIENT(self)
2881 print("Redirecting: sending connect command to ", self.netname, "\n");
2882 if(redirection_target == "self")
2883 stuffcmd(self, "\ndisconnect; reconnect\n");
2885 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2889 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2891 if(time > redirection_timeout || clients_found == 0)
2892 localcmd("\nwait; wait; wait; quit\n");
2897 void TargetMusic_RestoreGame();
2900 // Loaded from a save game
2901 // some things then break, so let's work around them...
2903 // Progs DB (capture records)
2904 ServerProgsDB = db_load("server.db");
2908 MapInfo_Enumerate();
2909 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
2912 TargetMusic_RestoreGame();
2919 if(gameover > 1) // shutting down already?
2922 gameover = 2; // 2 = server shutting down
2924 if(world_initialized > 0)
2926 world_initialized = 0;
2927 print("Saving persistent data...\n");
2931 PlayerStats_AddGlobalInfo(e);
2932 PlayerStats_Shutdown();
2934 if(!cheatcount_total)
2936 if(autocvar_sv_db_saveasdump)
2937 db_dump(ServerProgsDB, "server.db");
2939 db_save(ServerProgsDB, "server.db");
2941 if(autocvar_developer)
2943 if(autocvar_sv_db_saveasdump)
2944 db_dump(TemporaryDB, "server-temp.db");
2946 db_save(TemporaryDB, "server-temp.db");
2948 CheatShutdown(); // must be after cheatcount check
2949 db_close(ServerProgsDB);
2950 db_close(TemporaryDB);
2952 // tell the bot system the game is ending now
2955 WeaponStats_Shutdown();
2958 else if(world_initialized == 0)
2960 print("NOTE: crashed before even initializing the world, not saving persistent data\n");