Simutrans Sites
Know our official sites. Find tools and resources for Simutrans.

[patch] Multiple station capacity / Fair goods distribution

Started by TurfIt, September 12, 2010, 06:56:18 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


In the game server thread I mentioned:
Quote from: TurfIt on September 09, 2010, 07:36:02 PM
5) Oddities - might not be related to network but simply multiplayer.
   - Goods distribution from factories is being limited by the players stop with the least capacity. eg. Player 1 has a truck stop capacity 64, Player 2 has a train station capacity 320 both connected to the same factory. Once both stops have ~64 goods waiting, the factories output store starts filling up instead of Player 2s partially full station.

Attached is a patch to fix this. Goods are now distributed from factories to their attached stations in proportion to the remaining free space at the station.

e.g. Truck stop capacity 64, Train station capacity 320. The first distribution of 10 goods goes to the truck stop putting it at 15% full, the next 10 go to the empty Train station putting it to 3%. The next four distributions all go to the train station to get it up to 15%, then the truck stop gets 10 more, continue...

This seems strange at first thought but in testing works well. In the steady state with vehicles picking up the goods the end result is the same as the original code produces; Except, the extra capacity of the train station is used. i.e. The original code would fill both stations alternating 10 to each until they both have 70, and then stop distributing with the excess piling up in the factories output store. Hence, the train station is effectively reduced to a 64 capacity.

Multiplayer has nothing to do with the problem, it simply provides the condition where multiple stations would end up at a factory. An unlikely situation in single player - at least how I play.

In looking into this problem, I also noticed that the distribution wasn't very fair. i.e. One station would always be selected first for the distribution. This means all a player has to do is ensure a vehicle is always loading (if he was lucky enough to have the golden station) and he can deny the other players' station *any* goods. Ever!

First glace at the code showed a last_lieferziel_start variable that was "to distribute to all target equally". However, this only applied to goods leaving to multiple destination factories from the same source attached station. I've extended this functionality to also handle equal distribution to all attached stations. Renamed the variable to index_offset to reflect its new dual usage. last_lieferziel_start was also being incremented in ::step  - this can render it ineffective depending on the number in lieferziele. Now incremented in ::verteile_waren where it provides round robin service rather than semi random.

If vehicles are loading at multiple stations all connected to the same factory, each station/vehicle now receives a distribution in turn. No more players hogging all the output...

What this patch doesn't do:

1. Change the loading order of vehicles. i.e. If multiple vehicles are in the station all loading the same goods, they'll continue to load based upon internal ID.

2. Change the route finding of goods. If you have vehicles loading at the same station with goods destined for the same factory but separate destination stations, only one route will be picked and receive all the goods. An example, a public service stop connected to a coal mine with both a train platform and a truck loading bay. At a coal power plant there is a train station from player 1, and a truck bay for player 2. The route finder will pick either the truck route, or the train route and provide no goods to the other. Players in a multiplayer game would probably expect this setup to work. I would. The last discussion involving routing went rather bad so... 'nuff said.