]> git.localhorst.tv Git - blobs.git/blob - src/creature/Goal.hpp
4d3a17f431382d616a8f4828f7e1f9f3ee64529b
[blobs.git] / src / creature / Goal.hpp
1 #ifndef BLOBS_CREATURE_GOAL_HPP_
2 #define BLOBS_CREATURE_GOAL_HPP_
3
4 #include <functional>
5 #include <string>
6
7
8 namespace blobs {
9 namespace app {
10         struct Assets;
11 }
12 namespace math {
13         class GaloisLFSR;
14 }
15 namespace creature {
16
17 class Creature;
18 class Situation;
19 class Steering;
20
21 class Goal {
22
23 public:
24         using Callback = std::function<void(Goal &)>;
25
26 public:
27         explicit Goal(Creature &);
28         virtual ~Goal() noexcept;
29
30 public:
31         Creature &GetCreature() noexcept { return c; }
32         const Creature &GetCreature() const noexcept { return c; }
33         Situation &GetSituation() noexcept;
34         const Situation &GetSituation() const noexcept;
35         Steering &GetSteering() noexcept;
36         const Steering &GetSteering() const noexcept;
37         app::Assets &Assets() noexcept;
38         const app::Assets &Assets() const noexcept;
39         math::GaloisLFSR &Random() noexcept;
40
41         double Urgency() const noexcept { return urgency; }
42         void Urgency(double u) noexcept { urgency = u; }
43
44         bool Interruptible() const noexcept { return interruptible; }
45         void Interruptible(bool i) noexcept { interruptible = i; }
46
47         bool Complete() const noexcept { return complete; }
48         void SetComplete();
49         void SetForeground();
50         void SetBackground();
51         /// only supports one callback for now, new one will replace an old
52         void WhenComplete(Callback) noexcept;
53         void WhenForeground(Callback) noexcept;
54         /// on background will not be called when the goal is first inserted
55         /// but only after is has been in the foreground once
56         void WhenBackground(Callback) noexcept;
57
58 public:
59         virtual std::string Describe() const = 0;
60         virtual void Enable() { }
61         virtual void Tick(double dt) { }
62         virtual void Action() { }
63
64 private:
65         virtual void OnComplete() { }
66         virtual void OnForeground() { }
67         virtual void OnBackground() { }
68
69 private:
70         Creature &c;
71         Callback on_complete;
72         Callback on_foreground;
73         Callback on_background;
74         double urgency;
75         bool interruptible;
76         bool complete;
77
78 };
79
80 }
81 }
82
83 #endif