24 typedef std::shared_ptr<AI> AIPtr;
29 #define CONDITION_CLASS(ConditionName) \
30 explicit ConditionName(const std::string& parameters = "") : \
31 ::ai::ICondition(#ConditionName, parameters) { \
34 virtual ~ConditionName() { \
41 #define CONDITION_FACTORY_NO_IMPL(ConditionName) \
43 class Factory: public ::ai::IConditionFactory { \
45 ::ai::ConditionPtr create (const ::ai::ConditionFactoryContext *ctx) const override; \
47 static const Factory& getFactory() { \
48 static Factory FACTORY; \
55 #define CONDITION_FACTORY(ConditionName) \
57 class Factory: public ::ai::IConditionFactory { \
59 ::ai::ConditionPtr create (const ::ai::ConditionFactoryContext *ctx) const override { \
60 return std::make_shared<ConditionName>(ctx->parameters); \
63 static const Factory& getFactory() { \
64 static Factory FACTORY; \
73 #define CONDITION_FACTORY_SINGLETON \
75 class Factory: public ::ai::IConditionFactory { \
76 ::ai::ConditionPtr create (const ::ai::ConditionFactoryContext *) const { \
80 static const Factory& getFactory() { \
81 static Factory FACTORY; \
88 #define CONDITION_CLASS_SINGLETON(ConditionName) \
90 CONDITION_CLASS(ConditionName) \
92 static ConditionPtr& get() { \
93 AI_THREAD_LOCAL ConditionName* c = nullptr; \
94 if (c == nullptr) { c = new ConditionName; } \
95 AI_THREAD_LOCAL ConditionPtr _instance(c); \
98 CONDITION_FACTORY_SINGLETON
100 #define CONDITION_PRINT_SUBCONDITIONS_GETCONDITIONNAMEWITHVALUE \
101 void getConditionNameWithValue(std::stringstream& s, const ::ai::AIPtr& entity) override { \
104 for (::ai::ConditionsConstIter i = _conditions.begin(); i != _conditions.end(); ++i) { \
108 s << (*i)->getNameWithConditions(entity); \
115 typedef std::shared_ptr<ICondition> ConditionPtr;
116 typedef std::vector<ConditionPtr> Conditions;
117 typedef Conditions::iterator ConditionsIter;
118 typedef Conditions::const_iterator ConditionsConstIter;
126 static int getNextId() {
127 static int _nextId = 0;
128 const int id = _nextId++;
136 const std::string _name;
137 const std::string _parameters;
148 s <<
"{" << _parameters <<
"}";
151 ICondition(
const std::string& name,
const std::string& parameters) :
152 _id(getNextId()), _name(name), _parameters(parameters) {
155 virtual ~ICondition() {
163 virtual bool evaluate(
const AIPtr& entity) = 0;
168 const std::string&
getName()
const;
185 s << (
evaluate(entity) ?
"1" :
"0");
A condition can be placed on a TreeNode to decide which node is going to get executed. In general they are stateless. If they are not, it should explicitly get noted.
Definition: ICondition.h:124
virtual bool evaluate(const AIPtr &entity)=0
Checks whether the condition evaluates to true for the given entity.
Definition: MemoryAllocator.h:26
virtual void getConditionNameWithValue(std::stringstream &s, const AIPtr &entity)
Override this method to get a more detailed result in getNameWithConditions()
Definition: ICondition.h:146
int _id
Every node has an id to identify it. It's unique per type.
Definition: ICondition.h:135
std::string getNameWithConditions(const AIPtr &entity)
Returns the full condition string with all related conditions and results of the evaluation method...
Definition: ICondition.h:180
const std::string & getParameters() const
Returns the raw parameters of the condition.
Definition: ICondition.h:195
const std::string & getName() const
Returns the short name of the condition - without any related conditions or results.
Definition: ICondition.h:191