]> git.localhorst.tv Git - blobs.git/blob - src/creature/Goal.hpp
better heading implementation
[blobs.git] / src / creature / Goal.hpp
1 #ifndef BLOBS_CREATURE_GOAL_HPP_
2 #define BLOBS_CREATURE_GOAL_HPP_
3
4 #include "Creature.hpp"
5
6 #include <functional>
7 #include <string>
8
9
10 namespace blobs {
11 namespace app {
12         struct Assets;
13 }
14 namespace math {
15         class GaloisLFSR;
16 }
17 namespace creature {
18
19 class Goal {
20
21 public:
22         using Callback = std::function<void(Goal &)>;
23
24 public:
25         explicit Goal(Creature &);
26         virtual ~Goal() noexcept;
27
28 public:
29         Creature &GetCreature() noexcept { return c; }
30         const Creature &GetCreature() const noexcept { return c; }
31         Creature::Stats &GetStats() noexcept { return c.GetStats(); }
32         const Creature::Stats &GetStats() const noexcept { return c.GetStats(); }
33         Situation &GetSituation() noexcept { return c.GetSituation(); }
34         const Situation &GetSituation() const noexcept { return c.GetSituation(); }
35         Steering &GetSteering() noexcept { return c.GetSteering(); }
36         const Steering &GetSteering() const noexcept { return c.GetSteering(); }
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