Skip to content

Commit

Permalink
steam energy ok
Browse files Browse the repository at this point in the history
  • Loading branch information
Helfima committed Feb 23, 2020
1 parent d8b56fa commit d3bc44f
Show file tree
Hide file tree
Showing 23 changed files with 1,039 additions and 1,442 deletions.
41 changes: 21 additions & 20 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
---------------------------------------------------------------------------------------------------
Version: 0.9.33
Version: 0.10.6
Date: 23. 02. 2020
Changes:
- added all energy source prototypes
- added a new block for energy consumption
- removed energy tab
- modified property tab
- changed fluid recipe, now there are hidden except water and steam
Bugfixes:
- fixed width internal panel of edit recipe
---------------------------------------------------------------------------------------------------
Version: 0.10.5
Date: 17. 02. 2020
Bugfixes:
- fixed a bug in RecipePrototype
- fixed cap negative productivity
---------------------------------------------------------------------------------------------------
Version: 0.9.32
Date: 16. 02. 2020
Bugfixes:
- fixed iteration end on bluiding user cache
- fixed filter on recipe selector
---------------------------------------------------------------------------------------------------
Version: 0.9.31
Version: 0.10.4
Date: 16. 02. 2020
Changes:
- generate user cache on several tick
Expand All @@ -25,23 +32,18 @@ Date: 16. 02. 2020
- fixed generate user cache when auto pause is activate
- fixed crash on new game
---------------------------------------------------------------------------------------------------
Version: 0.9.30
Version: 0.10.3
Date: 10. 02. 2020
Changes:
- generate cache on game initialisation
- changed admin panel, but not need use
Bugfixes:
- fixed switch contain/equal in recipe selector
---------------------------------------------------------------------------------------------------
Version: 0.9.29
Date: 02. 02. 2020
Changes:
- changed admin panel, now can delete cache by panel
- added few tick to generate recipe panel
Bugfixes:
- fixed switch contain/equal in recipe selector
- fixed switch contain/equal in recipe selector
---------------------------------------------------------------------------------------------------
Version: 0.9.28
Version: 0.10.2
Date: 28. 01. 2020
Features:
- Added inserter in logistic information
Expand All @@ -51,24 +53,23 @@ Date: 28. 01. 2020
- removed cache variable can MP desync
- fixed arithemtic error on pollution
---------------------------------------------------------------------------------------------------
Version: 0.9.27
Version: 0.10.1
Date: 24. 01. 2020
Features:
- Added option to activate or disable pollution information
Changes:
- Changed preference panel
- Moved few mod settings in the preference panel
---------------------------------------------------------------------------------------------------
Version: 0.9.26
Date: 22. 01. 2020
Changes:
- Modify for factorio 0.18
- Changed pollution to display value, per minute in tooltip
Bugfixes:
- fixed copy/past block for fuel and module
- fixed default factory from mod setting and the default set at 1
---------------------------------------------------------------------------------------------------
Version: 0.9.25
Version: 0.10.0
Date: 22. 01. 2020
Changes:
- Modify for factorio 0.18
Bugfixes:
- fixed open selector in properties tab
---------------------------------------------------------------------------------------------------
Expand Down
9 changes: 2 additions & 7 deletions controller/Controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ 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 @@ -20,7 +19,6 @@ require "selector.TechnologySelector"
require "selector.ItemSelector"
require "selector.FluidSelector"

require "tab.EnergyTab"
require "tab.ProductionBlockTab"
require "tab.ProductionLineTab"
require "tab.ResourceTab"
Expand All @@ -31,9 +29,8 @@ require "tab.PrototypeFiltersTab"
require "tab.AdminTab"

require "model.Prototype"
require "model.BurnerPrototype"
require "model.ElectricPrototype"
require "model.EnergyPrototype"
require "model.EnergySourcePrototype"
require "model.EntityPrototype"
require "model.FluidboxPrototype"
require "model.FluidPrototype"
Expand Down Expand Up @@ -82,7 +79,6 @@ 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 @@ -100,7 +96,6 @@ 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 @@ -336,7 +331,7 @@ local pattern = "([^=]*)=?([^=]*)=?([^=]*)=?([^=]*)=?([^=]*)=?([^=]*)"
function Controller:onGuiAction(event)
Logging:debug(self.classname, "onGuiAction(event)", event)
if event.element ~= nil and (string.find(event.element.name,"^HM.*") or string.find(event.element.name,"^helmod.*")) then
Logging.profiler = true
Logging.profiler = false
Logging:profilerStart()

Logging:profilerStep("onGuiAction", "** start **")
Expand Down
6 changes: 3 additions & 3 deletions core/defines.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ helmod_flow_style = {
helmod_tag = {}
helmod_tag.color = {}
helmod_tag.color.close = "[/color]"
helmod_tag.color.white = "[color=229,229,229]"
helmod_tag.color.white = "[color=255,255,255]"
helmod_tag.color.gray = "[color=229,229,229]"
helmod_tag.color.yellow = "[color=255,222,61]"
helmod_tag.color.red = "[color=229,229,229]"
helmod_tag.color.green = "[color=229,229,229]"
helmod_tag.color.red = "[color=255,0,0]"
helmod_tag.color.green = "[color=0,127,14]"
helmod_tag.color.blue = "[color=66,141,255]"
helmod_tag.color.gold = "[color=255,230,192]"
helmod_tag.color.orange = "[color=255,106,0]"
Expand Down
7 changes: 5 additions & 2 deletions core/logging.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ function Logging:objectToString(object, level)
message = message.."\"__function\""
elseif object.isluaobject then
if object.valid then
local help = object.help()
local help = nil
pcall(function() help = object.help() end)
if help ~= nil and help ~= "" then
local lua_type = string.match(help, "Help for%s([^:]*)")
if lua_type == "LuaCustomTable" then
Expand All @@ -124,7 +125,9 @@ function Logging:objectToString(object, level)
end
return self:objectToString(custom_table, level)
elseif string.find(lua_type, "Lua") then
message = message..string.format("{\"type\":%q,\"name\":%q}", lua_type, object.name or "nil")
local object_name = "unknown"
pcall(function() object_name = object.name end)
message = message..string.format("{\"type\":%q,\"name\":%q}", lua_type, object_name or "nil")
else
message = message..string.format("{\"type\":%q,\"name\":%q}", object.type or "nil", object.name or "nil")
end
Expand Down
55 changes: 30 additions & 25 deletions data/ModelBuilder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ function ModelBuilder.addRecipeIntoProductionBlock(key, type, index)

if lua_recipe ~= nil then
-- ajoute le bloc si il n'existe pas
if model.blocks[current_block] == nil then
if model.blocks[current_block] == nil or (model.blocks[current_block].isEnergy ~= true and type == "energy") or (model.blocks[current_block].isEnergy == true and type ~= "energy") then
local modelBlock = Model.newBlock(lua_recipe)
local block_index = Model.countBlocks()
modelBlock.isEnergy = type == "energy"
modelBlock.index = block_index
modelBlock.unlinked = false
model.blocks[modelBlock.id] = modelBlock
Expand Down Expand Up @@ -78,32 +79,36 @@ function ModelBuilder.addRecipeIntoProductionBlock(key, type, index)
end
model.blocks[current_block].recipes[ModelRecipe.id] = ModelRecipe

local default_factory = User.getDefaultFactory(ModelRecipe)
if default_factory ~= nil then
Model.setFactory(current_block, ModelRecipe.id, default_factory.name, default_factory.fuel)
else
local default_factory_name = Model.getDefaultPrototypeFactory(recipe_prototype)
if default_factory_name ~= nil then
Model.setFactory(current_block, ModelRecipe.id, default_factory_name)
if type ~= "energy" then
local default_factory = User.getDefaultFactory(ModelRecipe)
if default_factory ~= nil then
Model.setFactory(current_block, ModelRecipe.id, default_factory.name, default_factory.fuel)
else
local default_factory_name = Model.getDefaultPrototypeFactory(recipe_prototype)
if default_factory_name ~= nil then
Model.setFactory(current_block, ModelRecipe.id, default_factory_name)
end
end
end
local default_factory_module = User.getDefaultFactoryModule(ModelRecipe)
if default_factory_module ~= nil then
ModelBuilder.setFactoryModulePriority(current_block, ModelRecipe.id, default_factory_module)
end

local default_beacon = User.getDefaultBeacon(ModelRecipe)
if default_beacon ~= nil then
Model.setBeacon(current_block, ModelRecipe.id, default_beacon.name, default_beacon.combo, default_beacon.factory)
else
local default_beacon_name = Model.getDefaultRecipeBeacon(lua_recipe.name)
if default_beacon_name ~= nil then
Model.setBeacon(current_block, ModelRecipe.id, default_beacon_name)
local default_factory_module = User.getDefaultFactoryModule(ModelRecipe)
if default_factory_module ~= nil then
ModelBuilder.setFactoryModulePriority(current_block, ModelRecipe.id, default_factory_module)
end
end
local default_beacon_module = User.getDefaultBeaconModule(ModelRecipe)
if default_beacon_module ~= nil then
ModelBuilder.setBeaconModulePriority(current_block, ModelRecipe.id, default_beacon_module)

local default_beacon = User.getDefaultBeacon(ModelRecipe)
if default_beacon ~= nil then
Model.setBeacon(current_block, ModelRecipe.id, default_beacon.name, default_beacon.combo, default_beacon.factory)
else
local default_beacon_name = Model.getDefaultRecipeBeacon(lua_recipe.name)
if default_beacon_name ~= nil then
Model.setBeacon(current_block, ModelRecipe.id, default_beacon_name)
end
end
local default_beacon_module = User.getDefaultBeaconModule(ModelRecipe)
if default_beacon_module ~= nil then
ModelBuilder.setBeaconModulePriority(current_block, ModelRecipe.id, default_beacon_module)
end
else
Model.setFactory(current_block, ModelRecipe.id, key, nil)
end

Logging:debug(ModelBuilder.classname, "addRecipeIntoProductionBlock()", model.blocks[current_block])
Expand Down
80 changes: 69 additions & 11 deletions data/ModelCompute.lua
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ function ModelCompute.getBlockMatrix(block)
-- cas de l'ingredient existant du cote produit
if col_index[name] ~= nil and lua_products[name] ~= nil then
-- cas de la valeur equivalente, on creer un nouveau element
if lua_products[name].count == lua_ingredients[name].count or recipe.type == "resource" then
if lua_products[name].count == lua_ingredients[name].count or recipe.type == "resource" or recipe.type == "energy" then
index = col_index[name]+1
else
index = col_index[name]
Expand Down Expand Up @@ -682,8 +682,12 @@ function ModelCompute.computeBlock(block)
recipe.production = mC[row_index][2]
row_index = row_index + 1
Logging:debug(ModelCompute.classname , "----> solver solution", recipe.name, icol, recipe.count)

ModelCompute.computeFactory(recipe)

if block.isEnergy == true then
ModelCompute.computeEnergyFactory(recipe)
else
ModelCompute.computeFactory(recipe)
end

block.power = block.power + recipe.energy_total
block.pollution_total = block.pollution_total + recipe.pollution_total
Expand Down Expand Up @@ -886,18 +890,15 @@ function ModelCompute.computeFactory(recipe)
else
recipe.beacon.count = 0
end
local beacon_prototype = EntityPrototype(recipe.factory)
local beacon_prototype = EntityPrototype(recipe.beacon)
recipe.beacon.energy = beacon_prototype:getEnergyUsage()
-- calcul des totaux
local fuel_emissions_multiplier = 1
if energy_type == "burner" then
if energy_type ~= "electric" then
recipe.factory.energy_total = 0
local fuel = recipe.factory.fuel
if fuel == nil then
fuel = EntityPrototype(recipe.factory):getBurnerPrototype():getFirstFuelItemPrototype().name
end
if fuel ~= nil then
local fuel_prototype = ItemPrototype(fuel)
if energy_type == "burner" or energy_type == "fluid" then
local energy_prototype = EntityPrototype(recipe.factory):getEnergySource()
local fuel_prototype = energy_prototype:getFuelPrototype(recipe.factory)
fuel_emissions_multiplier = fuel_prototype:getFuelEmissionsMultiplier()
end
else
Expand All @@ -914,6 +915,61 @@ function ModelCompute.computeFactory(recipe)
recipe.beacon.energy = math.ceil(recipe.beacon.energy)
end

-------------------------------------------------------------------------------
-- Compute energy factory for recipes
--
-- @function [parent=#ModelCompute] computeEnergyFactory
--
-- @param #table recipe
--
function ModelCompute.computeEnergyFactory(recipe)
Logging:trace(ModelCompute.classname, "computeFactory()", recipe.name)
local recipe_prototype = RecipePrototype(recipe)
local recipe_energy = recipe_prototype:getEnergy()
-- effet speed
recipe.factory.speed = ModelCompute.speedFactory(recipe) * (1 + recipe.factory.effects.speed)
Logging:debug(ModelCompute.classname, "recipe.factory.speed", ModelCompute.speedFactory(recipe), recipe.factory.speed)
-- cap speed creation maximum de 1 cycle par tick
if recipe.type ~= "fluid" and recipe_energy/recipe.factory.speed < 1/60 then recipe.factory.speed = 60*recipe_energy end

-- effet consumption
local factory_prototype = EntityPrototype(recipe.factory)
local energy_type = factory_prototype:getEnergyType()
recipe.factory.energy = factory_prototype:getEnergyNominal() * (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
recipe.factory.count = count
-- calcul des totaux
local fuel_emissions_multiplier = 1
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)
fuel_emissions_multiplier = fuel_prototype:getFuelEmissionsMultiplier()
end
else
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

recipe.energy_total = recipe.factory.energy_total
recipe.pollution_total = recipe.factory.pollution_total * fuel_emissions_multiplier * recipe_prototype:getEmissionsMultiplier()
-- arrondi des valeurs
recipe.factory.speed = recipe.factory.speed
recipe.factory.energy = math.ceil(recipe.factory.energy)

recipe.beacon.energy_total = 0
recipe.beacon.energy = 0
end

-------------------------------------------------------------------------------
-- Compute input and output
--
Expand Down Expand Up @@ -1208,6 +1264,8 @@ function ModelCompute.speedFactory(recipe)
elseif recipe.type == "technology" then
local bonus = Player.getForce().laboratory_speed_modifier or 1
return 1*bonus
elseif recipe.type == "energy" then
return 1
else
local factory_prototype = EntityPrototype(recipe.factory)
return factory_prototype:getCraftingSpeed()
Expand Down
Loading

0 comments on commit d3bc44f

Please sign in to comment.