SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
GroupFlee.h
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include "Steering.h"
7 
8 namespace ai {
9 namespace movement {
10 
14 class GroupFlee: public ISteering {
15 protected:
16  GroupId _groupId;
17 public:
18  STEERING_FACTORY(GroupFlee)
19 
20  explicit GroupFlee(const std::string& parameters) :
21  ISteering() {
22  _groupId = ::atoi(parameters.c_str());
23  }
24 
25  inline bool isValid () const {
26  return _groupId != -1;
27  }
28 
29  virtual MoveVector execute (const AIPtr& ai, float speed) const override {
30  const Zone* zone = ai->getZone();
31  if (zone == nullptr) {
32  return MoveVector(VEC3_INFINITE, 0.0f);
33  }
34  const glm::vec3& target = zone->getGroupMgr().getPosition(_groupId);
35  if (isInfinite(target)) {
36  return MoveVector(target, 0.0f);
37  }
38  const glm::vec3& v = glm::normalize(ai->getCharacter()->getPosition() - target);
39  const float orientation = angle(v);
40  const MoveVector d(v * speed, orientation);
41  return d;
42  }
43 };
44 
45 }
46 }
Definition: MoveVector.h:10
virtual MoveVector execute(const AIPtr &ai, float speed) const override
Calculates the MoveVector.
Definition: GroupFlee.h:29
Defines some basic movement algorithms like Wandering, Seeking and Fleeing.
Steering interface.
Definition: Steering.h:47
Flees from a particular group.
Definition: GroupFlee.h:14