Skip to content

Commit

Permalink
Small things
Browse files Browse the repository at this point in the history
  • Loading branch information
Exempt-Medic committed Jan 6, 2025
1 parent 12191f2 commit ff8b799
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
6 changes: 3 additions & 3 deletions BaseClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,14 +1267,14 @@ def __init__(self, player: int, name: str = '', address: Optional[int] = None, p
self.address = address
self.parent_region = parent

def can_fill(self, state: CollectionState, item: Item, check_access=True) -> bool:
def can_fill(self, state: CollectionState, item: Item, check_access: bool = True) -> bool:
if self.always_allow(state, item):
options = state.multiworld.worlds[self.player].options
options = state.multiworld.worlds[item.player].options
if item.name not in options.non_local_items and self.name not in options.non_local_locations:
return True

return (
(self.progress_type != LocationProgressType.EXCLUDED or not (item.advancement or item.useful))
(self.progress_type != LocationProgressType.EXCLUDED or item.excludable)
and self.item_rule(item)
and (not check_access or self.can_reach(state))
)
Expand Down
8 changes: 4 additions & 4 deletions test/general/test_fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,8 @@ def test_local_locations(self):
world.location_name_to_id[location.name] = id
world.location_id_to_name[id] = location.name

multiworld.local_locations[player1.id].value = set(names(player1.locations))
multiworld.local_locations[player2.id].value = set(names(player2.locations))
multiworld.worlds[player1.id].options.local_locations.value = set(names(player1.locations))
multiworld.worlds[player2.id].options.local_locations.value = set(names(player2.locations))
locality_rules(multiworld)

distribute_items_restrictive(multiworld)
Expand All @@ -740,8 +740,8 @@ def test_non_local_locations(self):
world.location_name_to_id[location.name] = id
world.location_id_to_name[id] = location.name

multiworld.non_local_locations[player1.id].value = set(names(player1.locations))
multiworld.non_local_locations[player2.id].value = set(names(player2.locations))
multiworld.worlds[player1.id].options.non_local_locations.value = set(names(player1.locations))
multiworld.worlds[player2.id].options.non_local_locations.value = set(names(player2.locations))
locality_rules(multiworld)

distribute_items_restrictive(multiworld)
Expand Down
23 changes: 14 additions & 9 deletions worlds/generic/Rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def item_locality_needed(multiworld: MultiWorld) -> bool:
return True
if group["non_local_items"]:
return True
return False


def location_locality_needed(multiworld: MultiWorld) -> bool:
Expand All @@ -38,6 +39,7 @@ def location_locality_needed(multiworld: MultiWorld) -> bool:
return True
if multiworld.worlds[player].options.non_local_locations.value:
return True
return False


def locality_rules(multiworld: MultiWorld):
Expand Down Expand Up @@ -98,43 +100,46 @@ def forbid(sender: int, receiver: int, items: typing.Set[str]):
local_func_cache = {}
for loc_name in world.options.local_locations.value:
location = world.get_location_if_available(loc_name)
if not location: continue
if not location:
continue

if location.item_rule in local_func_cache:
location.item_rule = local_func_cache[location.item_rule]
# empty rule that just returns True, overwrite
elif location.item_rule is location.__class__.item_rule:
local_func_cache[location.item_rule] = location.item_rule = \
lambda i, player = player: i.player == player
lambda i, p = player: i.player == p
# special rule, needs to also be fulfilled.
else:
local_func_cache[location.item_rule] = location.item_rule = \
lambda i, player = player, old_rule = location.item_rule: \
i.player == player and old_rule(i)
lambda i, p = player, old_rule = location.item_rule: \
i.player == p and old_rule(i)

non_local_func_cache = {}
for loc_name in world.options.non_local_locations.value:
location = world.get_location_if_available(loc_name)
if not location: continue
if not location:
continue

location = world.get_location(loc_name)
if location.item_rule in non_local_func_cache:
location.item_rule = non_local_func_cache[location.item_rule]
# empty rule that just returns True, overwrite
elif location.item_rule is location.__class__.item_rule:
non_local_func_cache[location.item_rule] = location.item_rule = \
lambda i, player = player: i.player != player
lambda i, p = player: i.player != p
# special rule, needs to also be fulfilled.
else:
non_local_func_cache[location.item_rule] = location.item_rule = \
lambda i, player = player, old_rule = location.item_rule: \
i.player != player and old_rule(i)
lambda i, p = player, old_rule = location.item_rule: \
i.player != p and old_rule(i)


def exclusion_rules(multiworld: MultiWorld, player: int, exclude_locations: typing.Set[str]) -> None:
for loc_name in exclude_locations:
location = multiworld.get_location_if_available(loc_name, player)
if not location: continue
if not location:
continue

if not location.advancement:
location.progress_type = LocationProgressType.EXCLUDED
Expand Down

0 comments on commit ff8b799

Please sign in to comment.