-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock.py
More file actions
52 lines (41 loc) · 1.94 KB
/
Copy pathblock.py
File metadata and controls
52 lines (41 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import numpy as np
from typing import Literal
from ..generic.external import landscapes
from ..generic.minus_one import get_minus_one
# lm_b = {lmwb, lmbb}
def data_to_lm_b(data_object, *, block_type: Literal["Walk", "Build"] = "Walk"):
lm_b = np.zeros(shape=data_object.lsiz.shape_micro, dtype=np.uint8)
block_typ_name = f"Logic{block_type}BlockArea"
micro_width = 2 * data_object.lsiz.width
micro_height = 2 * data_object.lsiz.height
no_landscape = get_minus_one(data_object.emla.dtype)
for y in range(micro_height):
for x in range(micro_width):
landscape_id = data_object.emla[y, x]
if landscape_id == no_landscape:
continue
landscape = landscapes[data_object.eald[landscape_id]]
landscape_valency = data_object.lmlv[y, x]
for valency, x_offset, y_offset, indent in landscape.get(block_typ_name, []):
if landscape_valency < valency:
continue
for x_iter in range(indent):
y_real = y + y_offset
x_real = x + x_offset + x_iter + int((y % 2 != 0) and (y_real % 2 == 0))
if 0 <= x_real < micro_width and 0 <= y_real < micro_height:
lm_b[y_real, x_real] = 1
return lm_b
def update_lm_b(data_object):
data_object.lmwb = data_to_lm_b(data_object, block_type="Walk")
data_object.lmbb = data_to_lm_b(data_object, block_type="Build")
return data_object
def data_to_lmsb(data_object):
lmsb = np.zeros(shape=data_object.lsiz.shape_micro, dtype=np.uint8)
for walkable_terrain_type in data_object.lasw.__class__.walkable_terrain_types: # noqa
for walk_sector in getattr(data_object.lasw, walkable_terrain_type):
for point in walk_sector.points:
lmsb[*point[::-1]] = 1
return lmsb
def update_lmsb(data_object):
data_object.lmsb = data_to_lmsb(data_object)
return data_object