22#
33# This script checks all the RUL0 files for errors such as sinkhole bugs..
44# If any are found, they are printed to stdout and the script exits with a non-zero return code.
5+ #
6+ # Minimum requirement: Python 3.12+
7+ # Further info: https://www.wiki.sc4devotion.com/index.php?title=RUL0
58
69import sys
710import os
@@ -21,9 +24,13 @@ def drop_comments(lines):
2124
2225# create mapping of (x,y)-cell to char
2326def parse_layout (lines ):
24- layout = [line [(line .index ("=" )+ 1 ):].strip () for line in drop_comments (lines )]
25- origin_x = ([l .index ("^" ) for l in layout if "^" in l ] or [0 ])[0 ]
26- origin_y = ([i for i , l in enumerate (layout ) if "<" in l ] or [0 ])[0 ]
27+ layout = [line [(line .index ("=" )+ 1 ):].strip () for line in drop_comments (l for _ , l in lines )]
28+ markers_x = [line .index ("^" ) for line in layout if "^" in line ]
29+ markers_y = [i for i , line in enumerate (layout ) if "<" in line ]
30+ if len (markers_x ) != 1 or len (markers_y ) != 1 :
31+ raise Exception (f"Missing or incorrect origin markers '^'/'<' in layout starting at line { lines [0 ][0 ]} " )
32+ origin_x = markers_x [0 ]
33+ origin_y = markers_y [0 ]
2734 cells = {(j - origin_x , i - origin_y ): char
2835 for i , row in enumerate (layout )
2936 for j , char in enumerate (row )
@@ -33,13 +40,13 @@ def parse_layout(lines):
3340
3441
3542def check_cons_layout (cell_lines , cons_lines ):
36- cell_layout = parse_layout (l for _ , l in cell_lines )
37- cons_layout = parse_layout (l for _ , l in cons_lines )
43+ cell_layout = parse_layout (cell_lines )
44+ cons_layout = parse_layout (cons_lines )
3845 bad_cells = [xy for xy in cons_layout .keys () if xy not in cell_layout ]
3946 if bad_cells :
4047 cell_layout_str = "" .join (f" { line_no } : { line } " for line_no , line in cell_lines )
4148 cons_layout_str = "" .join (f" { line_no } : { line } " for line_no , line in cons_lines )
42- raise Exception (f"Potential sinkhole bug in ConsLayout at cells { " " .join (map (str , bad_cells ))} :\n { cell_layout_str } ---\n { cons_layout_str } " )
49+ raise Exception (f"Potential sinkhole bug in ConsLayout at cells { ' ' .join (map (str , bad_cells ))} :\n { cell_layout_str } ---\n { cons_layout_str } " )
4350
4451
4552def scan_rul0_file (lines ):
0 commit comments