forked from FAForever/fa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEconomyBuildConditions.lua
More file actions
362 lines (324 loc) · 14.7 KB
/
EconomyBuildConditions.lua
File metadata and controls
362 lines (324 loc) · 14.7 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#****************************************************************************
#**
#** File : /lua/editor/EconomyBuildConditions.lua
#** Author(s): Dru Staltman, John Comes
#**
#** Summary : Generic AI Platoon Build Conditions
#** Build conditions always return true or false
#**
#** Copyright © 2005 Gas Powered Games, Inc. All rights reserved.
#****************************************************************************
local AIUtils = import('/lua/ai/aiutilities.lua')
local ScenarioFramework = import('/lua/scenarioframework.lua')
local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')
local BuildingTemplates = import('/lua/BuildingTemplates.lua')
##############################################################################################################
# function: GreaterThanEconStorageRatio = BuildCondition doc = "Please work function docs."
#
# parameter 0: string aiBrain = "default_brain"
# parameter 1: float mStorageRatio = 0.0 doc = "docs for param1"
# parameter 2: float eStorageRatio = 0.0 doc = "param2 docs"
#
##############################################################################################################
function GreaterThanEconStorageRatio(aiBrain, mStorageRatio, eStorageRatio)
local econ = AIUtils.AIGetEconomyNumbers(aiBrain)
if (econ.MassStorageRatio >= mStorageRatio and econ.EnergyStorageRatio >= eStorageRatio) then
return true
end
return false
end
##############################################################################################################
# function: GreaterThanEconStorageMax = BuildCondition doc = "Please work function docs."
#
# parameter 0: string aiBrain = "default_brain"
# parameter 1: int mStorage = 0 doc = "docs for param1"
# parameter 2: int eStorage = 0 doc = "param2 docs"
#
##############################################################################################################
function GreaterThanEconStorageMax(aiBrain, mStorage, eStorage)
local econ = AIUtils.AIGetEconomyNumbers(aiBrain)
if (econ.MassMaxStored >= mStorage and econ.EnergyMaxStored >= eStorage) then
return true
end
return false
end
##############################################################################################################
# function: GreaterThanEconStorageCurrent = BuildCondition doc = "Please work function docs."
#
# parameter 0: string aiBrain = "default_brain" doc = "docs for param1"
# parameter 1: integer mStorage = 0 doc = "docs for param1"
# parameter 2: integer eStorage = 0 doc = "param2 docs"
#
##############################################################################################################
function GreaterThanEconStorageCurrent(aiBrain, mStorage, eStorage)
local econ = AIUtils.AIGetEconomyNumbers(aiBrain)
if (econ.MassStorage >= mStorage and econ.EnergyStorage >= eStorage) then
return true
end
return false
end
##############################################################################################################
# function: LessThanEconTrend = BuildCondition doc = "Please work function docs."
#
# parameter 0: string aiBrain = "default_brain" doc = "docs for param1"
# parameter 1: integer mTrend = 0 doc = "docs for param1"
# parameter 2: integer eTrend = 0 doc = "param2 docs"
#
##############################################################################################################
function LessThanEconTrend(aiBrain, mTrend, eTrend)
local econ = AIUtils.AIGetEconomyNumbers(aiBrain)
if (econ.MassTrend < mTrend and econ.EnergyTrend < eTrend) then
return true
else
return false
end
end
##############################################################################################################
# function: LessThanEconStorageRatio = BuildCondition doc = "Please work function docs."
#
# parameter 0: string aiBrain = "default_brain" doc = "docs for param1"
# parameter 1: integer mStorageRatio = 0 doc = "docs for param1"
# parameter 2: integer eStorageRatio = 0 doc = "param2 docs"
#
##############################################################################################################
function LessThanEconStorageRatio(aiBrain, mStorageRatio, eStorageRatio)
local econ = AIUtils.AIGetEconomyNumbers(aiBrain)
if (econ.MassStorageRatio < mStorageRatio and econ.EnergyStorageRatio < eStorageRatio) then
return true
end
return false
end
##############################################################################################################
# function: LessEconStorageMax = BuildCondition doc = "Please work function docs."
#
# parameter 0: string aiBrain = "default_brain" doc = "docs for param1"
# parameter 1: integer mStorage = 0 doc = "docs for param1"
# parameter 2: integer eStorage = 0 doc = "param2 docs"
#
##############################################################################################################
function LessEconStorageMax(aiBrain, mStorage, eStorage)
local econ = AIUtils.AIGetEconomyNumbers(aiBrain)
if (econ.MassMaxStored < mStorage and econ.EnergyMaxStored < eStorage) then
return true
end
return false
end
##############################################################################################################
# function: LessEconStorageCurrent = BuildCondition doc = "Please work function docs."
#
# parameter 0: string aiBrain = "default_brain" doc = "docs for param1"
# parameter 1: integer mStorage = 0 doc = "docs for param1"
# parameter 2: integer eStorage = 0 doc = "param2 docs"
#
##############################################################################################################
function LessEconStorageCurrent(aiBrain, mStorage, eStorage)
local econ = AIUtils.AIGetEconomyNumbers(aiBrain)
if (econ.MassStorage < mStorage and econ.EnergyStorage < eStorage) then
return true
end
return false
end
##############################################################################################################
# function: GreaterThanEconTrend = BuildCondition doc = "Please work function docs."
#
# parameter 0: string aiBrain = "default_brain" doc = "docs for param1"
# parameter 1: int MassTrend = 1 doc = "docs for param1"
# parameter 2: int EnergyTrend = 1 doc = "param2 docs"
#
##############################################################################################################
function GreaterThanEconTrend(aiBrain, MassTrend, EnergyTrend)
local econ = AIUtils.AIGetEconomyNumbers(aiBrain)
if (econ.MassTrend >= MassTrend and econ.EnergyTrend >= EnergyTrend) then
return true
end
return false
end
##############################################################################################################
# function: GreaterThanEconIncome = BuildCondition doc = "Please work function docs."
#
# parameter 0: string aiBrain = "default_brain" doc = "docs for param1"
# parameter 1: int MassIncome = 0.1 doc = "docs for param1"
# parameter 2: int EnergyIncome = 1 doc = "param2 docs"
#
##############################################################################################################
function GreaterThanEconIncome(aiBrain, MassIncome, EnergyIncome)
if HaveGreaterThanUnitsWithCategory(aiBrain, 0, 'ENERGYPRODUCTION EXPERIMENTAL STRUCTURE') then
#LOG('*AI DEBUG: Found Paragon')
return true
end
local econ = AIUtils.AIGetEconomyNumbers(aiBrain)
if (econ.MassIncome >= MassIncome and econ.EnergyIncome >= EnergyIncome) then
return true
end
return false
end
##############################################################################################################
# function: LessThanEconIncome = BuildCondition doc = "Please work function docs."
#
# parameter 0: string aiBrain = "default_brain" doc = "docs for param1"
# parameter 1: int MassIncome = 0.1 doc = "docs for param1"
# parameter 2: int EnergyIncome = 1 doc = "param2 docs"
#
##############################################################################################################
function LessThanEconIncome(aiBrain, MassIncome, EnergyIncome)
if HaveGreaterThanUnitsWithCategory(aiBrain, 0, 'ENERGYPRODUCTION EXPERIMENTAL STRUCTURE') then
#LOG('*AI DEBUG: Found Paragon')
return false
end
local econ = AIUtils.AIGetEconomyNumbers(aiBrain)
if (econ.MassIncome < MassIncome and econ.EnergyIncome < EnergyIncome) then
return true
end
return false
end
##############################################################################################################
# function: LessThanEconEfficiency = BuildCondition doc = "Please work function docs."
#
# parameter 0: string aiBrain = "default_brain" doc = "docs for param1"
# parameter 1: int MassEfficiency = 1 doc = "docs for param1"
# parameter 2: int EnergyEfficiency = 1 doc = "param2 docs"
#
##############################################################################################################
function GreaterThanEconEfficiency(aiBrain, MassEfficiency, EnergyEfficiency)
if HaveGreaterThanUnitsWithCategory(aiBrain, 0, 'ENERGYPRODUCTION EXPERIMENTAL STRUCTURE') then
#LOG('*AI DEBUG: Found Paragon')
return true
end
local econ = AIUtils.AIGetEconomyNumbers(aiBrain)
if (econ.MassEfficiency >= MassEfficiency and econ.EnergyEfficiency >= EnergyEfficiency) then
return true
end
return false
end
function LessThanEconEfficiency(aiBrain, MassEfficiency, EnergyEfficiency)
if HaveGreaterThanUnitsWithCategory(aiBrain, 0, 'ENERGYPRODUCTION EXPERIMENTAL STRUCTURE') then
#LOG('*AI DEBUG: Found Paragon')
return false
end
local econ = AIUtils.AIGetEconomyNumbers(aiBrain)
if (econ.MassEfficiency <= MassEfficiency and econ.EnergyEfficiency <= EnergyEfficiency) then
return true
end
return false
end
##############################################################################################################
# function: LessThanEconEfficiencyOverTime = BuildCondition doc = "Please work function docs."
#
# parameter 0: string aiBrain = "default_brain" doc = "docs for param1"
# parameter 1: int MassEfficiency = 1 doc = "docs for param1"
# parameter 2: int EnergyEfficiency = 1 doc = "param2 docs"
#
##############################################################################################################
function GreaterThanEconEfficiencyOverTime(aiBrain, MassEfficiency, EnergyEfficiency)
if HaveGreaterThanUnitsWithCategory(aiBrain, 0, 'ENERGYPRODUCTION EXPERIMENTAL STRUCTURE') then
#LOG('*AI DEBUG: Found Paragon')
return true
end
local econ = AIUtils.AIGetEconomyNumbers(aiBrain)
if (econ.MassEfficiencyOverTime >= MassEfficiency and econ.EnergyEfficiencyOverTime >= EnergyEfficiency) then
return true
end
return false
end
function LessThanEconEfficiencyOverTime(aiBrain, MassEfficiency, EnergyEfficiency)
if HaveGreaterThanUnitsWithCategory(aiBrain, 0, 'ENERGYPRODUCTION EXPERIMENTAL STRUCTURE') then
#LOG('*AI DEBUG: Found Paragon')
return false
end
local econ = AIUtils.AIGetEconomyNumbers(aiBrain)
if (econ.MassEfficiencyOverTime <= MassEfficiency and econ.EnergyEfficiencyOverTime <= EnergyEfficiency) then
return true
end
return false
end
function MassIncomeToUnitRatio(aiBrain, ratio, compareType, unitCategory)
local econTime = aiBrain:GetEconomyOverTime()
local testCat = unitCategory
if type(testCat) == 'string' then
testCat = ParseEntityCategory(testCat)
end
local unitCount = aiBrain:GetCurrentUnits(testCat)
# Find units of this type being built or about to be built
unitCount = unitCount + aiBrain:GetEngineerManagerUnitsBeingBuilt(testCat)
local checkRatio = (econTime.MassIncome * 10) / unitCount
return CompareBody(checkRatio, ratio, compareType)
end
function GreaterThanMassIncomeToFactory(aiBrain, t1Drain, t2Drain, t3Drain)
local econTime = aiBrain:GetEconomyOverTime()
# T1 Test
local testCat = categories.TECH1 * categories.FACTORY
local unitCount = aiBrain:GetCurrentUnits(testCat)
# Find units of this type being built or about to be built
unitCount = unitCount + aiBrain:GetEngineerManagerUnitsBeingBuilt(testCat)
local massTotal = unitCount * t1Drain
# T2 Test
testCat = categories.TECH2 * categories.FACTORY
unitCount = aiBrain:GetCurrentUnits(testCat)
massTotal = massTotal + (unitCount * t2Drain)
# T3 Test
testCat = categories.TECH3 * categories.FACTORY
unitCount = aiBrain:GetCurrentUnits(testCat)
massTotal = massTotal + (unitCount * t3Drain)
if not CompareBody((econTime.MassIncome * 10), massTotal, '>') then
return false
end
return true
end
function MassToFactoryRatioBaseCheck(aiBrain, locationType)
local factoryManager = aiBrain.BuilderManagers[locationType].FactoryManager
if not factoryManager then
WARN('*AI WARNING: FactoryCapCheck - Invalid location - ' .. locationType)
return false
end
local t1 = aiBrain.BuilderManagers[locationType].BaseSettings.MassToFactoryValues.T1Value or 8
local t2 = aiBrain.BuilderManagers[locationType].BaseSettings.MassToFactoryValues.T2Value or 20
local t3 = aiBrain.BuilderManagers[locationType].BaseSettings.MassToFactoryValues.T3Value or 30
return GreaterThanMassIncomeToFactory(aiBrain, t1, t2, t3)
end
function CompareBody(numOne, numTwo, compareType)
if compareType == '>' then
if numOne > numTwo then
return true
end
elseif compareType == '<' then
if numOne < numTwo then
return true
end
elseif compareType == '>=' then
if numOne >= numTwo then
return true
end
elseif compareType == '<=' then
if numOne <= numTwo then
return true
end
else
error('*AI ERROR: Invalid compare type: ' .. compareType)
return false
end
return false
end
function HaveGreaterThanUnitsWithCategory(aiBrain, numReq, category, idleReq)
local numUnits
local total = 0
if type(category) == 'string' then
category = ParseEntityCategory(category)
end
if not idleReq then
numUnits = aiBrain:GetListOfUnits(category, false)
else
numUnits = aiBrain:GetListOfUnits(category, true)
end
for k,v in numUnits do
if v:GetFractionComplete() == 1 then
total = total + 1
if total > numReq then
return true
end
end
end
if total > numReq then
return true
end
return false
end