Make trains take the lowest available ID
Posted: Thu Nov 21, 2024 11:22 pm
TL;DR
Make trains take the lowest available ID when they are updatedExplanation
Currently, train IDs are assigned sequentially every time a train is "created". Given that they were previously only ever really used for pathfinding and niche circuit stuff, the implementation didn't really matter unless you were super OCD. However, now that train interrupts are a thing and everybody is racing to build the LTN mod in vanilla, train IDs have become a lot more necessary as the main way of differentiating behaviors between trains via circuit conditions (to prevent things like 2 trains getting dispatched to the same station / route). This is great, but it's highlighted a combination of flaws that results in some mildly annoying consequences.1) Train ID's are never reused unless the next ID overflows the integer cap.
2) Trains have a very overbroad definition of being "created", meaning that a new ID is assigned every time the train is changed.
This results in train ID's climbing way higher than is really necessary. For example, the first train in the world will have an ID of 1. Adding a wagon/engine to that train changes the ID to 2. This means that if you're building 2-4 trains like I am, each train effectively takes up 6 IDs, and that's in the perfect world where no trains or wagons are ever deleted/destroyed. God forbid you tinker with train schedules/configs, you'll end up with 10 trains and ID's as high as 1000.
It makes common operations like iterating over all trains take way longer than they need to, and just makes circuit stuff with the ID's overly complicated for weird, unintuitive reasons. Plus, I know its bad form to say "ItS a FiVe MiNuTe ChAnGe" when you aren't developing the codebase, but, like, c'mon. c'mooooooooon.
Pretty please?