SET_GROUP is working!

This commit is contained in:
FlightControl 2016-06-07 12:23:24 +02:00
parent afb71ecd26
commit 92e9f57b66
22 changed files with 194 additions and 69 deletions

View File

@ -121,7 +121,7 @@ function SCHEDULER:_Scheduler()
self:T( { Status, Result } )
if Status and ( ( not Result ) or ( Result and Result ~= false ) ) then
if Status and ( ( not Result == nil ) or ( Result and Result ~= false ) ) then
if self.Repeat and ( not self.StopSeconds or ( self.StopSeconds and timer.getTime() <= self.StartTime + self.StopSeconds ) ) then
timer.scheduleFunction(
self._Scheduler,

View File

@ -275,20 +275,22 @@ end
-- end
--end
--- Iterators
-- Iterators
--- Interate the SET_BASE and call an interator function for the given set, providing the Object for each element within the set and optional parameters.
-- @param #SET_BASE self
-- @param #function IteratorFunction The function that will be called when there is an alive player in the SET_BASE.
-- @return #SET_BASE self
function SET_BASE:ForEach( IteratorFunction, arg, Set )
function SET_BASE:ForEach( IteratorFunction, arg, Set, Function, FunctionArguments )
self:F3( arg )
local function CoRoutine()
local Count = 0
for ObjectID, Object in pairs( Set ) do
self:T2( Object )
IteratorFunction( Object, unpack( arg ) )
if Function( unpack( FunctionArguments ), Object ) == true then
IteratorFunction( Object, unpack( arg ) )
end
Count = Count + 1
if Count % 10 == 0 then
coroutine.yield( false )
@ -314,7 +316,7 @@ function SET_BASE:ForEach( IteratorFunction, arg, Set )
return false
end
local Scheduler = SCHEDULER:New( self, Schedule, {}, 0.001, 30, 0 )
local Scheduler = SCHEDULER:New( self, Schedule, {}, 0.001, 0.001, 0 )
return self
end
@ -556,7 +558,7 @@ function SET_GROUP:FindInDatabase( Event )
return Event.IniDCSGroupName, self.Database[Event.IniDCSGroupName]
end
--- Interate the SET_GROUP and call an interator function for each **alive** GROUP, providing the GROUP and optional parameters.
--- Iterate the SET_GROUP and call an iterator function for each **alive** GROUP, providing the GROUP and optional parameters.
-- @param #SET_GROUP self
-- @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
@ -568,6 +570,72 @@ function SET_GROUP:ForEachGroup( IteratorFunction, ... )
return self
end
--- Iterate the SET_GROUP and call an iterator function for each **alive** GROUP presence completely in a @{Zone}, providing the GROUP and optional parameters to the called function.
-- @param #SET_GROUP self
-- @param 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:ForEachGroupCompletelyInZone( ZoneObject, IteratorFunction, ... )
self:F2( arg )
self:ForEach( IteratorFunction, arg, self.Set,
--- @param Zone#ZONE_BASE ZoneObject
-- @param Group#GROUP GroupObject
function( ZoneObject, GroupObject )
if GroupObject:IsCompletelyInZone( ZoneObject ) then
return true
else
return false
end
end, { ZoneObject } )
return self
end
--- Iterate the SET_GROUP and call an iterator function for each **alive** GROUP presence partly in a @{Zone}, providing the GROUP and optional parameters to the called function.
-- @param #SET_GROUP self
-- @param 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:ForEachGroupPartlyInZone( ZoneObject, IteratorFunction, ... )
self:F2( arg )
self:ForEach( IteratorFunction, arg, self.Set,
--- @param Zone#ZONE_BASE ZoneObject
-- @param Group#GROUP GroupObject
function( ZoneObject, GroupObject )
if GroupObject:IsPartlyInZone( ZoneObject ) then
return true
else
return false
end
end, { ZoneObject } )
return self
end
--- Iterate the SET_GROUP and call an iterator function for each **alive** GROUP presence not in a @{Zone}, providing the GROUP and optional parameters to the called function.
-- @param #SET_GROUP self
-- @param 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:ForEachGroupNotInZone( ZoneObject, IteratorFunction, ... )
self:F2( arg )
self:ForEach( IteratorFunction, arg, self.Set,
--- @param Zone#ZONE_BASE ZoneObject
-- @param Group#GROUP GroupObject
function( ZoneObject, GroupObject )
if GroupObject:IsNotInZone( ZoneObject ) then
return true
else
return false
end
end, { ZoneObject } )
return self
end
----- Interate the SET_GROUP and call an interator function for each **alive** player, providing the Group of the player and optional parameters.
---- @param #SET_GROUP self

View File

@ -1,5 +1,5 @@
env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20160606_2213' )
env.info( 'Moose Generation Timestamp: 20160607_0904' )
local base = _G
env.info("Loading MOOSE " .. base.timer.getAbsTime() )

View File

@ -1,5 +1,5 @@
env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20160606_2213' )
env.info( 'Moose Generation Timestamp: 20160607_0904' )
local base = _G
env.info("Loading MOOSE " .. base.timer.getAbsTime() )

View File

@ -38,6 +38,26 @@ for i = 1, 30 do
GroupSAM_AttackVehicle = SpawnSAM_AttackVehicle:SpawnInZone( ZONE:New("Spawn Zone"), true)
end
SetVehicleCompletely = SET_GROUP:New()
:FilterPrefixes( "Spawn Vehicle Zone Completely" )
:FilterStart()
SetVehiclePartly = SET_GROUP:New()
:FilterPrefixes( "Spawn Vehicle Zone Partly" )
:FilterStart()
SetVehicleNot = SET_GROUP:New()
:FilterPrefixes( "Spawn Vehicle Zone Not" )
:FilterStart()
Spawn_Vehicle_Zone_Completely = SPAWN:New( 'Spawn Vehicle Zone Completely' )
Spawn_Vehicle_Zone_Partly = SPAWN:New( 'Spawn Vehicle Zone Partly' )
Spawn_Vehicle_Zone_Not = SPAWN:New( 'Spawn Vehicle Zone Not' )
for i = 1, 30 do
Spawn_Vehicle_Zone_Completely:SpawnInZone( ZONE:New("Spawn Zone Completely"), true)
Spawn_Vehicle_Zone_Partly:SpawnInZone( ZONE:New("Spawn Zone Partly"), true)
Spawn_Vehicle_Zone_Not:SpawnInZone( ZONE:New("Spawn Zone Not"), true)
end
--DBBlue:TraceDatabase()
--SCHEDULER:New( DBBluePlanes, DBBluePlanes.Flush, { }, 1 )
@ -79,5 +99,42 @@ SetSAMGroup:ForEachGroup(
end
end
)
GroupZoneCompletely = GROUP:FindByName( "Zone Completely" )
GroupZonePartly = GROUP:FindByName( "Zone Partly" )
GroupZoneNot = GROUP:FindByName( "Zone Not" )
ZoneCompletely = ZONE_POLYGON:New( "Zone Completely", GroupZoneCompletely ):SmokeZone( POINT_VEC3.SmokeColor.White )
ZonePartly = ZONE_POLYGON:New( "Zone Partly", GroupZonePartly ):SmokeZone( POINT_VEC3.SmokeColor.White )
ZoneNot = ZONE_POLYGON:New( "Zone Not", GroupZoneNot ):SmokeZone( POINT_VEC3.SmokeColor.White )
SetVehicleCompletely:ForEachGroupCompletelyInZone( ZoneCompletely,
--- @param Group#GROUP MooseGroup
function( MooseGroup )
for UnitId, UnitData in pairs( MooseGroup:GetUnits() ) do
local UnitAction = UnitData -- Unit#UNIT
UnitAction:SmokeBlue()
end
end
)
SetVehiclePartly:ForEachGroupPartlyInZone( ZonePartly,
--- @param Group#GROUP MooseGroup
function( MooseGroup )
for UnitId, UnitData in pairs( MooseGroup:GetUnits() ) do
local UnitAction = UnitData -- Unit#UNIT
UnitAction:SmokeBlue()
end
end
)
SetVehicleNot:ForEachGroupNotInZone( ZoneNot,
--- @param Group#GROUP MooseGroup
function( MooseGroup )
for UnitId, UnitData in pairs( MooseGroup:GetUnits() ) do
local UnitAction = UnitData -- Unit#UNIT
UnitAction:SmokeBlue()
end
end
)

View File

@ -200,7 +200,7 @@ The following iterator methods are currently available within the SET</em>UNIT:<
<h2>Global(s)</h2>
<table class="function_list">
<tr>
<td class="name" nowrap="nowrap"><a href="#SET">SET</a></td>
<td class="name" nowrap="nowrap"><a href="#SET_BASE">SET_BASE</a></td>
<td class="summary">
</td>
@ -218,76 +218,76 @@ The following iterator methods are currently available within the SET</em>UNIT:<
</td>
</tr>
</table>
<h2><a id="#(SET)">Type <code>SET</code></a></h2>
<h2><a id="#(SET_BASE)">Type <code>SET_BASE</code></a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap="nowrap"><a href="##(SET).ClassName">SET.ClassName</a></td>
<td class="name" nowrap="nowrap"><a href="##(SET_BASE).ClassName">SET_BASE.ClassName</a></td>
<td class="summary">
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(SET).Database">SET.Database</a></td>
<td class="name" nowrap="nowrap"><a href="##(SET_BASE).Database">SET_BASE.Database</a></td>
<td class="summary">
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(SET).Flush">SET:Flush()</a></td>
<td class="name" nowrap="nowrap"><a href="##(SET_BASE).Flush">SET_BASE:Flush()</a></td>
<td class="summary">
<p>Flushes the current SET contents in the log ...</p>
<p>Flushes the current SET_BASE contents in the log ...</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(SET).ForEach">SET:ForEach(IteratorFunction, arg, Set)</a></td>
<td class="name" nowrap="nowrap"><a href="##(SET_BASE).ForEach">SET_BASE:ForEach(IteratorFunction, arg, Set)</a></td>
<td class="summary">
<p>Interate the SET and call an interator function for the given set, providing the Object for each element within the set and optional parameters.</p>
<p>Interate the SET_BASE and call an interator function for the given set, providing the Object for each element within the set and optional parameters.</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(SET).IsIncludeObject">SET:IsIncludeObject(Object)</a></td>
<td class="name" nowrap="nowrap"><a href="##(SET_BASE).IsIncludeObject">SET_BASE:IsIncludeObject(Object)</a></td>
<td class="summary">
<p>Decides whether to include the Object</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(SET).New">SET:New(Database)</a></td>
<td class="name" nowrap="nowrap"><a href="##(SET_BASE).New">SET_BASE:New(Database)</a></td>
<td class="summary">
<p>Creates a new SET object, building a set of units belonging to a coalitions, categories, countries, types or with defined prefix names.</p>
<p>Creates a new SET_BASE object, building a set of units belonging to a coalitions, categories, countries, types or with defined prefix names.</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(SET).Set">SET.Set</a></td>
<td class="name" nowrap="nowrap"><a href="##(SET_BASE).Set">SET_BASE.Set</a></td>
<td class="summary">
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(SET)._Add">SET:_Add(ObjectName, Object)</a></td>
<td class="name" nowrap="nowrap"><a href="##(SET_BASE)._Add">SET_BASE:_Add(ObjectName, Object)</a></td>
<td class="summary">
<p>Adds a Object based on the Object Name.</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(SET)._EventOnBirth">SET:_EventOnBirth(Event)</a></td>
<td class="name" nowrap="nowrap"><a href="##(SET_BASE)._EventOnBirth">SET_BASE:_EventOnBirth(Event)</a></td>
<td class="summary">
<p>Handles the OnBirth event for the Set.</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(SET)._EventOnDeadOrCrash">SET:_EventOnDeadOrCrash(Event)</a></td>
<td class="name" nowrap="nowrap"><a href="##(SET_BASE)._EventOnDeadOrCrash">SET_BASE:_EventOnDeadOrCrash(Event)</a></td>
<td class="summary">
<p>Handles the OnDead or OnCrash event for alive units set.</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(SET)._FilterStart">SET:_FilterStart()</a></td>
<td class="name" nowrap="nowrap"><a href="##(SET_BASE)._FilterStart">SET_BASE:_FilterStart()</a></td>
<td class="summary">
<p>Starts the filtering for the defined collection.</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(SET)._Find">SET:_Find(ObjectName)</a></td>
<td class="name" nowrap="nowrap"><a href="##(SET_BASE)._Find">SET_BASE:_Find(ObjectName)</a></td>
<td class="summary">
<p>Finds an Object based on the Object Name.</p>
</td>
@ -486,9 +486,9 @@ The following iterator methods are currently available within the SET</em>UNIT:<
<dl class="function">
<dt>
<em><a href="##(SET)">#SET</a></em>
<a id="SET" >
<strong>SET</strong>
<em><a href="##(SET_BASE)">#SET_BASE</a></em>
<a id="SET_BASE" >
<strong>SET_BASE</strong>
</a>
</dt>
<dd>
@ -527,17 +527,17 @@ The following iterator methods are currently available within the SET</em>UNIT:<
</dl>
<h2><a id="#(Set)" >Type <code>Set</code></a></h2>
<h2><a id="#(SET)" >Type <code>SET</code></a></h2>
<h2><a id="#(SET_BASE)" >Type <code>SET_BASE</code></a></h2>
<p>SET class</p>
<p>SET_BASE class</p>
<h3>Field(s)</h3>
<dl class="function">
<dt>
<em>#string</em>
<a id="#(SET).ClassName" >
<strong>SET.ClassName</strong>
<a id="#(SET_BASE).ClassName" >
<strong>SET_BASE.ClassName</strong>
</a>
</dt>
<dd>
@ -550,8 +550,8 @@ The following iterator methods are currently available within the SET</em>UNIT:<
<dt>
<em></em>
<a id="#(SET).Database" >
<strong>SET.Database</strong>
<a id="#(SET_BASE).Database" >
<strong>SET_BASE.Database</strong>
</a>
</dt>
<dd>
@ -563,13 +563,13 @@ The following iterator methods are currently available within the SET</em>UNIT:<
<dl class="function">
<dt>
<a id="#(SET).Flush" >
<strong>SET:Flush()</strong>
<a id="#(SET_BASE).Flush" >
<strong>SET_BASE:Flush()</strong>
</a>
</dt>
<dd>
<p>Flushes the current SET contents in the log ...</p>
<p>Flushes the current SET_BASE contents in the log ...</p>
<p>(for debug reasons).</p>
@ -584,20 +584,20 @@ A string with the names of the objects.</p>
<dl class="function">
<dt>
<a id="#(SET).ForEach" >
<strong>SET:ForEach(IteratorFunction, arg, Set)</strong>
<a id="#(SET_BASE).ForEach" >
<strong>SET_BASE:ForEach(IteratorFunction, arg, Set)</strong>
</a>
</dt>
<dd>
<p>Interate the SET and call an interator function for the given set, providing the Object for each element within the set and optional parameters.</p>
<p>Interate the SET_BASE and call an interator function for the given set, providing the Object for each element within the set and optional parameters.</p>
<h3>Parameters</h3>
<ul>
<li>
<p><code><em>#function IteratorFunction </em></code>:
The function that will be called when there is an alive player in the SET.</p>
The function that will be called when there is an alive player in the SET_BASE.</p>
</li>
<li>
@ -613,7 +613,7 @@ The function that will be called when there is an alive player in the SET.</p>
</ul>
<h3>Return value</h3>
<p><em><a href="##(SET)">#SET</a>:</em>
<p><em><a href="##(SET_BASE)">#SET_BASE</a>:</em>
self</p>
</dd>
@ -621,8 +621,8 @@ self</p>
<dl class="function">
<dt>
<a id="#(SET).IsIncludeObject" >
<strong>SET:IsIncludeObject(Object)</strong>
<a id="#(SET_BASE).IsIncludeObject" >
<strong>SET_BASE:IsIncludeObject(Object)</strong>
</a>
</dt>
<dd>
@ -639,7 +639,7 @@ self</p>
</ul>
<h3>Return value</h3>
<p><em><a href="##(SET)">#SET</a>:</em>
<p><em><a href="##(SET_BASE)">#SET_BASE</a>:</em>
self</p>
</dd>
@ -647,13 +647,13 @@ self</p>
<dl class="function">
<dt>
<a id="#(SET).New" >
<strong>SET:New(Database)</strong>
<a id="#(SET_BASE).New" >
<strong>SET_BASE:New(Database)</strong>
</a>
</dt>
<dd>
<p>Creates a new SET object, building a set of units belonging to a coalitions, categories, countries, types or with defined prefix names.</p>
<p>Creates a new SET_BASE object, building a set of units belonging to a coalitions, categories, countries, types or with defined prefix names.</p>
<h3>Parameter</h3>
<ul>
@ -665,12 +665,12 @@ self</p>
</ul>
<h3>Return value</h3>
<p><em><a href="##(SET)">#SET</a>:</em></p>
<p><em><a href="##(SET_BASE)">#SET_BASE</a>:</em></p>
<h3>Usage:</h3>
<pre class="example"><code>-- Define a new SET Object. This DBObject will contain a reference to all Group and Unit Templates defined within the ME and the DCSRTE.
DBObject = SET:New()</code></pre>
<pre class="example"><code>-- Define a new SET_BASE Object. This DBObject will contain a reference to all Group and Unit Templates defined within the ME and the DCSRTE.
DBObject = SET_BASE:New()</code></pre>
</dd>
</dl>
@ -678,8 +678,8 @@ DBObject = SET:New()</code></pre>
<dt>
<em></em>
<a id="#(SET).Set" >
<strong>SET.Set</strong>
<a id="#(SET_BASE).Set" >
<strong>SET_BASE.Set</strong>
</a>
</dt>
<dd>
@ -691,8 +691,8 @@ DBObject = SET:New()</code></pre>
<dl class="function">
<dt>
<a id="#(SET)._Add" >
<strong>SET:_Add(ObjectName, Object)</strong>
<a id="#(SET_BASE)._Add" >
<strong>SET_BASE:_Add(ObjectName, Object)</strong>
</a>
</dt>
<dd>
@ -722,8 +722,8 @@ The added Object.</p>
<dl class="function">
<dt>
<a id="#(SET)._EventOnBirth" >
<strong>SET:_EventOnBirth(Event)</strong>
<a id="#(SET_BASE)._EventOnBirth" >
<strong>SET_BASE:_EventOnBirth(Event)</strong>
</a>
</dt>
<dd>
@ -743,8 +743,8 @@ The added Object.</p>
<dl class="function">
<dt>
<a id="#(SET)._EventOnDeadOrCrash" >
<strong>SET:_EventOnDeadOrCrash(Event)</strong>
<a id="#(SET_BASE)._EventOnDeadOrCrash" >
<strong>SET_BASE:_EventOnDeadOrCrash(Event)</strong>
</a>
</dt>
<dd>
@ -764,8 +764,8 @@ The added Object.</p>
<dl class="function">
<dt>
<a id="#(SET)._FilterStart" >
<strong>SET:_FilterStart()</strong>
<a id="#(SET_BASE)._FilterStart" >
<strong>SET_BASE:_FilterStart()</strong>
</a>
</dt>
<dd>
@ -774,7 +774,7 @@ The added Object.</p>
<h3>Return value</h3>
<p><em><a href="##(SET)">#SET</a>:</em>
<p><em><a href="##(SET_BASE)">#SET_BASE</a>:</em>
self</p>
</dd>
@ -782,8 +782,8 @@ self</p>
<dl class="function">
<dt>
<a id="#(SET)._Find" >
<strong>SET:_Find(ObjectName)</strong>
<a id="#(SET_BASE)._Find" >
<strong>SET_BASE:_Find(ObjectName)</strong>
</a>
</dt>
<dd>
@ -823,7 +823,7 @@ The Object found.</p>
<p>Handles the Database to check on an event (birth) that the Object was added in the Database.</p>
<p>This is required, because sometimes the _DATABASE birth event gets called later than the SET birth event!</p>
<p>This is required, because sometimes the <em>DATABASE birth event gets called later than the SET</em>BASE birth event!</p>
<h3>Parameter</h3>
<ul>
@ -1068,7 +1068,7 @@ The found Group.</p>
<p>Handles the Database to check on any event that Object exists in the Database.</p>
<p>This is required, because sometimes the _DATABASE event gets called later than the SET event or vise versa!</p>
<p>This is required, because sometimes the <em>DATABASE event gets called later than the SET</em>BASE event or vise versa!</p>
<h3>Parameter</h3>
<ul>
@ -1193,7 +1193,7 @@ DBObject = SET_GROUP:New()</code></pre>
<p>Handles the Database to check on an event (birth) that the Object was added in the Database.</p>
<p>This is required, because sometimes the _DATABASE birth event gets called later than the SET birth event!</p>
<p>This is required, because sometimes the <em>DATABASE birth event gets called later than the SET</em>BASE birth event!</p>
<h3>Parameter</h3>
<ul>
@ -1442,7 +1442,7 @@ self</p>
<p>Handles the Database to check on any event that Object exists in the Database.</p>
<p>This is required, because sometimes the _DATABASE event gets called later than the SET event or vise versa!</p>
<p>This is required, because sometimes the <em>DATABASE event gets called later than the SET</em>BASE event or vise versa!</p>
<h3>Parameter</h3>
<ul>