nml icon indicating copy to clipboard operation
nml copied to clipboard

Add: Support for NewGRF badges.

Open PeterN opened this issue 1 year ago • 2 comments

Add support for NewGRF badge feature in https://github.com/OpenTTD/OpenTTD/pull/13073

Use badge_table { } to create the translation table. Use badges property to assign a list of badges to an entity.

See 042_badges.nml for slightly more info.

PeterN avatar Jan 18 '25 19:01 PeterN

The regression test 042_badges will add a badge to the "Chaney 'Jubilee' (Steam)" engine, which will appear like so:

image

PeterN avatar Jan 18 '25 21:01 PeterN

Checking badges on a nearby tile for now would require something like this

switch(FEAT_STATIONS, SELF, _sw_check_yard_p1n1, [
    STORE_TEMP(1, 0x100),
    STORE_TEMP(bitmask(4), 0x101),
    var[0x79, 0, 0x1, 0xF1]]){return;}

better if we can simplify it to

nearby_tile_has_badge(x, y, badge, features)

whereas features is bitmask(FEAT_1, FEAT_2, ...)

WenSimEHRP avatar Mar 17 '25 09:03 WenSimEHRP

action 0 flags... badge_flags.patch

andythenorth avatar Apr 13 '25 07:04 andythenorth

badge_error_line_num.patch

More than happy to push these patches to my fork for cherrypick, but eh, they're tiny.

andythenorth avatar Apr 13 '25 10:04 andythenorth

Been using this for Iron Horse since the PR opened, works for me.

andythenorth avatar Jun 21 '25 17:06 andythenorth

No warning/error is thrown when creating a FEAT_BADGES item, whereby the label is not in the badgetable. Unless I'm msissing something here, I can't think why I would define a badge item that isn't in the badge table (and therefore isn't used on a vehicle?

I'm not sure if that should be considered an error, but it certainly feels like something that should trigger a warning since it's most likely a typo

audigex avatar Nov 04 '25 03:11 audigex

A similar "A warning would be nice" situation

If I have a badge eg "power/steam", but no "power" badge defined, the "power/steam" badge does show up in the newGRF debug menu but doesn't show up in the purchase menu as either a sprite or text. If the user's intention was to add text that's kinda obvious ("Power: steam" can't displayed if "Power" doesn't exist to have text), but it's a little counter-intuitive if the user is mostly thinking about adding a sprite but didn't want text

I assume this is a limitation of the implementation in OpenTTD rather than NML, but it would be good if NML threw a warning if a nested badge was defined without a parent badge already being defined

audigex avatar Nov 04 '25 14:11 audigex

No warning/error is thrown when creating a FEAT_BADGES item, whereby the label is not in the badgetable. Unless I'm msissing something here, I can't think why I would define a badge item that isn't in the badge table (and therefore isn't used on a vehicle?

I'm not sure if that should be considered an error, but it certainly feels like something that should trigger a warning since it's most likely a typo

Much like defining railtypes and roadtypes, there's no requirement to use badges when defining them. Maybe you wanted to make a collection of badges to be used in other NewGRFs. A badge table is only required to use badges, not to define them.

It's also not an error to not define a class badge.

PeterN avatar Nov 22 '25 22:11 PeterN

No warning/error is thrown when creating a FEAT_BADGES item, whereby the label is not in the badgetable. Unless I'm msissing something here, I can't think why I would define a badge item that isn't in the badge table (and therefore isn't used on a vehicle?

I'm not sure if that should be considered an error, but it certainly feels like something that should trigger a warning since it's most likely a typo

Much like defining railtypes and roadtypes, there's no requirement to use badges when defining them. Maybe you wanted to make a collection of badges to be used in other NewGRFs. A badge table is only required to use badges, not to define them.

It's also not an error to not define a class badge.

Lots of other NML warnings aren't really errors, either ... that's the point of a warning, surely? "You might be doing this intentionally but there's a good chance you aren't, maybe take a look?"

audigex avatar Nov 22 '25 22:11 audigex