mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Finalized the AIBALANCER class + PATROLZONE class
This commit is contained in:
@@ -52,6 +52,8 @@
|
|||||||
-- @extends Base#BASE
|
-- @extends Base#BASE
|
||||||
AIBALANCER = {
|
AIBALANCER = {
|
||||||
ClassName = "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.
|
--- 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
|
if ClientAIAliveState == true then
|
||||||
Client:SetState( self, 'AIAlive', false )
|
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" )
|
-- local PatrolZone = Client:GetState( self, "PatrolZone" )
|
||||||
if PatrolZone then
|
-- if PatrolZone then
|
||||||
PatrolZone = nil
|
-- PatrolZone = nil
|
||||||
Client:ClearState( self, "PatrolZone" )
|
-- Client:ClearState( self, "PatrolZone" )
|
||||||
end
|
-- end
|
||||||
|
|
||||||
if self.ToNearestAirbase == false and self.ToHomeAirbase == false then
|
if self.ToNearestAirbase == false and self.ToHomeAirbase == false then
|
||||||
AIGroup:Destroy()
|
AIGroup:Destroy()
|
||||||
@@ -200,15 +202,18 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
|
|||||||
if not ClientAIAliveState or ClientAIAliveState == false then
|
if not ClientAIAliveState or ClientAIAliveState == false then
|
||||||
Client:SetState( self, 'AIAlive', true )
|
Client:SetState( self, 'AIAlive', true )
|
||||||
|
|
||||||
|
|
||||||
-- OK, spawn a new group from the SpawnAI objects provided.
|
-- OK, spawn a new group from the SpawnAI objects provided.
|
||||||
local SpawnAICount = #self.SpawnAI
|
local SpawnAICount = #self.SpawnAI
|
||||||
local SpawnAIIndex = math.random( 1, SpawnAICount )
|
local SpawnAIIndex = math.random( 1, SpawnAICount )
|
||||||
local AIGroup = self.SpawnAI[SpawnAIIndex]:Spawn()
|
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...
|
--- Now test if the AIGroup needs to patrol a zone, otherwise let it follow its route...
|
||||||
if self.PatrolZone then
|
if self.PatrolZone then
|
||||||
local PatrolZone = PATROLZONE:New(
|
self.PatrolZones[#self.PatrolZones+1] = PATROLZONE:New(
|
||||||
self.PatrolZone.PatrolZone,
|
self.PatrolZone.PatrolZone,
|
||||||
self.PatrolZone.PatrolFloorAltitude,
|
self.PatrolZone.PatrolFloorAltitude,
|
||||||
self.PatrolZone.PatrolCeilingAltitude,
|
self.PatrolZone.PatrolCeilingAltitude,
|
||||||
@@ -217,12 +222,13 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
|
|||||||
)
|
)
|
||||||
|
|
||||||
if self.PatrolZone.PatrolManageFuel == true then
|
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
|
end
|
||||||
|
self.PatrolZones[#self.PatrolZones]:SetGroup( AIGroup )
|
||||||
|
|
||||||
PatrolZone:SetGroup( AIGroup )
|
--self.PatrolZones[#self.PatrolZones+1] = PatrolZone
|
||||||
|
|
||||||
Client:SetState( self, "PatrolZone", PatrolZone )
|
--Client:SetState( self, "PatrolZone", PatrolZone )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -585,18 +585,20 @@ function DATABASE:ForEach( IteratorFunction, FinalizeFunction, arg, Set )
|
|||||||
self:T2( Object )
|
self:T2( Object )
|
||||||
IteratorFunction( Object, unpack( arg ) )
|
IteratorFunction( Object, unpack( arg ) )
|
||||||
Count = Count + 1
|
Count = Count + 1
|
||||||
if Count % 10 == 0 then
|
-- if Count % 100 == 0 then
|
||||||
coroutine.yield( false )
|
-- coroutine.yield( false )
|
||||||
end
|
-- end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local co = coroutine.create( CoRoutine )
|
-- local co = coroutine.create( CoRoutine )
|
||||||
|
local co = CoRoutine
|
||||||
|
|
||||||
local function Schedule()
|
local function Schedule()
|
||||||
|
|
||||||
local status, res = coroutine.resume( co )
|
-- local status, res = coroutine.resume( co )
|
||||||
|
local status, res = co()
|
||||||
self:T3( { status, res } )
|
self:T3( { status, res } )
|
||||||
|
|
||||||
if status == false then
|
if status == false then
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ function PATROLZONE:SetGroup( PatrolGroup )
|
|||||||
self:NewPatrolRoute()
|
self:NewPatrolRoute()
|
||||||
|
|
||||||
if not self.PatrolOutOfFuelMonitor then
|
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 )
|
self.SpawnPatrolGroup = SPAWN:New( self.PatrolGroupTemplateName )
|
||||||
end
|
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...
|
--- 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 )
|
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:SetState( self.PatrolGroup, "PatrolZone", self )
|
||||||
self.PatrolGroup:WayPointFunction( #PatrolRoute, 1, "_NewPatrolRoute" )
|
self.PatrolGroup:WayPointFunction( #PatrolRoute, 1, "_NewPatrolRoute" )
|
||||||
|
|
||||||
@@ -234,14 +234,15 @@ function PATROLZONE:ManageFuel( PatrolFuelTresholdPercentage, PatrolOutOfFuelOrb
|
|||||||
self.PatrolOutOfFuelOrbitTime = PatrolOutOfFuelOrbitTime
|
self.PatrolOutOfFuelOrbitTime = PatrolOutOfFuelOrbitTime
|
||||||
|
|
||||||
if self.PatrolGroup then
|
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 )
|
self.SpawnPatrolGroup = SPAWN:New( self.PatrolGroupTemplateName )
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param #PATROLZONE self
|
--- @param #PATROLZONE self
|
||||||
function PATROLZONE:_MonitorOutOfFuelScheduled()
|
function _MonitorOutOfFuelScheduled( self )
|
||||||
|
self:F2( "_MonitorOutOfFuelScheduled" )
|
||||||
|
|
||||||
if self.PatrolGroup and self.PatrolGroup:IsAlive() then
|
if self.PatrolGroup and self.PatrolGroup:IsAlive() then
|
||||||
|
|
||||||
|
|||||||
@@ -455,18 +455,20 @@ function SET_BASE:ForEach( IteratorFunction, arg, Set, Function, FunctionArgumen
|
|||||||
IteratorFunction( Object, unpack( arg ) )
|
IteratorFunction( Object, unpack( arg ) )
|
||||||
end
|
end
|
||||||
Count = Count + 1
|
Count = Count + 1
|
||||||
if Count % self.YieldInterval == 0 then
|
-- if Count % self.YieldInterval == 0 then
|
||||||
coroutine.yield( false )
|
-- coroutine.yield( false )
|
||||||
end
|
-- end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local co = coroutine.create( CoRoutine )
|
-- local co = coroutine.create( CoRoutine )
|
||||||
|
local co = CoRoutine
|
||||||
|
|
||||||
local function Schedule()
|
local function Schedule()
|
||||||
|
|
||||||
local status, res = coroutine.resume( co )
|
-- local status, res = coroutine.resume( co )
|
||||||
|
local status, res = co()
|
||||||
self:T3( { status, res } )
|
self:T3( { status, res } )
|
||||||
|
|
||||||
if status == false then
|
if status == false then
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
env.info( '*** MOOSE STATIC INCLUDE START *** ' )
|
env.info( '*** MOOSE STATIC INCLUDE START *** ' )
|
||||||
env.info( 'Moose Generation Timestamp: 20160618_2312' )
|
env.info( 'Moose Generation Timestamp: 20160619_1502' )
|
||||||
local base = _G
|
local base = _G
|
||||||
|
|
||||||
Include = {}
|
Include = {}
|
||||||
@@ -9972,18 +9972,20 @@ function DATABASE:ForEach( IteratorFunction, FinalizeFunction, arg, Set )
|
|||||||
self:T2( Object )
|
self:T2( Object )
|
||||||
IteratorFunction( Object, unpack( arg ) )
|
IteratorFunction( Object, unpack( arg ) )
|
||||||
Count = Count + 1
|
Count = Count + 1
|
||||||
if Count % 10 == 0 then
|
-- if Count % 100 == 0 then
|
||||||
coroutine.yield( false )
|
-- coroutine.yield( false )
|
||||||
end
|
-- end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local co = coroutine.create( CoRoutine )
|
-- local co = coroutine.create( CoRoutine )
|
||||||
|
local co = CoRoutine
|
||||||
|
|
||||||
local function Schedule()
|
local function Schedule()
|
||||||
|
|
||||||
local status, res = coroutine.resume( co )
|
-- local status, res = coroutine.resume( co )
|
||||||
|
local status, res = co()
|
||||||
self:T3( { status, res } )
|
self:T3( { status, res } )
|
||||||
|
|
||||||
if status == false then
|
if status == false then
|
||||||
@@ -10610,18 +10612,20 @@ function SET_BASE:ForEach( IteratorFunction, arg, Set, Function, FunctionArgumen
|
|||||||
IteratorFunction( Object, unpack( arg ) )
|
IteratorFunction( Object, unpack( arg ) )
|
||||||
end
|
end
|
||||||
Count = Count + 1
|
Count = Count + 1
|
||||||
if Count % self.YieldInterval == 0 then
|
-- if Count % self.YieldInterval == 0 then
|
||||||
coroutine.yield( false )
|
-- coroutine.yield( false )
|
||||||
end
|
-- end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local co = coroutine.create( CoRoutine )
|
-- local co = coroutine.create( CoRoutine )
|
||||||
|
local co = CoRoutine
|
||||||
|
|
||||||
local function Schedule()
|
local function Schedule()
|
||||||
|
|
||||||
local status, res = coroutine.resume( co )
|
-- local status, res = coroutine.resume( co )
|
||||||
|
local status, res = co()
|
||||||
self:T3( { status, res } )
|
self:T3( { status, res } )
|
||||||
|
|
||||||
if status == false then
|
if status == false then
|
||||||
@@ -21201,7 +21205,7 @@ function PATROLZONE:SetGroup( PatrolGroup )
|
|||||||
self:NewPatrolRoute()
|
self:NewPatrolRoute()
|
||||||
|
|
||||||
if not self.PatrolOutOfFuelMonitor then
|
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 )
|
self.SpawnPatrolGroup = SPAWN:New( self.PatrolGroupTemplateName )
|
||||||
end
|
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...
|
--- 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 )
|
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:SetState( self.PatrolGroup, "PatrolZone", self )
|
||||||
self.PatrolGroup:WayPointFunction( #PatrolRoute, 1, "_NewPatrolRoute" )
|
self.PatrolGroup:WayPointFunction( #PatrolRoute, 1, "_NewPatrolRoute" )
|
||||||
|
|
||||||
@@ -21352,14 +21356,15 @@ function PATROLZONE:ManageFuel( PatrolFuelTresholdPercentage, PatrolOutOfFuelOrb
|
|||||||
self.PatrolOutOfFuelOrbitTime = PatrolOutOfFuelOrbitTime
|
self.PatrolOutOfFuelOrbitTime = PatrolOutOfFuelOrbitTime
|
||||||
|
|
||||||
if self.PatrolGroup then
|
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 )
|
self.SpawnPatrolGroup = SPAWN:New( self.PatrolGroupTemplateName )
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param #PATROLZONE self
|
--- @param #PATROLZONE self
|
||||||
function PATROLZONE:_MonitorOutOfFuelScheduled()
|
function _MonitorOutOfFuelScheduled( self )
|
||||||
|
self:F2( "_MonitorOutOfFuelScheduled" )
|
||||||
|
|
||||||
if self.PatrolGroup and self.PatrolGroup:IsAlive() then
|
if self.PatrolGroup and self.PatrolGroup:IsAlive() then
|
||||||
|
|
||||||
@@ -21433,6 +21438,8 @@ end--- This module contains the AIBALANCER class.
|
|||||||
-- @extends Base#BASE
|
-- @extends Base#BASE
|
||||||
AIBALANCER = {
|
AIBALANCER = {
|
||||||
ClassName = "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.
|
--- 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
|
if ClientAIAliveState == true then
|
||||||
Client:SetState( self, 'AIAlive', false )
|
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" )
|
-- local PatrolZone = Client:GetState( self, "PatrolZone" )
|
||||||
if PatrolZone then
|
-- if PatrolZone then
|
||||||
PatrolZone = nil
|
-- PatrolZone = nil
|
||||||
Client:ClearState( self, "PatrolZone" )
|
-- Client:ClearState( self, "PatrolZone" )
|
||||||
end
|
-- end
|
||||||
|
|
||||||
if self.ToNearestAirbase == false and self.ToHomeAirbase == false then
|
if self.ToNearestAirbase == false and self.ToHomeAirbase == false then
|
||||||
AIGroup:Destroy()
|
AIGroup:Destroy()
|
||||||
@@ -21581,15 +21588,18 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
|
|||||||
if not ClientAIAliveState or ClientAIAliveState == false then
|
if not ClientAIAliveState or ClientAIAliveState == false then
|
||||||
Client:SetState( self, 'AIAlive', true )
|
Client:SetState( self, 'AIAlive', true )
|
||||||
|
|
||||||
|
|
||||||
-- OK, spawn a new group from the SpawnAI objects provided.
|
-- OK, spawn a new group from the SpawnAI objects provided.
|
||||||
local SpawnAICount = #self.SpawnAI
|
local SpawnAICount = #self.SpawnAI
|
||||||
local SpawnAIIndex = math.random( 1, SpawnAICount )
|
local SpawnAIIndex = math.random( 1, SpawnAICount )
|
||||||
local AIGroup = self.SpawnAI[SpawnAIIndex]:Spawn()
|
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...
|
--- Now test if the AIGroup needs to patrol a zone, otherwise let it follow its route...
|
||||||
if self.PatrolZone then
|
if self.PatrolZone then
|
||||||
local PatrolZone = PATROLZONE:New(
|
self.PatrolZones[#self.PatrolZones+1] = PATROLZONE:New(
|
||||||
self.PatrolZone.PatrolZone,
|
self.PatrolZone.PatrolZone,
|
||||||
self.PatrolZone.PatrolFloorAltitude,
|
self.PatrolZone.PatrolFloorAltitude,
|
||||||
self.PatrolZone.PatrolCeilingAltitude,
|
self.PatrolZone.PatrolCeilingAltitude,
|
||||||
@@ -21598,12 +21608,13 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
|
|||||||
)
|
)
|
||||||
|
|
||||||
if self.PatrolZone.PatrolManageFuel == true then
|
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
|
end
|
||||||
|
self.PatrolZones[#self.PatrolZones]:SetGroup( AIGroup )
|
||||||
|
|
||||||
PatrolZone:SetGroup( AIGroup )
|
--self.PatrolZones[#self.PatrolZones+1] = PatrolZone
|
||||||
|
|
||||||
Client:SetState( self, "PatrolZone", PatrolZone )
|
--Client:SetState( self, "PatrolZone", PatrolZone )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
env.info( '*** MOOSE STATIC INCLUDE START *** ' )
|
env.info( '*** MOOSE STATIC INCLUDE START *** ' )
|
||||||
env.info( 'Moose Generation Timestamp: 20160618_2312' )
|
env.info( 'Moose Generation Timestamp: 20160619_1502' )
|
||||||
local base = _G
|
local base = _G
|
||||||
|
|
||||||
Include = {}
|
Include = {}
|
||||||
@@ -9972,18 +9972,20 @@ function DATABASE:ForEach( IteratorFunction, FinalizeFunction, arg, Set )
|
|||||||
self:T2( Object )
|
self:T2( Object )
|
||||||
IteratorFunction( Object, unpack( arg ) )
|
IteratorFunction( Object, unpack( arg ) )
|
||||||
Count = Count + 1
|
Count = Count + 1
|
||||||
if Count % 10 == 0 then
|
-- if Count % 100 == 0 then
|
||||||
coroutine.yield( false )
|
-- coroutine.yield( false )
|
||||||
end
|
-- end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local co = coroutine.create( CoRoutine )
|
-- local co = coroutine.create( CoRoutine )
|
||||||
|
local co = CoRoutine
|
||||||
|
|
||||||
local function Schedule()
|
local function Schedule()
|
||||||
|
|
||||||
local status, res = coroutine.resume( co )
|
-- local status, res = coroutine.resume( co )
|
||||||
|
local status, res = co()
|
||||||
self:T3( { status, res } )
|
self:T3( { status, res } )
|
||||||
|
|
||||||
if status == false then
|
if status == false then
|
||||||
@@ -10610,18 +10612,20 @@ function SET_BASE:ForEach( IteratorFunction, arg, Set, Function, FunctionArgumen
|
|||||||
IteratorFunction( Object, unpack( arg ) )
|
IteratorFunction( Object, unpack( arg ) )
|
||||||
end
|
end
|
||||||
Count = Count + 1
|
Count = Count + 1
|
||||||
if Count % self.YieldInterval == 0 then
|
-- if Count % self.YieldInterval == 0 then
|
||||||
coroutine.yield( false )
|
-- coroutine.yield( false )
|
||||||
end
|
-- end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local co = coroutine.create( CoRoutine )
|
-- local co = coroutine.create( CoRoutine )
|
||||||
|
local co = CoRoutine
|
||||||
|
|
||||||
local function Schedule()
|
local function Schedule()
|
||||||
|
|
||||||
local status, res = coroutine.resume( co )
|
-- local status, res = coroutine.resume( co )
|
||||||
|
local status, res = co()
|
||||||
self:T3( { status, res } )
|
self:T3( { status, res } )
|
||||||
|
|
||||||
if status == false then
|
if status == false then
|
||||||
@@ -21201,7 +21205,7 @@ function PATROLZONE:SetGroup( PatrolGroup )
|
|||||||
self:NewPatrolRoute()
|
self:NewPatrolRoute()
|
||||||
|
|
||||||
if not self.PatrolOutOfFuelMonitor then
|
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 )
|
self.SpawnPatrolGroup = SPAWN:New( self.PatrolGroupTemplateName )
|
||||||
end
|
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...
|
--- 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 )
|
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:SetState( self.PatrolGroup, "PatrolZone", self )
|
||||||
self.PatrolGroup:WayPointFunction( #PatrolRoute, 1, "_NewPatrolRoute" )
|
self.PatrolGroup:WayPointFunction( #PatrolRoute, 1, "_NewPatrolRoute" )
|
||||||
|
|
||||||
@@ -21352,14 +21356,15 @@ function PATROLZONE:ManageFuel( PatrolFuelTresholdPercentage, PatrolOutOfFuelOrb
|
|||||||
self.PatrolOutOfFuelOrbitTime = PatrolOutOfFuelOrbitTime
|
self.PatrolOutOfFuelOrbitTime = PatrolOutOfFuelOrbitTime
|
||||||
|
|
||||||
if self.PatrolGroup then
|
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 )
|
self.SpawnPatrolGroup = SPAWN:New( self.PatrolGroupTemplateName )
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param #PATROLZONE self
|
--- @param #PATROLZONE self
|
||||||
function PATROLZONE:_MonitorOutOfFuelScheduled()
|
function _MonitorOutOfFuelScheduled( self )
|
||||||
|
self:F2( "_MonitorOutOfFuelScheduled" )
|
||||||
|
|
||||||
if self.PatrolGroup and self.PatrolGroup:IsAlive() then
|
if self.PatrolGroup and self.PatrolGroup:IsAlive() then
|
||||||
|
|
||||||
@@ -21433,6 +21438,8 @@ end--- This module contains the AIBALANCER class.
|
|||||||
-- @extends Base#BASE
|
-- @extends Base#BASE
|
||||||
AIBALANCER = {
|
AIBALANCER = {
|
||||||
ClassName = "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.
|
--- 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
|
if ClientAIAliveState == true then
|
||||||
Client:SetState( self, 'AIAlive', false )
|
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" )
|
-- local PatrolZone = Client:GetState( self, "PatrolZone" )
|
||||||
if PatrolZone then
|
-- if PatrolZone then
|
||||||
PatrolZone = nil
|
-- PatrolZone = nil
|
||||||
Client:ClearState( self, "PatrolZone" )
|
-- Client:ClearState( self, "PatrolZone" )
|
||||||
end
|
-- end
|
||||||
|
|
||||||
if self.ToNearestAirbase == false and self.ToHomeAirbase == false then
|
if self.ToNearestAirbase == false and self.ToHomeAirbase == false then
|
||||||
AIGroup:Destroy()
|
AIGroup:Destroy()
|
||||||
@@ -21581,15 +21588,18 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
|
|||||||
if not ClientAIAliveState or ClientAIAliveState == false then
|
if not ClientAIAliveState or ClientAIAliveState == false then
|
||||||
Client:SetState( self, 'AIAlive', true )
|
Client:SetState( self, 'AIAlive', true )
|
||||||
|
|
||||||
|
|
||||||
-- OK, spawn a new group from the SpawnAI objects provided.
|
-- OK, spawn a new group from the SpawnAI objects provided.
|
||||||
local SpawnAICount = #self.SpawnAI
|
local SpawnAICount = #self.SpawnAI
|
||||||
local SpawnAIIndex = math.random( 1, SpawnAICount )
|
local SpawnAIIndex = math.random( 1, SpawnAICount )
|
||||||
local AIGroup = self.SpawnAI[SpawnAIIndex]:Spawn()
|
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...
|
--- Now test if the AIGroup needs to patrol a zone, otherwise let it follow its route...
|
||||||
if self.PatrolZone then
|
if self.PatrolZone then
|
||||||
local PatrolZone = PATROLZONE:New(
|
self.PatrolZones[#self.PatrolZones+1] = PATROLZONE:New(
|
||||||
self.PatrolZone.PatrolZone,
|
self.PatrolZone.PatrolZone,
|
||||||
self.PatrolZone.PatrolFloorAltitude,
|
self.PatrolZone.PatrolFloorAltitude,
|
||||||
self.PatrolZone.PatrolCeilingAltitude,
|
self.PatrolZone.PatrolCeilingAltitude,
|
||||||
@@ -21598,12 +21608,13 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
|
|||||||
)
|
)
|
||||||
|
|
||||||
if self.PatrolZone.PatrolManageFuel == true then
|
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
|
end
|
||||||
|
self.PatrolZones[#self.PatrolZones]:SetGroup( AIGroup )
|
||||||
|
|
||||||
PatrolZone:SetGroup( AIGroup )
|
--self.PatrolZones[#self.PatrolZones+1] = PatrolZone
|
||||||
|
|
||||||
Client:SetState( self, "PatrolZone", PatrolZone )
|
--Client:SetState( self, "PatrolZone", PatrolZone )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,5 +15,5 @@ RU_AIBalancer:ReturnToNearestAirbases( 10000, RU_AirbasesSet )
|
|||||||
|
|
||||||
local PatrolZoneGroup = GROUP:FindByName( "Patrol Zone" )
|
local PatrolZoneGroup = GROUP:FindByName( "Patrol Zone" )
|
||||||
local PatrolZone = ZONE_POLYGON:New( "PatrolZone", PatrolZoneGroup )
|
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 )
|
RU_AIBalancer:SetPatrolZone( PatrolZone )
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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>
|
<h2><a id="#(AIBALANCER)">Type <code>AIBALANCER</code></a></h2>
|
||||||
<table class="function_list">
|
<table class="function_list">
|
||||||
<tr>
|
<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="name" nowrap="nowrap"><a href="##(AIBALANCER).ClassName">AIBALANCER.ClassName</a></td>
|
||||||
<td class="summary">
|
<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="name" nowrap="nowrap"><a href="##(AIBALANCER).PatrolZone">AIBALANCER.PatrolZone</a></td>
|
||||||
<td class="summary">
|
<td class="summary">
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="name" nowrap="nowrap"><a href="##(AIBALANCER).PatrolZones">AIBALANCER.PatrolZones</a></td>
|
||||||
|
<td class="summary">
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -231,6 +243,20 @@ None of the script code has been used however within the new AIBALANCER moose cl
|
|||||||
<dl class="function">
|
<dl class="function">
|
||||||
<dt>
|
<dt>
|
||||||
|
|
||||||
|
<em></em>
|
||||||
|
<a id="#(AIBALANCER).AIGroups" >
|
||||||
|
<strong>AIBALANCER.AIGroups</strong>
|
||||||
|
</a>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
<dl class="function">
|
||||||
|
<dt>
|
||||||
|
|
||||||
<em>#string</em>
|
<em>#string</em>
|
||||||
<a id="#(AIBALANCER).ClassName" >
|
<a id="#(AIBALANCER).ClassName" >
|
||||||
<strong>AIBALANCER.ClassName</strong>
|
<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>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
<dl class="function">
|
<dl class="function">
|
||||||
|
|||||||
@@ -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="name" nowrap="nowrap"><a href="##(PATROLZONE).SpawnPatrolGroup">PATROLZONE.SpawnPatrolGroup</a></td>
|
||||||
<td class="summary">
|
<td class="summary">
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="name" nowrap="nowrap"><a href="##(PATROLZONE)._MonitorOutOfFuelScheduled">PATROLZONE:_MonitorOutOfFuelScheduled()</a></td>
|
|
||||||
<td class="summary">
|
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</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>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user