diff options
Diffstat (limited to 'mp/src/game/server/sceneentity.cpp')
| -rw-r--r-- | mp/src/game/server/sceneentity.cpp | 96 |
1 files changed, 30 insertions, 66 deletions
diff --git a/mp/src/game/server/sceneentity.cpp b/mp/src/game/server/sceneentity.cpp index 495aa004..ccdc4cd4 100644 --- a/mp/src/game/server/sceneentity.cpp +++ b/mp/src/game/server/sceneentity.cpp @@ -2163,11 +2163,6 @@ void CSceneEntity::InputTriggerEvent( inputdata_t &inputdata ) } } -struct NPCInterjection -{ - AI_Response *response; - CAI_BaseActor *npc; -}; //----------------------------------------------------------------------------- // Purpose: // Input : &inputdata - @@ -2176,93 +2171,62 @@ void CSceneEntity::InputInterjectResponse( inputdata_t &inputdata ) { // Not currently playing a scene if ( !m_pScene ) - { return; - } - CUtlVector< CAI_BaseActor * > candidates; - int i; - for ( i = 0 ; i < m_pScene->GetNumActors(); i++ ) + CUtlVector<CAI_BaseActor *> candidates; + + for ( int i = 0 ; i < m_pScene->GetNumActors(); i++ ) { CBaseFlex *pTestActor = FindNamedActor( i ); if ( !pTestActor ) continue; - CAI_BaseActor *pBaseActor = dynamic_cast<CAI_BaseActor*>(pTestActor); - if ( !pBaseActor ) - continue; - - if ( !pBaseActor->IsAlive() ) + CAI_BaseActor *pBaseActor = dynamic_cast<CAI_BaseActor *>(pTestActor); + if ( !pBaseActor || !pBaseActor->IsAlive() ) continue; candidates.AddToTail( pBaseActor ); } int c = candidates.Count(); - if ( !c ) - { return; - } - - int useIndex = 0; + if ( !m_bIsPlayingBack ) { // Use any actor if not playing a scene - useIndex = RandomInt( 0, c - 1 ); + // int useIndex = RandomInt( 0, c - 1 ); + Assert( !"m_bIsPlayBack is false and this code does nothing. Should it?"); } else { - CUtlVector< NPCInterjection > validResponses; + CUtlString modifiers("scene:"); + modifiers += STRING( GetEntityName() ); - char modifiers[ 512 ]; - Q_snprintf( modifiers, sizeof( modifiers ), "scene:%s", STRING( GetEntityName() ) ); - - for ( int i = 0; i < c; i++ ) + while (candidates.Count() > 0) { - CAI_BaseActor *npc = candidates[ i ]; - Assert( npc ); + // Pick a random slot in the candidates array. + int slot = RandomInt( 0, candidates.Count() - 1 ); - AI_Response *response = npc->SpeakFindResponse( inputdata.value.String(), modifiers ); - if ( !response ) - continue; - - float duration = npc->GetResponseDuration( response ); - // Couldn't look it up - if ( duration <= 0.0f ) - continue; + CAI_BaseActor *npc = candidates[ slot ]; - if ( !npc->PermitResponse( duration ) ) + // Try to find the response for this slot. + AI_Response response; + bool result = npc->SpeakFindResponse( response, inputdata.value.String(), modifiers.Get() ); + if ( result ) { - delete response; - continue; - } - - // - NPCInterjection inter; - inter.response = response; - inter.npc = npc; - - validResponses.AddToTail( inter ); - } + float duration = npc->GetResponseDuration( response ); - int rcount = validResponses.Count(); - if ( rcount >= 1 ) - { - int slot = RandomInt( 0, rcount - 1 ); - - for ( int i = 0; i < rcount; i++ ) - { - NPCInterjection *pInterjection = &validResponses[ i ]; - if ( i == slot ) + if ( ( duration > 0.0f ) && npc->PermitResponse( duration ) ) { - pInterjection->npc->SpeakDispatchResponse( inputdata.value.String(), pInterjection->response ); - } - else - { - delete pInterjection->response; + // If we could look it up, dispatch it and bail. + npc->SpeakDispatchResponse( inputdata.value.String(), response ); + return; } } + + // Remove this entry and look for another one. + candidates.FastRemove(slot); } } } @@ -2783,12 +2747,12 @@ void CSceneEntity::QueueResumePlayback( void ) CAI_BaseActor *pBaseActor = dynamic_cast<CAI_BaseActor*>(pActor); if ( pBaseActor ) { - AI_Response *result = pBaseActor->SpeakFindResponse( STRING(m_iszResumeSceneFile), NULL ); + AI_Response response; + bool result = pBaseActor->SpeakFindResponse( response, STRING(m_iszResumeSceneFile), NULL ); if ( result ) { - char response[ 256 ]; - result->GetResponse( response, sizeof( response ) ); - bStartedScene = InstancedScriptedScene( NULL, response, &m_hWaitingForThisResumeScene, 0, false ) != 0; + const char *szResponse = response.GetResponsePtr(); + bStartedScene = InstancedScriptedScene( NULL, szResponse, &m_hWaitingForThisResumeScene, 0, false ) != 0; } } } |