From 4faf95050c3c1a7a6963ff7fa768d6c87b3e7bc6 Mon Sep 17 00:00:00 2001 From: TimePath Date: Sun, 27 Aug 2017 15:26:41 +1000 Subject: [PATCH] Refactor game rules --- qcsrc/common/gamemodes/_mod.inc | 4 + qcsrc/common/gamemodes/_mod.qh | 4 + .../gamemodes/gamemode/nexball/nexball.qc | 15 ++-- .../gamemode/onslaught/sv_onslaught.qc | 10 +-- .../gamemode/onslaught/sv_onslaught.qh | 4 +- qcsrc/common/gamemodes/rules.qc | 1 + qcsrc/common/gamemodes/rules.qh | 5 ++ qcsrc/common/gamemodes/sv_rules.qc | 86 +++++++++++++++++++ qcsrc/common/gamemodes/sv_rules.qh | 40 +++++++++ qcsrc/server/g_world.qc | 15 +--- qcsrc/server/g_world.qh | 3 - qcsrc/server/mutators/gamemode.qh | 1 + .../mutators/mutator/gamemode_assault.qc | 8 +- .../mutators/mutator/gamemode_assault.qh | 2 +- qcsrc/server/mutators/mutator/gamemode_ca.qh | 13 ++- qcsrc/server/mutators/mutator/gamemode_ctf.qc | 23 ++--- qcsrc/server/mutators/mutator/gamemode_cts.qc | 22 +++-- qcsrc/server/mutators/mutator/gamemode_cts.qh | 3 +- .../mutators/mutator/gamemode_domination.qc | 18 ++-- .../mutators/mutator/gamemode_domination.qh | 5 +- .../mutators/mutator/gamemode_freezetag.qc | 6 +- .../mutators/mutator/gamemode_freezetag.qh | 5 +- .../mutators/mutator/gamemode_invasion.qc | 11 ++- .../mutators/mutator/gamemode_invasion.qh | 5 +- .../mutators/mutator/gamemode_keepaway.qc | 10 +-- .../mutators/mutator/gamemode_keyhunt.qc | 18 ++-- .../mutators/mutator/gamemode_keyhunt.qh | 5 +- qcsrc/server/mutators/mutator/gamemode_lms.qc | 9 +- qcsrc/server/mutators/mutator/gamemode_lms.qh | 3 +- .../server/mutators/mutator/gamemode_race.qc | 41 +++++---- qcsrc/server/mutators/mutator/gamemode_tdm.qh | 5 +- qcsrc/server/scores_rules.qc | 19 ++-- qcsrc/server/teamplay.qc | 11 +-- qcsrc/server/teamplay.qh | 2 - 34 files changed, 276 insertions(+), 156 deletions(-) create mode 100644 qcsrc/common/gamemodes/rules.qc create mode 100644 qcsrc/common/gamemodes/rules.qh create mode 100644 qcsrc/common/gamemodes/sv_rules.qc create mode 100644 qcsrc/common/gamemodes/sv_rules.qh diff --git a/qcsrc/common/gamemodes/_mod.inc b/qcsrc/common/gamemodes/_mod.inc index c3cec69dc..90cfa6aa4 100644 --- a/qcsrc/common/gamemodes/_mod.inc +++ b/qcsrc/common/gamemodes/_mod.inc @@ -1,3 +1,7 @@ // generated file; do not modify +#include +#ifdef SVQC + #include +#endif #include diff --git a/qcsrc/common/gamemodes/_mod.qh b/qcsrc/common/gamemodes/_mod.qh index 685c277b4..b3ed42da6 100644 --- a/qcsrc/common/gamemodes/_mod.qh +++ b/qcsrc/common/gamemodes/_mod.qh @@ -1,3 +1,7 @@ // generated file; do not modify +#include +#ifdef SVQC + #include +#endif #include diff --git a/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc b/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc index 6be1d95f9..be00469cf 100644 --- a/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc +++ b/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc @@ -72,11 +72,11 @@ float OtherTeam(float t) //works only if there are two teams on the map! const float ST_NEXBALL_GOALS = 1; void nb_ScoreRules(int teams) { - ScoreRules_basics(teams, 0, 0, true); - ScoreInfo_SetLabel_TeamScore( ST_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY); - ScoreInfo_SetLabel_PlayerScore( SP_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY); - ScoreInfo_SetLabel_PlayerScore(SP_NEXBALL_FAULTS, "faults", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER); - ScoreRules_basics_end(); + GameRules_scoring(teams, 0, 0, { + field_team(ST_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY); + field(SP_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY); + field(SP_NEXBALL_FAULTS, "faults", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER); + }); } void LogNB(string mode, entity actor) @@ -1155,8 +1155,9 @@ REGISTER_MUTATOR(nb, g_nexball) InitializeEntity(NULL, nb_delayedinit, INITPRIO_GAMETYPE); WEP_NEXBALL.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED; - ActivateTeamplay(); - SetLimits(autocvar_g_nexball_goallimit, autocvar_g_nexball_goalleadlimit, autocvar_timelimit_override, -1); + GameRules_teams(true); + GameRules_limit_score(autocvar_g_nexball_goallimit); + GameRules_limit_lead(autocvar_g_nexball_goalleadlimit); have_team_spawns = -1; // request team spawns } diff --git a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc index 9992a37f4..d85be170c 100644 --- a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc +++ b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc @@ -2174,11 +2174,11 @@ void ons_ScoreRules() if(c2 >= 0) teams |= BIT(1); if(c3 >= 0) teams |= BIT(2); if(c4 >= 0) teams |= BIT(3); - ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, 0, true); - ScoreInfo_SetLabel_TeamScore (ST_ONS_CAPS, "destroyed", SFL_SORT_PRIO_PRIMARY); - ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY); - ScoreInfo_SetLabel_PlayerScore(SP_ONS_TAKES, "takes", 0); - ScoreRules_basics_end(); + GameRules_scoring(teams, SFL_SORT_PRIO_PRIMARY, 0, { + field_team(ST_ONS_CAPS, "destroyed", SFL_SORT_PRIO_PRIMARY); + field(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY); + field(SP_ONS_TAKES, "takes", 0); + }); } void ons_DelayedInit(entity this) // Do this check with a delay so we can wait for teams to be set up diff --git a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qh b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qh index 0757d7bc6..f27689503 100644 --- a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qh +++ b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qh @@ -11,8 +11,8 @@ REGISTER_MUTATOR(ons, false) error("This is a game type and it cannot be added at runtime."); ons_Initialize(); - ActivateTeamplay(); - SetLimits(autocvar_g_onslaught_point_limit, autocvar_leadlimit_override, autocvar_timelimit_override, -1); + GameRules_teams(true); + GameRules_limit_score(autocvar_g_onslaught_point_limit); have_team_spawns = -1; // request team spawns } diff --git a/qcsrc/common/gamemodes/rules.qc b/qcsrc/common/gamemodes/rules.qc new file mode 100644 index 000000000..5cfbba2b9 --- /dev/null +++ b/qcsrc/common/gamemodes/rules.qc @@ -0,0 +1 @@ +#include "rules.qh" diff --git a/qcsrc/common/gamemodes/rules.qh b/qcsrc/common/gamemodes/rules.qh new file mode 100644 index 000000000..542548d0f --- /dev/null +++ b/qcsrc/common/gamemodes/rules.qh @@ -0,0 +1,5 @@ +#pragma once + +#ifdef SVQC +#include +#endif diff --git a/qcsrc/common/gamemodes/sv_rules.qc b/qcsrc/common/gamemodes/sv_rules.qc new file mode 100644 index 000000000..38e3fb2ab --- /dev/null +++ b/qcsrc/common/gamemodes/sv_rules.qc @@ -0,0 +1,86 @@ +#include "sv_rules.qh" + +#include + +void GameRules_teams(bool value) +{ + if (value) { + serverflags |= SERVERFLAG_TEAMPLAY; + teamplay = 1; + cvar_set("teamplay", "2"); // DP needs this for sending proper getstatus replies. + } else { + serverflags &= ~SERVERFLAG_TEAMPLAY; + teamplay = 0; + cvar_set("teamplay", "0"); // DP needs this for sending proper getstatus replies. + } +} + +bool _GameRules_score_enabled = true; +void GameRules_score_enabled(bool value) +{ + _GameRules_score_enabled = value; +} + +bool GameRules_limit_score_initialized; +void GameRules_limit_score(int limit) +{ + if (GameRules_limit_score_initialized) return; + if (autocvar_g_campaign) return; + if (limit < 0) return; + cvar_set("fraglimit", ftos(limit)); + GameRules_limit_score_initialized = true; +} + +bool GameRules_limit_lead_initialized; +void GameRules_limit_lead(int limit) +{ + if (GameRules_limit_lead_initialized) return; + if (autocvar_g_campaign) return; + if (limit < 0) return; + cvar_set("leadlimit", ftos(limit)); + GameRules_limit_lead_initialized = true; +} + +bool GameRules_limit_time_initialized; +void GameRules_limit_time(int limit) +{ + if (GameRules_limit_time_initialized) return; + if (autocvar_g_campaign) return; + if (limit < 0) return; + cvar_set("timelimit", ftos(limit)); + GameRules_limit_time_initialized = true; +} + +bool GameRules_limit_time_qualifying_initialized; +void GameRules_limit_time_qualifying(int limit) +{ + if (GameRules_limit_time_qualifying_initialized) return; + if (autocvar_g_campaign) return; + if (limit < 0) return; + cvar_set("g_race_qualifying_timelimit", ftos(limit)); + GameRules_limit_time_qualifying_initialized = true; +} + +void GameRules_limit_fallbacks() +{ + GameRules_limit_score(autocvar_fraglimit_override); + GameRules_limit_lead(autocvar_leadlimit_override); + GameRules_limit_time(autocvar_timelimit_override); +} + +void _GameRules_scoring_begin(int teams, float spprio, float stprio) +{ + ScoreRules_basics(teams, spprio, stprio, _GameRules_score_enabled); +} +void _GameRules_scoring_field(entity i, string label, int scoreflags) +{ + ScoreInfo_SetLabel_PlayerScore(i, label, scoreflags); +} +void _GameRules_scoring_field_team(float i, string label, int scoreflags) +{ + ScoreInfo_SetLabel_TeamScore(i, label, scoreflags); +} +void _GameRules_scoring_end() +{ + ScoreRules_basics_end(); +} diff --git a/qcsrc/common/gamemodes/sv_rules.qh b/qcsrc/common/gamemodes/sv_rules.qh new file mode 100644 index 000000000..588d8da70 --- /dev/null +++ b/qcsrc/common/gamemodes/sv_rules.qh @@ -0,0 +1,40 @@ +#pragma once + +// todo: accept the number of teams as a parameter +void GameRules_teams(bool value); + +/** + * Disabling score disables the "score" column on the scoreboard + */ +void GameRules_score_enabled(bool value); + +void GameRules_limit_score(int limit); +void GameRules_limit_lead(int limit); +void GameRules_limit_time(int limit); +void GameRules_limit_time_qualifying(int limit); + +/** + * Set any unspecified rules to their defaults + */ +void GameRules_limit_fallbacks(); + +// derive score_enabled from !frags_enabled + +/** + * @param teams a bitmask of active teams + * @param spprio player score priority (if frags aren't enabled) + * @param stprio team score priority (if frags aren't enabled) + */ +#define GameRules_scoring(teams, spprio, stprio, fields) MACRO_BEGIN { \ + _GameRules_scoring_begin((teams), (spprio), (stprio)); \ + noref void(entity, string, float) field = _GameRules_scoring_field; \ + /* todo: just have the one `field` function */ \ + noref void(int, string, float) field_team = _GameRules_scoring_field_team; \ + LAMBDA(fields); \ + _GameRules_scoring_end(); \ +} MACRO_END + +void _GameRules_scoring_begin(int teams, float spprio, float stprio); +void _GameRules_scoring_field(entity i, string label, int scoreflags); +void _GameRules_scoring_field_team(float i, string label, int scoreflags); +void _GameRules_scoring_end(); diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index 66612e0db..a0845d294 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -597,18 +597,6 @@ void __init_dedicated_server_shutdown() { MapInfo_Shutdown(); } -void SetLimits(int fraglimit_override, int leadlimit_override, float timelimit_override, float qualifying_override) -{ - if(!autocvar_g_campaign) - { - if(fraglimit_override >= 0) cvar_set("fraglimit", ftos(fraglimit_override)); - if(timelimit_override >= 0) cvar_set("timelimit", ftos(timelimit_override)); - if(leadlimit_override >= 0) cvar_set("leadlimit", ftos(leadlimit_override)); - if(qualifying_override >= 0) cvar_set("g_race_qualifying_timelimit", ftos(qualifying_override)); - } - limits_are_set = true; -} - void Map_MarkAsRecent(string m); float world_already_spawned; void Nagger_Init(); @@ -759,8 +747,7 @@ spawnfunc(worldspawn) readlevelcvars(); GrappleHookInit(); - if(!limits_are_set) - SetLimits(autocvar_fraglimit_override, autocvar_leadlimit_override, autocvar_timelimit_override, -1); + GameRules_limit_fallbacks(); if(warmup_limit == 0) warmup_limit = (autocvar_timelimit > 0) ? autocvar_timelimit * 60 : autocvar_timelimit; diff --git a/qcsrc/server/g_world.qh b/qcsrc/server/g_world.qh index 4d5401abd..034407bc1 100644 --- a/qcsrc/server/g_world.qh +++ b/qcsrc/server/g_world.qh @@ -10,9 +10,6 @@ const int WINNING_YES = 1; // winner found const int WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached const int WINNING_STARTSUDDENDEATHOVERTIME = 3; // no winner, enter suddendeath overtime NOW -bool limits_are_set = false; -void SetLimits(int fraglimit_override, int leadlimit_override, float timelimit_override, float qualifying_override); - float WinningCondition_Scores(float limit, float leadlimit); void SetWinners(.float field, float value); void IntermissionThink(entity this); diff --git a/qcsrc/server/mutators/gamemode.qh b/qcsrc/server/mutators/gamemode.qh index c6fdeb244..5de2a656a 100644 --- a/qcsrc/server/mutators/gamemode.qh +++ b/qcsrc/server/mutators/gamemode.qh @@ -6,6 +6,7 @@ #include #include #include +#include #include "mutator.qh" diff --git a/qcsrc/server/mutators/mutator/gamemode_assault.qc b/qcsrc/server/mutators/mutator/gamemode_assault.qc index bd88131d3..111b6db8e 100644 --- a/qcsrc/server/mutators/mutator/gamemode_assault.qc +++ b/qcsrc/server/mutators/mutator/gamemode_assault.qc @@ -622,8 +622,8 @@ void assault_ScoreRules() teams |= BIT(0); teams |= BIT(1); // always red vs blue - ScoreRules_basics(teams, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, true); - ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY); - ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY); - ScoreRules_basics_end(); + 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 8fd407485..dc46279e8 100644 --- a/qcsrc/server/mutators/mutator/gamemode_assault.qh +++ b/qcsrc/server/mutators/mutator/gamemode_assault.qh @@ -6,7 +6,7 @@ void assault_ScoreRules(); REGISTER_MUTATOR(as, false) { - ActivateTeamplay(); + GameRules_teams(true); have_team_spawns = -1; // request team spawns MUTATOR_ONADD diff --git a/qcsrc/server/mutators/mutator/gamemode_ca.qh b/qcsrc/server/mutators/mutator/gamemode_ca.qh index 5aba748fd..5069c010d 100644 --- a/qcsrc/server/mutators/mutator/gamemode_ca.qh +++ b/qcsrc/server/mutators/mutator/gamemode_ca.qh @@ -21,8 +21,6 @@ bool CA_CheckWinner(); void CA_RoundStart(); bool ca_isEliminated(entity e); -void SetLimits(int fraglimit_override, int leadlimit_override, float timelimit_override, float qualifying_override); - REGISTER_MUTATOR(ca, false) { MUTATOR_ONADD @@ -45,17 +43,18 @@ REGISTER_MUTATOR(ca, false) ca_teams = teams; // now set it? - ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, 0, true); - ScoreInfo_SetLabel_TeamScore(ST_CA_ROUNDS, "rounds", SFL_SORT_PRIO_PRIMARY); - ScoreRules_basics_end(); + GameRules_scoring(teams, SFL_SORT_PRIO_PRIMARY, 0, { + field_team(ST_CA_ROUNDS, "rounds", SFL_SORT_PRIO_PRIMARY); + }); 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); - ActivateTeamplay(); - SetLimits(autocvar_g_ca_point_limit, autocvar_g_ca_point_leadlimit, autocvar_timelimit_override, -1); + GameRules_teams(true); + GameRules_limit_score(autocvar_g_ca_point_limit); + GameRules_limit_lead(autocvar_g_ca_point_leadlimit); if (autocvar_g_ca_team_spawns) have_team_spawns = -1; // request team spawns diff --git a/qcsrc/server/mutators/mutator/gamemode_ctf.qc b/qcsrc/server/mutators/mutator/gamemode_ctf.qc index 4c88d5e45..930e93b83 100644 --- a/qcsrc/server/mutators/mutator/gamemode_ctf.qc +++ b/qcsrc/server/mutators/mutator/gamemode_ctf.qc @@ -12,8 +12,9 @@ REGISTER_MUTATOR(ctf, false) error("This is a game type and it cannot be added at runtime."); ctf_Initialize(); - ActivateTeamplay(); - SetLimits(autocvar_capturelimit_override, autocvar_captureleadlimit_override, autocvar_timelimit_override, -1); + GameRules_teams(true); + GameRules_limit_score(autocvar_capturelimit_override); + GameRules_limit_lead(autocvar_captureleadlimit_override); have_team_spawns = -1; // request team spawns } @@ -2690,15 +2691,15 @@ spawnfunc(team_CTL_bluelolly) { spawnfunc_item_flag_team2(this); } void ctf_ScoreRules(int teams) { CheckAllowedTeams(NULL); - ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, 0, true); - ScoreInfo_SetLabel_TeamScore (ST_CTF_CAPS, "caps", SFL_SORT_PRIO_PRIMARY); - ScoreInfo_SetLabel_PlayerScore(SP_CTF_CAPS, "caps", SFL_SORT_PRIO_SECONDARY); - ScoreInfo_SetLabel_PlayerScore(SP_CTF_CAPTIME, "captime", SFL_LOWER_IS_BETTER | SFL_TIME); - ScoreInfo_SetLabel_PlayerScore(SP_CTF_PICKUPS, "pickups", 0); - ScoreInfo_SetLabel_PlayerScore(SP_CTF_FCKILLS, "fckills", 0); - ScoreInfo_SetLabel_PlayerScore(SP_CTF_RETURNS, "returns", 0); - ScoreInfo_SetLabel_PlayerScore(SP_CTF_DROPS, "drops", SFL_LOWER_IS_BETTER); - ScoreRules_basics_end(); + GameRules_scoring(teams, SFL_SORT_PRIO_PRIMARY, 0, { + field_team(ST_CTF_CAPS, "caps", SFL_SORT_PRIO_PRIMARY); + field(SP_CTF_CAPS, "caps", SFL_SORT_PRIO_SECONDARY); + field(SP_CTF_CAPTIME, "captime", SFL_LOWER_IS_BETTER | SFL_TIME); + field(SP_CTF_PICKUPS, "pickups", 0); + field(SP_CTF_FCKILLS, "fckills", 0); + field(SP_CTF_RETURNS, "returns", 0); + field(SP_CTF_DROPS, "drops", SFL_LOWER_IS_BETTER); + }); } // code from here on is just to support maps that don't have flag and team entities diff --git a/qcsrc/server/mutators/mutator/gamemode_cts.qc b/qcsrc/server/mutators/mutator/gamemode_cts.qc index 3de77f372..1daea9eef 100644 --- a/qcsrc/server/mutators/mutator/gamemode_cts.qc +++ b/qcsrc/server/mutators/mutator/gamemode_cts.qc @@ -32,18 +32,16 @@ void havocbot_role_cts(entity this) void cts_ScoreRules() { - ScoreRules_basics(0, 0, 0, false); - if(g_race_qualifying) - { - ScoreInfo_SetLabel_PlayerScore(SP_RACE_FASTEST, "fastest", SFL_SORT_PRIO_PRIMARY | SFL_LOWER_IS_BETTER | SFL_TIME); - } - else - { - ScoreInfo_SetLabel_PlayerScore(SP_RACE_LAPS, "laps", SFL_SORT_PRIO_PRIMARY); - ScoreInfo_SetLabel_PlayerScore(SP_RACE_TIME, "time", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME); - ScoreInfo_SetLabel_PlayerScore(SP_RACE_FASTEST, "fastest", SFL_LOWER_IS_BETTER | SFL_TIME); - } - ScoreRules_basics_end(); + GameRules_score_enabled(false); + GameRules_scoring(0, 0, 0, { + if (g_race_qualifying) { + field(SP_RACE_FASTEST, "fastest", SFL_SORT_PRIO_PRIMARY | SFL_LOWER_IS_BETTER | SFL_TIME); + } else { + field(SP_RACE_LAPS, "laps", SFL_SORT_PRIO_PRIMARY); + field(SP_RACE_TIME, "time", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME); + field(SP_RACE_FASTEST, "fastest", SFL_LOWER_IS_BETTER | SFL_TIME); + } + }); } void cts_EventLog(string mode, entity actor) // use an alias for easy changing and quick editing later diff --git a/qcsrc/server/mutators/mutator/gamemode_cts.qh b/qcsrc/server/mutators/mutator/gamemode_cts.qh index 2a18fe915..f81ed274a 100644 --- a/qcsrc/server/mutators/mutator/gamemode_cts.qh +++ b/qcsrc/server/mutators/mutator/gamemode_cts.qh @@ -14,7 +14,8 @@ REGISTER_MUTATOR(cts, false) g_race_qualifying = true; independent_players = 1; - SetLimits(0, 0, autocvar_timelimit_override, -1); + GameRules_limit_score(0); + GameRules_limit_lead(0); cts_Initialize(); } diff --git a/qcsrc/server/mutators/mutator/gamemode_domination.qc b/qcsrc/server/mutators/mutator/gamemode_domination.qc index 7c645e4d3..ab053478c 100644 --- a/qcsrc/server/mutators/mutator/gamemode_domination.qc +++ b/qcsrc/server/mutators/mutator/gamemode_domination.qc @@ -559,10 +559,10 @@ void ScoreRules_dom(int teams) { if(domination_roundbased) { - ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, 0, true); - ScoreInfo_SetLabel_TeamScore (ST_DOM_CAPS, "caps", SFL_SORT_PRIO_PRIMARY); - ScoreInfo_SetLabel_PlayerScore(SP_DOM_TAKES, "takes", 0); - ScoreRules_basics_end(); + GameRules_scoring(teams, SFL_SORT_PRIO_PRIMARY, 0, { + field_team(ST_DOM_CAPS, "caps", SFL_SORT_PRIO_PRIMARY); + field(SP_DOM_TAKES, "takes", 0); + }); } else { @@ -572,11 +572,11 @@ void ScoreRules_dom(int teams) sp_domticks = SFL_SORT_PRIO_PRIMARY; else sp_score = SFL_SORT_PRIO_PRIMARY; - ScoreRules_basics(teams, sp_score, sp_score, true); - ScoreInfo_SetLabel_TeamScore (ST_DOM_TICKS, "ticks", sp_domticks); - ScoreInfo_SetLabel_PlayerScore(SP_DOM_TICKS, "ticks", sp_domticks); - ScoreInfo_SetLabel_PlayerScore(SP_DOM_TAKES, "takes", 0); - ScoreRules_basics_end(); + GameRules_scoring(teams, sp_score, sp_score, { + field_team(ST_DOM_TICKS, "ticks", sp_domticks); + field(SP_DOM_TICKS, "ticks", sp_domticks); + field(SP_DOM_TAKES, "takes", 0); + }); } } diff --git a/qcsrc/server/mutators/mutator/gamemode_domination.qh b/qcsrc/server/mutators/mutator/gamemode_domination.qh index 609fcfd0d..3fcca2e89 100644 --- a/qcsrc/server/mutators/mutator/gamemode_domination.qh +++ b/qcsrc/server/mutators/mutator/gamemode_domination.qh @@ -21,8 +21,9 @@ REGISTER_MUTATOR(dom, false) if (autocvar_g_domination_roundbased && autocvar_g_domination_roundbased_point_limit) fraglimit_override = autocvar_g_domination_roundbased_point_limit; - ActivateTeamplay(); - SetLimits(fraglimit_override, autocvar_g_domination_point_leadlimit, autocvar_timelimit_override, -1); + GameRules_teams(true); + GameRules_limit_score(fraglimit_override); + GameRules_limit_lead(autocvar_g_domination_point_leadlimit); have_team_spawns = -1; // request team spawns } diff --git a/qcsrc/server/mutators/mutator/gamemode_freezetag.qc b/qcsrc/server/mutators/mutator/gamemode_freezetag.qc index 9e9878c36..45a45240a 100644 --- a/qcsrc/server/mutators/mutator/gamemode_freezetag.qc +++ b/qcsrc/server/mutators/mutator/gamemode_freezetag.qc @@ -9,9 +9,9 @@ float autocvar_g_freezetag_warmup; void freezetag_ScoreRules(int teams) { - ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, true); // SFL_SORT_PRIO_PRIMARY - ScoreInfo_SetLabel_PlayerScore(SP_FREEZETAG_REVIVALS, "revivals", 0); - ScoreRules_basics_end(); + GameRules_scoring(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, { + field(SP_FREEZETAG_REVIVALS, "revivals", 0); + }); } void freezetag_count_alive_players() diff --git a/qcsrc/server/mutators/mutator/gamemode_freezetag.qh b/qcsrc/server/mutators/mutator/gamemode_freezetag.qh index fda0737dd..2274180aa 100644 --- a/qcsrc/server/mutators/mutator/gamemode_freezetag.qh +++ b/qcsrc/server/mutators/mutator/gamemode_freezetag.qh @@ -15,8 +15,9 @@ REGISTER_MUTATOR(ft, false) error("This is a game type and it cannot be added at runtime."); freezetag_Initialize(); - ActivateTeamplay(); - SetLimits(autocvar_g_freezetag_point_limit, autocvar_g_freezetag_point_leadlimit, autocvar_timelimit_override, -1); + GameRules_teams(true); + GameRules_limit_score(autocvar_g_freezetag_point_limit); + GameRules_limit_lead(autocvar_g_freezetag_point_leadlimit); if (autocvar_g_freezetag_team_spawns) have_team_spawns = -1; // request team spawns diff --git a/qcsrc/server/mutators/mutator/gamemode_invasion.qc b/qcsrc/server/mutators/mutator/gamemode_invasion.qc index 8ec353c1d..9dcf1d314 100644 --- a/qcsrc/server/mutators/mutator/gamemode_invasion.qc +++ b/qcsrc/server/mutators/mutator/gamemode_invasion.qc @@ -560,10 +560,13 @@ MUTATOR_HOOKFUNCTION(inv, AllowMobButcher) void invasion_ScoreRules(int inv_teams) { if(inv_teams) { CheckAllowedTeams(NULL); } - ScoreRules_basics(inv_teams, 0, 0, false); - if(inv_teams) ScoreInfo_SetLabel_TeamScore(ST_INV_KILLS, "frags", SFL_SORT_PRIO_PRIMARY); - ScoreInfo_SetLabel_PlayerScore(SP_KILLS, "frags", ((inv_teams) ? SFL_SORT_PRIO_SECONDARY : SFL_SORT_PRIO_PRIMARY)); - ScoreRules_basics_end(); + GameRules_score_enabled(false); + GameRules_scoring(inv_teams, 0, 0, { + if (inv_teams) { + field_team(ST_INV_KILLS, "frags", SFL_SORT_PRIO_PRIMARY); + } + field(SP_KILLS, "frags", ((inv_teams) ? SFL_SORT_PRIO_SECONDARY : SFL_SORT_PRIO_PRIMARY)); + }); } void invasion_DelayedInit(entity this) // Do this check with a delay so we can wait for teams to be set up. diff --git a/qcsrc/server/mutators/mutator/gamemode_invasion.qh b/qcsrc/server/mutators/mutator/gamemode_invasion.qh index 98322bcac..aad484cbf 100644 --- a/qcsrc/server/mutators/mutator/gamemode_invasion.qh +++ b/qcsrc/server/mutators/mutator/gamemode_invasion.qh @@ -20,10 +20,11 @@ REGISTER_MUTATOR(inv, false) cvar_settemp("g_monsters", "1"); - SetLimits(autocvar_g_invasion_point_limit, autocvar_leadlimit_override, autocvar_timelimit_override, -1); + GameRules_limit_score(autocvar_g_invasion_point_limit); + if (autocvar_g_invasion_teams >= 2) { - ActivateTeamplay(); + GameRules_teams(true); if (autocvar_g_invasion_team_spawns) have_team_spawns = -1; // request team spawns } diff --git a/qcsrc/server/mutators/mutator/gamemode_keepaway.qc b/qcsrc/server/mutators/mutator/gamemode_keepaway.qc index c28fd5eb8..93ec6558b 100644 --- a/qcsrc/server/mutators/mutator/gamemode_keepaway.qc +++ b/qcsrc/server/mutators/mutator/gamemode_keepaway.qc @@ -468,11 +468,11 @@ void ka_SpawnBall() // loads various values for the ball, runs only once at star void ka_ScoreRules() { - ScoreRules_basics(0, SFL_SORT_PRIO_PRIMARY, 0, true); // SFL_SORT_PRIO_PRIMARY - ScoreInfo_SetLabel_PlayerScore(SP_KEEPAWAY_PICKUPS, "pickups", 0); - ScoreInfo_SetLabel_PlayerScore(SP_KEEPAWAY_CARRIERKILLS, "bckills", 0); - ScoreInfo_SetLabel_PlayerScore(SP_KEEPAWAY_BCTIME, "bctime", SFL_SORT_PRIO_SECONDARY); - ScoreRules_basics_end(); + 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); + }); } void ka_Initialize() // run at the start of a match, initiates game mode diff --git a/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc b/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc index d32df0f59..0b407b709 100644 --- a/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc +++ b/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc @@ -88,15 +88,15 @@ int kh_Key_AllOwnedByWhichTeam(); const float ST_KH_CAPS = 1; void kh_ScoreRules(int teams) { - ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, true); - ScoreInfo_SetLabel_TeamScore( ST_KH_CAPS, "caps", SFL_SORT_PRIO_SECONDARY); - ScoreInfo_SetLabel_PlayerScore(SP_KH_CAPS, "caps", SFL_SORT_PRIO_SECONDARY); - ScoreInfo_SetLabel_PlayerScore(SP_KH_PUSHES, "pushes", 0); - ScoreInfo_SetLabel_PlayerScore(SP_KH_DESTROYS, "destroyed", SFL_LOWER_IS_BETTER); - ScoreInfo_SetLabel_PlayerScore(SP_KH_PICKUPS, "pickups", 0); - ScoreInfo_SetLabel_PlayerScore(SP_KH_KCKILLS, "kckills", 0); - ScoreInfo_SetLabel_PlayerScore(SP_KH_LOSSES, "losses", SFL_LOWER_IS_BETTER); - ScoreRules_basics_end(); + GameRules_scoring(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, { + field_team(ST_KH_CAPS, "caps", SFL_SORT_PRIO_SECONDARY); + field(SP_KH_CAPS, "caps", SFL_SORT_PRIO_SECONDARY); + field(SP_KH_PUSHES, "pushes", 0); + field(SP_KH_DESTROYS, "destroyed", SFL_LOWER_IS_BETTER); + field(SP_KH_PICKUPS, "pickups", 0); + field(SP_KH_KCKILLS, "kckills", 0); + field(SP_KH_LOSSES, "losses", SFL_LOWER_IS_BETTER); + }); } bool kh_KeyCarrier_waypointsprite_visible_for_player(entity this, entity player, entity view) // runs all the time diff --git a/qcsrc/server/mutators/mutator/gamemode_keyhunt.qh b/qcsrc/server/mutators/mutator/gamemode_keyhunt.qh index d0fb5f95b..3903caa98 100644 --- a/qcsrc/server/mutators/mutator/gamemode_keyhunt.qh +++ b/qcsrc/server/mutators/mutator/gamemode_keyhunt.qh @@ -15,8 +15,9 @@ REGISTER_MUTATOR(kh, false) error("This is a game type and it cannot be added at runtime."); kh_Initialize(); - ActivateTeamplay(); - SetLimits(autocvar_g_keyhunt_point_limit, autocvar_g_keyhunt_point_leadlimit, autocvar_timelimit_override, -1); + GameRules_teams(true); + GameRules_limit_score(autocvar_g_keyhunt_point_limit); + GameRules_limit_lead(autocvar_g_keyhunt_point_leadlimit); if (autocvar_g_keyhunt_team_spawns) have_team_spawns = -1; // request team spawns } diff --git a/qcsrc/server/mutators/mutator/gamemode_lms.qc b/qcsrc/server/mutators/mutator/gamemode_lms.qc index 158492cd3..2bc3ed27a 100644 --- a/qcsrc/server/mutators/mutator/gamemode_lms.qc +++ b/qcsrc/server/mutators/mutator/gamemode_lms.qc @@ -422,10 +422,11 @@ MUTATOR_HOOKFUNCTION(lms, AddPlayerScore) // scoreboard stuff void lms_ScoreRules() { - ScoreRules_basics(0, 0, 0, false); - ScoreInfo_SetLabel_PlayerScore(SP_LMS_LIVES, "lives", SFL_SORT_PRIO_SECONDARY); - ScoreInfo_SetLabel_PlayerScore(SP_LMS_RANK, "rank", SFL_LOWER_IS_BETTER | SFL_RANK | SFL_SORT_PRIO_PRIMARY | SFL_ALLOW_HIDE); - ScoreRules_basics_end(); + 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() diff --git a/qcsrc/server/mutators/mutator/gamemode_lms.qh b/qcsrc/server/mutators/mutator/gamemode_lms.qh index 1f1d2d4c3..8c47c92b7 100644 --- a/qcsrc/server/mutators/mutator/gamemode_lms.qh +++ b/qcsrc/server/mutators/mutator/gamemode_lms.qh @@ -14,7 +14,8 @@ REGISTER_MUTATOR(lms, false) error("This is a game type and it cannot be added at runtime."); lms_Initialize(); - SetLimits(((!autocvar_g_lms_lives_override) ? -1 : autocvar_g_lms_lives_override), 0, autocvar_timelimit_override, -1); + GameRules_limit_score(((!autocvar_g_lms_lives_override) ? -1 : autocvar_g_lms_lives_override)); + GameRules_limit_lead(0); } MUTATOR_ONROLLBACK_OR_REMOVE diff --git a/qcsrc/server/mutators/mutator/gamemode_race.qc b/qcsrc/server/mutators/mutator/gamemode_race.qc index 7628968ed..84ca96fae 100644 --- a/qcsrc/server/mutators/mutator/gamemode_race.qc +++ b/qcsrc/server/mutators/mutator/gamemode_race.qc @@ -37,25 +37,21 @@ void havocbot_role_race(entity this) void race_ScoreRules() { - ScoreRules_basics(race_teams, 0, 0, false); - if(race_teams) - { - ScoreInfo_SetLabel_TeamScore( ST_RACE_LAPS, "laps", SFL_SORT_PRIO_PRIMARY); - ScoreInfo_SetLabel_PlayerScore(SP_RACE_LAPS, "laps", SFL_SORT_PRIO_PRIMARY); - ScoreInfo_SetLabel_PlayerScore(SP_RACE_TIME, "time", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME); - ScoreInfo_SetLabel_PlayerScore(SP_RACE_FASTEST, "fastest", SFL_LOWER_IS_BETTER | SFL_TIME); - } - else if(g_race_qualifying) - { - ScoreInfo_SetLabel_PlayerScore(SP_RACE_FASTEST, "fastest", SFL_SORT_PRIO_PRIMARY | SFL_LOWER_IS_BETTER | SFL_TIME); - } - else - { - ScoreInfo_SetLabel_PlayerScore(SP_RACE_LAPS, "laps", SFL_SORT_PRIO_PRIMARY); - ScoreInfo_SetLabel_PlayerScore(SP_RACE_TIME, "time", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME); - ScoreInfo_SetLabel_PlayerScore(SP_RACE_FASTEST, "fastest", SFL_LOWER_IS_BETTER | SFL_TIME); - } - ScoreRules_basics_end(); + GameRules_score_enabled(false); + GameRules_scoring(race_teams, 0, 0, { + if (race_teams) { + field_team(ST_RACE_LAPS, "laps", SFL_SORT_PRIO_PRIMARY); + field(SP_RACE_LAPS, "laps", SFL_SORT_PRIO_PRIMARY); + field(SP_RACE_TIME, "time", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME); + field(SP_RACE_FASTEST, "fastest", SFL_LOWER_IS_BETTER | SFL_TIME); + } else if (g_race_qualifying) { + field(SP_RACE_FASTEST, "fastest", SFL_SORT_PRIO_PRIMARY | SFL_LOWER_IS_BETTER | SFL_TIME); + } else { + field(SP_RACE_LAPS, "laps", SFL_SORT_PRIO_PRIMARY); + field(SP_RACE_TIME, "time", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME); + field(SP_RACE_FASTEST, "fastest", SFL_LOWER_IS_BETTER | SFL_TIME); + } + }); } void race_EventLog(string mode, entity actor) // use an alias for easy changing and quick editing later @@ -443,7 +439,7 @@ void rc_SetLimits() if(autocvar_g_race_teams) { - ActivateTeamplay(); + GameRules_teams(true); race_teams = bound(2, autocvar_g_race_teams, 4); int teams = 0; if(race_teams >= 1) teams |= BIT(0); @@ -484,5 +480,8 @@ void rc_SetLimits() } else g_race_qualifying = 0; - SetLimits(fraglimit_override, leadlimit_override, timelimit_override, qualifying_override); + GameRules_limit_score(fraglimit_override); + GameRules_limit_lead(leadlimit_override); + GameRules_limit_time(timelimit_override); + GameRules_limit_time_qualifying(qualifying_override); } diff --git a/qcsrc/server/mutators/mutator/gamemode_tdm.qh b/qcsrc/server/mutators/mutator/gamemode_tdm.qh index e7efbae7f..5946f84a8 100644 --- a/qcsrc/server/mutators/mutator/gamemode_tdm.qh +++ b/qcsrc/server/mutators/mutator/gamemode_tdm.qh @@ -15,8 +15,9 @@ REGISTER_MUTATOR(tdm, false) error("This is a game type and it cannot be added at runtime."); InitializeEntity(NULL, tdm_DelayedInit, INITPRIO_GAMETYPE); - ActivateTeamplay(); - SetLimits(autocvar_g_tdm_point_limit, autocvar_g_tdm_point_leadlimit, autocvar_timelimit_override, -1); + GameRules_teams(true); + GameRules_limit_score(autocvar_g_tdm_point_limit); + GameRules_limit_lead(autocvar_g_tdm_point_leadlimit); if (autocvar_g_tdm_team_spawns) have_team_spawns = -1; // request team spawns } diff --git a/qcsrc/server/scores_rules.qc b/qcsrc/server/scores_rules.qc index 97e80409c..2b539c999 100644 --- a/qcsrc/server/scores_rules.qc +++ b/qcsrc/server/scores_rules.qc @@ -4,6 +4,7 @@ #include #include "client.qh" #include "scores.qh" +#include int ScoreRules_teams; @@ -57,17 +58,13 @@ void ScoreRules_basics_end() } void ScoreRules_generic() { - if(teamplay) - { + int teams = 0; + if (teamplay) { CheckAllowedTeams(NULL); - int teams = 0; - if(c1 >= 0) teams |= BIT(0); - if(c2 >= 0) teams |= BIT(1); - if(c3 >= 0) teams |= BIT(2); - if(c4 >= 0) teams |= BIT(3); - ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, true); + if (c1 >= 0) teams |= BIT(0); + if (c2 >= 0) teams |= BIT(1); + if (c3 >= 0) teams |= BIT(2); + if (c4 >= 0) teams |= BIT(3); } - else - ScoreRules_basics(0, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, true); - ScoreRules_basics_end(); + GameRules_scoring(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, {}); } diff --git a/qcsrc/server/teamplay.qc b/qcsrc/server/teamplay.qc index eda9b958b..e93a03201 100644 --- a/qcsrc/server/teamplay.qc +++ b/qcsrc/server/teamplay.qc @@ -37,13 +37,6 @@ void default_delayedinit(entity this) ScoreRules_generic(); } -void ActivateTeamplay() -{ - serverflags |= SERVERFLAG_TEAMPLAY; - teamplay = 1; - cvar_set("teamplay", "2"); // DP needs this for sending proper getstatus replies. -} - void InitGameplayMode() { VoteReset(); @@ -59,9 +52,7 @@ void InitGameplayMode() max_shot_distance = min(230000, vlen(world.maxs - world.mins)); MapInfo_LoadMapSettings(mapname); - serverflags &= ~SERVERFLAG_TEAMPLAY; - teamplay = 0; - cvar_set("teamplay", "0"); // DP needs this for sending proper getstatus replies. + GameRules_teams(false); if (!cvar_value_issafe(world.fog)) { diff --git a/qcsrc/server/teamplay.qh b/qcsrc/server/teamplay.qh index 127ac7a6d..8d0ea9cb8 100644 --- a/qcsrc/server/teamplay.qh +++ b/qcsrc/server/teamplay.qh @@ -18,8 +18,6 @@ void LogTeamchange(float player_id, float team_number, float type); void default_delayedinit(entity this); -void ActivateTeamplay(); - void InitGameplayMode(); string GetClientVersionMessage(entity this); -- 2.39.2