(C++)  1.0.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
BehaviorSequence.hh
1 #ifndef GRAIL_BEHAVIOR_SEQUENCE_H
2 #define GRAIL_BEHAVIOR_SEQUENCE_H
3 
4 #include "Behavior.hh"
5 
6 #include <vector>
7 #include <memory>
8 
9 namespace grail
10 {
14  class BehaviorSequence : public Behavior
15  {
16  public:
21  BehaviorSequence(std::size_t expectedSequenceSize = 3);
22  virtual ~BehaviorSequence() override = default;
23 
24  BehaviorSequence(const BehaviorSequence& other) = delete;
25  BehaviorSequence(BehaviorSequence&& other) = default;
26 
27  BehaviorSequence& operator = (const BehaviorSequence& other) = delete;
28  BehaviorSequence& operator = (BehaviorSequence&& other) = delete;
29 
30  template<typename BehaviorType, typename... ConstructorArguments>
35  void AddBehavior(ConstructorArguments&&... constructorArguments)
36  {
37  sequence.push_back(std::make_unique<BehaviorType>(std::forward<ConstructorArguments>(constructorArguments)...));
38  currentBehavior = sequence.begin();
39  }
40 
41  void Start(AIEntity &owner) override final;
42  void Update(AIEntity &owner, float deltaTime) override final;
43  void Finish(AIEntity &owner, const BehaviorStatus status) override final;
44 
45  bool IsFinished(const AIEntity &owner) const override final;
46 
52  virtual bool IsLegal(const AIEntity &owner) const override;
53 
58  virtual bool IsInterruptible() const override;
59 
60  private:
61  std::vector<std::unique_ptr<Behavior>> sequence{};
62  std::vector<std::unique_ptr<Behavior>>::iterator currentBehavior;
63  };
64 }
65 
66 #endif // GRAIL_BEHAVIOR_SEQUENCE_H
The AIEntity class - Defines a basic object which can execute behaviors.
Definition: AIEntity.hh:39
A high-level abstraction of actions in the game.
Definition: Behavior.hh:20
The BehaviorSequence class - specialized Behavior executing sequence of provided subbehaviors one by ...
Definition: BehaviorSequence.hh:15
void Update(AIEntity &owner, float deltaTime) override final
Definition: BehaviorSequence.cpp:20
virtual bool IsLegal(const AIEntity &owner) const override
IsLegal.
Definition: BehaviorSequence.cpp:54
bool IsFinished(const AIEntity &owner) const override final
Definition: BehaviorSequence.cpp:49
void AddBehavior(ConstructorArguments &&... constructorArguments)
AddBehavior - method emplacing new behavior in the sequence.
Definition: BehaviorSequence.hh:35
virtual bool IsInterruptible() const override
IsInterruptible.
Definition: BehaviorSequence.cpp:59
void Start(AIEntity &owner) override final
Definition: BehaviorSequence.cpp:14
void Finish(AIEntity &owner, const BehaviorStatus status) override final
Definition: BehaviorSequence.cpp:40