diff --git a/main/source/mod/AvHObjective.cpp b/main/source/mod/AvHObjective.cpp new file mode 100644 index 0000000..5ab90a4 --- /dev/null +++ b/main/source/mod/AvHObjective.cpp @@ -0,0 +1,197 @@ +#include "mod/AvHObjective.h" +#include +#include + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +AvHObjective::AvHObjective(const char *inName, const char *inTitle, const char *inDescription) +{ + this->mName = inName; + this->mTitle = inTitle; + this->mDescription = inDescription; + this->mState = OBJECTIVE_INDETERMINED; +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +AvHObjectiveState AvHObjective::GetState() +{ + return this->mState; +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +void AvHObjective::SetState(AvHObjectiveState inState) +{ + this->mState = inState; +} + + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +AvHObjectiveGroup::AvHObjectiveGroup() +{ + this->mTriggerOnComplete = false; + this->mTriggerOnFailed = false; + this->mState = OBJECTIVE_INDETERMINED; +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +AvHObjectiveGroup::~AvHObjectiveGroup() +{ + this->Clear(); +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +void AvHObjectiveGroup::Clear() +{ + AvHObjectiveList::iterator iter, end; + iter = this->mObjectives.begin(); + end = this->mObjectives.end(); + for(; iter < end; iter++) + { + delete((AvHObjective *)(iter)); + } + this->mObjectives.clear(); + + this->mName.clear(); + this->mTriggerOnComplete = false; + this->mTriggerOnFailed = false; + this->mState = OBJECTIVE_INDETERMINED; +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +AvHObjectiveState AvHObjectiveGroup::GetState() +{ + return this->mState; +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +AvHObjectiveState AvHObjectiveGroup::UpdateState() +{ + // iterate through the vector this->mObjectives + AvHObjectiveList::iterator iter, end; + iter = this->mObjectives.begin(); + end = this->mObjectives.end(); + + bool failed = true; + bool completed = true; + for(; iter < end; iter++) + { + AvHObjectiveState state = ((AvHObjective *)(iter))->mState; + if (state == OBJECTIVE_FAILED) + completed = false; + else if (state == OBJECTIVE_COMPLETED) + failed = false; + else if (state == OBJECTIVE_INDETERMINED) + completed = failed = false; + } + if (completed) + this->mState = OBJECTIVE_COMPLETED; + else if (failed) + this->mState = OBJECTIVE_FAILED; + + return this->mState; +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +AvHObjective *AvHObjectiveGroup::AddObjective(const char *inName, const char *inTitle, const char *inDescription) +{ + AvHObjective *theObjective = new AvHObjective(inName, inTitle, inDescription); + this->mObjectives.push_back(theObjective); + return theObjective; +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +AvHObjectiveManager::AvHObjectiveManager() +{ +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +AvHObjectiveManager::~AvHObjectiveManager() +{ + this->Clear(); +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +void AvHObjectiveManager::Clear() +{ + AvHObjectiveGroupList::iterator iter, end; + iter = this->mObjectiveGroups.begin(); + end = this->mObjectiveGroups.end(); + for(; iter != end; iter++) + { + delete((AvHObjectiveGroup *)(iter->second)); + } + this->mObjectiveGroups.clear(); + this->mObjectives.clear(); +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +AvHObjectiveGroup *AvHObjectiveManager::FindGroup(const char *inGroup) +{ + AvHObjectiveGroupList::iterator iter = this->mObjectiveGroups.begin(); + if (iter != this->mObjectiveGroups.end()) + { + return ((AvHObjectiveGroup *)(iter->second)); + } + return NULL; +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +AvHObjective *AvHObjectiveManager::FindObjective(const char *inObjectivename) +{ + AvHObjectiveMapList::iterator iter = this->mObjectives.find(inObjectivename); + if (iter != this->mObjectives.end()) + { + return ((AvHObjective *)(iter->second)); + } + return NULL; +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +void AvHObjectiveManager::AddObjective(const char *inGroup, const char *inName, const char *inTitle, const char *inDescription) +{ + AvHObjectiveGroup *theObjectiveGroup = this->FindGroup(inGroup); + if (!theObjectiveGroup) + { + theObjectiveGroup = new AvHObjectiveGroup(); + this->mObjectiveGroups.insert(std::make_pair(inGroup, theObjectiveGroup)); + } + AvHObjective *theObjective = theObjectiveGroup->AddObjective(inName, inTitle, inDescription); + this->mObjectives.insert(std::make_pair(inName, theObjective)); +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +void AvHObjectiveManager::SetObjectiveGroupTriggerState(const char *inGroup, AvHObjectiveState inState) +{ + AvHObjectiveGroup *theObjectiveGroup = this->FindGroup(inGroup); + if (theObjectiveGroup) + { + if (inState == OBJECTIVE_COMPLETED) + theObjectiveGroup->mTriggerOnComplete = true; + else if (inState == OBJECTIVE_FAILED) + theObjectiveGroup->mTriggerOnFailed = true; + } +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +AvHObjectiveState AvHObjectiveManager::GetObjectivesState() +{ + AvHObjectiveGroupList::iterator iter, end; + iter = this->mObjectiveGroups.begin(); + end = this->mObjectiveGroups.end(); + for(; iter != end; iter++) + { + bool triggerOnComplete = ((AvHObjectiveGroup *)(iter->second))->mTriggerOnComplete; + bool triggerOnFailed = ((AvHObjectiveGroup *)(iter->second))->mTriggerOnFailed; + if (triggerOnComplete || triggerOnFailed) + { + AvHObjectiveState state = ((AvHObjectiveGroup *)(iter->second))->UpdateState(); + + if (triggerOnComplete && state == OBJECTIVE_COMPLETED) + return OBJECTIVE_COMPLETED; + else if (triggerOnFailed && state == OBJECTIVE_FAILED) + return OBJECTIVE_FAILED; + } + } + return OBJECTIVE_INDETERMINED; +} \ No newline at end of file diff --git a/main/source/mod/AvHObjective.h b/main/source/mod/AvHObjective.h new file mode 100644 index 0000000..dd1e003 --- /dev/null +++ b/main/source/mod/AvHObjective.h @@ -0,0 +1,65 @@ +#ifndef AVH_OBJECTIVE_H +#define AVH_OBJECTIVE_H + +#include +#include +#include + +enum AvHObjectiveState +{ + OBJECTIVE_INDETERMINED, + OBJECTIVE_FAILED, + OBJECTIVE_COMPLETED +}; + +class AvHObjective +{ +public: + AvHObjective(const char *inName, const char *inTitle, const char *inDescription); + AvHObjectiveState GetState(); + void SetState(AvHObjectiveState inState); + std::string mName; + std::string mTitle; + std::string mDescription; + AvHObjectiveState mState; +}; + +typedef std::vector AvHObjectiveList; + +class AvHObjectiveGroup +{ +public: + AvHObjectiveGroup(); + ~AvHObjectiveGroup(); + void Clear(); + AvHObjectiveState GetState(); + AvHObjectiveState UpdateState(); + AvHObjective *AddObjective(const char *inName, const char *inTitle, const char *inDescription); + AvHObjectiveList mObjectives; + std::string mName; + bool mTriggerOnFailed; + bool mTriggerOnComplete; + AvHObjectiveState mState; +}; + +typedef std::map AvHObjectiveGroupList; +typedef std::map AvHObjectiveMapList; + +class AvHObjectiveManager +{ +public: + AvHObjectiveManager(); + ~AvHObjectiveManager(); + void Clear(); + AvHObjectiveGroup *FindGroup(const char *inGroup); + AvHObjective *FindObjective(const char *inObjectivename); + void AddObjective(const char *inGroup, const char *inName, const char *inTitle, const char *inDescription); + void AddObjectiveGroup(const char *inGroup); + void SetObjectiveGroupTriggerState(const char *inGroup, AvHObjectiveState inState); + AvHObjectiveState GetObjectivesState(); + AvHObjectiveGroupList mObjectiveGroups; + AvHObjectiveMapList mObjectives; + +}; + +#endif \ No newline at end of file