Quality Assurance


All Qualities, unlocked from the start! Quality Modules not included.

Tweaks
5 days ago
2.0
3.88K
Manufacturing Cheats

i [Added] Multiple Technological Improvements

a month ago
(updated a month ago)

Here is a patched version that removes them correctly:

            local function EnableQuality(Machine)
                -- Allow Qualities in all Machines.
                local qualityadded = false
                local hasquality = false
                while not hasquality do
                    if Machine.allowed_effects ~= nil then
                        if type(Machine.allowed_effects) ~= "string" then
                            for _, AllowedEffect in pairs(Machine.allowed_effects) do
                                if AllowedEffect == "quality" then
                                    hasquality = true
                                end
                            end
                            if hasquality == false then
                                table.insert(Machine.allowed_effects, "quality")
                                hasquality = true
                            end
                        else
                            Machine.allowed_effects = {Machine.allowed_effects}
                        end
                    else
                        Machine.allowed_effects = {}
                    end
                end
                return Machine
            end

            -- Add all qualities to the selected Technology, and remove technologies with no effect.
            local QualityTechnologyName = config("quality-unlock")
            log("Adding Qualities to \"".. QualityTechnologyName .."\" Technology.")
            local RemovedTechnologies = {}
            for i,Technology in pairs(data.raw["technology"]) do
                log("Scanning Technology \"" .. Technology.name .. "\" now.")
                if Technology.name ~= QualityTechnologyName then
                    if Technology.effects ~= nil then
                        log("Technology has Effects.")
                        local moved = false
                        for j,Effect in pairs(Technology.effects) do
                            log("Scanning Modifier of type \"" .. Effect.type .. "\" now.")
                            if Effect.type == "unlock-quality" and Effect.quality ~= "uncommon" and Effect.quality ~= "rare" then
                                log("Effect is a match. Moving Quality Unlock to Automation Technology.")
                                table.insert(data.raw["technology"][QualityTechnologyName].effects, Effect)
                                data.raw["technology"][i].effects[j] = nil
                                moved = true
                                log("Effect moved.")
                            end
                        end

                        if moved then    
                            function CleanNils(t)
                              local ans = {}
                              for _,v in pairs(t) do
                                ans[ #ans+1 ] = v
                              end
                              return ans
                            end

                            if Technology.effects ~= nil then 
                                Technology.effects = CleanNils(Technology.effects)
                            end

                            if Technology.effects == nil or #Technology.effects == 0 then
                                log("All effects of Technology \"" .. Technology.name .. "\" have been removed. Removing Technology.")
                                RemovedTechnologies[Technology.name] = Technology
                                data.raw["technology"][i] = nil
                            end
                        end
                    end
                end
            end

I also moved the prerequisites part to another loop cause it looks like the order of technologies table is not guaranteed to be in order of prerequisites.

a month ago
(updated a month ago)

You seem to be an expreienced modder, so I'm replying to your big block of code with another big block of code.

-- Add all qualities to the selected Technology, and remove technologies with no effect.
local QualityTechnologyName = config("quality-unlock")
log("Adding Qualities to \"".. QualityTechnologyName .."\" Technology.")
local RemovedTechnologies = {}
for i,Technology in pairs(data.raw["technology"]) do
    log("Scanning Technology \"" .. Technology.name .. "\" now.")
    if Technology.name ~= QualityTechnologyName then
        if Technology.effects ~= nil then
            log("Technology has Effects.")
            local moved = false
            for j,Effect in pairs(Technology.effects) do
                log("Scanning Modifier of type \"" .. Effect.type .. "\" now.")
                if Effect.type == "unlock-quality" then
                    log("Effect is a match! Testing for quality forward movement now.")
                    local MoveQuality = true
                    if config("quality-unlock") == "rocket-silo" or config("quality-unlock") == "quality-module-2" or config("quality-unlock") == "quality-module-3" then
                        if Effect.quality == "uncommon" or Effect.quality == "rare" then
                            MoveQuality = false
                            log("Moving this quality to the \"" .. config("quality-unlock") .. "\" technology would cause the \"" .. Effect.quality .. "\" quality to be moved forward instead of backward! Cancelling this effect movement.")
                        end
                    end
                    if MoveQuality then
                        log("Moving quality unlock for quality \"" .. Effect.quality .. "\" to the \"" .. config("quality-unlock") .. "\" technology.")
                        table.insert(data.raw["technology"][QualityTechnologyName].effects, Effect)
                        data.raw["technology"][i].effects[j] = nil
                        moved = true
                        log("Effect moved.")
                    end
                end
            end

            if moved then
                local function CleanNils(t)
                  local ans = {}
                  for _,v in pairs(t) do
                    ans[ #ans+1 ] = v
                  end
                  return ans
                end

                if Technology.effects ~= nil then 
                    Technology.effects = CleanNils(Technology.effects)
                end

                if Technology.effects == nil or #Technology.effects == 0 then
                    log("All effects of Technology \"" .. Technology.name .. "\" have been removed. Removing Technology.")
                    RemovedTechnologies[Technology.name] = Technology
                    data.raw["technology"][i] = nil
                end
            end
        end
    end
end
for i,Technology in pairs(data.raw["technology"]) do
    log("Scanning technology \"" .. Technology.name .. "\" now.")
    if Technology ~= nil then
        for _,RemovedTechnology in pairs(data.raw["technology"]) do
            log("Scanning removed technology \"" .. Technology.name .. "\" now.")
            if Technology.prerequisites ~= nil and Technology.prerequisites ~= {} and Technology.prerequisites ~= "" then
                log("Existing technology has dependencies.")
                for j,TechnologyDependency in pairs(Technology.prerequisites) do
                    log("Scanning dependency \"" .. TechnologyDependency .. "\" now.")
                    if TechnologyDependency == RemovedTechnology.name then
                        log("Dependency is a match! Replacing dependency for removed technology \"" .. RemovedTechnology.name .. "\" with the dependencies of that technology.")
                        table.remove(data.raw["technology"][i].prerequisites, j)
                        if RemovedTechnology.prerequisites ~= nil and RemovedTechnology.prerequisites ~= {} and RemovedTechnology.prerequisites ~= "" then
                            for _,RemovedTechnologyDependency in pairs(RemovedTechnology.prerequisites) do
                                local AddDependency = true
                                for k,OtherTechnologyDependency in pairs(Technology.prerequisites) do
                                    if OtherTechnologyDependency == RemovedTechnologyDependency then
                                        AddDependency = false
                                    end
                                end
                                if AddDependency then
                                    log("Adding dependency \"" .. RemovedTechnologyDependency .. "\" to technology \"" .. Technology.name .. "\" now.")
                                    table.insert(data.raw["technology"][i].prerequisites, RemovedTechnologyDependency)
                                end
                            end
                        end
                    end
                end
            end
        end
    end
end

I also fixed the other technology related issue while I'm at it.

a month ago

Wow, is this how essential technologies is supposed to look?
https://imgur.com/C4tNKh4

a month ago
(updated a month ago)

Great, looks good for me (the new code)

a month ago

Great, looks good for me (the new code)

Yes, but I hinted at essential technologies not working properly. The log is also spammed with a bunch of the same message.

a month ago

Instead of
for _,RemovedTechnology in pairs(data.raw["technology"]) do
should be
for _,RemovedTechnology in pairs(RemovedTechnologies) do

a month ago
(updated a month ago)

Ah,exactly.

You can also see my version (I haven't posted it initially):

        for i,Technology in pairs(data.raw["technology"]) do
            for _,RemovedTechnology in pairs(RemovedTechnologies) do
                if Technology.prerequisites ~= nil then
                    for n,Prerequisite in pairs(Technology.prerequisites) do
                        if RemovedTechnology.name == Prerequisite then
                            table.remove(data.raw["technology"][i].prerequisites[n])
                            for _,RemovedTechnologyPrerequisite in pairs(RemovedTechnology.prerequistites) do
                                table.append(Technology.prerequisites, RemovedTechnologyPrerequisite)
                            end
                        end
                    end
                end
            end
        end
a month ago

Also, fix for prerequisites of ams technologies. You don't need electronics, because steel-processing depends on it. Now it depends on tech, that unlocks each machine. Plus it uses the prerequsite's icon for the tech:

                Prerequisite = GetMachineTechnology(Machine)
                if Prerequisite ~= nil then
                    AMSMachineTechnology.prerequisites = {Prerequisite, "steel-processing"}
                    AMSMachineTechnology.icon = data.raw["technology"][Prerequisite].icon
                else
                    AMSMachineTechnology.prerequisites = {"steel-processing"}
                end

where GetMachineTechnology is:

local function GetMachineTechnology(Machine)
    for i,Technology in pairs(data.raw["technology"]) do
        if Technology.effects ~= nil then
            for j,Effect in pairs(Technology.effects) do
                if Effect ~= nil and Effect.type == "unlock-recipe" and Effect.recipe == Machine.name then
                    return Technology.name
                end
            end
        end
    end
    return nil
end
a month ago
(updated a month ago)

Thank you everyone for your code. I'll make sure to credit you in the code.
A.Freeman, that was a genuine mistake on my part, I should have thoroughly checked before being against the original code. Also, thank you for providing an updated solution to the technology problem. I was focused on providing weak compatibility with most mods than providing strong compatibility with a few mods.
wvlad, thank you for providing the fixed code for the dependencies even if it was in part.
Final version of the technology code:

-- Add all qualities to the selected Technology, and remove technologies with no effect.
-- Thank you, wvlad for providing me with this new effect movement and technology removal system. (If I ever add a supporters list, you'll be on it!)
local QualityTechnologyName = config("quality-unlock")
log("Adding Qualities to \"".. QualityTechnologyName .."\" Technology.")
local RemovedTechnologies = {}
for i,Technology in pairs(data.raw["technology"]) do
    log("Scanning Technology \"" .. Technology.name .. "\" now.")
    if Technology.name ~= QualityTechnologyName then
        if Technology.effects ~= nil then
            log("Technology has Effects.")
            local moved = false
            for j,Effect in pairs(Technology.effects) do
                log("Scanning Modifier of type \"" .. Effect.type .. "\" now.")
                if Effect.type == "unlock-quality" then
                    log("Effect is a match! Testing for quality forward movement now.")
                    local MoveQuality = true
                    if QualityTechnologyName == "rocket-silo" or QualityTechnologyName == "quality-module-2" or QualityTechnologyName == "quality-module-3" then
                        if Effect.quality == "uncommon" or Effect.quality == "rare" then
                            MoveQuality = false
                            log("Moving this quality to the \"" .. QualityTechnologyName .. "\" technology would cause the \"" .. Effect.quality .. "\" quality to be moved forward instead of backward! Cancelling this effect movement.")
                        end
                    end
                    if MoveQuality then
                        log("Moving quality unlock for quality \"" .. Effect.quality .. "\" to the \"" .. QualityTechnologyName .. "\" technology.")
                        table.insert(data.raw["technology"][QualityTechnologyName].effects, Effect)
                        data.raw["technology"][i].effects[j] = nil
                        moved = true
                        log("Effect moved.")
                    end
                end
            end

            if moved then
                local function CleanNils(t)
                  local ans = {}
                  for _,v in pairs(t) do
                    ans[ #ans+1 ] = v
                  end
                  return ans
                end

                if Technology.effects ~= nil then 
                    Technology.effects = CleanNils(Technology.effects)
                end

                if Technology.effects == nil or #Technology.effects == 0 then
                    log("All effects of Technology \"" .. Technology.name .. "\" have been removed. Removing Technology.")
                    RemovedTechnologies[Technology.name] = Technology
                    data.raw["technology"][i] = nil
                end
            end
        end
    end
end
for i,Technology in pairs(data.raw["technology"]) do
    log("Scanning technology \"" .. Technology.name .. "\" now.")
    if Technology ~= nil then
        for _,RemovedTechnology in pairs(RemovedTechnologies) do
            log("Scanning removed technology \"" .. Technology.name .. "\" now.")
            if Technology.prerequisites ~= nil and Technology.prerequisites ~= {} and Technology.prerequisites ~= "" then
                log("Existing technology has dependencies.")
                for j,TechnologyDependency in pairs(Technology.prerequisites) do
                    log("Scanning dependency \"" .. TechnologyDependency .. "\" now.")
                    if TechnologyDependency == RemovedTechnology.name then
                        log("Dependency is a match! Replacing dependency for removed technology \"" .. RemovedTechnology.name .. "\" with the dependencies of that technology.")
                        table.remove(data.raw["technology"][i].prerequisites, j)
                        if RemovedTechnology.prerequisites ~= nil and RemovedTechnology.prerequisites ~= {} and RemovedTechnology.prerequisites ~= "" then
                            for _,RemovedTechnologyDependency in pairs(RemovedTechnology.prerequisites) do
                                local AddDependency = true
                                for k,OtherTechnologyDependency in pairs(Technology.prerequisites) do
                                    if OtherTechnologyDependency == RemovedTechnologyDependency then
                                        AddDependency = false
                                    end
                                end
                                if AddDependency then
                                    log("Adding dependency \"" .. RemovedTechnologyDependency .. "\" to technology \"" .. Technology.name .. "\" now.")
                                    table.insert(data.raw["technology"][i].prerequisites, RemovedTechnologyDependency)
                                end
                            end
                        end
                    end
                end
            end
        end
    end
end

As well as the new prequesties system:

-- Thank you, A.Freeman (from the mod portal) for providing me with this new prerequisites system. (If I ever add a supporters list, you'll be on it!)
local function GetMachineTechnology(Machine)
    for i,Technology in pairs(data.raw["technology"]) do
        if Technology.effects ~= nil then
            for j,Effect in pairs(Technology.effects) do
                if Effect ~= nil and Effect.type == "unlock-recipe" and Effect.recipe == Machine.name then
                    return Technology.name
                end
            end
        end
    end
    return nil
end
This thread has been locked.