]> git.localhorst.tv Git - blobs.git/blob - src/creature/Genome.hpp
3361fdef2037d6f913a72ba12c098fe1ddc2e5de
[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 PropertySet {
23                 /// the age at which to transition to the next phase
24                 T age;
25                 /// maximum body mass
26                 T mass;
27                 /// fertility factor
28                 T fertility;
29                 /// skin highlight pronounciation
30                 T highlight;
31         };
32         template<class T>
33         struct Properties {
34                 PropertySet<T> props[6];
35                 PropertySet<T> &Birth() noexcept { return props[0]; }
36                 const PropertySet<T> &Birth() const noexcept { return props[0]; }
37                 PropertySet<T> &Child() noexcept { return props[1]; }
38                 const PropertySet<T> &Child() const noexcept { return props[1]; }
39                 PropertySet<T> &Youth() noexcept { return props[2]; }
40                 const PropertySet<T> &Youth() const noexcept { return props[2]; }
41                 PropertySet<T> &Adult() noexcept { return props[3]; }
42                 const PropertySet<T> &Adult() const noexcept { return props[3]; }
43                 PropertySet<T> &Elder() noexcept { return props[4]; }
44                 const PropertySet<T> &Elder() const noexcept { return props[4]; }
45                 PropertySet<T> &Death() noexcept { return props[5]; }
46                 const PropertySet<T> &Death() const noexcept { return props[5]; }
47
48                 /// "typical" properties
49                 /// every one of these should have at least one
50                 /// negative impact to prevent super-beings evolving
51                 /// power at the cost of higher solid intake
52                 T strength;
53                 /// more endurance at the cost of higher liquid intake
54                 T stamina;
55                 /// more speed at the cost of higher fatigue
56                 T dexerty;
57                 /// higher mental capacity at the cost of boredom
58                 T intelligence;
59                 /// how likely to mutate
60                 T mutability;
61         };
62         Properties<math::Distribution> properties;
63
64
65         struct Composition {
66                 // which resource
67                 int resource;
68                 // how much contained in the body
69                 // relative value to determine average density
70                 math::Distribution mass;
71                 // how much to circulate
72                 math::Distribution intake;
73                 // how important for alive-being
74                 math::Distribution penalty;
75                 // how much off the mass may stay in the body
76                 math::Distribution growth;
77         };
78         std::vector<Composition> composition;
79
80         math::Distribution base_hue;
81         math::Distribution base_saturation;
82         math::Distribution base_lightness;
83
84         void Configure(Creature &) const;
85
86         static PropertySet<double> Instantiate(
87                 const PropertySet<math::Distribution> &p,
88                 math::GaloisLFSR &rand
89         ) noexcept {
90                 return {
91                         p.age.FakeNormal(rand.SNorm()),
92                         p.mass.FakeNormal(rand.SNorm()),
93                         p.fertility.FakeNormal(rand.SNorm()),
94                         glm::clamp(p.highlight.FakeNormal(rand.SNorm()), 0.0, 1.0)
95                 };
96         }
97
98         static Properties<double> Instantiate(
99                 const Properties<math::Distribution> &p,
100                 math::GaloisLFSR &rand
101         ) noexcept {
102                 return {
103                         Instantiate(p.props[0], rand),
104                         Instantiate(p.props[1], rand),
105                         Instantiate(p.props[2], rand),
106                         Instantiate(p.props[3], rand),
107                         Instantiate(p.props[4], rand),
108                         Instantiate(p.props[5], rand),
109                         p.strength.FakeNormal(rand.SNorm()),
110                         p.stamina.FakeNormal(rand.SNorm()),
111                         p.dexerty.FakeNormal(rand.SNorm()),
112                         p.intelligence.FakeNormal(rand.SNorm()),
113                         p.mutability.FakeNormal(rand.SNorm())
114                 };
115         }
116
117 };
118
119 }
120 }
121
122 #endif