From a3972a65b9b443a6085a6ac40b153442e190f382 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 1 Sep 2025 12:54:46 -0400 Subject: Added progressive doors --- apworld/player_logic.py | 27 ++++++++++++++-- apworld/rules.py | 3 ++ apworld/static_logic.py | 3 ++ data/ids.yaml | 3 ++ data/progressives.txtpb | 22 +++++++++++++ proto/data.proto | 8 +++++ proto/human.proto | 10 ++++++ tools/assign_ids/main.cpp | 64 ++++++++++++++++++------------------- tools/datapacker/container.cpp | 17 ++++++++++ tools/datapacker/container.h | 3 ++ tools/datapacker/main.cpp | 33 +++++++++++++++++-- tools/util/ids_yaml_format.cpp | 12 +++++++ tools/validator/human_processor.cpp | 28 ++++++++++++++++ tools/validator/structs.h | 8 +++++ tools/validator/validator.cpp | 16 ++++++++++ 15 files changed, 219 insertions(+), 38 deletions(-) create mode 100644 data/progressives.txtpb diff --git a/apworld/player_logic.py b/apworld/player_logic.py index c6465f6..e08f644 100644 --- a/apworld/player_logic.py +++ b/apworld/player_logic.py @@ -23,6 +23,7 @@ def calculate_letter_histogram(solution: str) -> dict[str, int]: class AccessRequirements: items: set[str] + progressives: dict[str, int] rooms: set[str] symbols: set[str] letters: dict[str, int] @@ -32,6 +33,7 @@ class AccessRequirements: def __init__(self): self.items = set() + self.progressives = dict() self.rooms = set() self.symbols = set() self.letters = dict() @@ -47,6 +49,9 @@ class AccessRequirements: for item in other.items: self.items.add(item) + for item, amount in other.progressives.items(): + self.progressives[item] = max(amount, self.progressives.get(item, 0)) + for room in other.rooms: self.rooms.add(room) @@ -63,6 +68,8 @@ class AccessRequirements: parts = [] if len(self.items) > 0: parts.append(f"items={self.items}") + if len(self.progressives) > 0: + parts.append(f"progressives={self.progressives}") if len(self.rooms) > 0: parts.append(f"rooms={self.rooms}") if len(self.symbols) > 0: @@ -85,7 +92,7 @@ class Lingo2PlayerLogic: locations_by_room: dict[int, list[PlayerLocation]] event_loc_item_by_room: dict[int, dict[str, str]] - item_by_door: dict[int, str] + item_by_door: dict[int, tuple[str, int]] panel_reqs: dict[int, AccessRequirements] proxy_reqs: dict[int, dict[str, AccessRequirements]] @@ -103,12 +110,21 @@ class Lingo2PlayerLogic: self.door_reqs = dict() self.real_items = list() + if self.world.options.shuffle_doors: + for progressive in world.static_logic.objects.progressives: + for i in range(0, len(progressive.doors)): + self.item_by_door[progressive.doors[i]] = (progressive.name, i + 1) + self.real_items.append(progressive.name) + # We iterate through the doors in two parts because it is essential that we determine which doors are shuffled # before we calculate any access requirements. for door in world.static_logic.objects.doors: if door.type in [data_pb2.DoorType.STANDARD, data_pb2.DoorType.ITEM_ONLY] and self.world.options.shuffle_doors: + if door.id in self.item_by_door: + continue + door_item_name = self.world.static_logic.get_door_item_name(door) - self.item_by_door[door.id] = door_item_name + self.item_by_door[door.id] = (door_item_name, 1) self.real_items.append(door_item_name) for door in world.static_logic.objects.doors: @@ -261,7 +277,12 @@ class Lingo2PlayerLogic: def get_door_open_reqs(self, door_id: int) -> AccessRequirements: if door_id in self.item_by_door: reqs = AccessRequirements() - reqs.items.add(self.item_by_door.get(door_id)) + + item_name, amount = self.item_by_door.get(door_id) + if amount == 1: + reqs.items.add(item_name) + else: + reqs.progressives[item_name] = amount return reqs else: diff --git a/apworld/rules.py b/apworld/rules.py index 4a84acf..5e20de5 100644 --- a/apworld/rules.py +++ b/apworld/rules.py @@ -12,6 +12,9 @@ def lingo2_can_satisfy_requirements(state: CollectionState, reqs: AccessRequirem if not all(state.has(item, world.player) for item in reqs.items): return False + if not all(state.has(item, world.player, amount) for item, amount in reqs.progressives.items()): + return False + if not all(state.can_reach_region(region_name, world.player) for region_name in reqs.rooms): return False diff --git a/apworld/static_logic.py b/apworld/static_logic.py index ff1f17d..0613474 100644 --- a/apworld/static_logic.py +++ b/apworld/static_logic.py @@ -41,6 +41,9 @@ class Lingo2StaticLogic: location_name = f"{self.get_room_object_map_name(ending)} - {ending.name.title()} Ending" self.location_id_to_name[ending.ap_id] = location_name + for progressive in self.objects.progressives: + self.item_id_to_name[progressive.ap_id] = progressive.name + self.item_id_to_name[self.objects.special_ids["Nothing"]] = "Nothing" self.item_name_to_id = {name: ap_id for ap_id, name in self.item_id_to_name.items()} diff --git a/data/ids.yaml b/data/ids.yaml index 1184bfd..3aff6ea 100644 --- a/data/ids.yaml +++ b/data/ids.yaml @@ -3800,3 +3800,6 @@ endings: YELLOW: 1206 special: Nothing: 1160 +progressives: + Progressive Gold Ending: 2753 + Progressive Symbolic Entrance: 2752 diff --git a/data/progressives.txtpb b/data/progressives.txtpb new file mode 100644 index 0000000..cacb968 --- /dev/null +++ b/data/progressives.txtpb @@ -0,0 +1,22 @@ +progressives { + name: "Progressive Symbolic Entrance" + doors { map: "the_symbolic" name: "White Door" } + doors { map: "the_symbolic" name: "Black Door" } + doors { map: "the_symbolic" name: "Red Door" } + doors { map: "the_symbolic" name: "Blue Door" } + doors { map: "the_symbolic" name: "Green Door" } + doors { map: "the_symbolic" name: "Yellow Door" } + doors { map: "the_symbolic" name: "Purple Door" } + doors { map: "the_symbolic" name: "Orange Door" } +} +progressives { + name: "Progressive Gold Ending" + doors { map: "daedalus" name: "Red Rainbow Room" } + doors { map: "daedalus" name: "Orange Rainbow Room" } + doors { map: "daedalus" name: "Yellow Rainbow Room" } + doors { map: "daedalus" name: "Green Rainbow Room" } + doors { map: "daedalus" name: "Blue Rainbow Room" } + doors { map: "daedalus" name: "Purple Rainbow Room" } + doors { map: "daedalus" name: "Cyan Rainbow Room" } + doors { map: "daedalus" name: "Brown Rainbow Room" } +} diff --git a/proto/data.proto b/proto/data.proto index 60b603b..b627e83 100644 --- a/proto/data.proto +++ b/proto/data.proto @@ -221,6 +221,13 @@ message Map { optional string display_name = 3; } +message Progressive { + optional uint64 id = 1; + optional string name = 2; + optional uint64 ap_id = 3; + repeated uint64 doors = 4; +} + message AllObjects { repeated Map maps = 7; repeated Room rooms = 1; @@ -233,5 +240,6 @@ message AllObjects { repeated Mastery masteries = 10; repeated Ending endings = 12; repeated Connection connections = 6; + repeated Progressive progressives = 13; map special_ids = 8; } diff --git a/proto/human.proto b/proto/human.proto index c7e2f5d..8d882da 100644 --- a/proto/human.proto +++ b/proto/human.proto @@ -183,6 +183,15 @@ message HumanMap { repeated string excluded_nodes = 2; } +message HumanProgressive { + optional string name = 1; + repeated DoorIdentifier doors = 2; +} + +message HumanProgressives { + repeated HumanProgressive progressives = 1; +} + message IdMappings { message RoomIds { map panels = 1; @@ -198,4 +207,5 @@ message IdMappings { map special = 2; map letters = 3; map endings = 4; + map progressives = 5; } diff --git a/tools/assign_ids/main.cpp b/tools/assign_ids/main.cpp index e65e5e4..3a2f347 100644 --- a/tools/assign_ids/main.cpp +++ b/tools/assign_ids/main.cpp @@ -40,6 +40,7 @@ class AssignIds { ReadIds(ids_path); ProcessMaps(datadir_path); + ProcessProgressivesFile(datadir_path / "progressives.txtpb"); WriteIds(ids_path); @@ -54,44 +55,18 @@ class AssignIds { id_mappings_ = ReadIdsFromYaml(path.string()); for (const auto& [_, map] : id_mappings_.maps()) { - for (const auto& [_, id] : map.doors()) { - if (id > next_id_) { - next_id_ = id; - } - } + UpdateNextId(map.doors()); for (const auto& [_, room] : map.rooms()) { - for (const auto& [_, id] : room.panels()) { - if (id > next_id_) { - next_id_ = id; - } - } - - for (const auto& [_, id] : room.masteries()) { - if (id > next_id_) { - next_id_ = id; - } - } - } - } - - for (const auto& [_, id] : id_mappings_.special()) { - if (id > next_id_) { - next_id_ = id; + UpdateNextId(room.panels()); + UpdateNextId(room.masteries()); } } - for (const auto& [_, id] : id_mappings_.letters()) { - if (id > next_id_) { - next_id_ = id; - } - } - - for (const auto& [_, id] : id_mappings_.endings()) { - if (id > next_id_) { - next_id_ = id; - } - } + UpdateNextId(id_mappings_.special()); + UpdateNextId(id_mappings_.letters()); + UpdateNextId(id_mappings_.endings()); + UpdateNextId(id_mappings_.progressives()); next_id_++; } @@ -210,7 +185,30 @@ class AssignIds { } } + void ProcessProgressivesFile(std::filesystem::path path) { + if (!std::filesystem::exists(path)) { + return; + } + + auto h_progs = ReadMessageFromFile(path.string()); + auto& progs = *id_mappings_.mutable_progressives(); + + for (const HumanProgressive& h_prog : h_progs.progressives()) { + if (!progs.contains(h_prog.name())) { + progs[h_prog.name()] = next_id_++; + } + } + } + private: + void UpdateNextId(const google::protobuf::Map& ids) { + for (const auto& [_, id] : ids) { + if (id > next_id_) { + next_id_ = id; + } + } + } + std::string mapdir_; uint64_t next_id_ = 1; diff --git a/tools/datapacker/container.cpp b/tools/datapacker/container.cpp index 2c68552..624caf8 100644 --- a/tools/datapacker/container.cpp +++ b/tools/datapacker/container.cpp @@ -331,6 +331,23 @@ uint64_t Container::FindOrAddDoor(std::optional map_name, } } +uint64_t Container::FindOrAddProgressive(std::string prog_name) { + auto it = progressive_id_by_name_.find(prog_name); + + if (it == progressive_id_by_name_.end()) { + uint64_t new_id = all_objects_.progressives_size(); + Progressive* progressive = all_objects_.add_progressives(); + progressive->set_id(new_id); + progressive->set_name(prog_name); + + progressive_id_by_name_[prog_name] = new_id; + + return new_id; + } else { + return it->second; + } +} + void Container::AddConnection(const Connection& connection) { *all_objects_.add_connections() = connection; } diff --git a/tools/datapacker/container.h b/tools/datapacker/container.h index 68f5875..8cec560 100644 --- a/tools/datapacker/container.h +++ b/tools/datapacker/container.h @@ -60,6 +60,8 @@ class Container { void AddConnection(const Connection& connection); + uint64_t FindOrAddProgressive(std::string prog_name); + AllObjects& all_objects() { return all_objects_; } private: @@ -82,6 +84,7 @@ class Container { std::map> door_id_by_map_door_names_; std::map ending_id_by_name_; + std::map progressive_id_by_name_; }; } // namespace com::fourisland::lingo2_archipelago diff --git a/tools/datapacker/main.cpp b/tools/datapacker/main.cpp index 4923fce..5ed82cc 100644 --- a/tools/datapacker/main.cpp +++ b/tools/datapacker/main.cpp @@ -43,6 +43,7 @@ class DataPacker { ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt); ProcessMaps(datadir_path); + ProcessProgressivesFile(datadir_path / "progressives.txtpb"); ProcessIdsFile(datadir_path / "ids.yaml"); { @@ -104,7 +105,7 @@ class DataPacker { container_.FindOrAddRoom(current_map_name, h_room.name(), std::nullopt); Room& room = *container_.all_objects().mutable_rooms(room_id); - //room.set_display_name(h_room.display_name()); + // room.set_display_name(h_room.display_name()); if (h_room.has_panel_display_name()) { room.set_panel_display_name(h_room.panel_display_name()); @@ -388,7 +389,7 @@ class DataPacker { door.add_doors( container_.FindOrAddDoor(map_name, di.name(), current_map_name)); } - + for (const std::string& ending_name : h_door.endings()) { door.add_endings(container_.FindOrAddEnding(ending_name)); } @@ -544,6 +545,29 @@ class DataPacker { } } + void ProcessProgressivesFile(std::filesystem::path path) { + if (!std::filesystem::exists(path)) { + return; + } + + auto h_progs = ReadMessageFromFile(path.string()); + + for (const HumanProgressive& h_prog : h_progs.progressives()) { + ProcessProgressive(h_prog); + } + } + + void ProcessProgressive(const HumanProgressive& h_prog) { + uint64_t prog_id = container_.FindOrAddProgressive(h_prog.name()); + Progressive& prog = *container_.all_objects().mutable_progressives(prog_id); + + for (const DoorIdentifier& di : h_prog.doors()) { + uint64_t door_id = + container_.FindOrAddDoor(di.map(), di.name(), std::nullopt); + prog.add_doors(door_id); + } + } + void ProcessIdsFile(std::filesystem::path path) { auto ids = ReadIdsFromYaml(path.string()); @@ -585,6 +609,11 @@ class DataPacker { uint64_t ending_id = container_.FindOrAddEnding(ending_name); container_.all_objects().mutable_endings(ending_id)->set_ap_id(ap_id); } + + for (const auto& [prog_name, ap_id] : ids.progressives()) { + uint64_t prog_id = container_.FindOrAddProgressive(prog_name); + container_.all_objects().mutable_progressives(prog_id)->set_ap_id(ap_id); + } } std::string mapdir_; diff --git a/tools/util/ids_yaml_format.cpp b/tools/util/ids_yaml_format.cpp index f72f60e..ae62073 100644 --- a/tools/util/ids_yaml_format.cpp +++ b/tools/util/ids_yaml_format.cpp @@ -89,6 +89,13 @@ IdMappings ReadIdsFromYaml(const std::string& filename) { } } + if (document["progressives"]) { + for (const auto& prog_it : document["progressives"]) { + (*result.mutable_progressives())[prog_it.first.as()] = + prog_it.second.as(); + } + } + return result; } @@ -144,6 +151,11 @@ void WriteIdsAsYaml(const IdMappings& ids, const std::string& filename) { result["special"][special_name] = special_id; }); + OperateOnSortedMap(ids.progressives(), + [&result](const std::string& prog_name, uint64_t prog_id) { + result["progressives"][prog_name] = prog_id; + }); + std::ofstream output_stream(filename); output_stream << result << std::endl; } diff --git a/tools/validator/human_processor.cpp b/tools/validator/human_processor.cpp index 0f63936..49e7578 100644 --- a/tools/validator/human_processor.cpp +++ b/tools/validator/human_processor.cpp @@ -41,6 +41,7 @@ class HumanProcessor { ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt); ProcessMaps(datadir_path); + ProcessProgressivesFile(datadir_path / "progressives.txtpb"); ProcessIdsFile(datadir_path / "ids.txtpb"); } @@ -481,6 +482,33 @@ class HumanProcessor { } } + void ProcessProgressivesFile(std::filesystem::path path) { + if (!std::filesystem::exists(path)) { + return; + } + + auto h_progs = ReadMessageFromFile(path.string()); + + for (const HumanProgressive& h_prog : h_progs.progressives()) { + ProcessProgressive(h_prog); + } + } + + void ProcessProgressive(const HumanProgressive& h_prog) { + ProgressiveInfo& prog_info = info_.progressives[h_prog.name()]; + prog_info.definitions.push_back(h_prog); + + for (const DoorIdentifier& di : h_prog.doors()) { + if (!di.has_map()) { + prog_info.malformed_doors.push_back(di); + continue; + } + + DoorInfo& door_info = info_.doors[di]; + door_info.progressives_referenced_by.push_back(h_prog.name()); + } + } + void ProcessIdsFile(std::filesystem::path path) { // Ignore this for now. } diff --git a/tools/validator/structs.h b/tools/validator/structs.h index 0ca96fe..717fccf 100644 --- a/tools/validator/structs.h +++ b/tools/validator/structs.h @@ -45,6 +45,7 @@ struct DoorInfo { std::vector panels_referenced_by; std::vector paintings_referenced_by; std::vector ports_referenced_by; + std::vector progressives_referenced_by; MalformedIdentifiers malformed_identifiers; }; @@ -102,6 +103,12 @@ struct PanelNameInfo { std::vector panels_used_by; }; +struct ProgressiveInfo { + std::vector definitions; + + std::vector malformed_doors; +}; + struct CollectedInfo { std::map maps; std::map rooms; @@ -114,6 +121,7 @@ struct CollectedInfo { std::map letters; std::map endings; std::map panel_names; + std::map progressives; }; } // namespace com::fourisland::lingo2_archipelago diff --git a/tools/validator/validator.cpp b/tools/validator/validator.cpp index 9c66e09..fd004d7 100644 --- a/tools/validator/validator.cpp +++ b/tools/validator/validator.cpp @@ -45,6 +45,9 @@ class Validator { for (const auto& [panel_name, panel_info] : info_.panel_names) { ValidatePanelName(panel_name, panel_info); } + for (const auto& [prog_name, prog_info] : info_.progressives) { + ValidateProgressive(prog_name, prog_info); + } } private: @@ -164,6 +167,11 @@ class Validator { std::cout << " CONNECTION " << connection.ShortDebugString() << std::endl; } + + for (const std::string& prog_name : + door_info.progressives_referenced_by) { + std::cout << " PROGRESSIVE " << prog_name << std::endl; + } } else if (door_info.definitions.size() > 1) { std::cout << "Door " << door_identifier.ShortDebugString() << " was defined multiple times." << std::endl; @@ -369,6 +377,14 @@ class Validator { } } + void ValidateProgressive(const std::string& prog_name, + const ProgressiveInfo& prog_info) const { + if (prog_info.definitions.size() > 1) { + std::cout << "Progressive \"" << prog_name + << "\" has multiple definitions." << std::endl; + } + } + const CollectedInfo& info_; }; -- cgit 1.4.1