This commit is contained in:
nephacks
2025-06-04 03:22:50 +02:00
parent f234f23848
commit f12416cffd
14243 changed files with 6446499 additions and 26 deletions

View File

@@ -0,0 +1,52 @@
// ----------------------------------------- //
// File generated by VPC //
// ----------------------------------------- //
Source file: F:\csgo_64\cstrike15_src\responserules\runtime\criteriaset.cpp
Debug output file: F:\csgo_64\cstrike15_src\responserules\runtime\criteriaset.cpp
Release output file: F:\csgo_64\cstrike15_src\responserules\runtime\criteriaset.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\common\debug_lib_check.cpp
Debug output file: F:\csgo_64\cstrike15_src\common\debug_lib_check.cpp
Release output file: F:\csgo_64\cstrike15_src\common\debug_lib_check.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\responserules\runtime\response_system.cpp
Debug output file: F:\csgo_64\cstrike15_src\responserules\runtime\response_system.cpp
Release output file: F:\csgo_64\cstrike15_src\responserules\runtime\response_system.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\responserules\runtime\response_types.cpp
Debug output file: F:\csgo_64\cstrike15_src\responserules\runtime\response_types.cpp
Release output file: F:\csgo_64\cstrike15_src\responserules\runtime\response_types.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\responserules\runtime\response_types_internal.cpp
Debug output file: F:\csgo_64\cstrike15_src\responserules\runtime\response_types_internal.cpp
Release output file: F:\csgo_64\cstrike15_src\responserules\runtime\response_types_internal.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\responserules\runtime\rr_response.cpp
Debug output file: F:\csgo_64\cstrike15_src\responserules\runtime\rr_response.cpp
Release output file: F:\csgo_64\cstrike15_src\responserules\runtime\rr_response.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\responserules\runtime\rr_speechconcept.cpp
Debug output file: F:\csgo_64\cstrike15_src\responserules\runtime\rr_speechconcept.cpp
Release output file: F:\csgo_64\cstrike15_src\responserules\runtime\rr_speechconcept.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\responserules\runtime\rrrlib.cpp
Debug output file: F:\csgo_64\cstrike15_src\responserules\runtime\rrrlib.cpp
Release output file: F:\csgo_64\cstrike15_src\responserules\runtime\rrrlib.cpp
Containing unity file:
PCH file:

View File

@@ -0,0 +1,470 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#include "rrbase.h"
#include "utlmap.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
using namespace ResponseRules;
//-----------------------------------------------------------------------------
// Case-insensitive criteria symbol table
//-----------------------------------------------------------------------------
CUtlSymbolTable CriteriaSet::sm_CriteriaSymbols( 1024, 1024, true );
//-----------------------------------------------------------------------------
// Purpose:
// Input : *raw -
// *key -
// keylen -
// *value -
// valuelen -
// *duration -
// Output : static bool
//-----------------------------------------------------------------------------
const char *SplitContext( const char *raw, char *key, int keylen, char *value, int valuelen, float *duration, const char *entireContext )
{
char *colon1 = Q_strstr( raw, ":" );
if ( !colon1 )
{
DevMsg( "SplitContext: warning, ignoring context '%s', missing colon separator!\n", raw );
*key = *value = 0;
return NULL;
}
int len = colon1 - raw;
Q_strncpy( key, raw, MIN( len + 1, keylen ) );
key[ MIN( len, keylen - 1 ) ] = 0;
bool last = false;
char *end = Q_strstr( colon1 + 1, "," );
if ( !end )
{
int remaining = Q_strlen( colon1 + 1 );
end = colon1 + 1 + remaining;
last = true;
}
char *colon2 = Q_strstr( colon1 + 1, ":" );
if ( colon2 && ( colon2 < end ) )
{
if ( duration )
*duration = atof( colon2 + 1 );
char durationStartChar = *(colon2 + 1);
if ( durationStartChar < '0' || durationStartChar > '9' )
{
DevMsg( "SplitContext: warning, ignoring context '%s', missing comma separator! Entire context was '%s'.\n", raw, entireContext );
*key = *value = 0;
return NULL;
}
len = MIN( colon2 - ( colon1 + 1 ), valuelen - 1 );
Q_strncpy( value, colon1 + 1, len + 1 );
value[ len ] = 0;
}
else
{
if ( duration )
*duration = 0.0;
len = MIN( end - ( colon1 + 1 ), valuelen - 1 );
Q_strncpy( value, colon1 + 1, len + 1 );
value[ len ] = 0;
}
return last ? NULL : end + 1;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CriteriaSet::CriteriaSet() : m_Lookup( 0, 0, CritEntry_t::LessFunc ), m_bOverrideOnAppend(true),
m_nNumPrefixedContexts(0)
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CriteriaSet::CriteriaSet( const CriteriaSet& src ) : m_Lookup( 0, 0, CritEntry_t::LessFunc ), m_nNumPrefixedContexts(src.m_nNumPrefixedContexts)
{
m_Lookup.EnsureCapacity( src.m_Lookup.Count() );
for ( short i = src.m_Lookup.FirstInorder();
i != src.m_Lookup.InvalidIndex();
i = src.m_Lookup.NextInorder( i ) )
{
m_Lookup.Insert( src.m_Lookup[ i ] );
}
}
CriteriaSet::CriteriaSet( const char *criteria, const char *value ) : m_Lookup( 0, 0, CritEntry_t::LessFunc ), m_bOverrideOnAppend(true)
{
AppendCriteria(criteria,value);
}
//-----------------------------------------------------------------------------
// Computes a symbol for the criteria
//-----------------------------------------------------------------------------
CriteriaSet::CritSymbol_t CriteriaSet::ComputeCriteriaSymbol( const char *criteria )
{
return sm_CriteriaSymbols.AddString( criteria );
}
//-----------------------------------------------------------------------------
// Computes a symbol for the criteria
//-----------------------------------------------------------------------------
void CriteriaSet::AppendCriteria( CriteriaSet::CritSymbol_t criteria, const char *value, float weight )
{
int idx = FindCriterionIndex( criteria );
if ( idx == -1 )
{
CritEntry_t entry;
entry.criterianame = criteria;
MEM_ALLOC_CREDIT();
idx = m_Lookup.Insert( entry );
if ( sm_CriteriaSymbols.String(criteria)[0] == kAPPLYTOWORLDPREFIX )
{
m_nNumPrefixedContexts += 1;
}
}
else // criteria already existed
{
// bail out if override existing criteria is not allowed
if ( !m_bOverrideOnAppend )
return;
}
CritEntry_t *entry = &m_Lookup[ idx ];
entry->SetValue( value );
entry->weight = weight;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *criteria -
// "" -
// 1.0f -
//-----------------------------------------------------------------------------
void CriteriaSet::AppendCriteria( const char *pCriteriaName, const char *value /*= ""*/, float weight /*= 1.0f*/ )
{
CUtlSymbol criteria = ComputeCriteriaSymbol( pCriteriaName );
AppendCriteria( criteria, value, weight );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *criteria -
// "" -
// 1.0f -
//-----------------------------------------------------------------------------
void CriteriaSet::AppendCriteria( const char *criteria, float value, float weight /*= 1.0f*/ )
{
char buf[32];
V_snprintf( buf, 32, "%f", value );
AppendCriteria( criteria, buf, weight );
}
//-----------------------------------------------------------------------------
// Removes criteria in a set
//-----------------------------------------------------------------------------
void CriteriaSet::RemoveCriteria( const char *criteria )
{
const int idx = FindCriterionIndex( criteria );
if ( idx == -1 )
return;
if ( criteria[0] == kAPPLYTOWORLDPREFIX )
{
Assert( m_nNumPrefixedContexts > 0 );
m_nNumPrefixedContexts = isel( m_nNumPrefixedContexts - 1, m_nNumPrefixedContexts - 1, 0 );
}
RemoveCriteria( idx, false );
}
// bTestForIndex tells us whether the calling function has already checked for a
// $ prefix and decremented m_nNumPrefixedContexts appropriately (false),
// or if this function should do that (true).
void CriteriaSet::RemoveCriteria( int idx, bool bTestForPrefix )
{
Assert( m_Lookup.IsValidIndex(idx) );
if ( bTestForPrefix )
{
if ( sm_CriteriaSymbols.String( m_Lookup[idx].criterianame )[0] == kAPPLYTOWORLDPREFIX )
{
Assert( m_nNumPrefixedContexts > 0 );
m_nNumPrefixedContexts = isel( m_nNumPrefixedContexts - 1, m_nNumPrefixedContexts - 1, 0 );
}
}
m_Lookup.RemoveAt( idx );
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : int
//-----------------------------------------------------------------------------
int CriteriaSet::GetCount() const
{
return m_Lookup.Count();
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *name -
// Output : int
//-----------------------------------------------------------------------------
int CriteriaSet::FindCriterionIndex( CritSymbol_t criteria ) const
{
CritEntry_t search;
search.criterianame = criteria;
int idx = m_Lookup.Find( search );
return ( idx == m_Lookup.InvalidIndex() ) ? -1 : idx;
}
int CriteriaSet::FindCriterionIndex( const char *name ) const
{
CUtlSymbol criteria = ComputeCriteriaSymbol( name );
return FindCriterionIndex( criteria );
}
//-----------------------------------------------------------------------------
// Returns the name symbol
//-----------------------------------------------------------------------------
CriteriaSet::CritSymbol_t CriteriaSet::GetNameSymbol( int nIndex ) const
{
if ( nIndex < 0 || nIndex >= (int)m_Lookup.Count() )
return UTL_INVAL_SYMBOL;
const CritEntry_t *entry = &m_Lookup[ nIndex ];
return entry->criterianame;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : index -
// Output : char const
//-----------------------------------------------------------------------------
const char *CriteriaSet::GetName( int index ) const
{
if ( index < 0 || index >= (int)m_Lookup.Count() )
return "";
else
{
const char *pCriteriaName = sm_CriteriaSymbols.String( m_Lookup[ index ].criterianame );
return pCriteriaName ? pCriteriaName : "";
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : index -
// Output : char const
//-----------------------------------------------------------------------------
const char *CriteriaSet::GetValue( int index ) const
{
if ( index < 0 || index >= (int)m_Lookup.Count() )
return "";
const CritEntry_t *entry = &m_Lookup[ index ];
return entry->value ? entry->value : "";
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : index -
// Output : float
//-----------------------------------------------------------------------------
float CriteriaSet::GetWeight( int index ) const
{
if ( index < 0 || index >= (int)m_Lookup.Count() )
return 1.0f;
const CritEntry_t *entry = &m_Lookup[ index ];
return entry->weight;
}
//-----------------------------------------------------------------------------
// Purpose: Merge another criteria set into this one.
//-----------------------------------------------------------------------------
void CriteriaSet::Merge( const CriteriaSet * RESTRICT otherCriteria )
{
Assert(otherCriteria);
if (!otherCriteria)
return;
// for now, just duplicate everything.
int count = otherCriteria->GetCount();
EnsureCapacity( count + GetCount() );
for ( int i = 0 ; i < count ; ++i )
{
AppendCriteria( otherCriteria->GetNameSymbol(i), otherCriteria->GetValue(i), otherCriteria->GetWeight(i) );
}
}
void CriteriaSet::Merge( const char *modifiers ) // add criteria parsed from a text string
{
// Always include any optional modifiers
if ( modifiers == NULL )
return;
char copy_modifiers[ 255 ];
const char *pCopy;
char key[ 128 ] = { 0 };
char value[ 128 ] = { 0 };
Q_strncpy( copy_modifiers, modifiers, sizeof( copy_modifiers ) );
pCopy = copy_modifiers;
while( pCopy )
{
pCopy = SplitContext( pCopy, key, sizeof( key ), value, sizeof( value ), NULL, modifiers );
if( *key && *value )
{
AppendCriteria( key, value, 1 );
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CriteriaSet::Describe() const
{
// build an alphabetized representation of the set for printing
typedef CUtlMap<const char *, const CritEntry_t *> tMap;
tMap m_TempMap( 0, m_Lookup.Count(), CaselessStringLessThan );
for ( short i = m_Lookup.FirstInorder(); i != m_Lookup.InvalidIndex(); i = m_Lookup.NextInorder( i ) )
{
const CritEntry_t *entry = &m_Lookup[ i ];
m_TempMap.Insert( sm_CriteriaSymbols.String( entry->criterianame ), entry );
}
for ( tMap::IndexType_t i = m_TempMap.FirstInorder(); i != m_TempMap.InvalidIndex(); i = m_TempMap.NextInorder( i ) )
{
// const CritEntry_t *entry = &m_TempMap[ i ];
// const char *pCriteriaName = sm_CriteriaSymbols.String( entry->criterianame );
const char *name;
name = m_TempMap.Key( i );
const CritEntry_t *entry = m_TempMap.Element( i );
if ( entry->weight != 1.0f )
{
DevMsg( " %20s = '%s' (weight %f)\n", name, entry->value ? entry->value : "", entry->weight );
}
else
{
DevMsg( " %20s = '%s'\n", name, entry->value ? entry->value : "" );
}
}
/*
for ( short i = m_Lookup.FirstInorder(); i != m_Lookup.InvalidIndex(); i = m_Lookup.NextInorder( i ) )
{
const CritEntry_t *entry = &m_Lookup[ i ];
const char *pCriteriaName = sm_CriteriaSymbols.String( entry->criterianame );
if ( entry->weight != 1.0f )
{
DevMsg( " %20s = '%s' (weight %f)\n", pCriteriaName, entry->value ? entry->value : "", entry->weight );
}
else
{
DevMsg( " %20s = '%s'\n", pCriteriaName, entry->value ? entry->value : "" );
}
}
*/
}
void CriteriaSet::Reset()
{
m_Lookup.Purge();
}
void CriteriaSet::WriteToEntity( CBaseEntity *pEntity )
{
#if 0
if ( GetCount() < 1 )
return;
for ( int i = Head() ; IsValidIndex(i); i = Next(i) )
{
pEntity->AddContext( GetName(i), GetValue(i), 0 );
}
#else
AssertMsg( false, "CriteriaSet::WriteToEntity has not been ported from l4d2.\n" );
#endif
}
int CriteriaSet::InterceptWorldSetContexts( CriteriaSet * RESTRICT pFrom, CriteriaSet * RESTRICT pSetOnWorld )
{
// Assert( pFrom ); Assert( pTo ); Assert( pSetOnWorld );
Assert( pSetOnWorld != pFrom );
Assert( pSetOnWorld->GetCount() == 0 );
if ( pFrom->m_nNumPrefixedContexts == 0 )
{
// nothing needs to be done to it.
return 0;
}
#ifdef DEBUG
// save this off for later error checking.
const int nPrefixedContexts = pFrom->m_nNumPrefixedContexts;
#endif
// make enough space for the expected output quantity.
pSetOnWorld->EnsureCapacity( pFrom->m_nNumPrefixedContexts );
// initialize a buffer with the "world" prefix (so we can use strncpy instead of snprintf and be much faster)
char buf[80] = { 'w', 'o', 'r', 'l', 'd', '\0' };
const unsigned int PREFIXLEN = 5; // strlen("world")
// create a second tree that has the appropriately renamed criteria,
// then swap it into pFrom
CriteriaSet rewrite;
rewrite.EnsureCapacity( pFrom->GetCount() + 1 );
for ( int i = pFrom->Head(); pFrom->IsValidIndex(i); i = pFrom->Next(i) )
{
const char *pszName = pFrom->GetName( i );
if ( pszName[0] == CriteriaSet::kAPPLYTOWORLDPREFIX )
{ // redirect to the world contexts
V_strncpy( buf+PREFIXLEN, pszName+1, sizeof(buf) - PREFIXLEN );
rewrite.AppendCriteria( buf, pFrom->GetValue(i), pFrom->GetWeight(i) );
pSetOnWorld->AppendCriteria( pszName+1, pFrom->GetValue(i), pFrom->GetWeight(i) );
buf[PREFIXLEN] = 0;
}
else
{ // does not need to be fiddled; do not write back to world
rewrite.AppendCriteria( pFrom->GetNameSymbol(i), pFrom->GetValue(i), pFrom->GetWeight(i) );
}
}
AssertMsg2( pSetOnWorld->GetCount() == nPrefixedContexts, "Count of $ persistent RR contexts is inconsistent (%d vs %d)! Call Elan.",
pSetOnWorld->GetCount(), nPrefixedContexts );
pFrom->m_nNumPrefixedContexts = 0;
pFrom->m_Lookup.Swap(rewrite.m_Lookup);
return pSetOnWorld->GetCount();
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,260 @@
//========= Copyright © 1996-2010, Valve Corporation, All rights reserved. ============//
//
// Purpose: Core types for the response rules -- criteria, responses, rules, and matchers.
//
// $NoKeywords: $
//=============================================================================//
#include "rrbase.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace ResponseRules;
// bizarre function handed down from the misty days of yore
// and the original response system. a lot of stuff uses it
// and I can't be arsed to replace everything with the c stdlib
// stuff
namespace ResponseRules
{
extern const char *ResponseCopyString( const char *in );
};
//-------------------- MATCHER ----------------------------------------------
Matcher::Matcher()
{
valid = false;
isnumeric = false;
notequal = false;
usemin = false;
minequals = false;
usemax = false;
maxequals = false;
maxval = 0.0f;
minval = 0.0f;
token = UTL_INVAL_SYMBOL;
rawtoken = UTL_INVAL_SYMBOL;
}
void Matcher::Describe( void )
{
if ( !valid )
{
DevMsg( " invalid!\n" );
return;
}
char sz[ 128 ];
sz[ 0] = 0;
int minmaxcount = 0;
if ( usemin )
{
Q_snprintf( sz, sizeof( sz ), ">%s%.3f", minequals ? "=" : "", minval );
minmaxcount++;
}
if ( usemax )
{
char sz2[ 128 ];
Q_snprintf( sz2, sizeof( sz2 ), "<%s%.3f", maxequals ? "=" : "", maxval );
if ( minmaxcount > 0 )
{
Q_strncat( sz, " and ", sizeof( sz ), COPY_ALL_CHARACTERS );
}
Q_strncat( sz, sz2, sizeof( sz ), COPY_ALL_CHARACTERS );
minmaxcount++;
}
if ( minmaxcount >= 1 )
{
DevMsg( " matcher: %s\n", sz );
return;
}
if ( notequal )
{
DevMsg( " matcher: !=%s\n", GetToken() );
return;
}
DevMsg( " matcher: ==%s\n", GetToken() );
}
void Matcher::SetToken( char const *s )
{
token = g_RS.AddString( s );
}
void Matcher::SetRaw( char const *raw )
{
rawtoken = g_RS.AddString( raw );
}
char const *Matcher::GetToken()
{
if ( token.IsValid() )
{
return g_RS.String( token );
}
return "";
}
char const *Matcher::GetRaw()
{
if ( rawtoken.IsValid() )
{
return g_RS.String( rawtoken );
}
return "";
}
//-------------------- CRITERIA ----------------------------------------------
Criteria::Criteria()
{
value = NULL;
weight.SetFloat( 1.0f );
required = false;
}
Criteria::Criteria(const Criteria& src )
{
operator=( src );
}
Criteria::~Criteria()
{
// do nothing because we don't own name and value anymore
}
Criteria& Criteria::operator =(const Criteria& src )
{
if ( this == &src )
return *this;
nameSym = src.nameSym;
value = ResponseCopyString( src.value );
weight = src.weight;
required = src.required;
matcher = src.matcher;
int c = src.subcriteria.Count();
subcriteria.EnsureCapacity( c );
for ( int i = 0; i < c; i++ )
{
subcriteria.AddToTail( src.subcriteria[ i ] );
}
return *this;
}
//-------------------- RESPONSE ----------------------------------------------
ParserResponse::ParserResponse() : m_followup()
{
type = RESPONSE_NONE;
value = NULL;
weight.SetFloat( 1.0f );
depletioncount = 0;
first = false;
last = false;
}
ParserResponse& ParserResponse::operator =( const ParserResponse& src )
{
if ( this == &src )
return *this;
weight = src.weight;
type = src.type;
value = ResponseCopyString( src.value );
depletioncount = src.depletioncount;
first = src.first;
last = src.last;
params = src.params;
m_followup.followup_concept = ResponseCopyString(src.m_followup.followup_concept);
m_followup.followup_contexts = ResponseCopyString(src.m_followup.followup_contexts);
m_followup.followup_target = ResponseCopyString(src.m_followup.followup_target);
m_followup.followup_entityioinput = ResponseCopyString(src.m_followup.followup_entityioinput);
m_followup.followup_entityiotarget = ResponseCopyString(src.m_followup.followup_entityiotarget);
m_followup.followup_delay = src.m_followup.followup_delay;
m_followup.followup_entityiodelay = src.m_followup.followup_entityiodelay;
return *this;
}
ParserResponse::ParserResponse( const ParserResponse& src )
{
operator=( src );
}
ParserResponse::~ParserResponse()
{
// nothing to do, since we don't own
// the strings anymore
}
// ------------ RULE ---------------
Rule::Rule() : m_nForceWeight(0)
{
m_bMatchOnce = false;
m_bEnabled = true;
m_szContext = NULL;
m_bApplyContextToWorld = false;
}
Rule& Rule::operator =( const Rule& src )
{
if ( this == &src )
return *this;
int i;
int c;
c = src.m_Criteria.Count();
m_Criteria.EnsureCapacity( c );
for ( i = 0; i < c; i++ )
{
m_Criteria.AddToTail( src.m_Criteria[ i ] );
}
c = src.m_Responses.Count();
m_Responses.EnsureCapacity( c );
for ( i = 0; i < c; i++ )
{
m_Responses.AddToTail( src.m_Responses[ i ] );
}
SetContext( src.m_szContext );
m_bMatchOnce = src.m_bMatchOnce;
m_bEnabled = src.m_bEnabled;
m_bApplyContextToWorld = src.m_bApplyContextToWorld;
m_nForceWeight = src.m_nForceWeight;
return *this;
}
Rule::Rule( const Rule& src )
{
operator=(src);
}
Rule::~Rule()
{
}
void Rule::SetContext( const char *context )
{
// we don't own the data we point to, so just update pointer
m_szContext = ResponseCopyString( context );
}

View File

@@ -0,0 +1,120 @@
//========= Copyright © 1996-2010, Valve Corporation, All rights reserved. ============//
//
// Purpose: Core types for the response rules -- criteria, responses, rules, and matchers.
//
// $NoKeywords: $
//=============================================================================//
#include "rrbase.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace ResponseRules;
ResponseRulePartition::ResponseRulePartition()
{
Assert(true);
COMPILE_TIME_ASSERT( kIDX_ELEM_MASK < (1 << 16) );
COMPILE_TIME_ASSERT( (kIDX_ELEM_MASK & (kIDX_ELEM_MASK + 1)) == 0 ); /// assert is power of two minus one
}
ResponseRulePartition::~ResponseRulePartition()
{
RemoveAll();
}
ResponseRulePartition::tIndex ResponseRulePartition::IndexFromDictElem( tRuleDict* pDict, int elem )
{
Assert( pDict );
// If this fails, you've tried to build an index for a rule that's not stored
// in this partition
Assert( pDict >= m_RuleParts && pDict < m_RuleParts + N_RESPONSE_PARTITIONS );
AssertMsg1( elem <= kIDX_ELEM_MASK, "A rule dictionary has %d elements; this exceeds the 255 that can be packed into an index.\n", elem );
int bucket = pDict - m_RuleParts;
return ( bucket << 16 ) | ( elem & kIDX_ELEM_MASK ); // this is a native op on PPC
}
char const *ResponseRulePartition::GetElementName( const tIndex &i ) const
{
Assert( IsValid(i) );
return m_RuleParts[ BucketFromIdx(i) ].GetElementName( PartFromIdx(i) );
}
int ResponseRulePartition::Count( void )
{
int count = 0 ;
for ( int bukkit = 0 ; bukkit < N_RESPONSE_PARTITIONS ; ++bukkit )
{
count += m_RuleParts[bukkit].Count();
}
return count;
}
void ResponseRulePartition::RemoveAll( void )
{
for ( int bukkit = 0 ; bukkit < N_RESPONSE_PARTITIONS ; ++bukkit )
{
for ( int i = m_RuleParts[bukkit].FirstInorder(); i != m_RuleParts[bukkit].InvalidIndex(); i = m_RuleParts[bukkit].NextInorder( i ) )
{
delete m_RuleParts[bukkit][ i ];
}
m_RuleParts[bukkit].RemoveAll();
}
}
// don't bucket "subject" criteria that prefix with operators, since stripping all that out again would
// be a big pain, and the most important rules that need subjects are tlk_remarks anyway.
static inline bool CanBucketBySubject( const char * RESTRICT pszSubject )
{
return pszSubject &&
( ( pszSubject[0] >= 'A' && pszSubject[0] <= 'Z' ) ||
( pszSubject[0] >= 'a' && pszSubject[0] <= 'z' ) );
}
ResponseRulePartition::tRuleDict &ResponseRulePartition::GetDictForRule( CResponseSystem *pSystem, Rule *pRule )
{
const static CUtlSymbol kWHO = CriteriaSet::ComputeCriteriaSymbol("Who");
const static CUtlSymbol kCONCEPT = CriteriaSet::ComputeCriteriaSymbol("Concept");
const static CUtlSymbol kSUBJECT = CriteriaSet::ComputeCriteriaSymbol("Subject");
const char *pszSpeaker = pRule->GetValueForRuleCriterionByName( pSystem, kWHO );
const char *pszConcept = pRule->GetValueForRuleCriterionByName( pSystem, kCONCEPT );
const Criteria *pSubjCrit = pRule->GetPointerForRuleCriterionByName( pSystem, kSUBJECT );
return m_RuleParts[
GetBucketForSpeakerAndConcept( pszSpeaker, pszConcept,
( pSubjCrit && pSubjCrit->required && CanBucketBySubject(pSubjCrit->value) ) ?
pSubjCrit->value :
NULL )
];
}
void ResponseRulePartition::GetDictsForCriteria( CUtlVectorFixed< ResponseRulePartition::tRuleDict *, 2 > *pResult, const CriteriaSet &criteria )
{
pResult->RemoveAll();
pResult->EnsureCapacity( 2 );
// get the values for Who and Concept, which are what we bucket on
int speakerIdx = criteria.FindCriterionIndex( "Who" );
const char *pszSpeaker = speakerIdx != -1 ? criteria.GetValue( speakerIdx ) : NULL ;
int conceptIdx = criteria.FindCriterionIndex( "Concept" );
const char *pszConcept = conceptIdx != -1 ? criteria.GetValue( conceptIdx ) : NULL ;
int subjectIdx = criteria.FindCriterionIndex( "Subject" );
const char *pszSubject = subjectIdx != -1 ? criteria.GetValue( subjectIdx ) : NULL ;
pResult->AddToTail( &m_RuleParts[ GetBucketForSpeakerAndConcept(pszSpeaker, pszConcept, pszSubject) ] );
// also try the rules not specifying subject
pResult->AddToTail( &m_RuleParts[ GetBucketForSpeakerAndConcept(pszSpeaker, pszConcept, NULL) ] );
}

View File

@@ -0,0 +1,48 @@
//-----------------------------------------------------------------------------
// RESPONSERULES_RUNTIME.VPC
//
// Project Script
//-----------------------------------------------------------------------------
$Macro SRCDIR "..\.."
$include "$SRCDIR\vpc_scripts\source_lib_base.vpc"
$Configuration
{
$Compiler
{
$AdditionalIncludeDirectories "$BASE;$SRCDIR\public"
}
}
$Project "responserules_runtime"
{
$Folder "Header Files"
{
$file "$SRCDIR\public\responserules\response_types.h"
$file "$SRCDIR\public\responserules\response_host_interface.h"
$file "$SRCDIR\public\responserules\rr_speechconcept.h"
$file "$SRCDIR\common\responserules\response_types_internal.h"
$file "$SRCDIR\responserules\responserules_cli\response_system.h"
$file "rrbase.h"
}
$Folder "Source Files"
{
$file "rrrlib.cpp"
$file "response_types.cpp"
$file "response_types_internal.cpp"
$file "response_system.cpp"
$file "rr_speechconcept.cpp"
$file "rr_response.cpp"
$file "criteriaset.cpp"
}
$Folder "Public Header Files"
{
$File "$SRCDIR\public\tier2\interval.h"
}
}

View File

@@ -0,0 +1,13 @@
"vpc_cache"
{
"CacheVersion" "1"
"win32"
{
"CRCFile" "responserules_runtime.vcxproj.vpc_crc"
"OutputFiles"
{
"0" "responserules_runtime.vcxproj"
"1" "responserules_runtime.vcxproj.filters"
}
}
}

View File

@@ -0,0 +1,14 @@
//========= Copyright © 1996-2010, Valve Corporation, All rights reserved. ============//
//
// Purpose: Convars used by the response rule system.
//
// $NoKeywords: $
//=============================================================================//
#include "rrbase.h"
#include <convar.h>
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

View File

@@ -0,0 +1,311 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#include "rrbase.h"
#include <tier2/interval.h>
/*
#include "AI_Criteria.h"
#include "ai_speech.h"
#include <keyvalues.h>
#include "engine/IEngineSound.h"
*/
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
using namespace ResponseRules;
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CRR_Response::CRR_Response() : m_fMatchScore(0)
{
m_Type = ResponseRules::RESPONSE_NONE;
m_szResponseName[0] = 0;
m_szMatchingRule[0]=0;
m_szContext = NULL;
m_bApplyContextToWorld = false;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
CRR_Response::CRR_Response( const CRR_Response &from ) : m_fMatchScore(0)
{
// Assert( (void*)(&m_Type) == (void*)this );
Invalidate();
memcpy( this, &from, sizeof(*this) );
m_szContext = NULL;
SetContext( from.m_szContext );
m_bApplyContextToWorld = from.m_bApplyContextToWorld;
}
//-----------------------------------------------------------------------------
CRR_Response &CRR_Response::operator=( const CRR_Response &from )
{
// Assert( (void*)(&m_Type) == (void*)this );
Invalidate();
memcpy( this, &from, sizeof(*this) );
m_szContext = NULL;
SetContext( from.m_szContext );
m_bApplyContextToWorld = from.m_bApplyContextToWorld;
return *this;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CRR_Response::~CRR_Response()
{
if (m_szContext)
delete[] m_szContext;
}
void CRR_Response::Invalidate()
{
if (m_szContext)
{
delete[] m_szContext;
m_szContext = NULL;
}
m_Type = ResponseRules::RESPONSE_NONE;
m_szResponseName[0] = 0;
// not really necessary:
/*
m_szMatchingRule[0]=0;
m_szContext = NULL;
m_bApplyContextToWorld = false;
*/
}
// please do not new or delete CRR_Responses.
void CRR_Response::operator delete(void* p)
{
AssertMsg(false, "DO NOT new or delete CRR_Response s.");
free(p);
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *response -
// *criteria -
//-----------------------------------------------------------------------------
void CRR_Response::Init( ResponseType_t type, const char *responseName, const ResponseParams& responseparams, const char *ruleName, const char *applyContext, bool bApplyContextToWorld )
{
m_Type = type;
Q_strncpy( m_szResponseName, responseName, sizeof( m_szResponseName ) );
// Copy underlying criteria
Q_strncpy( m_szMatchingRule, ruleName ? ruleName : "NULL", sizeof( m_szMatchingRule ) );
m_Params = responseparams;
SetContext( applyContext );
m_bApplyContextToWorld = bApplyContextToWorld;
}
//-----------------------------------------------------------------------------
// Purpose: Debug-print the response. You can optionally pass in the criteria
// used to come up with this response (usually present in the calling function)
// if you want to print that as well. DO NOT store the entire criteria set in
// CRR_Response just to make this debug print cleaner.
//-----------------------------------------------------------------------------
void CRR_Response::Describe( const CriteriaSet *pDebugCriteria )
{
if ( pDebugCriteria )
{
DevMsg( "Search criteria:\n" );
pDebugCriteria->Describe();
}
if ( m_szMatchingRule[ 0 ] )
{
DevMsg( "Matched rule '%s', ", m_szMatchingRule );
}
if ( m_szContext )
{
DevMsg( "Contexts to set '%s' on %s, ", m_szContext, m_bApplyContextToWorld ? "world" : "speaker" );
}
DevMsg( "response %s = '%s'\n", DescribeResponse( (ResponseType_t)m_Type ), m_szResponseName );
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : char const
//-----------------------------------------------------------------------------
void CRR_Response::GetName( char *buf, size_t buflen ) const
{
Q_strncpy( buf, m_szResponseName, buflen );
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : char const
//-----------------------------------------------------------------------------
void CRR_Response::GetResponse( char *buf, size_t buflen ) const
{
GetName( buf, buflen );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : type -
// Output : char const
//-----------------------------------------------------------------------------
const char *CRR_Response::DescribeResponse( ResponseType_t type )
{
if ( (int)type < 0 || (int)type >= ResponseRules::NUM_RESPONSES )
{
Assert( 0 );
return "???CRR_Response bogus index";
}
switch( type )
{
default:
{
Assert( 0 );
}
// Fall through
case ResponseRules::RESPONSE_NONE:
return "RESPONSE_NONE";
case ResponseRules::RESPONSE_SPEAK:
return "RESPONSE_SPEAK";
case ResponseRules::RESPONSE_SENTENCE:
return "RESPONSE_SENTENCE";
case ResponseRules::RESPONSE_SCENE:
return "RESPONSE_SCENE";
case ResponseRules::RESPONSE_RESPONSE:
return "RESPONSE_RESPONSE";
case ResponseRules::RESPONSE_PRINT:
return "RESPONSE_PRINT";
case ResponseRules::RESPONSE_ENTITYIO:
return "RESPONSE_ENTITYIO";
}
return "RESPONSE_NONE";
}
/*
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CRR_Response::Release()
{
delete this;
}
*/
//-----------------------------------------------------------------------------
// Purpose:
// Output : soundlevel_t
//-----------------------------------------------------------------------------
soundlevel_t CRR_Response::GetSoundLevel() const
{
if ( m_Params.flags & ResponseParams::RG_SOUNDLEVEL )
{
return (soundlevel_t)m_Params.soundlevel;
}
return SNDLVL_TALKING;
}
float CRR_Response::GetRespeakDelay( void ) const
{
if ( m_Params.flags & ResponseParams::RG_RESPEAKDELAY )
{
interval_t temp;
m_Params.respeakdelay.ToInterval( temp );
return RandomInterval( temp );
}
return 0.0f;
}
float CRR_Response::GetWeaponDelay( void ) const
{
if ( m_Params.flags & ResponseParams::RG_WEAPONDELAY )
{
interval_t temp;
m_Params.weapondelay.ToInterval( temp );
return RandomInterval( temp );
}
return 0.0f;
}
bool CRR_Response::GetSpeakOnce( void ) const
{
if ( m_Params.flags & ResponseParams::RG_SPEAKONCE )
{
return true;
}
return false;
}
bool CRR_Response::ShouldntUseScene( void ) const
{
return ( m_Params.flags & ResponseParams::RG_DONT_USE_SCENE ) != 0;
}
bool CRR_Response::ShouldBreakOnNonIdle( void ) const
{
return ( m_Params.flags & ResponseParams::RG_STOP_ON_NONIDLE ) != 0;
}
int CRR_Response::GetOdds( void ) const
{
if ( m_Params.flags & ResponseParams::RG_ODDS )
{
return m_Params.odds;
}
return 100;
}
float CRR_Response::GetDelay() const
{
if ( m_Params.flags & ResponseParams::RG_DELAYAFTERSPEAK )
{
interval_t temp;
m_Params.delay.ToInterval( temp );
return RandomInterval( temp );
}
return 0.0f;
}
float CRR_Response::GetPreDelay() const
{
if ( m_Params.flags & ResponseParams::RG_DELAYBEFORESPEAK )
{
interval_t temp;
m_Params.predelay.ToInterval( temp );
return RandomInterval( temp );
}
return 0.0f;
}
//-----------------------------------------------------------------------------
// Purpose: Sets context string
// Output : void
//-----------------------------------------------------------------------------
void CRR_Response::SetContext( const char *context )
{
if (m_szContext)
{
delete[] m_szContext;
m_szContext = NULL;
}
if ( context )
{
int len = Q_strlen( context );
m_szContext = new char[ len + 1 ];
Q_memcpy( m_szContext, context, len );
m_szContext[ len ] = 0;
}
}

View File

@@ -0,0 +1,73 @@
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "rrbase.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
#if RR_CONCEPTS_ARE_STRINGS
#pragma error("RR_CONCEPTS_ARE_STRINGS no longer supported")
#else
using namespace ResponseRules;
// Used to turn ad-hoc concept from strings into numbers.
CRR_ConceptSymbolTable *g_pRRConceptTable = NULL;
// Q&D hack to defer initialization of concept table until I can figure out where it
// really needs to come from.
static void InitializeRRConceptTable()
{
if (g_pRRConceptTable == NULL)
{
g_pRRConceptTable = new CRR_ConceptSymbolTable( 64, 64, true );
}
}
// construct from string
CRR_Concept::CRR_Concept(const char *fromString)
{
InitializeRRConceptTable();
m_iConcept = g_pRRConceptTable->AddString(fromString);
}
CRR_Concept &CRR_Concept::operator=(const char *fromString)
{
InitializeRRConceptTable();
m_iConcept = g_pRRConceptTable->AddString(fromString);
return *this;
}
bool CRR_Concept::operator==(const char *pszConcept)
{
int otherConcept = g_pRRConceptTable->Find(pszConcept);
return ( otherConcept != UTL_INVAL_SYMBOL && otherConcept == m_iConcept );
}
const char *CRR_Concept::GetStringConcept() const
{
InitializeRRConceptTable();
AssertMsg( m_iConcept.IsValid(), "AI Concept has invalid string symbol.\n" );
const char * retval = g_pRRConceptTable->String(m_iConcept);
AssertMsg( retval, "An RR_Concept couldn't find its string in the symbol table!\n" );
if (retval == NULL)
{
Warning( "An RR_Concept couldn't find its string in the symbol table!\n" );
retval = "";
}
return retval;
}
const char *CRR_Concept::GetStringForGenericId(tGenericId genericId)
{
InitializeRRConceptTable();
return g_pRRConceptTable->String(genericId);
}
#endif

View File

@@ -0,0 +1,59 @@
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef RRBASE_H
#define RRBASE_H
#ifdef _WIN32
#pragma once
#endif
#ifdef _WIN32
// Silence certain warnings
// #pragma warning(disable : 4244) // int or float down-conversion
// #pragma warning(disable : 4305) // int or float data truncation
// #pragma warning(disable : 4201) // nameless struct/union
// #pragma warning(disable : 4511) // copy constructor could not be generated
// #pragma warning(disable : 4675) // resolved overload was found by argument dependent lookup
#endif
#ifdef _DEBUG
#define DEBUG 1
#endif
// Misc C-runtime library headers
#include <math.h>
#include <ctype.h>
#include <stdio.h>
// tier 0
#include "tier0/dbg.h"
#include "tier0/platform.h"
#include "basetypes.h"
// tier 1
#include "tier1/strtools.h"
#include "utlvector.h"
#include "utlsymbol.h"
// tier 2
#include "string_t.h"
// Shared engine/DLL constants
#include "const.h"
#include "edict.h"
// app
#if defined(_GAMECONSOLE)
#define DISABLE_DEBUG_HISTORY 1
#endif
#include "responserules/response_types.h"
#include "responserules/response_types_internal.h"
#include "responserules/response_host_interface.h"
#endif // CBASE_H

View File

@@ -0,0 +1,13 @@
/// PLACEHOLDER FILE FOR RESPONSE RULES RUNTIME LIBRARY
#include "rrbase.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
namespace ResponseRules
{
/// Custom symbol table for the response rules.
CUtlSymbolTable g_RS;
};

View File

@@ -0,0 +1,11 @@
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose: Builds the precompiled header for the game DLL
//
// $NoKeywords: $
//=============================================================================//
#include "rrbase.h"
// NOTE: DO NOT ADD ANY CODE OR HEADERS TO THIS FILE!!!

View File

@@ -0,0 +1,2 @@
SN Visual Studio Integration
IMPORTANT: Do not remove the custom build step for this file