Skip to content

Commit d1b5e9b

Browse files
authored
Add: Support for station property 1E (#333)
1 parent 3739dd4 commit d1b5e9b

File tree

8 files changed

+80
-22
lines changed

8 files changed

+80
-22
lines changed

examples/station/example_station.nml

+5-3
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,14 @@ item(FEAT_STATIONS, cow_pen) {
109109
/* Name of this particular station */
110110
name: string(STR_NAME_STATION);
111111
cargo_threshold: 160;
112-
draw_pylon_tiles: 0;
113-
hide_wire_tiles: 0xFF;
114-
non_traversable_tiles: 0xFF;
112+
tile_flags: [
113+
bitmask(STAT_TILE_NOWIRE, STAT_TILE_BLOCKED),
114+
bitmask(STAT_TILE_NOWIRE, STAT_TILE_BLOCKED)
115+
];
115116
}
116117
graphics {
117118
sprite_layouts: [cow_pen_X(0), cow_pen_Y(0)];
119+
select_tile_type: 0;
118120
purchase: cow_pen_half;
119121
LVST: random_cow_pen;
120122
cow_pen_empty;

nml/actions/action0properties.py

+41-12
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import itertools
1717

18-
from nml import generic, nmlop
18+
from nml import generic, nmlop, global_constants
1919
from nml.expression import (
2020
AcceptCargo,
2121
Array,
@@ -305,17 +305,22 @@ class VariableListProp(BaseAction0Property):
305305
Property value that is a variable-length list of variable sized values, the list length is written before the data.
306306
"""
307307

308-
def __init__(self, prop_num, data, size):
308+
def __init__(self, prop_num, data, size, extended):
309309
# data is a list, each element belongs to an item ID
310310
# Each element in the list is a list of cargo types
311311
self.prop_num = prop_num
312312
self.data = data
313313
self.size = size
314+
self.extended = extended
314315

315316
def write(self, file):
316317
file.print_bytex(self.prop_num)
317318
for elem in self.data:
318-
file.print_byte(len(elem))
319+
if self.extended:
320+
file.print_bytex(0xFF)
321+
file.print_word(len(elem))
322+
else:
323+
file.print_byte(len(elem))
319324
for i, val in enumerate(elem):
320325
if i % 8 == 0:
321326
file.newline()
@@ -325,13 +330,13 @@ def write(self, file):
325330
def get_size(self):
326331
total_len = 1 # Prop number
327332
for elem in self.data:
328-
# For each item ID to set, make space for all values + 1 for the length
329-
total_len += len(elem) * self.size + 1
333+
# For each item ID to set, make space for all values + 3 or 1 for the length
334+
total_len += len(elem) * self.size + (3 if self.extended else 1)
330335
return total_len
331336

332337

333-
def VariableByteListProp(prop_num, data):
334-
return VariableListProp(prop_num, data, 1)
338+
def VariableByteListProp(prop_num, data, extended=False):
339+
return VariableListProp(prop_num, data, 1, extended)
335340

336341

337342
def ctt_list(prop_num, *values):
@@ -348,8 +353,8 @@ def ctt_list(prop_num, *values):
348353
]
349354

350355

351-
def VariableWordListProp(num_prop, data):
352-
return VariableListProp(num_prop, data, 2)
356+
def VariableWordListProp(num_prop, data, extended=False):
357+
return VariableListProp(num_prop, data, 2, extended)
353358

354359

355360
def accepted_cargos(prop_num, *values):
@@ -707,6 +712,29 @@ def cargo_bitmask(value):
707712
return BitMask(value.values, value.pos).reduce()
708713

709714

715+
def station_tile_flags(value):
716+
if not isinstance(value, Array) or len(value.values) % 2 != 0:
717+
raise generic.ScriptError("Flag list must be an array of even length", value.pos)
718+
if len(value.values) > 8:
719+
return [VariableByteListProp(0x1E, [[flags.reduce_constant().value for flags in value.values]], True)]
720+
pylons = 0
721+
wires = 0
722+
blocked = 0
723+
for i, val in enumerate(value.values):
724+
flag = val.value
725+
if flag & 1 << global_constants.constant_numbers["STAT_TILE_PYLON"]:
726+
pylons = pylons | 1 << i
727+
if flag & 1 << global_constants.constant_numbers["STAT_TILE_NOWIRE"]:
728+
wires = wires | 1 << i
729+
if flag & 1 << global_constants.constant_numbers["STAT_TILE_BLOCKED"]:
730+
blocked = blocked | 1 << i
731+
return [
732+
Action0Property(0x11, ConstantNumeric(pylons), 1),
733+
Action0Property(0x14, ConstantNumeric(wires), 1),
734+
Action0Property(0x15, ConstantNumeric(blocked), 1),
735+
]
736+
737+
710738
# fmt: off
711739
properties[0x04] = {
712740
"class": {"size": 4, "num": 0x08, "first": None, "string_literal": 4},
@@ -718,11 +746,11 @@ def cargo_bitmask(value):
718746
# 0E (station layout) callback 24 should be enough
719747
# 0F (copy station layout)
720748
"cargo_threshold": {"size": 2, "num": 0x10},
721-
"draw_pylon_tiles": {"size": 1, "num": 0x11},
749+
"draw_pylon_tiles": {"size": 1, "num": 0x11, "replaced_by": "tile_flags"},
722750
"cargo_random_triggers": {"size": 4, "num": 0x12, "value_function": cargo_bitmask},
723751
"general_flags": {"size": 1, "num": 0x13, "value_function": station_flags},
724-
"hide_wire_tiles": {"size": 1, "num": 0x14},
725-
"non_traversable_tiles": {"size": 1, "num": 0x15},
752+
"hide_wire_tiles": {"size": 1, "num": 0x14, "replaced_by": "tile_flags"},
753+
"non_traversable_tiles": {"size": 1, "num": 0x15, "replaced_by": "tile_flags"},
726754
"animation_info": {"size": 2, "num": 0x16, "value_function": animation_info},
727755
"animation_speed": {"size": 1, "num": 0x17},
728756
"animation_triggers": {"size": 2, "num": 0x18},
@@ -731,6 +759,7 @@ def cargo_bitmask(value):
731759
# 1B (minimum bridge height) JGR only
732760
"name": {"size": 2, "num": (256, -1, 0x1C), "string": (256, 0xC5, 0xDC), "required": True},
733761
"classname": {"size": 2, "num": (256, -1, 0x1D), "string": (256, 0xC4, 0xDC)},
762+
"tile_flags": {"custom_function": station_tile_flags},
734763
}
735764
# fmt: on
736765

nml/global_constants.py

+5
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,11 @@ def constant_number(name, info, pos):
375375
"STAT_FLAG_CUSTOM_FOUNDATIONS" : 3,
376376
"STAT_FLAG_EXTENDED_FOUNDATIONS" : 4,
377377

378+
# station tile flags
379+
"STAT_TILE_PYLON" : 0,
380+
"STAT_TILE_NOWIRE" : 1,
381+
"STAT_TILE_BLOCKED" : 2,
382+
378383
# station tiles
379384
"STAT_ALL_TILES" : 0xFF,
380385

regression/040_station.nml

+12-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,18 @@ item (FEAT_STATIONS, basic_station, 255) {
111111
general_flags: bitmask(STAT_FLAG_EXTENDED_FOUNDATIONS);
112112
cargo_random_triggers: [LVST];
113113
disabled_platforms: bitmask(5, 6, 7, 8);
114-
114+
tile_flags: [
115+
0,
116+
bitmask(STAT_TILE_PYLON),
117+
bitmask(STAT_TILE_NOWIRE),
118+
bitmask(STAT_TILE_PYLON, STAT_TILE_NOWIRE),
119+
bitmask(STAT_TILE_BLOCKED),
120+
bitmask(STAT_TILE_PYLON, STAT_TILE_BLOCKED),
121+
bitmask(STAT_TILE_NOWIRE, STAT_TILE_BLOCKED),
122+
bitmask(STAT_TILE_PYLON, STAT_TILE_NOWIRE, STAT_TILE_BLOCKED),
123+
bitmask(STAT_TILE_NOWIRE),
124+
bitmask(STAT_TILE_PYLON, STAT_TILE_BLOCKED),
125+
];
115126
}
116127
graphics {
117128
foundations: 0;

regression/expected/040_station.grf

14 Bytes
Binary file not shown.

regression/expected/040_station.nfo

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121
4 * 16 00 08 \b1 02 FF \wx0000
2222
09 "COAL" "LVST"
2323

24-
5 * 21 00 04 \b4 01 FF \wx00FF
24+
5 * 35 00 04 \b5 01 FF \wx00FF
2525
08 "TEST"
2626
13 18
2727
12 \dx00000002
2828
0C F0
29+
1E FF \w10
30+
00 01 02 03 04 05 06 07
31+
02 05
2932

3033
6 * 11 04 04 FF 01 \wxC4FF "Test" 00
3134

38 Bytes
Binary file not shown.

regression/expected/example_station.nfo

+13-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Escapes: D= = DR D+ = DF D- = DC Du* = DM D* = DnF Du<< = DnC D<< = DO D& D| Du/ D/ Du% D%
66
// Format: spritenum imagefile depth xpos ypos xsize ysize xrel yrel zoom flags
77

8-
0 * 4 \d29
8+
0 * 4 \d30
99

1010
1 * 54 14 "C" "INFO"
1111
"B" "VRSN" \w4 \dx00000001
@@ -62,8 +62,8 @@
6262
08 "NML_"
6363
10 \wx00A0
6464
11 00
65-
14 FF
66-
15 FF
65+
14 03
66+
15 03
6767

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

@@ -131,8 +131,16 @@
131131
\wx00FF \dx00000000 \dx00000000 // cow_pen_half;
132132
\wx00FF // cow_pen_half;
133133

134-
29 * 13 03 04 01 00 \b2
134+
// Name: @action3_3
135+
29 * 33 02 04 FF 89
136+
0C 00 \dx0000FFFF
137+
\b2
138+
\wx00FF \dx00000000 \dx00000000 // @action3_2;
139+
\wx8000 \dx00000024 \dx00000024 // return 0;
140+
\wx00FD // @action3_0;
141+
142+
30 * 13 03 04 01 00 \b2
135143
00 \wx00FE // @action3_1;
136-
FF \wx00FF // @action3_2;
144+
FF \wx00FF // @action3_3;
137145
\wx00FD // @action3_0;
138146

0 commit comments

Comments
 (0)