CUGL 1.3
Cornell University Game Library
CUDecoratorNode.h
1 //
2 // CUDecoratorNode.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module provides support for a decorator behavior node. A decorator
6 // node has exactly one child, and is used to "change" the behavior of an
7 // existing node.
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_DECORATOR_NODE_H__
39 #define __CU_DECORATOR_NODE_H__
40 
41 #include <cugl/ai/behavior/CUBehaviorNode.h>
42 #include <string>
43 #include <vector>
44 
45 namespace cugl {
46  namespace ai {
47 
63 class DecoratorNode : public BehaviorNode {
64 public:
65 #pragma mark Constructors
66 
72  DecoratorNode() : BehaviorNode() { _classname = "DecoratorNode"; };
73 
78 
79 #pragma mark Tree Management
80 
89  const BehaviorNode* getChild() const {
90  return _children[0].get();
91  }
92 
104  template <typename T>
105  const T* getChild() const {
106  return dynamic_cast<const T*>(getChild());
107  }
108 
123  virtual void query(float dt) override;
124 
140  virtual BehaviorNode::State update(float dt) override;
141 };
142 
143  }
144 }
145 #endif /* __CU_DECORATOR_NODE_H__ */
cugl::ai::DecoratorNode::DecoratorNode
DecoratorNode()
Definition: CUDecoratorNode.h:72
cugl::ai::BehaviorNode::_classname
std::string _classname
Definition: CUBehaviorNode.h:306
cugl::ai::DecoratorNode::update
virtual BehaviorNode::State update(float dt) override
cugl::ai::DecoratorNode::query
virtual void query(float dt) override
cugl::ai::DecoratorNode::getChild
const BehaviorNode * getChild() const
Definition: CUDecoratorNode.h:89
cugl::ai::BehaviorNode
Definition: CUBehaviorNode.h:280
cugl::ai::BehaviorNode::dispose
virtual void dispose()
cugl::ai::DecoratorNode::~DecoratorNode
~DecoratorNode()
Definition: CUDecoratorNode.h:77
cugl::ai::BehaviorNode::State
State
Definition: CUBehaviorNode.h:290
cugl::ai::DecoratorNode
Definition: CUDecoratorNode.h:63
cugl::ai::BehaviorNode::_children
std::vector< std::shared_ptr< BehaviorNode > > _children
Definition: CUBehaviorNode.h:321