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;
47 void GotoNextMap(float reinit);
49 float(float reinit) 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");
101 if(autocvar__sv_init)
103 // cvar_set("_sv_init", "0");
104 // we do NOT set this to 0 any more, so someone "accidentally" changing
105 // to this "init" map on a dedicated server will cause no permanent
107 if(autocvar_g_maplist_shuffle)
109 n = tokenizebyseparator(autocvar_g_maplist, " ");
110 cvar_set("g_maplist_index", ftos(n - 1)); // jump to map 0 in GotoNextMap
113 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
115 if(!DoNextMapOverride(1))
123 self.nextthink = time;
127 self.nextthink = time + 1;
128 print("Waiting for _sv_init being set to 1 by initialization scripts...\n");
132 void cvar_changes_init()
136 float n, i, adding, pureadding;
139 strunzone(cvar_changes);
140 cvar_changes = string_null;
142 strunzone(cvar_purechanges);
143 cvar_purechanges = string_null;
144 cvar_purechanges_count = 0;
147 buf_cvarlist(h, "", "_"); // exclude all _ cvars as they are temporary
153 for(i = 0; i < n; ++i)
155 k = bufstr_get(h, i);
157 #define BADPREFIX(p) if(substring(k, 0, strlen(p)) == p) continue
158 #define BADPRESUFFIX(p,s) if(substring(k, 0, strlen(p)) == p && substring(k, -strlen(s), -1) == s) continue
159 #define BADCVAR(p) if(k == p) continue
161 // general excludes and namespaces for server admin used cvars
162 BADPREFIX("help_"); // PN's server has this listed as changed, let's not rat him out for THAT
166 BADPREFIX("cvar_check_");
168 BADCVAR("g_configversion");
169 BADCVAR("g_maplist_index");
170 BADCVAR("halflifebsp");
171 BADPREFIX("sv_world");
177 BADPREFIX("scoreboard_");
178 BADPREFIX("g_campaign");
179 BADPREFIX("g_waypointsprite_");
185 BADPREFIX("net_slist_");
191 BADPREFIX("sensitivity");
192 BADPREFIX("userbind");
195 BADPREFIX("crosshair");
196 BADCVAR("mod_q3bsp_lightmapmergepower");
197 BADCVAR("mod_q3bsp_nolightmaps");
199 BADCVAR("mastervolume");
201 BADCVAR("bgmvolume");
204 BADCVAR("developer");
205 BADCVAR("log_dest_udp");
207 BADCVAR("net_address");
208 BADCVAR("net_address_ipv6");
210 BADCVAR("savedgamecfg");
211 BADCVAR("serverconfig");
212 BADCVAR("sv_autoscreenshot");
213 BADCVAR("sv_heartbeatperiod");
214 BADCVAR("sv_vote_master_password");
215 BADCVAR("sys_colortranslation");
216 BADCVAR("sys_specialcharactertranslation");
217 BADCVAR("timeformat");
218 BADCVAR("timestamps");
219 BADPREFIX("developer_");
221 BADPREFIX("g_banned_list");
222 BADPREFIX("g_chat_flood_");
223 BADPREFIX("g_ghost_items");
224 BADPREFIX("g_playerstats_");
225 BADPREFIX("g_respawn_ghosts");
226 BADPREFIX("g_voice_flood_");
228 BADPREFIX("sv_allowdownloads");
229 BADPREFIX("sv_autodemo");
230 BADPREFIX("sv_curl_");
231 BADPREFIX("sv_eventlog");
232 BADPREFIX("sv_logscores_");
233 BADPREFIX("sv_master");
234 BADPREFIX("sv_weaponstats_");
235 BADPREFIX("sv_waypointsprite_");
236 BADCVAR("rescan_pending");
238 // these can contain player IDs, so better hide
239 BADPREFIX("g_forced_team_");
242 BADCVAR("fraglimit");
244 BADCVAR("g_assault");
249 BADCVAR("g_domination");
250 BADCVAR("g_domination_default_teams");
251 BADCVAR("g_freezetag");
252 BADCVAR("g_keepaway");
253 BADCVAR("g_keyhunt");
254 BADCVAR("g_keyhunt_teams");
255 BADCVAR("g_keyhunt_teams");
257 BADCVAR("g_nexball");
258 BADCVAR("g_onslaught");
260 BADCVAR("g_race_qualifying_timelimit");
261 BADCVAR("g_runematch");
263 BADCVAR("g_tdm_teams");
264 BADCVAR("leadlimit");
267 BADCVAR("timelimit");
271 BADCVAR("g_maplist");
272 BADCVAR("g_maplist_mostrecent");
276 d = cvar_defstring(k);
282 cvar_changes = strcat(cvar_changes, k, " \"", v, "\" // \"", d, "\"\n");
283 if(strlen(cvar_changes) > 16384)
285 cvar_changes = "// too many settings have been changed to show them here\n";
290 // now check if the changes are actually gameplay relevant
292 // does nothing visible
293 BADCVAR("captureleadlimit_override");
294 BADCVAR("g_arena_point_leadlimit");
295 BADCVAR("g_balance_kill_delay");
296 BADCVAR("g_ca_point_leadlimit");
297 BADCVAR("g_ctf_captimerecord_always");
298 BADCVAR("g_ctf_flag_capture_effects");
299 BADCVAR("g_ctf_flag_glowtrails");
300 BADCVAR("g_ctf_flag_pickup_effects");
301 BADCVAR("g_domination_point_leadlimit");
302 BADCVAR("g_forced_respawn");
303 BADCVAR("g_keyhunt_point_leadlimit");
304 BADCVAR("g_nexball_goalleadlimit");
305 BADCVAR("g_runematch_point_leadlimit");
306 BADCVAR("leadlimit_and_fraglimit");
307 BADCVAR("leadlimit_override");
309 BADCVAR("sv_allow_fullbright");
310 BADCVAR("sv_checkforpacketsduringsleep");
311 BADCVAR("sv_fraginfo");
312 BADCVAR("sv_timeout");
313 BADPREFIX("sv_timeout_");
314 BADCVAR("welcome_message_time");
315 BADPREFIX("crypto_");
316 BADPREFIX("g_chat_");
317 BADPREFIX("g_ctf_captimerecord_");
318 BADPREFIX("g_maplist_votable_");
322 BADPREFIX("sv_cullentities_");
323 BADPREFIX("sv_fraginfo_");
324 BADPREFIX("sv_maxidle_");
325 BADPREFIX("sv_vote_");
326 BADPREFIX("timelimit_");
327 BADCVAR("gameversion");
328 BADPREFIX("gameversion_");
329 BADCVAR("sv_namechangetimer");
330 #ifndef NO_LEGACY_NETWORKING
331 BADCVAR("sv_use_csqc_players"); // transition
334 // allowed changes to server admins (please sync this to server.cfg)
338 // :%s,//\([^ ]*\).*,BADCVAR("\1");,
340 // yes, this does contain some redundant stuff, don't really care
341 BADCVAR("bot_config_file");
342 BADCVAR("bot_number");
343 BADCVAR("bot_prefix");
344 BADCVAR("bot_suffix");
345 BADCVAR("capturelimit_override");
346 BADCVAR("fraglimit_override");
348 BADCVAR("g_antilag");
349 BADCVAR("g_balance_teams");
350 BADCVAR("g_balance_teams_force");
351 BADCVAR("g_ban_sync_trusted_servers");
352 BADCVAR("g_ban_sync_uri");
353 BADCVAR("g_ctf_ignore_frags");
354 BADCVAR("g_domination_point_limit");
355 BADCVAR("g_friendlyfire");
356 BADCVAR("g_fullbrightitems");
357 BADCVAR("g_fullbrightplayers");
358 BADCVAR("g_keyhunt_point_limit");
359 BADCVAR("g_keyhunt_teams_override");
360 BADCVAR("g_lms_lives_override");
361 BADCVAR("g_maplist");
362 BADCVAR("g_maplist_check_waypoints");
363 BADCVAR("g_maplist_mostrecent_count");
364 BADCVAR("g_maplist_shuffle");
365 BADCVAR("g_maplist_votable");
366 BADCVAR("g_maplist_votable_abstain");
367 BADCVAR("g_maplist_votable_nodetail");
368 BADCVAR("g_maplist_votable_suggestions");
369 BADCVAR("g_maxplayers");
370 BADCVAR("g_minstagib");
371 BADCVAR("g_mirrordamage");
372 BADCVAR("g_nexball_goallimit");
373 BADCVAR("g_powerups");
374 BADCVAR("g_runematch_point_limit");
375 BADCVAR("g_start_delay");
377 BADCVAR("g_weapon_stay"); BADPRESUFFIX("g_", "_weapon_stay");
380 BADCVAR("maxplayers");
381 BADCVAR("minplayers");
382 BADCVAR("net_address");
384 BADCVAR("rcon_password");
385 BADCVAR("rcon_restricted_commands");
386 BADCVAR("rcon_restricted_password");
388 BADCVAR("sv_adminnick");
389 BADCVAR("sv_autoscreenshot");
390 BADCVAR("sv_autotaunt");
391 BADCVAR("sv_curl_defaulturl");
392 BADCVAR("sv_defaultcharacter");
393 BADCVAR("sv_defaultplayercolors");
394 BADCVAR("sv_defaultplayermodel");
395 BADCVAR("sv_defaultplayerskin");
396 BADCVAR("sv_maxidle");
397 BADCVAR("sv_maxrate");
399 BADCVAR("sv_public");
400 BADCVAR("sv_ready_restart");
401 BADCVAR("sv_status_privacy");
403 BADCVAR("sv_vote_call");
404 BADCVAR("sv_vote_commands");
405 BADCVAR("sv_vote_majority_factor");
406 BADCVAR("sv_vote_master");
407 BADCVAR("sv_vote_master_commands");
408 BADCVAR("sv_vote_master_password");
409 BADCVAR("sv_vote_simple_majority_factor");
410 BADCVAR("sys_ticrate");
411 BADCVAR("teamplay_mode");
412 BADCVAR("timelimit_override");
413 BADCVAR("g_spawnshieldtime");
414 BADPREFIX("g_warmup_");
415 BADPREFIX("sv_ready_restart_");
417 if(autocvar_g_minstagib)
419 BADCVAR("g_grappling_hook");
420 BADCVAR("g_jetpack");
427 cvar_purechanges = strcat(cvar_purechanges, k, " \"", v, "\" // \"", d, "\"\n");
428 if(strlen(cvar_purechanges) > 16384)
430 cvar_purechanges = "// too many settings have been changed to show them here\n";
434 ++cvar_purechanges_count;
435 // WARNING: this variable is used for the server list
436 // NEVER dare to skip this code!
437 // Hacks to intentionally appearing as "pure server" even though you DO have
438 // modified settings may be punished by removal from the server list.
439 // You can do to the variables cvar_changes and cvar_purechanges all you want,
443 if(cvar_changes == "")
444 cvar_changes = "// this server runs at default server settings\n";
446 cvar_changes = strcat("// this server runs at modified server settings:\n", cvar_changes);
447 cvar_changes = strzone(cvar_changes);
448 if(cvar_purechanges == "")
449 cvar_purechanges = "// this server runs at default gameplay settings\n";
451 cvar_purechanges = strcat("// this server runs at modified gameplay settings:\n", cvar_purechanges);
452 cvar_purechanges = strzone(cvar_purechanges);
455 void detect_maptype()
464 o_x += random() * (world.maxs_x - world.mins_x);
465 o_y += random() * (world.maxs_y - world.mins_y);
466 o_z += random() * (world.maxs_z - world.mins_z);
468 tracebox(o, PL_MIN, PL_MAX, o - '0 0 32768', MOVE_WORLDONLY, world);
469 if(trace_fraction == 1)
474 for(i = 0; i < 64; i += 4)
476 tracebox(o, '-1 -1 -1' * i, '1 1 1' * i, o - '0 0 32768', MOVE_WORLDONLY, world);
477 if(trace_fraction == 1)
479 print(ftos(i), " -> ", vtos(trace_endpos), "\n");
488 float RandomSeed_Send(entity to, float sf)
490 WriteByte(MSG_ENTITY, ENT_CLIENT_RANDOMSEED);
491 WriteShort(MSG_ENTITY, self.cnt);
494 void RandomSeed_Think()
496 self.cnt = bound(0, floor(random() * 65536), 65535);
497 self.nextthink = time + 5;
501 void RandomSeed_Spawn()
503 randomseed = spawn();
504 randomseed.think = RandomSeed_Think;
505 Net_LinkEntity(randomseed, FALSE, 0, RandomSeed_Send);
510 self.think(); // sets random seed and nextthink
514 void spawnfunc___init_dedicated_server(void)
516 // handler for _init/_init map (only for dedicated server initialization)
518 world_initialized = -1; // don't complain
520 cvar_string = cvar_string_normal;
521 cvar_set = cvar_set_normal;
523 remove = remove_unsafely;
527 e.think = GotoFirstMap;
528 e.nextthink = time; // this is usually 1 at this point
531 e.classname = "info_player_deathmatch"; // safeguard against player joining
533 self.classname = "worldspawn"; // safeguard against various stuff ;)
535 // needs to be done so early because of the constants they create
540 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
543 void Map_MarkAsRecent(string m);
544 float world_already_spawned;
545 void RegisterWeapons();
547 void ClientInit_Spawn();
548 void WeaponStats_Init();
549 void WeaponStats_Shutdown();
550 void spawnfunc_worldspawn (void)
552 float fd, l, i, j, n;
556 cvar_string = cvar_string_normal;
557 cvar_set = cvar_set_normal;
559 if(world_already_spawned)
560 error("world already spawned - you may have EXACTLY ONE worldspawn!");
561 world_already_spawned = TRUE;
563 remove = remove_safely; // during spawning, watch what you remove!
565 check_unacceptable_compiler_bugs();
567 cvar_changes_init(); // do this very early now so it REALLY matches the server config
569 compressShortVector_init();
571 allowed_to_spawn = TRUE;
574 head = nextent(world);
579 head = nextent(head);
582 // needs to be done so early because of the constants they create
586 ServerProgsDB = db_load(strcat("server.db", autocvar_sessionid));
588 TemporaryDB = db_create();
593 // 1 FLICKER (first variety)
594 lightstyle(1, "mmnmmommommnonmmonqnmmo");
596 // 2 SLOW STRONG PULSE
597 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
599 // 3 CANDLE (first variety)
600 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
603 lightstyle(4, "mamamamamama");
606 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
608 // 6 FLICKER (second variety)
609 lightstyle(6, "nmonqnmomnmomomno");
611 // 7 CANDLE (second variety)
612 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
614 // 8 CANDLE (third variety)
615 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
617 // 9 SLOW STROBE (fourth variety)
618 lightstyle(9, "aaaaaaaazzzzzzzz");
620 // 10 FLUORESCENT FLICKER
621 lightstyle(10, "mmamammmmammamamaaamammma");
623 // 11 SLOW PULSE NOT FADE TO BLACK
624 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
626 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
631 if(autocvar_g_campaign)
634 Map_MarkAsRecent(mapname);
636 precache_model ("null"); // we need this one before InitGameplayMode
644 bot_waypoints_for_items = autocvar_g_waypoints_for_items;
645 if(bot_waypoints_for_items == 1)
646 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
647 bot_waypoints_for_items = 0;
651 WaypointSprite_Init();
656 GameLogInit(); // prepare everything
658 // changing the logic generating it is okay. But:
659 // it HAS to stay <= 64 chars
660 // character set: ASCII 33-126 without the following characters: : ; ' " \ $
661 if(autocvar_sv_eventlog)
663 s = sprintf("%d.%s.%06d", ftos(autocvar_sv_eventlog_files_counter), strftime(FALSE, "%s"), floor(random() * 1000000));
664 matchid = strzone(s);
666 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
667 s = ":gameinfo:mutators:LIST";
670 MUTATOR_CALLHOOK(BuildMutatorsString);
673 // simple, probably not good in the mutator system
674 if(autocvar_g_grappling_hook)
675 s = strcat(s, ":grappling_hook");
677 // initialiation stuff, not good in the mutator system
678 if(!autocvar_g_use_ammunition)
679 s = strcat(s, ":no_use_ammunition");
681 // initialiation stuff, not good in the mutator system
682 if(autocvar_g_pickup_items == 0)
683 s = strcat(s, ":no_pickup_items");
684 if(autocvar_g_pickup_items > 0)
685 s = strcat(s, ":pickup_items");
687 // initialiation stuff, not good in the mutator system
688 if(autocvar_g_weaponarena != "0")
689 s = strcat(s, ":", autocvar_g_weaponarena, " arena");
691 // TODO to mutator system
692 if(autocvar_g_norecoil)
693 s = strcat(s, ":norecoil");
695 // TODO to mutator system
696 if(autocvar_g_midair)
697 s = strcat(s, ":midair");
699 // TODO to mutator system
700 if(autocvar_g_minstagib)
701 s = strcat(s, ":minstagib");
703 // TODO to mutator system
704 if(autocvar_g_powerups == 0)
705 s = strcat(s, ":no_powerups");
706 if(autocvar_g_powerups > 0)
707 s = strcat(s, ":powerups");
710 GameLogEcho(":gameinfo:end");
713 matchid = strzone(ftos(random()));
715 cvar_set("nextmap", "");
719 if(autocvar_g_campaign)
727 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
729 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
731 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
734 while((s = fgets(fd)))
736 l = tokenize_console(s);
741 print("Found ^1UNSUPPORTED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
742 print(" cdtrack ", argv(2), "\n");
744 else if(argv(0) == "fog")
746 print("Found ^1UNSUPPORTED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
747 print(" \"fog\" \"", s, "\"\n");
749 else if(argv(0) == "set")
751 print("Found ^1UNSUPPORTED^7 set command in .cfg file; put this line in mapinfo instead:\n");
752 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
754 else if(argv(0) != "//")
756 print("Found ^1UNSUPPORTED^7 set command in .cfg file; put this line in mapinfo instead:\n");
757 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
766 addstat(STAT_WEAPONS, AS_INT, weapons);
767 addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
768 addstat(STAT_SWITCHINGWEAPON, AS_INT, switchingweapon);
769 addstat(STAT_GAMESTARTTIME, AS_FLOAT, stat_game_starttime);
770 addstat(STAT_ALLOW_OLDNEXBEAM, AS_INT, stat_allow_oldnexbeam);
773 addstat(STAT_STRENGTH_FINISHED, AS_FLOAT, strength_finished);
774 addstat(STAT_INVINCIBLE_FINISHED, AS_FLOAT, invincible_finished);
775 addstat(STAT_PRESSED_KEYS, AS_FLOAT, pressedkeys);
776 addstat(STAT_FUEL, AS_INT, ammo_fuel);
777 addstat(STAT_SHOTORG, AS_INT, stat_shotorg);
778 addstat(STAT_LEADLIMIT, AS_FLOAT, stat_leadlimit);
779 addstat(STAT_WEAPON_CLIPLOAD, AS_INT, clip_load);
780 addstat(STAT_WEAPON_CLIPSIZE, AS_INT, clip_size);
781 addstat(STAT_LAST_PICKUP, AS_FLOAT, last_pickup);
782 addstat(STAT_HIT_TIME, AS_FLOAT, hit_time);
783 addstat(STAT_TYPEHIT_TIME, AS_FLOAT, typehit_time);
784 addstat(STAT_LAYED_MINES, AS_INT, minelayer_mines);
786 addstat(STAT_NEX_CHARGE, AS_FLOAT, nex_charge);
787 addstat(STAT_NEX_CHARGEPOOL, AS_FLOAT, nex_chargepool_ammo);
789 addstat(STAT_HAGAR_LOAD, AS_INT, hagar_load);
791 if(g_ca || g_freezetag)
793 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
794 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
795 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
796 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
800 addstat(STAT_FROZEN, AS_INT, freezetag_frozen);
801 addstat(STAT_REVIVE_PROGRESS, AS_FLOAT, freezetag_revive_progress);
804 // g_movementspeed hack
805 addstat(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW, AS_FLOAT, stat_sv_airspeedlimit_nonqw);
806 addstat(STAT_MOVEVARS_MAXSPEED, AS_FLOAT, stat_sv_maxspeed);
807 addstat(STAT_MOVEVARS_AIRACCEL_QW, AS_FLOAT, stat_sv_airaccel_qw);
808 addstat(STAT_MOVEVARS_AIRSTRAFEACCEL_QW, AS_FLOAT, stat_sv_airstrafeaccel_qw);
811 addstat(STAT_SECRETS_TOTAL, AS_FLOAT, stat_secrets_total);
812 addstat(STAT_SECRETS_FOUND, AS_FLOAT, stat_secrets_found);
814 next_pingtime = time + 5;
818 // set up information replies for clients and server to use
819 lsmaps_reply = "^7Maps available: ";
820 lsnewmaps_reply = "^7Maps without a record set: ";
821 for(i = 0, j = 0; i < MapInfo_count; ++i)
823 if(MapInfo_Get_ByID(i))
824 if not(MapInfo_Map_flags & (MAPINFO_FLAG_HIDDEN | MAPINFO_FLAG_FORBIDDEN))
833 lsmaps_reply = strcat(lsmaps_reply, col, MapInfo_Map_bspname, " ");
835 if(g_race && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "time"))))
836 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
837 else if(g_cts && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "time"))))
838 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
842 lsmaps_reply = strzone(strcat(lsmaps_reply, "\n"));
843 lsnewmaps_reply = strzone(strcat(((!g_race && !g_cts) ? "Need to be playing race or CTS for lsnewmaps to work." : lsnewmaps_reply), "\n"));
845 maplist_reply = "^7Maps in list: ";
846 n = tokenize_console(autocvar_g_maplist);
847 for(i = 0, j = 0; i < n; ++i)
849 if(MapInfo_CheckMap(argv(i)))
855 maplist_reply = strcat(maplist_reply, col, argv(i), " ");
859 maplist_reply = strzone(strcat(maplist_reply, "\n"));
860 MapInfo_ClearTemps();
862 for(i = 0; i < 10; ++i)
864 records_reply[i] = strzone(getrecords(i));
867 ladder_reply = strzone(getladder());
869 rankings_reply = strzone(getrankings());
874 PingPLReport_Spawn();
878 localcmd("\n_sv_hook_gamestart ", GetGametype(), "\n");
880 // fill sv_curl_serverpackages from .serverpackage files
881 if(autocvar_sv_curl_serverpackages_auto)
884 n = tokenize_console(cvar_string("sv_curl_serverpackages"));
885 for(i = 0; i < n; ++i)
886 if(substring(argv(i), -14, -1) != "-serverpackage.txt")
887 if(substring(argv(i), -14, -1) != ".serverpackage") // OLD legacy
888 s = strcat(s, " ", argv(i));
889 fd = search_begin("*-serverpackage.txt", TRUE, FALSE);
892 j = search_getsize(fd);
893 for(i = 0; i < j; ++i)
894 s = strcat(s, " ", search_getfilename(fd, i));
897 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?
921 return MapInfo_Type_ToString(MapInfo_LoadedGametype);
924 string getmapname_stored;
930 float Map_Count, Map_Current;
931 string Map_Current_Name;
933 // NOTE: this now expects the map list to be already tokenized and the count in Map_Count
934 float GetMaplistPosition()
940 idx = autocvar_g_maplist_index;
947 for(pos = 0; pos < Map_Count; ++pos)
951 // resume normal maplist rotation if current map is not in g_maplist
955 float MapHasRightSize(string map)
958 if(currentbots || autocvar_bot_number || player_count < autocvar_minplayers)
959 if(autocvar_g_maplist_check_waypoints)
961 dprint("checkwp "); dprint(map);
962 if(!fexists(strcat("maps/", map, ".waypoints")))
964 dprint(": no waypoints\n");
967 dprint(": has waypoints\n");
970 // open map size restriction file
971 dprint("opensize "); dprint(map);
972 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
975 float mapmin, mapmax;
977 mapmin = stof(fgets(fh));
978 mapmax = stof(fgets(fh));
980 if(player_count < mapmin)
982 dprint("not enough\n");
985 if(player_count > mapmax)
987 dprint("too many\n");
990 dprint("right size\n");
993 dprint(": not found\n");
997 string Map_Filename(float position)
999 return strcat("maps/", argv(position), ".bsp");
1002 string strwords(string s, float w)
1005 for(endpos = 0; w && endpos >= 0; --w)
1006 endpos = strstrofs(s, " ", endpos + 1);
1010 return substring(s, 0, endpos);
1013 float strhasword(string s, string w)
1015 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
1018 void Map_MarkAsRecent(string m)
1020 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", autocvar_g_maplist_mostrecent), max(0, autocvar_g_maplist_mostrecent_count)));
1023 float Map_IsRecent(string m)
1025 return strhasword(autocvar_g_maplist_mostrecent, m);
1028 float Map_Check(float position, float pass)
1032 map_next = argv(position);
1035 if(Map_IsRecent(map_next))
1038 filename = Map_Filename(position);
1039 if(MapInfo_CheckMap(map_next))
1043 if(MapHasRightSize(map_next))
1048 dprint( "Couldn't select '", filename, "'..\n" );
1053 void Map_Goto_SetStr(string nextmapname)
1055 if(getmapname_stored != "")
1056 strunzone(getmapname_stored);
1057 if(nextmapname == "")
1058 getmapname_stored = "";
1060 getmapname_stored = strzone(nextmapname);
1063 void Map_Goto_SetFloat(float position)
1065 cvar_set("g_maplist_index", ftos(position));
1066 Map_Goto_SetStr(argv(position));
1069 void Map_Goto(float reinit)
1071 MapInfo_LoadMap(getmapname_stored, reinit);
1074 // return codes of map selectors:
1075 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
1076 // -2 = permanent failure
1077 float() MaplistMethod_Iterate = // usual method
1081 for(pass = 1; pass <= 2; ++pass)
1083 for(i = 1; i < Map_Count; ++i)
1086 mapindex = mod(i + Map_Current, Map_Count);
1087 if(Map_Check(mapindex, pass))
1094 float() MaplistMethod_Repeat = // fallback method
1096 if(Map_Check(Map_Current, 2))
1101 float() MaplistMethod_Random = // random map selection
1107 for(i = 0; i <= imax; ++i)
1110 mapindex = mod(Map_Current + floor(random() * (Map_Count - 1) + 1), Map_Count); // any OTHER map
1111 if(Map_Check(mapindex, 1))
1117 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
1118 // the exponent sets a bias on the map selection:
1119 // the higher the exponent, the less likely "shortly repeated" same maps are
1121 float i, j, imax, insertpos;
1125 for(i = 0; i <= imax; ++i)
1129 // now reinsert this at another position
1130 insertpos = pow(random(), 1 / exponent); // ]0, 1]
1131 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
1132 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
1133 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
1135 // insert the current map there
1137 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
1138 newlist = strcat(newlist, " ", argv(j));
1139 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
1140 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
1141 newlist = strcat(newlist, " ", argv(j));
1142 newlist = substring(newlist, 1, strlen(newlist) - 1);
1143 cvar_set("g_maplist", newlist);
1144 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1146 // NOTE: the selected map has just been inserted at (insertpos-1)th position
1147 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
1148 if(Map_Check(Map_Current, 1))
1156 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1159 bprint( "Maplist is empty! Resetting it to default map list.\n" );
1160 cvar_set("g_maplist", MapInfo_ListAllAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
1161 if(autocvar_g_maplist_shuffle)
1163 localcmd("\nmenu_cmd sync\n");
1164 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1167 error("empty maplist, cannot select a new map");
1168 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
1170 if(Map_Current_Name)
1171 strunzone(Map_Current_Name);
1172 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
1173 // this may or may not be correct, but who cares, in the worst case a map
1174 // isn't chosen in the first pass that should have been
1185 if(autocvar_g_maplist_shuffle > 0)
1186 nextMap = MaplistMethod_Shuffle(autocvar_g_maplist_shuffle + 1);
1189 if(autocvar_g_maplist_selectrandom)
1190 nextMap = MaplistMethod_Random();
1193 nextMap = MaplistMethod_Iterate();
1196 nextMap = MaplistMethod_Repeat();
1200 Map_Goto_SetFloat(nextMap);
1201 return getmapname_stored;
1207 float DoNextMapOverride(float reinit)
1209 if(autocvar_g_campaign)
1211 CampaignPostIntermission();
1212 alreadychangedlevel = TRUE;
1215 if(autocvar_quit_when_empty)
1217 if(player_count <= currentbots)
1220 alreadychangedlevel = TRUE;
1224 if(autocvar_quit_and_redirect != "")
1226 redirection_target = strzone(autocvar_quit_and_redirect);
1227 alreadychangedlevel = TRUE;
1230 if (autocvar_samelevel) // if samelevel is set, stay on same level
1232 localcmd("restart\n");
1233 alreadychangedlevel = TRUE;
1236 if(autocvar_nextmap != "")
1237 if(MapInfo_CheckMap(autocvar_nextmap))
1239 Map_Goto_SetStr(autocvar_nextmap);
1241 alreadychangedlevel = TRUE;
1244 if(autocvar_lastlevel)
1246 cvar_settemp_restore();
1247 localcmd("set lastlevel 0\ntogglemenu 1\n");
1248 alreadychangedlevel = TRUE;
1254 void GotoNextMap(float reinit)
1259 if (alreadychangedlevel)
1261 alreadychangedlevel = TRUE;
1267 for(allowReset = 1; allowReset >= 0; --allowReset)
1269 nextMap = GetNextMap();
1275 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1276 cvar_set("g_maplist", MapInfo_ListAllAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
1277 if(autocvar_g_maplist_shuffle)
1279 localcmd("\nmenu_cmd sync\n");
1283 error("Everything is broken - not even the default map list works. Please report this to the developers.");
1295 When the player presses attack or jump, change to the next level
1298 .float autoscreenshot;
1299 void() MapVote_Start;
1300 void() MapVote_Think;
1301 float mapvote_initialized;
1302 void IntermissionThink()
1304 FixIntermissionClient(self);
1306 if( (autocvar_sv_autoscreenshot || self.cvar_cl_autoscreenshot)
1307 && ((self.autoscreenshot > 0) && (time > self.autoscreenshot)) )
1309 self.autoscreenshot = -1;
1310 if(clienttype(self) == CLIENTTYPE_REAL) { stuffcmd(self, sprintf("\nautoscreenshot \"%s\" \"%s\"\n", GetMapname(), strftime(FALSE, "%s"))); }
1314 if (time < intermission_exittime)
1317 if(!mapvote_initialized)
1318 if (time < intermission_exittime + 10 && !(self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE))
1328 Returns the entity to view from
1332 entity FindIntermission()
1337 // look for info_intermission first
1338 spot = find (world, classname, "info_intermission");
1340 { // pick a random one
1344 spot = find (spot, classname, "info_intermission");
1346 spot = find (spot, classname, "info_intermission");
1352 // then look for the start position
1353 spot = find (world, classname, "info_player_start");
1357 // testinfo_player_start is only found in regioned levels
1358 spot = find (world, classname, "testplayerstart");
1362 // then look for the start position
1363 spot = find (world, classname, "info_player_deathmatch");
1367 //objerror ("FindIntermission: no spot");
1373 ===============================================================================
1377 ===============================================================================
1380 void DumpStats(float final)
1389 to_console = autocvar_sv_logscores_console;
1390 to_eventlog = autocvar_sv_eventlog;
1391 to_file = autocvar_sv_logscores_file;
1395 to_console = TRUE; // always print printstats replies
1396 to_eventlog = FALSE; // but never print them to the event log
1400 if(autocvar_sv_eventlog_console)
1401 to_console = FALSE; // otherwise we get the output twice
1407 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
1415 file = fopen(autocvar_sv_logscores_filename, FILE_APPEND);
1419 fputs(file, strcat(s, "\n"));
1422 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
1428 fputs(file, strcat(s, "\n"));
1430 FOR_EACH_CLIENT(other)
1432 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && autocvar_sv_logscores_bots))
1434 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
1435 s = strcat(s, ftos(rint(time - other.jointime)), ":");
1436 if(other.classname == "player" || g_arena || g_ca || g_lms)
1437 s = strcat(s, ftos(other.team), ":");
1439 s = strcat(s, "spectator:");
1442 print(s, other.netname, "\n");
1444 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
1446 fputs(file, strcat(s, other.netname, "\n"));
1452 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
1458 fputs(file, strcat(s, "\n"));
1460 for(i = 1; i < 16; ++i)
1462 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
1463 s = strcat(s, ":", ftos(i));
1469 fputs(file, strcat(s, "\n"));
1476 GameLogEcho(":end");
1479 fputs(file, ":end\n");
1484 void FixIntermissionClient(entity e)
1487 if(!e.autoscreenshot) // initial call
1489 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1491 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1492 e.solid = SOLID_NOT;
1493 e.movetype = MOVETYPE_NONE;
1494 e.takedamage = DAMAGE_NO;
1497 e.weaponentity.effects = EF_NODRAW;
1498 if (e.weaponentity.weaponentity)
1499 e.weaponentity.weaponentity.effects = EF_NODRAW;
1501 if(clienttype(e) == CLIENTTYPE_REAL)
1503 stuffcmd(e, "\nscr_printspeed 1000000\n");
1504 s = autocvar_sv_intermission_cdtrack;
1506 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1508 WriteByte(MSG_ONE, SVC_INTERMISSION);
1515 go to the next level for deathmatch
1516 only called if a time or frag limit has expired
1522 intermission_running = 1;
1524 // enforce a wait time before allowing changelevel
1525 if(player_count > 0)
1526 intermission_exittime = time + autocvar_sv_mapchange_delay;
1528 intermission_exittime = -1;
1531 WriteByte (MSG_ALL, SVC_CDTRACK);
1532 WriteByte (MSG_ALL, 3);
1533 WriteByte (MSG_ALL, 3);
1534 // done in FixIntermission
1537 //pos = FindIntermission ();
1545 PlayerStats_EndMatch(1);
1547 PlayerStats_AddGlobalInfo(e);
1548 PlayerStats_Shutdown();
1549 WeaponStats_Shutdown();
1551 if(autocvar_sv_eventlog)
1552 GameLogEcho(":gameover");
1556 FOR_EACH_PLAYER(other) {
1557 FixIntermissionClient(other);
1559 bprint(other.netname, " ^7wins.\n");
1562 if(autocvar_g_campaign)
1563 CampaignPreIntermission();
1565 localcmd("\nsv_hook_gameend\n");
1572 Exit deathmatch games upon conditions
1575 void CheckRules_Player()
1577 if (gameover) // someone else quit the game already
1580 if(self.deadflag == DEAD_NO)
1581 self.play_time += frametime;
1583 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1584 // (div0: and that in CheckRules_World please)
1587 float checkrules_equality;
1588 float checkrules_suddendeathwarning;
1589 float checkrules_suddendeathend;
1590 float checkrules_overtimesadded; //how many overtimes have been already added
1592 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1593 float WINNING_YES = 1; // winner found
1594 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1595 float WINNING_STARTSUDDENDEATHOVERTIME = 3; // no winner, enter suddendeath overtime NOW
1597 float InitiateSuddenDeath()
1599 // Check first whether normal overtimes could be added before initiating suddendeath mode
1600 // - for this timelimit_overtime needs to be >0 of course
1601 // - also check the winning condition calculated in the previous frame and only add normal overtime
1602 // again, if at the point at which timelimit would be extended again, still no winner was found
1603 if ((checkrules_overtimesadded >= 0) && (checkrules_overtimesadded < autocvar_timelimit_overtimes) && autocvar_timelimit_overtime && !(g_race && !g_race_qualifying))
1605 return 1; // need to call InitiateOvertime later
1609 if(!checkrules_suddendeathend)
1611 checkrules_suddendeathend = time + 60 * autocvar_timelimit_suddendeath;
1612 if(g_race && !g_race_qualifying)
1613 race_StartCompleting();
1619 void InitiateOvertime() // ONLY call this if InitiateSuddenDeath returned true
1621 ++checkrules_overtimesadded;
1622 //add one more overtime by simply extending the timelimit
1624 tl = autocvar_timelimit;
1625 tl += autocvar_timelimit_overtime;
1626 cvar_set("timelimit", ftos(tl));
1627 string minutesPlural;
1628 if (autocvar_timelimit_overtime == 1)
1629 minutesPlural = " ^3minute";
1631 minutesPlural = " ^3minutes";
1635 "^3Now playing ^1OVERTIME^3!\n\n^3Added ^1",
1636 ftos(autocvar_timelimit_overtime),
1643 float GetWinningCode(float fraglimitreached, float equality)
1645 if(autocvar_g_campaign == 1)
1646 if(fraglimitreached)
1653 if(fraglimitreached)
1654 return WINNING_STARTSUDDENDEATHOVERTIME;
1656 return WINNING_NEVER;
1658 if(fraglimitreached)
1664 // set the .winning flag for exactly those players with a given field value
1665 void SetWinners(.float field, float value)
1668 FOR_EACH_PLAYER(head)
1669 head.winning = (head.field == value);
1672 // set the .winning flag for those players with a given field value
1673 void AddWinners(.float field, float value)
1676 FOR_EACH_PLAYER(head)
1677 if(head.field == value)
1681 // clear the .winning flags
1682 void ClearWinners(void)
1685 FOR_EACH_PLAYER(head)
1689 // Onslaught winning condition:
1690 // game terminates if only one team has a working generator (or none)
1691 float WinningCondition_Onslaught()
1694 float t1, t2, t3, t4;
1696 WinningConditionHelper(); // set worldstatus
1701 // first check if the game has ended
1702 t1 = t2 = t3 = t4 = 0;
1703 head = find(world, classname, "onslaught_generator");
1706 if (head.health > 0)
1708 if (head.team == COLOR_TEAM1) t1 = 1;
1709 if (head.team == COLOR_TEAM2) t2 = 1;
1710 if (head.team == COLOR_TEAM3) t3 = 1;
1711 if (head.team == COLOR_TEAM4) t4 = 1;
1713 head = find(head, classname, "onslaught_generator");
1715 if (t1 + t2 + t3 + t4 < 2)
1717 // game over, only one team remains (or none)
1719 if (t1) SetWinners(team, COLOR_TEAM1);
1720 if (t2) SetWinners(team, COLOR_TEAM2);
1721 if (t3) SetWinners(team, COLOR_TEAM3);
1722 if (t4) SetWinners(team, COLOR_TEAM4);
1723 dprint("Have a winner, ending game.\n");
1727 // Two or more teams remain
1731 float LMS_NewPlayerLives()
1734 fl = autocvar_fraglimit;
1738 // first player has left the game for dying too much? Nobody else can get in.
1739 if(lms_lowest_lives < 1)
1742 if(!autocvar_g_lms_join_anytime)
1743 if(lms_lowest_lives < fl - autocvar_g_lms_last_join)
1746 return bound(1, lms_lowest_lives, fl);
1749 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1750 // they win. Otherwise the defending team wins once the timelimit passes.
1751 void assault_new_round();
1752 float WinningCondition_Assault()
1756 WinningConditionHelper(); // set worldstatus
1758 status = WINNING_NO;
1759 // as the timelimit has not yet passed just assume the defending team will win
1760 if(assault_attacker_team == COLOR_TEAM1)
1762 SetWinners(team, COLOR_TEAM2);
1766 SetWinners(team, COLOR_TEAM1);
1770 ent = find(world, classname, "target_assault_roundend");
1773 if(ent.winning) // round end has been triggered by attacking team
1775 bprint("ASSAULT: round completed...\n");
1776 SetWinners(team, assault_attacker_team);
1778 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
1780 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
1782 status = WINNING_YES;
1789 assault_new_round();
1798 // LMS winning condition: game terminates if and only if there's at most one
1799 // one player who's living lives. Top two scores being equal cancels the time
1801 float WinningCondition_LMS()
1808 have_player = FALSE;
1809 have_players = FALSE;
1810 l = LMS_NewPlayerLives();
1812 head = find(world, classname, "player");
1815 head2 = find(head, classname, "player");
1817 have_players = TRUE;
1821 // we have at least one player
1824 // two or more active players - continue with the game
1828 // exactly one player?
1831 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1835 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1841 // and assign him his first place
1842 PlayerScore_Add(head, SP_LMS_RANK, 1);
1849 // nobody is playing at all...
1852 // wait for players...
1856 // SNAFU (maybe a draw game?)
1858 dprint("No players, ending game.\n");
1863 // When we get here, we have at least two players who are actually LIVING,
1864 // now check if the top two players have equal score.
1865 WinningConditionHelper();
1868 if(WinningConditionHelper_winner)
1869 WinningConditionHelper_winner.winning = TRUE;
1870 if(WinningConditionHelper_topscore == WinningConditionHelper_secondscore)
1871 return WINNING_NEVER;
1873 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1877 void ShuffleMaplist()
1879 cvar_set("g_maplist", shufflewords(autocvar_g_maplist));
1883 float WinningCondition_Scores(float limit, float leadlimit)
1887 // TODO make everything use THIS winning condition (except LMS)
1888 WinningConditionHelper();
1892 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1893 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1894 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1895 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1899 if(WinningConditionHelper_winner)
1900 WinningConditionHelper_winner.winning = 1;
1901 if(WinningConditionHelper_winnerteam >= 0)
1902 SetWinners(team, WinningConditionHelper_winnerteam);
1904 if(WinningConditionHelper_lowerisbetter)
1906 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1907 WinningConditionHelper_secondscore = -WinningConditionHelper_secondscore;
1911 if(WinningConditionHelper_zeroisworst)
1912 leadlimit = 0; // not supported in this mode
1914 if(g_dm || g_tdm || g_arena || g_ca || (g_race && !g_race_qualifying) || g_nexball)
1915 // these modes always score in increments of 1, thus this makes sense
1917 if(leaderfrags != WinningConditionHelper_topscore)
1919 leaderfrags = WinningConditionHelper_topscore;
1922 if (leaderfrags == limit - 1)
1923 Announce("1fragleft");
1924 else if (leaderfrags == limit - 2)
1925 Announce("2fragsleft");
1926 else if (leaderfrags == limit - 3)
1927 Announce("3fragsleft");
1931 limitreached = FALSE;
1933 if(WinningConditionHelper_topscore >= limit)
1934 limitreached = TRUE;
1937 float leadlimitreached;
1938 leadlimitreached = (WinningConditionHelper_topscore - WinningConditionHelper_secondscore >= leadlimit);
1939 if(autocvar_leadlimit_and_fraglimit)
1940 limitreached = (limitreached && leadlimitreached);
1942 limitreached = (limitreached || leadlimitreached);
1945 return GetWinningCode(
1946 WinningConditionHelper_topscore && limitreached,
1947 WinningConditionHelper_equality
1951 float WinningCondition_Race(float fraglimit)
1962 if(p.race_completed)
1967 wc = WinningCondition_Scores(fraglimit, 0);
1969 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1970 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
1971 // do NOT support equality when the laps are all raced!
1972 return WINNING_STARTSUDDENDEATHOVERTIME;
1974 return WINNING_NEVER;
1978 float WinningCondition_QualifyingThenRace(float limit)
1981 wc = WinningCondition_Scores(limit, 0);
1983 // NEVER initiate overtime
1984 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
1992 float WinningCondition_RanOutOfSpawns()
1996 if(have_team_spawns <= 0)
1999 if(autocvar_g_spawn_useallspawns <= 0)
2002 if(!some_spawn_has_been_used)
2005 team1_score = team2_score = team3_score = team4_score = 0;
2007 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
2009 if(head.team == COLOR_TEAM1)
2011 else if(head.team == COLOR_TEAM2)
2013 else if(head.team == COLOR_TEAM3)
2015 else if(head.team == COLOR_TEAM4)
2019 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
2021 if(head.team == COLOR_TEAM1)
2023 else if(head.team == COLOR_TEAM2)
2025 else if(head.team == COLOR_TEAM3)
2027 else if(head.team == COLOR_TEAM4)
2032 if(team1_score + team2_score + team3_score + team4_score == 0)
2034 checkrules_equality = TRUE;
2037 else if(team1_score + team2_score + team3_score + team4_score == 1)
2040 if(team1_score) t = COLOR_TEAM1;
2041 if(team2_score) t = COLOR_TEAM2;
2042 if(team3_score) t = COLOR_TEAM3;
2043 if(team4_score) t = COLOR_TEAM4;
2044 CheckAllowedTeams(world);
2045 for(i = 0; i < MAX_TEAMSCORE; ++i)
2047 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
2048 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
2049 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
2050 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
2053 AddWinners(team, t);
2064 Exit deathmatch games upon conditions
2067 void ReadyRestart();
2068 void CheckRules_World()
2080 MapVote_Think should now do that part
2081 if (intermission_running)
2082 if (time >= intermission_exittime + 60)
2084 if(!DoNextMapOverride())
2090 if (gameover) // someone else quit the game already
2092 if(player_count == 0) // Nobody there? Then let's go to the next map
2094 // this will actually check the player count in the next frame
2095 // again, but this shouldn't hurt
2099 timelimit = autocvar_timelimit * 60;
2100 fraglimit = autocvar_fraglimit;
2101 leadlimit = autocvar_leadlimit;
2103 if(inWarmupStage || time <= game_starttime) // NOTE: this is <= to prevent problems in the very tic where the game starts
2106 timelimit = 0; // timelimit is not made for warmup
2108 fraglimit = 0; // no fraglimit for now
2109 leadlimit = 0; // no leadlimit for now
2113 timelimit = 0; // ONS has its own overtime rule
2117 timelimit += game_starttime;
2119 else if (timelimit < 0)
2129 if(checkrules_suddendeathend)
2131 if(!checkrules_suddendeathwarning)
2133 checkrules_suddendeathwarning = TRUE;
2134 if(g_race && !g_race_qualifying)
2135 bcenterprint("^3Everyone, finish your lap! The race is over!");
2137 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
2142 if (timelimit && time >= timelimit)
2144 if(g_race && (g_race_qualifying == 2) && timelimit > 0)
2147 float playerswithlaps;
2150 totalplayers = playerswithlaps = readyplayers = 0;
2151 FOR_EACH_PLAYER(head)
2154 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
2160 // at least 2 of the players have completed a lap: start the RACE
2161 // otherwise, the players should end the qualifying on their own
2162 if(readyplayers || playerswithlaps >= 2)
2164 checkrules_suddendeathend = 0;
2165 ReadyRestart(); // go to race
2169 wantovertime |= InitiateSuddenDeath();
2172 wantovertime |= InitiateSuddenDeath();
2176 if (checkrules_suddendeathend && time >= checkrules_suddendeathend)
2182 float checkrules_status;
2183 checkrules_status = WinningCondition_RanOutOfSpawns();
2184 if(checkrules_status == WINNING_YES)
2186 bprint("Hey! Someone ran out of spawns!\n");
2188 else if(g_race && !g_race_qualifying && timelimit >= 0)
2190 checkrules_status = WinningCondition_Race(fraglimit);
2191 //print("WC_RACE yields ", ftos(checkrules_status), "\n");
2193 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
2195 checkrules_status = WinningCondition_QualifyingThenRace(fraglimit);
2196 //print("WC_QUALIFYING_THEN_RACE yields ", ftos(checkrules_status), "\n");
2200 checkrules_status = WinningCondition_Assault(); // TODO remove this?
2204 checkrules_status = WinningCondition_LMS();
2206 else if (g_onslaught)
2208 checkrules_status = WinningCondition_Onslaught(); // TODO remove this?
2212 checkrules_status = WinningCondition_Scores(fraglimit, leadlimit);
2213 //print("WC_SCORES yields ", ftos(checkrules_status), "\n");
2216 if(checkrules_status == WINNING_STARTSUDDENDEATHOVERTIME)
2218 checkrules_status = WINNING_NEVER;
2219 checkrules_overtimesadded = -1;
2220 wantovertime |= InitiateSuddenDeath();
2223 if(checkrules_status == WINNING_NEVER)
2224 // equality cases! Nobody wins if the overtime ends in a draw.
2229 if(checkrules_status == WINNING_NEVER)
2232 checkrules_status = WINNING_YES;
2235 if(checkrules_suddendeathend)
2236 if(checkrules_status != WINNING_NEVER || time >= checkrules_suddendeathend)
2237 checkrules_status = WINNING_YES;
2239 if(checkrules_status == WINNING_YES)
2241 //print("WINNING\n");
2246 float mapvote_nextthink;
2247 float mapvote_initialized;
2248 float mapvote_keeptwotime;
2249 float mapvote_timeout;
2250 string mapvote_message;
2251 #define MAPVOTE_SCREENSHOT_DIRS_COUNT 4
2252 string mapvote_screenshot_dirs[MAPVOTE_SCREENSHOT_DIRS_COUNT];
2253 float mapvote_screenshot_dirs_count;
2255 float mapvote_count;
2256 float mapvote_count_real;
2257 string mapvote_maps[MAPVOTE_COUNT];
2258 float mapvote_maps_screenshot_dir[MAPVOTE_COUNT];
2259 string mapvote_maps_pakfile[MAPVOTE_COUNT];
2260 float mapvote_maps_suggested[MAPVOTE_COUNT];
2261 string mapvote_suggestions[MAPVOTE_COUNT];
2262 float mapvote_suggestion_ptr;
2263 float mapvote_voters;
2264 float mapvote_selections[MAPVOTE_COUNT];
2266 float mapvote_detail;
2267 float mapvote_abstain;
2270 void MapVote_ClearAllVotes()
2272 FOR_EACH_CLIENT(other)
2276 string MapVote_Suggest(string m)
2280 return "That's not how to use this command.";
2281 if(!autocvar_g_maplist_votable_suggestions)
2282 return "Suggestions are not accepted on this server.";
2283 if(mapvote_initialized)
2284 return "Can't suggest - voting is already in progress!";
2285 m = MapInfo_FixName(m);
2287 return "The map you suggested is not available on this server.";
2288 if(!autocvar_g_maplist_votable_suggestions_override_mostrecent)
2290 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
2292 if(!MapInfo_CheckMap(m))
2293 return "The map you suggested does not support the current game mode.";
2294 for(i = 0; i < mapvote_suggestion_ptr; ++i)
2295 if(mapvote_suggestions[i] == m)
2296 return "This map was already suggested.";
2297 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
2299 i = floor(random() * mapvote_suggestion_ptr);
2303 i = mapvote_suggestion_ptr;
2304 mapvote_suggestion_ptr += 1;
2306 if(mapvote_suggestions[i] != "")
2307 strunzone(mapvote_suggestions[i]);
2308 mapvote_suggestions[i] = strzone(m);
2309 if(autocvar_sv_eventlog)
2310 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
2311 return strcat("Suggestion of ", m, " accepted.");
2314 void MapVote_AddVotable(string nextMap, float isSuggestion)
2317 string pakfile, mapfile;
2321 for(j = 0; j < mapvote_count; ++j)
2322 if(mapvote_maps[j] == nextMap)
2324 // suggestions might be no longer valid/allowed after gametype switch!
2326 if(!MapInfo_CheckMap(nextMap))
2328 mapvote_maps[mapvote_count] = strzone(nextMap);
2329 mapvote_maps_suggested[mapvote_count] = isSuggestion;
2331 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2333 mapfile = strcat(mapvote_screenshot_dirs[i], "/", mapvote_maps[i]);
2334 pakfile = whichpack(strcat(mapfile, ".tga"));
2336 pakfile = whichpack(strcat(mapfile, ".jpg"));
2338 pakfile = whichpack(strcat(mapfile, ".png"));
2342 if(i >= mapvote_screenshot_dirs_count)
2343 i = 0; // FIXME maybe network this error case, as that means there is no mapshot on the server?
2344 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
2345 pakfile = substring(pakfile, o, -1);
2347 mapvote_maps_screenshot_dir[mapvote_count] = i;
2348 mapvote_maps_pakfile[mapvote_count] = strzone(pakfile);
2353 void MapVote_Spawn();
2359 MapVote_ClearAllVotes();
2362 mapvote_detail = !autocvar_g_maplist_votable_nodetail;
2363 mapvote_abstain = autocvar_g_maplist_votable_abstain;
2366 nmax = min(MAPVOTE_COUNT - 1, autocvar_g_maplist_votable);
2368 nmax = min(MAPVOTE_COUNT, autocvar_g_maplist_votable);
2369 smax = min3(nmax, autocvar_g_maplist_votable_suggestions, mapvote_suggestion_ptr);
2371 // we need this for AddVotable, as that cycles through the screenshot dirs
2372 mapvote_screenshot_dirs_count = tokenize_console(autocvar_g_maplist_votable_screenshot_dir);
2373 if(mapvote_screenshot_dirs_count == 0)
2374 mapvote_screenshot_dirs_count = tokenize_console("maps levelshots");
2375 mapvote_screenshot_dirs_count = min(mapvote_screenshot_dirs_count, MAPVOTE_SCREENSHOT_DIRS_COUNT);
2376 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2377 mapvote_screenshot_dirs[i] = strzone(argv(i));
2379 if(mapvote_suggestion_ptr)
2380 for(i = 0; i < 100 && mapvote_count < smax; ++i)
2381 MapVote_AddVotable(mapvote_suggestions[floor(random() * mapvote_suggestion_ptr)], TRUE);
2383 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2384 MapVote_AddVotable(GetNextMap(), FALSE);
2386 if(mapvote_count == 0)
2388 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
2389 cvar_set("g_maplist", MapInfo_ListAllAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
2390 if(autocvar_g_maplist_shuffle)
2392 localcmd("\nmenu_cmd sync\n");
2393 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2394 MapVote_AddVotable(GetNextMap(), FALSE);
2397 mapvote_count_real = mapvote_count;
2399 MapVote_AddVotable("don't care", 0);
2401 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
2403 mapvote_keeptwotime = time + autocvar_g_maplist_votable_keeptwotime;
2404 mapvote_timeout = time + autocvar_g_maplist_votable_timeout;
2405 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
2406 mapvote_keeptwotime = 0;
2407 mapvote_message = "Choose a map and press its key!";
2412 void MapVote_SendPicture(float id)
2415 WriteByte(MSG_ONE, SVC_TEMPENTITY);
2416 WriteByte(MSG_ONE, TE_CSQC_PICTURE);
2417 WriteByte(MSG_ONE, id);
2418 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dirs[mapvote_maps_screenshot_dir[id]], "/", mapvote_maps[id]), 3072);
2421 float MapVote_GetMapMask()
2423 float mask, i, power;
2425 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
2426 if(mapvote_maps[i] != "")
2432 float MapVote_SendEntity(entity to, float sf)
2437 sf &~= 2; // if we send 1, we don't need to also send 2
2439 WriteByte(MSG_ENTITY, ENT_CLIENT_MAPVOTE);
2440 WriteByte(MSG_ENTITY, sf);
2444 // flag 1 == initialization
2445 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2446 WriteString(MSG_ENTITY, mapvote_screenshot_dirs[i]);
2447 WriteString(MSG_ENTITY, "");
2448 WriteByte(MSG_ENTITY, mapvote_count);
2449 WriteByte(MSG_ENTITY, mapvote_abstain);
2450 WriteByte(MSG_ENTITY, mapvote_detail);
2451 WriteCoord(MSG_ENTITY, mapvote_timeout);
2452 if(mapvote_count <= 8)
2453 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2455 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2456 for(i = 0; i < mapvote_count; ++i)
2457 if(mapvote_maps[i] != "")
2459 if(mapvote_abstain && i == mapvote_count - 1)
2461 WriteString(MSG_ENTITY, ""); // abstain needs no text
2462 WriteString(MSG_ENTITY, ""); // abstain needs no pack
2463 WriteByte(MSG_ENTITY, 0); // abstain needs no screenshot dir
2467 WriteString(MSG_ENTITY, mapvote_maps[i]);
2468 WriteString(MSG_ENTITY, mapvote_maps_pakfile[i]);
2469 WriteByte(MSG_ENTITY, mapvote_maps_screenshot_dir[i]);
2476 // flag 2 == update of mask
2477 if(mapvote_count <= 8)
2478 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2480 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2486 for(i = 0; i < mapvote_count; ++i)
2487 if(mapvote_maps[i] != "")
2488 WriteByte(MSG_ENTITY, mapvote_selections[i]);
2490 WriteByte(MSG_ENTITY, to.mapvote);
2496 void MapVote_Spawn()
2498 Net_LinkEntity(mapvote_ent = spawn(), FALSE, 0, MapVote_SendEntity);
2501 void MapVote_TouchMask()
2503 mapvote_ent.SendFlags |= 2;
2506 void MapVote_TouchVotes(entity voter)
2508 mapvote_ent.SendFlags |= 4;
2511 float MapVote_Finished(float mappos)
2517 if(autocvar_sv_eventlog)
2519 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2520 result = strcat(result, ":", ftos(mapvote_selections[mappos]), "::");
2521 didntvote = mapvote_voters;
2522 for(i = 0; i < mapvote_count; ++i)
2523 if(mapvote_maps[i] != "")
2525 didntvote -= mapvote_selections[i];
2528 result = strcat(result, ":", mapvote_maps[i]);
2529 result = strcat(result, ":", ftos(mapvote_selections[i]));
2532 result = strcat(result, ":didn't vote:", ftos(didntvote));
2534 GameLogEcho(result);
2535 if(mapvote_maps_suggested[mappos])
2536 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
2539 FOR_EACH_REALCLIENT(other)
2540 FixClientCvars(other);
2542 Map_Goto_SetStr(mapvote_maps[mappos]);
2544 alreadychangedlevel = TRUE;
2547 void MapVote_CheckRules_1()
2551 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2553 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2554 mapvote_selections[i] = 0;
2558 FOR_EACH_REALCLIENT(other)
2563 i = other.mapvote - 1;
2564 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2565 mapvote_selections[i] = mapvote_selections[i] + 1;
2570 float MapVote_CheckRules_2()
2573 float firstPlace, secondPlace;
2574 float firstPlaceVotes, secondPlaceVotes;
2575 float mapvote_voters_real;
2578 if(mapvote_count_real == 1)
2579 return MapVote_Finished(0);
2581 mapvote_voters_real = mapvote_voters;
2583 mapvote_voters_real -= mapvote_selections[mapvote_count - 1];
2585 RandomSelection_Init();
2586 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2587 RandomSelection_Add(world, i, string_null, 1, mapvote_selections[i]);
2588 firstPlace = RandomSelection_chosen_float;
2589 firstPlaceVotes = RandomSelection_best_priority;
2590 //dprint("First place: ", ftos(firstPlace), "\n");
2591 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2593 RandomSelection_Init();
2594 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2596 RandomSelection_Add(world, i, string_null, 1, mapvote_selections[i]);
2597 secondPlace = RandomSelection_chosen_float;
2598 secondPlaceVotes = RandomSelection_best_priority;
2599 //dprint("Second place: ", ftos(secondPlace), "\n");
2600 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2602 if(firstPlace == -1)
2603 error("No first place in map vote... WTF?");
2605 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2606 return MapVote_Finished(firstPlace);
2608 if(mapvote_keeptwotime)
2609 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2612 MapVote_TouchMask();
2613 mapvote_message = "Now decide between the TOP TWO!";
2614 mapvote_keeptwotime = 0;
2615 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2616 result = strcat(result, ":", ftos(firstPlaceVotes));
2617 result = strcat(result, ":", mapvote_maps[secondPlace]);
2618 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2619 didntvote = mapvote_voters;
2620 for(i = 0; i < mapvote_count; ++i)
2621 if(mapvote_maps[i] != "")
2623 didntvote -= mapvote_selections[i];
2625 if(i != secondPlace)
2627 result = strcat(result, ":", mapvote_maps[i]);
2628 result = strcat(result, ":", ftos(mapvote_selections[i]));
2629 if(i < mapvote_count_real)
2631 strunzone(mapvote_maps[i]);
2632 mapvote_maps[i] = "";
2633 strunzone(mapvote_maps_pakfile[i]);
2634 mapvote_maps_pakfile[i] = "";
2638 result = strcat(result, ":didn't vote:", ftos(didntvote));
2639 if(autocvar_sv_eventlog)
2640 GameLogEcho(result);
2650 keeptwo = mapvote_keeptwotime;
2651 MapVote_CheckRules_1(); // count
2652 if(MapVote_CheckRules_2()) // decide
2656 FOR_EACH_REALCLIENT(other)
2658 // hide scoreboard again
2659 if(other.health != 2342)
2661 other.health = 2342;
2663 if(clienttype(other) == CLIENTTYPE_REAL)
2666 WriteByte(MSG_ONE, SVC_FINALE);
2667 WriteString(MSG_ONE, "");
2671 // clear possibly invalid votes
2672 if(mapvote_maps[other.mapvote - 1] == "")
2674 // use impulses as new vote
2675 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2676 if(mapvote_maps[other.impulse - 1] != "")
2678 other.mapvote = other.impulse;
2679 MapVote_TouchVotes(other);
2687 MapVote_CheckRules_1(); // just count
2689 void MapVote_Start()
2694 // wait for stats to be sent first
2695 if(!playerstats_waitforme)
2698 MapInfo_Enumerate();
2699 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
2702 void MapVote_Think()
2707 if(alreadychangedlevel)
2710 if(time < mapvote_nextthink)
2714 mapvote_nextthink = time + 0.5;
2716 if(!mapvote_initialized)
2718 if(autocvar_rescan_pending == 1)
2720 cvar_set("rescan_pending", "2");
2721 localcmd("fs_rescan\nrescan_pending 3\n");
2724 else if(autocvar_rescan_pending == 2)
2728 else if(autocvar_rescan_pending == 3)
2730 // now build missing mapinfo files
2731 if(!MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
2734 // we're done, start the timer
2735 cvar_set("rescan_pending", "0");
2738 mapvote_initialized = TRUE;
2739 if(DoNextMapOverride(0))
2741 if(!autocvar_g_maplist_votable || player_count <= 0)
2752 string GotoMap(string m)
2754 if(!MapInfo_CheckMap(m))
2755 return "The map you chose is not available on this server.";
2756 cvar_set("nextmap", m);
2757 cvar_set("timelimit", "-1");
2758 if(mapvote_initialized || alreadychangedlevel)
2760 if(DoNextMapOverride(0))
2761 return "Map switch initiated.";
2763 return "Hm... no. For some reason I like THIS map more.";
2766 return "Map switch will happen after scoreboard.";
2773 FOR_EACH_REALCLIENT(self)
2775 if(self.classname == "spectator")
2777 if(self.enemy.typehitsound)
2778 self.typehit_time = time;
2779 else if(self.enemy.hitsound)
2780 self.hit_time = time;
2784 if(self.typehitsound)
2785 self.typehit_time = time;
2786 else if(self.hitsound)
2787 self.hit_time = time;
2790 altime = time + frametime * (1 + autocvar_g_antilag_nudge);
2791 // add 1 frametime because after this, engine SV_Physics
2792 // increases time by a frametime and then networks the frame
2793 // add another frametime because client shows everything with
2794 // 1 frame of lag (cl_nolerp 0). The last +1 however should not be
2796 FOR_EACH_CLIENT(self)
2798 self.hitsound = FALSE;
2799 self.typehitsound = FALSE;
2800 antilag_record(self, altime);
2807 * returns TRUE if redirecting
2809 float redirection_timeout;
2810 float redirection_nextthink;
2811 float RedirectionThink()
2813 float clients_found;
2815 if(redirection_target == "")
2818 if(!redirection_timeout)
2820 cvar_set("sv_public", "-2");
2821 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2822 if(redirection_target == "self")
2823 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2825 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2828 if(time < redirection_nextthink)
2831 redirection_nextthink = time + 1;
2834 FOR_EACH_REALCLIENT(self)
2836 print("Redirecting: sending connect command to ", self.netname, "\n");
2837 if(redirection_target == "self")
2838 stuffcmd(self, "\ndisconnect; reconnect\n");
2840 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2844 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2846 if(time > redirection_timeout || clients_found == 0)
2847 localcmd("\nwait; wait; wait; quit\n");
2852 void TargetMusic_RestoreGame();
2855 // Loaded from a save game
2856 // some things then break, so let's work around them...
2858 // Progs DB (capture records)
2859 ServerProgsDB = db_load(strcat("server.db", autocvar_sessionid));
2863 MapInfo_Enumerate();
2864 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
2867 TargetMusic_RestoreGame();
2876 if(world_initialized > 0)
2878 world_initialized = 0;
2879 print("Saving persistent data...\n");
2882 PlayerStats_EndMatch(0);
2884 PlayerStats_AddGlobalInfo(e);
2885 PlayerStats_Shutdown();
2887 if(!cheatcount_total)
2889 if(autocvar_sv_db_saveasdump)
2890 db_dump(ServerProgsDB, strcat("server.db", autocvar_sessionid));
2892 db_save(ServerProgsDB, strcat("server.db", autocvar_sessionid));
2894 if(autocvar_developer)
2896 if(autocvar_sv_db_saveasdump)
2897 db_dump(TemporaryDB, "server-temp.db");
2899 db_save(TemporaryDB, "server-temp.db");
2901 CheatShutdown(); // must be after cheatcount check
2902 db_close(ServerProgsDB);
2903 db_close(TemporaryDB);
2905 // tell the bot system the game is ending now
2908 WeaponStats_Shutdown();
2911 else if(world_initialized == 0)
2913 print("NOTE: crashed before even initializing the world, not saving persistent data\n");