Bug: `alternative_sprites` in conditional blocks away from the parent behave inconsistently

Open
#371 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
compilers

Research direction

Start by reproducing the behavior with the attached redef-alternate.zip example and inspect how alternative_sprites and conditional blocks are processed. Compare the result with the linked NFO specification; done means conditional alternative sprites follow their condition and nonsensical separated definitions are handled consistently with NewGRF semantics.

Written by the indexing model from the issue text.

Description

As alternative_sprite blocks can be placed away from their 'parent' sprites, the NML syntax implies you can do things like define alternative_sprites in a conditional block which are used only when that condition is met. For example:

replace grid_temperate_spr3981(3981, "temperate_groundtiles_gridline_8bpp.png") { template_groundtiles(0, 0, 1) }
if (climate==CLIMATE_ARCTIC) {
    alternative_sprites (grid_temperate_spr3981, ZOOM_LEVEL_NORMAL, BIT_DEPTH_32BPP, "arctic_groundtiles_gridline_bt32bpp.png") { template_groundtiles(0, 0, 1) }
}

This doesn't work as you'd expect from the code. The alternative sprites are always used irrespective of climate.

The syntax also allows some quite nonsensical definitions:

if (climate==CLIMATE_TEMPERATE) {
    replace grid_temperate_spr3981(3981, "temperate_groundtiles_gridline_8bpp.png") { template_groundtiles(0, 0, 1) }
}
if (climate==CLIMATE_ARCTIC) {
    alternative_sprites (grid_temperate_spr3981, ZOOM_LEVEL_NORMAL, BIT_DEPTH_32BPP, "arctic_groundtiles_gridline_bt32bpp.png") { template_groundtiles(0, 0, 1) }
}

Such behaviour is not possible for NewGRFs (cf. NFO specs) as alternative sprites are just one part of the definition of a single real sprite.

Some example NML and images:
redef-alternate.zip

Dominant language
Python
Stars
61
Forks
47
Avg merge
8d 14h
Merged PRs (30d)
3

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OpenTTD/nml

All issues in OpenTTD/nml

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.