FS#5078 - NOAI API lack vehicle is old event

Attached to Project: OpenTTD
Opened by pagnon stephane (krinn) - Wednesday, 22 February 2012, 08:04 GMT
Last edited by andythenorth (andythenorth) - Saturday, 02 September 2017, 12:07 GMT
Type Feature Request
Category Script → NoAI
Status With patch
Assigned To Muxy (muxy)
Operating System All
Severity Low
Priority Normal
Reported Version Version?
Due in Version Undecided
Due Date Undecided
Percent Complete 80%
Votes 0
Private No


NOAI API doesn't handle <vehicle is old event>, most AI plays with autorenew feature and doesn't care about the event because the autorenew will replace old vehicle for them.

But for an AI that have its own replace vehicle function or when the openttd replace function is disable, there's no way for the AI to know a vehicle is old except by checking itself all vehicles current date status.

If you play as the AI you will get the windows popup when the event occurs but the event itself isn't trigger in NOAI API.

I think a ET_VEHICLE_IS_OLD (-> or something similar should exist so AI will get the event and can react to it, else the AI must handle it by browsing all its vehicles to check the age status.
This task depends upon

Comment by Thijs Marinussen (Yexo) - Friday, 09 March 2012, 22:38 GMT
If someone makes a proper patch for this it'll be included.
Comment by Muxy (muxy) - Sunday, 08 April 2012, 13:32 GMT
Started to work on it.
I'll give some news later after testing.
Comment by Muxy (muxy) - Tuesday, 10 April 2012, 18:56 GMT
Started to work on it.
I'll give some news later after testing.
Comment by Muxy (muxy) - Friday, 17 August 2012, 19:43 GMT
Here some start.

This has been tested with DictatorAI 156b modified with adding some code in the events handler and removing some code in the vehicle handler
and with a newgrf who sets bus lifetime to 1 year.
Comment by Thijs Marinussen (Yexo) - Monday, 20 August 2012, 20:36 GMT
Some small comments (copied from IRC so they don't get lost):
- You introduce unnecessary newlines at the start of the patch.
- It's missing documentation for ScriptEventVehicleOld
Comment by Muxy (muxy) - Tuesday, 21 August 2012, 18:40 GMT
Here is some update.

used script in src/script/api
Comment by Thijs Marinussen (Yexo) - Tuesday, 21 August 2012, 19:46 GMT Updated version with some comments fixed. However it still generates the event multiple times for the same engine, which I don't like at all.

Needs some thoughts about when to generate this event: 1 year before old age, exactly at old age or even later.
Comment by pagnon stephane (krinn) - Saturday, 25 August 2012, 00:32 GMT
sorry if i'm not of any help as i have 0 time until begin/mid september as my activity is resume to a work/sleep loop

i'll have a look at it as soon as i could.
Comment by Muxy (muxy) - Sunday, 26 August 2012, 16:11 GMT
Here is the event list generated per vehicle according the age :

1. One year before max_age : Vehicle is getting old
2. When reaching max age : Vehicle is getting very old
3. Every year after max_age : Vehicle is getting very old and need to be replaced

In my test i use a grf who is setting lifetime to 1 year, thus i dont get the first message, but only the second one. That's why it could be better to send the event in the second case : Vehicle is getting very old.

Before sending a diff file, I will wait for other advices.