This commit is contained in:
Walter Julius Hennecke 2014-03-09 22:47:15 +01:00
parent b9f90d4305
commit 4c152b09d0

View file

@ -40,152 +40,141 @@ class SnipeEnemy;
// //
// Method of Use: Called From State Machine // Method of Use: Called From State Machine
//-------------------------------------------------------------- //--------------------------------------------------------------
class SnipeEnemy : public Behavior class SnipeEnemy : public Behavior {
{ public:
//------------------------------------ //------------------------------------
// States // States
//------------------------------------ //------------------------------------
public: typedef enum {
typedef enum SNIPE_AIM_AND_FIRE_AIM,
{ SNIPE_AIM_AND_FIRE_PRE_FIRE,
SNIPE_AIM_AND_FIRE_AIM, SNIPE_AIM_AND_FIRE_ATTACK,
SNIPE_AIM_AND_FIRE_PRE_FIRE, SNIPE_AIM_AND_FIRE_POST_FIRE,
SNIPE_AIM_AND_FIRE_ATTACK, SNIPE_AIM_AND_FIRE_SUCCESS,
SNIPE_AIM_AND_FIRE_POST_FIRE, SNIPE_AIM_AND_FIRE_FAILED
SNIPE_AIM_AND_FIRE_SUCCESS, } SnipeAimAndFireStates_t;
SNIPE_AIM_AND_FIRE_FAILED
} SnipeAimAndFireStates_t;
//------------------------------------
// Parameters
//------------------------------------
private:
float _aimTime;
float _lockDownTime;
float _maxTorsoYaw;
float _maxTorsoPitch;
float _maxTorsoTurnSpeed;
int _shots;
//-------------------------------------
// Internal Functionality
//-------------------------------------
protected:
void transitionToState ( SnipeAimAndFireStates_t state );
void setInternalState ( SnipeAimAndFireStates_t state , const str &stateName );
void init ( Actor &self );
void think ();
void updateEnemy ();
void AdjustTorsoAngles ( const Vector &tagPos , const Vector &watchPosition );
void LerpTorsoBySpeed ( const Vector &angleDelta );
void setupStateAim ();
BehaviorReturnCode_t evaluateStateAim ();
void failureStateAim ( const str& failureReason );
void setupStatePreFire ();
BehaviorReturnCode_t evaluateStatePreFire ();
void failureStatePreFire ( const str& failureReason );
void setupStateAttack ();
BehaviorReturnCode_t evaluateStateAttack ();
void failureStateAttack ( const str& failureReason );
void setupStatePostFire ();
BehaviorReturnCode_t evaluateStatePostFire ();
void failureStatePostFire ( const str& failureReason );
//------------------------------------- //-------------------------------------
// Public Interface // Public Interface
//------------------------------------- //-------------------------------------
public: CLASS_PROTOTYPE(SnipeEnemy);
CLASS_PROTOTYPE( SnipeEnemy );
SnipeEnemy(); SnipeEnemy();
~SnipeEnemy(); ~SnipeEnemy();
void SetArgs ( Event *ev ); void SetArgs(Event* ev);
void AnimDone ( Event *ev ); void AnimDone(Event* ev);
void Begin ( Actor &self ); void Begin(Actor& self);
BehaviorReturnCode_t Evaluate ( Actor &self ); BehaviorReturnCode_t Evaluate(Actor& self);
void End ( Actor &self ); void End(Actor& self);
// Accessors // Accessors
virtual void Archive ( Archiver &arc ); virtual void Archive(Archiver& arc);
protected:
//-------------------------------------
// Internal Functionality
//-------------------------------------
void transitionToState(SnipeAimAndFireStates_t state);
void setInternalState(SnipeAimAndFireStates_t state, const str& stateName);
void init(Actor &self);
void think();
void updateEnemy();
void AdjustTorsoAngles(const Vector& tagPos, const Vector& watchPosition);
void LerpTorsoBySpeed(const Vector& angleDelta);
void setupStateAim();
BehaviorReturnCode_t evaluateStateAim();
void failureStateAim(const str& failureReason);
void setupStatePreFire();
BehaviorReturnCode_t evaluateStatePreFire();
void failureStatePreFire(const str& failureReason);
void setupStateAttack();
BehaviorReturnCode_t evaluateStateAttack();
void failureStateAttack(const str& failureReason);
void setupStatePostFire();
BehaviorReturnCode_t evaluateStatePostFire();
void failureStatePostFire(const str& failureReason);
private:
//------------------------------------
// Parameters
//------------------------------------
float _aimTime;
float _lockDownTime;
float _maxTorsoYaw;
float _maxTorsoPitch;
float _maxTorsoTurnSpeed;
int _shots;
//------------------------------------- //-------------------------------------
// Components // Components
//------------------------------------- //-------------------------------------
private: FireWeapon _fireWeapon;
FireWeapon _fireWeapon;
//------------------------------------- //-------------------------------------
// Member Variables // Member Variables
//------------------------------------- //-------------------------------------
private: SnipeAimAndFireStates_t _state;
SnipeAimAndFireStates_t _state; Vector _currentTorsoAngles;
Vector _currentTorsoAngles; float _endAimTime;
float _endAimTime; float _endLockDownTime;
float _endLockDownTime; EntityPtr _currentEnemy;
EntityPtr _currentEnemy; bool _canAttack;
bool _canAttack; bool _animDone;
bool _animDone; str _aimAnim;
str _aimAnim; str _preFireAnim;
str _preFireAnim; str _fireAnim;
str _fireAnim; str _postFireAnim;
str _postFireAnim; bool _fireFailed;
bool _fireFailed; Vector _lastGoodPosition;
Vector _lastGoodPosition; Vector _targetSpread;
Vector _targetSpread; Actor* _self;
Actor *_self; };
inline void SnipeEnemy::Archive(Archiver& arc) {
}; Behavior::Archive(arc);
inline void SnipeEnemy::Archive( Archiver &arc )
{
Behavior::Archive ( arc );
// //
// Archive Parameters // Archive Parameters
// //
arc.ArchiveFloat( &_aimTime ); arc.ArchiveFloat(&_aimTime);
arc.ArchiveFloat( &_lockDownTime ); arc.ArchiveFloat(&_lockDownTime);
arc.ArchiveFloat( &_maxTorsoYaw ); arc.ArchiveFloat(&_maxTorsoYaw);
arc.ArchiveFloat( &_maxTorsoPitch ); arc.ArchiveFloat(&_maxTorsoPitch);
arc.ArchiveFloat( &_maxTorsoTurnSpeed ); arc.ArchiveFloat(&_maxTorsoTurnSpeed);
arc.ArchiveInteger( &_shots ); arc.ArchiveInteger(&_shots);
arc.ArchiveVector( &_lastGoodPosition ); arc.ArchiveVector(&_lastGoodPosition);
arc.ArchiveVector( &_targetSpread ); arc.ArchiveVector(&_targetSpread);
// //
// Archive Components // Archive Components
// //
arc.ArchiveObject ( &_fireWeapon ); arc.ArchiveObject(&_fireWeapon);
// //
// Archive Member Variables // Archive Member Variables
// //
ArchiveEnum ( _state, SnipeAimAndFireStates_t ); ArchiveEnum(_state, SnipeAimAndFireStates_t);
arc.ArchiveVector ( &_currentTorsoAngles ); arc.ArchiveVector(&_currentTorsoAngles);
arc.ArchiveFloat( &_endAimTime ); arc.ArchiveFloat(&_endAimTime);
arc.ArchiveFloat( &_endLockDownTime ); arc.ArchiveFloat(&_endLockDownTime);
arc.ArchiveSafePointer( &_currentEnemy ); arc.ArchiveSafePointer(&_currentEnemy);
arc.ArchiveBool( &_canAttack ); arc.ArchiveBool(&_canAttack);
arc.ArchiveBool( &_animDone ); arc.ArchiveBool(&_animDone);
arc.ArchiveString( &_aimAnim ); arc.ArchiveString(&_aimAnim);
arc.ArchiveString( &_preFireAnim ); arc.ArchiveString(&_preFireAnim);
arc.ArchiveString( &_fireAnim ); arc.ArchiveString(&_fireAnim);
arc.ArchiveString( &_postFireAnim ); arc.ArchiveString(&_postFireAnim);
arc.ArchiveBool( &_fireFailed ); arc.ArchiveBool(&_fireFailed);
arc.ArchiveObjectPointer( ( Class ** )&_self ); arc.ArchiveObjectPointer((Class **)&_self);
} }