From ae32315bf735024cf57b87ccfe535f36876ffe89 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Mon, 12 Jul 2021 15:11:48 +0200 Subject: [PATCH] add World.location_names --- Main.py | 47 ++++++++++++++++++------------------ worlds/AutoWorld.py | 3 ++- worlds/alttp/ItemPool.py | 2 +- worlds/alttp/Regions.py | 2 +- worlds/alttp/Rom.py | 2 +- worlds/alttp/Shops.py | 4 +-- worlds/alttp/SubClasses.py | 32 ++++++++++++++++++++++++ worlds/alttp/__init__.py | 33 +++---------------------- worlds/factorio/__init__.py | 1 + worlds/hk/__init__.py | 1 + worlds/minecraft/__init__.py | 1 + 11 files changed, 70 insertions(+), 58 deletions(-) create mode 100644 worlds/alttp/SubClasses.py diff --git a/Main.py b/Main.py index 10657a19..6e11aa9f 100644 --- a/Main.py +++ b/Main.py @@ -125,7 +125,8 @@ def main(args, seed=None): world.slot_seeds = {player: random.Random(world.random.randint(0, 999999999)) for player in range(1, world.players + 1)} - for player in range(1, world.players + 1): + # system for sharing ER layouts + for player in world.alttp_player_ids: world.er_seeds[player] = str(world.random.randint(0, 2 ** 64)) if "-" in world.shuffle[player]: @@ -134,7 +135,6 @@ def main(args, seed=None): if shuffle == "vanilla": world.er_seeds[player] = "vanilla" elif seed.startswith("group-") or args.race: - # renamed from team to group to not confuse with existing team name use world.er_seeds[player] = get_same_seed(world, ( shuffle, seed, world.retro[player], world.mode[player], world.logic[player])) else: # not a race or group seed, use set seed as is. @@ -145,8 +145,9 @@ def main(args, seed=None): logger.info('Archipelago Version %s - Seed: %s\n', __version__, world.seed) logger.info("Found World Types:") + longest_name = max(len(text) for text in AutoWorld.AutoWorldRegister.world_types) for name, cls in AutoWorld.AutoWorldRegister.world_types.items(): - logger.info(f" {name:30} {cls}") + logger.info(f" {name:{longest_name}}: {len(cls.item_names):3} Items | {len(cls.location_names):3} Locations") parsed_names = parse_player_names(args.names, world.players, args.teams) world.teams = len(parsed_names) @@ -165,31 +166,31 @@ def main(args, seed=None): world.push_precollected(world.create_item(item_name, player)) for player in world.player_ids: + if player in world.alttp_player_ids: + # enforce pre-defined local items. + if world.goal[player] in ["localtriforcehunt", "localganontriforcehunt"]: + world.local_items[player].add('Triforce Piece') - # enforce pre-defined local items. - if world.goal[player] in ["localtriforcehunt", "localganontriforcehunt"]: - world.local_items[player].add('Triforce Piece') + # dungeon items can't be in non-local if the appropriate dungeon item shuffle setting is not set. + if not world.mapshuffle[player]: + world.non_local_items[player] -= item_name_groups['Maps'] + + if not world.compassshuffle[player]: + world.non_local_items[player] -= item_name_groups['Compasses'] + + if not world.keyshuffle[player]: + world.non_local_items[player] -= item_name_groups['Small Keys'] + + if not world.bigkeyshuffle[player]: + world.non_local_items[player] -= item_name_groups['Big Keys'] + + # Not possible to place pendants/crystals out side of boss prizes yet. + world.non_local_items[player] -= item_name_groups['Pendants'] + world.non_local_items[player] -= item_name_groups['Crystals'] # items can't be both local and non-local, prefer local world.non_local_items[player] -= world.local_items[player] - # dungeon items can't be in non-local if the appropriate dungeon item shuffle setting is not set. - if not world.mapshuffle[player]: - world.non_local_items[player] -= item_name_groups['Maps'] - - if not world.compassshuffle[player]: - world.non_local_items[player] -= item_name_groups['Compasses'] - - if not world.keyshuffle[player]: - world.non_local_items[player] -= item_name_groups['Small Keys'] - - if not world.bigkeyshuffle[player]: - world.non_local_items[player] -= item_name_groups['Big Keys'] - - # Not possible to place pendants/crystals out side of boss prizes yet. - world.non_local_items[player] -= item_name_groups['Pendants'] - world.non_local_items[player] -= item_name_groups['Crystals'] - AutoWorld.call_all(world, "create_regions") for player in world.alttp_player_ids: diff --git a/worlds/AutoWorld.py b/worlds/AutoWorld.py index 35c3c29d..c80d3150 100644 --- a/worlds/AutoWorld.py +++ b/worlds/AutoWorld.py @@ -31,9 +31,10 @@ class World(metaclass=AutoWorldRegister): player: int options: dict = {} topology_present: bool = False # indicate if world type has any meaningful layout/pathing - item_names: Set[str] = frozenset() + item_names: Set[str] = frozenset() # set of all potential item names # maps item group names to sets of items. Example: "Weapons" -> {"Sword", "Bow"} item_name_groups: Dict[str, Set[str]] = {} + location_names: Set[str] = frozenset() # set of all potential location names def __init__(self, world: MultiWorld, player: int): self.world = world diff --git a/worlds/alttp/ItemPool.py b/worlds/alttp/ItemPool.py index 5bd6f566..7cd83dad 100644 --- a/worlds/alttp/ItemPool.py +++ b/worlds/alttp/ItemPool.py @@ -2,7 +2,7 @@ from collections import namedtuple import logging from BaseClasses import Region, RegionType -from worlds.alttp import ALttPLocation +from worlds.alttp.SubClasses import ALttPLocation from worlds.alttp.Shops import TakeAny, total_shop_slots, set_up_shops, shuffle_shops from worlds.alttp.Bosses import place_bosses from worlds.alttp.Dungeons import get_dungeon_item_pool diff --git a/worlds/alttp/Regions.py b/worlds/alttp/Regions.py index 89a462ac..42df8c8e 100644 --- a/worlds/alttp/Regions.py +++ b/worlds/alttp/Regions.py @@ -2,7 +2,6 @@ import collections import typing from BaseClasses import Region, Entrance, RegionType -from worlds.alttp import ALttPLocation def create_regions(world, player): @@ -323,6 +322,7 @@ def create_dungeon_region(player: int, name: str, hint: str, locations=None, exi def _create_region(player: int, name: str, type: RegionType, hint: str, locations=None, exits=None): + from worlds.alttp.SubClasses import ALttPLocation ret = Region(name, type, hint, player) if locations is None: locations = [] diff --git a/worlds/alttp/Rom.py b/worlds/alttp/Rom.py index ef4dc4b1..390f096e 100644 --- a/worlds/alttp/Rom.py +++ b/worlds/alttp/Rom.py @@ -18,7 +18,7 @@ import bsdiff4 from typing import Optional from BaseClasses import CollectionState, Region -from worlds.alttp import ALttPLocation +from worlds.alttp.SubClasses import ALttPLocation from worlds.alttp.Shops import ShopType from worlds.alttp.Dungeons import dungeon_music_addresses from worlds.alttp.Regions import location_table, old_location_address_to_new_location_address diff --git a/worlds/alttp/Shops.py b/worlds/alttp/Shops.py index 64cdafc2..4f9ca4e9 100644 --- a/worlds/alttp/Shops.py +++ b/worlds/alttp/Shops.py @@ -1,9 +1,9 @@ from __future__ import annotations from enum import unique, Enum -from typing import List, Union, Optional, Set, NamedTuple, Dict +from typing import List, Optional, Set, NamedTuple, Dict import logging -from worlds.alttp import ALttPLocation +from worlds.alttp.SubClasses import ALttPLocation from worlds.alttp.EntranceShuffle import door_addresses from worlds.alttp.Items import item_name_groups, item_table, ItemFactory, trap_replaceable, GetBeemizerItem from Utils import int16_as_bytes diff --git a/worlds/alttp/SubClasses.py b/worlds/alttp/SubClasses.py new file mode 100644 index 00000000..aa349799 --- /dev/null +++ b/worlds/alttp/SubClasses.py @@ -0,0 +1,32 @@ +"""Module extending BaseClasses.py for aLttP""" +from typing import Optional + +from BaseClasses import Location, Item + + +class ALttPLocation(Location): + game: str = "A Link to the Past" + + def __init__(self, player: int, name: str = '', address=None, crystal: bool = False, + hint_text: Optional[str] = None, parent=None, + player_address=None): + super(ALttPLocation, self).__init__(player, name, address, parent) + self.crystal = crystal + self.player_address = player_address + self._hint_text: str = hint_text + + +class ALttPItem(Item): + game: str = "A Link to the Past" + + def __init__(self, name, player, advancement=False, type=None, item_code=None, pedestal_hint=None, pedestal_credit=None, + sick_kid_credit=None, zora_credit=None, witch_credit=None, flute_boy_credit=None, hint_text=None): + super(ALttPItem, self).__init__(name, advancement, item_code, player) + self.type = type + self._pedestal_hint_text = pedestal_hint + self.pedestal_credit_text = pedestal_credit + self.sickkid_credit_text = sick_kid_credit + self.zora_credit_text = zora_credit + self.magicshop_credit_text = witch_credit + self.fluteboy_credit_text = flute_boy_credit + self._hint_text = hint_text \ No newline at end of file diff --git a/worlds/alttp/__init__.py b/worlds/alttp/__init__.py index 8fa61a78..fc4459b5 100644 --- a/worlds/alttp/__init__.py +++ b/worlds/alttp/__init__.py @@ -1,9 +1,9 @@ -from typing import Optional - -from BaseClasses import Location, Item, CollectionState +from BaseClasses import Item, CollectionState +from .SubClasses import ALttPItem from ..AutoWorld import World from .Options import alttp_options from .Items import as_dict_item_table, item_name_groups, item_table +from .Regions import lookup_name_to_id class ALTTPWorld(World): @@ -12,6 +12,7 @@ class ALTTPWorld(World): topology_present = True item_name_groups = item_name_groups item_names = frozenset(item_table) + location_names = frozenset(lookup_name_to_id) def collect(self, state: CollectionState, item: Item) -> bool: if item.name.startswith('Progressive '): @@ -74,29 +75,3 @@ class ALTTPWorld(World): return ALttPItem(name, self.player, **as_dict_item_table[name]) -class ALttPLocation(Location): - game: str = "A Link to the Past" - - def __init__(self, player: int, name: str = '', address=None, crystal: bool = False, - hint_text: Optional[str] = None, parent=None, - player_address=None): - super(ALttPLocation, self).__init__(player, name, address, parent) - self.crystal = crystal - self.player_address = player_address - self._hint_text: str = hint_text - - -class ALttPItem(Item): - game: str = "A Link to the Past" - - def __init__(self, name, player, advancement=False, type=None, item_code=None, pedestal_hint=None, pedestal_credit=None, - sick_kid_credit=None, zora_credit=None, witch_credit=None, flute_boy_credit=None, hint_text=None): - super(ALttPItem, self).__init__(name, advancement, item_code, player) - self.type = type - self._pedestal_hint_text = pedestal_hint - self.pedestal_credit_text = pedestal_credit - self.sickkid_credit_text = sick_kid_credit - self.zora_credit_text = zora_credit - self.magicshop_credit_text = witch_credit - self.fluteboy_credit_text = flute_boy_credit - self._hint_text = hint_text \ No newline at end of file diff --git a/worlds/factorio/__init__.py b/worlds/factorio/__init__.py index d05557e3..6d64a67c 100644 --- a/worlds/factorio/__init__.py +++ b/worlds/factorio/__init__.py @@ -20,6 +20,7 @@ class Factorio(World): custom_recipes = {} additional_advancement_technologies = set() item_names = frozenset(tech_table) + location_names = frozenset(base_tech_table) def generate_basic(self): for tech_name in base_tech_table: diff --git a/worlds/hk/__init__.py b/worlds/hk/__init__.py index f7044073..9f4f8404 100644 --- a/worlds/hk/__init__.py +++ b/worlds/hk/__init__.py @@ -16,6 +16,7 @@ class HKWorld(World): game: str = "Hollow Knight" options = hollow_knight_options item_names: Set[str] = frozenset(item_table) + location_names: Set[str] = frozenset(lookup_name_to_id) def generate_basic(self): # Link regions diff --git a/worlds/minecraft/__init__.py b/worlds/minecraft/__init__.py index d1d6e81e..49ddb4e9 100644 --- a/worlds/minecraft/__init__.py +++ b/worlds/minecraft/__init__.py @@ -17,6 +17,7 @@ class MinecraftWorld(World): options = minecraft_options topology_present = True item_names = frozenset(item_table) + location_names = frozenset(advancement_table) def _get_mc_data(self): exits = ["Overworld Structure 1", "Overworld Structure 2", "Nether Structure 1", "Nether Structure 2",