FS#3044 - Long format model life property for vehicles

Attached to Project: OpenTTD
Opened by Jose Soler (Terkhen) - Monday, 20 July 2009, 14:20 GMT
Last edited by andythenorth (andythenorth) - Tuesday, 15 August 2017, 17:47 GMT
Type Patch
Category NewGRF
Status Closed
Assigned To andythenorth (andythenorth)
Operating System All
Severity Low
Priority Normal
Reported Version trunk
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 0
Private No


There is a long format introduction date for vehicles, but the model life property is still limited to a maximum of 254 years. I have been working to implement a long format model life property for vehicles that allows up to 65534 years. Since model life values greater than 255 would conflict with the current way of determining if a vehicle never expires, it is implemented in a different way. The EngineInfo struct now has a never_expire field. This field is set to true in the following cases:

- When a value of 0xFF is found at a model life property.

- When a value of 0xFFFF is found at a long format model life property.

- When initializing base engines out of the original engine data range.

- For all standard wagons.

This new value replaces the (base_life == 0xFF) condition when checking early retirement or if the engine is at the phase 2 of its life.

The long format model life property is word sized and has the following property numbers:

Trains: 0x2B
Road vehicles: 0x21
Airplanes: 0x1C
Ships: 0x1C

Since I don't know how the original property numbers were decided, I just used the first available position at each vehicle.

Attached is a diff file containing the source changes, a win32 binary and the two NewGRF files I used for testing this patch.
This task depends upon

Closed by  andythenorth (andythenorth)
Tuesday, 15 August 2017, 17:47 GMT
Reason for closing:  Won't implement
Additional comments about closing:  Mass closure of patch tickets with no commentary for >5 years. Goal is to reduce patch queue as an experiment to see if it aids faster reviewing and rejection/acceptance (it may not). If this offends you and the patch is maintained and compiles with current trunk, discuss with andythenorth in irc. (andythenorth has no ability to review patches but can re-open tickets).
Comment by Jean-Francois Claeys (Belugas) - Thursday, 23 July 2009, 16:55 GMT
Why do you set the never_end value to true in the engine's constructor?
That eludes me a bit.
Note that you might have a very good reason. Just wondering...
Comment by frosch (frosch) - Thursday, 23 July 2009, 17:28 GMT
The constructor thingie is ok.

1) Using bigger numbers will overflow duration_phase2. So e.g. limit it to 5000 years. (I don't think bigger numbers are of any interest)
2) Adding never_retire adds redundancy. Instead add e.g. static const Engine::BASELIFE_INFINITE = 0xFFFF, and convert the 0xFF when the old property is set.
Comment by Jose Soler (Terkhen) - Thursday, 23 July 2009, 23:56 GMT
The never_expire in the constructor was there to replace the old assignment to 0xFF, but as frosch said it was duplicating info. I have implemented both corrections. The long model life property now allows to set a number from 0 to 5000, with anything greater than 5000 being set to 0xFFFF.

EDIT: (Incorrect version, see new comment below)
Comment by Jose Soler (Terkhen) - Friday, 24 July 2009, 07:04 GMT
It seems I uploaded an intermediate version by mistake. I am sorry, here is the real patch:
Comment by Jean-Francois Claeys (Belugas) - Friday, 24 July 2009, 10:22 GMT
const int Engine::BASELIFE_MAXIMUM = 5000; <---- suggestion

Clamp(grf_load_word(&buf), MIN_YEAR, Engine::BASELIFE_MAXIMUM); <---- another suggestion

Comment by Jose Soler (Terkhen) - Friday, 24 July 2009, 14:30 GMT
Thanks for the suggestion; I have implemented it. Besides the old base life maximum (0xFF), I think that there's no more magic numbers remaining in the patch code.

What behaviour when numbers greater than the maximum base life is preferable?. Right now values greater than 5000 are clamped to 5000, being 0xFFFF the only value that creates a never expiring vehicle. If implementing that any value greater than 5000 creates a never expiring vehicle is preferred, I will change it back.
Comment by Jose Soler (Terkhen) - Thursday, 30 July 2009, 08:44 GMT
I have done two GRFs that are more interesting for testing this patch. They can be found here: