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_capture_leadlimit");
299 BADCVAR("g_ctf_flag_capture_effects");
300 BADCVAR("g_ctf_flag_glowtrails");
301 BADCVAR("g_ctf_flag_pickup_effects");
302 BADCVAR("g_domination_point_leadlimit");
303 BADCVAR("g_forced_respawn");
304 BADCVAR("g_keyhunt_point_leadlimit");
305 BADCVAR("g_nexball_goalleadlimit");
306 BADCVAR("g_runematch_point_leadlimit");
307 BADCVAR("leadlimit_and_fraglimit");
308 BADCVAR("leadlimit_override");
310 BADCVAR("sv_allow_fullbright");
311 BADCVAR("sv_checkforpacketsduringsleep");
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_capture_limit");
354 BADCVAR("g_ctf_ignore_frags");
355 BADCVAR("g_ctf_win_mode");
356 BADCVAR("g_domination_point_limit");
357 BADCVAR("g_friendlyfire");
358 BADCVAR("g_fullbrightitems");
359 BADCVAR("g_fullbrightplayers");
360 BADCVAR("g_keyhunt_point_limit");
361 BADCVAR("g_keyhunt_teams_override");
362 BADCVAR("g_lms_lives_override");
363 BADCVAR("g_maplist");
364 BADCVAR("g_maplist_check_waypoints");
365 BADCVAR("g_maplist_mostrecent_count");
366 BADCVAR("g_maplist_shuffle");
367 BADCVAR("g_maplist_votable");
368 BADCVAR("g_maplist_votable_abstain");
369 BADCVAR("g_maplist_votable_nodetail");
370 BADCVAR("g_maplist_votable_suggestions");
371 BADCVAR("g_maxplayers");
372 BADCVAR("g_minstagib");
373 BADCVAR("g_mirrordamage");
374 BADCVAR("g_nexball_goallimit");
375 BADCVAR("g_powerups");
376 BADCVAR("g_runematch_point_limit");
377 BADCVAR("g_start_delay");
379 BADCVAR("g_weapon_stay"); BADPRESUFFIX("g_", "_weapon_stay");
382 BADCVAR("maxplayers");
383 BADCVAR("minplayers");
384 BADCVAR("net_address");
386 BADCVAR("rcon_password");
387 BADCVAR("rcon_restricted_commands");
388 BADCVAR("rcon_restricted_password");
390 BADCVAR("sv_adminnick");
391 BADCVAR("sv_autoscreenshot");
392 BADCVAR("sv_autotaunt");
393 BADCVAR("sv_curl_defaulturl");
394 BADCVAR("sv_defaultcharacter");
395 BADCVAR("sv_defaultplayercolors");
396 BADCVAR("sv_defaultplayermodel");
397 BADCVAR("sv_defaultplayerskin");
398 BADCVAR("sv_maxidle");
399 BADCVAR("sv_maxrate");
401 BADCVAR("sv_public");
402 BADCVAR("sv_ready_restart");
403 BADCVAR("sv_status_privacy");
405 BADCVAR("sv_vote_call");
406 BADCVAR("sv_vote_commands");
407 BADCVAR("sv_vote_majority_factor");
408 BADCVAR("sv_vote_master");
409 BADCVAR("sv_vote_master_commands");
410 BADCVAR("sv_vote_master_password");
411 BADCVAR("sv_vote_simple_majority_factor");
412 BADCVAR("sys_ticrate");
413 BADCVAR("teamplay_mode");
414 BADCVAR("timelimit_override");
415 BADCVAR("g_spawnshieldtime");
416 BADPREFIX("g_warmup_");
417 BADPREFIX("sv_ready_restart_");
419 if(autocvar_g_minstagib)
421 BADCVAR("g_grappling_hook");
422 BADCVAR("g_jetpack");
429 cvar_purechanges = strcat(cvar_purechanges, k, " \"", v, "\" // \"", d, "\"\n");
430 if(strlen(cvar_purechanges) > 16384)
432 cvar_purechanges = "// too many settings have been changed to show them here\n";
436 ++cvar_purechanges_count;
437 // WARNING: this variable is used for the server list
438 // NEVER dare to skip this code!
439 // Hacks to intentionally appearing as "pure server" even though you DO have
440 // modified settings may be punished by removal from the server list.
441 // You can do to the variables cvar_changes and cvar_purechanges all you want,
445 if(cvar_changes == "")
446 cvar_changes = "// this server runs at default server settings\n";
448 cvar_changes = strcat("// this server runs at modified server settings:\n", cvar_changes);
449 cvar_changes = strzone(cvar_changes);
450 if(cvar_purechanges == "")
451 cvar_purechanges = "// this server runs at default gameplay settings\n";
453 cvar_purechanges = strcat("// this server runs at modified gameplay settings:\n", cvar_purechanges);
454 cvar_purechanges = strzone(cvar_purechanges);
457 void detect_maptype()
466 o_x += random() * (world.maxs_x - world.mins_x);
467 o_y += random() * (world.maxs_y - world.mins_y);
468 o_z += random() * (world.maxs_z - world.mins_z);
470 tracebox(o, PL_MIN, PL_MAX, o - '0 0 32768', MOVE_WORLDONLY, world);
471 if(trace_fraction == 1)
476 for(i = 0; i < 64; i += 4)
478 tracebox(o, '-1 -1 -1' * i, '1 1 1' * i, o - '0 0 32768', MOVE_WORLDONLY, world);
479 if(trace_fraction == 1)
481 print(ftos(i), " -> ", vtos(trace_endpos), "\n");
490 float RandomSeed_Send(entity to, float sf)
492 WriteByte(MSG_ENTITY, ENT_CLIENT_RANDOMSEED);
493 WriteShort(MSG_ENTITY, self.cnt);
496 void RandomSeed_Think()
498 self.cnt = bound(0, floor(random() * 65536), 65535);
499 self.nextthink = time + 5;
503 void RandomSeed_Spawn()
505 randomseed = spawn();
506 randomseed.think = RandomSeed_Think;
507 Net_LinkEntity(randomseed, FALSE, 0, RandomSeed_Send);
512 self.think(); // sets random seed and nextthink
516 void spawnfunc___init_dedicated_server(void)
518 // handler for _init/_init map (only for dedicated server initialization)
520 world_initialized = -1; // don't complain
522 cvar_string = cvar_string_normal;
523 cvar_set = cvar_set_normal;
525 remove = remove_unsafely;
529 e.think = GotoFirstMap;
530 e.nextthink = time; // this is usually 1 at this point
533 e.classname = "info_player_deathmatch"; // safeguard against player joining
535 self.classname = "worldspawn"; // safeguard against various stuff ;)
538 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
541 void Map_MarkAsRecent(string m);
542 float world_already_spawned;
543 void RegisterWeapons();
545 void ClientInit_Spawn();
546 void WeaponStats_Init();
547 void WeaponStats_Shutdown();
548 void spawnfunc_worldspawn (void)
550 float fd, l, i, j, n;
554 cvar_string = cvar_string_normal;
555 cvar_set = cvar_set_normal;
557 if(world_already_spawned)
558 error("world already spawned - you may have EXACTLY ONE worldspawn!");
559 world_already_spawned = TRUE;
561 remove = remove_safely; // during spawning, watch what you remove!
563 check_unacceptable_compiler_bugs();
565 cvar_changes_init(); // do this very early now so it REALLY matches the server config
567 compressShortVector_init();
569 allowed_to_spawn = TRUE;
572 head = nextent(world);
577 head = nextent(head);
580 // needs to be done so early as they would still spawn
583 ServerProgsDB = db_load(strcat("server.db", autocvar_sessionid));
585 TemporaryDB = db_create();
590 // 1 FLICKER (first variety)
591 lightstyle(1, "mmnmmommommnonmmonqnmmo");
593 // 2 SLOW STRONG PULSE
594 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
596 // 3 CANDLE (first variety)
597 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
600 lightstyle(4, "mamamamamama");
603 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
605 // 6 FLICKER (second variety)
606 lightstyle(6, "nmonqnmomnmomomno");
608 // 7 CANDLE (second variety)
609 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
611 // 8 CANDLE (third variety)
612 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
614 // 9 SLOW STROBE (fourth variety)
615 lightstyle(9, "aaaaaaaazzzzzzzz");
617 // 10 FLUORESCENT FLICKER
618 lightstyle(10, "mmamammmmammamamaaamammma");
620 // 11 SLOW PULSE NOT FADE TO BLACK
621 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
623 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
628 if(autocvar_g_campaign)
631 Map_MarkAsRecent(mapname);
633 precache_model ("null"); // we need this one before InitGameplayMode
641 bot_waypoints_for_items = autocvar_g_waypoints_for_items;
642 if(bot_waypoints_for_items == 1)
643 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
644 bot_waypoints_for_items = 0;
648 WaypointSprite_Init();
653 GameLogInit(); // prepare everything
655 // changing the logic generating it is okay. But:
656 // it HAS to stay <= 64 chars
657 // character set: ASCII 33-126 without the following characters: : ; ' " \ $
658 if(autocvar_sv_eventlog)
660 s = sprintf("%d.%s.%06d", ftos(autocvar_sv_eventlog_files_counter), strftime(FALSE, "%s"), floor(random() * 1000000));
661 matchid = strzone(s);
663 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
664 s = ":gameinfo:mutators:LIST";
667 MUTATOR_CALLHOOK(BuildMutatorsString);
670 // simple, probably not good in the mutator system
671 if(autocvar_g_grappling_hook)
672 s = strcat(s, ":grappling_hook");
674 // initialiation stuff, not good in the mutator system
675 if(!autocvar_g_use_ammunition)
676 s = strcat(s, ":no_use_ammunition");
678 // initialiation stuff, not good in the mutator system
679 if(autocvar_g_pickup_items == 0)
680 s = strcat(s, ":no_pickup_items");
681 if(autocvar_g_pickup_items > 0)
682 s = strcat(s, ":pickup_items");
684 // initialiation stuff, not good in the mutator system
685 if(autocvar_g_weaponarena != "0")
686 s = strcat(s, ":", autocvar_g_weaponarena, " arena");
688 // TODO to mutator system
689 if(autocvar_g_norecoil)
690 s = strcat(s, ":norecoil");
692 // TODO to mutator system
693 if(autocvar_g_midair)
694 s = strcat(s, ":midair");
696 // TODO to mutator system
697 if(autocvar_g_minstagib)
698 s = strcat(s, ":minstagib");
700 // TODO to mutator system
701 if(autocvar_g_powerups == 0)
702 s = strcat(s, ":no_powerups");
703 if(autocvar_g_powerups > 0)
704 s = strcat(s, ":powerups");
707 GameLogEcho(":gameinfo:end");
710 matchid = strzone(ftos(random()));
712 cvar_set("nextmap", "");
716 if(autocvar_g_campaign)
724 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
726 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
728 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
731 while((s = fgets(fd)))
733 l = tokenize_console(s);
738 print("Found ^1UNSUPPORTED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
739 print(" cdtrack ", argv(2), "\n");
741 else if(argv(0) == "fog")
743 print("Found ^1UNSUPPORTED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
744 print(" \"fog\" \"", s, "\"\n");
746 else if(argv(0) == "set")
748 print("Found ^1UNSUPPORTED^7 set command in .cfg file; put this line in mapinfo instead:\n");
749 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
751 else if(argv(0) != "//")
753 print("Found ^1UNSUPPORTED^7 set command in .cfg file; put this line in mapinfo instead:\n");
754 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
763 addstat(STAT_WEAPONS, AS_INT, weapons);
764 addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
765 addstat(STAT_SWITCHINGWEAPON, AS_INT, switchingweapon);
766 addstat(STAT_GAMESTARTTIME, AS_FLOAT, stat_game_starttime);
767 addstat(STAT_ALLOW_OLDNEXBEAM, AS_INT, stat_allow_oldnexbeam);
770 addstat(STAT_STRENGTH_FINISHED, AS_FLOAT, strength_finished);
771 addstat(STAT_INVINCIBLE_FINISHED, AS_FLOAT, invincible_finished);
772 addstat(STAT_PRESSED_KEYS, AS_FLOAT, pressedkeys);
773 addstat(STAT_FUEL, AS_INT, ammo_fuel);
774 addstat(STAT_SHOTORG, AS_INT, stat_shotorg);
775 addstat(STAT_LEADLIMIT, AS_FLOAT, stat_leadlimit);
776 addstat(STAT_WEAPON_CLIPLOAD, AS_INT, clip_load);
777 addstat(STAT_WEAPON_CLIPSIZE, AS_INT, clip_size);
778 addstat(STAT_LAST_PICKUP, AS_FLOAT, last_pickup);
779 addstat(STAT_HIT_TIME, AS_FLOAT, hit_time);
780 addstat(STAT_TYPEHIT_TIME, AS_FLOAT, typehit_time);
781 addstat(STAT_LAYED_MINES, AS_INT, minelayer_mines);
783 addstat(STAT_NEX_CHARGE, AS_FLOAT, nex_charge);
784 addstat(STAT_NEX_CHARGEPOOL, AS_FLOAT, nex_chargepool_ammo);
786 addstat(STAT_HAGAR_LOAD, AS_INT, hagar_load);
788 if(g_ca || g_freezetag)
790 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
791 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
792 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
793 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
797 addstat(STAT_FROZEN, AS_INT, freezetag_frozen);
798 addstat(STAT_REVIVE_PROGRESS, AS_FLOAT, freezetag_revive_progress);
801 // g_movementspeed hack
802 addstat(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW, AS_FLOAT, stat_sv_airspeedlimit_nonqw);
803 addstat(STAT_MOVEVARS_MAXSPEED, AS_FLOAT, stat_sv_maxspeed);
804 addstat(STAT_MOVEVARS_AIRACCEL_QW, AS_FLOAT, stat_sv_airaccel_qw);
805 addstat(STAT_MOVEVARS_AIRSTRAFEACCEL_QW, AS_FLOAT, stat_sv_airstrafeaccel_qw);
808 addstat(STAT_SECRETS_TOTAL, AS_FLOAT, stat_secrets_total);
809 addstat(STAT_SECRETS_FOUND, AS_FLOAT, stat_secrets_found);
811 next_pingtime = time + 5;
815 lsmaps_reply = "^7Maps available: ";
816 lsnewmaps_reply = "^7Maps without a record set: ";
817 for(i = 0, j = 0; i < MapInfo_count; ++i)
819 if(MapInfo_Get_ByID(i))
820 if not(MapInfo_Map_flags & (MAPINFO_FLAG_HIDDEN | MAPINFO_FLAG_FORBIDDEN))
827 lsmaps_reply = strcat(lsmaps_reply, col, MapInfo_Map_bspname, " ");
828 if(g_race && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "time"))))
829 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
830 else if(g_cts && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "time"))))
831 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
834 lsmaps_reply = strzone(strcat(lsmaps_reply, "\n"));
835 if (!g_race && !g_cts)
836 lsnewmaps_reply = "Need to be playing race or CTS for lsnewmaps to work.";
837 lsnewmaps_reply = strzone(strcat(lsnewmaps_reply, "\n"));
839 maplist_reply = "^7Maps in list: ";
840 n = tokenize_console(autocvar_g_maplist);
841 for(i = 0, j = 0; i < n; ++i)
843 if(MapInfo_CheckMap(argv(i)))
849 maplist_reply = strcat(maplist_reply, col, argv(i), " ");
853 maplist_reply = strzone(strcat(maplist_reply, "\n"));
854 MapInfo_ClearTemps();
856 for(i = 0; i < 10; ++i)
858 records_reply[i] = strzone(getrecords(i));
861 ladder_reply = strzone(getladder());
863 rankings_reply = strzone(getrankings());
867 PingPLReport_Spawn();
871 localcmd("\n_sv_hook_gamestart ", GetGametype(), "\n");
873 // fill sv_curl_serverpackages from .serverpackage files
874 if(autocvar_sv_curl_serverpackages_auto)
877 n = tokenize_console(cvar_string("sv_curl_serverpackages"));
878 for(i = 0; i < n; ++i)
879 if(substring(argv(i), -14, -1) != "-serverpackage.txt")
880 if(substring(argv(i), -14, -1) != ".serverpackage") // OLD legacy
881 s = strcat(s, " ", argv(i));
882 fd = search_begin("*-serverpackage.txt", TRUE, FALSE);
885 j = search_getsize(fd);
886 for(i = 0; i < j; ++i)
887 s = strcat(s, " ", search_getfilename(fd, i));
890 fd = search_begin("*.serverpackage", TRUE, FALSE);
893 j = search_getsize(fd);
894 for(i = 0; i < j; ++i)
895 s = strcat(s, " ", search_getfilename(fd, i));
898 cvar_set("sv_curl_serverpackages", substring(s, 1, -1));
903 world_initialized = 1;
906 void spawnfunc_light (void)
908 //makestatic (self); // Who the f___ did that?
914 return GametypeNameFromType(game);
917 string getmapname_stored;
923 float Map_Count, Map_Current;
924 string Map_Current_Name;
926 // NOTE: this now expects the map list to be already tokenized and the count in Map_Count
927 float GetMaplistPosition()
933 idx = autocvar_g_maplist_index;
940 for(pos = 0; pos < Map_Count; ++pos)
944 // resume normal maplist rotation if current map is not in g_maplist
948 float MapHasRightSize(string map)
951 if(currentbots || autocvar_bot_number || player_count < autocvar_minplayers)
952 if(autocvar_g_maplist_check_waypoints)
954 dprint("checkwp "); dprint(map);
955 if(!fexists(strcat("maps/", map, ".waypoints")))
957 dprint(": no waypoints\n");
960 dprint(": has waypoints\n");
963 // open map size restriction file
964 dprint("opensize "); dprint(map);
965 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
968 float mapmin, mapmax;
970 mapmin = stof(fgets(fh));
971 mapmax = stof(fgets(fh));
973 if(player_count < mapmin)
975 dprint("not enough\n");
978 if(player_count > mapmax)
980 dprint("too many\n");
983 dprint("right size\n");
986 dprint(": not found\n");
990 string Map_Filename(float position)
992 return strcat("maps/", argv(position), ".bsp");
995 string strwords(string s, float w)
998 for(endpos = 0; w && endpos >= 0; --w)
999 endpos = strstrofs(s, " ", endpos + 1);
1003 return substring(s, 0, endpos);
1006 float strhasword(string s, string w)
1008 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
1011 void Map_MarkAsRecent(string m)
1013 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", autocvar_g_maplist_mostrecent), max(0, autocvar_g_maplist_mostrecent_count)));
1016 float Map_IsRecent(string m)
1018 return strhasword(autocvar_g_maplist_mostrecent, m);
1021 float Map_Check(float position, float pass)
1025 map_next = argv(position);
1028 if(Map_IsRecent(map_next))
1031 filename = Map_Filename(position);
1032 if(MapInfo_CheckMap(map_next))
1036 if(MapHasRightSize(map_next))
1041 dprint( "Couldn't select '", filename, "'..\n" );
1046 void Map_Goto_SetStr(string nextmapname)
1048 if(getmapname_stored != "")
1049 strunzone(getmapname_stored);
1050 if(nextmapname == "")
1051 getmapname_stored = "";
1053 getmapname_stored = strzone(nextmapname);
1056 void Map_Goto_SetFloat(float position)
1058 cvar_set("g_maplist_index", ftos(position));
1059 Map_Goto_SetStr(argv(position));
1062 void Map_Goto(float reinit)
1064 MapInfo_LoadMap(getmapname_stored, reinit);
1067 // return codes of map selectors:
1068 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
1069 // -2 = permanent failure
1070 float() MaplistMethod_Iterate = // usual method
1074 for(pass = 1; pass <= 2; ++pass)
1076 for(i = 1; i < Map_Count; ++i)
1079 mapindex = mod(i + Map_Current, Map_Count);
1080 if(Map_Check(mapindex, pass))
1087 float() MaplistMethod_Repeat = // fallback method
1089 if(Map_Check(Map_Current, 2))
1094 float() MaplistMethod_Random = // random map selection
1100 for(i = 0; i <= imax; ++i)
1103 mapindex = mod(Map_Current + floor(random() * (Map_Count - 1) + 1), Map_Count); // any OTHER map
1104 if(Map_Check(mapindex, 1))
1110 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
1111 // the exponent sets a bias on the map selection:
1112 // the higher the exponent, the less likely "shortly repeated" same maps are
1114 float i, j, imax, insertpos;
1118 for(i = 0; i <= imax; ++i)
1122 // now reinsert this at another position
1123 insertpos = pow(random(), 1 / exponent); // ]0, 1]
1124 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
1125 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
1126 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
1128 // insert the current map there
1130 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
1131 newlist = strcat(newlist, " ", argv(j));
1132 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
1133 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
1134 newlist = strcat(newlist, " ", argv(j));
1135 newlist = substring(newlist, 1, strlen(newlist) - 1);
1136 cvar_set("g_maplist", newlist);
1137 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1139 // NOTE: the selected map has just been inserted at (insertpos-1)th position
1140 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
1141 if(Map_Check(Map_Current, 1))
1149 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1152 bprint( "Maplist is empty! Resetting it to default map list.\n" );
1153 cvar_set("g_maplist", MapInfo_ListAllAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
1154 if(autocvar_g_maplist_shuffle)
1156 localcmd("\nmenu_cmd sync\n");
1157 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1160 error("empty maplist, cannot select a new map");
1161 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
1163 if(Map_Current_Name)
1164 strunzone(Map_Current_Name);
1165 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
1166 // this may or may not be correct, but who cares, in the worst case a map
1167 // isn't chosen in the first pass that should have been
1178 if(autocvar_g_maplist_shuffle > 0)
1179 nextMap = MaplistMethod_Shuffle(autocvar_g_maplist_shuffle + 1);
1182 if(autocvar_g_maplist_selectrandom)
1183 nextMap = MaplistMethod_Random();
1186 nextMap = MaplistMethod_Iterate();
1189 nextMap = MaplistMethod_Repeat();
1193 Map_Goto_SetFloat(nextMap);
1194 return getmapname_stored;
1200 float DoNextMapOverride(float reinit)
1202 if(autocvar_g_campaign)
1204 CampaignPostIntermission();
1205 alreadychangedlevel = TRUE;
1208 if(autocvar_quit_when_empty)
1210 if(player_count <= currentbots)
1213 alreadychangedlevel = TRUE;
1217 if(autocvar_quit_and_redirect != "")
1219 redirection_target = strzone(autocvar_quit_and_redirect);
1220 alreadychangedlevel = TRUE;
1223 if (autocvar_samelevel) // if samelevel is set, stay on same level
1225 localcmd("restart\n");
1226 alreadychangedlevel = TRUE;
1229 if(autocvar_nextmap != "")
1230 if(MapInfo_CheckMap(autocvar_nextmap))
1232 Map_Goto_SetStr(autocvar_nextmap);
1234 alreadychangedlevel = TRUE;
1237 if(autocvar_lastlevel)
1239 cvar_settemp_restore();
1240 localcmd("set lastlevel 0\ntogglemenu 1\n");
1241 alreadychangedlevel = TRUE;
1247 void GotoNextMap(float reinit)
1252 if (alreadychangedlevel)
1254 alreadychangedlevel = TRUE;
1260 for(allowReset = 1; allowReset >= 0; --allowReset)
1262 nextMap = GetNextMap();
1268 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1269 cvar_set("g_maplist", MapInfo_ListAllAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
1270 if(autocvar_g_maplist_shuffle)
1272 localcmd("\nmenu_cmd sync\n");
1276 error("Everything is broken - not even the default map list works. Please report this to the developers.");
1288 When the player presses attack or jump, change to the next level
1291 .float autoscreenshot;
1292 void() MapVote_Start;
1293 void() MapVote_Think;
1294 float mapvote_initialized;
1295 void IntermissionThink()
1297 FixIntermissionClient(self);
1299 if( (autocvar_sv_autoscreenshot || self.cvar_cl_autoscreenshot)
1300 && ((self.autoscreenshot > 0) && (time > self.autoscreenshot)) )
1302 self.autoscreenshot = -1;
1303 if(clienttype(self) == CLIENTTYPE_REAL) { stuffcmd(self, sprintf("\nautoscreenshot \"%s\" \"%s\"\n", GetMapname(), strftime(FALSE, "%s"))); }
1307 if (time < intermission_exittime)
1310 if(!mapvote_initialized)
1311 if (time < intermission_exittime + 10 && !(self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE))
1321 Returns the entity to view from
1325 entity FindIntermission()
1330 // look for info_intermission first
1331 spot = find (world, classname, "info_intermission");
1333 { // pick a random one
1337 spot = find (spot, classname, "info_intermission");
1339 spot = find (spot, classname, "info_intermission");
1345 // then look for the start position
1346 spot = find (world, classname, "info_player_start");
1350 // testinfo_player_start is only found in regioned levels
1351 spot = find (world, classname, "testplayerstart");
1355 // then look for the start position
1356 spot = find (world, classname, "info_player_deathmatch");
1360 //objerror ("FindIntermission: no spot");
1366 ===============================================================================
1370 ===============================================================================
1373 void DumpStats(float final)
1382 to_console = autocvar_sv_logscores_console;
1383 to_eventlog = autocvar_sv_eventlog;
1384 to_file = autocvar_sv_logscores_file;
1388 to_console = TRUE; // always print printstats replies
1389 to_eventlog = FALSE; // but never print them to the event log
1393 if(autocvar_sv_eventlog_console)
1394 to_console = FALSE; // otherwise we get the output twice
1400 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
1408 file = fopen(autocvar_sv_logscores_filename, FILE_APPEND);
1412 fputs(file, strcat(s, "\n"));
1415 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
1421 fputs(file, strcat(s, "\n"));
1423 FOR_EACH_CLIENT(other)
1425 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && autocvar_sv_logscores_bots))
1427 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
1428 s = strcat(s, ftos(rint(time - other.jointime)), ":");
1429 if(other.classname == "player" || g_arena || g_ca || g_lms)
1430 s = strcat(s, ftos(other.team), ":");
1432 s = strcat(s, "spectator:");
1435 print(s, other.netname, "\n");
1437 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
1439 fputs(file, strcat(s, other.netname, "\n"));
1445 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
1451 fputs(file, strcat(s, "\n"));
1453 for(i = 1; i < 16; ++i)
1455 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
1456 s = strcat(s, ":", ftos(i));
1462 fputs(file, strcat(s, "\n"));
1469 GameLogEcho(":end");
1472 fputs(file, ":end\n");
1477 void FixIntermissionClient(entity e)
1480 if(!e.autoscreenshot) // initial call
1482 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1484 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1485 e.solid = SOLID_NOT;
1486 e.movetype = MOVETYPE_NONE;
1487 e.takedamage = DAMAGE_NO;
1490 e.weaponentity.effects = EF_NODRAW;
1491 if (e.weaponentity.weaponentity)
1492 e.weaponentity.weaponentity.effects = EF_NODRAW;
1494 if(clienttype(e) == CLIENTTYPE_REAL)
1496 stuffcmd(e, "\nscr_printspeed 1000000\n");
1497 s = autocvar_sv_intermission_cdtrack;
1499 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1501 WriteByte(MSG_ONE, SVC_INTERMISSION);
1508 go to the next level for deathmatch
1509 only called if a time or frag limit has expired
1515 intermission_running = 1;
1517 // enforce a wait time before allowing changelevel
1518 if(player_count > 0)
1519 intermission_exittime = time + autocvar_sv_mapchange_delay;
1521 intermission_exittime = -1;
1524 WriteByte (MSG_ALL, SVC_CDTRACK);
1525 WriteByte (MSG_ALL, 3);
1526 WriteByte (MSG_ALL, 3);
1527 // done in FixIntermission
1530 //pos = FindIntermission ();
1538 PlayerStats_EndMatch(1);
1540 PlayerStats_AddGlobalInfo(e);
1541 PlayerStats_Shutdown();
1542 WeaponStats_Shutdown();
1544 if(autocvar_sv_eventlog)
1545 GameLogEcho(":gameover");
1549 FOR_EACH_PLAYER(other) {
1550 FixIntermissionClient(other);
1552 bprint(other.netname, " ^7wins.\n");
1555 if(autocvar_g_campaign)
1556 CampaignPreIntermission();
1558 localcmd("\nsv_hook_gameend\n");
1565 Exit deathmatch games upon conditions
1568 void CheckRules_Player()
1570 if (gameover) // someone else quit the game already
1573 if(self.deadflag == DEAD_NO)
1574 self.play_time += frametime;
1576 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1577 // (div0: and that in CheckRules_World please)
1580 float checkrules_equality;
1581 float checkrules_suddendeathwarning;
1582 float checkrules_suddendeathend;
1583 float checkrules_overtimesadded; //how many overtimes have been already added
1585 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1586 float WINNING_YES = 1; // winner found
1587 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1588 float WINNING_STARTSUDDENDEATHOVERTIME = 3; // no winner, enter suddendeath overtime NOW
1590 float InitiateSuddenDeath()
1592 // Check first whether normal overtimes could be added before initiating suddendeath mode
1593 // - for this timelimit_overtime needs to be >0 of course
1594 // - also check the winning condition calculated in the previous frame and only add normal overtime
1595 // again, if at the point at which timelimit would be extended again, still no winner was found
1596 if ((checkrules_overtimesadded >= 0) && (checkrules_overtimesadded < autocvar_timelimit_overtimes) && autocvar_timelimit_overtime && !(g_race && !g_race_qualifying))
1598 return 1; // need to call InitiateOvertime later
1602 if(!checkrules_suddendeathend)
1604 checkrules_suddendeathend = time + 60 * autocvar_timelimit_suddendeath;
1605 if(g_race && !g_race_qualifying)
1606 race_StartCompleting();
1612 void InitiateOvertime() // ONLY call this if InitiateSuddenDeath returned true
1614 ++checkrules_overtimesadded;
1615 //add one more overtime by simply extending the timelimit
1617 tl = autocvar_timelimit;
1618 tl += autocvar_timelimit_overtime;
1619 cvar_set("timelimit", ftos(tl));
1620 string minutesPlural;
1621 if (autocvar_timelimit_overtime == 1)
1622 minutesPlural = " ^3minute";
1624 minutesPlural = " ^3minutes";
1628 "^3Now playing ^1OVERTIME^3!\n\n^3Added ^1",
1629 ftos(autocvar_timelimit_overtime),
1636 float GetWinningCode(float fraglimitreached, float equality)
1638 if(autocvar_g_campaign == 1)
1639 if(fraglimitreached)
1646 if(fraglimitreached)
1647 return WINNING_STARTSUDDENDEATHOVERTIME;
1649 return WINNING_NEVER;
1651 if(fraglimitreached)
1657 // set the .winning flag for exactly those players with a given field value
1658 void SetWinners(.float field, float value)
1661 FOR_EACH_PLAYER(head)
1662 head.winning = (head.field == value);
1665 // set the .winning flag for those players with a given field value
1666 void AddWinners(.float field, float value)
1669 FOR_EACH_PLAYER(head)
1670 if(head.field == value)
1674 // clear the .winning flags
1675 void ClearWinners(void)
1678 FOR_EACH_PLAYER(head)
1682 // Onslaught winning condition:
1683 // game terminates if only one team has a working generator (or none)
1684 float WinningCondition_Onslaught()
1687 float t1, t2, t3, t4;
1689 WinningConditionHelper(); // set worldstatus
1694 // first check if the game has ended
1695 t1 = t2 = t3 = t4 = 0;
1696 head = find(world, classname, "onslaught_generator");
1699 if (head.health > 0)
1701 if (head.team == COLOR_TEAM1) t1 = 1;
1702 if (head.team == COLOR_TEAM2) t2 = 1;
1703 if (head.team == COLOR_TEAM3) t3 = 1;
1704 if (head.team == COLOR_TEAM4) t4 = 1;
1706 head = find(head, classname, "onslaught_generator");
1708 if (t1 + t2 + t3 + t4 < 2)
1710 // game over, only one team remains (or none)
1712 if (t1) SetWinners(team, COLOR_TEAM1);
1713 if (t2) SetWinners(team, COLOR_TEAM2);
1714 if (t3) SetWinners(team, COLOR_TEAM3);
1715 if (t4) SetWinners(team, COLOR_TEAM4);
1716 dprint("Have a winner, ending game.\n");
1720 // Two or more teams remain
1724 float LMS_NewPlayerLives()
1727 fl = autocvar_fraglimit;
1731 // first player has left the game for dying too much? Nobody else can get in.
1732 if(lms_lowest_lives < 1)
1735 if(!autocvar_g_lms_join_anytime)
1736 if(lms_lowest_lives < fl - autocvar_g_lms_last_join)
1739 return bound(1, lms_lowest_lives, fl);
1742 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1743 // they win. Otherwise the defending team wins once the timelimit passes.
1744 void assault_new_round();
1745 float WinningCondition_Assault()
1749 WinningConditionHelper(); // set worldstatus
1751 status = WINNING_NO;
1752 // as the timelimit has not yet passed just assume the defending team will win
1753 if(assault_attacker_team == COLOR_TEAM1)
1755 SetWinners(team, COLOR_TEAM2);
1759 SetWinners(team, COLOR_TEAM1);
1763 ent = find(world, classname, "target_assault_roundend");
1766 if(ent.winning) // round end has been triggered by attacking team
1768 bprint("ASSAULT: round completed...\n");
1769 SetWinners(team, assault_attacker_team);
1771 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
1773 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
1775 status = WINNING_YES;
1782 assault_new_round();
1791 // LMS winning condition: game terminates if and only if there's at most one
1792 // one player who's living lives. Top two scores being equal cancels the time
1794 float WinningCondition_LMS()
1801 have_player = FALSE;
1802 have_players = FALSE;
1803 l = LMS_NewPlayerLives();
1805 head = find(world, classname, "player");
1808 head2 = find(head, classname, "player");
1810 have_players = TRUE;
1814 // we have at least one player
1817 // two or more active players - continue with the game
1821 // exactly one player?
1824 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1828 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1834 // and assign him his first place
1835 PlayerScore_Add(head, SP_LMS_RANK, 1);
1842 // nobody is playing at all...
1845 // wait for players...
1849 // SNAFU (maybe a draw game?)
1851 dprint("No players, ending game.\n");
1856 // When we get here, we have at least two players who are actually LIVING,
1857 // now check if the top two players have equal score.
1858 WinningConditionHelper();
1861 if(WinningConditionHelper_winner)
1862 WinningConditionHelper_winner.winning = TRUE;
1863 if(WinningConditionHelper_topscore == WinningConditionHelper_secondscore)
1864 return WINNING_NEVER;
1866 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1870 void ShuffleMaplist()
1872 cvar_set("g_maplist", shufflewords(autocvar_g_maplist));
1876 float WinningCondition_Scores(float limit, float leadlimit)
1880 // TODO make everything use THIS winning condition (except LMS)
1881 WinningConditionHelper();
1885 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1886 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1887 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1888 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1892 if(WinningConditionHelper_winner)
1893 WinningConditionHelper_winner.winning = 1;
1894 if(WinningConditionHelper_winnerteam >= 0)
1895 SetWinners(team, WinningConditionHelper_winnerteam);
1897 if(WinningConditionHelper_lowerisbetter)
1899 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1900 WinningConditionHelper_secondscore = -WinningConditionHelper_secondscore;
1904 if(WinningConditionHelper_zeroisworst)
1905 leadlimit = 0; // not supported in this mode
1907 if(g_dm || g_tdm || g_arena || g_ca || (g_race && !g_race_qualifying) || g_nexball)
1908 // these modes always score in increments of 1, thus this makes sense
1910 if(leaderfrags != WinningConditionHelper_topscore)
1912 leaderfrags = WinningConditionHelper_topscore;
1915 if (leaderfrags == limit - 1)
1916 Announce("1fragleft");
1917 else if (leaderfrags == limit - 2)
1918 Announce("2fragsleft");
1919 else if (leaderfrags == limit - 3)
1920 Announce("3fragsleft");
1924 limitreached = FALSE;
1926 if(WinningConditionHelper_topscore >= limit)
1927 limitreached = TRUE;
1930 float leadlimitreached;
1931 leadlimitreached = (WinningConditionHelper_topscore - WinningConditionHelper_secondscore >= leadlimit);
1932 if(autocvar_leadlimit_and_fraglimit)
1933 limitreached = (limitreached && leadlimitreached);
1935 limitreached = (limitreached || leadlimitreached);
1938 return GetWinningCode(
1939 WinningConditionHelper_topscore && limitreached,
1940 WinningConditionHelper_equality
1944 float WinningCondition_Race(float fraglimit)
1955 if(p.race_completed)
1960 wc = WinningCondition_Scores(fraglimit, 0);
1962 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1963 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
1964 // do NOT support equality when the laps are all raced!
1965 return WINNING_STARTSUDDENDEATHOVERTIME;
1967 return WINNING_NEVER;
1971 float WinningCondition_QualifyingThenRace(float limit)
1974 wc = WinningCondition_Scores(limit, 0);
1976 // NEVER initiate overtime
1977 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
1985 float WinningCondition_RanOutOfSpawns()
1989 if(have_team_spawns <= 0)
1992 if(autocvar_g_spawn_useallspawns <= 0)
1995 if(!some_spawn_has_been_used)
1998 team1_score = team2_score = team3_score = team4_score = 0;
2000 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
2002 if(head.team == COLOR_TEAM1)
2004 else if(head.team == COLOR_TEAM2)
2006 else if(head.team == COLOR_TEAM3)
2008 else if(head.team == COLOR_TEAM4)
2012 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
2014 if(head.team == COLOR_TEAM1)
2016 else if(head.team == COLOR_TEAM2)
2018 else if(head.team == COLOR_TEAM3)
2020 else if(head.team == COLOR_TEAM4)
2025 if(team1_score + team2_score + team3_score + team4_score == 0)
2027 checkrules_equality = TRUE;
2030 else if(team1_score + team2_score + team3_score + team4_score == 1)
2033 if(team1_score) t = COLOR_TEAM1;
2034 if(team2_score) t = COLOR_TEAM2;
2035 if(team3_score) t = COLOR_TEAM3;
2036 if(team4_score) t = COLOR_TEAM4;
2037 CheckAllowedTeams(world);
2038 for(i = 0; i < MAX_TEAMSCORE; ++i)
2040 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
2041 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
2042 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
2043 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
2046 AddWinners(team, t);
2057 Exit deathmatch games upon conditions
2060 void ReadyRestart();
2061 void CheckRules_World()
2073 MapVote_Think should now do that part
2074 if (intermission_running)
2075 if (time >= intermission_exittime + 60)
2077 if(!DoNextMapOverride())
2083 if (gameover) // someone else quit the game already
2085 if(player_count == 0) // Nobody there? Then let's go to the next map
2087 // this will actually check the player count in the next frame
2088 // again, but this shouldn't hurt
2092 timelimit = autocvar_timelimit * 60;
2093 fraglimit = autocvar_fraglimit;
2094 leadlimit = autocvar_leadlimit;
2096 if(inWarmupStage || time <= game_starttime) // NOTE: this is <= to prevent problems in the very tic where the game starts
2099 timelimit = 0; // timelimit is not made for warmup
2101 fraglimit = 0; // no fraglimit for now
2102 leadlimit = 0; // no leadlimit for now
2106 timelimit = 0; // ONS has its own overtime rule
2110 timelimit += game_starttime;
2112 else if (timelimit < 0)
2122 if(checkrules_suddendeathend)
2124 if(!checkrules_suddendeathwarning)
2126 checkrules_suddendeathwarning = TRUE;
2127 if(g_race && !g_race_qualifying)
2128 bcenterprint("^3Everyone, finish your lap! The race is over!");
2130 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
2135 if (timelimit && time >= timelimit)
2137 if(g_race && (g_race_qualifying == 2) && timelimit > 0)
2140 float playerswithlaps;
2143 totalplayers = playerswithlaps = readyplayers = 0;
2144 FOR_EACH_PLAYER(head)
2147 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
2153 // at least 2 of the players have completed a lap: start the RACE
2154 // otherwise, the players should end the qualifying on their own
2155 if(readyplayers || playerswithlaps >= 2)
2157 checkrules_suddendeathend = 0;
2158 ReadyRestart(); // go to race
2162 wantovertime |= InitiateSuddenDeath();
2165 wantovertime |= InitiateSuddenDeath();
2169 if (checkrules_suddendeathend && time >= checkrules_suddendeathend)
2175 float checkrules_status;
2176 checkrules_status = WinningCondition_RanOutOfSpawns();
2177 if(checkrules_status == WINNING_YES)
2179 bprint("Hey! Someone ran out of spawns!\n");
2181 else if(g_race && !g_race_qualifying && timelimit >= 0)
2183 checkrules_status = WinningCondition_Race(fraglimit);
2184 //print("WC_RACE yields ", ftos(checkrules_status), "\n");
2186 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
2188 checkrules_status = WinningCondition_QualifyingThenRace(fraglimit);
2189 //print("WC_QUALIFYING_THEN_RACE yields ", ftos(checkrules_status), "\n");
2193 checkrules_status = WinningCondition_Assault(); // TODO remove this?
2197 checkrules_status = WinningCondition_LMS();
2199 else if (g_onslaught)
2201 checkrules_status = WinningCondition_Onslaught(); // TODO remove this?
2205 checkrules_status = WinningCondition_Scores(fraglimit, leadlimit);
2206 //print("WC_SCORES yields ", ftos(checkrules_status), "\n");
2209 if(checkrules_status == WINNING_STARTSUDDENDEATHOVERTIME)
2211 checkrules_status = WINNING_NEVER;
2212 checkrules_overtimesadded = -1;
2213 wantovertime |= InitiateSuddenDeath();
2216 if(checkrules_status == WINNING_NEVER)
2217 // equality cases! Nobody wins if the overtime ends in a draw.
2222 if(checkrules_status == WINNING_NEVER)
2225 checkrules_status = WINNING_YES;
2228 if(checkrules_suddendeathend)
2229 if(checkrules_status != WINNING_NEVER || time >= checkrules_suddendeathend)
2230 checkrules_status = WINNING_YES;
2232 if(checkrules_status == WINNING_YES)
2234 //print("WINNING\n");
2239 float mapvote_nextthink;
2240 float mapvote_initialized;
2241 float mapvote_keeptwotime;
2242 float mapvote_timeout;
2243 string mapvote_message;
2244 #define MAPVOTE_SCREENSHOT_DIRS_COUNT 4
2245 string mapvote_screenshot_dirs[MAPVOTE_SCREENSHOT_DIRS_COUNT];
2246 float mapvote_screenshot_dirs_count;
2248 float mapvote_count;
2249 float mapvote_count_real;
2250 string mapvote_maps[MAPVOTE_COUNT];
2251 float mapvote_maps_screenshot_dir[MAPVOTE_COUNT];
2252 string mapvote_maps_pakfile[MAPVOTE_COUNT];
2253 float mapvote_maps_suggested[MAPVOTE_COUNT];
2254 string mapvote_suggestions[MAPVOTE_COUNT];
2255 float mapvote_suggestion_ptr;
2256 float mapvote_voters;
2257 float mapvote_selections[MAPVOTE_COUNT];
2259 float mapvote_detail;
2260 float mapvote_abstain;
2263 void MapVote_ClearAllVotes()
2265 FOR_EACH_CLIENT(other)
2269 string MapVote_Suggest(string m)
2273 return "That's not how to use this command.";
2274 if(!autocvar_g_maplist_votable_suggestions)
2275 return "Suggestions are not accepted on this server.";
2276 if(mapvote_initialized)
2277 return "Can't suggest - voting is already in progress!";
2278 m = MapInfo_FixName(m);
2280 return "The map you suggested is not available on this server.";
2281 if(!autocvar_g_maplist_votable_suggestions_override_mostrecent)
2283 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
2285 if(!MapInfo_CheckMap(m))
2286 return "The map you suggested does not support the current game mode.";
2287 for(i = 0; i < mapvote_suggestion_ptr; ++i)
2288 if(mapvote_suggestions[i] == m)
2289 return "This map was already suggested.";
2290 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
2292 i = floor(random() * mapvote_suggestion_ptr);
2296 i = mapvote_suggestion_ptr;
2297 mapvote_suggestion_ptr += 1;
2299 if(mapvote_suggestions[i] != "")
2300 strunzone(mapvote_suggestions[i]);
2301 mapvote_suggestions[i] = strzone(m);
2302 if(autocvar_sv_eventlog)
2303 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
2304 return strcat("Suggestion of ", m, " accepted.");
2307 void MapVote_AddVotable(string nextMap, float isSuggestion)
2310 string pakfile, mapfile;
2314 for(j = 0; j < mapvote_count; ++j)
2315 if(mapvote_maps[j] == nextMap)
2317 // suggestions might be no longer valid/allowed after gametype switch!
2319 if(!MapInfo_CheckMap(nextMap))
2321 mapvote_maps[mapvote_count] = strzone(nextMap);
2322 mapvote_maps_suggested[mapvote_count] = isSuggestion;
2324 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2326 mapfile = strcat(mapvote_screenshot_dirs[i], "/", mapvote_maps[i]);
2327 pakfile = whichpack(strcat(mapfile, ".tga"));
2329 pakfile = whichpack(strcat(mapfile, ".jpg"));
2331 pakfile = whichpack(strcat(mapfile, ".png"));
2335 if(i >= mapvote_screenshot_dirs_count)
2336 i = 0; // FIXME maybe network this error case, as that means there is no mapshot on the server?
2337 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
2338 pakfile = substring(pakfile, o, -1);
2340 mapvote_maps_screenshot_dir[mapvote_count] = i;
2341 mapvote_maps_pakfile[mapvote_count] = strzone(pakfile);
2346 void MapVote_Spawn();
2352 MapVote_ClearAllVotes();
2355 mapvote_detail = !autocvar_g_maplist_votable_nodetail;
2356 mapvote_abstain = autocvar_g_maplist_votable_abstain;
2359 nmax = min(MAPVOTE_COUNT - 1, autocvar_g_maplist_votable);
2361 nmax = min(MAPVOTE_COUNT, autocvar_g_maplist_votable);
2362 smax = min3(nmax, autocvar_g_maplist_votable_suggestions, mapvote_suggestion_ptr);
2364 // we need this for AddVotable, as that cycles through the screenshot dirs
2365 mapvote_screenshot_dirs_count = tokenize_console(autocvar_g_maplist_votable_screenshot_dir);
2366 if(mapvote_screenshot_dirs_count == 0)
2367 mapvote_screenshot_dirs_count = tokenize_console("maps levelshots");
2368 mapvote_screenshot_dirs_count = min(mapvote_screenshot_dirs_count, MAPVOTE_SCREENSHOT_DIRS_COUNT);
2369 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2370 mapvote_screenshot_dirs[i] = strzone(argv(i));
2372 if(mapvote_suggestion_ptr)
2373 for(i = 0; i < 100 && mapvote_count < smax; ++i)
2374 MapVote_AddVotable(mapvote_suggestions[floor(random() * mapvote_suggestion_ptr)], TRUE);
2376 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2377 MapVote_AddVotable(GetNextMap(), FALSE);
2379 if(mapvote_count == 0)
2381 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
2382 cvar_set("g_maplist", MapInfo_ListAllAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
2383 if(autocvar_g_maplist_shuffle)
2385 localcmd("\nmenu_cmd sync\n");
2386 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2387 MapVote_AddVotable(GetNextMap(), FALSE);
2390 mapvote_count_real = mapvote_count;
2392 MapVote_AddVotable("don't care", 0);
2394 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
2396 mapvote_keeptwotime = time + autocvar_g_maplist_votable_keeptwotime;
2397 mapvote_timeout = time + autocvar_g_maplist_votable_timeout;
2398 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
2399 mapvote_keeptwotime = 0;
2400 mapvote_message = "Choose a map and press its key!";
2405 void MapVote_SendPicture(float id)
2408 WriteByte(MSG_ONE, SVC_TEMPENTITY);
2409 WriteByte(MSG_ONE, TE_CSQC_PICTURE);
2410 WriteByte(MSG_ONE, id);
2411 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dirs[mapvote_maps_screenshot_dir[id]], "/", mapvote_maps[id]), 3072);
2414 float MapVote_GetMapMask()
2416 float mask, i, power;
2418 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
2419 if(mapvote_maps[i] != "")
2425 float MapVote_SendEntity(entity to, float sf)
2430 sf &~= 2; // if we send 1, we don't need to also send 2
2432 WriteByte(MSG_ENTITY, ENT_CLIENT_MAPVOTE);
2433 WriteByte(MSG_ENTITY, sf);
2437 // flag 1 == initialization
2438 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2439 WriteString(MSG_ENTITY, mapvote_screenshot_dirs[i]);
2440 WriteString(MSG_ENTITY, "");
2441 WriteByte(MSG_ENTITY, mapvote_count);
2442 WriteByte(MSG_ENTITY, mapvote_abstain);
2443 WriteByte(MSG_ENTITY, mapvote_detail);
2444 WriteCoord(MSG_ENTITY, mapvote_timeout);
2445 if(mapvote_count <= 8)
2446 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2448 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2449 for(i = 0; i < mapvote_count; ++i)
2450 if(mapvote_maps[i] != "")
2452 if(mapvote_abstain && i == mapvote_count - 1)
2454 WriteString(MSG_ENTITY, ""); // abstain needs no text
2455 WriteString(MSG_ENTITY, ""); // abstain needs no pack
2456 WriteByte(MSG_ENTITY, 0); // abstain needs no screenshot dir
2460 WriteString(MSG_ENTITY, mapvote_maps[i]);
2461 WriteString(MSG_ENTITY, mapvote_maps_pakfile[i]);
2462 WriteByte(MSG_ENTITY, mapvote_maps_screenshot_dir[i]);
2469 // flag 2 == update of mask
2470 if(mapvote_count <= 8)
2471 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2473 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2479 for(i = 0; i < mapvote_count; ++i)
2480 if(mapvote_maps[i] != "")
2481 WriteByte(MSG_ENTITY, mapvote_selections[i]);
2483 WriteByte(MSG_ENTITY, to.mapvote);
2489 void MapVote_Spawn()
2491 Net_LinkEntity(mapvote_ent = spawn(), FALSE, 0, MapVote_SendEntity);
2494 void MapVote_TouchMask()
2496 mapvote_ent.SendFlags |= 2;
2499 void MapVote_TouchVotes(entity voter)
2501 mapvote_ent.SendFlags |= 4;
2504 float MapVote_Finished(float mappos)
2510 if(autocvar_sv_eventlog)
2512 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2513 result = strcat(result, ":", ftos(mapvote_selections[mappos]), "::");
2514 didntvote = mapvote_voters;
2515 for(i = 0; i < mapvote_count; ++i)
2516 if(mapvote_maps[i] != "")
2518 didntvote -= mapvote_selections[i];
2521 result = strcat(result, ":", mapvote_maps[i]);
2522 result = strcat(result, ":", ftos(mapvote_selections[i]));
2525 result = strcat(result, ":didn't vote:", ftos(didntvote));
2527 GameLogEcho(result);
2528 if(mapvote_maps_suggested[mappos])
2529 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
2532 FOR_EACH_REALCLIENT(other)
2533 FixClientCvars(other);
2535 Map_Goto_SetStr(mapvote_maps[mappos]);
2537 alreadychangedlevel = TRUE;
2540 void MapVote_CheckRules_1()
2544 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2546 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2547 mapvote_selections[i] = 0;
2551 FOR_EACH_REALCLIENT(other)
2556 i = other.mapvote - 1;
2557 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2558 mapvote_selections[i] = mapvote_selections[i] + 1;
2563 float MapVote_CheckRules_2()
2566 float firstPlace, secondPlace;
2567 float firstPlaceVotes, secondPlaceVotes;
2568 float mapvote_voters_real;
2571 if(mapvote_count_real == 1)
2572 return MapVote_Finished(0);
2574 mapvote_voters_real = mapvote_voters;
2576 mapvote_voters_real -= mapvote_selections[mapvote_count - 1];
2578 RandomSelection_Init();
2579 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2580 RandomSelection_Add(world, i, string_null, 1, mapvote_selections[i]);
2581 firstPlace = RandomSelection_chosen_float;
2582 firstPlaceVotes = RandomSelection_best_priority;
2583 //dprint("First place: ", ftos(firstPlace), "\n");
2584 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2586 RandomSelection_Init();
2587 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2589 RandomSelection_Add(world, i, string_null, 1, mapvote_selections[i]);
2590 secondPlace = RandomSelection_chosen_float;
2591 secondPlaceVotes = RandomSelection_best_priority;
2592 //dprint("Second place: ", ftos(secondPlace), "\n");
2593 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2595 if(firstPlace == -1)
2596 error("No first place in map vote... WTF?");
2598 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2599 return MapVote_Finished(firstPlace);
2601 if(mapvote_keeptwotime)
2602 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2605 MapVote_TouchMask();
2606 mapvote_message = "Now decide between the TOP TWO!";
2607 mapvote_keeptwotime = 0;
2608 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2609 result = strcat(result, ":", ftos(firstPlaceVotes));
2610 result = strcat(result, ":", mapvote_maps[secondPlace]);
2611 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2612 didntvote = mapvote_voters;
2613 for(i = 0; i < mapvote_count; ++i)
2614 if(mapvote_maps[i] != "")
2616 didntvote -= mapvote_selections[i];
2618 if(i != secondPlace)
2620 result = strcat(result, ":", mapvote_maps[i]);
2621 result = strcat(result, ":", ftos(mapvote_selections[i]));
2622 if(i < mapvote_count_real)
2624 strunzone(mapvote_maps[i]);
2625 mapvote_maps[i] = "";
2626 strunzone(mapvote_maps_pakfile[i]);
2627 mapvote_maps_pakfile[i] = "";
2631 result = strcat(result, ":didn't vote:", ftos(didntvote));
2632 if(autocvar_sv_eventlog)
2633 GameLogEcho(result);
2643 keeptwo = mapvote_keeptwotime;
2644 MapVote_CheckRules_1(); // count
2645 if(MapVote_CheckRules_2()) // decide
2649 FOR_EACH_REALCLIENT(other)
2651 // hide scoreboard again
2652 if(other.health != 2342)
2654 other.health = 2342;
2656 if(clienttype(other) == CLIENTTYPE_REAL)
2659 WriteByte(MSG_ONE, SVC_FINALE);
2660 WriteString(MSG_ONE, "");
2664 // clear possibly invalid votes
2665 if(mapvote_maps[other.mapvote - 1] == "")
2667 // use impulses as new vote
2668 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2669 if(mapvote_maps[other.impulse - 1] != "")
2671 other.mapvote = other.impulse;
2672 MapVote_TouchVotes(other);
2680 MapVote_CheckRules_1(); // just count
2682 void MapVote_Start()
2687 // wait for stats to be sent first
2688 if(!playerstats_waitforme)
2691 MapInfo_Enumerate();
2692 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
2695 void MapVote_Think()
2700 if(alreadychangedlevel)
2703 if(time < mapvote_nextthink)
2707 mapvote_nextthink = time + 0.5;
2709 if(!mapvote_initialized)
2711 if(autocvar_rescan_pending == 1)
2713 cvar_set("rescan_pending", "2");
2714 localcmd("fs_rescan\nrescan_pending 3\n");
2717 else if(autocvar_rescan_pending == 2)
2721 else if(autocvar_rescan_pending == 3)
2723 // now build missing mapinfo files
2724 if(!MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
2727 // we're done, start the timer
2728 cvar_set("rescan_pending", "0");
2731 mapvote_initialized = TRUE;
2732 if(DoNextMapOverride(0))
2734 if(!autocvar_g_maplist_votable || player_count <= 0)
2745 string GotoMap(string m)
2747 if(!MapInfo_CheckMap(m))
2748 return "The map you chose is not available on this server.";
2749 cvar_set("nextmap", m);
2750 cvar_set("timelimit", "-1");
2751 if(mapvote_initialized || alreadychangedlevel)
2753 if(DoNextMapOverride(0))
2754 return "Map switch initiated.";
2756 return "Hm... no. For some reason I like THIS map more.";
2759 return "Map switch will happen after scoreboard.";
2766 FOR_EACH_REALCLIENT(self)
2768 if(self.classname == "spectator")
2770 if(self.enemy.typehitsound)
2771 self.typehit_time = time;
2772 else if(self.enemy.hitsound)
2773 self.hit_time = time;
2777 if(self.typehitsound)
2778 self.typehit_time = time;
2779 else if(self.hitsound)
2780 self.hit_time = time;
2783 altime = time + frametime * (1 + autocvar_g_antilag_nudge);
2784 // add 1 frametime because after this, engine SV_Physics
2785 // increases time by a frametime and then networks the frame
2786 // add another frametime because client shows everything with
2787 // 1 frame of lag (cl_nolerp 0). The last +1 however should not be
2789 FOR_EACH_CLIENT(self)
2791 self.hitsound = FALSE;
2792 self.typehitsound = FALSE;
2793 antilag_record(self, altime);
2800 * returns TRUE if redirecting
2802 float redirection_timeout;
2803 float redirection_nextthink;
2804 float RedirectionThink()
2806 float clients_found;
2808 if(redirection_target == "")
2811 if(!redirection_timeout)
2813 cvar_set("sv_public", "-2");
2814 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2815 if(redirection_target == "self")
2816 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2818 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2821 if(time < redirection_nextthink)
2824 redirection_nextthink = time + 1;
2827 FOR_EACH_REALCLIENT(self)
2829 print("Redirecting: sending connect command to ", self.netname, "\n");
2830 if(redirection_target == "self")
2831 stuffcmd(self, "\ndisconnect; reconnect\n");
2833 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2837 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2839 if(time > redirection_timeout || clients_found == 0)
2840 localcmd("\nwait; wait; wait; quit\n");
2845 void TargetMusic_RestoreGame();
2848 // Loaded from a save game
2849 // some things then break, so let's work around them...
2851 // Progs DB (capture records)
2852 ServerProgsDB = db_load(strcat("server.db", autocvar_sessionid));
2856 MapInfo_Enumerate();
2857 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
2860 TargetMusic_RestoreGame();
2869 if(world_initialized > 0)
2871 world_initialized = 0;
2872 print("Saving persistent data...\n");
2875 PlayerStats_EndMatch(0);
2877 PlayerStats_AddGlobalInfo(e);
2878 PlayerStats_Shutdown();
2880 if(!cheatcount_total)
2882 if(autocvar_sv_db_saveasdump)
2883 db_dump(ServerProgsDB, strcat("server.db", autocvar_sessionid));
2885 db_save(ServerProgsDB, strcat("server.db", autocvar_sessionid));
2887 if(autocvar_developer)
2889 if(autocvar_sv_db_saveasdump)
2890 db_dump(TemporaryDB, "server-temp.db");
2892 db_save(TemporaryDB, "server-temp.db");
2894 CheatShutdown(); // must be after cheatcount check
2895 db_close(ServerProgsDB);
2896 db_close(TemporaryDB);
2898 // tell the bot system the game is ending now
2901 WeaponStats_Shutdown();
2904 else if(world_initialized == 0)
2906 print("NOTE: crashed before even initializing the world, not saving persistent data\n");