forked from FAForever/fa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrategyBuilder.lua
More file actions
111 lines (97 loc) · 3.2 KB
/
StrategyBuilder.lua
File metadata and controls
111 lines (97 loc) · 3.2 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
#***************************************************************************
#*
#** File : /lua/sim/StrategyBuilder.lua
#**
#** Summary : Strategy Builder class
#**
#** Copyright © 2007 Gas Powered Games, Inc. All rights reserved.
#****************************************************************************
local AIUtils = import('/lua/ai/aiutilities.lua')
local Builder = import('/lua/sim/Builder.lua').Builder
# StrategyBuilderSpec
# This is the spec to have analyzed by the StrategyManager
#{
# BuilderData = {
# Some stuff could go here, eventually.
# }
#}
StrategyBuilder = Class(Builder) {
Create = function(self,brain,data,locationType)
Builder.Create(self,brain,data,locationType)
self:SetStrategyActive(false)
return true
end,
SetStrategyActive = function(self, bool)
if bool then
self.Active = true
if Builders[self.BuilderName].OnStrategyActivate then
Builders[self.BuilderName]:OnStrategyActivate(self.Brain)
end
else
self.Active = false
if Builders[self.BuilderName].OnStrategyDeactivate then
Builders[self.BuilderName]:OnStrategyDeactivate(self.Brain)
end
end
end,
IsStrategyActive = function(self)
return self.Active
end,
GetActivateBuilders = function(self)
if Builders[self.BuilderName].AddBuilders then
return Builders[self.BuilderName].AddBuilders
end
return false
end,
GetRemoveBuilders = function(self)
if Builders[self.BuilderName].RemoveBuilders then
return Builders[self.BuilderName].RemoveBuilders
end
return false
end,
GetStrategyTime = function(self)
if Builders[self.BuilderName].StrategyTime then
return Builders[self.BuilderName].StrategyTime
end
return false
end,
IsInterruptStrategy = function(self)
if Builders[self.BuilderName].InterruptStrategy then
return true
end
return false
end,
GetStrategyType = function(self)
if Builders[self.BuilderName].StrategyType then
return Builders[self.BuilderName].StrategyType
end
return false
end,
CalculatePriority = function(self, builderManager)
self.PriorityAltered = false
# Builders can have a function to update the priority
if Builders[self.BuilderName].PriorityFunction then
local newPri = Builders[self.BuilderName]:PriorityFunction(self.Brain)
if newPri > 100 then
newPri = 100
elseif newPri < 0 then
newPri = 0
end
if newPri != self.Priority then
self.Priority = newPri
self.SetByStrat = true
self.PriorityAltered = true
end
end
# Returns true if a priority change happened
local returnVal = self.PriorityAltered
return returnVal
end,
}
function CreateStrategy(brain, data, locationType)
local builder = StrategyBuilder()
if builder:Create(brain, data, locationType) then
return builder
end
return false
end