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