From 4ffb5871e4bc54ab6765fcd738835c295d1e2924 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 24 Jul 2024 13:36:07 -0400 Subject: Pilgrim Antechamber sunwarp now shows if pilgrimage is doable --- src/network_set.cpp | 13 +++++++++++++ src/network_set.h | 2 ++ src/subway_map.cpp | 20 +++++++++++++++++++- src/tracker_state.cpp | 13 +++++++++++++ src/tracker_state.h | 2 ++ 5 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/network_set.cpp b/src/network_set.cpp index 6d2a098..2a9e12c 100644 --- a/src/network_set.cpp +++ b/src/network_set.cpp @@ -21,6 +21,19 @@ void NetworkSet::AddLink(int id1, int id2) { network_by_item_[id2].insert({id1, id2}); } +void NetworkSet::AddLinkToNetwork(int network_id, int id1, int id2) { + if (id2 > id1) { + // Make sure id1 < id2 + std::swap(id1, id2); + } + + if (!network_by_item_.count(network_id)) { + network_by_item_[network_id] = {}; + } + + network_by_item_[network_id].insert({id1, id2}); +} + bool NetworkSet::IsItemInNetwork(int id) const { return network_by_item_.count(id); } diff --git a/src/network_set.h b/src/network_set.h index e6f0c07..cec3f39 100644 --- a/src/network_set.h +++ b/src/network_set.h @@ -13,6 +13,8 @@ class NetworkSet { void AddLink(int id1, int id2); + void AddLinkToNetwork(int network_id, int id1, int id2); + bool IsItemInNetwork(int id) const; const std::set>& GetNetworkGraph(int id) const; diff --git a/src/subway_map.cpp b/src/subway_map.cpp index 9bfedf9..e7ac317 100644 --- a/src/subway_map.cpp +++ b/src/subway_map.cpp @@ -107,7 +107,7 @@ void SubwayMap::OnConnect() { if (!AP_IsSunwarpShuffle() && subway_item.sunwarp && subway_item.sunwarp->type != SubwaySunwarpType::kFinal) { - std::string tag = fmt::format("subway{}", subway_item.sunwarp->dots); + std::string tag = fmt::format("sunwarp{}", subway_item.sunwarp->dots); tagged[tag].push_back(subway_item.id); } @@ -119,6 +119,9 @@ void SubwayMap::OnConnect() { } if (AP_IsSunwarpShuffle()) { + SubwaySunwarp final_sunwarp{.dots = 6, .type = SubwaySunwarpType::kFinal}; + int final_sunwarp_item = GD_GetSubwayItemForSunwarp(final_sunwarp); + for (const auto &[index, mapping] : AP_GetSunwarpMapping()) { std::string tag = fmt::format("sunwarp{}", mapping.dots); @@ -142,6 +145,11 @@ void SubwayMap::OnConnect() { tagged[tag].push_back(GD_GetSubwayItemForSunwarp(fromWarp)); tagged[tag].push_back(GD_GetSubwayItemForSunwarp(toWarp)); + + networks_.AddLinkToNetwork( + final_sunwarp_item, GD_GetSubwayItemForSunwarp(fromWarp), + mapping.dots == 6 ? final_sunwarp_item + : GD_GetSubwayItemForSunwarp(toWarp)); } } @@ -570,6 +578,16 @@ void SubwayMap::Redraw() { brush_color = wxRED_BRUSH; } } + } else if (subway_item.sunwarp && + subway_item.sunwarp->type == SubwaySunwarpType::kFinal && + AP_IsPilgrimageEnabled()) { + draw_type = ItemDrawType::kBox; + + if (IsPilgrimageDoable()) { + brush_color = wxGREEN_BRUSH; + } else { + brush_color = wxRED_BRUSH; + } } else if (!subway_item.paintings.empty()) { if (AP_IsPaintingShuffle()) { bool has_checked_painting = false; diff --git a/src/tracker_state.cpp b/src/tracker_state.cpp index bd63076..2ee705c 100644 --- a/src/tracker_state.cpp +++ b/src/tracker_state.cpp @@ -152,6 +152,7 @@ struct TrackerState { std::mutex reachability_mutex; RequirementCalculator requirements; std::map> door_reports; + bool pilgrimage_doable = false; }; enum Decision { kYes, kNo, kMaybe }; @@ -361,6 +362,8 @@ class StateCalculator { return door_report_; } + bool IsPilgrimageDoable() const { return pilgrimage_doable_; } + std::string GetPathToRoom(int room_id) const { if (!paths_.count(room_id)) { return ""; @@ -572,6 +575,8 @@ class StateCalculator { } } + pilgrimage_doable_ = true; + return kYes; } @@ -612,6 +617,7 @@ class StateCalculator { std::set solveable_panels_; std::set reachable_paintings_; std::map> door_report_; + bool pilgrimage_doable_ = false; std::map> paths_; }; @@ -663,6 +669,7 @@ void RecalculateReachability() { std::swap(GetState().reachable_doors, new_reachable_doors); std::swap(GetState().reachable_paintings, reachable_paintings); std::swap(GetState().door_reports, door_reports); + GetState().pilgrimage_doable = state_calculator.IsPilgrimageDoable(); } bool IsLocationReachable(int location_id) { @@ -692,3 +699,9 @@ const std::map& GetDoorRequirements(int door_id) { return GetState().door_reports[door_id]; } + +bool IsPilgrimageDoable() { + std::lock_guard reachability_guard(GetState().reachability_mutex); + + return GetState().pilgrimage_doable; +} diff --git a/src/tracker_state.h b/src/tracker_state.h index c7857a0..a8f155d 100644 --- a/src/tracker_state.h +++ b/src/tracker_state.h @@ -16,4 +16,6 @@ bool IsPaintingReachable(int painting_id); const std::map& GetDoorRequirements(int door_id); +bool IsPilgrimageDoable(); + #endif /* end of include guard: TRACKER_STATE_H_8639BC90 */ -- cgit 1.4.1