From 011f395bae43b1aa943c40936dc7a526816af43d Mon Sep 17 00:00:00 2001 From: Helfima Date: Fri, 9 Sep 2016 22:33:33 +0200 Subject: [PATCH] Fix recipe computing Added calculation with probability: amount = (amount_min + amount_max) * probability / 2) Added description on product of recipe edition (amount, amount_min, maount max and probabilty) Added cap 20% on speed and productivity effects --- helmod.lua | 2 +- info.json | 2 +- locale/en/locale.cfg | 2 ++ locale/fr/locale.cfg | 2 ++ locale/ru/local.cfg | 2 ++ planner/plannerModel.lua | 47 ++++++++++++++++++++++++++------ planner/plannerRecipeEdition.lua | 10 +++++-- planner/plannerResult.lua | 6 ++-- 8 files changed, 57 insertions(+), 16 deletions(-) diff --git a/helmod.lua b/helmod.lua index 4903d175..5f0b9b72 100644 --- a/helmod.lua +++ b/helmod.lua @@ -21,7 +21,7 @@ Logging.console = false --=========================== function helmod:on_init(event) self.name = "helmod" - self.version = "0.2.9" + self.version = "0.2.10" self.loaded = false; self.playerController = PlayerController:new() diff --git a/info.json b/info.json index c5283ecc..d39fd198 100644 --- a/info.json +++ b/info.json @@ -1,7 +1,7 @@ { "name": "helmod", - "version": "0.2.9", + "version": "0.2.10", "title": "Helmod: Assistant to plan its base.", "author": "Helfima", "contact": "Helfima", diff --git a/locale/en/locale.cfg b/locale/en/locale.cfg index b42d5947..6512d46d 100644 --- a/locale/en/locale.cfg +++ b/locale/en/locale.cfg @@ -126,6 +126,8 @@ remove-element=Remove this row up-element=Up this row down-element=Down this row module-description=__1__\nConsumption: __2__%\nSpeed: __3__%\nProductivity: __4__%\nPollution: __5__% +element-amount=Amount: __1__ +element-amount-probability=Amount min: __1__\nAmount max: __2__\nProbability: __3__ [controls] --Text for "game menu -> controls -> mods" planner-hotkey-main-window=Open/Close planner panel diff --git a/locale/fr/locale.cfg b/locale/fr/locale.cfg index 4238df17..fe10dcb8 100644 --- a/locale/fr/locale.cfg +++ b/locale/fr/locale.cfg @@ -126,6 +126,8 @@ remove-element=Supprimer cette ligne up-element=Monter cette ligne down-element=Descendre cette ligne module-description=__1__\nConsommation: __2__%\nVitesse: __3__%\nProductivité: __4__%\nPolution: __5__% +element-amount=Quantité: __1__ +element-amount-probability=Quantité min: __1__\nQuantité max: __2__\nProbabilité: __3__ [controls] --Text for "game menu -> controls -> mods" planner-hotkey-main-window=Open/Close planner panel \ No newline at end of file diff --git a/locale/ru/local.cfg b/locale/ru/local.cfg index 6d1cfe17..4d203e60 100644 --- a/locale/ru/local.cfg +++ b/locale/ru/local.cfg @@ -126,6 +126,8 @@ remove-element=Удал.строку up-element=Поднять строку down-element=Опустить строку module-description=__1__\nПотребление: __2__%\nСкорость: __3__%\nПродуктивность: __4__%\nЗагрязнение: __5__% +element-amount=Amount: __1__ +element-amount-probability=Amount min: __1__\nAmount max: __2__\nProbability: __3__ [controls] --Text for "game menu -> controls -> mods" planner-hotkey-main-window=Отк/закр окно планировщика diff --git a/planner/plannerModel.lua b/planner/plannerModel.lua index e9ab5103..518a665b 100644 --- a/planner/plannerModel.lua +++ b/planner/plannerModel.lua @@ -16,6 +16,9 @@ function PlannerModel.methods:init(parent) self.parent = parent self.player = self.parent.parent + self.capSpeed = 0.2 + self.capEnergy = 0.2 + self.capProductivity = 0.2 end ------------------------------------------------------------------------------- @@ -945,6 +948,28 @@ function PlannerModel.methods:update(player, force) end +------------------------------------------------------------------------------- +-- Get amount of element +-- +-- @function [parent=#PlannerModel] getElementAmount +-- +-- @param #table element +-- +-- @return #number +-- +-- @see http://lua-api.factorio.com/latest/Concepts.html#Product +-- +function PlannerModel.methods:getElementAmount(element) + if element.amount ~= nil then + return element.amount + end + + if element.probability ~= nil and element.amount_min ~= nil and element.amount_max ~= nil then + return ((element.amount_min + element.amount_max) * element.probability / 2) + end + + return 0 +end ------------------------------------------------------------------------------- -- Prepare model -- @@ -1011,10 +1036,11 @@ function PlannerModel.methods:computeProductionBlock(player, element, maxLoop, l end end -- check produit pilotant + -- @see http://lua-api.factorio.com/latest/Concepts.html#Product for _, product in pairs(recipe.products) do if mainProduct == nil then mainProduct = product - elseif product.count/product.amount > mainProduct.count/mainProduct.amount then + elseif product.count/self:getElementAmount(product) > mainProduct.count/self:getElementAmount(mainProduct) then mainProduct = product end end @@ -1023,7 +1049,7 @@ function PlannerModel.methods:computeProductionBlock(player, element, maxLoop, l -- met a jour le produit for index, product in pairs(recipe.products) do if product.name ~= mainProduct.name then - product.count = (mainProduct.count*product.amount/mainProduct.amount) + product.count = (mainProduct.count*self:getElementAmount(product)/self:getElementAmount(mainProduct)) end end end @@ -1031,8 +1057,8 @@ function PlannerModel.methods:computeProductionBlock(player, element, maxLoop, l local pCount = mainProduct.count; for k, ingredient in pairs(recipe.ingredients) do - local productNominal = mainProduct.amount - local productUsage = mainProduct.amount + local productNominal = self:getElementAmount(mainProduct) + local productUsage = self:getElementAmount(mainProduct) -- calcul production module factory for module, value in pairs(recipe.factory.modules) do local bonus = self.player:getModuleBonus(module, "productivity") @@ -1044,6 +1070,9 @@ function PlannerModel.methods:computeProductionBlock(player, element, maxLoop, l productUsage = productUsage + productNominal * value * bonus * recipe.beacon.efficiency * recipe.beacon.combo end end + -- cap le productivity a self.capProductivity + if productUsage < productNominal*self.capProductivity then productUsage = productNominal*self.capProductivity end + local nextCount = math.ceil(pCount*(ingredient.amount/productUsage)) ingredient.count = nextCount @@ -1069,7 +1098,7 @@ function PlannerModel.methods:computeProductionBlock(player, element, maxLoop, l element.count = math.ceil(recipe.factory.count/recipe.factory.limit) end end - + -- consomme les produits for _, product in pairs(recipe.products) do if ingredients ~= nil and ingredients[product.name] ~= nil then @@ -1203,8 +1232,10 @@ function PlannerModel.methods:computeFactory(player, recipe) end end - -- cap l'energy a 20% - if recipe.factory.energy < recipe.factory.energy_nominal*0.2 then recipe.factory.energy = recipe.factory.energy_nominal*0.2 end + -- cap le speed a self.capSpeed + if recipe.factory.speed < recipe.factory.speed_nominal*self.capSpeed then recipe.factory.speed = recipe.factory.speed_nominal*self.capSpeed end + -- cap l'energy a self.capEnergy + if recipe.factory.energy < recipe.factory.energy_nominal*self.capEnergy then recipe.factory.energy = recipe.factory.energy_nominal*self.capEnergy end -- compte le nombre de machines necessaires local product = nil for k, element in pairs(recipe.products) do @@ -1214,7 +1245,7 @@ function PlannerModel.methods:computeFactory(player, recipe) if product ~= nil then local model = self:getModel(player) -- [nombre d'item] * [effort necessaire du recipe] / ([la vitesse de la factory] * [nombre produit par le recipe] * [le temps en second]) - local count = math.ceil(product.count*recipe.energy/(recipe.factory.speed*product.amount*model.time)) + local count = math.ceil(product.count*recipe.energy/(recipe.factory.speed*self:getElementAmount(product)*model.time)) recipe.factory.count = count if recipe.beacon.active then recipe.beacon.count = math.ceil(count/recipe.beacon.factory) diff --git a/planner/plannerRecipeEdition.lua b/planner/plannerRecipeEdition.lua index e104c7e9..bfb5011e 100644 --- a/planner/plannerRecipeEdition.lua +++ b/planner/plannerRecipeEdition.lua @@ -481,7 +481,7 @@ function PlannerRecipeEdition.methods:updateRecipeIngredients(player, element, a end local tablePanel= self:addGuiTable(ingredientsPanel, "table-ingredients", 6) for key, ingredient in pairs(recipe.ingredients) do - self:addSpriteIconButton(tablePanel, "item=ID=", self.player:getIconType(ingredient), ingredient.name) + self:addSpriteIconButton(tablePanel, "item=ID=", self.player:getIconType(ingredient), ingredient.name, ingredient.name, ({"tooltip.element-amount", ingredient.amount})) self:addGuiLabel(tablePanel, ingredient.name, ingredient.amount) end end @@ -512,8 +512,12 @@ function PlannerRecipeEdition.methods:updateRecipeProducts(player, element, acti end local tablePanel= self:addGuiTable(productsPanel, "table-products", 6) for key, product in pairs(recipe.products) do - self:addSpriteIconButton(tablePanel, "item=ID=", self.player:getIconType(product), product.name) - self:addGuiLabel(tablePanel, product.name, product.amount) + if product.amount ~= nil then + self:addSpriteIconButton(tablePanel, "item=ID=", self.player:getIconType(product), product.name, product.name, ({"tooltip.element-amount", product.amount})) + else + self:addSpriteIconButton(tablePanel, "item=ID=", self.player:getIconType(product), product.name, product.name, ({"tooltip.element-amount-probability", product.amount_min, product.amount_max, product.probability})) + end + self:addGuiLabel(tablePanel, product.name, self.model:getElementAmount(product)) end end end diff --git a/planner/plannerResult.lua b/planner/plannerResult.lua index 22da9462..e4189cd6 100644 --- a/planner/plannerResult.lua +++ b/planner/plannerResult.lua @@ -469,7 +469,7 @@ function PlannerResult.methods:updateProductionBlock(player, item, item2, item3) for r, product in pairs(element.products) do -- product = {type="item", name="steel-plate", amount=8} local cell = self:addGuiFlowH(outputTable,"cell_"..product.name) - self:addSelectSpriteIconButton(cell, "HMPlannerProductEdition=OPEN=ID="..element.id.."=", self.player:getIconType(product), product.name, "X"..product.amount, nil, ({"tooltip.edit-product"})) + self:addSelectSpriteIconButton(cell, "HMPlannerProductEdition=OPEN=ID="..element.id.."=", self.player:getIconType(product), product.name, "X"..self.model:getElementAmount(product), nil, ({"tooltip.edit-product"})) self:addGuiLabel(cell, product.name, self:formatNumber(product.count), "helmod_label-right-60") end end @@ -897,7 +897,7 @@ function PlannerResult.methods:addProductionBlockRow(player, guiTable, blockId, for r, product in pairs(recipe.products) do local cell = self:addGuiFlowH(tProducts,"cell_"..product.name) -- product = {type="item", name="steel-plate", amount=8} - self:addSpriteIconButton(cell, "HMPlannerResourceInfo=OPEN=ID="..blockId.."="..recipe.name.."=", self.player:getIconType(product), product.name, "X"..product.amount) + self:addSpriteIconButton(cell, "HMPlannerResourceInfo=OPEN=ID="..blockId.."="..recipe.name.."=", self.player:getIconType(product), product.name, "X"..self.model:getElementAmount(product)) self:addGuiLabel(cell, product.name, self:formatNumber(product.count), "helmod_label-right-60") end @@ -974,7 +974,7 @@ function PlannerResult.methods:addProductionLineRow(player, guiTable, element) for r, product in pairs(element.products) do -- product = {type="item", name="steel-plate", amount=8} local cell = self:addGuiFlowH(tProducts,"cell_"..product.name) - self:addSelectSpriteIconButton(cell, "HMPlannerProductEdition=OPEN=ID="..element.id.."=", self.player:getIconType(product), product.name, "X"..product.amount, nil, ({"tooltip.edit-product"})) + self:addSelectSpriteIconButton(cell, "HMPlannerProductEdition=OPEN=ID="..element.id.."=", self.player:getIconType(product), product.name, "X"..self.model:getElementAmount(product), nil, ({"tooltip.edit-product"})) self:addGuiLabel(cell, product.name, self:formatNumber(product.count), "helmod_label-right-60") end