]> git.localhorst.tv Git - blobs.git/blob - src/creature/Genome.hpp
color mutation
[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[9];
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                 /// how likely to adapt to new environments
48                 T &Adaptability() noexcept { return props[7]; }
49                 const T &Adaptability() const noexcept { return props[7]; }
50                 /// mass of offspring
51                 T &OffspringMass() noexcept { return props[8]; }
52                 const T &OffspringMass() const noexcept { return props[8]; }
53         };
54         Properties<math::Distribution> properties;
55
56         math::Distribution base_hue;
57         math::Distribution base_saturation;
58         math::Distribution base_lightness;
59
60         math::Distribution highlight_hue;
61         math::Distribution highlight_saturation;
62         math::Distribution highlight_lightness;
63
64         void Configure(Creature &) const;
65
66         static Properties<double> Instantiate(
67                 const Properties<math::Distribution> &p,
68                 math::GaloisLFSR &rand
69         ) noexcept {
70                 return {
71                         p.props[0].FakeNormal(rand.SNorm()),
72                         p.props[1].FakeNormal(rand.SNorm()),
73                         p.props[2].FakeNormal(rand.SNorm()),
74                         p.props[3].FakeNormal(rand.SNorm()),
75                         p.props[4].FakeNormal(rand.SNorm()),
76                         glm::clamp(p.props[5].FakeNormal(rand.SNorm()), 0.0, 1.0),
77                         glm::clamp(p.props[6].FakeNormal(rand.SNorm()), 0.0, 1.0),
78                         glm::clamp(p.props[7].FakeNormal(rand.SNorm()), 0.0, 1.0),
79                         p.props[8].FakeNormal(rand.SNorm())
80                 };
81         }
82
83 };
84
85 }
86 }
87
88 #endif