#SCENERY - Improvements

This commit is contained in:
Applevangelist 2022-10-13 10:48:51 +02:00
parent dc6159f90a
commit d0b6791efd

View File

@ -4,7 +4,7 @@
-- --
-- ### Author: **FlightControl** -- ### Author: **FlightControl**
-- --
-- ### Contributions: -- ### Contributions: **Applevangelist**
-- --
-- === -- ===
-- --
@ -14,6 +14,9 @@
--- @type SCENERY --- @type SCENERY
-- @field #string ClassName
-- @field #string SceneryName
-- @field #DCS.Object SceneryObject
-- @extends Wrapper.Positionable#POSITIONABLE -- @extends Wrapper.Positionable#POSITIONABLE
@ -43,14 +46,14 @@ function SCENERY:Register( SceneryName, SceneryObject )
return self return self
end end
--- Register scenery object as POSITIONABLE. --- Obtain DCS Object from the SCENERY Object.
--@param #SCENERY self --@param #SCENERY self
--@return #DCS.Object DCS scenery object. --@return #DCS.Object DCS scenery object.
function SCENERY:GetDCSObject() function SCENERY:GetDCSObject()
return self.SceneryObject return self.SceneryObject
end end
--- Register scenery object as POSITIONABLE. --- Get the threat level of a SCENERY object. Always 0.
--@param #SCENERY self --@param #SCENERY self
--@return #number Threat level 0. --@return #number Threat level 0.
--@return #string "Scenery". --@return #string "Scenery".
@ -58,39 +61,59 @@ function SCENERY:GetThreatLevel()
return 0, "Scenery" return 0, "Scenery"
end end
--- Create a SCENERY object from it's name/id. --- Find a SCENERY object from it's name/id. Since SCENERY isn't registered in the Moose database (just too many objects per map), we need to do a scan first
-- to find the correct object.
--@param #SCENERY self --@param #SCENERY self
--@param #string name The name/id of the scenery object as taken from the ME. Ex. '595785449' --@param #string Name The name/id of the scenery object as taken from the ME. Ex. '595785449'
--@return #SCENERY Scenery Object - **Note** this might not point to anything useful. Check with `myscenery:IsAlive()` if it is valid. --@param Core.Point#COORDINATE Coordinate Where to find the scenery object
function SCENERY:FindByName(name) --@param #number Radius (optional) Search radius around coordinate, defaults to 100
local findAirbase = function () --@return #SCENERY Scenery Object or `nil` if it cannot be found
local airbases = AIRBASE.GetAllAirbases() function SCENERY:FindByName(Name, Coordinate, Radius)
for index,airbase in pairs(airbases) do
local surftype = airbase:GetCoordinate():GetSurfaceType() local radius = Radius or 100
if surftype ~= land.SurfaceType.SHALLOW_WATER and surftype ~= land.SurfaceType.WATER then local name = Name or "unknown"
return airbase:GetCoordinate() local scenery = nil
end
end ---
return nil -- @param Core.Point#COORDINATE coordinate
end -- @param #number radius
-- @param #string name
local sceneryScan = function (scancoord) local function SceneryScan (coordinate, radius, name)
if scancoord ~= nil then if coordinate ~= nil then
local _,_,sceneryfound,_,_,scenerylist = scancoord:ScanObjects(200, false, false, true) local scenerylist = coordinate:ScanScenery(radius)
if sceneryfound == true then local rscenery = nil
scenerylist[1].id_ = name for _,_scenery in pairs(scenerylist) do
SCENERY.SceneryObject = SCENERY:Register(scenerylist[1].id_, scenerylist[1]) local scenery = _scenery -- Wrapper.Scenery#SCENERY
return SCENERY.SceneryObject if tostring(scenery.SceneryName) == tostring(name) then
rscenery = scenery
break
end
end end
return rscenery
end end
return nil return nil
end end
if SCENERY.SceneryObject then if Coordinate then
SCENERY.SceneryObject.SceneryObject.id_ = name scenery = SceneryScan(Coordinate, radius, name)
SCENERY.SceneryObject.SceneryName = name
return SCENERY:Register(SCENERY.SceneryObject.SceneryObject.id_, SCENERY.SceneryObject.SceneryObject)
else
return sceneryScan(findAirbase())
end end
return scenery
end
--- Find a SCENERY object from it's name/id. Since SCENERY isn't registered in the Moose database (just too many objects per map), we need to do a scan first
-- to find the correct object.
--@param #SCENERY self
--@param #string Name The name/id of the scenery object as taken from the ME. Ex. '595785449'
--@param Core.Zone#ZONE Zone Where to find the scenery object. Can be handed as zone name.
--@param #number Radius (optional) Search radius around coordinate, defaults to 100
--@return #SCENERY Scenery Object or `nil` if it cannot be found
function SCENERY:FindByNameInZone(Name, Zone, Radius)
local radius = Radius or 100
local name = Name or "unknown"
if type(Zone) == "string" then
Zone = ZONE:FindByName(Zone)
end
local coordinate = Zone:GetCoordinate()
return self:FindByName(Name,coordinate,Radius)
end end