This commit is contained in:
Walter Julius Hennecke 2014-03-09 22:23:28 +01:00
parent 7b73980dc2
commit 66f262fd5f
1 changed files with 191 additions and 206 deletions

View File

@ -40,164 +40,149 @@ class HealGroupMember;
// //
// Method of Use: Called From State Machine // Method of Use: Called From State Machine
//-------------------------------------------------------------- //--------------------------------------------------------------
class HealGroupMember : public Behavior class HealGroupMember : public Behavior {
{ public:
//------------------------------------ //------------------------------------
// States // States
//------------------------------------ //------------------------------------
public: typedef enum {
typedef enum
{
HGM_STATE_GOTO_ENTITY, HGM_STATE_GOTO_ENTITY,
HGM_STATE_FACE_TARGET, HGM_STATE_FACE_TARGET,
HGM_STATE_ANIMATE, HGM_STATE_ANIMATE,
HGM_STATE_HEAL, HGM_STATE_HEAL,
HGM_STATE_FAILED, HGM_STATE_FAILED,
HGM_STATE_SUCCESS, HGM_STATE_SUCCESS,
} healGroupMemberStates_t; } healGroupMemberStates_t;
typedef struct typedef struct {
{
EntityPtr ent; EntityPtr ent;
float health; float health;
float dist; float dist;
bool treated; bool treated;
} triageEntry_t; } triageEntry_t;
//------------------------------------
// Parameters
//------------------------------------
private:
str _anim;
float _healDistance;
float _maxDistance;
float _initialHealPercentage;
float _regenHealPercentage;
float _regenInterval;
float _maxPercentage;
//-------------------------------------
// Internal Functionality
//-------------------------------------
protected:
void init ( Actor &self );
void doHeal ( Actor &self );
void setupGotoEntity ( Actor &self );
void doGotoEntity ( Actor &self );
void gotoEntityFailed ( Actor &self );
void setupRotateToEntity ( Actor &self );
void doRotateToEntity ( Actor &self );
void rotateToEntityFailed ( Actor &self );
void setupAnimate ( Actor &self );
void doAnimate ( Actor &self );
void animateFailed ( Actor &self );
void updateTriageList ( Actor &self );
void updateTriageEntry ( Actor &self , Entity *ent );
bool allPatientsTreated ( Actor &self );
bool patientTreated ( Actor &self , Entity *ent );
void treatedPatient ( Actor &self , Entity *ent );
Actor* findHighestPriorityPatient ( Actor &self );
//------------------------------------- //-------------------------------------
// Public Interface // Public Interface
//------------------------------------- //-------------------------------------
public: CLASS_PROTOTYPE(HealGroupMember);
CLASS_PROTOTYPE( HealGroupMember );
HealGroupMember(); HealGroupMember();
~HealGroupMember(); ~HealGroupMember();
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);
virtual void Archive ( Archiver &arc ); virtual void Archive(Archiver& arc);
protected:
//-------------------------------------
// Internal Functionality
//-------------------------------------
void init(Actor& self);
void doHeal(Actor& self);
void setupGotoEntity(Actor& self);
void doGotoEntity(Actor& self);
void gotoEntityFailed(Actor& self);
void setupRotateToEntity(Actor& self);
void doRotateToEntity(Actor& self);
void rotateToEntityFailed(Actor& self);
void setupAnimate(Actor& self);
void doAnimate(Actor& self);
void animateFailed(Actor& self);
void updateTriageList(Actor& self);
void updateTriageEntry(Actor& self, Entity* ent);
bool allPatientsTreated(Actor& self);
bool patientTreated(Actor& self, Entity* ent);
void treatedPatient(Actor& self, Entity* ent);
Actor* findHighestPriorityPatient(Actor& self);
private:
//------------------------------------
// Parameters
//------------------------------------
str _anim;
float _healDistance;
float _maxDistance;
float _initialHealPercentage;
float _regenHealPercentage;
float _regenInterval;
float _maxPercentage;
//------------------------------------- //-------------------------------------
// Components // Components
//------------------------------------- //-------------------------------------
private: GotoEntity _gotoEntity;
GotoEntity _gotoEntity; RotateToEntity _rotateToEntity;
RotateToEntity _rotateToEntity;
//------------------------------------- //-------------------------------------
// Member Variables // Member Variables
//------------------------------------- //-------------------------------------
private: unsigned int _state;
unsigned int _state; ActorPtr _currentPatient;
ActorPtr _currentPatient; str _legAnim;
str _legAnim; float _nextTriageUpdate;
float _nextTriageUpdate; Container<triageEntry_t*> _triageList;
Container<triageEntry_t*> _triageList; };
}; inline void HealGroupMember::Archive(Archiver& arc) {
int num, i;
inline void HealGroupMember::Archive( Archiver &arc )
{
int num , i;
triageEntry_t* checkEntry; triageEntry_t* checkEntry;
Behavior::Archive ( arc ); Behavior::Archive(arc);
// Archive Parameters // Archive Parameters
arc.ArchiveString ( &_anim ); arc.ArchiveString(&_anim);
arc.ArchiveFloat ( &_healDistance ); arc.ArchiveFloat(&_healDistance);
arc.ArchiveFloat ( &_maxDistance ); arc.ArchiveFloat(&_maxDistance);
arc.ArchiveFloat ( &_initialHealPercentage ); arc.ArchiveFloat(&_initialHealPercentage);
arc.ArchiveFloat ( &_regenHealPercentage ); arc.ArchiveFloat(&_regenHealPercentage);
arc.ArchiveFloat ( &_regenInterval ); arc.ArchiveFloat(&_regenInterval);
arc.ArchiveFloat ( &_maxPercentage ); arc.ArchiveFloat(&_maxPercentage);
// Archive Components // Archive Components
arc.ArchiveObject ( &_gotoEntity ); arc.ArchiveObject(&_gotoEntity);
arc.ArchiveObject ( &_rotateToEntity ); arc.ArchiveObject(&_rotateToEntity);
// Archive Member Vars // Archive Member Vars
arc.ArchiveUnsigned ( &_state ); arc.ArchiveUnsigned(&_state);
arc.ArchiveSafePointer ( &_currentPatient ); arc.ArchiveSafePointer(&_currentPatient);
arc.ArchiveString ( &_legAnim ); arc.ArchiveString(&_legAnim);
arc.ArchiveFloat ( &_nextTriageUpdate ); arc.ArchiveFloat(&_nextTriageUpdate);
if ( arc.Saving() ) if (arc.Saving()) {
{
num = _triageList.NumObjects(); num = _triageList.NumObjects();
arc.ArchiveInteger( &num ); arc.ArchiveInteger(&num);
for ( i = num ; i > 0 ; i-- ) for (i = num; i > 0; i--) {
{ checkEntry = _triageList.ObjectAt(i);
checkEntry = _triageList.ObjectAt( i ); arc.ArchiveSafePointer(&checkEntry->ent);
arc.ArchiveSafePointer( &checkEntry->ent ); arc.ArchiveFloat(&checkEntry->health);
arc.ArchiveFloat( &checkEntry->health ); arc.ArchiveFloat(&checkEntry->dist);
arc.ArchiveFloat( &checkEntry->dist ); arc.ArchiveBool(&checkEntry->treated);
arc.ArchiveBool( &checkEntry->treated );
}
} }
else } else {
{ arc.ArchiveInteger(&num);
arc.ArchiveInteger( &num );
_triageList.ClearObjectList(); _triageList.ClearObjectList();
_triageList.Resize( num ); _triageList.Resize(num);
for ( i = 1 ; i<= num ; i++ ) for (i = 1; i <= num; i++) {
{
checkEntry = new triageEntry_t; checkEntry = new triageEntry_t;
arc.ArchiveSafePointer( &checkEntry->ent); arc.ArchiveSafePointer(&checkEntry->ent);
arc.ArchiveFloat( &checkEntry->health ); arc.ArchiveFloat(&checkEntry->health);
arc.ArchiveFloat( &checkEntry->dist ); arc.ArchiveFloat(&checkEntry->dist);
arc.ArchiveBool( &checkEntry->treated ); arc.ArchiveBool(&checkEntry->treated);
}
} }
}
} }