diff options
Diffstat (limited to 'apworld')
| -rw-r--r-- | apworld/CHANGELOG.md | 54 | ||||
| -rw-r--r-- | apworld/README.md | 48 | ||||
| -rw-r--r-- | apworld/__init__.py | 35 | ||||
| -rw-r--r-- | apworld/docs/en_Lingo_2.md | 4 | ||||
| -rw-r--r-- | apworld/items.py | 26 | ||||
| -rw-r--r-- | apworld/options.py | 77 | ||||
| -rw-r--r-- | apworld/player_logic.py | 247 | ||||
| -rw-r--r-- | apworld/regions.py | 41 | ||||
| -rw-r--r-- | apworld/requirements.txt | 2 | ||||
| -rw-r--r-- | apworld/rules.py | 35 | ||||
| -rw-r--r-- | apworld/static_logic.py | 34 | ||||
| -rw-r--r-- | apworld/version.py | 1 |
12 files changed, 546 insertions, 58 deletions
| diff --git a/apworld/CHANGELOG.md b/apworld/CHANGELOG.md new file mode 100644 index 0000000..af45992 --- /dev/null +++ b/apworld/CHANGELOG.md | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | # lingo2-archipelago Apworld Releases | ||
| 2 | |||
| 3 | ## v5.5 - 2025-09-16 | ||
| 4 | |||
| 5 | - Fixed a panel in The Ancient that was missing a symbol. | ||
| 6 | - Fixed an issue where you could be expected to get S1 in The Darkroom without | ||
| 7 | having U. | ||
| 8 | - Renamed a few locations. | ||
| 9 | |||
| 10 | Download: | ||
| 11 | [lingo2.apworld](https://files.fourisland.com/releases/lingo2-archipelago/apworld/v5.5/lingo2.apworld)<br/> | ||
| 12 | Template YAML: | ||
| 13 | [Lingo 2.yaml](https://files.fourisland.com/releases/lingo2-archipelago/apworld/v5.5/Lingo%202.yaml)<br/> | ||
| 14 | Source: | ||
| 15 | [v5.5](https://code.fourisland.com/lingo2-archipelago/tag/?h=apworld-v5.5) | ||
| 16 | |||
| 17 | ## v4.4 - 2025-09-14 | ||
| 18 | |||
| 19 | - Fixed panel set location names. | ||
| 20 | |||
| 21 | Download: | ||
| 22 | [lingo2.apworld](https://files.fourisland.com/releases/lingo2-archipelago/apworld/v4.4/lingo2.apworld)<br/> | ||
| 23 | Template YAML: | ||
| 24 | [Lingo 2.yaml](https://files.fourisland.com/releases/lingo2-archipelago/apworld/v4.4/Lingo%202.yaml)<br/> | ||
| 25 | Source: | ||
| 26 | [v4.4](https://code.fourisland.com/lingo2-archipelago/tag/?h=apworld-v4.4) | ||
| 27 | |||
| 28 | ## v4.3 - 2025-09-13 | ||
| 29 | |||
| 30 | - Added a location for the anti-collectable in The Repetitive. | ||
| 31 | - Added trap items. These remove letters from your keyboard until you use the | ||
| 32 | Key Return in The Entry, similar to the anti-collectable in The Repetitive. | ||
| 33 | This can be controlled using the `trap_percentage` option, which defaults to | ||
| 34 | zero. | ||
| 35 | - Fixed crash on load when using Python 3.11. | ||
| 36 | |||
| 37 | Download: | ||
| 38 | [lingo2.apworld](https://files.fourisland.com/releases/lingo2-archipelago/apworld/v4.3/lingo2.apworld)<br/> | ||
| 39 | Template YAML: | ||
| 40 | [Lingo 2.yaml](https://files.fourisland.com/releases/lingo2-archipelago/apworld/v4.3/Lingo%202.yaml)<br/> | ||
| 41 | Source: | ||
| 42 | [v4.3](https://code.fourisland.com/lingo2-archipelago/tag/?h=apworld-v4.3) | ||
| 43 | |||
| 44 | ## v3.2 - 2025-09-12 | ||
| 45 | |||
| 46 | - Initial release for testing. Features include door shuffle, letter shuffle, | ||
| 47 | and symbol shuffle. | ||
| 48 | |||
| 49 | Download: | ||
| 50 | [lingo2.apworld](https://files.fourisland.com/releases/lingo2-archipelago/apworld/v3.2/lingo2.apworld)<br/> | ||
| 51 | Template YAML: | ||
| 52 | [Lingo 2.yaml](https://files.fourisland.com/releases/lingo2-archipelago/apworld/v3.2/Lingo%202.yaml)<br/> | ||
| 53 | Source: | ||
| 54 | [v3.2](https://code.fourisland.com/lingo2-archipelago/tag/?h=apworld-v3.2) | ||
| diff --git a/apworld/README.md b/apworld/README.md new file mode 100644 index 0000000..13374b2 --- /dev/null +++ b/apworld/README.md | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | # Lingo 2 Apworld | ||
| 2 | |||
| 3 | The Lingo 2 Apworld allows you to generate Archipelago Multiworlds containing | ||
| 4 | Lingo 2. | ||
| 5 | |||
| 6 | ## Installation | ||
| 7 | |||
| 8 | 1. Download the Lingo 2 Apworld from | ||
| 9 | [the releases page](https://code.fourisland.com/lingo2-archipelago/about/apworld/CHANGELOG.md). | ||
| 10 | 2. If you do not already have it, download and install the | ||
| 11 | [Archipelago software](https://github.com/ArchipelagoMW/Archipelago/releases/). | ||
| 12 | 3. Double click on `lingo2.apworld` to install it, or copy it manually to the | ||
| 13 | `custom_worlds` folder of your Archipelago installation. | ||
| 14 | |||
| 15 | ## Running from source | ||
| 16 | |||
| 17 | The apworld is mostly written in Python, which does not need to be compiled. | ||
| 18 | However, there are two files that need to be generated before the apworld can be | ||
| 19 | used. | ||
| 20 | |||
| 21 | The first file is `data.binpb`, the datafile containing the randomizer logic. | ||
| 22 | You can read about how to generate it on | ||
| 23 | [its own README page](https://code.fourisland.com/lingo2-archipelago/about/data/README.md). | ||
| 24 | Once you have it, put it in a subfolder of `apworld` called `generated`. | ||
| 25 | |||
| 26 | The second generated file is `data_pb2.py`. This file allows Archipelago to read | ||
| 27 | the datafile. We use `protoc`, the Protocol Buffer compiler, to generate it. As | ||
| 28 | of 0.6.3, Archipelago has protobuf 3.20.3 packaged with it, which means we need | ||
| 29 | to compile our proto file with a similar version. | ||
| 30 | |||
| 31 | If you followed the steps to generate `data.binpb` and compiled the `datapacker` | ||
| 32 | tool yourself, you will already have protobuf version 3.21.12 installed through | ||
| 33 | vcpkg. You can then run a command similar to this in order to generate the | ||
| 34 | python file. | ||
| 35 | |||
| 36 | ```shell | ||
| 37 | .\out\build\x64-Debug\vcpkg_installed\x64-windows\tools\protobuf\protoc.exe -Iproto\ ^ | ||
| 38 | --python_out=apworld\generated\ .\proto\data.proto | ||
| 39 | ``` | ||
| 40 | |||
| 41 | The exact path to `protoc.exe` is going to depend on where vcpkg installed its | ||
| 42 | packages. The above location is where Visual Studio will probably put it. | ||
| 43 | |||
| 44 | After generating those two files, the apworld should be functional. You can copy | ||
| 45 | it into an Archipelago source tree (rename the folder `apworld` to `lingo2` if | ||
| 46 | you do so) if you want to edit/debug the code. Otherwise, you can zip up the | ||
| 47 | folder and rename it to `lingo2.apworld` in order to package it for | ||
| 48 | distribution. | ||
| diff --git a/apworld/__init__.py b/apworld/__init__.py index 8e3066d..8b2e42e 100644 --- a/apworld/__init__.py +++ b/apworld/__init__.py | |||
| @@ -1,18 +1,27 @@ | |||
| 1 | """ | 1 | """ |
| 2 | Archipelago init file for Lingo 2 | 2 | Archipelago init file for Lingo 2 |
| 3 | """ | 3 | """ |
| 4 | from BaseClasses import ItemClassification, Item | 4 | from BaseClasses import ItemClassification, Item, Tutorial |
| 5 | from worlds.AutoWorld import WebWorld, World | 5 | from worlds.AutoWorld import WebWorld, World |
| 6 | from .items import Lingo2Item | 6 | from .items import Lingo2Item, ANTI_COLLECTABLE_TRAPS |
| 7 | from .options import Lingo2Options | 7 | from .options import Lingo2Options |
| 8 | from .player_logic import Lingo2PlayerLogic | 8 | from .player_logic import Lingo2PlayerLogic |
| 9 | from .regions import create_regions | 9 | from .regions import create_regions |
| 10 | from .static_logic import Lingo2StaticLogic | 10 | from .static_logic import Lingo2StaticLogic |
| 11 | from .version import APWORLD_VERSION | ||
| 11 | 12 | ||
| 12 | 13 | ||
| 13 | class Lingo2WebWorld(WebWorld): | 14 | class Lingo2WebWorld(WebWorld): |
| 14 | rich_text_options_doc = True | 15 | rich_text_options_doc = True |
| 15 | theme = "grass" | 16 | theme = "grass" |
| 17 | tutorials = [Tutorial( | ||
| 18 | "Multiworld Setup Guide", | ||
| 19 | "A guide to playing Lingo 2 with Archipelago.", | ||
| 20 | "English", | ||
| 21 | "en_Lingo_2.md", | ||
| 22 | "setup/en", | ||
| 23 | ["hatkirby"] | ||
| 24 | )] | ||
| 16 | 25 | ||
| 17 | 26 | ||
| 18 | class Lingo2World(World): | 27 | class Lingo2World(World): |
| @@ -32,6 +41,8 @@ class Lingo2World(World): | |||
| 32 | static_logic = Lingo2StaticLogic() | 41 | static_logic = Lingo2StaticLogic() |
| 33 | item_name_to_id = static_logic.item_name_to_id | 42 | item_name_to_id = static_logic.item_name_to_id |
| 34 | location_name_to_id = static_logic.location_name_to_id | 43 | location_name_to_id = static_logic.location_name_to_id |
| 44 | item_name_groups = static_logic.item_name_groups | ||
| 45 | location_name_groups = static_logic.location_name_groups | ||
| 35 | 46 | ||
| 36 | player_logic: Lingo2PlayerLogic | 47 | player_logic: Lingo2PlayerLogic |
| 37 | 48 | ||
| @@ -51,6 +62,20 @@ class Lingo2World(World): | |||
| 51 | total_locations = sum(len(locs) for locs in self.player_logic.locations_by_room.values()) | 62 | total_locations = sum(len(locs) for locs in self.player_logic.locations_by_room.values()) |
| 52 | 63 | ||
| 53 | item_difference = total_locations - len(pool) | 64 | item_difference = total_locations - len(pool) |
| 65 | |||
| 66 | if self.options.trap_percentage > 0: | ||
| 67 | num_traps = int(item_difference * self.options.trap_percentage / 100) | ||
| 68 | item_difference = item_difference - num_traps | ||
| 69 | |||
| 70 | trap_names = [] | ||
| 71 | trap_weights = [] | ||
| 72 | for letter_name, weight in self.static_logic.letter_weights.items(): | ||
| 73 | trap_names.append(f"Anti {letter_name}") | ||
| 74 | trap_weights.append(weight) | ||
| 75 | |||
| 76 | bad_letters = self.random.choices(trap_names, weights=trap_weights, k=num_traps) | ||
| 77 | pool += [self.create_item(trap_name) for trap_name in bad_letters] | ||
| 78 | |||
| 54 | for i in range(0, item_difference): | 79 | for i in range(0, item_difference): |
| 55 | pool.append(self.create_item(self.get_filler_item_name())) | 80 | pool.append(self.create_item(self.get_filler_item_name())) |
| 56 | 81 | ||
| @@ -58,6 +83,7 @@ class Lingo2World(World): | |||
| 58 | 83 | ||
| 59 | def create_item(self, name: str) -> Item: | 84 | def create_item(self, name: str) -> Item: |
| 60 | return Lingo2Item(name, ItemClassification.filler if name == self.get_filler_item_name() else | 85 | return Lingo2Item(name, ItemClassification.filler if name == self.get_filler_item_name() else |
| 86 | ItemClassification.trap if name in ANTI_COLLECTABLE_TRAPS else | ||
| 61 | ItemClassification.progression, | 87 | ItemClassification.progression, |
| 62 | self.item_name_to_id.get(name), self.player) | 88 | self.item_name_to_id.get(name), self.player) |
| 63 | 89 | ||
| @@ -66,15 +92,20 @@ class Lingo2World(World): | |||
| 66 | 92 | ||
| 67 | def fill_slot_data(self): | 93 | def fill_slot_data(self): |
| 68 | slot_options = [ | 94 | slot_options = [ |
| 95 | "cyan_door_behavior", | ||
| 69 | "daedalus_roof_access", | 96 | "daedalus_roof_access", |
| 70 | "keyholder_sanity", | 97 | "keyholder_sanity", |
| 98 | "shuffle_control_center_colors", | ||
| 71 | "shuffle_doors", | 99 | "shuffle_doors", |
| 100 | "shuffle_gallery_paintings", | ||
| 72 | "shuffle_letters", | 101 | "shuffle_letters", |
| 102 | "shuffle_symbols", | ||
| 73 | "victory_condition", | 103 | "victory_condition", |
| 74 | ] | 104 | ] |
| 75 | 105 | ||
| 76 | slot_data = { | 106 | slot_data = { |
| 77 | **self.options.as_dict(*slot_options), | 107 | **self.options.as_dict(*slot_options), |
| 108 | "version": [self.static_logic.get_data_version(), APWORLD_VERSION], | ||
| 78 | } | 109 | } |
| 79 | 110 | ||
| 80 | return slot_data | 111 | return slot_data |
| diff --git a/apworld/docs/en_Lingo_2.md b/apworld/docs/en_Lingo_2.md new file mode 100644 index 0000000..977795a --- /dev/null +++ b/apworld/docs/en_Lingo_2.md | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | # Lingo 2 | ||
| 2 | |||
| 3 | See [the project README](https://code.fourisland.com/lingo2-archipelago/about/) | ||
| 4 | for installation instructions and frequently asked questions. \ No newline at end of file | ||
| diff --git a/apworld/items.py b/apworld/items.py index 971a709..28158c3 100644 --- a/apworld/items.py +++ b/apworld/items.py | |||
| @@ -1,5 +1,31 @@ | |||
| 1 | from .generated import data_pb2 as data_pb2 | ||
| 1 | from BaseClasses import Item | 2 | from BaseClasses import Item |
| 2 | 3 | ||
| 3 | 4 | ||
| 4 | class Lingo2Item(Item): | 5 | class Lingo2Item(Item): |
| 5 | game: str = "Lingo 2" | 6 | game: str = "Lingo 2" |
| 7 | |||
| 8 | |||
| 9 | SYMBOL_ITEMS: dict[data_pb2.PuzzleSymbol, str] = { | ||
| 10 | data_pb2.PuzzleSymbol.SUN: "Sun Symbol", | ||
| 11 | data_pb2.PuzzleSymbol.SPARKLES: "Sparkles Symbol", | ||
| 12 | data_pb2.PuzzleSymbol.ZERO: "Zero Symbol", | ||
| 13 | data_pb2.PuzzleSymbol.EXAMPLE: "Example Symbol", | ||
| 14 | data_pb2.PuzzleSymbol.BOXES: "Boxes Symbol", | ||
| 15 | data_pb2.PuzzleSymbol.PLANET: "Planet Symbol", | ||
| 16 | data_pb2.PuzzleSymbol.PYRAMID: "Pyramid Symbol", | ||
| 17 | data_pb2.PuzzleSymbol.CROSS: "Cross Symbol", | ||
| 18 | data_pb2.PuzzleSymbol.SWEET: "Sweet Symbol", | ||
| 19 | data_pb2.PuzzleSymbol.GENDER: "Gender Symbol", | ||
| 20 | data_pb2.PuzzleSymbol.AGE: "Age Symbol", | ||
| 21 | data_pb2.PuzzleSymbol.SOUND: "Sound Symbol", | ||
| 22 | data_pb2.PuzzleSymbol.ANAGRAM: "Anagram Symbol", | ||
| 23 | data_pb2.PuzzleSymbol.JOB: "Job Symbol", | ||
| 24 | data_pb2.PuzzleSymbol.STARS: "Stars Symbol", | ||
| 25 | data_pb2.PuzzleSymbol.NULL: "Null Symbol", | ||
| 26 | data_pb2.PuzzleSymbol.EVAL: "Eval Symbol", | ||
| 27 | data_pb2.PuzzleSymbol.LINGO: "Lingo Symbol", | ||
| 28 | data_pb2.PuzzleSymbol.QUESTION: "Question Symbol", | ||
| 29 | } | ||
| 30 | |||
| 31 | ANTI_COLLECTABLE_TRAPS: list[str] = [f"Anti {letter}" for letter in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"] | ||
| diff --git a/apworld/options.py b/apworld/options.py index f7dc5bd..52d2034 100644 --- a/apworld/options.py +++ b/apworld/options.py | |||
| @@ -1,13 +1,26 @@ | |||
| 1 | from dataclasses import dataclass | 1 | from dataclasses import dataclass |
| 2 | 2 | ||
| 3 | from Options import PerGameCommonOptions, Toggle, Choice | 3 | from Options import PerGameCommonOptions, Toggle, Choice, DefaultOnToggle, Range |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | class ShuffleDoors(Toggle): | 6 | class ShuffleDoors(DefaultOnToggle): |
| 7 | """If enabled, most doors will open from receiving an item rather than fulfilling the in-game requirements.""" | 7 | """If enabled, most doors will open from receiving an item rather than fulfilling the in-game requirements.""" |
| 8 | display_name = "Shuffle Doors" | 8 | display_name = "Shuffle Doors" |
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | class ShuffleControlCenterColors(Toggle): | ||
| 12 | """ | ||
| 13 | Some doors open after solving the COLOR panel in the Control Center. If this option is enabled, these doors will | ||
| 14 | instead open upon receiving an item. | ||
| 15 | """ | ||
| 16 | display_name = "Shuffle Control Center Colors" | ||
| 17 | |||
| 18 | |||
| 19 | class ShuffleGalleryPaintings(Toggle): | ||
| 20 | """If enabled, gallery paintings will appear from receiving an item rather than by triggering them normally.""" | ||
| 21 | display_name = "Shuffle Gallery Paintings" | ||
| 22 | |||
| 23 | |||
| 11 | class ShuffleLetters(Choice): | 24 | class ShuffleLetters(Choice): |
| 12 | """ | 25 | """ |
| 13 | Controls how letter unlocks are handled. Note that H1, I1, N1, and T1 will always be present at their vanilla | 26 | Controls how letter unlocks are handled. Note that H1, I1, N1, and T1 will always be present at their vanilla |
| @@ -31,6 +44,14 @@ class ShuffleLetters(Choice): | |||
| 31 | option_item_cyan = 4 | 44 | option_item_cyan = 4 |
| 32 | 45 | ||
| 33 | 46 | ||
| 47 | class ShuffleSymbols(Toggle): | ||
| 48 | """ | ||
| 49 | If enabled, 19 items will be added to the pool, representing the different symbols that can appear on a panel. | ||
| 50 | Players will be prevented from solving puzzles with symbols on them until all of the required symbols are unlocked. | ||
| 51 | """ | ||
| 52 | display_name = "Shuffle Symbols" | ||
| 53 | |||
| 54 | |||
| 34 | class KeyholderSanity(Toggle): | 55 | class KeyholderSanity(Toggle): |
| 35 | """ | 56 | """ |
| 36 | If enabled, 26 locations will be created for placing each key into its respective Green Ending keyholder. | 57 | If enabled, 26 locations will be created for placing each key into its respective Green Ending keyholder. |
| @@ -40,6 +61,27 @@ class KeyholderSanity(Toggle): | |||
| 40 | display_name = "Keyholder Sanity" | 61 | display_name = "Keyholder Sanity" |
| 41 | 62 | ||
| 42 | 63 | ||
| 64 | class CyanDoorBehavior(Choice): | ||
| 65 | """ | ||
| 66 | Cyan-colored doors usually only open upon unlocking double letters. Some panels also only appear upon unlocking | ||
| 67 | double letters. This option determines how these unlocks should behave. | ||
| 68 | |||
| 69 | - **Collect H2**: In the base game, H2 is the first double letter you are intended to collect, so cyan doors only | ||
| 70 | open when you collect the H2 pickup in The Repetitive. Collecting the actual pickup is still required even with | ||
| 71 | remote letter shuffle enabled. | ||
| 72 | - **Any Double Letter**: Cyan doors will open when you have unlocked any cyan letter on your keyboard. In letter | ||
| 73 | shuffle, this means receiving a cyan letter, not picking up a cyan letter collectable. | ||
| 74 | - **Item**: Cyan doors will be grouped together in a single item. | ||
| 75 | |||
| 76 | Note that some cyan doors are impacted by door shuffle (e.g. the entrance to The Tower). When door shuffle is | ||
| 77 | enabled, these doors won't be affected by the value of this option. | ||
| 78 | """ | ||
| 79 | display_name = "Cyan Door Behavior" | ||
| 80 | option_collect_h2 = 0 | ||
| 81 | option_any_double_letter = 1 | ||
| 82 | option_item = 2 | ||
| 83 | |||
| 84 | |||
| 43 | class DaedalusRoofAccess(Toggle): | 85 | class DaedalusRoofAccess(Toggle): |
| 44 | """ | 86 | """ |
| 45 | If enabled, the player will be logically expected to be able to go from the castle entrance to any part of Daedalus | 87 | If enabled, the player will be logically expected to be able to go from the castle entrance to any part of Daedalus |
| @@ -51,7 +93,23 @@ class DaedalusRoofAccess(Toggle): | |||
| 51 | 93 | ||
| 52 | 94 | ||
| 53 | class VictoryCondition(Choice): | 95 | class VictoryCondition(Choice): |
| 54 | """Victory condition.""" | 96 | """ |
| 97 | This option determines what your goal is. | ||
| 98 | |||
| 99 | - **Gray Ending** (The Colorful) | ||
| 100 | - **Purple Ending** (The Sun Temple). This ordinarily requires all level 1 (purple) letters. | ||
| 101 | - **Mint Ending** (typing EXIT into the keyholders in Control Center) | ||
| 102 | - **Black Ending** (The Graveyard) | ||
| 103 | - **Blue Ending** (The Words) | ||
| 104 | - **Cyan Ending** (The Parthenon). This ordinarily requires almost all level 2 (cyan) letters. | ||
| 105 | - **Red Ending** (The Tower) | ||
| 106 | - **Plum Ending** (The Wondrous / The Door) | ||
| 107 | - **Orange Ending** (the castle in Daedalus) | ||
| 108 | - **Gold Ending** (The Gold). This involves going through the color rooms in Daedalus. | ||
| 109 | - **Yellow Ending** (The Gallery). This requires unlocking all gallery paintings. | ||
| 110 | - **Green Ending** (The Ancient). This requires filling all keyholders with specific letters. | ||
| 111 | - **White Ending** (Control Center). This combines every other ending. | ||
| 112 | """ | ||
| 55 | display_name = "Victory Condition" | 113 | display_name = "Victory Condition" |
| 56 | option_gray_ending = 0 | 114 | option_gray_ending = 0 |
| 57 | option_purple_ending = 1 | 115 | option_purple_ending = 1 |
| @@ -68,10 +126,23 @@ class VictoryCondition(Choice): | |||
| 68 | option_white_ending = 12 | 126 | option_white_ending = 12 |
| 69 | 127 | ||
| 70 | 128 | ||
| 129 | class TrapPercentage(Range): | ||
| 130 | """Replaces junk items with traps, at the specified rate.""" | ||
| 131 | display_name = "Trap Percentage" | ||
| 132 | range_start = 0 | ||
| 133 | range_end = 100 | ||
| 134 | default = 0 | ||
| 135 | |||
| 136 | |||
| 71 | @dataclass | 137 | @dataclass |
| 72 | class Lingo2Options(PerGameCommonOptions): | 138 | class Lingo2Options(PerGameCommonOptions): |
| 73 | shuffle_doors: ShuffleDoors | 139 | shuffle_doors: ShuffleDoors |
| 140 | shuffle_control_center_colors: ShuffleControlCenterColors | ||
| 141 | shuffle_gallery_paintings: ShuffleGalleryPaintings | ||
| 74 | shuffle_letters: ShuffleLetters | 142 | shuffle_letters: ShuffleLetters |
| 143 | shuffle_symbols: ShuffleSymbols | ||
| 75 | keyholder_sanity: KeyholderSanity | 144 | keyholder_sanity: KeyholderSanity |
| 145 | cyan_door_behavior: CyanDoorBehavior | ||
| 76 | daedalus_roof_access: DaedalusRoofAccess | 146 | daedalus_roof_access: DaedalusRoofAccess |
| 77 | victory_condition: VictoryCondition | 147 | victory_condition: VictoryCondition |
| 148 | trap_percentage: TrapPercentage | ||
| diff --git a/apworld/player_logic.py b/apworld/player_logic.py index 5cb9011..4aa481d 100644 --- a/apworld/player_logic.py +++ b/apworld/player_logic.py | |||
| @@ -1,9 +1,10 @@ | |||
| 1 | from enum import IntEnum, auto | 1 | from enum import IntEnum, auto |
| 2 | 2 | ||
| 3 | from .generated import data_pb2 as data_pb2 | 3 | from .generated import data_pb2 as data_pb2 |
| 4 | from .items import SYMBOL_ITEMS | ||
| 4 | from typing import TYPE_CHECKING, NamedTuple | 5 | from typing import TYPE_CHECKING, NamedTuple |
| 5 | 6 | ||
| 6 | from .options import VictoryCondition, ShuffleLetters | 7 | from .options import VictoryCondition, ShuffleLetters, CyanDoorBehavior |
| 7 | 8 | ||
| 8 | if TYPE_CHECKING: | 9 | if TYPE_CHECKING: |
| 9 | from . import Lingo2World | 10 | from . import Lingo2World |
| @@ -23,21 +24,38 @@ class AccessRequirements: | |||
| 23 | items: set[str] | 24 | items: set[str] |
| 24 | progressives: dict[str, int] | 25 | progressives: dict[str, int] |
| 25 | rooms: set[str] | 26 | rooms: set[str] |
| 26 | symbols: set[str] | ||
| 27 | letters: dict[str, int] | 27 | letters: dict[str, int] |
| 28 | cyans: bool | 28 | cyans: bool |
| 29 | 29 | ||
| 30 | # This is an AND of ORs. | 30 | # This is an AND of ORs. |
| 31 | or_logic: list[list["AccessRequirements"]] | 31 | or_logic: list[list["AccessRequirements"]] |
| 32 | 32 | ||
| 33 | # When complete_at is set, at least that many of the requirements in possibilities must be accessible. This should | ||
| 34 | # only be used for doors with complete_at > 1, as or_logic is more efficient for complete_at == 1. | ||
| 35 | complete_at: int | None | ||
| 36 | possibilities: list["AccessRequirements"] | ||
| 37 | |||
| 33 | def __init__(self): | 38 | def __init__(self): |
| 34 | self.items = set() | 39 | self.items = set() |
| 35 | self.progressives = dict() | 40 | self.progressives = dict() |
| 36 | self.rooms = set() | 41 | self.rooms = set() |
| 37 | self.symbols = set() | ||
| 38 | self.letters = dict() | 42 | self.letters = dict() |
| 39 | self.cyans = False | 43 | self.cyans = False |
| 40 | self.or_logic = list() | 44 | self.or_logic = list() |
| 45 | self.complete_at = None | ||
| 46 | self.possibilities = list() | ||
| 47 | |||
| 48 | def copy(self) -> "AccessRequirements": | ||
| 49 | reqs = AccessRequirements() | ||
| 50 | reqs.items = self.items.copy() | ||
| 51 | reqs.progressives = self.progressives.copy() | ||
| 52 | reqs.rooms = self.rooms.copy() | ||
| 53 | reqs.letters = self.letters.copy() | ||
| 54 | reqs.cyans = self.cyans | ||
| 55 | reqs.or_logic = [[other_req.copy() for other_req in disjunction] for disjunction in self.or_logic] | ||
| 56 | reqs.complete_at = self.complete_at | ||
| 57 | reqs.possibilities = self.possibilities.copy() | ||
| 58 | return reqs | ||
| 41 | 59 | ||
| 42 | def merge(self, other: "AccessRequirements"): | 60 | def merge(self, other: "AccessRequirements"): |
| 43 | for item in other.items: | 61 | for item in other.items: |
| @@ -49,9 +67,6 @@ class AccessRequirements: | |||
| 49 | for room in other.rooms: | 67 | for room in other.rooms: |
| 50 | self.rooms.add(room) | 68 | self.rooms.add(room) |
| 51 | 69 | ||
| 52 | for symbol in other.symbols: | ||
| 53 | self.symbols.add(symbol) | ||
| 54 | |||
| 55 | for letter, level in other.letters.items(): | 70 | for letter, level in other.letters.items(): |
| 56 | self.letters[letter] = max(self.letters.get(letter, 0), level) | 71 | self.letters[letter] = max(self.letters.get(letter, 0), level) |
| 57 | 72 | ||
| @@ -60,6 +75,98 @@ class AccessRequirements: | |||
| 60 | for disjunction in other.or_logic: | 75 | for disjunction in other.or_logic: |
| 61 | self.or_logic.append(disjunction) | 76 | self.or_logic.append(disjunction) |
| 62 | 77 | ||
| 78 | if other.complete_at is not None: | ||
| 79 | # Merging multiple requirements that use complete_at sucks, and is part of why we want to minimize use of | ||
| 80 | # it. If both requirements use complete_at, we will cheat by using the or_logic field, which supports | ||
| 81 | # conjunctions of requirements. | ||
| 82 | if self.complete_at is not None: | ||
| 83 | print("Merging requirements with complete_at > 1. This is messy and should be avoided!") | ||
| 84 | |||
| 85 | left_req = AccessRequirements() | ||
| 86 | left_req.complete_at = self.complete_at | ||
| 87 | left_req.possibilities = self.possibilities | ||
| 88 | self.or_logic.append([left_req]) | ||
| 89 | |||
| 90 | self.complete_at = None | ||
| 91 | self.possibilities = list() | ||
| 92 | |||
| 93 | right_req = AccessRequirements() | ||
| 94 | right_req.complete_at = other.complete_at | ||
| 95 | right_req.possibilities = other.possibilities | ||
| 96 | self.or_logic.append([right_req]) | ||
| 97 | else: | ||
| 98 | self.complete_at = other.complete_at | ||
| 99 | self.possibilities = other.possibilities | ||
| 100 | |||
| 101 | def is_empty(self) -> bool: | ||
| 102 | return (len(self.items) == 0 and len(self.progressives) == 0 and len(self.rooms) == 0 and len(self.letters) == 0 | ||
| 103 | and not self.cyans and len(self.or_logic) == 0 and self.complete_at is None) | ||
| 104 | |||
| 105 | def __eq__(self, other: "AccessRequirements"): | ||
| 106 | return (self.items == other.items and self.progressives == other.progressives and self.rooms == other.rooms and | ||
| 107 | self.letters == other.letters and self.cyans == other.cyans and self.or_logic == other.or_logic and | ||
| 108 | self.complete_at == other.complete_at and self.possibilities == other.possibilities) | ||
| 109 | |||
| 110 | def simplify(self): | ||
| 111 | resimplify = False | ||
| 112 | |||
| 113 | if len(self.or_logic) > 0: | ||
| 114 | old_or_logic = self.or_logic | ||
| 115 | |||
| 116 | def remove_redundant(sub_reqs: "AccessRequirements"): | ||
| 117 | new_reqs = sub_reqs.copy() | ||
| 118 | new_reqs.letters = {l: v for l, v in new_reqs.letters.items() if self.letters.get(l, 0) < v} | ||
| 119 | if new_reqs != sub_reqs: | ||
| 120 | return new_reqs | ||
| 121 | else: | ||
| 122 | return sub_reqs | ||
| 123 | |||
| 124 | self.or_logic = [] | ||
| 125 | for disjunction in old_or_logic: | ||
| 126 | new_disjunction = [] | ||
| 127 | for ssr in disjunction: | ||
| 128 | new_ssr = remove_redundant(ssr) | ||
| 129 | if not new_ssr.is_empty(): | ||
| 130 | new_disjunction.append(new_ssr) | ||
| 131 | else: | ||
| 132 | new_disjunction.clear() | ||
| 133 | break | ||
| 134 | if len(new_disjunction) == 1: | ||
| 135 | self.merge(new_disjunction[0]) | ||
| 136 | resimplify = True | ||
| 137 | elif len(new_disjunction) > 1: | ||
| 138 | if all(cjr == new_disjunction[0] for cjr in new_disjunction): | ||
| 139 | self.merge(new_disjunction[0]) | ||
| 140 | resimplify = True | ||
| 141 | else: | ||
| 142 | self.or_logic.append(new_disjunction) | ||
| 143 | |||
| 144 | if resimplify: | ||
| 145 | self.simplify() | ||
| 146 | |||
| 147 | def get_referenced_rooms(self): | ||
| 148 | result = set(self.rooms) | ||
| 149 | |||
| 150 | for disjunction in self.or_logic: | ||
| 151 | for sub_req in disjunction: | ||
| 152 | result = result.union(sub_req.get_referenced_rooms()) | ||
| 153 | |||
| 154 | for sub_req in self.possibilities: | ||
| 155 | result = result.union(sub_req.get_referenced_rooms()) | ||
| 156 | |||
| 157 | return result | ||
| 158 | |||
| 159 | def remove_room(self, room: str): | ||
| 160 | if room in self.rooms: | ||
| 161 | self.rooms.remove(room) | ||
| 162 | |||
| 163 | for disjunction in self.or_logic: | ||
| 164 | for sub_req in disjunction: | ||
| 165 | sub_req.remove_room(room) | ||
| 166 | |||
| 167 | for sub_req in self.possibilities: | ||
| 168 | sub_req.remove_room(room) | ||
| 169 | |||
| 63 | def __repr__(self): | 170 | def __repr__(self): |
| 64 | parts = [] | 171 | parts = [] |
| 65 | if len(self.items) > 0: | 172 | if len(self.items) > 0: |
| @@ -68,15 +175,17 @@ class AccessRequirements: | |||
| 68 | parts.append(f"progressives={self.progressives}") | 175 | parts.append(f"progressives={self.progressives}") |
| 69 | if len(self.rooms) > 0: | 176 | if len(self.rooms) > 0: |
| 70 | parts.append(f"rooms={self.rooms}") | 177 | parts.append(f"rooms={self.rooms}") |
| 71 | if len(self.symbols) > 0: | ||
| 72 | parts.append(f"symbols={self.symbols}") | ||
| 73 | if len(self.letters) > 0: | 178 | if len(self.letters) > 0: |
| 74 | parts.append(f"letters={self.letters}") | 179 | parts.append(f"letters={self.letters}") |
| 75 | if self.cyans: | 180 | if self.cyans: |
| 76 | parts.append(f"cyans=True") | 181 | parts.append(f"cyans=True") |
| 77 | if len(self.or_logic) > 0: | 182 | if len(self.or_logic) > 0: |
| 78 | parts.append(f"or_logic={self.or_logic}") | 183 | parts.append(f"or_logic={self.or_logic}") |
| 79 | return f"AccessRequirements({", ".join(parts)})" | 184 | if self.complete_at is not None: |
| 185 | parts.append(f"complete_at={self.complete_at}") | ||
| 186 | if len(self.possibilities) > 0: | ||
| 187 | parts.append(f"possibilities={self.possibilities}") | ||
| 188 | return "AccessRequirements(" + ", ".join(parts) + ")" | ||
| 80 | 189 | ||
| 81 | 190 | ||
| 82 | class PlayerLocation(NamedTuple): | 191 | class PlayerLocation(NamedTuple): |
| @@ -123,16 +232,60 @@ class Lingo2PlayerLogic: | |||
| 123 | self.item_by_door[progressive.doors[i]] = (progressive.name, i + 1) | 232 | self.item_by_door[progressive.doors[i]] = (progressive.name, i + 1) |
| 124 | self.real_items.append(progressive.name) | 233 | self.real_items.append(progressive.name) |
| 125 | 234 | ||
| 235 | for door_group in world.static_logic.objects.door_groups: | ||
| 236 | if door_group.type == data_pb2.DoorGroupType.CONNECTOR: | ||
| 237 | if not self.world.options.shuffle_doors: | ||
| 238 | continue | ||
| 239 | elif door_group.type == data_pb2.DoorGroupType.COLOR_CONNECTOR: | ||
| 240 | if not self.world.options.shuffle_control_center_colors: | ||
| 241 | continue | ||
| 242 | elif door_group.type == data_pb2.DoorGroupType.SHUFFLE_GROUP: | ||
| 243 | if not self.world.options.shuffle_doors: | ||
| 244 | continue | ||
| 245 | else: | ||
| 246 | continue | ||
| 247 | |||
| 248 | for door in door_group.doors: | ||
| 249 | self.item_by_door[door] = (door_group.name, 1) | ||
| 250 | |||
| 251 | self.real_items.append(door_group.name) | ||
| 252 | |||
| 126 | # We iterate through the doors in two parts because it is essential that we determine which doors are shuffled | 253 | # We iterate through the doors in two parts because it is essential that we determine which doors are shuffled |
| 127 | # before we calculate any access requirements. | 254 | # before we calculate any access requirements. |
| 128 | for door in world.static_logic.objects.doors: | 255 | for door in world.static_logic.objects.doors: |
| 129 | if door.type in [data_pb2.DoorType.STANDARD, data_pb2.DoorType.ITEM_ONLY] and self.world.options.shuffle_doors: | 256 | if door.type in [data_pb2.DoorType.EVENT, data_pb2.DoorType.LOCATION_ONLY, data_pb2.DoorType.GRAVESTONE]: |
| 130 | if door.id in self.item_by_door: | 257 | continue |
| 258 | |||
| 259 | if door.id in self.item_by_door: | ||
| 260 | continue | ||
| 261 | |||
| 262 | if (door.type in [data_pb2.DoorType.STANDARD, data_pb2.DoorType.ITEM_ONLY] and | ||
| 263 | not self.world.options.shuffle_doors): | ||
| 264 | continue | ||
| 265 | |||
| 266 | if (door.type == data_pb2.DoorType.CONTROL_CENTER_COLOR and | ||
| 267 | not self.world.options.shuffle_control_center_colors): | ||
| 268 | continue | ||
| 269 | |||
| 270 | if door.type == data_pb2.DoorType.GALLERY_PAINTING and not self.world.options.shuffle_gallery_paintings: | ||
| 271 | continue | ||
| 272 | |||
| 273 | door_item_name = self.world.static_logic.get_door_item_name(door) | ||
| 274 | self.item_by_door[door.id] = (door_item_name, 1) | ||
| 275 | self.real_items.append(door_item_name) | ||
| 276 | |||
| 277 | # We handle cyan_door_behavior = Item after door shuffle, because cyan doors that are impacted by door shuffle | ||
| 278 | # should be exempt from cyan_door_behavior. | ||
| 279 | if world.options.cyan_door_behavior == CyanDoorBehavior.option_item: | ||
| 280 | for door_group in world.static_logic.objects.door_groups: | ||
| 281 | if door_group.type != data_pb2.DoorGroupType.CYAN_DOORS: | ||
| 131 | continue | 282 | continue |
| 132 | 283 | ||
| 133 | door_item_name = self.world.static_logic.get_door_item_name(door) | 284 | for door in door_group.doors: |
| 134 | self.item_by_door[door.id] = (door_item_name, 1) | 285 | if not door in self.item_by_door: |
| 135 | self.real_items.append(door_item_name) | 286 | self.item_by_door[door] = (door_group.name, 1) |
| 287 | |||
| 288 | self.real_items.append(door_group.name) | ||
| 136 | 289 | ||
| 137 | for door in world.static_logic.objects.doors: | 290 | for door in world.static_logic.objects.doors: |
| 138 | if door.type in [data_pb2.DoorType.STANDARD, data_pb2.DoorType.LOCATION_ONLY, data_pb2.DoorType.GRAVESTONE]: | 291 | if door.type in [data_pb2.DoorType.STANDARD, data_pb2.DoorType.LOCATION_ONLY, data_pb2.DoorType.GRAVESTONE]: |
| @@ -190,6 +343,10 @@ class Lingo2PlayerLogic: | |||
| 190 | self.locations_by_room.setdefault(keyholder.room_id, []).append(PlayerLocation(keyholder.ap_id, | 343 | self.locations_by_room.setdefault(keyholder.room_id, []).append(PlayerLocation(keyholder.ap_id, |
| 191 | reqs)) | 344 | reqs)) |
| 192 | 345 | ||
| 346 | if self.world.options.shuffle_symbols: | ||
| 347 | for symbol_name in SYMBOL_ITEMS.values(): | ||
| 348 | self.real_items.append(symbol_name) | ||
| 349 | |||
| 193 | def get_panel_reqs(self, panel_id: int, answer: str | None) -> AccessRequirements: | 350 | def get_panel_reqs(self, panel_id: int, answer: str | None) -> AccessRequirements: |
| 194 | if answer is None: | 351 | if answer is None: |
| 195 | if panel_id not in self.panel_reqs: | 352 | if panel_id not in self.panel_reqs: |
| @@ -212,25 +369,35 @@ class Lingo2PlayerLogic: | |||
| 212 | self.add_solution_reqs(reqs, answer) | 369 | self.add_solution_reqs(reqs, answer) |
| 213 | elif len(panel.proxies) > 0: | 370 | elif len(panel.proxies) > 0: |
| 214 | possibilities = [] | 371 | possibilities = [] |
| 372 | already_filled = False | ||
| 215 | 373 | ||
| 216 | for proxy in panel.proxies: | 374 | for proxy in panel.proxies: |
| 217 | proxy_reqs = AccessRequirements() | 375 | proxy_reqs = AccessRequirements() |
| 218 | self.add_solution_reqs(proxy_reqs, proxy.answer) | 376 | self.add_solution_reqs(proxy_reqs, proxy.answer) |
| 219 | 377 | ||
| 220 | possibilities.append(proxy_reqs) | 378 | if not proxy_reqs.is_empty(): |
| 379 | possibilities.append(proxy_reqs) | ||
| 380 | else: | ||
| 381 | already_filled = True | ||
| 382 | break | ||
| 221 | 383 | ||
| 222 | if not any(proxy.answer == panel.answer for proxy in panel.proxies): | 384 | if not already_filled and not any(proxy.answer == panel.answer for proxy in panel.proxies): |
| 223 | proxy_reqs = AccessRequirements() | 385 | proxy_reqs = AccessRequirements() |
| 224 | self.add_solution_reqs(proxy_reqs, panel.answer) | 386 | self.add_solution_reqs(proxy_reqs, panel.answer) |
| 225 | 387 | ||
| 226 | possibilities.append(proxy_reqs) | 388 | if not proxy_reqs.is_empty(): |
| 389 | possibilities.append(proxy_reqs) | ||
| 390 | else: | ||
| 391 | already_filled = True | ||
| 227 | 392 | ||
| 228 | reqs.or_logic.append(possibilities) | 393 | if not already_filled: |
| 394 | reqs.or_logic.append(possibilities) | ||
| 229 | else: | 395 | else: |
| 230 | self.add_solution_reqs(reqs, panel.answer) | 396 | self.add_solution_reqs(reqs, panel.answer) |
| 231 | 397 | ||
| 232 | for symbol in panel.symbols: | 398 | if self.world.options.shuffle_symbols: |
| 233 | reqs.symbols.add(symbol) | 399 | for symbol in panel.symbols: |
| 400 | reqs.items.add(SYMBOL_ITEMS.get(symbol)) | ||
| 234 | 401 | ||
| 235 | if panel.HasField("required_door"): | 402 | if panel.HasField("required_door"): |
| 236 | door_reqs = self.get_door_open_reqs(panel.required_door) | 403 | door_reqs = self.get_door_open_reqs(panel.required_door) |
| @@ -253,18 +420,26 @@ class Lingo2PlayerLogic: | |||
| 253 | door = self.world.static_logic.objects.doors[door_id] | 420 | door = self.world.static_logic.objects.doors[door_id] |
| 254 | reqs = AccessRequirements() | 421 | reqs = AccessRequirements() |
| 255 | 422 | ||
| 256 | # TODO: lavender_cubes, endings | ||
| 257 | if not door.HasField("complete_at") or door.complete_at == 0: | 423 | if not door.HasField("complete_at") or door.complete_at == 0: |
| 258 | for proxy in door.panels: | 424 | for proxy in door.panels: |
| 259 | panel_reqs = self.get_panel_reqs(proxy.panel, proxy.answer if proxy.HasField("answer") else None) | 425 | panel_reqs = self.get_panel_reqs(proxy.panel, proxy.answer if proxy.HasField("answer") else None) |
| 260 | reqs.merge(panel_reqs) | 426 | reqs.merge(panel_reqs) |
| 261 | elif door.complete_at == 1: | 427 | elif door.complete_at == 1: |
| 262 | reqs.or_logic.append([self.get_panel_reqs(proxy.panel, | 428 | disjunction = [] |
| 263 | proxy.answer if proxy.HasField("answer") else None) | 429 | for proxy in door.panels: |
| 264 | for proxy in door.panels]) | 430 | proxy_reqs = self.get_panel_reqs(proxy.panel, proxy.answer if proxy.HasField("answer") else None) |
| 431 | if proxy_reqs.is_empty(): | ||
| 432 | disjunction.clear() | ||
| 433 | break | ||
| 434 | else: | ||
| 435 | disjunction.append(proxy_reqs) | ||
| 436 | if len(disjunction) > 0: | ||
| 437 | reqs.or_logic.append(disjunction) | ||
| 265 | else: | 438 | else: |
| 266 | # TODO: Handle complete_at > 1 | 439 | reqs.complete_at = door.complete_at |
| 267 | pass | 440 | for proxy in door.panels: |
| 441 | panel_reqs = self.get_panel_reqs(proxy.panel, proxy.answer if proxy.HasField("answer") else None) | ||
| 442 | reqs.possibilities.append(panel_reqs) | ||
| 268 | 443 | ||
| 269 | if door.HasField("control_center_color"): | 444 | if door.HasField("control_center_color"): |
| 270 | # TODO: Logic for ensuring two CC states aren't needed at once. | 445 | # TODO: Logic for ensuring two CC states aren't needed at once. |
| @@ -272,12 +447,14 @@ class Lingo2PlayerLogic: | |||
| 272 | self.add_solution_reqs(reqs, door.control_center_color) | 447 | self.add_solution_reqs(reqs, door.control_center_color) |
| 273 | 448 | ||
| 274 | if door.double_letters: | 449 | if door.double_letters: |
| 275 | if self.world.options.shuffle_letters in [ShuffleLetters.option_vanilla, | 450 | if self.world.options.cyan_door_behavior == CyanDoorBehavior.option_collect_h2: |
| 276 | ShuffleLetters.option_vanilla_cyan]: | ||
| 277 | reqs.rooms.add("The Repetitive - Main Room") | 451 | reqs.rooms.add("The Repetitive - Main Room") |
| 278 | elif self.world.options.shuffle_letters in [ShuffleLetters.option_progressive, | 452 | elif self.world.options.cyan_door_behavior == CyanDoorBehavior.option_any_double_letter: |
| 279 | ShuffleLetters.option_item_cyan]: | 453 | if self.world.options.shuffle_letters != ShuffleLetters.option_unlocked: |
| 280 | reqs.cyans = True | 454 | reqs.cyans = True |
| 455 | elif self.world.options.cyan_door_behavior == CyanDoorBehavior.option_item: | ||
| 456 | # There shouldn't be any locations that are cyan doors. | ||
| 457 | pass | ||
| 281 | 458 | ||
| 282 | for keyholder_uses in door.keyholders: | 459 | for keyholder_uses in door.keyholders: |
| 283 | key_name = keyholder_uses.key.upper() | 460 | key_name = keyholder_uses.key.upper() |
| @@ -293,12 +470,18 @@ class Lingo2PlayerLogic: | |||
| 293 | 470 | ||
| 294 | for ending_id in door.endings: | 471 | for ending_id in door.endings: |
| 295 | ending = self.world.static_logic.objects.endings[ending_id] | 472 | ending = self.world.static_logic.objects.endings[ending_id] |
| 296 | reqs.items.add(f"{ending.name.capitalize()} Ending (Achieved)") | 473 | |
| 474 | if self.world.options.victory_condition.current_key.removesuffix("_ending").upper() == ending.name: | ||
| 475 | reqs.items.add("Victory") | ||
| 476 | else: | ||
| 477 | reqs.items.add(f"{ending.name.capitalize()} Ending (Achieved)") | ||
| 297 | 478 | ||
| 298 | for sub_door_id in door.doors: | 479 | for sub_door_id in door.doors: |
| 299 | sub_reqs = self.get_door_open_reqs(sub_door_id) | 480 | sub_reqs = self.get_door_open_reqs(sub_door_id) |
| 300 | reqs.merge(sub_reqs) | 481 | reqs.merge(sub_reqs) |
| 301 | 482 | ||
| 483 | reqs.simplify() | ||
| 484 | |||
| 302 | return reqs | 485 | return reqs |
| 303 | 486 | ||
| 304 | # This gets the requirements to open a door within the world. When a door is shuffled, this means having the item | 487 | # This gets the requirements to open a door within the world. When a door is shuffled, this means having the item |
| diff --git a/apworld/regions.py b/apworld/regions.py index e30493c..fad9bc7 100644 --- a/apworld/regions.py +++ b/apworld/regions.py | |||
| @@ -11,12 +11,17 @@ if TYPE_CHECKING: | |||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | def create_region(room, world: "Lingo2World") -> Region: | 13 | def create_region(room, world: "Lingo2World") -> Region: |
| 14 | new_region = Region(world.static_logic.get_room_region_name(room.id), world.player, world.multiworld) | 14 | return Region(world.static_logic.get_room_region_name(room.id), world.player, world.multiworld) |
| 15 | 15 | ||
| 16 | |||
| 17 | def create_locations(room, new_region: Region, world: "Lingo2World", regions: dict[str, Region]): | ||
| 16 | for location in world.player_logic.locations_by_room.get(room.id, {}): | 18 | for location in world.player_logic.locations_by_room.get(room.id, {}): |
| 19 | reqs = location.reqs.copy() | ||
| 20 | reqs.remove_room(new_region.name) | ||
| 21 | |||
| 17 | new_location = Lingo2Location(world.player, world.static_logic.location_id_to_name[location.code], | 22 | new_location = Lingo2Location(world.player, world.static_logic.location_id_to_name[location.code], |
| 18 | location.code, new_region) | 23 | location.code, new_region) |
| 19 | new_location.access_rule = make_location_lambda(location.reqs, world) | 24 | new_location.access_rule = make_location_lambda(reqs, world, regions) |
| 20 | new_region.locations.append(new_location) | 25 | new_region.locations.append(new_location) |
| 21 | 26 | ||
| 22 | for event_name, item_name in world.player_logic.event_loc_item_by_room.get(room.id, {}).items(): | 27 | for event_name, item_name in world.player_logic.event_loc_item_by_room.get(room.id, {}).items(): |
| @@ -25,17 +30,23 @@ def create_region(room, world: "Lingo2World") -> Region: | |||
| 25 | new_location.place_locked_item(event_item) | 30 | new_location.place_locked_item(event_item) |
| 26 | new_region.locations.append(new_location) | 31 | new_region.locations.append(new_location) |
| 27 | 32 | ||
| 28 | return new_region | ||
| 29 | |||
| 30 | |||
| 31 | def create_regions(world: "Lingo2World"): | 33 | def create_regions(world: "Lingo2World"): |
| 32 | regions = { | 34 | regions = { |
| 33 | "Menu": Region("Menu", world.player, world.multiworld) | 35 | "Menu": Region("Menu", world.player, world.multiworld) |
| 34 | } | 36 | } |
| 35 | 37 | ||
| 38 | region_and_room = [] | ||
| 39 | |||
| 40 | # Create the regions in two stages. First, make the actual region objects and memoize them. Then, add all of the | ||
| 41 | # locations. This allows us to reference the actual region objects in the access rules for the locations, which is | ||
| 42 | # faster than having to look them up during access checking. | ||
| 36 | for room in world.static_logic.objects.rooms: | 43 | for room in world.static_logic.objects.rooms: |
| 37 | region = create_region(room, world) | 44 | region = create_region(room, world) |
| 38 | regions[region.name] = region | 45 | regions[region.name] = region |
| 46 | region_and_room.append((region, room)) | ||
| 47 | |||
| 48 | for (region, room) in region_and_room: | ||
| 49 | create_locations(room, region, world, regions) | ||
| 39 | 50 | ||
| 40 | regions["Menu"].connect(regions["The Entry - Starting Room"], "Start Game") | 51 | regions["Menu"].connect(regions["The Entry - Starting Room"], "Start Game") |
| 41 | 52 | ||
| @@ -46,6 +57,10 @@ def create_regions(world: "Lingo2World"): | |||
| 46 | 57 | ||
| 47 | from_region = world.static_logic.get_room_region_name(connection.from_room) | 58 | from_region = world.static_logic.get_room_region_name(connection.from_room) |
| 48 | to_region = world.static_logic.get_room_region_name(connection.to_room) | 59 | to_region = world.static_logic.get_room_region_name(connection.to_room) |
| 60 | |||
| 61 | if from_region not in regions or to_region not in regions: | ||
| 62 | continue | ||
| 63 | |||
| 49 | connection_name = f"{from_region} -> {to_region}" | 64 | connection_name = f"{from_region} -> {to_region}" |
| 50 | 65 | ||
| 51 | reqs = AccessRequirements() | 66 | reqs = AccessRequirements() |
| @@ -82,14 +97,16 @@ def create_regions(world: "Lingo2World"): | |||
| 82 | else: | 97 | else: |
| 83 | connection_name = f"{connection_name} (via panel {panel.name})" | 98 | connection_name = f"{connection_name} (via panel {panel.name})" |
| 84 | 99 | ||
| 85 | if from_region in regions and to_region in regions: | 100 | reqs.simplify() |
| 86 | connection = Entrance(world.player, connection_name, regions[from_region]) | 101 | reqs.remove_room(from_region) |
| 87 | connection.access_rule = make_location_lambda(reqs, world) | 102 | |
| 103 | connection = Entrance(world.player, connection_name, regions[from_region]) | ||
| 104 | connection.access_rule = make_location_lambda(reqs, world, regions) | ||
| 88 | 105 | ||
| 89 | regions[from_region].exits.append(connection) | 106 | regions[from_region].exits.append(connection) |
| 90 | connection.connect(regions[to_region]) | 107 | connection.connect(regions[to_region]) |
| 91 | 108 | ||
| 92 | for region in reqs.rooms: | 109 | for region in reqs.get_referenced_rooms(): |
| 93 | world.multiworld.register_indirect_condition(regions[region], connection) | 110 | world.multiworld.register_indirect_condition(regions[region], connection) |
| 94 | 111 | ||
| 95 | world.multiworld.regions += regions.values() | 112 | world.multiworld.regions += regions.values() |
| diff --git a/apworld/requirements.txt b/apworld/requirements.txt index b701d11..dbc395b 100644 --- a/apworld/requirements.txt +++ b/apworld/requirements.txt | |||
| @@ -1 +1 @@ | |||
| protobuf>=5.29.3 \ No newline at end of file | protobuf==3.20.3 | ||
| diff --git a/apworld/rules.py b/apworld/rules.py index 56486fa..c077858 100644 --- a/apworld/rules.py +++ b/apworld/rules.py | |||
| @@ -1,14 +1,15 @@ | |||
| 1 | from collections.abc import Callable | 1 | from collections.abc import Callable |
| 2 | from typing import TYPE_CHECKING | 2 | from typing import TYPE_CHECKING |
| 3 | 3 | ||
| 4 | from BaseClasses import CollectionState | 4 | from BaseClasses import CollectionState, Region |
| 5 | from .player_logic import AccessRequirements | 5 | from .player_logic import AccessRequirements |
| 6 | 6 | ||
| 7 | if TYPE_CHECKING: | 7 | if TYPE_CHECKING: |
| 8 | from . import Lingo2World | 8 | from . import Lingo2World |
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | def lingo2_can_satisfy_requirements(state: CollectionState, reqs: AccessRequirements, world: "Lingo2World") -> bool: | 11 | def lingo2_can_satisfy_requirements(state: CollectionState, reqs: AccessRequirements, regions: list[Region], |
| 12 | world: "Lingo2World") -> bool: | ||
| 12 | if not all(state.has(item, world.player) for item in reqs.items): | 13 | if not all(state.has(item, world.player) for item in reqs.items): |
| 13 | return False | 14 | return False |
| 14 | 15 | ||
| @@ -18,7 +19,8 @@ def lingo2_can_satisfy_requirements(state: CollectionState, reqs: AccessRequirem | |||
| 18 | if not all(state.can_reach_region(region_name, world.player) for region_name in reqs.rooms): | 19 | if not all(state.can_reach_region(region_name, world.player) for region_name in reqs.rooms): |
| 19 | return False | 20 | return False |
| 20 | 21 | ||
| 21 | # TODO: symbols | 22 | if not all(state.can_reach(region) for region in regions): |
| 23 | return False | ||
| 22 | 24 | ||
| 23 | for letter_key, letter_level in reqs.letters.items(): | 25 | for letter_key, letter_level in reqs.letters.items(): |
| 24 | if not state.has(letter_key, world.player, letter_level): | 26 | if not state.has(letter_key, world.player, letter_level): |
| @@ -30,11 +32,32 @@ def lingo2_can_satisfy_requirements(state: CollectionState, reqs: AccessRequirem | |||
| 30 | return False | 32 | return False |
| 31 | 33 | ||
| 32 | if len(reqs.or_logic) > 0: | 34 | if len(reqs.or_logic) > 0: |
| 33 | if not all(any(lingo2_can_satisfy_requirements(state, sub_reqs, world) for sub_reqs in subjunction) | 35 | if not all(any(lingo2_can_satisfy_requirements(state, sub_reqs, [], world) for sub_reqs in subjunction) |
| 34 | for subjunction in reqs.or_logic): | 36 | for subjunction in reqs.or_logic): |
| 35 | return False | 37 | return False |
| 36 | 38 | ||
| 39 | if reqs.complete_at is not None: | ||
| 40 | completed = 0 | ||
| 41 | checked = 0 | ||
| 42 | for possibility in reqs.possibilities: | ||
| 43 | checked += 1 | ||
| 44 | if lingo2_can_satisfy_requirements(state, possibility, [], world): | ||
| 45 | completed += 1 | ||
| 46 | if completed >= reqs.complete_at: | ||
| 47 | break | ||
| 48 | elif len(reqs.possibilities) - checked + completed < reqs.complete_at: | ||
| 49 | # There aren't enough remaining possibilities for the check to pass. | ||
| 50 | return False | ||
| 51 | if completed < reqs.complete_at: | ||
| 52 | return False | ||
| 53 | |||
| 37 | return True | 54 | return True |
| 38 | 55 | ||
| 39 | def make_location_lambda(reqs: AccessRequirements, world: "Lingo2World") -> Callable[[CollectionState], bool]: | 56 | def make_location_lambda(reqs: AccessRequirements, world: "Lingo2World", |
| 40 | return lambda state: lingo2_can_satisfy_requirements(state, reqs, world) | 57 | regions: dict[str, Region]) -> Callable[[CollectionState], bool]: |
| 58 | # Replace required rooms with regions for the top level requirement, which saves looking up the regions during rule | ||
| 59 | # checking. | ||
| 60 | required_regions = [regions[room_name] for room_name in reqs.rooms] | ||
| 61 | new_reqs = reqs.copy() | ||
| 62 | new_reqs.rooms.clear() | ||
| 63 | return lambda state: lingo2_can_satisfy_requirements(state, new_reqs, required_regions, world) | ||
| diff --git a/apworld/static_logic.py b/apworld/static_logic.py index b699d59..e4d7d49 100644 --- a/apworld/static_logic.py +++ b/apworld/static_logic.py | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | from .generated import data_pb2 as data_pb2 | 1 | from .generated import data_pb2 as data_pb2 |
| 2 | from .items import SYMBOL_ITEMS, ANTI_COLLECTABLE_TRAPS | ||
| 2 | import pkgutil | 3 | import pkgutil |
| 3 | 4 | ||
| 4 | class Lingo2StaticLogic: | 5 | class Lingo2StaticLogic: |
| @@ -8,9 +9,17 @@ class Lingo2StaticLogic: | |||
| 8 | item_name_to_id: dict[str, int] | 9 | item_name_to_id: dict[str, int] |
| 9 | location_name_to_id: dict[str, int] | 10 | location_name_to_id: dict[str, int] |
| 10 | 11 | ||
| 12 | item_name_groups: dict[str, list[str]] | ||
| 13 | location_name_groups: dict[str, list[str]] | ||
| 14 | |||
| 15 | letter_weights: dict[str, int] | ||
| 16 | |||
| 11 | def __init__(self): | 17 | def __init__(self): |
| 12 | self.item_id_to_name = {} | 18 | self.item_id_to_name = {} |
| 13 | self.location_id_to_name = {} | 19 | self.location_id_to_name = {} |
| 20 | self.item_name_groups = {} | ||
| 21 | self.location_name_groups = {} | ||
| 22 | self.letter_weights = {} | ||
| 14 | 23 | ||
| 15 | file = pkgutil.get_data(__name__, "generated/data.binpb") | 24 | file = pkgutil.get_data(__name__, "generated/data.binpb") |
| 16 | self.objects = data_pb2.AllObjects() | 25 | self.objects = data_pb2.AllObjects() |
| @@ -29,31 +38,49 @@ class Lingo2StaticLogic: | |||
| 29 | letter_name = f"{letter.key.upper()}{'2' if letter.level2 else '1'}" | 38 | letter_name = f"{letter.key.upper()}{'2' if letter.level2 else '1'}" |
| 30 | location_name = f"{self.get_room_object_map_name(letter)} - {letter_name}" | 39 | location_name = f"{self.get_room_object_map_name(letter)} - {letter_name}" |
| 31 | self.location_id_to_name[letter.ap_id] = location_name | 40 | self.location_id_to_name[letter.ap_id] = location_name |
| 41 | self.location_name_groups.setdefault("Letters", []).append(location_name) | ||
| 32 | 42 | ||
| 33 | if not letter.level2: | 43 | if not letter.level2: |
| 34 | self.item_id_to_name[letter.ap_id] = letter.key.upper() | 44 | self.item_id_to_name[letter.ap_id] = letter.key.upper() |
| 45 | self.item_name_groups.setdefault("Letters", []).append(letter.key.upper()) | ||
| 35 | 46 | ||
| 36 | for mastery in self.objects.masteries: | 47 | for mastery in self.objects.masteries: |
| 37 | location_name = f"{self.get_room_object_map_name(mastery)} - Mastery" | 48 | location_name = f"{self.get_room_object_map_name(mastery)} - Mastery" |
| 38 | self.location_id_to_name[mastery.ap_id] = location_name | 49 | self.location_id_to_name[mastery.ap_id] = location_name |
| 50 | self.location_name_groups.setdefault("Masteries", []).append(location_name) | ||
| 39 | 51 | ||
| 40 | for ending in self.objects.endings: | 52 | for ending in self.objects.endings: |
| 41 | location_name = f"{self.get_room_object_map_name(ending)} - {ending.name.title()} Ending" | 53 | location_name = f"{self.get_room_object_map_name(ending)} - {ending.name.title()} Ending" |
| 42 | self.location_id_to_name[ending.ap_id] = location_name | 54 | self.location_id_to_name[ending.ap_id] = location_name |
| 55 | self.location_name_groups.setdefault("Endings", []).append(location_name) | ||
| 43 | 56 | ||
| 44 | for progressive in self.objects.progressives: | 57 | for progressive in self.objects.progressives: |
| 45 | self.item_id_to_name[progressive.ap_id] = progressive.name | 58 | self.item_id_to_name[progressive.ap_id] = progressive.name |
| 46 | 59 | ||
| 60 | for door_group in self.objects.door_groups: | ||
| 61 | self.item_id_to_name[door_group.ap_id] = door_group.name | ||
| 62 | |||
| 47 | for keyholder in self.objects.keyholders: | 63 | for keyholder in self.objects.keyholders: |
| 48 | if keyholder.HasField("key"): | 64 | if keyholder.HasField("key"): |
| 49 | location_name = f"{self.get_room_object_location_prefix(keyholder)} - {keyholder.key.upper()} Keyholder" | 65 | location_name = f"{self.get_room_object_location_prefix(keyholder)} - {keyholder.key.upper()} Keyholder" |
| 50 | self.location_id_to_name[keyholder.ap_id] = location_name | 66 | self.location_id_to_name[keyholder.ap_id] = location_name |
| 67 | self.location_name_groups.setdefault("Keyholders", []).append(location_name) | ||
| 51 | 68 | ||
| 52 | self.item_id_to_name[self.objects.special_ids["A Job Well Done"]] = "A Job Well Done" | 69 | self.item_id_to_name[self.objects.special_ids["A Job Well Done"]] = "A Job Well Done" |
| 53 | 70 | ||
| 71 | for symbol_name in SYMBOL_ITEMS.values(): | ||
| 72 | self.item_id_to_name[self.objects.special_ids[symbol_name]] = symbol_name | ||
| 73 | |||
| 74 | for trap_name in ANTI_COLLECTABLE_TRAPS: | ||
| 75 | self.item_id_to_name[self.objects.special_ids[trap_name]] = trap_name | ||
| 76 | |||
| 54 | self.item_name_to_id = {name: ap_id for ap_id, name in self.item_id_to_name.items()} | 77 | self.item_name_to_id = {name: ap_id for ap_id, name in self.item_id_to_name.items()} |
| 55 | self.location_name_to_id = {name: ap_id for ap_id, name in self.location_id_to_name.items()} | 78 | self.location_name_to_id = {name: ap_id for ap_id, name in self.location_id_to_name.items()} |
| 56 | 79 | ||
| 80 | for panel in self.objects.panels: | ||
| 81 | for letter in panel.answer.upper(): | ||
| 82 | self.letter_weights[letter] = self.letter_weights.get(letter, 0) + 1 | ||
| 83 | |||
| 57 | def get_door_item_name(self, door: data_pb2.Door) -> str: | 84 | def get_door_item_name(self, door: data_pb2.Door) -> str: |
| 58 | return f"{self.get_map_object_map_name(door)} - {door.name}" | 85 | return f"{self.get_map_object_map_name(door)} - {door.name}" |
| 59 | 86 | ||
| @@ -77,7 +104,7 @@ class Lingo2StaticLogic: | |||
| 77 | if door.type != data_pb2.DoorType.STANDARD: | 104 | if door.type != data_pb2.DoorType.STANDARD: |
| 78 | return None | 105 | return None |
| 79 | 106 | ||
| 80 | if len(door.keyholders) > 0 or len(door.endings) > 0: | 107 | if len(door.keyholders) > 0 or len(door.endings) > 0 or door.HasField("complete_at"): |
| 81 | return None | 108 | return None |
| 82 | 109 | ||
| 83 | if len(door.panels) > 4: | 110 | if len(door.panels) > 4: |
| @@ -113,7 +140,7 @@ class Lingo2StaticLogic: | |||
| 113 | for panel_id in door.panels] | 140 | for panel_id in door.panels] |
| 114 | panel_names.sort() | 141 | panel_names.sort() |
| 115 | 142 | ||
| 116 | return f"{map_part} - {", ".join(panel_names)}" | 143 | return map_part + " - " + ", ".join(panel_names) |
| 117 | 144 | ||
| 118 | def get_door_location_name_by_id(self, door_id: int) -> str: | 145 | def get_door_location_name_by_id(self, door_id: int) -> str: |
| 119 | door = self.objects.doors[door_id] | 146 | door = self.objects.doors[door_id] |
| @@ -137,3 +164,6 @@ class Lingo2StaticLogic: | |||
| 137 | return f"{game_map.display_name} ({room.panel_display_name})" | 164 | return f"{game_map.display_name} ({room.panel_display_name})" |
| 138 | else: | 165 | else: |
| 139 | return game_map.display_name | 166 | return game_map.display_name |
| 167 | |||
| 168 | def get_data_version(self) -> int: | ||
| 169 | return self.objects.version | ||
| diff --git a/apworld/version.py b/apworld/version.py new file mode 100644 index 0000000..a0becae --- /dev/null +++ b/apworld/version.py | |||
| @@ -0,0 +1 @@ | |||
| APWORLD_VERSION = 5 | |||
