From d5322466e9fafd2cf6aaa726c0dbaacae616cecf Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Sun, 21 Jan 2024 16:44:31 +0100 Subject: [PATCH] SCENERY add-ons --- Moose Development/Moose/Core/Set.lua | 2 +- Moose Development/Moose/Wrapper/Scenery.lua | 28 ++++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index 70fe7eaad..0045ee7fa 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -8399,7 +8399,7 @@ do -- SET_SCENERY --- Calculate current relative lifepoints of the SET objects, i.e. Life divided by Life0 as percentage value, eg 75 meaning 75% alive. -- **CAVEAT**: Some objects change their life value or "hitpoints" **after** the first hit. Hence we will adjust the Life0 value to 120% -- of the last life value if life exceeds life0 ata any point. - -- Thus will will get a smooth percentage decrease, if you use this e.g. as success criteria for a bombing task. + -- Thus we will get a smooth percentage decrease, if you use this e.g. as success criteria for a bombing task. -- @param #SET_SCENERY self -- @return #number LifePoints function SET_SCENERY:GetRelativeLife() diff --git a/Moose Development/Moose/Wrapper/Scenery.lua b/Moose Development/Moose/Wrapper/Scenery.lua index 1ef31a039..2706aad71 100644 --- a/Moose Development/Moose/Wrapper/Scenery.lua +++ b/Moose Development/Moose/Wrapper/Scenery.lua @@ -123,18 +123,38 @@ end --- Check if SCENERY Object is alive. --@param #SCENERY self +--@param #number Threshold (Optional) If given, SCENERY counts as alive above this relative life in percent (1..100). --@return #number life -function SCENERY:IsAlive() - return self:GetLife() >= 1 and true or false +function SCENERY:IsAlive(Threshold) + if not Threshold then + return self:GetLife() >= 1 and true or false + else + return self:GetRelativeLife() > Threshold and true or false + end end --- Check if SCENERY Object is dead. --@param #SCENERY self +--@param #number Threshold (Optional) If given, SCENERY counts as dead below this relative life in percent (1..100). --@return #number life -function SCENERY:IsDead() - return self:GetLife() < 1 and true or false +function SCENERY:IsDead(Threshold) + if not Threshold then + return self:GetLife() < 1 and true or false + else + return self:GetRelativeLife() <= Threshold and true or false + end end +--- Get SCENERY relative life in percent, e.g. 75. +--@param #SCENERY self +--@return #number rlife +function SCENERY:GetRelativeLife() + local life = self:GetLife() + local life0 = self:GetLife0() + local rlife = math.floor((life/life0)*100) + return rlife +end + --- Get the threat level of a SCENERY object. Always 0 as scenery does not pose a threat to anyone. --@param #SCENERY self --@return #number Threat level 0.