OpenTTD / nml

NewGRF Meta Language
GNU General Public License v2.0
43 stars 36 forks source link

Change: Support extended DCxx string range, and station names for IDs > 255 #293

Closed glx22 closed 1 year ago

glx22 commented 1 year ago

Implements support for https://github.com/OpenTTD/OpenTTD/commit/f5394ed2ef32efdccb6312dd830d827e67d1311d and https://github.com/OpenTTD/OpenTTD/commit/bc7dfd7b46c0184dc4b2cc376556702ac0ac1019.

Draft because only half of it is done.

For stations I have 2 options, just switch to DCxx range, or use a mechanism to still use C5xx and C6xx ranges for IDs < 256 then fallback to DCxx.

michicc commented 1 year ago

For the extended string range there also needs to be a way to reference them from a switch block.

As far as I can tell, a string() in a switch will always be allocated in the D0 range, even if it is used in the text stack and not as a CB result. Some kind of additional feature or automatic logic would be needed to also make it useable for e.g. the engine name callback.

glx22 commented 1 year ago

Yeah it allocates in D0 range and does some magic to return the unprefixed ID. Then authors have to readd the prefix in some cases (can't remember exactly where and why, but I'm sure I saw this being done)

Edit: found where I saw it (see https://github.com/andythenorth/firs/blob/main/src/templates/extra_text_informative.pynml#L42-L47)

glx22 commented 1 year ago

I used a very simple mechanism to switch range for station names depending on IDs. For classnames I just decided to use only DCxx range, as in most cases many stations will use the same class.

Regarding the D0xx range and switches, I think it's very difficult to determine if you are in the callback result case (which means allocate in D000 range and return allocated_id - 0xD000 + 0x8000) or in the procedure result case (allocated in DCxx range and possibly put on text stack) Hmm, even a procedure call result could actually be used as a callback result.