When you're upgrading your track network using the track conversion tool, to something like monorail or maglev, you'll usually get a 'train in the way' error if you try to upgrade a depot whilst a train is stopped in there. This patch autoconverts all stopped trains, and their wagons, to the first compatible train/wagon of the new track type. This vastly increases the speed of upgrading your train network - simply build up money, send all your trains to the depots, and convert the depots along with the track and all the trains will also be converted!
Any comments/code improvements/suggestions welcome!
Version history:
v0.1 (for SVN trunk r12347):
- Initial release.
v0.2 (for SVN trunk r12421):
- Now you have to hold CTRL when converting rail to autoconvert depots with trains in.
- Extra options added to the autoreplacement code (thanks Bjarni!), now we only upgrade a depot if we can afford to upgrade ALL trains in depot.
- Significant code overhaul, split up CmdConvertRail into 2 functions as we now need to iterate through all selected tiles twice, to check whether we have the money necessary for the conversion first; we must do this manually because we had to cause this command to trigger 'notest' in DoCommand.
- When querying the cost of converting track, if only depots with trains are selected, gives a cost estimation of upgrading each depot (ie. max possible cost).
- When querying to cost of converting track, if any track or empty depots are selected, gives a cost estimation of just upgrading any selected track (ie. min possible cost).
- When actually doing the replacement, always tries to convert any selected track or empty depots first. If that was successful, goes through each found depot with trains in, and tries to convert it; does so if we can afford the conversion.
- The cost animation near the cursor will reflect the cost of upgrding any empty depots and track tiles (INCLUDING the track tiles of the upgraded depots that had trains in them!). Each upgraded depot will have its own cost animation too, indicating the cost of upgrading the trains and wagons in that depot.
Known bugs:
- Group handling probably isn't very good; currently we just get the EngineReplacement for the group ID of the train (ie. engV->group_id), but set it again using the ALL_GROUP group.
- We might need one or two more custom strings for this patch (although I haven't found the need for any more yet...)
- I'm told there may also be problems with NewGRF, as some GRF sets disallow certain cargo types for certain track types. As my patch basically uses the autoreplace code, I'm hoping that as long as autoreplace is maintained to work with NewGRF, so this patch will work.
- Some code cleanup is needed.
- Currently, if we're estimating the cost of autoreplacing trains in a depot, the command will fail if we don't have enough money. The command needs not to fail, but to return the cost estimation of replacement. This patch currently hacks around this by charging 100 million for replacement if the cost estimation fails, but this should be fixed (Bjarni needs to fix this one in the autoreplace code )
- Doesn't handle very well replacing wagons for NewGRF sets that might not allow certain cargo types on certain track types (what is the best way to handle this? Hmm.)
- Doesn't handle very well replacing train engines that can hold cargo - maybe (maybe not?) we should try to replace them with train engines that handle the same type of cargo.
- Doesn't have a GUI to specify replacements (do we want this? It would seem very complex, perhaps unnecessarily so.)