From fe18b3b9cdf3d48562542874744c9fb07319f2f5 Mon Sep 17 00:00:00 2001 From: glx22 Date: Tue, 26 Sep 2023 23:23:17 +0200 Subject: [PATCH] Fix a9a1a3e: Don't use station properties 1C/1D for IDs 00-FF --- nml/actions/action0.py | 18 +++-- nml/actions/action0properties.py | 6 +- regression/040_station.nml | 4 +- regression/expected/040_station.grf | Bin 1261 -> 1264 bytes regression/expected/040_station.nfo | 86 ++++++++++++------------ regression/expected/example_station.grf | Bin 3933 -> 3927 bytes regression/expected/example_station.nfo | 40 ++++++----- 7 files changed, 79 insertions(+), 75 deletions(-) diff --git a/nml/actions/action0.py b/nml/actions/action0.py index 9d8babb9..8e84a8ac 100644 --- a/nml/actions/action0.py +++ b/nml/actions/action0.py @@ -597,6 +597,14 @@ def parse_property(prop_info, value_list, feature, id): if "custom_function" in prop_info: props = prop_info["custom_function"](*value_list) else: + + def apply_threshold(value): + if not isinstance(value, tuple): + return value + assert len(value) == 3 + threshold, below, above = value + return below if id.value < threshold else above + # First process each element in the value_list final_values = [] for i, value in enumerate(value_list): @@ -629,10 +637,7 @@ def parse_property(prop_info, value_list, feature, id): raise generic.ScriptError( "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 + string_range = apply_threshold(prop_info["string"]) stringid, string_actions = action4.get_string_action4s(feature, string_range, value, id) value = expression.ConstantNumeric(stringid) action_list_append.extend(string_actions) @@ -646,8 +651,9 @@ def parse_property(prop_info, value_list, feature, id): final_values.append(value) # Now, write a single Action0 Property with all of these values - if prop_info["num"] != -1: - props = [Action0Property(prop_info["num"], final_values, prop_info["size"])] + prop_num = apply_threshold(prop_info["num"]) + if prop_num != -1: + props = [Action0Property(prop_num, final_values, prop_info["size"])] else: props = [] diff --git a/nml/actions/action0properties.py b/nml/actions/action0properties.py index f2ab91cc..b0074a34 100644 --- a/nml/actions/action0properties.py +++ b/nml/actions/action0properties.py @@ -116,6 +116,7 @@ def get_size(self): # 'string', if set, means that the value of the property should be a string. # The value of characteristic indicates the string range to use (usually 0xD0 or 0xDC) # If set to None, the string will use the ID of the item (used for vehicle names) +# It can also be a (threshold, below, above) tuple to select range depending on ID # # 'string_literal', if set, indicates that the value of the property should # be a literal (quoted) string. The value of the characteristic is equal to @@ -155,6 +156,7 @@ def get_size(self): # 'num' is the Action0 property number of the action 0 property, as given by the # nfo specs. If set to -1, no action0 property will be generated. If # 'custom_function' is set, this value is not needed and can be left out. +# It can also be a (threshold, below, above) tuple to set 'num' depending on ID. # # 'size' is the size (in bytes) of the resulting action 0 property. Valid # values are 1 (byte), 2 (word) or 4 (dword). For other (or variable) sizes, @@ -706,8 +708,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 - "name": {"size": 2, "num": 0x1C, "string": (256, 0xC5, 0xDC), "required": True}, - "classname": {"size": 2, "num": 0x1D, "string": 0xDC}, + "name": {"size": 2, "num": (256, -1, 0x1C), "string": (256, 0xC5, 0xDC), "required": True}, + "classname": {"size": 2, "num": (256, -1, 0x1D), "string": (256, 0xC4, 0xDC)}, } # fmt: on diff --git a/regression/040_station.nml b/regression/040_station.nml index 5313aee4..7458d5b2 100644 --- a/regression/040_station.nml +++ b/regression/040_station.nml @@ -103,7 +103,7 @@ spritelayout station_sprite_layout_1(a) { } } -item (FEAT_STATIONS, basic_station) { +item (FEAT_STATIONS, basic_station, 255) { property { class : "TEST"; classname: string(STR_STATION_TEST_CLASS); @@ -128,7 +128,7 @@ item (FEAT_STATIONS, basic_station) { } } -item (FEAT_STATIONS, basic_station_copied_layout) { +item (FEAT_STATIONS, basic_station_copied_layout, 256) { property { class : "TEST"; classname: string(STR_STATION_TEST_CLASS); diff --git a/regression/expected/040_station.grf b/regression/expected/040_station.grf index a5d99774380a9ad97adf6485e2d90ebe8b4f2595..c04740a6ec5e54012ee0cf8e876171f6f6aeaec3 100644 GIT binary patch delta 263 zcmX|)y-EX75QWd#JBWKX3zC>1i9cz40qZm|s7)Y{Ea`(-Y@@<%X`^ot?xP4kfvxxe z?kfb+sfdjC-omNQd^7XSCf%kPa5cYt%5C4?ud~N;06;}FK~vmRHO^O6c|EM^RbAfQ z4$rU`=GbMTKsuR?r_<%4=td|)^`qiqQFIR4iD#{?*GC=oHR|^N`}N0(Gwkh%C%?Jt z@s#>J;v1>XnwL>KY?`Pv_ym8T-}pkr5JLsyt0OdrY|^j|@yDQ5*Og@_q96eMT`21w QWWdb5OP{TnbDxj@01SXdxc~qF delta 262 zcmeys`IeKLfx$h_ccVX$&+wmxG0IFfW>jKi z*c`@qmXVQRvI_IIP_Ws|EQ}1y4Br_Te>435$?$_g2x2xfBhU$Ovl)+y!Hi@)>XcZV znXFJ;l30?NpQm8N05l)yL>5Mn4lahtVk}{T>>wea$&5e)L4b2|J&QCW*W}qOQjFYS LHV=r+0+Is&E7?2i diff --git a/regression/expected/040_station.nfo b/regression/expected/040_station.nfo index 8eb8fc98..a5850a48 100644 --- a/regression/expected/040_station.nfo +++ b/regression/expected/040_station.nfo @@ -16,40 +16,40 @@ 00 00 2 * 52 08 08 "NML\40" "NML regression test" 00 "A test newgrf testing NML" 00 -3 * 11 04 04 FF 01 \wxDC00 "Test" 00 +3 * 27 04 04 FF 02 \wxDC00 "Test" 00 "Basic station 2" 00 4 * 16 00 08 \b1 02 FF \wx0000 09 "COAL" "LVST" -5 * 27 00 04 \b6 01 FF \wx0000 +5 * 21 00 04 \b4 01 FF \wx00FF 08 "TEST" -1D \wxDC00 -1C \wxC500 13 18 12 \dx00000002 0C F0 -6 * 20 04 04 FF 01 \wxC500 "Basic station" 00 +6 * 11 04 04 FF 01 \wxC4FF "Test" 00 + +7 * 20 04 04 FF 01 \wxC5FF "Basic station" 00 -7 * 6 01 04 \b2 FF \wx0002 +8 * 6 01 04 \b2 FF \wx0002 -8 station.png 8bpp 1 1 5 5 -2 -2 normal -9 station.png 8bpp 7 1 5 5 -2 -2 normal +9 station.png 8bpp 1 1 5 5 -2 -2 normal +10 station.png 8bpp 7 1 5 5 -2 -2 normal -10 station.png 8bpp 2 2 3 3 -1 -1 normal -11 station.png 8bpp 8 2 3 3 -1 -1 normal +11 station.png 8bpp 2 2 3 3 -1 -1 normal +12 station.png 8bpp 8 2 3 3 -1 -1 normal // Name: station_spriteset - feature 04 -12 * 7 02 04 FF \b0 \b1 +13 * 7 02 04 FF \b0 \b1 \w0 // Name: station_spriteset2 - feature 04 -13 * 7 02 04 FE \b0 \b1 +14 * 7 02 04 FE \b0 \b1 \w1 -14 * 114 00 04 \b1 01 FF \wx0000 +15 * 114 00 04 \b1 01 FF \wx00FF 1A \b2 \b68 \dx000003F4 \wx0000 \dx0000842E \wx0000 \b0 \b0 \b0 \b16 \b5 \b2 @@ -62,9 +62,9 @@ \dx0000842D \wx0000 \b11 \b0 \b0 \b5 \b16 \b2 \dx8000842D \wx0042 \b20 \b10 80 84 03 -// Name: Station Layout@registers - Id 00 +// Name: Station Layout@registers - Id FF // a : register 80 -15 * 77 02 04 FD 89 +16 * 77 02 04 FD 89 1A 20 \dx00000000 \2sto 1A 20 \dx00000081 \2r 1A 20 \dx00000000 @@ -78,8 +78,8 @@ \b0 \wx8000 // Return computed value -// Name: Station Layout@prepare - Id 00 -16 * 34 02 04 FC 89 +// Name: Station Layout@prepare - Id FF +17 * 34 02 04 FC 89 1A 20 \dx00000000 \2sto 1A 20 \dx00000000 \2r 1A 20 \dx00000001 @@ -88,9 +88,9 @@ \wx8000 // Return computed value // Name: @action3_0 -17 * 49 02 04 FB 89 -7E FC 20 \dxFFFFFFFF // Station Layout@prepare - Id 00 -\2r 7E FD 20 \dxFFFFFFFF // Station Layout@registers - Id 00 +18 * 49 02 04 FB 89 +7E FC 20 \dxFFFFFFFF // Station Layout@prepare - Id FF +\2r 7E FD 20 \dxFFFFFFFF // Station Layout@registers - Id FF \2r 10 00 \dx000000FF \b2 \wx8000 \dx00000002 \dx00000002 // return 0; @@ -98,9 +98,9 @@ \wx00FF // station_spriteset; // Name: @action3_1 -18 * 49 02 04 FA 89 -7E FC 20 \dxFFFFFFFF // Station Layout@prepare - Id 00 -\2r 7E FD 20 \dxFFFFFFFF // Station Layout@registers - Id 00 +19 * 49 02 04 FA 89 +7E FC 20 \dxFFFFFFFF // Station Layout@prepare - Id FF +\2r 7E FD 20 \dxFFFFFFFF // Station Layout@registers - Id FF \2r 10 00 \dx000000FF \b2 \wx00FF \dx00000001 \dx00000001 // station_spriteset; @@ -108,9 +108,9 @@ \wx00FE // station_spriteset2; // Name: @action3_2 -19 * 49 02 04 FC 89 -7E FC 20 \dxFFFFFFFF // Station Layout@prepare - Id 00 -\2r 7E FD 20 \dxFFFFFFFF // Station Layout@registers - Id 00 +20 * 49 02 04 FC 89 +7E FC 20 \dxFFFFFFFF // Station Layout@prepare - Id FF +\2r 7E FD 20 \dxFFFFFFFF // Station Layout@registers - Id FF \2r 10 00 \dx000000FF \b2 \wx8000 \dx00000002 \dx00000002 // return 0; @@ -118,42 +118,42 @@ \wx00FF // station_spriteset; // Name: @action3_3 -20 * 55 02 04 F9 89 +21 * 55 02 04 F9 89 1A 20 \dx00000003 \2sto 1A 20 \dx00000003 -\2r 7E FD 20 \dxFFFFFFFF // Station Layout@registers - Id 00 +\2r 7E FD 20 \dxFFFFFFFF // Station Layout@registers - Id FF \2r 10 00 \dx000000FF \b2 \wx8000 \dx00000002 \dx00000002 // return 0; \wx00FE \dx00000003 \dx00000003 // station_spriteset2; \wx00FF // station_spriteset; -21 * 9 00 04 \b1 01 FF \wx0000 +22 * 9 00 04 \b1 01 FF \wx00FF 0B 08 // Name: @return_action_0 -22 * 20 02 04 F8 89 +23 * 20 02 04 F8 89 43 38 \dx0000000F \2+ 43 1C \dx0000000F \b0 \wx8000 // Return computed value // Name: @action3_4 -23 * 23 02 04 F8 89 +24 * 23 02 04 F8 89 0C 00 \dx0000FFFF \b1 \wx00F8 \dx00000142 \dx00000142 // return (var[0x43, 24, 15] + var[0x43, 28, 15]) \wx00FB // @action3_0; // Name: @return_action_1 -24 * 20 02 04 F7 89 +25 * 20 02 04 F7 89 43 38 \dx0000000F \2+ 43 1C \dx0000000F \b0 \wx8000 // Return computed value // Name: @action3_5 -25 * 33 02 04 F7 89 +26 * 33 02 04 F7 89 0C 00 \dx0000FFFF \b2 \wx00FA \dx00000000 \dx00000000 // @action3_1; @@ -161,35 +161,33 @@ \wx00FB // @action3_0; // Name: @return_action_2 -26 * 20 02 04 FA 89 +27 * 20 02 04 FA 89 43 38 \dx0000000F \2+ 43 1C \dx0000000F \b0 \wx8000 // Return computed value // Name: @action3_6 -27 * 33 02 04 FB 89 +28 * 33 02 04 FB 89 0C 00 \dx0000FFFF \b2 \wx00FC \dx00000000 \dx00000000 // @action3_2; \wx00FA \dx00000142 \dx00000142 // return (var[0x43, 24, 15] + var[0x43, 28, 15]) \wx00FB // @action3_0; -28 * 16 03 04 01 00 \b3 +29 * 18 03 04 01 FF \wx00FF \b3 00 \wx00F7 // @action3_5; 01 \wx00FB // @action3_6; FF \wx00F9 // @action3_3; \wx00F8 // @action3_4; -29 * 18 00 04 \b3 01 FF \wx0001 +30 * 18 00 04 \b3 01 FF \wx0100 08 "TEST" 1D \wxDC00 -1C \wxC501 - -30 * 22 04 04 FF 01 \wxC501 "Basic station 2" 00 +1C \wxDC01 -31 * 9 00 04 \b1 01 FF \wx0001 -0A 00 +31 * 9 00 04 \b1 01 FF \wx0100 +0A FF // Name: @CB_FAILED_REAL04 32 * 7 02 04 F8 \b0 \b1 @@ -205,13 +203,13 @@ FF \wx00F9 // @action3_3; // Name: @action3_7 34 * 41 02 04 F8 89 -7E FD 20 \dxFFFFFFFF // Station Layout@registers - Id 00 +7E FD 20 \dxFFFFFFFF // Station Layout@registers - Id FF \2r 10 00 \dx000000FF \b2 \wx00FF \dx00000001 \dx00000001 // station_spriteset; \wx00FE \dx00000003 \dx00000003 // station_spriteset2; \wx00F8 // @CB_FAILED04; -35 * 7 03 04 01 01 \b0 +35 * 9 03 04 01 FF \wx0100 \b0 \wx00F8 // @action3_7; diff --git a/regression/expected/example_station.grf b/regression/expected/example_station.grf index 77ffb496588f82cf408d3de80df0dd66285a6e55..ba767de2c8f1861e737af13686b8956ab627f7f9 100644 GIT binary patch delta 171 zcmcaBcU_K~fx$hlj&ifNGj1 zH!zoME@l;EWaR~NZvwe#o8PmQF|zRixxX1FU*y@lS%cGok&Pe7k7ki~^g_@JwU^0D%ZB*#H0l delta 159 zcmcaEcUO*^fx$h`Hy@*z5Ca3le-@Vij0|`De0>yLD-v@Ha#ANtFy>9} zXVhS00ZRWBoVt{F$>v;EK}JTt&Gl>#7#aCDCvY$^u?YYrqnRdGGpBAo%k_hiQE>Ay Ho{3BVy7?&_ diff --git a/regression/expected/example_station.nfo b/regression/expected/example_station.nfo index f1a9a462..0e8c930a 100644 --- a/regression/expected/example_station.nfo +++ b/regression/expected/example_station.nfo @@ -16,59 +16,57 @@ 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] -4 * 5 0D 7E \D= A1 00 +3 * 5 0D 7E \D= A1 00 // param[127] = (param[126] - 302012611) -5 * 9 0D 7F \D- 7E FF \dx120058C3 +4 * 9 0D 7F \D- 7E FF \dx120058C3 // param[127] = (param[127] << -31) -6 * 9 0D 7F \Du<< 7F FF \dxFFFFFFE1 +5 * 9 0D 7F \Du<< 7F FF \dxFFFFFFE1 -7 * 9 09 7F 04 \7= \dx00000000 01 +6 * 9 09 7F 04 \7= \dx00000000 01 -8 * 19 0B 03 7F 06 "1.2.0 (r22723)" 00 +7 * 19 0B 03 7F 06 "1.2.0 (r22723)" 00 -9 * 12 00 08 \b1 01 FF \wx0000 +8 * 12 00 08 \b1 01 FF \wx0000 09 "LVST" -10 * 6 01 04 \b3 FF \wx0002 +9 * 6 01 04 \b3 FF \wx0002 -11 cows_cargo.png 8bpp 10 10 64 65 -31 -34 normal -12 cows_cargo.png 8bpp 220 10 64 65 -31 -34 normal +10 cows_cargo.png 8bpp 10 10 64 65 -31 -34 normal +11 cows_cargo.png 8bpp 220 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 +12 cows_cargo.png 8bpp 80 10 64 65 -31 -34 normal +13 cows_cargo.png 8bpp 290 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 +14 cows_cargo.png 8bpp 150 10 64 65 -31 -34 normal +15 cows_cargo.png 8bpp 360 10 64 65 -31 -34 normal // Name: cow_pen_1 - feature 04 -17 * 11 02 04 FF \b2 \b1 +16 * 11 02 04 FF \b2 \b1 \w0 \w1 \w2 // Name: cow_pen_2 - feature 04 -18 * 13 02 04 FE \b3 \b1 +17 * 13 02 04 FE \b3 \b1 \w0 \w1 \w2 \w2 // Name: random_cow_pen -19 * 11 02 04 FE 80 00 \b16 02 +18 * 11 02 04 FE 80 00 \b16 02 \wx00FF // (1/2) -> (1/2): cow_pen_1; \wx00FE // (1/2) -> (1/2): cow_pen_2; -20 * 27 00 04 \b7 01 FF \wx0000 +19 * 21 00 04 \b5 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