From 900355a291cd2c2452e909407a57d3e81d7ad85e Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 21 Mar 2025 12:51:05 -0400 Subject: Stopped using apclient get_item_name --- src/ap_state.cpp | 8 +------ src/ap_state.h | 5 ----- src/game_data.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/game_data.h | 2 ++ src/tracker_state.cpp | 5 ++--- 5 files changed, 67 insertions(+), 15 deletions(-) diff --git a/src/ap_state.cpp b/src/ap_state.cpp index 8ba6633..c1147f6 100644 --- a/src/ap_state.cpp +++ b/src/ap_state.cpp @@ -261,8 +261,6 @@ struct APState { checked_paintings.count(painting_mapping.at(painting_id))); } - std::string GetItemName(int id) { return apclient->get_item_name(id, "Lingo"); } - void RevealPaintings() { std::lock_guard state_guard(state_mutex); @@ -432,7 +430,7 @@ struct APState { } for (const auto& [item_id, item_index] : index_by_item) { - item_states.push_back(ItemState{.name = GetItemName(item_id), + item_states.push_back(ItemState{.name = GD_GetItemName(item_id), .amount = inventory[item_id], .index = item_index}); } @@ -743,10 +741,6 @@ bool AP_HasItemSafe(int item_id, int quantity) { return GetState().HasItemSafe(item_id, quantity); } -std::string AP_GetItemName(int item_id) { - return GetState().GetItemName(item_id); -} - DoorShuffleMode AP_GetDoorShuffleMode() { std::lock_guard state_guard(GetState().state_mutex); diff --git a/src/ap_state.h b/src/ap_state.h index 8641000..54e1187 100644 --- a/src/ap_state.h +++ b/src/ap_state.h @@ -63,11 +63,6 @@ bool AP_HasItem(int item_id, int quantity = 1); bool AP_HasItemSafe(int item_id, int quantity = 1); -// This doesn't lock the client mutex because it is ONLY to be called from -// RecalculateReachability, which is only called from within a client callback -// anyway. -std::string AP_GetItemName(int item_id); - DoorShuffleMode AP_GetDoorShuffleMode(); bool AP_AreDoorsGrouped(); diff --git a/src/game_data.cpp b/src/game_data.cpp index a5af66b..7ce1fb6 100644 --- a/src/game_data.cpp +++ b/src/game_data.cpp @@ -44,6 +44,8 @@ struct GameData { std::map subway_item_by_painting_; std::map subway_item_by_sunwarp_; + std::map item_by_ap_id_; + bool loaded_area_data_ = false; std::set malconfigured_areas_; @@ -76,6 +78,14 @@ struct GameData { init_color_id("Brown"); init_color_id("Gray"); + if (ids_config["special_items"]) { + for (const auto& special_item_it : ids_config["special_items"]) + { + item_by_ap_id_[special_item_it.second.as()] = + special_item_it.first.as(); + } + } + rooms_.reserve(lingo_config.size() * 2); std::vector panel_location_ids; @@ -339,6 +349,9 @@ struct GameData { ids_config["doors"][rooms_[room_id].name] [doors_[door_id].name]["item"] .as(); + + item_by_ap_id_[doors_[door_id].ap_item_id] = + doors_[door_id].item_name; } else { TrackerLog(fmt::format("Missing AP item ID for door {} - {}", rooms_[room_id].name, @@ -355,6 +368,9 @@ struct GameData { doors_[door_id].group_ap_item_id = ids_config["door_groups"][doors_[door_id].group_name] .as(); + + item_by_ap_id_[doors_[door_id].group_ap_item_id] = + doors_[door_id].group_name; } else { TrackerLog(fmt::format("Missing AP item ID for door group {}", doors_[door_id].group_name)); @@ -418,21 +434,50 @@ struct GameData { int panel_door_id = AddOrGetPanelDoor(rooms_[room_id].name, panel_door_name); + std::map> panel_per_room; + int num_panels = 0; for (const auto &panel_node : panel_door_it.second["panels"]) { + num_panels++; + int panel_id = -1; if (panel_node.IsScalar()) { panel_id = AddOrGetPanel(rooms_[room_id].name, panel_node.as()); + + panel_per_room[rooms_[room_id].name].push_back( + panel_node.as()); } else { panel_id = AddOrGetPanel(panel_node["room"].as(), panel_node["panel"].as()); + + panel_per_room[panel_node["room"].as()].push_back( + panel_node["panel"].as()); } Panel &panel = panels_[panel_id]; panel.panel_door = panel_door_id; } + if (panel_door_it.second["item_name"]) { + panel_doors_[panel_door_id].item_name = + panel_door_it.second["item_name"].as(); + } else { + std::vector room_strs; + for (const auto &[room_str, panels_str] : panel_per_room) { + room_strs.push_back(fmt::format( + "{} - {}", room_str, hatkirby::implode(panels_str, ", "))); + } + + if (num_panels == 1) { + panel_doors_[panel_door_id].item_name = + fmt::format("{} (Panel)", room_strs[0]); + } else { + panel_doors_[panel_door_id].item_name = fmt::format( + "{} (Panels)", hatkirby::implode(room_strs, " and ")); + } + } + if (ids_config["panel_doors"] && ids_config["panel_doors"][rooms_[room_id].name] && ids_config["panel_doors"][rooms_[room_id].name] @@ -440,6 +485,9 @@ struct GameData { panel_doors_[panel_door_id].ap_item_id = ids_config["panel_doors"][rooms_[room_id].name][panel_door_name] .as(); + + item_by_ap_id_[panel_doors_[panel_door_id].ap_item_id] = + panel_doors_[panel_door_id].item_name; } else { TrackerLog(fmt::format("Missing AP item ID for panel door {} - {}", rooms_[room_id].name, panel_door_name)); @@ -453,6 +501,9 @@ struct GameData { ids_config["panel_groups"][panel_group]) { panel_doors_[panel_door_id].group_ap_item_id = ids_config["panel_groups"][panel_group].as(); + + item_by_ap_id_[panel_doors_[panel_door_id].group_ap_item_id] = + panel_group; } else { TrackerLog(fmt::format( "Missing AP item ID for panel door group {}", panel_group)); @@ -516,6 +567,8 @@ struct GameData { ids_config["progression"][progressive_item_name]) { progressive_item_id = ids_config["progression"][progressive_item_name].as(); + + item_by_ap_id_[progressive_item_id] = progressive_item_name; } else { TrackerLog(fmt::format("Missing AP item ID for progressive item {}", progressive_item_name)); @@ -1008,6 +1061,15 @@ int GD_GetSubwayItemForSunwarp(const SubwaySunwarp &sunwarp) { return GetState().subway_item_by_sunwarp_.at(sunwarp); } +std::string GD_GetItemName(int id) { + auto it = GetState().item_by_ap_id_.find(id); + if (it != GetState().item_by_ap_id_.end()) { + return it->second; + } else { + return "Unknown"; + } +} + LingoColor GetLingoColorForString(const std::string &str) { if (str == "black") { return LingoColor::kBlack; diff --git a/src/game_data.h b/src/game_data.h index 815ae2e..44084d9 100644 --- a/src/game_data.h +++ b/src/game_data.h @@ -90,6 +90,7 @@ struct PanelDoor { int ap_item_id = -1; int group_ap_item_id = -1; std::vector progressives; + std::string item_name; }; struct Exit { @@ -190,6 +191,7 @@ const std::vector& GD_GetSubwayItems(); const SubwayItem& GD_GetSubwayItem(int id); std::optional GD_GetSubwayItemForPainting(const std::string& painting_id); int GD_GetSubwayItemForSunwarp(const SubwaySunwarp& sunwarp); +std::string GD_GetItemName(int id); LingoColor GetLingoColorForString(const std::string& str); diff --git a/src/tracker_state.cpp b/src/tracker_state.cpp index 40ba6c4..bf2725a 100644 --- a/src/tracker_state.cpp +++ b/src/tracker_state.cpp @@ -473,8 +473,7 @@ class StateCalculator { Decision decision = IsNonGroupedDoorReachable(panel_door_obj); if (report) { - (*report)[AP_GetItemName(panel_door_obj.ap_item_id)] = - (decision == kYes); + (*report)[panel_door_obj.item_name] = (decision == kYes); } if (decision != kYes) { @@ -485,7 +484,7 @@ class StateCalculator { for (int item_id : reqs.items) { bool has_item = AP_HasItem(item_id); if (report) { - (*report)[AP_GetItemName(item_id)] = has_item; + (*report)[GD_GetItemName(item_id)] = has_item; } if (!has_item) { -- cgit 1.4.1