From dc4a14397ae226d91041389c2a47993f9c22f83d Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 3 May 2023 14:09:40 -0400 Subject: Added painting shuffle support --- ap_state.cpp | 13 +++++++++++++ ap_state.h | 9 +++++++++ game_data.cpp | 33 +++++++++++++++++++++++++++++++++ game_data.h | 13 +++++++++++++ tracker_state.cpp | 17 ++++++++++++++++- 5 files changed, 84 insertions(+), 1 deletion(-) diff --git a/ap_state.cpp b/ap_state.cpp index 2c8ba0a..8400557 100644 --- a/ap_state.cpp +++ b/ap_state.cpp @@ -56,6 +56,10 @@ void APState::Connect(std::string server, std::string player, inventory_.clear(); checked_locations_.clear(); + door_shuffle_mode_ = kNO_DOORS; + color_shuffle_ = false; + painting_shuffle_ = false; + painting_mapping_.clear(); bool connected = false; bool has_connection_result = false; @@ -103,6 +107,15 @@ void APState::Connect(std::string server, std::string player, door_shuffle_mode_ = slot_data["shuffle_doors"].get(); color_shuffle_ = slot_data["shuffle_colors"].get(); + painting_shuffle_ = slot_data["shuffle_paintings"].get(); + + if (painting_shuffle_ && slot_data.contains("painting_entrance_to_exit")) { + painting_mapping_.clear(); + + for (const auto& mapping_it : slot_data["painting_entrance_to_exit"].items()) { + painting_mapping_[mapping_it.key()] = mapping_it.value(); + } + } connected = true; has_connection_result = true; diff --git a/ap_state.h b/ap_state.h index 5ed7574..8f27a23 100644 --- a/ap_state.h +++ b/ap_state.h @@ -32,6 +32,12 @@ class APState { bool IsColorShuffle() const { return color_shuffle_; } + bool IsPaintingShuffle() const { return painting_shuffle_; } + + const std::map GetPaintingMapping() const { + return painting_mapping_; + } + private: void RefreshTracker(); @@ -51,6 +57,9 @@ class APState { DoorShuffleMode door_shuffle_mode_ = kNO_DOORS; bool color_shuffle_ = false; + bool painting_shuffle_ = false; + + std::map painting_mapping_; }; APState& GetAPState(); diff --git a/game_data.cpp b/game_data.cpp index 80ffd97..2f8f505 100644 --- a/game_data.cpp +++ b/game_data.cpp @@ -63,6 +63,10 @@ GameData::GameData() { door_room, entrance_it.second["door"].as()); } + if (entrance_it.second["painting"]) { + exit_obj.painting = entrance_it.second["painting"].as(); + } + from_room_obj.exits.push_back(exit_obj); break; } @@ -78,6 +82,10 @@ GameData::GameData() { exit_obj.door = AddOrGetDoor(door_room, option["door"].as()); + if (option["painting"]) { + exit_obj.painting = option["painting"].as(); + } + from_room_obj.exits.push_back(exit_obj); } @@ -225,6 +233,31 @@ GameData::GameData() { } } } + + if (room_it.second["paintings"]) { + for (const auto& painting : room_it.second["paintings"]) { + std::string painting_id = painting["id"].as(); + room_by_painting_[painting_id] = room_id; + + if (!painting["exit_only"] || !painting["exit_only"].as()) { + PaintingExit painting_exit; + painting_exit.id = painting_id; + + if (painting["required_door"]) { + std::string rd_room = room_obj.name; + if (painting["required_door"]["room"]) { + rd_room = painting["required_door"]["room"].as(); + } + + painting_exit.door = AddOrGetDoor( + rd_room, + painting["required_door"]["door"].as()); + } + + room_obj.paintings.push_back(painting_exit); + } + } + } } map_areas_.reserve(areas_config.size()); diff --git a/game_data.h b/game_data.h index 6ee277b..981f56f 100644 --- a/game_data.h +++ b/game_data.h @@ -45,11 +45,18 @@ struct Door { struct Exit { int destination_room; std::optional door; + bool painting = false; +}; + +struct PaintingExit { + std::string id; + std::optional door; }; struct Room { std::string name; std::vector exits; + std::vector paintings; }; struct Location { @@ -87,6 +94,10 @@ class GameData { const Panel& GetPanel(int panel_id) const { return panels_.at(panel_id); } + int GetRoomForPainting(const std::string& painting_id) const { + return room_by_painting_.at(painting_id); + } + private: int AddOrGetRoom(std::string room); int AddOrGetDoor(std::string room, std::string door); @@ -102,6 +113,8 @@ class GameData { std::map door_by_id_; std::map panel_by_id_; std::map area_by_id_; + + std::map room_by_painting_; }; const GameData& GetGameData(); diff --git a/tracker_state.cpp b/tracker_state.cpp index a84dd6e..169d301 100644 --- a/tracker_state.cpp +++ b/tracker_state.cpp @@ -99,7 +99,22 @@ void TrackerState::CalculateState() { const Room& room_obj = GetGameData().GetRoom(room_exit.destination_room); for (const Exit& out_edge : room_obj.exits) { - new_boundary.push_back(out_edge); + if (!out_edge.painting || !GetAPState().IsPaintingShuffle()) { + new_boundary.push_back(out_edge); + } + } + + if (GetAPState().IsPaintingShuffle()) { + for (const PaintingExit& out_edge : room_obj.paintings) { + if (GetAPState().GetPaintingMapping().count(out_edge.id)) { + Exit painting_exit; + painting_exit.destination_room = GetGameData().GetRoomForPainting( + GetAPState().GetPaintingMapping().at(out_edge.id)); + painting_exit.door = out_edge.door; + + new_boundary.push_back(painting_exit); + } + } } } } -- cgit 1.4.1