Helfima / helmod

Factorio Mod
154 stars 66 forks source link

Add support for fluid consuption in mining recipes. #140

Closed minno726 closed 6 years ago

minno726 commented 6 years ago

Sample production line.

Mining uranium ore requires sulfuric acid, but that ingredient isn't listed in the production block.

Helfima commented 6 years ago

it's a game mechanics not a recipe to implement that we must know how sulfuric acid is needed for produce 1 ore it's the same for all burner machines

minno726 commented 6 years ago

I have very limited internet access at the moment, so I can't do a PR. Here's the change that will add fluid inputs to mining recipes:


+++ helmod_0.7.9/model/RecipePrototype.lua      2018-05-31 22:47:54.966947900 -0500
@@ -200,7 +200,13 @@
     if lua_type == "recipe" then
       return lua_prototype.ingredients
     elseif lua_type == "resource" then
-      return {{name=lua_prototype.name, type="item", amount=1}}
+      local ingredients = {{name=lua_prototype.name, type="item", amount=1}}
+      -- ajouter le liquide obligatoire, s'il y en a
+      if lua_prototype.mineable_properties and lua_prototype.mineable_properties.required_fluid then
+        local fluid_ingredient = {name=lua_prototype.mineable_properties.required_fluid, type="fluid", amount=lua_prototype.mineable_properties.fluid_amount/10}
+        table.insert(ingredients, fluid_ingredient)
+      end
+      return ingredients
     elseif lua_type == "fluid" then
       if lua_prototype.name == "steam" then
         EntityPrototype.load(factory)```
minno726 commented 6 years ago

Hang on, found a bug. It doesn't properly reduce the amount of fluid demanded for a certain output as mining productivity increases, which happens to be the entire reason I want this feature.

minno726 commented 6 years ago

Updated patch that solves this issue and also #125. I have tested in-game that it correctly calculates both the ore output and fluid consumption of a mining drill with mining productivity research.


--- helmod_0.7.8/core/ModelCompute.lua  2018-02-14 07:26:13.063202200 -0600
+++ helmod_0.7.10/core/ModelCompute.lua 2018-06-01 02:26:11.283903000 -0500
@@ -1132,8 +1132,7 @@
     local mining_power = EntityPrototype.load(recipe.factory).getMiningPower()
     local hardness = EntityPrototype.load(recipe.name).getMineableHardness()
     local mining_time = EntityPrototype.load(recipe.name).getMineableMiningTime()
-    local bonus = Player.getForce().mining_drill_productivity_bonus
-    return (mining_power - hardness) * mining_speed * (1 + bonus) / mining_time
+    return (mining_power - hardness) * mining_speed / mining_time
   elseif recipe.type == "technology" then
     local bonus = Player.getForce().laboratory_speed_modifier or 1
     return 1*bonus
diff -Naru helmod_0.7.8/info.json helmod_0.7.10/info.json
--- helmod_0.7.8/info.json      2018-04-07 05:35:30.784572800 -0500
+++ helmod_0.7.10/info.json     2018-06-01 01:59:46.725135500 -0500
@@ -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",
diff -Naru helmod_0.7.8/model/Product.lua helmod_0.7.10/model/Product.lua
--- helmod_0.7.8/model/Product.lua      2018-01-17 18:57:28.117490400 -0600
+++ helmod_0.7.10/model/Product.lua     2018-06-01 02:27:29.456224100 -0500
@@ -110,6 +110,24 @@
 end

 -------------------------------------------------------------------------------
+-- Get the productivity bonus of the recipe
+--
+-- @function [parent=#Product] getProductivityBonus
+--
+-- @param #table recipe
+--
+-- @return #number
+--
+function Product.getProductivityBonus(recipe)
+  Logging:debug(Product.classname, "getProductivityBonus(recipe)", lua_product)
+  local productivity = recipe.factory.effects.productivity
+  if recipe.type == "resource" then
+    productivity = productivity + Player.getForce().mining_drill_productivity_bonus
+  end
+  return productivity
+end
+
+-------------------------------------------------------------------------------
 -- Get amount of element
 --
 -- @function [parent=#Product] getAmount
@@ -124,7 +142,7 @@
   if recipe == nil then
     return amount
   end
-  return amount + amount * recipe.factory.effects.productivity
+  return amount + amount * Product.getProductivityBonus(recipe)
 end

 -------------------------------------------------------------------------------
@@ -139,7 +157,7 @@
 function Product.countProduct(recipe)
   Logging:debug(Product.classname, "countProduct",lua_product)
   local amount = Product.getElementAmount(lua_product)
-  return (amount + amount * recipe.factory.effects.productivity ) * recipe.count
+  return (amount + amount * Product.getProductivityBonus(recipe) ) * recipe.count
 end

 -------------------------------------------------------------------------------
diff -Naru helmod_0.7.8/model/RecipePrototype.lua helmod_0.7.10/model/RecipePrototype.lua
--- helmod_0.7.8/model/RecipePrototype.lua      2018-01-05 12:59:47.025025100 -0600
+++ helmod_0.7.10/model/RecipePrototype.lua     2018-06-01 02:11:11.751600100 -0500
@@ -200,7 +200,13 @@
     if lua_type == "recipe" then
       return lua_prototype.ingredients
     elseif lua_type == "resource" then
-      return {{name=lua_prototype.name, type="item", amount=1}}
+      local ingredients = {}
+      -- ajouter le liquide obligatoire, s'il y en a
+      if lua_prototype.mineable_properties and lua_prototype.mineable_properties.required_fluid then
+        local fluid_ingredient = {name=lua_prototype.mineable_properties.required_fluid, type="fluid", amount=lua_prototype.mineable_properties.fluid_amount/10}
+        table.insert(ingredients, fluid_ingredient)
+      end
+      return ingredients
     elseif lua_type == "fluid" then
       if lua_prototype.name == "steam" then
         EntityPrototype.load(factory)```
Helfima commented 6 years ago

i have made a little change capture I want see the ores :)

minno726 commented 6 years ago

I found another bug in my mining fluid fix. When there's a mining step in a production block that consumes a fluid and another step that produces that fluid, it doesn't deduct the miner's consumption from the output window. So e.g. if I'm producing and consuming 10 units of acid it displays as having 10 units of excess. To fix that:

--- helmod_0.7.10/core/ModelCompute.lua 2018-06-01 02:26:11.283903000 -0500
+++ helmod_0.7.11/core/ModelCompute.lua 2018-06-02 23:36:50.308353100 -0500
@@ -734,7 +734,7 @@
         local count = Product.load(lua_ingredient).countIngredient(recipe)
         -- consomme les ingredients
         -- exclus le type ressource ou fluid
-        if recipe.type ~= "resource" and recipe.type ~= "fluid" and block.products[lua_ingredient.name] ~= nil then
+        if recipe.type ~= "fluid" and block.products[lua_ingredient.name] ~= nil then
           block.products[lua_ingredient.name].count = block.products[lua_ingredient.name].count - count
         end
       end

I've seen a lot of other places that are excluding fluid and resource recipes, so they might need to be updated too, but as far as I found while I was testing this is the only place that needs to be changed.