Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
Improved logic of sharing industry production between stations #7922
Since the dawn of time Industries in TTD only share cargo between two stations max. This behavior doesn't seem to be based on any logic and leads to some issues in mp as it can be easily abused.
So this patch:
Shares are still based on station rating like it was before and, in fact, this patch doesn't change behaviour at all if there are less than 3 stations around (except for negligible rounding losses).
I didn't add a new setting for this change as IMO it only fixes exploits/limitations and doesn't change the gameplay logic. So I can't imagine why would anyone ever want to opt-out of it.
Hm, apparently there was PR #7184 that got completely derailed and rejected. So, just to emphasize some points.
It only solves one specific quirk of game mechanics that so far is only known to confuse people and/or being abused. For example, currently there is no such thing as competition between three companies on one industry. Third station won't even get any cargo unless it uses another exploit to start acceptance.
After a discussion in IRC I changed implementation so that it takes cargo bits that would've been lost previously to rounding issues and distributes them among the best rated stations, similarly to what original implementation did.
Also I left CanMoveGoodsToStation as a separate function for better readability even though I don't need to call it twice anymore.
Notably it works about as fast as original implementation in the most common cases of 0 or 1 stations. For the other cases it's about 6 times slower but that seems to be ok as they are quite rare when playing normally and it's probably going to waste even more time in StationFinder anyway.
P.S. Can also be similarly optimized for 2 stations I just didn't see any particular reason to complicate it even more.