Skip to content

Commit

Permalink
Added flare stack/clarifier consumption recipes
Browse files Browse the repository at this point in the history
Added flare stack/clarifier consumption recipes
Fixed show assembly for recipe
Fixed product name for resource recipe
  • Loading branch information
Helfima committed Jun 3, 2018
1 parent 1cff679 commit 13c33fc
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 54 deletions.
10 changes: 5 additions & 5 deletions controller/Controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@ end
--
function Controller.onGuiClosed(event)
Logging:trace(Controller.classname, "onGuiClosed(event)", event)
if event.element ~= nil and event.element.name == "helmod_main_panel" then
event.element.destroy()
end
Controller.cleanController(Player.native())
end

-------------------------------------------------------------------------------
Expand All @@ -185,8 +183,7 @@ function Controller.onGuiClick(event)
end

if event.element.name == Controller.classname.."=CLOSE" then
local player = game.players[event.player_index]
Controller.cleanController(player)
Controller.cleanController(Player.native())
end
Controller.parseEvent(event)
end
Expand All @@ -213,6 +210,9 @@ function Controller.parseEvent(event, type)
if main_panel:isOpened() then
main_panel:main()
main_panel:main()
else
-- prevent change location
Controller.cleanController(Player.native())
end
end
-- hotkey action
Expand Down
4 changes: 2 additions & 2 deletions core/MainPanel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ function MainPanel.methods:main()
local lua_player = Player.native()
local location = Player.getSettings("display_location")
local gui_main = lua_player.gui[location]
if gui_main["helmod_main_panel"] ~= nil and gui_main["helmod_main_panel"].valid then
gui_main["helmod_main_panel"].destroy()
if self:isOpened() then
Controller.cleanController(Player.native())
else
-- interessant mais genere une fausse UI ouverte
--Player.native().opened = self:getMainPanel()
Expand Down
49 changes: 30 additions & 19 deletions core/ModelCompute.lua
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,29 @@ function ModelCompute.computeBlockRecipe(block, recipe)
local production = 1
if recipe.production ~= nil then production = recipe.production end

-- recipe classique
-- prepare le recipe
for _, lua_product in pairs(RecipePrototype.getProducts()) do
if block.ingredients[lua_product.name] ~= nil then
local product = Product.load(lua_product).new()
local p_amount = Product.getAmount(recipe)
local count = block.ingredients[lua_product.name].count*production / p_amount
-- for void in angel mod
if p_amount == 0 then
local lua_ingredient = RecipePrototype.getIngredients(recipe.factory)[1]
local ingredient = Product.load(lua_ingredient).new()
p_amount = ingredient.amount
count = block.products[lua_ingredient.name].count*production / p_amount
-- for void in angel mod
if RecipePrototype.isVoid() then
Logging:debug(ModelCompute.classname, "isvoid", RecipePrototype.isVoid(), "recipe name", recipe.name)
local lua_ingredient = RecipePrototype.getIngredients(recipe.factory)[1]
local ingredient = Product.load(lua_ingredient).new()
local p_amount = ingredient.amount
local count = 0
if block.products[lua_ingredient.name] ~= nil then
count = block.products[lua_ingredient.name].count*production / p_amount
end
if recipe.count < count then recipe.count = count end
else
-- recipe classique
-- prepare le recipe
for _, lua_product in pairs(RecipePrototype.getProducts()) do
if block.ingredients[lua_product.name] ~= nil then
local product = Product.load(lua_product).new()
local p_amount = Product.getAmount(recipe)
local count = block.ingredients[lua_product.name].count*production / p_amount
Logging:debug(ModelCompute.classname, "count", count)
Logging:debug(ModelCompute.classname, "p_amount", p_amount)
if recipe.count < count then recipe.count = count end
end
Logging:debug(ModelCompute.classname, "count", count)
Logging:debug(ModelCompute.classname, "p_amount", p_amount)
if recipe.count < count then recipe.count = count end
end
end
Logging:debug(ModelCompute.classname, "recipe.count=", recipe.count)
Expand Down Expand Up @@ -302,7 +308,7 @@ end
-- @param #table block block of model
--
function ModelCompute.prepareBlock(block)
Logging:debug(ModelCompute.classname, "computeBlock():", block.name)
Logging:debug(ModelCompute.classname, "prepareBlock", block.name)
local model = Model.getModel()

local recipes = block.recipes
Expand Down Expand Up @@ -330,6 +336,7 @@ function ModelCompute.prepareBlock(block)
block.ingredients[lua_ingredient.name].count = 0
end
-- construit la list des produits
-- si c'est un voider la liste est vide
for _, lua_product in pairs(RecipePrototype.getProducts()) do
if block.products[lua_product.name] == nil then
block.products[lua_product.name] = Product.load(lua_product).new()
Expand Down Expand Up @@ -641,7 +648,7 @@ end
-- @param #table block block of model
--
function ModelCompute.computeBlock(block)
Logging:debug(Model.classname, "computeBlock():", block.name)
Logging:debug(ModelCompute.classname, "********** computeBlock **********")
local model = Model.getModel()

local recipes = block.recipes
Expand Down Expand Up @@ -746,6 +753,9 @@ function ModelCompute.computeBlock(block)
-- exclus le type ressource ou fluid
if recipe.type ~= "resource" and recipe.type ~= "fluid" and block.products[lua_ingredient.name] ~= nil and block.mining_ingredient ~= lua_ingredient.name then
block.products[lua_ingredient.name].count = block.products[lua_ingredient.name].count - count
if RecipePrototype.isVoid() then
block.ingredients[lua_ingredient.name].count = block.ingredients[lua_ingredient.name].count - count
end
end
end
Logging:debug(ModelCompute.classname , "********** Compute after clean ingredient:", block)
Expand All @@ -762,7 +772,8 @@ function ModelCompute.computeBlock(block)

-- reduit les produits du block
for _, product in pairs(block.products) do
if block.ingredients[product.name] ~= nil and block.mining_ingredient ~= product.name then
-- change le satus si exedant
if block.ingredients[product.name] ~= nil and block.mining_ingredient ~= product.name and not(RecipePrototype.isVoid()) then
product.state = 2
end
if block.products[product.name].count < 0.01 and not(bit32.band(product.state, 1) > 0) then
Expand Down
1 change: 1 addition & 0 deletions core/defines.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ helmod_settings_mod = {
"HMRemote",
"HMResourceEdition",
"HMResourceTab",
"HMRuleEdition",
"HMSatisticTab",
"HMSummaryTab",
"HMTechnology",
Expand Down
11 changes: 9 additions & 2 deletions edition/ProductEdition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ function ProductEdition.methods:after_open(event, action, item, item2, item3)
end

local product = nil
local product_count = 0

-------------------------------------------------------------------------------
-- On update
Expand All @@ -139,9 +140,15 @@ function ProductEdition.methods:onUpdate(event, action, item, item2, item3)
local model = Model.getModel()
product = nil
if model.blocks[item] ~= nil then
for _, element in pairs(model.blocks[item].products) do
local block = model.blocks[item]
for _, element in pairs(block.products) do
if element.name == item2 then
product = element
if block.input[product.name] then
product_count = block.input[product.name]
else
product_count = product.count
end
end
end
end
Expand Down Expand Up @@ -172,7 +179,7 @@ function ProductEdition.methods:updateInfo(item, item2, item3)
ElementGui.addGuiLabel(tablePanel, "product-label", Player.getLocalisedName(product))

ElementGui.addGuiLabel(tablePanel, "quantity-label", ({"helmod_common.quantity"}))
ElementGui.addGuiText(tablePanel, "quantity", product.count)
ElementGui.addGuiText(tablePanel, "quantity", product_count or 0)
end
end

Expand Down
2 changes: 1 addition & 1 deletion edition/RuleEdition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function RuleEdition.methods:updateRule(item, item2, item3)
end
if rule_mod == nil then rule_mod = mod_list[1] end
ElementGui.addGuiLabel(rule_table, "label-mod", ({"helmod_rule-edition-panel.mod"}))
ElementGui.addGuiDropDown(rule_table, "dropdown=ID=", "mod", mod_list, rule_mod)
ElementGui.addGuiDropDown(rule_table, self:classname().."=dropdown=ID=", "mod", mod_list, rule_mod)

-- name
local helmod_rule_manes = {}
Expand Down
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

{
"name": "helmod",
"version": "0.7.8",
"version": "0.7.10",
"title": "Helmod: assistant for planning your base.",
"author": "Helfima",
"contact": "Helfima",
Expand Down
14 changes: 14 additions & 0 deletions model/EntityPrototype.lua
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,20 @@ function EntityPrototype.getMineableMiningFluidAmount()
return 0
end

-------------------------------------------------------------------------------
-- Return mineable property products
--
-- @function [parent=#EntityPrototype] getMineableMiningProducts
--
-- @return #string
--
function EntityPrototype.getMineableMiningProducts()
if lua_entity_prototype ~= nil and lua_entity_prototype.mineable_properties ~= nil then
return lua_entity_prototype.mineable_properties.products
end
return {}
end

-------------------------------------------------------------------------------
-- Return electric energy source prototype buffer capacity
--
Expand Down
6 changes: 4 additions & 2 deletions model/Model.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ function Model.resetRules()
table.insert(global.rules, {index=7, mod="DyWorld", name="production-crafting", category="extraction-machine", type="entity-subgroup", value="dyworld-extraction-burner", excluded = false})
table.insert(global.rules, {index=8, mod="DyWorld", name="production-crafting", category="extraction-machine", type="entity-subgroup", value="dyworld-drills-electric", excluded = false})
table.insert(global.rules, {index=9, mod="DyWorld", name="production-crafting", category="extraction-machine", type="entity-subgroup", value="dyworld-drills-burner", excluded = false})
table.insert(global.rules, {index=10, mod="DyWorld", name="production-crafting", category="standard", type="entity-group", value="production", excluded = true})
table.insert(global.rules, {index=11, mod="DyWorld", name="production-crafting", category="extraction-machine", type="entity-group", value="production", excluded = true})
table.insert(global.rules, {index=10, mod="DyWorld", name="production-crafting", category="standard", type="entity-name", value="assembling-machine-1", excluded = true})
table.insert(global.rules, {index=11, mod="DyWorld", name="production-crafting", category="standard", type="entity-name", value="assembling-machine-2", excluded = true})
table.insert(global.rules, {index=12, mod="DyWorld", name="production-crafting", category="standard", type="entity-name", value="assembling-machine-3", excluded = true})
table.insert(global.rules, {index=13, mod="DyWorld", name="production-crafting", category="extraction-machine", type="entity-group", value="production", excluded = true})
end

-------------------------------------------------------------------------------
Expand Down
15 changes: 10 additions & 5 deletions model/Player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ end
-------------------------------------------------------------------------------
-- Return rule
--
-- @function [parent=#Player] getRules
-- @function [parent=#Player] checkRules
--
-- @param #boolean check
-- @param #table rules
Expand Down Expand Up @@ -602,17 +602,18 @@ function Player.getProductionsCrafting(category, lua_recipe)
else
for key, lua_entity in pairs(game.entity_prototypes) do
if lua_entity.type ~= nil and lua_entity.type ~= "offshore-pump" and lua_entity.name ~= nil and lua_entity.name ~= "player" then
Logging:debug(Player.classname, "getProductionsCrafting(category):item", lua_entity.name, lua_entity.type, lua_entity.group.name, lua_entity.subgroup.name, lua_entity.crafting_categories)
Logging:trace(Player.classname, "loop production machines", lua_entity.name, lua_entity.type, lua_entity.group.name, lua_entity.subgroup.name, lua_entity.crafting_categories)
local check = false
if category ~= nil then
if not(rules_included[category]) and not(rules_included[category]) then
-- standard recipe
if lua_entity.crafting_categories ~= nil and lua_entity.crafting_categories[category] then
local recipe_ingredient_count = #RecipePrototype.load(lua_recipe, "recipe").getIngredients(lua_entity)
local recipe_ingredient_count = RecipePrototype.load(lua_recipe, "recipe").getIngredientCount(lua_entity)
local factory_ingredient_count = EntityPrototype.load(lua_entity).getIngredientCount()
Logging:debug(Player.classname, "crafting", recipe_ingredient_count, factory_ingredient_count)
if factory_ingredient_count >= recipe_ingredient_count then
check = true
Logging:debug(Player.classname, "allowed machine", lua_entity.name)
end
-- resolve rule excluded
check = Player.checkRules(check, rules_excluded, "standard", lua_entity, false)
Expand Down Expand Up @@ -721,8 +722,12 @@ function Player.searchRecipe(name)
end
-- recherche dans les resource
for key, resource in pairs(Player.getResources()) do
if resource.name == name then
table.insert(recipes,{name=resource.name, type="resource"})
local products = EntityPrototype.load(resource).getMineableMiningProducts()
for key, product in pairs(products) do
if product.name == name then
table.insert(recipes,{name=resource.name, type="resource"})
break
end
end
end
-- recherche dans les fluids
Expand Down
14 changes: 14 additions & 0 deletions model/Product.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ function Product.getElementAmount(element)
return 0
end

-------------------------------------------------------------------------------
-- Get type of element (item or fluid)
--
-- @function [parent=#Product] getType
--
-- @return #string
--
function Product.getType()
Logging:debug(Product.classname, "getType()",lua_product)
if lua_product.type == 1 or lua_product.type == "fluid" then return "fluid" end
return "item"
end

-------------------------------------------------------------------------------
-- Get amount of element
--
Expand Down Expand Up @@ -206,6 +219,7 @@ end
--
function Product.getProductivityBonus(recipe)
Logging:debug(Product.classname, "getProductivityBonus(recipe)", lua_product)
if recipe.isluaobject or recipe.factory == nil or recipe.factory.effects == nil then return 1 end
local productivity = recipe.factory.effects.productivity
if recipe.type == "resource" then
productivity = productivity + Player.getForce().mining_drill_productivity_bonus
Expand Down
Loading

0 comments on commit 13c33fc

Please sign in to comment.