From d1542fb195d451b4c1d62fce9d960ccaf81a0238 Mon Sep 17 00:00:00 2001 From: TimePath Date: Sun, 27 Aug 2017 20:11:26 +1000 Subject: [PATCH] GameRules: initialize as early as possible --- .../gamemodes/gamemode/nexball/nexball.qc | 2 +- .../gamemode/onslaught/sv_onslaught.qh | 4 ++-- .../mutators/mutator/gamemode_assault.qc | 10 ---------- .../mutators/mutator/gamemode_assault.qh | 11 +++++----- qcsrc/server/mutators/mutator/gamemode_ca.qh | 13 +++++------- qcsrc/server/mutators/mutator/gamemode_ctf.qc | 20 ------------------- qcsrc/server/mutators/mutator/gamemode_ctf.qh | 17 ++++++++++++++++ .../mutators/mutator/gamemode_domination.qh | 4 ++-- .../mutators/mutator/gamemode_freezetag.qh | 5 ++--- .../mutators/mutator/gamemode_invasion.qh | 15 ++++++-------- .../mutators/mutator/gamemode_keepaway.qc | 5 ----- .../mutators/mutator/gamemode_keepaway.qh | 6 ++++++ .../mutators/mutator/gamemode_keyhunt.qc | 2 +- .../mutators/mutator/gamemode_keyhunt.qh | 6 +++--- qcsrc/server/mutators/mutator/gamemode_lms.qc | 12 ----------- qcsrc/server/mutators/mutator/gamemode_lms.qh | 9 +++++++-- .../server/mutators/mutator/gamemode_race.qh | 1 + qcsrc/server/mutators/mutator/gamemode_tdm.qh | 6 +++--- 18 files changed, 62 insertions(+), 86 deletions(-) diff --git a/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc b/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc index 4f8d6b559..5a0ff2a2c 100644 --- a/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc +++ b/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc @@ -71,7 +71,7 @@ float OtherTeam(float t) //works only if there are two teams on the map! return e.team; } -const float ST_NEXBALL_GOALS = 1; +const int ST_NEXBALL_GOALS = 1; void nb_ScoreRules(int teams) { GameRules_scoring(teams, 0, 0, { diff --git a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qh b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qh index c1cce29be..5c7fd4697 100644 --- a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qh +++ b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qh @@ -8,10 +8,10 @@ REGISTER_MUTATOR(ons, false) MUTATOR_STATIC(); MUTATOR_ONADD { - ons_Initialize(); - GameRules_teams(true); GameRules_limit_score(autocvar_g_onslaught_point_limit); + + ons_Initialize(); } return false; } diff --git a/qcsrc/server/mutators/mutator/gamemode_assault.qc b/qcsrc/server/mutators/mutator/gamemode_assault.qc index e839546d8..affa033de 100644 --- a/qcsrc/server/mutators/mutator/gamemode_assault.qc +++ b/qcsrc/server/mutators/mutator/gamemode_assault.qc @@ -614,13 +614,3 @@ MUTATOR_HOOKFUNCTION(as, ReadyRestart_Deny) // readyrestart not supported (yet) return true; } - -// scoreboard setup -void assault_ScoreRules() -{ - int teams = BITS(2); // always red vs blue - GameRules_scoring(teams, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, { - field_team(ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY); - field(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY); - }); -} diff --git a/qcsrc/server/mutators/mutator/gamemode_assault.qh b/qcsrc/server/mutators/mutator/gamemode_assault.qh index 0e279b8dc..f437d98b5 100644 --- a/qcsrc/server/mutators/mutator/gamemode_assault.qh +++ b/qcsrc/server/mutators/mutator/gamemode_assault.qh @@ -2,7 +2,7 @@ #include "../gamemode.qh" -void assault_ScoreRules(); +const int ST_ASSAULT_OBJECTIVES = 1; REGISTER_MUTATOR(as, false) { @@ -10,7 +10,11 @@ REGISTER_MUTATOR(as, false) MUTATOR_ONADD { GameRules_teams(true); - assault_ScoreRules(); + int teams = BITS(2); // always red vs blue + GameRules_scoring(teams, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, { + field_team(ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY); + field(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY); + }); } return 0; } @@ -38,8 +42,5 @@ void(entity bot) havocbot_ast_reset_role; void(entity this, float ratingscale, vector org, float sradius) havocbot_goalrating_items; void(entity this, float ratingscale, vector org, float sradius) havocbot_goalrating_enemyplayers; -// scoreboard stuff -const float ST_ASSAULT_OBJECTIVES = 1; - // predefined spawnfuncs void target_objective_decrease_activate(entity this); diff --git a/qcsrc/server/mutators/mutator/gamemode_ca.qh b/qcsrc/server/mutators/mutator/gamemode_ca.qh index bf4a453a3..0982fcca8 100644 --- a/qcsrc/server/mutators/mutator/gamemode_ca.qh +++ b/qcsrc/server/mutators/mutator/gamemode_ca.qh @@ -26,7 +26,10 @@ REGISTER_MUTATOR(ca, false) MUTATOR_STATIC(); MUTATOR_ONADD { - allowed_to_spawn = true; + GameRules_teams(true); + GameRules_spawning_teams(autocvar_g_ca_team_spawns); + GameRules_limit_score(autocvar_g_ca_point_limit); + GameRules_limit_lead(autocvar_g_ca_point_leadlimit); ca_teams = autocvar_g_ca_teams_override; if (ca_teams < 2) @@ -37,16 +40,10 @@ REGISTER_MUTATOR(ca, false) field_team(ST_CA_ROUNDS, "rounds", SFL_SORT_PRIO_PRIMARY); }); + allowed_to_spawn = true; round_handler_Spawn(CA_CheckTeams, CA_CheckWinner, CA_RoundStart); round_handler_Init(5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit); - EliminatedPlayers_Init(ca_isEliminated); - - GameRules_teams(true); - GameRules_limit_score(autocvar_g_ca_point_limit); - GameRules_limit_lead(autocvar_g_ca_point_leadlimit); - - GameRules_spawning_teams(autocvar_g_ca_team_spawns); } return 0; } diff --git a/qcsrc/server/mutators/mutator/gamemode_ctf.qc b/qcsrc/server/mutators/mutator/gamemode_ctf.qc index 8e11e1d78..3cf560ebe 100644 --- a/qcsrc/server/mutators/mutator/gamemode_ctf.qc +++ b/qcsrc/server/mutators/mutator/gamemode_ctf.qc @@ -1,28 +1,8 @@ #include "gamemode_ctf.qh" -#ifndef CSQC #include -void ctf_Initialize(); - -REGISTER_MUTATOR(ctf, false) -{ - MUTATOR_STATIC(); - MUTATOR_ONADD - { - ctf_Initialize(); - - GameRules_teams(true); - GameRules_limit_score(autocvar_capturelimit_override); - GameRules_limit_lead(autocvar_captureleadlimit_override); - } - return 0; -} -#endif - -#ifdef SVQC #include #include -#endif #include diff --git a/qcsrc/server/mutators/mutator/gamemode_ctf.qh b/qcsrc/server/mutators/mutator/gamemode_ctf.qh index 8ef860846..0b86a57f8 100644 --- a/qcsrc/server/mutators/mutator/gamemode_ctf.qh +++ b/qcsrc/server/mutators/mutator/gamemode_ctf.qh @@ -3,6 +3,23 @@ #ifdef SVQC #include "../gamemode.qh" + +void ctf_Initialize(); + +REGISTER_MUTATOR(ctf, false) +{ + MUTATOR_STATIC(); + MUTATOR_ONADD + { + GameRules_teams(true); + GameRules_limit_score(autocvar_capturelimit_override); + GameRules_limit_lead(autocvar_captureleadlimit_override); + + ctf_Initialize(); + } + return 0; +} + // used in cheats.qc void ctf_RespawnFlag(entity flag); diff --git a/qcsrc/server/mutators/mutator/gamemode_domination.qh b/qcsrc/server/mutators/mutator/gamemode_domination.qh index 8b4ca399b..cf5e54f6d 100644 --- a/qcsrc/server/mutators/mutator/gamemode_domination.qh +++ b/qcsrc/server/mutators/mutator/gamemode_domination.qh @@ -14,8 +14,6 @@ REGISTER_MUTATOR(dom, false) MUTATOR_STATIC(); MUTATOR_ONADD { - dom_Initialize(); - int fraglimit_override = autocvar_g_domination_point_limit; if (autocvar_g_domination_roundbased && autocvar_g_domination_roundbased_point_limit) fraglimit_override = autocvar_g_domination_roundbased_point_limit; @@ -23,6 +21,8 @@ REGISTER_MUTATOR(dom, false) GameRules_teams(true); GameRules_limit_score(fraglimit_override); GameRules_limit_lead(autocvar_g_domination_point_leadlimit); + + dom_Initialize(); } return 0; } diff --git a/qcsrc/server/mutators/mutator/gamemode_freezetag.qh b/qcsrc/server/mutators/mutator/gamemode_freezetag.qh index b84a62201..a258d82ea 100644 --- a/qcsrc/server/mutators/mutator/gamemode_freezetag.qh +++ b/qcsrc/server/mutators/mutator/gamemode_freezetag.qh @@ -12,13 +12,12 @@ REGISTER_MUTATOR(ft, false) MUTATOR_STATIC(); MUTATOR_ONADD { - freezetag_Initialize(); - GameRules_teams(true); + GameRules_spawning_teams(autocvar_g_freezetag_team_spawns); GameRules_limit_score(autocvar_g_freezetag_point_limit); GameRules_limit_lead(autocvar_g_freezetag_point_leadlimit); - GameRules_spawning_teams(autocvar_g_freezetag_team_spawns); + freezetag_Initialize(); } return 0; } diff --git a/qcsrc/server/mutators/mutator/gamemode_invasion.qh b/qcsrc/server/mutators/mutator/gamemode_invasion.qh index e902b5ee6..0ea0e82c4 100644 --- a/qcsrc/server/mutators/mutator/gamemode_invasion.qh +++ b/qcsrc/server/mutators/mutator/gamemode_invasion.qh @@ -14,18 +14,15 @@ REGISTER_MUTATOR(inv, false) MUTATOR_STATIC(); MUTATOR_ONADD { - g_invasion = true; - invasion_Initialize(); - - cvar_settemp("g_monsters", "1"); - - GameRules_limit_score(autocvar_g_invasion_point_limit); - - if (autocvar_g_invasion_teams >= 2) - { + if (autocvar_g_invasion_teams >= 2) { GameRules_teams(true); GameRules_spawning_teams(autocvar_g_invasion_team_spawns); } + GameRules_limit_score(autocvar_g_invasion_point_limit); + + g_invasion = true; + cvar_settemp("g_monsters", "1"); + invasion_Initialize(); } return 0; } diff --git a/qcsrc/server/mutators/mutator/gamemode_keepaway.qc b/qcsrc/server/mutators/mutator/gamemode_keepaway.qc index 727324268..7b33bea6f 100644 --- a/qcsrc/server/mutators/mutator/gamemode_keepaway.qc +++ b/qcsrc/server/mutators/mutator/gamemode_keepaway.qc @@ -472,10 +472,5 @@ void ka_SpawnBall() // loads various values for the ball, runs only once at star void ka_Initialize() // run at the start of a match, initiates game mode { - GameRules_scoring(0, SFL_SORT_PRIO_PRIMARY, 0, { - field(SP_KEEPAWAY_PICKUPS, "pickups", 0); - field(SP_KEEPAWAY_CARRIERKILLS, "bckills", 0); - field(SP_KEEPAWAY_BCTIME, "bctime", SFL_SORT_PRIO_SECONDARY); - }); ka_SpawnBall(); } diff --git a/qcsrc/server/mutators/mutator/gamemode_keepaway.qh b/qcsrc/server/mutators/mutator/gamemode_keepaway.qh index 21cc3e46d..abbabbd5b 100644 --- a/qcsrc/server/mutators/mutator/gamemode_keepaway.qh +++ b/qcsrc/server/mutators/mutator/gamemode_keepaway.qh @@ -9,6 +9,12 @@ REGISTER_MUTATOR(ka, false) MUTATOR_STATIC(); MUTATOR_ONADD { + GameRules_scoring(0, SFL_SORT_PRIO_PRIMARY, 0, { + field(SP_KEEPAWAY_PICKUPS, "pickups", 0); + field(SP_KEEPAWAY_CARRIERKILLS, "bckills", 0); + field(SP_KEEPAWAY_BCTIME, "bctime", SFL_SORT_PRIO_SECONDARY); + }); + ka_Initialize(); } return false; diff --git a/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc b/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc index 864290301..15b6e0f4a 100644 --- a/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc +++ b/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc @@ -85,7 +85,7 @@ int kh_key_dropped, kh_key_carried; int kh_Key_AllOwnedByWhichTeam(); -const float ST_KH_CAPS = 1; +const int ST_KH_CAPS = 1; void kh_ScoreRules(int teams) { GameRules_scoring(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, { diff --git a/qcsrc/server/mutators/mutator/gamemode_keyhunt.qh b/qcsrc/server/mutators/mutator/gamemode_keyhunt.qh index 9e8ded5ac..77d7c06fc 100644 --- a/qcsrc/server/mutators/mutator/gamemode_keyhunt.qh +++ b/qcsrc/server/mutators/mutator/gamemode_keyhunt.qh @@ -12,12 +12,12 @@ REGISTER_MUTATOR(kh, false) MUTATOR_STATIC(); MUTATOR_ONADD { - kh_Initialize(); - GameRules_teams(true); + GameRules_spawning_teams(autocvar_g_keyhunt_team_spawns); GameRules_limit_score(autocvar_g_keyhunt_point_limit); GameRules_limit_lead(autocvar_g_keyhunt_point_leadlimit); - GameRules_spawning_teams(autocvar_g_keyhunt_team_spawns); + + kh_Initialize(); } return 0; } diff --git a/qcsrc/server/mutators/mutator/gamemode_lms.qc b/qcsrc/server/mutators/mutator/gamemode_lms.qc index 354c1e15f..4d6f70438 100644 --- a/qcsrc/server/mutators/mutator/gamemode_lms.qc +++ b/qcsrc/server/mutators/mutator/gamemode_lms.qc @@ -419,19 +419,7 @@ MUTATOR_HOOKFUNCTION(lms, AddPlayerScore) return true; // allow writing to this field in intermission as it is needed for newly joining players } -// scoreboard stuff -void lms_ScoreRules() -{ - GameRules_score_enabled(false); - GameRules_scoring(0, 0, 0, { - field(SP_LMS_LIVES, "lives", SFL_SORT_PRIO_SECONDARY); - field(SP_LMS_RANK, "rank", SFL_LOWER_IS_BETTER | SFL_RANK | SFL_SORT_PRIO_PRIMARY | SFL_ALLOW_HIDE); - }); -} - void lms_Initialize() { lms_lowest_lives = 9999; - - lms_ScoreRules(); } diff --git a/qcsrc/server/mutators/mutator/gamemode_lms.qh b/qcsrc/server/mutators/mutator/gamemode_lms.qh index 303dd3bd2..c69113a0c 100644 --- a/qcsrc/server/mutators/mutator/gamemode_lms.qh +++ b/qcsrc/server/mutators/mutator/gamemode_lms.qh @@ -11,10 +11,15 @@ REGISTER_MUTATOR(lms, false) MUTATOR_STATIC(); MUTATOR_ONADD { - lms_Initialize(); - GameRules_limit_score(((!autocvar_g_lms_lives_override) ? -1 : autocvar_g_lms_lives_override)); GameRules_limit_lead(0); + GameRules_score_enabled(false); + GameRules_scoring(0, 0, 0, { + field(SP_LMS_LIVES, "lives", SFL_SORT_PRIO_SECONDARY); + field(SP_LMS_RANK, "rank", SFL_LOWER_IS_BETTER | SFL_RANK | SFL_SORT_PRIO_PRIMARY | SFL_ALLOW_HIDE); + }); + + lms_Initialize(); } return 0; } diff --git a/qcsrc/server/mutators/mutator/gamemode_race.qh b/qcsrc/server/mutators/mutator/gamemode_race.qh index c1b700442..1e475e3ce 100644 --- a/qcsrc/server/mutators/mutator/gamemode_race.qh +++ b/qcsrc/server/mutators/mutator/gamemode_race.qh @@ -11,6 +11,7 @@ REGISTER_MUTATOR(rc, false) MUTATOR_ONADD { rc_SetLimits(); + race_Initialize(); } return 0; diff --git a/qcsrc/server/mutators/mutator/gamemode_tdm.qh b/qcsrc/server/mutators/mutator/gamemode_tdm.qh index 28331dfef..c163962fa 100644 --- a/qcsrc/server/mutators/mutator/gamemode_tdm.qh +++ b/qcsrc/server/mutators/mutator/gamemode_tdm.qh @@ -12,12 +12,12 @@ REGISTER_MUTATOR(tdm, false) MUTATOR_STATIC(); MUTATOR_ONADD { - InitializeEntity(NULL, tdm_DelayedInit, INITPRIO_GAMETYPE); - GameRules_teams(true); + GameRules_spawning_teams(autocvar_g_tdm_team_spawns); GameRules_limit_score(autocvar_g_tdm_point_limit); GameRules_limit_lead(autocvar_g_tdm_point_leadlimit); - GameRules_spawning_teams(autocvar_g_tdm_team_spawns); + + InitializeEntity(NULL, tdm_DelayedInit, INITPRIO_GAMETYPE); } return 0; } -- 2.39.2