diff --git a/godot/GameObjects/enemy_unit.tscn b/godot/GameObjects/enemy_unit.tscn index 81ac260..13d8c55 100644 --- a/godot/GameObjects/enemy_unit.tscn +++ b/godot/GameObjects/enemy_unit.tscn @@ -36,8 +36,7 @@ actions_inspector = [3, 2, 4, 5, 1] unique_name_in_owner = true [node name="EntityHealth" type="EntityHealth" parent="."] -injury_max = 20 -wounds_max = 20 +injury_max = 100 unique_name_in_owner = true [node name="NavigationAgent3D" type="NavigationAgent3D" parent="."] diff --git a/src/entity_health.cpp b/src/entity_health.cpp index 99592b8..47a6fd6 100644 --- a/src/entity_health.cpp +++ b/src/entity_health.cpp @@ -29,8 +29,8 @@ void EntityHealth::_bind_methods() { } void EntityHealth::_enter_tree() { - this->injury_current = this->injury_max; - this->wounds_current = this->wounds_max; + this->injury_current = gd::Math::max(1, this->injury_max); + this->wounds_current = gd::Math::max(0, this->wounds_max); } void EntityHealth::damaged_by(int amount, Unit *source) { @@ -53,7 +53,7 @@ void EntityHealth::healed_by(int amount, Unit *source) { } void EntityHealth::receive_wounds(int incoming_amount, Unit *source) { - if(this->is_conscious()) { + if(this->wounds_max > 0 && this->is_conscious()) { this->wounds_current -= incoming_amount; if(this->wounds_current <= 0) { this->emit_signal("unconscious", source); @@ -70,12 +70,14 @@ void EntityHealth::receive_injury(int incoming_amount, Unit *source) { } float EntityHealth::get_wounds_damage_factor() const { - return float(this->injury_current) / float(this->injury_max); + return this->injury_max == 0 + ? 1.f + : float(this->injury_current) / float(this->injury_max); } bool EntityHealth::is_conscious() const { return !this->is_dead() - && this->wounds_current > 0; + && (this->wounds_current > 0 || this->wounds_max <= 0); } bool EntityHealth::can_be_revived() const { diff --git a/src/entity_health.hpp b/src/entity_health.hpp index a8871fe..cd664a7 100644 --- a/src/entity_health.hpp +++ b/src/entity_health.hpp @@ -37,10 +37,10 @@ public: private: Stats const *stats; // long term health - int injury_max{10}; + int injury_max{10}; //!< the "health" value, has to be more than 1 int injury_current{0}; // short term health - int wounds_max{10}; + int wounds_max{0}; //!< the "healthy" value, if set to zero, short-term health is removed int wounds_current{0}; };