There is only 1 place to start
The commander has it's own permanent command thread running.
This thread is initialized in the first platoon builder:
- Code: Select all
BuilderGroupName = 'Initial ACU Builders Uveso', -- BuilderGroupName, "\lua\AI\AIBaseTemplates\"
BuildersType = 'EngineerBuilder',
Builder {
BuilderName = 'UC CDR Initial Default',
PlatoonAddBehaviors = { 'CommanderBehaviorUveso', },
PlatoonTemplate = 'CommanderBuilder',
Priority = 19500,
BuilderConditions = {
{ IBC, 'NotPreBuilt', {}},
},
InstantCheck = true,
BuilderType = 'Any',
PlatoonAddFunctions = { {SAI, 'BuildOnce'}, },
BuilderData = {
Construction = {
AdjacencyCategory = 'MASSEXTRACTION, FACTORY CONSTRUCTION',
AdjacencyDistance = 50,
BuildStructures = {
'T1LANDFactory',
'T1EnergyProduction',
'T1EnergyProduction',
'T1EnergyProduction',
}
}
}
},
Here we can see that this builder has an additional "Behavior" function:
- Code: Select all
PlatoonAddBehaviors = { 'CommanderBehaviorUveso', },
This means that we not only start building energy and (start)factory, we also add a programm thread to the ACU called "CommanderBehaviorUveso".
It's the same mechanic that we use for air planes (watching for refuel etc.)
This leads us to the file "AIBeahviors.lua" where the function "CommanderBehaviorUveso" is located:
- Code: Select all
[...]\Mods\AI-Uveso\hook\lua\AI\AIBehaviors.lua
Here you can find and edit the CommanderBehaviorThread.
There are already 2 main functions present:
- Code: Select all
-- Go back to base
if not cdr.Dead then
CDRReturnHomeUveso(aiBrain, cdr)
end
The upper part is calling the function CDRReturnHomeUveso() and is used to return the commander to the base if he is more then 50 map units away from base.
- Code: Select all
-- Call platoon resume building deal...
if not cdr.Dead and cdr:IsIdleState() then
if not cdr.EngineerBuildQueue or table.getn(cdr.EngineerBuildQueue) == 0 then
--LOG('* CommanderThreadUveso: Idle and no BuildQueue')
local pool = aiBrain:GetPlatoonUniquelyNamed('ArmyPool')
aiBrain:AssignUnitsToPlatoon( pool, {cdr}, 'Unassigned', 'None' )
elseif cdr.EngineerBuildQueue and table.getn(cdr.EngineerBuildQueue) != 0 then
--LOG('* CommanderThreadUveso: Idle and BuildQueue')
if not cdr.NotBuildingThread then
cdr.NotBuildingThread = cdr:ForkThread(platoon.WatchForNotBuilding)
end
end
end
This part is the build function in case a Builder is assingning a buildplatoon to the commander. (don't change it or the ACU will not build anything)
Now you can add functions like the "Go back to base" behavior.
For more examples see the sorian
AI thread:
https://github.com/FAForever/fa/blob/develop/lua/AI/AIBehaviors.lua#L1978[Edit] You can't start ACU-upgrades or enhancments form this thread. They will be initalized with platoonbuilders like here:
https://github.com/FAForever/fa/blob/develop/lua/AI/AIBuilders/AIEconomicBuilders.lua#L741