From 8843c5ec81d746c6badb57f0af1696731d70ee60 Mon Sep 17 00:00:00 2001 From: glx22 Date: Sun, 21 Apr 2024 15:15:04 +0200 Subject: [PATCH 1/2] Add: Regression test for name callback --- regression/013_train_callback.nml | 4 + regression/expected/013_train_callback.grf | Bin 7776 -> 7856 bytes regression/expected/013_train_callback.nfo | 164 +++++++++++---------- regression/lang/english.lng | 2 + 4 files changed, 94 insertions(+), 76 deletions(-) diff --git a/regression/013_train_callback.nml b/regression/013_train_callback.nml index 32c79b0f..2286f24d 100644 --- a/regression/013_train_callback.nml +++ b/regression/013_train_callback.nml @@ -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 { @@ -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; } } diff --git a/regression/expected/013_train_callback.grf b/regression/expected/013_train_callback.grf index fbfdf1bf594863e0a64997e98e4d6fb337e1a8fb..e7c73218cc0036c7b6e43411a143f09d9e74a491 100644 GIT binary patch delta 466 zcmW-Z&r1|>7{=ds*zdSA`_o-#cXsxNvziVR9=vqQgAjIUJBWWk8%T%R_MozeNQ)w} z=%IMTgRzJN89~&the|UL(L)L=L3OA@GoKRU-1qatqImikxNOJH2R&l(QYBcV(78_#qL^^}IKj?WxG#lO!% z3~3b+l4=WI)$2IXUUL}BdRs&!+ry0C!P~$(M^Ol_awq;r`k{wjaSV;nDaTO{x3~+X z$UGZTJK_YsMB5^H<+l;;#?Q_sn^=mKL`t%c*fsLV#n;%vr}zn{QSW-m84MdUoW+i@ z%{fdb+T4wD@&ns&%tg-Qo!R0ZJWYKQz0%_lwXB0#Yg1g4TMakNEJo60(I>Yb(%;0P T8O7gpgZr_P`Ns|xvcE0?=a_>p delta 382 zcmW-bJ4nM|6ovn*{nI2i>BAH!0}QO^JUT?r_d`__+H+Zv}&~v5C==raEdtVvL2v`QsI% zc(5l?bC@x2k1X=;n`X$H3YAD#f&pVh{vvCWQRjW+!<9y?Q~;XTPdUQ;VBoVs(F`&y zOEwoGwt$La;!v6<8D{vF2c}oNsSfJ40#!aG6<6{lwO~yt@`#`{IN@FlsJo=$Rc&xx zbQidh^Z0Gqq$oBbRf=IamcyjBO>vO^NeR^T8nxmqx (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 +44 * 9 0D 7F \D& 83 FF \dx000000FF -44 * 7 06 +45 * 7 06 7F 04 FF \wx0006 FF // Name: bulk_wagon_coal_climate_switch -45 * 23 02 00 FD 89 +46 * 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 +47 * 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 +48 * 9 02 00 FD \b1 \b1 \w0 \w0 // Name: @CB_FAILED00 -48 * 23 02 00 FD 89 +49 * 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 +50 * 83 02 00 FE 89 47 00 \dx000000FF \b7 \wx8019 \dx0000002F \dx0000002F // 47 .. 47: return 25; @@ -145,7 +147,7 @@ FF \wx00FD // No default specified -> fail callback // Name: bulk_wagon_cb_weight_switch -50 * 53 02 00 FD 89 +51 * 53 02 00 FD 89 47 00 \dx000000FF \b4 \wx8012 \dx00000013 \dx00000013 // 19 .. 19: return 18; @@ -154,50 +156,58 @@ FF \wx8012 \dx0000001A \dx0000001A // 26 .. 26: return 18; \wx00FD // No default specified -> fail callback +// Name: bulk_wagon_cb_name_switch +52 * 30 02 00 FF 89 +1A 20 \dx0000D000 +\2sto 1A 00 \dx00000100 +\b1 +\wx8000 \dx00000001 \dx00000000 // Bogus range to avoid nvar == 0 +\wx8001 // default: return string(STR_JUST_STRING); + // param[125] = (param[1] * 5000) -51 * 9 0D 7D \D* 01 FF \dx00001388 +53 * 9 0D 7D \D* 01 FF \dx00001388 // param[126] = (param[125] + 698) -52 * 9 0D 7E \D+ 7D FF \dx000002BA +54 * 9 0D 7E \D+ 7D FF \dx000002BA // param[127] = (param[126] / 1397) -53 * 9 0D 7F \D/ 7E FF \dx00000575 +55 * 9 0D 7F \D/ 7E FF \dx00000575 // param[124] = (param[2] * 12500) -54 * 9 0D 7C \D* 02 FF \dx000030D4 +56 * 9 0D 7C \D* 02 FF \dx000030D4 // param[125] = (param[124] + 6286) -55 * 9 0D 7D \D+ 7C FF \dx0000188E +57 * 9 0D 7D \D+ 7C FF \dx0000188E // param[126] = (param[125] / 12573) -56 * 9 0D 7E \D/ 7D FF \dx0000311D +58 * 9 0D 7E \D/ 7D FF \dx0000311D // param[123] = (param[3] * 8) -57 * 9 0D 7B \D* 03 FF \dx00000008 +59 * 9 0D 7B \D* 03 FF \dx00000008 // param[124] = (param[123] + 2) -58 * 9 0D 7C \D+ 7B FF \dx00000002 +60 * 9 0D 7C \D+ 7B FF \dx00000002 // param[125] = (param[124] / 5) -59 * 9 0D 7D \D/ 7C FF \dx00000005 +61 * 9 0D 7D \D/ 7C FF \dx00000005 // param[122] = (param[4] * 2965) -60 * 9 0D 7A \D* 04 FF \dx00000B95 +62 * 9 0D 7A \D* 04 FF \dx00000B95 // param[123] = (param[122] + 1105) -61 * 9 0D 7B \D+ 7A FF \dx00000451 +63 * 9 0D 7B \D+ 7A FF \dx00000451 // param[124] = (param[123] / 2211) -62 * 9 0D 7C \D/ 7B FF \dx000008A3 +64 * 9 0D 7C \D/ 7B FF \dx000008A3 -63 * 22 06 +65 * 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 +66 * 22 00 00 \b5 01 FF \wx0074 09 \wx0024 09 \wx0000 09 \wx0000 @@ -205,17 +215,17 @@ FF 0B \wx0000 // param[127] = (param[1] & 255) -65 * 9 0D 7F \D& 01 FF \dx000000FF +67 * 9 0D 7F \D& 01 FF \dx000000FF // param[126] = (param[1] << -8) -66 * 9 0D 7E \D<< 01 FF \dxFFFFFFF8 +68 * 9 0D 7E \D<< 01 FF \dxFFFFFFF8 -67 * 12 06 +69 * 12 06 7F 01 FF \wx004D 7E 01 FF \wx004F FF -68 * 82 00 00 \b26 01 FF \wx0074 +70 * 82 00 00 \b26 01 FF \wx0074 06 0F 28 \wx0010 1D \dx00000000 @@ -244,13 +254,14 @@ FF 24 00 25 00 -69 * 27 04 00 7F 01 FF \wx0074 "NML Test bulk wagon" 00 +71 * 27 04 00 7F 01 FF \wx0074 "NML Test bulk wagon" 00 -70 * 9 00 00 \b1 01 FF \wx0074 +72 * 11 00 00 \b2 01 FF \wx0074 1E 08 +31 01 // Name: @action3_0 -71 * 33 02 00 FD 89 +73 * 33 02 00 FD 89 10 00 \dx000000FF \b2 \wx00FE \dx00000014 \dx00000014 // bulk_wagon_cb_capacity_switch; @@ -258,7 +269,7 @@ FF \wx00FC // bulk_wagon_graphics_switch; // Name: @action3_1 -72 * 33 02 00 FF 89 +74 * 33 02 00 FB 89 10 00 \dx000000FF \b2 \wx801E \dx00000014 \dx00000014 // return 30; @@ -266,7 +277,7 @@ FF \wx00FC // bulk_wagon_graphics_switch; // Name: @action3_2 -73 * 33 02 00 FD 89 +75 * 33 02 00 FD 89 0C 00 \dx0000FFFF \b2 \wx00FE \dx00000015 \dx00000015 // bulk_wagon_cb_capacity_switch; @@ -274,13 +285,14 @@ FF \wx00FC // bulk_wagon_graphics_switch; // Name: @action3_3 -74 * 23 02 00 FC 89 +76 * 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 +77 * 12 03 00 01 FF \wx0074 \b1 FF \wx00FC // @action3_3; \wx00FD // @action3_2; diff --git a/regression/lang/english.lng b/regression/lang/english.lng index e8f7accb..9ffc40bd 100644 --- a/regression/lang/english.lng +++ b/regression/lang/english.lng @@ -41,3 +41,5 @@ STR_COALMINE_MONTH_11 :{BLACK}diamonds STR_BREWERY_NAME :Brewery STR_032_HOUSE :Example house + +STR_JUST_STRING :{STRING} From 945227b003588d285d8cc9fda70ddb626d8f4886 Mon Sep 17 00:00:00 2001 From: glx22 Date: Sun, 21 Apr 2024 14:26:10 +0200 Subject: [PATCH 2/2] Change: Reduce D0xx usage where possible --- nml/actions/action2var.py | 9 +- regression/expected/013_train_callback.grf | Bin 7856 -> 7867 bytes regression/expected/013_train_callback.nfo | 158 +++++++++++---------- 3 files changed, 88 insertions(+), 79 deletions(-) diff --git a/nml/actions/action2var.py b/nml/actions/action2var.py index 4a95ab90..b564d82c 100644 --- a/nml/actions/action2var.py +++ b/nml/actions/action2var.py @@ -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): """ @@ -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)) @@ -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) @@ -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)) diff --git a/regression/expected/013_train_callback.grf b/regression/expected/013_train_callback.grf index e7c73218cc0036c7b6e43411a143f09d9e74a491..607c77f03a0c6da31044717490ec5618211d25a0 100644 GIT binary patch delta 398 zcmX|6JxD@f6#Z`asqdN3|L60mrTu8sRG{}L1AR2;d zXh&w?)ZUhX-EbKsuD@-Yu%L!*PMR#}&~jf^pan0h?p zN%xo=mx0xZJ*+VOAC%)G!=bUM)Iw--adsw@o|sO~XOB&kE0B|n4STICS8Q4$wal0z zeAMU_vHvQUF!VQZNq`hGl8RH~ILS~=cibYlGTvkz6`uszT%cy$n6Jr-O)1S4p_ZVV zy3r>ekqu?J%I$)?LeU&W&9X-h>^5(a69e`L64nE9fs{{jqoS0^gA3alsY1IWFBC_W zYrlElN-Lty9Qp9-oa2oz&*4zRn0M`vACmi>0;st6DTs_`nOa~~^VEu4wMrpede10~ zw6;!dsB0x^N6GidJ48kiFTp78^+Vn%&<2*ZAh!HT9ueqSZ{x7Bh{ zG_{p-UTdMH39U$RP`D@;@sPu}zJ0!*zNfLHm@35J=)i_kj>y~fLI|^w@8MlFp=-a* zEWSXdQt+_PS%#Mm*9(07 zbX~yDqI(mn!8^F9WTk-d_DaPSVXx;JLAt$Fg!ts0mBPkSU|b1t!IwdVe*dG?V6ZgL zgI#P>6VRAe*QG{-o&0+?#sVoc@hb3vW|o3^=-dcxNm0Wo{yE*6!k%yjExZj^(8|L| X1#L_=?4X? (3/4): bulk_wagon_coal_default_group; \wx00FD // (1/3) -> (1/4): bulk_wagon_coal2_group; // param[127] = (param[131] & 255) -44 * 9 0D 7F \D& 83 FF \dx000000FF +45 * 9 0D 7F \D& 83 FF \dx000000FF -45 * 7 06 +46 * 7 06 7F 04 FF \wx0006 FF // Name: bulk_wagon_coal_climate_switch -46 * 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 -47 * 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 -48 * 9 02 00 FD \b1 \b1 +49 * 9 02 00 FD \b1 \b1 \w0 \w0 // Name: @CB_FAILED00 -49 * 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 -50 * 83 02 00 FE 89 +51 * 83 02 00 FE 89 47 00 \dx000000FF \b7 \wx8019 \dx0000002F \dx0000002F // 47 .. 47: return 25; @@ -147,7 +149,7 @@ FF \wx00FD // No default specified -> fail callback // Name: bulk_wagon_cb_weight_switch -51 * 53 02 00 FD 89 +52 * 53 02 00 FD 89 47 00 \dx000000FF \b4 \wx8012 \dx00000013 \dx00000013 // 19 .. 19: return 18; @@ -157,57 +159,57 @@ FF \wx00FD // No default specified -> fail callback // Name: bulk_wagon_cb_name_switch -52 * 30 02 00 FF 89 -1A 20 \dx0000D000 +53 * 30 02 00 FF 89 +1A 20 \dx0000DC00 \2sto 1A 00 \dx00000100 \b1 \wx8000 \dx00000001 \dx00000000 // Bogus range to avoid nvar == 0 -\wx8001 // default: return string(STR_JUST_STRING); +\wx8000 // default: return string(STR_JUST_STRING); // param[125] = (param[1] * 5000) -53 * 9 0D 7D \D* 01 FF \dx00001388 +54 * 9 0D 7D \D* 01 FF \dx00001388 // param[126] = (param[125] + 698) -54 * 9 0D 7E \D+ 7D FF \dx000002BA +55 * 9 0D 7E \D+ 7D FF \dx000002BA // param[127] = (param[126] / 1397) -55 * 9 0D 7F \D/ 7E FF \dx00000575 +56 * 9 0D 7F \D/ 7E FF \dx00000575 // param[124] = (param[2] * 12500) -56 * 9 0D 7C \D* 02 FF \dx000030D4 +57 * 9 0D 7C \D* 02 FF \dx000030D4 // param[125] = (param[124] + 6286) -57 * 9 0D 7D \D+ 7C FF \dx0000188E +58 * 9 0D 7D \D+ 7C FF \dx0000188E // param[126] = (param[125] / 12573) -58 * 9 0D 7E \D/ 7D FF \dx0000311D +59 * 9 0D 7E \D/ 7D FF \dx0000311D // param[123] = (param[3] * 8) -59 * 9 0D 7B \D* 03 FF \dx00000008 +60 * 9 0D 7B \D* 03 FF \dx00000008 // param[124] = (param[123] + 2) -60 * 9 0D 7C \D+ 7B FF \dx00000002 +61 * 9 0D 7C \D+ 7B FF \dx00000002 // param[125] = (param[124] / 5) -61 * 9 0D 7D \D/ 7C FF \dx00000005 +62 * 9 0D 7D \D/ 7C FF \dx00000005 // param[122] = (param[4] * 2965) -62 * 9 0D 7A \D* 04 FF \dx00000B95 +63 * 9 0D 7A \D* 04 FF \dx00000B95 // param[123] = (param[122] + 1105) -63 * 9 0D 7B \D+ 7A FF \dx00000451 +64 * 9 0D 7B \D+ 7A FF \dx00000451 // param[124] = (param[123] / 2211) -64 * 9 0D 7C \D/ 7B FF \dx000008A3 +65 * 9 0D 7C \D/ 7B FF \dx000008A3 -65 * 22 06 +66 * 22 06 7F 02 FF \wx000B 7E 02 FF \wx000E 7D 02 FF \wx0011 7C 02 FF \wx0014 FF -66 * 22 00 00 \b5 01 FF \wx0074 +67 * 22 00 00 \b5 01 FF \wx0074 09 \wx0024 09 \wx0000 09 \wx0000 @@ -215,17 +217,17 @@ FF 0B \wx0000 // param[127] = (param[1] & 255) -67 * 9 0D 7F \D& 01 FF \dx000000FF +68 * 9 0D 7F \D& 01 FF \dx000000FF // param[126] = (param[1] << -8) -68 * 9 0D 7E \D<< 01 FF \dxFFFFFFF8 +69 * 9 0D 7E \D<< 01 FF \dxFFFFFFF8 -69 * 12 06 +70 * 12 06 7F 01 FF \wx004D 7E 01 FF \wx004F FF -70 * 82 00 00 \b26 01 FF \wx0074 +71 * 82 00 00 \b26 01 FF \wx0074 06 0F 28 \wx0010 1D \dx00000000 @@ -254,14 +256,14 @@ FF 24 00 25 00 -71 * 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 -72 * 11 00 00 \b2 01 FF \wx0074 +73 * 11 00 00 \b2 01 FF \wx0074 1E 08 31 01 // Name: @action3_0 -73 * 33 02 00 FD 89 +74 * 33 02 00 FD 89 10 00 \dx000000FF \b2 \wx00FE \dx00000014 \dx00000014 // bulk_wagon_cb_capacity_switch; @@ -269,7 +271,7 @@ FF \wx00FC // bulk_wagon_graphics_switch; // Name: @action3_1 -74 * 33 02 00 FB 89 +75 * 33 02 00 FB 89 10 00 \dx000000FF \b2 \wx801E \dx00000014 \dx00000014 // return 30; @@ -277,7 +279,7 @@ FF \wx00FC // bulk_wagon_graphics_switch; // Name: @action3_2 -75 * 33 02 00 FD 89 +76 * 33 02 00 FD 89 0C 00 \dx0000FFFF \b2 \wx00FE \dx00000015 \dx00000015 // bulk_wagon_cb_capacity_switch; @@ -285,14 +287,14 @@ FF \wx00FC // bulk_wagon_graphics_switch; // Name: @action3_3 -76 * 33 02 00 FC 89 +77 * 33 02 00 FC 89 0C 00 \dx0000FFFF \b2 \wx00FB \dx00000036 \dx00000036 // @action3_1; \wx00FF \dx00000161 \dx00000161 // bulk_wagon_cb_name_switch; \wx00FC // bulk_wagon_graphics_switch; -77 * 12 03 00 01 FF \wx0074 \b1 +78 * 12 03 00 01 FF \wx0074 \b1 FF \wx00FC // @action3_3; \wx00FD // @action3_2;