diff --git a/src/combat/combat.cpp b/src/combat/combat.cpp index 81d1003..d5fbec6 100644 --- a/src/combat/combat.cpp +++ b/src/combat/combat.cpp @@ -12,7 +12,6 @@ namespace components { target.take_damage(my_dmg); } - INVARIANT(); return my_dmg; } @@ -26,20 +25,19 @@ namespace components { // don't go below 0 hp = std::max(0, hp - my_dmg); - has_died = hp <= 0; - INVARIANT(); + // don't mark it dead here, the System will do it + // so that it can notify of live->dead transition } bool Combat::less_than(int level) { - INVARIANT(); // originally this checked main body parts like // head, stomach, and chest return hp <= level; } bool Combat::is_dead() { - INVARIANT(); - return has_died; + dbc::check(hp >= 0, "invalid HP, went below zero"); + return hp == 0; } bool Combat::almost_dead() { @@ -47,17 +45,10 @@ namespace components { } bool Combat::can_heal() { - INVARIANT(); return hp < max_hp; } void Combat::apply_healing(Curative& cure) { - INVARIANT(); hp += std::min(hp + cure.hp, max_hp); } - - void Combat::INVARIANT() { - dbc::check(!(hp <= 0 && has_died == false), "entity hp <= 0 && has_died==false, they should be dead"); - dbc::check(!(hp > 0 && has_died == true), "entity has hp > 0 but is marked dead, should be alive"); - } } diff --git a/src/game/components.hpp b/src/game/components.hpp index 78f16c0..d4c8329 100644 --- a/src/game/components.hpp +++ b/src/game/components.hpp @@ -133,7 +133,6 @@ namespace components { bool almost_dead(); bool can_heal(); void apply_healing(Curative& cure); - void INVARIANT(); }; struct LightSource { diff --git a/src/game/systems.cpp b/src/game/systems.cpp index efb0bb5..73ac99f 100644 --- a/src/game/systems.cpp +++ b/src/game/systems.cpp @@ -191,15 +191,18 @@ void System::death() { std::vector dead_things; world.query([&](auto ent, auto &combat) { - // bring out yer dead - if(combat.is_dead()) { + // bring out yer dead, have to do it here to notify on the transition from + // live -> dead + if(!combat.has_died && combat.is_dead()) { + combat.has_died = true; + if(ent != player.entity) { // we won't change out the player's components later dead_things.push_back(ent); } // we need to send this event for everything that dies world.send(game::Event::DEATH, ent, {}); - } else if(float(combat.hp) / float(combat.max_hp) < 0.5f) { + } else if(combat.almost_dead()) { // if enemies are below 50% health they are marked with bad health if(world.has(ent)) { auto& enemy_ai = world.get(ent);