LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

ProductionChainManager

Description
This class handles the interaction between Production- and/or SellingPoints
Parent
AbstractManager
Functions

addProductionPoint

Description
Definition
addProductionPoint()
Code
73function ProductionChainManager:addProductionPoint(productionPoint)
74 if self.reverseProductionPoint[productionPoint] then
75 printf("Warning: Production point '%s' already registered.", productionPoint:tableId())
76 return false
77 end
78 if #self.productionPoints >= ProductionChainManager.NUM_MAX_PRODUCTION_POINTS then
79 printf("Maximum number of %i Production Points reached.", ProductionChainManager.NUM_MAX_PRODUCTION_POINTS)
80 return false
81 end
82
83 if #self.productionPoints == 0 and self.isServer then
84 g_currentMission:addUpdateable(self)
85 end
86
87 self.reverseProductionPoint[productionPoint] = true
88 table.insert(self.productionPoints, productionPoint)
89
90--#debug if self.debugEnabled then
91--#debug g_currentMission:addDrawable(productionPoint)
92--#debug end
93
94 local farmId = productionPoint:getOwnerFarmId()
95 if farmId ~= AccessHandler.EVERYONE then
96 if not self.farmIds[farmId] then
97 self.farmIds[farmId] = {}
98 end
99 self:addProductionPointToFarm(productionPoint, self.farmIds[farmId])
100 end
101 return true
102end

addProductionPointToFarm

Description
Definition
addProductionPointToFarm()
Code
106function ProductionChainManager:addProductionPointToFarm(productionPoint, farmTable)
107 if not farmTable.productionPoints then
108 farmTable.productionPoints = {}
109 end
110 table.insert(farmTable.productionPoints, productionPoint)
111
112 if not farmTable.inputTypeToProductionPoints then
113 farmTable.inputTypeToProductionPoints = {}
114 end
115
116 for inputType in pairs(productionPoint.inputFillTypeIds) do
117 if not farmTable.inputTypeToProductionPoints[inputType] then
118 farmTable.inputTypeToProductionPoints[inputType] = {}
119 end
120 table.insert(farmTable.inputTypeToProductionPoints[inputType], productionPoint)
121 end
122end

getHasFreeSlots

Description
Definition
getHasFreeSlots()
Code
181function ProductionChainManager:getHasFreeSlots()
182 return #self.productionPoints < ProductionChainManager.NUM_MAX_PRODUCTION_POINTS
183end

getNumOfProductionPoints

Description
Definition
getNumOfProductionPoints()
Code
175function ProductionChainManager:getNumOfProductionPoints()
176 return #self.productionPoints
177end

getProductionPointsForFarmId

Description
Definition
getProductionPointsForFarmId()
Code
169function ProductionChainManager:getProductionPointsForFarmId(farmId)
170 return self.farmIds[farmId] and self.farmIds[farmId].productionPoints or {}
171end

hourChanged

Description
Definition
hourChanged()
Code
226function ProductionChainManager:hourChanged()
227 self.hourChangedDirty = true
228end

initDataStructures

Description
Initialize data structures
Definition
initDataStructures()
Code
42function ProductionChainManager:initDataStructures()
43 self.productionPoints = {}
44 self.reverseProductionPoint = {}
45
46 self.farmIds = {}
47
48 self.currentUpdateIndex = 1
49 self.hourChangedDirty = false
50 self.hourChangeUpdating = false
51end

new

Description
Creating manager
Definition
new()
Return Values
tableinstanceinstance of object
Code
18function ProductionChainManager.new(isServer, customMt)
19 local self = AbstractManager.new(customMt or ProductionChainManager_mt)
20
21 self.isServer = isServer
22
23--#debug self.debugEnabled = false
24
25--#debug addConsoleCommand("gsProductionPointToggleDebug", "Toggle production point debugging", "consoleCommandToggleProdPointDebug", self)
26 addConsoleCommand("gsProductionPointsList", "List all production points on map", "commandListProductionPoints", self)
27 addConsoleCommand("gsProductionPointsPrintAutoDeliverMapping", "Prints which fillTypes are required by which production points", "commandPrintAutoDeliverMapping", self)
28 addConsoleCommand("gsProductionPointSetOwner", "", "commandSetOwner", self)
29 addConsoleCommand("gsProductionPointSetProductionState", "", "commandSetProductionState", self)
30 addConsoleCommand("gsProductionPointSetOutputMode", "", "commandSetOutputMode", self)
31 addConsoleCommand("gsProductionPointSetFillLevel", "", "commandSetFillLevel", self)
32
33 if self.isServer then
34 g_messageCenter:subscribe(MessageType.HOUR_CHANGED, self.hourChanged, self)
35 end
36
37 return self
38end

removeProductionPoint

Description
Definition
removeProductionPoint()
Code
126function ProductionChainManager:removeProductionPoint(productionPoint)
127 self.reverseProductionPoint[productionPoint] = nil
128
129 if table.removeElement(self.productionPoints, productionPoint) then
130 local farmId = productionPoint:getOwnerFarmId()
131 if farmId ~= AccessHandler.EVERYONE then
132 self.farmIds[farmId] = self:removeProductionPointFromFarm(productionPoint, self.farmIds[farmId])
133 end
134
135--#debug if self.debugEnabled then
136--#debug g_currentMission:removeDrawable(productionPoint)
137--#debug end
138 end
139
140 if #self.productionPoints == 0 and self.isServer then
141 g_currentMission:removeUpdateable(self)
142 end
143end

removeProductionPointFromFarm

Description
Definition
removeProductionPointFromFarm()
Code
147function ProductionChainManager:removeProductionPointFromFarm(productionPoint, farmTable)
148 table.removeElement(farmTable.productionPoints, productionPoint)
149
150 local inputTypeToProductionPoints = farmTable.inputTypeToProductionPoints
151 for inputType in pairs(productionPoint.inputFillTypeIds) do
152 if inputTypeToProductionPoints[inputType] then
153 if not table.removeElement(inputTypeToProductionPoints[inputType], productionPoint) then
154 log("Error: ProductionChainManager:removeProductionPoint(): Unable to remove production point from input type mapping")
155 end
156 if #inputTypeToProductionPoints[inputType] == 0 then
157 inputTypeToProductionPoints[inputType] = nil
158 end
159 end
160 end
161 if #farmTable.productionPoints == 0 then
162 farmTable = nil
163 end
164 return farmTable
165end

unloadMapData

Description
Definition
unloadMapData()
Code
55function ProductionChainManager:unloadMapData()
56--#debug removeConsoleCommand("gsProductionPointToggleDebug")
57 removeConsoleCommand("gsProductionPointsList")
58 removeConsoleCommand("gsProductionPointsPrintAutoDeliverMapping")
59 removeConsoleCommand("gsProductionPointSetOwner")
60 removeConsoleCommand("gsProductionPointSetProductionState")
61 removeConsoleCommand("gsProductionPointSetOutputMode")
62 removeConsoleCommand("gsProductionPointSetFillLevel")
63
64 if self.isServer then
65 g_messageCenter:unsubscribe(MessageType.HOUR_CHANGED, self)
66 end
67
68 ProductionChainManager:superClass().unloadMapData(self)
69end

updateBalance

Description
Definition
updateBalance()
Code
288function ProductionChainManager:updateBalance()
289
290end