]> git.localhorst.tv Git - blobs.git/blob - src/creature/Genome.hpp
overhaul need system
[blobs.git] / src / creature / Genome.hpp
1 #ifndef BLOBS_CREATURE_GENOME_HPP_
2 #define BLOBS_CREATURE_GENOME_HPP_
3
4 #include "../math/Distribution.hpp"
5 #include "../math/GaloisLFSR.hpp"
6 #include "../math/glm.hpp"
7
8 #include <vector>
9
10
11 namespace blobs {
12 namespace app {
13         struct Assets;
14 }
15 namespace creature {
16
17 class Creature;
18
19 struct Genome {
20
21         template<class T>
22         struct Properties {
23                 /// every one of these should have at least one
24                 /// negative impact to prevent super-beings evolving
25                 T props[8];
26                 /// power at the cost of higher solid intake
27                 T &Strength() noexcept { return props[0]; }
28                 const T &Strength() const noexcept { return props[0]; }
29                 /// more endurance at the cost of higher liquid intake
30                 T &Stamina() noexcept { return props[1]; }
31                 const T &Stamina() const noexcept { return props[1]; }
32                 /// more speed at the cost of higher fatigue
33                 T &Dexerty() noexcept { return props[2]; }
34                 const T &Dexerty() const noexcept { return props[2]; }
35                 /// higher mental capacity at the cost of boredom
36                 T &Intelligence() noexcept { return props[3]; }
37                 const T &Intelligence() const noexcept { return props[3]; }
38                 /// average lifetime in seconds
39                 T &Lifetime() noexcept { return props[4]; }
40                 const T &Lifetime() const noexcept { return props[4]; }
41                 /// how likely to succeed in reproduction
42                 T &Fertility() noexcept { return props[5]; }
43                 const T &Fertility() const noexcept { return props[5]; }
44                 /// how likely to mutate
45                 T &Mutability() noexcept { return props[6]; }
46                 const T &Mutability() const noexcept { return props[6]; }
47                 /// mass of offspring
48                 T &OffspringMass() noexcept { return props[7]; }
49                 const T &OffspringMass() const noexcept { return props[7]; }
50         };
51         Properties<math::Distribution> properties;
52
53         math::Distribution base_hue;
54         math::Distribution base_saturation;
55         math::Distribution base_lightness;
56
57         void Configure(Creature &) const;
58
59         static Properties<double> Instantiate(
60                 const Properties<math::Distribution> &p,
61                 math::GaloisLFSR &rand
62         ) noexcept {
63                 return {
64                         p.props[0].FakeNormal(rand.SNorm()),
65                         p.props[1].FakeNormal(rand.SNorm()),
66                         p.props[2].FakeNormal(rand.SNorm()),
67                         p.props[3].FakeNormal(rand.SNorm()),
68                         p.props[4].FakeNormal(rand.SNorm()),
69                         p.props[5].FakeNormal(rand.SNorm()),
70                         p.props[6].FakeNormal(rand.SNorm()),
71                         p.props[7].FakeNormal(rand.SNorm())
72                 };
73         }
74
75 };
76
77 }
78 }
79
80 #endif