From 1ec273825497fd6feda19079fa8006096777b11d Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 2 May 2023 21:00:00 -0400 Subject: Support door shuffle --- ap_state.cpp | 24 +++++++++++++++++++----- ap_state.h | 9 +++++---- game_data.cpp | 5 +++++ game_data.h | 3 +++ tracker_state.cpp | 34 +++++++++++++++------------------- 5 files changed, 47 insertions(+), 28 deletions(-) diff --git a/ap_state.cpp b/ap_state.cpp index 9df487f..910feb7 100644 --- a/ap_state.cpp +++ b/ap_state.cpp @@ -17,11 +17,6 @@ constexpr int AP_REVISION = 0; constexpr int ITEM_HANDLING = 7; // <- all -NLOHMANN_JSON_SERIALIZE_ENUM(DoorShuffleMode, - {{DoorShuffleMode::kNone, "none"}, - {DoorShuffleMode::kSimple, "simple"}, - {DoorShuffleMode::kComplex, "complex"}}); - APState::APState() { std::thread([this]() { for (;;) { @@ -178,6 +173,17 @@ void APState::Connect(std::string server, std::string player, } } + for (const Door& door : GetGameData().GetDoors()) { + if (!door.skip_item) { + ap_id_by_item_name_[door.item_name] = GetItemId(door.item_name); + + if (!door.group_name.empty() && + !ap_id_by_item_name_.count(door.group_name)) { + ap_id_by_item_name_[door.group_name] = GetItemId(door.group_name); + } + } + } + ap_id_by_color_[LingoColor::kBlack] = GetItemId("Black"); ap_id_by_color_[LingoColor::kRed] = GetItemId("Red"); ap_id_by_color_[LingoColor::kBlue] = GetItemId("Blue"); @@ -212,6 +218,14 @@ bool APState::HasColorItem(LingoColor color) const { } } +bool APState::HasItem(const std::string& item) const { + if (ap_id_by_item_name_.count(item)) { + return inventory_.count(ap_id_by_item_name_.at(item)); + } else { + return false; + } +} + void APState::RefreshTracker() { GetTrackerState().CalculateState(); tracker_frame_->UpdateIndicators(); diff --git a/ap_state.h b/ap_state.h index d818b40..d815f93 100644 --- a/ap_state.h +++ b/ap_state.h @@ -11,7 +11,7 @@ #include "game_data.h" #include "tracker_frame.h" -enum class DoorShuffleMode { kNone, kSimple, kComplex }; +enum DoorShuffleMode { kNO_DOORS = 0, kSIMPLE_DOORS = 1, kCOMPLEX_DOORS = 2 }; class APState { public: @@ -27,6 +27,8 @@ class APState { bool HasColorItem(LingoColor color) const; + bool HasItem(const std::string& item) const; + DoorShuffleMode GetDoorShuffleMode() const { return door_shuffle_mode_; } bool IsColorShuffle() const { return color_shuffle_; } @@ -46,11 +48,10 @@ class APState { std::set checked_locations_; std::map, int64_t> ap_id_by_location_id_; - std::map ap_id_by_door_id_; - std::map ap_id_by_door_group_id_; + std::map ap_id_by_item_name_; std::map ap_id_by_color_; - DoorShuffleMode door_shuffle_mode_ = DoorShuffleMode::kNone; + DoorShuffleMode door_shuffle_mode_ = kNO_DOORS; bool color_shuffle_ = false; }; diff --git a/game_data.cpp b/game_data.cpp index af5f665..b1504de 100644 --- a/game_data.cpp +++ b/game_data.cpp @@ -183,8 +183,13 @@ GameData::GameData() { door_obj.skip_location = door_it.second["skip_location"].as(); } + if (door_it.second["skip_item"]) { + door_obj.skip_item = door_it.second["skip_item"].as(); + } + if (door_it.second["event"]) { door_obj.skip_location = door_it.second["event"].as(); + door_obj.skip_item = door_it.second["event"].as(); } if (door_it.second["item_name"]) { diff --git a/game_data.h b/game_data.h index ec3e94d..3c50b68 100644 --- a/game_data.h +++ b/game_data.h @@ -36,6 +36,7 @@ struct Door { std::string item_name; std::string group_name; bool skip_location = false; + bool skip_item = false; std::vector panels; bool exclude_reduce = true; }; @@ -79,6 +80,8 @@ class GameData { const Room& GetRoom(int room_id) const { return rooms_.at(room_id); } + const std::vector& GetDoors() const { return doors_; } + const Door& GetDoor(int door_id) const { return doors_.at(door_id); } const Panel& GetPanel(int panel_id) const { return panels_.at(panel_id); } diff --git a/tracker_state.cpp b/tracker_state.cpp index 62e4612..a84dd6e 100644 --- a/tracker_state.cpp +++ b/tracker_state.cpp @@ -42,26 +42,23 @@ bool IsPanelReachable_Helper(int panel_id, bool IsDoorReachable_Helper(int door_id, const std::set& reachable_rooms) { const Door& door_obj = GetGameData().GetDoor(door_id); - switch (GetAPState().GetDoorShuffleMode()) { - case DoorShuffleMode::kNone: { - if (!reachable_rooms.count(door_obj.room)) { - return false; - } + if (GetAPState().GetDoorShuffleMode() == kNO_DOORS || door_obj.skip_item) { + if (!reachable_rooms.count(door_obj.room)) { + return false; + } - for (int panel_id : door_obj.panels) { - if (!IsPanelReachable_Helper(panel_id, reachable_rooms)) { - return false; - } + for (int panel_id : door_obj.panels) { + if (!IsPanelReachable_Helper(panel_id, reachable_rooms)) { + return false; } - - return true; - } - case DoorShuffleMode::kSimple: { - break; - } - case DoorShuffleMode::kComplex: { - break; } + + return true; + } else if (GetAPState().GetDoorShuffleMode() == kSIMPLE_DOORS && + !door_obj.group_name.empty()) { + return GetAPState().HasItem(door_obj.group_name); + } else { + return GetAPState().HasItem(door_obj.item_name); } } @@ -88,8 +85,7 @@ void TrackerState::CalculateState() { if (room_exit.door.has_value()) { if (IsDoorReachable_Helper(*room_exit.door, reachable_rooms)) { valid_transition = true; - } else if (GetAPState().GetDoorShuffleMode() == - DoorShuffleMode::kNone) { + } else if (GetAPState().GetDoorShuffleMode() == kNO_DOORS) { new_boundary.push_back(room_exit); } } else { -- cgit 1.4.1