Upgrading from a version prior to 0.7.3 changes specific use cases using vehicle random_bits

Open
#350 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Start by reproducing the two switch examples with nmlc and tracing how switch ranges and random_bits are handled. Identify the existing compiler diagnostic and test locations while checking the behavior change introduced by #288. Done means affected cases produce a useful warning when no valid range or default exists, with coverage for the reported examples.

Written by the indexing model from the issue text.

Description

Hello,

I recently upgraded from 0.7.1 to 0.7.5, and when I re-compiled a GRF (Mop's Expanded Road Vehicles) I noticed that some vehicles in-game had broken sprites.
I narrowed it down to this change, #288, after reading through the changelogs and testing different versions/commits.

This is due to how the original code is in deciding between different spritesets, f.ex:

switch (FEAT_ROADVEHS, SELF, switch_w_l_f_flat_e, random_bits ) {
    0..63:         spriteset_w_l_f_flat_e;
    64..127:       spriteset_w_l_f_flat_f;
    128..191:       spriteset_w_l_f_flat_g;
    192..255:       spriteset_w_l_f_flat_h;
}

As there is no default value or specific range defined there is no valid choice when the random value is between 256-65535.

I don't know if any other GRFs have the same issue, or if this is a very specific issue to how this GRF was written.
However, I do think it would be nice to have this show up as a warning in the nmlc output, if possible, so that its easier to catch if this is a problem in their code.

It also changes the probability between choices in cases like this, where it will now heavily favour the default value when compiled with a newer version of NML:

switch (FEAT_ROADVEHS, SELF, switch_o_box_b, random_bits ) {
        0..69: spritegroup_o_box_a;
        70..139: spritegroup_o_box_b;
        140..209: spritegroup_o_box_c;
        210..255: spritegroup_o_box_d;
        default: spritegroup_o_box_b;       
}

However, that is less of an issue, as it at least does have a default value to fall back to, even though it might lead to an unknown/unwanted change in behaviour for other GRFs, if they have implemented logic like this, and they are unaware of the random bits change.

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.