FS#6530 - loading of mixed cattle and grain

Attached to Project: OpenTTD
Opened by Hans-Georg (HGA) - Thursday, 15 December 2016, 14:59 GMT
Type Bug
Category Core
Status New
Assigned To No-one
Operating System Windows
Severity Medium
Priority Normal
Reported Version 1.6.1
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 0
Private No


I have a station (Neu Würzburg Höhe) for loading cattles and grain from a farm.
The trains have 5 cars for cattles and 5 for grain.
On the station there a thousends of cattles and tons of grain available.
If a empty train arraives the station, the loading starts immediatly in 9% steps. After the first loading (cattles or grain) are completed, the löading stops for a while. Than loading starts again with the second good, but only in 2% steps. Therefore the complete loading takes very long.

For testing I have biuld a new train with only one kind of good. This loading happens in 20% steps and is very quick.

I have attached the game.
This task depends upon

Comment by Grzegorz Duczyński (adf88) - Friday, 23 December 2016, 13:45 GMT
There's no "Neu Würzburg Höhe" in your savegame...
Comment by frosch (frosch) - Saturday, 24 December 2016, 11:40 GMT
It is at tile 1049, 964. (scrollto 0x1e2419)
The "Höhe" part is translated and says "Heights" if OTTD is set to english.

Another hint: If you do not have matching NewGRF, it is a good idea to pause after loading the game, stop all road vehicles, and then unpause again.
Comment by Hans-Georg (HGA) - Sunday, 25 December 2016, 10:39 GMT
Here is a new File. The specific station is on the fromt.
Comment by Grzegorz Duczyński (adf88) - Monday, 26 December 2016, 06:14 GMT
Everything perfectly normal here. Cargo gets loaded almost instantly. Why in 2% steps? Because the farm doesn't keep up with grain production. If you pause a train and wait until few hundreds of tones of grain gathered, you will see that loading is faster again.

"Tones" is not that much. One tone is the smallest unit, 30 tones fits into single wagon, 5 wagons will hold 150 tones.
Comment by frosch (frosch) - Monday, 26 December 2016, 11:54 GMT
I think the observation refers to how the vehicles reserve cargo.

If there is not enough cargo waiting at the station to fill all vehicles, then the wagons reserve cargo starting from the front, while the wagons in the back do not reserve any cargo. Thus the wagons do not load in parallel, and total loading takes longer.
That is, the current algorithm prefers to load the 1st wagon to 100% while keeping the other wagons empty.

In the past this worked differently, all wagons always loaded in parallel.

The loading was changed to the current algorithm because of refit-in-station with "any cargo type". Wagons can only refit while they have no cargo loaded.
However, it is only supposed to work that way, if the order actually says "refit to any cargo".

The bug seems to be, that the loading always behaves like there is a "refit to any cargo" order.
Comment by Grzegorz Duczyński (adf88) - Monday, 26 December 2016, 12:32 GMT
You are talking about totally different thing. The author of this ticket was complaining that "complete loading takes very long".
Comment by Grzegorz Duczyński (adf88) - Monday, 26 December 2016, 13:06 GMT
Your observation seems invalid too. Wagons do load in parallel even if there is a cargo shortage.

From what I observed, grain is being loaded in 5t pieces. If you have 10 tones on a station, 2 wagons will load in parallel.
Comment by frosch (frosch) - Monday, 26 December 2016, 20:47 GMT
The next train that arrives at the station is train 14.
While there are about 30t of grain waiting, only the first grain wagon is being loaded.
See screenshot.

This is also the reason why loading takes so long. To load 5 grain wagons it takes 30 instead of 6 loading steps due to sequential loading.
Comment by Grzegorz Duczyński (adf88) - Tuesday, 27 December 2016, 05:49 GMT
It's hard to notice but you are right about "sequential" loading. Loading will happen in parallel only if there is enough cargo waiting on the station.

You are wrong about total loading time, it cannot be faster. No matter whether train loads sequentially or in parallel, it will always have to wait until cargo "appears" on the station.

This behavior has lesser impact on total loading time. We observe these effects only if there is cargo shortage - when train have to wait anyway. Only loading of the last wagon will cause a bit of a slowdown.

I'm not saying it's not a bug. I'm saying that it's not what this ticket is about.
Comment by Grzegorz Duczyński (adf88) - Tuesday, 27 December 2016, 07:36 GMT
I'm currently investigating the "improved_load" case. I'll let you know what are my findings.

Comment by Grzegorz Duczyński (adf88) - Tuesday, 27 December 2016, 09:45 GMT
OK, I have a clue. I tested few revisions. Always same conditions:
- vanilla trunk
- starting new game (never loading a savegame)
- clean config file
- always coal and only coal
- 9 wagons attached to Ginzu A4, "full load any"
- coal mine production increased to about 300t/month (cheat)

In all these revisions:
* r26856
* r26857 -Fix [ FS#6110 ]: Reserve cargo after refitting and only if necessary.
* r26916
* r26917 -Revert (r26857): It broke improved loading.

loading behaves the same:
* When 'improve_load' is OFF, wagons load in PARALLEL.
* When 'improve_load' is ON, wagons load GRADUALLY.

In revisions:
* r26918 -Fix [ FS#6110 ]: Reserve cargo only after unloading finished or if the vehicle has the desired cargo already
* current trunk
wagons always load GRADUALLY, no matter what the 'improved_load' is set to.

So what is "improved_load" supposed to do then? It seems that the behavior was reversed before and now is broken.
Comment by frosch (frosch) - Tuesday, 03 January 2017, 16:46 GMT
There are two settings, they are supposed to do these two things:
* gradual_loading: Vehicle load in steps, instead of all at once.
* improved_load: When multiple vehicles are loading at a station: The second vehicle only starts loading, if there is enough cargo to full-load the first one.

Improved loading gets more complicated, if cargodist is enabled and the two vehicles have different destinations.

So, is the issue that improved_loading now treats "multiple wagons" like "multiple vehicles"?
Comment by Grzegorz Duczyński (adf88) - Tuesday, 03 January 2017, 17:59 GMT
Sorry for using word "gradual", I wasn't referring to "gradual_loading". Typing "gradual" I meant behavior of "improved_loading".

In revisions r26856, r26857, r26916, r26917 improved_load works - if turned OFF all wagons always load equally, when turned ON next wagon starts loading only if there is enough cargo to fill previous wagon. But since r26918 the loading is always "improved" even if "improved_load" is turned OFF.

I was testing ONLY the condition that I described - other settings set to their defaults, coal train, full load etc.
I wasn't testing "refit at station" nor cdist.
Comment by andythenorth (andythenorth) - Thursday, 31 August 2017, 07:43 GMT
Seems like a tarpit. Even discussing it means understanding the combinatorial settings correctly.

Can we improve that by removing the gradual and improved settings (defaulting to 'on' in both cases), and consolidating to one mechanic for loading vehicles?

I'm aware that will break some eggs, but eh, that's how we get a nice omelette.