mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
#SCENERY - Improvements
This commit is contained in:
parent
cd99c053df
commit
ab4c83d284
@ -594,7 +594,7 @@ do -- COORDINATE
|
||||
--- Scan/find SCENERY objects within a certain radius around the coordinate using the world.searchObjects() DCS API function.
|
||||
-- @param #COORDINATE self
|
||||
-- @param #number radius (Optional) Scan radius in meters. Default 100 m.
|
||||
-- @return table Set of scenery objects.
|
||||
-- @return table Table of SCENERY objects.
|
||||
function COORDINATE:ScanScenery(radius)
|
||||
|
||||
local _,_,_,_,_,scenerys=self:ScanObjects(radius, false, false, true)
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
--
|
||||
-- ### Author: **FlightControl**
|
||||
--
|
||||
-- ### Contributions:
|
||||
-- ### Contributions: **Applevangelist**
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
@ -14,6 +14,9 @@
|
||||
|
||||
|
||||
--- @type SCENERY
|
||||
-- @field #string ClassName
|
||||
-- @field #string SceneryName
|
||||
-- @field #DCS.Object SceneryObject
|
||||
-- @extends Wrapper.Positionable#POSITIONABLE
|
||||
|
||||
|
||||
@ -43,14 +46,14 @@ function SCENERY:Register( SceneryName, SceneryObject )
|
||||
return self
|
||||
end
|
||||
|
||||
--- Register scenery object as POSITIONABLE.
|
||||
--- Obtain DCS Object from the SCENERY Object.
|
||||
--@param #SCENERY self
|
||||
--@return #DCS.Object DCS scenery object.
|
||||
function SCENERY:GetDCSObject()
|
||||
return self.SceneryObject
|
||||
end
|
||||
|
||||
--- Register scenery object as POSITIONABLE.
|
||||
--- Get the threat level of a SCENERY object. Always 0.
|
||||
--@param #SCENERY self
|
||||
--@return #number Threat level 0.
|
||||
--@return #string "Scenery".
|
||||
@ -58,39 +61,59 @@ function SCENERY:GetThreatLevel()
|
||||
return 0, "Scenery"
|
||||
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 #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.
|
||||
function SCENERY:FindByName(name)
|
||||
local findAirbase = function ()
|
||||
local airbases = AIRBASE.GetAllAirbases()
|
||||
for index,airbase in pairs(airbases) do
|
||||
local surftype = airbase:GetCoordinate():GetSurfaceType()
|
||||
if surftype ~= land.SurfaceType.SHALLOW_WATER and surftype ~= land.SurfaceType.WATER then
|
||||
return airbase:GetCoordinate()
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local sceneryScan = function (scancoord)
|
||||
if scancoord ~= nil then
|
||||
local _,_,sceneryfound,_,_,scenerylist = scancoord:ScanObjects(200, false, false, true)
|
||||
if sceneryfound == true then
|
||||
scenerylist[1].id_ = name
|
||||
SCENERY.SceneryObject = SCENERY:Register(scenerylist[1].id_, scenerylist[1])
|
||||
return SCENERY.SceneryObject
|
||||
--@param #string Name The name/id of the scenery object as taken from the ME. Ex. '595785449'
|
||||
--@param Core.Point#COORDINATE Coordinate Where to find the scenery object
|
||||
--@param #number Radius (optional) Search radius around coordinate, defaults to 100
|
||||
--@return #SCENERY Scenery Object or `nil` if it cannot be found
|
||||
function SCENERY:FindByName(Name, Coordinate, Radius)
|
||||
|
||||
local radius = Radius or 100
|
||||
local name = Name or "unknown"
|
||||
local scenery = nil
|
||||
|
||||
---
|
||||
-- @param Core.Point#COORDINATE coordinate
|
||||
-- @param #number radius
|
||||
-- @param #string name
|
||||
local function SceneryScan (coordinate, radius, name)
|
||||
if coordinate ~= nil then
|
||||
local scenerylist = coordinate:ScanScenery(radius)
|
||||
local rscenery = nil
|
||||
for _,_scenery in pairs(scenerylist) do
|
||||
local scenery = _scenery -- Wrapper.Scenery#SCENERY
|
||||
if tostring(scenery.SceneryName) == tostring(name) then
|
||||
rscenery = scenery
|
||||
break
|
||||
end
|
||||
end
|
||||
return rscenery
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
if SCENERY.SceneryObject then
|
||||
SCENERY.SceneryObject.SceneryObject.id_ = name
|
||||
SCENERY.SceneryObject.SceneryName = name
|
||||
return SCENERY:Register(SCENERY.SceneryObject.SceneryObject.id_, SCENERY.SceneryObject.SceneryObject)
|
||||
else
|
||||
return sceneryScan(findAirbase())
|
||||
if Coordinate then
|
||||
scenery = SceneryScan(Coordinate, radius, name)
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user