23 Limit(
const std::string& name,
const std::string& parameters,
const ConditionPtr& condition) :
24 TreeNode(name, parameters, condition) {
26 if (!parameters.empty()) {
27 _amount = ::atoi(parameters.c_str());
33 TreeNodeStatus
execute(
const AIPtr& entity, int64_t deltaMillis)
override {
34 ai_assert(_children.size() == 1,
"Limit must have exactly one node");
40 const int alreadyExecuted = getLimitState(entity);
41 if (alreadyExecuted >= _amount) {
42 return state(entity, FINISHED);
45 const TreeNodePtr& treeNode = *_children.begin();
46 const TreeNodeStatus status = treeNode->execute(entity, deltaMillis);
47 setLimitState(entity, alreadyExecuted + 1);
48 if (status == RUNNING) {
49 return state(entity, RUNNING);
51 return state(entity, FAILED);
#define ai_assert(condition,...)
Provide your own assert - this is only executed in DEBUG mode.
Definition: Types.h:75
TreeNode(const std::string &name, const std::string ¶meters, const ConditionPtr &condition)
Definition: TreeNode.h:121
A decorator node which limits the execution of the attached child to a specified amount of runs...
Definition: Limit.h:17
TreeNodeStatus execute(const AIPtr &entity, int64_t deltaMillis) override
Definition: Limit.h:33
virtual TreeNodeStatus execute(const AIPtr &entity, int64_t deltaMillis)
Definition: TreeNodeImpl.h:184
The base class for all behaviour tree actions.
Definition: TreeNode.h:88
#define NODE_FACTORY(NodeName)
A node factory macro to ease and unify the registration at AIRegistry.
Definition: TreeNode.h:54