CUGL 1.3
Cornell University Game Library
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
CULeafNode.h
1 //
2 // CULeafNode.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module provides support for a leaf behavior node. A leaf node has
6 // no children. Instead, it only has an associated action. Any running
7 // leaf node will execute its action on update.
8 //
9 // BehaviorNode objects are managed by BehaviorManager, and should never
10 // be allocated directly. Instead, you create a behavior node definition
11 // and pass it to a factor method in BehaviorManager.
12 //
13 // EXPERIMENTAL: This module is experimental. The API may change significantly
14 // in future CUGL releases.
15 //
16 // CUGL MIT License:
17 // This software is provided 'as-is', without any express or implied
18 // warranty. In no event will the authors be held liable for any damages
19 // arising from the use of this software.
20 //
21 // Permission is granted to anyone to use this software for any purpose,
22 // including commercial applications, and to alter it and redistribute it
23 // freely, subject to the following restrictions:
24 //
25 // 1. The origin of this software must not be misrepresented; you must not
26 // claim that you wrote the original software. If you use this software
27 // in a product, an acknowledgment in the product documentation would be
28 // appreciated but is not required.
29 //
30 // 2. Altered source versions must be plainly marked as such, and must not
31 // be misrepresented as being the original software.
32 //
33 // 3. This notice may not be removed or altered from any source distribution.
34 //
35 // Author: Apurv Sethi and Andrew Matsumoto (with Walker White)
36 // Version: 5/21/2018
37 //
38 #ifndef __CU_LEAF_NODE_H__
39 #define __CU_LEAF_NODE_H__
40 #include <cugl/ai/behavior/CUBehaviorNode.h>
41 #include <cugl/ai/behavior/CUBehaviorAction.h>
42 #include <string>
43 #include <vector>
44 
45 namespace cugl {
46  namespace ai {
56 class LeafNode : public BehaviorNode {
57 #pragma mark Values
58 protected:
60  std::shared_ptr<BehaviorAction> _action;
61 
62 public:
63 #pragma mark -
64 #pragma mark Constructors
65 
71  LeafNode();
72 
76  ~LeafNode() { dispose(); }
77 
85  void dispose() override;
86 
87 #pragma mark Attributes
88 
98  std::string toString(bool verbose = false) const override;
99 
108  const BehaviorAction* getAction() const { return _action.get(); }
109 
115  void setAction(const std::shared_ptr<BehaviorAction>& action) {
116  _action = action;
117  }
118 
119 #pragma mark Behavior Management
120 
127  void reset() override;
128 
136  void pause() override;
137 
144  void resume() override;
145 
151  void preempt() override;
152 
167  void query(float dt) override;
168 
184  BehaviorNode::State update(float dt) override;
185 
186 };
187  }
188 }
189 #endif /* __CU_LEAF_NODE_H__ */
cugl::ai::LeafNode
Definition: CULeafNode.h:56
cugl::ai::LeafNode::getAction
const BehaviorAction * getAction() const
Definition: CULeafNode.h:108
cugl::ai::LeafNode::reset
void reset() override
cugl::ai::BehaviorNode
Definition: CUBehaviorNode.h:280
cugl::ai::LeafNode::update
BehaviorNode::State update(float dt) override
cugl::ai::LeafNode::toString
std::string toString(bool verbose=false) const override
cugl::ai::LeafNode::LeafNode
LeafNode()
cugl::ai::LeafNode::setAction
void setAction(const std::shared_ptr< BehaviorAction > &action)
Definition: CULeafNode.h:115
cugl::ai::LeafNode::dispose
void dispose() override
cugl::ai::LeafNode::~LeafNode
~LeafNode()
Definition: CULeafNode.h:76
cugl::ai::LeafNode::resume
void resume() override
cugl::ai::BehaviorNode::State
State
Definition: CUBehaviorNode.h:290
cugl::ai::LeafNode::preempt
void preempt() override
cugl::ai::LeafNode::pause
void pause() override
cugl::ai::LeafNode::query
void query(float dt) override
cugl::ai::BehaviorAction
Definition: CUBehaviorAction.h:126
cugl::ai::LeafNode::_action
std::shared_ptr< BehaviorAction > _action
Definition: CULeafNode.h:60