Jump to content

Module:Cargo

From Steam & Steel

Documentation for this module may be created at Module:Cargo/doc

local module = {}

-- PLEASE add trailing commas to every line in a table - it makes it easier to edit in the future!
-- do not add ambiguous information or guess-work, without proper reasoning - test and confirm in-game to your best ability!

-- keep all maps in the same order, it simplifies editing in the future
-- keep all cargo in ALPHABETICAL order

-- sort INDUSTRIES by TIER, followed by ALPHABETICAL
-- example: {Quarry, Coal Mine} - quarry is a nlower tier industry

-- WEIGHT is in KILOGRAM - it can be converted with math.floor(weight * 2.20462)

-- leave notes in the form of comments if necessary.

local page_title = mw.title.getCurrentTitle()
-- mw is a mediawiki global (i think)
local page_name = page_title.fullText

local all_maps = { "Coal Valley", "Badlands", "Gold Rush", "Scarlet Heights", "Maple Ridge", "Stormy Coast", "Misty Summit", "Hazel Sierra"}
--todo: grab these from the map module

module.cargo = {
	["Aluminium Ingots"] = {
		buy_price = 61,
		
		weight = 3130,
		
		maps = {"Scarlet Heights", "Maple Ridge", "Stormy Coast", "Misty Summit"},
		produced_at = {"Aluminium Plant"},
		consumed_at = {"Machine Shop"},
	},
	["Bauxite Ore"] = {
		buy_price = 25,
		
		weight = 1130,
		
		maps = {"Scarlet Heights", "Maple Ridge", "Stormy Coast", "Misty Summit"},
		produced_at = {"Bauxite Mine"},
		consumed_at = {"Aluminium Plant"},
	},
	["Beams"] = {
		buy_price = 16,
		
		weight = 801,
		
		maps = all_maps,
		produced_at = {"Lumber Mill"},
		consumed_at = {"Quarry", "Bauxite Mine", "Gold Mine", "Iron Mine", "Coal Mine", "Oil Well"},
	},
	["Bricks"] = {
		buy_price = 87,
		
		weight = 0,
		
		maps = {"Stormy Coast"},
		produced_at = {"Brickworks"},
		consumed_at = { },
	},
	["Cattle"] = {
		buy_price = 94,
		
		weight = 675,
		
		maps = all_maps,
		produced_at = {"Farm", "Ranch"},
		consumed_at = {"Slaughterhouse"},
	},
	["Chemicals"] = {
		buy_price = 38,
		
		weight = 2620,
		
		maps = {"Badlands", "Gold Rush"},
		produced_at = {"Oil Refinery"},
		consumed_at = {"Tannery"},
	},
	["Clay"] = {
		buy_price = 60,
		
		weight = 0,
		
		maps = {"Stormy Coast"},
		produced_at = {"Clay Pit"},
		consumed_at = { },
	},
	["Coal"] = {
		buy_price = 39,
		
		weight = 1483,
		
		maps = all_maps,
		produced_at = {"Quarry", "Coal Mine"},
		consumed_at = {"Brickworks", "Copper Mine", "Gold Smith", "Copper Works", "Iron Works", "Smeltery", "Machine Shop", "Shipyard", "Oil Refinery"},
	},
	["Copper Ingots"] = {
		buy_price = 143,
		
		weight = 10545,
		
		maps = {"Coal Valley", "Badlands", "Gold Rush"},
		produced_at = {"Copper Works"},
		consumed_at = {"Machine Shop"},
	},
	["Copper Ore"] = {
		buy_price = 22,
		
		weight = 3531,
		
		maps = {"Coal Valley", "Badlands", "Gold Rush"},
		produced_at = {"Copper Mine"},
		consumed_at = {"Copper Works"},
	},
	["Cordwood"] = {
		buy_price = 9,
		
		weight = 319,
		
		maps = all_maps,
		produced_at = {"Cactus Camp", "Forest"},
		consumed_at = { "Clay Pit", "Fishery", "Sand Bar", "Distillery", "Brickworks", "Slaughterhouse", "Food Factory", "Copper Mine", "Tannery", "Aluminium Plant", "Copper Works", "Gold Smith", "Iron Works", "Smeltery", "Oil Refinery"},
	},
	["Crude Oil"] = {
		buy_price = 38,
		
		weight = 2024,
		
		maps = {"Badlands", "Gold Rush"},
		produced_at = {"Oil Well"},
		consumed_at = { "Oil Refinery"},
	},
	["Cut Stone"] = {
		buy_price = 9,
		
		weight = 1641,
		
		maps = all_maps,
		produced_at = {"Quarry"},
		consumed_at = { }, -- no use !!!
	},
	["Fish"] = {
		buy_price = 46,
		
		weight = 0,
		
		maps = {"Stormy Coast"},
		produced_at = {"Fishery"},
		consumed_at = {"Food Factory"},
	},
	["Food"] = {
		buy_price = 28,
		
		weight = 104,
		
		maps = all_maps,
		produced_at = {"Food Factory", "Slaughterhouse"},
		consumed_at = { }, -- no use !!!
	},
	["Gold Ore"] = {
		buy_price = 17,
		
		weight = 2119,
		
		maps = {"Badlands", "Gold Rush"},
		produced_at = {"Gold Mine"},
		consumed_at = {"Gold Smith"},
	},
	["Grain"] = {
		buy_price = 11,
		
		weight = 87,
		
		maps = {"Coal Valley", "Maple Ridge", "Stormy Coast"},
		produced_at = {"Farm"},
		consumed_at = {"Distillery", "Food Factory"},
	},
	["Gravel"] = {
		buy_price = 17,
		
		weight = 2119,
		
		maps = all_maps,
		produced_at = {"Bauxite Mine", "Copper Mine", "Gold Mine", "Iron Mine", "Quarry", "Coal Mine"},
		consumed_at = {"Brickworks"},
	},
	["Grease"] = {
		buy_price = 104,
		
		weight = 2143,
		
		maps = all_maps,
		produced_at = {"Slaugherhouse", "Oil Refinery"},
		consumed_at = {"Machine Shop", "Oil Well"},
	},
	["Iron Ingots"] = {
		buy_price = 94,
		
		weight = 8437,
		
		maps = all_maps,
		produced_at = {"Iron Works", "Smeltery"},
		consumed_at = {"Machine Shop", "Shipyard"},
	},
	["Iron Ore"] = {
		buy_price = 50,
		
		weight = 2825,
		
		maps = all_maps,
		produced_at = {"Iron Mine"},
		consumed_at = {"Iron Works", "Smeltery"},
	},
	["Jewelry"] = {
		buy_price = 605,
		
		weight = 70,
		
		maps = {"Badlands", "Gold Rush"},
		produced_at = {"Gold Smith"},
		consumed_at = {},
	},
	["Kerosene"] = {
		buy_price = 36,
		
		weight = 504,
		
		maps = {"Badlands", "Gold Rush"},
		produced_at = {"Oil Refinery"},
		consumed_at = {"Copper Mine", "Gold Mine", "Iron Mine", "Quarry", "Iron Works", "Smeltery", "Coal Mine"},
	},
	["Leather"] = {
		buy_price = 6,
		
		weight = 34,
		
		maps = all_maps,
		produced_at = {"Slaughterhouse"},
		consumed_at = {"Tannery"},
	},
	["Logs"] = {
		buy_price = 7,
		
		weight = 464,
		
		maps = all_maps,
		produced_at = {"Cactus Camp", "Forest"},
		consumed_at = {"Lumber Mill"},
	},
	["Lumber"] = {
		buy_price = 19,
		
		weight = 796,
		
		maps = all_maps,
		produced_at = {"Lumber Mill"},
		consumed_at = {"Bauxite Mine", "Copper Mine", "Gold Mine", "Iron Mine", "Coal Mine"},
	},
	["Machinery"] = {
		buy_price = 1000,
		
		weight = 47599,
		
		maps = all_maps,
		produced_at = {"Machine Shop"},
		consumed_at = {"Clay Pit", "Sand Bar", "Fishery", "Food Factory", "Lumber Mill", "Copper Mine", "Coal Mine", "Oil Well", "Oil Refinery"},
	},
	["Paper"] = {
		buy_price = 0,
		
		weight = 0,
		
		maps = {"Hazel Sierra"},
		produced_at = {"Paper Mill"},
		consumed_at = {},
	},
	["Pipes"] = {
		buy_price = 165,
		
		weight = 1105,
		
		maps = {"Coal Valley", "Badlands", "Gold Rush"},
		produced_at = {"Copper Works"},
		consumed_at = {"Distillery", "Oil Well", "Oil Refinery"},
	},
	["Rails"] = {
		buy_price = 94,
		
		weight = 3822,
		
		maps = all_maps,
		produced_at = {"Iron Works", "Smeltery"},
		consumed_at = {"Copper Mine", "Gold Mine", "Iron Mine", "Coal Mine"},
	},
	["Rum"] = {
		buy_price = 28,
		
		weight = 273,
		
		maps = {"Coal Valley", "Maple Ridge", "Stormy Coast"},
		produced_at = {"Distillery"},
		consumed_at = { },
	},
	["Sand"] = {
		buy_price = 42,
		
		weight = 0,
		
		maps = {"Stormy Coast"},
		produced_at = {"Sand Bar"},
		consumed_at = { },
	},
	["Textiles"] = {
		buy_price = 28,
		
		weight = 74,
		
		maps = all_maps,
		produced_at = {"Tannery"},
		consumed_at = { },
	},
	["Tools"] = {
		buy_price = 56,
		
		weight = 352,
		
		maps = all_maps,
		produced_at = {"Machine Shop"},
		consumed_at = {"Cactus Camp", "Clay Pit", "Farm", "Forest", "Fishery", "Ranch", "Sand Bar", "Brickworks", "Food Factory", "Slaughterhouse", "Bauxite Mine", "Copper Mine", "Gold Mine", "Iron Mine", "Tannery", "Quarry", "Aluminium Plant", "Copper Works", "Gold Smith", "Iron Works", "Smeltery", "Coal Mine", "Shipyard"},
	},
	["Uncut Gems"] = {
		buy_price = 56,
		
		weight = 91,
		
		maps = {"Badlands", "Gold Rush"},
		produced_at = {"Coal Mine"},
		consumed_at = {"Gold Smith"},
	},
	["Water"] = {
		buy_price = 0,
		
		weight = 0,
		
		maps = {"Hazel Sierra"},
		produced_at = {"Water Pumping Station"},
		consumed_at = {},
	},
	["Wood Pulp"] = {
		buy_price = 0,
		
		weight = 0,
		
		maps = {"Hazel Sierra"},
		produced_at = {"Sawmill"},
		consumed_at = {},
	},
}

-- PLEASE do testing with 17' stakes on logs/beams, and 10 ton ballasts with cordwood - these are loaded with INTEGER values
-- so they can be easily calculated. purchase one resource and divide the cost by COAL VALLEY price to estimate the markup/down.

module.map_multipliers = {
	["Coal Valley"] = 1,
	["Badlands"] = 1,
	["Gold Rush"] = 1.15,
	["Scarlet Heights"] = 1.23,
	
	["Maple Ridge"] = 1.23,
	-- PLEASE test this, this is guesswork still!!!
	-- - saismee
	
	["Stormy Coast"] = 0.69,
	-- I have no idea if this is correct, PLEASE confirm
	-- This is a guess based on logs (costing 5 instead of 7), cordwood (costing 6 instead of 9), and aluminium ingots (costing 42 instead of 61)
	-- I have estimated around 69% price, as 66.6% would be too low for aluminium (41), and 70% being too high (43)
	-- - saismee
	
	["Hazel Sierra"] = 1, -- CURRENTLY UNKNOWN!
	
	["Misty Summit"] = 2,
}

for _, info in pairs(module.cargo) do
	local set = {}
	for _, map in pairs(info.maps) do set[map] = true end
	info.maps = set
end

function module.getPrice(frame)
	-- Cargo Name|Map Name
	local cargo, map = frame.args[1], frame.args[2]
	if cargo:len() < 1 then
		cargo = page_name
	end
	return string.format("$%.2f", module.cargo[cargo].buy_price * module.map_multipliers[map])
end

function module.getPriceRow(frame)
	-- Cargo Name
	local out = ""
	for index, value in ipairs(all_maps) do
		if module.cargo[frame.args[1]].maps[value] then
			out = out .. "| style=\"text-align:center;\" |" .. module.getPrice({args = {frame.args[1], value}})
		else
			out = out .. "| style=\"text-align:center;\" |"
		end
		if index ~= #all_maps then out = out .. "\n" end
	end
	return out
end

function getCargoPageRow(frame)
	-- Cargo Name
	local out = "|-\n| style=\"text-align:center;\" |<u>[[" .. frame.args[1] .. "]]</u>\n"
	
	out = out .. module.getPriceRow(frame)
	
	out = out .. "\n| style=\"text-align:center;\" |" .. module.getValue({args = {frame.args[1], "weight"}}) .. " kg"
	.. "\n| style=\"text-align:center;\" |" .. math.floor(module.getValue({args = {frame.args[1], "weight"}}) * 2.20462) .. " lbs"
	
	if #module.getValue({args = {frame.args[1], "produced_at"}}) > 0 then
		out = out .. "\n| style=\"text-align:center;\" | [[" .. table.concat(module.getValue({args = {frame.args[1], "produced_at"}}), "]], [[") .. "]]"
	else
		out = out .. "\n| style=\"text-align:center;\" | N/A" -- huh?
	end
	
	if #module.getValue({args = {frame.args[1], "consumed_at"}}) > 0 then
		out = out .. "\n| style=\"text-align:center;\" | [[" .. table.concat(module.getValue({args = {frame.args[1], "consumed_at"}}), "]], [[") .. "]]"
	else
		out = out .. "\n| style=\"text-align:center;\" | [[Freight Depot]]"
	end
	
	return out
end

function module.getCargoPage(frame)
	local out = ""
	local sortable_cargo = {}
	for name, info in pairs(module.cargo) do
		info.name = name
		table.insert(sortable_cargo, info)
	end
	table.sort(sortable_cargo, function(a, b) return a.name:lower() < b.name:lower() end)
	for _, info in pairs(sortable_cargo) do
		out = out .. getCargoPageRow({args = {info.name}}) .. "\n"
	end
	
	return out
end

function module.getValue(frame)
	-- Cargo Name|Property
	local cargo, property = frame.args[1], frame.args[2]
	if not cargo then
		cargo = page_name
	end
	return module.cargo[cargo][property]
end

return module