diff --git a/Moose Development/Moose/Core/Point.lua b/Moose Development/Moose/Core/Point.lua index 65022dec4..5139d50a2 100644 --- a/Moose Development/Moose/Core/Point.lua +++ b/Moose Development/Moose/Core/Point.lua @@ -446,6 +446,47 @@ do -- COORDINATE return gotunits, gotstatics, gotscenery, Units, Statics, Scenery end + + --- Scan/find UNITS 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 Core.Set#SET_UNIT Set of units. + function COORDINATE:ScanUnits(radius) + + local _,_,_,units=self:ScanObjects(radius, true, false, false) + + local set=SET_UNIT:New() + + for _,unit in pairs(units) do + set:AddUnit(unit) + end + + return set + end + + --- Find the closest unit to the COORDINATE within a certain radius. + -- @param #COORDINATE self + -- @param #number radius Scan radius in meters. Default 100 m. + -- @return Wrapper.Unit#UNIT The closest unit or #nil if no unit is inside the given radius. + function COORDINATE:FindClosestUnit(radius) + + local units=self:ScanUnits(radius) + + local umin=nil --Wrapper.Unit#UNIT + local dmin=math.huge + for _,_unit in pairs(units.Set) do + local unit=_unit --Wrapper.Unit#UNIT + local coordinate=unit:GetCoordinate() + local d=self:Get2DDistance(coordinate) + if d0 then + self:ScheduleOnce(Delay, USERFLAG.Set, self, Number) + else + trigger.action.setUserFlag( self.UserFlagName, Number ) + end return self end diff --git a/Moose Development/Moose/Functional/CleanUp.lua b/Moose Development/Moose/Functional/CleanUp.lua index e8fd44972..a2183c097 100644 --- a/Moose Development/Moose/Functional/CleanUp.lua +++ b/Moose Development/Moose/Functional/CleanUp.lua @@ -244,8 +244,8 @@ end -- @param Core.Event#EVENTDATA EventData function CLEANUP_AIRBASE.__:OnEventBirth( EventData ) self:F( { EventData } ) - - if EventData.IniUnit:IsAlive() ~= nil then + + if EventData and EventData.IniUnit and EventData.IniUnit:IsAlive() ~= nil then if self:IsInAirbase( EventData.IniUnit:GetVec2() ) then self.CleanUpList[EventData.IniDCSUnitName] = {} self.CleanUpList[EventData.IniDCSUnitName].CleanUpUnit = EventData.IniUnit diff --git a/Moose Development/Moose/Functional/Warehouse.lua b/Moose Development/Moose/Functional/Warehouse.lua index 433e3f178..06b8c67c4 100644 --- a/Moose Development/Moose/Functional/Warehouse.lua +++ b/Moose Development/Moose/Functional/Warehouse.lua @@ -1764,7 +1764,7 @@ _WAREHOUSEDB = { --- Warehouse class version. -- @field #string version -WAREHOUSE.version="1.0.1" +WAREHOUSE.version="1.0.2" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO: Warehouse todo list. @@ -8404,7 +8404,7 @@ end -- @return #string Text about warehouse stock function WAREHOUSE:_UpdateWarehouseMarkText() - if self.makerOn then + if self.markerOn then -- Create a mark with the current assets in stock. if self.markerid~=nil then diff --git a/Moose Development/Moose/Wrapper/Positionable.lua b/Moose Development/Moose/Wrapper/Positionable.lua index db8283a64..be85454a3 100644 --- a/Moose Development/Moose/Wrapper/Positionable.lua +++ b/Moose Development/Moose/Wrapper/Positionable.lua @@ -602,6 +602,26 @@ function POSITIONABLE:IsGround() end +--- Returns if the unit is of ship category. +-- @param #POSITIONABLE self +-- @return #boolean Ship category evaluation result. +function POSITIONABLE:IsShip() + self:F2() + + local DCSUnit = self:GetDCSObject() + + if DCSUnit then + local UnitDescriptor = DCSUnit:getDesc() + + local IsShip = ( UnitDescriptor.category == Unit.Category.SHIP ) + + return IsShip + end + + return nil +end + + --- Returns true if the POSITIONABLE is in the air. -- Polymorphic, is overridden in GROUP and UNIT. -- @param Wrapper.Positionable#POSITIONABLE self