Added rr_disableemptyrules cvar, which prevents rules from being selected again after their norepeat/speakonce responses are exhausted

This commit is contained in:
Blixibon 2021-03-17 16:55:54 -05:00
parent 4b8da761ce
commit 4e09f4bdf5
2 changed files with 46 additions and 0 deletions

View File

@ -12,6 +12,9 @@
#include "convar.h" #include "convar.h"
#include "fmtstr.h" #include "fmtstr.h"
#include "generichash.h" #include "generichash.h"
#ifdef MAPBASE
#include "tier1/mapbase_matchers_base.h"
#endif
// memdbgon must be the last include file in a .cpp file!!! // memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h" #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" ); 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 #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 // Purpose: Make certain responses unavailable by marking them as depleted
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -863,6 +902,9 @@ int CResponseSystem::SelectWeightedResponseFromResponseGroup( ResponseGroup *g,
if ( g->IsNoRepeat() ) if ( g->IsNoRepeat() )
{ {
g->SetEnabled( false ); g->SetEnabled( false );
#ifdef MAPBASE
DisableEmptyRules();
#endif
return -1; return -1;
} }
} }

View File

@ -242,6 +242,10 @@ public:
ResponseRulePartition::tIndex FindBestMatchingRule( const CriteriaSet& set, bool verbose, float &scoreOfBestMatchingRule ); 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 ScoreCriteriaAgainstRule( const CriteriaSet& set, ResponseRulePartition::tRuleDict &dict, int irule, bool verbose = false );
float RecursiveScoreSubcriteriaAgainstRule( const CriteriaSet& set, Criteria *parent, bool& exclude, bool verbose /*=false*/ ); float RecursiveScoreSubcriteriaAgainstRule( const CriteriaSet& set, Criteria *parent, bool& exclude, bool verbose /*=false*/ );
float ScoreCriteriaAgainstRuleCriteria( const CriteriaSet& set, int icriterion, bool& exclude, bool verbose = false ); float ScoreCriteriaAgainstRuleCriteria( const CriteriaSet& set, int icriterion, bool& exclude, bool verbose = false );