2 void PingPLReport_Think()
7 delta = 3 / maxclients;
8 if(delta < sys_frametime)
10 self.nextthink = time + delta;
12 e = edict_num(self.cnt + 1);
13 if(clienttype(e) == CLIENTTYPE_REAL)
15 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
16 WriteByte(MSG_BROADCAST, TE_CSQC_PINGPLREPORT);
17 WriteByte(MSG_BROADCAST, self.cnt);
18 WriteShort(MSG_BROADCAST, max(1, e.ping));
19 WriteByte(MSG_BROADCAST, ceil(e.ping_packetloss * 255));
20 WriteByte(MSG_BROADCAST, ceil(e.ping_movementloss * 255));
24 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
25 WriteByte(MSG_BROADCAST, TE_CSQC_PINGPLREPORT);
26 WriteByte(MSG_BROADCAST, self.cnt);
27 WriteShort(MSG_BROADCAST, 0);
28 WriteByte(MSG_BROADCAST, 0);
29 WriteByte(MSG_BROADCAST, 0);
31 self.cnt = mod(self.cnt + 1, maxclients);
33 void PingPLReport_Spawn()
35 pingplreport = spawn();
36 pingplreport.classname = "pingplreport";
37 pingplreport.think = PingPLReport_Think;
38 pingplreport.nextthink = time;
41 float SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS = 1;
42 string redirection_target;
43 float world_initialized;
49 float() DoNextMapOverride;
51 void SetDefaultAlpha()
53 if(cvar("g_running_guns"))
55 default_player_alpha = -1;
56 default_weapon_alpha = +1;
60 default_player_alpha = cvar("g_balance_cloaked_alpha");
61 default_weapon_alpha = default_player_alpha;
65 default_player_alpha = cvar("g_player_alpha");
66 if(default_player_alpha == 0)
67 default_player_alpha = 1;
68 default_weapon_alpha = default_player_alpha;
72 void fteqcc_testbugs()
76 if(!cvar("developer_fteqccbugs"))
79 dprint("*** fteqcc test: checking for bugs...\n");
83 if(sqrt(a) - sqrt(b - a) == 0)
84 dprint("*** fteqcc test: found same-function-twice bug\n");
86 dprint("*** fteqcc test: same-function-twice bug got FINALLY FIXED! HOORAY!\n");
90 world.enemy.cnt += 10;
91 if(world.cnt > 0.2 || world.cnt < -0.2) // don't error out if it's just roundoff errors
92 dprint("*** fteqcc test: found += bug\n");
94 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
99 * Takes care of pausing and unpausing the game.
100 * Centerprints the information about an upcoming or active timeout to all active
101 * players. Also plays reminder sounds.
103 void timeoutHandler_Think() {
104 local string timeStr;
106 if (timeoutStatus == 1) {
107 if (remainingLeadTime > 0) {
108 //centerprint the information to every player
109 timeStr = getTimeoutText(0);
110 FOR_EACH_REALCLIENT(plr) {
111 if(plr.classname == "player") {
112 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
115 remainingLeadTime -= 1;
116 //think again in 1 second:
117 self.nextthink = time + 1;
120 //now pause the game:
122 //reset all the flood variables
123 FOR_EACH_CLIENT(plr) {
124 plr.nickspamcount = plr.nickspamtime = plr.floodcontrol_chat = plr.floodcontrol_chatteam = plr.floodcontrol_chattell = plr.floodcontrol_voice = plr.floodcontrol_voiceteam = 0;
126 cvar_set("slowmo", ftos(TIMEOUT_SLOWMO_VALUE));
127 //copy .v_angle to .lastV_angle for every player in order to fix their view during pause (see PlayerPreThink)
128 FOR_EACH_REALPLAYER(plr) {
129 plr.lastV_angle = plr.v_angle;
131 self.nextthink = time;
134 else if (timeoutStatus == 2) {
135 if (remainingTimeoutTime > 0) {
136 timeStr = getTimeoutText(0);
137 FOR_EACH_REALCLIENT(plr) {
138 if(plr.classname == "player") {
139 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
142 if(remainingTimeoutTime == cvar("sv_timeout_resumetime")) { //play a warning sound when only <sv_timeout_resumetime> seconds are left
143 Announce("prepareforbattle");
145 remainingTimeoutTime -= 1;
146 self.nextthink = time + TIMEOUT_SLOWMO_VALUE;
149 //unpause the game again
150 remainingTimeoutTime = timeoutStatus = 0;
151 cvar_set("slowmo", ftos(orig_slowmo));
152 //and unlock the fixed view again once there is no timeout active anymore
153 FOR_EACH_REALPLAYER(plr) {
154 plr.fixangle = FALSE;
156 //get rid of the countdown message
157 FOR_EACH_REALCLIENT(plr) {
158 if(plr.classname == "player") {
159 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
167 else if (timeoutStatus == 0) { //if a player called the resumegame command (which set timeoutStatus to 0 already)
168 FOR_EACH_REALCLIENT(plr) {
169 if(plr.classname == "player") {
170 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
183 // cvar_set("_sv_init", "0");
184 // we do NOT set this to 0 any more, so someone "accidentally" changing
185 // to this "init" map on a dedicated server will cause no permanent
187 if(cvar("g_maplist_shuffle"))
189 n = tokenizebyseparator(cvar_string("g_maplist"), " ");
190 cvar_set("g_maplist_index", ftos(n - 1)); // jump to map 0 in GotoNextMap
193 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
195 if(!DoNextMapOverride())
203 self.nextthink = time;
207 self.nextthink = time + 1;
208 print("Waiting for _sv_init being set to 1 by initialization scripts...\n");
212 void cvar_changes_init()
216 float n, i, adding, pureadding;
219 strunzone(cvar_changes);
220 cvar_changes = string_null;
222 strunzone(cvar_purechanges);
223 cvar_purechanges = string_null;
224 cvar_purechanges_count = 0;
227 buf_cvarlist(h, "", "_"); // exclude all _ cvars as they are temporary
233 for(i = 0; i < n; ++i)
235 k = bufstr_get(h, i);
237 #define BADPREFIX(p) if(substring(k, 0, strlen(p)) == p) continue
238 #define BADCVAR(p) if(k == p) continue
241 BADPREFIX("cvar_check_");
243 BADCVAR("g_configversion");
244 BADCVAR("g_maplist_index");
245 BADCVAR("halflifebsp");
246 BADPREFIX("sv_world");
252 BADPREFIX("scoreboard_");
253 BADPREFIX("g_campaign");
258 BADPREFIX("net_slist_");
263 BADPREFIX("userbind");
266 BADPREFIX("crosshair");
267 BADCVAR("mod_q3bsp_lightmapmergepower");
268 BADCVAR("mod_q3bsp_nolightmaps");
270 BADCVAR("mastervolume");
272 BADCVAR("bgmvolume");
275 BADCVAR("serverconfig");
277 BADPREFIX("g_chat_flood_");
278 BADPREFIX("g_voice_flood_");
280 BADPREFIX("settemp_");
281 BADPREFIX("sv_allowdownloads_");
282 BADPREFIX("sv_autodemo");
283 BADPREFIX("sv_curl_");
284 BADPREFIX("sv_eventlog");
285 BADPREFIX("sv_logscores_");
286 BADPREFIX("sv_master");
287 BADCVAR("g_banned_list");
288 BADCVAR("log_dest_udp");
290 BADCVAR("net_address");
292 BADCVAR("savedgamecfg");
293 BADCVAR("sv_heartbeatperiod");
294 BADCVAR("sv_vote_master_password");
295 BADCVAR("sys_colortranslation");
296 BADCVAR("sys_specialcharactertranslation");
297 BADCVAR("timestamps");
298 BADCVAR("net_address");
299 BADCVAR("net_address_ipv6");
300 BADPREFIX("sv_weaponstats_");
301 BADCVAR("developer");
302 BADPREFIX("developer_");
305 BADCVAR("timelimit");
306 BADCVAR("fraglimit");
307 BADCVAR("leadlimit");
308 BADCVAR("g_tdm_teams");
309 BADCVAR("g_keyhunt_teams");
310 BADCVAR("g_domination_default_teams");
311 BADCVAR("g_race_qualifying_timelimit");
315 BADCVAR("g_assault");
318 BADCVAR("g_domination");
319 BADCVAR("g_keyhunt");
320 BADCVAR("g_keyhunt_teams");
321 BADCVAR("g_onslaught");
324 BADCVAR("g_runematch");
326 BADCVAR("g_nexball");
331 BADCVAR("g_maplist");
332 BADCVAR("g_maplist_mostrecent");
336 d = cvar_defstring(k);
342 cvar_changes = strcat(cvar_changes, k, " \"", v, "\" // \"", d, "\"\n");
343 if(strlen(cvar_changes) > 16384)
345 cvar_changes = "// too many settings have been changed to show them here\n";
350 // now check if the changes are actually gameplay relevant
352 // does nothing visible
353 BADCVAR("captureleadlimit_override");
354 BADCVAR("g_arena_point_leadlimit");
355 BADCVAR("g_ca_point_leadlimit");
356 BADCVAR("g_ctf_capture_leadlimit");
357 BADCVAR("g_domination_point_leadlimit");
358 BADCVAR("g_keyhunt_point_leadlimit");
359 BADCVAR("g_nexball_goalleadlimit");
360 BADCVAR("g_runematch_point_leadlimit");
361 BADCVAR("leadlimit_and_fraglimit");
362 BADCVAR("leadlimit_override");
363 BADCVAR("sv_checkforpacketsduringsleep");
364 BADPREFIX("crypto_");
365 BADPREFIX("g_chat_");
367 BADPREFIX("sv_fragmessage_");
368 BADPREFIX("sv_vote_");
369 BADPREFIX("timelimit_");
371 // allowed changes to server admins (please sync this to server.cfg)
375 // :%s,//\([^ ]*\).*,BADCVAR("\1");,
377 // yes, this does contain some redundant stuff, don't really care
378 BADCVAR("bot_number");
379 BADCVAR("bot_prefix");
380 BADCVAR("bot_suffix");
381 BADCVAR("capturelimit_override");
382 BADCVAR("fraglimit_override");
384 BADCVAR("g_antilag");
385 BADCVAR("g_balance_teams");
386 BADCVAR("g_balance_teams_force");
387 BADCVAR("g_ban_sync_trusted_servers");
388 BADCVAR("g_ban_sync_uri");
389 BADCVAR("g_ctf_capture_limit");
390 BADCVAR("g_ctf_ignore_frags");
391 BADCVAR("g_ctf_win_mode");
392 BADCVAR("g_domination_point_limit");
393 BADCVAR("g_fullbrightitems");
394 BADCVAR("g_fullbrightplayers");
395 BADCVAR("g_keyhunt_point_limit");
396 BADCVAR("g_keyhunt_teams_override");
397 BADCVAR("g_lms_lives_override");
398 BADCVAR("g_maplist");
399 BADCVAR("g_maplist_check_waypoints");
400 BADCVAR("g_maplist_mostrecent_count");
401 BADCVAR("g_maplist_shuffle");
402 BADCVAR("g_maplist_votable");
403 BADCVAR("g_maplist_votable_abstain");
404 BADCVAR("g_maplist_votable_nodetail");
405 BADCVAR("g_maplist_votable_suggestions");
406 BADCVAR("g_nexball_goallimit");
407 BADCVAR("g_runematch_point_limit");
408 BADCVAR("g_start_delay");
411 BADCVAR("maxplayers");
412 BADCVAR("minplayers");
413 BADCVAR("net_address");
415 BADCVAR("rcon_password");
416 BADCVAR("rcon_restricted_commands");
417 BADCVAR("rcon_restricted_password");
419 BADCVAR("sv_adminnick");
420 BADCVAR("sv_autoscreenshot");
421 BADCVAR("sv_curl_defaulturl");
422 BADCVAR("sv_defaultcharacter");
423 BADCVAR("sv_defaultplayermodel");
424 BADCVAR("sv_defaultplayerskin");
425 BADCVAR("sv_maxidle");
426 BADCVAR("sv_maxrate");
428 BADCVAR("sv_public");
429 BADCVAR("sv_ready_restart");
430 BADCVAR("sv_status_privacy");
431 BADCVAR("sv_vote_call");
432 BADCVAR("sv_vote_commands");
433 BADCVAR("sv_vote_majority_factor");
434 BADCVAR("sv_vote_master");
435 BADCVAR("sv_vote_master_commands");
436 BADCVAR("sv_vote_master_password");
437 BADCVAR("sv_vote_simple_majority_factor");
438 BADCVAR("timelimit_override");
444 cvar_purechanges = strcat(cvar_purechanges, k, " \"", v, "\" // \"", d, "\"\n");
445 if(strlen(cvar_purechanges) > 16384)
447 cvar_purechanges = "// too many settings have been changed to show them here\n";
451 ++cvar_purechanges_count;
452 // WARNING: this variable is used for the server list
453 // NEVER dare to skip this code!
454 // Hacks to intentionally appearing as "pure server" even though you DO have
455 // modified settings may be punished by removal from the server list.
456 // You can do to the variables cvar_changes and cvar_purechanges all you want,
460 if(cvar_changes == "")
461 cvar_changes = "// this server runs at default server settings\n";
463 cvar_changes = strcat("// this server runs at modified server settings:\n", cvar_changes);
464 cvar_changes = strzone(cvar_changes);
465 if(cvar_purechanges == "")
466 cvar_purechanges = "// this server runs at default gameplay settings\n";
468 cvar_purechanges = strcat("// this server runs at modified gameplay settings:\n", cvar_purechanges);
469 cvar_purechanges = strzone(cvar_purechanges);
472 void detect_maptype()
481 o_x += random() * (world.maxs_x - world.mins_x);
482 o_y += random() * (world.maxs_y - world.mins_y);
483 o_z += random() * (world.maxs_z - world.mins_z);
485 tracebox(o, PL_MIN, PL_MAX, o - '0 0 32768', MOVE_WORLDONLY, world);
486 if(trace_fraction == 1)
491 for(i = 0; i < 64; i += 4)
493 tracebox(o, '-1 -1 -1' * i, '1 1 1' * i, o - '0 0 32768', MOVE_WORLDONLY, world);
494 if(trace_fraction == 1)
496 print(ftos(i), " -> ", vtos(trace_endpos), "\n");
505 float RandomSeed_Send(entity to, float sf)
507 WriteByte(MSG_ENTITY, ENT_CLIENT_RANDOMSEED);
508 WriteShort(MSG_ENTITY, self.cnt);
511 void RandomSeed_Think()
513 self.cnt = bound(0, floor(random() * 65536), 65535);
514 self.nextthink = time + 5;
518 void RandomSeed_Spawn()
520 randomseed = spawn();
521 randomseed.think = RandomSeed_Think;
522 Net_LinkEntity(randomseed, FALSE, 0, RandomSeed_Send);
527 self.think(); // sets random seed and nextthink
531 void spawnfunc___init_dedicated_server(void)
533 // handler for _init/_init map (only for dedicated server initialization)
535 world_initialized = -1; // don't complain
537 cvar_string = cvar_string_normal;
538 cvar_set = cvar_set_normal;
540 remove = remove_unsafely;
544 e.think = GotoFirstMap;
545 e.nextthink = time; // this is usually 1 at this point
548 e.classname = "info_player_deathmatch"; // safeguard against player joining
550 self.classname = "worldspawn"; // safeguard against various stuff ;)
553 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
556 void Map_MarkAsRecent(string m);
557 float world_already_spawned;
558 void RegisterWeapons();
560 void ClientInit_Spawn();
561 void WeaponStats_Init();
562 void WeaponStats_Shutdown();
563 void spawnfunc_worldspawn (void)
565 float fd, l, i, j, n;
569 cvar_string = cvar_string_normal;
570 cvar_set = cvar_set_normal;
572 if(world_already_spawned)
573 error("world already spawned - you may have EXACTLY ONE worldspawn!");
574 world_already_spawned = TRUE;
576 remove = remove_safely; // during spawning, watch what you remove!
578 check_unacceptable_compiler_bugs();
580 cvar_changes_init(); // do this very early now so it REALLY matches the server config
582 compressShortVector_init();
584 allowed_to_spawn = TRUE;
587 head = nextent(world);
592 head = nextent(head);
595 // needs to be done so early as they would still spawn
598 ServerProgsDB = db_load("server.db");
600 TemporaryDB = db_create();
603 TODO sound pack system
604 // initialize sound pack system
605 soundpack = cvar_string("g_soundpack");
607 soundpack = strcat(soundpack, "/");
608 soundpack = strzone(soundpack);
614 // 1 FLICKER (first variety)
615 lightstyle(1, "mmnmmommommnonmmonqnmmo");
617 // 2 SLOW STRONG PULSE
618 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
620 // 3 CANDLE (first variety)
621 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
624 lightstyle(4, "mamamamamama");
627 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
629 // 6 FLICKER (second variety)
630 lightstyle(6, "nmonqnmomnmomomno");
632 // 7 CANDLE (second variety)
633 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
635 // 8 CANDLE (third variety)
636 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
638 // 9 SLOW STROBE (fourth variety)
639 lightstyle(9, "aaaaaaaazzzzzzzz");
641 // 10 FLUORESCENT FLICKER
642 lightstyle(10, "mmamammmmammamamaaamammma");
644 // 11 SLOW PULSE NOT FADE TO BLACK
645 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
647 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
652 if(cvar("g_campaign"))
655 Map_MarkAsRecent(mapname);
657 precache_model ("null"); // we need this one before InitGameplayMode
665 bot_waypoints_for_items = cvar("g_waypoints_for_items");
666 if(bot_waypoints_for_items == 1)
667 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
668 bot_waypoints_for_items = 0;
670 // for setting by mapinfo
671 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
672 cvar_set("sv_q3acompat_machineshotgunswap", "0");
676 WaypointSprite_Init();
681 GameLogInit(); // prepare everything
682 if(cvar("sv_eventlog"))
684 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
685 s = strcat(s, ftos(random()));
686 matchid = strzone(s);
688 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
689 s = ":gameinfo:mutators:LIST";
692 MUTATOR_CALLHOOK(BuildMutatorsString);
695 if(cvar("g_grappling_hook"))
696 s = strcat(s, ":grappling_hook");
697 if(!cvar("g_use_ammunition"))
698 s = strcat(s, ":no_use_ammunition");
699 if(!cvar("g_pickup_items"))
700 s = strcat(s, ":no_pickup_items");
701 if(cvar_string("g_weaponarena") != "0")
702 s = strcat(s, ":", cvar_string("g_weaponarena"), " arena");
703 if(cvar("g_vampire"))
704 s = strcat(s, ":vampire");
705 if(cvar("g_laserguided_missile"))
706 s = strcat(s, ":laserguided_missile");
707 if(cvar("g_norecoil"))
708 s = strcat(s, ":norecoil");
710 s = strcat(s, ":midair");
711 if(cvar("g_minstagib"))
712 s = strcat(s, ":minstagib");
714 GameLogEcho(":gameinfo:end");
717 matchid = strzone(ftos(random()));
719 cvar_set("nextmap", "");
723 if(cvar("g_campaign"))
731 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
733 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
735 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
738 while((s = fgets(fd)))
740 l = tokenize_console(s);
745 print("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
746 print(" cdtrack ", argv(2), "\n");
748 else if(argv(0) == "fog")
750 print("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
751 print(" \"fog\" \"", s, "\"\n");
753 else if(argv(0) == "set")
755 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
756 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
758 else if(argv(0) != "//")
760 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
761 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
770 addstat(STAT_WEAPONS, AS_INT, weapons);
771 addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
772 addstat(STAT_GAMESTARTTIME, AS_FLOAT, stat_game_starttime);
773 addstat(STAT_ALLOW_OLDNEXBEAM, AS_INT, stat_allow_oldnexbeam);
776 addstat(STAT_STRENGTH_FINISHED, AS_FLOAT, strength_finished);
777 addstat(STAT_INVINCIBLE_FINISHED, AS_FLOAT, invincible_finished);
778 addstat(STAT_PRESSED_KEYS, AS_FLOAT, pressedkeys);
779 addstat(STAT_FUEL, AS_INT, ammo_fuel);
780 addstat(STAT_DAMAGE_HITS, AS_INT, stat_hit);
781 addstat(STAT_DAMAGE_FIRED, AS_INT, stat_fired);
782 addstat(STAT_SHOTORG, AS_INT, stat_shotorg);
783 addstat(STAT_LEADLIMIT, AS_FLOAT, stat_leadlimit);
784 addstat(STAT_BULLETS_LOADED, AS_INT, campingrifle_bulletcounter);
785 addstat(STAT_LAST_PICKUP, AS_FLOAT, last_pickup);
787 addstat(STAT_NEX_CHARGE, AS_FLOAT, nex_charge);
791 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
792 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
794 // g_movementspeed hack
795 addstat(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW, AS_FLOAT, stat_sv_airspeedlimit_nonqw);
796 addstat(STAT_MOVEVARS_AIRACCEL_QW, AS_FLOAT, stat_sv_airaccel_qw);
797 addstat(STAT_MOVEVARS_AIRSTRAFEACCEL_QW, AS_FLOAT, stat_sv_airstrafeaccel_qw);
799 next_pingtime = time + 5;
803 lsmaps_reply = "^7Maps available: ";
804 lsnewmaps_reply = "^7Maps without a record set: ";
805 for(i = 0, j = 0; i < MapInfo_count; ++i)
807 if(MapInfo_Get_ByID(i))
808 if not(MapInfo_Map_flags & (MAPINFO_FLAG_HIDDEN | MAPINFO_FLAG_FORBIDDEN))
815 lsmaps_reply = strcat(lsmaps_reply, col, MapInfo_Map_bspname, " ");
816 if(g_race && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "time"))))
817 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
818 else if(g_cts && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "time"))))
819 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
822 lsmaps_reply = strzone(strcat(lsmaps_reply, "\n"));
823 if (!g_race && !g_cts)
824 lsnewmaps_reply = "Need to be playing race or CTS for lsnewmaps to work.";
825 lsnewmaps_reply = strzone(strcat(lsnewmaps_reply, "\n"));
827 maplist_reply = "^7Maps in list: ";
828 n = tokenize_console(cvar_string("g_maplist"));
829 for(i = 0, j = 0; i < n; ++i)
831 if(MapInfo_CheckMap(argv(i)))
837 maplist_reply = strcat(maplist_reply, col, argv(i), " ");
841 maplist_reply = strzone(strcat(maplist_reply, "\n"));
842 MapInfo_ClearTemps();
844 for(i = 0; i < 10; ++i)
846 records_reply[i] = strzone(getrecords(i));
849 ladder_reply = strzone(getladder());
851 rankings_reply = strzone(getrankings());
855 PingPLReport_Spawn();
859 localcmd("\n_sv_hook_gamestart ", GetGametype(), "\n");
861 // fill sv_curl_serverpackages from .serverpackage files
862 if(cvar("sv_curl_serverpackages_auto"))
864 fd = search_begin("*.serverpackage", TRUE, FALSE);
868 j = search_getsize(fd);
869 for(i = 0; i < j; ++i)
870 s = strcat(s, " ", search_getfilename(fd, i));
873 cvar_set("sv_curl_serverpackages", substring(s, 1, -1));
876 world_initialized = 1;
879 void spawnfunc_light (void)
881 //makestatic (self); // Who the f___ did that?
885 float TryFile( string pFilename )
888 dprint("TryFile(\"", pFilename, "\")\n");
889 lHandle = fopen( pFilename, FILE_READ );
890 if( lHandle != -1 ) {
900 return GametypeNameFromType(game);
903 string getmapname_stored;
909 float Map_Count, Map_Current;
910 string Map_Current_Name;
912 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
913 float GetMaplistPosition()
919 idx = cvar("g_maplist_index");
926 for(pos = 0; pos < Map_Count; ++pos)
930 // resume normal maplist rotation if current map is not in g_maplist
934 float MapHasRightSize(string map)
937 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
938 if(cvar("g_maplist_check_waypoints"))
940 dprint("checkwp "); dprint(map);
941 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
944 dprint(": no waypoints\n");
947 dprint(": has waypoints\n");
951 // open map size restriction file
952 dprint("opensize "); dprint(map);
953 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
956 float mapmin, mapmax;
958 mapmin = stof(fgets(fh));
959 mapmax = stof(fgets(fh));
961 if(player_count < mapmin)
963 dprint("not enough\n");
966 if(player_count > mapmax)
968 dprint("too many\n");
971 dprint("right size\n");
974 dprint(": not found\n");
978 string Map_Filename(float position)
980 return strcat("maps/", argv(position), ".bsp");
983 string strwords(string s, float w)
986 for(endpos = 0; w && endpos >= 0; --w)
987 endpos = strstrofs(s, " ", endpos + 1);
991 return substring(s, 0, endpos);
994 float strhasword(string s, string w)
996 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
999 void Map_MarkAsRecent(string m)
1001 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), max(0, cvar("g_maplist_mostrecent_count"))));
1004 float Map_IsRecent(string m)
1006 return strhasword(cvar_string("g_maplist_mostrecent"), m);
1009 float Map_Check(float position, float pass)
1013 map_next = argv(position);
1016 if(Map_IsRecent(map_next))
1019 filename = Map_Filename(position);
1020 if(MapInfo_CheckMap(map_next))
1024 if(MapHasRightSize(map_next))
1029 dprint( "Couldn't select '", filename, "'..\n" );
1034 void Map_Goto_SetStr(string nextmapname)
1036 if(getmapname_stored != "")
1037 strunzone(getmapname_stored);
1038 if(nextmapname == "")
1039 getmapname_stored = "";
1041 getmapname_stored = strzone(nextmapname);
1044 void Map_Goto_SetFloat(float position)
1046 cvar_set("g_maplist_index", ftos(position));
1047 Map_Goto_SetStr(argv(position));
1052 // settings persist, except...
1053 localcmd("\nsettemp_restore\n");
1059 MapInfo_LoadMap(getmapname_stored);
1062 // return codes of map selectors:
1063 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
1064 // -2 = permanent failure
1065 float() MaplistMethod_Iterate = // usual method
1069 for(pass = 1; pass <= 2; ++pass)
1071 for(i = 1; i < Map_Count; ++i)
1074 mapindex = mod(i + Map_Current, Map_Count);
1075 if(Map_Check(mapindex, pass))
1082 float() MaplistMethod_Repeat = // fallback method
1084 if(Map_Check(Map_Current, 2))
1089 float() MaplistMethod_Random = // random map selection
1095 for(i = 0; i <= imax; ++i)
1098 mapindex = mod(Map_Current + floor(random() * (Map_Count - 1) + 1), Map_Count); // any OTHER map
1099 if(Map_Check(mapindex, 1))
1105 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
1106 // the exponent sets a bias on the map selection:
1107 // the higher the exponent, the less likely "shortly repeated" same maps are
1109 float i, j, imax, insertpos;
1113 for(i = 0; i <= imax; ++i)
1117 // now reinsert this at another position
1118 insertpos = pow(random(), 1 / exponent); // ]0, 1]
1119 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
1120 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
1121 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
1123 // insert the current map there
1125 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
1126 newlist = strcat(newlist, " ", argv(j));
1127 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
1128 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
1129 newlist = strcat(newlist, " ", argv(j));
1130 newlist = substring(newlist, 1, strlen(newlist) - 1);
1131 cvar_set("g_maplist", newlist);
1132 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
1134 // NOTE: the selected map has just been inserted at (insertpos-1)th position
1135 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
1136 if(Map_Check(Map_Current, 1))
1144 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
1147 bprint( "Maplist is empty! Resetting it to default map list.\n" );
1148 cvar_set("g_maplist", MapInfo_ListAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
1149 if(cvar("g_maplist_shuffle"))
1151 localcmd("\nmenu_cmd sync\n");
1152 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
1155 error("empty maplist, cannot select a new map");
1156 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
1158 if(Map_Current_Name)
1159 strunzone(Map_Current_Name);
1160 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
1161 // this may or may not be correct, but who cares, in the worst case a map
1162 // isn't chosen in the first pass that should have been
1173 if(cvar("g_maplist_shuffle") > 0)
1174 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
1177 if(cvar("g_maplist_selectrandom"))
1178 nextMap = MaplistMethod_Random();
1181 nextMap = MaplistMethod_Iterate();
1184 nextMap = MaplistMethod_Repeat();
1188 Map_Goto_SetFloat(nextMap);
1189 return getmapname_stored;
1195 float DoNextMapOverride()
1197 if(cvar("g_campaign"))
1199 CampaignPostIntermission();
1200 alreadychangedlevel = TRUE;
1203 if(cvar("quit_when_empty"))
1205 if(player_count <= currentbots)
1208 alreadychangedlevel = TRUE;
1212 if(cvar_string("quit_and_redirect") != "")
1214 redirection_target = strzone(cvar_string("quit_and_redirect"));
1215 alreadychangedlevel = TRUE;
1218 if (cvar("samelevel")) // if samelevel is set, stay on same level
1220 // 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)
1221 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
1222 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
1223 localcmd("restart\n");
1224 //changelevel (mapname);
1225 alreadychangedlevel = TRUE;
1228 if(cvar_string("nextmap") != "")
1229 if(MapInfo_CheckMap(cvar_string("nextmap")))
1231 Map_Goto_SetStr(cvar_string("nextmap"));
1233 alreadychangedlevel = TRUE;
1236 if(cvar("lastlevel"))
1239 localcmd("set lastlevel 0\ntogglemenu\n");
1240 alreadychangedlevel = TRUE;
1248 //local string nextmap;
1249 //local float n, nummaps;
1251 if (alreadychangedlevel)
1253 alreadychangedlevel = TRUE;
1259 for(allowReset = 1; allowReset >= 0; --allowReset)
1261 nextMap = GetNextMap();
1267 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1268 cvar_set("g_maplist", MapInfo_ListAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
1269 if(cvar("g_maplist_shuffle"))
1271 localcmd("\nmenu_cmd sync\n");
1275 error("Everything is broken - not even the default map list works. Please report this to the developers.");
1287 When the player presses attack or jump, change to the next level
1290 .float autoscreenshot;
1291 void() MapVote_Start;
1292 void() MapVote_Think;
1293 float mapvote_initialized;
1294 void IntermissionThink()
1296 FixIntermissionClient(self);
1298 if(cvar("sv_autoscreenshot"))
1299 if(self.autoscreenshot > 0)
1300 if(time > self.autoscreenshot)
1302 self.autoscreenshot = -1;
1303 if(clienttype(self) == CLIENTTYPE_REAL)
1304 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
1308 if (time < intermission_exittime)
1311 if(!mapvote_initialized)
1312 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
1322 Returns the entity to view from
1326 entity FindIntermission()
1331 // look for info_intermission first
1332 spot = find (world, classname, "info_intermission");
1334 { // pick a random one
1338 spot = find (spot, classname, "info_intermission");
1340 spot = find (spot, classname, "info_intermission");
1346 // then look for the start position
1347 spot = find (world, classname, "info_player_start");
1351 // testinfo_player_start is only found in regioned levels
1352 spot = find (world, classname, "testplayerstart");
1356 // then look for the start position
1357 spot = find (world, classname, "info_player_deathmatch");
1361 //objerror ("FindIntermission: no spot");
1367 ===============================================================================
1371 ===============================================================================
1374 void DumpStats(float final)
1378 local float to_console;
1379 local float to_eventlog;
1380 local float to_file;
1383 to_console = cvar("sv_logscores_console");
1384 to_eventlog = cvar("sv_eventlog");
1385 to_file = cvar("sv_logscores_file");
1389 to_console = TRUE; // always print printstats replies
1390 to_eventlog = FALSE; // but never print them to the event log
1394 if(cvar("sv_eventlog_console"))
1395 to_console = FALSE; // otherwise we get the output twice
1401 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
1409 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
1413 fputs(file, strcat(s, "\n"));
1416 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
1422 fputs(file, strcat(s, "\n"));
1424 FOR_EACH_CLIENT(other)
1426 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
1428 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
1429 s = strcat(s, ftos(rint(time - other.jointime)), ":");
1430 if(other.classname == "player" || g_arena || g_ca || g_lms)
1431 s = strcat(s, ftos(other.team), ":");
1433 s = strcat(s, "spectator:");
1436 print(s, other.netname, "\n");
1438 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
1440 fputs(file, strcat(s, other.netname, "\n"));
1446 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
1452 fputs(file, strcat(s, "\n"));
1454 for(i = 1; i < 16; ++i)
1456 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
1457 s = strcat(s, ":", ftos(i));
1463 fputs(file, strcat(s, "\n"));
1470 GameLogEcho(":end");
1473 fputs(file, ":end\n");
1478 void FixIntermissionClient(entity e)
1481 if(!e.autoscreenshot) // initial call
1483 e.angles = e.v_angle;
1484 e.angles_x = -e.angles_x;
1485 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1487 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1488 e.solid = SOLID_NOT;
1489 e.movetype = MOVETYPE_NONE;
1490 e.takedamage = DAMAGE_NO;
1493 e.weaponentity.effects = EF_NODRAW;
1494 if (e.weaponentity.weaponentity)
1495 e.weaponentity.weaponentity.effects = EF_NODRAW;
1497 if(clienttype(e) == CLIENTTYPE_REAL)
1499 stuffcmd(e, "\nscr_printspeed 1000000\n");
1500 s = cvar_string("sv_intermission_cdtrack");
1502 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1504 WriteByte(MSG_ONE, SVC_INTERMISSION);
1508 //e.velocity = '0 0 0';
1509 //e.fixangle = TRUE;
1511 // TODO halt weapon animation
1516 go to the next level for deathmatch
1517 only called if a time or frag limit has expired
1525 intermission_running = 1;
1527 // enforce a wait time before allowing changelevel
1528 if(player_count > 0)
1529 intermission_exittime = time + cvar("sv_mapchange_delay");
1531 intermission_exittime = -1;
1534 WriteByte (MSG_ALL, SVC_CDTRACK);
1535 WriteByte (MSG_ALL, 3);
1536 WriteByte (MSG_ALL, 3);
1537 // done in FixIntermission
1540 //pos = FindIntermission ();
1546 if(cvar("sv_eventlog"))
1547 GameLogEcho(":gameover");
1553 // save the stats to a text file on the client
1554 // stuffcmd(other, log_stats "stats/file_name");
1556 // stuffcmd(other, log_stats "");
1557 // use a filename similar to the demo name
1558 // string file_name;
1559 // file_name = strcat("\nlog_file \"stats/", strftime(TRUE, "%Y-%m-%d_%H-%M"), "_", mapname, ".txt\""); // open the log file
1561 // write a stats parser for the menu
1563 if(cvar("sv_accuracy_data_send")) {
1564 string stats_to_send;
1566 FOR_EACH_CLIENT(other) { // make the string to send
1567 FixIntermissionClient(other);
1569 if(other.cvar_cl_accuracy_data_share) {
1570 stats_to_send = strcat(stats_to_send, ":hits:", other.netname);
1572 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1573 stats_to_send = strcat(stats_to_send, ":", ftos(other.stats_hit[i-1]));
1575 stats_to_send = strcat(stats_to_send, "\n:fired:", other.netname);
1577 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1578 stats_to_send = strcat(stats_to_send, ":", ftos(other.stats_fired[i-1]));
1580 stats_to_send = strcat(stats_to_send, "\n");
1584 FOR_EACH_REALCLIENT(other) { // only spam humans
1585 Score_NicePrint(other); // print the score
1587 if(other.cvar_cl_accuracy_data_receive) // send the stats string to all the willing clients
1588 bprint(stats_to_send);
1590 } else { // ye olde message
1591 FOR_EACH_PLAYER(other) {
1592 FixIntermissionClient(other);
1595 bprint(other.netname, " ^7wins.\n");
1599 if(cvar("g_campaign"))
1600 CampaignPreIntermission();
1602 localcmd("\nsv_hook_gameend\n");
1609 Exit deathmatch games upon conditions
1612 void CheckRules_Player()
1614 if (gameover) // someone else quit the game already
1617 if(self.deadflag == DEAD_NO)
1618 self.play_time += frametime;
1620 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1621 // (div0: and that in CheckRules_World please)
1624 float checkrules_equality;
1625 float checkrules_suddendeathwarning;
1626 float checkrules_suddendeathend;
1627 float checkrules_overtimesadded; //how many overtimes have been already added
1629 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1630 float WINNING_YES = 1; // winner found
1631 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1632 float WINNING_STARTSUDDENDEATHOVERTIME = 3; // no winner, enter suddendeath overtime NOW
1634 float InitiateSuddenDeath()
1636 // Check first whether normal overtimes could be added before initiating suddendeath mode
1637 // - for this timelimit_overtime needs to be >0 of course
1638 // - also check the winning condition calculated in the previous frame and only add normal overtime
1639 // again, if at the point at which timelimit would be extended again, still no winner was found
1640 if ((checkrules_overtimesadded >= 0) && (checkrules_overtimesadded < cvar("timelimit_overtimes")) && cvar("timelimit_overtime") && !(g_race && !g_race_qualifying))
1642 return 1; // need to call InitiateOvertime later
1646 if(!checkrules_suddendeathend)
1648 checkrules_suddendeathend = time + 60 * cvar("timelimit_suddendeath");
1649 if(g_race && !g_race_qualifying)
1650 race_StartCompleting();
1656 void InitiateOvertime() // ONLY call this if InitiateSuddenDeath returned true
1658 ++checkrules_overtimesadded;
1659 //add one more overtime by simply extending the timelimit
1661 tl = cvar("timelimit");
1662 tl += cvar("timelimit_overtime");
1663 cvar_set("timelimit", ftos(tl));
1664 string minutesPlural;
1665 if (cvar("timelimit_overtime") == 1)
1666 minutesPlural = " ^3minute";
1668 minutesPlural = " ^3minutes";
1672 "^3Now playing ^1OVERTIME^3!\n\n^3Added ^1",
1673 ftos(cvar("timelimit_overtime")),
1680 float GetWinningCode(float fraglimitreached, float equality)
1682 if(cvar("g_campaign") == 1)
1683 if(fraglimitreached)
1690 if(fraglimitreached)
1691 return WINNING_STARTSUDDENDEATHOVERTIME;
1693 return WINNING_NEVER;
1695 if(fraglimitreached)
1701 // set the .winning flag for exactly those players with a given field value
1702 void SetWinners(.float field, float value)
1705 FOR_EACH_PLAYER(head)
1706 head.winning = (head.field == value);
1709 // set the .winning flag for those players with a given field value
1710 void AddWinners(.float field, float value)
1713 FOR_EACH_PLAYER(head)
1714 if(head.field == value)
1718 // clear the .winning flags
1719 void ClearWinners(void)
1722 FOR_EACH_PLAYER(head)
1726 // Onslaught winning condition:
1727 // game terminates if only one team has a working generator (or none)
1728 float WinningCondition_Onslaught()
1731 local float t1, t2, t3, t4;
1733 WinningConditionHelper(); // set worldstatus
1738 // first check if the game has ended
1739 t1 = t2 = t3 = t4 = 0;
1740 head = find(world, classname, "onslaught_generator");
1743 if (head.health > 0)
1745 if (head.team == COLOR_TEAM1) t1 = 1;
1746 if (head.team == COLOR_TEAM2) t2 = 1;
1747 if (head.team == COLOR_TEAM3) t3 = 1;
1748 if (head.team == COLOR_TEAM4) t4 = 1;
1750 head = find(head, classname, "onslaught_generator");
1752 if (t1 + t2 + t3 + t4 < 2)
1754 // game over, only one team remains (or none)
1756 if (t1) SetWinners(team, COLOR_TEAM1);
1757 if (t2) SetWinners(team, COLOR_TEAM2);
1758 if (t3) SetWinners(team, COLOR_TEAM3);
1759 if (t4) SetWinners(team, COLOR_TEAM4);
1760 dprint("Have a winner, ending game.\n");
1764 // Two or more teams remain
1768 float LMS_NewPlayerLives()
1771 fl = cvar("fraglimit");
1775 // first player has left the game for dying too much? Nobody else can get in.
1776 if(lms_lowest_lives < 1)
1779 if(!cvar("g_lms_join_anytime"))
1780 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1783 return bound(1, lms_lowest_lives, fl);
1786 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1787 // they win. Otherwise the defending team wins once the timelimit passes.
1788 void assault_new_round();
1789 float WinningCondition_Assault()
1793 WinningConditionHelper(); // set worldstatus
1795 status = WINNING_NO;
1796 // as the timelimit has not yet passed just assume the defending team will win
1797 if(assault_attacker_team == COLOR_TEAM1)
1799 SetWinners(team, COLOR_TEAM2);
1803 SetWinners(team, COLOR_TEAM1);
1807 ent = find(world, classname, "target_assault_roundend");
1810 if(ent.winning) // round end has been triggered by attacking team
1812 bprint("ASSAULT: round completed...\n");
1813 SetWinners(team, assault_attacker_team);
1815 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
1817 if(ent.cnt == 1 || cvar("g_campaign")) // this was the second round
1819 status = WINNING_YES;
1823 local entity oldself;
1826 assault_new_round();
1835 // LMS winning condition: game terminates if and only if there's at most one
1836 // one player who's living lives. Top two scores being equal cancels the time
1838 float WinningCondition_LMS()
1845 have_player = FALSE;
1846 have_players = FALSE;
1847 l = LMS_NewPlayerLives();
1849 head = find(world, classname, "player");
1852 head2 = find(head, classname, "player");
1854 have_players = TRUE;
1858 // we have at least one player
1861 // two or more active players - continue with the game
1865 // exactly one player?
1868 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1872 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1878 // and assign him his first place
1879 PlayerScore_Add(head, SP_LMS_RANK, 1);
1886 // nobody is playing at all...
1889 // wait for players...
1893 // SNAFU (maybe a draw game?)
1895 dprint("No players, ending game.\n");
1900 // When we get here, we have at least two players who are actually LIVING,
1901 // now check if the top two players have equal score.
1902 WinningConditionHelper();
1905 if(WinningConditionHelper_winner)
1906 WinningConditionHelper_winner.winning = TRUE;
1907 if(WinningConditionHelper_topscore == WinningConditionHelper_secondscore)
1908 return WINNING_NEVER;
1910 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1914 void ShuffleMaplist()
1916 cvar_set("g_maplist", shufflewords(cvar_string("g_maplist")));
1920 float WinningCondition_Scores(float limit, float leadlimit)
1924 // TODO make everything use THIS winning condition (except LMS)
1925 WinningConditionHelper();
1929 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1930 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1931 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1932 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1936 if(WinningConditionHelper_winner)
1937 WinningConditionHelper_winner.winning = 1;
1938 if(WinningConditionHelper_winnerteam >= 0)
1939 SetWinners(team, WinningConditionHelper_winnerteam);
1941 if(WinningConditionHelper_lowerisbetter)
1943 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1944 WinningConditionHelper_secondscore = -WinningConditionHelper_secondscore;
1948 if(WinningConditionHelper_zeroisworst)
1949 leadlimit = 0; // not supported in this mode
1951 if(g_dm || g_tdm || g_arena || g_ca || (g_race && !g_race_qualifying) || g_nexball)
1952 // these modes always score in increments of 1, thus this makes sense
1954 if(leaderfrags != WinningConditionHelper_topscore)
1956 leaderfrags = WinningConditionHelper_topscore;
1959 if (leaderfrags == limit - 1)
1960 Announce("1fragleft");
1961 else if (leaderfrags == limit - 2)
1962 Announce("2fragsleft");
1963 else if (leaderfrags == limit - 3)
1964 Announce("3fragsleft");
1968 limitreached = FALSE;
1970 if(WinningConditionHelper_topscore >= limit)
1971 limitreached = TRUE;
1974 float leadlimitreached;
1975 leadlimitreached = (WinningConditionHelper_topscore - WinningConditionHelper_secondscore >= leadlimit);
1976 if(cvar("leadlimit_and_fraglimit"))
1977 limitreached = (limitreached && leadlimitreached);
1979 limitreached = (limitreached || leadlimitreached);
1982 return GetWinningCode(
1983 WinningConditionHelper_topscore && limitreached,
1984 WinningConditionHelper_equality
1988 float WinningCondition_Race(float fraglimit)
1999 if(p.race_completed)
2004 wc = WinningCondition_Scores(fraglimit, 0);
2006 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
2007 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
2008 // do NOT support equality when the laps are all raced!
2009 return WINNING_STARTSUDDENDEATHOVERTIME;
2011 return WINNING_NEVER;
2015 void ReadyRestart();
2016 float WinningCondition_QualifyingThenRace(float limit)
2019 wc = WinningCondition_Scores(limit, 0);
2021 // NEVER initiate overtime
2022 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
2030 float WinningCondition_RanOutOfSpawns()
2034 if(have_team_spawns <= 0)
2037 if(!some_spawn_has_been_used)
2040 team1_score = team2_score = team3_score = team4_score = 0;
2042 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
2044 if(head.team == COLOR_TEAM1)
2046 else if(head.team == COLOR_TEAM2)
2048 else if(head.team == COLOR_TEAM3)
2050 else if(head.team == COLOR_TEAM4)
2054 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
2056 if(head.team == COLOR_TEAM1)
2058 else if(head.team == COLOR_TEAM2)
2060 else if(head.team == COLOR_TEAM3)
2062 else if(head.team == COLOR_TEAM4)
2067 if(team1_score + team2_score + team3_score + team4_score == 0)
2069 checkrules_equality = TRUE;
2072 else if(team1_score + team2_score + team3_score + team4_score == 1)
2075 if(team1_score) t = COLOR_TEAM1;
2076 if(team2_score) t = COLOR_TEAM2;
2077 if(team3_score) t = COLOR_TEAM3;
2078 if(team4_score) t = COLOR_TEAM4;
2079 CheckAllowedTeams(world);
2080 for(i = 0; i < MAX_TEAMSCORE; ++i)
2082 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
2083 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
2084 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
2085 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
2088 AddWinners(team, t);
2099 Exit deathmatch games upon conditions
2102 void CheckRules_World()
2114 MapVote_Think should now do that part
2115 if (intermission_running)
2116 if (time >= intermission_exittime + 60)
2118 if(!DoNextMapOverride())
2124 if (gameover) // someone else quit the game already
2126 if(player_count == 0) // Nobody there? Then let's go to the next map
2128 // this will actually check the player count in the next frame
2129 // again, but this shouldn't hurt
2133 timelimit = cvar("timelimit") * 60;
2134 fraglimit = cvar("fraglimit");
2135 leadlimit = cvar("leadlimit");
2137 if(inWarmupStage || time <= game_starttime) // NOTE: this is <= to prevent problems in the very tic where the game starts
2140 timelimit = 0; // timelimit is not made for warmup
2142 fraglimit = 0; // no fraglimit for now
2143 leadlimit = 0; // no leadlimit for now
2147 timelimit = 0; // ONS has its own overtime rule
2151 timelimit += game_starttime;
2153 else if (timelimit < 0)
2163 if(checkrules_suddendeathend)
2165 if(!checkrules_suddendeathwarning)
2167 checkrules_suddendeathwarning = TRUE;
2168 if(g_race && !g_race_qualifying)
2169 bcenterprint("^3Everyone, finish your lap! The race is over!");
2171 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
2176 if (timelimit && time >= timelimit)
2178 if(g_race && (g_race_qualifying == 2) && timelimit > 0)
2181 float playerswithlaps;
2184 totalplayers = playerswithlaps = readyplayers = 0;
2185 FOR_EACH_PLAYER(head)
2188 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
2194 // at least 2 of the players have completed a lap: start the RACE
2195 // otherwise, the players should end the qualifying on their own
2196 if(readyplayers || playerswithlaps >= 2)
2198 checkrules_suddendeathend = 0;
2199 ReadyRestart(); // go to race
2203 wantovertime |= InitiateSuddenDeath();
2206 wantovertime |= InitiateSuddenDeath();
2210 if (checkrules_suddendeathend && time >= checkrules_suddendeathend)
2216 float checkrules_status;
2217 checkrules_status = WinningCondition_RanOutOfSpawns();
2218 if(checkrules_status == WINNING_YES)
2220 bprint("Hey! Someone ran out of spawns!\n");
2222 else if(g_race && !g_race_qualifying && timelimit >= 0)
2224 checkrules_status = WinningCondition_Race(fraglimit);
2225 //print("WC_RACE yields ", ftos(checkrules_status), "\n");
2227 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
2229 checkrules_status = WinningCondition_QualifyingThenRace(fraglimit);
2230 //print("WC_QUALIFYING_THEN_RACE yields ", ftos(checkrules_status), "\n");
2234 checkrules_status = WinningCondition_Assault(); // TODO remove this?
2238 checkrules_status = WinningCondition_LMS();
2240 else if (g_onslaught)
2242 checkrules_status = WinningCondition_Onslaught(); // TODO remove this?
2246 checkrules_status = WinningCondition_Scores(fraglimit, leadlimit);
2247 //print("WC_SCORES yields ", ftos(checkrules_status), "\n");
2250 if(checkrules_status == WINNING_STARTSUDDENDEATHOVERTIME)
2252 checkrules_status = WINNING_NEVER;
2253 checkrules_overtimesadded = -1;
2254 wantovertime |= InitiateSuddenDeath();
2257 if(checkrules_status == WINNING_NEVER)
2258 // equality cases! Nobody wins if the overtime ends in a draw.
2263 if(checkrules_status == WINNING_NEVER)
2266 checkrules_status = WINNING_YES;
2269 if(checkrules_suddendeathend)
2270 if(checkrules_status != WINNING_NEVER || time >= checkrules_suddendeathend)
2271 checkrules_status = WINNING_YES;
2273 if(checkrules_status == WINNING_YES)
2275 //print("WINNING\n");
2280 float mapvote_nextthink;
2281 float mapvote_initialized;
2282 float mapvote_keeptwotime;
2283 float mapvote_timeout;
2284 string mapvote_message;
2285 #define MAPVOTE_SCREENSHOT_DIRS_COUNT 4
2286 string mapvote_screenshot_dirs[MAPVOTE_SCREENSHOT_DIRS_COUNT];
2287 float mapvote_screenshot_dirs_count;
2289 float mapvote_count;
2290 float mapvote_count_real;
2291 string mapvote_maps[MAPVOTE_COUNT];
2292 float mapvote_maps_screenshot_dir[MAPVOTE_COUNT];
2293 string mapvote_maps_pakfile[MAPVOTE_COUNT];
2294 float mapvote_maps_suggested[MAPVOTE_COUNT];
2295 string mapvote_suggestions[MAPVOTE_COUNT];
2296 float mapvote_suggestion_ptr;
2297 float mapvote_maxlen;
2298 float mapvote_voters;
2299 float mapvote_votes[MAPVOTE_COUNT];
2301 float mapvote_detail;
2302 float mapvote_abstain;
2305 void MapVote_ClearAllVotes()
2307 FOR_EACH_CLIENT(other)
2311 string MapVote_Suggest(string m)
2315 return "That's not how to use this command.";
2316 if(!cvar("g_maplist_votable_suggestions"))
2317 return "Suggestions are not accepted on this server.";
2318 if(mapvote_initialized)
2319 return "Can't suggest - voting is already in progress!";
2320 m = MapInfo_FixName(m);
2322 return "The map you suggested is not available on this server.";
2323 if(!cvar("g_maplist_votable_suggestions_override_mostrecent"))
2325 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
2327 if(!MapInfo_CheckMap(m))
2328 return "The map you suggested does not support the current game mode.";
2329 for(i = 0; i < mapvote_suggestion_ptr; ++i)
2330 if(mapvote_suggestions[i] == m)
2331 return "This map was already suggested.";
2332 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
2334 i = floor(random() * mapvote_suggestion_ptr);
2338 i = mapvote_suggestion_ptr;
2339 mapvote_suggestion_ptr += 1;
2341 if(mapvote_suggestions[i] != "")
2342 strunzone(mapvote_suggestions[i]);
2343 mapvote_suggestions[i] = strzone(m);
2344 if(cvar("sv_eventlog"))
2345 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
2346 return strcat("Suggestion of ", m, " accepted.");
2349 void MapVote_AddVotable(string nextMap, float isSuggestion)
2352 string pakfile, mapfile;
2356 for(j = 0; j < mapvote_count; ++j)
2357 if(mapvote_maps[j] == nextMap)
2359 if(strlen(nextMap) > mapvote_maxlen)
2360 mapvote_maxlen = strlen(nextMap);
2361 mapvote_maps[mapvote_count] = strzone(nextMap);
2362 mapvote_maps_suggested[mapvote_count] = isSuggestion;
2364 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2366 mapfile = strcat(mapvote_screenshot_dirs[i], "/", mapvote_maps[i]);
2367 pakfile = whichpack(strcat(mapfile, ".tga"));
2369 pakfile = whichpack(strcat(mapfile, ".jpg"));
2371 pakfile = whichpack(strcat(mapfile, ".png"));
2375 if(i >= mapvote_screenshot_dirs_count)
2376 i = 0; // FIXME maybe network this error case, as that means there is no mapshot on the server?
2377 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
2378 pakfile = substring(pakfile, o, -1);
2380 mapvote_maps_screenshot_dir[mapvote_count] = i;
2381 mapvote_maps_pakfile[mapvote_count] = strzone(pakfile);
2386 void MapVote_Spawn();
2392 MapVote_ClearAllVotes();
2395 mapvote_detail = !cvar("g_maplist_votable_nodetail");
2396 mapvote_abstain = cvar("g_maplist_votable_abstain");
2399 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
2401 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
2402 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
2404 // we need this for AddVotable, as that cycles through the screenshot dirs
2405 mapvote_screenshot_dirs_count = tokenize_console(cvar_string("g_maplist_votable_screenshot_dir"));
2406 if(mapvote_screenshot_dirs_count == 0)
2407 mapvote_screenshot_dirs_count = tokenize_console("maps levelshots");
2408 mapvote_screenshot_dirs_count = min(mapvote_screenshot_dirs_count, MAPVOTE_SCREENSHOT_DIRS_COUNT);
2409 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2410 mapvote_screenshot_dirs[i] = strzone(argv(i));
2412 if(mapvote_suggestion_ptr)
2413 for(i = 0; i < 100 && mapvote_count < smax; ++i)
2414 MapVote_AddVotable(mapvote_suggestions[floor(random() * mapvote_suggestion_ptr)], TRUE);
2416 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2417 MapVote_AddVotable(GetNextMap(), FALSE);
2419 if(mapvote_count == 0)
2421 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
2422 cvar_set("g_maplist", MapInfo_ListAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
2423 if(cvar("g_maplist_shuffle"))
2425 localcmd("\nmenu_cmd sync\n");
2426 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2427 MapVote_AddVotable(GetNextMap(), FALSE);
2430 mapvote_count_real = mapvote_count;
2432 MapVote_AddVotable("don't care", 0);
2434 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
2436 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
2437 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
2438 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
2439 mapvote_keeptwotime = 0;
2440 mapvote_message = "Choose a map and press its key!";
2445 void MapVote_SendPicture(float id)
2448 WriteByte(MSG_ONE, SVC_TEMPENTITY);
2449 WriteByte(MSG_ONE, TE_CSQC_PICTURE);
2450 WriteByte(MSG_ONE, id);
2451 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dirs[mapvote_maps_screenshot_dir[id]], "/", mapvote_maps[id]), 3072);
2454 float GameCommand_MapVote(string cmd)
2456 if(!intermission_running)
2459 if(cmd == "mv_getpic")
2461 MapVote_SendPicture(stof(argv(1)));
2468 float MapVote_GetMapMask()
2470 float mask, i, power;
2472 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
2473 if(mapvote_maps[i] != "")
2479 float MapVote_SendEntity(entity to, float sf)
2484 sf &~= 2; // if we send 1, we don't need to also send 2
2486 WriteByte(MSG_ENTITY, ENT_CLIENT_MAPVOTE);
2487 WriteByte(MSG_ENTITY, sf);
2491 // flag 1 == initialization
2492 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2493 WriteString(MSG_ENTITY, mapvote_screenshot_dirs[i]);
2494 WriteString(MSG_ENTITY, "");
2495 WriteByte(MSG_ENTITY, mapvote_count);
2496 WriteByte(MSG_ENTITY, mapvote_abstain);
2497 WriteByte(MSG_ENTITY, mapvote_detail);
2498 WriteCoord(MSG_ENTITY, mapvote_timeout);
2499 if(mapvote_count <= 8)
2500 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2502 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2503 for(i = 0; i < mapvote_count; ++i)
2504 if(mapvote_maps[i] != "")
2506 if(mapvote_abstain && i == mapvote_count - 1)
2508 WriteString(MSG_ENTITY, ""); // abstain needs no text
2509 WriteString(MSG_ENTITY, ""); // abstain needs no pack
2510 WriteByte(MSG_ENTITY, 0); // abstain needs no screenshot dir
2514 WriteString(MSG_ENTITY, mapvote_maps[i]);
2515 WriteString(MSG_ENTITY, mapvote_maps_pakfile[i]);
2516 WriteByte(MSG_ENTITY, mapvote_maps_screenshot_dir[i]);
2523 // flag 2 == update of mask
2524 if(mapvote_count <= 8)
2525 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2527 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2533 for(i = 0; i < mapvote_count; ++i)
2534 if(mapvote_maps[i] != "")
2535 WriteByte(MSG_ENTITY, mapvote_votes[i]);
2537 WriteByte(MSG_ENTITY, to.mapvote);
2543 void MapVote_Spawn()
2545 Net_LinkEntity(mapvote_ent = spawn(), FALSE, 0, MapVote_SendEntity);
2548 void MapVote_TouchMask()
2550 mapvote_ent.SendFlags |= 2;
2553 void MapVote_TouchVotes(entity voter)
2555 mapvote_ent.SendFlags |= 4;
2558 float MapVote_Finished(float mappos)
2564 if(cvar("sv_eventlog"))
2566 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2567 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
2568 didntvote = mapvote_voters;
2569 for(i = 0; i < mapvote_count; ++i)
2570 if(mapvote_maps[i] != "")
2572 didntvote -= mapvote_votes[i];
2575 result = strcat(result, ":", mapvote_maps[i]);
2576 result = strcat(result, ":", ftos(mapvote_votes[i]));
2579 result = strcat(result, ":didn't vote:", ftos(didntvote));
2581 GameLogEcho(result);
2582 if(mapvote_maps_suggested[mappos])
2583 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
2586 FOR_EACH_REALCLIENT(other)
2587 FixClientCvars(other);
2589 Map_Goto_SetStr(mapvote_maps[mappos]);
2591 alreadychangedlevel = TRUE;
2594 void MapVote_CheckRules_1()
2598 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2600 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2601 mapvote_votes[i] = 0;
2605 FOR_EACH_REALCLIENT(other)
2610 i = other.mapvote - 1;
2611 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2612 mapvote_votes[i] = mapvote_votes[i] + 1;
2617 float MapVote_CheckRules_2()
2620 float firstPlace, secondPlace;
2621 float firstPlaceVotes, secondPlaceVotes;
2622 float mapvote_voters_real;
2625 if(mapvote_count_real == 1)
2626 return MapVote_Finished(0);
2628 mapvote_voters_real = mapvote_voters;
2630 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2632 RandomSelection_Init();
2633 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2634 RandomSelection_Add(world, i, string_null, 1, mapvote_votes[i]);
2635 firstPlace = RandomSelection_chosen_float;
2636 firstPlaceVotes = RandomSelection_best_priority;
2637 //dprint("First place: ", ftos(firstPlace), "\n");
2638 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2640 RandomSelection_Init();
2641 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2643 RandomSelection_Add(world, i, string_null, 1, mapvote_votes[i]);
2644 secondPlace = RandomSelection_chosen_float;
2645 secondPlaceVotes = RandomSelection_best_priority;
2646 //dprint("Second place: ", ftos(secondPlace), "\n");
2647 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2649 if(firstPlace == -1)
2650 error("No first place in map vote... WTF?");
2652 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2653 return MapVote_Finished(firstPlace);
2655 if(mapvote_keeptwotime)
2656 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2659 MapVote_TouchMask();
2660 mapvote_message = "Now decide between the TOP TWO!";
2661 mapvote_keeptwotime = 0;
2662 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2663 result = strcat(result, ":", ftos(firstPlaceVotes));
2664 result = strcat(result, ":", mapvote_maps[secondPlace]);
2665 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2666 didntvote = mapvote_voters;
2667 for(i = 0; i < mapvote_count; ++i)
2668 if(mapvote_maps[i] != "")
2670 didntvote -= mapvote_votes[i];
2672 if(i != secondPlace)
2674 result = strcat(result, ":", mapvote_maps[i]);
2675 result = strcat(result, ":", ftos(mapvote_votes[i]));
2676 if(i < mapvote_count_real)
2678 strunzone(mapvote_maps[i]);
2679 mapvote_maps[i] = "";
2680 strunzone(mapvote_maps_pakfile[i]);
2681 mapvote_maps_pakfile[i] = "";
2685 result = strcat(result, ":didn't vote:", ftos(didntvote));
2686 if(cvar("sv_eventlog"))
2687 GameLogEcho(result);
2697 keeptwo = mapvote_keeptwotime;
2698 MapVote_CheckRules_1(); // count
2699 if(MapVote_CheckRules_2()) // decide
2703 FOR_EACH_REALCLIENT(other)
2705 // hide scoreboard again
2706 if(other.health != 2342)
2708 other.health = 2342;
2710 if(clienttype(other) == CLIENTTYPE_REAL)
2713 WriteByte(MSG_ONE, SVC_FINALE);
2714 WriteString(MSG_ONE, "");
2718 // clear possibly invalid votes
2719 if(mapvote_maps[other.mapvote - 1] == "")
2721 // use impulses as new vote
2722 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2723 if(mapvote_maps[other.impulse - 1] != "")
2725 other.mapvote = other.impulse;
2726 MapVote_TouchVotes(other);
2734 MapVote_CheckRules_1(); // just count
2736 void MapVote_Start()
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(cvar("rescan_pending") == 1)
2763 cvar_set("rescan_pending", "2");
2764 localcmd("fs_rescan\nrescan_pending 3\n");
2767 else if(cvar("rescan_pending") == 2)
2771 else if(cvar("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(!cvar("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 + cvar("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();
2915 if(gameover > 1) // shutting down already?
2918 gameover = 2; // 2 = server shutting down
2920 if(world_initialized > 0)
2922 world_initialized = 0;
2923 print("Saving persistent data...\n");
2925 if(!cheatcount_total)
2927 if(cvar("sv_db_saveasdump"))
2928 db_dump(ServerProgsDB, "server.db");
2930 db_save(ServerProgsDB, "server.db");
2932 if(cvar("developer"))
2934 if(cvar("sv_db_saveasdump"))
2935 db_dump(TemporaryDB, "server-temp.db");
2937 db_save(TemporaryDB, "server-temp.db");
2939 CheatShutdown(); // must be after cheatcount check
2940 db_close(ServerProgsDB);
2941 db_close(TemporaryDB);
2943 // tell the bot system the game is ending now
2946 WeaponStats_Shutdown();
2949 else if(world_initialized == 0)
2951 print("NOTE: crashed before even initializing the world, not saving persistent data\n");