1837: fix for multiple train discards #11705 #11711
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #11705
Before clicking "Create"
master
pins
orarchive_alpha_games
label if this change will break existing gamesdocker compose exec rack rubocop -a
docker compose exec rack rake
Implementation Notes
@round.merged_trains[action.entity].delete(action.train)
is a silent no-op (returnsnil
, but we're not using the return value) if either:action.train
(the discarded train) is not a member of@round.merged_trains[action.entity]
(the list of merged trains)It can be safely called every time we discard a train.
Explanation of Change
Phase change which both lowers the train limit and merges coal companies can leave a corporation needing to discard multiple trains to meet the new train limit. This could be trains from both the merged coal companies, which must be discarded first, and also from the corporation's trains that were already owned before the merge.
The existing code chooses either the list of 'merged' trains, if non-empty, or the list of already-owned trains, and tries to satisfy ALL of the required discards from that list. If more trains must be discarded than are in the 'merged' list, the game stalls. It does not empty the list of 'merged' trains until after the corporation is back down to the train limit.
By removing each train from the list of 'merged' trains as it is discarded, we can get to an empty list of 'merged' trains during the discard step, which triggers the logic to show the list of already-owned trains to complete the discard process.
Screenshots
Any Assumptions / Hacks