Skip to content

Commit

Permalink
Core: World: MultiWorld and another deprecated option getter (Archipe…
Browse files Browse the repository at this point in the history
…lagoMW#3254)

* world: multiworld and deprecated options getting

* Oops

* Found two more
  • Loading branch information
Exempt-Medic authored May 12, 2024
1 parent af83050 commit 701fbab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions BaseClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ def __init__(self, player: int, name: str = '', address: Optional[int] = None, p
self.parent_region = parent

def can_fill(self, state: CollectionState, item: Item, check_access=True) -> bool:
return ((self.always_allow(state, item) and item.name not in state.multiworld.non_local_items[item.player])
return ((self.always_allow(state, item) and item.name not in state.multiworld.worlds[item.player].options.non_local_items)
or ((self.progress_type != LocationProgressType.EXCLUDED or not (item.advancement or item.useful))
and self.item_rule(item)
and (not check_access or self.can_reach(state))))
Expand Down Expand Up @@ -1246,7 +1246,7 @@ def create_playthrough(self, create_paths: bool = True) -> None:
logging.debug('The following items could not be reached: %s', ['%s (Player %d) at %s (Player %d)' % (
location.item.name, location.item.player, location.name, location.player) for location in
sphere_candidates])
if any([multiworld.accessibility[location.item.player] != 'minimal' for location in sphere_candidates]):
if any([multiworld.worlds[location.item.player].options.accessibility != 'minimal' for location in sphere_candidates]):
raise RuntimeError(f'Not all progression items reachable ({sphere_candidates}). '
f'Something went terribly wrong here.')
else:
Expand Down
34 changes: 17 additions & 17 deletions worlds/generic/Rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,58 +14,58 @@
ItemRule = typing.Callable[[object], bool]


def locality_needed(world: MultiWorld) -> bool:
for player in world.player_ids:
if world.local_items[player].value:
def locality_needed(multiworld: MultiWorld) -> bool:
for player in multiworld.player_ids:
if multiworld.worlds[player].options.local_items.value:
return True
if world.non_local_items[player].value:
if multiworld.worlds[player].options.non_local_items.value:
return True

# Group
for group_id, group in world.groups.items():
if set(world.player_ids) == set(group["players"]):
for group_id, group in multiworld.groups.items():
if set(multiworld.player_ids) == set(group["players"]):
continue
if group["local_items"]:
return True
if group["non_local_items"]:
return True


def locality_rules(world: MultiWorld):
if locality_needed(world):
def locality_rules(multiworld: MultiWorld):
if locality_needed(multiworld):

forbid_data: typing.Dict[int, typing.Dict[int, typing.Set[str]]] = \
collections.defaultdict(lambda: collections.defaultdict(set))

def forbid(sender: int, receiver: int, items: typing.Set[str]):
forbid_data[sender][receiver].update(items)

for receiving_player in world.player_ids:
local_items: typing.Set[str] = world.worlds[receiving_player].options.local_items.value
for receiving_player in multiworld.player_ids:
local_items: typing.Set[str] = multiworld.worlds[receiving_player].options.local_items.value
if local_items:
for sending_player in world.player_ids:
for sending_player in multiworld.player_ids:
if receiving_player != sending_player:
forbid(sending_player, receiving_player, local_items)
non_local_items: typing.Set[str] = world.worlds[receiving_player].options.non_local_items.value
non_local_items: typing.Set[str] = multiworld.worlds[receiving_player].options.non_local_items.value
if non_local_items:
forbid(receiving_player, receiving_player, non_local_items)

# Group
for receiving_group_id, receiving_group in world.groups.items():
if set(world.player_ids) == set(receiving_group["players"]):
for receiving_group_id, receiving_group in multiworld.groups.items():
if set(multiworld.player_ids) == set(receiving_group["players"]):
continue
if receiving_group["local_items"]:
for sending_player in world.player_ids:
for sending_player in multiworld.player_ids:
if sending_player not in receiving_group["players"]:
forbid(sending_player, receiving_group_id, receiving_group["local_items"])
if receiving_group["non_local_items"]:
for sending_player in world.player_ids:
for sending_player in multiworld.player_ids:
if sending_player in receiving_group["players"]:
forbid(sending_player, receiving_group_id, receiving_group["non_local_items"])

# create fewer lambda's to save memory and cache misses
func_cache = {}
for location in world.get_locations():
for location in multiworld.get_locations():
if (location.player, location.item_rule) in func_cache:
location.item_rule = func_cache[location.player, location.item_rule]
# empty rule that just returns True, overwrite
Expand Down

0 comments on commit 701fbab

Please sign in to comment.