1 #define LATENCY_THINKRATE 10
6 void PingPLReport_Think()
11 delta = 3 / maxclients;
12 if(delta < sys_frametime)
14 self.nextthink = time + delta;
16 e = edict_num(self.cnt + 1);
17 if(clienttype(e) == CLIENTTYPE_REAL)
19 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
20 WriteByte(MSG_BROADCAST, TE_CSQC_PINGPLREPORT);
21 WriteByte(MSG_BROADCAST, self.cnt);
22 WriteShort(MSG_BROADCAST, max(1, e.ping));
23 WriteByte(MSG_BROADCAST, ceil(e.ping_packetloss * 255));
24 WriteByte(MSG_BROADCAST, ceil(e.ping_movementloss * 255));
26 // record latency times for clients throughout the match so we can report it to playerstats
27 if(time > (e.latency_time + LATENCY_THINKRATE))
29 e.latency_sum += e.ping;
31 e.latency_time = time;
32 //print("sum: ", ftos(e.latency_sum), ", cnt: ", ftos(e.latency_cnt), ", avg: ", ftos(e.latency_sum / e.latency_cnt), ".\n");
37 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
38 WriteByte(MSG_BROADCAST, TE_CSQC_PINGPLREPORT);
39 WriteByte(MSG_BROADCAST, self.cnt);
40 WriteShort(MSG_BROADCAST, 0);
41 WriteByte(MSG_BROADCAST, 0);
42 WriteByte(MSG_BROADCAST, 0);
44 self.cnt = mod(self.cnt + 1, maxclients);
46 void PingPLReport_Spawn()
48 pingplreport = spawn();
49 pingplreport.classname = "pingplreport";
50 pingplreport.think = PingPLReport_Think;
51 pingplreport.nextthink = time;
54 float SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS = 1;
55 string redirection_target;
56 float world_initialized;
60 void GotoNextMap(float reinit);
61 void ShuffleMaplist();
62 float(float reinit) DoNextMapOverride;
64 void SetDefaultAlpha()
66 if(autocvar_g_running_guns)
68 default_player_alpha = -1;
69 default_weapon_alpha = +1;
73 default_player_alpha = autocvar_g_balance_cloaked_alpha;
74 default_weapon_alpha = default_player_alpha;
78 default_player_alpha = autocvar_g_player_alpha;
79 if(default_player_alpha == 0)
80 default_player_alpha = 1;
81 default_weapon_alpha = default_player_alpha;
85 void fteqcc_testbugs()
89 if(!autocvar_developer_fteqccbugs)
92 dprint("*** fteqcc test: checking for bugs...\n");
96 if(sqrt(a) - sqrt(b - a) == 0)
97 dprint("*** fteqcc test: found same-function-twice bug\n");
99 dprint("*** fteqcc test: same-function-twice bug got FINALLY FIXED! HOORAY!\n");
103 world.enemy.cnt += 10;
104 if(world.cnt > 0.2 || world.cnt < -0.2) // don't error out if it's just roundoff errors
105 dprint("*** fteqcc test: found += bug\n");
107 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
114 if(autocvar__sv_init)
116 // cvar_set("_sv_init", "0");
117 // we do NOT set this to 0 any more, so someone "accidentally" changing
118 // to this "init" map on a dedicated server will cause no permanent
120 if(autocvar_g_maplist_shuffle)
122 n = tokenizebyseparator(autocvar_g_maplist, " ");
123 cvar_set("g_maplist_index", ftos(n - 1)); // jump to map 0 in GotoNextMap
126 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
128 if(!DoNextMapOverride(1))
136 self.nextthink = time;
140 self.nextthink = time + 1;
141 print("Waiting for _sv_init being set to 1 by initialization scripts...\n");
145 void cvar_changes_init()
149 float n, i, adding, pureadding;
152 strunzone(cvar_changes);
153 cvar_changes = string_null;
155 strunzone(cvar_purechanges);
156 cvar_purechanges = string_null;
157 cvar_purechanges_count = 0;
160 buf_cvarlist(h, "", "_"); // exclude all _ cvars as they are temporary
166 for(i = 0; i < n; ++i)
168 k = bufstr_get(h, i);
170 #define BADPREFIX(p) if(substring(k, 0, strlen(p)) == p) continue
171 #define BADPRESUFFIX(p,s) if(substring(k, 0, strlen(p)) == p && substring(k, -strlen(s), -1) == s) continue
172 #define BADCVAR(p) if(k == p) continue
174 // general excludes and namespaces for server admin used cvars
175 BADPREFIX("help_"); // PN's server has this listed as changed, let's not rat him out for THAT
179 BADPREFIX("cvar_check_");
181 BADCVAR("g_configversion");
182 BADCVAR("g_maplist_index");
183 BADCVAR("halflifebsp");
184 BADPREFIX("sv_world");
190 BADPREFIX("scoreboard_");
191 BADPREFIX("g_campaign");
192 BADPREFIX("g_waypointsprite_");
198 BADPREFIX("net_slist_");
204 BADPREFIX("sensitivity");
205 BADPREFIX("userbind");
208 BADPREFIX("crosshair");
209 BADCVAR("mod_q3bsp_lightmapmergepower");
210 BADCVAR("mod_q3bsp_nolightmaps");
212 BADCVAR("mastervolume");
214 BADCVAR("bgmvolume");
217 BADCVAR("developer");
218 BADCVAR("log_dest_udp");
220 BADCVAR("net_address");
221 BADCVAR("net_address_ipv6");
223 BADCVAR("savedgamecfg");
224 BADCVAR("serverconfig");
225 BADCVAR("sv_autoscreenshot");
226 BADCVAR("sv_heartbeatperiod");
227 BADCVAR("sv_vote_master_password");
228 BADCVAR("sys_colortranslation");
229 BADCVAR("sys_specialcharactertranslation");
230 BADCVAR("timeformat");
231 BADCVAR("timestamps");
232 BADPREFIX("developer_");
234 BADPREFIX("g_banned_list");
235 BADPREFIX("g_chat_flood_");
236 BADPREFIX("g_ghost_items");
237 BADPREFIX("g_playerstats_");
238 BADPREFIX("g_respawn_ghosts");
239 BADPREFIX("g_voice_flood_");
241 BADPREFIX("sv_allowdownloads");
242 BADPREFIX("sv_autodemo");
243 BADPREFIX("sv_curl_");
244 BADPREFIX("sv_eventlog");
245 BADPREFIX("sv_logscores_");
246 BADPREFIX("sv_master");
247 BADPREFIX("sv_weaponstats_");
248 BADPREFIX("sv_waypointsprite_");
249 BADCVAR("rescan_pending");
251 // these can contain player IDs, so better hide
252 BADPREFIX("g_forced_team_");
255 BADCVAR("fraglimit");
257 BADCVAR("g_assault");
262 BADCVAR("g_domination");
263 BADCVAR("g_domination_default_teams");
264 BADCVAR("g_freezetag");
265 BADCVAR("g_keepaway");
266 BADCVAR("g_keyhunt");
267 BADCVAR("g_keyhunt_teams");
268 BADCVAR("g_keyhunt_teams");
270 BADCVAR("g_nexball");
271 BADCVAR("g_onslaught");
273 BADCVAR("g_race_qualifying_timelimit");
274 BADCVAR("g_runematch");
276 BADCVAR("g_tdm_teams");
277 BADCVAR("leadlimit");
280 BADCVAR("timelimit");
284 BADCVAR("g_maplist");
285 BADCVAR("g_maplist_mostrecent");
289 d = cvar_defstring(k);
295 cvar_changes = strcat(cvar_changes, k, " \"", v, "\" // \"", d, "\"\n");
296 if(strlen(cvar_changes) > 16384)
298 cvar_changes = "// too many settings have been changed to show them here\n";
303 // now check if the changes are actually gameplay relevant
305 // does nothing visible
306 BADCVAR("captureleadlimit_override");
307 BADCVAR("g_arena_point_leadlimit");
308 BADCVAR("g_balance_kill_delay");
309 BADCVAR("g_ca_point_leadlimit");
310 BADCVAR("g_ctf_captimerecord_always");
311 BADCVAR("g_ctf_flag_glowtrails");
312 BADCVAR("g_ctf_flag_pickup_verbosename");
313 BADCVAR("g_domination_point_leadlimit");
314 BADCVAR("g_forced_respawn");
315 BADCVAR("g_keyhunt_point_leadlimit");
317 BADCVAR("g_nexball_goalleadlimit");
318 BADCVAR("g_runematch_point_leadlimit");
319 BADCVAR("leadlimit_and_fraglimit");
320 BADCVAR("leadlimit_override");
322 BADCVAR("sv_allow_fullbright");
323 BADCVAR("sv_checkforpacketsduringsleep");
324 BADCVAR("sv_fraginfo");
325 BADCVAR("sv_timeout");
326 BADPREFIX("sv_timeout_");
327 BADCVAR("welcome_message_time");
328 BADPREFIX("crypto_");
329 BADPREFIX("g_chat_");
330 BADPREFIX("g_ctf_captimerecord_");
331 BADPREFIX("g_maplist_votable_");
335 BADPREFIX("sv_cullentities_");
336 BADPREFIX("sv_fraginfo_");
337 BADPREFIX("sv_maxidle_");
338 BADPREFIX("sv_vote_");
339 BADPREFIX("timelimit_");
340 BADCVAR("gameversion");
341 BADPREFIX("gameversion_");
342 BADCVAR("sv_namechangetimer");
343 #ifndef NO_LEGACY_NETWORKING
344 BADCVAR("sv_use_csqc_players"); // transition
347 // allowed changes to server admins (please sync this to server.cfg)
351 // :%s,//\([^ ]*\).*,BADCVAR("\1");,
353 // yes, this does contain some redundant stuff, don't really care
354 BADCVAR("bot_config_file");
355 BADCVAR("bot_number");
356 BADCVAR("bot_prefix");
357 BADCVAR("bot_suffix");
358 BADCVAR("capturelimit_override");
359 BADCVAR("fraglimit_override");
361 BADCVAR("g_antilag");
362 BADCVAR("g_balance_teams");
363 BADCVAR("g_balance_teams_prevent_imbalance");
364 BADCVAR("g_balance_teams_scorefactor");
365 BADCVAR("g_ban_sync_trusted_servers");
366 BADCVAR("g_ban_sync_uri");
367 BADCVAR("g_ctf_ignore_frags");
368 BADCVAR("g_domination_point_limit");
369 BADCVAR("g_friendlyfire");
370 BADCVAR("g_fullbrightitems");
371 BADCVAR("g_fullbrightplayers");
372 BADCVAR("g_keyhunt_point_limit");
373 BADCVAR("g_keyhunt_teams_override");
374 BADCVAR("g_lms_lives_override");
375 BADCVAR("g_maplist");
376 BADCVAR("g_maplist_check_waypoints");
377 BADCVAR("g_maplist_mostrecent_count");
378 BADCVAR("g_maplist_shuffle");
379 BADCVAR("g_maplist_votable");
380 BADCVAR("g_maplist_votable_abstain");
381 BADCVAR("g_maplist_votable_nodetail");
382 BADCVAR("g_maplist_votable_suggestions");
383 BADCVAR("g_maxplayers");
384 BADCVAR("g_mirrordamage");
385 BADCVAR("g_nexball_goallimit");
386 BADCVAR("g_powerups");
387 BADCVAR("g_runematch_point_limit");
388 BADCVAR("g_start_delay");
390 BADCVAR("g_weapon_stay"); BADPRESUFFIX("g_", "_weapon_stay");
393 BADCVAR("maxplayers");
394 BADCVAR("minplayers");
395 BADCVAR("net_address");
397 BADCVAR("rcon_password");
398 BADCVAR("rcon_restricted_commands");
399 BADCVAR("rcon_restricted_password");
401 BADCVAR("sv_adminnick");
402 BADCVAR("sv_autoscreenshot");
403 BADCVAR("sv_autotaunt");
404 BADCVAR("sv_curl_defaulturl");
405 BADCVAR("sv_defaultcharacter");
406 BADCVAR("sv_defaultplayercolors");
407 BADCVAR("sv_defaultplayermodel");
408 BADCVAR("sv_defaultplayerskin");
409 BADCVAR("sv_maxidle");
410 BADCVAR("sv_maxrate");
412 BADCVAR("sv_public");
413 BADCVAR("sv_ready_restart");
414 BADCVAR("sv_status_privacy");
416 BADCVAR("sv_vote_call");
417 BADCVAR("sv_vote_commands");
418 BADCVAR("sv_vote_majority_factor");
419 BADCVAR("sv_vote_master");
420 BADCVAR("sv_vote_master_commands");
421 BADCVAR("sv_vote_master_password");
422 BADCVAR("sv_vote_simple_majority_factor");
423 BADCVAR("sys_ticrate");
424 BADCVAR("teamplay_mode");
425 BADCVAR("timelimit_override");
426 BADCVAR("g_spawnshieldtime");
427 BADPREFIX("g_warmup_");
428 BADPREFIX("sv_ready_restart_");
430 // mutators that announce themselves properly to the server browser
431 BADCVAR("g_minstagib");
432 BADCVAR("g_new_toys");
435 if(autocvar_g_minstagib)
437 BADCVAR("g_grappling_hook");
438 BADCVAR("g_jetpack");
445 cvar_purechanges = strcat(cvar_purechanges, k, " \"", v, "\" // \"", d, "\"\n");
446 if(strlen(cvar_purechanges) > 16384)
448 cvar_purechanges = "// too many settings have been changed to show them here\n";
452 ++cvar_purechanges_count;
453 // WARNING: this variable is used for the server list
454 // NEVER dare to skip this code!
455 // Hacks to intentionally appearing as "pure server" even though you DO have
456 // modified settings may be punished by removal from the server list.
457 // You can do to the variables cvar_changes and cvar_purechanges all you want,
461 if(cvar_changes == "")
462 cvar_changes = "// this server runs at default server settings\n";
464 cvar_changes = strcat("// this server runs at modified server settings:\n", cvar_changes);
465 cvar_changes = strzone(cvar_changes);
466 if(cvar_purechanges == "")
467 cvar_purechanges = "// this server runs at default gameplay settings\n";
469 cvar_purechanges = strcat("// this server runs at modified gameplay settings:\n", cvar_purechanges);
470 cvar_purechanges = strzone(cvar_purechanges);
473 void detect_maptype()
482 o_x += random() * (world.maxs_x - world.mins_x);
483 o_y += random() * (world.maxs_y - world.mins_y);
484 o_z += random() * (world.maxs_z - world.mins_z);
486 tracebox(o, PL_MIN, PL_MAX, o - '0 0 32768', MOVE_WORLDONLY, world);
487 if(trace_fraction == 1)
492 for(i = 0; i < 64; i += 4)
494 tracebox(o, '-1 -1 -1' * i, '1 1 1' * i, o - '0 0 32768', MOVE_WORLDONLY, world);
495 if(trace_fraction == 1)
497 print(ftos(i), " -> ", vtos(trace_endpos), "\n");
506 float RandomSeed_Send(entity to, float sf)
508 WriteByte(MSG_ENTITY, ENT_CLIENT_RANDOMSEED);
509 WriteShort(MSG_ENTITY, self.cnt);
512 void RandomSeed_Think()
514 self.cnt = bound(0, floor(random() * 65536), 65535);
515 self.nextthink = time + 5;
519 void RandomSeed_Spawn()
521 randomseed = spawn();
522 randomseed.think = RandomSeed_Think;
523 Net_LinkEntity(randomseed, FALSE, 0, RandomSeed_Send);
528 self.think(); // sets random seed and nextthink
532 void spawnfunc___init_dedicated_server(void)
534 // handler for _init/_init map (only for dedicated server initialization)
536 world_initialized = -1; // don't complain
538 cvar_string = cvar_string_normal;
539 cvar_set = cvar_set_normal;
541 remove = remove_unsafely;
545 e.think = GotoFirstMap;
546 e.nextthink = time; // this is usually 1 at this point
549 e.classname = "info_player_deathmatch"; // safeguard against player joining
551 self.classname = "worldspawn"; // safeguard against various stuff ;)
553 // needs to be done so early because of the constants they create
554 CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
555 CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
558 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
561 void Map_MarkAsRecent(string m);
562 float world_already_spawned;
564 void ClientInit_Spawn();
565 void WeaponStats_Init();
566 void WeaponStats_Shutdown();
567 void spawnfunc_worldspawn (void)
569 float fd, l, i, j, n;
573 cvar_string = cvar_string_normal;
574 cvar_set = cvar_set_normal;
576 if(world_already_spawned)
577 error("world already spawned - you may have EXACTLY ONE worldspawn!");
578 world_already_spawned = TRUE;
580 remove = remove_safely; // during spawning, watch what you remove!
582 check_unacceptable_compiler_bugs();
584 cvar_changes_init(); // do this very early now so it REALLY matches the server config
586 compressShortVector_init();
589 head = nextent(world);
594 head = nextent(head);
597 // needs to be done so early because of the constants they create
598 CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
599 CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
601 ServerProgsDB = db_load(strcat("server.db", autocvar_sessionid));
603 TemporaryDB = db_create();
608 // 1 FLICKER (first variety)
609 lightstyle(1, "mmnmmommommnonmmonqnmmo");
611 // 2 SLOW STRONG PULSE
612 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
614 // 3 CANDLE (first variety)
615 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
618 lightstyle(4, "mamamamamama");
621 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
623 // 6 FLICKER (second variety)
624 lightstyle(6, "nmonqnmomnmomomno");
626 // 7 CANDLE (second variety)
627 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
629 // 8 CANDLE (third variety)
630 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
632 // 9 SLOW STROBE (fourth variety)
633 lightstyle(9, "aaaaaaaazzzzzzzz");
635 // 10 FLUORESCENT FLICKER
636 lightstyle(10, "mmamammmmammamamaaamammma");
638 // 11 SLOW PULSE NOT FADE TO BLACK
639 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
641 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
646 if(autocvar_g_campaign)
649 Map_MarkAsRecent(mapname);
651 PlayerStats_Init(); // we need this to be initiated before InitGameplayMode
653 precache_model ("null"); // we need this one before InitGameplayMode
661 bot_waypoints_for_items = autocvar_g_waypoints_for_items;
662 if(bot_waypoints_for_items == 1)
663 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
664 bot_waypoints_for_items = 0;
668 WaypointSprite_Init();
670 GameLogInit(); // prepare everything
672 // changing the logic generating it is okay. But:
673 // it HAS to stay <= 64 chars
674 // character set: ASCII 33-126 without the following characters: : ; ' " \ $
675 if(autocvar_sv_eventlog)
677 s = sprintf("%d.%s.%06d", ftos(autocvar_sv_eventlog_files_counter), strftime(FALSE, "%s"), floor(random() * 1000000));
678 matchid = strzone(s);
680 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
681 s = ":gameinfo:mutators:LIST";
684 MUTATOR_CALLHOOK(BuildMutatorsString);
687 // simple, probably not good in the mutator system
688 if(autocvar_g_grappling_hook)
689 s = strcat(s, ":grappling_hook");
691 // initialiation stuff, not good in the mutator system
692 if(!autocvar_g_use_ammunition)
693 s = strcat(s, ":no_use_ammunition");
695 // initialiation stuff, not good in the mutator system
696 if(autocvar_g_pickup_items == 0)
697 s = strcat(s, ":no_pickup_items");
698 if(autocvar_g_pickup_items > 0)
699 s = strcat(s, ":pickup_items");
701 // initialiation stuff, not good in the mutator system
702 if(autocvar_g_weaponarena != "0")
703 s = strcat(s, ":", autocvar_g_weaponarena, " arena");
705 // TODO to mutator system
706 if(autocvar_g_norecoil)
707 s = strcat(s, ":norecoil");
709 // TODO to mutator system
710 if(autocvar_g_midair)
711 s = strcat(s, ":midair");
713 // TODO to mutator system
714 if(autocvar_g_minstagib)
715 s = strcat(s, ":minstagib");
717 // TODO to mutator system
718 if(autocvar_g_powerups == 0)
719 s = strcat(s, ":no_powerups");
720 if(autocvar_g_powerups > 0)
721 s = strcat(s, ":powerups");
724 GameLogEcho(":gameinfo:end");
727 matchid = strzone(ftos(random()));
729 cvar_set("nextmap", "");
733 if(autocvar_g_campaign)
741 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
743 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
745 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
748 while((s = fgets(fd)))
750 l = tokenize_console(s);
755 print("Found ^1UNSUPPORTED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
756 print(" cdtrack ", argv(2), "\n");
758 else if(argv(0) == "fog")
760 print("Found ^1UNSUPPORTED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
761 print(" \"fog\" \"", s, "\"\n");
763 else if(argv(0) == "set")
765 print("Found ^1UNSUPPORTED^7 set command in .cfg file; put this line in mapinfo instead:\n");
766 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
768 else if(argv(0) != "//")
770 print("Found ^1UNSUPPORTED^7 set command in .cfg file; put this line in mapinfo instead:\n");
771 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
781 addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
782 addstat(STAT_SWITCHINGWEAPON, AS_INT, switchingweapon);
783 addstat(STAT_GAMESTARTTIME, AS_FLOAT, stat_game_starttime);
784 addstat(STAT_ALLOW_OLDNEXBEAM, AS_INT, stat_allow_oldnexbeam);
787 addstat(STAT_STRENGTH_FINISHED, AS_FLOAT, strength_finished);
788 addstat(STAT_INVINCIBLE_FINISHED, AS_FLOAT, invincible_finished);
789 addstat(STAT_SUPERWEAPONS_FINISHED, AS_FLOAT, superweapons_finished);
790 addstat(STAT_PRESSED_KEYS, AS_FLOAT, pressedkeys);
791 addstat(STAT_FUEL, AS_INT, ammo_fuel);
792 addstat(STAT_SHOTORG, AS_INT, stat_shotorg);
793 addstat(STAT_LEADLIMIT, AS_FLOAT, stat_leadlimit);
794 addstat(STAT_WEAPON_CLIPLOAD, AS_INT, clip_load);
795 addstat(STAT_WEAPON_CLIPSIZE, AS_INT, clip_size);
796 addstat(STAT_LAST_PICKUP, AS_FLOAT, last_pickup);
797 addstat(STAT_HIT_TIME, AS_FLOAT, hit_time);
798 addstat(STAT_TYPEHIT_TIME, AS_FLOAT, typehit_time);
799 addstat(STAT_LAYED_MINES, AS_INT, minelayer_mines);
801 addstat(STAT_NEX_CHARGE, AS_FLOAT, nex_charge);
802 addstat(STAT_NEX_CHARGEPOOL, AS_FLOAT, nex_chargepool_ammo);
804 addstat(STAT_HAGAR_LOAD, AS_INT, hagar_load);
808 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
809 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
812 // g_movementspeed hack
813 addstat(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW, AS_FLOAT, stat_sv_airspeedlimit_nonqw);
814 addstat(STAT_MOVEVARS_MAXSPEED, AS_FLOAT, stat_sv_maxspeed);
815 addstat(STAT_MOVEVARS_AIRACCEL_QW, AS_FLOAT, stat_sv_airaccel_qw);
816 addstat(STAT_MOVEVARS_AIRSTRAFEACCEL_QW, AS_FLOAT, stat_sv_airstrafeaccel_qw);
819 addstat(STAT_SECRETS_TOTAL, AS_FLOAT, stat_secrets_total);
820 addstat(STAT_SECRETS_FOUND, AS_FLOAT, stat_secrets_found);
823 addstat(STAT_RESPAWN_TIME, AS_FLOAT, stat_respawn_time);
825 next_pingtime = time + 5;
829 // set up information replies for clients and server to use
830 lsmaps_reply = "^7Maps available: ";
831 lsnewmaps_reply = "^7Maps without a record set: ";
832 for(i = 0, j = 0; i < MapInfo_count; ++i)
834 if(MapInfo_Get_ByID(i))
835 if not(MapInfo_Map_flags & (MAPINFO_FLAG_HIDDEN | MAPINFO_FLAG_FORBIDDEN))
844 lsmaps_reply = strcat(lsmaps_reply, col, MapInfo_Map_bspname, " ");
846 if(g_race && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "time"))))
847 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
848 else if(g_cts && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "time"))))
849 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
853 lsmaps_reply = strzone(strcat(lsmaps_reply, "\n"));
854 lsnewmaps_reply = strzone(strcat(((!g_race && !g_cts) ? "Need to be playing race or CTS for lsnewmaps to work." : lsnewmaps_reply), "\n"));
856 maplist_reply = "^7Maps in list: ";
857 n = tokenize_console(autocvar_g_maplist);
858 for(i = 0, j = 0; i < n; ++i)
860 if(MapInfo_CheckMap(argv(i)))
866 maplist_reply = strcat(maplist_reply, col, argv(i), " ");
870 maplist_reply = strzone(strcat(maplist_reply, "\n"));
871 MapInfo_ClearTemps();
873 for(i = 0; i < 10; ++i)
877 records_reply[i] = strzone(s);
880 ladder_reply = strzone(getladder());
882 rankings_reply = strzone(getrankings());
887 PingPLReport_Spawn();
891 localcmd("\n_sv_hook_gamestart ", GetGametype(), "\n");
893 // fill sv_curl_serverpackages from .serverpackage files
894 if(autocvar_sv_curl_serverpackages_auto)
897 n = tokenize_console(cvar_string("sv_curl_serverpackages"));
898 for(i = 0; i < n; ++i)
899 if(substring(argv(i), -14, -1) != "-serverpackage.txt")
900 if(substring(argv(i), -14, -1) != ".serverpackage") // OLD legacy
901 s = strcat(s, " ", argv(i));
902 fd = search_begin("*-serverpackage.txt", TRUE, FALSE);
905 j = search_getsize(fd);
906 for(i = 0; i < j; ++i)
907 s = strcat(s, " ", search_getfilename(fd, i));
910 fd = search_begin("*.serverpackage", TRUE, FALSE);
913 j = search_getsize(fd);
914 for(i = 0; i < j; ++i)
915 s = strcat(s, " ", search_getfilename(fd, i));
918 cvar_set("sv_curl_serverpackages", substring(s, 1, -1));
921 // MOD AUTHORS: change this, and possibly remove a few of the blocks below to ignore certain changes
923 // physics/balance/config changes that count as mod
924 if(cvar_string("g_mod_physics") != cvar_defstring("g_mod_physics"))
925 modname = cvar_string("g_mod_physics");
926 if(cvar_string("g_mod_balance") != cvar_defstring("g_mod_balance"))
927 modname = cvar_string("g_mod_balance");
928 if(cvar_string("g_mod_config") != cvar_defstring("g_mod_config"))
929 modname = cvar_string("g_mod_config");
930 // weird mutators that deserve to count as mod
931 if(autocvar_g_minstagib)
932 modname = "MinstaGib";
933 // extra mutators that deserve to count as mod
934 MUTATOR_CALLHOOK(SetModname);
937 modname = strzone(modname);
939 WinningConditionHelper(); // set worldstatus
941 world_initialized = 1;
944 void spawnfunc_light (void)
946 //makestatic (self); // Who the f___ did that?
952 return MapInfo_Type_ToString(MapInfo_LoadedGametype);
955 string getmapname_stored;
961 float Map_Count, Map_Current;
962 string Map_Current_Name;
964 // NOTE: this now expects the map list to be already tokenized and the count in Map_Count
965 float GetMaplistPosition()
971 idx = autocvar_g_maplist_index;
978 for(pos = 0; pos < Map_Count; ++pos)
982 // resume normal maplist rotation if current map is not in g_maplist
986 float MapHasRightSize(string map)
989 if(currentbots || autocvar_bot_number || player_count < autocvar_minplayers)
990 if(autocvar_g_maplist_check_waypoints)
992 dprint("checkwp "); dprint(map);
993 if(!fexists(strcat("maps/", map, ".waypoints")))
995 dprint(": no waypoints\n");
998 dprint(": has waypoints\n");
1001 // open map size restriction file
1002 dprint("opensize "); dprint(map);
1003 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
1006 float mapmin, mapmax;
1008 mapmin = stof(fgets(fh));
1009 mapmax = stof(fgets(fh));
1011 if(player_count < mapmin)
1013 dprint("not enough\n");
1016 if(player_count > mapmax)
1018 dprint("too many\n");
1021 dprint("right size\n");
1024 dprint(": not found\n");
1028 string Map_Filename(float position)
1030 return strcat("maps/", argv(position), ".bsp");
1033 string strwords(string s, float w)
1036 for(endpos = 0; w && endpos >= 0; --w)
1037 endpos = strstrofs(s, " ", endpos + 1);
1041 return substring(s, 0, endpos);
1044 float strhasword(string s, string w)
1046 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
1049 void Map_MarkAsRecent(string m)
1051 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", autocvar_g_maplist_mostrecent), max(0, autocvar_g_maplist_mostrecent_count)));
1054 float Map_IsRecent(string m)
1056 return strhasword(autocvar_g_maplist_mostrecent, m);
1059 float Map_Check(float position, float pass)
1063 map_next = argv(position);
1066 if(Map_IsRecent(map_next))
1069 filename = Map_Filename(position);
1070 if(MapInfo_CheckMap(map_next))
1074 if(MapHasRightSize(map_next))
1079 dprint( "Couldn't select '", filename, "'..\n" );
1084 void Map_Goto_SetStr(string nextmapname)
1086 if(getmapname_stored != "")
1087 strunzone(getmapname_stored);
1088 if(nextmapname == "")
1089 getmapname_stored = "";
1091 getmapname_stored = strzone(nextmapname);
1094 void Map_Goto_SetFloat(float position)
1096 cvar_set("g_maplist_index", ftos(position));
1097 Map_Goto_SetStr(argv(position));
1100 void Map_Goto(float reinit)
1102 MapInfo_LoadMap(getmapname_stored, reinit);
1105 // return codes of map selectors:
1106 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
1107 // -2 = permanent failure
1108 float() MaplistMethod_Iterate = // usual method
1112 for(pass = 1; pass <= 2; ++pass)
1114 for(i = 1; i < Map_Count; ++i)
1117 mapindex = mod(i + Map_Current, Map_Count);
1118 if(Map_Check(mapindex, pass))
1125 float() MaplistMethod_Repeat = // fallback method
1127 if(Map_Check(Map_Current, 2))
1132 float() MaplistMethod_Random = // random map selection
1138 for(i = 0; i <= imax; ++i)
1141 mapindex = mod(Map_Current + floor(random() * (Map_Count - 1) + 1), Map_Count); // any OTHER map
1142 if(Map_Check(mapindex, 1))
1148 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
1149 // the exponent sets a bias on the map selection:
1150 // the higher the exponent, the less likely "shortly repeated" same maps are
1152 float i, j, imax, insertpos;
1156 for(i = 0; i <= imax; ++i)
1160 // now reinsert this at another position
1161 insertpos = pow(random(), 1 / exponent); // ]0, 1]
1162 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
1163 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
1164 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
1166 // insert the current map there
1168 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
1169 newlist = strcat(newlist, " ", argv(j));
1170 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
1171 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
1172 newlist = strcat(newlist, " ", argv(j));
1173 newlist = substring(newlist, 1, strlen(newlist) - 1);
1174 cvar_set("g_maplist", newlist);
1175 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1177 // NOTE: the selected map has just been inserted at (insertpos-1)th position
1178 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
1179 if(Map_Check(Map_Current, 1))
1187 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1190 bprint( "Maplist is empty! Resetting it to default map list.\n" );
1191 cvar_set("g_maplist", MapInfo_ListAllAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
1192 if(autocvar_g_maplist_shuffle)
1194 localcmd("\nmenu_cmd sync\n");
1195 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1198 error("empty maplist, cannot select a new map");
1199 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
1201 if(Map_Current_Name)
1202 strunzone(Map_Current_Name);
1203 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
1204 // this may or may not be correct, but who cares, in the worst case a map
1205 // isn't chosen in the first pass that should have been
1216 if(autocvar_g_maplist_shuffle > 0)
1217 nextMap = MaplistMethod_Shuffle(autocvar_g_maplist_shuffle + 1);
1220 if(autocvar_g_maplist_selectrandom)
1221 nextMap = MaplistMethod_Random();
1224 nextMap = MaplistMethod_Iterate();
1227 nextMap = MaplistMethod_Repeat();
1231 Map_Goto_SetFloat(nextMap);
1232 return getmapname_stored;
1238 float DoNextMapOverride(float reinit)
1240 if(autocvar_g_campaign)
1242 CampaignPostIntermission();
1243 alreadychangedlevel = TRUE;
1246 if(autocvar_quit_when_empty)
1248 if(player_count <= currentbots)
1251 alreadychangedlevel = TRUE;
1255 if(autocvar_quit_and_redirect != "")
1257 redirection_target = strzone(autocvar_quit_and_redirect);
1258 alreadychangedlevel = TRUE;
1261 if (!reinit && autocvar_samelevel) // if samelevel is set, stay on same level
1263 localcmd("restart\n");
1264 alreadychangedlevel = TRUE;
1267 if(autocvar_nextmap != "")
1268 if(MapInfo_CheckMap(autocvar_nextmap))
1270 Map_Goto_SetStr(autocvar_nextmap);
1272 alreadychangedlevel = TRUE;
1275 if(!reinit && autocvar_lastlevel)
1277 cvar_settemp_restore();
1278 localcmd("set lastlevel 0\ntogglemenu 1\n");
1279 alreadychangedlevel = TRUE;
1285 void GotoNextMap(float reinit)
1290 if (alreadychangedlevel)
1292 alreadychangedlevel = TRUE;
1298 for(allowReset = 1; allowReset >= 0; --allowReset)
1300 nextMap = GetNextMap();
1306 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1307 cvar_set("g_maplist", MapInfo_ListAllAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
1308 if(autocvar_g_maplist_shuffle)
1310 localcmd("\nmenu_cmd sync\n");
1314 error("Everything is broken - not even the default map list works. Please report this to the developers.");
1326 When the player presses attack or jump, change to the next level
1329 .float autoscreenshot;
1330 void() MapVote_Start;
1331 void() MapVote_Think;
1332 float mapvote_initialized;
1333 void IntermissionThink()
1335 FixIntermissionClient(self);
1337 float server_screenshot = (autocvar_sv_autoscreenshot && self.cvar_cl_autoscreenshot);
1338 float client_screenshot = (self.cvar_cl_autoscreenshot == 2);
1340 if( (server_screenshot || client_screenshot)
1341 && ((self.autoscreenshot > 0) && (time > self.autoscreenshot)) )
1343 self.autoscreenshot = -1;
1344 if(clienttype(self) == CLIENTTYPE_REAL) { stuffcmd(self, sprintf("\nscreenshot screenshots/autoscreenshot/%s-%s.jpg; echo \"^5A screenshot has been taken at request of the server.\"", GetMapname(), strftime(FALSE, "%s"))); }
1348 if (time < intermission_exittime)
1351 if(!mapvote_initialized)
1352 if (time < intermission_exittime + 10 && !(self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE))
1362 Returns the entity to view from
1366 entity FindIntermission()
1371 // look for info_intermission first
1372 spot = find (world, classname, "info_intermission");
1374 { // pick a random one
1378 spot = find (spot, classname, "info_intermission");
1380 spot = find (spot, classname, "info_intermission");
1386 // then look for the start position
1387 spot = find (world, classname, "info_player_start");
1391 // testinfo_player_start is only found in regioned levels
1392 spot = find (world, classname, "testplayerstart");
1396 // then look for the start position
1397 spot = find (world, classname, "info_player_deathmatch");
1401 //objerror ("FindIntermission: no spot");
1407 ===============================================================================
1411 ===============================================================================
1414 void DumpStats(float final)
1423 to_console = autocvar_sv_logscores_console;
1424 to_eventlog = autocvar_sv_eventlog;
1425 to_file = autocvar_sv_logscores_file;
1429 to_console = TRUE; // always print printstats replies
1430 to_eventlog = FALSE; // but never print them to the event log
1434 if(autocvar_sv_eventlog_console)
1435 to_console = FALSE; // otherwise we get the output twice
1441 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
1451 file = fopen(autocvar_sv_logscores_filename, FILE_APPEND);
1455 fputs(file, strcat(s, "\n"));
1458 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
1464 fputs(file, strcat(s, "\n"));
1466 FOR_EACH_CLIENT(other)
1468 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && autocvar_sv_logscores_bots))
1470 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
1471 s = strcat(s, ftos(rint(time - other.jointime)), ":");
1472 if(other.classname == "player" || g_arena || g_ca || g_lms)
1473 s = strcat(s, ftos(other.team), ":");
1475 s = strcat(s, "spectator:");
1478 print(s, other.netname, "\n");
1480 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
1482 fputs(file, strcat(s, other.netname, "\n"));
1488 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
1494 fputs(file, strcat(s, "\n"));
1496 for(i = 1; i < 16; ++i)
1498 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
1499 s = strcat(s, ":", ftos(i));
1505 fputs(file, strcat(s, "\n"));
1512 GameLogEcho(":end");
1515 fputs(file, ":end\n");
1520 void FixIntermissionClient(entity e)
1523 if(!e.autoscreenshot) // initial call
1525 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1527 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1528 e.solid = SOLID_NOT;
1529 e.movetype = MOVETYPE_NONE;
1530 e.takedamage = DAMAGE_NO;
1533 e.weaponentity.effects = EF_NODRAW;
1534 if (e.weaponentity.weaponentity)
1535 e.weaponentity.weaponentity.effects = EF_NODRAW;
1537 if(clienttype(e) == CLIENTTYPE_REAL)
1539 stuffcmd(e, "\nscr_printspeed 1000000\n");
1540 s = autocvar_sv_intermission_cdtrack;
1542 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1544 WriteByte(MSG_ONE, SVC_INTERMISSION);
1549 void minstagib_stop_countdown(entity e);
1551 go to the next level for deathmatch
1552 only called if a time or frag limit has expired
1558 intermission_running = 1;
1560 // enforce a wait time before allowing changelevel
1561 if(player_count > 0)
1562 intermission_exittime = time + autocvar_sv_mapchange_delay;
1564 intermission_exittime = -1;
1567 WriteByte (MSG_ALL, SVC_CDTRACK);
1568 WriteByte (MSG_ALL, 3);
1569 WriteByte (MSG_ALL, 3);
1570 // done in FixIntermission
1573 //pos = FindIntermission ();
1581 PlayerStats_EndMatch(1);
1583 PlayerStats_AddGlobalInfo(e);
1584 PlayerStats_Shutdown();
1585 WeaponStats_Shutdown();
1587 if(autocvar_sv_eventlog)
1588 GameLogEcho(":gameover");
1592 FOR_EACH_PLAYER(other) {
1593 minstagib_stop_countdown(other);
1594 FixIntermissionClient(other);
1596 bprint(other.netname, " ^7wins.\n");
1599 if(autocvar_g_campaign)
1600 CampaignPreIntermission();
1602 MUTATOR_CALLHOOK(MatchEnd);
1604 localcmd("\nsv_hook_gameend\n");
1611 Exit deathmatch games upon conditions
1614 void CheckRules_Player()
1616 if (gameover) // someone else quit the game already
1619 if(self.deadflag == DEAD_NO)
1620 self.play_time += frametime;
1622 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1623 // (div0: and that in CheckRules_World please)
1626 float checkrules_equality;
1627 float checkrules_suddendeathwarning;
1628 float checkrules_suddendeathend;
1629 float checkrules_overtimesadded; //how many overtimes have been already added
1631 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1632 float WINNING_YES = 1; // winner found
1633 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1634 float WINNING_STARTSUDDENDEATHOVERTIME = 3; // no winner, enter suddendeath overtime NOW
1636 float InitiateSuddenDeath()
1638 // Check first whether normal overtimes could be added before initiating suddendeath mode
1639 // - for this timelimit_overtime needs to be >0 of course
1640 // - also check the winning condition calculated in the previous frame and only add normal overtime
1641 // again, if at the point at which timelimit would be extended again, still no winner was found
1642 if (!autocvar_g_campaign && (checkrules_overtimesadded >= 0) && (checkrules_overtimesadded < autocvar_timelimit_overtimes) && autocvar_timelimit_overtime && !(g_race && !g_race_qualifying))
1644 return 1; // need to call InitiateOvertime later
1648 if(!checkrules_suddendeathend)
1650 if(autocvar_g_campaign)
1651 checkrules_suddendeathend = time; // no suddendeath in campaign
1653 checkrules_suddendeathend = time + 60 * autocvar_timelimit_suddendeath;
1654 if(g_race && !g_race_qualifying)
1655 race_StartCompleting();
1661 void InitiateOvertime() // ONLY call this if InitiateSuddenDeath returned true
1663 ++checkrules_overtimesadded;
1664 //add one more overtime by simply extending the timelimit
1666 tl = autocvar_timelimit;
1667 tl += autocvar_timelimit_overtime;
1668 cvar_set("timelimit", ftos(tl));
1669 string minutesPlural;
1670 if (autocvar_timelimit_overtime == 1)
1671 minutesPlural = " ^3minute";
1673 minutesPlural = " ^3minutes";
1677 "^3Now playing ^1OVERTIME^3!\n\n^3Added ^1",
1678 ftos(autocvar_timelimit_overtime),
1685 float GetWinningCode(float fraglimitreached, float equality)
1687 if(autocvar_g_campaign == 1)
1688 if(fraglimitreached)
1695 if(fraglimitreached)
1696 return WINNING_STARTSUDDENDEATHOVERTIME;
1698 return WINNING_NEVER;
1700 if(fraglimitreached)
1706 // set the .winning flag for exactly those players with a given field value
1707 void SetWinners(.float field, float value)
1710 FOR_EACH_PLAYER(head)
1711 head.winning = (head.field == value);
1714 // set the .winning flag for those players with a given field value
1715 void AddWinners(.float field, float value)
1718 FOR_EACH_PLAYER(head)
1719 if(head.field == value)
1723 // clear the .winning flags
1724 void ClearWinners(void)
1727 FOR_EACH_PLAYER(head)
1731 // Onslaught winning condition:
1732 // game terminates if only one team has a working generator (or none)
1733 float WinningCondition_Onslaught()
1736 float t1, t2, t3, t4;
1738 WinningConditionHelper(); // set worldstatus
1743 // first check if the game has ended
1744 t1 = t2 = t3 = t4 = 0;
1745 head = find(world, classname, "onslaught_generator");
1748 if (head.health > 0)
1750 if (head.team == COLOR_TEAM1) t1 = 1;
1751 if (head.team == COLOR_TEAM2) t2 = 1;
1752 if (head.team == COLOR_TEAM3) t3 = 1;
1753 if (head.team == COLOR_TEAM4) t4 = 1;
1755 head = find(head, classname, "onslaught_generator");
1757 if (t1 + t2 + t3 + t4 < 2)
1759 // game over, only one team remains (or none)
1761 if (t1) SetWinners(team, COLOR_TEAM1);
1762 if (t2) SetWinners(team, COLOR_TEAM2);
1763 if (t3) SetWinners(team, COLOR_TEAM3);
1764 if (t4) SetWinners(team, COLOR_TEAM4);
1765 dprint("Have a winner, ending game.\n");
1769 // Two or more teams remain
1773 float LMS_NewPlayerLives()
1776 fl = autocvar_fraglimit;
1780 // first player has left the game for dying too much? Nobody else can get in.
1781 if(lms_lowest_lives < 1)
1784 if(!autocvar_g_lms_join_anytime)
1785 if(lms_lowest_lives < fl - autocvar_g_lms_last_join)
1788 return bound(1, lms_lowest_lives, fl);
1791 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1792 // they win. Otherwise the defending team wins once the timelimit passes.
1793 void assault_new_round();
1794 float WinningCondition_Assault()
1798 WinningConditionHelper(); // set worldstatus
1800 status = WINNING_NO;
1801 // as the timelimit has not yet passed just assume the defending team will win
1802 if(assault_attacker_team == COLOR_TEAM1)
1804 SetWinners(team, COLOR_TEAM2);
1808 SetWinners(team, COLOR_TEAM1);
1812 ent = find(world, classname, "target_assault_roundend");
1815 if(ent.winning) // round end has been triggered by attacking team
1817 bprint("ASSAULT: round completed...\n");
1818 SetWinners(team, assault_attacker_team);
1820 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
1822 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
1824 status = WINNING_YES;
1831 assault_new_round();
1840 // LMS winning condition: game terminates if and only if there's at most one
1841 // one player who's living lives. Top two scores being equal cancels the time
1843 float WinningCondition_LMS()
1850 have_player = FALSE;
1851 have_players = FALSE;
1852 l = LMS_NewPlayerLives();
1854 head = find(world, classname, "player");
1857 head2 = find(head, classname, "player");
1859 have_players = TRUE;
1863 // we have at least one player
1866 // two or more active players - continue with the game
1870 // exactly one player?
1873 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1877 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1883 // and assign him his first place
1884 PlayerScore_Add(head, SP_LMS_RANK, 1);
1891 // nobody is playing at all...
1894 // wait for players...
1898 // SNAFU (maybe a draw game?)
1900 dprint("No players, ending game.\n");
1905 // When we get here, we have at least two players who are actually LIVING,
1906 // now check if the top two players have equal score.
1907 WinningConditionHelper();
1910 if(WinningConditionHelper_winner)
1911 WinningConditionHelper_winner.winning = TRUE;
1912 if(WinningConditionHelper_topscore == WinningConditionHelper_secondscore)
1913 return WINNING_NEVER;
1915 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1919 void ShuffleMaplist()
1921 cvar_set("g_maplist", shufflewords(autocvar_g_maplist));
1925 float WinningCondition_Scores(float limit, float leadlimit)
1929 // TODO make everything use THIS winning condition (except LMS)
1930 WinningConditionHelper();
1934 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1935 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1936 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1937 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1941 if(WinningConditionHelper_winner)
1942 WinningConditionHelper_winner.winning = 1;
1943 if(WinningConditionHelper_winnerteam >= 0)
1944 SetWinners(team, WinningConditionHelper_winnerteam);
1946 if(WinningConditionHelper_lowerisbetter)
1948 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1949 WinningConditionHelper_secondscore = -WinningConditionHelper_secondscore;
1953 if(WinningConditionHelper_zeroisworst)
1954 leadlimit = 0; // not supported in this mode
1956 if(g_dm || g_tdm || g_arena || g_ca || (g_race && !g_race_qualifying) || g_nexball)
1957 // these modes always score in increments of 1, thus this makes sense
1959 if(leaderfrags != WinningConditionHelper_topscore)
1961 leaderfrags = WinningConditionHelper_topscore;
1964 if (leaderfrags == limit - 1)
1965 Announce("1fragleft");
1966 else if (leaderfrags == limit - 2)
1967 Announce("2fragsleft");
1968 else if (leaderfrags == limit - 3)
1969 Announce("3fragsleft");
1973 limitreached = FALSE;
1975 if(WinningConditionHelper_topscore >= limit)
1976 limitreached = TRUE;
1979 float leadlimitreached;
1980 leadlimitreached = (WinningConditionHelper_topscore - WinningConditionHelper_secondscore >= leadlimit);
1981 if(autocvar_leadlimit_and_fraglimit)
1982 limitreached = (limitreached && leadlimitreached);
1984 limitreached = (limitreached || leadlimitreached);
1988 game_completion_ratio = max(game_completion_ratio, bound(0, WinningConditionHelper_topscore / limit, 1));
1990 return GetWinningCode(
1991 WinningConditionHelper_topscore && limitreached,
1992 WinningConditionHelper_equality
1996 float WinningCondition_Race(float fraglimit)
2007 if(p.race_completed)
2012 wc = WinningCondition_Scores(fraglimit, 0);
2014 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
2015 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
2016 // do NOT support equality when the laps are all raced!
2017 return WINNING_STARTSUDDENDEATHOVERTIME;
2019 return WINNING_NEVER;
2022 float WinningCondition_QualifyingThenRace(float limit)
2025 wc = WinningCondition_Scores(limit, 0);
2027 // NEVER initiate overtime
2028 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
2036 float WinningCondition_RanOutOfSpawns()
2040 if(have_team_spawns <= 0)
2043 if(autocvar_g_spawn_useallspawns <= 0)
2046 if(!some_spawn_has_been_used)
2049 team1_score = team2_score = team3_score = team4_score = 0;
2051 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
2053 if(head.team == COLOR_TEAM1)
2055 else if(head.team == COLOR_TEAM2)
2057 else if(head.team == COLOR_TEAM3)
2059 else if(head.team == COLOR_TEAM4)
2063 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
2065 if(head.team == COLOR_TEAM1)
2067 else if(head.team == COLOR_TEAM2)
2069 else if(head.team == COLOR_TEAM3)
2071 else if(head.team == COLOR_TEAM4)
2076 if(team1_score + team2_score + team3_score + team4_score == 0)
2078 checkrules_equality = TRUE;
2081 else if(team1_score + team2_score + team3_score + team4_score == 1)
2086 else if(team2_score)
2088 else if(team3_score)
2090 else // if(team4_score)
2092 CheckAllowedTeams(world);
2093 for(i = 0; i < MAX_TEAMSCORE; ++i)
2095 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
2096 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
2097 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
2098 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
2101 AddWinners(team, t);
2112 Exit deathmatch games upon conditions
2115 void ReadyRestart();
2116 void CheckRules_World()
2128 MapVote_Think should now do that part
2129 if (intermission_running)
2130 if (time >= intermission_exittime + 60)
2132 if(!DoNextMapOverride())
2138 if (gameover) // someone else quit the game already
2140 if(player_count == 0) // Nobody there? Then let's go to the next map
2142 // this will actually check the player count in the next frame
2143 // again, but this shouldn't hurt
2147 timelimit = autocvar_timelimit * 60;
2148 fraglimit = autocvar_fraglimit;
2149 leadlimit = autocvar_leadlimit;
2151 if(inWarmupStage || time <= game_starttime) // NOTE: this is <= to prevent problems in the very tic where the game starts
2154 timelimit = 0; // timelimit is not made for warmup
2156 fraglimit = 0; // no fraglimit for now
2157 leadlimit = 0; // no leadlimit for now
2162 timelimit += game_starttime;
2164 else if (timelimit < 0)
2172 timelimit = 0; // ONS has its own overtime rule
2177 if(timelimit > game_starttime)
2178 game_completion_ratio = (time - game_starttime) / (timelimit - game_starttime);
2180 game_completion_ratio = 0;
2182 if(checkrules_suddendeathend)
2184 if(!checkrules_suddendeathwarning)
2186 checkrules_suddendeathwarning = TRUE;
2187 if(g_race && !g_race_qualifying)
2188 bcenterprint("^3Everyone, finish your lap! The race is over!");
2190 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
2195 if (timelimit && time >= timelimit)
2197 if(g_race && (g_race_qualifying == 2) && timelimit > 0)
2200 float playerswithlaps;
2203 totalplayers = playerswithlaps = readyplayers = 0;
2204 FOR_EACH_PLAYER(head)
2207 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
2213 // at least 2 of the players have completed a lap: start the RACE
2214 // otherwise, the players should end the qualifying on their own
2215 if(readyplayers || playerswithlaps >= 2)
2217 checkrules_suddendeathend = 0;
2218 ReadyRestart(); // go to race
2222 wantovertime |= InitiateSuddenDeath();
2225 wantovertime |= InitiateSuddenDeath();
2229 if (checkrules_suddendeathend && time >= checkrules_suddendeathend)
2235 float checkrules_status;
2236 checkrules_status = WinningCondition_RanOutOfSpawns();
2237 if(checkrules_status == WINNING_YES)
2239 bprint("Hey! Someone ran out of spawns!\n");
2241 else if(g_race && !g_race_qualifying && timelimit >= 0)
2243 checkrules_status = WinningCondition_Race(fraglimit);
2244 //print("WC_RACE yields ", ftos(checkrules_status), "\n");
2246 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
2248 checkrules_status = WinningCondition_QualifyingThenRace(fraglimit);
2249 //print("WC_QUALIFYING_THEN_RACE yields ", ftos(checkrules_status), "\n");
2253 checkrules_status = WinningCondition_Assault(); // TODO remove this?
2257 checkrules_status = WinningCondition_LMS();
2259 else if (g_onslaught)
2261 checkrules_status = WinningCondition_Onslaught(); // TODO remove this?
2265 checkrules_status = WinningCondition_Scores(fraglimit, leadlimit);
2266 //print("WC_SCORES yields ", ftos(checkrules_status), "\n");
2269 if(checkrules_status == WINNING_STARTSUDDENDEATHOVERTIME)
2271 checkrules_status = WINNING_NEVER;
2272 checkrules_overtimesadded = -1;
2273 wantovertime |= InitiateSuddenDeath();
2276 if(checkrules_status == WINNING_NEVER)
2277 // equality cases! Nobody wins if the overtime ends in a draw.
2282 if(checkrules_status == WINNING_NEVER)
2285 checkrules_status = WINNING_YES;
2288 if(checkrules_suddendeathend)
2289 if(checkrules_status != WINNING_NEVER || time >= checkrules_suddendeathend)
2290 checkrules_status = WINNING_YES;
2292 if(checkrules_status == WINNING_YES)
2294 //print("WINNING\n");
2299 float mapvote_nextthink;
2300 float mapvote_initialized;
2301 float mapvote_keeptwotime;
2302 float mapvote_timeout;
2303 string mapvote_message;
2304 #define MAPVOTE_SCREENSHOT_DIRS_COUNT 4
2305 string mapvote_screenshot_dirs[MAPVOTE_SCREENSHOT_DIRS_COUNT];
2306 float mapvote_screenshot_dirs_count;
2308 float mapvote_count;
2309 float mapvote_count_real;
2310 string mapvote_maps[MAPVOTE_COUNT];
2311 float mapvote_maps_screenshot_dir[MAPVOTE_COUNT];
2312 string mapvote_maps_pakfile[MAPVOTE_COUNT];
2313 float mapvote_maps_suggested[MAPVOTE_COUNT];
2314 string mapvote_suggestions[MAPVOTE_COUNT];
2315 float mapvote_suggestion_ptr;
2316 float mapvote_voters;
2317 float mapvote_selections[MAPVOTE_COUNT];
2319 float mapvote_detail;
2320 float mapvote_abstain;
2323 void MapVote_ClearAllVotes()
2325 FOR_EACH_CLIENT(other)
2329 string MapVote_Suggest(string m)
2333 return "That's not how to use this command.";
2334 if(!autocvar_g_maplist_votable_suggestions)
2335 return "Suggestions are not accepted on this server.";
2336 if(mapvote_initialized)
2337 return "Can't suggest - voting is already in progress!";
2338 m = MapInfo_FixName(m);
2340 return "The map you suggested is not available on this server.";
2341 if(!autocvar_g_maplist_votable_suggestions_override_mostrecent)
2343 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
2345 if(!MapInfo_CheckMap(m))
2346 return "The map you suggested does not support the current game mode.";
2347 for(i = 0; i < mapvote_suggestion_ptr; ++i)
2348 if(mapvote_suggestions[i] == m)
2349 return "This map was already suggested.";
2350 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
2352 i = floor(random() * mapvote_suggestion_ptr);
2356 i = mapvote_suggestion_ptr;
2357 mapvote_suggestion_ptr += 1;
2359 if(mapvote_suggestions[i] != "")
2360 strunzone(mapvote_suggestions[i]);
2361 mapvote_suggestions[i] = strzone(m);
2362 if(autocvar_sv_eventlog)
2363 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
2364 return strcat("Suggestion of ", m, " accepted.");
2367 void MapVote_AddVotable(string nextMap, float isSuggestion)
2370 string pakfile, mapfile;
2374 for(j = 0; j < mapvote_count; ++j)
2375 if(mapvote_maps[j] == nextMap)
2377 // suggestions might be no longer valid/allowed after gametype switch!
2379 if(!MapInfo_CheckMap(nextMap))
2381 mapvote_maps[mapvote_count] = strzone(nextMap);
2382 mapvote_maps_suggested[mapvote_count] = isSuggestion;
2384 pakfile = string_null;
2385 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2387 mapfile = strcat(mapvote_screenshot_dirs[i], "/", mapvote_maps[i]);
2388 pakfile = whichpack(strcat(mapfile, ".tga"));
2390 pakfile = whichpack(strcat(mapfile, ".jpg"));
2392 pakfile = whichpack(strcat(mapfile, ".png"));
2396 if(i >= mapvote_screenshot_dirs_count)
2397 i = 0; // FIXME maybe network this error case, as that means there is no mapshot on the server?
2398 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
2399 pakfile = substring(pakfile, o, -1);
2401 mapvote_maps_screenshot_dir[mapvote_count] = i;
2402 mapvote_maps_pakfile[mapvote_count] = strzone(pakfile);
2407 void MapVote_Spawn();
2413 MapVote_ClearAllVotes();
2416 mapvote_detail = !autocvar_g_maplist_votable_nodetail;
2417 mapvote_abstain = autocvar_g_maplist_votable_abstain;
2420 nmax = min(MAPVOTE_COUNT - 1, autocvar_g_maplist_votable);
2422 nmax = min(MAPVOTE_COUNT, autocvar_g_maplist_votable);
2423 smax = min3(nmax, autocvar_g_maplist_votable_suggestions, mapvote_suggestion_ptr);
2425 // we need this for AddVotable, as that cycles through the screenshot dirs
2426 mapvote_screenshot_dirs_count = tokenize_console(autocvar_g_maplist_votable_screenshot_dir);
2427 if(mapvote_screenshot_dirs_count == 0)
2428 mapvote_screenshot_dirs_count = tokenize_console("maps levelshots");
2429 mapvote_screenshot_dirs_count = min(mapvote_screenshot_dirs_count, MAPVOTE_SCREENSHOT_DIRS_COUNT);
2430 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2431 mapvote_screenshot_dirs[i] = strzone(argv(i));
2433 if(mapvote_suggestion_ptr)
2434 for(i = 0; i < 100 && mapvote_count < smax; ++i)
2435 MapVote_AddVotable(mapvote_suggestions[floor(random() * mapvote_suggestion_ptr)], TRUE);
2437 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2438 MapVote_AddVotable(GetNextMap(), FALSE);
2440 if(mapvote_count == 0)
2442 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
2443 cvar_set("g_maplist", MapInfo_ListAllAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
2444 if(autocvar_g_maplist_shuffle)
2446 localcmd("\nmenu_cmd sync\n");
2447 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2448 MapVote_AddVotable(GetNextMap(), FALSE);
2451 mapvote_count_real = mapvote_count;
2453 MapVote_AddVotable("don't care", 0);
2455 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
2457 mapvote_keeptwotime = time + autocvar_g_maplist_votable_keeptwotime;
2458 mapvote_timeout = time + autocvar_g_maplist_votable_timeout;
2459 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
2460 mapvote_keeptwotime = 0;
2461 mapvote_message = "Choose a map and press its key!";
2466 void MapVote_SendPicture(float id)
2469 WriteByte(MSG_ONE, SVC_TEMPENTITY);
2470 WriteByte(MSG_ONE, TE_CSQC_PICTURE);
2471 WriteByte(MSG_ONE, id);
2472 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dirs[mapvote_maps_screenshot_dir[id]], "/", mapvote_maps[id]), 3072);
2475 float MapVote_GetMapMask()
2477 float mask, i, power;
2479 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
2480 if(mapvote_maps[i] != "")
2486 float MapVote_SendEntity(entity to, float sf)
2491 sf &~= 2; // if we send 1, we don't need to also send 2
2493 WriteByte(MSG_ENTITY, ENT_CLIENT_MAPVOTE);
2494 WriteByte(MSG_ENTITY, sf);
2498 // flag 1 == initialization
2499 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2500 WriteString(MSG_ENTITY, mapvote_screenshot_dirs[i]);
2501 WriteString(MSG_ENTITY, "");
2502 WriteByte(MSG_ENTITY, mapvote_count);
2503 WriteByte(MSG_ENTITY, mapvote_abstain);
2504 WriteByte(MSG_ENTITY, mapvote_detail);
2505 WriteCoord(MSG_ENTITY, mapvote_timeout);
2506 if(mapvote_count <= 8)
2507 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2509 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2510 for(i = 0; i < mapvote_count; ++i)
2511 if(mapvote_maps[i] != "")
2513 if(mapvote_abstain && i == mapvote_count - 1)
2515 WriteString(MSG_ENTITY, ""); // abstain needs no text
2516 WriteString(MSG_ENTITY, ""); // abstain needs no pack
2517 WriteByte(MSG_ENTITY, 0); // abstain needs no screenshot dir
2521 WriteString(MSG_ENTITY, mapvote_maps[i]);
2522 WriteString(MSG_ENTITY, mapvote_maps_pakfile[i]);
2523 WriteByte(MSG_ENTITY, mapvote_maps_screenshot_dir[i]);
2530 // flag 2 == update of mask
2531 if(mapvote_count <= 8)
2532 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2534 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2540 for(i = 0; i < mapvote_count; ++i)
2541 if(mapvote_maps[i] != "")
2542 WriteByte(MSG_ENTITY, mapvote_selections[i]);
2544 WriteByte(MSG_ENTITY, to.mapvote);
2550 void MapVote_Spawn()
2552 Net_LinkEntity(mapvote_ent = spawn(), FALSE, 0, MapVote_SendEntity);
2555 void MapVote_TouchMask()
2557 mapvote_ent.SendFlags |= 2;
2560 void MapVote_TouchVotes(entity voter)
2562 mapvote_ent.SendFlags |= 4;
2565 float MapVote_Finished(float mappos)
2571 if(autocvar_sv_eventlog)
2573 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2574 result = strcat(result, ":", ftos(mapvote_selections[mappos]), "::");
2575 didntvote = mapvote_voters;
2576 for(i = 0; i < mapvote_count; ++i)
2577 if(mapvote_maps[i] != "")
2579 didntvote -= mapvote_selections[i];
2582 result = strcat(result, ":", mapvote_maps[i]);
2583 result = strcat(result, ":", ftos(mapvote_selections[i]));
2586 result = strcat(result, ":didn't vote:", ftos(didntvote));
2588 GameLogEcho(result);
2589 if(mapvote_maps_suggested[mappos])
2590 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
2593 FOR_EACH_REALCLIENT(other)
2594 FixClientCvars(other);
2596 Map_Goto_SetStr(mapvote_maps[mappos]);
2598 alreadychangedlevel = TRUE;
2601 void MapVote_CheckRules_1()
2605 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2607 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2608 mapvote_selections[i] = 0;
2612 FOR_EACH_REALCLIENT(other)
2617 i = other.mapvote - 1;
2618 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2619 mapvote_selections[i] = mapvote_selections[i] + 1;
2624 float MapVote_CheckRules_2()
2627 float firstPlace, secondPlace;
2628 float firstPlaceVotes, secondPlaceVotes;
2629 float mapvote_voters_real;
2632 if(mapvote_count_real == 1)
2633 return MapVote_Finished(0);
2635 mapvote_voters_real = mapvote_voters;
2637 mapvote_voters_real -= mapvote_selections[mapvote_count - 1];
2639 RandomSelection_Init();
2640 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2641 RandomSelection_Add(world, i, string_null, 1, mapvote_selections[i]);
2642 firstPlace = RandomSelection_chosen_float;
2643 firstPlaceVotes = RandomSelection_best_priority;
2644 //dprint("First place: ", ftos(firstPlace), "\n");
2645 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2647 RandomSelection_Init();
2648 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2650 RandomSelection_Add(world, i, string_null, 1, mapvote_selections[i]);
2651 secondPlace = RandomSelection_chosen_float;
2652 secondPlaceVotes = RandomSelection_best_priority;
2653 //dprint("Second place: ", ftos(secondPlace), "\n");
2654 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2656 if(firstPlace == -1)
2657 error("No first place in map vote... WTF?");
2659 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2660 return MapVote_Finished(firstPlace);
2662 if(mapvote_keeptwotime)
2663 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2666 MapVote_TouchMask();
2667 mapvote_message = "Now decide between the TOP TWO!";
2668 mapvote_keeptwotime = 0;
2669 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2670 result = strcat(result, ":", ftos(firstPlaceVotes));
2671 result = strcat(result, ":", mapvote_maps[secondPlace]);
2672 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2673 didntvote = mapvote_voters;
2674 for(i = 0; i < mapvote_count; ++i)
2675 if(mapvote_maps[i] != "")
2677 didntvote -= mapvote_selections[i];
2679 if(i != secondPlace)
2681 result = strcat(result, ":", mapvote_maps[i]);
2682 result = strcat(result, ":", ftos(mapvote_selections[i]));
2683 if(i < mapvote_count_real)
2685 strunzone(mapvote_maps[i]);
2686 mapvote_maps[i] = "";
2687 strunzone(mapvote_maps_pakfile[i]);
2688 mapvote_maps_pakfile[i] = "";
2692 result = strcat(result, ":didn't vote:", ftos(didntvote));
2693 if(autocvar_sv_eventlog)
2694 GameLogEcho(result);
2704 keeptwo = mapvote_keeptwotime;
2705 MapVote_CheckRules_1(); // count
2706 if(MapVote_CheckRules_2()) // decide
2710 FOR_EACH_REALCLIENT(other)
2712 // hide scoreboard again
2713 if(other.health != 2342)
2715 other.health = 2342;
2717 if(clienttype(other) == CLIENTTYPE_REAL)
2720 WriteByte(MSG_ONE, SVC_FINALE);
2721 WriteString(MSG_ONE, "");
2725 // clear possibly invalid votes
2726 if(mapvote_maps[other.mapvote - 1] == "")
2728 // use impulses as new vote
2729 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2730 if(mapvote_maps[other.impulse - 1] != "")
2732 other.mapvote = other.impulse;
2733 MapVote_TouchVotes(other);
2741 MapVote_CheckRules_1(); // just count
2743 void MapVote_Start()
2748 // wait for stats to be sent first
2749 if(!playerstats_waitforme)
2752 MapInfo_Enumerate();
2753 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
2756 void MapVote_Think()
2761 if(alreadychangedlevel)
2764 if(time < mapvote_nextthink)
2768 mapvote_nextthink = time + 0.5;
2770 if(!mapvote_initialized)
2772 if(autocvar_rescan_pending == 1)
2774 cvar_set("rescan_pending", "2");
2775 localcmd("fs_rescan\nrescan_pending 3\n");
2778 else if(autocvar_rescan_pending == 2)
2782 else if(autocvar_rescan_pending == 3)
2784 // now build missing mapinfo files
2785 if(!MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
2788 // we're done, start the timer
2789 cvar_set("rescan_pending", "0");
2792 mapvote_initialized = TRUE;
2793 if(DoNextMapOverride(0))
2795 if(!autocvar_g_maplist_votable || player_count <= 0)
2806 string GotoMap(string m)
2808 if(!MapInfo_CheckMap(m))
2809 return "The map you chose is not available on this server.";
2810 cvar_set("nextmap", m);
2811 cvar_set("timelimit", "-1");
2812 if(mapvote_initialized || alreadychangedlevel)
2814 if(DoNextMapOverride(0))
2815 return "Map switch initiated.";
2817 return "Hm... no. For some reason I like THIS map more.";
2820 return "Map switch will happen after scoreboard.";
2827 FOR_EACH_REALCLIENT(self)
2829 if(self.classname == "spectator")
2831 if(self.enemy.typehitsound)
2832 self.typehit_time = time;
2833 else if(self.enemy.hitsound)
2834 self.hit_time = time;
2838 if(self.typehitsound)
2839 self.typehit_time = time;
2840 else if(self.hitsound)
2841 self.hit_time = time;
2844 altime = time + frametime * (1 + autocvar_g_antilag_nudge);
2845 // add 1 frametime because after this, engine SV_Physics
2846 // increases time by a frametime and then networks the frame
2847 // add another frametime because client shows everything with
2848 // 1 frame of lag (cl_nolerp 0). The last +1 however should not be
2850 FOR_EACH_CLIENT(self)
2852 self.hitsound = FALSE;
2853 self.typehitsound = FALSE;
2854 antilag_record(self, altime);
2861 * returns TRUE if redirecting
2863 float redirection_timeout;
2864 float redirection_nextthink;
2865 float RedirectionThink()
2867 float clients_found;
2869 if(redirection_target == "")
2872 if(!redirection_timeout)
2874 cvar_set("sv_public", "-2");
2875 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2876 if(redirection_target == "self")
2877 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2879 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2882 if(time < redirection_nextthink)
2885 redirection_nextthink = time + 1;
2888 FOR_EACH_REALCLIENT(self)
2891 print("Redirecting: sending connect command to ", self.netname, "\n");
2892 if(redirection_target == "self")
2893 stuffcmd(self, "\ndisconnect; defer ", ftos(autocvar_quit_and_redirect_timer), " reconnect\n");
2895 stuffcmd(self, strcat("\ndisconnect; defer ", ftos(autocvar_quit_and_redirect_timer), " \"connect ", redirection_target, "\"\n"));
2899 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2901 if(time > redirection_timeout || clients_found == 0)
2902 localcmd("\nwait; wait; wait; quit\n");
2907 void TargetMusic_RestoreGame();
2910 // Loaded from a save game
2911 // some things then break, so let's work around them...
2913 // Progs DB (capture records)
2914 ServerProgsDB = db_load(strcat("server.db", autocvar_sessionid));
2918 MapInfo_Enumerate();
2919 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
2922 TargetMusic_RestoreGame();
2931 if(world_initialized > 0)
2933 world_initialized = 0;
2934 print("Saving persistent data...\n");
2937 PlayerStats_EndMatch(0);
2939 PlayerStats_AddGlobalInfo(e);
2940 PlayerStats_Shutdown();
2942 if(!cheatcount_total)
2944 if(autocvar_sv_db_saveasdump)
2945 db_dump(ServerProgsDB, strcat("server.db", autocvar_sessionid));
2947 db_save(ServerProgsDB, strcat("server.db", autocvar_sessionid));
2949 if(autocvar_developer)
2951 if(autocvar_sv_db_saveasdump)
2952 db_dump(TemporaryDB, "server-temp.db");
2954 db_save(TemporaryDB, "server-temp.db");
2956 CheatShutdown(); // must be after cheatcount check
2957 db_close(ServerProgsDB);
2958 db_close(TemporaryDB);
2960 // tell the bot system the game is ending now
2963 WeaponStats_Shutdown();
2966 else if(world_initialized == 0)
2968 print("NOTE: crashed before even initializing the world, not saving persistent data\n");