Module AI_Balancer

SP:N MP:Y AI:Y HU:N TYP:A -- This module contains the AI_BALANCER class.

AI Balancing will replace in multi player missions non-occupied human slots with AI groups, in order to provide an engaging simulation environment, even when there are hardly any players in the mission.

Banner Image


1) AI.AIBalancer#AIBALANCER class, extends Core.Fsm#FSM_SET

The AI.AIBalancer#AIBALANCER class monitors and manages as many AI GROUPS as there are CLIENTS in a SETCLIENT collection not occupied by human players. In other words, use AIBALANCER to simulate human behaviour by spawning in replacement AI.

The AI_BALANCER class manages internally a collection of AI management objects, which govern the behaviour of the spawned AI Wrapper.Group#GROUP manages the functionality to control the Finite State Machine (FSM) and calls for each event the state transition methods providing the internal Core.Fsm#FSM_SET.Set object containing the AI and additional event parameters provided during the event.

1.1) AI_BALANCER construction

Create a new AI_BALANCER object with the AI_BALANCER.New() method:

1.2) AI_BALANCER is a FSM

The AI_BALANCER is a state machine: it manages the different events and states of the Core.Fsm#FSM_SET.Set it is governing. The AI_BALANCER has a default flow to manage the set.

Process

1.2.1) AI_BALANCER States

  • Monitoring ( Set ): Monitoring the Set if all AI is spawned for the Clients.
  • Spawning ( Set, ClientName ): There is a new AI group spawned with ClientName as the name of reference.
  • Spawned ( Set, AIGroup ): A new AI has been spawned. You can handle this event to customize the AI behaviour with other AI FSMs or own processes.
  • Destroying ( Set, AIGroup ): The AI is being destroyed.
  • Returning ( Set, AIGroup ): The AI is returning to the airbase specified by the ReturnToAirbase methods. Handle this state to customize the return behaviour of the AI, if any.

1.2.2) AI_BALANCER Events

  • Monitor ( Set ): Every 10 seconds, the Monitor event is triggered to monitor the Set.
  • Spawn ( Set, ClientName ): Triggers when there is a new AI group to be spawned with ClientName as the name of reference.
  • Spawned ( Set, AIGroup ): Triggers when a new AI has been spawned. You can handle this event to customize the AI behaviour with other AI FSMs or own processes.
  • Destroy ( Set, AIGroup ): The AI is being destroyed.
  • Return ( Set, AIGroup ): The AI is returning to the airbase specified by the ReturnToAirbase methods.

1.3) AI_BALANCER spawn interval for replacement AI

Use the method AI_BALANCER.InitSpawnInterval() to set the earliest and latest interval in seconds that is waited until a new replacement AI is spawned.

1.4) AI_BALANCER returns AI to Airbases

By default, When a human player joins a slot that is AI_BALANCED, the AI group will be destroyed by default. However, there are 2 additional options that you can use to customize the destroy behaviour. When a human player joins a slot, you can configure to let the AI return to:

Note that when AI returns to an airbase, it will trigger the Return event and will return, otherwise when the AI is destroyed, the Destroy event will be triggered.


API CHANGE HISTORY

The underlying change log documents the API changes. Please read this carefully. The following notation is used:

  • Added parts are expressed in bold type face.
  • Removed parts are expressed in italic type face.

Hereby the change log:

2017-01-08: AI_BALANCER:InitSpawnInterval( Earliest, Latest ) added.


AUTHORS and CONTRIBUTIONS

Contributions:

  • Dutch_Baron: Working together with James has resulted in the creation of the AI_BALANCER class. James has shared his ideas on balancing AI with air units, and together we made a first design which you can use now :-)

  • SNAFU: Had a couple of mails with the guys to validate, if the same concept in the GCI/CAP script could be reworked within MOOSE. None of the script code has been used however within the new AI_BALANCER moose class.

Authors:

  • FlightControl: Framework Design & Programming and Documentation.

Global(s)

AI_BALANCER

Type AI_BALANCER

AI_BALANCER.AIGroups
AI_BALANCER.ClassName
AI_BALANCER.Earliest
AI_BALANCER:InitSpawnInterval(Earliest, Latest)

Sets the earliest to the latest interval in seconds how long AI_BALANCER will wait to spawn a new AI.

AI_BALANCER.Latest
AI_BALANCER:New(SetClient, SpawnAI)

Creates a new AI_BALANCER object

AI_BALANCER.PatrolZones
AI_BALANCER.ReturnAirbaseSet
AI_BALANCER:ReturnToHomeAirbase(ReturnTresholdRange)

Returns the AI to the home Wrapper.Airbase#AIRBASE.

AI_BALANCER:ReturnToNearestAirbases(ReturnTresholdRange, ReturnAirbaseSet)

Returns the AI to the nearest friendly Wrapper.Airbase#AIRBASE.

AI_BALANCER.ReturnTresholdRange
AI_BALANCER.SetClient
AI_BALANCER.SpawnAI
AI_BALANCER.Test
AI_BALANCER.ToHomeAirbase
AI_BALANCER.ToNearestAirbase
AI_BALANCER:onenterDestroying(SetGroup, AIGroup, From, Event, To, ClientName)
AI_BALANCER:onenterMonitoring(SetGroup)
AI_BALANCER:onenterReturning(SetGroup, AIGroup, From, Event, To)
AI_BALANCER:onenterSpawning(SetGroup, ClientName, AIGroup, From, Event, To)

Global(s)

#AI_BALANCER AI_BALANCER

Type AI_Balancer

Type AI_BALANCER

AI_BALANCER class

Field(s)

AI_BALANCER.AIGroups
#string AI_BALANCER.ClassName
AI_BALANCER.Earliest
AI_BALANCER:InitSpawnInterval(Earliest, Latest)

Sets the earliest to the latest interval in seconds how long AI_BALANCER will wait to spawn a new AI.

Provide 2 identical seconds if the interval should be a fixed amount of seconds.

Parameters

  • #number Earliest : The earliest a new AI can be spawned in seconds.

  • #number Latest : The latest a new AI can be spawned in seconds.

Return value

self

AI_BALANCER.Latest
AI_BALANCER:New(SetClient, SpawnAI)

Creates a new AI_BALANCER object

Parameters

  • Core.Set#SET_CLIENT SetClient : A SET_CLIENT object that will contain the CLIENT objects to be monitored if they are alive or not (joined by a player).

  • Functional.Spawn#SPAWN SpawnAI : The default Spawn object to spawn new AI Groups when needed.

Return value

#AI_BALANCER:

AI_BALANCER.PatrolZones
AI_BALANCER.ReturnAirbaseSet
AI_BALANCER:ReturnToHomeAirbase(ReturnTresholdRange)

Returns the AI to the home Wrapper.Airbase#AIRBASE.

Parameter

AI_BALANCER:ReturnToNearestAirbases(ReturnTresholdRange, ReturnAirbaseSet)

Returns the AI to the nearest friendly Wrapper.Airbase#AIRBASE.

Parameters

AI_BALANCER.ReturnTresholdRange
Core.Set#SET_CLIENT AI_BALANCER.SetClient
Functional.Spawn#SPAWN AI_BALANCER.SpawnAI
Wrapper.Group#GROUP AI_BALANCER.Test
#boolean AI_BALANCER.ToHomeAirbase
#boolean AI_BALANCER.ToNearestAirbase
AI_BALANCER:onenterDestroying(SetGroup, AIGroup, From, Event, To, ClientName)

Parameters

AI_BALANCER:onenterMonitoring(SetGroup)

Parameter

  • SetGroup :

AI_BALANCER:onenterReturning(SetGroup, AIGroup, From, Event, To)

Parameters

AI_BALANCER:onenterSpawning(SetGroup, ClientName, AIGroup, From, Event, To)

Parameters