This commit is contained in:
Walter Julius Hennecke 2014-03-09 23:04:25 +01:00
parent bc0aecbafd
commit 5477f6b6b8

View file

@ -40,160 +40,149 @@ class TorsoAimAndFireWeapon;
// //
// Method of Use: Called From State Machine // Method of Use: Called From State Machine
//-------------------------------------------------------------- //--------------------------------------------------------------
class TorsoAimAndFireWeapon : public Behavior class TorsoAimAndFireWeapon : public Behavior {
{ public:
//------------------------------------ //------------------------------------
// States // States
//------------------------------------ //------------------------------------
public: typedef enum {
typedef enum TORSO_AIM_AND_FIRE_AIM,
{ TORSO_AIM_AND_FIRE_PRE_FIRE,
TORSO_AIM_AND_FIRE_AIM, TORSO_AIM_AND_FIRE_ATTACK,
TORSO_AIM_AND_FIRE_PRE_FIRE, TORSO_AIM_AND_FIRE_POST_FIRE,
TORSO_AIM_AND_FIRE_ATTACK, TORSO_AIM_AND_FIRE_SUCCESS,
TORSO_AIM_AND_FIRE_POST_FIRE, TORSO_AIM_AND_FIRE_FAILED
TORSO_AIM_AND_FIRE_SUCCESS, } TorsoAimAndFireStates_t;
TORSO_AIM_AND_FIRE_FAILED
} TorsoAimAndFireStates_t;
//------------------------------------
// Parameters
//------------------------------------
private:
float _aimTimeMin;
float _aimTimeMax;
float _fireTimeMin;
float _fireTimeMax;
bool _forceAttack;
float _maxTorsoYaw;
float _maxTorsoPitch;
float _maxTorsoTurnSpeed;
int _shots;
bool _aimOnly;
bool _repeat;
//-------------------------------------
// Internal Functionality
//-------------------------------------
protected:
void transitionToState ( TorsoAimAndFireStates_t state );
void setInternalState ( TorsoAimAndFireStates_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(TorsoAimAndFireWeapon);
CLASS_PROTOTYPE( TorsoAimAndFireWeapon );
TorsoAimAndFireWeapon(); TorsoAimAndFireWeapon();
~TorsoAimAndFireWeapon(); ~TorsoAimAndFireWeapon();
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(TorsoAimAndFireStates_t state);
void setInternalState(TorsoAimAndFireStates_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 _aimTimeMin;
float _aimTimeMax;
float _fireTimeMin;
float _fireTimeMax;
bool _forceAttack;
float _maxTorsoYaw;
float _maxTorsoPitch;
float _maxTorsoTurnSpeed;
int _shots;
bool _aimOnly;
bool _repeat;
//------------------------------------- //-------------------------------------
// Components // Components
//------------------------------------- //-------------------------------------
private: FireWeapon _fireWeapon;
FireWeapon _fireWeapon;
//------------------------------------- //-------------------------------------
// Member Variables // Member Variables
//------------------------------------- //-------------------------------------
private: TorsoAimAndFireStates_t _state;
TorsoAimAndFireStates_t _state; Vector _currentTorsoAngles;
Vector _currentTorsoAngles; float _endFireTime;
float _endFireTime; float _endAimTime;
float _endAimTime; 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; bool _endOnAimFail;
bool _endOnAimFail; Actor* _self;
Actor *_self; };
inline void TorsoAimAndFireWeapon::Archive(Archiver& arc) {
}; Behavior::Archive(arc);
inline void TorsoAimAndFireWeapon::Archive( Archiver &arc )
{
Behavior::Archive ( arc );
// //
// Archive Parameters // Archive Parameters
// //
arc.ArchiveFloat( &_aimTimeMin ); arc.ArchiveFloat(&_aimTimeMin);
arc.ArchiveFloat( &_aimTimeMax ); arc.ArchiveFloat(&_aimTimeMax);
arc.ArchiveFloat( &_fireTimeMin ); arc.ArchiveFloat(&_fireTimeMin);
arc.ArchiveFloat( &_fireTimeMax ); arc.ArchiveFloat(&_fireTimeMax);
arc.ArchiveBool( &_forceAttack ); arc.ArchiveBool(&_forceAttack);
arc.ArchiveFloat( &_maxTorsoYaw ); arc.ArchiveFloat(&_maxTorsoYaw);
arc.ArchiveFloat( &_maxTorsoPitch ); arc.ArchiveFloat(&_maxTorsoPitch);
arc.ArchiveFloat( &_maxTorsoTurnSpeed ); arc.ArchiveFloat(&_maxTorsoTurnSpeed);
arc.ArchiveBool( &_aimOnly ); arc.ArchiveBool(&_aimOnly);
arc.ArchiveInteger( &_shots ); arc.ArchiveInteger(&_shots);
arc.ArchiveBool( &_repeat ); arc.ArchiveBool(&_repeat);
// //
// Archive Components // Archive Components
// //
arc.ArchiveObject ( &_fireWeapon ); arc.ArchiveObject(&_fireWeapon);
// //
// Archive Member Variables // Archive Member Variables
// //
ArchiveEnum ( _state, TorsoAimAndFireStates_t ); ArchiveEnum(_state, TorsoAimAndFireStates_t);
arc.ArchiveVector ( &_currentTorsoAngles ); arc.ArchiveVector(&_currentTorsoAngles);
arc.ArchiveFloat( &_endFireTime ); arc.ArchiveFloat(&_endFireTime);
arc.ArchiveFloat( &_endAimTime ); arc.ArchiveFloat(&_endAimTime);
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.ArchiveBool( &_endOnAimFail ); arc.ArchiveBool(&_endOnAimFail);
arc.ArchiveObjectPointer( ( Class ** )&_self ); arc.ArchiveObjectPointer((Class **)&_self);
} }
#endif /* __TORSO_AIM_AND_FIRE_WEAPON___ */ #endif /* __TORSO_AIM_AND_FIRE_WEAPON___ */