mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
#SCENERY - Some fixes for kissing getLife function on some objects, and life points being zero on some objects
This commit is contained in:
parent
b2dc7bc232
commit
b522b38d31
@ -48,8 +48,8 @@ function SCENERY:Register( SceneryName, SceneryObject )
|
|||||||
|
|
||||||
self.SceneryObject = SceneryObject
|
self.SceneryObject = SceneryObject
|
||||||
|
|
||||||
if self.SceneryObject then
|
if self.SceneryObject and self.SceneryObject.getLife then -- fix some objects do not have all functions
|
||||||
self.Life0 = self.SceneryObject:getLife()
|
self.Life0 = self.SceneryObject:getLife() or 0
|
||||||
else
|
else
|
||||||
self.Life0 = 0
|
self.Life0 = 0
|
||||||
end
|
end
|
||||||
@ -59,7 +59,7 @@ function SCENERY:Register( SceneryName, SceneryObject )
|
|||||||
return self
|
return self
|
||||||
end
|
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 #SCENERY self
|
||||||
-- @param #string PropertyName The name of a the QuadZone Property from the scenery assignment to be retrieved.
|
-- @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.
|
-- @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]
|
return self.Properties[PropertyName]
|
||||||
end
|
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.
|
--- Returns the scenery Properties table.
|
||||||
-- @param #SCENERY self
|
-- @param #SCENERY self
|
||||||
-- @return #table The Key:Value table of QuadZone properties of the zone from the scenery assignment .
|
-- @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
|
return self.SceneryObject
|
||||||
end
|
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%
|
-- **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
|
-- 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.
|
-- criteria for a bombing task.
|
||||||
@ -105,7 +113,7 @@ end
|
|||||||
--@return #number life
|
--@return #number life
|
||||||
function SCENERY:GetLife()
|
function SCENERY:GetLife()
|
||||||
local life = 0
|
local life = 0
|
||||||
if self.SceneryObject then
|
if self.SceneryObject and self.SceneryObject.getLife then
|
||||||
life = self.SceneryObject:getLife()
|
life = self.SceneryObject:getLife()
|
||||||
if life > self.Life0 then
|
if life > self.Life0 then
|
||||||
self.Life0 = math.floor(life * 1.2)
|
self.Life0 = math.floor(life * 1.2)
|
||||||
@ -121,7 +129,7 @@ function SCENERY:GetLife0()
|
|||||||
return self.Life0 or 0
|
return self.Life0 or 0
|
||||||
end
|
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 #SCENERY self
|
||||||
--@param #number Threshold (Optional) If given, SCENERY counts as alive above this relative life in percent (1..100).
|
--@param #number Threshold (Optional) If given, SCENERY counts as alive above this relative life in percent (1..100).
|
||||||
--@return #number life
|
--@return #number life
|
||||||
@ -133,7 +141,7 @@ function SCENERY:IsAlive(Threshold)
|
|||||||
end
|
end
|
||||||
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 #SCENERY self
|
||||||
--@param #number Threshold (Optional) If given, SCENERY counts as dead below this relative life in percent (1..100).
|
--@param #number Threshold (Optional) If given, SCENERY counts as dead below this relative life in percent (1..100).
|
||||||
--@return #number life
|
--@return #number life
|
||||||
@ -145,12 +153,13 @@ function SCENERY:IsDead(Threshold)
|
|||||||
end
|
end
|
||||||
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
|
--@param #SCENERY self
|
||||||
--@return #number rlife
|
--@return #number rlife
|
||||||
function SCENERY:GetRelativeLife()
|
function SCENERY:GetRelativeLife()
|
||||||
local life = self:GetLife()
|
local life = self:GetLife()
|
||||||
local life0 = self:GetLife0()
|
local life0 = self:GetLife0()
|
||||||
|
if life == 0 or life0 == 0 then return 0 end
|
||||||
local rlife = math.floor((life/life0)*100)
|
local rlife = math.floor((life/life0)*100)
|
||||||
return rlife
|
return rlife
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user