From 4e09f4bdf506c34794a244e405ccfb72b8b83420 Mon Sep 17 00:00:00 2001 From: Blixibon Date: Wed, 17 Mar 2021 16:55:54 -0500 Subject: [PATCH] Added rr_disableemptyrules cvar, which prevents rules from being selected again after their norepeat/speakonce responses are exhausted --- .../responserules/runtime/response_system.cpp | 42 +++++++++++++++++++ .../responserules/runtime/response_system.h | 4 ++ 2 files changed, 46 insertions(+) diff --git a/sp/src/responserules/runtime/response_system.cpp b/sp/src/responserules/runtime/response_system.cpp index 60fedddb..15950b07 100644 --- a/sp/src/responserules/runtime/response_system.cpp +++ b/sp/src/responserules/runtime/response_system.cpp @@ -12,6 +12,9 @@ #include "convar.h" #include "fmtstr.h" #include "generichash.h" +#ifdef MAPBASE +#include "tier1/mapbase_matchers_base.h" +#endif // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" @@ -86,6 +89,10 @@ ConVar rr_dumpresponses( "rr_dumpresponses", "0", FCVAR_NONE, "Dump all response ConVar rr_debugresponseconcept( "rr_debugresponseconcept", "", FCVAR_NONE, "If set, rr_debugresponses will print only responses testing for the specified concept" ); #define RR_DEBUGRESPONSES_SPECIALCASE 4 +#ifdef MAPBASE +ConVar rr_disableemptyrules( "rr_disableemptyrules", "0", FCVAR_NONE, "Disables rules with no remaining responses, e.g. rules which use norepeat responses." ); +#endif + //----------------------------------------------------------------------------- @@ -788,6 +795,38 @@ void CResponseSystem::ResetResponseGroups() } } +#ifdef MAPBASE +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CResponseSystem::DisableEmptyRules() +{ + if (rr_disableemptyrules.GetBool() == false) + return; + + for ( ResponseRulePartition::tIndex idx = m_RulePartitions.First() ; + m_RulePartitions.IsValid(idx) ; + idx = m_RulePartitions.Next(idx) ) + { + Rule &rule = m_RulePartitions[ idx ]; + + // Set it as disabled in advance + rule.m_bEnabled = false; + + int c2 = rule.m_Responses.Count(); + for (int s = 0; s < c2; s++) + { + if (m_Responses[rule.m_Responses[s]].IsEnabled()) + { + // Re-enable it if there's any valid responses + rule.m_bEnabled = true; + break; + } + } + } +} +#endif + //----------------------------------------------------------------------------- // Purpose: Make certain responses unavailable by marking them as depleted //----------------------------------------------------------------------------- @@ -863,6 +902,9 @@ int CResponseSystem::SelectWeightedResponseFromResponseGroup( ResponseGroup *g, if ( g->IsNoRepeat() ) { g->SetEnabled( false ); +#ifdef MAPBASE + DisableEmptyRules(); +#endif return -1; } } diff --git a/sp/src/responserules/runtime/response_system.h b/sp/src/responserules/runtime/response_system.h index 9849b5a9..b675e816 100644 --- a/sp/src/responserules/runtime/response_system.h +++ b/sp/src/responserules/runtime/response_system.h @@ -241,6 +241,10 @@ public: float LookupEnumeration( const char *name, bool& found ); ResponseRulePartition::tIndex FindBestMatchingRule( const CriteriaSet& set, bool verbose, float &scoreOfBestMatchingRule ); + +#ifdef MAPBASE + void DisableEmptyRules(); +#endif float ScoreCriteriaAgainstRule( const CriteriaSet& set, ResponseRulePartition::tRuleDict &dict, int irule, bool verbose = false ); float RecursiveScoreSubcriteriaAgainstRule( const CriteriaSet& set, Criteria *parent, bool& exclude, bool verbose /*=false*/ );