forked from FAForever/fa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAIAddBuilderTable.lua
80 lines (71 loc) · 3.53 KB
/
AIAddBuilderTable.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
--***************************************************************************
--** File : /lua/ai/AIAddBuilderTable.lua
--**
--** Summary : Default economic builders for skirmish
--**
--** Copyright © 2005 Gas Powered Games, Inc. All rights reserved.
--****************************************************************************
---@param aiBrain AIBrain
---@param locationType string
---@param baseBuilderName string
function AddGlobalBaseTemplate(aiBrain, locationType, baseBuilderName)
if not BaseBuilderTemplates[baseBuilderName] then
error('*AI ERROR: Invalid BaseBuilderTemplate: none found named - ' .. baseBuilderName)
end
for k,v in BaseBuilderTemplates[baseBuilderName].Builders do
AddGlobalBuilderGroup(aiBrain, locationType, v)
end
-- Cheating AI's don't have always OmniView, so we build NonCheaterBuilders for all AI's.
-- (OmniView is an ACU enhancement. If you lose your ACU, you will also lose OmniView.)
-- Also we don't need to save resources for cheat AI's since we can simply increase the AI Cheatfactor in options.
if BaseBuilderTemplates[baseBuilderName].NonCheatBuilders then
for k,v in BaseBuilderTemplates[baseBuilderName].NonCheatBuilders do
AddGlobalBuilderGroup(aiBrain, locationType, v)
end
end
aiBrain.BuilderManagers[locationType].BaseSettings = BaseBuilderTemplates[baseBuilderName].BaseSettings
end
---@param aiBrain AIBrain
---@param locationType string
---@param builderGroupName string
function AddGlobalBuilderGroup(aiBrain, locationType, builderGroupName)
if BuilderGroups[builderGroupName] then
AddBuilderTable(aiBrain, locationType, BuilderGroups[builderGroupName], builderGroupName)
else
WARN('['..string.gsub(debug.getinfo(1).source, ".*\\(.*.lua)", "%1")..', line:'..debug.getinfo(1).currentline..'] *AddGlobalBuilderGroup ERROR: BuilderGroup ' .. tostring(builderGroupName) .. ' does not exist!' )
end
end
---@param aiBrain AIBrain
---@param locationType string
---@param builderTable table
---@param tableName string
function AddBuilderTable(aiBrain, locationType, builderTable, tableName)
aiBrain.BuilderManagers[locationType].BuilderHandles = aiBrain.BuilderManagers[locationType].BuilderHandles or {}
aiBrain.BuilderManagers[locationType].BuilderHandles[tableName] = {}
local builders = aiBrain.BuilderManagers[locationType].BuilderHandles[tableName]
local managers = aiBrain.BuilderManagers[locationType]
local tableType, builderFunction
if builderTable.BuildersType == 'PlatoonFormBuilder' then
tableType = 'PlatoonFormManager'
elseif builderTable.BuildersType == 'EngineerBuilder' then
tableType = 'EngineerManager'
elseif builderTable.BuildersType == 'FactoryBuilder' then
tableType = 'FactoryManager'
elseif builderTable.BuildersType == 'StrategyBuilder' and managers.StrategyManager then
tableType = 'StrategyManager'
else
WARN('*AI ERROR: Invalid BuildersType ('..tostring(builderTable.BuildersType)..') for table of builder to add to brain')
return
end
for k,v in builderTable do
if k != 'BuildersType' and k != 'BuilderGroupName' then
if type(v) != 'string' then
error('*AI ERROR: Invalid builder type in BuilderGroup - ' .. tableName)
end
if not Builders[v] then
WARN('*AI ERROR: Invalid Builder named - ' .. v)
end
table.insert(builders, managers[tableType]:AddBuilder(Builders[v], locationType))
end
end
end