Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- Objects
- Parameters
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
ProductionChainManager
DescriptionThis class handles the interaction between Production- and/or SellingPointsParent
AbstractManagerFunctions
- addProductionPoint
- addProductionPointToFarm
- getHasFreeSlots
- getNumOfProductionPoints
- getProductionPointsForFarmId
- hourChanged
- initDataStructures
- new
- removeProductionPoint
- removeProductionPointFromFarm
- unloadMapData
- updateBalance
addProductionPoint
DescriptionDefinitionaddProductionPoint()Code
73 | function 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 |
102 | end |
addProductionPointToFarm
DescriptionDefinitionaddProductionPointToFarm()Code
106 | function 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 |
122 | end |
getHasFreeSlots
DescriptionDefinitiongetHasFreeSlots()Code
181 | function ProductionChainManager:getHasFreeSlots() |
182 | return #self.productionPoints < ProductionChainManager.NUM_MAX_PRODUCTION_POINTS |
183 | end |
getNumOfProductionPoints
DescriptionDefinitiongetNumOfProductionPoints()Code
175 | function ProductionChainManager:getNumOfProductionPoints() |
176 | return #self.productionPoints |
177 | end |
getProductionPointsForFarmId
DescriptionDefinitiongetProductionPointsForFarmId()Code
169 | function ProductionChainManager:getProductionPointsForFarmId(farmId) |
170 | return self.farmIds[farmId] and self.farmIds[farmId].productionPoints or {} |
171 | end |
hourChanged
DescriptionDefinitionhourChanged()Code
226 | function ProductionChainManager:hourChanged() |
227 | self.hourChangedDirty = true |
228 | end |
initDataStructures
DescriptionInitialize data structuresDefinition
initDataStructures()Code
42 | function 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 |
51 | end |
new
DescriptionCreating managerDefinition
new()Return Values
table | instance | instance of object |
18 | function 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 |
38 | end |
removeProductionPoint
DescriptionDefinitionremoveProductionPoint()Code
126 | function 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 |
143 | end |
removeProductionPointFromFarm
DescriptionDefinitionremoveProductionPointFromFarm()Code
147 | function 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 |
165 | end |
unloadMapData
DescriptionDefinitionunloadMapData()Code
55 | function 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) |
69 | end |
updateBalance
DescriptionDefinitionupdateBalance()Code
288 | function ProductionChainManager:updateBalance() |
289 | |
290 | end |