updates compat
This commit is contained in:
parent
ee250a2aa2
commit
7b3b574b1a
5 changed files with 170 additions and 39 deletions
|
@ -1,4 +1,9 @@
|
|||
---------------------------------------------------------------------------------------------------
|
||||
Version: 0.0.16
|
||||
Date: 2022-08-09
|
||||
Fixes:
|
||||
- Generically compatible with modded recipes that use electronic circuits.
|
||||
---------------------------------------------------------------------------------------------------
|
||||
Version: 0.0.15
|
||||
Date: 2022-08-05
|
||||
Features:
|
||||
|
|
|
@ -21,7 +21,7 @@ end
|
|||
if not mods.Krastorio2 and not mods["aai-industry"] and not mods.bzaluminum and not mods.bzcarbon then
|
||||
util.replace_ingredient("offshore-pump", "electronic-circuit", "copper-cable")
|
||||
util.replace_ingredient("lab", "electronic-circuit", "copper-cable")
|
||||
util.replace_ingredient("electric-mining-drill", "electronic-circuit", "copper-cable")
|
||||
util.replace_ingredient("electric-mining-drill", "electronic-circuit", "copper-cable", 2, true)
|
||||
util.replace_ingredient("assembling-machine-1", "electronic-circuit", "copper-plate")
|
||||
util.replace_ingredient("radar", "electronic-circuit", "copper-plate")
|
||||
util.replace_ingredient("splitter", "electronic-circuit", "copper-cable", 20)
|
||||
|
@ -39,6 +39,9 @@ if not mods.Krastorio2 and not mods["aai-industry"] and not mods.bzaluminum and
|
|||
util.set_enabled("inserter", false)
|
||||
util.add_prerequisite("logistic-science-pack", "electronics")
|
||||
end
|
||||
if not mods.bzaluminum and not mods.bzcarbon then
|
||||
util.replace_ingredients_prior_to("electronics", "electronic-circuit", "copper-cable", 2)
|
||||
end
|
||||
|
||||
util.remove_ingredient("small-lamp", "blank-circuit") -- mod mash
|
||||
|
||||
|
|
196
data-util.lua
196
data-util.lua
|
@ -23,6 +23,33 @@ else
|
|||
util.titanium_processing = "titanium-processing"
|
||||
end
|
||||
|
||||
function util.se6()
|
||||
return mods["space-exploration"] and mods["space-exploration"] >= "0.6"
|
||||
end
|
||||
|
||||
util.cablesg = util.se6() and "electronic" or "cable"
|
||||
|
||||
function get_setting(name)
|
||||
if settings.startup[name] == nil then
|
||||
return nil
|
||||
end
|
||||
return settings.startup[name].value
|
||||
end
|
||||
|
||||
allbypass = {}
|
||||
if get_setting("bz-recipe-bypass") then
|
||||
for recipe in string.gmatch(me.get_setting("bz-recipe-bypass"), '[^",%s]+') do
|
||||
allbypass[recipe] = true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function bypass(recipe_name)
|
||||
if me.bypass[recipe_name] then return true end
|
||||
if allbypass[recipe_name] then return true end
|
||||
if get_setting("bz-tabula-rasa") then return true end
|
||||
end
|
||||
|
||||
function util.fe_plus(sub)
|
||||
if mods["FactorioExtended-Plus-"..sub] then
|
||||
return true
|
||||
|
@ -116,21 +143,25 @@ function util.add_unlock(technology_name, recipe)
|
|||
util.add_effect(technology_name, {type="unlock-recipe", recipe=recipe})
|
||||
end
|
||||
|
||||
-- remove recipe unlock effect from a given technology
|
||||
-- remove recipe unlock effect from a given technology, multiple times if necessary
|
||||
function util.remove_recipe_effect(technology_name, recipe_name)
|
||||
local technology = data.raw.technology[technology_name]
|
||||
local index = -1
|
||||
if technology and technology.effects then
|
||||
for i, effect in pairs(technology.effects) do
|
||||
if effect.type == "unlock-recipe" and effect.recipe == recipe_name then
|
||||
index = i
|
||||
break
|
||||
end
|
||||
local technology = data.raw.technology[technology_name]
|
||||
local index = -1
|
||||
local cnt = 0
|
||||
if technology and technology.effects then
|
||||
for i, effect in pairs(technology.effects) do
|
||||
if effect.type == "unlock-recipe" and effect.recipe == recipe_name then
|
||||
index = i
|
||||
cnt = cnt + 1
|
||||
end
|
||||
end
|
||||
if index > -1 then
|
||||
table.remove(technology.effects, index)
|
||||
if cnt > 1 then -- not over yet, do it again
|
||||
util.remove_recipe_effect(technology_name, recipe_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
if index > -1 then
|
||||
table.remove(technology.effects, index)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Set technology ingredients
|
||||
|
@ -159,7 +190,7 @@ end
|
|||
|
||||
-- Add a given quantity of ingredient to a given recipe
|
||||
function util.add_or_add_to_ingredient(recipe_name, ingredient, quantity)
|
||||
if me.bypass[recipe_name] then return end
|
||||
if bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] and data.raw.item[ingredient] then
|
||||
me.add_modified(recipe_name)
|
||||
add_or_add_to_ingredient(data.raw.recipe[recipe_name], ingredient, quantity)
|
||||
|
@ -182,7 +213,7 @@ end
|
|||
|
||||
-- Add a given quantity of ingredient to a given recipe
|
||||
function util.add_ingredient(recipe_name, ingredient, quantity)
|
||||
if me.bypass[recipe_name] then return end
|
||||
if bypass(recipe_name) then return end
|
||||
local is_fluid = not not data.raw.fluid[ingredient]
|
||||
if data.raw.recipe[recipe_name] and (data.raw.item[ingredient] or is_fluid) then
|
||||
me.add_modified(recipe_name)
|
||||
|
@ -209,7 +240,7 @@ end
|
|||
|
||||
-- Add a given ingredient prototype to a given recipe
|
||||
function util.add_ingredient_raw(recipe_name, ingredient)
|
||||
if me.bypass[recipe_name] then return end
|
||||
if bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] and (data.raw.item[ingredient.name] or data.raw.item[ingredient[1]]) then
|
||||
me.add_modified(recipe_name)
|
||||
add_ingredient_raw(data.raw.recipe[recipe_name], ingredient)
|
||||
|
@ -234,7 +265,7 @@ end
|
|||
|
||||
-- Set an ingredient to a given quantity
|
||||
function util.set_ingredient(recipe_name, ingredient, quantity)
|
||||
if me.bypass[recipe_name] then return end
|
||||
if bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] and data.raw.item[ingredient] then
|
||||
me.add_modified(recipe_name)
|
||||
set_ingredient(data.raw.recipe[recipe_name], ingredient, quantity)
|
||||
|
@ -262,6 +293,7 @@ end
|
|||
-- Add a given quantity of product to a given recipe.
|
||||
-- Only works for recipes with multiple products
|
||||
function util.add_product(recipe_name, product)
|
||||
if bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] and (data.raw.item[product[1]] or data.raw.item[product.name]) then
|
||||
add_product(data.raw.recipe[recipe_name], product)
|
||||
add_product(data.raw.recipe[recipe_name].normal, product)
|
||||
|
@ -328,17 +360,18 @@ function util.get_amount(recipe_name, product)
|
|||
end
|
||||
|
||||
-- Replace one ingredient with another in a recipe
|
||||
function util.replace_ingredient(recipe_name, old, new, amount)
|
||||
if me.bypass[recipe_name] then return end
|
||||
-- Use amount to set an amount. If that amount is a multiplier instead of an exact amount, set multiply true.
|
||||
function util.replace_ingredient(recipe_name, old, new, amount, multiply)
|
||||
if bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] and (data.raw.item[new] or data.raw.fluid[new]) then
|
||||
me.add_modified(recipe_name)
|
||||
replace_ingredient(data.raw.recipe[recipe_name], old, new, amount)
|
||||
replace_ingredient(data.raw.recipe[recipe_name].normal, old, new, amount)
|
||||
replace_ingredient(data.raw.recipe[recipe_name].expensive, old, new, amount)
|
||||
replace_ingredient(data.raw.recipe[recipe_name], old, new, amount, multiply)
|
||||
replace_ingredient(data.raw.recipe[recipe_name].normal, old, new, amount, multiply)
|
||||
replace_ingredient(data.raw.recipe[recipe_name].expensive, old, new, amount, multiply)
|
||||
end
|
||||
end
|
||||
|
||||
function replace_ingredient(recipe, old, new, amount)
|
||||
function replace_ingredient(recipe, old, new, amount, multiply)
|
||||
if recipe ~= nil and recipe.ingredients ~= nil then
|
||||
for i, existing in pairs(recipe.ingredients) do
|
||||
if existing[1] == new or existing.name == new then
|
||||
|
@ -348,11 +381,23 @@ function replace_ingredient(recipe, old, new, amount)
|
|||
for i, ingredient in pairs(recipe.ingredients) do
|
||||
if ingredient.name == old then
|
||||
ingredient.name = new
|
||||
if amount then ingredient.amount = amount end
|
||||
if amount then
|
||||
if multiply then
|
||||
ingredient.amount = amount * ingredient.amount
|
||||
else
|
||||
ingredient.amount = amount
|
||||
end
|
||||
end
|
||||
end
|
||||
if ingredient[1] == old then
|
||||
ingredient[1] = new
|
||||
if amount then ingredient[2] = amount end
|
||||
if amount then
|
||||
if multiply then
|
||||
ingredient[2] = amount * ingredient[2]
|
||||
else
|
||||
ingredient[2] = amount
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -360,7 +405,7 @@ end
|
|||
|
||||
-- Remove an ingredient from a recipe
|
||||
function util.remove_ingredient(recipe_name, old)
|
||||
if me.bypass[recipe_name] then return end
|
||||
if bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] then
|
||||
me.add_modified(recipe_name)
|
||||
remove_ingredient(data.raw.recipe[recipe_name], old)
|
||||
|
@ -386,7 +431,7 @@ end
|
|||
|
||||
-- Replace an amount of an ingredient in a recipe. Keep at least 1 of old.
|
||||
function util.replace_some_ingredient(recipe_name, old, old_amount, new, new_amount)
|
||||
if me.bypass[recipe_name] then return end
|
||||
if bypass(recipe_name) then return end
|
||||
local is_fluid = not not data.raw.fluid[new]
|
||||
if data.raw.recipe[recipe_name] and (data.raw.item[new] or is_fluid) then
|
||||
me.add_modified(recipe_name)
|
||||
|
@ -419,7 +464,7 @@ end
|
|||
function util.set_product_amount(recipe_name, product, amount)
|
||||
me.add_modified(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
if me.bypass[recipe_name] then return end
|
||||
if bypass(recipe_name) then return end
|
||||
set_product_amount(data.raw.recipe[recipe_name], product, amount)
|
||||
set_product_amount(data.raw.recipe[recipe_name].normal, product, amount)
|
||||
set_product_amount(data.raw.recipe[recipe_name].expensive, product, amount)
|
||||
|
@ -459,7 +504,7 @@ end
|
|||
function util.multiply_recipe(recipe_name, multiple)
|
||||
me.add_modified(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
if me.bypass[recipe_name] then return end
|
||||
if bypass(recipe_name) then return end
|
||||
multiply_recipe(data.raw.recipe[recipe_name], multiple)
|
||||
multiply_recipe(data.raw.recipe[recipe_name].normal, multiple)
|
||||
multiply_recipe(data.raw.recipe[recipe_name].expensive, multiple)
|
||||
|
@ -532,7 +577,7 @@ end
|
|||
function util.remove_product(recipe_name, old)
|
||||
me.add_modified(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
if me.bypass[recipe_name] then return end
|
||||
if bypass(recipe_name) then return end
|
||||
remove_product(data.raw.recipe[recipe_name], old)
|
||||
remove_product(data.raw.recipe[recipe_name].normal, old)
|
||||
remove_product(data.raw.recipe[recipe_name].expensive, old)
|
||||
|
@ -555,6 +600,7 @@ function remove_product(recipe, old)
|
|||
end
|
||||
|
||||
function util.set_main_product(recipe_name, product)
|
||||
if bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] then
|
||||
set_main_product(data.raw.recipe[recipe_name], product)
|
||||
set_main_product(data.raw.recipe[recipe_name].normal, product)
|
||||
|
@ -570,6 +616,7 @@ end
|
|||
|
||||
-- Replace one product with another in a recipe
|
||||
function util.replace_product(recipe_name, old, new)
|
||||
if bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] then
|
||||
replace_product(data.raw.recipe[recipe_name], old, new)
|
||||
replace_product(data.raw.recipe[recipe_name].normal, old, new)
|
||||
|
@ -615,7 +662,7 @@ end
|
|||
function util.set_recipe_time(recipe_name, time)
|
||||
me.add_modified(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
if me.bypass[recipe_name] then return end
|
||||
if bypass(recipe_name) then return end
|
||||
set_recipe_time(data.raw.recipe[recipe_name], time)
|
||||
set_recipe_time(data.raw.recipe[recipe_name].normal, time)
|
||||
set_recipe_time(data.raw.recipe[recipe_name].expensive, time)
|
||||
|
@ -634,7 +681,7 @@ end
|
|||
function util.multiply_time(recipe_name, factor)
|
||||
me.add_modified(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
if me.bypass[recipe_name] then return end
|
||||
if bypass(recipe_name) then return end
|
||||
multiply_time(data.raw.recipe[recipe_name], factor)
|
||||
multiply_time(data.raw.recipe[recipe_name].normal, factor)
|
||||
multiply_time(data.raw.recipe[recipe_name].expensive, factor)
|
||||
|
@ -653,7 +700,7 @@ end
|
|||
function util.add_time(recipe_name, amount)
|
||||
me.add_modified(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
if me.bypass[recipe_name] then return end
|
||||
if bypass(recipe_name) then return end
|
||||
add_time(data.raw.recipe[recipe_name], amount)
|
||||
add_time(data.raw.recipe[recipe_name].normal, amount)
|
||||
add_time(data.raw.recipe[recipe_name].expensive, amount)
|
||||
|
@ -670,7 +717,7 @@ end
|
|||
|
||||
-- Set recipe category
|
||||
function util.set_category(recipe_name, category)
|
||||
if me.bypass[recipe_name] then return end
|
||||
if bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] and data.raw["recipe-category"][category] then
|
||||
me.add_modified(recipe_name)
|
||||
data.raw.recipe[recipe_name].category = category
|
||||
|
@ -679,7 +726,7 @@ end
|
|||
|
||||
-- Set recipe subgroup
|
||||
function util.set_subgroup(recipe_name, subgroup)
|
||||
if me.bypass[recipe_name] then return end
|
||||
if bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] then
|
||||
me.add_modified(recipe_name)
|
||||
data.raw.recipe[recipe_name].subgroup = subgroup
|
||||
|
@ -688,7 +735,7 @@ end
|
|||
|
||||
-- Set item subgroup
|
||||
function util.set_item_subgroup(item, subgroup)
|
||||
if me.bypass[item] then return end
|
||||
if bypass(item) then return end
|
||||
if data.raw.item[item] and data.raw["item-subgroup"][subgroup] then
|
||||
data.raw.item[item].subgroup = subgroup
|
||||
end
|
||||
|
@ -696,7 +743,7 @@ end
|
|||
|
||||
-- Set recipe icons
|
||||
function util.set_icons(recipe_name, icons)
|
||||
if me.bypass[recipe_name] then return end
|
||||
if bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] then
|
||||
me.add_modified(recipe_name)
|
||||
data.raw.recipe[recipe_name].icons = icons
|
||||
|
@ -755,6 +802,7 @@ function add_to_ingredient(recipe, it, amount)
|
|||
end
|
||||
|
||||
function util.add_to_product(recipe, product, amount)
|
||||
if bypass(recipe) then return end
|
||||
if data.raw.recipe[recipe] then
|
||||
add_to_product(data.raw.recipe[recipe], product, amount)
|
||||
add_to_product(data.raw.recipe[recipe].normal, product, amount)
|
||||
|
@ -867,4 +915,78 @@ function util.create_list()
|
|||
end
|
||||
end
|
||||
|
||||
function util.remove_prior_unlocks(tech, recipe)
|
||||
if data.raw.technology[tech].prerequisites then
|
||||
for i, prerequisite in pairs(data.raw.technology[tech].prerequisites) do
|
||||
remove_prior_unlocks(prerequisite, recipe)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function remove_prior_unlocks(tech, recipe)
|
||||
local technology = data.raw.technology[tech]
|
||||
if technology then
|
||||
util.remove_recipe_effect(tech, recipe)
|
||||
if technology.prerequisites then
|
||||
for i, prerequisite in pairs(technology.prerequisites) do
|
||||
-- log("BZZZ removing prior unlocks, checking " .. prerequisite)
|
||||
remove_prior_unlocks(prerequisite, recipe)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function util.replace_ingredients_prior_to(tech, old, new, multiplier)
|
||||
if not data.raw.technology[tech] then
|
||||
log("Not replacing ingredient "..old.." with "..new.." because tech "..tech.." was not found")
|
||||
return
|
||||
end
|
||||
util.remove_prior_unlocks(tech, old)
|
||||
for i, recipe in pairs(data.raw.recipe) do
|
||||
if (recipe.enabled and recipe.enabled ~= 'false')
|
||||
and (not recipe.hidden or recipe.hidden == 'true') -- probably don't want to change hidden recipes
|
||||
then
|
||||
-- log("BZZZ due to 'enabled' replacing " .. old .. " with " .. new .." in " .. recipe.name)
|
||||
util.replace_ingredient(recipe.name, old, new, multiplier, true)
|
||||
end
|
||||
end
|
||||
if data.raw.technology[tech].prerequisites then
|
||||
for i, prerequisite in pairs(data.raw.technology[tech].prerequisites) do
|
||||
replace_ingredients_prior_to(prerequisite, old, new, multiplier)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function replace_ingredients_prior_to(tech, old, new, multiplier)
|
||||
local technology = data.raw.technology[tech]
|
||||
if technology then
|
||||
if technology.effects then
|
||||
for i, effect in pairs(technology.effects) do
|
||||
if effect.type == "unlock-recipe" then
|
||||
-- log("BZZZ replacing " .. old .. " with " .. new .." in " .. effect.recipe)
|
||||
util.replace_ingredient(effect.recipe, old, new, multiplier, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
if technology.prerequisites then
|
||||
for i, prerequisite in pairs(technology.prerequisites) do
|
||||
-- log("BZZZ checking " .. prerequisite)
|
||||
replace_ingredients_prior_to(prerequisite, old, new, multiplier)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function util.remove_all_recipe_effects(recipe_name)
|
||||
for name, _ in pairs(data.raw.technology) do
|
||||
util.remove_recipe_effect(name, recipe_name)
|
||||
end
|
||||
end
|
||||
|
||||
function util.add_unlock_force(technology_name, recipe)
|
||||
util.set_enabled(recipe, false)
|
||||
util.remove_all_recipe_effects(recipe)
|
||||
util.add_unlock(technology_name, recipe)
|
||||
end
|
||||
|
||||
return util
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "bzgas",
|
||||
"version": "0.0.15",
|
||||
"version": "0.0.16",
|
||||
"factorio_version": "1.1",
|
||||
"title": "Natural Gas",
|
||||
"author": "Brevven",
|
||||
|
|
1
me.lua
1
me.lua
|
@ -17,6 +17,7 @@ function me.use_boiler()
|
|||
end
|
||||
|
||||
function me.use_phenol()
|
||||
if me.get_setting("bz-all-intermediates") then return true end
|
||||
return me.get_setting("bzgas-more-intermediates") == "phenol"
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue