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: Reduce D0xx usage where possible #326

Merged
merged 2 commits into from
Apr 21, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion nml/actions/action2var.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ def __init__(self, action_feature, var_range=0x89):
self.var_list = []
self.var_list_size = 0
self.proc_call_list = []
self.in_store_op = False

def preprocess_binop(self, expr):
"""
Expand Down Expand Up @@ -571,6 +572,9 @@ def parse_binop(self, expr):
if expr.op.act2_num is None:
expr.supported_by_action2(True)

if expr.op == nmlop.STO_TMP:
self.in_store_op = True

if (
isinstance(expr.expr2, (expression.ConstantNumeric, expression.Variable))
or isinstance(expr.expr2, (VarAction2LoadTempVar, VarAction2LoadCallParam))
Expand Down Expand Up @@ -601,6 +605,9 @@ def parse_binop(self, expr):

self.parse(expr2)

if expr.op == nmlop.STO_TMP:
self.in_store_op = False

def parse_constant(self, expr):
var = VarAction2Var(0x1A, 0, expr.value)
self.var_list.append(var)
Expand All @@ -614,7 +621,7 @@ def parse_param(self, expr):
self.var_list_size += var.get_size()

def parse_string(self, expr):
str_id, actions = action4.get_string_action4s(0, 0xD0, expr)
str_id, actions = action4.get_string_action4s(0, 0xDC if self.in_store_op else 0xD0, expr)
self.extra_actions.extend(actions)
self.parse_constant(expression.ConstantNumeric(str_id))

Expand Down
4 changes: 4 additions & 0 deletions regression/013_train_callback.nml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ switch (FEAT_TRAINS, SELF, bulk_wagon_cb_weight_switch, cargo_type_in_veh) {
// no default: instead fail CB and use weight set in properties (25t)
}

switch (FEAT_TRAINS, SELF, bulk_wagon_cb_name_switch, STORE_TEMP(string(STR_NAME_BULK_WAGON), 0x100)) {
return string(STR_JUST_STRING);
}

item(FEAT_TRAINS, bulk_wagon) {
property {
Expand Down Expand Up @@ -144,6 +147,7 @@ item(FEAT_TRAINS, bulk_wagon) {
purchase_weight: return 25;
cargo_capacity: bulk_wagon_cb_capacity_switch;
purchase_cargo_capacity: return 30;
name: bulk_wagon_cb_name_switch;
default: bulk_wagon_graphics_switch;
}
}
Binary file modified regression/expected/013_train_callback.grf
Binary file not shown.
166 changes: 90 additions & 76 deletions regression/expected/013_train_callback.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 \d75
0 * 4 \d78

1 * 54 14 "C" "INFO"
"B" "VRSN" \w4 \dx00000000
Expand All @@ -16,7 +16,11 @@
00
00
2 * 52 08 08 "NML\13" "NML regression test" 00 "A test newgrf testing NML" 00
3 * 208 00 08 \b1 32 FF \wx0000
3 * 8 04 00 FF 01 \wxD000 "\80" 00

4 * 26 04 00 FF 01 \wxDC00 "NML Test bulk wagon" 00

5 * 208 00 08 \b1 32 FF \wx0000
09 "WDPR" "SCRP" "CMNT" "WOOD" "LVST"
"STEL" "VEHI" "BRCK" "WOOL" "BUBL"
"TOYS" "FZDR" "FRUT" "FRVG" "FOOD"
Expand All @@ -28,111 +32,111 @@
"MAIL" "BATT" "SWET" "RUBR" "FMSP"
"ENSP" "MNSP" "FICR" "PLAS" "PLST"

4 * 28 00 08 \b1 05 FF \wx0000
6 * 28 00 08 \b1 05 FF \wx0000
12 "RAIL" "ELRL" "MONO" "MGLV" "TRPD"

5 * 6 01 00 \b8 FF \wx0004
7 * 6 01 00 \b8 FF \wx0004

6 temperate_railwagons.png 8bpp 0 25 8 24 -3 -12 normal
7 temperate_railwagons.png 8bpp 16 25 22 17 -14 -9 normal
8 temperate_railwagons.png 8bpp 48 25 32 12 -16 -8 normal
9 temperate_railwagons.png 8bpp 96 25 22 17 -6 -9 normal
8 temperate_railwagons.png 8bpp 0 25 8 24 -3 -12 normal
9 temperate_railwagons.png 8bpp 16 25 22 17 -14 -9 normal
10 temperate_railwagons.png 8bpp 48 25 32 12 -16 -8 normal
11 temperate_railwagons.png 8bpp 96 25 22 17 -6 -9 normal

10 temperate_railwagons.png 8bpp 0 250 8 24 -3 -12 normal
11 temperate_railwagons.png 8bpp 16 250 22 17 -14 -9 normal
12 temperate_railwagons.png 8bpp 48 250 32 12 -16 -8 normal
13 temperate_railwagons.png 8bpp 96 250 22 17 -6 -9 normal
12 temperate_railwagons.png 8bpp 0 250 8 24 -3 -12 normal
13 temperate_railwagons.png 8bpp 16 250 22 17 -14 -9 normal
14 temperate_railwagons.png 8bpp 48 250 32 12 -16 -8 normal
15 temperate_railwagons.png 8bpp 96 250 22 17 -6 -9 normal

14 arctic_railwagons.pcx 8bpp 0 25 8 24 -3 -12 normal
15 arctic_railwagons.pcx 8bpp 16 25 22 17 -14 -9 normal
16 arctic_railwagons.pcx 8bpp 48 25 32 12 -16 -8 normal
17 arctic_railwagons.pcx 8bpp 96 25 22 17 -6 -9 normal
16 arctic_railwagons.pcx 8bpp 0 25 8 24 -3 -12 normal
17 arctic_railwagons.pcx 8bpp 16 25 22 17 -14 -9 normal
18 arctic_railwagons.pcx 8bpp 48 25 32 12 -16 -8 normal
19 arctic_railwagons.pcx 8bpp 96 25 22 17 -6 -9 normal

18 arctic_railwagons.pcx 8bpp 0 250 8 24 -3 -12 normal
19 arctic_railwagons.pcx 8bpp 16 250 22 17 -14 -9 normal
20 arctic_railwagons.pcx 8bpp 48 250 32 12 -16 -8 normal
21 arctic_railwagons.pcx 8bpp 96 250 22 17 -6 -9 normal
20 arctic_railwagons.pcx 8bpp 0 250 8 24 -3 -12 normal
21 arctic_railwagons.pcx 8bpp 16 250 22 17 -14 -9 normal
22 arctic_railwagons.pcx 8bpp 48 250 32 12 -16 -8 normal
23 arctic_railwagons.pcx 8bpp 96 250 22 17 -6 -9 normal

22 temperate_railwagons.png 8bpp 0 225 8 24 -3 -12 normal
23 temperate_railwagons.png 8bpp 16 225 22 17 -14 -9 normal
24 temperate_railwagons.png 8bpp 48 225 32 12 -16 -8 normal
25 temperate_railwagons.png 8bpp 96 225 22 17 -6 -9 normal
24 temperate_railwagons.png 8bpp 0 225 8 24 -3 -12 normal
25 temperate_railwagons.png 8bpp 16 225 22 17 -14 -9 normal
26 temperate_railwagons.png 8bpp 48 225 32 12 -16 -8 normal
27 temperate_railwagons.png 8bpp 96 225 22 17 -6 -9 normal

26 temperate_railwagons.png 8bpp 0 350 8 24 -3 -12 normal
27 temperate_railwagons.png 8bpp 16 350 22 17 -14 -9 normal
28 temperate_railwagons.png 8bpp 48 350 32 12 -16 -8 normal
29 temperate_railwagons.png 8bpp 96 350 22 17 -6 -9 normal
28 temperate_railwagons.png 8bpp 0 350 8 24 -3 -12 normal
29 temperate_railwagons.png 8bpp 16 350 22 17 -14 -9 normal
30 temperate_railwagons.png 8bpp 48 350 32 12 -16 -8 normal
31 temperate_railwagons.png 8bpp 96 350 22 17 -6 -9 normal

30 temperate_railwagons.png 8bpp 0 150 8 24 -3 -12 normal
31 temperate_railwagons.png 8bpp 16 150 22 17 -14 -9 normal
32 temperate_railwagons.png 8bpp 48 150 32 12 -16 -8 normal
33 temperate_railwagons.png 8bpp 96 150 22 17 -6 -9 normal
32 temperate_railwagons.png 8bpp 0 150 8 24 -3 -12 normal
33 temperate_railwagons.png 8bpp 16 150 22 17 -14 -9 normal
34 temperate_railwagons.png 8bpp 48 150 32 12 -16 -8 normal
35 temperate_railwagons.png 8bpp 96 150 22 17 -6 -9 normal

34 temperate_railwagons.png 8bpp 0 275 8 24 -3 -12 normal
35 temperate_railwagons.png 8bpp 16 275 22 17 -14 -9 normal
36 temperate_railwagons.png 8bpp 48 275 32 12 -16 -8 normal
37 temperate_railwagons.png 8bpp 96 275 22 17 -6 -9 normal
36 temperate_railwagons.png 8bpp 0 275 8 24 -3 -12 normal
37 temperate_railwagons.png 8bpp 16 275 22 17 -14 -9 normal
38 temperate_railwagons.png 8bpp 48 275 32 12 -16 -8 normal
39 temperate_railwagons.png 8bpp 96 275 22 17 -6 -9 normal

// Name: bulk_wagon_coal_default_group - feature 00
38 * 13 02 00 FF \b2 \b2
40 * 13 02 00 FF \b2 \b2
\w0 \w1
\w0 \w1

// Name: bulk_wagon_coal_arctic_group - feature 00
39 * 13 02 00 FE \b2 \b2
41 * 13 02 00 FE \b2 \b2
\w2 \w3
\w2 \w3

// Name: bulk_wagon_coal2_group - feature 00
40 * 13 02 00 FD \b2 \b2
42 * 13 02 00 FD \b2 \b2
\w4 \w5
\w4 \w5

// Name: bulk_wagon_grain_group - feature 00
41 * 13 02 00 FC \b2 \b2
43 * 13 02 00 FC \b2 \b2
\w6 \w7
\w6 \w7

// Name: bulk_wagon_coal_default_switch
42 * 15 02 00 FD 80 02 \b0 04
44 * 15 02 00 FD 80 02 \b0 04
\wx00FF \wx00FF \wx00FF // (2/3) -> (3/4): bulk_wagon_coal_default_group;
\wx00FD // (1/3) -> (1/4): bulk_wagon_coal2_group;

// param[127] = (param[131] & 255)
43 * 9 0D 7F \D& 83 FF \dx000000FF
45 * 9 0D 7F \D& 83 FF \dx000000FF

44 * 7 06
46 * 7 06
7F 04 FF \wx0006
FF

// Name: bulk_wagon_coal_climate_switch
45 * 23 02 00 FD 89
47 * 23 02 00 FD 89
1A 00 \dx00000000 // param[127]
\b1
\wx00FE \dx00000001 \dx00000001 // 1 .. 1: bulk_wagon_coal_arctic_group;
\wx00FD // default: bulk_wagon_coal_default_switch;

// Name: bulk_wagon_graphics_switch
46 * 23 02 00 FC 89
48 * 23 02 00 FC 89
47 00 \dx000000FF
\b1
\wx00FD \dx00000013 \dx00000013 // 19 .. 19: bulk_wagon_coal_climate_switch;
\wx00FC // default: bulk_wagon_grain_group;

// Name: @CB_FAILED_REAL00
47 * 9 02 00 FD \b1 \b1
49 * 9 02 00 FD \b1 \b1
\w0
\w0

// Name: @CB_FAILED00
48 * 23 02 00 FD 89
50 * 23 02 00 FD 89
0C 00 \dx0000FFFF
\b1
\wx8000 \dx00000000 \dx00000000 // graphics callback -> return 0
\wx00FD // Non-graphics callback, return graphics result

// Name: bulk_wagon_cb_capacity_switch
49 * 83 02 00 FE 89
51 * 83 02 00 FE 89
47 00 \dx000000FF
\b7
\wx8019 \dx0000002F \dx0000002F // 47 .. 47: return 25;
Expand All @@ -145,7 +149,7 @@ FF
\wx00FD // No default specified -> fail callback

// Name: bulk_wagon_cb_weight_switch
50 * 53 02 00 FD 89
52 * 53 02 00 FD 89
47 00 \dx000000FF
\b4
\wx8012 \dx00000013 \dx00000013 // 19 .. 19: return 18;
Expand All @@ -154,68 +158,76 @@ FF
\wx8012 \dx0000001A \dx0000001A // 26 .. 26: return 18;
\wx00FD // No default specified -> fail callback

// Name: bulk_wagon_cb_name_switch
53 * 30 02 00 FF 89
1A 20 \dx0000DC00
\2sto 1A 00 \dx00000100
\b1
\wx8000 \dx00000001 \dx00000000 // Bogus range to avoid nvar == 0
\wx8000 // default: return string(STR_JUST_STRING);

// param[125] = (param[1] * 5000)
51 * 9 0D 7D \D* 01 FF \dx00001388
54 * 9 0D 7D \D* 01 FF \dx00001388

// param[126] = (param[125] + 698)
52 * 9 0D 7E \D+ 7D FF \dx000002BA
55 * 9 0D 7E \D+ 7D FF \dx000002BA

// param[127] = (param[126] / 1397)
53 * 9 0D 7F \D/ 7E FF \dx00000575
56 * 9 0D 7F \D/ 7E FF \dx00000575

// param[124] = (param[2] * 12500)
54 * 9 0D 7C \D* 02 FF \dx000030D4
57 * 9 0D 7C \D* 02 FF \dx000030D4

// param[125] = (param[124] + 6286)
55 * 9 0D 7D \D+ 7C FF \dx0000188E
58 * 9 0D 7D \D+ 7C FF \dx0000188E

// param[126] = (param[125] / 12573)
56 * 9 0D 7E \D/ 7D FF \dx0000311D
59 * 9 0D 7E \D/ 7D FF \dx0000311D

// param[123] = (param[3] * 8)
57 * 9 0D 7B \D* 03 FF \dx00000008
60 * 9 0D 7B \D* 03 FF \dx00000008

// param[124] = (param[123] + 2)
58 * 9 0D 7C \D+ 7B FF \dx00000002
61 * 9 0D 7C \D+ 7B FF \dx00000002

// param[125] = (param[124] / 5)
59 * 9 0D 7D \D/ 7C FF \dx00000005
62 * 9 0D 7D \D/ 7C FF \dx00000005

// param[122] = (param[4] * 2965)
60 * 9 0D 7A \D* 04 FF \dx00000B95
63 * 9 0D 7A \D* 04 FF \dx00000B95

// param[123] = (param[122] + 1105)
61 * 9 0D 7B \D+ 7A FF \dx00000451
64 * 9 0D 7B \D+ 7A FF \dx00000451

// param[124] = (param[123] / 2211)
62 * 9 0D 7C \D/ 7B FF \dx000008A3
65 * 9 0D 7C \D/ 7B FF \dx000008A3

63 * 22 06
66 * 22 06
7F 02 FF \wx000B
7E 02 FF \wx000E
7D 02 FF \wx0011
7C 02 FF \wx0014
FF

64 * 22 00 00 \b5 01 FF \wx0074
67 * 22 00 00 \b5 01 FF \wx0074
09 \wx0024
09 \wx0000
09 \wx0000
09 \wx0000
0B \wx0000

// param[127] = (param[1] & 255)
65 * 9 0D 7F \D& 01 FF \dx000000FF
68 * 9 0D 7F \D& 01 FF \dx000000FF

// param[126] = (param[1] << -8)
66 * 9 0D 7E \D<< 01 FF \dxFFFFFFF8
69 * 9 0D 7E \D<< 01 FF \dxFFFFFFF8

67 * 12 06
70 * 12 06
7F 01 FF \wx004D
7E 01 FF \wx004F
FF

68 * 82 00 00 \b26 01 FF \wx0074
71 * 82 00 00 \b26 01 FF \wx0074
06 0F
28 \wx0010
1D \dx00000000
Expand Down Expand Up @@ -244,43 +256,45 @@ FF
24 00
25 00

69 * 27 04 00 7F 01 FF \wx0074 "NML Test bulk wagon" 00
72 * 27 04 00 7F 01 FF \wx0074 "NML Test bulk wagon" 00

70 * 9 00 00 \b1 01 FF \wx0074
73 * 11 00 00 \b2 01 FF \wx0074
1E 08
31 01

// Name: @action3_0
71 * 33 02 00 FD 89
74 * 33 02 00 FD 89
10 00 \dx000000FF
\b2
\wx00FE \dx00000014 \dx00000014 // bulk_wagon_cb_capacity_switch;
\wx00FD \dx00000016 \dx00000016 // bulk_wagon_cb_weight_switch;
\wx00FC // bulk_wagon_graphics_switch;

// Name: @action3_1
72 * 33 02 00 FF 89
75 * 33 02 00 FB 89
10 00 \dx000000FF
\b2
\wx801E \dx00000014 \dx00000014 // return 30;
\wx8019 \dx00000016 \dx00000016 // return 25;
\wx00FC // bulk_wagon_graphics_switch;

// Name: @action3_2
73 * 33 02 00 FD 89
76 * 33 02 00 FD 89
0C 00 \dx0000FFFF
\b2
\wx00FE \dx00000015 \dx00000015 // bulk_wagon_cb_capacity_switch;
\wx00FD \dx00000036 \dx00000036 // @action3_0;
\wx00FC // bulk_wagon_graphics_switch;

// Name: @action3_3
74 * 23 02 00 FC 89
77 * 33 02 00 FC 89
0C 00 \dx0000FFFF
\b1
\wx00FF \dx00000036 \dx00000036 // @action3_1;
\b2
\wx00FB \dx00000036 \dx00000036 // @action3_1;
\wx00FF \dx00000161 \dx00000161 // bulk_wagon_cb_name_switch;
\wx00FC // bulk_wagon_graphics_switch;

75 * 12 03 00 01 FF \wx0074 \b1
78 * 12 03 00 01 FF \wx0074 \b1
FF \wx00FC // @action3_3;
\wx00FD // @action3_2;

2 changes: 2 additions & 0 deletions regression/lang/english.lng
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ STR_COALMINE_MONTH_11 :{BLACK}diamonds
STR_BREWERY_NAME :Brewery

STR_032_HOUSE :Example house

STR_JUST_STRING :{STRING}