aboutsummaryrefslogtreecommitdiff
path: root/mp/src/game/server/sceneentity.cpp
diff options
context:
space:
mode:
authorMichael Sartain <[email protected]>2014-10-02 08:25:55 -0700
committerMichael Sartain <[email protected]>2014-10-02 08:25:55 -0700
commit55ed12f8d1eb6887d348be03aee5573d44177ffb (patch)
tree3686f7ca78c780cd9a3d367b79a9d9250c1be7c0 /mp/src/game/server/sceneentity.cpp
parent* Added support for Visual C++ 2013 Express to VPC (diff)
downloadsource-sdk-2013-55ed12f8d1eb6887d348be03aee5573d44177ffb.tar.xz
source-sdk-2013-55ed12f8d1eb6887d348be03aee5573d44177ffb.zip
Updated the SDK with the latest code from the TF and HL2 branches.
Diffstat (limited to 'mp/src/game/server/sceneentity.cpp')
-rw-r--r--mp/src/game/server/sceneentity.cpp96
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;
}
}
}