The difficulty.One of the main addition to FA campaign AI was the reaive AI.
The reactive AI is what produce most of the attack waves.
If you look at any FA campaign (in your map folder), you will see a serie of "m<number>AiName.lua".
These are the AI scripts for different missions part and ai brain.
Let's take mission 2 part 1 as exemple.
The only AI at that point is "The order". The file used is :m1orderai.lua.
It's imported in the main _script.lua file :
- Code: Select all
local M1OrderAI = import('/maps/X1CA_Coop_001_v06/X1CA_Coop_001_v06_m1orderai.lua')
As it's on startup, the AI is created in the startup script. For others parts, they are defined in each mission intro/setup.
- Code: Select all
# -----------
# Order M1 AI
# -----------
M1OrderAI.OrderM1WestBaseAI()
M1OrderAI.OrderM1EastBaseAI()
Because the Order has two bases (west and east).
So in the AI script (m1orderai.lua):
- Code: Select all
# -------------
# Base Managers
# -------------
local OrderM1WestBase = BaseManager.CreateBaseManager()
local OrderM1EastBase = BaseManager.CreateBaseManager()
That initialize the AI for both base.
- Code: Select all
function OrderM1WestBaseAI()
Is the function called in _script.lua.
- Code: Select all
local opai = OrderM1WestBase:AddReactiveAI('ExperimentalLand', 'AirRetaliation', 'OrderM1WestBase_ExperimentalLand')
opai:SetChildActive('HeavyGunships', false)
opai:SetChildActive('StrategicBombers', false)
These are the reactive AI.
What it means is that if the player is building an experimental, the AI will send some air, but without the HeavyGunships and StrategicBombers (these are presets).
That's probably the main thing you want to add.
At the end of that function, we have:
- Code: Select all
OrderM1WestBaseAirAttacks()
It call another function that set up air attacks:
- Code: Select all
# -------------------------------------
# Order M1 West Base Op AI, Air Attacks
# -------------------------------------
# sends 2, 4, 6 [bombers]
quantity = {2, 4, 6}
opai = OrderM1WestBase:AddOpAI('AirAttacks', 'M1_WestAirAttack1',
{
MasterPlatoonFunction = {SPAIFileName, 'PatrolChainPickerThread'},
PlatoonData = {
PatrolChains = {'M1_Order_W_AirAttack_1_Chain', 'M1_Order_W_AirAttack_2_Chain', 'M1_Order_W_AirAttack_3_Chain'},
},
Priority = 90,
}
)
# using quantity count based on difficulty for number of units sent in per group
opai:SetChildQuantity('Bombers', quantity[Difficulty])
It's quite self-explanatory.
"AirAttacks" is the type of attack.
'M1_WestAirAttack1', is an unique name for the attack (same as OrderM1WestBase_ExperimentalLand in the ReactiveAI)
- Code: Select all
MasterPlatoonFunction = {SPAIFileName, 'PatrolChainPickerThread'},
It's what the platoon will do. In this case, it will patrol around some waypoint. You have to inspect the existing FA campaign scripts to see what is possible (attacks, random patrols, ...)
- Code: Select all
PatrolChains = {'M1_Order_W_AirAttack_1_Chain', 'M1_Order_W_AirAttack_2_Chain', 'M1_Order_W_AirAttack_3_Chain'},
It's the patrol of the attack. These are waypoints defined in the _save.lua (Domino editor will create them easily).
You should either create new waypoints, or use existing one in the vanilla maps.
opai:SetChildQuantity('Bombers', quantity[Difficulty]) define the quantity of bombers depending of the difficulty. It's defined here:
- Code: Select all
quantity = {2, 4, 6}
I think altering vanilla maps to add these AI is a good starting point to learn how to script a campaign.
Feel free to ask questions here!
In order to test your map, you can make a copy of it and start FA from
c:\ProgramData\FAForever\bin\
with
- Code: Select all
ForgedAlliance.exe /init init_coop.lua
Then select your map. You don't need to restart FA each time you modify a script. You can just restart the map inside FA.