[WIP/MOD] Supply And Trade Routes (including build supply and mining)

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

leecarter
Posts: 377
Joined: Sat, 9. Sep 06, 22:35
x3tc

Re: [WIP/MOD] Supply And Trade Routes (including build supply and mining)

Post by leecarter » Fri, 28. Dec 18, 21:12

TheDeliveryMan wrote:
Fri, 28. Dec 18, 18:12
Alright, noted as frequently made feature request ;)
As I play this afternoon my "station building supply" station is providing me with an obscene amount of turret and shield components. What would be cool is if I could set up a station with nothing but storage and call it the over stock station. I would manually dump wares into the overstock when I had enough on hand. Then I would have these aforementioned "direct transfer" ships set up to snag the wares from the overstock station (a station with no prices associated to it) and distribute them to various stripped down stations throughout the galaxy. So like a station with nothing but a dock, storage, and a shield component module sitting in Profit Center that doesn't produce anything, just waits for overstock to appear and then sells it, you could also associate tater traders to those stations for selling.

There's a lot of uses for being able to tell a ship "go put this thing in that thing and keep doing it", especially if you want to go the trade empire route. A network of production hubs, storage hubs, both locked to trading with other factions, and then perfectly located little store fronts to sell them in would be so cool to build. Would add a new dimension to the game when I finally go to wipe the Teladi menace from the galaxy too.

TheDeliveryMan
Posts: 255
Joined: Sat, 10. Dec 11, 04:10
x4

Re: [WIP/MOD] Supply And Trade Routes (including build supply and mining)

Post by TheDeliveryMan » Sat, 29. Dec 18, 19:17

leecarter wrote:
Fri, 28. Dec 18, 21:12
TheDeliveryMan wrote:
Fri, 28. Dec 18, 18:12
Alright, noted as frequently made feature request ;)
As I play this afternoon my "station building supply" station is providing me with an obscene amount of turret and shield components. What would be cool is if I could set up a station with nothing but storage and call it the over stock station. I would manually dump wares into the overstock when I had enough on hand. Then I would have these aforementioned "direct transfer" ships set up to snag the wares from the overstock station (a station with no prices associated to it) and distribute them to various stripped down stations throughout the galaxy. So like a station with nothing but a dock, storage, and a shield component module sitting in Profit Center that doesn't produce anything, just waits for overstock to appear and then sells it, you could also associate tater traders to those stations for selling.

There's a lot of uses for being able to tell a ship "go put this thing in that thing and keep doing it", especially if you want to go the trade empire route. A network of production hubs, storage hubs, both locked to trading with other factions, and then perfectly located little store fronts to sell them in would be so cool to build. Would add a new dimension to the game when I finally go to wipe the Teladi menace from the galaxy too.
What if you could create buy and sell offers at your storage hubs and store fronts?

leecarter
Posts: 377
Joined: Sat, 9. Sep 06, 22:35
x3tc

Re: [WIP/MOD] Supply And Trade Routes (including build supply and mining)

Post by leecarter » Sat, 29. Dec 18, 21:21

TheDeliveryMan wrote:
Sat, 29. Dec 18, 19:17
What if you could create buy and sell offers at your storage hubs and store fronts?
You mean create buy offers for goods you don't actually produce at the station? Yeah that would work too, you could basically make your own trade station then, no need to slap on a factory mod just to be able to sell things. That would be sweet!

TheDeliveryMan
Posts: 255
Joined: Sat, 10. Dec 11, 04:10
x4

Re: [WIP/MOD] Supply And Trade Routes (including build supply and mining)

Post by TheDeliveryMan » Sun, 30. Dec 18, 19:08

leecarter wrote:
Sat, 29. Dec 18, 21:21
TheDeliveryMan wrote:
Sat, 29. Dec 18, 19:17
What if you could create buy and sell offers at your storage hubs and store fronts?
You mean create buy offers for goods you don't actually produce at the station? Yeah that would work too, you could basically make your own trade station then, no need to slap on a factory mod just to be able to sell things. That would be sweet!
Yes, I tested it with a regular player station with just a dock and storage. From a script I use the same function that runs on vanilla trade stations. I can configure it to be a buy, sell, or both offer and I can set the price to be either fixed at average or dynamic. The actual price and amount calculations are then done by the game engine. These offers show up on the map and my trade route freighters reacted to them just as expected, so that seems to work. Unfortunately, the vanilla station overview only displays the sell offer but not the buy offer.

leecarter
Posts: 377
Joined: Sat, 9. Sep 06, 22:35
x3tc

Re: [WIP/MOD] Supply And Trade Routes (including build supply and mining)

Post by leecarter » Sun, 30. Dec 18, 19:17

TheDeliveryMan wrote:
Sun, 30. Dec 18, 19:08
Yes, I tested it with a regular player station with just a dock and storage. From a script I use the same function that runs on vanilla trade stations. I can configure it to be a buy, sell, or both offer and I can set the price to be either fixed at average or dynamic. The actual price and amount calculations are then done by the game engine. These offers show up on the map and my trade route freighters reacted to them just as expected, so that seems to work. Unfortunately, the vanilla station overview only displays the sell offer but not the buy offer.
Can you see them in the right click context -> trade offers dialog? Ideally you'd be able to adjust buying manually, but if they exist and are automatic you've basically just created a player trade station mod! Nice!

I have some X4 time set aside this afternoon and I'd be happy to do some testing if you want to share. I'll post some feedback before I go to bed. Feels like a totally different mod, so maybe create a new thread. Or, just send me a PM with the download link if you want to keep it away from the masses for now.

At any rate, very cool - can't wait to try it!

LegionOfOne
Posts: 122
Joined: Sun, 16. Dec 18, 14:16
x4

Re: [WIP/MOD] Supply And Trade Routes (including build supply and mining)

Post by LegionOfOne » Tue, 1. Jan 19, 16:25

I would love a mod to make a true trade station as well ! I've been trying to mod the station overview myself, trying to show every ware when there are no production modules so I can set buy and sell orders. I've even tried dummy production modules that simulate inputs and outputs to allow buy/sell orders without producing anything, but no luck yet.
If you can achieve something similar, count me in for beta-testing and debug.

What's really needed is the ability to add and remove buy/sell orders on every ware when a station only has storage, and the ability to set prices on auto or user-defined values.
One or a few stations set to buy low and sell high would really help with the game's economy as well as our pockets. Any system with an overproduction and falling prices would get a new client before the price craters, and until the prices rises to a reasonnable level again. And any system with a critical shortage and a spiking price would get a new supplier, until the price drops to reasonnable levels again. I hope it may fix some of the current bottlenecks in the economy.

Next order of business would be fixing storage allocation, so you can set how much storage space to 'reserve' for every ware, and maybe have every cargo space not reserved be open to all wares.
Right now the storage allocation is quite a mess on production stations too. They allocate all available storage automatically, meaning I can't just tell a station to keep a reasonnable supply of raw resources and leave a huge cargo space available to stockpile my finished goods while I wait for the price to rise.
Also, if I produce a lot of water and consume a little, I can't set my station to keep a set reserve of water and sell everything above that reserve. If you give a sell order, they will potentially sell everything to the last drop and stop production down the line.

So if you see a potential fix for any of that, I'll gladly help as well !

Good luck :)

Edit : Something on-topic !
Could you do an even simpler version of the trade script that just trades one ware between two stations, constantly, without profit calculations or any kind of downtime, no matter if they sell at the same price they bought or even at a loss ?
That way you can setup supply routes between your own stations easily without adding unneccessary caculations, and worry about making money down the line. Also, it should stop traders idling so damn much ! :)

leecarter
Posts: 377
Joined: Sat, 9. Sep 06, 22:35
x3tc

Re: [WIP/MOD] Supply And Trade Routes (including build supply and mining)

Post by leecarter » Tue, 1. Jan 19, 17:10

LegionOfOne wrote:
Tue, 1. Jan 19, 16:25
I would love a mod to make a true trade station as well ! I've been trying to mod the station overview myself, trying to show every ware when there are no production modules so I can set buy and sell orders. I've even tried dummy production modules that simulate inputs and outputs to allow buy/sell orders without producing anything, but no luck yet.
If you can achieve something similar, count me in for beta-testing and debug.

What's really needed is the ability to add and remove buy/sell orders on every ware when a station only has storage, and the ability to set prices on auto or user-defined values.
One or a few stations set to buy low and sell high would really help with the game's economy as well as our pockets. Any system with an overproduction and falling prices would get a new client before the price craters, and until the prices rises to a reasonnable level again. And any system with a critical shortage and a spiking price would get a new supplier, until the price drops to reasonnable levels again. I hope it may fix some of the current bottlenecks in the economy.

Next order of business would be fixing storage allocation, so you can set how much storage space to 'reserve' for every ware, and maybe have every cargo space not reserved be open to all wares.
Right now the storage allocation is quite a mess on production stations too. They allocate all available storage automatically, meaning I can't just tell a station to keep a reasonnable supply of raw resources and leave a huge cargo space available to stockpile my finished goods while I wait for the price to rise.
Also, if I produce a lot of water and consume a little, I can't set my station to keep a set reserve of water and sell everything above that reserve. If you give a sell order, they will potentially sell everything to the last drop and stop production down the line.

So if you see a potential fix for any of that, I'll gladly help as well !

Good luck :)

Edit : Something on-topic !
Could you do an even simpler version of the trade script that just trades one ware between two stations, constantly, without profit calculations or any kind of downtime, no matter if they sell at the same price they bought or even at a loss ?
That way you can setup supply routes between your own stations easily without adding unneccessary caculations, and worry about making money down the line. Also, it should stop traders idling so damn much ! :)
You and I are totally on the same page.

To make an efficient (and fun) trade empire we need to able to separate production -> warehouse -> distribution -> sales. A good network of specialized hubs would use far fewer ships, be much cheaper to build, and be much more profitable as you could build mini trade stations along the highways or in sectors where the wares are in the most demand. Let the AI do the legwork and come to your perfectly placed outlet stores instead of building a massive fleet of trade ships. Meanwhile the real core of your empire is all in one or two sectors doing all the resource gathering and production.

Would also make the strategic side better because it would be easier to defend and launch attacks from your self-sustaining core sectors (this is where player shipbuilding really needs to be in game - but that's another topic). Having trade stations is a good first step as you could build them and then lock trading to other factions basically creating a warehouse, but you still have to play the price game even though it's all your money and you still have to deal with the pesky manager dictating storage amounts.

Hey TheDeliveryMan, is it possible to make it so we can add more than one ware to your trader script? Also, I've found that it works great between sectors, but in the same sector the ships have a tendency to start meandering aimlessly after awhile (at least between player owned stations).

LegionOfOne
Posts: 122
Joined: Sun, 16. Dec 18, 14:16
x4

Re: [WIP/MOD] Supply And Trade Routes (including build supply and mining)

Post by LegionOfOne » Tue, 1. Jan 19, 19:19

Agreed on all points :)

For shipbuilding, tried the mod, unfortunately the saves got corrupted after a while so I'll have to wait for Egosoft to implement it in 2.0 :rant:

I thought of a potential quick and dirty solution for trade stations :
If you can make a trade script that just grabs a ware from a player-owned station A, no buying it or anything, just grab it, and then just dump it into another player-owned station's inventory, we could achieve the desired result.
(should still check that the station's cargo isn't completely full, and shouldn't be used on a production station since it would mess with reserved spaces for wares)
Because once a station has a ware in inventory, you can set a sell order on it, using the logistical overview. So the only problem is supply. At worst the sell order would disappear once you exhaust your stock (not tested), and you'll have to wait for your traders to 'force-feed' that station more wares to be able to set a sell order again.
Bonus, that station would have no buy orders set at all, so traders assigned to it would just sell and sell more :)

TheDeliveryMan
Posts: 255
Joined: Sat, 10. Dec 11, 04:10
x4

Re: [WIP/MOD] Supply And Trade Routes (including build supply and mining)

Post by TheDeliveryMan » Tue, 1. Jan 19, 19:40

LegionOfOne wrote:
Tue, 1. Jan 19, 16:25
I would love a mod to make a true trade station as well ! I've been trying to mod the station overview myself, trying to show every ware when there are no production modules so I can set buy and sell orders. I've even tried dummy production modules that simulate inputs and outputs to allow buy/sell orders without producing anything, but no luck yet.
If you can achieve something similar, count me in for beta-testing and debug.
I'll send you a PM.
LegionOfOne wrote:
Tue, 1. Jan 19, 16:25
Edit : Something on-topic !
Could you do an even simpler version of the trade script that just trades one ware between two stations, constantly, without profit calculations or any kind of downtime, no matter if they sell at the same price they bought or even at a loss ?
That way you can setup supply routes between your own stations easily without adding unneccessary caculations, and worry about making money down the line. Also, it should stop traders idling so damn much ! :)
That's already possible with the current version.

TheDeliveryMan
Posts: 255
Joined: Sat, 10. Dec 11, 04:10
x4

Re: [WIP/MOD] Supply And Trade Routes (including build supply and mining)

Post by TheDeliveryMan » Tue, 1. Jan 19, 20:10

leecarter wrote:
Tue, 1. Jan 19, 17:10
Hey TheDeliveryMan, is it possible to make it so we can add more than one ware to your trader script?
In X3 I have used CLS2 quite a lot and I came to the conclusion that setting up a freighter to deal with more than one ware is not worth the trouble. I think the same applies here.
leecarter wrote:
Tue, 1. Jan 19, 17:10
Also, I've found that it works great between sectors, but in the same sector the ships have a tendency to start meandering aimlessly after awhile (at least between player owned stations).
If there is nothing to do then they currently idle around wherever they happen to be. This is indeed not nice, especially if your freighter just bought a full cargo of spaceweed from SCA and doesn't find a customer to sell to... I will add some option to set a home base or home zone where they will return to when there is nothing to do.

LegionOfOne
Posts: 122
Joined: Sun, 16. Dec 18, 14:16
x4

Re: [WIP/MOD] Supply And Trade Routes (including build supply and mining)

Post by LegionOfOne » Tue, 1. Jan 19, 20:50

TheDeliveryMan wrote:
Tue, 1. Jan 19, 19:40
I'll send you a PM.
Awesome ! Thanks :)
TheDeliveryMan wrote:
Tue, 1. Jan 19, 19:40
That's already possible with the current version.
Chalk it up to me being dense then. But my freighters were idling while I had plenty to sell and enough buy orders, with only one buyer and one seller set, both in the same region through a superhighway.
Going to test it again along with my brand new trade station :D

leecarter
Posts: 377
Joined: Sat, 9. Sep 06, 22:35
x3tc

Re: [WIP/MOD] Supply And Trade Routes (including build supply and mining)

Post by leecarter » Tue, 1. Jan 19, 21:20

LegionOfOne wrote:
Tue, 1. Jan 19, 20:50
TheDeliveryMan wrote:
Tue, 1. Jan 19, 19:40
I'll send you a PM.
Awesome ! Thanks :)
:thumb_up: :thumb_up:

LegionOfOne
Posts: 122
Joined: Sun, 16. Dec 18, 14:16
x4

Re: [WIP/MOD] Supply And Trade Routes (including build supply and mining)

Post by LegionOfOne » Thu, 3. Jan 19, 22:49

After my first round of testing, I have some feedback.
Quick overview of my setup : A few factories that only need miners and produce everything they need from raw resources. One trade station ( :mrgreen: more on that later) that bought my factories' final products.
Everything set to exclude other factions, and I only used your scripts, no vanilla trader or other Tatertrade (only vanilla miners assigned to stations).

Overall, the scripts work absolutely great ! As you said, they do make trade runs with 0 profit when they have no better option, which is very useful, no other script will do it. Still *a little* too much idle time between runs, but light-years beyond vanilla behaviors :).

One caveat : this maybe linked to the the vanilla behavior of station managers, but I can't get your scripts to buy up any ware that the station uses. For ex. : My station produces a lot of E-cells, and consumes a few of them. Your traders will never buy e-cells from this station ever, they'll just idle if they have no other supplier. Probably because the wares are marked by the manager as 'must store' because they are used in production, even when the storage for them is full...
That behavior was consistent on every station : wares that were used were never sold, wares not used were sold without problem. Only exception : food and meds, sold without problem even though pops consumed it.

And I say 'sold', but I noticed something strange : the stations didn't get nor spend a dime for these trades (all happening between player-owned stations). My trade station bought everything my factories made but the budget never moved a single cent, even though I was selling nothing yet, only buying.

Also tried your script on a few mining ships : worked great. The only problem is that it uses resource probes, and they never worked right for me. Must have dropped 30 probes at various resource-filled spots in Nopileo's Fortune, only 3 ever gave me readings, so the other ones couldn't be used as 'vendors'. And they vastly underestimate available resources : one probe was showing almost 0 ice density, and my miner with your script was idling waiting for ice to be available at the probe. But a vanilla miner was happily mining a huge ice asteroid less than 3 km from the probe, and I saw a lot more ice around. So it would probably work a lot better if we could set a whole system as 'vendor' instead of a resource probe, as they are problematic.

One quality-of life request : it would be useful if the ships could get as commander the first player-owned station they find in their buyer and seller lists. That way they don't clutter the 'unassigned ships' section of the UI.

Your script work great to patch supply gaps : for instance, vanilla miners sometimes mine too much of one resource the station needs and not enough of another. If the price of raw resources fluctuates automatically in your factories, a few miners running your script will go to the station with the best price, thus the worse shortage, and avoid production stopping down the line.

But these scripts still THINK, check prices, idle a little, all that.
Sometimes that's what you need, but mostly I need something even simpler : a basic order loop.

Go to station A => Pick up ware => Go to station B => Drop ware => Back to station A. That's it, no idle time, no recrimination.

You can go a bit fancier :
Goto A => Check if enough ware to fill cargo => Wait until true, then pick up => Goto B => check if space in storage, then drop => Back to A.

Now the deluxe version, that's on top of my wishlist :)

Same as before, but with potentially several suppliers and buyers.
BUT : the script ALWAYS buys from vendor 1 if enough to fill cargo. If not, only then do you check vendor 2, then 3, etc.
Same with several customers : always sell to customer 1 if enough space to take the delivery. If not, only then do you check customer 2.

That way the script has almost no calculations involved, so can loop orders without lag, and most importantly it behaves in an entirely deterministic manner. That would be just perfect.

As an added bonus, if those scripts can drop cargo into a station 'non-consensually', even if the station has no buy order for it, that can be enough to create a rudimentary trade station. Once you have a ware in inventory, you can set a sell offer and manage the price from the logistical overview. You then just need to keep force-feeding more wares into it, instead of having buy offers.

Now onto some feedback about the WIP Trade Station Mod, in a spoiler since it's a bit off-topic.
Spoiler
Show
It works !!!! My god it's amazing, I could kiss you right now !

Sure, I couldn't find a way to change the buy price in-game, so I had to dig in the save's xml to edit the overrides myself. Not exactly user-friendly, i'll grant you that :)
But once that was done, it worked like a dream !
The wares only apprar in the logistical overview once there is at least one unit in stock though, but then you can set the sell prices from there as you want, add or remove auto pricing without affecting your buy prices.

Now all you need is a way to see the buy offers in the logistical overview, so you can set the prices there, and the mod will be ready in my opinion for a beta release.

The only small bug I encountered : when I asked my station to build itself some drones, the order my manager put in for drone parts, e-cells and smartchips overwrote my buy prices and deleted my sell order for these wares.
But really, given how AMAZING it is to finally have my trade station, it's a very minor annoyance.

Thanks so much ! And all this from repurposing an AI script. The greatest effect from the smallest of changes, a true master of code at work :)

AttilaTheHunk
Posts: 2
Joined: Sun, 14. Feb 16, 06:55
x4

Re: [WIP/MOD] Supply And Trade Routes (including build supply and mining)

Post by AttilaTheHunk » Fri, 4. Jan 19, 06:22

I tried this mod but the ship idles for too long, then waits for signal and return to idling.

leecarter
Posts: 377
Joined: Sat, 9. Sep 06, 22:35
x3tc

Re: [WIP/MOD] Supply And Trade Routes (including build supply and mining)

Post by leecarter » Fri, 4. Jan 19, 13:35

LegionOfOne wrote:
Thu, 3. Jan 19, 22:49
Spoiler
Show
It works !!!! My god it's amazing, I could kiss you right now !

Sure, I couldn't find a way to change the buy price in-game, so I had to dig in the save's xml to edit the overrides myself. Not exactly user-friendly, i'll grant you that :)
But once that was done, it worked like a dream !
The wares only apprar in the logistical overview once there is at least one unit in stock though, but then you can set the sell prices from there as you want, add or remove auto pricing without affecting your buy prices.

Now all you need is a way to see the buy offers in the logistical overview, so you can set the prices there, and the mod will be ready in my opinion for a beta release.

The only small bug I encountered : when I asked my station to build itself some drones, the order my manager put in for drone parts, e-cells and smartchips overwrote my buy prices and deleted my sell order for these wares.
But really, given how AMAZING it is to finally have my trade station, it's a very minor annoyance.

Thanks so much ! And all this from repurposing an AI script. The greatest effect from the smallest of changes, a true master of code at work :)
I'm a huge fan too of it too. Makes so many more options available! Not just for selling but also storage and distribution.

But like you I wasn't really getting the behavior out of the various trade ship mods out there that I was looking for, so I wrote my own transport ship mod inspired by this ware house script:

viewtopic.php?f=181&t=411837

It's not exactly what you described as wanting, but you might find it handy.

Post Reply

Return to “X4: Foundations - Scripts and Modding”