Jump to content

[MOD] Trading Routes by Value -- Simple


Gwydion5

Recommended Posts

I am not a coder, scripter, mathematician. So anyone who wants to take this and improve it, or do it better, be my guest.  8)

 

One thing that I've noticed is that the routes compiled in the trading system GUI, are not optimal. The only thing they care about it seems is price points. But as some of you may have noticed, often times the lowest price for you to buy a good, and the highest price for you to sell it, can be constrained by the volume of the transaction possible. So what I have done is changed it and put more emphasis on the total value of purchase and sale of goods over the price.

 

For example:

 

Buying Logic:

* War Robots in -207:18 can be bought for a price of $67,389 and has a stock of 4256 for a buy value of $286,807,584

* War Robots in -212:18 can be bought for a price of $37,927 and has a stock of 1331 for a buy value of $50,480,837

 

Currently the routes logic would pick -212:18 as the best sector to buy War Robots from and while it has a better price point, it's profit potential is actually less.

 

Selling Logic:

* War Robots in -207:-5 can be sold for a price of $93,174 and has a stock of 2421 units with a max stock of 6200, making  the actual sellable stock 3779 for a total of $352,104,546

* War Robots in -194:4 can be sold for a price of $105,826 and has a stock of 268 units with a max stock of 1600, making the actual sellable stock 1332 for a total of $140,960,232

 

Currently the routes logic would pick -194:4 as the best sector to sell War Robots to and while it has the better price point, it's profit potential is actually less.

 

So what is returned in the Routes tab for the Trade System is this :

* War Robots | 37,927 | -212:18 | > | 105,826 | -194:4 | ( 1331 units for a buy value of $50,480,837 selling 1331 for a sale value $140,854,406 and profit of $90,373,569)

 

What my alterations do instead would return this:

* War Robots | 67,389 | -207:18 | > | 93,174 | -207:-5 | ( 4256 units for a buy value of $286,807,584 selling 3779 units for a sale value of $352,104,546 and a profit of $65,296,962 with 477 units left over. Which if sold to -194:4 would result in a sale value of $50,479,002 for a total profit of 115,775,964)

 

This particular example is not typical. Usually a station selling a little more than 3x the stock is a lot more competitive on the price, but since it was an ingame example that I tested the mod code against to make sure it worked like I wanted it to, I figured I'd just use that. I will also admit that there is a lot more work to be done if you want to get in to more accurate route valuations. But since the current route valuations only seem to care about price and not total value, I figured this is a decent improvement.

 

Attached is the lua file, you need to extract this in your "\Steam\steamapps\common\Avorion\data\scripts\systems" directory.

 

Unless I'm feeling particularly self-abusive, I will not be doing more than I already have. I have also commented on original code and the code I added should anyone want to understand what I did and/or improve upon it. Comments and feedback appreciated.

tradingoverview.zip

Link to comment
Share on other sites

Value column added at the end of the sellable table. ((maxStock - stock) * price = sellable.value)

177: table.insert(sellable, {good = good, price = price, stock = stock, maxStock = maxStock, station = station.title, titleArgs = station:getTitleArguments(), stationIndex = station.index, coords = vec2(Sector():getCoordinates()), value = ((maxStock-stock) * price)})

 

Value column added at the end of the buyable table. (stock * price = buyable.value)

198: table.insert(buyable, {good = good, price = price, stock = stock, maxStock = maxStock, station = station.title, titleArgs = station:getTitleArguments(), stationIndex = station.index, coords = vec2(Sector():getCoordinates()), value = (stock * price)})

 

changed buyable valuation from price to stock.

240: --if existing == nil or offer.price < existing.price then -- original code.

241: -- line below ideally should be nil or offer.stock > existing stock AND offer.price < existing.price. But I couldn't get it to work.

242: if existing == nil or offer.stock > existing.stock then -- Generally speaking, higher offer stock tends to be better.

 

changed sellable valuation from price to value.

252: --if existing == nil or offer.price > existing.price then -- original code.

253: if existing == nil or offer.value > existing.value then -- Highest Sale Value from gatherData function for sellable

 

changed routes valuation from price to value.

269: --if sellable ~= nil and sellable.price > offer.price then -- original code

270: if sellable ~= nil and sellable.value > offer.value then --Makes sure sell value is greater than buy value.

 

New sort function for routesGUI based on value

401: -- New sort function for routes based on Value

402: function routesByValue(a, b)

403: -- calculate max value

404: local pa = (a.sellable.value - a.buyable.value)

405: local pb = (b.sellable.value - b.buyable.value)

406: return pa > pb

407: end

 

Implementation of new sort function in routesGUI

536: --table.sort(routes, routesByPriceMargin) -- original code

537: table.sort(routes, routesByValue) -- uses new sort function "routesByValue"

Link to comment
Share on other sites

Thank you for looking into this!

Does it also show the stock that is able to be sold with this?

Some stations pop up as trade routes, only to find out later that they sell a considerable small amount compared to the factory selling the required resources.

Link to comment
Share on other sites

Thank you for looking into this!

Does it also show the stock that is able to be sold with this?

Some stations pop up as trade routes, only to find out later that they sell a considerable small amount compared to the factory selling the required resources.

 

It does not, you'd have to edit the routesGUI. I'm not a coder, so the amount of time it would take me to learn the logic / syntax to correctly modify the interface for routes is a path of much resistance. I'm sure I could do it, but it would take me 10 to 20 or even 50 times longer than someone who is actually proficient and comfortable with lua scripting.

 

What my mod/alterations really do is give you the highest buyable good station and highest sellable station and make those the preferred routes, sorted by the route with the highest profit. Like I said it's a simple mod, and one that could use a lot of improvement. But it will get the job done and give you generally more profitable / productive trade routes to go after.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...