Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions nml/actions/action0.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,9 @@ def parse_property(prop_info, value_list, feature, id):
"String used as value for non-string property: " + str(prop_info["num"]), value.pos
)
string_range = prop_info["string"]
if isinstance(string_range, tuple):
threshold, below, above = string_range
string_range = below if id.value < threshold else above
stringid, string_actions = action4.get_string_action4s(feature, string_range, value, id)
value = expression.ConstantNumeric(stringid)
action_list_append.extend(string_actions)
Expand Down
5 changes: 2 additions & 3 deletions nml/actions/action0properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,8 @@ def cargo_bitmask(value):
# 19 (road routing) reserved for future use
# 1A (advanced sprite layout) is implemented elsewhere
# 1B (minimum bridge height) JGR only

"classname": {"num": -1, "string": 0xC4},
"name": {"num": -1, "string": 0xC5, "required": True},
"name": {"size": 2, "num": 0x1C, "string": (256, 0xC5, 0xDC), "required": True},
"classname": {"size": 2, "num": 0x1D, "string": 0xDC},
}
# fmt: on

Expand Down
6 changes: 5 additions & 1 deletion nml/actions/action4.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ def skip_action9(self):
0xD0: {"random_id": True, "total": 0x400, "ids": list(range(0xD3FF, 0xCFFF, -1))},
# Misc. persistent text ids, used to set properties.
# Use Ids DC00..DCFF first to keep compatibility with older versions of OTTD.
0xDC: {"random_id": True, "total": 0x800, "ids": list(range(0xDBFF, 0xD7FF, -1)) + list(range(0xDFFF, 0xDBFF, -1))},
0xDC: {
"random_id": True,
"total": 0x2800,
"ids": list(range(0xFFFF, 0xDFFF, -1)) + list(range(0xDBFF, 0xD7FF, -1)) + list(range(0xDFFF, 0xDBFF, -1)),
frosch123 marked this conversation as resolved.
Show resolved Hide resolved
},
}

# Mapping of string identifiers to D0xx/DCxx text ids
Expand Down
Binary file modified regression/expected/040_station.grf
Binary file not shown.
30 changes: 16 additions & 14 deletions regression/expected/040_station.nfo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Escapes: D= = DR D+ = DF D- = DC Du* = DM D* = DnF Du<< = DnC D<< = DO D& D| Du/ D/ Du% D%
// Format: spritenum imagefile depth xpos ypos xsize ysize xrel yrel zoom flags

0 * 4 \d36
0 * 4 \d35

1 * 54 14 "C" "INFO"
"B" "VRSN" \w4 \dx00000000
Expand All @@ -16,17 +16,19 @@
00
00
2 * 52 08 08 "NML\40" "NML regression test" 00 "A test newgrf testing NML" 00
3 * 16 00 08 \b1 02 FF \wx0000
3 * 11 04 04 FF 01 \wxDC00 "Test" 00

4 * 16 00 08 \b1 02 FF \wx0000
09 "COAL" "LVST"

4 * 21 00 04 \b4 01 FF \wx0000
5 * 27 00 04 \b6 01 FF \wx0000
08 "TEST"
1D \wxDC00
1C \wxC500
13 18
12 \dx00000002
0C F0

5 * 11 04 04 FF 01 \wxC400 "Test" 00

6 * 20 04 04 FF 01 \wxC500 "Basic station" 00

7 * 6 01 04 \b2 FF \wx0002
Expand Down Expand Up @@ -179,37 +181,37 @@
FF \wx00F9 // @action3_3;
\wx00F8 // @action3_4;

29 * 12 00 04 \b1 01 FF \wx0001
29 * 18 00 04 \b3 01 FF \wx0001
08 "TEST"
1D \wxDC00
1C \wxC501

30 * 11 04 04 FF 01 \wxC401 "Test" 00

31 * 22 04 04 FF 01 \wxC501 "Basic station 2" 00
30 * 22 04 04 FF 01 \wxC501 "Basic station 2" 00

32 * 9 00 04 \b1 01 FF \wx0001
31 * 9 00 04 \b1 01 FF \wx0001
0A 00

// Name: @CB_FAILED_REAL04
33 * 7 02 04 F8 \b0 \b1
32 * 7 02 04 F8 \b0 \b1

\w0

// Name: @CB_FAILED04
34 * 23 02 04 F8 89
33 * 23 02 04 F8 89
0C 00 \dx0000FFFF
\b1
\wx8000 \dx00000000 \dx00000000 // graphics callback -> return 0
\wx00F8 // Non-graphics callback, return graphics result

// Name: @action3_7
35 * 41 02 04 F8 89
34 * 41 02 04 F8 89
7E FD 20 \dxFFFFFFFF // Station Layout@registers - Id 00
\2r 10 00 \dx000000FF
\b2
\wx00FF \dx00000001 \dx00000001 // station_spriteset;
\wx00FE \dx00000003 \dx00000003 // station_spriteset2;
\wx00F8 // @CB_FAILED04;

36 * 7 03 04 01 01 \b0
35 * 7 03 04 01 01 \b0
\wx00F8 // @action3_7;

Binary file modified regression/expected/example_station.grf
Binary file not shown.
40 changes: 21 additions & 19 deletions regression/expected/example_station.nfo
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,59 @@
00
00
2 * 193 08 08 "NML\06" "NML Example NewGRF: Station" 00 "\8ENML Example NewGRF: Station\0D\98This NewGRF is intended to provide a coding example for the high-level NewGRF-coding language NML.\0DConversion of CHIPS Cow pens." 00
3 * 18 04 04 FF 01 \wxDC00 "NML Example" 00

// param[126] = param[161]
3 * 5 0D 7E \D= A1 00
4 * 5 0D 7E \D= A1 00

// param[127] = (param[126] - 302012611)
4 * 9 0D 7F \D- 7E FF \dx120058C3
5 * 9 0D 7F \D- 7E FF \dx120058C3

// param[127] = (param[127] << -31)
5 * 9 0D 7F \Du<< 7F FF \dxFFFFFFE1
6 * 9 0D 7F \Du<< 7F FF \dxFFFFFFE1

6 * 9 09 7F 04 \7= \dx00000000 01
7 * 9 09 7F 04 \7= \dx00000000 01

7 * 19 0B 03 7F 06 "1.2.0 (r22723)" 00
8 * 19 0B 03 7F 06 "1.2.0 (r22723)" 00

8 * 12 00 08 \b1 01 FF \wx0000
9 * 12 00 08 \b1 01 FF \wx0000
09 "LVST"

9 * 6 01 04 \b3 FF \wx0002
10 * 6 01 04 \b3 FF \wx0002

10 cows_cargo.png 8bpp 10 10 64 65 -31 -34 normal
11 cows_cargo.png 8bpp 220 10 64 65 -31 -34 normal
11 cows_cargo.png 8bpp 10 10 64 65 -31 -34 normal
12 cows_cargo.png 8bpp 220 10 64 65 -31 -34 normal

12 cows_cargo.png 8bpp 80 10 64 65 -31 -34 normal
13 cows_cargo.png 8bpp 290 10 64 65 -31 -34 normal
13 cows_cargo.png 8bpp 80 10 64 65 -31 -34 normal
14 cows_cargo.png 8bpp 290 10 64 65 -31 -34 normal

14 cows_cargo.png 8bpp 150 10 64 65 -31 -34 normal
15 cows_cargo.png 8bpp 360 10 64 65 -31 -34 normal
15 cows_cargo.png 8bpp 150 10 64 65 -31 -34 normal
16 cows_cargo.png 8bpp 360 10 64 65 -31 -34 normal

// Name: cow_pen_1 - feature 04
16 * 11 02 04 FF \b2 \b1
17 * 11 02 04 FF \b2 \b1
\w0 \w1
\w2

// Name: cow_pen_2 - feature 04
17 * 13 02 04 FE \b3 \b1
18 * 13 02 04 FE \b3 \b1
\w0 \w1 \w2
\w2

// Name: random_cow_pen
18 * 11 02 04 FE 80 00 \b16 02
19 * 11 02 04 FE 80 00 \b16 02
\wx00FF // (1/2) -> (1/2): cow_pen_1;
\wx00FE // (1/2) -> (1/2): cow_pen_2;

19 * 21 00 04 \b5 01 FF \wx0000
20 * 27 00 04 \b7 01 FF \wx0000
08 "NML_"
1D \wxDC00
1C \wxC500
10 \wx00A0
11 00
14 FF
15 FF

20 * 18 04 04 FF 01 \wxC400 "NML Example" 00

21 * 21 04 04 FF 01 \wxC500 "CHIPS Cow pens" 00

// Name: cow_pen_half - feature 04
Expand Down