Backwards Compatibility and Vehicle IDs

Discussions about the technical aspects of graphics development, including NewGRF tools and utilities.

Moderator: Graphics Moderators

Post Reply
User avatar
Andrew350
Route Supervisor
Route Supervisor
Posts: 488
Joined: 19 Dec 2011 07:54
Location: Washington State, USA
Contact:

Backwards Compatibility and Vehicle IDs

Post by Andrew350 » 14 Jul 2015 03:21

Hi all, I just had an idea and wanted some clarification about maintaining backwards compatibility:

If I explicitly define my vehicle ids, is it safe to add new vehicles 'in front' of existing ones, or should I always add new vehicles to the end of the list no matter what?

I ask because when changing sensitive properties, the only option to maintain backwards compatibility is to create a new vehicle and mark the old one as unavailable. That's fine, but after changing properties on many vehicles multiple times, the end of the vehicle list becomes a cluttered mess, and I'd like my NML code to remain easily readable. So if it's possible (i.e. won't cause problems), I was thinking of just inserting those 'new' vehicles right below the one I'm 'replacing', obviously with a new vehicle id, instead of just adding each new vehicle to the end of the list haphazardly. I just want to make sure it's safe before doing it.

Also on a related note, do you have to use all ids sequentially, ie. 00, 01, 02, 03... etc, or can you define them in intervals like 00, 10, 20, 30... and then later add vehicles with ids in-between? Would that be safe, or no?

Transportman
Tycoon
Tycoon
Posts: 2693
Joined: 22 Feb 2011 18:34

Re: Backwards Compatibility and Vehicle IDs

Post by Transportman » 14 Jul 2015 05:15

Andrew350 wrote:If I explicitly define my vehicle ids, is it safe to add new vehicles 'in front' of existing ones, or should I always add new vehicles to the end of the list no matter what?
That should indeed be possible, but if people upgrade from multiple versions back, they might get some errors because the ID already was in use in their version, but now is replaced by a different vehicle.
I ask because when changing sensitive properties, the only option to maintain backwards compatibility is to create a new vehicle and mark the old one as unavailable. That's fine, but after changing properties on many vehicles multiple times, the end of the vehicle list becomes a cluttered mess, and I'd like my NML code to remain easily readable.
If you define them in a separate file (like 2cc TrainsInNML does for example), things still keep quite readable, it just becomes a long list.
Also on a related note, do you have to use all ids sequentially, ie. 00, 01, 02, 03... etc, or can you define them in intervals like 00, 10, 20, 30... and then later add vehicles with ids in-between? Would that be safe, or no?
You can define them as you wish, as long as you do not have the same ID for different vehicles. In 2cc TrainsInNML, I reserved blocks of 1000 IDs for different vehicle types, also because I use the IDs to check if vehicles may be attached to other vehicles in the set. You can check the file here.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML

User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9293
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Backwards Compatibility and Vehicle IDs

Post by planetmaker » 14 Jul 2015 06:15

If you simply add new vehicles and keep the old vehicles with their IDs and properties around, if you do not change the meaning of NewGRF parameters, then the NewGRF will be compatible with old(er) versions. However at some stage you got the same vehicle defined several times in the code, just with slightly varying properties - which doesn't exactly help maintaining the code :)

VehicleIDs do not need to be sequentially in the code and can have any gap you want. As long as the IDs are un-touched you can insert new vehicles at any place in the code as well.

User avatar
Andrew350
Route Supervisor
Route Supervisor
Posts: 488
Joined: 19 Dec 2011 07:54
Location: Washington State, USA
Contact:

Re: Backwards Compatibility and Vehicle IDs

Post by Andrew350 » 17 Jul 2015 02:28

Awesome! Now I just wish I had thought to do this from the beginning. :lol:

Thanks guys :)

Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 1 guest