Question about variable B4 for industries.

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

Moderator: Graphics Moderators

Post Reply
ziond
Engineer
Engineer
Posts: 50
Joined: 04 Mar 2009 10:55
Location: Moscow, Russia

Question about variable B4 for industries.

Post by ziond »

IMO in OpenTTD all (not primary) industries protected for five years since the date of opening (or since starting of the game?).
And I don't like this behaviour. I'm trying to edit PBI (my favourite industries set) in order to change the default behaviour for the (not primary) industry closure.
So, I have enabled CB29 by setting prop.21 to 1C

Code: Select all

-1 * -1   00 0A 02 01 0A 21 1C 22 05
then I have made handler for CB29

Code: Select all

//do nothing if there was cargo delivery in last 360 days else close industry
-1 * -1   02 0A 31 85 00 20 FF FF \2- b4 00 FF FF 01
          00 80 01 00 68 01 
          03 80

//do nothing if industry age less then 360
-1 * -1   02 0A 31 85 23 20 FF FF \2- 46 00 FF FF 01
          00 80 00 00 68 01 
          31 00

//handle CB29
-1 * -1   02 0A 11 81 0C 00 FF 01 
          31 00 29 29 
          11 00
I think that this code should check for industry age and if age more then X days (X=360) check if it was cargo delivery in last Y days(Y=360) and then close industry. After some testing I found that this code don't work for me if current year less than 1920. And this is expected.

For dates before 1920 it is possible to calculate industry age in long format dates (var23 - var46) against short format dates (var00 - varB0). I have search for opportunity to calculate the time since the last cargo delivery in long format dates, but found nothing :( .

So the question is:
Is it possible to calculate the time since the last cargo delivery if current year less then 1920?

P.S. Sorry for my English...
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Question about variable B4 for industries.

Post by frosch »

You could add a production callback and store the date in some persistent register.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
ziond
Engineer
Engineer
Posts: 50
Joined: 04 Mar 2009 10:55
Location: Moscow, Russia

Re: Question about variable B4 for industries.

Post by ziond »

You could add a production callback and store the date in some persistent register.
This seems to be nice and elegant solution :)
Thank you!
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 4 guests