1268 | function 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}) |
1302 | end |
927 | function 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 |
969 | end |
499 | function 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 |
540 | end |
85 | function 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") |
93 | end |
47 | function 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") |
81 | end |
546 | function 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 |
589 | end |