Fixed AI_BALANCER problem with AI not patrolling...

-- Need to redo a video, because I gave the wrong example ...
This commit is contained in:
FlightControl 2017-01-12 12:19:23 +01:00
parent 2453fb6780
commit 6716f2907b
11 changed files with 118 additions and 41 deletions

View File

@ -345,8 +345,8 @@ function AI_PATROLZONE:onenterRoute()
self.Controllable:SetState( self.Controllable, "PatrolZone", self )
self.Controllable:WayPointFunction( #PatrolRoute, 1, "_NewPatrolRoute" )
--- NOW ACT_ROUTE THE GROUP!
self.Controllable:WayPointExecute( 1 )
--- NOW ROUTE THE GROUP!
self.Controllable:WayPointExecute( 1, 5 )
self:__Patrol( 30 )
end

View File

@ -66,9 +66,9 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr
-- If the object used as the key is nil, then the garbage collector will remove the item from the Functions array.
self.ObjectSchedulers = self.ObjectSchedulers or setmetatable( {}, { __mode = "v" } )
if Scheduler.SchedulerObject then
if Scheduler.MasterObject then
self.ObjectSchedulers[self.CallID] = Scheduler
self:E( { CallID = self.CallID, ObjectScheduler = tostring(self.ObjectSchedulers[self.CallID]), SchedulerObject = tostring(Scheduler.SchedulerObject) } )
self:E( { CallID = self.CallID, ObjectScheduler = tostring(self.ObjectSchedulers[self.CallID]), MasterObject = tostring(Scheduler.MasterObject) } )
else
self.PersistentSchedulers[self.CallID] = Scheduler
self:E( { CallID = self.CallID, PersistentScheduler = self.PersistentSchedulers[self.CallID] } )
@ -80,7 +80,7 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr
self.Schedule[Scheduler][self.CallID].Function = ScheduleFunction
self.Schedule[Scheduler][self.CallID].Arguments = ScheduleArguments
self.Schedule[Scheduler][self.CallID].StartTime = timer.getTime() + ( Start or 0 )
self.Schedule[Scheduler][self.CallID].Start = Start + .001
self.Schedule[Scheduler][self.CallID].Start = Start + .1
self.Schedule[Scheduler][self.CallID].Repeat = Repeat
self.Schedule[Scheduler][self.CallID].Randomize = Randomize
self.Schedule[Scheduler][self.CallID].Stop = Stop
@ -156,7 +156,7 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr
self:Stop( Scheduler, CallID )
end
else
--self:E( "Scheduled obscolete call for CallID: " .. CallID )
self:E( "Scheduled obscolete call for CallID: " .. CallID )
end
return nil

View File

@ -69,6 +69,8 @@ function SCHEDULER:New( SchedulerObject, SchedulerFunction, SchedulerArguments,
local ScheduleID = nil
self.MasterObject = SchedulerObject
if SchedulerFunction then
ScheduleID = self:Schedule( SchedulerObject, SchedulerFunction, SchedulerArguments, Start, Repeat, RandomizeFactor, Stop )
end

View File

@ -591,6 +591,7 @@ function SPAWN:ReSpawn( SpawnIndex )
-- TODO: This logic makes DCS crash and i don't know why (yet).
local SpawnGroup = self:GetGroupFromIndex( SpawnIndex )
local WayPoints = SpawnGroup and SpawnGroup.WayPoints or nil
if SpawnGroup then
local SpawnDCSGroup = SpawnGroup:GetDCSObject()
if SpawnDCSGroup then
@ -598,7 +599,15 @@ function SPAWN:ReSpawn( SpawnIndex )
end
end
return self:SpawnWithIndex( SpawnIndex )
local SpawnGroup = self:SpawnWithIndex( SpawnIndex )
if SpawnGroup and WayPoints then
-- If there were WayPoints set, then Re-Execute those WayPoints!
self:E( WayPoints )
SpawnGroup:WayPointInitialize( WayPoints )
SpawnGroup:WayPointExecute( 1, 5 )
end
return SpawnGroup
end
--- Will spawn a group with a specified index number.

View File

@ -144,6 +144,8 @@ function CONTROLLABLE:New( ControllableName )
local self = BASE:Inherit( self, POSITIONABLE:New( ControllableName ) )
self:F2( ControllableName )
self.ControllableName = ControllableName
self.TaskScheduler = SCHEDULER:New( self )
return self
end
@ -202,7 +204,7 @@ function CONTROLLABLE:PushTask( DCSTask, WaitTime )
-- Controller:pushTask( DCSTask )
if WaitTime then
SCHEDULER:New( Controller, Controller.pushTask, { DCSTask }, WaitTime )
self.TaskScheduler:Schedule( Controller, Controller.pushTask, { DCSTask }, WaitTime )
else
Controller:pushTask( DCSTask )
end
@ -233,7 +235,7 @@ function CONTROLLABLE:SetTask( DCSTask, WaitTime )
if not WaitTime then
Controller:setTask( DCSTask )
else
SCHEDULER:New( Controller, Controller.setTask, { DCSTask }, WaitTime )
self.TaskScheduler:Schedule( Controller, Controller.setTask, { DCSTask }, WaitTime )
end
return self
@ -1494,7 +1496,7 @@ function CONTROLLABLE:Route( GoPoints )
local MissionTask = { id = 'Mission', params = { route = { points = Points, }, }, }
local Controller = self:_GetController()
--Controller.setTask( Controller, MissionTask )
SCHEDULER:New( Controller, Controller.setTask, { MissionTask }, 1 )
self.TaskScheduler:Schedule( Controller, Controller.setTask, { MissionTask }, 1 )
return self
end
@ -2122,7 +2124,7 @@ end
-- @param #table WayPoints If WayPoints is given, then use the route.
-- @return #CONTROLLABLE
function CONTROLLABLE:WayPointInitialize( WayPoints )
self:F( { WayPoint, WayPointIndex, WayPointFunction } )
self:F( { WayPoints } )
if WayPoints then
self.WayPoints = WayPoints
@ -2133,6 +2135,18 @@ function CONTROLLABLE:WayPointInitialize( WayPoints )
return self
end
--- Get the current WayPoints set with the WayPoint functions( Note that the WayPoints can be nil, although there ARE waypoints).
-- @param #CONTROLLABLE self
-- @return #table WayPoints If WayPoints is given, then return the WayPoints structure.
function CONTROLLABLE:GetWayPoints()
self:F( )
if self.WayPoints then
return self.WayPoints
end
return nil
end
--- Registers a waypoint function that will be executed when the controllable moves over the WayPoint.
-- @param #CONTROLLABLE self

View File

@ -1,5 +1,5 @@
env.info( '*** MOOSE STATIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20170110_1254' )
env.info( 'Moose Generation Timestamp: 20170112_1201' )
local base = _G
Include = {}
@ -3857,6 +3857,8 @@ function SCHEDULER:New( SchedulerObject, SchedulerFunction, SchedulerArguments,
local ScheduleID = nil
self.MasterObject = SchedulerObject
if SchedulerFunction then
ScheduleID = self:Schedule( SchedulerObject, SchedulerFunction, SchedulerArguments, Start, Repeat, RandomizeFactor, Stop )
end
@ -4015,9 +4017,9 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr
-- If the object used as the key is nil, then the garbage collector will remove the item from the Functions array.
self.ObjectSchedulers = self.ObjectSchedulers or setmetatable( {}, { __mode = "v" } )
if Scheduler.SchedulerObject then
if Scheduler.MasterObject then
self.ObjectSchedulers[self.CallID] = Scheduler
self:E( { CallID = self.CallID, ObjectScheduler = tostring(self.ObjectSchedulers[self.CallID]), SchedulerObject = tostring(Scheduler.SchedulerObject) } )
self:E( { CallID = self.CallID, ObjectScheduler = tostring(self.ObjectSchedulers[self.CallID]), MasterObject = tostring(Scheduler.MasterObject) } )
else
self.PersistentSchedulers[self.CallID] = Scheduler
self:E( { CallID = self.CallID, PersistentScheduler = self.PersistentSchedulers[self.CallID] } )
@ -4029,7 +4031,7 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr
self.Schedule[Scheduler][self.CallID].Function = ScheduleFunction
self.Schedule[Scheduler][self.CallID].Arguments = ScheduleArguments
self.Schedule[Scheduler][self.CallID].StartTime = timer.getTime() + ( Start or 0 )
self.Schedule[Scheduler][self.CallID].Start = Start + .001
self.Schedule[Scheduler][self.CallID].Start = Start + .1
self.Schedule[Scheduler][self.CallID].Repeat = Repeat
self.Schedule[Scheduler][self.CallID].Randomize = Randomize
self.Schedule[Scheduler][self.CallID].Stop = Stop
@ -4105,7 +4107,7 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr
self:Stop( Scheduler, CallID )
end
else
--self:E( "Scheduled obscolete call for CallID: " .. CallID )
self:E( "Scheduled obscolete call for CallID: " .. CallID )
end
return nil
@ -12627,6 +12629,8 @@ function CONTROLLABLE:New( ControllableName )
local self = BASE:Inherit( self, POSITIONABLE:New( ControllableName ) )
self:F2( ControllableName )
self.ControllableName = ControllableName
self.TaskScheduler = SCHEDULER:New( self )
return self
end
@ -12685,7 +12689,7 @@ function CONTROLLABLE:PushTask( DCSTask, WaitTime )
-- Controller:pushTask( DCSTask )
if WaitTime then
SCHEDULER:New( Controller, Controller.pushTask, { DCSTask }, WaitTime )
self.TaskScheduler:Schedule( Controller, Controller.pushTask, { DCSTask }, WaitTime )
else
Controller:pushTask( DCSTask )
end
@ -12716,7 +12720,7 @@ function CONTROLLABLE:SetTask( DCSTask, WaitTime )
if not WaitTime then
Controller:setTask( DCSTask )
else
SCHEDULER:New( Controller, Controller.setTask, { DCSTask }, WaitTime )
self.TaskScheduler:Schedule( Controller, Controller.setTask, { DCSTask }, WaitTime )
end
return self
@ -13977,7 +13981,7 @@ function CONTROLLABLE:Route( GoPoints )
local MissionTask = { id = 'Mission', params = { route = { points = Points, }, }, }
local Controller = self:_GetController()
--Controller.setTask( Controller, MissionTask )
SCHEDULER:New( Controller, Controller.setTask, { MissionTask }, 1 )
self.TaskScheduler:Schedule( Controller, Controller.setTask, { MissionTask }, 1 )
return self
end
@ -14605,7 +14609,7 @@ end
-- @param #table WayPoints If WayPoints is given, then use the route.
-- @return #CONTROLLABLE
function CONTROLLABLE:WayPointInitialize( WayPoints )
self:F( { WayPoint, WayPointIndex, WayPointFunction } )
self:F( { WayPoints } )
if WayPoints then
self.WayPoints = WayPoints
@ -14616,6 +14620,18 @@ function CONTROLLABLE:WayPointInitialize( WayPoints )
return self
end
--- Get the current WayPoints set with the WayPoint functions( Note that the WayPoints can be nil, although there ARE waypoints).
-- @param #CONTROLLABLE self
-- @return #table WayPoints If WayPoints is given, then return the WayPoints structure.
function CONTROLLABLE:GetWayPoints()
self:F( )
if self.WayPoints then
return self.WayPoints
end
return nil
end
--- Registers a waypoint function that will be executed when the controllable moves over the WayPoint.
-- @param #CONTROLLABLE self
@ -18775,6 +18791,7 @@ function SPAWN:ReSpawn( SpawnIndex )
-- TODO: This logic makes DCS crash and i don't know why (yet).
local SpawnGroup = self:GetGroupFromIndex( SpawnIndex )
local WayPoints = SpawnGroup and SpawnGroup.WayPoints or nil
if SpawnGroup then
local SpawnDCSGroup = SpawnGroup:GetDCSObject()
if SpawnDCSGroup then
@ -18782,7 +18799,15 @@ function SPAWN:ReSpawn( SpawnIndex )
end
end
return self:SpawnWithIndex( SpawnIndex )
local SpawnGroup = self:SpawnWithIndex( SpawnIndex )
if SpawnGroup and WayPoints then
-- If there were WayPoints set, then Re-Execute those WayPoints!
self:E( WayPoints )
SpawnGroup:WayPointInitialize( WayPoints )
SpawnGroup:WayPointExecute( 1, 5 )
end
return SpawnGroup
end
--- Will spawn a group with a specified index number.
@ -24834,8 +24859,8 @@ function AI_PATROLZONE:onenterRoute()
self.Controllable:SetState( self.Controllable, "PatrolZone", self )
self.Controllable:WayPointFunction( #PatrolRoute, 1, "_NewPatrolRoute" )
--- NOW ACT_ROUTE THE GROUP!
self.Controllable:WayPointExecute( 1 )
--- NOW ROUTE THE GROUP!
self.Controllable:WayPointExecute( 1, 5 )
self:__Patrol( 30 )
end

View File

@ -1,5 +1,5 @@
env.info( '*** MOOSE STATIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20170110_1254' )
env.info( 'Moose Generation Timestamp: 20170112_1201' )
local base = _G
Include = {}
@ -3857,6 +3857,8 @@ function SCHEDULER:New( SchedulerObject, SchedulerFunction, SchedulerArguments,
local ScheduleID = nil
self.MasterObject = SchedulerObject
if SchedulerFunction then
ScheduleID = self:Schedule( SchedulerObject, SchedulerFunction, SchedulerArguments, Start, Repeat, RandomizeFactor, Stop )
end
@ -4015,9 +4017,9 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr
-- If the object used as the key is nil, then the garbage collector will remove the item from the Functions array.
self.ObjectSchedulers = self.ObjectSchedulers or setmetatable( {}, { __mode = "v" } )
if Scheduler.SchedulerObject then
if Scheduler.MasterObject then
self.ObjectSchedulers[self.CallID] = Scheduler
self:E( { CallID = self.CallID, ObjectScheduler = tostring(self.ObjectSchedulers[self.CallID]), SchedulerObject = tostring(Scheduler.SchedulerObject) } )
self:E( { CallID = self.CallID, ObjectScheduler = tostring(self.ObjectSchedulers[self.CallID]), MasterObject = tostring(Scheduler.MasterObject) } )
else
self.PersistentSchedulers[self.CallID] = Scheduler
self:E( { CallID = self.CallID, PersistentScheduler = self.PersistentSchedulers[self.CallID] } )
@ -4029,7 +4031,7 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr
self.Schedule[Scheduler][self.CallID].Function = ScheduleFunction
self.Schedule[Scheduler][self.CallID].Arguments = ScheduleArguments
self.Schedule[Scheduler][self.CallID].StartTime = timer.getTime() + ( Start or 0 )
self.Schedule[Scheduler][self.CallID].Start = Start + .001
self.Schedule[Scheduler][self.CallID].Start = Start + .1
self.Schedule[Scheduler][self.CallID].Repeat = Repeat
self.Schedule[Scheduler][self.CallID].Randomize = Randomize
self.Schedule[Scheduler][self.CallID].Stop = Stop
@ -4105,7 +4107,7 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr
self:Stop( Scheduler, CallID )
end
else
--self:E( "Scheduled obscolete call for CallID: " .. CallID )
self:E( "Scheduled obscolete call for CallID: " .. CallID )
end
return nil
@ -12627,6 +12629,8 @@ function CONTROLLABLE:New( ControllableName )
local self = BASE:Inherit( self, POSITIONABLE:New( ControllableName ) )
self:F2( ControllableName )
self.ControllableName = ControllableName
self.TaskScheduler = SCHEDULER:New( self )
return self
end
@ -12685,7 +12689,7 @@ function CONTROLLABLE:PushTask( DCSTask, WaitTime )
-- Controller:pushTask( DCSTask )
if WaitTime then
SCHEDULER:New( Controller, Controller.pushTask, { DCSTask }, WaitTime )
self.TaskScheduler:Schedule( Controller, Controller.pushTask, { DCSTask }, WaitTime )
else
Controller:pushTask( DCSTask )
end
@ -12716,7 +12720,7 @@ function CONTROLLABLE:SetTask( DCSTask, WaitTime )
if not WaitTime then
Controller:setTask( DCSTask )
else
SCHEDULER:New( Controller, Controller.setTask, { DCSTask }, WaitTime )
self.TaskScheduler:Schedule( Controller, Controller.setTask, { DCSTask }, WaitTime )
end
return self
@ -13977,7 +13981,7 @@ function CONTROLLABLE:Route( GoPoints )
local MissionTask = { id = 'Mission', params = { route = { points = Points, }, }, }
local Controller = self:_GetController()
--Controller.setTask( Controller, MissionTask )
SCHEDULER:New( Controller, Controller.setTask, { MissionTask }, 1 )
self.TaskScheduler:Schedule( Controller, Controller.setTask, { MissionTask }, 1 )
return self
end
@ -14605,7 +14609,7 @@ end
-- @param #table WayPoints If WayPoints is given, then use the route.
-- @return #CONTROLLABLE
function CONTROLLABLE:WayPointInitialize( WayPoints )
self:F( { WayPoint, WayPointIndex, WayPointFunction } )
self:F( { WayPoints } )
if WayPoints then
self.WayPoints = WayPoints
@ -14616,6 +14620,18 @@ function CONTROLLABLE:WayPointInitialize( WayPoints )
return self
end
--- Get the current WayPoints set with the WayPoint functions( Note that the WayPoints can be nil, although there ARE waypoints).
-- @param #CONTROLLABLE self
-- @return #table WayPoints If WayPoints is given, then return the WayPoints structure.
function CONTROLLABLE:GetWayPoints()
self:F( )
if self.WayPoints then
return self.WayPoints
end
return nil
end
--- Registers a waypoint function that will be executed when the controllable moves over the WayPoint.
-- @param #CONTROLLABLE self
@ -18775,6 +18791,7 @@ function SPAWN:ReSpawn( SpawnIndex )
-- TODO: This logic makes DCS crash and i don't know why (yet).
local SpawnGroup = self:GetGroupFromIndex( SpawnIndex )
local WayPoints = SpawnGroup and SpawnGroup.WayPoints or nil
if SpawnGroup then
local SpawnDCSGroup = SpawnGroup:GetDCSObject()
if SpawnDCSGroup then
@ -18782,7 +18799,15 @@ function SPAWN:ReSpawn( SpawnIndex )
end
end
return self:SpawnWithIndex( SpawnIndex )
local SpawnGroup = self:SpawnWithIndex( SpawnIndex )
if SpawnGroup and WayPoints then
-- If there were WayPoints set, then Re-Execute those WayPoints!
self:E( WayPoints )
SpawnGroup:WayPointInitialize( WayPoints )
SpawnGroup:WayPointExecute( 1, 5 )
end
return SpawnGroup
end
--- Will spawn a group with a specified index number.
@ -24834,8 +24859,8 @@ function AI_PATROLZONE:onenterRoute()
self.Controllable:SetState( self.Controllable, "PatrolZone", self )
self.Controllable:WayPointFunction( #PatrolRoute, 1, "_NewPatrolRoute" )
--- NOW ACT_ROUTE THE GROUP!
self.Controllable:WayPointExecute( 1 )
--- NOW ROUTE THE GROUP!
self.Controllable:WayPointExecute( 1, 5 )
self:__Patrol( 30 )
end

View File

@ -31,15 +31,17 @@ local RU_PlanesSpawn = SPAWN:New( "AI RU" ):InitCleanUp( 20 )
-- Start the AI_BALANCER, using the SET of red CLIENTs, and the SPAWN object as a parameter.
local RU_AI_Balancer = AI_BALANCER:New( RU_PlanesClientSet, RU_PlanesSpawn )
local PatrolZones = {}
function RU_AI_Balancer:OnAfterSpawned( SetGroup, From, Event, To, AIGroup )
local PatrolZoneGroup = GROUP:FindByName( "PatrolZone" )
local PatrolZone = ZONE_POLYGON:New( "PatrolZone", PatrolZoneGroup )
local Patrol = AI_PATROLZONE:New( PatrolZone, 3000, 6000, 400, 600 )
Patrol:ManageFuel( 0.2, 60 )
Patrol:SetControllable( AIGroup )
Patrol:__Start( 5 )
PatrolZones[AIGroup] = AI_PATROLZONE:New( PatrolZone, 3000, 6000, 400, 600 )
PatrolZones[AIGroup]:ManageFuel( 0.2, 60 )
PatrolZones[AIGroup]:SetControllable( AIGroup )
PatrolZones[AIGroup]:__Start( 5 )
end

View File

@ -25,7 +25,7 @@ local RU_PlanesClientSet = SET_CLIENT:New():FilterCountries( "RUSSIA" ):FilterCa
-- Define the SPAWN object for the red AI plane template.
-- We use InitCleanUp to check every 20 seconds, if there are no planes blocked at the airbase, waithing for take-off.
-- If a blocked plane exists, this red plane will be ReSpawned.
local RU_PlanesSpawn = SPAWN:New( "AI RU" )
local RU_PlanesSpawn = SPAWN:New( "AI RU" ):InitCleanUp( 60 )
-- Start the AI_BALANCER, using the SET of red CLIENTs, and the SPAWN object as a parameter.
local RU_AI_Balancer = AI_BALANCER:New( RU_PlanesClientSet, RU_PlanesSpawn )

View File

@ -24,7 +24,7 @@ local RU_PlanesClientSet = SET_CLIENT:New():FilterCountries( "RUSSIA" ):FilterCa
-- Define the SPAWN object for the red AI plane template.
-- We use InitCleanUp to check every 20 seconds, if there are no planes blocked at the airbase, waithing for take-off.
-- If a blocked plane exists, this red plane will be ReSpawned.
local RU_PlanesSpawn = SPAWN:New( "AI RU" ):InitCleanUp( 20 )
local RU_PlanesSpawn = SPAWN:New( "AI RU" ):InitCleanUp( 60 )
-- Start the AI_BALANCER, using the SET of red CLIENTs, and the SPAWN object as a parameter.
local RU_AI_Balancer = AI_BALANCER:New( RU_PlanesClientSet, RU_PlanesSpawn )