From ed21bb3d1d3e6fcd869fc4923d3a8035113d8fee Mon Sep 17 00:00:00 2001 From: Blixibon Date: Mon, 17 Jan 2022 16:49:52 -0600 Subject: [PATCH] Added misc. speech/choreo utilities to ai_speech_new --- sp/src/game/server/ai_speech_new.cpp | 26 ++++++++++++++++++++++++++ sp/src/game/server/ai_speech_new.h | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/sp/src/game/server/ai_speech_new.cpp b/sp/src/game/server/ai_speech_new.cpp index 41fe6182..8d73911f 100644 --- a/sp/src/game/server/ai_speech_new.cpp +++ b/sp/src/game/server/ai_speech_new.cpp @@ -1528,6 +1528,32 @@ void CAI_Expresser::ClearSpokeConcept( const AIConcept_t &concept ) m_ConceptHistories.Remove( concept ); } +#ifdef MAPBASE +//------------------------------------- + +AIConcept_t CAI_Expresser::GetLastSpokeConcept( AIConcept_t excludeConcept /* = NULL */ ) +{ + int iLastSpokenIndex = m_ConceptHistories.InvalidIndex(); + float flLast = 0.0f; + for ( int i = m_ConceptHistories.First(); i != m_ConceptHistories.InvalidIndex(); i = m_ConceptHistories.Next(i ) ) + { + ConceptHistory_t *h = &m_ConceptHistories[ i ]; + + // If an 'exclude concept' was provided, skip over this entry in the history if it matches the exclude concept + if ( excludeConcept != NULL && FStrEq( m_ConceptHistories.GetElementName( i ), excludeConcept ) ) + continue; + + if ( h->timeSpoken >= flLast ) + { + iLastSpokenIndex = i; + flLast = h->timeSpoken; + } + } + + return iLastSpokenIndex != m_ConceptHistories.InvalidIndex() ? m_ConceptHistories.GetElementName( iLastSpokenIndex ) : NULL; +} +#endif + //------------------------------------- void CAI_Expresser::DumpHistories() diff --git a/sp/src/game/server/ai_speech_new.h b/sp/src/game/server/ai_speech_new.h index 1882e66e..70e73354 100644 --- a/sp/src/game/server/ai_speech_new.h +++ b/sp/src/game/server/ai_speech_new.h @@ -211,6 +211,10 @@ public: float GetTimeSpokeConcept( const AIConcept_t &concept ); // returns -1 if never void SetSpokeConcept( const AIConcept_t &concept, AI_Response *response, bool bCallback = true ); void ClearSpokeConcept( const AIConcept_t &concept ); + +#ifdef MAPBASE + AIConcept_t GetLastSpokeConcept( AIConcept_t excludeConcept = NULL ); +#endif // --------------------------------