mirror of
https://github.com/celisej567/source-sdk-2013.git
synced 2026-09-23 20:09:45 +03:00
Added prototype Response System library port from the Alien Swarm SDK
This commit is contained in:
@@ -137,12 +137,23 @@ bool ConceptStringLessFunc( const string_t &lhs, const string_t &rhs )
|
||||
return CaselessStringLessThan( STRING(lhs), STRING(rhs) );
|
||||
}
|
||||
|
||||
#ifdef NEW_RESPONSE_SYSTEM
|
||||
bool ConceptInfoStringLessFunc( const AIConcept_t& lhs, const AIConcept_t& rhs )
|
||||
{
|
||||
return CaselessStringLessThan( lhs.GetStringConcept(), rhs.GetStringConcept() );
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class CConceptInfoMap : public CUtlMap<AIConcept_t, ConceptInfo_t *> {
|
||||
public:
|
||||
CConceptInfoMap() :
|
||||
#ifdef NEW_RESPONSE_SYSTEM
|
||||
CUtlMap<AIConcept_t, ConceptInfo_t *>( ConceptInfoStringLessFunc )
|
||||
#else
|
||||
CUtlMap<AIConcept_t, ConceptInfo_t *>( CaselessStringLessThan )
|
||||
#endif
|
||||
{
|
||||
for ( int i = 0; i < ARRAYSIZE(g_ConceptInfos); i++ )
|
||||
{
|
||||
@@ -557,7 +568,11 @@ void CAI_PlayerAlly::PrescheduleThink( void )
|
||||
if ( SelectNonCombatSpeech( &selection ) )
|
||||
{
|
||||
SetSpeechTarget( selection.hSpeechTarget );
|
||||
#ifdef NEW_RESPONSE_SYSTEM
|
||||
SpeakDispatchResponse( selection.concept.c_str(), &selection.Response );
|
||||
#else
|
||||
SpeakDispatchResponse( selection.concept.c_str(), selection.pResponse );
|
||||
#endif
|
||||
m_flNextIdleSpeechTime = gpGlobals->curtime + RandomFloat( 20,30 );
|
||||
}
|
||||
else
|
||||
@@ -599,12 +614,22 @@ bool CAI_PlayerAlly::SelectSpeechResponse( AIConcept_t concept, const char *pszM
|
||||
{
|
||||
if ( IsAllowedToSpeak( concept ) )
|
||||
{
|
||||
#ifdef NEW_RESPONSE_SYSTEM
|
||||
bool result = SpeakFindResponse( pSelection->Response, concept, pszModifiers );
|
||||
if ( result )
|
||||
{
|
||||
pSelection->concept = concept;
|
||||
pSelection->hSpeechTarget = pTarget;
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
AI_Response *pResponse = SpeakFindResponse( concept, pszModifiers );
|
||||
if ( pResponse )
|
||||
{
|
||||
pSelection->Set( concept, pResponse, pTarget );
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -614,7 +639,9 @@ bool CAI_PlayerAlly::SelectSpeechResponse( AIConcept_t concept, const char *pszM
|
||||
void CAI_PlayerAlly::SetPendingSpeech( AIConcept_t concept, AI_Response *pResponse )
|
||||
{
|
||||
m_PendingResponse = *pResponse;
|
||||
#ifndef NEW_RESPONSE_SYSTEM
|
||||
pResponse->Release();
|
||||
#endif
|
||||
m_PendingConcept = concept;
|
||||
m_TimePendingSet = gpGlobals->curtime;
|
||||
}
|
||||
@@ -696,7 +723,11 @@ bool CAI_PlayerAlly::SelectInterjection()
|
||||
if ( SelectIdleSpeech( &selection ) )
|
||||
{
|
||||
SetSpeechTarget( selection.hSpeechTarget );
|
||||
#ifdef NEW_RESPONSE_SYSTEM
|
||||
SpeakDispatchResponse( selection.concept.c_str(), &selection.Response );
|
||||
#else
|
||||
SpeakDispatchResponse( selection.concept.c_str(), selection.pResponse );
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -881,6 +912,18 @@ bool CAI_PlayerAlly::AskQuestionNow( CBaseEntity *pSpeechTarget, int iQARandomNu
|
||||
m_iQARandomNumber = RandomInt(0, 100);
|
||||
|
||||
AISpeechSelection_t selection;
|
||||
#ifdef NEW_RESPONSE_SYSTEM
|
||||
if (SelectSpeechResponse( concept, NULL, m_hPotentialSpeechTarget.Get(), &selection ))
|
||||
{
|
||||
SetSpeechTarget( selection.hSpeechTarget );
|
||||
ClearPendingSpeech();
|
||||
|
||||
// Speak immediately
|
||||
return SpeakDispatchResponse( selection.concept.c_str(), &selection.Response );
|
||||
}
|
||||
|
||||
return false;
|
||||
#else
|
||||
SelectSpeechResponse( concept, NULL, m_hPotentialSpeechTarget.Get(), &selection );
|
||||
|
||||
SetSpeechTarget( selection.hSpeechTarget );
|
||||
@@ -891,6 +934,7 @@ bool CAI_PlayerAlly::AskQuestionNow( CBaseEntity *pSpeechTarget, int iQARandomNu
|
||||
|
||||
// Speak immediately
|
||||
return SpeakDispatchResponse( selection.concept.c_str(), selection.pResponse );
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -980,7 +1024,11 @@ void CAI_PlayerAlly::AnswerQuestion( CAI_PlayerAlly *pQuestioner, int iQARandomN
|
||||
|
||||
Assert( selection.pResponse );
|
||||
SetSpeechTarget( selection.hSpeechTarget );
|
||||
#ifdef NEW_RESPONSE_SYSTEM
|
||||
SpeakDispatchResponse( selection.concept.c_str(), &selection.Response );
|
||||
#else
|
||||
SpeakDispatchResponse( selection.concept.c_str(), selection.pResponse );
|
||||
#endif
|
||||
|
||||
// Prevent idle speech for a while
|
||||
DeferAllIdleSpeech( random->RandomFloat( TALKER_DEFER_IDLE_SPEAK_MIN, TALKER_DEFER_IDLE_SPEAK_MAX ), GetSpeechTarget()->MyNPCPointer() );
|
||||
@@ -1032,7 +1080,11 @@ int CAI_PlayerAlly::SelectNonCombatSpeechSchedule()
|
||||
{
|
||||
Assert( selection.pResponse );
|
||||
SetSpeechTarget( selection.hSpeechTarget );
|
||||
#ifdef NEW_RESPONSE_SYSTEM
|
||||
SetPendingSpeech( selection.concept.c_str(), &selection.Response );
|
||||
#else
|
||||
SetPendingSpeech( selection.concept.c_str(), selection.pResponse );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1107,9 +1159,13 @@ void CAI_PlayerAlly::StartTask( const Task_t *pTask )
|
||||
case TASK_TALKER_SPEAK_PENDING:
|
||||
if ( !m_PendingConcept.empty() )
|
||||
{
|
||||
#ifdef NEW_RESPONSE_SYSTEM
|
||||
SpeakDispatchResponse( m_PendingConcept.c_str(), &m_PendingResponse );
|
||||
#else
|
||||
AI_Response *pResponse = new AI_Response;
|
||||
*pResponse = m_PendingResponse;
|
||||
SpeakDispatchResponse( m_PendingConcept.c_str(), pResponse );
|
||||
#endif
|
||||
m_PendingConcept.erase();
|
||||
TaskComplete();
|
||||
}
|
||||
@@ -1844,6 +1900,18 @@ bool CAI_PlayerAlly::RespondedTo( const char *ResponseConcept, bool bForce, bool
|
||||
{
|
||||
// We're being forced to respond to the event, probably because it's the
|
||||
// player dying or something equally important.
|
||||
#ifdef NEW_RESPONSE_SYSTEM
|
||||
AI_Response response;
|
||||
bool result = SpeakFindResponse( response, ResponseConcept, NULL );
|
||||
if ( result )
|
||||
{
|
||||
// We've got something to say. Stop any scenes we're in, and speak the response.
|
||||
if ( bCancelScene )
|
||||
RemoveActorFromScriptedScenes( this, false );
|
||||
|
||||
return SpeakDispatchResponse( ResponseConcept, &response );
|
||||
}
|
||||
#else
|
||||
AI_Response *result = SpeakFindResponse( ResponseConcept, NULL );
|
||||
if ( result )
|
||||
{
|
||||
@@ -1854,6 +1922,7 @@ bool CAI_PlayerAlly::RespondedTo( const char *ResponseConcept, bool bForce, bool
|
||||
bool spoke = SpeakDispatchResponse( ResponseConcept, result );
|
||||
return spoke;
|
||||
}
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user