15
15
16
16
import itertools
17
17
18
- from nml import generic , nmlop
18
+ from nml import generic , nmlop , global_constants
19
19
from nml .expression import (
20
20
AcceptCargo ,
21
21
Array ,
@@ -305,17 +305,22 @@ class VariableListProp(BaseAction0Property):
305
305
Property value that is a variable-length list of variable sized values, the list length is written before the data.
306
306
"""
307
307
308
- def __init__ (self , prop_num , data , size ):
308
+ def __init__ (self , prop_num , data , size , extended ):
309
309
# data is a list, each element belongs to an item ID
310
310
# Each element in the list is a list of cargo types
311
311
self .prop_num = prop_num
312
312
self .data = data
313
313
self .size = size
314
+ self .extended = extended
314
315
315
316
def write (self , file ):
316
317
file .print_bytex (self .prop_num )
317
318
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 ))
319
324
for i , val in enumerate (elem ):
320
325
if i % 8 == 0 :
321
326
file .newline ()
@@ -325,13 +330,13 @@ def write(self, file):
325
330
def get_size (self ):
326
331
total_len = 1 # Prop number
327
332
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 )
330
335
return total_len
331
336
332
337
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 )
335
340
336
341
337
342
def ctt_list (prop_num , * values ):
@@ -348,8 +353,8 @@ def ctt_list(prop_num, *values):
348
353
]
349
354
350
355
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 )
353
358
354
359
355
360
def accepted_cargos (prop_num , * values ):
@@ -707,6 +712,29 @@ def cargo_bitmask(value):
707
712
return BitMask (value .values , value .pos ).reduce ()
708
713
709
714
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
+
710
738
# fmt: off
711
739
properties [0x04 ] = {
712
740
"class" : {"size" : 4 , "num" : 0x08 , "first" : None , "string_literal" : 4 },
@@ -718,11 +746,11 @@ def cargo_bitmask(value):
718
746
# 0E (station layout) callback 24 should be enough
719
747
# 0F (copy station layout)
720
748
"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" },
722
750
"cargo_random_triggers" : {"size" : 4 , "num" : 0x12 , "value_function" : cargo_bitmask },
723
751
"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" },
726
754
"animation_info" : {"size" : 2 , "num" : 0x16 , "value_function" : animation_info },
727
755
"animation_speed" : {"size" : 1 , "num" : 0x17 },
728
756
"animation_triggers" : {"size" : 2 , "num" : 0x18 },
@@ -731,6 +759,7 @@ def cargo_bitmask(value):
731
759
# 1B (minimum bridge height) JGR only
732
760
"name" : {"size" : 2 , "num" : (256 , - 1 , 0x1C ), "string" : (256 , 0xC5 , 0xDC ), "required" : True },
733
761
"classname" : {"size" : 2 , "num" : (256 , - 1 , 0x1D ), "string" : (256 , 0xC4 , 0xDC )},
762
+ "tile_flags" : {"custom_function" : station_tile_flags },
734
763
}
735
764
# fmt: on
736
765
0 commit comments