local function constructionCallback(fileName, data) local updateFn = data.updateFn if data.type == "TOWN_BUILDING" then if data.updateFn ~= nil then data.updateFn = function(params) local parcelSize = 8 local borderSize = 2 local mailChance = 0.33 local wasteChance = 0.33 if ( data.townBuildingParams.landUseType == "RESIDENTIAL" )then if ( math.random() < mailChance ) then params.cargoTypes = { "MAIL" } end end local result = updateFn(params) local ruleCapacity = math.ceil(params.capacity / 4) if (ruleCapacity > 0 and params.cargoTypes and #params.cargoTypes > 0) then if params.cargoTypes then result.stocks = { } local inputs = {} for i=1, #params.cargoTypes do local t = {} for j=1, #params.cargoTypes do t[j] = 0 end t[i] = 1 inputs[#inputs + 1] = t result.stocks[i] = { cargoType = params.cargoTypes[i], type = "RECEIVING", edges = { }, moreCapacity = ruleCapacity * 100 } end local outStock = {} if (data.townBuildingParams.landUseType == "COMMERCIAL" or data.townBuildingParams.landUseType == "RESIDENTIAL") and ( math.random() < mailChance ) then outStock = { UNSORTED_MAIL = 1 } elseif (data.townBuildingParams.landUseType == "INDUSTRIAL") and ( math.random() < wasteChance ) then outStock = { WASTE = 1 } end result.rule = { input = inputs, output = outStock, capacity = ruleCapacity, consumptionFactor = 1.2, } end end return result end end elseif data.type == "INDUSTRY" then data.updateFn = function(params) local result = updateFn(params) if result ~= nil then if result.rule ~= nil then local currentLevel = (params.productionLevel or 0) + 1 local numLevels = 1 -- not sure how to get levels local inpEnabled = (params.inputEnabled or 1) == 1 local inputRule = (params.input or (inpEnabled and data.stockListConfig and data.stockListConfig.rule.input)) or { {} } params.industrialCapacity = 5+3*currentLevel; if params.commercialCapacity then result.personCapacity = { type = "COMMERCIAL", capacity = params.commercialCapacity, } elseif params.industrialCapacity then result.personCapacity = { type = "INDUSTRIAL", capacity = params.industrialCapacity, } end result.cost = 2518745 * numLevels * (1+result.rule.capacity/200) -- cost depends on capacity and potential if not inputRule[1][1] then result.cost = 4 * result.cost end -- raw industries are more expensive --result.bulldozeCost = 1000000 -- bulldozing industries does not work --print(table.toString(inputRule)) end return result end end end return data end --Special thanks to: --Yeol for the town building, industry, and improvements to the cargo injection script --FxUK for assistance with adding these scripts to the mod.lua, thus removing the need to overwrite any vanilla files. function data() return { info = { minorVersion = 0, severityAdd = "NONE", severityRemove = "WARNING", name = _("Industry Expanded Add-On - Mail and Waste"), description = _("Introduces Mail and Waste cargo chains (3 new cargo types and 2 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 most other industry or cargo demand mod!"), tags = { "Script Mod", "Industry", "Misc", "Resource" }, authors = { { name = "Col0Korn", role = "CREATOR", }, }, }, runFn = function (settings) game.config.industryButton = true addModifier("loadConstruction", constructionCallback) 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 foundGoodsCapacity = 0 local foundGoodsCargobay = null local foundGoodsCustomCargoModels = null local foundCoalCapacity = 0 local foundCoalCargobay = null local foundCoalCustomCargoModels = 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) == "GOODS") then foundGoodsCapacity = data.metadata.transportVehicle.compartments[i][j][k].capacity foundGoodsCargobay = data.metadata.transportVehicle.compartments[i][j][k].cargoBay foundGoodsCustomCargoModels = 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 end end end if(foundGoodsCapacity>0) then print("mod \"Industry Expanded\" modifying vehicle to carry Mail, unsorted mail: " .. fileName) table.insert(data.metadata.transportVehicle.compartments[i], { { type = "MAIL", capacity = foundGoodsCapacity, cargoBay = foundGoodsCargobay, customCargoModels = foundGoodsCustomCargoModels } }) table.insert(data.metadata.transportVehicle.compartments[i], { { type = "UNSORTED_MAIL", capacity = foundGoodsCapacity, cargoBay = foundGoodsCargobay, customCargoModels = foundGoodsCustomCargoModels } }) end if(foundCoalCapacity>0) then print("mod \"Industry Expanded\" modifying vehicle to carry Waste: " .. fileName) table.insert(data.metadata.transportVehicle.compartments[i], { { type = "WASTE", capacity = foundCoalCapacity, cargoBay = foundCoalCargobay, customCargoModels = foundCoalCustomCargoModels } }) 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 foundGoodsCapacity = 0 local foundGoodsCustomCargoModels = null local foundCoalCapacity = 0 local foundCoalCustomCargoModels = 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) == "GOODS") then foundGoodsCapacity = data.metadata.transportVehicle.compartmentsList[h].loadConfigs[i].cargoEntries[j].capacity foundGoodsCustomCargoModels = 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 end end if(foundGoodsCapacity>0) then print("mod \"Industry Expanded\" modifying vehicle to carry Mail, Unsorted mail: " .. fileName) table.insert(data.metadata.transportVehicle.compartmentsList[h].loadConfigs, {cargoEntries = { { type = "MAIL", capacity = foundGoodsCapacity, customCargoModels = foundGoodsCustomCargoModels, }}}) table.insert(data.metadata.transportVehicle.compartmentsList[h].loadConfigs, {cargoEntries = { { type = "UNSORTED_MAIL", capacity = foundGoodsCapacity, customCargoModels = foundGoodsCustomCargoModels,}}}) end if(foundCoalCapacity>0) then print("mod \"Industry Expanded\" modifying vehicle to carry Waste: " .. fileName) table.insert(data.metadata.transportVehicle.compartmentsList[h].loadConfigs, {cargoEntries = { { type = "WASTE", capacity = foundCoalCapacity, customCargoModels = foundCoalCustomCargoModels, }}}) end end end end end end end end end return data end) end } end