Grail (C++)  1.4.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
Behavior.hh
1 // Copyright QED Software 2023.
2 
3 #ifndef GRAIL_AI_BEHAVIOR_H
4 #define GRAIL_AI_BEHAVIOR_H
5 
6 #include <memory>
7 #include <string>
8 
9 namespace grail
10 {
11  class AIEntity;
12 
13  enum class BehaviorStatus
14  {
15  SUSPENDED = 0,
16  ACTIVE,
17  FINISHED,
18  DELEGALIZED,
19  };
20 
22  class Behavior
23  {
24  friend class AIEntity;
25  friend class BehaviorSequence;
26 
27  public:
28  Behavior(std::unique_ptr<Behavior> recoveryBehavior = nullptr);
29  Behavior(Behavior&&) = default;
30 
31  virtual ~Behavior();
32 
33  Behavior& operator =(const Behavior&) = delete;
34  Behavior& operator =(Behavior&&) = delete;
35 
38  virtual void Start(AIEntity& owner);
39 
42  virtual void Update(AIEntity& owner, float deltaTime);
43 
46  virtual void Finish(AIEntity& owner, const BehaviorStatus status);
47 
49  virtual bool IsFinished(const AIEntity& owner) const;
50 
53  virtual bool IsLegal(const AIEntity& owner) const;
54 
56  virtual bool IsInterruptible() const;
57 
62  BehaviorStatus GetStatus() const;
63 
64  virtual std::unique_ptr<Behavior> GetRecoveryBehavior();
65 
66  virtual std::string GetName() const;
67 
68  protected:
69  std::unique_ptr<Behavior> recoveryBehavior{nullptr};
70 
71  private:
72  void UpdateStatus(const AIEntity& owner);
73  void SetStatus(BehaviorStatus newStatus);
74 
75  BehaviorStatus status = BehaviorStatus::SUSPENDED;
76  };
77 }
78 #endif //GRAIL_AI_BEHAVIOR_H
grail::Behavior::IsLegal
virtual bool IsLegal(const AIEntity &owner) const
Definition: Behavior.cpp:36
grail::AIEntity
The AIEntity class - Defines a basic object which can execute behaviors.
Definition: AIEntity.hh:50
grail::Behavior::Start
virtual void Start(AIEntity &owner)
Definition: Behavior.cpp:19
grail::Behavior::Update
virtual void Update(AIEntity &owner, float deltaTime)
Definition: Behavior.cpp:23
grail::Behavior::IsFinished
virtual bool IsFinished(const AIEntity &owner) const
Definition: Behavior.cpp:31
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::Behavior::GetStatus
BehaviorStatus GetStatus() const
GetStatus.
Definition: Behavior.cpp:61
grail::Behavior::Finish
virtual void Finish(AIEntity &owner, const BehaviorStatus status)
Definition: Behavior.cpp:27
grail::Behavior::IsInterruptible
virtual bool IsInterruptible() const
Definition: Behavior.cpp:41