Skip to content

[1824/1858/1866/18Tokaido] Unlimited trains#12722

Open
ollybh wants to merge 6 commits into
tobymao:masterfrom
ollybh:unlimited-trains
Open

[1824/1858/1866/18Tokaido] Unlimited trains#12722
ollybh wants to merge 6 commits into
tobymao:masterfrom
ollybh:unlimited-trains

Conversation

@ollybh

@ollybh ollybh commented May 31, 2026

Copy link
Copy Markdown
Collaborator

Implementation Notes

Adds support for unlimited trains to 1824 (base game and Cisleithania variants), the 1858 family (Iberia, Switzerland and India), 1866 and 18Tokaido.

Explanation of Change

Commit 287fcba added support for unlimited trains. Part of this involved using the num_trains method to calculate how many train objects needed to be initially created for an unlimited rank of train, normally one, but more if there is an event that fires on the nth train being bought.

1824, 1858, 1866 and 18Tokaido already had their own versions of num_trains. They are using this method to allow the number of trains to be calculated from optional rules selected, or player counts.

These two different uses of num_trains don't work together, preventing these games from simply changing the train rank count to unlimited in their definitions.

This splits the uses, creating a new train_rank_count method that is called from init_train_handler to determine how many Train objects should be created for each type of train.

This also changes the Train initialiser to take unlimited as a parameter, instead of assuming that the trains hash will contain a :num key.

Finally, it changes 1848 to remove that game's custom init_train_handler method. To do this the DEPOT_CLASS constant is set for that game.

Fixes #12719. Works towards fixing #12237.

This supersedes PR #12595 and parts of #12593.

Any Assumptions / Hacks

An alternate approach to adding the unlimited parameter to the Train class would be to call num_trains (or something similar) from the view classes and drop the unlimited attribute from a train object. That might make more sense (it's the rank of trains that's unlimited, not the individual train) but would have been a bigger change.

Before clicking "Create"

  • Branch is derived from the latest master
  • Add the pins or archive_alpha_games label if this change will break existing games
  • Code passes linter with docker compose exec rack rubocop -a
  • Tests pass cleanly with docker compose exec rack rake

1848's overridden `init_train_handler` method is not needed if
`DEPOT_CLASS` is used to set the custom Depot class.
ollybh added 5 commits May 31, 2026 17:55
Commit 287fcba added support for unlimited trains. Part of this
involved using the `num_trains` method to calculate how many train
objects needed to be initially created for an unlimited rank of train,
normally one, but more if there is an event that fires on the nth train
being bought.

Several games (1824/1858/1866/18Tokaido) already had their own versions
of `num_trains`. They are using this method to allow the number of
trains to be calculated from optional rules selected, or player counts.

These two different uses of `num_trains` don't work together, preventing
these games from simply changing the train rank count to `unlimited` in
their definitions.

This splits the uses, creating a new `train_rank_count` method that is
called from `init_train_handler` to determine how many Train objects
should be created for each type of train.

This also changes the Train initialiser to take `unlimited` as a
parameter, instead of assuming that the `trains` hash will contain a
`:num` key.
7E, 6M and 5D trains are unlimited in 1858 Iberia and 1858 India.
6E, 5M and 5D trains are unlimited in 1858 Switzerland.
10 trains are unlimited in both base 1824 and the Cisleithania variants.

This removes the custom `init_train_handler` method. A custom
`num_trains` method that looks up the number of each train type is added
and the base `init_train_handler` method can be used.
The 10 and 6E trains are unlimited in the full 1866 game and all the
scenarios.
18Tokaido is an 18Chesapeake variant and so diesels are unlimited.
@ollybh ollybh force-pushed the unlimited-trains branch from 59d749a to 5f80c6c Compare May 31, 2026 16:56
@perwestling

Copy link
Copy Markdown
Collaborator

I checked the 1824 code and it looked fine. (Although 1824::Depot probably could be refactored a little bit. But as it works I suppose it is fine. It is over 5 years since I created it.)

@ollybh ollybh mentioned this pull request Jun 7, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[1824/1858/1866/18Tokaido] Unlimited trains for games with overridden num_trains method

2 participants