(I could only figure this out because I programmed in NFO first and learnt that expressions can be chained. The NML documentation could need some better examples.)
I also want to raise the question if there’s an easier way to do that.
Code: Select all
switch( FEAT_OBJECTS, SELF, switch_AnhalterSW_sections, [ // the array bracket contains a chain of expressions
// First I check if the 6 neighbor tiles in Y directions have the same object (id 0x09).
// Every tile gets one bit in the result value (by using the bitmask)
// (For example: "001011" if the next two and the fourth neighbor are the same object.)
STORE_TEMP(
((nearby_tile_object_type(0, 1) == 0x09)? bitmask(0):0) // summing the results of
+ ((nearby_tile_object_type(0, 2) == 0x09)? bitmask(1):0) // multiple "?: if expressions"
+ ((nearby_tile_object_type(0, 3) == 0x09)? bitmask(2):0) // to one value
+ ((nearby_tile_object_type(0, 4) == 0x09)? bitmask(3):0)
+ ((nearby_tile_object_type(0, 5) == 0x09)? bitmask(4):0)
+ ((nearby_tile_object_type(0, 6) == 0x09)? bitmask(5):0), 0 ), //and saving it to temp var 0
// Taking temp var 0 and checking:
// if exact the next 1 or 3 or 5 neighbors are the same object (id 0x09)
// then save "2" (= section 2) to var 1, else 0
STORE_TEMP(
(getbits(LOAD_TEMP(0), 0, 2) == bitmask( 0 ) // the 2 first bits of temp var 0: check, if only the first one is set
|| getbits(LOAD_TEMP(0), 0, 4) == bitmask( 0,1,2 ) // OR the 4 first bits ... OR the 6 first bits ...
|| getbits(LOAD_TEMP(0), 0, 6) == bitmask( 0,1,2,3,4 ))? 2 : 0, 1 ),
// if exact the next 2 or 4 or 6 neighbors are the same object (id 0x09)
// then save "3" (= section 3) to var 1, else take var 1’s former value by loading it
STORE_TEMP(
(getbits(LOAD_TEMP(0), 0, 3) == bitmask( 0,1 )
|| getbits(LOAD_TEMP(0), 0, 5) == bitmask( 0,1,2,3 )
|| getbits(LOAD_TEMP(0), 0, 7) == bitmask( 0,1,2,3,4,5 ))? 3 : LOAD_TEMP(1), 1 ),
// if the next neighbor is, but the other side isn’t the same object (id 0x09)
// then save "4" to var 1, else keep var 1’s value by loading it
STORE_TEMP(
(nearby_tile_object_type(0, -1) != 0x09
&& nearby_tile_object_type(0, 1) == 0x09)? 4 : LOAD_TEMP(1), 1 ),
// load the now calculated value of temp var 1 and finish the expression block [].
// (The last value will be evaluated by the switch, like if you use the result of a function call)
LOAD_TEMP(1)
] ){
4: sprtLyt_Anhalter_facingSW_sec4;
3: sprtLyt_Anhalter_facingSW_sec3;
2: sprtLyt_Anhalter_facingSW_sec2;
sprtLyt_Anhalter_facingSW_sec1; // default: section 1
}
But again: Is there an easier way to check multiple tiles?