12 #define TIMERNODE_CLASS(NodeName) \
13 NodeName(const std::string& name, const std::string& parameters, const ConditionPtr& condition) : \
14 ITimedNode(name, parameters, condition) { \
15 _type = AI_STRINGIFY(NodeName); \
17 virtual ~NodeName() { \
20 NODE_FACTORY(NodeName)
30 ITimedNode(
const std::string& name,
const std::string& parameters,
const ConditionPtr& condition) :
31 TreeNode(name, parameters, condition), _timerMillis(NOTSTARTED) {
32 if (!parameters.empty()) {
33 _millis = ::atol(parameters.c_str());
40 TreeNodeStatus
execute(
const AIPtr& entity, int64_t deltaMillis)
override {
42 if (result == CANNOTEXECUTE)
45 if (_timerMillis == NOTSTARTED) {
46 _timerMillis = _millis;
47 const TreeNodeStatus status =
executeStart(entity, deltaMillis);
48 if (status == FINISHED)
49 _timerMillis = NOTSTARTED;
50 return state(entity, status);
53 if (_timerMillis - deltaMillis > 0) {
54 _timerMillis -= deltaMillis;
56 if (status == FINISHED)
57 _timerMillis = NOTSTARTED;
58 return state(entity, status);
61 _timerMillis = NOTSTARTED;
TreeNode(const std::string &name, const std::string ¶meters, const ConditionPtr &condition)
Definition: TreeNode.h:121
virtual TreeNodeStatus executeExpired(const AIPtr &, int64_t)
Called in the frame where the timer expired.
Definition: ITimedNode.h:89
virtual TreeNodeStatus execute(const AIPtr &entity, int64_t deltaMillis)
Definition: TreeNodeImpl.h:184
A timed node is a TreeNode that is executed until a given time (millis) is elapsed.
Definition: ITimedNode.h:25
The base class for all behaviour tree actions.
Definition: TreeNode.h:88
virtual TreeNodeStatus executeRunning(const AIPtr &, int64_t)
Called whenever the timer is running. Not called in the frame where the timer is started or in the fr...
Definition: ITimedNode.h:81
TreeNodeStatus execute(const AIPtr &entity, int64_t deltaMillis) override
Definition: ITimedNode.h:40
virtual TreeNodeStatus executeStart(const AIPtr &, int64_t)
Called whenever the timer is started or restarted.
Definition: ITimedNode.h:69