| Line 1: |
Line 1: |
| − | local U = require("Module:Utils") | + | local U = require("Module:Core") |
| | | | |
| | local Self = {} | | local Self = {} |
| Line 289: |
Line 289: |
| | } | | } |
| | --]] | | --]] |
| − |
| |
| − | function findGroups(id)
| |
| − | local groups = {}
| |
| − | for typeGroup, resourceGroups in ipairs(Self.groups) do
| |
| − | for resourceGroup, equipment in ipairs(resourceGroups) do
| |
| − | if equipment[id] and equipment[id] > 0 then
| |
| − | groups[typeGroup] = groups[typeGroup] or {}
| |
| − | groups[typeGroup][resourceGroup] = equipment[id]
| |
| − | end
| |
| − | end
| |
| − | end
| |
| − | return groups
| |
| − | end
| |
| | | | |
| | function ensureResourceGroup(fuel, ammo, steel, bauxite, resourceGroup) | | function ensureResourceGroup(fuel, ammo, steel, bauxite, resourceGroup) |
| Line 321: |
Line 308: |
| | local result = {} | | local result = {} |
| | local id = eq:id() | | local id = eq:id() |
| − | local groups = findGroups(id)
| |
| | local fuel = (eq:scrap().fuel or 1) * 10 | | local fuel = (eq:scrap().fuel or 1) * 10 |
| | local ammo = (eq:scrap().ammo or 1) * 10 | | local ammo = (eq:scrap().ammo or 1) * 10 |
| | local steel = (eq:scrap().steel or 1) * 10 | | local steel = (eq:scrap().steel or 1) * 10 |
| | local bauxite = (eq:scrap().bauxite or 1) * 10 | | local bauxite = (eq:scrap().bauxite or 1) * 10 |
| − | for typeGroup, resourceGroups in pairs(groups) do | + | local maxRate |
| − | for resourceGroup, n in pairs(resourceGroups) do | + | for typeGroup, resourceGroups in ipairs(Self.groups) do |
| − | local fuel, ammo, steel, bauxite = ensureResourceGroup(fuel, ammo, steel, bauxite, resourceGroup) | + | for resourceGroup, equipment in ipairs(resourceGroups) do |
| − | local recipe = U.format{
| + | if equipment[id] and equipment[id] > 0 then |
| − | "${fuel}/${ammo}/${steel}/${bauxite}",
| + | local fuel, ammo, steel, bauxite = ensureResourceGroup(fuel, ammo, steel, bauxite, resourceGroup) |
| − | fuel = fuel,
| + | local recipe = U.format{ |
| − | ammo = ammo,
| + | "${fuel}/${ammo}/${steel}/${bauxite}", |
| − | steel = steel,
| + | fuel = fuel, |
| − | bauxite = bauxite,
| + | ammo = ammo, |
| − | }
| + | steel = steel, |
| − | result[recipe] = result[recipe] or {}
| + | bauxite = bauxite, |
| − | result[recipe][Self.typeGroups[typeGroup]] = U.round(100 * n / 50)
| + | } |
| | + | result[recipe] = result[recipe] or { |
| | + | fuel = fuel, |
| | + | ammo = ammo, |
| | + | steel = steel, |
| | + | bauxite = bauxite, |
| | + | resourceGroup = resourceGroup, |
| | + | types = {}, |
| | + | } |
| | + | local rate = U.round(100 * equipment[id] / 50) |
| | + | result[recipe].types[Self.typeGroups[typeGroup]] = result[recipe].types[Self.typeGroups[typeGroup]] or { |
| | + | rate = rate, |
| | + | } |
| | + | if not maxRate or rate > maxRate then |
| | + | maxRate = rate |
| | + | end |
| | + | break |
| | + | end |
| | end | | end |
| | end | | end |
| Line 344: |
Line 347: |
| | U.isort(U.keys(result)), | | U.isort(U.keys(result)), |
| | function(recipe) | | function(recipe) |
| − | local types = U.isort(U.keys(result[recipe])) | + | local types = U.isort(U.keys(result[recipe].types)) |
| | + | local resourceGroup = result[recipe].resourceGroup |
| | return U.format{ | | return U.format{ |
| | rates and "${rates}" or "${recipe} (${types})", | | rates and "${rates}" or "${recipe} (${types})", |
| − | recipe = recipe, | + | recipe = U.format{ |
| − | types = U.ijoin(types, "/"), | + | "${fuel}/${ammo}/${steel}/${bauxite}", |
| − | rates = U.ijoin(U.imap(types, function(type) return tostring(result[recipe][type]) .. "%" end), "/"), | + | fuel = (resourceGroup == 1 and U.red or U.id)(result[recipe].fuel), |
| | + | ammo = (resourceGroup == 2 and U.red or U.id)(result[recipe].ammo), |
| | + | steel = (resourceGroup == 1 and U.red or U.id)(result[recipe].steel), |
| | + | bauxite = (resourceGroup == 3 and U.red or U.id)(result[recipe].bauxite), |
| | + | }, |
| | + | types = U.ijoin(U.imap(types, function(type) |
| | + | local rate = result[recipe].types[type].rate |
| | + | return (rate == maxRate and U.red or U.id)(type) |
| | + | end), "/"), |
| | + | rates = U.ijoin(U.imap(types, function(type) |
| | + | local rate = result[recipe].types[type].rate |
| | + | return (rate == maxRate and U.red or U.id)(tostring(rate) .. "%") |
| | + | end), "/"), |
| | } | | } |
| | end | | end |