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 ) function AI_BALANCER:New( SetClient, SpawnAI )
-- Inherits from BASE -- 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:SetStartState( "None" )
self:AddTransition( "*", "Start", "Monitoring" ) self:AddTransition( "*", "Start", "Monitoring" )
@ -103,14 +103,12 @@ function AI_BALANCER:New( SetClient, SpawnAI )
self:AddTransition( "*", "End", "End" ) self:AddTransition( "*", "End", "End" )
self:AddTransition( "*", "Dead", "End" ) self:AddTransition( "*", "Dead", "End" )
self.SetClient = SetClient self.SetClient = SetClient
self.SpawnAI = SpawnAI self.SpawnAI = SpawnAI
self.ToNearestAirbase = false self.ToNearestAirbase = false
self.ToHomeAirbase = false self.ToHomeAirbase = false
self:__Start( 1 ) self:__Start( 5 )
return self return self
end end
@ -190,6 +188,8 @@ end
--- @param #AI_BALANCER self --- @param #AI_BALANCER self
function AI_BALANCER:onenterMonitoring( SetGroup ) function AI_BALANCER:onenterMonitoring( SetGroup )
self:E( { self.SetClient:Count() } )
self.SetClient:ForEachClient( self.SetClient:ForEachClient(
--- @param Wrapper.Client#CLIENT Client --- @param Wrapper.Client#CLIENT Client
function( 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. -- 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: -- There are 2 moments when state transition methods will be called by the state machine:
-- --
-- * **Before** the state transition. -- * **Leaving** the state.
-- The state transition method needs to start with the name **OnBefore + the name of 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 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, -- 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! -- but then you'll need to specify your own logic using the AIControllable!
-- --
-- * **After** the state transition. -- * **Entering** the state.
-- The state transition method needs to start with the name **OnAfter + the name of 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. -- These state transition methods need to provide a return value, which is specified at the function description.
-- --
-- 2) #AI_CARGO_UNIT class -- 2) #AI_CARGO_UNIT class
@ -135,45 +135,45 @@
-- UnLoaded -- UnLoaded
--- @function [parent=#AI_CARGO] OnBeforeUnLoaded --- @function [parent=#AI_CARGO] OnLeaveUnLoaded
-- @param #AI_CARGO self -- @param #AI_CARGO self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable -- @param Wrapper.Controllable#CONTROLLABLE Controllable
-- @return #boolean -- @return #boolean
--- @function [parent=#AI_CARGO] OnAfterUnLoaded --- @function [parent=#AI_CARGO] OnEnterUnLoaded
-- @param #AI_CARGO self -- @param #AI_CARGO self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable -- @param Wrapper.Controllable#CONTROLLABLE Controllable
-- Loaded -- Loaded
--- @function [parent=#AI_CARGO] OnBeforeLoaded --- @function [parent=#AI_CARGO] OnLeaveLoaded
-- @param #AI_CARGO self -- @param #AI_CARGO self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable -- @param Wrapper.Controllable#CONTROLLABLE Controllable
-- @return #boolean -- @return #boolean
--- @function [parent=#AI_CARGO] OnAfterLoaded --- @function [parent=#AI_CARGO] OnEnterLoaded
-- @param #AI_CARGO self -- @param #AI_CARGO self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable -- @param Wrapper.Controllable#CONTROLLABLE Controllable
-- Boarding -- Boarding
--- @function [parent=#AI_CARGO] OnBeforeBoarding --- @function [parent=#AI_CARGO] OnLeaveBoarding
-- @param #AI_CARGO self -- @param #AI_CARGO self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable -- @param Wrapper.Controllable#CONTROLLABLE Controllable
-- @return #boolean -- @return #boolean
--- @function [parent=#AI_CARGO] OnAfterBoarding --- @function [parent=#AI_CARGO] OnEnterBoarding
-- @param #AI_CARGO self -- @param #AI_CARGO self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable -- @param Wrapper.Controllable#CONTROLLABLE Controllable
-- UnBoarding -- UnBoarding
--- @function [parent=#AI_CARGO] OnBeforeUnBoarding --- @function [parent=#AI_CARGO] OnLeaveUnBoarding
-- @param #AI_CARGO self -- @param #AI_CARGO self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable -- @param Wrapper.Controllable#CONTROLLABLE Controllable
-- @return #boolean -- @return #boolean
--- @function [parent=#AI_CARGO] OnAfterUnBoarding --- @function [parent=#AI_CARGO] OnEnterUnBoarding
-- @param #AI_CARGO self -- @param #AI_CARGO self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable -- @param Wrapper.Controllable#CONTROLLABLE Controllable

View File

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

View File

@ -68,10 +68,10 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr
if Scheduler.SchedulerObject then if Scheduler.SchedulerObject then
self.ObjectSchedulers[self.CallID] = Scheduler 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 else
self.PersistentSchedulers[self.CallID] = Scheduler self.PersistentSchedulers[self.CallID] = Scheduler
self:T3( { self.CallID, self.PersistentSchedulers[self.CallID] } ) self:E( { CallID = self.CallID, PersistentScheduler = self.PersistentSchedulers[self.CallID] } )
end end
self.Schedule = self.Schedule or setmetatable( {}, { __mode = "k" } ) 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:F2( { Start, Repeat, RandomizeFactor, Stop } )
self:T3( { SchedulerArguments } ) 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 self.SchedulerObject = SchedulerObject
local ScheduleID = _SCHEDULEDISPATCHER:AddSchedule( local ScheduleID = _SCHEDULEDISPATCHER:AddSchedule(

View File

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

View File

@ -5,4 +5,19 @@ rem Provide as the only parameter the path to the .miz files, which can be embed
echo Path to Mission Files: %1 echo Path to Mission Files: %1
For /R %1 %%G IN (*.miz) do 7z u "%%G" "l10n\DEFAULT\Moose.lua" rem For /R %1 %%G IN (*.miz) do 7z u "%%G" "l10n\DEFAULT\Moose.lua"
For /R %1 %%M IN (*.miz) do (
echo off
cd
echo "Mission: %%M"
mkdir Temp
cd Temp
mkdir l10n
mkdir l10n\DEFAULT
copy ..\..\Moose.lua l10n\DEFAULT
copy "%%~pM%%~nM.lua" l10n\DEFAULT\*.*
dir l10n\DEFAULT
7z -bb0 u "%%M" "l10n\DEFAULT\*.lua"
cd ..
rmdir /S /Q Temp
)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,16 +1,16 @@
RU_PlanesClientSet = SET_CLIENT:New():FilterCountries( "RUSSIA" ):FilterCategories( "plane" ):FilterStart()
RU_PlanesSpawn = SPAWN:New( "AI RU" ):InitCleanUp( 20 )
RU_AI_Balancer = AI_BALANCER:New( RU_PlanesClientSet, RU_PlanesSpawn )
local US_PlanesClientSet = SET_CLIENT:New():FilterCountries( "USA" ):FilterCategories( "plane" ):FilterStart() RU_AirbasesSet = SET_AIRBASE:New():FilterCoalitions("red"):FilterStart()
local US_PlanesSpawn = SPAWN:New( "AI US" ):InitCleanUp( 20 )
local US_AI_Balancer = AI_BALANCER:New( US_PlanesClientSet, US_PlanesSpawn )
local RU_PlanesClientSet = SET_CLIENT:New():FilterCountries( "RUSSIA" ):FilterCategories( "plane" ):FilterStart()
local RU_PlanesSpawn = SPAWN:New( "AI RU" ):InitCleanUp( 20 )
local RU_AI_Balancer = AI_BALANCER:New( RU_PlanesClientSet, RU_PlanesSpawn )
local RU_AirbasesSet = SET_AIRBASE:New():FilterCoalitions("red"):FilterStart()
RU_AirbasesSet:Flush() RU_AirbasesSet:Flush()
RU_AI_Balancer:ReturnToNearestAirbases( 10000, RU_AirbasesSet ) RU_AI_Balancer:ReturnToNearestAirbases( 10000, RU_AirbasesSet )
US_PlanesClientSet = SET_CLIENT:New():FilterCountries( "USA" ):FilterCategories( "plane" ):FilterStart()
US_PlanesSpawn = SPAWN:New( "AI US" ):InitCleanUp( 20 )
US_AI_Balancer = AI_BALANCER:New( US_PlanesClientSet, US_PlanesSpawn )
--RU_AI_Balancer:ReturnToHomeAirbase( 10000 ) --RU_AI_Balancer:ReturnToHomeAirbase( 10000 )
--local PatrolZoneGroup = GROUP:FindByName( "Patrol Zone Blue" ) --local PatrolZoneGroup = GROUP:FindByName( "Patrol Zone Blue" )

View File

@ -12,13 +12,13 @@ local CargoCarrierTo = UNIT:FindByName( "CarrierTo" )
InfantryCargo:Board( CargoCarrierFrom ) InfantryCargo:Board( CargoCarrierFrom )
-- Once the Cargo has been loaded into the Carrier, drive to a point and unload the Cargo. -- Once the Cargo has been loaded into the Carrier, drive to a point and unload the Cargo.
function InfantryCargo:OnAfterLoaded() function InfantryCargo:OnEnterLoaded()
self:__UnBoard( 1 ) self:__UnBoard( 1 )
self.OnAfterLoaded = nil self.OnEnterLoaded = nil
end end
-- Once the Cargo has been unloaded from the Carrier (the Cargo has arrived to the unload gathering point), OnBoard the Cargo in the other Carrier. -- Once the Cargo has been unloaded from the Carrier (the Cargo has arrived to the unload gathering point), OnBoard the Cargo in the other Carrier.
function InfantryCargo:OnAfterUnLoaded() function InfantryCargo:OnEnterUnLoaded()
self:__Board( 1, CargoCarrierTo ) self:__Board( 1, CargoCarrierTo )
self.OnAfterUnLoaded = nil self.OnEnterUnLoaded = nil
end end

View File

@ -17,13 +17,13 @@ local CargoCarrierTo = UNIT:FindByName( "CarrierTo" )
InfantryCargo:Board( CargoCarrierFrom ) InfantryCargo:Board( CargoCarrierFrom )
-- Once the Cargo has been loaded into the Carrier, drive to a point and unload the Cargo. -- Once the Cargo has been loaded into the Carrier, drive to a point and unload the Cargo.
function InfantryCargo:OnAfterLoaded() function InfantryCargo:OnEnterLoaded()
self:__UnBoard( 1 ) self:__UnBoard( 1 )
self.OnAfterLoaded = nil self.OnEnterLoaded = nil
end end
-- Once the Cargo has been unloaded from the Carrier (the Cargo has arrived to the unload gathering point), OnBoard the Cargo in the other Carrier. -- Once the Cargo has been unloaded from the Carrier (the Cargo has arrived to the unload gathering point), OnBoard the Cargo in the other Carrier.
function InfantryCargo:OnAfterUnLoaded() function InfantryCargo:OnEnterUnLoaded()
self:__Board( 1, CargoCarrierTo ) self:__Board( 1, CargoCarrierTo )
self.OnAfterUnLoaded = nil self.OnEnterUnLoaded = nil
end end

View File

@ -35,7 +35,7 @@ Patrol2:ManageFuel( 0.2, 0 )
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE self
-- @param Wrapper.Group#GROUP AIGroup -- @param Wrapper.Group#GROUP AIGroup
-- @return #boolean If false is returned, then the OnAfter state transition function will not be called. -- @return #boolean If false is returned, then the OnAfter state transition function will not be called.
function Patrol1:OnBeforeRTB( AIGroup ) function Patrol1:OnLeaveRTB( AIGroup )
AIGroup:MessageToRed( "Returning to base", 20 ) AIGroup:MessageToRed( "Returning to base", 20 )
end end
@ -51,14 +51,14 @@ end
--- State transition function for the PROCESS\_PATROLZONE **Patrol1** object --- State transition function for the PROCESS\_PATROLZONE **Patrol1** object
-- @param Process_PatrolCore.Zone#AI_PATROLZONE self -- @param Process_PatrolCore.Zone#AI_PATROLZONE self
-- @param Wrapper.Group#GROUP AIGroup -- @param Wrapper.Group#GROUP AIGroup
function Patrol1:OnAfterPatrol( AIGroup ) function Patrol1:OnEnterPatrol( AIGroup )
AIGroup:MessageToRed( "Patrolling in zone " .. PatrolZone1:GetName() , 20 ) AIGroup:MessageToRed( "Patrolling in zone " .. PatrolZone1:GetName() , 20 )
end end
--- State transition function for the PROCESS\_PATROLZONE **Patrol2** object --- State transition function for the PROCESS\_PATROLZONE **Patrol2** object
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE self
-- @param Wrapper.Group#GROUP AIGroup -- @param Wrapper.Group#GROUP AIGroup
-- @return #boolean If false is returned, then the OnAfter state transition function will not be called. -- @return #boolean If false is returned, then the OnEnter state transition function will not be called.
function Patrol2:OnBeforeRTB( AIGroup ) function Patrol2:OnBeforeRTB( AIGroup )
AIGroup:MessageToRed( "Returning to base", 20 ) AIGroup:MessageToRed( "Returning to base", 20 )
end end
@ -66,7 +66,7 @@ end
--- State transition function for the PROCESS\_PATROLZONE **Patrol2** object --- State transition function for the PROCESS\_PATROLZONE **Patrol2** object
-- @param Process_PatrolCore.Zone#AI_PATROLZONE self -- @param Process_PatrolCore.Zone#AI_PATROLZONE self
-- @param Wrapper.Group#GROUP AIGroup -- @param Wrapper.Group#GROUP AIGroup
function Patrol2:OnAfterRTB( AIGroup ) function Patrol2:OnEnterRTB( AIGroup )
local NewGroup = PatrolSpawn:Spawn() local NewGroup = PatrolSpawn:Spawn()
Patrol1:SetControllable( NewGroup ) Patrol1:SetControllable( NewGroup )
Patrol1:__Start( 1 ) Patrol1:__Start( 1 )
@ -75,6 +75,6 @@ end
--- State transition function for the PROCESS\_PATROLZONE **Patrol2** object --- State transition function for the PROCESS\_PATROLZONE **Patrol2** object
-- @param Process_PatrolCore.Zone#AI_PATROLZONE self -- @param Process_PatrolCore.Zone#AI_PATROLZONE self
-- @param Wrapper.Group#GROUP AIGroup -- @param Wrapper.Group#GROUP AIGroup
function Patrol2:OnAfterPatrol( AIGroup ) function Patrol2:OnEnterPatrol( AIGroup )
AIGroup:MessageToRed( "Patrolling in zone " .. PatrolZone2:GetName() , 20 ) AIGroup:MessageToRed( "Patrolling in zone " .. PatrolZone2:GetName() , 20 )
end end

View File

@ -506,7 +506,7 @@ SEADProcess:AddScoreProcess( "Updated", "Account", "Failed", "failed to destroy
SEADProcess:AddScore( "Success", "Destroyed all target radars", 250 ) SEADProcess:AddScore( "Success", "Destroyed all target radars", 250 )
SEADProcess:AddScore( "Failed", "Failed to destroy all target radars", -100 ) SEADProcess:AddScore( "Failed", "Failed to destroy all target radars", -100 )
function SEADProcess:OnEnterUpdated(Controllable,From,Event,To) function SEADProcess:OnEnterUpdated( Controllable, From, Event, To )
self:E( { self } ) self:E( { self } )
self:Account() self:Account()
self:Smoke() self:Smoke()
@ -517,7 +517,7 @@ end
-- we check if the SEADTask has still AlivePlayers assigned to the Task. -- we check if the SEADTask has still AlivePlayers assigned to the Task.
-- If not, the Task will Abort. -- If not, the Task will Abort.
-- And it will be Replanned within 30 seconds. -- And it will be Replanned within 30 seconds.
function SEADTask:OnAfterPlayerCrashed( PlayerUnit, PlayerName ) function SEADTask:OnEnterPlayerCrashed( PlayerUnit, PlayerName )
if not SEADTask:HasAliveUnits() then if not SEADTask:HasAliveUnits() then
SEADTask:__Abort() SEADTask:__Abort()
SEADTask:__Replan( 30 ) SEADTask:__Replan( 30 )