From b522b38d31e5e4c0373cd83a9a644bc3806a8141 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Fri, 17 Jan 2025 09:21:48 +0100 Subject: [PATCH] #SCENERY - Some fixes for kissing getLife function on some objects, and life points being zero on some objects --- Moose Development/Moose/Wrapper/Scenery.lua | 25 ++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Moose Development/Moose/Wrapper/Scenery.lua b/Moose Development/Moose/Wrapper/Scenery.lua index 2706aad71..eb69e7ab4 100644 --- a/Moose Development/Moose/Wrapper/Scenery.lua +++ b/Moose Development/Moose/Wrapper/Scenery.lua @@ -48,8 +48,8 @@ function SCENERY:Register( SceneryName, SceneryObject ) self.SceneryObject = SceneryObject - if self.SceneryObject then - self.Life0 = self.SceneryObject:getLife() + if self.SceneryObject and self.SceneryObject.getLife then -- fix some objects do not have all functions + self.Life0 = self.SceneryObject:getLife() or 0 else self.Life0 = 0 end @@ -59,7 +59,7 @@ function SCENERY:Register( SceneryName, SceneryObject ) return self end ---- Returns the Value of the zone with the given PropertyName, or nil if no matching property exists. +--- Returns the value of the scenery with the given PropertyName, or nil if no matching property exists. -- @param #SCENERY self -- @param #string PropertyName The name of a the QuadZone Property from the scenery assignment to be retrieved. -- @return #string The Value of the QuadZone Property from the scenery assignment with the given PropertyName, or nil if absent. @@ -67,6 +67,14 @@ function SCENERY:GetProperty(PropertyName) return self.Properties[PropertyName] end +--- Checks if the value of the scenery with the given PropertyName exists. +-- @param #SCENERY self +-- @param #string PropertyName The name of a the QuadZone Property from the scenery assignment to be retrieved. +-- @return #boolean Outcome True if it exists, else false. +function SCENERY:HasProperty(PropertyName) + return self.Properties[PropertyName] ~= nil and true or false +end + --- Returns the scenery Properties table. -- @param #SCENERY self -- @return #table The Key:Value table of QuadZone properties of the zone from the scenery assignment . @@ -97,7 +105,7 @@ function SCENERY:GetDCSObject() return self.SceneryObject end ---- Get current life points from the SCENERY Object. +--- Get current life points from the SCENERY Object. Note - Some scenery objects always have 0 life points. -- **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 (initial life) at any point. Thus will will get a smooth percentage decrease, if you use this e.g. as success -- criteria for a bombing task. @@ -105,7 +113,7 @@ end --@return #number life function SCENERY:GetLife() local life = 0 - if self.SceneryObject then + if self.SceneryObject and self.SceneryObject.getLife then life = self.SceneryObject:getLife() if life > self.Life0 then self.Life0 = math.floor(life * 1.2) @@ -121,7 +129,7 @@ function SCENERY:GetLife0() return self.Life0 or 0 end ---- Check if SCENERY Object is alive. +--- Check if SCENERY Object is alive. Note - Some scenery objects always have 0 life points. --@param #SCENERY self --@param #number Threshold (Optional) If given, SCENERY counts as alive above this relative life in percent (1..100). --@return #number life @@ -133,7 +141,7 @@ function SCENERY:IsAlive(Threshold) end end ---- Check if SCENERY Object is dead. +--- Check if SCENERY Object is dead. Note - Some scenery objects always have 0 life points. --@param #SCENERY self --@param #number Threshold (Optional) If given, SCENERY counts as dead below this relative life in percent (1..100). --@return #number life @@ -145,12 +153,13 @@ function SCENERY:IsDead(Threshold) end end ---- Get SCENERY relative life in percent, e.g. 75. +--- Get SCENERY relative life in percent, e.g. 75. Note - Some scenery objects always have 0 life points. --@param #SCENERY self --@return #number rlife function SCENERY:GetRelativeLife() local life = self:GetLife() local life0 = self:GetLife0() + if life == 0 or life0 == 0 then return 0 end local rlife = math.floor((life/life0)*100) return rlife end