diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index 091276242..a108b9e77 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -904,6 +904,8 @@ end do -- SET_GROUP --- @type SET_GROUP #SET_GROUP + -- @field Core.Timer#TIMER ZoneTimer + -- @field #number ZoneTimerInterval -- @extends Core.Set#SET_BASE --- Mission designers can use the @{Core.Set#SET_GROUP} class to build sets of groups belonging to certain: @@ -1343,6 +1345,25 @@ do -- SET_GROUP end return self end + + --- [Internal] Private function for use of continous zone filter + -- @param #SET_GROUP self + -- @return #SET_GROUP self + function SET_GROUP:_ContinousZoneFilter() + + local Database = _DATABASE.GROUPS + + for ObjectName, Object in pairs( Database ) do + if self:IsIncludeObject( Object ) and self:IsNotInSet(Object) then + self:Add( ObjectName, Object ) + elseif (not self:IsIncludeObject( Object )) and self:IsInSet(Object) then + self:Remove(ObjectName) + end + end + + return self + + end --- Builds a set of groups that are only active. -- Only the groups that are active will be included within the set. @@ -1381,10 +1402,46 @@ do -- SET_GROUP self:HandleEvent( EVENTS.Dead, self._EventOnDeadOrCrash ) self:HandleEvent( EVENTS.Crash, self._EventOnDeadOrCrash ) self:HandleEvent( EVENTS.RemoveUnit, self._EventOnDeadOrCrash ) + if self.Filter.Zones then + self.ZoneTimer = TIMER:New(self._ContinousZoneFilter,self) + local timing = self.ZoneTimerInterval or 30 + self.ZoneTimer:Start(timing,timing) + end end return self end + + --- Set filter timer interval for FilterZones if using active filtering with FilterStart(). + -- @param #SET_GROUP self + -- @param #number Seconds Seconds between check intervals, defaults to 30. **Caution** - do not be too agressive with timing! Groups are usually not moving fast enough + -- to warrant a check of below 10 seconds. + -- @return #SET_GROUP self + function SET_GROUP:FilterZoneTimer(Seconds) + self.ZoneTimerInterval = Seconds or 30 + return self + end + + --- Stops the filtering. + -- @param #SET_GROUP self + -- @return #SET_GROUP self + function SET_GROUP:FilterStop() + + if _DATABASE then + + self:UnHandleEvent(EVENTS.Birth) + self:UnHandleEvent(EVENTS.Dead) + self:UnHandleEvent(EVENTS.Crash) + self:UnHandleEvent(EVENTS.RemoveUnit) + + if self.Filter.Zones and self.ZoneTimer and self.ZoneTimer:IsRunning() then + self.ZoneTimer:Stop() + end + end + + return self + end + --- Handles the OnDead or OnCrash event for alive groups set. -- Note: The GROUP object in the SET_GROUP collection will only be removed if the last unit is destroyed of the GROUP. @@ -1956,6 +2013,8 @@ end do -- SET_UNIT --- @type SET_UNIT + -- @field Core.Timer#TIMER ZoneTimer + -- @field #number ZoneTimerInterval -- @extends Core.Set#SET_BASE --- Mission designers can use the SET_UNIT class to build sets of units belonging to certain: @@ -2347,7 +2406,56 @@ do -- SET_UNIT return CountU end + + --- [Internal] Private function for use of continous zone filter + -- @param #SET_UNIT self + -- @return #SET_UNIT self + function SET_UNIT:_ContinousZoneFilter() + + local Database = _DATABASE.UNITS + + for ObjectName, Object in pairs( Database ) do + if self:IsIncludeObject( Object ) and self:IsNotInSet(Object) then + self:Add( ObjectName, Object ) + elseif (not self:IsIncludeObject( Object )) and self:IsInSet(Object) then + self:Remove(ObjectName) + end + end + + return self + + end + + --- Set filter timer interval for FilterZones if using active filtering with FilterStart(). + -- @param #SET_UNIT self + -- @param #number Seconds Seconds between check intervals, defaults to 30. **Caution** - do not be too agressive with timing! Groups are usually not moving fast enough + -- to warrant a check of below 10 seconds. + -- @return #SET_UNIT self + function SET_UNIT:FilterZoneTimer(Seconds) + self.ZoneTimerInterval = Seconds or 30 + return self + end + + --- Stops the filtering. + -- @param #SET_UNIT self + -- @return #SET_UNIT self + function SET_UNIT:FilterStop() + if _DATABASE then + + self:UnHandleEvent(EVENTS.Birth) + self:UnHandleEvent(EVENTS.Dead) + self:UnHandleEvent(EVENTS.Crash) + self:UnHandleEvent(EVENTS.RemoveUnit) + + if self.Filter.Zones and self.ZoneTimer and self.ZoneTimer:IsRunning() then + self.ZoneTimer:Stop() + end + end + + return self + end + --- Starts the filtering. -- @param #SET_UNIT self -- @return #SET_UNIT self @@ -2359,6 +2467,11 @@ do -- SET_UNIT self:HandleEvent( EVENTS.Dead, self._EventOnDeadOrCrash ) self:HandleEvent( EVENTS.Crash, self._EventOnDeadOrCrash ) self:HandleEvent( EVENTS.RemoveUnit, self._EventOnDeadOrCrash ) + if self.Filter.Zones then + self.ZoneTimer = TIMER:New(self._ContinousZoneFilter,self) + local timing = self.ZoneTimerInterval or 30 + self.ZoneTimer:Start(timing,timing) + end end return self @@ -3834,6 +3947,8 @@ end do -- SET_CLIENT --- @type SET_CLIENT + -- @field Core.Timer#TIMER ZoneTimer + -- @field #number ZoneTimerInterval -- @extends Core.Set#SET_BASE --- Mission designers can use the @{Core.Set#SET_CLIENT} class to build sets of units belonging to certain: @@ -4141,6 +4256,54 @@ do -- SET_CLIENT return self end + --- [Internal] Private function for use of continous zone filter + -- @param #SET_CLIENT self + -- @return #SET_CLIENT self + function SET_CLIENT:_ContinousZoneFilter() + + local Database = _DATABASE.CLIENTS + + for ObjectName, Object in pairs( Database ) do + if self:IsIncludeObject( Object ) and self:IsNotInSet(Object) then + self:Add( ObjectName, Object ) + elseif (not self:IsIncludeObject( Object )) and self:IsInSet(Object) then + self:Remove(ObjectName) + end + end + + return self + + end + + --- Set filter timer interval for FilterZones if using active filtering with FilterStart(). + -- @param #SET_CLIENT self + -- @param #number Seconds Seconds between check intervals, defaults to 30. **Caution** - do not be too agressive with timing! Groups are usually not moving fast enough + -- to warrant a check of below 10 seconds. + -- @return #SET_CLIENT self + function SET_CLIENT:FilterZoneTimer(Seconds) + self.ZoneTimerInterval = Seconds or 30 + return self + end + + --- Stops the filtering. + -- @param #SET_CLIENT self + -- @return #SET_CLIENT self + function SET_CLIENT:FilterStop() + + if _DATABASE then + + self:UnHandleEvent(EVENTS.Birth) + self:UnHandleEvent(EVENTS.Dead) + self:UnHandleEvent(EVENTS.Crash) + + if self.Filter.Zones and self.ZoneTimer and self.ZoneTimer:IsRunning() then + self.ZoneTimer:Stop() + end + end + + return self + end + --- Starts the filtering. -- @param #SET_CLIENT self -- @return #SET_CLIENT self @@ -4151,6 +4314,11 @@ do -- SET_CLIENT self:HandleEvent( EVENTS.Birth, self._EventOnBirth ) self:HandleEvent( EVENTS.Dead, self._EventOnDeadOrCrash ) self:HandleEvent( EVENTS.Crash, self._EventOnDeadOrCrash ) + if self.Filter.Zones then + self.ZoneTimer = TIMER:New(self._ContinousZoneFilter,self) + local timing = self.ZoneTimerInterval or 30 + self.ZoneTimer:Start(timing,timing) + end end return self