Skip to content

Commit

Permalink
added a new block for energy consumption
Browse files Browse the repository at this point in the history
  Changes:
    - added a new block for energy consumption
    - added all energy source prototypes
    - removed energy tab
    - modified property tab
    - changed fluid recipe, now there are hidden except water and steam
    - removed ingredient for ressource recipes and water recipe
  Bugfixes:
    - fixed width internal panel of edit recipe
  • Loading branch information
Helfima committed Feb 25, 2020
1 parent d3bc44f commit 67510eb
Show file tree
Hide file tree
Showing 21 changed files with 954 additions and 128 deletions.
3 changes: 2 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
Version: 0.10.6
Date: 23. 02. 2020
Changes:
- added all energy source prototypes
- added a new block for energy consumption
- added all energy source prototypes
- removed energy tab
- modified property tab
- changed fluid recipe, now there are hidden except water and steam
- removed ingredient for ressource recipes and water recipe
Bugfixes:
- fixed width internal panel of edit recipe
---------------------------------------------------------------------------------------------------
Expand Down
19 changes: 14 additions & 5 deletions controller/Controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require "dialog.Calculator"
require "dialog.RecipeExplorer"
require "edition.RecipeEdition"
require "edition.ProductEdition"
require "edition.EnergyEdition"
require "edition.RuleEdition"
require "edition.PreferenceEdition"
require "selector.ContainerSelector"
Expand All @@ -19,6 +20,7 @@ require "selector.TechnologySelector"
require "selector.ItemSelector"
require "selector.FluidSelector"

require "tab.EnergyTab"
require "tab.ProductionBlockTab"
require "tab.ProductionLineTab"
require "tab.ResourceTab"
Expand Down Expand Up @@ -79,6 +81,7 @@ function Controller:prepare()

table.insert(forms, ProductionLineTab("HMProductionLineTab"))
table.insert(forms, ProductionBlockTab("HMProductionBlockTab"))
--table.insert(forms, EnergyTab("HMEnergyTab"))
table.insert(forms, ResourceTab("HMResourceTab"))
table.insert(forms, SummaryTab("HMSummaryTab"))
table.insert(forms, StatisticTab("HMStatisticTab"))
Expand All @@ -96,6 +99,7 @@ function Controller:prepare()

table.insert(forms, RecipeEdition("HMRecipeEdition"))
table.insert(forms, ProductEdition("HMProductEdition"))
--table.insert(forms, EnergyEdition("HMEnergyEdition"))
table.insert(forms, RuleEdition("HMRuleEdition"))
table.insert(forms, PreferenceEdition("HMPreferenceEdition"))

Expand Down Expand Up @@ -644,6 +648,11 @@ function Controller:onEventAccessWrite(event)
local model = Model.getModel()
local model_id = User.getParameter("model_id")
local current_block = User.getParameter("current_block")
local block = model.blocks[current_block] or {}
local selector_name = "HMRecipeSelector"
if model.blocks[current_block] ~= nil and model.blocks[current_block].isEnergy then
selector_name = "HMEnergySelector"
end

if event.action == "change-tab" then
if event.item1 == "HMProductionBlockTab" and event.item2 == "new" then
Expand Down Expand Up @@ -682,7 +691,7 @@ function Controller:onEventAccessWrite(event)

if event.action == "product-edition" then
if event.button == defines.mouse_button_type.right then
self:send("on_gui_open", event, "HMRecipeSelector")
self:send("on_gui_open", event, selector_name)
else
self:send("on_gui_open", event, "HMProductEdition")
end
Expand All @@ -696,7 +705,7 @@ function Controller:onEventAccessWrite(event)

if event.action == "production-recipe-product-add" then
if event.button == defines.mouse_button_type.right then
self:send("on_gui_open", event, "HMRecipeSelector")
self:send("on_gui_open", event, selector_name)
else
local recipes = Player.searchRecipe(event.item3, true)
if #recipes == 1 then
Expand All @@ -708,14 +717,14 @@ function Controller:onEventAccessWrite(event)
else
-- pour ouvrir avec le filtre ingredient
event.button = defines.mouse_button_type.right
self:send("on_gui_open", event, "HMRecipeSelector")
self:send("on_gui_open", event, selector_name)
end
end
end

if event.action == "production-recipe-ingredient-add" then
if event.button == defines.mouse_button_type.right then
self:send("on_gui_open", event, "HMRecipeSelector")
self:send("on_gui_open", event, selector_name)
else
local recipes = Player.searchRecipe(event.item3)
if #recipes == 1 then
Expand All @@ -725,7 +734,7 @@ function Controller:onEventAccessWrite(event)
User.setParameter("scroll_element", new_recipe.id)
self:send("on_gui_update", event)
else
self:send("on_gui_open", event, "HMRecipeSelector")
self:send("on_gui_open", event, selector_name)
end
end
end
Expand Down
17 changes: 17 additions & 0 deletions data/ModelBuilder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,23 @@ function ModelBuilder.updateFactory(item, key, options)
end
end

-------------------------------------------------------------------------------
-- Update a factory
--
-- @function [parent=#ModelBuilder] updateTemperatureFactory
--
-- @param #string item block_id or resource
-- @param #string key object name
-- @param #table options
--
function ModelBuilder.updateTemperatureFactory(item, key, options)
Logging:debug(ModelBuilder.classname, "updateTemperatureFactory()", item, key, options)
local object = Model.getObject(item, key)
if object ~= nil then
object.factory.target_temperature = options.target_temperature or 0
end
end

-------------------------------------------------------------------------------
-- Update a factory
--
Expand Down
34 changes: 21 additions & 13 deletions data/ModelCompute.lua
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ function ModelCompute.computeFactory(recipe)
-- effet consumption
local factory_prototype = EntityPrototype(recipe.factory)
local energy_type = factory_prototype:getEnergyType()
recipe.factory.energy = factory_prototype:getMaxEnergyUsage() * (1 + recipe.factory.effects.consumption)
recipe.factory.energy = factory_prototype:getEnergyConsumption() * (1 + recipe.factory.effects.consumption)

-- effet pollution
recipe.factory.pollution = factory_prototype:getPollution() * (1 + recipe.factory.effects.pollution)
Expand All @@ -898,7 +898,7 @@ function ModelCompute.computeFactory(recipe)
recipe.factory.energy_total = 0
if energy_type == "burner" or energy_type == "fluid" then
local energy_prototype = EntityPrototype(recipe.factory):getEnergySource()
local fuel_prototype = energy_prototype:getFuelPrototype(recipe.factory)
local fuel_prototype = energy_prototype:getFuelPrototype()
fuel_emissions_multiplier = fuel_prototype:getFuelEmissionsMultiplier()
end
else
Expand All @@ -924,6 +924,7 @@ end
--
function ModelCompute.computeEnergyFactory(recipe)
Logging:trace(ModelCompute.classname, "computeFactory()", recipe.name)
local model = Model.getModel()
local recipe_prototype = RecipePrototype(recipe)
local recipe_energy = recipe_prototype:getEnergy()
-- effet speed
Expand All @@ -934,14 +935,20 @@ function ModelCompute.computeEnergyFactory(recipe)

-- effet consumption
local factory_prototype = EntityPrototype(recipe.factory)
local energy_prototype = factory_prototype:getEnergySource()

local energy_type = factory_prototype:getEnergyType()
recipe.factory.energy = factory_prototype:getEnergyNominal() * (1 + recipe.factory.effects.consumption)
local gameDay = {day=12500,dust=5000,night=2500,dawn=2500}
if factory_prototype:getType() == EntityType.accumulator then
local dark_time = (gameDay.dust/2 + gameDay.night + gameDay.dawn / 2 )
recipe_energy = dark_time/60
end
recipe.factory.energy = factory_prototype:getEnergyConsumption() * (1 + recipe.factory.effects.consumption)

-- effet pollution
recipe.factory.pollution = factory_prototype:getPollution() * (1 + recipe.factory.effects.pollution)

-- compte le nombre de machines necessaires
local model = Model.getModel()
-- [ratio recipe] * [effort necessaire du recipe] / ([la vitesse de la factory]
local count = recipe.count*recipe_energy/recipe.factory.speed
if recipe.factory.speed == 0 then count = 0 end
Expand All @@ -951,12 +958,12 @@ function ModelCompute.computeEnergyFactory(recipe)
if energy_type ~= "electric" then
recipe.factory.energy_total = 0
if energy_type == "burner" or energy_type == "fluid" then
local energy_prototype = EntityPrototype(recipe.factory):getEnergySource()
local fuel_prototype = energy_prototype:getFuelPrototype(recipe.factory)
local fuel_prototype = energy_prototype:getFuelPrototype()
fuel_emissions_multiplier = fuel_prototype:getFuelEmissionsMultiplier()
end
else
recipe.factory.energy_total = math.ceil(recipe.factory.count*recipe.factory.energy)
recipe.factory.energy_total = 0
--recipe.factory.energy_total = math.ceil(recipe.factory.count*recipe.factory.energy)
end
recipe.factory.pollution_total = recipe.factory.pollution * recipe.factory.count * model.time

Expand Down Expand Up @@ -1186,20 +1193,20 @@ function ModelCompute.computePower(key)
local secondary_prototype = EntityPrototype(power.secondary.name)
if primary_prototype:getType() == EntityType.generator then
-- calcul primary
local count = math.ceil( power.power / primary_prototype:getEnergyNominal() )
local count = math.ceil( power.power / primary_prototype:getEnergyConsumption() )
power.primary.count = count or 0
-- calcul secondary
if secondary_prototype:native() ~= nil and secondary_prototype:getType() == EntityType.boiler then
local count = 0
count = math.ceil( power.power / secondary_prototype:getEnergyNominal() )
count = math.ceil( power.power / secondary_prototype:getEnergyConsumption() )
power.secondary.count = count or 0
else
power.secondary.count = 0
end
end
if primary_prototype:getType() == EntityType.solar_panel then
-- calcul primary
local count = math.ceil( power.power / primary_prototype:getEnergyNominal() )
local count = math.ceil( power.power / primary_prototype:getEnergyConsumption() )
power.primary.count = count or 0
-- calcul secondary
if secondary_prototype:native() ~= nil and secondary_prototype:getType() == EntityType.accumulator then
Expand All @@ -1209,10 +1216,11 @@ function ModelCompute.computePower(key)
-- selon les aires il faut de l'accu en dehors du jour selon le trapese journalier
local accu= (gameDay.dust/factor + gameDay.night + gameDay.dawn / factor ) / ( gameDay.day )
-- puissance nominale la nuit
local count1 = power.power/ secondary_prototype:getElectricOutputFlowLimit()
local energy_prototype = secondary_prototype:getEnergySource()
local count1 = power.power/ energy_prototype:getOutputFlowLimit()
-- puissance durant la penombre
-- formula (puissance*durree_penombre)/(60s*capacite)
local count2 = power.power*( gameDay.dust / factor + gameDay.night + gameDay.dawn / factor ) / ( 60 * secondary_prototype:getElectricBufferCapacity() )
local count2 = power.power*( gameDay.dust / factor + gameDay.night + gameDay.dawn / factor ) / ( 60 * energy_prototype:getBufferCapacity() )

Logging:debug(ModelCompute.classname , "********** computePower result:", accu, count1, count2)
if count1 > count2 then
Expand Down Expand Up @@ -1242,7 +1250,7 @@ function ModelCompute.speedFactory(recipe)
local factory_prototype = EntityPrototype(recipe.factory)
-- info energy 1J=1W
local power_extract = factory_prototype:getPowerExtract()
local power_usage = factory_prototype:getMaxEnergyUsage()
local power_usage = factory_prototype:getEnergyConsumption()
Logging:debug(ModelCompute.classname, "power_extract", power_extract, "power_usage", power_usage, "fluid", power_usage/power_extract)
return power_usage/power_extract
elseif recipe.type == "resource" then
Expand Down
Loading

0 comments on commit 67510eb

Please sign in to comment.