]> git.localhorst.tv Git - blobs.git/blob - src/creature/Genome.hpp
generate base color for creature
[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
7 #include <vector>
8
9
10 namespace blobs {
11 namespace app {
12         struct Assets;
13 }
14 namespace creature {
15
16 class Creature;
17
18 struct Genome {
19
20         template<class T>
21         struct PropertySet {
22                 T age;
23                 T mass;
24                 T fertility;
25         };
26         template<class T>
27         struct Properties {
28                 PropertySet<T> props[6];
29                 PropertySet<T> &Birth() noexcept { return props[0]; }
30                 const PropertySet<T> &Birth() const noexcept { return props[0]; }
31                 PropertySet<T> &Child() noexcept { return props[1]; }
32                 const PropertySet<T> &Child() const noexcept { return props[1]; }
33                 PropertySet<T> &Youth() noexcept { return props[2]; }
34                 const PropertySet<T> &Youth() const noexcept { return props[2]; }
35                 PropertySet<T> &Adult() noexcept { return props[3]; }
36                 const PropertySet<T> &Adult() const noexcept { return props[3]; }
37                 PropertySet<T> &Elder() noexcept { return props[4]; }
38                 const PropertySet<T> &Elder() const noexcept { return props[4]; }
39                 PropertySet<T> &Death() noexcept { return props[5]; }
40                 const PropertySet<T> &Death() const noexcept { return props[5]; }
41         };
42         Properties<math::Distribution> properties;
43
44
45         struct Composition {
46                 // which resource
47                 int resource;
48                 // how much contained in the body
49                 // relative value to determine average density
50                 math::Distribution mass;
51                 // how much to circulate
52                 math::Distribution intake;
53                 // how important for alive-being
54                 math::Distribution penalty;
55                 // how much off the mass may stay in the body
56                 math::Distribution growth;
57         };
58         std::vector<Composition> composition;
59
60         math::Distribution base_hue;
61         math::Distribution base_saturation;
62         math::Distribution base_lightness;
63
64         void Configure(Creature &) const;
65
66         static PropertySet<double> Instantiate(
67                 const PropertySet<math::Distribution> &p,
68                 math::GaloisLFSR &rand
69         ) noexcept {
70                 return {
71                         p.age.FakeNormal(rand.SNorm()),
72                         p.mass.FakeNormal(rand.SNorm()),
73                         p.fertility.FakeNormal(rand.SNorm())
74                 };
75         }
76
77         static Properties<double> Instantiate(
78                 const Properties<math::Distribution> &p,
79                 math::GaloisLFSR &rand
80         ) noexcept {
81                 return {
82                         Instantiate(p.props[0], rand),
83                         Instantiate(p.props[1], rand),
84                         Instantiate(p.props[2], rand),
85                         Instantiate(p.props[3], rand),
86                         Instantiate(p.props[4], rand),
87                         Instantiate(p.props[5], rand)
88                 };
89         }
90
91 };
92
93 }
94 }
95
96 #endif