From ec9a5efdde705711d71f443224bd2c699042c04a Mon Sep 17 00:00:00 2001 From: FlightControl Date: Mon, 1 Oct 2018 22:06:42 +0200 Subject: [PATCH] -- Added AnyInZone stuff. -- Now for tasking, routing messages show the task name... --- Moose Development/Moose/Actions/Act_Route.lua | 8 +++---- Moose Development/Moose/Core/Set.lua | 23 +++++++++++++++++++ Moose Development/Moose/Wrapper/Group.lua | 17 ++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/Moose Development/Moose/Actions/Act_Route.lua b/Moose Development/Moose/Actions/Act_Route.lua index 9f858879f..d719f1f7b 100644 --- a/Moose Development/Moose/Actions/Act_Route.lua +++ b/Moose Development/Moose/Actions/Act_Route.lua @@ -362,7 +362,7 @@ do -- ACT_ROUTE_POINT local Distance = self.Coordinate:Get2DDistance( ProcessUnit:GetCoordinate() ) if Distance <= self.Range then - local RouteText = "You have arrived." + local RouteText = "Task \"" .. self:GetTask():GetName() .. "\", you have arrived." self:GetCommandCenter():MessageTypeToGroup( RouteText, ProcessUnit:GetGroup(), MESSAGE.Type.Information ) return true end @@ -381,7 +381,7 @@ do -- ACT_ROUTE_POINT -- @param #string To function ACT_ROUTE_POINT:onafterReport( ProcessUnit, From, Event, To ) - local RouteText = self:GetRouteText( ProcessUnit ) + local RouteText = "Task \"" .. self:GetTask():GetName() .. "\", " .. self:GetRouteText( ProcessUnit ) self:GetCommandCenter():MessageTypeToGroup( RouteText, ProcessUnit:GetGroup(), MESSAGE.Type.Update ) end @@ -453,7 +453,7 @@ do -- ACT_ROUTE_ZONE function ACT_ROUTE_ZONE:onfuncHasArrived( ProcessUnit ) if ProcessUnit:IsInZone( self.Zone ) then - local RouteText = "You have arrived within the zone." + local RouteText = "Task \"" .. self:GetTask():GetName() .. "\", you have arrived within the zone." self:GetCommandCenter():MessageTypeToGroup( RouteText, ProcessUnit:GetGroup(), MESSAGE.Type.Information ) end @@ -471,7 +471,7 @@ do -- ACT_ROUTE_ZONE function ACT_ROUTE_ZONE:onafterReport( ProcessUnit, From, Event, To ) self:F( { ProcessUnit = ProcessUnit } ) - local RouteText = self:GetRouteText( ProcessUnit ) + local RouteText = "Task \"" .. self:GetTask():GetName() .. "\", " .. self:GetRouteText( ProcessUnit ) self:GetCommandCenter():MessageTypeToGroup( RouteText, ProcessUnit:GetGroup(), MESSAGE.Type.Update ) end diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index d1a1cc8db..15621ec6f 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -1229,6 +1229,29 @@ do -- SET_GROUP end return true end + + --- Iterate the SET_GROUP and call an iterator function for each alive GROUP that has any unit in the @{Core.Zone}, providing the GROUP and optional parameters to the called function. + -- @param #SET_GROUP self + -- @param Core.Zone#ZONE ZoneObject The Zone to be tested for. + -- @param #function IteratorFunction The function that will be called when there is an alive GROUP in the SET_GROUP. The function needs to accept a GROUP parameter. + -- @return #SET_GROUP self + function SET_GROUP:ForEachGroupAnyInZone( ZoneObject, IteratorFunction, ... ) + self:F2( arg ) + + self:ForEach( IteratorFunction, arg, self:GetSet(), + --- @param Core.Zone#ZONE_BASE ZoneObject + -- @param Wrapper.Group#GROUP GroupObject + function( ZoneObject, GroupObject ) + if GroupObject:IsAnyInZone( ZoneObject ) then + return true + else + return false + end + end, { ZoneObject } ) + + return self + end + --- Iterate the SET_GROUP and return true if at least one of the @{Wrapper.Group#GROUP} is completely inside the @{Core.Zone#ZONE} -- @param #SET_GROUP self diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index 536d7f8e8..e00e79c4d 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -1008,6 +1008,23 @@ function GROUP:IsNotInZone( Zone ) return true end +--- Returns true if any units of the group are within a @{Core.Zone}. +-- @param #GROUP self +-- @param Core.Zone#ZONE_BASE Zone The zone to test. +-- @return #boolean Returns true if any unit of the Group is within the @{Core.Zone#ZONE_BASE} +function GROUP:IsAnyInZone( Zone ) + + if not self:IsAlive() then return false end + + for UnitID, UnitData in pairs( self:GetUnits() ) do + local Unit = UnitData -- Wrapper.Unit#UNIT + if Zone:IsVec3InZone( Unit:GetVec3() ) then + return true + end + end + return false +end + --- Returns the number of UNITs that are in the @{Zone} -- @param #GROUP self -- @param Core.Zone#ZONE_BASE Zone The zone to test.