From 2f8d74c655bff9ea40ee468acc410d7328100ec4 Mon Sep 17 00:00:00 2001 From: Brevven Date: Sat, 30 Jan 2021 03:55:13 -0800 Subject: [PATCH] compatible with K2, SE --- info.json | 3 +- prototypes/optical-fiber.lua | 7 +++-- prototypes/silica-recipe.lua | 43 +++++++++++++++++++++++++-- prototypes/silicon-recipe.lua | 24 +++++++++++++-- recipe-updates.lua | 56 +++++++++++++++++++++++++++-------- util.lua | 38 ++++++++++++++++++++---- 6 files changed, 143 insertions(+), 28 deletions(-) diff --git a/info.json b/info.json index bc34964..8dada1a 100644 --- a/info.json +++ b/info.json @@ -1,12 +1,13 @@ { "name": "bzsilicon", - "version": "0.2.0", + "version": "0.3.0", "factorio_version": "1.1", "title": "Silica & Silicon", "author": "Brevven", "contact": "", "homepage": "", "dependencies": [ + "? Krastorio2", "base >= 0.18" ], "description": "Adds simple Silica and Silicon to the game, along with basic fiber optics." diff --git a/prototypes/optical-fiber.lua b/prototypes/optical-fiber.lua index 6e33df3..ece5a0b 100644 --- a/prototypes/optical-fiber.lua +++ b/prototypes/optical-fiber.lua @@ -1,4 +1,5 @@ -- Optical Fiber +local util = require("__bzsilicon__.util"); data:extend( { { @@ -8,7 +9,7 @@ data:extend( icon_size = 32, subgroup = "intermediate-product", order = "a[optical-fiber]", - stack_size = 200 + stack_size = util.get_stack_size(200) }, { type = "recipe", @@ -34,8 +35,8 @@ data:extend( name = "fiber-optics", icons = { - { icon = "__base__/graphics/technology/optics.png", icon_size = 128 }, - { icon = "__bzsilicon__/graphics/icons/optical-fiber.png", icon_size = 32, scale=1.5, shift={32,-48} }, + { icon = "__base__/graphics/technology/optics.png", icon_size = 256 }, + { icon = "__bzsilicon__/graphics/icons/optical-fiber.png", icon_size = 32, scale=3, shift={32,-48} }, }, effects = { diff --git a/prototypes/silica-recipe.lua b/prototypes/silica-recipe.lua index 93f4a41..d0d0a6f 100644 --- a/prototypes/silica-recipe.lua +++ b/prototypes/silica-recipe.lua @@ -1,7 +1,17 @@ -- Silica +local util = require("__bzsilicon__.util"); data:extend( { - { + mods["Krastorio2"] and { + type = "recipe", + name = "silica", + category = "crushing", + enabled = false, + energy_required = 4, + ingredients = {{"quartz", 10}}, + result = "silica", + result_count = 30 + } or { type = "recipe", name = "silica", category = "smelting", @@ -30,9 +40,36 @@ data:extend( icon_size = 64, subgroup = "raw-material", order = "b[silica]", - stack_size = 100 + stack_size = util.get_stack_size(100) }, - { + mods["Krastorio2"] and { + type = "technology", + name = "silica-processing", + icon_size = 128, + icon = "__bzsilicon__/graphics/icons/silica-processing.png", + effects = + { + { + type = "unlock-recipe", + recipe = "silica" + }, + { + type = "unlock-recipe", + recipe = "quartz" + }, + }, + prerequisites = {"kr-fluids-chemistry"}, + unit = + { + count = 10, + ingredients = + { + {"automation-science-pack", 1}, + }, + time = 30 + }, + order = "b-b" + } or { type = "technology", name = "silica-processing", icon_size = 128, diff --git a/prototypes/silicon-recipe.lua b/prototypes/silicon-recipe.lua index c7acaca..4d36fb7 100644 --- a/prototypes/silicon-recipe.lua +++ b/prototypes/silicon-recipe.lua @@ -1,7 +1,24 @@ -- Silicon +local util = require("__bzsilicon__.util"); +if mods["Krastorio2"] then + util.remove_raw("recipe", "silicon-2") +end + data:extend( { - { + mods["Krastorio2"] and { + type = "recipe", + name = "silicon", + category = "smelting", + enabled = false, + energy_required = 14.4, + ingredients = { + {"silica", 18}, + {"coke", 1} + }, + result = "silicon", + result_count = 3 + } or { type = "recipe", name = "silicon", category = "smelting", @@ -30,8 +47,9 @@ data:extend( icon_size = 64, subgroup = "raw-material", order = "b[silicon]", - stack_size = 100 + stack_size = util.get_stack_size(100) }, + (not mods["Krastorio2"]) and { type = "technology", name = "silicon-processing", @@ -56,6 +74,6 @@ data:extend( }, prerequisites = {"silica-processing"}, order = "b-b" - }, + } or nil, } ) diff --git a/recipe-updates.lua b/recipe-updates.lua index 1b5f203..f0b70a9 100644 --- a/recipe-updates.lua +++ b/recipe-updates.lua @@ -1,19 +1,26 @@ local util = require("__bzsilicon__.util"); -util.remove_ingredient("concrete", "stone-brick"); -util.add_ingredient("concrete", "silica", 25); -util.add_prerequisite("concrete", "silica-processing") +if not mods["Krastorio2"] then + util.remove_ingredient("concrete", "stone-brick"); + util.add_ingredient("concrete", "silica", 25); + util.add_prerequisite("concrete", "silica-processing") -util.replace_some_ingredient("processing-unit", "electronic-circuit", "silicon", 10) -util.add_prerequisite("advanced-electronics-2", "silicon-processing") + util.replace_some_ingredient("processing-unit", "electronic-circuit", "silicon", 10) + util.add_prerequisite("advanced-electronics-2", util.silicon_processing) -util.replace_some_ingredient("solar-panel", "electronic-circuit", "silicon", 10) -util.add_prerequisite("solar-energy", "silicon-processing") + util.replace_some_ingredient("solar-panel", "electronic-circuit", "silicon", 10) + util.add_prerequisite("solar-energy", "silicon-processing") -util.replace_ingredient("effectivity-module", "electronic-circuit", "silicon") -util.replace_ingredient("productivity-module", "electronic-circuit", "silicon") -util.replace_ingredient("speed-module", "electronic-circuit", "silicon") -util.add_prerequisite("modules", "silicon-processing") + util.replace_ingredient("effectivity-module", "electronic-circuit", "silicon") + util.replace_ingredient("productivity-module", "electronic-circuit", "silicon") + util.replace_ingredient("speed-module", "electronic-circuit", "silicon") + util.add_prerequisite("modules", util.silicon_processing) +else + util.remove_ingredient("concrete", "stone-brick"); + if not mods["space-exploration"] then + util.add_ingredient("concrete", "sand", 25); + end +end util.replace_ingredient("beacon", "copper-cable", "optical-fiber") util.add_prerequisite("effect-transmission", "fiber-optics") @@ -34,4 +41,29 @@ util.add_ingredient("decider-combinator", "optical-fiber", 1); util.add_ingredient("programmable-speaker", "optical-fiber", 1); util.add_prerequisite("circuit-network", "fiber-optics") -util.add_prerequisite("circuit-network", "silicon-processing") +util.add_prerequisite("circuit-network", util.silicon_processing) + +if mods["Krastorio2"] then + util.add_prerequisite("kr-silicon-processing", "silica-processing") + util.add_ingredient("biusart-lab", "optical-fiber", 10) + util.add_ingredient("ai-core", "optical-fiber", 2) +end + +if mods["aai-signal-transimission"] then + util.add_ingredient("aai-signal-receiver", "optical-fiber", 2) + util.add_ingredient("aai-signal-sender", "optical-fiber", 2) +end +if mods["aai-industry"] then + util.add_ingredient("beacon", "optical-fiber", 10) +end + +if mods["space-exploration"] then + util.add_ingredient("se-space-astrometrics-laboratory", "optical-fiber", 10) + util.add_ingredient("se-space-gravimetrics-laboratory", "optical-fiber", 10) + util.add_ingredient("se-space-laser-laboratory", "optical-fiber", 10) + util.add_ingredient("se-space-science-lab", "optical-fiber", 10) + util.add_ingredient("se-space-supercomputer-1", "optical-fiber", 100) + util.add_ingredient("se-space-supercomputer-2", "optical-fiber", 500) + + util.add_ingredient("se-polarisation-data", "optical-fiber", 1) +end diff --git a/util.lua b/util.lua index d4d492a..a469e0e 100644 --- a/util.lua +++ b/util.lua @@ -1,5 +1,25 @@ local util = {} +util.silicon_processing = mods["Krastorio2"] and "kr-silicon-processing" or "silicon-processing" + +function util.get_stack_size(default) + if mods["Krastorio2"] then + size = tonumber(krastorio.general.getSafeSettingValue("kr-stack-size")) + return size or default + end + return default +end + +-- Remove an element of type t and name from data.raw +function util.remove_raw(t, name) + for i, elem in pairs(data.raw[t]) do + if elem.name == name then + data.raw[t][i] = nil + break + end + end +end + -- Add a prerequisite to a given technology function util.add_prerequisite(technology_name, prerequisite) technology = data.raw.technology[technology_name] @@ -8,9 +28,11 @@ end -- Add a given quantity of ingredient to a given recipe function util.add_ingredient(recipe_name, ingredient, quantity) - add_ingredient(data.raw.recipe[recipe_name], ingredient, quantity) - add_ingredient(data.raw.recipe[recipe_name].normal, ingredient, quantity) - add_ingredient(data.raw.recipe[recipe_name].expensive, ingredient, quantity) + if data.raw.recipe[recipe_name] then + add_ingredient(data.raw.recipe[recipe_name], ingredient, quantity) + add_ingredient(data.raw.recipe[recipe_name].normal, ingredient, quantity) + add_ingredient(data.raw.recipe[recipe_name].expensive, ingredient, quantity) + end end function add_ingredient(recipe, ingredient, quantity) @@ -21,9 +43,11 @@ end -- Replace one ingredien with another in a recipe function util.replace_ingredient(recipe_name, old, new) + if data.raw.recipe[recipe_name] then replace_ingredient(data.raw.recipe[recipe_name], old, new) replace_ingredient(data.raw.recipe[recipe_name].normal, old, new) replace_ingredient(data.raw.recipe[recipe_name].expensive, old, new) + end end function replace_ingredient(recipe, old, new) @@ -39,9 +63,11 @@ end -- Remove an ingredient from a recipe function util.remove_ingredient(recipe_name, old) - remove_ingredient(data.raw.recipe[recipe_name], old) - remove_ingredient(data.raw.recipe[recipe_name].normal, old) - remove_ingredient(data.raw.recipe[recipe_name].expensive, old) + if data.raw.recipe[recipe_name] then + remove_ingredient(data.raw.recipe[recipe_name], old) + remove_ingredient(data.raw.recipe[recipe_name].normal, old) + remove_ingredient(data.raw.recipe[recipe_name].expensive, old) + end end function remove_ingredient(recipe, old)