ef2gamesource/dlls/game/talk.cpp

434 lines
9.4 KiB
C++
Raw Normal View History

2012-12-30 16:37:54 +00:00
//-----------------------------------------------------------------------------
//
// $Logfile:: /EF2/Code/DLLs/game/talk.cpp $
// $Revision:: 16 $
// $Author:: Singlis $
// $Date:: 9/26/03 2:36p $
//
// Copyright (C) 2002 by Ritual Entertainment, Inc.
// All rights reserved.
//
// This source may not be distributed and/or modified without
// expressly written permission by Ritual Entertainment, Inc.
//
//
// DESCRIPTION:
// Talk Implementation
//
// PARAMETERS:
//
// ANIMATIONS:
//--------------------------------------------------------------------------------
#include "actor.h"
#include "talk.hpp"
#include <qcommon/gameplaymanager.h>
Event EV_TalkBehavior_GreetingDone
(
"greetingdone",
EV_DEFAULT,
NULL,
NULL,
"Notifies the talk behavior the greeting dialog is done"
);
/****************************************************************************
2012-12-31 15:19:55 +00:00
Talk Class Definition
2012-12-30 16:37:54 +00:00
****************************************************************************/
CLASS_DECLARATION( Behavior, Talk, NULL )
2012-12-31 15:19:55 +00:00
{
{ &EV_TalkBehavior_GreetingDone, &Talk::GreetingDone },
{ &EV_Behavior_AnimDone, &Talk::AnimDone },
{ NULL, NULL }
};
2012-12-30 16:37:54 +00:00
void Talk::SetUser
(
Sentient *user
)
2012-12-31 15:19:55 +00:00
{
2012-12-30 16:37:54 +00:00
ent_listening = user;
2012-12-31 15:19:55 +00:00
}
2012-12-30 16:37:54 +00:00
void Talk::AnimDone
(
2012-12-31 15:19:55 +00:00
Event *
2012-12-30 16:37:54 +00:00
)
2012-12-31 15:19:55 +00:00
{
2012-12-30 16:37:54 +00:00
turnto.ProcessEvent( EV_Behavior_AnimDone );
animDone = true;
2012-12-31 15:19:55 +00:00
}
2012-12-30 16:37:54 +00:00
2012-12-31 15:19:55 +00:00
void Talk::GreetingDone( Event * )
2012-12-30 16:37:54 +00:00
{
mode = TALK_MODE_TURN_TO;
}
void Talk::Begin
(
Actor &self
)
2012-12-31 15:19:55 +00:00
{
2012-12-30 16:37:54 +00:00
Vector dir;
Vector angles;
const char *anim_name;
oldAnimName = "";
2012-12-31 15:19:55 +00:00
2012-12-30 16:37:54 +00:00
anim_name = self.animname;
last_headwatch_target = self.headWatcher->GetWatchTarget();
animDone = true;
move_allowed = true;
turnto.SetUseTurnAnim( false );
/*
if ( strncmp( anim_name, "sit_leanover", 12 ) == 0 )
2012-12-31 15:19:55 +00:00
{
move_allowed = false;
}
2012-12-30 16:37:54 +00:00
else if ( strncmp( anim_name, "sit", 3 ) == 0 )
2012-12-31 15:19:55 +00:00
{
move_allowed = false;
self.SetAnim( "sit_talk" );
}
2012-12-30 16:37:54 +00:00
else if ( strncmp( anim_name, "talk_sit_stunned", 15 ) == 0 )
2012-12-31 15:19:55 +00:00
{
move_allowed = false;
}
2012-12-30 16:37:54 +00:00
else if ( strncmp( anim_name, "talk_headset", 12 ) == 0 )
2012-12-31 15:19:55 +00:00
{
move_allowed = true;
}
2012-12-30 16:37:54 +00:00
else if ( strncmp( anim_name, "stand_hypnotized", 16 ) == 0 )
2012-12-31 15:19:55 +00:00
{
move_allowed = false;
}
2012-12-30 16:37:54 +00:00
else if ( strncmp( anim_name, "talk_hipnotic", 13 ) == 0 )
2012-12-31 15:19:55 +00:00
{
move_allowed = false;
}
2012-12-30 16:37:54 +00:00
else if ( strncmp( anim_name, "rope", 4 ) == 0 )
2012-12-31 15:19:55 +00:00
{
move_allowed = false;
}
2012-12-30 16:37:54 +00:00
else
2012-12-31 15:19:55 +00:00
{
move_allowed = true;
self.SetAnim( "talk" );
}*/
2012-12-30 16:37:54 +00:00
if ( self.talkMode == TALK_IGNORE )
2012-12-31 15:19:55 +00:00
{
2012-12-30 16:37:54 +00:00
move_allowed = false;
2012-12-31 15:19:55 +00:00
}
2012-12-30 16:37:54 +00:00
if ( self.talkMode == TALK_HEADWATCH )
2012-12-31 15:19:55 +00:00
{
2012-12-30 16:37:54 +00:00
move_allowed = false;
oldAnimName = self.animname;
2012-12-31 15:19:55 +00:00
}
2012-12-30 16:37:54 +00:00
if ( self.talkMode != TALK_IGNORE )
2012-12-31 15:19:55 +00:00
{
2012-12-30 16:37:54 +00:00
if ( ent_listening )
self.headWatcher->SetWatchTarget( ent_listening );
2012-12-31 15:19:55 +00:00
}
2012-12-30 16:37:54 +00:00
mode = TALK_MODE_PLAY_GREETING;
Entity *currentEnemy = NULL;
currentEnemy = self.enemyManager->GetCurrentEnemy();
if ( currentEnemy )
mode = TALK_MODE_COMBAT;
original_yaw = self.angles[YAW];
if ( ent_listening )
2012-12-31 15:19:55 +00:00
{
2012-12-30 16:37:54 +00:00
dir = ent_listening->centroid - self.centroid;
angles = dir.toAngles();
yaw = angles[YAW];
2012-12-31 15:19:55 +00:00
}
2012-12-30 16:37:54 +00:00
/*if ( !self.GetActorFlag(ACTOR_FLAG_PLAYING_DIALOG_ANIM) )
2012-12-31 15:19:55 +00:00
{
self.SetAnim( "conv" , EV_Actor_NotifyBehavior );
self.SetActorFlag( ACTOR_FLAG_PLAYING_DIALOG_ANIM , true );
}
2012-12-30 16:37:54 +00:00
*/
2012-12-31 15:19:55 +00:00
}
2012-12-30 16:37:54 +00:00
BehaviorReturnCode_t Talk::Evaluate
(
Actor &self
)
2012-12-31 15:19:55 +00:00
{
2012-12-30 16:37:54 +00:00
Vector dir;
Vector angles;
str greetingDialog;
str combatDialog;
float greetingDialogLength;
Event *greetingEvent;
char localizedDialogName[MAX_QPATH];
//Event *event;
if ( !ent_listening )
mode = TALK_MODE_TURN_BACK;
if ( !self.GetActorFlag(ACTOR_FLAG_PLAYING_DIALOG_ANIM) && animDone && self.GetActorFlag(ACTOR_FLAG_DIALOG_PLAYING) )
2012-12-31 15:19:55 +00:00
{
2012-12-30 16:37:54 +00:00
if ( self.useConvAnims )
2012-12-31 15:19:55 +00:00
{
2012-12-30 16:37:54 +00:00
//self.SetActorFlag(ACTOR_FLAG_CAN_CHANGE_ANIM , true);
self.SetAnim( "talk" , EV_Actor_NotifyBehavior );
self.SetActorFlag( ACTOR_FLAG_PLAYING_DIALOG_ANIM , true );
self.SetActorFlag(ACTOR_FLAG_CAN_CHANGE_ANIM , false );
animDone = false;
}
2012-12-31 15:19:55 +00:00
}
2012-12-30 16:37:54 +00:00
if ( self.useConvAnims && animDone && mode != TALK_MODE_WAIT && mode != TALK_MODE_TURN_TO )
2012-12-31 15:19:55 +00:00
{
self.SetActorFlag(ACTOR_FLAG_CAN_CHANGE_ANIM , true);
self.SetAnim( "conv-idle" , EV_Actor_NotifyBehavior );
//self.SetActorFlag(ACTOR_FLAG_CAN_CHANGE_ANIM , false );
//self.SetAnim( "idle" );
animDone = false;
}
2012-12-30 16:37:54 +00:00
if ( self.useConvAnims && /*animDone &&*/ mode == TALK_MODE_WAIT )
2012-12-31 15:19:55 +00:00
{
self.SetActorFlag(ACTOR_FLAG_CAN_CHANGE_ANIM , true);
if ( oldAnimName.length() )
self.SetAnim( oldAnimName );
else
self.SetAnim( "idle" );
animDone = false;
}
2012-12-30 16:37:54 +00:00
if ( !self.GetActorFlag(ACTOR_FLAG_PLAYING_DIALOG_ANIM) && !self.GetActorFlag(ACTOR_FLAG_DIALOG_PLAYING) && !self.talkMode == TALK_HEADWATCH )
2012-12-31 15:19:55 +00:00
{
2012-12-30 16:37:54 +00:00
self.SetAnim( "idle" );
animDone = true;
2012-12-31 15:19:55 +00:00
}
2012-12-30 16:37:54 +00:00
if ( self.GetActorFlag(ACTOR_FLAG_PLAYING_DIALOG_ANIM) && animDone )
2012-12-31 15:19:55 +00:00
{
2012-12-30 16:37:54 +00:00
if ( oldAnimName.length() )
2012-12-31 15:19:55 +00:00
{
2012-12-30 16:37:54 +00:00
self.SetActorFlag(ACTOR_FLAG_CAN_CHANGE_ANIM , true );
self.SetAnim( oldAnimName );
self.SetActorFlag(ACTOR_FLAG_CAN_CHANGE_ANIM , false );
if ( mode != TALK_MODE_TURN_BACK )
mode = TALK_MODE_WAIT;
2012-12-31 15:19:55 +00:00
2012-12-30 16:37:54 +00:00
}
2012-12-31 15:19:55 +00:00
}
2012-12-30 16:37:54 +00:00
switch( mode )
2012-12-31 15:19:55 +00:00
{
case TALK_MODE_COMBAT:
combatDialog = self.FindDialog( ent_listening, DIALOG_TYPE_COMBAT );
if ( !combatDialog.length() )
2012-12-30 16:37:54 +00:00
return BEHAVIOR_SUCCESS;
2012-12-31 15:19:55 +00:00
self.PlayDialog( ent_listening , -1.0f, -1.0f, combatDialog.c_str() );
return BEHAVIOR_SUCCESS;
2012-12-30 16:37:54 +00:00
break;
2012-12-31 15:19:55 +00:00
case TALK_MODE_PLAY_GREETING:
greetingDialog = self.FindDialog( ent_listening, DIALOG_TYPE_GREETING );
if ( !greetingDialog.length() )
{
mode = TALK_MODE_TURN_TO;
return BEHAVIOR_EVALUATING;
}
2012-12-30 16:37:54 +00:00
2012-12-31 15:19:55 +00:00
gi.LocalizeFilePath( greetingDialog.c_str(), localizedDialogName );
greetingDialogLength = gi.SoundLength( localizedDialogName );
2012-12-30 16:37:54 +00:00
2012-12-31 15:19:55 +00:00
if ( greetingDialogLength > 0 )
{
greetingEvent = new Event(EV_TalkBehavior_GreetingDone);
PostEvent(greetingEvent , greetingDialogLength );
2012-12-30 16:37:54 +00:00
2012-12-31 15:19:55 +00:00
Event *dialogEvent = new Event( EV_SimplePlayDialog );
dialogEvent->AddString( greetingDialog.c_str() );
ent_listening->ProcessEvent( dialogEvent );
//ent_listening->Sound( greetingDialog );
mode = TALK_MODE_WAIT_FOR_GREETING;
}
else
{
mode = TALK_MODE_TURN_TO;
}
2012-12-30 16:37:54 +00:00
break;
2012-12-31 15:19:55 +00:00
case TALK_MODE_WAIT_FOR_GREETING:
//Waiting on the Greeting Done Event Here
2012-12-30 16:37:54 +00:00
break;
2012-12-31 15:19:55 +00:00
case TALK_MODE_TURN_TO :
if ( move_allowed )
{
turnto.SetDirection( yaw );
2012-12-30 16:37:54 +00:00
2012-12-31 15:19:55 +00:00
if ( !turnto.Evaluate( self ) )
{
2012-12-30 16:37:54 +00:00
mode = TALK_MODE_TALK;
self.PlayDialog( ent_listening );
/* event = new Event( EV_Player_WatchActor );
event->AddEntity( &self );
ent_listening->PostEvent( event, 0.05 ); */
2012-12-31 15:19:55 +00:00
}
}
else
{
mode = TALK_MODE_TALK;
self.PlayDialog( ent_listening );
2012-12-30 16:37:54 +00:00
2012-12-31 15:19:55 +00:00
/* event = new Event( EV_Player_WatchActor );
event->AddEntity( &self );
ent_listening->PostEvent( event, 0.05 ); */
}
break;
case TALK_MODE_TALK :
2012-12-30 16:37:54 +00:00
2012-12-31 15:19:55 +00:00
if ( move_allowed )
{
dir = ent_listening->centroid - self.centroid;
angles = dir.toAngles();
turnto.SetDirection( angles[YAW] );
turnto.Evaluate( self );
}
2012-12-30 16:37:54 +00:00
2012-12-31 15:19:55 +00:00
if ( !self.GetActorFlag( ACTOR_FLAG_DIALOG_PLAYING ) )
{
mode = TALK_MODE_WAIT;
self.state_flags &= ~STATE_FLAG_USED;
2012-12-30 16:37:54 +00:00
2012-12-31 15:19:55 +00:00
// Tell player to stop watching us
2012-12-30 16:37:54 +00:00
2012-12-31 15:19:55 +00:00
/* event = new Event( EV_Player_StopWatchingActor );
event->AddEntity( &self );
ent_listening->PostEvent( event, 0 ); */
//ent_listening->CancelEventsOfType( EV_Player_WatchActor );
}
else if ( !self.GetActorFlag( ACTOR_FLAG_RADIUS_DIALOG_PLAYING ) )
{
if ( !self.WithinDistance( ent_listening, self.radiusDialogRange ) )
{
self.PlayRadiusDialog( ent_listening );
/*
int postive_response = true;
str check_alias;
if (postive_response)
{
check_alias = self.GetRandomAlias("radiusdialog_positive");
if(check_alias.length())
2012-12-30 16:37:54 +00:00
{
2012-12-31 15:19:55 +00:00
self.PlayRadiusDialog(ent_listening, "radiusdialog_positive");
}
2012-12-30 16:37:54 +00:00
}
2012-12-31 15:19:55 +00:00
else
2012-12-30 16:37:54 +00:00
{
2012-12-31 15:19:55 +00:00
check_alias = self.GetRandomAlias("radiusdialog_negative");
if(check_alias.length())
{
self.PlayRadiusDialog(ent_listening, "radiusdialog_negative");
}
2012-12-30 16:37:54 +00:00
}
2012-12-31 15:19:55 +00:00
*/
}
}
break;
case TALK_MODE_WAIT :
2012-12-30 16:37:54 +00:00
2012-12-31 15:19:55 +00:00
if ( move_allowed )
{
dir = ent_listening->centroid - self.centroid;
angles = dir.toAngles();
turnto.SetDirection( angles[YAW] );
turnto.Evaluate( self );
}
2012-12-30 16:37:54 +00:00
2012-12-31 15:19:55 +00:00
if ( !self.WithinDistance( ent_listening, 100.0f ) )
mode = TALK_MODE_TURN_BACK;
2012-12-30 16:37:54 +00:00
2012-12-31 15:19:55 +00:00
if ( self.state_flags & STATE_FLAG_USED )
{
mode = TALK_MODE_TURN_TO;
self.SetActorFlag(ACTOR_FLAG_PLAYING_DIALOG_ANIM, false );
2012-12-30 16:37:54 +00:00
2012-12-31 15:19:55 +00:00
dir = ent_listening->centroid - self.centroid;
angles = dir.toAngles();
yaw = angles[YAW];
2012-12-30 16:37:54 +00:00
2012-12-31 15:19:55 +00:00
self.state_flags &= ~STATE_FLAG_USED;
2012-12-30 16:37:54 +00:00
2012-12-31 15:19:55 +00:00
/* event = new Event( EV_Player_WatchActor );
event->AddEntity( &self );
ent_listening->PostEvent( event, 0.05 ); */
2012-12-30 16:37:54 +00:00
}
2012-12-31 15:19:55 +00:00
break;
case TALK_MODE_TURN_BACK :
if ( move_allowed )
{
turnto.SetDirection( original_yaw );
2012-12-30 16:37:54 +00:00
2012-12-31 15:19:55 +00:00
if ( !turnto.Evaluate( self ) )
return BEHAVIOR_SUCCESS;
}
else
{
return BEHAVIOR_SUCCESS;
}
break;
2012-12-30 16:37:54 +00:00
}
2012-12-31 15:19:55 +00:00
return BEHAVIOR_EVALUATING;
}
2012-12-30 16:37:54 +00:00
void Talk::End( Actor &self )
2012-12-31 15:19:55 +00:00
{
2012-12-30 16:37:54 +00:00
self.SetActorFlag( ACTOR_FLAG_PLAYING_DIALOG_ANIM , false );
self.SetActorFlag(ACTOR_FLAG_CAN_CHANGE_ANIM , true );
self.ClearLegAnim();
self.ClearTorsoAnim();
if ( oldAnimName.length() )
2012-12-31 15:19:55 +00:00
{
2012-12-30 16:37:54 +00:00
self.SetAnim( oldAnimName );
2012-12-31 15:19:55 +00:00
}
2012-12-30 16:37:54 +00:00
else
2012-12-31 15:19:55 +00:00
{
2012-12-30 16:37:54 +00:00
self.SetAnim( "idle" );
2012-12-31 15:19:55 +00:00
}
2012-12-30 16:37:54 +00:00
if ( last_headwatch_target )
self.headWatcher->SetWatchTarget( last_headwatch_target );
else
self.headWatcher->SetWatchTarget( NULL );
2012-12-31 15:19:55 +00:00
}
2012-12-30 16:37:54 +00:00