diff --git a/lignumis/prototypes/compatibility/k2so.lua b/lignumis/prototypes/compatibility/k2so.lua index 7dc2b2b..8067db5 100644 --- a/lignumis/prototypes/compatibility/k2so.lua +++ b/lignumis/prototypes/compatibility/k2so.lua @@ -78,27 +78,9 @@ data:extend({ } }) -data:extend({ - { - type = "technology", - name = "gold-tech-card", - icon = Lignumis.graphics .. "technology/lig-gold-science-pack-tech.png", - icon_size = 128, - unit = { - time = 45, - count = 500, - ingredients = { - { "wood-science-pack", 1 }, - { "steam-science-pack", 1 } - } - }, - prerequisites = { "gold-fluid-handling", "kr-advanced-lab" }, - effects = { - { type = "unlock-recipe", recipe = "gold-research-data" }, - { type = "unlock-recipe", recipe = "gold-tech-card" } - } - } -}) +Technology:new("kr-advanced-lab") + :addRecipe("gold-research-data") + :addRecipe("gold-tech-card") data.raw.recipe["burner-inserter"].ingredients = { { type = "item", name = "wooden-gear-wheel", amount = 1 }, @@ -141,89 +123,76 @@ if settings.startup["kr-realistic-weapons"].value then data.raw.recipe["firearm-magazine"].enabled = false end -if settings.startup["lignumis-technology-progression"].value - and settings.startup["lignumis-k2so-gold-tech-card"].value -then - for _, technology in pairs(data.raw.technology) do - if technology.unit - and technology.unit.ingredients - and not technology.lignumis_skip_science_packs - and not table.contains(Lignumis.science_blacklist, technology.name) - and not table.contains(Lignumis.science_pack_whitelist, technology.name) - then - local has_whitelisted_pack = false - local has_wood_pack = false - local has_steam_pack = false +if not (settings.startup["lignumis-technology-progression"].value and + settings.startup["lignumis-k2so-gold-tech-card"].value) then + return +end - for _, ingredient in pairs(technology.unit.ingredients) do - local ingredient_name = ingredient[1] or ingredient.name +local function upgrade_to_gold_card(tech) + if not (tech and tech.unit and tech.unit.ingredients) then return end - if ingredient_name == "wood-science-pack" then - has_wood_pack = true - elseif ingredient_name == "steam-science-pack" then - has_steam_pack = true - elseif table.contains(Lignumis.science_pack_whitelist, ingredient_name) then - has_whitelisted_pack = true - end - end + local new_ingredients = {} + local changed = false - if has_whitelisted_pack and has_wood_pack and has_steam_pack then - local ingredients = {} - - for _, ingredient in pairs(technology.unit.ingredients) do - local ingredient_name = ingredient[1] or ingredient.name - - if ingredient_name ~= "wood-science-pack" and ingredient_name ~= "steam-science-pack" then - table.insert(ingredients, ingredient) - end - end - - table.insert(ingredients, { "gold-tech-card", 1 }) - technology.unit.ingredients = ingredients - - if technology.prerequisites and not table.contains(technology.prerequisites, "gold-tech-card") then - table.insert(technology.prerequisites, "gold-tech-card") - end - end + for _, ing in pairs(tech.unit.ingredients) do + local name = ing[1] or ing.name + if name == "wood-science-pack" or name == "steam-science-pack" then + changed = true + else + table.insert(new_ingredients, ing) end end - for _, lab in pairs(data.raw.lab) do - if lab.inputs and not table.contains(Lignumis.lab_blacklist, lab.name) and not table.contains(lab.inputs, "gold-tech-card") then - table.insert(lab.inputs, "gold-tech-card") - end + local has_gold = false + for _, ing in pairs(new_ingredients) do + if (ing[1] or ing.name) == "gold-tech-card" then has_gold = true break end end - local utility_science = data.raw.technology["utility-science-pack"] - if utility_science and utility_science.unit and utility_science.unit.ingredients then - local ingredients = {} + if not has_gold then + table.insert(new_ingredients, {"gold-tech-card", 1}) + changed = true + end - for _, ingredient in pairs(utility_science.unit.ingredients) do - local ingredient_name = ingredient[1] or ingredient.name - - if ingredient_name ~= "wood-science-pack" and ingredient_name ~= "steam-science-pack" then - table.insert(ingredients, ingredient) - end - end - - local has_gold_card = false - for _, ingredient in pairs(ingredients) do - local ingredient_name = ingredient[1] or ingredient.name - if ingredient_name == "gold-tech-card" then - has_gold_card = true - break - end - end - - if not has_gold_card then - table.insert(ingredients, { "gold-tech-card", 1 }) - end - - utility_science.unit.ingredients = ingredients - - utility_science.prerequisites = utility_science.prerequisites or {} - if not table.contains(utility_science.prerequisites, "gold-tech-card") then - table.insert(utility_science.prerequisites, "gold-tech-card") + if changed then + tech.unit.ingredients = new_ingredients + tech.prerequisites = tech.prerequisites or {} + if not table.contains(tech.prerequisites, "kr-advanced-lab") then + table.insert(tech.prerequisites, "kr-advanced-lab") end end end + +for name, tech in pairs(data.raw.technology) do + if tech.unit and tech.unit.ingredients + and not tech.lignumis_skip_science_packs + and not table.contains(Lignumis.science_blacklist, name) + and not table.contains(Lignumis.science_pack_whitelist, name) then + + local has_wood = false + local has_steam = false + local has_white = false + for _, ing in pairs(tech.unit.ingredients) do + local n = ing[1] or ing.name + if n == "wood-science-pack" then has_wood = true + elseif n == "steam-science-pack" then has_steam = true + elseif table.contains(Lignumis.science_pack_whitelist, n) then has_white = true end + end + + if has_wood and has_steam and has_white then + upgrade_to_gold_card(tech) + end + end +end + +-- Special Cases needing fixing +upgrade_to_gold_card(data.raw.technology["production-science-pack"]) +upgrade_to_gold_card(data.raw.technology["utility-science-pack"]) + +-- Make sure gold tech card is in the labs, same code as in vanilla-updates.lua +for _, lab in pairs(data.raw.lab) do + if lab.inputs and not table.contains(Lignumis.lab_blacklist, lab.name) then + if not table.contains(lab.inputs, "gold-tech-card") then + table.insert(lab.inputs, "gold-tech-card") + end + end +end \ No newline at end of file