local isInputOutputEmpty = function(inputOrOutput) if inputOrOutput == nil then return true elseif next(inputOrOutput) == nil then return true else for num, sub in pairs(inputOrOutput) do if num ~= 1 then return false elseif type(sub) == "table" then if next(sub) ~= nil then return false end else return false end end return true end end local function constructionCallback(capacityFactor) return function(fileName, data) local updateFn = data.updateFn if data.type == "INDUSTRY" then if data.updateFn ~= nil then data.updateFn = function(params) local result = updateFn(params) if result ~= nil and result.rule ~= nil then if result.rule.capacity ~= nil then local source = isInputOutputEmpty(result.rule.input) if source == true then if isInputOutputEmpty(result.rule.output) == false then -- increase production of source industries result.rule.capacity = result.rule.capacity * capacityFactor end end end end return result end end end return data end end local sourceIndustryCapacityFactors = { 1, 1.5, 2, } function data() return { info = { minorVersion = 0, severityAdd = "NONE", severityRemove = "WARNING", name = _("Industry Expanded"), description = _("Introduces 13 new cargo types and many new industries to make for a more complex, yet balanced experience. Appropriate cargo vehicles support the new cargo types. This mod does not overwrite any vanilla assets, so it is 100% compatible with any other industry or cargo demand mod!"), tags = { "Script Mod", "Industry", "Misc", "Resource" }, authors = { { name = "Col0Korn", role = "CREATOR", }, }, params = { { key = "Col0Korn_source_industry_capacity_factor", name = _("Source Industry Capacity Factor"), values = { "1", "1.5", "2" }, defaultIndex = 1, }, }, }, runFn = function (settings, modParams) local params = modParams[getCurrentModId()] addModifier("loadConstruction", constructionCallback(sourceIndustryCapacityFactors[params.Col0Korn_source_industry_capacity_factor+1])) addModifier("loadModel", function (fileName, data) if (string.find(fileName, "vehicle") == nil) then return data end if (data.metadata) then if (data.metadata.transportVehicle) then if (data.metadata.transportVehicle.carrier) then if(data.metadata.transportVehicle.compartments) then for i=1,#data.metadata.transportVehicle.compartments do local foundFoodCapacity = 0 local foundFoodCargobay = null local foundFoodCustomCargoModels = null local foundPlasticCapacity = 0 local foundPlasticCargobay = null local foundPlasticCustomCargoModels = null local foundConstructionCapacity = 0 local foundConstructionCargobay = null local foundConstructionCustomCargoModels = null local foundLogsCapacity = 0 local foundLogsCargobay = null local foundLogsCustomCargoModels = null local foundCoalCapacity = 0 local foundCoalCargobay = null local foundCoalCustomCargoModels = null local foundFuelCapacity = 0 local foundFuelCargobay = null local foundFuelCustomCargoModels = null for j=1,#data.metadata.transportVehicle.compartments[i] do for k=1,#data.metadata.transportVehicle.compartments[i][j] do if (string.upper(data.metadata.transportVehicle.compartments[i][j][k].type) == "FOOD") then foundFoodCapacity = data.metadata.transportVehicle.compartments[i][j][k].capacity foundFoodCargobay = data.metadata.transportVehicle.compartments[i][j][k].cargoBay foundFoodCustomCargoModels = data.metadata.transportVehicle.compartments[i][j][k].customCargoModels elseif (string.upper(data.metadata.transportVehicle.compartments[i][j][k].type) == "PLASTIC") then foundPlasticCapacity = data.metadata.transportVehicle.compartments[i][j][k].capacity foundPlasticCargobay = data.metadata.transportVehicle.compartments[i][j][k].cargoBay foundPlasticCustomCargoModels = data.metadata.transportVehicle.compartments[i][j][k].customCargoModels elseif (string.upper(data.metadata.transportVehicle.compartments[i][j][k].type) == "CONSTRUCTION_MATERIALS") then foundConstructionCapacity = data.metadata.transportVehicle.compartments[i][j][k].capacity foundConstructionCargobay = data.metadata.transportVehicle.compartments[i][j][k].cargoBay foundConstructionCustomCargoModels = data.metadata.transportVehicle.compartments[i][j][k].customCargoModels elseif (string.upper(data.metadata.transportVehicle.compartments[i][j][k].type) == "LOGS") then foundLogsCapacity = data.metadata.transportVehicle.compartments[i][j][k].capacity foundLogsCargobay = data.metadata.transportVehicle.compartments[i][j][k].cargoBay foundLogsCustomCargoModels = data.metadata.transportVehicle.compartments[i][j][k].customCargoModels elseif (string.upper(data.metadata.transportVehicle.compartments[i][j][k].type) == "COAL") then foundCoalCapacity = data.metadata.transportVehicle.compartments[i][j][k].capacity foundCoalCargobay = data.metadata.transportVehicle.compartments[i][j][k].cargoBay foundCoalCustomCargoModels = data.metadata.transportVehicle.compartments[i][j][k].customCargoModels elseif (string.upper(data.metadata.transportVehicle.compartments[i][j][k].type) == "FUEL") then foundFuelCapacity = data.metadata.transportVehicle.compartments[i][j][k].capacity foundFuelCargobay = data.metadata.transportVehicle.compartments[i][j][k].cargoBay foundFuelCustomCargoModels = data.metadata.transportVehicle.compartments[i][j][k].customCargoModels end end end if(foundFoodCapacity>0) then print("mod \"Industry Expanded\" modifying vehicle to carry Livestock, Fish, Meat, Coffee, Coffee Berries, Alcohol: " .. fileName) table.insert(data.metadata.transportVehicle.compartments[i], { { type = "LIVESTOCK", capacity = foundFoodCapacity, cargoBay = foundFoodCargobay, customCargoModels = foundFoodCustomCargoModels } }) table.insert(data.metadata.transportVehicle.compartments[i], { { type = "FISH", capacity = foundFoodCapacity, cargoBay = foundFoodCargobay, customCargoModels = foundFoodCustomCargoModels } }) table.insert(data.metadata.transportVehicle.compartments[i], { { type = "MEAT", capacity = foundFoodCapacity, cargoBay = foundFoodCargobay, customCargoModels = foundFoodCustomCargoModels } }) table.insert(data.metadata.transportVehicle.compartments[i], { { type = "COFFEE_BERRIES", capacity = foundFoodCapacity, cargoBay = foundFoodCargobay, customCargoModels = foundFoodCustomCargoModels } }) table.insert(data.metadata.transportVehicle.compartments[i], { { type = "COFFEE", capacity = foundFoodCapacity, cargoBay = foundFoodCargobay, customCargoModels = foundFoodCustomCargoModels } }) table.insert(data.metadata.transportVehicle.compartments[i], { { type = "ALCOHOL", capacity = foundFoodCapacity, cargoBay = foundFoodCargobay, customCargoModels = foundFoodCustomCargoModels } }) end if(foundPlasticCapacity>0) then print("mod \"Industry Expanded\" modifying vehicle to carry Paper: " .. fileName) table.insert(data.metadata.transportVehicle.compartments[i], { { type = "PAPER", capacity = foundPlasticCapacity, cargoBay = foundPlasticCargobay, customCargoModels = foundPlasticCustomCargoModels } }) end if(foundConstructionCapacity>0) then print("mod \"Industry Expanded\" modifying vehicle to carry Oil Sand: " .. fileName) table.insert(data.metadata.transportVehicle.compartments[i], { { type = "OIL_SAND", capacity = foundConstructionCapacity, cargoBay = foundConstructionCargobay, customCargoModels = foundConstructionCustomCargoModels } }) end if(foundLogsCapacity>0) then print("mod \"Industry Expanded\" modifying vehicle to carry Marble, Silver: " .. fileName) table.insert(data.metadata.transportVehicle.compartments[i], { { type = "MARBLE", capacity = foundLogsCapacity, cargoBay = foundLogsCargobay, customCargoModels = foundLogsCustomCargoModels } }) table.insert(data.metadata.transportVehicle.compartments[i], { { type = "SILVER", capacity = foundLogsCapacity, cargoBay = foundLogsCargobay, customCargoModels = foundLogsCustomCargoModels } }) end if(foundCoalCapacity>0) then print("mod \"Industry Expanded\" modifying vehicle to carry Slag, Sand, Silver Ore: " .. fileName) table.insert(data.metadata.transportVehicle.compartments[i], { { type = "SLAG", capacity = foundCoalCapacity, cargoBay = foundCoalCargobay, customCargoModels = foundCoalCustomCargoModels } }) table.insert(data.metadata.transportVehicle.compartments[i], { { type = "SAND", capacity = foundCoalCapacity, cargoBay = foundCoalCargobay, customCargoModels = foundCoalCustomCargoModels } }) table.insert(data.metadata.transportVehicle.compartments[i], { { type = "SILVER_ORE", capacity = foundCoalCapacity, cargoBay = foundCoalCargobay, customCargoModels = foundCoalCustomCargoModels } }) end if(foundFuelCapacity>0 and foundPlasticCapacity == 0) then print("mod \"Industry Expanded\" modifying vehicle to carry Liquid Plastic: " .. fileName) table.insert(data.metadata.transportVehicle.compartments[i], { { type = "PLASTIC", capacity = foundFuelCapacity, cargoBay = foundFuelCargobay, customCargoModels = foundFuelCustomCargoModels } }) end end elseif(data.metadata.transportVehicle.compartmentsList) then for h=1,#data.metadata.transportVehicle.compartmentsList do if ( data.metadata.transportVehicle.compartmentsList[h].loadConfigs ) then for i=1,#data.metadata.transportVehicle.compartmentsList[h].loadConfigs do local foundFoodCapacity = 0 local foundFoodCustomCargoModels = null local foundPlasticCapacity = 0 local foundPlasticCustomCargoModels = null local foundConstructionCapacity = 0 local foundConstructionCustomCargoModels = null local foundLogsCapacity = 0 local foundLogsCustomCargoModels = null local foundCoalCapacity = 0 local foundCoalCustomCargoModels = null local foundFuelCapacity = 0 local foundFuelCustomCargoModels = null -- Specific check/fix added for the mod: "modwerkstatt_speedlimits_1" if ( data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries ) then for j=1,#data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries do if (string.upper(data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries[j].type) == "FOOD") then foundFoodCapacity = data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries[j].capacity foundFoodCustomCargoModels = data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries[j].customCargoModels elseif (string.upper(data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries[j].type) == "PLASTIC") then foundPlasticCapacity = data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries[j].capacity foundPlasticCustomCargoModels = data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries[j].customCargoModels elseif (string.upper(data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries[j].type) == "CONSTRUCTION_MATERIALS") then foundConstructionCapacity = data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries[j].capacity foundConstructionCustomCargoModels = data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries[j].customCargoModels elseif (string.upper(data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries[j].type) == "LOGS") then foundLogsCapacity = data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries[j].capacity foundLogsCustomCargoModels = data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries[j].customCargoModels elseif (string.upper(data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries[j].type) == "COAL") then foundCoalCapacity = data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries[j].capacity foundCoalCustomCargoModels = data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries[j].customCargoModels elseif (string.upper(data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries[j].type) == "FUEL") then foundFuelCapacity = data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries[j].capacity foundFuelCustomCargoModels = data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries[j].customCargoModels end end if(foundFoodCapacity>0) then print("mod \"Industry Expanded\" modifying vehicle to carry Livestock, Fish, Meat, Coffee, Coffee Berries, Alcohol: " .. fileName) table.insert(data.metadata.transportVehicle.compartmentsList[h].loadConfigs, {cargoEntries = { { type = "LIVESTOCK", capacity = foundFoodCapacity, customCargoModels = foundFoodCustomCargoModels }}}) table.insert(data.metadata.transportVehicle.compartmentsList[h].loadConfigs, {cargoEntries = { { type = "FISH", capacity = foundFoodCapacity, customCargoModels = foundFoodCustomCargoModels }}}) table.insert(data.metadata.transportVehicle.compartmentsList[h].loadConfigs, {cargoEntries = { { type = "MEAT", capacity = foundFoodCapacity, customCargoModels = foundFoodCustomCargoModels }}}) table.insert(data.metadata.transportVehicle.compartmentsList[h].loadConfigs, {cargoEntries = { { type = "COFFEE_BERRIES", capacity = foundFoodCapacity, customCargoModels = foundFoodCustomCargoModels }}}) table.insert(data.metadata.transportVehicle.compartmentsList[h].loadConfigs, {cargoEntries = { { type = "COFFEE", capacity = foundFoodCapacity, customCargoModels = foundFoodCustomCargoModels }}}) table.insert(data.metadata.transportVehicle.compartmentsList[h].loadConfigs, {cargoEntries = { { type = "ALCOHOL", capacity = foundFoodCapacity, customCargoModels = foundFoodCustomCargoModels }}}) end if(foundPlasticCapacity>0) then print("mod \"Industry Expanded\" modifying vehicle to carry Paper: " .. fileName) table.insert(data.metadata.transportVehicle.compartmentsList[h].loadConfigs, {cargoEntries = { { type = "PAPER", capacity = foundPlasticCapacity, customCargoModels = foundPlasticCustomCargoModels }}}) end if(foundConstructionCapacity>0) then print("mod \"Industry Expanded\" modifying vehicle to carry Oil Sand: " .. fileName) table.insert(data.metadata.transportVehicle.compartmentsList[h].loadConfigs, {cargoEntries = { { type = "OIL_SAND", capacity = foundConstructionCapacity, customCargoModels = foundConstructionCustomCargoModels }}}) end if(foundLogsCapacity>0) then print("mod \"Industry Expanded\" modifying vehicle to carry Marble, Silver: " .. fileName) table.insert(data.metadata.transportVehicle.compartmentsList[h].loadConfigs, {cargoEntries = { { type = "MARBLE", capacity = foundLogsCapacity, customCargoModels = foundLogsCustomCargoModels }}}) table.insert(data.metadata.transportVehicle.compartmentsList[h].loadConfigs, {cargoEntries = { { type = "SILVER", capacity = foundLogsCapacity, customCargoModels = foundLogsCustomCargoModels }}}) end if(foundCoalCapacity>0) then print("mod \"Industry Expanded\" modifying vehicle to carry Slag, Sand Silver Ore: " .. fileName) table.insert(data.metadata.transportVehicle.compartmentsList[h].loadConfigs, {cargoEntries = { { type = "SLAG", capacity = foundCoalCapacity, customCargoModels = foundCoalCustomCargoModels }}}) table.insert(data.metadata.transportVehicle.compartmentsList[h].loadConfigs, {cargoEntries = { { type = "SAND", capacity = foundCoalCapacity, customCargoModels = foundCoalCustomCargoModels }}}) table.insert(data.metadata.transportVehicle.compartmentsList[h].loadConfigs, {cargoEntries = { { type = "SILVER_ORE", capacity = foundCoalCapacity, customCargoModels = foundCoalCustomCargoModels }}}) end if(foundFuelCapacity>0 and foundPlasticCapacity == 0) then print("mod \"Industry Expanded\" modifying vehicle to carry Liquid Plastic: " .. fileName) table.insert(data.metadata.transportVehicle.compartmentsList[h].loadConfigs, {cargoEntries = { { type = "PLASTIC", capacity = foundFuelCapacity, customCargoModels = foundFuelCustomCargoModels }}}) end end end end end end end end end return data end) end } end