Skip to content

Commit

Permalink
#SCENERY - Some fixes for kissing getLife function on some objects, a…
Browse files Browse the repository at this point in the history
…nd life points being zero on some objects
  • Loading branch information
Applevangelist committed Jan 17, 2025
1 parent b2dc7bc commit b522b38
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions Moose Development/Moose/Wrapper/Scenery.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -59,14 +59,22 @@ 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.
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 .
Expand Down Expand Up @@ -97,15 +105,15 @@ 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.
--@param #SCENERY self
--@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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b522b38

Please sign in to comment.