-
-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathCpAIBunkerSiloWorker.lua
More file actions
161 lines (135 loc) · 6.99 KB
/
Copy pathCpAIBunkerSiloWorker.lua
File metadata and controls
161 lines (135 loc) · 6.99 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
--- This spec is only for overwriting giants function of the AIFieldWorker.
local modName = CpAIBunkerSiloWorker and CpAIBunkerSiloWorker.MOD_NAME -- for reload
---@class CpAIBunkerSiloWorker
CpAIBunkerSiloWorker = {}
CpAIBunkerSiloWorker.startText = g_i18n:getText("CP_fieldWorkJobParameters_startAt_bunkerSilo")
CpAIBunkerSiloWorker.MOD_NAME = g_currentModName or modName
CpAIBunkerSiloWorker.NAME = ".cpAIBunkerSiloWorker"
CpAIBunkerSiloWorker.SPEC_NAME = CpAIBunkerSiloWorker.MOD_NAME .. CpAIBunkerSiloWorker.NAME
CpAIBunkerSiloWorker.KEY = "."..CpAIBunkerSiloWorker.MOD_NAME..CpAIBunkerSiloWorker.NAME
function CpAIBunkerSiloWorker.initSpecialization()
local schema = Vehicle.xmlSchemaSavegame
local key = "vehicles.vehicle(?)" .. CpAIBunkerSiloWorker.KEY
CpJobParameters.registerXmlSchema(schema, key..".cpJob")
end
function CpAIBunkerSiloWorker.prerequisitesPresent(specializations)
return SpecializationUtil.hasSpecialization(CpAIWorker, specializations)
end
function CpAIBunkerSiloWorker.register(typeManager,typeName,specializations)
if CpAIBunkerSiloWorker.prerequisitesPresent(specializations) then
typeManager:addSpecialization(typeName, CpAIBunkerSiloWorker.SPEC_NAME)
end
end
function CpAIBunkerSiloWorker.registerEventListeners(vehicleType)
SpecializationUtil.registerEventListener(vehicleType, 'onLoad', CpAIBunkerSiloWorker)
SpecializationUtil.registerEventListener(vehicleType, 'onLoadFinished', CpAIBunkerSiloWorker)
SpecializationUtil.registerEventListener(vehicleType, 'onReadStream', CpAIBunkerSiloWorker)
SpecializationUtil.registerEventListener(vehicleType, 'onWriteStream', CpAIBunkerSiloWorker)
end
function CpAIBunkerSiloWorker.registerFunctions(vehicleType)
SpecializationUtil.registerFunction(vehicleType, "getCanStartCpBunkerSiloWorker", CpAIBunkerSiloWorker.getCanStartCpBunkerSiloWorker)
SpecializationUtil.registerFunction(vehicleType, "getCpBunkerSiloWorkerJobParameters", CpAIBunkerSiloWorker.getCpBunkerSiloWorkerJobParameters)
SpecializationUtil.registerFunction(vehicleType, "applyCpBunkerSiloWorkerJobParameters", CpAIBunkerSiloWorker.applyCpBunkerSiloWorkerJobParameters)
SpecializationUtil.registerFunction(vehicleType, "getCpBunkerSiloWorkerJob", CpAIBunkerSiloWorker.getCpBunkerSiloWorkerJob)
end
function CpAIBunkerSiloWorker.registerOverwrittenFunctions(vehicleType)
SpecializationUtil.registerOverwrittenFunction(vehicleType, 'getCanStartCp', CpAIBunkerSiloWorker.getCanStartCp)
SpecializationUtil.registerOverwrittenFunction(vehicleType, 'getCpStartableJob', CpAIBunkerSiloWorker.getCpStartableJob)
SpecializationUtil.registerOverwrittenFunction(vehicleType, 'startCpAtFirstWp', CpAIBunkerSiloWorker.startCpAtFirstWp)
SpecializationUtil.registerOverwrittenFunction(vehicleType, 'startCpAtLastWp', CpAIBunkerSiloWorker.startCpAtLastWp)
end
-- shortcut to access the spec
function CpAIBunkerSiloWorker.getSpec(self)
return self["spec_" .. CpAIBunkerSiloWorker.SPEC_NAME]
end
------------------------------------------------------------------------------------------------------------------------
--- Event listeners
---------------------------------------------------------------------------------------------------------------------------
function CpAIBunkerSiloWorker:onLoad(savegame)
local spec = CpAIBunkerSiloWorker.getSpec(self)
--- This job is for starting the driving with a key bind or the mini gui.
spec.cpJob = g_currentMission.aiJobTypeManager:createJob(AIJobType.BUNKER_SILO_CP)
spec.cpJob:setVehicle(self, true)
end
function CpAIBunkerSiloWorker:onLoadFinished(savegame)
local spec = CpAIBunkerSiloWorker.getSpec(self)
if savegame ~= nil then
spec.cpJob:loadFromXMLFile(savegame.xmlFile, savegame.key.. CpAIBunkerSiloWorker.KEY..".cpJob")
end
end
function CpAIBunkerSiloWorker:saveToXMLFile(xmlFile, baseKey, usedModNames)
local spec = CpAIBunkerSiloWorker.getSpec(self)
spec.cpJob:saveToXMLFile(xmlFile, baseKey.. ".cpJob")
end
function CpAIBunkerSiloWorker:onReadStream(streamId, connection)
local spec = CpAIBunkerSiloWorker.getSpec(self)
spec.cpJob:readStream(streamId, connection)
end
function CpAIBunkerSiloWorker:onWriteStream(streamId, connection)
local spec = CpAIBunkerSiloWorker.getSpec(self)
spec.cpJob:writeStream(streamId, connection)
end
--- Is the bunker silo allowed?
function CpAIBunkerSiloWorker:getCanStartCpBunkerSiloWorker()
return not self:getCanStartCpFieldWork()
and not self:getCanStartCpBaleFinder()
and not self:getCanStartCpCombineUnloader()
and not self:getCanStartCpSiloLoaderWorker()
end
function CpAIBunkerSiloWorker:getCanStartCp(superFunc)
return superFunc(self) or self:getCanStartCpBunkerSiloWorker()
end
function CpAIBunkerSiloWorker:getCpStartableJob(superFunc, isStartedByHud)
local spec = CpAIBunkerSiloWorker.getSpec(self)
if isStartedByHud and self:cpIsHudBunkerSiloJobSelected() then
return self:getCanStartCpBunkerSiloWorker() and spec.cpJob
end
return superFunc(self, isStartedByHud) or not isStartedByHud and self:getCanStartCpBunkerSiloWorker() and spec.cpJob
end
function CpAIBunkerSiloWorker:getCpBunkerSiloWorkerJobParameters()
local spec = CpAIBunkerSiloWorker.getSpec(self)
return spec.cpJob:getCpJobParameters()
end
function CpAIBunkerSiloWorker:applyCpBunkerSiloWorkerJobParameters(job)
local spec = CpAIBunkerSiloWorker.getSpec(self)
spec.cpJob:getCpJobParameters():validateSettings()
spec.cpJob:copyFrom(job)
end
function CpAIBunkerSiloWorker:getCpBunkerSiloWorkerJob()
local spec = CpAIBunkerSiloWorker.getSpec(self)
return spec.cpJob
end
--- Starts the cp driver at the first waypoint.
function CpAIBunkerSiloWorker:startCpAtFirstWp(superFunc, ...)
if not superFunc(self, ...) then
if self:getCanStartCpBunkerSiloWorker() then
local spec = CpAIBunkerSiloWorker.getSpec(self)
spec.cpJob:applyCurrentState(self, g_currentMission, g_currentMission.playerSystem:getLocalPlayer().farmId, true)
spec.cpJob:setValues()
local success = spec.cpJob:validate(false)
if success then
g_client:getServerConnection():sendEvent(AIJobStartRequestEvent.new(spec.cpJob, self:getOwnerFarmId()))
return true
end
end
else
return true
end
end
--- Starts the cp driver at the last driven waypoint.
function CpAIBunkerSiloWorker:startCpAtLastWp(superFunc, ...)
if not superFunc(self, ...) then
if self:getCanStartCpBunkerSiloWorker() then
local spec = CpAIBunkerSiloWorker.getSpec(self)
spec.cpJob:applyCurrentState(self, g_currentMission, g_currentMission.playerSystem:getLocalPlayer().farmId, true)
spec.cpJob:setValues()
local success = spec.cpJob:validate(false)
if success then
g_client:getServerConnection():sendEvent(AIJobStartRequestEvent.new(spec.cpJob, self:getOwnerFarmId()))
return true
end
end
else
return true
end
end