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_keyhunt");
329 BADCVAR("g_keyhunt_teams");
330 BADCVAR("g_onslaught");
333 BADCVAR("g_runematch");
335 BADCVAR("g_nexball");
336 BADCVAR("g_keepaway");
341 BADCVAR("g_maplist");
342 BADCVAR("g_maplist_mostrecent");
346 d = cvar_defstring(k);
352 cvar_changes = strcat(cvar_changes, k, " \"", v, "\" // \"", d, "\"\n");
353 if(strlen(cvar_changes) > 16384)
355 cvar_changes = "// too many settings have been changed to show them here\n";
360 // now check if the changes are actually gameplay relevant
362 // does nothing visible
363 BADCVAR("captureleadlimit_override");
364 BADCVAR("g_arena_point_leadlimit");
365 BADCVAR("g_ca_point_leadlimit");
366 BADCVAR("g_ctf_capture_leadlimit");
367 BADCVAR("g_domination_point_leadlimit");
368 BADCVAR("g_keyhunt_point_leadlimit");
369 BADCVAR("g_nexball_goalleadlimit");
370 BADCVAR("g_runematch_point_leadlimit");
371 BADCVAR("leadlimit_and_fraglimit");
372 BADCVAR("leadlimit_override");
373 BADCVAR("sv_checkforpacketsduringsleep");
375 BADCVAR("sv_timeout");
376 BADPREFIX("crypto_");
377 BADPREFIX("g_chat_");
380 BADPREFIX("sv_fragmessage_");
381 BADPREFIX("sv_vote_");
382 BADPREFIX("timelimit_");
384 // allowed changes to server admins (please sync this to server.cfg)
388 // :%s,//\([^ ]*\).*,BADCVAR("\1");,
390 // yes, this does contain some redundant stuff, don't really care
391 BADCVAR("bot_number");
392 BADCVAR("bot_prefix");
393 BADCVAR("bot_suffix");
394 BADCVAR("capturelimit_override");
395 BADCVAR("fraglimit_override");
397 BADCVAR("g_antilag");
398 BADCVAR("g_balance_teams");
399 BADCVAR("g_balance_teams_force");
400 BADCVAR("g_ban_sync_trusted_servers");
401 BADCVAR("g_ban_sync_uri");
402 BADCVAR("g_ctf_capture_limit");
403 BADCVAR("g_ctf_ignore_frags");
404 BADCVAR("g_ctf_win_mode");
405 BADCVAR("g_domination_point_limit");
406 BADCVAR("g_fullbrightitems");
407 BADCVAR("g_fullbrightplayers");
408 BADCVAR("g_keyhunt_point_limit");
409 BADCVAR("g_keyhunt_teams_override");
410 BADCVAR("g_lms_lives_override");
411 BADCVAR("g_maplist");
412 BADCVAR("g_maplist_check_waypoints");
413 BADCVAR("g_maplist_mostrecent_count");
414 BADCVAR("g_maplist_shuffle");
415 BADCVAR("g_maplist_votable");
416 BADCVAR("g_maplist_votable_abstain");
417 BADCVAR("g_maplist_votable_nodetail");
418 BADCVAR("g_maplist_votable_suggestions");
419 BADCVAR("g_minstagib");
420 BADCVAR("g_nexball_goallimit");
421 BADCVAR("g_runematch_point_limit");
422 BADCVAR("g_start_delay");
423 BADCVAR("g_weapon_stay"); BADPRESUFFIX("g_", "_weapon_stay");
426 BADCVAR("maxplayers");
427 BADCVAR("minplayers");
428 BADCVAR("net_address");
430 BADCVAR("rcon_password");
431 BADCVAR("rcon_restricted_commands");
432 BADCVAR("rcon_restricted_password");
434 BADCVAR("sv_adminnick");
435 BADCVAR("sv_autoscreenshot");
436 BADCVAR("sv_curl_defaulturl");
437 BADCVAR("sv_defaultcharacter");
438 BADCVAR("sv_defaultplayercolors");
439 BADCVAR("sv_defaultplayermodel");
440 BADCVAR("sv_defaultplayerskin");
441 BADCVAR("sv_maxidle");
442 BADCVAR("sv_maxrate");
444 BADCVAR("sv_public");
445 BADCVAR("sv_ready_restart");
446 BADCVAR("sv_status_privacy");
447 BADCVAR("sv_vote_call");
448 BADCVAR("sv_vote_commands");
449 BADCVAR("sv_vote_majority_factor");
450 BADCVAR("sv_vote_master");
451 BADCVAR("sv_vote_master_commands");
452 BADCVAR("sv_vote_master_password");
453 BADCVAR("sv_vote_simple_majority_factor");
454 BADCVAR("timelimit_override");
455 BADPREFIX("g_warmup");
457 if(autocvar_g_minstagib)
459 BADCVAR("g_grappling_hook");
460 BADCVAR("g_jetpack");
467 cvar_purechanges = strcat(cvar_purechanges, k, " \"", v, "\" // \"", d, "\"\n");
468 if(strlen(cvar_purechanges) > 16384)
470 cvar_purechanges = "// too many settings have been changed to show them here\n";
474 ++cvar_purechanges_count;
475 // WARNING: this variable is used for the server list
476 // NEVER dare to skip this code!
477 // Hacks to intentionally appearing as "pure server" even though you DO have
478 // modified settings may be punished by removal from the server list.
479 // You can do to the variables cvar_changes and cvar_purechanges all you want,
483 if(cvar_changes == "")
484 cvar_changes = "// this server runs at default server settings\n";
486 cvar_changes = strcat("// this server runs at modified server settings:\n", cvar_changes);
487 cvar_changes = strzone(cvar_changes);
488 if(cvar_purechanges == "")
489 cvar_purechanges = "// this server runs at default gameplay settings\n";
491 cvar_purechanges = strcat("// this server runs at modified gameplay settings:\n", cvar_purechanges);
492 cvar_purechanges = strzone(cvar_purechanges);
495 void detect_maptype()
504 o_x += random() * (world.maxs_x - world.mins_x);
505 o_y += random() * (world.maxs_y - world.mins_y);
506 o_z += random() * (world.maxs_z - world.mins_z);
508 tracebox(o, PL_MIN, PL_MAX, o - '0 0 32768', MOVE_WORLDONLY, world);
509 if(trace_fraction == 1)
514 for(i = 0; i < 64; i += 4)
516 tracebox(o, '-1 -1 -1' * i, '1 1 1' * i, o - '0 0 32768', MOVE_WORLDONLY, world);
517 if(trace_fraction == 1)
519 print(ftos(i), " -> ", vtos(trace_endpos), "\n");
528 float RandomSeed_Send(entity to, float sf)
530 WriteByte(MSG_ENTITY, ENT_CLIENT_RANDOMSEED);
531 WriteShort(MSG_ENTITY, self.cnt);
534 void RandomSeed_Think()
536 self.cnt = bound(0, floor(random() * 65536), 65535);
537 self.nextthink = time + 5;
541 void RandomSeed_Spawn()
543 randomseed = spawn();
544 randomseed.think = RandomSeed_Think;
545 Net_LinkEntity(randomseed, FALSE, 0, RandomSeed_Send);
550 self.think(); // sets random seed and nextthink
554 void spawnfunc___init_dedicated_server(void)
556 // handler for _init/_init map (only for dedicated server initialization)
558 world_initialized = -1; // don't complain
560 cvar_string = cvar_string_normal;
561 cvar_set = cvar_set_normal;
563 remove = remove_unsafely;
567 e.think = GotoFirstMap;
568 e.nextthink = time; // this is usually 1 at this point
571 e.classname = "info_player_deathmatch"; // safeguard against player joining
573 self.classname = "worldspawn"; // safeguard against various stuff ;)
576 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
579 void Map_MarkAsRecent(string m);
580 float world_already_spawned;
581 void RegisterWeapons();
583 void ClientInit_Spawn();
584 void WeaponStats_Init();
585 void WeaponStats_Shutdown();
586 void spawnfunc_worldspawn (void)
588 float fd, l, i, j, n;
592 cvar_string = cvar_string_normal;
593 cvar_set = cvar_set_normal;
595 if(world_already_spawned)
596 error("world already spawned - you may have EXACTLY ONE worldspawn!");
597 world_already_spawned = TRUE;
599 remove = remove_safely; // during spawning, watch what you remove!
601 check_unacceptable_compiler_bugs();
603 cvar_changes_init(); // do this very early now so it REALLY matches the server config
605 compressShortVector_init();
607 allowed_to_spawn = TRUE;
610 head = nextent(world);
615 head = nextent(head);
618 // needs to be done so early as they would still spawn
621 ServerProgsDB = db_load("server.db");
623 TemporaryDB = db_create();
628 // 1 FLICKER (first variety)
629 lightstyle(1, "mmnmmommommnonmmonqnmmo");
631 // 2 SLOW STRONG PULSE
632 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
634 // 3 CANDLE (first variety)
635 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
638 lightstyle(4, "mamamamamama");
641 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
643 // 6 FLICKER (second variety)
644 lightstyle(6, "nmonqnmomnmomomno");
646 // 7 CANDLE (second variety)
647 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
649 // 8 CANDLE (third variety)
650 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
652 // 9 SLOW STROBE (fourth variety)
653 lightstyle(9, "aaaaaaaazzzzzzzz");
655 // 10 FLUORESCENT FLICKER
656 lightstyle(10, "mmamammmmammamamaaamammma");
658 // 11 SLOW PULSE NOT FADE TO BLACK
659 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
661 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
666 if(autocvar_g_campaign)
669 Map_MarkAsRecent(mapname);
671 precache_model ("null"); // we need this one before InitGameplayMode
679 bot_waypoints_for_items = autocvar_g_waypoints_for_items;
680 if(bot_waypoints_for_items == 1)
681 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
682 bot_waypoints_for_items = 0;
684 // for setting by mapinfo
685 q3acompat_machineshotgunswap = autocvar_sv_q3acompat_machineshotgunswap;
686 cvar_set("sv_q3acompat_machineshotgunswap", "0");
690 WaypointSprite_Init();
695 GameLogInit(); // prepare everything
696 if(autocvar_sv_eventlog)
698 s = strcat(ftos(autocvar_sv_eventlog_files_counter), ".");
699 s = strcat(s, ftos(random()));
700 matchid = strzone(s);
702 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
703 s = ":gameinfo:mutators:LIST";
706 MUTATOR_CALLHOOK(BuildMutatorsString);
709 // simple, probably not good in the mutator system
710 if(autocvar_g_grappling_hook)
711 s = strcat(s, ":grappling_hook");
713 // initialiation stuff, not good in the mutator system
714 if(!autocvar_g_use_ammunition)
715 s = strcat(s, ":no_use_ammunition");
717 // initialiation stuff, not good in the mutator system
718 if(!autocvar_g_pickup_items)
719 s = strcat(s, ":no_pickup_items");
721 // initialiation stuff, not good in the mutator system
722 if(autocvar_g_weaponarena != "0")
723 s = strcat(s, ":", autocvar_g_weaponarena, " arena");
725 // TODO to mutator system
726 if(autocvar_g_norecoil)
727 s = strcat(s, ":norecoil");
729 // TODO to mutator system
730 if(autocvar_g_midair)
731 s = strcat(s, ":midair");
733 // TODO to mutator system
734 if(autocvar_g_minstagib)
735 s = strcat(s, ":minstagib");
738 GameLogEcho(":gameinfo:end");
741 matchid = strzone(ftos(random()));
743 cvar_set("nextmap", "");
747 if(autocvar_g_campaign)
755 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
757 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
759 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
762 while((s = fgets(fd)))
764 l = tokenize_console(s);
769 print("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
770 print(" cdtrack ", argv(2), "\n");
772 else if(argv(0) == "fog")
774 print("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
775 print(" \"fog\" \"", s, "\"\n");
777 else if(argv(0) == "set")
779 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
780 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
782 else if(argv(0) != "//")
784 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
785 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
794 addstat(STAT_WEAPONS, AS_INT, weapons);
795 addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
796 addstat(STAT_GAMESTARTTIME, AS_FLOAT, stat_game_starttime);
797 addstat(STAT_ALLOW_OLDNEXBEAM, AS_INT, stat_allow_oldnexbeam);
800 addstat(STAT_STRENGTH_FINISHED, AS_FLOAT, strength_finished);
801 addstat(STAT_INVINCIBLE_FINISHED, AS_FLOAT, invincible_finished);
802 addstat(STAT_PRESSED_KEYS, AS_FLOAT, pressedkeys);
803 addstat(STAT_FUEL, AS_INT, ammo_fuel);
804 addstat(STAT_SHOTORG, AS_INT, stat_shotorg);
805 addstat(STAT_LEADLIMIT, AS_FLOAT, stat_leadlimit);
806 addstat(STAT_BULLETS_LOADED, AS_INT, campingrifle_bulletcounter);
807 addstat(STAT_LAST_PICKUP, AS_FLOAT, last_pickup);
809 addstat(STAT_NEX_CHARGE, AS_FLOAT, nex_charge);
810 addstat(STAT_NEX_CHARGEPOOL, AS_FLOAT, nex_chargepool_ammo);
812 if(g_ca || g_freezetag)
814 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
815 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
816 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
817 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
821 addstat(STAT_FROZEN, AS_INT, freezetag_frozen);
822 addstat(STAT_REVIVE_PROGRESS, AS_FLOAT, freezetag_revive_progress);
825 // g_movementspeed hack
826 addstat(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW, AS_FLOAT, stat_sv_airspeedlimit_nonqw);
827 addstat(STAT_MOVEVARS_MAXSPEED, AS_FLOAT, stat_sv_maxspeed);
828 addstat(STAT_MOVEVARS_AIRACCEL_QW, AS_FLOAT, stat_sv_airaccel_qw);
829 addstat(STAT_MOVEVARS_AIRSTRAFEACCEL_QW, AS_FLOAT, stat_sv_airstrafeaccel_qw);
831 next_pingtime = time + 5;
835 lsmaps_reply = "^7Maps available: ";
836 lsnewmaps_reply = "^7Maps without a record set: ";
837 for(i = 0, j = 0; i < MapInfo_count; ++i)
839 if(MapInfo_Get_ByID(i))
840 if not(MapInfo_Map_flags & (MAPINFO_FLAG_HIDDEN | MAPINFO_FLAG_FORBIDDEN))
847 lsmaps_reply = strcat(lsmaps_reply, col, MapInfo_Map_bspname, " ");
848 if(g_race && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "time"))))
849 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
850 else if(g_cts && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "time"))))
851 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
854 lsmaps_reply = strzone(strcat(lsmaps_reply, "\n"));
855 if (!g_race && !g_cts)
856 lsnewmaps_reply = "Need to be playing race or CTS for lsnewmaps to work.";
857 lsnewmaps_reply = strzone(strcat(lsnewmaps_reply, "\n"));
859 maplist_reply = "^7Maps in list: ";
860 n = tokenize_console(autocvar_g_maplist);
861 for(i = 0, j = 0; i < n; ++i)
863 if(MapInfo_CheckMap(argv(i)))
869 maplist_reply = strcat(maplist_reply, col, argv(i), " ");
873 maplist_reply = strzone(strcat(maplist_reply, "\n"));
874 MapInfo_ClearTemps();
876 for(i = 0; i < 10; ++i)
878 records_reply[i] = strzone(getrecords(i));
881 ladder_reply = strzone(getladder());
883 rankings_reply = strzone(getrankings());
887 PingPLReport_Spawn();
891 localcmd("\n_sv_hook_gamestart ", GetGametype(), "\n");
893 // fill sv_curl_serverpackages from .serverpackage files
894 if(autocvar_sv_curl_serverpackages_auto)
896 fd = search_begin("*.serverpackage", TRUE, FALSE);
900 j = search_getsize(fd);
901 for(i = 0; i < j; ++i)
902 s = strcat(s, " ", search_getfilename(fd, i));
905 cvar_set("sv_curl_serverpackages", substring(s, 1, -1));
910 world_initialized = 1;
913 void spawnfunc_light (void)
915 //makestatic (self); // Who the f___ did that?
919 float TryFile( string pFilename )
922 dprint("TryFile(\"", pFilename, "\")\n");
923 lHandle = fopen( pFilename, FILE_READ );
924 if( lHandle != -1 ) {
934 return GametypeNameFromType(game);
937 string getmapname_stored;
943 float Map_Count, Map_Current;
944 string Map_Current_Name;
946 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
947 float GetMaplistPosition()
953 idx = autocvar_g_maplist_index;
960 for(pos = 0; pos < Map_Count; ++pos)
964 // resume normal maplist rotation if current map is not in g_maplist
968 float MapHasRightSize(string map)
971 if(currentbots || autocvar_bot_number || player_count < autocvar_minplayers)
972 if(autocvar_g_maplist_check_waypoints)
974 dprint("checkwp "); dprint(map);
975 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
978 dprint(": no waypoints\n");
981 dprint(": has waypoints\n");
985 // open map size restriction file
986 dprint("opensize "); dprint(map);
987 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
990 float mapmin, mapmax;
992 mapmin = stof(fgets(fh));
993 mapmax = stof(fgets(fh));
995 if(player_count < mapmin)
997 dprint("not enough\n");
1000 if(player_count > mapmax)
1002 dprint("too many\n");
1005 dprint("right size\n");
1008 dprint(": not found\n");
1012 string Map_Filename(float position)
1014 return strcat("maps/", argv(position), ".bsp");
1017 string strwords(string s, float w)
1020 for(endpos = 0; w && endpos >= 0; --w)
1021 endpos = strstrofs(s, " ", endpos + 1);
1025 return substring(s, 0, endpos);
1028 float strhasword(string s, string w)
1030 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
1033 void Map_MarkAsRecent(string m)
1035 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", autocvar_g_maplist_mostrecent), max(0, autocvar_g_maplist_mostrecent_count)));
1038 float Map_IsRecent(string m)
1040 return strhasword(autocvar_g_maplist_mostrecent, m);
1043 float Map_Check(float position, float pass)
1047 map_next = argv(position);
1050 if(Map_IsRecent(map_next))
1053 filename = Map_Filename(position);
1054 if(MapInfo_CheckMap(map_next))
1058 if(MapHasRightSize(map_next))
1063 dprint( "Couldn't select '", filename, "'..\n" );
1068 void Map_Goto_SetStr(string nextmapname)
1070 if(getmapname_stored != "")
1071 strunzone(getmapname_stored);
1072 if(nextmapname == "")
1073 getmapname_stored = "";
1075 getmapname_stored = strzone(nextmapname);
1078 void Map_Goto_SetFloat(float position)
1080 cvar_set("g_maplist_index", ftos(position));
1081 Map_Goto_SetStr(argv(position));
1086 // settings persist, except...
1087 localcmd("\nsettemp_restore\n");
1093 MapInfo_LoadMap(getmapname_stored);
1096 // return codes of map selectors:
1097 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
1098 // -2 = permanent failure
1099 float() MaplistMethod_Iterate = // usual method
1103 for(pass = 1; pass <= 2; ++pass)
1105 for(i = 1; i < Map_Count; ++i)
1108 mapindex = mod(i + Map_Current, Map_Count);
1109 if(Map_Check(mapindex, pass))
1116 float() MaplistMethod_Repeat = // fallback method
1118 if(Map_Check(Map_Current, 2))
1123 float() MaplistMethod_Random = // random map selection
1129 for(i = 0; i <= imax; ++i)
1132 mapindex = mod(Map_Current + floor(random() * (Map_Count - 1) + 1), Map_Count); // any OTHER map
1133 if(Map_Check(mapindex, 1))
1139 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
1140 // the exponent sets a bias on the map selection:
1141 // the higher the exponent, the less likely "shortly repeated" same maps are
1143 float i, j, imax, insertpos;
1147 for(i = 0; i <= imax; ++i)
1151 // now reinsert this at another position
1152 insertpos = pow(random(), 1 / exponent); // ]0, 1]
1153 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
1154 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
1155 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
1157 // insert the current map there
1159 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
1160 newlist = strcat(newlist, " ", argv(j));
1161 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
1162 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
1163 newlist = strcat(newlist, " ", argv(j));
1164 newlist = substring(newlist, 1, strlen(newlist) - 1);
1165 cvar_set("g_maplist", newlist);
1166 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1168 // NOTE: the selected map has just been inserted at (insertpos-1)th position
1169 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
1170 if(Map_Check(Map_Current, 1))
1178 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1181 bprint( "Maplist is empty! Resetting it to default map list.\n" );
1182 cvar_set("g_maplist", MapInfo_ListAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
1183 if(autocvar_g_maplist_shuffle)
1185 localcmd("\nmenu_cmd sync\n");
1186 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1189 error("empty maplist, cannot select a new map");
1190 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
1192 if(Map_Current_Name)
1193 strunzone(Map_Current_Name);
1194 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
1195 // this may or may not be correct, but who cares, in the worst case a map
1196 // isn't chosen in the first pass that should have been
1207 if(autocvar_g_maplist_shuffle > 0)
1208 nextMap = MaplistMethod_Shuffle(autocvar_g_maplist_shuffle + 1);
1211 if(autocvar_g_maplist_selectrandom)
1212 nextMap = MaplistMethod_Random();
1215 nextMap = MaplistMethod_Iterate();
1218 nextMap = MaplistMethod_Repeat();
1222 Map_Goto_SetFloat(nextMap);
1223 return getmapname_stored;
1229 float DoNextMapOverride()
1231 if(autocvar_g_campaign)
1233 CampaignPostIntermission();
1234 alreadychangedlevel = TRUE;
1237 if(autocvar_quit_when_empty)
1239 if(player_count <= currentbots)
1242 alreadychangedlevel = TRUE;
1246 if(autocvar_quit_and_redirect != "")
1248 redirection_target = strzone(autocvar_quit_and_redirect);
1249 alreadychangedlevel = TRUE;
1252 if (autocvar_samelevel) // if samelevel is set, stay on same level
1254 // 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)
1255 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
1256 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
1257 localcmd("restart\n");
1258 //changelevel (mapname);
1259 alreadychangedlevel = TRUE;
1262 if(autocvar_nextmap != "")
1263 if(MapInfo_CheckMap(autocvar_nextmap))
1265 Map_Goto_SetStr(autocvar_nextmap);
1267 alreadychangedlevel = TRUE;
1270 if(autocvar_lastlevel)
1273 localcmd("set lastlevel 0\ntogglemenu\n");
1274 alreadychangedlevel = TRUE;
1282 //local string nextmap;
1283 //local float n, nummaps;
1285 if (alreadychangedlevel)
1287 alreadychangedlevel = TRUE;
1293 for(allowReset = 1; allowReset >= 0; --allowReset)
1295 nextMap = GetNextMap();
1301 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1302 cvar_set("g_maplist", MapInfo_ListAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
1303 if(autocvar_g_maplist_shuffle)
1305 localcmd("\nmenu_cmd sync\n");
1309 error("Everything is broken - not even the default map list works. Please report this to the developers.");
1321 When the player presses attack or jump, change to the next level
1324 .float autoscreenshot;
1325 void() MapVote_Start;
1326 void() MapVote_Think;
1327 float mapvote_initialized;
1328 void IntermissionThink()
1330 FixIntermissionClient(self);
1332 if(autocvar_sv_autoscreenshot)
1333 if(self.autoscreenshot > 0)
1334 if(time > self.autoscreenshot)
1336 self.autoscreenshot = -1;
1337 if(clienttype(self) == CLIENTTYPE_REAL)
1338 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
1342 if (time < intermission_exittime)
1345 if(!mapvote_initialized)
1346 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
1356 Returns the entity to view from
1360 entity FindIntermission()
1365 // look for info_intermission first
1366 spot = find (world, classname, "info_intermission");
1368 { // pick a random one
1372 spot = find (spot, classname, "info_intermission");
1374 spot = find (spot, classname, "info_intermission");
1380 // then look for the start position
1381 spot = find (world, classname, "info_player_start");
1385 // testinfo_player_start is only found in regioned levels
1386 spot = find (world, classname, "testplayerstart");
1390 // then look for the start position
1391 spot = find (world, classname, "info_player_deathmatch");
1395 //objerror ("FindIntermission: no spot");
1401 ===============================================================================
1405 ===============================================================================
1408 void DumpStats(float final)
1418 to_console = autocvar_sv_logscores_console;
1419 to_eventlog = autocvar_sv_eventlog;
1420 to_file = autocvar_sv_logscores_file;
1424 to_console = TRUE; // always print printstats replies
1425 to_eventlog = FALSE; // but never print them to the event log
1429 if(autocvar_sv_eventlog_console)
1430 to_console = FALSE; // otherwise we get the output twice
1436 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
1444 file = fopen(autocvar_sv_logscores_filename, FILE_APPEND);
1448 fputs(file, strcat(s, "\n"));
1451 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
1457 fputs(file, strcat(s, "\n"));
1459 FOR_EACH_CLIENT(other)
1461 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && autocvar_sv_logscores_bots))
1463 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
1464 s = strcat(s, ftos(rint(time - other.jointime)), ":");
1465 if(other.classname == "player" || g_arena || g_ca || g_lms)
1466 s = strcat(s, ftos(other.team), ":");
1468 s = strcat(s, "spectator:");
1471 print(s, other.netname, "\n");
1473 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
1475 fputs(file, strcat(s, other.netname, "\n"));
1481 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
1487 fputs(file, strcat(s, "\n"));
1489 for(i = 1; i < 16; ++i)
1491 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
1492 s = strcat(s, ":", ftos(i));
1498 fputs(file, strcat(s, "\n"));
1505 GameLogEcho(":end");
1508 fputs(file, ":end\n");
1514 PlayerStats_AddGlobalInfo(e);
1515 PlayerStats_Shutdown();
1518 void FixIntermissionClient(entity e)
1521 if(!e.autoscreenshot) // initial call
1523 e.angles = e.v_angle;
1524 e.angles_x = -e.angles_x;
1525 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1527 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1528 e.solid = SOLID_NOT;
1529 e.movetype = MOVETYPE_NONE;
1530 e.takedamage = DAMAGE_NO;
1533 e.weaponentity.effects = EF_NODRAW;
1534 if (e.weaponentity.weaponentity)
1535 e.weaponentity.weaponentity.effects = EF_NODRAW;
1537 if(clienttype(e) == CLIENTTYPE_REAL)
1539 stuffcmd(e, "\nscr_printspeed 1000000\n");
1540 s = autocvar_sv_intermission_cdtrack;
1542 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1544 WriteByte(MSG_ONE, SVC_INTERMISSION);
1548 //e.velocity = '0 0 0';
1549 //e.fixangle = TRUE;
1551 // TODO halt weapon animation
1556 go to the next level for deathmatch
1557 only called if a time or frag limit has expired
1563 intermission_running = 1;
1565 // enforce a wait time before allowing changelevel
1566 if(player_count > 0)
1567 intermission_exittime = time + autocvar_sv_mapchange_delay;
1569 intermission_exittime = -1;
1572 WriteByte (MSG_ALL, SVC_CDTRACK);
1573 WriteByte (MSG_ALL, 3);
1574 WriteByte (MSG_ALL, 3);
1575 // done in FixIntermission
1578 //pos = FindIntermission ();
1584 if(autocvar_sv_eventlog)
1585 GameLogEcho(":gameover");
1589 FOR_EACH_PLAYER(other) {
1590 FixIntermissionClient(other);
1592 bprint(other.netname, " ^7wins.\n");
1595 if(autocvar_g_campaign)
1596 CampaignPreIntermission();
1598 localcmd("\nsv_hook_gameend\n");
1605 Exit deathmatch games upon conditions
1608 void CheckRules_Player()
1610 if (gameover) // someone else quit the game already
1613 if(self.deadflag == DEAD_NO)
1614 self.play_time += frametime;
1616 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1617 // (div0: and that in CheckRules_World please)
1620 float checkrules_equality;
1621 float checkrules_suddendeathwarning;
1622 float checkrules_suddendeathend;
1623 float checkrules_overtimesadded; //how many overtimes have been already added
1625 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1626 float WINNING_YES = 1; // winner found
1627 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1628 float WINNING_STARTSUDDENDEATHOVERTIME = 3; // no winner, enter suddendeath overtime NOW
1630 float InitiateSuddenDeath()
1632 // Check first whether normal overtimes could be added before initiating suddendeath mode
1633 // - for this timelimit_overtime needs to be >0 of course
1634 // - also check the winning condition calculated in the previous frame and only add normal overtime
1635 // again, if at the point at which timelimit would be extended again, still no winner was found
1636 if ((checkrules_overtimesadded >= 0) && (checkrules_overtimesadded < autocvar_timelimit_overtimes) && autocvar_timelimit_overtime && !(g_race && !g_race_qualifying))
1638 return 1; // need to call InitiateOvertime later
1642 if(!checkrules_suddendeathend)
1644 checkrules_suddendeathend = time + 60 * autocvar_timelimit_suddendeath;
1645 if(g_race && !g_race_qualifying)
1646 race_StartCompleting();
1652 void InitiateOvertime() // ONLY call this if InitiateSuddenDeath returned true
1654 ++checkrules_overtimesadded;
1655 //add one more overtime by simply extending the timelimit
1657 tl = autocvar_timelimit;
1658 tl += autocvar_timelimit_overtime;
1659 cvar_set("timelimit", ftos(tl));
1660 string minutesPlural;
1661 if (autocvar_timelimit_overtime == 1)
1662 minutesPlural = " ^3minute";
1664 minutesPlural = " ^3minutes";
1668 "^3Now playing ^1OVERTIME^3!\n\n^3Added ^1",
1669 ftos(autocvar_timelimit_overtime),
1676 float GetWinningCode(float fraglimitreached, float equality)
1678 if(autocvar_g_campaign == 1)
1679 if(fraglimitreached)
1686 if(fraglimitreached)
1687 return WINNING_STARTSUDDENDEATHOVERTIME;
1689 return WINNING_NEVER;
1691 if(fraglimitreached)
1697 // set the .winning flag for exactly those players with a given field value
1698 void SetWinners(.float field, float value)
1701 FOR_EACH_PLAYER(head)
1702 head.winning = (head.field == value);
1705 // set the .winning flag for those players with a given field value
1706 void AddWinners(.float field, float value)
1709 FOR_EACH_PLAYER(head)
1710 if(head.field == value)
1714 // clear the .winning flags
1715 void ClearWinners(void)
1718 FOR_EACH_PLAYER(head)
1722 // Onslaught winning condition:
1723 // game terminates if only one team has a working generator (or none)
1724 float WinningCondition_Onslaught()
1727 local float t1, t2, t3, t4;
1729 WinningConditionHelper(); // set worldstatus
1734 // first check if the game has ended
1735 t1 = t2 = t3 = t4 = 0;
1736 head = find(world, classname, "onslaught_generator");
1739 if (head.health > 0)
1741 if (head.team == COLOR_TEAM1) t1 = 1;
1742 if (head.team == COLOR_TEAM2) t2 = 1;
1743 if (head.team == COLOR_TEAM3) t3 = 1;
1744 if (head.team == COLOR_TEAM4) t4 = 1;
1746 head = find(head, classname, "onslaught_generator");
1748 if (t1 + t2 + t3 + t4 < 2)
1750 // game over, only one team remains (or none)
1752 if (t1) SetWinners(team, COLOR_TEAM1);
1753 if (t2) SetWinners(team, COLOR_TEAM2);
1754 if (t3) SetWinners(team, COLOR_TEAM3);
1755 if (t4) SetWinners(team, COLOR_TEAM4);
1756 dprint("Have a winner, ending game.\n");
1760 // Two or more teams remain
1764 float LMS_NewPlayerLives()
1767 fl = autocvar_fraglimit;
1771 // first player has left the game for dying too much? Nobody else can get in.
1772 if(lms_lowest_lives < 1)
1775 if(!autocvar_g_lms_join_anytime)
1776 if(lms_lowest_lives < fl - autocvar_g_lms_last_join)
1779 return bound(1, lms_lowest_lives, fl);
1782 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1783 // they win. Otherwise the defending team wins once the timelimit passes.
1784 void assault_new_round();
1785 float WinningCondition_Assault()
1789 WinningConditionHelper(); // set worldstatus
1791 status = WINNING_NO;
1792 // as the timelimit has not yet passed just assume the defending team will win
1793 if(assault_attacker_team == COLOR_TEAM1)
1795 SetWinners(team, COLOR_TEAM2);
1799 SetWinners(team, COLOR_TEAM1);
1803 ent = find(world, classname, "target_assault_roundend");
1806 if(ent.winning) // round end has been triggered by attacking team
1808 bprint("ASSAULT: round completed...\n");
1809 SetWinners(team, assault_attacker_team);
1811 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
1813 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
1815 status = WINNING_YES;
1819 local entity oldself;
1822 assault_new_round();
1831 // LMS winning condition: game terminates if and only if there's at most one
1832 // one player who's living lives. Top two scores being equal cancels the time
1834 float WinningCondition_LMS()
1841 have_player = FALSE;
1842 have_players = FALSE;
1843 l = LMS_NewPlayerLives();
1845 head = find(world, classname, "player");
1848 head2 = find(head, classname, "player");
1850 have_players = TRUE;
1854 // we have at least one player
1857 // two or more active players - continue with the game
1861 // exactly one player?
1864 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1868 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1874 // and assign him his first place
1875 PlayerScore_Add(head, SP_LMS_RANK, 1);
1882 // nobody is playing at all...
1885 // wait for players...
1889 // SNAFU (maybe a draw game?)
1891 dprint("No players, ending game.\n");
1896 // When we get here, we have at least two players who are actually LIVING,
1897 // now check if the top two players have equal score.
1898 WinningConditionHelper();
1901 if(WinningConditionHelper_winner)
1902 WinningConditionHelper_winner.winning = TRUE;
1903 if(WinningConditionHelper_topscore == WinningConditionHelper_secondscore)
1904 return WINNING_NEVER;
1906 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1910 void ShuffleMaplist()
1912 cvar_set("g_maplist", shufflewords(autocvar_g_maplist));
1916 float WinningCondition_Scores(float limit, float leadlimit)
1920 // TODO make everything use THIS winning condition (except LMS)
1921 WinningConditionHelper();
1925 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1926 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1927 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1928 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1932 if(WinningConditionHelper_winner)
1933 WinningConditionHelper_winner.winning = 1;
1934 if(WinningConditionHelper_winnerteam >= 0)
1935 SetWinners(team, WinningConditionHelper_winnerteam);
1937 if(WinningConditionHelper_lowerisbetter)
1939 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1940 WinningConditionHelper_secondscore = -WinningConditionHelper_secondscore;
1944 if(WinningConditionHelper_zeroisworst)
1945 leadlimit = 0; // not supported in this mode
1947 if(g_dm || g_tdm || g_arena || g_ca || (g_race && !g_race_qualifying) || g_nexball)
1948 // these modes always score in increments of 1, thus this makes sense
1950 if(leaderfrags != WinningConditionHelper_topscore)
1952 leaderfrags = WinningConditionHelper_topscore;
1955 if (leaderfrags == limit - 1)
1956 Announce("1fragleft");
1957 else if (leaderfrags == limit - 2)
1958 Announce("2fragsleft");
1959 else if (leaderfrags == limit - 3)
1960 Announce("3fragsleft");
1964 limitreached = FALSE;
1966 if(WinningConditionHelper_topscore >= limit)
1967 limitreached = TRUE;
1970 float leadlimitreached;
1971 leadlimitreached = (WinningConditionHelper_topscore - WinningConditionHelper_secondscore >= leadlimit);
1972 if(autocvar_leadlimit_and_fraglimit)
1973 limitreached = (limitreached && leadlimitreached);
1975 limitreached = (limitreached || leadlimitreached);
1978 return GetWinningCode(
1979 WinningConditionHelper_topscore && limitreached,
1980 WinningConditionHelper_equality
1984 float WinningCondition_Race(float fraglimit)
1995 if(p.race_completed)
2000 wc = WinningCondition_Scores(fraglimit, 0);
2002 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
2003 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
2004 // do NOT support equality when the laps are all raced!
2005 return WINNING_STARTSUDDENDEATHOVERTIME;
2007 return WINNING_NEVER;
2011 void ReadyRestart();
2012 float WinningCondition_QualifyingThenRace(float limit)
2015 wc = WinningCondition_Scores(limit, 0);
2017 // NEVER initiate overtime
2018 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
2026 float WinningCondition_RanOutOfSpawns()
2030 if(have_team_spawns <= 0)
2033 if(!some_spawn_has_been_used)
2036 team1_score = team2_score = team3_score = team4_score = 0;
2038 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
2040 if(head.team == COLOR_TEAM1)
2042 else if(head.team == COLOR_TEAM2)
2044 else if(head.team == COLOR_TEAM3)
2046 else if(head.team == COLOR_TEAM4)
2050 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
2052 if(head.team == COLOR_TEAM1)
2054 else if(head.team == COLOR_TEAM2)
2056 else if(head.team == COLOR_TEAM3)
2058 else if(head.team == COLOR_TEAM4)
2063 if(team1_score + team2_score + team3_score + team4_score == 0)
2065 checkrules_equality = TRUE;
2068 else if(team1_score + team2_score + team3_score + team4_score == 1)
2071 if(team1_score) t = COLOR_TEAM1;
2072 if(team2_score) t = COLOR_TEAM2;
2073 if(team3_score) t = COLOR_TEAM3;
2074 if(team4_score) t = COLOR_TEAM4;
2075 CheckAllowedTeams(world);
2076 for(i = 0; i < MAX_TEAMSCORE; ++i)
2078 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
2079 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
2080 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
2081 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
2084 AddWinners(team, t);
2095 Exit deathmatch games upon conditions
2098 void CheckRules_World()
2110 MapVote_Think should now do that part
2111 if (intermission_running)
2112 if (time >= intermission_exittime + 60)
2114 if(!DoNextMapOverride())
2120 if (gameover) // someone else quit the game already
2122 if(player_count == 0) // Nobody there? Then let's go to the next map
2124 // this will actually check the player count in the next frame
2125 // again, but this shouldn't hurt
2129 timelimit = autocvar_timelimit * 60;
2130 fraglimit = autocvar_fraglimit;
2131 leadlimit = autocvar_leadlimit;
2133 if(inWarmupStage || time <= game_starttime) // NOTE: this is <= to prevent problems in the very tic where the game starts
2136 timelimit = 0; // timelimit is not made for warmup
2138 fraglimit = 0; // no fraglimit for now
2139 leadlimit = 0; // no leadlimit for now
2143 timelimit = 0; // ONS has its own overtime rule
2147 timelimit += game_starttime;
2149 else if (timelimit < 0)
2159 if(checkrules_suddendeathend)
2161 if(!checkrules_suddendeathwarning)
2163 checkrules_suddendeathwarning = TRUE;
2164 if(g_race && !g_race_qualifying)
2165 bcenterprint("^3Everyone, finish your lap! The race is over!");
2167 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
2172 if (timelimit && time >= timelimit)
2174 if(g_race && (g_race_qualifying == 2) && timelimit > 0)
2177 float playerswithlaps;
2180 totalplayers = playerswithlaps = readyplayers = 0;
2181 FOR_EACH_PLAYER(head)
2184 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
2190 // at least 2 of the players have completed a lap: start the RACE
2191 // otherwise, the players should end the qualifying on their own
2192 if(readyplayers || playerswithlaps >= 2)
2194 checkrules_suddendeathend = 0;
2195 ReadyRestart(); // go to race
2199 wantovertime |= InitiateSuddenDeath();
2202 wantovertime |= InitiateSuddenDeath();
2206 if (checkrules_suddendeathend && time >= checkrules_suddendeathend)
2212 float checkrules_status;
2213 checkrules_status = WinningCondition_RanOutOfSpawns();
2214 if(checkrules_status == WINNING_YES)
2216 bprint("Hey! Someone ran out of spawns!\n");
2218 else if(g_race && !g_race_qualifying && timelimit >= 0)
2220 checkrules_status = WinningCondition_Race(fraglimit);
2221 //print("WC_RACE yields ", ftos(checkrules_status), "\n");
2223 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
2225 checkrules_status = WinningCondition_QualifyingThenRace(fraglimit);
2226 //print("WC_QUALIFYING_THEN_RACE yields ", ftos(checkrules_status), "\n");
2230 checkrules_status = WinningCondition_Assault(); // TODO remove this?
2234 checkrules_status = WinningCondition_LMS();
2236 else if (g_onslaught)
2238 checkrules_status = WinningCondition_Onslaught(); // TODO remove this?
2242 checkrules_status = WinningCondition_Scores(fraglimit, leadlimit);
2243 //print("WC_SCORES yields ", ftos(checkrules_status), "\n");
2246 if(checkrules_status == WINNING_STARTSUDDENDEATHOVERTIME)
2248 checkrules_status = WINNING_NEVER;
2249 checkrules_overtimesadded = -1;
2250 wantovertime |= InitiateSuddenDeath();
2253 if(checkrules_status == WINNING_NEVER)
2254 // equality cases! Nobody wins if the overtime ends in a draw.
2259 if(checkrules_status == WINNING_NEVER)
2262 checkrules_status = WINNING_YES;
2265 if(checkrules_suddendeathend)
2266 if(checkrules_status != WINNING_NEVER || time >= checkrules_suddendeathend)
2267 checkrules_status = WINNING_YES;
2269 if(checkrules_status == WINNING_YES)
2271 //print("WINNING\n");
2276 float mapvote_nextthink;
2277 float mapvote_initialized;
2278 float mapvote_keeptwotime;
2279 float mapvote_timeout;
2280 string mapvote_message;
2281 #define MAPVOTE_SCREENSHOT_DIRS_COUNT 4
2282 string mapvote_screenshot_dirs[MAPVOTE_SCREENSHOT_DIRS_COUNT];
2283 float mapvote_screenshot_dirs_count;
2285 float mapvote_count;
2286 float mapvote_count_real;
2287 string mapvote_maps[MAPVOTE_COUNT];
2288 float mapvote_maps_screenshot_dir[MAPVOTE_COUNT];
2289 string mapvote_maps_pakfile[MAPVOTE_COUNT];
2290 float mapvote_maps_suggested[MAPVOTE_COUNT];
2291 string mapvote_suggestions[MAPVOTE_COUNT];
2292 float mapvote_suggestion_ptr;
2293 float mapvote_maxlen;
2294 float mapvote_voters;
2295 float mapvote_votes[MAPVOTE_COUNT];
2297 float mapvote_detail;
2298 float mapvote_abstain;
2301 void MapVote_ClearAllVotes()
2303 FOR_EACH_CLIENT(other)
2307 string MapVote_Suggest(string m)
2311 return "That's not how to use this command.";
2312 if(!autocvar_g_maplist_votable_suggestions)
2313 return "Suggestions are not accepted on this server.";
2314 if(mapvote_initialized)
2315 return "Can't suggest - voting is already in progress!";
2316 m = MapInfo_FixName(m);
2318 return "The map you suggested is not available on this server.";
2319 if(!autocvar_g_maplist_votable_suggestions_override_mostrecent)
2321 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
2323 if(!MapInfo_CheckMap(m))
2324 return "The map you suggested does not support the current game mode.";
2325 for(i = 0; i < mapvote_suggestion_ptr; ++i)
2326 if(mapvote_suggestions[i] == m)
2327 return "This map was already suggested.";
2328 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
2330 i = floor(random() * mapvote_suggestion_ptr);
2334 i = mapvote_suggestion_ptr;
2335 mapvote_suggestion_ptr += 1;
2337 if(mapvote_suggestions[i] != "")
2338 strunzone(mapvote_suggestions[i]);
2339 mapvote_suggestions[i] = strzone(m);
2340 if(autocvar_sv_eventlog)
2341 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
2342 return strcat("Suggestion of ", m, " accepted.");
2345 void MapVote_AddVotable(string nextMap, float isSuggestion)
2348 string pakfile, mapfile;
2352 for(j = 0; j < mapvote_count; ++j)
2353 if(mapvote_maps[j] == nextMap)
2355 if(strlen(nextMap) > mapvote_maxlen)
2356 mapvote_maxlen = strlen(nextMap);
2357 mapvote_maps[mapvote_count] = strzone(nextMap);
2358 mapvote_maps_suggested[mapvote_count] = isSuggestion;
2360 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2362 mapfile = strcat(mapvote_screenshot_dirs[i], "/", mapvote_maps[i]);
2363 pakfile = whichpack(strcat(mapfile, ".tga"));
2365 pakfile = whichpack(strcat(mapfile, ".jpg"));
2367 pakfile = whichpack(strcat(mapfile, ".png"));
2371 if(i >= mapvote_screenshot_dirs_count)
2372 i = 0; // FIXME maybe network this error case, as that means there is no mapshot on the server?
2373 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
2374 pakfile = substring(pakfile, o, -1);
2376 mapvote_maps_screenshot_dir[mapvote_count] = i;
2377 mapvote_maps_pakfile[mapvote_count] = strzone(pakfile);
2382 void MapVote_Spawn();
2388 MapVote_ClearAllVotes();
2391 mapvote_detail = !autocvar_g_maplist_votable_nodetail;
2392 mapvote_abstain = autocvar_g_maplist_votable_abstain;
2395 nmax = min(MAPVOTE_COUNT - 1, autocvar_g_maplist_votable);
2397 nmax = min(MAPVOTE_COUNT, autocvar_g_maplist_votable);
2398 smax = min3(nmax, autocvar_g_maplist_votable_suggestions, mapvote_suggestion_ptr);
2400 // we need this for AddVotable, as that cycles through the screenshot dirs
2401 mapvote_screenshot_dirs_count = tokenize_console(autocvar_g_maplist_votable_screenshot_dir);
2402 if(mapvote_screenshot_dirs_count == 0)
2403 mapvote_screenshot_dirs_count = tokenize_console("maps levelshots");
2404 mapvote_screenshot_dirs_count = min(mapvote_screenshot_dirs_count, MAPVOTE_SCREENSHOT_DIRS_COUNT);
2405 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2406 mapvote_screenshot_dirs[i] = strzone(argv(i));
2408 if(mapvote_suggestion_ptr)
2409 for(i = 0; i < 100 && mapvote_count < smax; ++i)
2410 MapVote_AddVotable(mapvote_suggestions[floor(random() * mapvote_suggestion_ptr)], TRUE);
2412 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2413 MapVote_AddVotable(GetNextMap(), FALSE);
2415 if(mapvote_count == 0)
2417 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
2418 cvar_set("g_maplist", MapInfo_ListAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
2419 if(autocvar_g_maplist_shuffle)
2421 localcmd("\nmenu_cmd sync\n");
2422 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2423 MapVote_AddVotable(GetNextMap(), FALSE);
2426 mapvote_count_real = mapvote_count;
2428 MapVote_AddVotable("don't care", 0);
2430 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
2432 mapvote_keeptwotime = time + autocvar_g_maplist_votable_keeptwotime;
2433 mapvote_timeout = time + autocvar_g_maplist_votable_timeout;
2434 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
2435 mapvote_keeptwotime = 0;
2436 mapvote_message = "Choose a map and press its key!";
2441 void MapVote_SendPicture(float id)
2444 WriteByte(MSG_ONE, SVC_TEMPENTITY);
2445 WriteByte(MSG_ONE, TE_CSQC_PICTURE);
2446 WriteByte(MSG_ONE, id);
2447 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dirs[mapvote_maps_screenshot_dir[id]], "/", mapvote_maps[id]), 3072);
2450 float GameCommand_MapVote(string cmd)
2452 if(!intermission_running)
2455 if(cmd == "mv_getpic")
2457 MapVote_SendPicture(stof(argv(1)));
2464 float MapVote_GetMapMask()
2466 float mask, i, power;
2468 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
2469 if(mapvote_maps[i] != "")
2475 float MapVote_SendEntity(entity to, float sf)
2480 sf &~= 2; // if we send 1, we don't need to also send 2
2482 WriteByte(MSG_ENTITY, ENT_CLIENT_MAPVOTE);
2483 WriteByte(MSG_ENTITY, sf);
2487 // flag 1 == initialization
2488 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2489 WriteString(MSG_ENTITY, mapvote_screenshot_dirs[i]);
2490 WriteString(MSG_ENTITY, "");
2491 WriteByte(MSG_ENTITY, mapvote_count);
2492 WriteByte(MSG_ENTITY, mapvote_abstain);
2493 WriteByte(MSG_ENTITY, mapvote_detail);
2494 WriteCoord(MSG_ENTITY, mapvote_timeout);
2495 if(mapvote_count <= 8)
2496 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2498 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2499 for(i = 0; i < mapvote_count; ++i)
2500 if(mapvote_maps[i] != "")
2502 if(mapvote_abstain && i == mapvote_count - 1)
2504 WriteString(MSG_ENTITY, ""); // abstain needs no text
2505 WriteString(MSG_ENTITY, ""); // abstain needs no pack
2506 WriteByte(MSG_ENTITY, 0); // abstain needs no screenshot dir
2510 WriteString(MSG_ENTITY, mapvote_maps[i]);
2511 WriteString(MSG_ENTITY, mapvote_maps_pakfile[i]);
2512 WriteByte(MSG_ENTITY, mapvote_maps_screenshot_dir[i]);
2519 // flag 2 == update of mask
2520 if(mapvote_count <= 8)
2521 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2523 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2529 for(i = 0; i < mapvote_count; ++i)
2530 if(mapvote_maps[i] != "")
2531 WriteByte(MSG_ENTITY, mapvote_votes[i]);
2533 WriteByte(MSG_ENTITY, to.mapvote);
2539 void MapVote_Spawn()
2541 Net_LinkEntity(mapvote_ent = spawn(), FALSE, 0, MapVote_SendEntity);
2544 void MapVote_TouchMask()
2546 mapvote_ent.SendFlags |= 2;
2549 void MapVote_TouchVotes(entity voter)
2551 mapvote_ent.SendFlags |= 4;
2554 float MapVote_Finished(float mappos)
2560 if(autocvar_sv_eventlog)
2562 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2563 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
2564 didntvote = mapvote_voters;
2565 for(i = 0; i < mapvote_count; ++i)
2566 if(mapvote_maps[i] != "")
2568 didntvote -= mapvote_votes[i];
2571 result = strcat(result, ":", mapvote_maps[i]);
2572 result = strcat(result, ":", ftos(mapvote_votes[i]));
2575 result = strcat(result, ":didn't vote:", ftos(didntvote));
2577 GameLogEcho(result);
2578 if(mapvote_maps_suggested[mappos])
2579 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
2582 FOR_EACH_REALCLIENT(other)
2583 FixClientCvars(other);
2585 Map_Goto_SetStr(mapvote_maps[mappos]);
2587 alreadychangedlevel = TRUE;
2590 void MapVote_CheckRules_1()
2594 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2596 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2597 mapvote_votes[i] = 0;
2601 FOR_EACH_REALCLIENT(other)
2606 i = other.mapvote - 1;
2607 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2608 mapvote_votes[i] = mapvote_votes[i] + 1;
2613 float MapVote_CheckRules_2()
2616 float firstPlace, secondPlace;
2617 float firstPlaceVotes, secondPlaceVotes;
2618 float mapvote_voters_real;
2621 if(mapvote_count_real == 1)
2622 return MapVote_Finished(0);
2624 mapvote_voters_real = mapvote_voters;
2626 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2628 RandomSelection_Init();
2629 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2630 RandomSelection_Add(world, i, string_null, 1, mapvote_votes[i]);
2631 firstPlace = RandomSelection_chosen_float;
2632 firstPlaceVotes = RandomSelection_best_priority;
2633 //dprint("First place: ", ftos(firstPlace), "\n");
2634 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2636 RandomSelection_Init();
2637 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2639 RandomSelection_Add(world, i, string_null, 1, mapvote_votes[i]);
2640 secondPlace = RandomSelection_chosen_float;
2641 secondPlaceVotes = RandomSelection_best_priority;
2642 //dprint("Second place: ", ftos(secondPlace), "\n");
2643 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2645 if(firstPlace == -1)
2646 error("No first place in map vote... WTF?");
2648 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2649 return MapVote_Finished(firstPlace);
2651 if(mapvote_keeptwotime)
2652 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2655 MapVote_TouchMask();
2656 mapvote_message = "Now decide between the TOP TWO!";
2657 mapvote_keeptwotime = 0;
2658 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2659 result = strcat(result, ":", ftos(firstPlaceVotes));
2660 result = strcat(result, ":", mapvote_maps[secondPlace]);
2661 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2662 didntvote = mapvote_voters;
2663 for(i = 0; i < mapvote_count; ++i)
2664 if(mapvote_maps[i] != "")
2666 didntvote -= mapvote_votes[i];
2668 if(i != secondPlace)
2670 result = strcat(result, ":", mapvote_maps[i]);
2671 result = strcat(result, ":", ftos(mapvote_votes[i]));
2672 if(i < mapvote_count_real)
2674 strunzone(mapvote_maps[i]);
2675 mapvote_maps[i] = "";
2676 strunzone(mapvote_maps_pakfile[i]);
2677 mapvote_maps_pakfile[i] = "";
2681 result = strcat(result, ":didn't vote:", ftos(didntvote));
2682 if(autocvar_sv_eventlog)
2683 GameLogEcho(result);
2693 keeptwo = mapvote_keeptwotime;
2694 MapVote_CheckRules_1(); // count
2695 if(MapVote_CheckRules_2()) // decide
2699 FOR_EACH_REALCLIENT(other)
2701 // hide scoreboard again
2702 if(other.health != 2342)
2704 other.health = 2342;
2706 if(clienttype(other) == CLIENTTYPE_REAL)
2709 WriteByte(MSG_ONE, SVC_FINALE);
2710 WriteString(MSG_ONE, "");
2714 // clear possibly invalid votes
2715 if(mapvote_maps[other.mapvote - 1] == "")
2717 // use impulses as new vote
2718 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2719 if(mapvote_maps[other.impulse - 1] != "")
2721 other.mapvote = other.impulse;
2722 MapVote_TouchVotes(other);
2730 MapVote_CheckRules_1(); // just count
2732 void MapVote_Start()
2737 // wait for stats to be sent first
2738 if(!playerstats_waitforme)
2741 MapInfo_Enumerate();
2742 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
2745 void MapVote_Think()
2750 if(alreadychangedlevel)
2753 if(time < mapvote_nextthink)
2757 mapvote_nextthink = time + 0.5;
2759 if(!mapvote_initialized)
2761 if(autocvar_rescan_pending == 1)
2763 cvar_set("rescan_pending", "2");
2764 localcmd("fs_rescan\nrescan_pending 3\n");
2767 else if(autocvar_rescan_pending == 2)
2771 else if(autocvar_rescan_pending == 3)
2773 // now build missing mapinfo files
2774 if(!MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
2777 // we're done, start the timer
2778 cvar_set("rescan_pending", "0");
2781 mapvote_initialized = TRUE;
2782 if(DoNextMapOverride())
2784 if(!autocvar_g_maplist_votable || player_count <= 0)
2795 string GotoMap(string m)
2797 if(!MapInfo_CheckMap(m))
2798 return "The map you chose is not available on this server.";
2799 cvar_set("nextmap", m);
2800 cvar_set("timelimit", "-1");
2801 if(mapvote_initialized || alreadychangedlevel)
2803 if(DoNextMapOverride())
2804 return "Map switch initiated.";
2806 return "Hm... no. For some reason I like THIS map more.";
2809 return "Map switch will happen after scoreboard.";
2816 FOR_EACH_REALCLIENT(self)
2818 if(self.classname == "spectator")
2820 if(self.enemy.typehitsound)
2821 play2(self, "misc/typehit.wav");
2822 else if(self.enemy.hitsound && self.cvar_cl_hitsound)
2823 play2(self, "misc/hit.wav");
2827 if(self.typehitsound)
2828 play2(self, "misc/typehit.wav");
2829 else if(self.hitsound && self.cvar_cl_hitsound)
2830 play2(self, "misc/hit.wav");
2833 altime = time + frametime * (1 + autocvar_g_antilag_nudge);
2834 // add 1 frametime because after this, engine SV_Physics
2835 // increases time by a frametime and then networks the frame
2836 // add another frametime because client shows everything with
2837 // 1 frame of lag (cl_nolerp 0). The last +1 however should not be
2839 FOR_EACH_CLIENT(self)
2841 self.hitsound = FALSE;
2842 self.typehitsound = FALSE;
2843 antilag_record(self, altime);
2850 * returns TRUE if redirecting
2852 float redirection_timeout;
2853 float redirection_nextthink;
2854 float RedirectionThink()
2856 float clients_found;
2858 if(redirection_target == "")
2861 if(!redirection_timeout)
2863 cvar_set("sv_public", "-2");
2864 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2865 if(redirection_target == "self")
2866 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2868 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2871 if(time < redirection_nextthink)
2874 redirection_nextthink = time + 1;
2877 FOR_EACH_REALCLIENT(self)
2879 print("Redirecting: sending connect command to ", self.netname, "\n");
2880 if(redirection_target == "self")
2881 stuffcmd(self, "\ndisconnect; reconnect\n");
2883 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2887 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2889 if(time > redirection_timeout || clients_found == 0)
2890 localcmd("\nwait; wait; wait; quit\n");
2895 void TargetMusic_RestoreGame();
2898 // Loaded from a save game
2899 // some things then break, so let's work around them...
2901 // Progs DB (capture records)
2902 ServerProgsDB = db_load("server.db");
2906 MapInfo_Enumerate();
2907 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
2910 TargetMusic_RestoreGame();
2917 if(gameover > 1) // shutting down already?
2920 gameover = 2; // 2 = server shutting down
2922 if(world_initialized > 0)
2924 world_initialized = 0;
2925 print("Saving persistent data...\n");
2929 PlayerStats_AddGlobalInfo(e);
2930 PlayerStats_Shutdown();
2932 if(!cheatcount_total)
2934 if(autocvar_sv_db_saveasdump)
2935 db_dump(ServerProgsDB, "server.db");
2937 db_save(ServerProgsDB, "server.db");
2939 if(autocvar_developer)
2941 if(autocvar_sv_db_saveasdump)
2942 db_dump(TemporaryDB, "server-temp.db");
2944 db_save(TemporaryDB, "server-temp.db");
2946 CheatShutdown(); // must be after cheatcount check
2947 db_close(ServerProgsDB);
2948 db_close(TemporaryDB);
2950 // tell the bot system the game is ending now
2953 WeaponStats_Shutdown();
2956 else if(world_initialized == 0)
2958 print("NOTE: crashed before even initializing the world, not saving persistent data\n");