Skip to content

Commit

Permalink
Add: Support for station variable 6B
Browse files Browse the repository at this point in the history
  • Loading branch information
glx22 committed Mar 24, 2024
1 parent 26f271f commit 6c7c05e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
20 changes: 18 additions & 2 deletions nml/actions/action2var_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,22 @@ def platform_info_fix_var(var, info):
var.param = None
return var

def value_station_id(var, info):
# 'nearby_tile_station_id' is accessible via 2 different variables
# - var68 bits 0-7 (8 bits only)
# - var6B bits 0-15 (16 bits but OpenTTD 14+)
openttd14 = nmlop.CMP_GE(
expression.Variable(expression.ConstantNumeric(0x21)), # openttd version
expression.ConstantNumeric(0x1E000000) # version_openttd(14, 0)
)
var68 = expression.Variable(
expression.ConstantNumeric(0x68),
expression.ConstantNumeric(0),
expression.ConstantNumeric(0xFF),
var.param
)
return expression.TernaryOp(openttd14, var, var68, var.pos)

varact2vars60x_stations = {
**varact2vars60x_base_stations,
'nearby_tile_animation_frame' : {'var': 0x66, 'start': 0, 'size': 32, 'param_function': signed_tile_offset},
Expand All @@ -352,14 +368,14 @@ def platform_info_fix_var(var, info):
'nearby_tile_height' : {'var': 0x67, 'start': 16, 'size': 8, 'param_function': signed_tile_offset},
'nearby_tile_class' : {'var': 0x67, 'start': 24, 'size': 4, 'param_function': signed_tile_offset},
'nearby_tile_is_station' : {'var': 0x68, 'start': 0, 'size': 32, 'param_function': signed_tile_offset, 'value_function': lambda var, info: nmlop.CMP_NEQ(var, 0xFFFFFFFF)},
'nearby_tile_station_id' : {'var': 0x68, 'start': 0, 'size': 8, 'param_function': signed_tile_offset},
'nearby_tile_same_grf' : {'var': 0x68, 'start': 8, 'size': 2, 'param_function': signed_tile_offset, 'value_function': value_equals(0)},
'nearby_tile_other_grf' : {'var': 0x68, 'start': 8, 'size': 2, 'param_function': signed_tile_offset, 'value_function': value_equals(1)},
'nearby_tile_original_gfx' : {'var': 0x68, 'start': 8, 'size': 2, 'param_function': signed_tile_offset, 'value_function': value_equals(2)},
'nearby_tile_same_station' : {'var': 0x68, 'start': 10, 'size': 1, 'param_function': signed_tile_offset},
'nearby_tile_perpendicular' : {'var': 0x68, 'start': 11, 'size': 1, 'param_function': signed_tile_offset},
'nearby_tile_tile_type' : {'var': 0x68, 'start': 11, 'size': 3, 'param_function': signed_tile_offset},
'nearby_tile_grfid' : {'var': 0x6A, 'start': 0, 'size': 32, 'param_function': signed_tile_offset},
'nearby_tile_station_id' : {'var': 0x6B, 'start': 0, 'size': 16, 'param_function': signed_tile_offset, 'value_function': value_station_id},
# 'var' will be set in the value_function, depending on parameter
'platform_length' : {'var': 0x00, 'start': 16, 'size': 4, 'param_function': platform_info_param, 'value_function': platform_info_fix_var},
'platform_count' : {'var': 0x00, 'start': 20, 'size': 4, 'param_function': platform_info_param, 'value_function': platform_info_fix_var},
Expand Down Expand Up @@ -824,7 +840,6 @@ def industry_cargotype(name, args, pos, info):
'nearby_tile_class' : {'var': 0x67, 'start': 24, 'size': 4, 'param_function': signed_tile_offset},
'nearby_tile_road_stop_info' : {'var': 0x68, 'start': 0, 'size': 32, 'param_function': signed_tile_offset},
'nearby_tile_is_road_stop' : {'var': 0x68, 'start': 0, 'size': 32, 'param_function': signed_tile_offset, 'value_function': lambda var, info: nmlop.CMP_NEQ(var, 0xFFFFFFFF)},
'nearby_tile_road_stop_id' : {'var': 0x68, 'start': 0, 'size': 8, 'param_function': signed_tile_offset},
'nearby_tile_same_grf' : {'var': 0x68, 'start': 8, 'size': 2, 'param_function': signed_tile_offset, 'value_function': value_equals(0)},
'nearby_tile_other_grf' : {'var': 0x68, 'start': 8, 'size': 2, 'param_function': signed_tile_offset, 'value_function': value_equals(1)},
'nearby_tile_original_gfx' : {'var': 0x68, 'start': 8, 'size': 2, 'param_function': signed_tile_offset, 'value_function': value_equals(2)},
Expand All @@ -835,6 +850,7 @@ def industry_cargotype(name, args, pos, info):
'nearby_tile_stop_type' : {'var': 0x68, 'start': 16, 'size': 4, 'param_function': signed_tile_offset},
'nearby_tile_same_stop_type' : {'var': 0x68, 'start': 20, 'size': 1, 'param_function': signed_tile_offset},
'nearby_tile_grfid' : {'var': 0x6A, 'start': 0, 'size': 32, 'param_function': signed_tile_offset},
'nearby_tile_road_stop_id' : {'var': 0x6B, 'start': 0, 'size': 16, 'param_function': signed_tile_offset},
}

class VarAct2Scope:
Expand Down
2 changes: 1 addition & 1 deletion regression/040_station.nml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ item (FEAT_STATIONS, basic_station, 255) {
}
graphics {
foundations: 0;
prepare_layout: [STORE_TEMP(0,0), STORE_TEMP(1,1)];
prepare_layout: [STORE_TEMP(0,nearby_tile_station_id(-1,2)), STORE_TEMP(1,1)];
purchase_prepare_layout: STORE_TEMP(3,3);
sprite_layouts: [
station_sprite_layout_0,
Expand Down
Binary file modified regression/expected/040_station.grf
Binary file not shown.
19 changes: 16 additions & 3 deletions regression/expected/040_station.nfo
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,22 @@
\wx8000 // Return computed value

// Name: Station Layout@prepare - Id FF
17 * 34 02 04 FC 89
1A 20 \dx00000000
\2sto 1A 20 \dx00000000
17 * 131 02 04 FC 89
21 20 \dxFFFFFFFF
\2cmp 1A 20 \dx1E000000
\2< 1A 20 \dx00000001
\2sto 1A 20 \dx00000080 // guard
\2^ 1A 20 \dx00000001
\2sto 1A 20 \dx00000081 // !guard
\2r 7D 81 20 \dxFFFFFFFF
\2* 68 2F 20 \dx000000FF
\2sto 1A 20 \dx00000082
\2r 7D 80 20 \dxFFFFFFFF
\2* 6B 2F 20 \dx0000FFFF
\2+ 7D 82 20 \dxFFFFFFFF
\2sto 1A 20 \dx00000083
\2r 1A 20 \dx00000000
\2sto 7D 83 20 \dxFFFFFFFF
\2r 1A 20 \dx00000001
\2sto 1A 00 \dx00000001
\b0
Expand Down

0 comments on commit 6c7c05e

Please sign in to comment.