#Big modpack compatibility

1 messages · Page 1 of 1 (latest)

tribal dune
#

Hello, as some of you may know i'm trying to get a rather big set of mods working together (in my name).

The biggest issue so far has been MSP-30, which has made way too many tech cycles in my tree. (tech cycles mean that for example a tech needs a pack which has not been yet unlocked) Basocally softlocking my game.

So I've started to make a solver which would fix the tech cycles. The idea in a nutshell is that:

  1. It finds a technology which unlocks some MSP-30 pack
    2.It deletes said pack from the tech's cost it found the unlock in, and also from each and every one of the prerequisites of the tech. So even the prereqs of the prereqs and so on.
    3.Done.

And for whatever reason, my code doesn't work. Hence this thread, code will be below. All code would be in the same file: data-final-fixes, but i've split it up the code in to parts so discord doesn't complain about the size.

#

huh

#
require('__stdlib__/stdlib/data/data').Util.create_data_globals()
local function remove_prereq_packs(tech_name, pack_name)
    local tech = data.raw.technology[tech_name]
    assert(tech, "expected tech with name " .. tech_name .. " to exist")

    -- Remove science pack from all prerequisites, until it can't find the pack anymore
    if not tech.unit then return end -- Has no ingredients
    local found_ingredient = false
    for ingredient_index, ingredient in pairs(tech.unit.ingredients) do
        local ingredient_name = ingredient.name or ingredient[1]
        if ingredient_name == pack_name  then
            table.remove(tech.unit.ingredients, ingredient_index)
            found_ingredient = true
            break -- This `pairs` iterator is now broken
        end
    end

    -- Do recursion!
    if not found_ingredient then return end -- But not if this tech doesn't have the science pack
    for _, prerequisites_name in pairs(tech.prerequisites or { } ) do
        remove_prereq_packs(prerequisites_name, pack_name)
    end
end

--weird spaghetti to handle an edge situation where the science does not have the pack as it's cost, so it calls the function on it's prereqs.
local function call_remove_prereq_packs(tech_name, pack_name)
    --this is to call the function correctly if the tech does not have the pack it wants removed in it's cost
    local tech_has_pack = false
    local technology = data.raw.technology[tech_name]
    for i, ingredient in pairs(technology.unit.ingredients) do
        if ingredient == pack_name then
            tech_has_pack = true
        end
    end
    if tech_has_pack then
        --normal behaviour, call it on the intended tech
        remove_prereq_packs(tech_name, pack_name)
    elseif not tech_has_pack then
        --call it on the tech's prereqs for it to work properly
        for _, tech in pairs(technology.prerequisites) do
           remove_prereq_packs(tech, pack_name)
        end
    end
end
#
local MSP_sciences = {
    "more-science-pack-2",
    "more-science-pack-3",
    "more-science-pack-4",
    "more-science-pack-5",
    "more-science-pack-6",
    "more-science-pack-7",
    "more-science-pack-8",
    "more-science-pack-9",
    "more-science-pack-10",
    "more-science-pack-11",
    "more-science-pack-12",
    "more-science-pack-13",
    "more-science-pack-14",
    "more-science-pack-15",
    "more-science-pack-16",
    "more-science-pack-17",
    "more-science-pack-18",
    "more-science-pack-19",
    "more-science-pack-20",
    "more-science-pack-21",
    "more-science-pack-22",
    "more-science-pack-23",
    "more-science-pack-24",
    "more-science-pack-25",
    "more-science-pack-26",
    "more-science-pack-27",
    "more-science-pack-28",
    "more-science-pack-29",
    "more-science-pack-30"
}
--same order as the table: MSP_sciences, so for example "logistics" = "more-science-pack-2" and so on.
local MSP_sciences_unlocking_tech_names = {
    "logistics",
    "military",
    "optics",
    "automation-2",
    "advanced-material-processing",
    "circuit-network",
    "oil-processing",
    "electric-energy-accumulators",
    "sulfur-processing",
    "rail-signals",
    "construction-robotics",
    "flamethrower",
    "tank",
    "laser-turret",
    "defender",
    "electric-energy-distribution-2",
    "productivity-module-2",
    "nuclear-power",
    "automation-3",
    "energy-shield-mk2-equipment",
    "logistics-3",
    "effect-transmission",
    "logistic-system",
    "advanced-electronics-2",
    "advanced-oil-processing",
    "explosive-rocketry",
    "artillery",
    "atomic-bomb",
    "rocket-silo"
} 

#

--move all sciences to more sensible places
--if science not mentioned it's in a sensible spot

--science 2
RECIPE("more-science-pack-2"):remove_unlock("optics")
RECIPE("more-science-pack-2"):add_unlock("logistics")
--science 3
TECHNOLOGY("military"):remove_pack("more-science-pack-3")
RECIPE("more-science-pack-3"):add_unlock("military")
TECHNOLOGY("light-armor"):remove_pack("more-science-pack-3")
RECIPE("more-science-pack-3"):remove_unlock("stone-wall")
--science 4
RECIPE("more-science-pack-4"):remove_unlock("electronics")
RECIPE("more-science-pack-4"):add_unlock("optics")
--Logistic system has 4 packs as a unlock, 24, 25, 26 ,27
--only 24 belongs there
RECIPE("more-science-pack-25"):remove_unlock("logistic-system")
RECIPE("more-science-pack-26"):remove_unlock("logistic-system")
RECIPE("more-science-pack-27"):remove_unlock("logistic-system")
--move 25, 26, 27
RECIPE("more-science-pack-25"):add_unlock("advanced-electronics-2")
RECIPE("more-science-pack-26"):add_unlock("advanced-oil-processing")
RECIPE("more-science-pack-27"):add_unlock("explosive-rocketry")



--Bruteforce the packs in the wrong places out
for i, tech_name in ipairs(MSP_sciences_unlocking_tech_names) do
    call_remove_prereq_packs(tech_name, MSP_sciences[i])
end

#

And here's how it's not working. The construction bots unlock the science 12, But the science 12 is still in a prerequisite

tribal dune
#

I recommend to resize this thread to be a bit wider so the code is readable

radiant stone
#

yeah i did that, made it look much better 👍

radiant stone
#

is it possible for a tech to require a science and a later tech to not require it?

#

if so, the if not found_ingredient then return end could screw with things

#

call_remove_prereq_packs only looks one iteration down

#

if you want to limit the number of iterations you look through, you could add a iterations_without_found_ingredient into the remove_prereq_packs and only do return end if iterations_without_found_ingredient equals however many arbitrary iterations you're willing to search

weak shoal
#

I personally would just nuke the techs and rebuild after all the mods are loaded

#

wipe all the packs

#

then find when a pack becomes available and seed all future techs with it

#

prevents any edge cases

#

and means any new mods that get integrated will integrate fine

radiant stone
#

^ honestly a better idea

#

seems like hell having 30 science packs the whole time, but looking at the mod it's consistent w/ it

tribal dune
#

I think I'd only nuke the MSP sciences

tribal dune
tribal dune
#

Or I do that and my game becomes a lot harder

#

hmm

tribal dune
tribal dune
#

god recursion is confusing