First of all, absolutely love this patch! A dream come true for everyone who hates tedious clickery.
Secondly, I found something in CmdTemplateReplaceVehicle (tbtr_templace_vehicle_func.cpp):
Code: Select all
TileIndex tile = incoming->tile;
TemplateVehicle *tv = GetTemplateVehicleByGroupID(incoming->group_id);
EngineID eid = tv->engine_type;
/* first some tests on necessity and sanity */
if ( !tv )
The sanity check on tv
is performed after it has already been accessed. This crashed my game when I forced a vehicle which was getting old and was scheduled for auto-renewal into a depot. Moving the command cost definitions and the sanity check up, before tv->engineType
fixed the crash, but the core issue still seems to be that this patch conflicts with auto-renewal, since the trains in question still do not get renewed. This is only my first, wild guess and I'm not all too familiar with the codebase, so please take the following with a grain of salt:
I think that auto-renewal uses the same system as the default auto-replacement feature. Now if a train is in a group that has a template assigned, this patch suppresses the auto-replacement. Thus trains do not get auto-renewed. For some odd reason, however, the train's group ID does not seem to be valid when it is passed to CmdTemplateReplaceVehicle
, since incoming->group_id
seemed to return 0
here, but only for trains which are scheduled for auto-renewal. My first guess was that the vehicles get auto-renewed, which would invalidate the reference in _vehicles_to_templatereplace
. But then again, the train would be actually auto-renewed once I fixed the crash if this were the case, which it doesn't.
Edit: After the fix above, it actually does auto-renew the train, but only if it's forced into a depot. It does not auto-renew it when it's just stopping by for maintenance.