void operator ()(creature::Creature &c) {
if (planet.Creatures().empty()) {
- std::cout << "no more creatures, game over" << std::endl;
+ planet.GetSimulation().Log() << "no more creatures, game over" << std::endl;
state.GetCreaturePanel().Hide();
while (app.HasState()) {
app.PopState();
void Creature::Hurt(double amount) noexcept {
stats.Damage().Add(amount);
if (stats.Damage().Full()) {
- std::cout << "[" << ui::TimeString(sim.Time()) << "] " << name << " ";
+ std::ostream &log = sim.Log() << name << " ";
if (stats.Exhaustion().Full()) {
- std::cout << "died of exhaustion";
+ log << "died of exhaustion";
} else if (stats.Breath().Full()) {
- std::cout << "suffocated";
+ log << "suffocated";
} else if (stats.Thirst().Full()) {
- std::cout << "died of thirst";
+ log << "died of thirst";
} else if (stats.Hunger().Full()) {
- std::cout << "starved to death";
+ log << "starved to death";
} else {
- std::cout << "succumed to wounds";
+ log << "succumed to wounds";
}
- std::cout << " at an age of " << ui::TimeString(Age())
+ log << " at an age of " << ui::TimeString(Age())
<< " (" << ui::PercentageString(Age() / properties.Lifetime())
- << "% of life expectancy of " << ui::TimeString(properties.Lifetime())
+ << " of life expectancy of " << ui::TimeString(properties.Lifetime())
<< ")" << std::endl;
Die();
}
s.GetPlanet(), s.Surface(),
s.Position() + glm::dvec3(0.0, 0.55 * a->Size(), 0.0));
a->BuildVAO();
- std::cout << "[" << ui::TimeString(c.GetSimulation().Time()) << "] "
- << a->Name() << " was born" << std::endl;
+ c.GetSimulation().Log() << a->Name() << " was born" << std::endl;
Creature *b = new Creature(c.GetSimulation());
b->AddParent(c);
s.GetPlanet(), s.Surface(),
s.Position() - glm::dvec3(0.0, 0.55 * b->Size(), 0.0));
b->BuildVAO();
- std::cout << "[" << ui::TimeString(c.GetSimulation().Time()) << "] "
- << b->Name() << " was born" << std::endl;
+ c.GetSimulation().Log() << b->Name() << " was born" << std::endl;
c.Die();
}
void BlobBackgroundTask::CheckSplit() {
if (GetCreature().Mass() > GetCreature().OffspringMass() * 2.0
&& GetCreature().OffspringChance() > Assets().random.UNorm()) {
- std::cout << "[" << ui::TimeString(GetCreature().GetSimulation().Time())
- << "] " << GetCreature().Name() << " split" << std::endl;
+ GetCreature().GetSimulation().Log() << GetCreature().Name() << " split" << std::endl;
Split(GetCreature());
return;
}
public:
bool HasSimulation() const noexcept { return sim; }
+ Simulation &GetSimulation() noexcept { return *sim; }
const Simulation &GetSimulation() const noexcept { return *sim; }
void SetSimulation(Simulation &) noexcept;
#include "Set.hpp"
#include "../app/Assets.hpp"
+#include <iosfwd>
#include <set>
#include <vector>
const std::vector<Record> &Records() const noexcept { return records; }
void CheckRecords(creature::Creature &) noexcept;
+ std::ostream &Log();
+
private:
Body &root;
app::Assets &assets;
#include "Planet.hpp"
#include "Sun.hpp"
#include "../creature/Creature.hpp"
+#include "../ui/string.hpp"
#include <algorithm>
+#include <iostream>
namespace blobs {
void Simulation::CheckRecords(creature::Creature &c) noexcept {
if (c.Age() > records[0].value) {
+ if (records[0].holder && records[0].holder != &c) {
+ Log() << "new age record by " << c.Name() << std::endl;
+ }
records[0].value = c.Age();
records[0].time = Time();
records[0].holder = &c;
}
if (c.Mass() > records[1].value) {
+ if (records[1].holder && records[1].holder != &c) {
+ Log() << "new mass record by " << c.Name() << std::endl;
+ }
records[1].value = c.Mass();
records[1].time = Time();
records[1].holder = &c;
}
if (c.Size() > records[2].value) {
+ if (records[2].holder && records[2].holder != &c) {
+ Log() << "new size record by " << c.Name() << std::endl;
+ }
records[2].value = c.Size();
records[2].time = Time();
records[2].holder = &c;
}
if (c.Strength() > records[3].value) {
+ if (records[3].holder && records[3].holder != &c) {
+ Log() << "new strength record by " << c.Name() << std::endl;
+ }
records[3].value = c.Strength();
records[3].time = Time();
records[3].holder = &c;
}
if (c.Stamina() > records[4].value) {
+ if (records[4].holder && records[4].holder != &c) {
+ Log() << "new stamina record by " << c.Name() << std::endl;
+ }
records[4].value = c.Stamina();
records[4].time = Time();
records[4].holder = &c;
}
if (c.Dexerty() > records[5].value) {
+ if (records[5].holder && records[5].holder != &c) {
+ Log() << "new dexerty record by " << c.Name() << std::endl;
+ }
records[5].value = c.Dexerty();
records[5].time = Time();
records[5].holder = &c;
}
if (c.Intelligence() > records[6].value) {
+ if (records[6].holder && records[6].holder != &c) {
+ Log() << "new intelligence record by " << c.Name() << std::endl;
+ }
records[6].value = c.Intelligence();
records[6].time = Time();
records[6].holder = &c;
}
}
+std::ostream &Simulation::Log() {
+ return std::cout << '[' << ui::TimeString(Time()) << "] ";
+}
+
}
}