From 980053916b0924dae7951c80dfa605e845e1118a Mon Sep 17 00:00:00 2001 From: Grey-Echo Date: Sat, 22 Apr 2017 11:15:16 +0200 Subject: [PATCH] Solves a bug in GROUP:IsPartlyInZone() If only the first UNITs of the GROUP where outside the ZONE, the function would still return false This behaviour is fixed by this commit. --- Moose Development/Moose/Core/Set.lua | 8 ++++---- Moose Development/Moose/Wrapper/Group.lua | 17 +++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index 7225ff63f..9bfd27a02 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -1004,14 +1004,14 @@ function SET_GROUP:AnyCompletelyInZone(Zone) self:F2(Zone) local Set = self:GetSet() for GroupID, GroupData in pairs(Set) do -- For each GROUP in SET_GROUP - if GroupData:IsCompletlyInZone(Zone) then + if GroupData:IsCompletelyInZone(Zone) then return true end end return false end ---- Iterate the SET_GROUP and return true if at least one least one @{#UNIT} of one @{GROUP} of the @{SET_GROUP} is in @{ZONE} +--- Iterate the SET_GROUP and return true if at least one @{#UNIT} of one @{GROUP} of the @{SET_GROUP} is in @{ZONE} -- @param #SET_GROUP self -- @param Core.Zone#ZONE ZoneObject The Zone to be tested for. -- @return #boolean true if at least one of the @{Wrapper.Group#GROUP} is partly or completly inside the @{Core.Zone#ZONE}, false otherwise. @@ -1023,7 +1023,7 @@ end -- if MySetGroup:AnyPartlyInZone(MyZone) then -- MESSAGE:New("At least one GROUP has at least one UNIT in zone !", 10):ToAll() -- else --- MESSAGE:New("No GROUP is completely in zone !", 10):ToAll() +-- MESSAGE:New("No UNIT of any GROUP is in zone !", 10):ToAll() -- end function SET_GROUP:AnyPartlyInZone(Zone) self:F2(Zone) @@ -1050,7 +1050,7 @@ end -- if MySetGroup:NoneInZone(MyZone) then -- MESSAGE:New("No GROUP is completely in zone !", 10):ToAll() -- else --- MESSAGE:New("At least one GROUP has at least one UNIT in zone !", 10):ToAll() +-- MESSAGE:New("No UNIT of any GROUP is in zone !", 10):ToAll() -- end function SET_GROUP:NoneInZone(Zone) self:F2(Zone) diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index 2d845a9f2..3e9e6b5f9 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -555,22 +555,23 @@ end function GROUP:IsPartlyInZone( Zone ) self:F2( { self.GroupName, Zone } ) - local PartlyInZone = false + local IsOneUnitInZone = false + local IsOneUnitOutsideZone = false for UnitID, UnitData in pairs( self:GetUnits() ) do local Unit = UnitData -- Wrapper.Unit#UNIT if Zone:IsVec3InZone( Unit:GetVec3() ) then - PartlyInZone = true + IsOneUnitInZone = true else - -- So, if there were groups in the zone found, and suddenly one NOT in the zone, - -- then the group is partialy in the zone :-) - if PartlyInZone == true then - return true - end + IsOneUnitOutsideZone = true end end - return false + if IsOneUnitInZone and IsOneUnitOutsideZone then + return true + else + return false + end end --- Returns true if none of the group units of the group are within a @{Zone}.