2 void PingPLReport_Think()
7 delta = 3 / maxclients;
8 if(delta < sys_frametime)
10 self.nextthink = time + delta;
12 e = edict_num(self.cnt + 1);
13 if(clienttype(e) == CLIENTTYPE_REAL)
15 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
16 WriteByte(MSG_BROADCAST, TE_CSQC_PINGPLREPORT);
17 WriteByte(MSG_BROADCAST, self.cnt);
18 WriteShort(MSG_BROADCAST, max(1, e.ping));
19 WriteByte(MSG_BROADCAST, ceil(e.ping_packetloss * 255));
20 WriteByte(MSG_BROADCAST, ceil(e.ping_movementloss * 255));
24 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
25 WriteByte(MSG_BROADCAST, TE_CSQC_PINGPLREPORT);
26 WriteByte(MSG_BROADCAST, self.cnt);
27 WriteShort(MSG_BROADCAST, 0);
28 WriteByte(MSG_BROADCAST, 0);
29 WriteByte(MSG_BROADCAST, 0);
31 self.cnt = mod(self.cnt + 1, maxclients);
33 void PingPLReport_Spawn()
35 pingplreport = spawn();
36 pingplreport.classname = "pingplreport";
37 pingplreport.think = PingPLReport_Think;
38 pingplreport.nextthink = time;
41 float SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS = 1;
42 string redirection_target;
43 float world_initialized;
49 float() DoNextMapOverride;
51 void SetDefaultAlpha()
53 if(autocvar_g_running_guns)
55 default_player_alpha = -1;
56 default_weapon_alpha = +1;
60 default_player_alpha = autocvar_g_balance_cloaked_alpha;
61 default_weapon_alpha = default_player_alpha;
65 default_player_alpha = autocvar_g_player_alpha;
66 if(default_player_alpha == 0)
67 default_player_alpha = 1;
68 default_weapon_alpha = default_player_alpha;
72 void fteqcc_testbugs()
76 if(!autocvar_developer_fteqccbugs)
79 dprint("*** fteqcc test: checking for bugs...\n");
83 if(sqrt(a) - sqrt(b - a) == 0)
84 dprint("*** fteqcc test: found same-function-twice bug\n");
86 dprint("*** fteqcc test: same-function-twice bug got FINALLY FIXED! HOORAY!\n");
90 world.enemy.cnt += 10;
91 if(world.cnt > 0.2 || world.cnt < -0.2) // don't error out if it's just roundoff errors
92 dprint("*** fteqcc test: found += bug\n");
94 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
99 * Takes care of pausing and unpausing the game.
100 * Centerprints the information about an upcoming or active timeout to all active
101 * players. Also plays reminder sounds.
103 void timeoutHandler_Think() {
105 if (timeoutStatus == 1) {
106 if (remainingLeadTime > 0) {
107 //centerprint the information to every player
108 FOR_EACH_REALCLIENT(plr) {
109 if(plr.classname == "player") {
110 Send_CSQC_Centerprint_Generic(plr, CPID_TIMEOUT_COUNTDOWN, "Timeout begins in %d seconds!", 1, remainingLeadTime);
113 remainingLeadTime -= 1;
114 //think again in 1 second:
115 self.nextthink = time + 1;
118 //now pause the game:
120 //reset all the flood variables
121 FOR_EACH_CLIENT(plr) {
122 plr.nickspamcount = plr.nickspamtime = plr.floodcontrol_chat = plr.floodcontrol_chatteam = plr.floodcontrol_chattell = plr.floodcontrol_voice = plr.floodcontrol_voiceteam = 0;
124 cvar_set("slowmo", ftos(TIMEOUT_SLOWMO_VALUE));
125 //copy .v_angle to .lastV_angle for every player in order to fix their view during pause (see PlayerPreThink)
126 FOR_EACH_REALPLAYER(plr) {
127 plr.lastV_angle = plr.v_angle;
129 self.nextthink = time;
132 else if (timeoutStatus == 2) {
133 if (remainingTimeoutTime > 0) {
134 FOR_EACH_REALCLIENT(plr) {
135 if(plr.classname == "player") {
136 Send_CSQC_Centerprint_Generic(plr, CPID_TIMEOUT_COUNTDOWN, "Timeout ends in %d seconds!", 1, remainingTimeoutTime);
139 if(remainingTimeoutTime == autocvar_sv_timeout_resumetime) { //play a warning sound when only <sv_timeout_resumetime> seconds are left
140 Announce("prepareforbattle");
142 remainingTimeoutTime -= 1;
143 self.nextthink = time + TIMEOUT_SLOWMO_VALUE;
146 //unpause the game again
147 remainingTimeoutTime = timeoutStatus = 0;
148 cvar_set("slowmo", ftos(orig_slowmo));
149 //and unlock the fixed view again once there is no timeout active anymore
150 FOR_EACH_REALPLAYER(plr) {
151 plr.fixangle = FALSE;
153 //get rid of the countdown message
154 FOR_EACH_REALCLIENT(plr) {
155 if(plr.classname == "player") {
156 Send_CSQC_Centerprint_Generic_Expire(plr, CPID_TIMEOUT_COUNTDOWN);
164 else if (timeoutStatus == 0) { //if a player called the resumegame command (which set timeoutStatus to 0 already)
165 FOR_EACH_REALCLIENT(plr) {
166 if(plr.classname == "player") {
167 Send_CSQC_Centerprint_Generic_Expire(plr, CPID_TIMEOUT_COUNTDOWN);
178 if(autocvar__sv_init)
180 // cvar_set("_sv_init", "0");
181 // we do NOT set this to 0 any more, so someone "accidentally" changing
182 // to this "init" map on a dedicated server will cause no permanent
184 if(autocvar_g_maplist_shuffle)
186 n = tokenizebyseparator(autocvar_g_maplist, " ");
187 cvar_set("g_maplist_index", ftos(n - 1)); // jump to map 0 in GotoNextMap
190 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
192 if(!DoNextMapOverride())
200 self.nextthink = time;
204 self.nextthink = time + 1;
205 print("Waiting for _sv_init being set to 1 by initialization scripts...\n");
209 void cvar_changes_init()
213 float n, i, adding, pureadding;
216 strunzone(cvar_changes);
217 cvar_changes = string_null;
219 strunzone(cvar_purechanges);
220 cvar_purechanges = string_null;
221 cvar_purechanges_count = 0;
224 buf_cvarlist(h, "", "_"); // exclude all _ cvars as they are temporary
230 for(i = 0; i < n; ++i)
232 k = bufstr_get(h, i);
234 #define BADPREFIX(p) if(substring(k, 0, strlen(p)) == p) continue
235 #define BADPRESUFFIX(p,s) if(substring(k, 0, strlen(p)) == p && substring(k, -strlen(s), -1) == s) continue
236 #define BADCVAR(p) if(k == p) continue
238 // general excludes and namespaces for server admin used cvars
239 BADPREFIX("help_"); // PN's server has this listed as changed, let's not rat him out for THAT
243 BADPREFIX("cvar_check_");
245 BADCVAR("g_configversion");
246 BADCVAR("g_maplist_index");
247 BADCVAR("halflifebsp");
248 BADPREFIX("sv_world");
254 BADPREFIX("scoreboard_");
255 BADPREFIX("g_campaign");
256 BADPREFIX("g_waypointsprite_");
262 BADPREFIX("net_slist_");
268 BADPREFIX("sensitivity");
269 BADPREFIX("userbind");
272 BADPREFIX("crosshair");
273 BADCVAR("mod_q3bsp_lightmapmergepower");
274 BADCVAR("mod_q3bsp_nolightmaps");
276 BADCVAR("mastervolume");
278 BADCVAR("bgmvolume");
281 BADCVAR("developer");
282 BADCVAR("log_dest_udp");
284 BADCVAR("net_address");
285 BADCVAR("net_address_ipv6");
287 BADCVAR("savedgamecfg");
288 BADCVAR("serverconfig");
289 BADCVAR("sv_autoscreenshot");
290 BADCVAR("sv_heartbeatperiod");
291 BADCVAR("sv_vote_master_password");
292 BADCVAR("sys_colortranslation");
293 BADCVAR("sys_specialcharactertranslation");
294 BADCVAR("timeformat");
295 BADCVAR("timestamps");
296 BADPREFIX("developer_");
298 BADPREFIX("g_banned_list");
299 BADPREFIX("g_chat_flood_");
300 BADPREFIX("g_playerstats_");
301 BADPREFIX("g_voice_flood_");
303 BADPREFIX("settemp_");
304 BADPREFIX("sv_allowdownloads_");
305 BADPREFIX("sv_autodemo");
306 BADPREFIX("sv_curl_");
307 BADPREFIX("sv_eventlog");
308 BADPREFIX("sv_logscores_");
309 BADPREFIX("sv_master");
310 BADPREFIX("sv_weaponstats_");
311 BADPREFIX("sv_waypointsprite_");
312 BADCVAR("rescan_pending");
314 // these can contain player IDs, so better hide
315 BADPREFIX("g_forced_team_");
318 BADCVAR("fraglimit");
320 BADCVAR("g_assault");
325 BADCVAR("g_domination");
326 BADCVAR("g_domination_default_teams");
327 BADCVAR("g_freezetag");
328 BADCVAR("g_keepaway");
329 BADCVAR("g_keyhunt");
330 BADCVAR("g_keyhunt_teams");
331 BADCVAR("g_keyhunt_teams");
333 BADCVAR("g_nexball");
334 BADCVAR("g_onslaught");
336 BADCVAR("g_race_qualifying_timelimit");
337 BADCVAR("g_runematch");
339 BADCVAR("g_tdm_teams");
340 BADCVAR("leadlimit");
343 BADCVAR("timelimit");
347 BADCVAR("g_maplist");
348 BADCVAR("g_maplist_mostrecent");
352 d = cvar_defstring(k);
358 cvar_changes = strcat(cvar_changes, k, " \"", v, "\" // \"", d, "\"\n");
359 if(strlen(cvar_changes) > 16384)
361 cvar_changes = "// too many settings have been changed to show them here\n";
366 // now check if the changes are actually gameplay relevant
368 // does nothing visible
369 BADCVAR("captureleadlimit_override");
370 BADCVAR("g_arena_point_leadlimit");
371 BADCVAR("g_balance_kill_delay");
372 BADCVAR("g_ca_point_leadlimit");
373 BADCVAR("g_ctf_captimerecord_always");
374 BADCVAR("g_ctf_capture_leadlimit");
375 BADCVAR("g_ctf_flag_capture_effects");
376 BADCVAR("g_ctf_flag_glowtrails");
377 BADCVAR("g_ctf_flag_pickup_effects");
378 BADCVAR("g_domination_point_leadlimit");
379 BADCVAR("g_forced_respawn");
380 BADCVAR("g_keyhunt_point_leadlimit");
381 BADCVAR("g_nexball_goalleadlimit");
382 BADCVAR("g_runematch_point_leadlimit");
383 BADCVAR("leadlimit_and_fraglimit");
384 BADCVAR("leadlimit_override");
386 BADCVAR("sv_allow_fullbright");
387 BADCVAR("sv_checkforpacketsduringsleep");
388 BADCVAR("sv_timeout");
389 BADCVAR("welcome_message_time");
390 BADPREFIX("crypto_");
391 BADPREFIX("g_chat_");
392 BADPREFIX("g_ctf_captimerecord_");
393 BADPREFIX("g_maplist_votable_");
397 BADPREFIX("sv_cullentities_");
398 BADPREFIX("sv_fraginfo_");
399 BADPREFIX("sv_maxidle_");
400 BADPREFIX("sv_vote_");
401 BADPREFIX("timelimit_");
402 BADCVAR("gameversion");
403 BADPREFIX("gameversion_");
404 BADCVAR("sv_namechangetimer");
406 // allowed changes to server admins (please sync this to server.cfg)
410 // :%s,//\([^ ]*\).*,BADCVAR("\1");,
412 // yes, this does contain some redundant stuff, don't really care
413 BADCVAR("bot_config_file");
414 BADCVAR("bot_number");
415 BADCVAR("bot_prefix");
416 BADCVAR("bot_suffix");
417 BADCVAR("capturelimit_override");
418 BADCVAR("fraglimit_override");
420 BADCVAR("g_antilag");
421 BADCVAR("g_balance_teams");
422 BADCVAR("g_balance_teams_force");
423 BADCVAR("g_ban_sync_trusted_servers");
424 BADCVAR("g_ban_sync_uri");
425 BADCVAR("g_ctf_capture_limit");
426 BADCVAR("g_ctf_ignore_frags");
427 BADCVAR("g_ctf_win_mode");
428 BADCVAR("g_domination_point_limit");
429 BADCVAR("g_friendlyfire");
430 BADCVAR("g_fullbrightitems");
431 BADCVAR("g_fullbrightplayers");
432 BADCVAR("g_keyhunt_point_limit");
433 BADCVAR("g_keyhunt_teams_override");
434 BADCVAR("g_lms_lives_override");
435 BADCVAR("g_maplist");
436 BADCVAR("g_maplist_check_waypoints");
437 BADCVAR("g_maplist_mostrecent_count");
438 BADCVAR("g_maplist_shuffle");
439 BADCVAR("g_maplist_votable");
440 BADCVAR("g_maplist_votable_abstain");
441 BADCVAR("g_maplist_votable_nodetail");
442 BADCVAR("g_maplist_votable_suggestions");
443 BADCVAR("g_maxplayers");
444 BADCVAR("g_minstagib");
445 BADCVAR("g_mirrordamage");
446 BADCVAR("g_nexball_goallimit");
447 BADCVAR("g_runematch_point_limit");
448 BADCVAR("g_start_delay");
450 BADCVAR("g_weapon_stay"); BADPRESUFFIX("g_", "_weapon_stay");
453 BADCVAR("maxplayers");
454 BADCVAR("minplayers");
455 BADCVAR("net_address");
457 BADCVAR("rcon_password");
458 BADCVAR("rcon_restricted_commands");
459 BADCVAR("rcon_restricted_password");
461 BADCVAR("sv_adminnick");
462 BADCVAR("sv_autoscreenshot");
463 BADCVAR("sv_autotaunt");
464 BADCVAR("sv_curl_defaulturl");
465 BADCVAR("sv_defaultcharacter");
466 BADCVAR("sv_defaultplayercolors");
467 BADCVAR("sv_defaultplayermodel");
468 BADCVAR("sv_defaultplayerskin");
469 BADCVAR("sv_maxidle");
470 BADCVAR("sv_maxrate");
472 BADCVAR("sv_public");
473 BADCVAR("sv_ready_restart");
474 BADCVAR("sv_status_privacy");
476 BADCVAR("sv_vote_call");
477 BADCVAR("sv_vote_commands");
478 BADCVAR("sv_vote_majority_factor");
479 BADCVAR("sv_vote_master");
480 BADCVAR("sv_vote_master_commands");
481 BADCVAR("sv_vote_master_password");
482 BADCVAR("sv_vote_simple_majority_factor");
483 BADCVAR("sys_ticrate");
484 BADCVAR("teamplay_mode");
485 BADCVAR("timelimit_override");
486 BADPREFIX("g_warmup_");
487 BADPREFIX("sv_ready_restart_");
489 if(autocvar_g_minstagib)
491 BADCVAR("g_grappling_hook");
492 BADCVAR("g_jetpack");
499 cvar_purechanges = strcat(cvar_purechanges, k, " \"", v, "\" // \"", d, "\"\n");
500 if(strlen(cvar_purechanges) > 16384)
502 cvar_purechanges = "// too many settings have been changed to show them here\n";
506 ++cvar_purechanges_count;
507 // WARNING: this variable is used for the server list
508 // NEVER dare to skip this code!
509 // Hacks to intentionally appearing as "pure server" even though you DO have
510 // modified settings may be punished by removal from the server list.
511 // You can do to the variables cvar_changes and cvar_purechanges all you want,
515 if(cvar_changes == "")
516 cvar_changes = "// this server runs at default server settings\n";
518 cvar_changes = strcat("// this server runs at modified server settings:\n", cvar_changes);
519 cvar_changes = strzone(cvar_changes);
520 if(cvar_purechanges == "")
521 cvar_purechanges = "// this server runs at default gameplay settings\n";
523 cvar_purechanges = strcat("// this server runs at modified gameplay settings:\n", cvar_purechanges);
524 cvar_purechanges = strzone(cvar_purechanges);
527 void detect_maptype()
536 o_x += random() * (world.maxs_x - world.mins_x);
537 o_y += random() * (world.maxs_y - world.mins_y);
538 o_z += random() * (world.maxs_z - world.mins_z);
540 tracebox(o, PL_MIN, PL_MAX, o - '0 0 32768', MOVE_WORLDONLY, world);
541 if(trace_fraction == 1)
546 for(i = 0; i < 64; i += 4)
548 tracebox(o, '-1 -1 -1' * i, '1 1 1' * i, o - '0 0 32768', MOVE_WORLDONLY, world);
549 if(trace_fraction == 1)
551 print(ftos(i), " -> ", vtos(trace_endpos), "\n");
560 float RandomSeed_Send(entity to, float sf)
562 WriteByte(MSG_ENTITY, ENT_CLIENT_RANDOMSEED);
563 WriteShort(MSG_ENTITY, self.cnt);
566 void RandomSeed_Think()
568 self.cnt = bound(0, floor(random() * 65536), 65535);
569 self.nextthink = time + 5;
573 void RandomSeed_Spawn()
575 randomseed = spawn();
576 randomseed.think = RandomSeed_Think;
577 Net_LinkEntity(randomseed, FALSE, 0, RandomSeed_Send);
582 self.think(); // sets random seed and nextthink
586 void spawnfunc___init_dedicated_server(void)
588 // handler for _init/_init map (only for dedicated server initialization)
590 world_initialized = -1; // don't complain
592 cvar_string = cvar_string_normal;
593 cvar_set = cvar_set_normal;
595 remove = remove_unsafely;
599 e.think = GotoFirstMap;
600 e.nextthink = time; // this is usually 1 at this point
603 e.classname = "info_player_deathmatch"; // safeguard against player joining
605 self.classname = "worldspawn"; // safeguard against various stuff ;)
608 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
611 void Map_MarkAsRecent(string m);
612 float world_already_spawned;
613 void RegisterWeapons();
615 void ClientInit_Spawn();
616 void WeaponStats_Init();
617 void WeaponStats_Shutdown();
618 void spawnfunc_worldspawn (void)
620 float fd, l, i, j, n;
624 cvar_string = cvar_string_normal;
625 cvar_set = cvar_set_normal;
627 if(world_already_spawned)
628 error("world already spawned - you may have EXACTLY ONE worldspawn!");
629 world_already_spawned = TRUE;
631 remove = remove_safely; // during spawning, watch what you remove!
633 check_unacceptable_compiler_bugs();
635 cvar_changes_init(); // do this very early now so it REALLY matches the server config
637 compressShortVector_init();
639 allowed_to_spawn = TRUE;
642 head = nextent(world);
647 head = nextent(head);
650 // needs to be done so early as they would still spawn
653 ServerProgsDB = db_load(strcat("server.db", autocvar_sessionid));
655 TemporaryDB = db_create();
660 // 1 FLICKER (first variety)
661 lightstyle(1, "mmnmmommommnonmmonqnmmo");
663 // 2 SLOW STRONG PULSE
664 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
666 // 3 CANDLE (first variety)
667 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
670 lightstyle(4, "mamamamamama");
673 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
675 // 6 FLICKER (second variety)
676 lightstyle(6, "nmonqnmomnmomomno");
678 // 7 CANDLE (second variety)
679 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
681 // 8 CANDLE (third variety)
682 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
684 // 9 SLOW STROBE (fourth variety)
685 lightstyle(9, "aaaaaaaazzzzzzzz");
687 // 10 FLUORESCENT FLICKER
688 lightstyle(10, "mmamammmmammamamaaamammma");
690 // 11 SLOW PULSE NOT FADE TO BLACK
691 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
693 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
698 if(autocvar_g_campaign)
701 Map_MarkAsRecent(mapname);
703 precache_model ("null"); // we need this one before InitGameplayMode
711 bot_waypoints_for_items = autocvar_g_waypoints_for_items;
712 if(bot_waypoints_for_items == 1)
713 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
714 bot_waypoints_for_items = 0;
718 WaypointSprite_Init();
723 GameLogInit(); // prepare everything
725 // changing the logic generating it is okay. But:
726 // it HAS to stay <= 64 chars
727 // character set: ASCII 33-126 without the following characters: : ; ' " \ $
728 if(autocvar_sv_eventlog)
730 s = sprintf("%d.%s.%06d", ftos(autocvar_sv_eventlog_files_counter), strftime(FALSE, "%s"), floor(random() * 1000000));
731 matchid = strzone(s);
733 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
734 s = ":gameinfo:mutators:LIST";
737 MUTATOR_CALLHOOK(BuildMutatorsString);
740 // simple, probably not good in the mutator system
741 if(autocvar_g_grappling_hook)
742 s = strcat(s, ":grappling_hook");
744 // initialiation stuff, not good in the mutator system
745 if(!autocvar_g_use_ammunition)
746 s = strcat(s, ":no_use_ammunition");
748 // initialiation stuff, not good in the mutator system
749 if(!autocvar_g_pickup_items)
750 s = strcat(s, ":no_pickup_items");
752 // initialiation stuff, not good in the mutator system
753 if(autocvar_g_weaponarena != "0")
754 s = strcat(s, ":", autocvar_g_weaponarena, " arena");
756 // TODO to mutator system
757 if(autocvar_g_norecoil)
758 s = strcat(s, ":norecoil");
760 // TODO to mutator system
761 if(autocvar_g_midair)
762 s = strcat(s, ":midair");
764 // TODO to mutator system
765 if(autocvar_g_minstagib)
766 s = strcat(s, ":minstagib");
769 GameLogEcho(":gameinfo:end");
772 matchid = strzone(ftos(random()));
774 cvar_set("nextmap", "");
778 if(autocvar_g_campaign)
786 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
788 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
790 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
793 while((s = fgets(fd)))
795 l = tokenize_console(s);
800 print("Found ^1UNSUPPORTED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
801 print(" cdtrack ", argv(2), "\n");
803 else if(argv(0) == "fog")
805 print("Found ^1UNSUPPORTED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
806 print(" \"fog\" \"", s, "\"\n");
808 else if(argv(0) == "set")
810 print("Found ^1UNSUPPORTED^7 set command in .cfg file; put this line in mapinfo instead:\n");
811 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
813 else if(argv(0) != "//")
815 print("Found ^1UNSUPPORTED^7 set command in .cfg file; put this line in mapinfo instead:\n");
816 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
825 addstat(STAT_WEAPONS, AS_INT, weapons);
826 addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
827 addstat(STAT_SWITCHINGWEAPON, AS_INT, switchingweapon);
828 addstat(STAT_GAMESTARTTIME, AS_FLOAT, stat_game_starttime);
829 addstat(STAT_ALLOW_OLDNEXBEAM, AS_INT, stat_allow_oldnexbeam);
832 addstat(STAT_STRENGTH_FINISHED, AS_FLOAT, strength_finished);
833 addstat(STAT_INVINCIBLE_FINISHED, AS_FLOAT, invincible_finished);
834 addstat(STAT_PRESSED_KEYS, AS_FLOAT, pressedkeys);
835 addstat(STAT_FUEL, AS_INT, ammo_fuel);
836 addstat(STAT_SHOTORG, AS_INT, stat_shotorg);
837 addstat(STAT_LEADLIMIT, AS_FLOAT, stat_leadlimit);
838 addstat(STAT_WEAPON_CLIPLOAD, AS_INT, clip_load);
839 addstat(STAT_WEAPON_CLIPSIZE, AS_INT, clip_size);
840 addstat(STAT_LAST_PICKUP, AS_FLOAT, last_pickup);
841 addstat(STAT_HIT_TIME, AS_FLOAT, hit_time);
842 addstat(STAT_TYPEHIT_TIME, AS_FLOAT, typehit_time);
843 addstat(STAT_LAYED_MINES, AS_INT, minelayer_mines);
845 addstat(STAT_NEX_CHARGE, AS_FLOAT, nex_charge);
846 addstat(STAT_NEX_CHARGEPOOL, AS_FLOAT, nex_chargepool_ammo);
848 addstat(STAT_HAGAR_LOAD, AS_INT, hagar_load);
850 if(g_ca || g_freezetag)
852 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
853 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
854 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
855 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
859 addstat(STAT_FROZEN, AS_INT, freezetag_frozen);
860 addstat(STAT_REVIVE_PROGRESS, AS_FLOAT, freezetag_revive_progress);
863 // g_movementspeed hack
864 addstat(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW, AS_FLOAT, stat_sv_airspeedlimit_nonqw);
865 addstat(STAT_MOVEVARS_MAXSPEED, AS_FLOAT, stat_sv_maxspeed);
866 addstat(STAT_MOVEVARS_AIRACCEL_QW, AS_FLOAT, stat_sv_airaccel_qw);
867 addstat(STAT_MOVEVARS_AIRSTRAFEACCEL_QW, AS_FLOAT, stat_sv_airstrafeaccel_qw);
870 addstat(STAT_SECRETS_TOTAL, AS_FLOAT, stat_secrets_total);
871 addstat(STAT_SECRETS_FOUND, AS_FLOAT, stat_secrets_found);
873 next_pingtime = time + 5;
877 lsmaps_reply = "^7Maps available: ";
878 lsnewmaps_reply = "^7Maps without a record set: ";
879 for(i = 0, j = 0; i < MapInfo_count; ++i)
881 if(MapInfo_Get_ByID(i))
882 if not(MapInfo_Map_flags & (MAPINFO_FLAG_HIDDEN | MAPINFO_FLAG_FORBIDDEN))
889 lsmaps_reply = strcat(lsmaps_reply, col, MapInfo_Map_bspname, " ");
890 if(g_race && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "time"))))
891 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
892 else if(g_cts && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "time"))))
893 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
896 lsmaps_reply = strzone(strcat(lsmaps_reply, "\n"));
897 if (!g_race && !g_cts)
898 lsnewmaps_reply = "Need to be playing race or CTS for lsnewmaps to work.";
899 lsnewmaps_reply = strzone(strcat(lsnewmaps_reply, "\n"));
901 maplist_reply = "^7Maps in list: ";
902 n = tokenize_console(autocvar_g_maplist);
903 for(i = 0, j = 0; i < n; ++i)
905 if(MapInfo_CheckMap(argv(i)))
911 maplist_reply = strcat(maplist_reply, col, argv(i), " ");
915 maplist_reply = strzone(strcat(maplist_reply, "\n"));
916 MapInfo_ClearTemps();
918 for(i = 0; i < 10; ++i)
920 records_reply[i] = strzone(getrecords(i));
923 ladder_reply = strzone(getladder());
925 rankings_reply = strzone(getrankings());
929 PingPLReport_Spawn();
933 localcmd("\n_sv_hook_gamestart ", GetGametype(), "\n");
935 // fill sv_curl_serverpackages from .serverpackage files
936 if(autocvar_sv_curl_serverpackages_auto)
939 n = tokenize_console(cvar_string("sv_curl_serverpackages"));
940 for(i = 0; i < n; ++i)
941 if(substring(argv(i), -14, -1) != ".serverpackage")
942 s = strcat(s, " ", argv(i));
943 fd = search_begin("*.serverpackage", TRUE, FALSE);
946 j = search_getsize(fd);
947 for(i = 0; i < j; ++i)
948 s = strcat(s, " ", search_getfilename(fd, i));
951 cvar_set("sv_curl_serverpackages", substring(s, 1, -1));
956 world_initialized = 1;
959 void spawnfunc_light (void)
961 //makestatic (self); // Who the f___ did that?
967 return GametypeNameFromType(game);
970 string getmapname_stored;
976 float Map_Count, Map_Current;
977 string Map_Current_Name;
979 // NOTE: this now expects the map list to be already tokenized and the count in Map_Count
980 float GetMaplistPosition()
986 idx = autocvar_g_maplist_index;
993 for(pos = 0; pos < Map_Count; ++pos)
997 // resume normal maplist rotation if current map is not in g_maplist
1001 float MapHasRightSize(string map)
1004 if(currentbots || autocvar_bot_number || player_count < autocvar_minplayers)
1005 if(autocvar_g_maplist_check_waypoints)
1007 dprint("checkwp "); dprint(map);
1008 if(!fexists(strcat("maps/", map, ".waypoints")))
1010 dprint(": no waypoints\n");
1013 dprint(": has waypoints\n");
1016 // open map size restriction file
1017 dprint("opensize "); dprint(map);
1018 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
1021 float mapmin, mapmax;
1023 mapmin = stof(fgets(fh));
1024 mapmax = stof(fgets(fh));
1026 if(player_count < mapmin)
1028 dprint("not enough\n");
1031 if(player_count > mapmax)
1033 dprint("too many\n");
1036 dprint("right size\n");
1039 dprint(": not found\n");
1043 string Map_Filename(float position)
1045 return strcat("maps/", argv(position), ".bsp");
1048 string strwords(string s, float w)
1051 for(endpos = 0; w && endpos >= 0; --w)
1052 endpos = strstrofs(s, " ", endpos + 1);
1056 return substring(s, 0, endpos);
1059 float strhasword(string s, string w)
1061 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
1064 void Map_MarkAsRecent(string m)
1066 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", autocvar_g_maplist_mostrecent), max(0, autocvar_g_maplist_mostrecent_count)));
1069 float Map_IsRecent(string m)
1071 return strhasword(autocvar_g_maplist_mostrecent, m);
1074 float Map_Check(float position, float pass)
1078 map_next = argv(position);
1081 if(Map_IsRecent(map_next))
1084 filename = Map_Filename(position);
1085 if(MapInfo_CheckMap(map_next))
1089 if(MapHasRightSize(map_next))
1094 dprint( "Couldn't select '", filename, "'..\n" );
1099 void Map_Goto_SetStr(string nextmapname)
1101 if(getmapname_stored != "")
1102 strunzone(getmapname_stored);
1103 if(nextmapname == "")
1104 getmapname_stored = "";
1106 getmapname_stored = strzone(nextmapname);
1109 void Map_Goto_SetFloat(float position)
1111 cvar_set("g_maplist_index", ftos(position));
1112 Map_Goto_SetStr(argv(position));
1117 // settings persist, except...
1118 localcmd("\nsettemp_restore\n");
1124 MapInfo_LoadMap(getmapname_stored);
1127 // return codes of map selectors:
1128 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
1129 // -2 = permanent failure
1130 float() MaplistMethod_Iterate = // usual method
1134 for(pass = 1; pass <= 2; ++pass)
1136 for(i = 1; i < Map_Count; ++i)
1139 mapindex = mod(i + Map_Current, Map_Count);
1140 if(Map_Check(mapindex, pass))
1147 float() MaplistMethod_Repeat = // fallback method
1149 if(Map_Check(Map_Current, 2))
1154 float() MaplistMethod_Random = // random map selection
1160 for(i = 0; i <= imax; ++i)
1163 mapindex = mod(Map_Current + floor(random() * (Map_Count - 1) + 1), Map_Count); // any OTHER map
1164 if(Map_Check(mapindex, 1))
1170 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
1171 // the exponent sets a bias on the map selection:
1172 // the higher the exponent, the less likely "shortly repeated" same maps are
1174 float i, j, imax, insertpos;
1178 for(i = 0; i <= imax; ++i)
1182 // now reinsert this at another position
1183 insertpos = pow(random(), 1 / exponent); // ]0, 1]
1184 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
1185 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
1186 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
1188 // insert the current map there
1190 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
1191 newlist = strcat(newlist, " ", argv(j));
1192 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
1193 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
1194 newlist = strcat(newlist, " ", argv(j));
1195 newlist = substring(newlist, 1, strlen(newlist) - 1);
1196 cvar_set("g_maplist", newlist);
1197 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1199 // NOTE: the selected map has just been inserted at (insertpos-1)th position
1200 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
1201 if(Map_Check(Map_Current, 1))
1209 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1212 bprint( "Maplist is empty! Resetting it to default map list.\n" );
1213 cvar_set("g_maplist", MapInfo_ListAllAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
1214 if(autocvar_g_maplist_shuffle)
1216 localcmd("\nmenu_cmd sync\n");
1217 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1220 error("empty maplist, cannot select a new map");
1221 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
1223 if(Map_Current_Name)
1224 strunzone(Map_Current_Name);
1225 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
1226 // this may or may not be correct, but who cares, in the worst case a map
1227 // isn't chosen in the first pass that should have been
1238 if(autocvar_g_maplist_shuffle > 0)
1239 nextMap = MaplistMethod_Shuffle(autocvar_g_maplist_shuffle + 1);
1242 if(autocvar_g_maplist_selectrandom)
1243 nextMap = MaplistMethod_Random();
1246 nextMap = MaplistMethod_Iterate();
1249 nextMap = MaplistMethod_Repeat();
1253 Map_Goto_SetFloat(nextMap);
1254 return getmapname_stored;
1260 float DoNextMapOverride()
1262 if(autocvar_g_campaign)
1264 CampaignPostIntermission();
1265 alreadychangedlevel = TRUE;
1268 if(autocvar_quit_when_empty)
1270 if(player_count <= currentbots)
1273 alreadychangedlevel = TRUE;
1277 if(autocvar_quit_and_redirect != "")
1279 redirection_target = strzone(autocvar_quit_and_redirect);
1280 alreadychangedlevel = TRUE;
1283 if (autocvar_samelevel) // if samelevel is set, stay on same level
1285 localcmd("restart\n");
1286 alreadychangedlevel = TRUE;
1289 if(autocvar_nextmap != "")
1290 if(MapInfo_CheckMap(autocvar_nextmap))
1292 Map_Goto_SetStr(autocvar_nextmap);
1294 alreadychangedlevel = TRUE;
1297 if(autocvar_lastlevel)
1300 localcmd("set lastlevel 0\ntogglemenu\n");
1301 alreadychangedlevel = TRUE;
1312 if (alreadychangedlevel)
1314 alreadychangedlevel = TRUE;
1320 for(allowReset = 1; allowReset >= 0; --allowReset)
1322 nextMap = GetNextMap();
1328 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1329 cvar_set("g_maplist", MapInfo_ListAllAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
1330 if(autocvar_g_maplist_shuffle)
1332 localcmd("\nmenu_cmd sync\n");
1336 error("Everything is broken - not even the default map list works. Please report this to the developers.");
1348 When the player presses attack or jump, change to the next level
1351 .float autoscreenshot;
1352 void() MapVote_Start;
1353 void() MapVote_Think;
1354 float mapvote_initialized;
1355 void IntermissionThink()
1357 FixIntermissionClient(self);
1359 if( (autocvar_sv_autoscreenshot || self.cvar_cl_autoscreenshot)
1360 && ((self.autoscreenshot > 0) && (time > self.autoscreenshot)) )
1362 self.autoscreenshot = -1;
1363 if(clienttype(self) == CLIENTTYPE_REAL)
1364 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
1368 if (time < intermission_exittime)
1371 if(!mapvote_initialized)
1372 if (time < intermission_exittime + 10 && !(self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE))
1382 Returns the entity to view from
1386 entity FindIntermission()
1391 // look for info_intermission first
1392 spot = find (world, classname, "info_intermission");
1394 { // pick a random one
1398 spot = find (spot, classname, "info_intermission");
1400 spot = find (spot, classname, "info_intermission");
1406 // then look for the start position
1407 spot = find (world, classname, "info_player_start");
1411 // testinfo_player_start is only found in regioned levels
1412 spot = find (world, classname, "testplayerstart");
1416 // then look for the start position
1417 spot = find (world, classname, "info_player_deathmatch");
1421 //objerror ("FindIntermission: no spot");
1427 ===============================================================================
1431 ===============================================================================
1434 void DumpStats(float final)
1443 to_console = autocvar_sv_logscores_console;
1444 to_eventlog = autocvar_sv_eventlog;
1445 to_file = autocvar_sv_logscores_file;
1449 to_console = TRUE; // always print printstats replies
1450 to_eventlog = FALSE; // but never print them to the event log
1454 if(autocvar_sv_eventlog_console)
1455 to_console = FALSE; // otherwise we get the output twice
1461 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
1469 file = fopen(autocvar_sv_logscores_filename, FILE_APPEND);
1473 fputs(file, strcat(s, "\n"));
1476 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
1482 fputs(file, strcat(s, "\n"));
1484 FOR_EACH_CLIENT(other)
1486 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && autocvar_sv_logscores_bots))
1488 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
1489 s = strcat(s, ftos(rint(time - other.jointime)), ":");
1490 if(other.classname == "player" || g_arena || g_ca || g_lms)
1491 s = strcat(s, ftos(other.team), ":");
1493 s = strcat(s, "spectator:");
1496 print(s, other.netname, "\n");
1498 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
1500 fputs(file, strcat(s, other.netname, "\n"));
1506 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
1512 fputs(file, strcat(s, "\n"));
1514 for(i = 1; i < 16; ++i)
1516 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
1517 s = strcat(s, ":", ftos(i));
1523 fputs(file, strcat(s, "\n"));
1530 GameLogEcho(":end");
1533 fputs(file, ":end\n");
1538 void FixIntermissionClient(entity e)
1541 if(!e.autoscreenshot) // initial call
1543 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1545 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1546 e.solid = SOLID_NOT;
1547 e.movetype = MOVETYPE_NONE;
1548 e.takedamage = DAMAGE_NO;
1551 e.weaponentity.effects = EF_NODRAW;
1552 if (e.weaponentity.weaponentity)
1553 e.weaponentity.weaponentity.effects = EF_NODRAW;
1555 if(clienttype(e) == CLIENTTYPE_REAL)
1557 stuffcmd(e, "\nscr_printspeed 1000000\n");
1558 s = autocvar_sv_intermission_cdtrack;
1560 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1562 WriteByte(MSG_ONE, SVC_INTERMISSION);
1569 go to the next level for deathmatch
1570 only called if a time or frag limit has expired
1576 intermission_running = 1;
1578 // enforce a wait time before allowing changelevel
1579 if(player_count > 0)
1580 intermission_exittime = time + autocvar_sv_mapchange_delay;
1582 intermission_exittime = -1;
1585 WriteByte (MSG_ALL, SVC_CDTRACK);
1586 WriteByte (MSG_ALL, 3);
1587 WriteByte (MSG_ALL, 3);
1588 // done in FixIntermission
1591 //pos = FindIntermission ();
1599 PlayerStats_EndMatch(1);
1601 PlayerStats_AddGlobalInfo(e);
1602 PlayerStats_Shutdown();
1603 WeaponStats_Shutdown();
1605 if(autocvar_sv_eventlog)
1606 GameLogEcho(":gameover");
1610 FOR_EACH_PLAYER(other) {
1611 FixIntermissionClient(other);
1613 bprint(other.netname, " ^7wins.\n");
1616 if(autocvar_g_campaign)
1617 CampaignPreIntermission();
1619 localcmd("\nsv_hook_gameend\n");
1626 Exit deathmatch games upon conditions
1629 void CheckRules_Player()
1631 if (gameover) // someone else quit the game already
1634 if(self.deadflag == DEAD_NO)
1635 self.play_time += frametime;
1637 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1638 // (div0: and that in CheckRules_World please)
1641 float checkrules_equality;
1642 float checkrules_suddendeathwarning;
1643 float checkrules_suddendeathend;
1644 float checkrules_overtimesadded; //how many overtimes have been already added
1646 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1647 float WINNING_YES = 1; // winner found
1648 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1649 float WINNING_STARTSUDDENDEATHOVERTIME = 3; // no winner, enter suddendeath overtime NOW
1651 float InitiateSuddenDeath()
1653 // Check first whether normal overtimes could be added before initiating suddendeath mode
1654 // - for this timelimit_overtime needs to be >0 of course
1655 // - also check the winning condition calculated in the previous frame and only add normal overtime
1656 // again, if at the point at which timelimit would be extended again, still no winner was found
1657 if ((checkrules_overtimesadded >= 0) && (checkrules_overtimesadded < autocvar_timelimit_overtimes) && autocvar_timelimit_overtime && !(g_race && !g_race_qualifying))
1659 return 1; // need to call InitiateOvertime later
1663 if(!checkrules_suddendeathend)
1665 checkrules_suddendeathend = time + 60 * autocvar_timelimit_suddendeath;
1666 if(g_race && !g_race_qualifying)
1667 race_StartCompleting();
1673 void InitiateOvertime() // ONLY call this if InitiateSuddenDeath returned true
1675 ++checkrules_overtimesadded;
1676 //add one more overtime by simply extending the timelimit
1678 tl = autocvar_timelimit;
1679 tl += autocvar_timelimit_overtime;
1680 cvar_set("timelimit", ftos(tl));
1681 string minutesPlural;
1682 if (autocvar_timelimit_overtime == 1)
1683 minutesPlural = " ^3minute";
1685 minutesPlural = " ^3minutes";
1689 "^3Now playing ^1OVERTIME^3!\n\n^3Added ^1",
1690 ftos(autocvar_timelimit_overtime),
1697 float GetWinningCode(float fraglimitreached, float equality)
1699 if(autocvar_g_campaign == 1)
1700 if(fraglimitreached)
1707 if(fraglimitreached)
1708 return WINNING_STARTSUDDENDEATHOVERTIME;
1710 return WINNING_NEVER;
1712 if(fraglimitreached)
1718 // set the .winning flag for exactly those players with a given field value
1719 void SetWinners(.float field, float value)
1722 FOR_EACH_PLAYER(head)
1723 head.winning = (head.field == value);
1726 // set the .winning flag for those players with a given field value
1727 void AddWinners(.float field, float value)
1730 FOR_EACH_PLAYER(head)
1731 if(head.field == value)
1735 // clear the .winning flags
1736 void ClearWinners(void)
1739 FOR_EACH_PLAYER(head)
1743 // Onslaught winning condition:
1744 // game terminates if only one team has a working generator (or none)
1745 float WinningCondition_Onslaught()
1748 float t1, t2, t3, t4;
1750 WinningConditionHelper(); // set worldstatus
1755 // first check if the game has ended
1756 t1 = t2 = t3 = t4 = 0;
1757 head = find(world, classname, "onslaught_generator");
1760 if (head.health > 0)
1762 if (head.team == COLOR_TEAM1) t1 = 1;
1763 if (head.team == COLOR_TEAM2) t2 = 1;
1764 if (head.team == COLOR_TEAM3) t3 = 1;
1765 if (head.team == COLOR_TEAM4) t4 = 1;
1767 head = find(head, classname, "onslaught_generator");
1769 if (t1 + t2 + t3 + t4 < 2)
1771 // game over, only one team remains (or none)
1773 if (t1) SetWinners(team, COLOR_TEAM1);
1774 if (t2) SetWinners(team, COLOR_TEAM2);
1775 if (t3) SetWinners(team, COLOR_TEAM3);
1776 if (t4) SetWinners(team, COLOR_TEAM4);
1777 dprint("Have a winner, ending game.\n");
1781 // Two or more teams remain
1785 float LMS_NewPlayerLives()
1788 fl = autocvar_fraglimit;
1792 // first player has left the game for dying too much? Nobody else can get in.
1793 if(lms_lowest_lives < 1)
1796 if(!autocvar_g_lms_join_anytime)
1797 if(lms_lowest_lives < fl - autocvar_g_lms_last_join)
1800 return bound(1, lms_lowest_lives, fl);
1803 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1804 // they win. Otherwise the defending team wins once the timelimit passes.
1805 void assault_new_round();
1806 float WinningCondition_Assault()
1810 WinningConditionHelper(); // set worldstatus
1812 status = WINNING_NO;
1813 // as the timelimit has not yet passed just assume the defending team will win
1814 if(assault_attacker_team == COLOR_TEAM1)
1816 SetWinners(team, COLOR_TEAM2);
1820 SetWinners(team, COLOR_TEAM1);
1824 ent = find(world, classname, "target_assault_roundend");
1827 if(ent.winning) // round end has been triggered by attacking team
1829 bprint("ASSAULT: round completed...\n");
1830 SetWinners(team, assault_attacker_team);
1832 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
1834 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
1836 status = WINNING_YES;
1843 assault_new_round();
1852 // LMS winning condition: game terminates if and only if there's at most one
1853 // one player who's living lives. Top two scores being equal cancels the time
1855 float WinningCondition_LMS()
1862 have_player = FALSE;
1863 have_players = FALSE;
1864 l = LMS_NewPlayerLives();
1866 head = find(world, classname, "player");
1869 head2 = find(head, classname, "player");
1871 have_players = TRUE;
1875 // we have at least one player
1878 // two or more active players - continue with the game
1882 // exactly one player?
1885 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1889 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1895 // and assign him his first place
1896 PlayerScore_Add(head, SP_LMS_RANK, 1);
1903 // nobody is playing at all...
1906 // wait for players...
1910 // SNAFU (maybe a draw game?)
1912 dprint("No players, ending game.\n");
1917 // When we get here, we have at least two players who are actually LIVING,
1918 // now check if the top two players have equal score.
1919 WinningConditionHelper();
1922 if(WinningConditionHelper_winner)
1923 WinningConditionHelper_winner.winning = TRUE;
1924 if(WinningConditionHelper_topscore == WinningConditionHelper_secondscore)
1925 return WINNING_NEVER;
1927 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1931 void ShuffleMaplist()
1933 cvar_set("g_maplist", shufflewords(autocvar_g_maplist));
1937 float WinningCondition_Scores(float limit, float leadlimit)
1941 // TODO make everything use THIS winning condition (except LMS)
1942 WinningConditionHelper();
1946 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1947 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1948 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1949 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1953 if(WinningConditionHelper_winner)
1954 WinningConditionHelper_winner.winning = 1;
1955 if(WinningConditionHelper_winnerteam >= 0)
1956 SetWinners(team, WinningConditionHelper_winnerteam);
1958 if(WinningConditionHelper_lowerisbetter)
1960 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1961 WinningConditionHelper_secondscore = -WinningConditionHelper_secondscore;
1965 if(WinningConditionHelper_zeroisworst)
1966 leadlimit = 0; // not supported in this mode
1968 if(g_dm || g_tdm || g_arena || g_ca || (g_race && !g_race_qualifying) || g_nexball)
1969 // these modes always score in increments of 1, thus this makes sense
1971 if(leaderfrags != WinningConditionHelper_topscore)
1973 leaderfrags = WinningConditionHelper_topscore;
1976 if (leaderfrags == limit - 1)
1977 Announce("1fragleft");
1978 else if (leaderfrags == limit - 2)
1979 Announce("2fragsleft");
1980 else if (leaderfrags == limit - 3)
1981 Announce("3fragsleft");
1985 limitreached = FALSE;
1987 if(WinningConditionHelper_topscore >= limit)
1988 limitreached = TRUE;
1991 float leadlimitreached;
1992 leadlimitreached = (WinningConditionHelper_topscore - WinningConditionHelper_secondscore >= leadlimit);
1993 if(autocvar_leadlimit_and_fraglimit)
1994 limitreached = (limitreached && leadlimitreached);
1996 limitreached = (limitreached || leadlimitreached);
1999 return GetWinningCode(
2000 WinningConditionHelper_topscore && limitreached,
2001 WinningConditionHelper_equality
2005 float WinningCondition_Race(float fraglimit)
2016 if(p.race_completed)
2021 wc = WinningCondition_Scores(fraglimit, 0);
2023 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
2024 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
2025 // do NOT support equality when the laps are all raced!
2026 return WINNING_STARTSUDDENDEATHOVERTIME;
2028 return WINNING_NEVER;
2032 void ReadyRestart();
2033 float WinningCondition_QualifyingThenRace(float limit)
2036 wc = WinningCondition_Scores(limit, 0);
2038 // NEVER initiate overtime
2039 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
2047 float WinningCondition_RanOutOfSpawns()
2051 if(have_team_spawns <= 0)
2054 if(autocvar_g_spawn_useallspawns <= 0)
2057 if(!some_spawn_has_been_used)
2060 team1_score = team2_score = team3_score = team4_score = 0;
2062 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
2064 if(head.team == COLOR_TEAM1)
2066 else if(head.team == COLOR_TEAM2)
2068 else if(head.team == COLOR_TEAM3)
2070 else if(head.team == COLOR_TEAM4)
2074 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
2076 if(head.team == COLOR_TEAM1)
2078 else if(head.team == COLOR_TEAM2)
2080 else if(head.team == COLOR_TEAM3)
2082 else if(head.team == COLOR_TEAM4)
2087 if(team1_score + team2_score + team3_score + team4_score == 0)
2089 checkrules_equality = TRUE;
2092 else if(team1_score + team2_score + team3_score + team4_score == 1)
2095 if(team1_score) t = COLOR_TEAM1;
2096 if(team2_score) t = COLOR_TEAM2;
2097 if(team3_score) t = COLOR_TEAM3;
2098 if(team4_score) t = COLOR_TEAM4;
2099 CheckAllowedTeams(world);
2100 for(i = 0; i < MAX_TEAMSCORE; ++i)
2102 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
2103 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
2104 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
2105 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
2108 AddWinners(team, t);
2119 Exit deathmatch games upon conditions
2122 void CheckRules_World()
2134 MapVote_Think should now do that part
2135 if (intermission_running)
2136 if (time >= intermission_exittime + 60)
2138 if(!DoNextMapOverride())
2144 if (gameover) // someone else quit the game already
2146 if(player_count == 0) // Nobody there? Then let's go to the next map
2148 // this will actually check the player count in the next frame
2149 // again, but this shouldn't hurt
2153 timelimit = autocvar_timelimit * 60;
2154 fraglimit = autocvar_fraglimit;
2155 leadlimit = autocvar_leadlimit;
2157 if(inWarmupStage || time <= game_starttime) // NOTE: this is <= to prevent problems in the very tic where the game starts
2160 timelimit = 0; // timelimit is not made for warmup
2162 fraglimit = 0; // no fraglimit for now
2163 leadlimit = 0; // no leadlimit for now
2167 timelimit = 0; // ONS has its own overtime rule
2171 timelimit += game_starttime;
2173 else if (timelimit < 0)
2183 if(checkrules_suddendeathend)
2185 if(!checkrules_suddendeathwarning)
2187 checkrules_suddendeathwarning = TRUE;
2188 if(g_race && !g_race_qualifying)
2189 bcenterprint("^3Everyone, finish your lap! The race is over!");
2191 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
2196 if (timelimit && time >= timelimit)
2198 if(g_race && (g_race_qualifying == 2) && timelimit > 0)
2201 float playerswithlaps;
2204 totalplayers = playerswithlaps = readyplayers = 0;
2205 FOR_EACH_PLAYER(head)
2208 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
2214 // at least 2 of the players have completed a lap: start the RACE
2215 // otherwise, the players should end the qualifying on their own
2216 if(readyplayers || playerswithlaps >= 2)
2218 checkrules_suddendeathend = 0;
2219 ReadyRestart(); // go to race
2223 wantovertime |= InitiateSuddenDeath();
2226 wantovertime |= InitiateSuddenDeath();
2230 if (checkrules_suddendeathend && time >= checkrules_suddendeathend)
2236 float checkrules_status;
2237 checkrules_status = WinningCondition_RanOutOfSpawns();
2238 if(checkrules_status == WINNING_YES)
2240 bprint("Hey! Someone ran out of spawns!\n");
2242 else if(g_race && !g_race_qualifying && timelimit >= 0)
2244 checkrules_status = WinningCondition_Race(fraglimit);
2245 //print("WC_RACE yields ", ftos(checkrules_status), "\n");
2247 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
2249 checkrules_status = WinningCondition_QualifyingThenRace(fraglimit);
2250 //print("WC_QUALIFYING_THEN_RACE yields ", ftos(checkrules_status), "\n");
2254 checkrules_status = WinningCondition_Assault(); // TODO remove this?
2258 checkrules_status = WinningCondition_LMS();
2260 else if (g_onslaught)
2262 checkrules_status = WinningCondition_Onslaught(); // TODO remove this?
2266 checkrules_status = WinningCondition_Scores(fraglimit, leadlimit);
2267 //print("WC_SCORES yields ", ftos(checkrules_status), "\n");
2270 if(checkrules_status == WINNING_STARTSUDDENDEATHOVERTIME)
2272 checkrules_status = WINNING_NEVER;
2273 checkrules_overtimesadded = -1;
2274 wantovertime |= InitiateSuddenDeath();
2277 if(checkrules_status == WINNING_NEVER)
2278 // equality cases! Nobody wins if the overtime ends in a draw.
2283 if(checkrules_status == WINNING_NEVER)
2286 checkrules_status = WINNING_YES;
2289 if(checkrules_suddendeathend)
2290 if(checkrules_status != WINNING_NEVER || time >= checkrules_suddendeathend)
2291 checkrules_status = WINNING_YES;
2293 if(checkrules_status == WINNING_YES)
2295 //print("WINNING\n");
2300 float mapvote_nextthink;
2301 float mapvote_initialized;
2302 float mapvote_keeptwotime;
2303 float mapvote_timeout;
2304 string mapvote_message;
2305 #define MAPVOTE_SCREENSHOT_DIRS_COUNT 4
2306 string mapvote_screenshot_dirs[MAPVOTE_SCREENSHOT_DIRS_COUNT];
2307 float mapvote_screenshot_dirs_count;
2309 float mapvote_count;
2310 float mapvote_count_real;
2311 string mapvote_maps[MAPVOTE_COUNT];
2312 float mapvote_maps_screenshot_dir[MAPVOTE_COUNT];
2313 string mapvote_maps_pakfile[MAPVOTE_COUNT];
2314 float mapvote_maps_suggested[MAPVOTE_COUNT];
2315 string mapvote_suggestions[MAPVOTE_COUNT];
2316 float mapvote_suggestion_ptr;
2317 float mapvote_voters;
2318 float mapvote_votes[MAPVOTE_COUNT];
2320 float mapvote_detail;
2321 float mapvote_abstain;
2324 void MapVote_ClearAllVotes()
2326 FOR_EACH_CLIENT(other)
2330 string MapVote_Suggest(string m)
2334 return "That's not how to use this command.";
2335 if(!autocvar_g_maplist_votable_suggestions)
2336 return "Suggestions are not accepted on this server.";
2337 if(mapvote_initialized)
2338 return "Can't suggest - voting is already in progress!";
2339 m = MapInfo_FixName(m);
2341 return "The map you suggested is not available on this server.";
2342 if(!autocvar_g_maplist_votable_suggestions_override_mostrecent)
2344 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
2346 if(!MapInfo_CheckMap(m))
2347 return "The map you suggested does not support the current game mode.";
2348 for(i = 0; i < mapvote_suggestion_ptr; ++i)
2349 if(mapvote_suggestions[i] == m)
2350 return "This map was already suggested.";
2351 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
2353 i = floor(random() * mapvote_suggestion_ptr);
2357 i = mapvote_suggestion_ptr;
2358 mapvote_suggestion_ptr += 1;
2360 if(mapvote_suggestions[i] != "")
2361 strunzone(mapvote_suggestions[i]);
2362 mapvote_suggestions[i] = strzone(m);
2363 if(autocvar_sv_eventlog)
2364 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
2365 return strcat("Suggestion of ", m, " accepted.");
2368 void MapVote_AddVotable(string nextMap, float isSuggestion)
2371 string pakfile, mapfile;
2375 for(j = 0; j < mapvote_count; ++j)
2376 if(mapvote_maps[j] == nextMap)
2378 // suggestions might be no longer valid/allowed after gametype switch!
2380 if(!MapInfo_CheckMap(nextMap))
2382 mapvote_maps[mapvote_count] = strzone(nextMap);
2383 mapvote_maps_suggested[mapvote_count] = isSuggestion;
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 GameCommand_MapVote(string cmd)
2477 if(!intermission_running)
2480 if(cmd == "mv_getpic")
2482 MapVote_SendPicture(stof(argv(1)));
2489 float MapVote_GetMapMask()
2491 float mask, i, power;
2493 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
2494 if(mapvote_maps[i] != "")
2500 float MapVote_SendEntity(entity to, float sf)
2505 sf &~= 2; // if we send 1, we don't need to also send 2
2507 WriteByte(MSG_ENTITY, ENT_CLIENT_MAPVOTE);
2508 WriteByte(MSG_ENTITY, sf);
2512 // flag 1 == initialization
2513 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2514 WriteString(MSG_ENTITY, mapvote_screenshot_dirs[i]);
2515 WriteString(MSG_ENTITY, "");
2516 WriteByte(MSG_ENTITY, mapvote_count);
2517 WriteByte(MSG_ENTITY, mapvote_abstain);
2518 WriteByte(MSG_ENTITY, mapvote_detail);
2519 WriteCoord(MSG_ENTITY, mapvote_timeout);
2520 if(mapvote_count <= 8)
2521 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2523 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2524 for(i = 0; i < mapvote_count; ++i)
2525 if(mapvote_maps[i] != "")
2527 if(mapvote_abstain && i == mapvote_count - 1)
2529 WriteString(MSG_ENTITY, ""); // abstain needs no text
2530 WriteString(MSG_ENTITY, ""); // abstain needs no pack
2531 WriteByte(MSG_ENTITY, 0); // abstain needs no screenshot dir
2535 WriteString(MSG_ENTITY, mapvote_maps[i]);
2536 WriteString(MSG_ENTITY, mapvote_maps_pakfile[i]);
2537 WriteByte(MSG_ENTITY, mapvote_maps_screenshot_dir[i]);
2544 // flag 2 == update of mask
2545 if(mapvote_count <= 8)
2546 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2548 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2554 for(i = 0; i < mapvote_count; ++i)
2555 if(mapvote_maps[i] != "")
2556 WriteByte(MSG_ENTITY, mapvote_votes[i]);
2558 WriteByte(MSG_ENTITY, to.mapvote);
2564 void MapVote_Spawn()
2566 Net_LinkEntity(mapvote_ent = spawn(), FALSE, 0, MapVote_SendEntity);
2569 void MapVote_TouchMask()
2571 mapvote_ent.SendFlags |= 2;
2574 void MapVote_TouchVotes(entity voter)
2576 mapvote_ent.SendFlags |= 4;
2579 float MapVote_Finished(float mappos)
2585 if(autocvar_sv_eventlog)
2587 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2588 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
2589 didntvote = mapvote_voters;
2590 for(i = 0; i < mapvote_count; ++i)
2591 if(mapvote_maps[i] != "")
2593 didntvote -= mapvote_votes[i];
2596 result = strcat(result, ":", mapvote_maps[i]);
2597 result = strcat(result, ":", ftos(mapvote_votes[i]));
2600 result = strcat(result, ":didn't vote:", ftos(didntvote));
2602 GameLogEcho(result);
2603 if(mapvote_maps_suggested[mappos])
2604 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
2607 FOR_EACH_REALCLIENT(other)
2608 FixClientCvars(other);
2610 Map_Goto_SetStr(mapvote_maps[mappos]);
2612 alreadychangedlevel = TRUE;
2615 void MapVote_CheckRules_1()
2619 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2621 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2622 mapvote_votes[i] = 0;
2626 FOR_EACH_REALCLIENT(other)
2631 i = other.mapvote - 1;
2632 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2633 mapvote_votes[i] = mapvote_votes[i] + 1;
2638 float MapVote_CheckRules_2()
2641 float firstPlace, secondPlace;
2642 float firstPlaceVotes, secondPlaceVotes;
2643 float mapvote_voters_real;
2646 if(mapvote_count_real == 1)
2647 return MapVote_Finished(0);
2649 mapvote_voters_real = mapvote_voters;
2651 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2653 RandomSelection_Init();
2654 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2655 RandomSelection_Add(world, i, string_null, 1, mapvote_votes[i]);
2656 firstPlace = RandomSelection_chosen_float;
2657 firstPlaceVotes = RandomSelection_best_priority;
2658 //dprint("First place: ", ftos(firstPlace), "\n");
2659 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2661 RandomSelection_Init();
2662 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2664 RandomSelection_Add(world, i, string_null, 1, mapvote_votes[i]);
2665 secondPlace = RandomSelection_chosen_float;
2666 secondPlaceVotes = RandomSelection_best_priority;
2667 //dprint("Second place: ", ftos(secondPlace), "\n");
2668 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2670 if(firstPlace == -1)
2671 error("No first place in map vote... WTF?");
2673 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2674 return MapVote_Finished(firstPlace);
2676 if(mapvote_keeptwotime)
2677 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2680 MapVote_TouchMask();
2681 mapvote_message = "Now decide between the TOP TWO!";
2682 mapvote_keeptwotime = 0;
2683 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2684 result = strcat(result, ":", ftos(firstPlaceVotes));
2685 result = strcat(result, ":", mapvote_maps[secondPlace]);
2686 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2687 didntvote = mapvote_voters;
2688 for(i = 0; i < mapvote_count; ++i)
2689 if(mapvote_maps[i] != "")
2691 didntvote -= mapvote_votes[i];
2693 if(i != secondPlace)
2695 result = strcat(result, ":", mapvote_maps[i]);
2696 result = strcat(result, ":", ftos(mapvote_votes[i]));
2697 if(i < mapvote_count_real)
2699 strunzone(mapvote_maps[i]);
2700 mapvote_maps[i] = "";
2701 strunzone(mapvote_maps_pakfile[i]);
2702 mapvote_maps_pakfile[i] = "";
2706 result = strcat(result, ":didn't vote:", ftos(didntvote));
2707 if(autocvar_sv_eventlog)
2708 GameLogEcho(result);
2718 keeptwo = mapvote_keeptwotime;
2719 MapVote_CheckRules_1(); // count
2720 if(MapVote_CheckRules_2()) // decide
2724 FOR_EACH_REALCLIENT(other)
2726 // hide scoreboard again
2727 if(other.health != 2342)
2729 other.health = 2342;
2731 if(clienttype(other) == CLIENTTYPE_REAL)
2734 WriteByte(MSG_ONE, SVC_FINALE);
2735 WriteString(MSG_ONE, "");
2739 // clear possibly invalid votes
2740 if(mapvote_maps[other.mapvote - 1] == "")
2742 // use impulses as new vote
2743 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2744 if(mapvote_maps[other.impulse - 1] != "")
2746 other.mapvote = other.impulse;
2747 MapVote_TouchVotes(other);
2755 MapVote_CheckRules_1(); // just count
2757 void MapVote_Start()
2762 // wait for stats to be sent first
2763 if(!playerstats_waitforme)
2766 MapInfo_Enumerate();
2767 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
2770 void MapVote_Think()
2775 if(alreadychangedlevel)
2778 if(time < mapvote_nextthink)
2782 mapvote_nextthink = time + 0.5;
2784 if(!mapvote_initialized)
2786 if(autocvar_rescan_pending == 1)
2788 cvar_set("rescan_pending", "2");
2789 localcmd("fs_rescan\nrescan_pending 3\n");
2792 else if(autocvar_rescan_pending == 2)
2796 else if(autocvar_rescan_pending == 3)
2798 // now build missing mapinfo files
2799 if(!MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
2802 // we're done, start the timer
2803 cvar_set("rescan_pending", "0");
2806 mapvote_initialized = TRUE;
2807 if(DoNextMapOverride())
2809 if(!autocvar_g_maplist_votable || player_count <= 0)
2820 string GotoMap(string m)
2822 if(!MapInfo_CheckMap(m))
2823 return "The map you chose is not available on this server.";
2824 cvar_set("nextmap", m);
2825 cvar_set("timelimit", "-1");
2826 if(mapvote_initialized || alreadychangedlevel)
2828 if(DoNextMapOverride())
2829 return "Map switch initiated.";
2831 return "Hm... no. For some reason I like THIS map more.";
2834 return "Map switch will happen after scoreboard.";
2841 FOR_EACH_REALCLIENT(self)
2843 if(self.classname == "spectator")
2845 if(self.enemy.typehitsound)
2846 self.typehit_time = time;
2847 else if(self.enemy.hitsound)
2848 self.hit_time = time;
2852 if(self.typehitsound)
2853 self.typehit_time = time;
2854 else if(self.hitsound)
2855 self.hit_time = time;
2858 altime = time + frametime * (1 + autocvar_g_antilag_nudge);
2859 // add 1 frametime because after this, engine SV_Physics
2860 // increases time by a frametime and then networks the frame
2861 // add another frametime because client shows everything with
2862 // 1 frame of lag (cl_nolerp 0). The last +1 however should not be
2864 FOR_EACH_CLIENT(self)
2866 self.hitsound = FALSE;
2867 self.typehitsound = FALSE;
2868 antilag_record(self, altime);
2875 * returns TRUE if redirecting
2877 float redirection_timeout;
2878 float redirection_nextthink;
2879 float RedirectionThink()
2881 float clients_found;
2883 if(redirection_target == "")
2886 if(!redirection_timeout)
2888 cvar_set("sv_public", "-2");
2889 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2890 if(redirection_target == "self")
2891 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2893 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2896 if(time < redirection_nextthink)
2899 redirection_nextthink = time + 1;
2902 FOR_EACH_REALCLIENT(self)
2904 print("Redirecting: sending connect command to ", self.netname, "\n");
2905 if(redirection_target == "self")
2906 stuffcmd(self, "\ndisconnect; reconnect\n");
2908 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2912 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2914 if(time > redirection_timeout || clients_found == 0)
2915 localcmd("\nwait; wait; wait; quit\n");
2920 void TargetMusic_RestoreGame();
2923 // Loaded from a save game
2924 // some things then break, so let's work around them...
2926 // Progs DB (capture records)
2927 ServerProgsDB = db_load(strcat("server.db", autocvar_sessionid));
2931 MapInfo_Enumerate();
2932 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
2935 TargetMusic_RestoreGame();
2942 if(gameover > 1) // shutting down already?
2945 gameover = 2; // 2 = server shutting down
2947 if(world_initialized > 0)
2949 world_initialized = 0;
2950 print("Saving persistent data...\n");
2953 PlayerStats_EndMatch(0);
2955 PlayerStats_AddGlobalInfo(e);
2956 PlayerStats_Shutdown();
2958 if(!cheatcount_total)
2960 if(autocvar_sv_db_saveasdump)
2961 db_dump(ServerProgsDB, strcat("server.db", autocvar_sessionid));
2963 db_save(ServerProgsDB, strcat("server.db", autocvar_sessionid));
2965 if(autocvar_developer)
2967 if(autocvar_sv_db_saveasdump)
2968 db_dump(TemporaryDB, "server-temp.db");
2970 db_save(TemporaryDB, "server-temp.db");
2972 CheatShutdown(); // must be after cheatcount check
2973 db_close(ServerProgsDB);
2974 db_close(TemporaryDB);
2976 // tell the bot system the game is ending now
2979 WeaponStats_Shutdown();
2982 else if(world_initialized == 0)
2984 print("NOTE: crashed before even initializing the world, not saving persistent data\n");