Transportorio

by Zomiib

Transport resources and trade your way up! start with just a bit of coal and work your way up to rockets.

Overhaul
2 years ago
1.1
1.23K

b trades list shows not the exact product ratios

2 years ago

In the trade list are many trades like 10 plastic --> 1 electric-engine
but in real life :) you dont get 1 because this recipe has a probality set so it is 10 plastic --> 0.545 electric-engine
the GUI shows "1" because the "product.amount" = 1 but it ignores the product.probabilty in this case is not 1

so i made a fix for this ... see below

then there are some trades with two products but of the same item like 10 rocket-fuel ---> 2 electric-engine + 1 electric-engine
(the "1" is always the above probability thing)- so it means ---> 2 electric-engine + 0.456 electric-engine
and this simply means you get ---> 2.456 electric-engine

so i updated the function to show only the precise resulting product amount you will get (rounded by 4 digits)

and here is the "patch note"

show precise ratios

in lua.gui in function Trades_menu:create_row

--after
trade_row_flow.add{type="label", caption = " --->"}
-- replace product loop with

local last_button = nil
local last_amount = 0.0
for i, product in ipairs(products) do

    -- calculate the precise product amount
    local product_amount = 0.0
    if product.amount ~= nil then
        product_amount = product.amount
    end
    if product.amount_min~=nil and product.amount_max~=nil then
        product_amount = product.amount_min * product.amount_max / 2 -- avarage aof min and max
    end 
    if product.probability~=nil then
        product_amount = product_amount * product.probability
    end 
    -- round to 4 digits
    product_amount = math.floor(product_amount * 10^4 + 0.5) / 10^4



    if last_button~=nil then
        if last_button.sprite == product.type .. "/" .. product.name then
            -- same item so we only add the new amount
            product_amount = last_amount + product_amount
        else
            -- not the same item   show it
            trade_row_flow.add(last_button)
            trade_row_flow.add {type="label", caption = last_amount }
        end

    end

    last_amount =  product_amount
    last_button = {
        type="sprite-button",
        sprite = product.type .. "/" .. product.name, 
        tags={
            action="tro_filter_list",
            item_name=product.name,
            filter="product", 
            type=product.type
        },
        tooltip={"", {"tro.item_name"}, ": ", product.name, " | ", {"tro.trade_menu_item_sprite_button_instructions"}}
    }

end

trade_row_flow.add(last_button)
trade_row_flow.add {type="label", caption = last_amount }

end


...its such a great scenario I m in .. 40+h (in 4 days) THANKS!

New response