SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
Steering.h
Go to the documentation of this file.
1 
5 #pragma once
6 
7 #include "AI.h"
8 #include "zone/Zone.h"
9 #include "IAIFactory.h"
10 #include "common/Math.h"
11 #include "common/MoveVector.h"
12 #include "common/String.h"
13 #include "common/MemoryAllocator.h"
14 #include "ICharacter.h"
15 
16 namespace ai {
17 namespace movement {
18 
19 #define STEERING_FACTORY(SteeringName) \
20 public: \
21  class Factory: public ::ai::ISteeringFactory { \
22  public: \
23  ::ai::SteeringPtr create (const ::ai::SteeringFactoryContext *ctx) const override { \
24  return std::make_shared<SteeringName>(ctx->parameters); \
25  } \
26  }; \
27  static const Factory& getFactory() { \
28  static Factory FACTORY; \
29  return FACTORY; \
30  }
31 
32 #define STEERING_FACTORY_SINGLETON \
33 public: \
34  class Factory: public ::ai::ISteeringFactory { \
35  ::ai::SteeringPtr create (const ::ai::SteeringFactoryContext */*ctx*/) const { \
36  return get(); \
37  } \
38  }; \
39  static const Factory& getFactory() { \
40  static Factory FACTORY; \
41  return FACTORY; \
42  }
43 
47 class ISteering : public MemObject {
48 public:
49  virtual ~ISteering() {}
56  virtual MoveVector execute (const AIPtr& ai, float speed) const = 0;
57 };
58 
62 class SelectionSteering : public ISteering {
63 protected:
64  glm::vec3 getSelectionTarget(const AIPtr& entity, std::size_t index) const {
65  const FilteredEntities& selection = entity->getFilteredEntities();
66  if (selection.empty() || selection.size() <= index) {
67  return VEC3_INFINITE;
68  }
69  const Zone* zone = entity->getZone();
70  const CharacterId characterId = selection[index];
71  const AIPtr& ai = zone->getAI(characterId);
72  const ICharacterPtr character = ai->getCharacter();
73  return character->getPosition();
74  }
75 
76 public:
77  virtual ~SelectionSteering() {}
78 };
79 
80 }
81 }
IFilter steering interface
Definition: Steering.h:62
Definition: MoveVector.h:10
Definition: MemoryAllocator.h:26
Steering interface.
Definition: Steering.h:47
virtual MoveVector execute(const AIPtr &ai, float speed) const =0
Calculates the MoveVector.