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 |
Line 327: |
Line 313: |
| local bauxite = (eq:scrap().bauxite or 1) * 10 | | local bauxite = (eq:scrap().bauxite or 1) * 10 |
| local maxRate | | local maxRate |
− | for typeGroup, resourceGroups in pairs(groups) do | + | for typeGroup, resourceGroups in ipairs(Self.groups) do |
− | for resourceGroup, n in pairs(resourceGroups) do | + | for resourceGroup, equipment in ipairs(resourceGroups) do |
− | local fuel, ammo, steel, bauxite = ensureResourceGroup(fuel, ammo, steel, bauxite, resourceGroup) | + | if equipment[id] and equipment[id] > 0 then |
− | local recipe = U.format{
| + | local fuel, ammo, steel, bauxite = ensureResourceGroup(fuel, ammo, steel, bauxite, resourceGroup) |
− | "${fuel}/${ammo}/${steel}/${bauxite}",
| + | local recipe = U.format{ |
− | fuel = fuel,
| + | "${fuel}/${ammo}/${steel}/${bauxite}", |
− | ammo = ammo,
| + | fuel = fuel, |
− | steel = steel,
| + | ammo = ammo, |
− | bauxite = bauxite,
| + | steel = steel, |
− | }
| + | bauxite = bauxite, |
− | result[recipe] = result[recipe] or {
| + | } |
− | fuel = fuel,
| + | result[recipe] = result[recipe] or { |
− | ammo = ammo,
| + | fuel = fuel, |
− | steel = steel,
| + | ammo = ammo, |
− | bauxite = bauxite,
| + | steel = steel, |
− | resourceGroup = resourceGroup,
| + | bauxite = bauxite, |
− | types = {},
| + | resourceGroup = resourceGroup, |
− | }
| + | types = {}, |
− | local rate = U.round(100 * n / 50)
| + | } |
− | result[recipe].types[Self.typeGroups[typeGroup]] = rate
| + | local rate = U.round(100 * equipment[id] / 50) |
− | if not maxRate or rate > maxRate then
| + | result[recipe].types[Self.typeGroups[typeGroup]] = result[recipe].types[Self.typeGroups[typeGroup]] or { |
− | maxRate = rate
| + | rate = rate, |
| + | } |
| + | if not maxRate or rate > maxRate then |
| + | maxRate = rate |
| + | end |
| + | break |
| end | | end |
| end | | end |
Line 368: |
Line 359: |
| }, | | }, |
| types = U.ijoin(U.imap(types, function(type) | | types = U.ijoin(U.imap(types, function(type) |
− | local rate = result[recipe].types[type] | + | local rate = result[recipe].types[type].rate |
| return (rate == maxRate and U.red or U.id)(type) | | return (rate == maxRate and U.red or U.id)(type) |
| end), "/"), | | end), "/"), |
| rates = U.ijoin(U.imap(types, function(type) | | rates = U.ijoin(U.imap(types, function(type) |
− | local rate = result[recipe].types[type] | + | local rate = result[recipe].types[type].rate |
− | return (rate == maxRate and U.red or U.id)(tostring(result[recipe].types[type]) .. "%") | + | return (rate == maxRate and U.red or U.id)(tostring(rate) .. "%") |
| end), "/"), | | end), "/"), |
| } | | } |