AI_BALANCER fixes and other stuff

This commit is contained in:
FlightControl
2017-01-07 16:44:41 +01:00
parent fc100716e0
commit 196f85f07b
71 changed files with 117 additions and 59464 deletions

View File

@@ -91,7 +91,7 @@ AI_BALANCER = {
function AI_BALANCER:New( SetClient, SpawnAI )
-- Inherits from BASE
local self = BASE:Inherit( self, FSM_SET:New( SET_GROUP:New() ) ) -- Core.Fsm#FSM_SET
self = BASE:Inherit( self, FSM_SET:New( SET_GROUP:New() ) ) -- Core.Fsm#FSM_SET
self:SetStartState( "None" )
self:AddTransition( "*", "Start", "Monitoring" )
@@ -103,14 +103,12 @@ function AI_BALANCER:New( SetClient, SpawnAI )
self:AddTransition( "*", "End", "End" )
self:AddTransition( "*", "Dead", "End" )
self.SetClient = SetClient
self.SpawnAI = SpawnAI
self.ToNearestAirbase = false
self.ToHomeAirbase = false
self:__Start( 1 )
self:__Start( 5 )
return self
end
@@ -190,6 +188,8 @@ end
--- @param #AI_BALANCER self
function AI_BALANCER:onenterMonitoring( SetGroup )
self:E( { self.SetClient:Count() } )
self.SetClient:ForEachClient(
--- @param Wrapper.Client#CLIENT Client
function( Client )

View File

@@ -42,14 +42,14 @@
-- State transition functions can be set **by the mission designer** customizing or improving the behaviour of the state.
-- There are 2 moments when state transition methods will be called by the state machine:
--
-- * **Before** the state transition.
-- The state transition method needs to start with the name **OnBefore + the name of the state**.
-- * **Leaving** the state.
-- The state transition method needs to start with the name **OnLeave + the name of the state**.
-- If the state transition method returns false, then the processing of the state transition will not be done!
-- If you want to change the behaviour of the AIControllable at this event, return false,
-- but then you'll need to specify your own logic using the AIControllable!
--
-- * **After** the state transition.
-- The state transition method needs to start with the name **OnAfter + the name of the state**.
-- * **Entering** the state.
-- The state transition method needs to start with the name **OnEnter + the name of the state**.
-- These state transition methods need to provide a return value, which is specified at the function description.
--
-- 2) #AI_CARGO_UNIT class
@@ -135,45 +135,45 @@
-- UnLoaded
--- @function [parent=#AI_CARGO] OnBeforeUnLoaded
--- @function [parent=#AI_CARGO] OnLeaveUnLoaded
-- @param #AI_CARGO self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable
-- @return #boolean
--- @function [parent=#AI_CARGO] OnAfterUnLoaded
--- @function [parent=#AI_CARGO] OnEnterUnLoaded
-- @param #AI_CARGO self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable
-- Loaded
--- @function [parent=#AI_CARGO] OnBeforeLoaded
--- @function [parent=#AI_CARGO] OnLeaveLoaded
-- @param #AI_CARGO self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable
-- @return #boolean
--- @function [parent=#AI_CARGO] OnAfterLoaded
--- @function [parent=#AI_CARGO] OnEnterLoaded
-- @param #AI_CARGO self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable
-- Boarding
--- @function [parent=#AI_CARGO] OnBeforeBoarding
--- @function [parent=#AI_CARGO] OnLeaveBoarding
-- @param #AI_CARGO self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable
-- @return #boolean
--- @function [parent=#AI_CARGO] OnAfterBoarding
--- @function [parent=#AI_CARGO] OnEnterBoarding
-- @param #AI_CARGO self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable
-- UnBoarding
--- @function [parent=#AI_CARGO] OnBeforeUnBoarding
--- @function [parent=#AI_CARGO] OnLeaveUnBoarding
-- @param #AI_CARGO self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable
-- @return #boolean
--- @function [parent=#AI_CARGO] OnAfterUnBoarding
--- @function [parent=#AI_CARGO] OnEnterUnBoarding
-- @param #AI_CARGO self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable

View File

@@ -310,7 +310,7 @@ do -- FSM
function FSM:New( FsmT )
-- Inherits from BASE
local self = BASE:Inherit( self, BASE:New() )
self = BASE:Inherit( self, BASE:New() )
self.options = options or {}
self.options.subs = self.options.subs or {}
@@ -537,17 +537,17 @@ do -- FSM
self:E( { EventName, ... } )
local can, to = self:can( EventName )
self:E( { EventName, self.current, can, to } )
local Can, to = self:can( EventName )
self:E( { From = self.current, Event = EventName, To = to, Can = Can } )
local ReturnValues = nil
if can then
if Can then
local from = self.current
local params = { from, EventName, to, ... }
if self:_call_handler("onbefore" .. EventName, params) == false
or self:_call_handler("onleave" .. from, params) == false then
or self:_call_handler("OnBefore" .. EventName, params) == false
or self:_call_handler("onleave" .. from, params) == false
or self:_call_handler("OnLeave" .. from, params) == false then
return false
end
@@ -572,7 +572,9 @@ do -- FSM
if fsmparent and Event then
self:F2( { "end state: ", fsmparent, Event } )
self:_call_handler("onenter" .. to, params)
self:_call_handler("OnEnter" .. to, params)
self:_call_handler("onafter" .. EventName, params)
self:_call_handler("OnAfter" .. EventName, params)
self:_call_handler("onstatechange", params)
fsmparent[Event]( fsmparent )
execute = false
@@ -581,24 +583,15 @@ do -- FSM
if execute then
-- only execute the call if the From state is not equal to the To state! Otherwise this function should never execute!
if from ~= to then
self:T3( { onenter = "onenter" .. to, callback = self["onenter" .. to] } )
self:_call_handler("onenter" .. to, params)
self:_call_handler("OnEnter" .. to, params)
end
self:T3( { On = "OnBefore" .. to, callback = self["OnBefore" .. to] } )
if ( self:_call_handler("OnBefore" .. to, params ) ~= false ) then
self:T3( { onafter = "onafter" .. EventName, callback = self["onafter" .. EventName] } )
self:_call_handler("onafter" .. EventName, params)
self:T3( { On = "OnAfter" .. EventName, callback = self["OnAfter" .. EventName] } )
ReturnValues = self:_call_handler("OnAfter" .. EventName, params )
end
self:_call_handler("onafter" .. EventName, params)
self:_call_handler("OnAfter" .. EventName, params)
self:_call_handler("onstatechange", params)
end
return ReturnValues
end
return nil
@@ -1007,7 +1000,7 @@ do -- FSM_SET
function FSM_SET:New( FSMSet )
-- Inherits from BASE
local self = BASE:Inherit( self, FSM:New() ) -- Core.Fsm#FSM_SET
self = BASE:Inherit( self, FSM:New() ) -- Core.Fsm#FSM_SET
if FSMSet then
self:Set( FSMSet )

View File

@@ -68,10 +68,10 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr
if Scheduler.SchedulerObject then
self.ObjectSchedulers[self.CallID] = Scheduler
self:T3( { self.CallID, self.ObjectSchedulers[self.CallID] } )
self:E( { CallID = self.CallID, ObjectScheduler = tostring(self.ObjectSchedulers[self.CallID]), SchedulerObject = tostring(Scheduler.SchedulerObject) } )
else
self.PersistentSchedulers[self.CallID] = Scheduler
self:T3( { self.CallID, self.PersistentSchedulers[self.CallID] } )
self:E( { CallID = self.CallID, PersistentScheduler = self.PersistentSchedulers[self.CallID] } )
end
self.Schedule = self.Schedule or setmetatable( {}, { __mode = "k" } )

View File

@@ -96,7 +96,11 @@ function SCHEDULER:Schedule( SchedulerObject, SchedulerFunction, SchedulerArgume
self:F2( { Start, Repeat, RandomizeFactor, Stop } )
self:T3( { SchedulerArguments } )
local ObjectName = "-"
if SchedulerObject and SchedulerObject.ClassName and SchedulerObject.ClassID then
ObjectName = SchedulerObject.ClassName .. SchedulerObject.ClassID
end
self:E( { "Schedule :", ObjectName, tostring( SchedulerObject ), Start, Repeat, RandomizeFactor, Stop } )
self.SchedulerObject = SchedulerObject
local ScheduleID = _SCHEDULEDISPATCHER:AddSchedule(

View File

@@ -233,6 +233,7 @@
-- @field #table Filter
-- @field #table Set
-- @field #table List
-- @field Core.Scheduler#SCHEDULER CallScheduler
-- @extends Core.Base#BASE
SET_BASE = {
ClassName = "SET_BASE",
@@ -250,7 +251,7 @@ SET_BASE = {
function SET_BASE:New( Database )
-- Inherits from BASE
local self = BASE:Inherit( self, BASE:New() )
local self = BASE:Inherit( self, BASE:New() ) -- Core.Set#SET_BASE
self.Database = Database
@@ -260,6 +261,8 @@ function SET_BASE:New( Database )
self.List = {}
self.List.__index = self.List
self.List = setmetatable( { Count = 0 }, self.List )
self.CallScheduler = SCHEDULER:New( self )
return self
end
@@ -647,7 +650,7 @@ function SET_BASE:ForEach( IteratorFunction, arg, Set, Function, FunctionArgumen
return false
end
local Scheduler = SCHEDULER:New( self, Schedule, {}, self.TimeInterval, self.TimeInterval, 0 )
self.CallScheduler:Schedule( self, Schedule, {}, self.TimeInterval, self.TimeInterval, 0 )
return self
end