Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions nml/actions/action2.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,16 @@ def __init__(self, feature, name, pos):
self.tmp_locations = list(range(0x80, 0x80 + total_tmp_locations))

def prepare_output(self, sprite_num):
assert self.num_refs != 0, "Action 2 is not referenced"
free_references(self)

global spritegroup_stats

try:
if self.num_refs == 0:
self.id = free_action2_ids[0]
else:
self.id = free_action2_ids.pop()
num_used = total_action2_ids - len(free_action2_ids)
if num_used > spritegroup_stats[0]:
spritegroup_stats = (num_used, self.pos)
self.id = free_action2_ids.pop()
num_used = total_action2_ids - len(free_action2_ids)
if num_used > spritegroup_stats[0]:
spritegroup_stats = (num_used, self.pos)
except IndexError:
raise generic.ScriptError(
"Unable to allocate ID for [random]switch, sprite set/layout/group or produce-block."
Expand Down
22 changes: 10 additions & 12 deletions nml/actions/action3.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ def parse_graphics_block_single_id(
prepare_layout = None
purchase_prepare_layout = None
foundations = None
need_purchase = False

for graphics in graphics_block.graphics_list:
cargo_id = graphics.cargo_id
Expand All @@ -332,6 +333,9 @@ def parse_graphics_block_single_id(
if house_tile is not None and "tiles" in info and house_tile not in info["tiles"]:
continue

if "purchase" in info and info["purchase"] == 2:
need_purchase = True

if info["type"] == "cargo":
# Not a callback, but an alias for a certain cargo type
if info["num"] in cargo_gfx:
Expand Down Expand Up @@ -409,13 +413,12 @@ def parse_graphics_block_single_id(
raise generic.ScriptError("Default graphics are defined twice.", graphics_block.default_graphics.pos)
cargo_gfx[None] = graphics_block.default_graphics.value

if layouts or foundations:
if None not in cargo_gfx:
cargo_gfx[None] = expression.SpriteGroupRef(expression.Identifier("CB_FAILED", None), [], None)

if purchase_prepare_layout and 0xFF not in cargo_gfx:
cargo_gfx[0xFF] = cargo_gfx[None]
if "default" in action3_callbacks.callbacks[feature] and None not in cargo_gfx:
cargo_gfx[None] = expression.SpriteGroupRef(expression.Identifier("CB_FAILED", None), [], None)
if need_purchase and 0xFF not in cargo_gfx:
cargo_gfx[0xFF] = cargo_gfx[None]

if layouts or foundations:
var10map, registers_ref = layouts or (None, None)

for cargo in sorted(cargo_gfx, key=lambda x: -1 if x is None else x):
Expand Down Expand Up @@ -465,8 +468,6 @@ def parse_graphics_block_single_id(
if len(callbacks) != 0 or feature == 0x07:
cb_flags = 0
# Determine the default value
if None not in cargo_gfx:
cargo_gfx[None] = expression.SpriteGroupRef(expression.Identifier("CB_FAILED", None), [], None)
default_val = cargo_gfx[None]

cb_mapping = {}
Expand All @@ -490,15 +491,12 @@ def parse_graphics_block_single_id(
if isinstance(purchase, str):
# Not in purchase list, if separate purchase CB is set
purchase = 0 if purchase in seen_callbacks else 1
# Explicit purchase CBs will need a purchase cargo, even if not needed for graphics
if purchase == 2 and 0xFF not in cargo_gfx:
cargo_gfx[0xFF] = default_val

num = cb_info["num"]
if num == 0x36:
if purchase != 2:
cb36_mapping[cb_info["var10"]] = mapping_val
if purchase != 0:
if purchase != 0 and 0xFF in cargo_gfx:
cb36_buy_mapping[cb_info["var10"]] = mapping_val
elif feature == 0x0A and num == 0x00:
# Industry production CB
Expand Down
Binary file modified regression/expected/example_road_vehicle.grf
Binary file not shown.
Loading
Loading