Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: World: MultiWorld and another deprecated option getter #3254

Merged
merged 4 commits into from
May 12, 2024
Merged
Changes from 3 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
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
Loading