Skip to main content

HealthComponent Class

Component for tracking entity health and damage. More...

Declaration

class helios::engine::mechanics::health::components::HealthComponent { ... }

Public Constructors Index

HealthComponent ()=default
HealthComponent (const float maxHealth)

Constructs a HealthComponent with the given maximum health. More...

HealthComponent (const HealthComponent &other)

Copy constructor. More...

HealthComponent (HealthComponent &&) noexcept=default

Public Operators Index

HealthComponent &operator= (const HealthComponent &)=default
HealthComponent &operator= (HealthComponent &&) noexcept=default

Public Member Functions Index

boolisEnabled () const noexcept

Checks whether this component is enabled. More...

voidenable () noexcept

Enables this component. More...

voiddisable () noexcept

Disables this component. More...

voidsetHealthDepletedBehavior (const HealthDepletedBehavior behavior) noexcept

Sets the health depletion response behaviour. More...

HealthDepletedBehaviorhealthDepletedBehavior () const noexcept

Returns the health depletion response behaviour. More...

voidtakeDamage (const float damage) noexcept

Applies damage to this entity. More...

voidheal (const float amount) noexcept

Heals this entity. More...

voidsetMaxHealth (const float maxHealth) noexcept

Sets the maximum health value. More...

boolisAlive () const noexcept

Checks if the entity is alive. More...

floathealth () const noexcept

Returns the current health value. More...

floatmaxHealth () const noexcept

Returns the maximum health value. More...

boolisDirty () const noexcept

Checks whether the health value has been modified. More...

voidclearDirty () noexcept

Resets the dirty flag. More...

voidreset ()

Resets health to maximum. More...

voidonAcquire () noexcept

Called when this entity is acquired from a pool. More...

voidonRelease () noexcept

Called when this entity is released back to a pool. More...

Private Member Attributes Index

floatmaxHealth_ {}

Maximum health value. More...

floathealth_ {}

Current health value. More...

boolisEnabled_ = true

Whether this component is enabled. More...

HealthDepletedBehaviorhealthDepletedBehavior_ = HealthDepletedBehavior::None

Flags controlling the response when health reaches zero. More...

boolisDirty_ = true

True if the health value was modified since the last clear. More...

Description

Component for tracking entity health and damage.

Manages current and maximum health values for an entity. Provides methods for taking damage, healing, and checking alive status.

Definition at line 26 of file HealthComponent.ixx.

Public Constructors

HealthComponent()

helios::engine::mechanics::health::components::HealthComponent::HealthComponent ()
default

Definition at line 83 of file HealthComponent.ixx.

Referenced by HealthComponent, HealthComponent, operator= and operator=.

HealthComponent()

helios::engine::mechanics::health::components::HealthComponent::HealthComponent (const float maxHealth)
inline explicit

Constructs a HealthComponent with the given maximum health.

Parameters
maxHealth

The maximum health value.

Definition at line 90 of file HealthComponent.ixx.

90 explicit HealthComponent(const float maxHealth) : maxHealth_(maxHealth) {};

Reference maxHealth.

HealthComponent()

helios::engine::mechanics::health::components::HealthComponent::HealthComponent (const HealthComponent & other)
inline

Copy constructor.

Parameters
other

The component to copy from.

Definition at line 97 of file HealthComponent.ixx.

98 :
99 maxHealth_(other.maxHealth_),
100 healthDepletedBehavior_(other.healthDepletedBehavior_)
101 {
102 assert(maxHealth_ != 0.0f && "max health must not be 0");
103 isDirty_ = true;
104 }

Reference HealthComponent.

HealthComponent()

helios::engine::mechanics::health::components::HealthComponent::HealthComponent (HealthComponent &&)
noexcept default

Definition at line 107 of file HealthComponent.ixx.

Reference HealthComponent.

Public Operators

operator=()

HealthComponent & helios::engine::mechanics::health::components::HealthComponent::operator= (const HealthComponent &)
default

Definition at line 106 of file HealthComponent.ixx.

Reference HealthComponent.

operator=()

HealthComponent & helios::engine::mechanics::health::components::HealthComponent::operator= (HealthComponent &&)
noexcept default

Definition at line 108 of file HealthComponent.ixx.

Reference HealthComponent.

Public Member Functions

clearDirty()

void helios::engine::mechanics::health::components::HealthComponent::clearDirty ()
inline noexcept

Resets the dirty flag.

Definition at line 201 of file HealthComponent.ixx.

201 void clearDirty() noexcept {
202 isDirty_ = false;
203 }

disable()

void helios::engine::mechanics::health::components::HealthComponent::disable ()
inline noexcept

Disables this component.

Definition at line 79 of file HealthComponent.ixx.

79 void disable() noexcept {
80 isEnabled_ = false;
81 }

enable()

void helios::engine::mechanics::health::components::HealthComponent::enable ()
inline noexcept

Enables this component.

Definition at line 72 of file HealthComponent.ixx.

72 void enable() noexcept {
73 isEnabled_ = true;
74 }

heal()

void helios::engine::mechanics::health::components::HealthComponent::heal (const float amount)
inline noexcept

Heals this entity.

Health is clamped to the maximum health value.

Parameters
amount

The amount to heal.

Definition at line 147 of file HealthComponent.ixx.

147 void heal(const float amount) noexcept {
148 health_ = std::min(maxHealth_, health_ + amount);
149 isDirty_ = true;
150 }

health()

float helios::engine::mechanics::health::components::HealthComponent::health ()
inline nodiscard noexcept

Returns the current health value.

Returns

The current health.

Definition at line 176 of file HealthComponent.ixx.

176 [[nodiscard]] float health() const noexcept {
177 return health_;
178 }

healthDepletedBehavior()

HealthDepletedBehavior helios::engine::mechanics::health::components::HealthComponent::healthDepletedBehavior ()
inline nodiscard noexcept

Returns the health depletion response behaviour.

Returns

Current HealthDepletedBehavior flags.

Definition at line 124 of file HealthComponent.ixx.

124 [[nodiscard]] HealthDepletedBehavior healthDepletedBehavior() const noexcept {
125 return healthDepletedBehavior_;
126 }

isAlive()

bool helios::engine::mechanics::health::components::HealthComponent::isAlive ()
inline nodiscard noexcept

Checks if the entity is alive.

Returns

True if health is greater than 0.

Definition at line 167 of file HealthComponent.ixx.

167 [[nodiscard]] bool isAlive() const noexcept {
168 return health_ > 0.0f;
169 }

Referenced by helios::engine::mechanics::health::HealthManager::flush.

isDirty()

bool helios::engine::mechanics::health::components::HealthComponent::isDirty ()
inline nodiscard noexcept

Checks whether the health value has been modified.

Returns

True if modified since the last clearDirty() call.

Definition at line 194 of file HealthComponent.ixx.

194 [[nodiscard]] bool isDirty() const noexcept {
195 return isDirty_;
196 }

isEnabled()

bool helios::engine::mechanics::health::components::HealthComponent::isEnabled ()
inline nodiscard noexcept

Checks whether this component is enabled.

Returns

True if enabled, false otherwise.

Definition at line 65 of file HealthComponent.ixx.

65 [[nodiscard]] bool isEnabled() const noexcept {
66 return isEnabled_;
67 }

maxHealth()

float helios::engine::mechanics::health::components::HealthComponent::maxHealth ()
inline nodiscard noexcept

Returns the maximum health value.

Returns

The maximum health.

Definition at line 185 of file HealthComponent.ixx.

185 [[nodiscard]] float maxHealth() const noexcept {
186 return maxHealth_;
187 }

Referenced by HealthComponent and setMaxHealth.

onAcquire()

void helios::engine::mechanics::health::components::HealthComponent::onAcquire ()
inline noexcept

Called when this entity is acquired from a pool.

Resets health to maximum value.

Definition at line 219 of file HealthComponent.ixx.

219 void onAcquire() noexcept {
220 reset();
221 }

Reference reset.

onRelease()

void helios::engine::mechanics::health::components::HealthComponent::onRelease ()
inline noexcept

Called when this entity is released back to a pool.

Resets health to maximum value.

Definition at line 228 of file HealthComponent.ixx.

228 void onRelease() noexcept {
229 reset();
230 }

Reference reset.

reset()

void helios::engine::mechanics::health::components::HealthComponent::reset ()
inline

Resets health to maximum.

Definition at line 209 of file HealthComponent.ixx.

209 void reset() {
210 health_ = maxHealth_;
211 isDirty_ = true;
212 }

Referenced by onAcquire and onRelease.

setHealthDepletedBehavior()

void helios::engine::mechanics::health::components::HealthComponent::setHealthDepletedBehavior (const HealthDepletedBehavior behavior)
inline noexcept

Sets the health depletion response behaviour.

Parameters
behavior

Bitmask of HealthDepletedBehavior flags.

Definition at line 115 of file HealthComponent.ixx.

115 void setHealthDepletedBehavior(const HealthDepletedBehavior behavior) noexcept {
116 healthDepletedBehavior_ = behavior;
117 }

Reference setHealthDepletedBehavior.

Referenced by setHealthDepletedBehavior.

setMaxHealth()

void helios::engine::mechanics::health::components::HealthComponent::setMaxHealth (const float maxHealth)
inline noexcept

Sets the maximum health value.

Parameters
maxHealth

The new maximum health.

Definition at line 157 of file HealthComponent.ixx.

157 void setMaxHealth(const float maxHealth) noexcept {
158 maxHealth_ = maxHealth;
159 isDirty_ = true;
160 }

Reference maxHealth.

takeDamage()

void helios::engine::mechanics::health::components::HealthComponent::takeDamage (const float damage)
inline noexcept

Applies damage to this entity.

Health is clamped to a minimum of 0.

Parameters
damage

The amount of damage to apply.

Definition at line 135 of file HealthComponent.ixx.

135 void takeDamage(const float damage) noexcept {
136 health_ = std::max(0.0f, health_ - damage);
137 isDirty_ = true;
138 }

Private Member Attributes

health_

float helios::engine::mechanics::health::components::HealthComponent::health_ {}

Current health value.

Definition at line 39 of file HealthComponent.ixx.

39 float health_{};

healthDepletedBehavior_

HealthDepletedBehavior helios::engine::mechanics::health::components::HealthComponent::healthDepletedBehavior_ = HealthDepletedBehavior::None

Flags controlling the response when health reaches zero.

Definition at line 51 of file HealthComponent.ixx.

isDirty_

bool helios::engine::mechanics::health::components::HealthComponent::isDirty_ = true

True if the health value was modified since the last clear.

Definition at line 56 of file HealthComponent.ixx.

56 bool isDirty_ = true;

isEnabled_

bool helios::engine::mechanics::health::components::HealthComponent::isEnabled_ = true

Whether this component is enabled.

Definition at line 44 of file HealthComponent.ixx.

44 bool isEnabled_ = true;

maxHealth_

float helios::engine::mechanics::health::components::HealthComponent::maxHealth_ {}

Maximum health value.

Definition at line 33 of file HealthComponent.ixx.

33 float maxHealth_{};

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.