From 67c5e57b0a56fc640653e9a88946d5f33eadb358 Mon Sep 17 00:00:00 2001 From: NoFantasy Date: Sun, 21 Feb 2010 11:45:44 +0100 Subject: [PATCH] [9427] Add helper functions for Unit::Get/SetHealthPercent Signed-off-by: NoFantasy --- src/game/Unit.cpp | 6 ++++++ src/game/Unit.h | 2 ++ src/shared/revision_nr.h | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index deab46f60..2cb70f2f5 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -11649,6 +11649,12 @@ void Unit::SetMaxHealth(uint32 val) SetHealth(val); } +void Unit::SetHealthPercent(float percent) +{ + uint32 newHealth = GetMaxHealth() * percent/100.0f; + SetHealth(newHealth); +} + void Unit::SetPower(Powers power, uint32 val) { if(GetPower(power) == val) diff --git a/src/game/Unit.h b/src/game/Unit.h index 52cc3a59e..158903a68 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -1160,8 +1160,10 @@ class MANGOS_DLL_SPEC Unit : public WorldObject uint32 GetHealth() const { return GetUInt32Value(UNIT_FIELD_HEALTH); } uint32 GetMaxHealth() const { return GetUInt32Value(UNIT_FIELD_MAXHEALTH); } + float GetHealthPercent() const { return (GetHealth()*100.0f) / GetMaxHealth(); } void SetHealth( uint32 val); void SetMaxHealth(uint32 val); + void SetHealthPercent(float percent); int32 ModifyHealth(int32 val); Powers getPowerType() const { return Powers(GetByteValue(UNIT_FIELD_BYTES_0, 3)); } diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 4c68a9479..76a2df8c5 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "9426" + #define REVISION_NR "9427" #endif // __REVISION_NR_H__