From ea16cff14ff4faf5782da8ff684a6ec412b7b6ac Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sun, 12 May 2024 17:48:02 -0400 Subject: Started making subway map --- src/tracker_state.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/tracker_state.h') diff --git a/src/tracker_state.h b/src/tracker_state.h index e73607f..119b3b5 100644 --- a/src/tracker_state.h +++ b/src/tracker_state.h @@ -5,4 +5,6 @@ void RecalculateReachability(); bool IsLocationReachable(int location_id); +bool IsDoorOpen(int door_id); + #endif /* end of include guard: TRACKER_STATE_H_8639BC90 */ -- cgit 1.4.1 From 4d8e36245e8ce43eef9b687a9108fd4c353f756f Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Thu, 16 May 2024 17:06:33 -0400 Subject: Added door popups that report requirements --- src/ap_state.cpp | 7 ++ src/ap_state.h | 2 + src/subway_map.cpp | 181 ++++++++++++++++++++--------- src/subway_map.h | 2 + src/tracker_state.cpp | 314 ++++++++++++++++++++++++++++++++++++-------------- src/tracker_state.h | 7 ++ 6 files changed, 377 insertions(+), 136 deletions(-) (limited to 'src/tracker_state.h') diff --git a/src/ap_state.cpp b/src/ap_state.cpp index f245c2b..20245e5 100644 --- a/src/ap_state.cpp +++ b/src/ap_state.cpp @@ -271,6 +271,7 @@ struct APState { connected = true; has_connection_result = true; + ResetReachabilityRequirements(); RefreshTracker(true); std::list corrected_keys; @@ -447,6 +448,8 @@ struct APState { return ap_id; } + std::string GetItemName(int id) { return apclient->get_item_name(id); } + bool HasReachedGoal() { return data_storage.count(victory_data_storage_key) && std::any_cast(data_storage.at(victory_data_storage_key)) == @@ -485,6 +488,10 @@ bool AP_HasItem(int item_id, int quantity) { return GetState().HasItem(item_id, quantity); } +std::string AP_GetItemName(int item_id) { + return GetState().GetItemName(item_id); +} + DoorShuffleMode AP_GetDoorShuffleMode() { return GetState().door_shuffle_mode; } bool AP_IsColorShuffle() { return GetState().color_shuffle; } diff --git a/src/ap_state.h b/src/ap_state.h index 5fbb720..0ae6a25 100644 --- a/src/ap_state.h +++ b/src/ap_state.h @@ -49,6 +49,8 @@ bool AP_HasCheckedHuntPanel(int location_id); bool AP_HasItem(int item_id, int quantity = 1); +std::string AP_GetItemName(int item_id); + DoorShuffleMode AP_GetDoorShuffleMode(); bool AP_IsColorShuffle(); diff --git a/src/subway_map.cpp b/src/subway_map.cpp index 6070fd5..2e7b36f 100644 --- a/src/subway_map.cpp +++ b/src/subway_map.cpp @@ -33,6 +33,14 @@ SubwayMap::SubwayMap(wxWindow *parent) : wxPanel(parent, wxID_ANY) { return; } + unchecked_eye_ = + wxBitmap(wxImage(GetAbsolutePath("assets/unchecked.png").c_str(), + wxBITMAP_TYPE_PNG) + .Scale(32, 32)); + checked_eye_ = wxBitmap( + wxImage(GetAbsolutePath("assets/checked.png").c_str(), wxBITMAP_TYPE_PNG) + .Scale(32, 32)); + tree_ = std::make_unique>( quadtree::Box{0, 0, static_cast(map_image_.GetWidth()), static_cast(map_image_.GetHeight())}); @@ -113,75 +121,144 @@ void SubwayMap::OnPaint(wxPaintEvent &event) { wxBufferedPaintDC dc(this); dc.DrawBitmap(rendered_, 0, 0); - if (hovered_item_ && networks_.IsItemInNetwork(*hovered_item_)) { - dc.SetBrush(*wxTRANSPARENT_BRUSH); + if (hovered_item_) { + const SubwayItem &subway_item = GD_GetSubwayItem(*hovered_item_); + if (subway_item.door && !GetDoorRequirements(*subway_item.door).empty()) { + const std::map &report = + GetDoorRequirements(*subway_item.door); - for (const auto &[item_id1, item_id2] : - networks_.GetNetworkGraph(*hovered_item_)) { - const SubwayItem &item1 = GD_GetSubwayItem(item_id1); - const SubwayItem &item2 = GD_GetSubwayItem(item_id2); + int acc_height = 10; + int col_width = 0; - int item1_x = (item1.x + AREA_ACTUAL_SIZE / 2) * render_width_ / map_image_.GetWidth() + render_x_; - int item1_y = (item1.y + AREA_ACTUAL_SIZE / 2) * render_width_ / map_image_.GetWidth() + render_y_; + for (const auto &[text, obtained] : report) { + wxSize item_extent = dc.GetTextExtent(text); + int item_height = std::max(32, item_extent.GetHeight()) + 10; + acc_height += item_height; - int item2_x = (item2.x + AREA_ACTUAL_SIZE / 2) * render_width_ / map_image_.GetWidth() + render_x_; - int item2_y = (item2.y + AREA_ACTUAL_SIZE / 2) * render_width_ / map_image_.GetWidth() + render_y_; + if (item_extent.GetWidth() > col_width) { + col_width = item_extent.GetWidth(); + } + } + + int item_width = col_width + 10 + 32; + int full_width = item_width + 20; + + int popup_x = (subway_item.x + AREA_ACTUAL_SIZE / 2) * render_width_ / + map_image_.GetWidth() + + render_x_; + int popup_y = (subway_item.y + AREA_ACTUAL_SIZE / 2) * render_width_ / + map_image_.GetWidth() + + render_y_; + + if (popup_x + full_width > GetSize().GetWidth()) { + popup_x = GetSize().GetWidth() - full_width; + } + if (popup_y + acc_height > GetSize().GetHeight()) { + popup_y = GetSize().GetHeight() - acc_height; + } - int left = std::min(item1_x, item2_x); - int top = std::min(item1_y, item2_y); - int right = std::max(item1_x, item2_x); - int bottom = std::max(item1_y, item2_y); + dc.SetPen(*wxTRANSPARENT_PEN); + dc.SetBrush(*wxBLACK_BRUSH); + dc.DrawRectangle({popup_x, popup_y}, {full_width, acc_height}); - int halfwidth = right - left; - int halfheight = bottom - top; + dc.SetFont(GetFont()); - if (halfwidth < 4 || halfheight < 4) { - dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, 4)); - dc.DrawLine(item1_x, item1_y, item2_x, item2_y); - dc.SetPen(*wxThePenList->FindOrCreatePen(*wxCYAN, 2)); - dc.DrawLine(item1_x, item1_y, item2_x, item2_y); - } else { - int ellipse_x; - int ellipse_y; - double start; - double end; + int cur_height = 10; - if (item1_x > item2_x) { - ellipse_y = top; + for (const auto& [text, obtained] : report) { + wxBitmap *eye_ptr = obtained ? &unchecked_eye_ : &checked_eye_; - if (item1_y > item2_y) { - ellipse_x = left - halfwidth; + dc.DrawBitmap(*eye_ptr, {popup_x + 10, popup_y + cur_height}); - start = 0; - end = 90; - } else { - ellipse_x = left; + dc.SetTextForeground(obtained ? *wxWHITE : *wxRED); + wxSize item_extent = dc.GetTextExtent(text); + dc.DrawText( + text, + {popup_x + 10 + 32 + 10, + popup_y + cur_height + (32 - dc.GetFontMetrics().height) / 2}); - start = 90; - end = 180; - } + cur_height += 10 + 32; + } + } + + if (networks_.IsItemInNetwork(*hovered_item_)) { + dc.SetBrush(*wxTRANSPARENT_BRUSH); + + for (const auto &[item_id1, item_id2] : + networks_.GetNetworkGraph(*hovered_item_)) { + const SubwayItem &item1 = GD_GetSubwayItem(item_id1); + const SubwayItem &item2 = GD_GetSubwayItem(item_id2); + + int item1_x = (item1.x + AREA_ACTUAL_SIZE / 2) * render_width_ / + map_image_.GetWidth() + + render_x_; + int item1_y = (item1.y + AREA_ACTUAL_SIZE / 2) * render_width_ / + map_image_.GetWidth() + + render_y_; + + int item2_x = (item2.x + AREA_ACTUAL_SIZE / 2) * render_width_ / + map_image_.GetWidth() + + render_x_; + int item2_y = (item2.y + AREA_ACTUAL_SIZE / 2) * render_width_ / + map_image_.GetWidth() + + render_y_; + + int left = std::min(item1_x, item2_x); + int top = std::min(item1_y, item2_y); + int right = std::max(item1_x, item2_x); + int bottom = std::max(item1_y, item2_y); + + int halfwidth = right - left; + int halfheight = bottom - top; + + if (halfwidth < 4 || halfheight < 4) { + dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, 4)); + dc.DrawLine(item1_x, item1_y, item2_x, item2_y); + dc.SetPen(*wxThePenList->FindOrCreatePen(*wxCYAN, 2)); + dc.DrawLine(item1_x, item1_y, item2_x, item2_y); } else { - ellipse_y = top - halfheight; + int ellipse_x; + int ellipse_y; + double start; + double end; - if (item1_y > item2_y) { - ellipse_x = left - halfwidth; + if (item1_x > item2_x) { + ellipse_y = top; - start = 270; - end = 360; + if (item1_y > item2_y) { + ellipse_x = left - halfwidth; + + start = 0; + end = 90; + } else { + ellipse_x = left; + + start = 90; + end = 180; + } } else { - ellipse_x = left; + ellipse_y = top - halfheight; + + if (item1_y > item2_y) { + ellipse_x = left - halfwidth; - start = 180; - end = 270; + start = 270; + end = 360; + } else { + ellipse_x = left; + + start = 180; + end = 270; + } } - } - dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, 4)); - dc.DrawEllipticArc(ellipse_x, ellipse_y, halfwidth * 2, halfheight * 2, - start, end); - dc.SetPen(*wxThePenList->FindOrCreatePen(*wxCYAN, 2)); - dc.DrawEllipticArc(ellipse_x, ellipse_y, halfwidth * 2, halfheight * 2, - start, end); + dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, 4)); + dc.DrawEllipticArc(ellipse_x, ellipse_y, halfwidth * 2, halfheight * 2, + start, end); + dc.SetPen(*wxThePenList->FindOrCreatePen(*wxCYAN, 2)); + dc.DrawEllipticArc(ellipse_x, ellipse_y, halfwidth * 2, halfheight * 2, + start, end); + } } } } diff --git a/src/subway_map.h b/src/subway_map.h index e5f0bf6..52d07b8 100644 --- a/src/subway_map.h +++ b/src/subway_map.h @@ -34,6 +34,8 @@ class SubwayMap : public wxPanel { wxImage map_image_; wxImage owl_image_; + wxBitmap unchecked_eye_; + wxBitmap checked_eye_; wxBitmap rendered_; int render_x_ = 0; diff --git a/src/tracker_state.cpp b/src/tracker_state.cpp index 5588c7f..ccb3fbd 100644 --- a/src/tracker_state.cpp +++ b/src/tracker_state.cpp @@ -12,10 +12,138 @@ namespace { +struct Requirements { + bool disabled = false; + + std::set doors; // non-grouped, handles progressive + std::set items; // all other items + std::set rooms; // maybe + bool mastery = false; // maybe + bool panel_hunt = false; // maybe + + void Merge(const Requirements& rhs) { + if (rhs.disabled) { + return; + } + + for (int id : rhs.doors) { + doors.insert(id); + } + for (int id : rhs.items) { + items.insert(id); + } + for (int id : rhs.rooms) { + rooms.insert(id); + } + mastery = mastery || rhs.mastery; + panel_hunt = panel_hunt || rhs.panel_hunt; + } +}; + +class RequirementCalculator { + public: + void Reset() { + doors_.clear(); + panels_.clear(); + } + + const Requirements& GetDoor(int door_id) { + if (!doors_.count(door_id)) { + Requirements requirements; + const Door& door_obj = GD_GetDoor(door_id); + + if (!AP_IsPilgrimageEnabled() && + door_obj.type == DoorType::kSunPainting) { + requirements.items.insert(door_obj.ap_item_id); + } else if (door_obj.type == DoorType::kSunwarp) { + switch (AP_GetSunwarpAccess()) { + case kSUNWARP_ACCESS_NORMAL: + // Do nothing. + break; + case kSUNWARP_ACCESS_DISABLED: + requirements.disabled = true; + break; + case kSUNWARP_ACCESS_UNLOCK: + requirements.items.insert(door_obj.group_ap_item_id); + break; + case kSUNWARP_ACCESS_INDIVIDUAL: + case kSUNWARP_ACCESS_PROGRESSIVE: + requirements.doors.insert(door_obj.id); + break; + } + } else if (AP_GetDoorShuffleMode() == kNO_DOORS || door_obj.skip_item) { + requirements.rooms.insert(door_obj.room); + + for (int panel_id : door_obj.panels) { + const Requirements& panel_reqs = GetPanel(panel_id); + requirements.Merge(panel_reqs); + } + } else if (AP_GetDoorShuffleMode() == kSIMPLE_DOORS && + !door_obj.group_name.empty()) { + requirements.items.insert(door_obj.group_ap_item_id); + } else { + requirements.doors.insert(door_obj.id); + } + + doors_[door_id] = requirements; + } + + return doors_[door_id]; + } + + const Requirements& GetPanel(int panel_id) { + if (!panels_.count(panel_id)) { + Requirements requirements; + const Panel& panel_obj = GD_GetPanel(panel_id); + + requirements.rooms.insert(panel_obj.room); + + if (panel_obj.name == "THE MASTER") { + requirements.mastery = true; + } + + if ((panel_obj.name == "ANOTHER TRY" || panel_obj.name == "LEVEL 2") && + AP_GetLevel2Requirement() > 1) { + requirements.panel_hunt = true; + } + + for (int room_id : panel_obj.required_rooms) { + requirements.rooms.insert(room_id); + } + + for (int door_id : panel_obj.required_doors) { + const Requirements& door_reqs = GetDoor(door_id); + requirements.Merge(door_reqs); + } + + for (int panel_id : panel_obj.required_panels) { + const Requirements& panel_reqs = GetPanel(panel_id); + requirements.Merge(panel_reqs); + } + + if (AP_IsColorShuffle()) { + for (LingoColor color : panel_obj.colors) { + requirements.items.insert(GD_GetItemIdForColor(color)); + } + } + + panels_[panel_id] = requirements; + } + + return panels_[panel_id]; + } + + private: + std::map doors_; + std::map panels_; +}; + struct TrackerState { std::map reachability; std::set reachable_doors; std::mutex reachability_mutex; + RequirementCalculator requirements; + std::map> door_reports; }; enum Decision { kYes, kNo, kMaybe }; @@ -172,6 +300,10 @@ class StateCalculator { const std::set& GetSolveablePanels() const { return solveable_panels_; } + const std::map>& GetDoorReports() const { + return door_report_; + } + private: Decision IsNonGroupedDoorReachable(const Door& door_obj) { bool has_item = AP_HasItem(door_obj.ap_item_id); @@ -188,68 +320,52 @@ class StateCalculator { return has_item ? kYes : kNo; } - Decision IsDoorReachable_Helper(int door_id) { - const Door& door_obj = GD_GetDoor(door_id); - - if (!AP_IsPilgrimageEnabled() && door_obj.type == DoorType::kSunPainting) { - return AP_HasItem(door_obj.ap_item_id) ? kYes : kNo; - } else if (door_obj.type == DoorType::kSunwarp) { - switch (AP_GetSunwarpAccess()) { - case kSUNWARP_ACCESS_NORMAL: - return kYes; - case kSUNWARP_ACCESS_DISABLED: - return kNo; - case kSUNWARP_ACCESS_UNLOCK: - return AP_HasItem(door_obj.group_ap_item_id) ? kYes : kNo; - case kSUNWARP_ACCESS_INDIVIDUAL: - case kSUNWARP_ACCESS_PROGRESSIVE: - return IsNonGroupedDoorReachable(door_obj); - } - } else if (AP_GetDoorShuffleMode() == kNO_DOORS || door_obj.skip_item) { - if (!reachable_rooms_.count(door_obj.room)) { - return kMaybe; - } + Decision AreRequirementsSatisfied(const Requirements& reqs, std::map* report = nullptr) { + if (reqs.disabled) { + return kNo; + } - for (int panel_id : door_obj.panels) { - if (!solveable_panels_.count(panel_id)) { - return kMaybe; - } - } + Decision final_decision = kYes; - return kYes; - } else if (AP_GetDoorShuffleMode() == kSIMPLE_DOORS && - !door_obj.group_name.empty()) { - return AP_HasItem(door_obj.group_ap_item_id) ? kYes : kNo; - } else { - return IsNonGroupedDoorReachable(door_obj); - } - } + for (int door_id : reqs.doors) { + const Door& door_obj = GD_GetDoor(door_id); + Decision decision = IsNonGroupedDoorReachable(door_obj); - Decision IsDoorReachable(int door_id) { - if (options_.parent) { - return options_.parent->IsDoorReachable(door_id); - } + if (report) { + (*report)[door_obj.item_name] = (decision == kYes); + } - if (door_decisions_.count(door_id)) { - return door_decisions_.at(door_id); + if (decision != kYes) { + final_decision = decision; + } } + + for (int item_id : reqs.items) { + bool has_item = AP_HasItem(item_id); + if (report) { + (*report)[AP_GetItemName(item_id)] = has_item; + } - Decision result = IsDoorReachable_Helper(door_id); - if (result != kMaybe) { - door_decisions_[door_id] = result; + if (!has_item) { + final_decision = kNo; + } } - return result; - } - - Decision IsPanelReachable(int panel_id) { - const Panel& panel_obj = GD_GetPanel(panel_id); + for (int room_id : reqs.rooms) { + bool reachable = reachable_rooms_.count(room_id); + + if (report) { + std::string report_name = + "Reach \"" + GD_GetRoom(room_id).name + "\""; + (*report)[report_name] = reachable; + } - if (!reachable_rooms_.count(panel_obj.room)) { - return kMaybe; + if (!reachable && final_decision != kNo) { + final_decision = kMaybe; + } } - - if (panel_obj.name == "THE MASTER") { + + if (reqs.mastery) { int achievements_accessible = 0; for (int achieve_id : GD_GetAchievementPanels()) { @@ -262,12 +378,18 @@ class StateCalculator { } } - return (achievements_accessible >= AP_GetMasteryRequirement()) ? kYes - : kMaybe; + bool can_mastery = + (achievements_accessible >= AP_GetMasteryRequirement()); + if (report) { + (*report)["Mastery"] = can_mastery; + } + + if (can_mastery && final_decision != kNo) { + final_decision = kMaybe; + } } - if ((panel_obj.name == "ANOTHER TRY" || panel_obj.name == "LEVEL 2") && - AP_GetLevel2Requirement() > 1) { + if (reqs.panel_hunt) { int counting_panels_accessible = 0; for (int solved_panel_id : solveable_panels_) { @@ -278,44 +400,52 @@ class StateCalculator { } } - return (counting_panels_accessible >= AP_GetLevel2Requirement() - 1) - ? kYes - : kMaybe; + bool can_level2 = + (counting_panels_accessible >= AP_GetLevel2Requirement() - 1); + if (report) { + std::string report_name = + std::to_string(AP_GetLevel2Requirement()) + " Panels"; + (*report)[report_name] = can_level2; + } + + if (can_level2 && final_decision != kNo) { + final_decision = kMaybe; + } } - for (int room_id : panel_obj.required_rooms) { - if (!reachable_rooms_.count(room_id)) { - return kMaybe; - } + return final_decision; + } + + Decision IsDoorReachable_Helper(int door_id) { + if (door_report_.count(door_id)) { + door_report_[door_id].clear(); + } else { + door_report_[door_id] = {}; } + + return AreRequirementsSatisfied(GetState().requirements.GetDoor(door_id), + &door_report_[door_id]); + } - for (int door_id : panel_obj.required_doors) { - Decision door_reachable = IsDoorReachable(door_id); - if (door_reachable == kNo) { - const Door& door_obj = GD_GetDoor(door_id); - return (door_obj.is_event || AP_GetDoorShuffleMode() == kNO_DOORS) - ? kMaybe - : kNo; - } else if (door_reachable == kMaybe) { - return kMaybe; - } + Decision IsDoorReachable(int door_id) { + if (options_.parent) { + return options_.parent->IsDoorReachable(door_id); } - for (int panel_id : panel_obj.required_panels) { - if (!solveable_panels_.count(panel_id)) { - return kMaybe; - } + if (door_decisions_.count(door_id)) { + return door_decisions_.at(door_id); } - if (AP_IsColorShuffle()) { - for (LingoColor color : panel_obj.colors) { - if (!AP_HasItem(GD_GetItemIdForColor(color))) { - return kNo; - } - } + Decision result = IsDoorReachable_Helper(door_id); + if (result != kMaybe) { + door_decisions_[door_id] = result; } - return kYes; + return result; + } + + Decision IsPanelReachable(int panel_id) { + return AreRequirementsSatisfied(GetState().requirements.GetPanel(panel_id)); } Decision IsExitUsable(const Exit& room_exit) { @@ -401,10 +531,16 @@ class StateCalculator { std::set reachable_rooms_; std::map door_decisions_; std::set solveable_panels_; + std::map> door_report_; }; } // namespace +void ResetReachabilityRequirements() { + std::lock_guard reachability_guard(GetState().reachability_mutex); + GetState().requirements.Reset(); +} + void RecalculateReachability() { StateCalculator state_calculator({.start = GD_GetRoomByName("Menu")}); state_calculator.Calculate(); @@ -435,10 +571,14 @@ void RecalculateReachability() { } } + std::map> door_reports = + state_calculator.GetDoorReports(); + { std::lock_guard reachability_guard(GetState().reachability_mutex); std::swap(GetState().reachability, new_reachability); std::swap(GetState().reachable_doors, new_reachable_doors); + std::swap(GetState().door_reports, door_reports); } } @@ -457,3 +597,9 @@ bool IsDoorOpen(int door_id) { return GetState().reachable_doors.count(door_id); } + +const std::map& GetDoorRequirements(int door_id) { + std::lock_guard reachability_guard(GetState().reachability_mutex); + + return GetState().door_reports.at(door_id); +} diff --git a/src/tracker_state.h b/src/tracker_state.h index 119b3b5..7acb0f2 100644 --- a/src/tracker_state.h +++ b/src/tracker_state.h @@ -1,10 +1,17 @@ #ifndef TRACKER_STATE_H_8639BC90 #define TRACKER_STATE_H_8639BC90 +#include +#include + +void ResetReachabilityRequirements(); + void RecalculateReachability(); bool IsLocationReachable(int location_id); bool IsDoorOpen(int door_id); +const std::map& GetDoorRequirements(int door_id); + #endif /* end of include guard: TRACKER_STATE_H_8639BC90 */ -- cgit 1.4.1 From 67a2efe7be6f4872adca8d944ebf403046472a98 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Thu, 6 Jun 2024 13:53:20 -0400 Subject: Proper painting reachability detection --- src/area_popup.cpp | 16 ++++++------ src/game_data.cpp | 34 +++++++++++++++++++------- src/game_data.h | 11 ++++++--- src/tracker_panel.cpp | 7 +++--- src/tracker_state.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++--------- src/tracker_state.h | 2 ++ 6 files changed, 103 insertions(+), 34 deletions(-) (limited to 'src/tracker_state.h') diff --git a/src/area_popup.cpp b/src/area_popup.cpp index b5c1ccb..58d8897 100644 --- a/src/area_popup.cpp +++ b/src/area_popup.cpp @@ -66,8 +66,9 @@ void AreaPopup::UpdateIndicators() { } if (AP_IsPaintingShuffle()) { - for (const PaintingExit& painting : map_area.paintings) { - wxSize item_extent = mem_dc.GetTextExtent(painting.id); + for (int painting_id : map_area.paintings) { + const PaintingExit& painting = GD_GetPaintingExit(painting_id); + wxSize item_extent = mem_dc.GetTextExtent(painting.internal_id); // TODO: Replace with a friendly name. int item_height = std::max(32, item_extent.GetHeight()) + 10; acc_height += item_height; @@ -123,18 +124,19 @@ void AreaPopup::UpdateIndicators() { } if (AP_IsPaintingShuffle()) { - for (const PaintingExit& painting : map_area.paintings) { - bool checked = AP_IsPaintingChecked(painting.id); + for (int painting_id : map_area.paintings) { + const PaintingExit& painting = GD_GetPaintingExit(painting_id); + bool checked = AP_IsPaintingChecked(painting.internal_id); wxBitmap* eye_ptr = checked ? &checked_eye_ : &unchecked_eye_; mem_dc.DrawBitmap(*eye_ptr, {10, cur_height}); - bool reachable = painting.door ? IsDoorOpen(*painting.door) : true; + bool reachable = IsPaintingReachable(painting_id); const wxColour* text_color = reachable ? wxWHITE : wxRED; mem_dc.SetTextForeground(*text_color); - wxSize item_extent = mem_dc.GetTextExtent(painting.id); - mem_dc.DrawText(painting.id, + wxSize item_extent = mem_dc.GetTextExtent(painting.internal_id); // TODO: Replace with friendly name. + mem_dc.DrawText(painting.internal_id, {10 + 32 + 10, cur_height + (32 - mem_dc.GetFontMetrics().height) / 2}); diff --git a/src/game_data.cpp b/src/game_data.cpp index 4dd69e2..71b8629 100644 --- a/src/game_data.cpp +++ b/src/game_data.cpp @@ -48,11 +48,13 @@ struct GameData { std::vector panels_; std::vector map_areas_; std::vector subway_items_; + std::vector paintings_; std::map room_by_id_; std::map door_by_id_; std::map panel_by_id_; std::map area_by_id_; + std::map painting_by_id_; std::vector door_definition_order_; @@ -419,13 +421,13 @@ struct 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; + std::string internal_id = painting["id"].as(); if ((!painting["exit_only"] || !painting["exit_only"].as()) && (!painting["disable"] || !painting["disable"].as())) { - PaintingExit painting_exit; - painting_exit.id = painting_id; + int painting_id = AddOrGetPainting(internal_id); + PaintingExit &painting_exit = paintings_[painting_id]; + painting_exit.room = room_id; if (painting["required_door"]) { std::string rd_room = rooms_[room_id].name; @@ -437,7 +439,7 @@ struct GameData { rd_room, painting["required_door"]["door"].as()); } - rooms_[room_id].paintings.push_back(painting_exit); + rooms_[room_id].paintings.push_back(painting_exit.id); } } } @@ -606,8 +608,8 @@ struct GameData { int area_id = AddOrGetArea(area_name); MapArea &map_area = map_areas_[area_id]; - for (const PaintingExit &painting : room.paintings) { - map_area.paintings.push_back(painting); + for (int painting_id : room.paintings) { + map_area.paintings.push_back(painting_id); } } } @@ -738,6 +740,16 @@ struct GameData { return area_by_id_[area]; } + + int AddOrGetPainting(std::string internal_id) { + if (!painting_by_id_.count(internal_id)) { + int painting_id = paintings_.size(); + painting_by_id_[internal_id] = painting_id; + paintings_.push_back({.id = painting_id, .internal_id = internal_id}); + } + + return painting_by_id_[internal_id]; + } }; GameData &GetState() { @@ -773,8 +785,12 @@ const Panel &GD_GetPanel(int panel_id) { return GetState().panels_.at(panel_id); } -int GD_GetRoomForPainting(const std::string &painting_id) { - return GetState().room_by_painting_.at(painting_id); +const PaintingExit &GD_GetPaintingExit(int painting_id) { + return GetState().paintings_.at(painting_id); +} + +int GD_GetPaintingByName(const std::string &name) { + return GetState().painting_by_id_.at(name); } const std::vector &GD_GetAchievementPanels() { diff --git a/src/game_data.h b/src/game_data.h index 68ba5e4..e0942f7 100644 --- a/src/game_data.h +++ b/src/game_data.h @@ -87,14 +87,16 @@ struct Exit { }; struct PaintingExit { - std::string id; + int id; + int room; + std::string internal_id; std::optional door; }; struct Room { std::string name; std::vector exits; - std::vector paintings; + std::vector paintings; std::vector sunwarps; std::vector panels; }; @@ -113,7 +115,7 @@ struct MapArea { int id; std::string name; std::vector locations; - std::vector paintings; + std::vector paintings; int map_x; int map_y; int classification = 0; @@ -152,7 +154,8 @@ const std::vector& GD_GetDoors(); const Door& GD_GetDoor(int door_id); int GD_GetDoorByName(const std::string& name); const Panel& GD_GetPanel(int panel_id); -int GD_GetRoomForPainting(const std::string& painting_id); +const PaintingExit& GD_GetPaintingExit(int painting_id); +int GD_GetPaintingByName(const std::string& name); const std::vector& GD_GetAchievementPanels(); int GD_GetItemIdForColor(LingoColor color); const std::vector& GD_GetSunwarpDoors(); diff --git a/src/tracker_panel.cpp b/src/tracker_panel.cpp index 0385f89..f0810c9 100644 --- a/src/tracker_panel.cpp +++ b/src/tracker_panel.cpp @@ -172,9 +172,10 @@ void TrackerPanel::Redraw() { } if (AP_IsPaintingShuffle()) { - for (const PaintingExit &painting : map_area.paintings) { - if (!AP_IsPaintingChecked(painting.id)) { - bool reachable = painting.door ? IsDoorOpen(*painting.door) : true; + for (int painting_id : map_area.paintings) { + const PaintingExit &painting = GD_GetPaintingExit(painting_id); + if (!AP_IsPaintingChecked(painting.internal_id)) { + bool reachable = IsPaintingReachable(painting_id); if (reachable) { has_reachable_unchecked = true; diff --git a/src/tracker_state.cpp b/src/tracker_state.cpp index 187a4a8..46bdbec 100644 --- a/src/tracker_state.cpp +++ b/src/tracker_state.cpp @@ -141,6 +141,7 @@ class RequirementCalculator { struct TrackerState { std::map reachability; std::set reachable_doors; + std::set reachable_paintings; std::mutex reachability_mutex; RequirementCalculator requirements; std::map> door_reports; @@ -170,6 +171,7 @@ class StateCalculator { void Calculate() { std::list panel_boundary; + std::list painting_boundary; std::list flood_boundary; flood_boundary.push_back({.destination_room = options_.start}); @@ -177,6 +179,8 @@ class StateCalculator { while (reachable_changed) { reachable_changed = false; + std::list new_boundary; + std::list new_panel_boundary; for (int panel_id : panel_boundary) { if (solveable_panels_.count(panel_id)) { @@ -192,7 +196,33 @@ class StateCalculator { } } - std::list new_boundary; + std::list new_painting_boundary; + for (int painting_id : painting_boundary) { + if (reachable_paintings_.count(painting_id)) { + continue; + } + + Decision painting_reachable = IsPaintingReachable(painting_id); + if (painting_reachable == kYes) { + reachable_paintings_.insert(painting_id); + reachable_changed = true; + + PaintingExit cur_painting = GD_GetPaintingExit(painting_id); + if (AP_GetPaintingMapping().count(cur_painting.internal_id) && + AP_GetCheckedPaintings().count(cur_painting.internal_id)) { + Exit painting_exit; + PaintingExit target_painting = + GD_GetPaintingExit(GD_GetPaintingByName( + AP_GetPaintingMapping().at(cur_painting.internal_id))); + painting_exit.destination_room = target_painting.room; + + new_boundary.push_back(painting_exit); + } + } else if (painting_reachable == kMaybe) { + new_painting_boundary.push_back(painting_id); + } + } + for (const Exit& room_exit : flood_boundary) { if (reachable_rooms_.count(room_exit.destination_room)) { continue; @@ -227,16 +257,8 @@ class StateCalculator { } if (AP_IsPaintingShuffle()) { - for (const PaintingExit& out_edge : room_obj.paintings) { - if (AP_GetPaintingMapping().count(out_edge.id) && - AP_GetCheckedPaintings().count(out_edge.id)) { - Exit painting_exit; - painting_exit.destination_room = GD_GetRoomForPainting( - AP_GetPaintingMapping().at(out_edge.id)); - painting_exit.door = out_edge.door; - - new_boundary.push_back(painting_exit); - } + for (int out_edge : room_obj.paintings) { + new_painting_boundary.push_back(out_edge); } } @@ -285,6 +307,7 @@ class StateCalculator { flood_boundary = new_boundary; panel_boundary = new_panel_boundary; + painting_boundary = new_painting_boundary; } // Now that we know the full reachable area, let's make sure all doors are @@ -302,6 +325,10 @@ class StateCalculator { const std::set& GetSolveablePanels() const { return solveable_panels_; } + const std::set& GetReachablePaintings() const { + return reachable_paintings_; + } + const std::map>& GetDoorReports() const { return door_report_; } @@ -450,6 +477,15 @@ class StateCalculator { return AreRequirementsSatisfied(GetState().requirements.GetPanel(panel_id)); } + Decision IsPaintingReachable(int painting_id) { + const PaintingExit& painting = GD_GetPaintingExit(painting_id); + if (painting.door) { + return IsDoorReachable(*painting.door); + } + + return kYes; + } + Decision IsExitUsable(const Exit& room_exit) { if (room_exit.type == EntranceType::kPilgrimage) { if (options_.pilgrimage || !AP_IsPilgrimageEnabled()) { @@ -533,6 +569,7 @@ class StateCalculator { std::set reachable_rooms_; std::map door_decisions_; std::set solveable_panels_; + std::set reachable_paintings_; std::map> door_report_; }; @@ -573,6 +610,7 @@ void RecalculateReachability() { } } + std::set reachable_paintings = state_calculator.GetReachablePaintings(); std::map> door_reports = state_calculator.GetDoorReports(); @@ -580,6 +618,7 @@ void RecalculateReachability() { std::lock_guard reachability_guard(GetState().reachability_mutex); std::swap(GetState().reachability, new_reachability); std::swap(GetState().reachable_doors, new_reachable_doors); + std::swap(GetState().reachable_paintings, reachable_paintings); std::swap(GetState().door_reports, door_reports); } } @@ -600,6 +639,12 @@ bool IsDoorOpen(int door_id) { return GetState().reachable_doors.count(door_id); } +bool IsPaintingReachable(int painting_id) { + std::lock_guard reachability_guard(GetState().reachability_mutex); + + return GetState().reachable_paintings.count(painting_id); +} + const std::map& GetDoorRequirements(int door_id) { std::lock_guard reachability_guard(GetState().reachability_mutex); diff --git a/src/tracker_state.h b/src/tracker_state.h index 7acb0f2..c7857a0 100644 --- a/src/tracker_state.h +++ b/src/tracker_state.h @@ -12,6 +12,8 @@ bool IsLocationReachable(int location_id); bool IsDoorOpen(int door_id); +bool IsPaintingReachable(int painting_id); + const std::map& GetDoorRequirements(int door_id); #endif /* end of include guard: TRACKER_STATE_H_8639BC90 */ -- cgit 1.4.1