2 void PingPLReport_Think()
7 delta = 3 / maxclients;
8 if(delta < sys_frametime)
10 self.nextthink = time + delta;
12 e = edict_num(self.cnt + 1);
13 if(clienttype(e) == CLIENTTYPE_REAL)
15 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
16 WriteByte(MSG_BROADCAST, TE_CSQC_PINGPLREPORT);
17 WriteByte(MSG_BROADCAST, self.cnt);
18 WriteShort(MSG_BROADCAST, max(1, e.ping));
19 WriteByte(MSG_BROADCAST, ceil(e.ping_packetloss * 255));
20 WriteByte(MSG_BROADCAST, ceil(e.ping_movementloss * 255));
24 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
25 WriteByte(MSG_BROADCAST, TE_CSQC_PINGPLREPORT);
26 WriteByte(MSG_BROADCAST, self.cnt);
27 WriteShort(MSG_BROADCAST, 0);
28 WriteByte(MSG_BROADCAST, 0);
29 WriteByte(MSG_BROADCAST, 0);
31 self.cnt = mod(self.cnt + 1, maxclients);
33 void PingPLReport_Spawn()
35 pingplreport = spawn();
36 pingplreport.classname = "pingplreport";
37 pingplreport.think = PingPLReport_Think;
38 pingplreport.nextthink = time;
41 float SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS = 1;
42 string redirection_target;
43 float world_initialized;
47 void GotoNextMap(float reinit);
49 float(float reinit) DoNextMapOverride;
51 void SetDefaultAlpha()
53 if(autocvar_g_running_guns)
55 default_player_alpha = -1;
56 default_weapon_alpha = +1;
60 default_player_alpha = autocvar_g_balance_cloaked_alpha;
61 default_weapon_alpha = default_player_alpha;
65 default_player_alpha = autocvar_g_player_alpha;
66 if(default_player_alpha == 0)
67 default_player_alpha = 1;
68 default_weapon_alpha = default_player_alpha;
72 void fteqcc_testbugs()
76 if(!autocvar_developer_fteqccbugs)
79 dprint("*** fteqcc test: checking for bugs...\n");
83 if(sqrt(a) - sqrt(b - a) == 0)
84 dprint("*** fteqcc test: found same-function-twice bug\n");
86 dprint("*** fteqcc test: same-function-twice bug got FINALLY FIXED! HOORAY!\n");
90 world.enemy.cnt += 10;
91 if(world.cnt > 0.2 || world.cnt < -0.2) // don't error out if it's just roundoff errors
92 dprint("*** fteqcc test: found += bug\n");
94 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
101 if(autocvar__sv_init)
103 // cvar_set("_sv_init", "0");
104 // we do NOT set this to 0 any more, so someone "accidentally" changing
105 // to this "init" map on a dedicated server will cause no permanent
107 if(autocvar_g_maplist_shuffle)
109 n = tokenizebyseparator(autocvar_g_maplist, " ");
110 cvar_set("g_maplist_index", ftos(n - 1)); // jump to map 0 in GotoNextMap
113 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
115 if(!DoNextMapOverride(1))
123 self.nextthink = time;
127 self.nextthink = time + 1;
128 print("Waiting for _sv_init being set to 1 by initialization scripts...\n");
132 void cvar_changes_init()
136 float n, i, adding, pureadding;
139 strunzone(cvar_changes);
140 cvar_changes = string_null;
142 strunzone(cvar_purechanges);
143 cvar_purechanges = string_null;
144 cvar_purechanges_count = 0;
147 buf_cvarlist(h, "", "_"); // exclude all _ cvars as they are temporary
153 for(i = 0; i < n; ++i)
155 k = bufstr_get(h, i);
157 #define BADPREFIX(p) if(substring(k, 0, strlen(p)) == p) continue
158 #define BADPRESUFFIX(p,s) if(substring(k, 0, strlen(p)) == p && substring(k, -strlen(s), -1) == s) continue
159 #define BADCVAR(p) if(k == p) continue
161 // general excludes and namespaces for server admin used cvars
162 BADPREFIX("help_"); // PN's server has this listed as changed, let's not rat him out for THAT
166 BADPREFIX("cvar_check_");
168 BADCVAR("g_configversion");
169 BADCVAR("g_maplist_index");
170 BADCVAR("halflifebsp");
171 BADPREFIX("sv_world");
177 BADPREFIX("scoreboard_");
178 BADPREFIX("g_campaign");
179 BADPREFIX("g_waypointsprite_");
185 BADPREFIX("net_slist_");
191 BADPREFIX("sensitivity");
192 BADPREFIX("userbind");
195 BADPREFIX("crosshair");
196 BADCVAR("mod_q3bsp_lightmapmergepower");
197 BADCVAR("mod_q3bsp_nolightmaps");
199 BADCVAR("mastervolume");
201 BADCVAR("bgmvolume");
204 BADCVAR("developer");
205 BADCVAR("log_dest_udp");
207 BADCVAR("net_address");
208 BADCVAR("net_address_ipv6");
210 BADCVAR("savedgamecfg");
211 BADCVAR("serverconfig");
212 BADCVAR("sv_autoscreenshot");
213 BADCVAR("sv_heartbeatperiod");
214 BADCVAR("sv_vote_master_password");
215 BADCVAR("sys_colortranslation");
216 BADCVAR("sys_specialcharactertranslation");
217 BADCVAR("timeformat");
218 BADCVAR("timestamps");
219 BADPREFIX("developer_");
221 BADPREFIX("g_banned_list");
222 BADPREFIX("g_chat_flood_");
223 BADPREFIX("g_ghost_items");
224 BADPREFIX("g_playerstats_");
225 BADPREFIX("g_respawn_ghosts");
226 BADPREFIX("g_voice_flood_");
228 BADPREFIX("sv_allowdownloads");
229 BADPREFIX("sv_autodemo");
230 BADPREFIX("sv_curl_");
231 BADPREFIX("sv_eventlog");
232 BADPREFIX("sv_logscores_");
233 BADPREFIX("sv_master");
234 BADPREFIX("sv_weaponstats_");
235 BADPREFIX("sv_waypointsprite_");
236 BADCVAR("rescan_pending");
238 // these can contain player IDs, so better hide
239 BADPREFIX("g_forced_team_");
242 BADCVAR("fraglimit");
244 BADCVAR("g_assault");
249 BADCVAR("g_domination");
250 BADCVAR("g_domination_default_teams");
251 BADCVAR("g_freezetag");
252 BADCVAR("g_keepaway");
253 BADCVAR("g_keyhunt");
254 BADCVAR("g_keyhunt_teams");
255 BADCVAR("g_keyhunt_teams");
257 BADCVAR("g_nexball");
258 BADCVAR("g_onslaught");
260 BADCVAR("g_race_qualifying_timelimit");
261 BADCVAR("g_runematch");
263 BADCVAR("g_tdm_teams");
264 BADCVAR("leadlimit");
267 BADCVAR("timelimit");
271 BADCVAR("g_maplist");
272 BADCVAR("g_maplist_mostrecent");
276 d = cvar_defstring(k);
282 cvar_changes = strcat(cvar_changes, k, " \"", v, "\" // \"", d, "\"\n");
283 if(strlen(cvar_changes) > 16384)
285 cvar_changes = "// too many settings have been changed to show them here\n";
290 // now check if the changes are actually gameplay relevant
292 // does nothing visible
293 BADCVAR("captureleadlimit_override");
294 BADCVAR("g_arena_point_leadlimit");
295 BADCVAR("g_balance_kill_delay");
296 BADCVAR("g_ca_point_leadlimit");
297 BADCVAR("g_ctf_captimerecord_always");
298 BADCVAR("g_ctf_flag_capture_effects");
299 BADCVAR("g_ctf_flag_glowtrails");
300 BADCVAR("g_ctf_flag_pickup_effects");
301 BADCVAR("g_domination_point_leadlimit");
302 BADCVAR("g_forced_respawn");
303 BADCVAR("g_keyhunt_point_leadlimit");
305 BADCVAR("g_nexball_goalleadlimit");
306 BADCVAR("g_runematch_point_leadlimit");
307 BADCVAR("leadlimit_and_fraglimit");
308 BADCVAR("leadlimit_override");
310 BADCVAR("sv_allow_fullbright");
311 BADCVAR("sv_checkforpacketsduringsleep");
312 BADCVAR("sv_fraginfo");
313 BADCVAR("sv_timeout");
314 BADPREFIX("sv_timeout_");
315 BADCVAR("welcome_message_time");
316 BADPREFIX("crypto_");
317 BADPREFIX("g_chat_");
318 BADPREFIX("g_ctf_captimerecord_");
319 BADPREFIX("g_maplist_votable_");
323 BADPREFIX("sv_cullentities_");
324 BADPREFIX("sv_fraginfo_");
325 BADPREFIX("sv_maxidle_");
326 BADPREFIX("sv_vote_");
327 BADPREFIX("timelimit_");
328 BADCVAR("gameversion");
329 BADPREFIX("gameversion_");
330 BADCVAR("sv_namechangetimer");
331 #ifndef NO_LEGACY_NETWORKING
332 BADCVAR("sv_use_csqc_players"); // transition
335 // allowed changes to server admins (please sync this to server.cfg)
339 // :%s,//\([^ ]*\).*,BADCVAR("\1");,
341 // yes, this does contain some redundant stuff, don't really care
342 BADCVAR("bot_config_file");
343 BADCVAR("bot_number");
344 BADCVAR("bot_prefix");
345 BADCVAR("bot_suffix");
346 BADCVAR("capturelimit_override");
347 BADCVAR("fraglimit_override");
349 BADCVAR("g_antilag");
350 BADCVAR("g_balance_teams");
351 BADCVAR("g_balance_teams_force");
352 BADCVAR("g_ban_sync_trusted_servers");
353 BADCVAR("g_ban_sync_uri");
354 BADCVAR("g_ctf_ignore_frags");
355 BADCVAR("g_domination_point_limit");
356 BADCVAR("g_friendlyfire");
357 BADCVAR("g_fullbrightitems");
358 BADCVAR("g_fullbrightplayers");
359 BADCVAR("g_keyhunt_point_limit");
360 BADCVAR("g_keyhunt_teams_override");
361 BADCVAR("g_lms_lives_override");
362 BADCVAR("g_maplist");
363 BADCVAR("g_maplist_check_waypoints");
364 BADCVAR("g_maplist_mostrecent_count");
365 BADCVAR("g_maplist_shuffle");
366 BADCVAR("g_maplist_votable");
367 BADCVAR("g_maplist_votable_abstain");
368 BADCVAR("g_maplist_votable_nodetail");
369 BADCVAR("g_maplist_votable_suggestions");
370 BADCVAR("g_maxplayers");
371 BADCVAR("g_minstagib");
372 BADCVAR("g_mirrordamage");
373 BADCVAR("g_nexball_goallimit");
374 BADCVAR("g_powerups");
375 BADCVAR("g_runematch_point_limit");
376 BADCVAR("g_start_delay");
378 BADCVAR("g_weapon_stay"); BADPRESUFFIX("g_", "_weapon_stay");
381 BADCVAR("maxplayers");
382 BADCVAR("minplayers");
383 BADCVAR("net_address");
385 BADCVAR("rcon_password");
386 BADCVAR("rcon_restricted_commands");
387 BADCVAR("rcon_restricted_password");
389 BADCVAR("sv_adminnick");
390 BADCVAR("sv_autoscreenshot");
391 BADCVAR("sv_autotaunt");
392 BADCVAR("sv_curl_defaulturl");
393 BADCVAR("sv_defaultcharacter");
394 BADCVAR("sv_defaultplayercolors");
395 BADCVAR("sv_defaultplayermodel");
396 BADCVAR("sv_defaultplayerskin");
397 BADCVAR("sv_maxidle");
398 BADCVAR("sv_maxrate");
400 BADCVAR("sv_public");
401 BADCVAR("sv_ready_restart");
402 BADCVAR("sv_status_privacy");
404 BADCVAR("sv_vote_call");
405 BADCVAR("sv_vote_commands");
406 BADCVAR("sv_vote_majority_factor");
407 BADCVAR("sv_vote_master");
408 BADCVAR("sv_vote_master_commands");
409 BADCVAR("sv_vote_master_password");
410 BADCVAR("sv_vote_simple_majority_factor");
411 BADCVAR("sys_ticrate");
412 BADCVAR("teamplay_mode");
413 BADCVAR("timelimit_override");
414 BADCVAR("g_spawnshieldtime");
415 BADPREFIX("g_warmup_");
416 BADPREFIX("sv_ready_restart_");
418 if(autocvar_g_minstagib)
420 BADCVAR("g_grappling_hook");
421 BADCVAR("g_jetpack");
428 cvar_purechanges = strcat(cvar_purechanges, k, " \"", v, "\" // \"", d, "\"\n");
429 if(strlen(cvar_purechanges) > 16384)
431 cvar_purechanges = "// too many settings have been changed to show them here\n";
435 ++cvar_purechanges_count;
436 // WARNING: this variable is used for the server list
437 // NEVER dare to skip this code!
438 // Hacks to intentionally appearing as "pure server" even though you DO have
439 // modified settings may be punished by removal from the server list.
440 // You can do to the variables cvar_changes and cvar_purechanges all you want,
444 if(cvar_changes == "")
445 cvar_changes = "// this server runs at default server settings\n";
447 cvar_changes = strcat("// this server runs at modified server settings:\n", cvar_changes);
448 cvar_changes = strzone(cvar_changes);
449 if(cvar_purechanges == "")
450 cvar_purechanges = "// this server runs at default gameplay settings\n";
452 cvar_purechanges = strcat("// this server runs at modified gameplay settings:\n", cvar_purechanges);
453 cvar_purechanges = strzone(cvar_purechanges);
456 void detect_maptype()
465 o_x += random() * (world.maxs_x - world.mins_x);
466 o_y += random() * (world.maxs_y - world.mins_y);
467 o_z += random() * (world.maxs_z - world.mins_z);
469 tracebox(o, PL_MIN, PL_MAX, o - '0 0 32768', MOVE_WORLDONLY, world);
470 if(trace_fraction == 1)
475 for(i = 0; i < 64; i += 4)
477 tracebox(o, '-1 -1 -1' * i, '1 1 1' * i, o - '0 0 32768', MOVE_WORLDONLY, world);
478 if(trace_fraction == 1)
480 print(ftos(i), " -> ", vtos(trace_endpos), "\n");
489 float RandomSeed_Send(entity to, float sf)
491 WriteByte(MSG_ENTITY, ENT_CLIENT_RANDOMSEED);
492 WriteShort(MSG_ENTITY, self.cnt);
495 void RandomSeed_Think()
497 self.cnt = bound(0, floor(random() * 65536), 65535);
498 self.nextthink = time + 5;
502 void RandomSeed_Spawn()
504 randomseed = spawn();
505 randomseed.think = RandomSeed_Think;
506 Net_LinkEntity(randomseed, FALSE, 0, RandomSeed_Send);
511 self.think(); // sets random seed and nextthink
515 void spawnfunc___init_dedicated_server(void)
517 // handler for _init/_init map (only for dedicated server initialization)
519 world_initialized = -1; // don't complain
521 cvar_string = cvar_string_normal;
522 cvar_set = cvar_set_normal;
524 remove = remove_unsafely;
528 e.think = GotoFirstMap;
529 e.nextthink = time; // this is usually 1 at this point
532 e.classname = "info_player_deathmatch"; // safeguard against player joining
534 self.classname = "worldspawn"; // safeguard against various stuff ;)
536 // needs to be done so early because of the constants they create
541 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
544 void Map_MarkAsRecent(string m);
545 float world_already_spawned;
546 void RegisterWeapons();
548 void ClientInit_Spawn();
549 void WeaponStats_Init();
550 void WeaponStats_Shutdown();
551 void spawnfunc_worldspawn (void)
553 float fd, l, i, j, n;
557 cvar_string = cvar_string_normal;
558 cvar_set = cvar_set_normal;
560 if(world_already_spawned)
561 error("world already spawned - you may have EXACTLY ONE worldspawn!");
562 world_already_spawned = TRUE;
564 remove = remove_safely; // during spawning, watch what you remove!
566 check_unacceptable_compiler_bugs();
568 cvar_changes_init(); // do this very early now so it REALLY matches the server config
570 compressShortVector_init();
572 allowed_to_spawn = TRUE;
575 head = nextent(world);
580 head = nextent(head);
583 // needs to be done so early because of the constants they create
587 ServerProgsDB = db_load(strcat("server.db", autocvar_sessionid));
589 TemporaryDB = db_create();
594 // 1 FLICKER (first variety)
595 lightstyle(1, "mmnmmommommnonmmonqnmmo");
597 // 2 SLOW STRONG PULSE
598 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
600 // 3 CANDLE (first variety)
601 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
604 lightstyle(4, "mamamamamama");
607 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
609 // 6 FLICKER (second variety)
610 lightstyle(6, "nmonqnmomnmomomno");
612 // 7 CANDLE (second variety)
613 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
615 // 8 CANDLE (third variety)
616 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
618 // 9 SLOW STROBE (fourth variety)
619 lightstyle(9, "aaaaaaaazzzzzzzz");
621 // 10 FLUORESCENT FLICKER
622 lightstyle(10, "mmamammmmammamamaaamammma");
624 // 11 SLOW PULSE NOT FADE TO BLACK
625 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
627 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
632 if(autocvar_g_campaign)
635 Map_MarkAsRecent(mapname);
637 precache_model ("null"); // we need this one before InitGameplayMode
645 bot_waypoints_for_items = autocvar_g_waypoints_for_items;
646 if(bot_waypoints_for_items == 1)
647 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
648 bot_waypoints_for_items = 0;
652 WaypointSprite_Init();
657 GameLogInit(); // prepare everything
659 // changing the logic generating it is okay. But:
660 // it HAS to stay <= 64 chars
661 // character set: ASCII 33-126 without the following characters: : ; ' " \ $
662 if(autocvar_sv_eventlog)
664 s = sprintf("%d.%s.%06d", ftos(autocvar_sv_eventlog_files_counter), strftime(FALSE, "%s"), floor(random() * 1000000));
665 matchid = strzone(s);
667 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
668 s = ":gameinfo:mutators:LIST";
671 MUTATOR_CALLHOOK(BuildMutatorsString);
674 // simple, probably not good in the mutator system
675 if(autocvar_g_grappling_hook)
676 s = strcat(s, ":grappling_hook");
678 // initialiation stuff, not good in the mutator system
679 if(!autocvar_g_use_ammunition)
680 s = strcat(s, ":no_use_ammunition");
682 // initialiation stuff, not good in the mutator system
683 if(autocvar_g_pickup_items == 0)
684 s = strcat(s, ":no_pickup_items");
685 if(autocvar_g_pickup_items > 0)
686 s = strcat(s, ":pickup_items");
688 // initialiation stuff, not good in the mutator system
689 if(autocvar_g_weaponarena != "0")
690 s = strcat(s, ":", autocvar_g_weaponarena, " arena");
692 // TODO to mutator system
693 if(autocvar_g_norecoil)
694 s = strcat(s, ":norecoil");
696 // TODO to mutator system
697 if(autocvar_g_midair)
698 s = strcat(s, ":midair");
700 // TODO to mutator system
701 if(autocvar_g_minstagib)
702 s = strcat(s, ":minstagib");
704 // TODO to mutator system
705 if(autocvar_g_powerups == 0)
706 s = strcat(s, ":no_powerups");
707 if(autocvar_g_powerups > 0)
708 s = strcat(s, ":powerups");
711 GameLogEcho(":gameinfo:end");
714 matchid = strzone(ftos(random()));
716 cvar_set("nextmap", "");
720 if(autocvar_g_campaign)
728 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
730 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
732 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
735 while((s = fgets(fd)))
737 l = tokenize_console(s);
742 print("Found ^1UNSUPPORTED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
743 print(" cdtrack ", argv(2), "\n");
745 else if(argv(0) == "fog")
747 print("Found ^1UNSUPPORTED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
748 print(" \"fog\" \"", s, "\"\n");
750 else if(argv(0) == "set")
752 print("Found ^1UNSUPPORTED^7 set command in .cfg file; put this line in mapinfo instead:\n");
753 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
755 else if(argv(0) != "//")
757 print("Found ^1UNSUPPORTED^7 set command in .cfg file; put this line in mapinfo instead:\n");
758 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
767 addstat(STAT_WEAPONS, AS_INT, weapons);
768 addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
769 addstat(STAT_SWITCHINGWEAPON, AS_INT, switchingweapon);
770 addstat(STAT_GAMESTARTTIME, AS_FLOAT, stat_game_starttime);
771 addstat(STAT_ALLOW_OLDNEXBEAM, AS_INT, stat_allow_oldnexbeam);
774 addstat(STAT_STRENGTH_FINISHED, AS_FLOAT, strength_finished);
775 addstat(STAT_INVINCIBLE_FINISHED, AS_FLOAT, invincible_finished);
776 addstat(STAT_SUPERWEAPONS_FINISHED, AS_FLOAT, superweapons_finished);
777 addstat(STAT_PRESSED_KEYS, AS_FLOAT, pressedkeys);
778 addstat(STAT_FUEL, AS_INT, ammo_fuel);
779 addstat(STAT_SHOTORG, AS_INT, stat_shotorg);
780 addstat(STAT_LEADLIMIT, AS_FLOAT, stat_leadlimit);
781 addstat(STAT_WEAPON_CLIPLOAD, AS_INT, clip_load);
782 addstat(STAT_WEAPON_CLIPSIZE, AS_INT, clip_size);
783 addstat(STAT_LAST_PICKUP, AS_FLOAT, last_pickup);
784 addstat(STAT_HIT_TIME, AS_FLOAT, hit_time);
785 addstat(STAT_TYPEHIT_TIME, AS_FLOAT, typehit_time);
786 addstat(STAT_LAYED_MINES, AS_INT, minelayer_mines);
788 addstat(STAT_NEX_CHARGE, AS_FLOAT, nex_charge);
789 addstat(STAT_NEX_CHARGEPOOL, AS_FLOAT, nex_chargepool_ammo);
791 addstat(STAT_HAGAR_LOAD, AS_INT, hagar_load);
793 if(g_ca || g_freezetag)
795 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
796 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
797 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
798 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
802 addstat(STAT_FROZEN, AS_INT, freezetag_frozen);
803 addstat(STAT_REVIVE_PROGRESS, AS_FLOAT, freezetag_revive_progress);
806 // g_movementspeed hack
807 addstat(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW, AS_FLOAT, stat_sv_airspeedlimit_nonqw);
808 addstat(STAT_MOVEVARS_MAXSPEED, AS_FLOAT, stat_sv_maxspeed);
809 addstat(STAT_MOVEVARS_AIRACCEL_QW, AS_FLOAT, stat_sv_airaccel_qw);
810 addstat(STAT_MOVEVARS_AIRSTRAFEACCEL_QW, AS_FLOAT, stat_sv_airstrafeaccel_qw);
813 addstat(STAT_SECRETS_TOTAL, AS_FLOAT, stat_secrets_total);
814 addstat(STAT_SECRETS_FOUND, AS_FLOAT, stat_secrets_found);
816 next_pingtime = time + 5;
820 // set up information replies for clients and server to use
821 lsmaps_reply = "^7Maps available: ";
822 lsnewmaps_reply = "^7Maps without a record set: ";
823 for(i = 0, j = 0; i < MapInfo_count; ++i)
825 if(MapInfo_Get_ByID(i))
826 if not(MapInfo_Map_flags & (MAPINFO_FLAG_HIDDEN | MAPINFO_FLAG_FORBIDDEN))
835 lsmaps_reply = strcat(lsmaps_reply, col, MapInfo_Map_bspname, " ");
837 if(g_race && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "time"))))
838 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
839 else if(g_cts && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "time"))))
840 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
844 lsmaps_reply = strzone(strcat(lsmaps_reply, "\n"));
845 lsnewmaps_reply = strzone(strcat(((!g_race && !g_cts) ? "Need to be playing race or CTS for lsnewmaps to work." : lsnewmaps_reply), "\n"));
847 maplist_reply = "^7Maps in list: ";
848 n = tokenize_console(autocvar_g_maplist);
849 for(i = 0, j = 0; i < n; ++i)
851 if(MapInfo_CheckMap(argv(i)))
857 maplist_reply = strcat(maplist_reply, col, argv(i), " ");
861 maplist_reply = strzone(strcat(maplist_reply, "\n"));
862 MapInfo_ClearTemps();
864 for(i = 0; i < 10; ++i)
866 records_reply[i] = strzone(getrecords(i));
869 ladder_reply = strzone(getladder());
871 rankings_reply = strzone(getrankings());
876 PingPLReport_Spawn();
880 localcmd("\n_sv_hook_gamestart ", GetGametype(), "\n");
882 // fill sv_curl_serverpackages from .serverpackage files
883 if(autocvar_sv_curl_serverpackages_auto)
886 n = tokenize_console(cvar_string("sv_curl_serverpackages"));
887 for(i = 0; i < n; ++i)
888 if(substring(argv(i), -14, -1) != "-serverpackage.txt")
889 if(substring(argv(i), -14, -1) != ".serverpackage") // OLD legacy
890 s = strcat(s, " ", argv(i));
891 fd = search_begin("*-serverpackage.txt", TRUE, FALSE);
894 j = search_getsize(fd);
895 for(i = 0; i < j; ++i)
896 s = strcat(s, " ", search_getfilename(fd, i));
899 fd = search_begin("*.serverpackage", TRUE, FALSE);
902 j = search_getsize(fd);
903 for(i = 0; i < j; ++i)
904 s = strcat(s, " ", search_getfilename(fd, i));
907 cvar_set("sv_curl_serverpackages", substring(s, 1, -1));
912 // MOD AUTHORS: change this, and possibly remove a few of the blocks below to ignore certain changes
914 // physics/balance/config changes that count as mod
915 if(cvar_string("g_mod_physics") != cvar_defstring("g_mod_physics"))
916 modname = cvar_string("g_mod_physics");
917 if(cvar_string("g_mod_balance") != cvar_defstring("g_mod_balance"))
918 modname = cvar_string("g_mod_balance");
919 if(cvar_string("g_mod_config") != cvar_defstring("g_mod_config"))
920 modname = cvar_string("g_mod_config");
921 // weird mutators that deserve to count as mod
922 if(autocvar_g_minstagib)
923 modname = "MinstaGib";
924 // extra mutators that deserve to count as mod
925 MUTATOR_CALLHOOK(SetModname);
926 // weird game types that deserve to count as mod
930 modname = strzone(modname);
932 WinningConditionHelper(); // set worldstatus
934 world_initialized = 1;
937 void spawnfunc_light (void)
939 //makestatic (self); // Who the f___ did that?
945 return MapInfo_Type_ToString(MapInfo_LoadedGametype);
948 string getmapname_stored;
954 float Map_Count, Map_Current;
955 string Map_Current_Name;
957 // NOTE: this now expects the map list to be already tokenized and the count in Map_Count
958 float GetMaplistPosition()
964 idx = autocvar_g_maplist_index;
971 for(pos = 0; pos < Map_Count; ++pos)
975 // resume normal maplist rotation if current map is not in g_maplist
979 float MapHasRightSize(string map)
982 if(currentbots || autocvar_bot_number || player_count < autocvar_minplayers)
983 if(autocvar_g_maplist_check_waypoints)
985 dprint("checkwp "); dprint(map);
986 if(!fexists(strcat("maps/", map, ".waypoints")))
988 dprint(": no waypoints\n");
991 dprint(": has waypoints\n");
994 // open map size restriction file
995 dprint("opensize "); dprint(map);
996 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
999 float mapmin, mapmax;
1001 mapmin = stof(fgets(fh));
1002 mapmax = stof(fgets(fh));
1004 if(player_count < mapmin)
1006 dprint("not enough\n");
1009 if(player_count > mapmax)
1011 dprint("too many\n");
1014 dprint("right size\n");
1017 dprint(": not found\n");
1021 string Map_Filename(float position)
1023 return strcat("maps/", argv(position), ".bsp");
1026 string strwords(string s, float w)
1029 for(endpos = 0; w && endpos >= 0; --w)
1030 endpos = strstrofs(s, " ", endpos + 1);
1034 return substring(s, 0, endpos);
1037 float strhasword(string s, string w)
1039 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
1042 void Map_MarkAsRecent(string m)
1044 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", autocvar_g_maplist_mostrecent), max(0, autocvar_g_maplist_mostrecent_count)));
1047 float Map_IsRecent(string m)
1049 return strhasword(autocvar_g_maplist_mostrecent, m);
1052 float Map_Check(float position, float pass)
1056 map_next = argv(position);
1059 if(Map_IsRecent(map_next))
1062 filename = Map_Filename(position);
1063 if(MapInfo_CheckMap(map_next))
1067 if(MapHasRightSize(map_next))
1072 dprint( "Couldn't select '", filename, "'..\n" );
1077 void Map_Goto_SetStr(string nextmapname)
1079 if(getmapname_stored != "")
1080 strunzone(getmapname_stored);
1081 if(nextmapname == "")
1082 getmapname_stored = "";
1084 getmapname_stored = strzone(nextmapname);
1087 void Map_Goto_SetFloat(float position)
1089 cvar_set("g_maplist_index", ftos(position));
1090 Map_Goto_SetStr(argv(position));
1093 void Map_Goto(float reinit)
1095 MapInfo_LoadMap(getmapname_stored, reinit);
1098 // return codes of map selectors:
1099 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
1100 // -2 = permanent failure
1101 float() MaplistMethod_Iterate = // usual method
1105 for(pass = 1; pass <= 2; ++pass)
1107 for(i = 1; i < Map_Count; ++i)
1110 mapindex = mod(i + Map_Current, Map_Count);
1111 if(Map_Check(mapindex, pass))
1118 float() MaplistMethod_Repeat = // fallback method
1120 if(Map_Check(Map_Current, 2))
1125 float() MaplistMethod_Random = // random map selection
1131 for(i = 0; i <= imax; ++i)
1134 mapindex = mod(Map_Current + floor(random() * (Map_Count - 1) + 1), Map_Count); // any OTHER map
1135 if(Map_Check(mapindex, 1))
1141 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
1142 // the exponent sets a bias on the map selection:
1143 // the higher the exponent, the less likely "shortly repeated" same maps are
1145 float i, j, imax, insertpos;
1149 for(i = 0; i <= imax; ++i)
1153 // now reinsert this at another position
1154 insertpos = pow(random(), 1 / exponent); // ]0, 1]
1155 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
1156 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
1157 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
1159 // insert the current map there
1161 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
1162 newlist = strcat(newlist, " ", argv(j));
1163 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
1164 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
1165 newlist = strcat(newlist, " ", argv(j));
1166 newlist = substring(newlist, 1, strlen(newlist) - 1);
1167 cvar_set("g_maplist", newlist);
1168 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1170 // NOTE: the selected map has just been inserted at (insertpos-1)th position
1171 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
1172 if(Map_Check(Map_Current, 1))
1180 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1183 bprint( "Maplist is empty! Resetting it to default map list.\n" );
1184 cvar_set("g_maplist", MapInfo_ListAllAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
1185 if(autocvar_g_maplist_shuffle)
1187 localcmd("\nmenu_cmd sync\n");
1188 Map_Count = tokenizebyseparator(autocvar_g_maplist, " ");
1191 error("empty maplist, cannot select a new map");
1192 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
1194 if(Map_Current_Name)
1195 strunzone(Map_Current_Name);
1196 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
1197 // this may or may not be correct, but who cares, in the worst case a map
1198 // isn't chosen in the first pass that should have been
1209 if(autocvar_g_maplist_shuffle > 0)
1210 nextMap = MaplistMethod_Shuffle(autocvar_g_maplist_shuffle + 1);
1213 if(autocvar_g_maplist_selectrandom)
1214 nextMap = MaplistMethod_Random();
1217 nextMap = MaplistMethod_Iterate();
1220 nextMap = MaplistMethod_Repeat();
1224 Map_Goto_SetFloat(nextMap);
1225 return getmapname_stored;
1231 float DoNextMapOverride(float reinit)
1233 if(autocvar_g_campaign)
1235 CampaignPostIntermission();
1236 alreadychangedlevel = TRUE;
1239 if(autocvar_quit_when_empty)
1241 if(player_count <= currentbots)
1244 alreadychangedlevel = TRUE;
1248 if(autocvar_quit_and_redirect != "")
1250 redirection_target = strzone(autocvar_quit_and_redirect);
1251 alreadychangedlevel = TRUE;
1254 if (!reinit && autocvar_samelevel) // if samelevel is set, stay on same level
1256 localcmd("restart\n");
1257 alreadychangedlevel = TRUE;
1260 if(autocvar_nextmap != "")
1261 if(MapInfo_CheckMap(autocvar_nextmap))
1263 Map_Goto_SetStr(autocvar_nextmap);
1265 alreadychangedlevel = TRUE;
1268 if(!reinit && autocvar_lastlevel)
1270 cvar_settemp_restore();
1271 localcmd("set lastlevel 0\ntogglemenu 1\n");
1272 alreadychangedlevel = TRUE;
1278 void GotoNextMap(float reinit)
1283 if (alreadychangedlevel)
1285 alreadychangedlevel = TRUE;
1291 for(allowReset = 1; allowReset >= 0; --allowReset)
1293 nextMap = GetNextMap();
1299 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1300 cvar_set("g_maplist", MapInfo_ListAllAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
1301 if(autocvar_g_maplist_shuffle)
1303 localcmd("\nmenu_cmd sync\n");
1307 error("Everything is broken - not even the default map list works. Please report this to the developers.");
1319 When the player presses attack or jump, change to the next level
1322 .float autoscreenshot;
1323 void() MapVote_Start;
1324 void() MapVote_Think;
1325 float mapvote_initialized;
1326 void IntermissionThink()
1328 FixIntermissionClient(self);
1330 float server_screenshot = (autocvar_sv_autoscreenshot && self.cvar_cl_autoscreenshot);
1331 float client_screenshot = (self.cvar_cl_autoscreenshot == 2);
1333 if( (server_screenshot || client_screenshot)
1334 && ((self.autoscreenshot > 0) && (time > self.autoscreenshot)) )
1336 self.autoscreenshot = -1;
1337 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"))); }
1341 if (time < intermission_exittime)
1344 if(!mapvote_initialized)
1345 if (time < intermission_exittime + 10 && !(self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE))
1355 Returns the entity to view from
1359 entity FindIntermission()
1364 // look for info_intermission first
1365 spot = find (world, classname, "info_intermission");
1367 { // pick a random one
1371 spot = find (spot, classname, "info_intermission");
1373 spot = find (spot, classname, "info_intermission");
1379 // then look for the start position
1380 spot = find (world, classname, "info_player_start");
1384 // testinfo_player_start is only found in regioned levels
1385 spot = find (world, classname, "testplayerstart");
1389 // then look for the start position
1390 spot = find (world, classname, "info_player_deathmatch");
1394 //objerror ("FindIntermission: no spot");
1400 ===============================================================================
1404 ===============================================================================
1407 void DumpStats(float final)
1416 to_console = autocvar_sv_logscores_console;
1417 to_eventlog = autocvar_sv_eventlog;
1418 to_file = autocvar_sv_logscores_file;
1422 to_console = TRUE; // always print printstats replies
1423 to_eventlog = FALSE; // but never print them to the event log
1427 if(autocvar_sv_eventlog_console)
1428 to_console = FALSE; // otherwise we get the output twice
1434 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
1442 file = fopen(autocvar_sv_logscores_filename, FILE_APPEND);
1446 fputs(file, strcat(s, "\n"));
1449 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
1455 fputs(file, strcat(s, "\n"));
1457 FOR_EACH_CLIENT(other)
1459 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && autocvar_sv_logscores_bots))
1461 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
1462 s = strcat(s, ftos(rint(time - other.jointime)), ":");
1463 if(other.classname == "player" || g_arena || g_ca || g_lms)
1464 s = strcat(s, ftos(other.team), ":");
1466 s = strcat(s, "spectator:");
1469 print(s, other.netname, "\n");
1471 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
1473 fputs(file, strcat(s, other.netname, "\n"));
1479 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
1485 fputs(file, strcat(s, "\n"));
1487 for(i = 1; i < 16; ++i)
1489 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
1490 s = strcat(s, ":", ftos(i));
1496 fputs(file, strcat(s, "\n"));
1503 GameLogEcho(":end");
1506 fputs(file, ":end\n");
1511 void FixIntermissionClient(entity e)
1514 if(!e.autoscreenshot) // initial call
1516 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1518 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1519 e.solid = SOLID_NOT;
1520 e.movetype = MOVETYPE_NONE;
1521 e.takedamage = DAMAGE_NO;
1524 e.weaponentity.effects = EF_NODRAW;
1525 if (e.weaponentity.weaponentity)
1526 e.weaponentity.weaponentity.effects = EF_NODRAW;
1528 if(clienttype(e) == CLIENTTYPE_REAL)
1530 stuffcmd(e, "\nscr_printspeed 1000000\n");
1531 s = autocvar_sv_intermission_cdtrack;
1533 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1535 WriteByte(MSG_ONE, SVC_INTERMISSION);
1540 void minstagib_stop_countdown(entity e);
1542 go to the next level for deathmatch
1543 only called if a time or frag limit has expired
1549 intermission_running = 1;
1551 // enforce a wait time before allowing changelevel
1552 if(player_count > 0)
1553 intermission_exittime = time + autocvar_sv_mapchange_delay;
1555 intermission_exittime = -1;
1558 WriteByte (MSG_ALL, SVC_CDTRACK);
1559 WriteByte (MSG_ALL, 3);
1560 WriteByte (MSG_ALL, 3);
1561 // done in FixIntermission
1564 //pos = FindIntermission ();
1572 PlayerStats_EndMatch(1);
1574 PlayerStats_AddGlobalInfo(e);
1575 PlayerStats_Shutdown();
1576 WeaponStats_Shutdown();
1578 if(autocvar_sv_eventlog)
1579 GameLogEcho(":gameover");
1583 FOR_EACH_PLAYER(other) {
1584 minstagib_stop_countdown(other);
1585 FixIntermissionClient(other);
1587 bprint(other.netname, " ^7wins.\n");
1590 if(autocvar_g_campaign)
1591 CampaignPreIntermission();
1593 localcmd("\nsv_hook_gameend\n");
1600 Exit deathmatch games upon conditions
1603 void CheckRules_Player()
1605 if (gameover) // someone else quit the game already
1608 if(self.deadflag == DEAD_NO)
1609 self.play_time += frametime;
1611 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1612 // (div0: and that in CheckRules_World please)
1615 float checkrules_equality;
1616 float checkrules_suddendeathwarning;
1617 float checkrules_suddendeathend;
1618 float checkrules_overtimesadded; //how many overtimes have been already added
1620 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1621 float WINNING_YES = 1; // winner found
1622 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1623 float WINNING_STARTSUDDENDEATHOVERTIME = 3; // no winner, enter suddendeath overtime NOW
1625 float InitiateSuddenDeath()
1627 // Check first whether normal overtimes could be added before initiating suddendeath mode
1628 // - for this timelimit_overtime needs to be >0 of course
1629 // - also check the winning condition calculated in the previous frame and only add normal overtime
1630 // again, if at the point at which timelimit would be extended again, still no winner was found
1631 if (!autocvar_g_campaign && (checkrules_overtimesadded >= 0) && (checkrules_overtimesadded < autocvar_timelimit_overtimes) && autocvar_timelimit_overtime && !(g_race && !g_race_qualifying))
1633 return 1; // need to call InitiateOvertime later
1637 if(!checkrules_suddendeathend)
1639 if(autocvar_g_campaign)
1640 checkrules_suddendeathend = time; // no suddendeath in campaign
1642 checkrules_suddendeathend = time + 60 * autocvar_timelimit_suddendeath;
1643 if(g_race && !g_race_qualifying)
1644 race_StartCompleting();
1650 void InitiateOvertime() // ONLY call this if InitiateSuddenDeath returned true
1652 ++checkrules_overtimesadded;
1653 //add one more overtime by simply extending the timelimit
1655 tl = autocvar_timelimit;
1656 tl += autocvar_timelimit_overtime;
1657 cvar_set("timelimit", ftos(tl));
1658 string minutesPlural;
1659 if (autocvar_timelimit_overtime == 1)
1660 minutesPlural = " ^3minute";
1662 minutesPlural = " ^3minutes";
1666 "^3Now playing ^1OVERTIME^3!\n\n^3Added ^1",
1667 ftos(autocvar_timelimit_overtime),
1674 float GetWinningCode(float fraglimitreached, float equality)
1676 if(autocvar_g_campaign == 1)
1677 if(fraglimitreached)
1684 if(fraglimitreached)
1685 return WINNING_STARTSUDDENDEATHOVERTIME;
1687 return WINNING_NEVER;
1689 if(fraglimitreached)
1695 // set the .winning flag for exactly those players with a given field value
1696 void SetWinners(.float field, float value)
1699 FOR_EACH_PLAYER(head)
1700 head.winning = (head.field == value);
1703 // set the .winning flag for those players with a given field value
1704 void AddWinners(.float field, float value)
1707 FOR_EACH_PLAYER(head)
1708 if(head.field == value)
1712 // clear the .winning flags
1713 void ClearWinners(void)
1716 FOR_EACH_PLAYER(head)
1720 // Onslaught winning condition:
1721 // game terminates if only one team has a working generator (or none)
1722 float WinningCondition_Onslaught()
1725 float t1, t2, t3, t4;
1727 WinningConditionHelper(); // set worldstatus
1732 // first check if the game has ended
1733 t1 = t2 = t3 = t4 = 0;
1734 head = find(world, classname, "onslaught_generator");
1737 if (head.health > 0)
1739 if (head.team == COLOR_TEAM1) t1 = 1;
1740 if (head.team == COLOR_TEAM2) t2 = 1;
1741 if (head.team == COLOR_TEAM3) t3 = 1;
1742 if (head.team == COLOR_TEAM4) t4 = 1;
1744 head = find(head, classname, "onslaught_generator");
1746 if (t1 + t2 + t3 + t4 < 2)
1748 // game over, only one team remains (or none)
1750 if (t1) SetWinners(team, COLOR_TEAM1);
1751 if (t2) SetWinners(team, COLOR_TEAM2);
1752 if (t3) SetWinners(team, COLOR_TEAM3);
1753 if (t4) SetWinners(team, COLOR_TEAM4);
1754 dprint("Have a winner, ending game.\n");
1758 // Two or more teams remain
1762 float LMS_NewPlayerLives()
1765 fl = autocvar_fraglimit;
1769 // first player has left the game for dying too much? Nobody else can get in.
1770 if(lms_lowest_lives < 1)
1773 if(!autocvar_g_lms_join_anytime)
1774 if(lms_lowest_lives < fl - autocvar_g_lms_last_join)
1777 return bound(1, lms_lowest_lives, fl);
1780 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1781 // they win. Otherwise the defending team wins once the timelimit passes.
1782 void assault_new_round();
1783 float WinningCondition_Assault()
1787 WinningConditionHelper(); // set worldstatus
1789 status = WINNING_NO;
1790 // as the timelimit has not yet passed just assume the defending team will win
1791 if(assault_attacker_team == COLOR_TEAM1)
1793 SetWinners(team, COLOR_TEAM2);
1797 SetWinners(team, COLOR_TEAM1);
1801 ent = find(world, classname, "target_assault_roundend");
1804 if(ent.winning) // round end has been triggered by attacking team
1806 bprint("ASSAULT: round completed...\n");
1807 SetWinners(team, assault_attacker_team);
1809 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
1811 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
1813 status = WINNING_YES;
1820 assault_new_round();
1829 // LMS winning condition: game terminates if and only if there's at most one
1830 // one player who's living lives. Top two scores being equal cancels the time
1832 float WinningCondition_LMS()
1839 have_player = FALSE;
1840 have_players = FALSE;
1841 l = LMS_NewPlayerLives();
1843 head = find(world, classname, "player");
1846 head2 = find(head, classname, "player");
1848 have_players = TRUE;
1852 // we have at least one player
1855 // two or more active players - continue with the game
1859 // exactly one player?
1862 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1866 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1872 // and assign him his first place
1873 PlayerScore_Add(head, SP_LMS_RANK, 1);
1880 // nobody is playing at all...
1883 // wait for players...
1887 // SNAFU (maybe a draw game?)
1889 dprint("No players, ending game.\n");
1894 // When we get here, we have at least two players who are actually LIVING,
1895 // now check if the top two players have equal score.
1896 WinningConditionHelper();
1899 if(WinningConditionHelper_winner)
1900 WinningConditionHelper_winner.winning = TRUE;
1901 if(WinningConditionHelper_topscore == WinningConditionHelper_secondscore)
1902 return WINNING_NEVER;
1904 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1908 void ShuffleMaplist()
1910 cvar_set("g_maplist", shufflewords(autocvar_g_maplist));
1914 float WinningCondition_Scores(float limit, float leadlimit)
1918 // TODO make everything use THIS winning condition (except LMS)
1919 WinningConditionHelper();
1923 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1924 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1925 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1926 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1930 if(WinningConditionHelper_winner)
1931 WinningConditionHelper_winner.winning = 1;
1932 if(WinningConditionHelper_winnerteam >= 0)
1933 SetWinners(team, WinningConditionHelper_winnerteam);
1935 if(WinningConditionHelper_lowerisbetter)
1937 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1938 WinningConditionHelper_secondscore = -WinningConditionHelper_secondscore;
1942 if(WinningConditionHelper_zeroisworst)
1943 leadlimit = 0; // not supported in this mode
1945 if(g_dm || g_tdm || g_arena || g_ca || (g_race && !g_race_qualifying) || g_nexball)
1946 // these modes always score in increments of 1, thus this makes sense
1948 if(leaderfrags != WinningConditionHelper_topscore)
1950 leaderfrags = WinningConditionHelper_topscore;
1953 if (leaderfrags == limit - 1)
1954 Announce("1fragleft");
1955 else if (leaderfrags == limit - 2)
1956 Announce("2fragsleft");
1957 else if (leaderfrags == limit - 3)
1958 Announce("3fragsleft");
1962 limitreached = FALSE;
1964 if(WinningConditionHelper_topscore >= limit)
1965 limitreached = TRUE;
1968 float leadlimitreached;
1969 leadlimitreached = (WinningConditionHelper_topscore - WinningConditionHelper_secondscore >= leadlimit);
1970 if(autocvar_leadlimit_and_fraglimit)
1971 limitreached = (limitreached && leadlimitreached);
1973 limitreached = (limitreached || leadlimitreached);
1976 return GetWinningCode(
1977 WinningConditionHelper_topscore && limitreached,
1978 WinningConditionHelper_equality
1982 float WinningCondition_Race(float fraglimit)
1993 if(p.race_completed)
1998 wc = WinningCondition_Scores(fraglimit, 0);
2000 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
2001 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
2002 // do NOT support equality when the laps are all raced!
2003 return WINNING_STARTSUDDENDEATHOVERTIME;
2005 return WINNING_NEVER;
2009 float WinningCondition_QualifyingThenRace(float limit)
2012 wc = WinningCondition_Scores(limit, 0);
2014 // NEVER initiate overtime
2015 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
2023 float WinningCondition_RanOutOfSpawns()
2027 if(have_team_spawns <= 0)
2030 if(autocvar_g_spawn_useallspawns <= 0)
2033 if(!some_spawn_has_been_used)
2036 team1_score = team2_score = team3_score = team4_score = 0;
2038 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
2040 if(head.team == COLOR_TEAM1)
2042 else if(head.team == COLOR_TEAM2)
2044 else if(head.team == COLOR_TEAM3)
2046 else if(head.team == COLOR_TEAM4)
2050 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
2052 if(head.team == COLOR_TEAM1)
2054 else if(head.team == COLOR_TEAM2)
2056 else if(head.team == COLOR_TEAM3)
2058 else if(head.team == COLOR_TEAM4)
2063 if(team1_score + team2_score + team3_score + team4_score == 0)
2065 checkrules_equality = TRUE;
2068 else if(team1_score + team2_score + team3_score + team4_score == 1)
2071 if(team1_score) t = COLOR_TEAM1;
2072 if(team2_score) t = COLOR_TEAM2;
2073 if(team3_score) t = COLOR_TEAM3;
2074 if(team4_score) t = COLOR_TEAM4;
2075 CheckAllowedTeams(world);
2076 for(i = 0; i < MAX_TEAMSCORE; ++i)
2078 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
2079 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
2080 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
2081 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
2084 AddWinners(team, t);
2095 Exit deathmatch games upon conditions
2098 void ReadyRestart();
2099 void CheckRules_World()
2111 MapVote_Think should now do that part
2112 if (intermission_running)
2113 if (time >= intermission_exittime + 60)
2115 if(!DoNextMapOverride())
2121 if (gameover) // someone else quit the game already
2123 if(player_count == 0) // Nobody there? Then let's go to the next map
2125 // this will actually check the player count in the next frame
2126 // again, but this shouldn't hurt
2130 timelimit = autocvar_timelimit * 60;
2131 fraglimit = autocvar_fraglimit;
2132 leadlimit = autocvar_leadlimit;
2134 if(inWarmupStage || time <= game_starttime) // NOTE: this is <= to prevent problems in the very tic where the game starts
2137 timelimit = 0; // timelimit is not made for warmup
2139 fraglimit = 0; // no fraglimit for now
2140 leadlimit = 0; // no leadlimit for now
2144 timelimit = 0; // ONS has its own overtime rule
2148 timelimit += game_starttime;
2150 else if (timelimit < 0)
2160 if(checkrules_suddendeathend)
2162 if(!checkrules_suddendeathwarning)
2164 checkrules_suddendeathwarning = TRUE;
2165 if(g_race && !g_race_qualifying)
2166 bcenterprint("^3Everyone, finish your lap! The race is over!");
2168 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
2173 if (timelimit && time >= timelimit)
2175 if(g_race && (g_race_qualifying == 2) && timelimit > 0)
2178 float playerswithlaps;
2181 totalplayers = playerswithlaps = readyplayers = 0;
2182 FOR_EACH_PLAYER(head)
2185 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
2191 // at least 2 of the players have completed a lap: start the RACE
2192 // otherwise, the players should end the qualifying on their own
2193 if(readyplayers || playerswithlaps >= 2)
2195 checkrules_suddendeathend = 0;
2196 ReadyRestart(); // go to race
2200 wantovertime |= InitiateSuddenDeath();
2203 wantovertime |= InitiateSuddenDeath();
2207 if (checkrules_suddendeathend && time >= checkrules_suddendeathend)
2213 float checkrules_status;
2214 checkrules_status = WinningCondition_RanOutOfSpawns();
2215 if(checkrules_status == WINNING_YES)
2217 bprint("Hey! Someone ran out of spawns!\n");
2219 else if(g_race && !g_race_qualifying && timelimit >= 0)
2221 checkrules_status = WinningCondition_Race(fraglimit);
2222 //print("WC_RACE yields ", ftos(checkrules_status), "\n");
2224 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
2226 checkrules_status = WinningCondition_QualifyingThenRace(fraglimit);
2227 //print("WC_QUALIFYING_THEN_RACE yields ", ftos(checkrules_status), "\n");
2231 checkrules_status = WinningCondition_Assault(); // TODO remove this?
2235 checkrules_status = WinningCondition_LMS();
2237 else if (g_onslaught)
2239 checkrules_status = WinningCondition_Onslaught(); // TODO remove this?
2243 checkrules_status = WinningCondition_Scores(fraglimit, leadlimit);
2244 //print("WC_SCORES yields ", ftos(checkrules_status), "\n");
2247 if(checkrules_status == WINNING_STARTSUDDENDEATHOVERTIME)
2249 checkrules_status = WINNING_NEVER;
2250 checkrules_overtimesadded = -1;
2251 wantovertime |= InitiateSuddenDeath();
2254 if(checkrules_status == WINNING_NEVER)
2255 // equality cases! Nobody wins if the overtime ends in a draw.
2260 if(checkrules_status == WINNING_NEVER)
2263 checkrules_status = WINNING_YES;
2266 if(checkrules_suddendeathend)
2267 if(checkrules_status != WINNING_NEVER || time >= checkrules_suddendeathend)
2268 checkrules_status = WINNING_YES;
2270 if(checkrules_status == WINNING_YES)
2272 //print("WINNING\n");
2277 float mapvote_nextthink;
2278 float mapvote_initialized;
2279 float mapvote_keeptwotime;
2280 float mapvote_timeout;
2281 string mapvote_message;
2282 #define MAPVOTE_SCREENSHOT_DIRS_COUNT 4
2283 string mapvote_screenshot_dirs[MAPVOTE_SCREENSHOT_DIRS_COUNT];
2284 float mapvote_screenshot_dirs_count;
2286 float mapvote_count;
2287 float mapvote_count_real;
2288 string mapvote_maps[MAPVOTE_COUNT];
2289 float mapvote_maps_screenshot_dir[MAPVOTE_COUNT];
2290 string mapvote_maps_pakfile[MAPVOTE_COUNT];
2291 float mapvote_maps_suggested[MAPVOTE_COUNT];
2292 string mapvote_suggestions[MAPVOTE_COUNT];
2293 float mapvote_suggestion_ptr;
2294 float mapvote_voters;
2295 float mapvote_selections[MAPVOTE_COUNT];
2297 float mapvote_detail;
2298 float mapvote_abstain;
2301 void MapVote_ClearAllVotes()
2303 FOR_EACH_CLIENT(other)
2307 string MapVote_Suggest(string m)
2311 return "That's not how to use this command.";
2312 if(!autocvar_g_maplist_votable_suggestions)
2313 return "Suggestions are not accepted on this server.";
2314 if(mapvote_initialized)
2315 return "Can't suggest - voting is already in progress!";
2316 m = MapInfo_FixName(m);
2318 return "The map you suggested is not available on this server.";
2319 if(!autocvar_g_maplist_votable_suggestions_override_mostrecent)
2321 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
2323 if(!MapInfo_CheckMap(m))
2324 return "The map you suggested does not support the current game mode.";
2325 for(i = 0; i < mapvote_suggestion_ptr; ++i)
2326 if(mapvote_suggestions[i] == m)
2327 return "This map was already suggested.";
2328 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
2330 i = floor(random() * mapvote_suggestion_ptr);
2334 i = mapvote_suggestion_ptr;
2335 mapvote_suggestion_ptr += 1;
2337 if(mapvote_suggestions[i] != "")
2338 strunzone(mapvote_suggestions[i]);
2339 mapvote_suggestions[i] = strzone(m);
2340 if(autocvar_sv_eventlog)
2341 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
2342 return strcat("Suggestion of ", m, " accepted.");
2345 void MapVote_AddVotable(string nextMap, float isSuggestion)
2348 string pakfile, mapfile;
2352 for(j = 0; j < mapvote_count; ++j)
2353 if(mapvote_maps[j] == nextMap)
2355 // suggestions might be no longer valid/allowed after gametype switch!
2357 if(!MapInfo_CheckMap(nextMap))
2359 mapvote_maps[mapvote_count] = strzone(nextMap);
2360 mapvote_maps_suggested[mapvote_count] = isSuggestion;
2362 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2364 mapfile = strcat(mapvote_screenshot_dirs[i], "/", mapvote_maps[i]);
2365 pakfile = whichpack(strcat(mapfile, ".tga"));
2367 pakfile = whichpack(strcat(mapfile, ".jpg"));
2369 pakfile = whichpack(strcat(mapfile, ".png"));
2373 if(i >= mapvote_screenshot_dirs_count)
2374 i = 0; // FIXME maybe network this error case, as that means there is no mapshot on the server?
2375 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
2376 pakfile = substring(pakfile, o, -1);
2378 mapvote_maps_screenshot_dir[mapvote_count] = i;
2379 mapvote_maps_pakfile[mapvote_count] = strzone(pakfile);
2384 void MapVote_Spawn();
2390 MapVote_ClearAllVotes();
2393 mapvote_detail = !autocvar_g_maplist_votable_nodetail;
2394 mapvote_abstain = autocvar_g_maplist_votable_abstain;
2397 nmax = min(MAPVOTE_COUNT - 1, autocvar_g_maplist_votable);
2399 nmax = min(MAPVOTE_COUNT, autocvar_g_maplist_votable);
2400 smax = min3(nmax, autocvar_g_maplist_votable_suggestions, mapvote_suggestion_ptr);
2402 // we need this for AddVotable, as that cycles through the screenshot dirs
2403 mapvote_screenshot_dirs_count = tokenize_console(autocvar_g_maplist_votable_screenshot_dir);
2404 if(mapvote_screenshot_dirs_count == 0)
2405 mapvote_screenshot_dirs_count = tokenize_console("maps levelshots");
2406 mapvote_screenshot_dirs_count = min(mapvote_screenshot_dirs_count, MAPVOTE_SCREENSHOT_DIRS_COUNT);
2407 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2408 mapvote_screenshot_dirs[i] = strzone(argv(i));
2410 if(mapvote_suggestion_ptr)
2411 for(i = 0; i < 100 && mapvote_count < smax; ++i)
2412 MapVote_AddVotable(mapvote_suggestions[floor(random() * mapvote_suggestion_ptr)], TRUE);
2414 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2415 MapVote_AddVotable(GetNextMap(), FALSE);
2417 if(mapvote_count == 0)
2419 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
2420 cvar_set("g_maplist", MapInfo_ListAllAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
2421 if(autocvar_g_maplist_shuffle)
2423 localcmd("\nmenu_cmd sync\n");
2424 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
2425 MapVote_AddVotable(GetNextMap(), FALSE);
2428 mapvote_count_real = mapvote_count;
2430 MapVote_AddVotable("don't care", 0);
2432 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
2434 mapvote_keeptwotime = time + autocvar_g_maplist_votable_keeptwotime;
2435 mapvote_timeout = time + autocvar_g_maplist_votable_timeout;
2436 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
2437 mapvote_keeptwotime = 0;
2438 mapvote_message = "Choose a map and press its key!";
2443 void MapVote_SendPicture(float id)
2446 WriteByte(MSG_ONE, SVC_TEMPENTITY);
2447 WriteByte(MSG_ONE, TE_CSQC_PICTURE);
2448 WriteByte(MSG_ONE, id);
2449 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dirs[mapvote_maps_screenshot_dir[id]], "/", mapvote_maps[id]), 3072);
2452 float MapVote_GetMapMask()
2454 float mask, i, power;
2456 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
2457 if(mapvote_maps[i] != "")
2463 float MapVote_SendEntity(entity to, float sf)
2468 sf &~= 2; // if we send 1, we don't need to also send 2
2470 WriteByte(MSG_ENTITY, ENT_CLIENT_MAPVOTE);
2471 WriteByte(MSG_ENTITY, sf);
2475 // flag 1 == initialization
2476 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
2477 WriteString(MSG_ENTITY, mapvote_screenshot_dirs[i]);
2478 WriteString(MSG_ENTITY, "");
2479 WriteByte(MSG_ENTITY, mapvote_count);
2480 WriteByte(MSG_ENTITY, mapvote_abstain);
2481 WriteByte(MSG_ENTITY, mapvote_detail);
2482 WriteCoord(MSG_ENTITY, mapvote_timeout);
2483 if(mapvote_count <= 8)
2484 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2486 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2487 for(i = 0; i < mapvote_count; ++i)
2488 if(mapvote_maps[i] != "")
2490 if(mapvote_abstain && i == mapvote_count - 1)
2492 WriteString(MSG_ENTITY, ""); // abstain needs no text
2493 WriteString(MSG_ENTITY, ""); // abstain needs no pack
2494 WriteByte(MSG_ENTITY, 0); // abstain needs no screenshot dir
2498 WriteString(MSG_ENTITY, mapvote_maps[i]);
2499 WriteString(MSG_ENTITY, mapvote_maps_pakfile[i]);
2500 WriteByte(MSG_ENTITY, mapvote_maps_screenshot_dir[i]);
2507 // flag 2 == update of mask
2508 if(mapvote_count <= 8)
2509 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
2511 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
2517 for(i = 0; i < mapvote_count; ++i)
2518 if(mapvote_maps[i] != "")
2519 WriteByte(MSG_ENTITY, mapvote_selections[i]);
2521 WriteByte(MSG_ENTITY, to.mapvote);
2527 void MapVote_Spawn()
2529 Net_LinkEntity(mapvote_ent = spawn(), FALSE, 0, MapVote_SendEntity);
2532 void MapVote_TouchMask()
2534 mapvote_ent.SendFlags |= 2;
2537 void MapVote_TouchVotes(entity voter)
2539 mapvote_ent.SendFlags |= 4;
2542 float MapVote_Finished(float mappos)
2548 if(autocvar_sv_eventlog)
2550 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2551 result = strcat(result, ":", ftos(mapvote_selections[mappos]), "::");
2552 didntvote = mapvote_voters;
2553 for(i = 0; i < mapvote_count; ++i)
2554 if(mapvote_maps[i] != "")
2556 didntvote -= mapvote_selections[i];
2559 result = strcat(result, ":", mapvote_maps[i]);
2560 result = strcat(result, ":", ftos(mapvote_selections[i]));
2563 result = strcat(result, ":didn't vote:", ftos(didntvote));
2565 GameLogEcho(result);
2566 if(mapvote_maps_suggested[mappos])
2567 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
2570 FOR_EACH_REALCLIENT(other)
2571 FixClientCvars(other);
2573 Map_Goto_SetStr(mapvote_maps[mappos]);
2575 alreadychangedlevel = TRUE;
2578 void MapVote_CheckRules_1()
2582 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2584 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2585 mapvote_selections[i] = 0;
2589 FOR_EACH_REALCLIENT(other)
2594 i = other.mapvote - 1;
2595 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2596 mapvote_selections[i] = mapvote_selections[i] + 1;
2601 float MapVote_CheckRules_2()
2604 float firstPlace, secondPlace;
2605 float firstPlaceVotes, secondPlaceVotes;
2606 float mapvote_voters_real;
2609 if(mapvote_count_real == 1)
2610 return MapVote_Finished(0);
2612 mapvote_voters_real = mapvote_voters;
2614 mapvote_voters_real -= mapvote_selections[mapvote_count - 1];
2616 RandomSelection_Init();
2617 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2618 RandomSelection_Add(world, i, string_null, 1, mapvote_selections[i]);
2619 firstPlace = RandomSelection_chosen_float;
2620 firstPlaceVotes = RandomSelection_best_priority;
2621 //dprint("First place: ", ftos(firstPlace), "\n");
2622 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2624 RandomSelection_Init();
2625 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2627 RandomSelection_Add(world, i, string_null, 1, mapvote_selections[i]);
2628 secondPlace = RandomSelection_chosen_float;
2629 secondPlaceVotes = RandomSelection_best_priority;
2630 //dprint("Second place: ", ftos(secondPlace), "\n");
2631 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2633 if(firstPlace == -1)
2634 error("No first place in map vote... WTF?");
2636 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2637 return MapVote_Finished(firstPlace);
2639 if(mapvote_keeptwotime)
2640 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2643 MapVote_TouchMask();
2644 mapvote_message = "Now decide between the TOP TWO!";
2645 mapvote_keeptwotime = 0;
2646 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2647 result = strcat(result, ":", ftos(firstPlaceVotes));
2648 result = strcat(result, ":", mapvote_maps[secondPlace]);
2649 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2650 didntvote = mapvote_voters;
2651 for(i = 0; i < mapvote_count; ++i)
2652 if(mapvote_maps[i] != "")
2654 didntvote -= mapvote_selections[i];
2656 if(i != secondPlace)
2658 result = strcat(result, ":", mapvote_maps[i]);
2659 result = strcat(result, ":", ftos(mapvote_selections[i]));
2660 if(i < mapvote_count_real)
2662 strunzone(mapvote_maps[i]);
2663 mapvote_maps[i] = "";
2664 strunzone(mapvote_maps_pakfile[i]);
2665 mapvote_maps_pakfile[i] = "";
2669 result = strcat(result, ":didn't vote:", ftos(didntvote));
2670 if(autocvar_sv_eventlog)
2671 GameLogEcho(result);
2681 keeptwo = mapvote_keeptwotime;
2682 MapVote_CheckRules_1(); // count
2683 if(MapVote_CheckRules_2()) // decide
2687 FOR_EACH_REALCLIENT(other)
2689 // hide scoreboard again
2690 if(other.health != 2342)
2692 other.health = 2342;
2694 if(clienttype(other) == CLIENTTYPE_REAL)
2697 WriteByte(MSG_ONE, SVC_FINALE);
2698 WriteString(MSG_ONE, "");
2702 // clear possibly invalid votes
2703 if(mapvote_maps[other.mapvote - 1] == "")
2705 // use impulses as new vote
2706 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2707 if(mapvote_maps[other.impulse - 1] != "")
2709 other.mapvote = other.impulse;
2710 MapVote_TouchVotes(other);
2718 MapVote_CheckRules_1(); // just count
2720 void MapVote_Start()
2725 // wait for stats to be sent first
2726 if(!playerstats_waitforme)
2729 MapInfo_Enumerate();
2730 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
2733 void MapVote_Think()
2738 if(alreadychangedlevel)
2741 if(time < mapvote_nextthink)
2745 mapvote_nextthink = time + 0.5;
2747 if(!mapvote_initialized)
2749 if(autocvar_rescan_pending == 1)
2751 cvar_set("rescan_pending", "2");
2752 localcmd("fs_rescan\nrescan_pending 3\n");
2755 else if(autocvar_rescan_pending == 2)
2759 else if(autocvar_rescan_pending == 3)
2761 // now build missing mapinfo files
2762 if(!MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
2765 // we're done, start the timer
2766 cvar_set("rescan_pending", "0");
2769 mapvote_initialized = TRUE;
2770 if(DoNextMapOverride(0))
2772 if(!autocvar_g_maplist_votable || player_count <= 0)
2783 string GotoMap(string m)
2785 if(!MapInfo_CheckMap(m))
2786 return "The map you chose is not available on this server.";
2787 cvar_set("nextmap", m);
2788 cvar_set("timelimit", "-1");
2789 if(mapvote_initialized || alreadychangedlevel)
2791 if(DoNextMapOverride(0))
2792 return "Map switch initiated.";
2794 return "Hm... no. For some reason I like THIS map more.";
2797 return "Map switch will happen after scoreboard.";
2804 FOR_EACH_REALCLIENT(self)
2806 if(self.classname == "spectator")
2808 if(self.enemy.typehitsound)
2809 self.typehit_time = time;
2810 else if(self.enemy.hitsound)
2811 self.hit_time = time;
2815 if(self.typehitsound)
2816 self.typehit_time = time;
2817 else if(self.hitsound)
2818 self.hit_time = time;
2821 altime = time + frametime * (1 + autocvar_g_antilag_nudge);
2822 // add 1 frametime because after this, engine SV_Physics
2823 // increases time by a frametime and then networks the frame
2824 // add another frametime because client shows everything with
2825 // 1 frame of lag (cl_nolerp 0). The last +1 however should not be
2827 FOR_EACH_CLIENT(self)
2829 self.hitsound = FALSE;
2830 self.typehitsound = FALSE;
2831 antilag_record(self, altime);
2838 * returns TRUE if redirecting
2840 float redirection_timeout;
2841 float redirection_nextthink;
2842 float RedirectionThink()
2844 float clients_found;
2846 if(redirection_target == "")
2849 if(!redirection_timeout)
2851 cvar_set("sv_public", "-2");
2852 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2853 if(redirection_target == "self")
2854 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2856 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2859 if(time < redirection_nextthink)
2862 redirection_nextthink = time + 1;
2865 FOR_EACH_REALCLIENT(self)
2868 print("Redirecting: sending connect command to ", self.netname, "\n");
2869 if(redirection_target == "self")
2870 stuffcmd(self, "\ndisconnect; defer ", ftos(autocvar_quit_and_redirect_timer), " reconnect\n");
2872 stuffcmd(self, strcat("\ndisconnect; defer ", ftos(autocvar_quit_and_redirect_timer), " \"connect ", redirection_target, "\"\n"));
2876 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2878 if(time > redirection_timeout || clients_found == 0)
2879 localcmd("\nwait; wait; wait; quit\n");
2884 void TargetMusic_RestoreGame();
2887 // Loaded from a save game
2888 // some things then break, so let's work around them...
2890 // Progs DB (capture records)
2891 ServerProgsDB = db_load(strcat("server.db", autocvar_sessionid));
2895 MapInfo_Enumerate();
2896 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
2899 TargetMusic_RestoreGame();
2908 if(world_initialized > 0)
2910 world_initialized = 0;
2911 print("Saving persistent data...\n");
2914 PlayerStats_EndMatch(0);
2916 PlayerStats_AddGlobalInfo(e);
2917 PlayerStats_Shutdown();
2919 if(!cheatcount_total)
2921 if(autocvar_sv_db_saveasdump)
2922 db_dump(ServerProgsDB, strcat("server.db", autocvar_sessionid));
2924 db_save(ServerProgsDB, strcat("server.db", autocvar_sessionid));
2926 if(autocvar_developer)
2928 if(autocvar_sv_db_saveasdump)
2929 db_dump(TemporaryDB, "server-temp.db");
2931 db_save(TemporaryDB, "server-temp.db");
2933 CheatShutdown(); // must be after cheatcount check
2934 db_close(ServerProgsDB);
2935 db_close(TemporaryDB);
2937 // tell the bot system the game is ending now
2940 WeaponStats_Shutdown();
2943 else if(world_initialized == 0)
2945 print("NOTE: crashed before even initializing the world, not saving persistent data\n");