Finalized the AIBALANCER class + PATROLZONE class

This commit is contained in:
FlightControl 2016-06-19 15:03:50 +02:00
parent ffbc4a838e
commit e0b32fe5d5
32 changed files with 154 additions and 100 deletions

View File

@ -52,6 +52,8 @@
-- @extends Base#BASE
AIBALANCER = {
ClassName = "AIBALANCER",
PatrolZones = {},
AIGroups = {},
}
--- Creates a new AIBALANCER object, building a set of units belonging to a coalitions, categories, countries, types or with defined prefix names.
@ -135,13 +137,13 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
if ClientAIAliveState == true then
Client:SetState( self, 'AIAlive', false )
local AIGroup = Client:GetState( self, 'AIGroup' ) -- Group#GROUP
local AIGroup = self.AIGroups[Client.UnitName] -- Group#GROUP
local PatrolZone = Client:GetState( self, "PatrolZone" )
if PatrolZone then
PatrolZone = nil
Client:ClearState( self, "PatrolZone" )
end
-- local PatrolZone = Client:GetState( self, "PatrolZone" )
-- if PatrolZone then
-- PatrolZone = nil
-- Client:ClearState( self, "PatrolZone" )
-- end
if self.ToNearestAirbase == false and self.ToHomeAirbase == false then
AIGroup:Destroy()
@ -200,15 +202,18 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
if not ClientAIAliveState or ClientAIAliveState == false then
Client:SetState( self, 'AIAlive', true )
-- OK, spawn a new group from the SpawnAI objects provided.
local SpawnAICount = #self.SpawnAI
local SpawnAIIndex = math.random( 1, SpawnAICount )
local AIGroup = self.SpawnAI[SpawnAIIndex]:Spawn()
Client:SetState( self, 'AIGroup', AIGroup )
AIGroup:E( "spawning new AIGroup" )
--TODO: need to rework UnitName thing ...
self.AIGroups[Client.UnitName] = AIGroup
--- Now test if the AIGroup needs to patrol a zone, otherwise let it follow its route...
if self.PatrolZone then
local PatrolZone = PATROLZONE:New(
self.PatrolZones[#self.PatrolZones+1] = PATROLZONE:New(
self.PatrolZone.PatrolZone,
self.PatrolZone.PatrolFloorAltitude,
self.PatrolZone.PatrolCeilingAltitude,
@ -217,12 +222,13 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
)
if self.PatrolZone.PatrolManageFuel == true then
PatrolZone:ManageFuel( self.PatrolZone.PatrolFuelTresholdPercentage, self.PatrolZone.PatrolOutOfFuelOrbitTime )
self.PatrolZones[#self.PatrolZones]:ManageFuel( self.PatrolZone.PatrolFuelTresholdPercentage, self.PatrolZone.PatrolOutOfFuelOrbitTime )
end
self.PatrolZones[#self.PatrolZones]:SetGroup( AIGroup )
PatrolZone:SetGroup( AIGroup )
Client:SetState( self, "PatrolZone", PatrolZone )
--self.PatrolZones[#self.PatrolZones+1] = PatrolZone
--Client:SetState( self, "PatrolZone", PatrolZone )
end
end
end

View File

@ -585,18 +585,20 @@ function DATABASE:ForEach( IteratorFunction, FinalizeFunction, arg, Set )
self:T2( Object )
IteratorFunction( Object, unpack( arg ) )
Count = Count + 1
if Count % 10 == 0 then
coroutine.yield( false )
end
-- if Count % 100 == 0 then
-- coroutine.yield( false )
-- end
end
return true
end
local co = coroutine.create( CoRoutine )
-- local co = coroutine.create( CoRoutine )
local co = CoRoutine
local function Schedule()
local status, res = coroutine.resume( co )
-- local status, res = coroutine.resume( co )
local status, res = co()
self:T3( { status, res } )
if status == false then

View File

@ -83,7 +83,7 @@ function PATROLZONE:SetGroup( PatrolGroup )
self:NewPatrolRoute()
if not self.PatrolOutOfFuelMonitor then
self.PatrolOutOfFuelMonitor = SCHEDULER:New( self, self._MonitorOutOfFuelScheduled, {}, 60, 120, 0.2 )
self.PatrolOutOfFuelMonitor = SCHEDULER:New( nil, _MonitorOutOfFuelScheduled, { self }, 1, 120, 0 )
self.SpawnPatrolGroup = SPAWN:New( self.PatrolGroupTemplateName )
end
@ -209,7 +209,7 @@ function PATROLZONE:NewPatrolRoute()
--- Now we're going to do something special, we're going to call a function from a waypoint action at the PatrolGroup...
self.PatrolGroup:WayPointInitialize( PatrolRoute )
--- Do a trick, link the NewPatrolRoute function of the PATROLGROUP object to the PatrolGroupin a temporary variable ...
--- Do a trick, link the NewPatrolRoute function of the PATROLGROUP object to the PatrolGroup in a temporary variable ...
self.PatrolGroup:SetState( self.PatrolGroup, "PatrolZone", self )
self.PatrolGroup:WayPointFunction( #PatrolRoute, 1, "_NewPatrolRoute" )
@ -234,14 +234,15 @@ function PATROLZONE:ManageFuel( PatrolFuelTresholdPercentage, PatrolOutOfFuelOrb
self.PatrolOutOfFuelOrbitTime = PatrolOutOfFuelOrbitTime
if self.PatrolGroup then
self.PatrolOutOfFuelMonitor = SCHEDULER:New( self, self._MonitorOutOfFuelScheduled, {}, 60, 120, 0.2 )
self.PatrolOutOfFuelMonitor = SCHEDULER:New( self, self._MonitorOutOfFuelScheduled, {}, 1, 120, 0 )
self.SpawnPatrolGroup = SPAWN:New( self.PatrolGroupTemplateName )
end
return self
end
--- @param #PATROLZONE self
function PATROLZONE:_MonitorOutOfFuelScheduled()
function _MonitorOutOfFuelScheduled( self )
self:F2( "_MonitorOutOfFuelScheduled" )
if self.PatrolGroup and self.PatrolGroup:IsAlive() then

View File

@ -455,18 +455,20 @@ function SET_BASE:ForEach( IteratorFunction, arg, Set, Function, FunctionArgumen
IteratorFunction( Object, unpack( arg ) )
end
Count = Count + 1
if Count % self.YieldInterval == 0 then
coroutine.yield( false )
end
-- if Count % self.YieldInterval == 0 then
-- coroutine.yield( false )
-- end
end
return true
end
local co = coroutine.create( CoRoutine )
-- local co = coroutine.create( CoRoutine )
local co = CoRoutine
local function Schedule()
local status, res = coroutine.resume( co )
-- local status, res = coroutine.resume( co )
local status, res = co()
self:T3( { status, res } )
if status == false then

View File

@ -1,5 +1,5 @@
env.info( '*** MOOSE STATIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20160618_2312' )
env.info( 'Moose Generation Timestamp: 20160619_1502' )
local base = _G
Include = {}
@ -9972,18 +9972,20 @@ function DATABASE:ForEach( IteratorFunction, FinalizeFunction, arg, Set )
self:T2( Object )
IteratorFunction( Object, unpack( arg ) )
Count = Count + 1
if Count % 10 == 0 then
coroutine.yield( false )
end
-- if Count % 100 == 0 then
-- coroutine.yield( false )
-- end
end
return true
end
local co = coroutine.create( CoRoutine )
-- local co = coroutine.create( CoRoutine )
local co = CoRoutine
local function Schedule()
local status, res = coroutine.resume( co )
-- local status, res = coroutine.resume( co )
local status, res = co()
self:T3( { status, res } )
if status == false then
@ -10610,18 +10612,20 @@ function SET_BASE:ForEach( IteratorFunction, arg, Set, Function, FunctionArgumen
IteratorFunction( Object, unpack( arg ) )
end
Count = Count + 1
if Count % self.YieldInterval == 0 then
coroutine.yield( false )
end
-- if Count % self.YieldInterval == 0 then
-- coroutine.yield( false )
-- end
end
return true
end
local co = coroutine.create( CoRoutine )
-- local co = coroutine.create( CoRoutine )
local co = CoRoutine
local function Schedule()
local status, res = coroutine.resume( co )
-- local status, res = coroutine.resume( co )
local status, res = co()
self:T3( { status, res } )
if status == false then
@ -21201,7 +21205,7 @@ function PATROLZONE:SetGroup( PatrolGroup )
self:NewPatrolRoute()
if not self.PatrolOutOfFuelMonitor then
self.PatrolOutOfFuelMonitor = SCHEDULER:New( self, self._MonitorOutOfFuelScheduled, {}, 60, 120, 0.2 )
self.PatrolOutOfFuelMonitor = SCHEDULER:New( nil, _MonitorOutOfFuelScheduled, { self }, 1, 120, 0 )
self.SpawnPatrolGroup = SPAWN:New( self.PatrolGroupTemplateName )
end
@ -21327,7 +21331,7 @@ function PATROLZONE:NewPatrolRoute()
--- Now we're going to do something special, we're going to call a function from a waypoint action at the PatrolGroup...
self.PatrolGroup:WayPointInitialize( PatrolRoute )
--- Do a trick, link the NewPatrolRoute function of the PATROLGROUP object to the PatrolGroupin a temporary variable ...
--- Do a trick, link the NewPatrolRoute function of the PATROLGROUP object to the PatrolGroup in a temporary variable ...
self.PatrolGroup:SetState( self.PatrolGroup, "PatrolZone", self )
self.PatrolGroup:WayPointFunction( #PatrolRoute, 1, "_NewPatrolRoute" )
@ -21352,14 +21356,15 @@ function PATROLZONE:ManageFuel( PatrolFuelTresholdPercentage, PatrolOutOfFuelOrb
self.PatrolOutOfFuelOrbitTime = PatrolOutOfFuelOrbitTime
if self.PatrolGroup then
self.PatrolOutOfFuelMonitor = SCHEDULER:New( self, self._MonitorOutOfFuelScheduled, {}, 60, 120, 0.2 )
self.PatrolOutOfFuelMonitor = SCHEDULER:New( self, self._MonitorOutOfFuelScheduled, {}, 1, 120, 0 )
self.SpawnPatrolGroup = SPAWN:New( self.PatrolGroupTemplateName )
end
return self
end
--- @param #PATROLZONE self
function PATROLZONE:_MonitorOutOfFuelScheduled()
function _MonitorOutOfFuelScheduled( self )
self:F2( "_MonitorOutOfFuelScheduled" )
if self.PatrolGroup and self.PatrolGroup:IsAlive() then
@ -21433,6 +21438,8 @@ end--- This module contains the AIBALANCER class.
-- @extends Base#BASE
AIBALANCER = {
ClassName = "AIBALANCER",
PatrolZones = {},
AIGroups = {},
}
--- Creates a new AIBALANCER object, building a set of units belonging to a coalitions, categories, countries, types or with defined prefix names.
@ -21516,13 +21523,13 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
if ClientAIAliveState == true then
Client:SetState( self, 'AIAlive', false )
local AIGroup = Client:GetState( self, 'AIGroup' ) -- Group#GROUP
local AIGroup = self.AIGroups[Client.UnitName] -- Group#GROUP
local PatrolZone = Client:GetState( self, "PatrolZone" )
if PatrolZone then
PatrolZone = nil
Client:ClearState( self, "PatrolZone" )
end
-- local PatrolZone = Client:GetState( self, "PatrolZone" )
-- if PatrolZone then
-- PatrolZone = nil
-- Client:ClearState( self, "PatrolZone" )
-- end
if self.ToNearestAirbase == false and self.ToHomeAirbase == false then
AIGroup:Destroy()
@ -21581,15 +21588,18 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
if not ClientAIAliveState or ClientAIAliveState == false then
Client:SetState( self, 'AIAlive', true )
-- OK, spawn a new group from the SpawnAI objects provided.
local SpawnAICount = #self.SpawnAI
local SpawnAIIndex = math.random( 1, SpawnAICount )
local AIGroup = self.SpawnAI[SpawnAIIndex]:Spawn()
Client:SetState( self, 'AIGroup', AIGroup )
AIGroup:E( "spawning new AIGroup" )
--TODO: need to rework UnitName thing ...
self.AIGroups[Client.UnitName] = AIGroup
--- Now test if the AIGroup needs to patrol a zone, otherwise let it follow its route...
if self.PatrolZone then
local PatrolZone = PATROLZONE:New(
self.PatrolZones[#self.PatrolZones+1] = PATROLZONE:New(
self.PatrolZone.PatrolZone,
self.PatrolZone.PatrolFloorAltitude,
self.PatrolZone.PatrolCeilingAltitude,
@ -21598,12 +21608,13 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
)
if self.PatrolZone.PatrolManageFuel == true then
PatrolZone:ManageFuel( self.PatrolZone.PatrolFuelTresholdPercentage, self.PatrolZone.PatrolOutOfFuelOrbitTime )
self.PatrolZones[#self.PatrolZones]:ManageFuel( self.PatrolZone.PatrolFuelTresholdPercentage, self.PatrolZone.PatrolOutOfFuelOrbitTime )
end
self.PatrolZones[#self.PatrolZones]:SetGroup( AIGroup )
PatrolZone:SetGroup( AIGroup )
Client:SetState( self, "PatrolZone", PatrolZone )
--self.PatrolZones[#self.PatrolZones+1] = PatrolZone
--Client:SetState( self, "PatrolZone", PatrolZone )
end
end
end

View File

@ -1,5 +1,5 @@
env.info( '*** MOOSE STATIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20160618_2312' )
env.info( 'Moose Generation Timestamp: 20160619_1502' )
local base = _G
Include = {}
@ -9972,18 +9972,20 @@ function DATABASE:ForEach( IteratorFunction, FinalizeFunction, arg, Set )
self:T2( Object )
IteratorFunction( Object, unpack( arg ) )
Count = Count + 1
if Count % 10 == 0 then
coroutine.yield( false )
end
-- if Count % 100 == 0 then
-- coroutine.yield( false )
-- end
end
return true
end
local co = coroutine.create( CoRoutine )
-- local co = coroutine.create( CoRoutine )
local co = CoRoutine
local function Schedule()
local status, res = coroutine.resume( co )
-- local status, res = coroutine.resume( co )
local status, res = co()
self:T3( { status, res } )
if status == false then
@ -10610,18 +10612,20 @@ function SET_BASE:ForEach( IteratorFunction, arg, Set, Function, FunctionArgumen
IteratorFunction( Object, unpack( arg ) )
end
Count = Count + 1
if Count % self.YieldInterval == 0 then
coroutine.yield( false )
end
-- if Count % self.YieldInterval == 0 then
-- coroutine.yield( false )
-- end
end
return true
end
local co = coroutine.create( CoRoutine )
-- local co = coroutine.create( CoRoutine )
local co = CoRoutine
local function Schedule()
local status, res = coroutine.resume( co )
-- local status, res = coroutine.resume( co )
local status, res = co()
self:T3( { status, res } )
if status == false then
@ -21201,7 +21205,7 @@ function PATROLZONE:SetGroup( PatrolGroup )
self:NewPatrolRoute()
if not self.PatrolOutOfFuelMonitor then
self.PatrolOutOfFuelMonitor = SCHEDULER:New( self, self._MonitorOutOfFuelScheduled, {}, 60, 120, 0.2 )
self.PatrolOutOfFuelMonitor = SCHEDULER:New( nil, _MonitorOutOfFuelScheduled, { self }, 1, 120, 0 )
self.SpawnPatrolGroup = SPAWN:New( self.PatrolGroupTemplateName )
end
@ -21327,7 +21331,7 @@ function PATROLZONE:NewPatrolRoute()
--- Now we're going to do something special, we're going to call a function from a waypoint action at the PatrolGroup...
self.PatrolGroup:WayPointInitialize( PatrolRoute )
--- Do a trick, link the NewPatrolRoute function of the PATROLGROUP object to the PatrolGroupin a temporary variable ...
--- Do a trick, link the NewPatrolRoute function of the PATROLGROUP object to the PatrolGroup in a temporary variable ...
self.PatrolGroup:SetState( self.PatrolGroup, "PatrolZone", self )
self.PatrolGroup:WayPointFunction( #PatrolRoute, 1, "_NewPatrolRoute" )
@ -21352,14 +21356,15 @@ function PATROLZONE:ManageFuel( PatrolFuelTresholdPercentage, PatrolOutOfFuelOrb
self.PatrolOutOfFuelOrbitTime = PatrolOutOfFuelOrbitTime
if self.PatrolGroup then
self.PatrolOutOfFuelMonitor = SCHEDULER:New( self, self._MonitorOutOfFuelScheduled, {}, 60, 120, 0.2 )
self.PatrolOutOfFuelMonitor = SCHEDULER:New( self, self._MonitorOutOfFuelScheduled, {}, 1, 120, 0 )
self.SpawnPatrolGroup = SPAWN:New( self.PatrolGroupTemplateName )
end
return self
end
--- @param #PATROLZONE self
function PATROLZONE:_MonitorOutOfFuelScheduled()
function _MonitorOutOfFuelScheduled( self )
self:F2( "_MonitorOutOfFuelScheduled" )
if self.PatrolGroup and self.PatrolGroup:IsAlive() then
@ -21433,6 +21438,8 @@ end--- This module contains the AIBALANCER class.
-- @extends Base#BASE
AIBALANCER = {
ClassName = "AIBALANCER",
PatrolZones = {},
AIGroups = {},
}
--- Creates a new AIBALANCER object, building a set of units belonging to a coalitions, categories, countries, types or with defined prefix names.
@ -21516,13 +21523,13 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
if ClientAIAliveState == true then
Client:SetState( self, 'AIAlive', false )
local AIGroup = Client:GetState( self, 'AIGroup' ) -- Group#GROUP
local AIGroup = self.AIGroups[Client.UnitName] -- Group#GROUP
local PatrolZone = Client:GetState( self, "PatrolZone" )
if PatrolZone then
PatrolZone = nil
Client:ClearState( self, "PatrolZone" )
end
-- local PatrolZone = Client:GetState( self, "PatrolZone" )
-- if PatrolZone then
-- PatrolZone = nil
-- Client:ClearState( self, "PatrolZone" )
-- end
if self.ToNearestAirbase == false and self.ToHomeAirbase == false then
AIGroup:Destroy()
@ -21581,15 +21588,18 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
if not ClientAIAliveState or ClientAIAliveState == false then
Client:SetState( self, 'AIAlive', true )
-- OK, spawn a new group from the SpawnAI objects provided.
local SpawnAICount = #self.SpawnAI
local SpawnAIIndex = math.random( 1, SpawnAICount )
local AIGroup = self.SpawnAI[SpawnAIIndex]:Spawn()
Client:SetState( self, 'AIGroup', AIGroup )
AIGroup:E( "spawning new AIGroup" )
--TODO: need to rework UnitName thing ...
self.AIGroups[Client.UnitName] = AIGroup
--- Now test if the AIGroup needs to patrol a zone, otherwise let it follow its route...
if self.PatrolZone then
local PatrolZone = PATROLZONE:New(
self.PatrolZones[#self.PatrolZones+1] = PATROLZONE:New(
self.PatrolZone.PatrolZone,
self.PatrolZone.PatrolFloorAltitude,
self.PatrolZone.PatrolCeilingAltitude,
@ -21598,12 +21608,13 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
)
if self.PatrolZone.PatrolManageFuel == true then
PatrolZone:ManageFuel( self.PatrolZone.PatrolFuelTresholdPercentage, self.PatrolZone.PatrolOutOfFuelOrbitTime )
self.PatrolZones[#self.PatrolZones]:ManageFuel( self.PatrolZone.PatrolFuelTresholdPercentage, self.PatrolZone.PatrolOutOfFuelOrbitTime )
end
self.PatrolZones[#self.PatrolZones]:SetGroup( AIGroup )
PatrolZone:SetGroup( AIGroup )
Client:SetState( self, "PatrolZone", PatrolZone )
--self.PatrolZones[#self.PatrolZones+1] = PatrolZone
--Client:SetState( self, "PatrolZone", PatrolZone )
end
end
end

View File

@ -15,5 +15,5 @@ RU_AIBalancer:ReturnToNearestAirbases( 10000, RU_AirbasesSet )
local PatrolZoneGroup = GROUP:FindByName( "Patrol Zone" )
local PatrolZone = ZONE_POLYGON:New( "PatrolZone", PatrolZoneGroup )
local PatrolZone = PATROLZONE:New( PatrolZone, 3000, 6000, 300, 600 ):ManageFuel( 0.2, 60 )
local PatrolZone = PATROLZONE:New( PatrolZone, 3000, 6000, 300, 600 ):ManageFuel( 0.2, 180 )
RU_AIBalancer:SetPatrolZone( PatrolZone )

View File

@ -127,6 +127,12 @@ None of the script code has been used however within the new AIBALANCER moose cl
<h2><a id="#(AIBALANCER)">Type <code>AIBALANCER</code></a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap="nowrap"><a href="##(AIBALANCER).AIGroups">AIBALANCER.AIGroups</a></td>
<td class="summary">
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(AIBALANCER).ClassName">AIBALANCER.ClassName</a></td>
<td class="summary">
@ -142,6 +148,12 @@ None of the script code has been used however within the new AIBALANCER moose cl
<td class="name" nowrap="nowrap"><a href="##(AIBALANCER).PatrolZone">AIBALANCER.PatrolZone</a></td>
<td class="summary">
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(AIBALANCER).PatrolZones">AIBALANCER.PatrolZones</a></td>
<td class="summary">
</td>
</tr>
<tr>
@ -231,6 +243,20 @@ None of the script code has been used however within the new AIBALANCER moose cl
<dl class="function">
<dt>
<em></em>
<a id="#(AIBALANCER).AIGroups" >
<strong>AIBALANCER.AIGroups</strong>
</a>
</dt>
<dd>
</dd>
</dl>
<dl class="function">
<dt>
<em>#string</em>
<a id="#(AIBALANCER).ClassName" >
<strong>AIBALANCER.ClassName</strong>
@ -287,6 +313,20 @@ self</p>
</dd>
</dl>
<dl class="function">
<dt>
<em></em>
<a id="#(AIBALANCER).PatrolZones" >
<strong>AIBALANCER.PatrolZones</strong>
</a>
</dt>
<dd>
</dd>
</dl>
<dl class="function">

View File

@ -233,12 +233,6 @@ Use the method <a href="PatrolZone.html##(PATROLZONE).ManageFuel">PatrolZone#PAT
<td class="name" nowrap="nowrap"><a href="##(PATROLZONE).SpawnPatrolGroup">PATROLZONE.SpawnPatrolGroup</a></td>
<td class="summary">
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(PATROLZONE)._MonitorOutOfFuelScheduled">PATROLZONE:_MonitorOutOfFuelScheduled()</a></td>
<td class="summary">
</td>
</tr>
</table>
@ -675,19 +669,6 @@ self</p>
</dd>
</dl>
<dl class="function">
<dt>
<a id="#(PATROLZONE)._MonitorOutOfFuelScheduled" >
<strong>PATROLZONE:_MonitorOutOfFuelScheduled()</strong>
</a>
</dt>
<dd>
</dd>
</dl>