X-Git-Url: http://git.localhorst.tv/?p=blobs.git;a=blobdiff_plain;f=src%2Fcreature%2Fcreature.cpp;h=4345bd9837b668bdd96a2cc612514c22a25ae686;hp=c83f11cea3168c388195da964b20bf118a8c5809;hb=69dade793864169f7773cc133d54277eea9bf760;hpb=cd9cee86b336b5ec531028ac2deebb391e48ed21 diff --git a/src/creature/creature.cpp b/src/creature/creature.cpp index c83f11c..4345bd9 100644 --- a/src/creature/creature.cpp +++ b/src/creature/creature.cpp @@ -1,5 +1,6 @@ #include "Creature.hpp" #include "Genome.hpp" +#include "Memory.hpp" #include "Situation.hpp" #include "Steering.hpp" @@ -35,6 +36,7 @@ Creature::Creature(world::Simulation &sim) , health(1.0) , on_death() , removable(false) +, memory(*this) , needs() , goals() , situation() @@ -112,6 +114,7 @@ void Creature::Tick(double dt) { << name << " died of old age" << std::endl; } + memory.Tick(dt); for (auto &need : needs) { need->Tick(dt); } @@ -391,6 +394,39 @@ void Split(Creature &c) { } +Memory::Memory(Creature &c) +: c(c) { +} + +Memory::~Memory() { +} + +void Memory::Tick(double dt) { + Situation &s = c.GetSituation(); + if (s.OnSurface()) { + TrackStay({ &s.GetPlanet(), s.Surface(), s.SurfacePosition() }, dt); + } +} + +void Memory::TrackStay(const Location &l, double t) { + const world::TileType &type = l.planet->TypeAt(l.surface, l.coords.x, l.coords.y); + auto entry = known_types.find(type.id); + if (entry != known_types.end()) { + entry->second.last_been = c.GetSimulation().Time(); + entry->second.last_loc = l; + entry->second.time_spent += t; + } else { + known_types.emplace(type.id, Stay{ + c.GetSimulation().Time(), + l, + c.GetSimulation().Time(), + l, + t + }); + } +} + + Situation::Situation() : planet(nullptr) , position(0.0)