From 08c72df1e5cfb25ec34c3a45cb937513dd886abb Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Tue, 28 Mar 2023 11:02:42 +0200 Subject: [PATCH] SET_STATIC - Added GetClosestStatic() --- Moose Development/Moose/Core/Set.lua | 69 ++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index 3920315a0..7382ffe09 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -1900,24 +1900,6 @@ do -- SET_GROUP return MGroupInclude end - --- Iterate the SET_GROUP and set for each unit the default cargo bay weight limit. - -- Because within a group, the type of carriers can differ, each cargo bay weight limit is set on @{Wrapper.Unit} level. - -- @param #SET_GROUP self - -- @usage - -- -- Set the default cargo bay weight limits of the carrier units. - -- local MySetGroup = SET_GROUP:New() - -- MySetGroup:SetCargoBayWeightLimit() - function SET_GROUP:SetCargoBayWeightLimit() - local Set = self:GetSet() - for GroupID, GroupData in pairs( Set ) do -- For each GROUP in SET_GROUP - for UnitName, UnitData in pairs( GroupData:GetUnits() ) do - -- local UnitData = UnitData -- Wrapper.Unit#UNIT - UnitData:SetCargoBayWeightLimit() - end - end - end - - --- Get the closest group of the set with respect to a given reference coordinate. Optionally, only groups of given coalitions are considered in the search. -- @param #SET_GROUP self -- @param Core.Point#COORDINATE Coordinate Reference Coordinate from which the closest group is determined. @@ -1952,6 +1934,23 @@ do -- SET_GROUP return gmin, dmin end + --- Iterate the SET_GROUP and set for each unit the default cargo bay weight limit. + -- Because within a group, the type of carriers can differ, each cargo bay weight limit is set on @{Wrapper.Unit} level. + -- @param #SET_GROUP self + -- @usage + -- -- Set the default cargo bay weight limits of the carrier units. + -- local MySetGroup = SET_GROUP:New() + -- MySetGroup:SetCargoBayWeightLimit() + function SET_GROUP:SetCargoBayWeightLimit() + local Set = self:GetSet() + for GroupID, GroupData in pairs( Set ) do -- For each GROUP in SET_GROUP + for UnitName, UnitData in pairs( GroupData:GetUnits() ) do + -- local UnitData = UnitData -- Wrapper.Unit#UNIT + UnitData:SetCargoBayWeightLimit() + end + end + end + end do -- SET_UNIT @@ -3794,6 +3793,40 @@ do -- SET_STATIC return TypeReport:Text( Delimiter ) end + --- Get the closest static of the set with respect to a given reference coordinate. Optionally, only statics of given coalitions are considered in the search. + -- @param #SET_STATIC self + -- @param Core.Point#COORDINATE Coordinate Reference Coordinate from which the closest static is determined. + -- @return Wrapper.Static#STATIC The closest static (if any). + -- @return #number Distance in meters to the closest static. + function SET_STATIC:GetClosestStatic(Coordinate, Coalitions) + + local Set = self:GetSet() + + local dmin=math.huge + local gmin=nil + + for GroupID, GroupData in pairs( Set ) do -- For each STATIC in SET_STATIC + local group=GroupData --Wrapper.Static#STATIC + + if group and group:IsAlive() and (Coalitions==nil or UTILS.IsAnyInTable(Coalitions, group:GetCoalition())) then + + local coord=group:GetCoord() + + -- Distance between ref. coordinate and group coordinate. + local d=UTILS.VecDist3D(Coordinate, coord) + + if d