1 #include "Simulation.hpp"
6 #include "../creature/Creature.hpp"
7 #include "../ui/string.hpp"
16 Simulation::Simulation(Body &r, app::Assets &assets)
27 records[0].name = "Age";
28 records[0].type = Record::TIME;
29 records[1].name = "Mass";
30 records[1].type = Record::MASS;
31 records[2].name = "Size";
32 records[2].type = Record::LENGTH;
33 records[3].name = "Strength";
34 records[4].name = "Stamina";
35 records[5].name = "Dexerty";
36 records[6].name = "Intelligence";
39 Simulation::~Simulation() {
40 for (auto c : alive) {
48 void Simulation::Tick(double dt) {
50 for (auto body : bodies) {
53 for (auto c : alive) {
58 void Simulation::AddBody(Body &b) {
59 b.SetSimulation(*this);
63 void Simulation::AddPlanet(Planet &p) {
68 void Simulation::AddSun(Sun &s) {
73 void Simulation::SetAlive(creature::Creature *c) {
77 void Simulation::SetDead(creature::Creature *c) {
78 auto entry = std::find(alive.begin(), alive.end(), c);
79 if (entry != alive.end()) {
86 void Simulation::CheckRecords(creature::Creature &c) noexcept {
87 if (c.Age() > records[0].value) {
88 if (records[0].holder && records[0].holder != &c) {
89 Log() << "new age record by " << c.Name() << std::endl;
91 records[0].value = c.Age();
92 records[0].time = Time();
93 records[0].holder = &c;
95 if (c.Mass() > records[1].value) {
96 if (records[1].holder && records[1].holder != &c) {
97 Log() << "new mass record by " << c.Name() << std::endl;
99 records[1].value = c.Mass();
100 records[1].time = Time();
101 records[1].holder = &c;
103 if (c.Size() > records[2].value) {
104 if (records[2].holder && records[2].holder != &c) {
105 Log() << "new size record by " << c.Name() << std::endl;
107 records[2].value = c.Size();
108 records[2].time = Time();
109 records[2].holder = &c;
111 if (c.Strength() > records[3].value) {
112 if (records[3].holder && records[3].holder != &c) {
113 Log() << "new strength record by " << c.Name() << std::endl;
115 records[3].value = c.Strength();
116 records[3].time = Time();
117 records[3].holder = &c;
119 if (c.Stamina() > records[4].value) {
120 if (records[4].holder && records[4].holder != &c) {
121 Log() << "new stamina record by " << c.Name() << std::endl;
123 records[4].value = c.Stamina();
124 records[4].time = Time();
125 records[4].holder = &c;
127 if (c.Dexerty() > records[5].value) {
128 if (records[5].holder && records[5].holder != &c) {
129 Log() << "new dexerty record by " << c.Name() << std::endl;
131 records[5].value = c.Dexerty();
132 records[5].time = Time();
133 records[5].holder = &c;
135 if (c.Intelligence() > records[6].value) {
136 if (records[6].holder && records[6].holder != &c) {
137 Log() << "new intelligence record by " << c.Name() << std::endl;
139 records[6].value = c.Intelligence();
140 records[6].time = Time();
141 records[6].holder = &c;
145 std::ostream &Simulation::Log() {
146 return std::cout << '[' << ui::TimeString(Time()) << "] ";