25640 Posts in 4304 Topics - by 9391 Members - Latest Member: Esgaldu1

Author Topic: Factory - negative upgrade costs  (Read 297 times)

Hammelpilaw

  • Sr. Member
  • ****
  • Posts: 367
    • View Profile
    • Scrap Yard - Avofactory
Factory - negative upgrade costs
« on: January 13, 2018, 08:32:58 AM »
Player owned stations have negative upgrade costs when their price is below 3 millions (like potato factory). Maybe set a min price of 3mio for all stations, that would also help for modded stations wich may be even cheaper.

Rinart73

  • Full Member
  • ***
  • Posts: 127
  • Discord: Rinart73#7304
    • View Profile
Re: Factory - negative upgrade costs
« Reply #1 on: January 13, 2018, 08:50:42 AM »
This happens not because of factory price, but because of how getFactoryUpgradeCost function works (productions.lua).

Code: [Select]
function getFactoryUpgradeCost(production, size)

    -- calculate the difference between the value of ingredients and results
    local ingredientValue = 0
    local resultValue = 0

    for _, ingredient in pairs(production.ingredients) do
        local good = goods[ingredient.name]
        ingredientValue = ingredientValue + good.price * ingredient.amount
    end

    for _, result in pairs(production.results) do
        local good = goods[result.name]
        resultValue = resultValue + good.price * result.amount
    end

    local diff = resultValue - ingredientValue

    local costs = diff * 1000 * size
    return costs
end

While we have following in productionsindex.lua:
Code: [Select]
table.insert(productions, {factory="${good} Farm ${size}", ingredients={{name="Energy Cell", amount=6, optional=1}, {name="Water", amount=30, optional=0}}, results={{name="Potato", amount=35}}, garbages={{name="Oxygen", amount=8}}})
So, basically we have following values:
Code: [Select]
ingredientValue = 300 + 600 = 900
resultValue = 840
diff = -60
costs = -60 * 1000 * size

Is optional ingredient even a thing? How it works?
Anyway, thats because this happens.

Hammelpilaw

  • Sr. Member
  • ****
  • Posts: 367
    • View Profile
    • Scrap Yard - Avofactory
Re: Factory - negative upgrade costs
« Reply #2 on: January 13, 2018, 10:47:51 AM »
Oh yes I see. However, to me it seems this part could be improved. A station can theoreticly have negative prices for creating and updating. Both should be fixed, not just the upgrade cost. It could be like this (untested):

Code: [Select]
function getDiff(production)
    -- calculate the difference between the value of ingredients and results
    local ingredientValue = 0
    local resultValue = 0

    for _, ingredient in pairs(production.ingredients) do
        local good = goods[ingredient.name]
        ingredientValue = ingredientValue + good.price * ingredient.amount
    end

    for _, result in pairs(production.results) do
        local good = goods[result.name]
        resultValue = resultValue + good.price * result.amount
    end

    return resultValue - ingredientValue
end

function getFactoryCost(production)
    local diff = getDiff(production)
    if diff < 0 then
        diff = 0
    end
    local costs = 3000000 -- 3 mio minimum for a factory
    costs = costs + diff * 4500
    return costs
end

function getFactoryUpgradeCost(production, size)

    local diff = getDiff(production)
   
    if diff < 1 then
        diff = 1
    end

    local costs = diff * 1000 * size
    return costs
end