mirror of
https://github.com/ENSL/NS.git
synced 2024-11-10 15:21:54 +00:00
git-svn-id: https://unknownworlds.svn.cloudforge.com/ns1@287 67975925-1194-0748-b3d5-c16f83f1a3a1
This commit is contained in:
parent
d7194eb748
commit
62a773737b
2 changed files with 262 additions and 0 deletions
197
main/source/mod/AvHObjective.cpp
Normal file
197
main/source/mod/AvHObjective.cpp
Normal file
|
@ -0,0 +1,197 @@
|
|||
#include "mod/AvHObjective.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
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;
|
||||
}
|
65
main/source/mod/AvHObjective.h
Normal file
65
main/source/mod/AvHObjective.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
#ifndef AVH_OBJECTIVE_H
|
||||
#define AVH_OBJECTIVE_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
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<AvHObjective *> 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<const char *, AvHObjectiveGroup *> AvHObjectiveGroupList;
|
||||
typedef std::map<const char *, AvHObjective *> 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
|
Loading…
Reference in a new issue