LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

ProductionPoint

Parent
Object
Functions

buyRequest

Description
when player activates trigger on not-owned production point
Definition
buyRequest()
Code
1268function ProductionPoint:buyRequest()
1269
1270 local storeItem = g_storeManager:getItemByXMLFilename(self.owningPlaceable.configFileName)
1271 local price = g_currentMission.economyManager:getBuyPrice(storeItem) or self.owningPlaceable:getPrice()
1272 if self.owningPlaceable.buysFarmland and self.owningPlaceable.farmlandId ~= nil then
1273 local farmland = g_farmlandManager:getFarmlandById(self.owningPlaceable.farmlandId)
1274 if farmland ~= nil and g_farmlandManager:getFarmlandOwner(self.owningPlaceable.farmlandId) ~= self.mission:getFarmId() then
1275 price = price + farmland.price
1276 end
1277 end
1278
1279 local activatable = self.activatable
1280 local productionPoint = self
1281 local buyingEventCallback = function(statusCode)
1282 if statusCode ~= nil then
1283 local dialogArgs = BuyExistingPlaceableEvent.DIALOG_MESSAGES[statusCode]
1284 if dialogArgs ~= nil then
1285 g_gui:showInfoDialog({text=g_i18n:getText(dialogArgs.text), dialogType=dialogArgs.dialogType})
1286 end
1287 end
1288 g_messageCenter:unsubscribe(BuyExistingPlaceableEvent, productionPoint)
1289 activatable:updateText()
1290 end
1291
1292 local text = string.format(g_i18n:getText("dialog_buyBuildingFor"), self:getName(), g_i18n:formatMoney(price, 0, true))
1293 local dialogCallback = function(yes)
1294 if yes then
1295 g_messageCenter:subscribe(BuyExistingPlaceableEvent, buyingEventCallback)
1296
1297 g_client:getServerConnection():sendEvent(BuyExistingPlaceableEvent.new(self.owningPlaceable, self.mission:getFarmId()))
1298 end
1299 end
1300
1301 g_gui:showYesNoDialog({text=text, callback=dialogCallback})
1302end

getSpecValueInputFillTypes

Description
Definition
getSpecValueInputFillTypes()
Code
1202function ProductionPoint.getSpecValueInputFillTypes(storeItem, realItem)
1203 if storeItem.specs.prodPointInputFillTypes == nil then
1204 return nil
1205 end
1206
1207 return g_fillTypeManager:getFillTypesByNames(table.concatKeys(storeItem.specs.prodPointInputFillTypes, " "))
1208end

getSpecValueOutputFillTypes

Description
Definition
getSpecValueOutputFillTypes()
Code
1227function ProductionPoint.getSpecValueOutputFillTypes(storeItem, realItem)
1228 if storeItem.specs.prodPointOutputFillTypes == nil then
1229 return nil
1230 end
1231
1232 return g_fillTypeManager:getFillTypesByNames(table.concatKeys(storeItem.specs.prodPointOutputFillTypes, " "))
1233end

interactionTriggerCallback

Description
Definition
interactionTriggerCallback()
Code
1237function ProductionPoint:interactionTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay, otherShapeId)
1238 if onEnter or onLeave then
1239 if self.mission.player and self.mission.player.rootNode == otherId then
1240 if onEnter then
1241 -- automatically perform action without manual activation on mobile
1242 if Platform.isMobile and self.activatable:getIsActivatable() then
1243 self.activatable:run()
1244 return
1245 end
1246
1247 self.activatable:updateText()
1248
1249 self.mission.activatableObjectsSystem:addActivatable(self.activatable)
1250 end
1251 if onLeave then
1252 self.mission.activatableObjectsSystem:removeActivatable(self.activatable)
1253 end
1254 end
1255 end
1256end

loadFromXMLFile

Description
Loading from attributes and nodes
Definition
loadFromXMLFile(integer xmlFile, string key)
Arguments
integerxmlFileid of xml object
stringkeykey
Return Values
booleansuccesssuccess
Code
927function ProductionPoint:loadFromXMLFile(xmlFile, key)
928 local palletSpawnCooldown = xmlFile:getValue(key .. "#palletSpawnCooldown")
929 if palletSpawnCooldown then
930 self.palletSpawnCooldown = g_time + palletSpawnCooldown
931 end
932
933 self.productionCostsToClaim = xmlFile:getValue(key .. "#productionCostsToClaim") or self.productionCostsToClaim
934
935 if self.owningPlaceable.ownerFarmId == AccessHandler.EVERYONE then
936 for n=1, #self.productions do
937 self:setProductionState(self.productions[n].id, true)
938 end
939 end
940
941 xmlFile:iterate(key..".production", function(index, productionKey)
942 local prodId = xmlFile:getValue(productionKey .. "#id")
943 local isEnabled = xmlFile:getValue(productionKey .. "#isEnabled")
944 if self.productionsIdToObj[prodId] == nil then
945 Logging.xmlWarning(xmlFile, "Unknown production id '%s'", prodId)
946 else
947 self:setProductionState(prodId, isEnabled)
948 end
949 end)
950
951 xmlFile:iterate(key..".directSellFillType", function(index, directSellKey)
952 local fillType = g_fillTypeManager:getFillTypeIndexByName(xmlFile:getValue(directSellKey))
953 if fillType then
954 self:setOutputDistributionMode(fillType, ProductionPoint.OUTPUT_MODE.DIRECT_SELL)
955 end
956 end)
957
958 xmlFile:iterate(key..".autoDeliverFillType", function(index, autoDeliverKey)
959 local fillType = g_fillTypeManager:getFillTypeIndexByName(xmlFile:getValue(autoDeliverKey))
960 if fillType then
961 self:setOutputDistributionMode(fillType, ProductionPoint.OUTPUT_MODE.AUTO_DELIVER)
962 end
963 end)
964
965 if not self.storage:loadFromXMLFile(xmlFile, key .. ".storage") then
966 return false
967 end
968 return true
969end

loadSpecValueInputFillTypes

Description
Definition
loadSpecValueInputFillTypes()
Code
1187function ProductionPoint.loadSpecValueInputFillTypes(xmlFile, customEnvironment, baseDir)
1188 local fillTypeNames = nil
1189 xmlFile:iterate("placeable.productionPoint.productions.production", function(_, productionKey)
1190 xmlFile:iterate(productionKey .. ".inputs.input", function(_, inputKey)
1191 local fillTypeName = xmlFile:getValue(inputKey .. "#fillType")
1192 fillTypeNames = fillTypeNames or {}
1193 fillTypeNames[fillTypeName] = true
1194 end)
1195 end)
1196
1197 return fillTypeNames
1198end

loadSpecValueOutputFillTypes

Description
Definition
loadSpecValueOutputFillTypes()
Code
1212function ProductionPoint.loadSpecValueOutputFillTypes(xmlFile, customEnvironment, baseDir)
1213 local fillTypeNames = nil
1214 xmlFile:iterate("placeable.productionPoint.productions.production", function(_, productionKey)
1215 xmlFile:iterate(productionKey .. ".outputs.output", function(_, inputKey)
1216 local fillTypeName = xmlFile:getValue(inputKey .. "#fillType")
1217 fillTypeNames = fillTypeNames or {}
1218 fillTypeNames[fillTypeName] = true
1219 end)
1220 end)
1221
1222 return fillTypeNames
1223end

openMenu

Description
when player activates trigger on self-owned production point
Definition
openMenu()
Code
1261function ProductionPoint:openMenu()
1262 g_gui:showGui("InGameMenu")
1263 g_messageCenter:publishDelayed(MessageType.GUI_INGAME_OPEN_PRODUCTION_SCREEN, self)
1264end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
499function ProductionPoint:readStream(streamId, connection)
500 ProductionPoint:superClass().readStream(self, streamId, connection)
501
502 if connection:getIsServer() then
503 -- direct sell fillTypes
504 for i=1, streamReadUInt8(streamId) do
505 self:setOutputDistributionMode(streamReadUIntN(streamId, FillTypeManager.SEND_NUM_BITS), ProductionPoint.OUTPUT_MODE.DIRECT_SELL)
506 end
507
508 -- auto deliver fillTypes
509 for i=1, streamReadUInt8(streamId) do
510 self:setOutputDistributionMode(streamReadUIntN(streamId, FillTypeManager.SEND_NUM_BITS), ProductionPoint.OUTPUT_MODE.AUTO_DELIVER)
511 end
512
513 -- unloading station
514 local unloadingStationId = NetworkUtil.readNodeObjectId(streamId)
515 self.unloadingStation:readStream(streamId, connection)
516 g_client:finishRegisterObject(self.unloadingStation, unloadingStationId)
517
518 -- loading station
519 if self.loadingStation ~= nil then
520 local loadingStationId = NetworkUtil.readNodeObjectId(streamId)
521 self.loadingStation:readStream(streamId, connection)
522 g_client:finishRegisterObject(self.loadingStation, loadingStationId)
523 end
524
525 -- storage
526 local storageId = NetworkUtil.readNodeObjectId(streamId)
527 self.storage:readStream(streamId, connection)
528 g_client:finishRegisterObject(self.storage, storageId)
529
530 -- active productions + status
531 for i=1, streamReadUInt8(streamId) do
532 local productionId = streamReadString(streamId)
533 self:setProductionState(productionId, true)
534
535 self:setProductionStatus(productionId, streamReadUIntN(streamId, ProductionPoint.PROD_STATUS_NUM_BITS))
536 end
537
538 self.palletLimitReached = streamReadBool(streamId)
539 end
540end

readUpdateStream

Description
Definition
readUpdateStream()
Code
593function ProductionPoint:readUpdateStream(streamId, timestamp, connection)
594 if connection:getIsServer() then
595 self.palletLimitReached = streamReadBool(streamId)
596 end
597end

registerSavegameXMLPaths

Description
Definition
registerSavegameXMLPaths()
Code
85function ProductionPoint.registerSavegameXMLPaths(schema, basePath)
86 schema:register(XMLValueType.INT, basePath .. "#palletSpawnCooldown", "remaining cooldown duration of pallet spawner")
87 schema:register(XMLValueType.FLOAT, basePath .. "#productionCostsToClaim", "production costs yet to be claimed from the owning player")
88 schema:register(XMLValueType.STRING, basePath .. ".directSellFillType(?)", "fillType currently configured to be directly sold")
89 schema:register(XMLValueType.STRING, basePath .. ".autoDeliverFillType(?)", "fillType currently configured to be automatically delivered")
90 schema:register(XMLValueType.STRING, basePath .. ".production(?)#id", "Unique id of the production")
91 schema:register(XMLValueType.BOOL, basePath .. ".production(?)#isEnabled", "State of the production")
92 Storage.registerSavegameXMLPaths(schema , basePath .. ".storage")
93end

registerXMLPaths

Description
Definition
registerXMLPaths()
Code
47function ProductionPoint.registerXMLPaths(schema, basePath)
48 schema:register(XMLValueType.STRING, basePath .. "#name", "Name of the Production Point", "unnamed production point")
49 schema:register(XMLValueType.BOOL, basePath .. ".productions#sharedThroughputCapacity", "Productions slow each other down if active at the same time", true)
50 schema:register(XMLValueType.STRING, basePath .. ".productions.production(?)#id", "Unique string used for identifying the production", nil, true)
51 schema:register(XMLValueType.L10N_STRING, basePath .. ".productions.production(?)#name", "Name of the production used inside the UI", "unnamed production")
52 schema:register(XMLValueType.STRING, basePath .. ".productions.production(?)#params", "Optional parameters formatted into #name")
53 schema:register(XMLValueType.FLOAT, basePath .. ".productions.production(?)#cyclesPerMonth", "Number of performed production cycles per ingame month (divided by the number of enabled productions, unless sharedThroughputCapacity is set to false)", 1440)
54 schema:register(XMLValueType.FLOAT, basePath .. ".productions.production(?)#cyclesPerHour", "Number of production cycles per ingame hour per day (==month) (divided by the number of enabled productions, unless sharedThroughputCapacity is set to false)", 60)
55 schema:register(XMLValueType.FLOAT, basePath .. ".productions.production(?)#cyclesPerMinute", "Number of performed production cycles per ingame minute (divided by the number of enabled productions)", 1)
56 schema:register(XMLValueType.FLOAT, basePath .. ".productions.production(?)#costsPerActiveMonth", "Costs per ingame hour if this production is enabled per ingame month (regardless of whether it is producing or not)", 1440)
57 schema:register(XMLValueType.FLOAT, basePath .. ".productions.production(?)#costsPerActiveHour", "Costs per ingame hour if this production is enabled per day (==month) (regardless of whether it is producing or not)", 60)
58 schema:register(XMLValueType.FLOAT, basePath .. ".productions.production(?)#costsPerActiveMinute", "Costs per ingame minute if this production is enabled (regardless of whether it is producing or not)", 1)
59 schema:register(XMLValueType.STRING, basePath .. ".productions.production(?).inputs.input(?)#fillType", "Input fillType", nil, true)
60 schema:register(XMLValueType.FLOAT, basePath .. ".productions.production(?).inputs.input(?)#amount", "Used amount per cycle", 1)
61 schema:register(XMLValueType.STRING, basePath .. ".productions.production(?).outputs.output(?)#fillType", "Output fillType", nil, true)
62 schema:register(XMLValueType.FLOAT, basePath .. ".productions.production(?).outputs.output(?)#amount", "Produced amount per cycle", 1)
63 schema:register(XMLValueType.BOOL, basePath .. ".productions.production(?).outputs.output(?)#sellDirectly", "Directly sell produced amount", false)
64
65 schema:register(XMLValueType.NODE_INDEX, basePath .. ".playerTrigger#node", "", "")
66
67 SoundManager.registerSampleXMLPaths(schema, basePath .. ".sounds", "active")
68 SoundManager.registerSampleXMLPaths(schema, basePath .. ".sounds", "idle")
69 SoundManager.registerSampleXMLPaths(schema, basePath .. ".productions.production(?).sounds", "active")
70
71 AnimationManager.registerAnimationNodesXMLPaths(schema, basePath .. ".animationNodes")
72 AnimationManager.registerAnimationNodesXMLPaths(schema, basePath .. ".productions.production(?).animationNodes")
73
74 EffectManager.registerEffectXMLPaths(schema, basePath .. ".effectNodes")
75 EffectManager.registerEffectXMLPaths(schema, basePath .. ".productions.production(?).effectNodes")
76
77 SellingStation.registerXMLPaths(schema, basePath .. ".sellingStation")
78 LoadingStation.registerXMLPaths(schema, basePath .. ".loadingStation")
79 PalletSpawner.registerXMLPaths(schema, basePath .. ".palletSpawner")
80 Storage.registerXMLPaths(schema , basePath .. ".storage")
81end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
546function ProductionPoint:writeStream(streamId, connection)
547 ProductionPoint:superClass().writeStream(self, streamId, connection)
548
549 if not connection:getIsServer() then
550 -- direct sell fillTypes
551 streamWriteUInt8(streamId, table.size(self.outputFillTypeIdsDirectSell))
552 for directSellFillTypeId in pairs(self.outputFillTypeIdsDirectSell) do
553 streamWriteUIntN(streamId, directSellFillTypeId, FillTypeManager.SEND_NUM_BITS)
554 end
555
556 -- auto deliver fillTypes
557 streamWriteUInt8(streamId, table.size(self.outputFillTypeIdsAutoDeliver))
558 for autoDeliverFillTypeId in pairs(self.outputFillTypeIdsAutoDeliver) do
559 streamWriteUIntN(streamId, autoDeliverFillTypeId, FillTypeManager.SEND_NUM_BITS)
560 end
561
562 -- unloading station
563 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.unloadingStation))
564 self.unloadingStation:writeStream(streamId, connection)
565 g_server:registerObjectInStream(connection, self.unloadingStation)
566
567 -- loading station
568 if self.loadingStation ~= nil then
569 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.loadingStation))
570 self.loadingStation:writeStream(streamId, connection)
571 g_server:registerObjectInStream(connection, self.loadingStation)
572 end
573
574 -- storage
575 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.storage))
576 self.storage:writeStream(streamId, connection)
577 g_server:registerObjectInStream(connection, self.storage)
578
579 -- active productions + status
580 streamWriteUInt8(streamId, #self.activeProductions)
581 for i=1, #self.activeProductions do
582 local production = self.activeProductions[i]
583 streamWriteString(streamId, production.id)
584 streamWriteUIntN(streamId, production.status, ProductionPoint.PROD_STATUS_NUM_BITS)
585 end
586
587 streamWriteBool(streamId, self.palletLimitReached)
588 end
589end

writeUpdateStream

Description
Definition
writeUpdateStream()
Code
601function ProductionPoint:writeUpdateStream(streamId, connection, dirtyMask)
602 if not connection:getIsServer() then
603 streamWriteBool(streamId, self.palletLimitReached)
604 end
605end