[Patch] Distribute delivered cargo over multiple accepting industries.

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
Bartje321
Engineer
Engineer
Posts: 1
Joined: 28 Sep 2017 13:39

[Patch] Distribute delivered cargo over multiple accepting industries.

Post by Bartje321 » 29 Sep 2017 13:31

I've created a patch do distribute incoming cargo over multiple industries, This so i can get some extra good's out on my stations by building extra factories.
It's my first patch and my first c++ in 10 years, so any feedback is welcome.

It works as follows:
When the game tries to deliver the cargo from the unloading vehicle to the industry instead of finding the first one and drop all the items in that industry it first checks how much accepting industries there are.
If there is only one it will drop the cargo on that one.
If there is more than one it will divide the amount of cargo evenly over all the industries, and buffer the remaining cargo for the next run.
Eg: 5 items of cargo delivered to 2 factories mean both factories will get 2 items and 1 item will be buffered. When the next 5 units arrive it will add the 1 still buffered and deliver 3 cargo to the factories.

The buffered cargo isn't saved when saving (As far as I know, I don't know how data is getting saved), so saving and loading may cause some lost cargo, but this is only a small amount (< num factories for the station per station). I don't think it's worth
I'm not sure how this patch will work in multiplayer or if it will cause desyncs, I've got no knowledge about how the multiplayer code works.

Note that when applying the patch to an already patched game or newer version it may be needed to manually adjust the savegame version in saveload.cpp and settings.ini

There is a setting to toggle the function on and off, By default, it is off. So you have to enable this manually.
cargodistribute_r27917_1.diff
(8.94 KiB) Downloaded 66 times
Screenshots:
[+] Spoiler
Image
Image
Attachments
throughput.png
(676.84 KiB) Not downloaded yet
ecs.png
(322.91 KiB) Not downloaded yet

xarick
Transport Coordinator
Transport Coordinator
Posts: 273
Joined: 26 Feb 2015 00:52

Re: [Patch] Distribute delivered cargo over multiple accepting industries.

Post by xarick » 04 Nov 2017 01:44

I tried to code something similar.
I've also tried adding a "buffered cargo", which i called "fraction cargo" but instead of making it part of the station struct, I made it part of the Industry instead.

It didn't do as well as yours. I was getting a high degree of variance on cargo delivered per industry.
Image

When I tried yours, I got a better picture.
Image


Wish I had the code to show you, but I gave up on it.
Formerly known as Samu

Eddi
Tycoon
Tycoon
Posts: 7424
Joined: 17 Jan 2007 00:14

Re: [Patch] Distribute delivered cargo over multiple accepting industries.

Post by Eddi » 05 Dec 2017 09:09

Bartje321 wrote:The buffered cargo isn't saved when saving [...] I don't think it's worth
I'm not sure how this patch will work in multiplayer or if it will cause desyncs
saving is essential for multiplayer-safety. all players must get the exact same game state, which is done by transferring a savegame.

so even if you think one or two cargo pieces is not that relevant, it's exactly that one or two difference that will cause a desync in multiplayer. (this is also why we cannot use floating point numbers, because we cannot have any rounding errors)
You might not exactly be interested in Ferion, but if you are, have fun :)

Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 3 guests