FS#6359 - Remaining lifetime (years) does not go negative

Attached to Project: OpenTTD
Opened by Simon Smith (Simons_Mith) - Sunday, 09 August 2015, 14:35 GMT
Type Bug
Category Vehicles
Status Assigned
Assigned To David (chindit)
Operating System All
Severity Low
Priority Normal
Reported Version 1.5.1
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 0
Private No


An order such as

'Jump to order 7 when Remaining lifetime (years) is less than 0'

never triggers, even when the vehicle concerned was 41 years (max age 38).

I altered it to 'Jump to order 7 when Remaining lifetime (years) is less equal to 0'
and that did work, but then it triggered a year earlier than I really wanted.

See also feature request 'Req: 'max reliability' order filter', which is what I really wanted
in the first place.
This task depends upon

Comment by David (chindit) - Monday, 17 August 2015, 15:36 GMT Comment by Alberth (Alberth) - Wednesday, 19 August 2015, 17:14 GMT
So how is it fixed exactly?

You only seem to throw a message when you detect 'property < 0'. The OP doesn't want '< 0', and he doesn't want '<= 0' (or '== 0') that you force him into by throwing messages.
At least with the patch here

(you can link to specific posts with the 'post' icon at the right-top. Even better, attach the patch here, so it doesn't get lost.)
Comment by David (chindit) - Friday, 21 August 2015, 10:26 GMT
I've worked on two different solutions which are complementary.

1st : throwing a message if there is an unfulfillable condition, like «load percentage < 0» Patch (latest version) is joined to this post.
2nd : removing the negative limit for remaining lifetime. This was done just with a small modification on the check of conditional order. Patch is also joined to this post.

I've tested it and orders like this are now 100% functional:
1)Go to A, full load
2)Service at depot X
3)Go to B, unload
4)CONDITIONAL : jump to 1 if Remaining lifetime is >= 0
5)Go to depot X, stop
Comment by frosch (frosch) - Friday, 21 August 2015, 17:54 GMT
2nd: "value" is an unsigned integer. All the input to the conditional orders is unsigned, all the way from the GUI to the game logic.
Comment by David (chindit) - Friday, 21 August 2015, 17:59 GMT
It's not a problem because I don't change "value".
"Value" is the number entered by the user. In this particular case: 0.
Only the calculated age is under 0 and this particular value is used ONLY in the order comparator. So, there is no problem
Comment by Grzegorz Duczyński (adf88) - Sunday, 20 September 2015, 09:16 GMT
I can think of few ways of dealing with the problem.

1. Do an exact comparison without rounding (probably most feasible).
2. Change years to months (minimise the damage).
3. Compare against ceil(years(lifetime)) instead of floor(years(lifetime))