📄 actor.h
字号:
ThreadMarker marker;
Container<StateInfo *> actionList;
virtual void Archive( Archiver &arc );
virtual void Unarchive( Archiver &arc );
};
inline EXPORT_FROM_DLL void ActorState::Archive
(
Archiver &arc
)
{
int i, num;
Class::Archive( arc );
arc.WriteString( name );
arc.WriteString( anim );
arc.WriteEvent( *animDoneEvent );
//FIXME
arc.WriteBoolean( behavior != NULL );
if ( behavior )
{
arc.WriteObject( behavior );
}
arc.WriteSafePointer( path );
arc.WriteInteger( thread );
arc.WriteObject( &marker );
num = actionList.NumObjects();
arc.WriteInteger( num );
for ( i = 1; i <= num; i++ )
{
arc.WriteObject( actionList.ObjectAt( i ) );
}
}
inline EXPORT_FROM_DLL void ActorState::Unarchive
(
Archiver &arc
)
{
Event * ev;
int i, num;
Class::Unarchive( arc );
arc.ReadString( &name );
arc.ReadString( &anim );
ev = new Event;
arc.ReadEvent( ev );
animDoneEvent = ev;
//FIXME
behavior = NULL;
if ( arc.ReadBoolean() )
{
behavior = ( Behavior * )arc.ReadObject();
}
arc.ReadSafePointer( &path );
arc.ReadInteger( &thread );
arc.ReadObject( &marker );
actionList.FreeObjectList();
arc.ReadInteger( &num );
for ( i = 1; i <= num; i++ )
{
StateInfo * info;
info = new StateInfo;
arc.ReadObject( info );
actionList.AddObject( info );
}
}
//
// Exported templated classes must be explicitly instantiated
//
#ifdef EXPORT_TEMPLATE
template class EXPORT_FROM_DLL Container<EntityPtr>;
template class EXPORT_FROM_DLL Stack<ActorState *>;
#endif
class EXPORT_FROM_DLL Actor : public Sentient
{
public:
str newanim;
Event *newanimevent;
int newanimnum;
str spawngroup;
int movement;
stepmoveresult_t lastmove;
float forwardspeed;
actortype_t actortype;
int attackmode;
Vector standsize_min;
Vector standsize_max;
Vector crouchsize_min;
Vector crouchsize_max;
str state;
str animname;
Container<StateInfo *> actionList;
int numonstack;
Stack<ActorState *> stateStack;
BehaviorPtr behavior;
str currentBehavior;
PathPtr path;
Container<EntityPtr> targetList;
Container<EntityPtr> nearbyList;
Container<EntityPtr> enemyList;
EntityPtr currentEnemy;
qboolean seenEnemy;
range_t enemyRange;
EntityPtr lastEnemy;
float fov;
float fovdot;
float vision_distance;
Vector startpos;
Vector move;
Vector movedir;
float movespeed;
Vector movevelocity;
float totallen;
float turnspeed;
Vector animdir;
float chattime;
float nextsoundtime;
qboolean hasalert;
PathNodePtr movegoal;
PathNodePtr soundnode;
ThreadPtr thread;
ThreadPtr actorthread;
str actorscript;
str actorstart;
TouchFieldPtr trig;
qboolean has_melee;
float melee_damage;
float melee_range;
float aim;
float pain_threshold;
qboolean checkStrafe;
float next_drown_time;
float air_finished;
float attack_range;
float shots_per_attack;
qboolean deathgib;
str kill_thread;
Vector eyeoffset;
float last_jump_time;
qboolean nodeathfade;
qboolean nochatter;
CLASS_PROTOTYPE( Actor );
// Initialization functions
Actor();
~Actor();
void Start( Event *ev );
// Vision functions
range_t Range( Entity *ent );
qboolean InFOV( Vector pos );
qboolean InFOV( Entity *ent );
qboolean CanSeeFOV( Entity *ent );
qboolean CanSeeFrom( Vector pos, Entity *ent );
qboolean CanSee( Entity *ent );
int EnemyCanSeeMeFrom( Vector pos );
qboolean CanSeeEnemyFrom( Vector pos );
// Weapon functions
qboolean WeaponReady( void );
void Attack( Event *ev );
virtual Vector GunPosition( void );
virtual Vector MyGunAngles( Vector muzzlepos, qboolean firing );
virtual void GetGunOrientation( Vector muzzlepos, Vector *forward, Vector *right, Vector *up );
virtual qboolean CanShootFrom( Vector pos, Entity *ent, qboolean usecurrentangles );
virtual qboolean CanShoot( Entity *ent, qboolean usecurrentangles );
// Actor type script commands
void FriendEvent( Event *ev );
void CivilianEvent( Event *ev );
void EnemyEvent( Event *ev );
void InanimateEvent( Event *ev );
void MonsterEvent( Event *ev );
void AnimalEvent( Event *ev );
// Enemy management
qboolean HasEnemies( void );
qboolean IsEnemy( Entity *ent );
void MakeEnemy( Entity *ent, qboolean force = false );
qboolean Likes( Entity *ent );
qboolean Hates( Entity *ent );
// Targeting functions
qboolean GetVisibleTargets( void );
void TargetEnemies( Event *ev );
Entity *BestTarget( void );
Sentient *NearFriend( void );
qboolean CloseToEnemy( Vector pos, float howclose );
float AttackRange( void );
float MinimumAttackRange( void );
// State control functions
void EnableState( str action );
void DisableState( str action );
StateInfo *SetResponse( str action, str response, qboolean ignore = false );
const char *GetResponse( str action, qboolean force = false );
StateInfo *GetState( str action );
// State stack management
void ClearStateStack( void );
qboolean PopState( void );
void PushState( const char *newstate, ScriptThread *newthread = NULL, ThreadMarker *marker = NULL );
// State control script commands
void DefineStateEvent( Event *ev );
void CopyStateEvent( Event *ev );
void IgnoreAllEvent( Event *ev );
void IgnoreEvent( Event *ev );
void RespondToAllEvent( Event *ev );
void RespondToEvent( Event *ev );
void ClearStateEvent( Event *ev );
void StateDoneEvent( Event *ev );
void SetStateEvent( Event *ev );
// Thread management
void SetupThread( void );
qboolean DoAction( str name, qboolean force = false );
qboolean ForceAction( str name );
void ProcessScript( ScriptThread *thread, Event *ev = NULL );
void StartMove( Event *ev );
ScriptVariable *SetVariable( const char *name, float value );
ScriptVariable *SetVariable( const char *name, int value );
ScriptVariable *SetVariable( const char *name, const char *text );
ScriptVariable *SetVariable( const char *name, str &text );
ScriptVariable *SetVariable( const char *name, Entity *ent );
ScriptVariable *SetVariable( const char *name, Vector &vec );
// Thread based script commands
void SetScript( Event *ev );
void SetThread( Event *ev );
// Behavior management
void EndBehavior( void );
void SetBehaviorEvent( Event *ev );
void SetBehavior( Behavior *newbehavior, Event *argevent = NULL, ScriptThread *thread = NULL );
void FinishedBehavior( Event *ev );
void NotifyBehavior( Event *ev );
void ForwardBehaviorEvent( Event *ev );
// Path and node management
void SetPath( Path *newpath );
void ReserveNodeEvent( Event *ev );
void ReleaseNodeEvent( Event *ev );
// Animation control functions
void ChangeAnim( void );
qboolean SetAnim( str anim, Event *ev = NULL );
qboolean SetAnim( str anim, Event &ev );
void Anim( Event *ev );
// Script commands
void CrouchSize( Event *ev );
void SetFov( Event *ev );
void SetVisionDistance( Event *ev );
void LookAt( Event *ev );
void TurnToEvent( Event *ev );
void IdleEvent( Event *ev );
void WalkTo( Event *ev );
void RunTo( Event *ev );
void AttackEntity( Event *ev );
void AttackPlayer( Event *ev );
void JumpToEvent( Event *ev );
void GotoEvent( Event *ev );
// Script conditionals
void IfEnemyVisibleEvent( Event *ev );
void IfNearEvent( Event *ev );
void IfCanHideAtEvent( Event *ev );
void IfCanStrafeAttackEvent( Event *ev );
void IfCanMeleeAttackEvent( Event *ev );
void IfCanShootEvent( Event *ev );
void IfEnemyWithinEvent( Event *ev );
// Sound reaction functions
void IgnoreSoundsEvent( Event *ev );
void RespondToSoundsEvent( Event *ev );
void InvestigateWeaponSound( Event *ev );
void InvestigateMovementSound( Event *ev );
void InvestigatePainSound( Event *ev );
void InvestigateDeathSound( Event *ev );
void InvestigateBreakingSound( Event *ev );
void InvestigateDoorSound( Event *ev );
void InvestigateMutantSound( Event *ev );
void InvestigateVoiceSound( Event *ev );
void InvestigateMachineSound( Event *ev );
void InvestigateRadioSound( Event *ev );
// Pain and death related functions
void Pain( Event *ev );
void Dead( Event *ev );
void Killed( Event *ev );
void GibEvent( Event *ev );
void RemoveUselessBody( Event *ev );
// Movement functions
void ForwardSpeedEvent( Event *ev );
void SwimEvent( Event *ev );
void FlyEvent( Event *ev );
void NotLandEvent( Event *ev );
qboolean CanMoveTo( Vector pos );
void Accelerate( Vector steering );
void CalcMove( void );
void setAngles( Vector ang );
stepmoveresult_t WaterMove( void );
stepmoveresult_t AirMove( void );
stepmoveresult_t TryMove( void );
void CheckWater( void );
virtual void setSize( Vector min, Vector max );
// Debug functions
void ShowInfo( void );
// General functions
virtual void Chatter( const char *sound, float chance = 10, float volume = 1.0f, int channel = CHAN_VOICE );
void ActivateEvent( Event *ev );
void UseEvent( Event *ev );
void Prethink( void );
virtual void Archive( Archiver &arc );
virtual void Unarchive( Archiver &arc );
void SetAim( Event *ev );
void SetMeleeRange( Event *ev );
void SetMeleeDamage( Event *ev );
void MeleeEvent( Event *ev );
void AttackFinishedEvent( Event *ev );
void CanStrafeEvent( Event *ev );
void NoStrafeEvent( Event *ev );
void SetPainThresholdEvent( Event *ev );
void SetKillThreadEvent( Event *ev );
void AttackRangeEvent( Event *ev );
void AttackModeEvent( Event *ev );
void ShotsPerAttackEvent( Event *ev );
void ClearEnemyEvent( Event *ev );
void SetHealth( Event *ev );
void ClearEnemies( void );
void EyeOffset( Event *ev );
void NoDeathFadeEvent( Event *ev );
void NoChatterEvent( Event *ev );
void TurnSpeedEvent( Event *ev );
qboolean HasWeapon( void );
float JumpTo( PathNode * goal, float speed );
float JumpTo( Entity * goal, float speed );
float JumpTo( Vector targ, float speed );
};
inline EXPORT_FROM_DLL void Actor::Archive
(
Archiver &arc
)
{
int i, num;
Stack<ActorState *> tempStack;
ActorState *s;
Sentient::Archive( arc );
arc.WriteString( newanim );
arc.WriteEvent( *newanimevent );
arc.WriteInteger( newanimnum );
arc.WriteString( spawngroup );
arc.WriteInteger( movement );
// cast as stepmoveresult_t on read
arc.WriteInteger( ( int )lastmove );
arc.WriteFloat( forwardspeed );
// cast as actortype_t on read
arc.WriteInteger( ( int )actortype );
arc.WriteInteger( attackmode );
arc.WriteVector( standsize_min );
arc.WriteVector( standsize_max );
arc.WriteVector( crouchsize_min );
arc.WriteVector( crouchsize_max );
arc.WriteString( state );
arc.WriteString( animname );
num = actionList.NumObjects();
arc.WriteInteger( num );
for ( i = 1; i <= num; i++ )
{
arc.WriteObject( actionList.ObjectAt( i ) );
}
arc.WriteInteger( numonstack );
// We have to push all the states onto another stack in order to
// save them out in the proper order and to restore them after
// saving the game.
for( i = 1; i <= numonstack; i++ )
{
tempStack.Push( stateStack.Pop() );
}
// put them back on the stateStack as we write them out.
for( i = 1; i <= numonstack; i++ )
{
s = tempStack.Pop();
stateStack.Push( s );
arc.WriteObject( s );
}
// FIXME
arc.WriteBoolean( behavior != NULL );
if ( behavior )
{
arc.WriteObject( behavior );
}
arc.WriteString( currentBehavior );
arc.WriteSafePointer( path );
num = targetList.NumObjects();
arc.WriteInteger( num );
for ( i = 1; i <= num; i++ )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -