SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
AIStubTypes.h
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include <vector>
7 #include <string>
8 #include "common/Math.h"
9 #include "common/Types.h"
10 #include "tree/TreeNode.h"
11 
12 namespace ai {
13 
20  AIStateAggroEntry(ai::CharacterId _id, float _aggro) :
21  id(_id), aggro(_aggro) {
22  }
23  ai::CharacterId id;
24  float aggro;
25 };
26 
30 class AIStateAggro {
31 private:
32  std::vector<AIStateAggroEntry> _aggro;
33 public:
34  inline void reserve(std::size_t size) {
35  if (size > 0)
36  _aggro.reserve(size);
37  }
38 
39  inline void addAggro(const AIStateAggroEntry& entry) {
40  _aggro.push_back(entry);
41  }
42 
43  inline const std::vector<AIStateAggroEntry>& getAggro() const {
44  return _aggro;
45  }
46 };
47 
49 private:
50  int32_t _id;
51  std::string _name;
52  std::string _type;
53  std::string _parameters;
54  std::string _conditionType;
55  std::string _conditionParameters;
56 public:
57  AIStateNodeStatic(const int32_t id, const std::string& name, const std::string& type, const std::string& parameters, const std::string& conditionType, const std::string& conditionParameters) :
58  _id(id), _name(name), _type(type), _parameters(parameters), _conditionType(conditionType), _conditionParameters(conditionParameters) {
59  }
60 
62  _id(-1) {
63  }
64 
65  inline int32_t getId() const {
66  return _id;
67  }
68 
69  inline const std::string& getName() const {
70  return _name;
71  }
72 
73  inline const std::string& getType() const {
74  return _type;
75  }
76 
80  inline const std::string& getParameters() const {
81  return _parameters;
82  }
83 
87  inline const std::string& getConditionParameters() const {
88  return _conditionParameters;
89  }
90 
91  inline std::string getCondition() const {
92  return _conditionType + "(" + _conditionParameters + ")";
93  }
94 
98  inline const std::string& getConditionType() const {
99  return _conditionType;
100  }
101 };
102 
106 class AIStateNode {
107 private:
108  int32_t _nodeId;
109  std::string _condition;
110  typedef std::vector<AIStateNode> NodeVector;
111  NodeVector _children;
112  int64_t _lastRun;
113  TreeNodeStatus _status;
114  bool _currentlyRunning;
115 public:
116  AIStateNode(int32_t id, const std::string& condition, int64_t lastRun, TreeNodeStatus status, bool currentlyRunning) :
117  _nodeId(id), _condition(condition), _lastRun(lastRun), _status(status), _currentlyRunning(currentlyRunning) {
118  }
119 
120  AIStateNode() :
121  _nodeId(-1), _lastRun(-1L), _status(UNKNOWN), _currentlyRunning(false) {
122  }
123 
124  void addChildren(const AIStateNode& child) {
125  _children.push_back(child);
126  }
127 
128  void addChildren(AIStateNode&& child) {
129  _children.push_back(std::move(child));
130  }
131 
132  inline const std::vector<AIStateNode>& getChildren() const {
133  return _children;
134  }
135 
136  inline std::vector<AIStateNode>& getChildren() {
137  return _children;
138  }
139 
140  inline int32_t getNodeId() const {
141  return _nodeId;
142  }
143 
144  inline const std::string& getCondition() const {
145  return _condition;
146  }
147 
151  inline int64_t getLastRun() const {
152  return _lastRun;
153  }
154 
158  inline TreeNodeStatus getStatus() const {
159  return _status;
160  }
161 
166  inline bool isRunning() const {
167  return _currentlyRunning;
168  }
169 };
170 
175 private:
176  ai::CharacterId _id;
177  glm::vec3 _position;
178  float _orientation;
179  CharacterAttributes _attributes;
180 public:
181  AIStateWorld() : _id(-1), _position(0.0f, 0.0f, 0.0f), _orientation(0.0f) {}
182 
183  AIStateWorld(const ai::CharacterId& id, const glm::vec3& position, float orientation, const CharacterAttributes& attributes) :
184  _id(id), _position(position), _orientation(orientation), _attributes(attributes) {
185  }
186 
187  AIStateWorld(const ai::CharacterId& id, const glm::vec3& position, float orientation, CharacterAttributes&& attributes) :
188  _id(id), _position(position), _orientation(orientation), _attributes(std::move(attributes)) {
189  }
190 
191  AIStateWorld(const ai::CharacterId& id, const glm::vec3& position, float orientation) :
192  _id(id), _position(position), _orientation(orientation) {
193  }
194 
195  inline bool operator==(const AIStateWorld &other) const {
196  return _id == other._id;
197  }
198 
199  inline bool operator<(const AIStateWorld &other) const {
200  return _id < other._id;
201  }
202 
206  inline const ai::CharacterId& getId() const {
207  return _id;
208  }
209 
215  inline float getOrientation() const {
216  return _orientation;
217  }
218 
222  inline const glm::vec3& getPosition() const {
223  return _position;
224  }
225 
229  inline const CharacterAttributes& getAttributes() const {
230  return _attributes;
231  }
232 
236  inline CharacterAttributes& getAttributes() {
237  return _attributes;
238  }
239 };
240 
241 }
bool isRunning() const
Some nodes have a state that holds which children is currently running.
Definition: AIStubTypes.h:166
const std::string & getConditionParameters() const
Returns the raw condition parameters.
Definition: AIStubTypes.h:87
TreeNodeStatus getStatus() const
Definition: AIStubTypes.h:158
float getOrientation() const
Definition: AIStubTypes.h:215
This is a representation of a character state for the serialization.
Definition: AIStubTypes.h:174
CharacterAttributes & getAttributes()
Definition: AIStubTypes.h:236
int64_t getLastRun() const
Definition: AIStubTypes.h:151
The list of aggro entry for a character.
Definition: AIStubTypes.h:30
const std::string & getConditionType() const
Returns the raw condition type string.
Definition: AIStubTypes.h:98
Definition: AIStubTypes.h:48
const ai::CharacterId & getId() const
Definition: AIStubTypes.h:206
The aggro entry for the AIStateAggro.
Definition: AIStubTypes.h:19
This is a representation of a behaviour tree node for the serialization.
Definition: AIStubTypes.h:106
const CharacterAttributes & getAttributes() const
Definition: AIStubTypes.h:229
const glm::vec3 & getPosition() const
Definition: AIStubTypes.h:222
const std::string & getParameters() const
Returns the raw parameters for the task node.
Definition: AIStubTypes.h:80