X-Git-Url: http://git.localhorst.tv/?p=blobs.git;a=blobdiff_plain;f=src%2Fcreature%2Fcreature.cpp;h=c83f11cea3168c388195da964b20bf118a8c5809;hp=0aa2b396324cc477c75b2c4313866f3d738a51c8;hb=cd9cee86b336b5ec531028ac2deebb391e48ed21;hpb=42db7d9d2286e50896ad172e2e4a8fbe65c8a4a9 diff --git a/src/creature/creature.cpp b/src/creature/creature.cpp index 0aa2b39..c83f11c 100644 --- a/src/creature/creature.cpp +++ b/src/creature/creature.cpp @@ -53,6 +53,8 @@ void Creature::Grow(double amount) noexcept { void Creature::Hurt(double dt) noexcept { health = std::max(0.0, health - dt); if (health == 0.0) { + std::cout << "[" << int(sim.Time()) << "s] " + << name << " died" << std::endl; Die(); } } @@ -105,6 +107,11 @@ void Creature::Tick(double dt) { situation.Move(vel * dt); vel += acc * dt; + if (Age() > properties.death_age) { + std::cout << "[" << int(sim.Time()) << "s] " + << name << " died of old age" << std::endl; + } + for (auto &need : needs) { need->Tick(dt); } @@ -402,16 +409,25 @@ bool Situation::OnSurface() const noexcept { return type == PLANET_SURFACE; } +bool Situation::OnTile() const noexcept { + glm::ivec2 t(planet->SurfacePosition(surface, position)); + return type == PLANET_SURFACE + && t.x >= 0 && t.x < planet->SideLength() + && t.y >= 0 && t.y < planet->SideLength(); +} + +glm::ivec2 Situation::SurfacePosition() const noexcept { + return planet->SurfacePosition(surface, position); +} + world::Tile &Situation::GetTile() const noexcept { - double side_length = planet->SideLength(); - double offset = side_length * 0.5; - double x = std::max(0.0, std::min(side_length, position.x + offset)); - double y = std::max(0.0, std::min(side_length, position.y + offset)); - return planet->TileAt(surface, int(x), int(y)); + glm::ivec2 t(planet->SurfacePosition(surface, position)); + return planet->TileAt(surface, t.x, t.y); } const world::TileType &Situation::GetTileType() const noexcept { - return planet->GetSimulation().TileTypes()[GetTile().type]; + glm::ivec2 t(planet->SurfacePosition(surface, position)); + return planet->TypeAt(surface, t.x, t.y); } void Situation::Move(const glm::dvec3 &dp) noexcept {