Skip to content

Commit 0970aa9

Browse files
authored
Gamemode specific score / round limits (#1887)
1 parent 83d1c70 commit 0970aa9

2 files changed

Lines changed: 113 additions & 17 deletions

File tree

src/game/shared/neo/neo_gamerules.cpp

Lines changed: 110 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,60 @@ const NeoGameTypeSettings NEO_GAME_TYPE_SETTINGS[NEO_GAME_TYPE__TOTAL] = {
419419
// convert a velocity in ft/sec and a mass in grains to an impulse in kg in/s
420420
#define BULLET_IMPULSE(grains, ftpersec) ((ftpersec)*12*BULLET_MASS_GRAINS_TO_KG(grains)*BULLET_IMPULSE_EXAGGERATION)
421421

422+
extern ConVar neo_score_limit;
423+
extern ConVar neo_round_limit;
424+
extern ConVar sv_neo_ctg_score_limit;
425+
extern ConVar sv_neo_ctg_round_limit;
426+
427+
static void neoScoreLimitLegacyCallback(IConVar* var, const char* pOldValue, float flOldValue)
428+
{
429+
Warning("Using legacy neo_score_limit cvar. Use sv_neo_[gamemode]_score_limit instead!\n");
430+
sv_neo_ctg_score_limit.SetValue(neo_score_limit.GetInt());
431+
}
432+
433+
static void neoRoundLimitLegacyCallback(IConVar* var, const char* pOldValue, float flOldValue)
434+
{
435+
Warning("Using legacy neo_round_limit cvar. Use sv_neo_[gamemode]_round_limit instead!\n");
436+
sv_neo_ctg_round_limit.SetValue(neo_round_limit.GetInt());
437+
}
438+
439+
ConVar neo_score_limit("neo_score_limit", "7", FCVAR_REPLICATED | FCVAR_HIDDEN, "(Legacy) Neo score limit.", true, 0.0f, true, 99.0f
440+
#ifdef GAME_DLL
441+
, neoScoreLimitLegacyCallback
442+
#endif
443+
);
444+
ConVar neo_round_limit("neo_round_limit", "0", FCVAR_REPLICATED | FCVAR_HIDDEN, "(Legacy) Max amount of rounds, 0 for no limit.", true, 0.0f, false, 0.0f
445+
#ifdef GAME_DLL
446+
, neoRoundLimitLegacyCallback
447+
#endif
448+
);
422449

423-
ConVar neo_score_limit("neo_score_limit", "7", FCVAR_REPLICATED, "Neo score limit.", true, 0.0f, true, 99.0f);
424-
ConVar neo_round_limit("neo_round_limit", "0", FCVAR_REPLICATED, "Max amount of rounds, 0 for no limit.", true, 0.0f, false, 0.0f);
425450
ConVar neo_round_sudden_death("neo_round_sudden_death", "1", FCVAR_REPLICATED, "If neo_round_limit is not 0 and round is past "
426451
"neo_round_limit, go into sudden death where match won't end until a team won.", true, 0.0f, true, 1.0f);
427452

453+
// Score Limit
454+
ConVar sv_neo_tdm_score_limit("sv_neo_tdm_score_limit", "1", FCVAR_REPLICATED, "TDM score limit", true, 0.0f, true, 99.0f);
455+
456+
ConVar sv_neo_ctg_score_limit("sv_neo_ctg_score_limit", "7", FCVAR_REPLICATED, "CTG score limit", true, 0.0f, true, 99.0f);
457+
458+
ConVar sv_neo_vip_score_limit("sv_neo_vip_score_limit", "7", FCVAR_REPLICATED, "VIP score limit", true, 0.0f, true, 99.0f);
459+
460+
ConVar sv_neo_dm_score_limit("sv_neo_dm_score_limit", "7", FCVAR_REPLICATED, "DM score limit", true, 0.0f, true, 99.0f);
461+
462+
ConVar sv_neo_jgr_score_limit("sv_neo_jgr_score_limit", "0", FCVAR_REPLICATED, "JGR score limit", true, 0.0f, true, 99.0f);
463+
464+
// Round Limit
465+
ConVar sv_neo_tdm_round_limit("sv_neo_tdm_round_limit", "0", FCVAR_REPLICATED, "TDM max amount of rounds, 0 for no limit.", true, 0.0f, false, 0.0f);
466+
467+
ConVar sv_neo_ctg_round_limit("sv_neo_ctg_round_limit", "0", FCVAR_REPLICATED, "CTG max amount of rounds, 0 for no limit.", true, 0.0f, false, 0.0f);
468+
469+
ConVar sv_neo_vip_round_limit("sv_neo_vip_round_limit", "0", FCVAR_REPLICATED, "VIP max amount of rounds, 0 for no limit.", true, 0.0f, false, 0.0f);
470+
471+
ConVar sv_neo_dm_round_limit("sv_neo_dm_round_limit", "0", FCVAR_REPLICATED, "DM max amount of rounds, 0 for no limit.", true, 0.0f, false, 0.0f);
472+
473+
ConVar sv_neo_jgr_round_limit("sv_neo_jgr_round_limit", "5", FCVAR_REPLICATED, "JGR max amount of rounds, 0 for no limit.", true, 0.0f, false, 0.0f);
474+
475+
// Round Time Limit (make these sv_neo at some point)
428476
ConVar neo_tdm_round_timelimit("neo_tdm_round_timelimit", "10.25", FCVAR_REPLICATED, "TDM round timelimit, in minutes.",
429477
true, 0.0f, false, 600.0f);
430478

@@ -2589,6 +2637,56 @@ CNEORules::ReadyPlayers CNEORules::FetchReadyPlayers() const
25892637
return readyPlayers;
25902638
}
25912639

2640+
const int CNEORules::GetScoreLimit() const
2641+
{
2642+
switch (m_nGameTypeSelected)
2643+
{
2644+
case NEO_GAME_TYPE_TDM:
2645+
return sv_neo_tdm_score_limit.GetInt();
2646+
break;
2647+
case NEO_GAME_TYPE_CTG:
2648+
return sv_neo_ctg_score_limit.GetInt();
2649+
break;
2650+
case NEO_GAME_TYPE_VIP:
2651+
return sv_neo_vip_score_limit.GetInt();
2652+
break;
2653+
case NEO_GAME_TYPE_DM:
2654+
return sv_neo_dm_score_limit.GetInt();
2655+
break;
2656+
case NEO_GAME_TYPE_JGR:
2657+
return sv_neo_jgr_score_limit.GetInt();
2658+
break;
2659+
default:
2660+
return sv_neo_ctg_score_limit.GetInt();
2661+
break;
2662+
}
2663+
}
2664+
2665+
const int CNEORules::GetRoundLimit() const
2666+
{
2667+
switch (m_nGameTypeSelected)
2668+
{
2669+
case NEO_GAME_TYPE_TDM:
2670+
return sv_neo_tdm_round_limit.GetInt();
2671+
break;
2672+
case NEO_GAME_TYPE_CTG:
2673+
return sv_neo_ctg_round_limit.GetInt();
2674+
break;
2675+
case NEO_GAME_TYPE_VIP:
2676+
return sv_neo_vip_round_limit.GetInt();
2677+
break;
2678+
case NEO_GAME_TYPE_DM:
2679+
return sv_neo_dm_round_limit.GetInt();
2680+
break;
2681+
case NEO_GAME_TYPE_JGR:
2682+
return sv_neo_jgr_round_limit.GetInt();
2683+
break;
2684+
default:
2685+
return sv_neo_ctg_round_limit.GetInt();
2686+
break;
2687+
}
2688+
}
2689+
25922690
void CNEORules::StartNextRound()
25932691
{
25942692
// Only check ready-up on idle state
@@ -3534,7 +3632,7 @@ bool CNEORules::RoundIsInSuddenDeath() const
35343632
auto teamNSF = GetGlobalTeam(TEAM_NSF);
35353633
if (teamJinrai && teamNSF)
35363634
{
3537-
return (neo_round_limit.GetInt() != 0 && (m_iRoundNumber > neo_round_limit.GetInt()) && teamJinrai->GetRoundsWon() == teamNSF->GetRoundsWon());
3635+
return (GetRoundLimit() != 0 && (m_iRoundNumber > GetRoundLimit()) && teamJinrai->GetRoundsWon() == teamNSF->GetRoundsWon());
35383636
}
35393637
return false;
35403638
#endif
@@ -3547,10 +3645,10 @@ bool CNEORules::RoundIsMatchPoint() const
35473645
#else
35483646
auto teamJinrai = GetGlobalTeam(TEAM_JINRAI);
35493647
auto teamNSF = GetGlobalTeam(TEAM_NSF);
3550-
if (teamJinrai && teamNSF && neo_round_limit.GetInt() != 0)
3648+
if (teamJinrai && teamNSF && GetRoundLimit() != 0)
35513649
{
35523650
if (RoundIsInSuddenDeath()) return false;
3553-
const int roundDiff = neo_round_limit.GetInt() - m_iRoundNumber;
3651+
const int roundDiff = GetRoundLimit() - m_iRoundNumber;
35543652
if ((teamJinrai->GetRoundsWon() + 1) > (teamNSF->GetRoundsWon() + roundDiff)) return true;
35553653
if ((teamNSF->GetRoundsWon() + 1) > (teamJinrai->GetRoundsWon() + roundDiff)) return true;
35563654
return false;
@@ -3566,9 +3664,9 @@ bool CNEORules::RoundIsDoOrDie() const
35663664
#else
35673665
auto teamJinrai = GetGlobalTeam(TEAM_JINRAI);
35683666
auto teamNSF = GetGlobalTeam(TEAM_NSF);
3569-
if (teamJinrai && teamNSF && neo_round_limit.GetInt() != 0)
3667+
if (teamJinrai && teamNSF && GetRoundLimit() != 0)
35703668
{
3571-
const int roundsLeft = neo_round_limit.GetInt() - m_iRoundNumber + 1;
3669+
const int roundsLeft = GetRoundLimit() - m_iRoundNumber + 1;
35723670
if ((teamJinrai->GetRoundsWon() + roundsLeft) == teamNSF->GetRoundsWon()) return true;
35733671
if ((teamNSF->GetRoundsWon() + roundsLeft) == teamJinrai->GetRoundsWon()) return true;
35743672
return false;
@@ -3630,14 +3728,9 @@ void CNEORules::SetWinningTeam(int team, int iWinReason, bool bForceMapReset, bo
36303728
auto teamJinrai = GetGlobalTeam(TEAM_JINRAI);
36313729
auto teamNSF = GetGlobalTeam(TEAM_NSF);
36323730

3633-
if (neo_score_limit.GetInt() != 0)
3731+
if (GetScoreLimit() != 0)
36343732
{
3635-
#ifdef DEBUG
3636-
float neoScoreLimitMin = -1.0f;
3637-
AssertOnce(neo_score_limit.GetMin(neoScoreLimitMin));
3638-
AssertOnce(neoScoreLimitMin >= 0);
3639-
#endif
3640-
if (winningTeam->GetRoundsWon() >= neo_score_limit.GetInt())
3733+
if (winningTeam->GetRoundsWon() >= GetScoreLimit())
36413734
{
36423735
V_sprintf_safe(victoryMsg, "Team %s wins the match!\n", (team == TEAM_JINRAI ? "Jinrai" : "NSF"));
36433736
gotMatchWinner = true;
@@ -3646,14 +3739,14 @@ void CNEORules::SetWinningTeam(int team, int iWinReason, bool bForceMapReset, bo
36463739

36473740
// If a hard round limit is set, end the game and show the team
36483741
// that won with the most score, sudden death, or tie out
3649-
if (neo_round_limit.GetInt() != 0 && teamJinrai && teamNSF)
3742+
if (GetRoundLimit() != 0 && teamJinrai && teamNSF)
36503743
{
36513744
// If there's a round limit and the other team cannot really catch up with the
36523745
// winning team, then end the match early.
36533746
bool earlyWin = false;
36543747
if (!RoundIsInSuddenDeath())
36553748
{
3656-
const int roundDiff = neo_round_limit.GetInt() - m_iRoundNumber;
3749+
const int roundDiff = GetRoundLimit() - m_iRoundNumber;
36573750
earlyWin = (earlyWin || (teamJinrai->GetRoundsWon() > (teamNSF->GetRoundsWon() + roundDiff)));
36583751
earlyWin = (earlyWin || (teamNSF->GetRoundsWon() > (teamJinrai->GetRoundsWon() + roundDiff)));
36593752
}
@@ -3663,7 +3756,7 @@ void CNEORules::SetWinningTeam(int team, int iWinReason, bool bForceMapReset, bo
36633756
((teamJinrai->GetRoundsWon() > teamNSF->GetRoundsWon()) ? "Jinrai" : "NSF"));
36643757
gotMatchWinner = true;
36653758
}
3666-
else if (m_iRoundNumber >= neo_round_limit.GetInt())
3759+
else if (m_iRoundNumber >= GetRoundLimit())
36673760
{
36683761
if (teamJinrai->GetRoundsWon() == teamNSF->GetRoundsWon())
36693762
{

src/game/shared/neo/neo_gamerules.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,9 @@ class CNEORules : public CHL2MPRules, public CGameEventListener
437437
void ResetMapSessionCommon();
438438

439439
#ifdef GAME_DLL
440+
const int GetScoreLimit() const;
441+
const int GetRoundLimit() const;
442+
440443
void SpawnTheGhost(const Vector *origin = nullptr);
441444
void SpawnTheJuggernaut(const Vector *origin = nullptr);
442445
void SelectTheVIP();

0 commit comments

Comments
 (0)