Module AI.AI_Balancer
AI - Balance player slots with AI to create an engaging simulation environment, independent of the amount of players.
Features:
- Automatically spawn AI as a replacement of free player slots for a coalition.
- Make the AI to perform tasks.
- Define a maximum amount of AI to be active at the same time.
- Configure the behaviour of AI when a human joins a slot for which an AI is active.
Demo Missions
YouTube Playlist
Author: FlightControl
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 :-)
Global(s)
Global AI_BALANCER |
Monitors and manages as many replacement AI groups as there are CLIENTS in a SET_CLIENT collection, which are not occupied by human players. |
Monitors and manages as many replacement AI groups as there are CLIENTS in a SET_CLIENT collection, which are not occupied by human players.
In other words, use AI_BALANCER to simulate human behaviour by spawning in replacement AI in multi player missions.
The parent class Core.Fsm#FSM_SET manages the functionality to control the Finite State Machine (FSM). The mission designer can tailor the behaviour of the AI_BALANCER, by defining event and state transition methods. An explanation about state and event transition methods can be found in the Core.Fsm module documentation.
The mission designer can tailor the AI_BALANCER behaviour, by implementing a state or event handling method for the following:
- AI_BALANCER.OnAfterSpawned( AISet, From, Event, To, AIGroup ): Define to add extra logic when an AI is spawned.
1. AI_BALANCER construction
Create a new AI_BALANCER object with the AI_BALANCER.New() method:
2. AI_BALANCER is a FSM
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.
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.
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.
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:
- AI_BALANCER.ReturnToHomeAirbase: Returns the AI to the home Wrapper.Airbase#AIRBASE.
- AI_BALANCER.ReturnToNearestAirbases: Returns the AI to the nearest friendly Wrapper.Airbase#AIRBASE.
Note that when AI returns to an airbase, the AI_BALANCER will trigger the Return event and the AI will return, otherwise the AI_BALANCER will trigger a Destroy event, and the AI will be destroyed.
Developer Note
Note while this class still works, it is no longer supported as the original author stopped active development of MOOSE Therefore, this class is considered to be deprecated
Type(s)
Fields and Methods inherited from AI_BALANCER | Description |
---|---|
Sets the earliest to the latest interval in seconds how long AI_BALANCER will wait to spawn a new AI. |
|
Creates a new AI_BALANCER object |
|
Returns the AI to the home Wrapper.Airbase#AIRBASE. |
|
AI_BALANCER:ReturnToNearestAirbases(ReturnThresholdRange, ReturnAirbaseSet) |
Returns the AI to the nearest friendly Wrapper.Airbase#AIRBASE. |
AI_BALANCER:onenterDestroying(SetGroup, AIGroup, From, Event, To, ClientName) |
AI_BALANCER:onenterDestroying |
AI_BALANCER:onenterMonitoring |
|
AI_BALANCER:onenterReturning(SetGroup, From, Event, To, AIGroup) |
RTB |
AI_BALANCER:onenterSpawning(SetGroup, ClientName, AIGroup, From, Event, To) |
AI_BALANCER:onenterSpawning |
Field(s)
Function(s)
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.
Defined in:
AI_BALANCER
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
Creates a new AI_BALANCER object
Defined in:
AI_BALANCER
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).
Core.Spawn#SPAWN SpawnAI
The default Spawn object to spawn new AI Groups when needed.
Return value:
Returns the AI to the home Wrapper.Airbase#AIRBASE.
Defined in:
AI_BALANCER
Parameter:
DCS#Distance ReturnThresholdRange
If there is an enemy Wrapper.Client#CLIENT within the ReturnThresholdRange given in meters, the AI will not return to the nearest Wrapper.Airbase#AIRBASE.
Returns the AI to the nearest friendly Wrapper.Airbase#AIRBASE.
Defined in:
AI_BALANCER
Parameters:
DCS#Distance ReturnThresholdRange
If there is an enemy Wrapper.Client#CLIENT within the ReturnThresholdRange given in meters, the AI will not return to the nearest Wrapper.Airbase#AIRBASE.
Core.Set#SET_AIRBASE ReturnAirbaseSet
The SET of Core.Set#SET_AIRBASEs to evaluate where to return to.
AI_BALANCER:onenterDestroying
Defined in:
AI_BALANCER
Parameters:
Core.Set#SET_GROUP SetGroup
Wrapper.Group#GROUP AIGroup
From
Event
To
ClientName
AI_BALANCER:onenterMonitoring
Defined in:
AI_BALANCER
Parameter:
SetGroup
RTB
Defined in:
AI_BALANCER
Parameters:
Core.Set#SET_GROUP SetGroup
#string From
#string Event
#string To
Wrapper.Group#GROUP AIGroup
AI_BALANCER:onenterSpawning
Defined in:
AI_BALANCER
Parameters:
Core.Set#SET_GROUP SetGroup
#string ClientName
Wrapper.Group#GROUP AIGroup
From
Event
To