diff options
| author | Star Rauchenberger <fefferburbia@gmail.com> | 2025-03-13 11:55:55 -0400 |
|---|---|---|
| committer | Star Rauchenberger <fefferburbia@gmail.com> | 2025-03-13 11:55:55 -0400 |
| commit | dacbe8e3fbda85f7c2e7e7b660795f2a080a9d25 (patch) | |
| tree | 65f201e323d5d6a36291ec5a108c4b14649116da /src/ap_state.cpp | |
| parent | f4945731a958371d206ccfa4a34486b263be5b21 (diff) | |
| download | lingo-ap-tracker-dacbe8e3fbda85f7c2e7e7b660795f2a080a9d25.tar.gz lingo-ap-tracker-dacbe8e3fbda85f7c2e7e7b660795f2a080a9d25.tar.bz2 lingo-ap-tracker-dacbe8e3fbda85f7c2e7e7b660795f2a080a9d25.zip | |
Use sync fields for hunt panels
Diffstat (limited to 'src/ap_state.cpp')
| -rw-r--r-- | src/ap_state.cpp | 53 |
1 files changed, 34 insertions, 19 deletions
| diff --git a/src/ap_state.cpp b/src/ap_state.cpp index 023bf7f..8ba6633 100644 --- a/src/ap_state.cpp +++ b/src/ap_state.cpp | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | #include <any> | 10 | #include <any> |
| 11 | #include <apclient.hpp> | 11 | #include <apclient.hpp> |
| 12 | #include <apuuid.hpp> | 12 | #include <apuuid.hpp> |
| 13 | #include <bitset> | ||
| 13 | #include <chrono> | 14 | #include <chrono> |
| 14 | #include <exception> | 15 | #include <exception> |
| 15 | #include <filesystem> | 16 | #include <filesystem> |
| @@ -37,6 +38,10 @@ constexpr int ITEM_HANDLING = 7; // <- all | |||
| 37 | constexpr int CONNECTION_TIMEOUT = 50000; // 50 seconds | 38 | constexpr int CONNECTION_TIMEOUT = 50000; // 50 seconds |
| 38 | constexpr int CONNECTION_BACKOFF_INTERVAL = 100; | 39 | constexpr int CONNECTION_BACKOFF_INTERVAL = 100; |
| 39 | 40 | ||
| 41 | constexpr int PANEL_COUNT = 803; | ||
| 42 | constexpr int PANEL_BITFIELD_LENGTH = 48; | ||
| 43 | constexpr int PANEL_BITFIELDS = 17; | ||
| 44 | |||
| 40 | namespace { | 45 | namespace { |
| 41 | 46 | ||
| 42 | const std::set<long> kNonProgressionItems = { | 47 | const std::set<long> kNonProgressionItems = { |
| @@ -79,6 +84,7 @@ struct APState { | |||
| 79 | std::set<int64_t> checked_locations; | 84 | std::set<int64_t> checked_locations; |
| 80 | std::map<std::string, std::any> data_storage; | 85 | std::map<std::string, std::any> data_storage; |
| 81 | std::optional<std::tuple<int, int>> player_pos; | 86 | std::optional<std::tuple<int, int>> player_pos; |
| 87 | std::bitset<PANEL_COUNT> solved_panels; | ||
| 82 | 88 | ||
| 83 | DoorShuffleMode door_shuffle_mode = kNO_DOORS; | 89 | DoorShuffleMode door_shuffle_mode = kNO_DOORS; |
| 84 | bool group_doors = false; | 90 | bool group_doors = false; |
| @@ -142,6 +148,7 @@ struct APState { | |||
| 142 | checked_locations.clear(); | 148 | checked_locations.clear(); |
| 143 | data_storage.clear(); | 149 | data_storage.clear(); |
| 144 | player_pos = std::nullopt; | 150 | player_pos = std::nullopt; |
| 151 | solved_panels.reset(); | ||
| 145 | victory_data_storage_key.clear(); | 152 | victory_data_storage_key.clear(); |
| 146 | door_shuffle_mode = kNO_DOORS; | 153 | door_shuffle_mode = kNO_DOORS; |
| 147 | group_doors = false; | 154 | group_doors = false; |
| @@ -216,14 +223,6 @@ struct APState { | |||
| 216 | return checked_locations.count(location_id); | 223 | return checked_locations.count(location_id); |
| 217 | } | 224 | } |
| 218 | 225 | ||
| 219 | bool HasCheckedHuntPanel(int location_id) { | ||
| 220 | std::lock_guard state_guard(state_mutex); | ||
| 221 | |||
| 222 | std::string key = | ||
| 223 | fmt::format("{}Hunt|{}", data_storage_prefix, location_id); | ||
| 224 | return data_storage.count(key) && std::any_cast<bool>(data_storage.at(key)); | ||
| 225 | } | ||
| 226 | |||
| 227 | bool HasItem(int item_id, int quantity) { | 226 | bool HasItem(int item_id, int quantity) { |
| 228 | return inventory.count(item_id) && inventory.at(item_id) >= quantity; | 227 | return inventory.count(item_id) && inventory.at(item_id) >= quantity; |
| 229 | } | 228 | } |
| @@ -288,6 +287,12 @@ struct APState { | |||
| 288 | 30; // CLIENT_GOAL | 287 | 30; // CLIENT_GOAL |
| 289 | } | 288 | } |
| 290 | 289 | ||
| 290 | bool IsPanelSolved(int solve_index) { | ||
| 291 | std::lock_guard state_guard(state_mutex); | ||
| 292 | |||
| 293 | return solved_panels.test(solve_index); | ||
| 294 | } | ||
| 295 | |||
| 291 | private: | 296 | private: |
| 292 | void Initialize() { | 297 | void Initialize() { |
| 293 | if (!initialized) { | 298 | if (!initialized) { |
| @@ -300,11 +305,8 @@ struct APState { | |||
| 300 | "Achievement|{}", GD_GetPanel(panel_id).achievement_name)); | 305 | "Achievement|{}", GD_GetPanel(panel_id).achievement_name)); |
| 301 | } | 306 | } |
| 302 | 307 | ||
| 303 | for (const MapArea& map_area : GD_GetMapAreas()) { | 308 | for (int i = 0; i < PANEL_BITFIELDS; i++) { |
| 304 | for (const Location& location : map_area.locations) { | 309 | tracked_data_storage_keys.push_back(fmt::format("Panels_{}", i)); |
| 305 | tracked_data_storage_keys.push_back( | ||
| 306 | fmt::format("Hunt|{}", location.ap_location_id)); | ||
| 307 | } | ||
| 308 | } | 310 | } |
| 309 | 311 | ||
| 310 | tracked_data_storage_keys.push_back("PlayerPos"); | 312 | tracked_data_storage_keys.push_back("PlayerPos"); |
| @@ -610,8 +612,6 @@ struct APState { | |||
| 610 | 612 | ||
| 611 | if (key.find("Achievement|") != std::string::npos) { | 613 | if (key.find("Achievement|") != std::string::npos) { |
| 612 | state_update.achievements = true; | 614 | state_update.achievements = true; |
| 613 | } else if (key.find("Hunt|") != std::string::npos) { | ||
| 614 | state_update.hunt_panels = true; | ||
| 615 | } | 615 | } |
| 616 | } else if (value.is_number()) { | 616 | } else if (value.is_number()) { |
| 617 | data_storage[key] = value.get<int>(); | 617 | data_storage[key] = value.get<int>(); |
| @@ -620,6 +620,21 @@ struct APState { | |||
| 620 | 620 | ||
| 621 | if (key == victory_data_storage_key) { | 621 | if (key == victory_data_storage_key) { |
| 622 | state_update.cleared_locations = true; | 622 | state_update.cleared_locations = true; |
| 623 | } else if (key.find("Panels_") != std::string::npos) { | ||
| 624 | int bitfield_num = | ||
| 625 | std::stoi(key.substr(data_storage_prefix.size() + 7)); | ||
| 626 | uint64_t bitfield_value = value.get<uint64_t>(); | ||
| 627 | for (int i = 0; i < PANEL_BITFIELD_LENGTH; i++) { | ||
| 628 | if ((bitfield_value & (1LL << i)) != 0) { | ||
| 629 | int solve_index = bitfield_num * PANEL_BITFIELD_LENGTH + i; | ||
| 630 | |||
| 631 | if (!solved_panels.test(solve_index)) { | ||
| 632 | state_update.panels.insert(solve_index); | ||
| 633 | } | ||
| 634 | |||
| 635 | solved_panels.set(solve_index); | ||
| 636 | } | ||
| 637 | } | ||
| 623 | } | 638 | } |
| 624 | } else if (value.is_object()) { | 639 | } else if (value.is_object()) { |
| 625 | if (key.ends_with("PlayerPos")) { | 640 | if (key.ends_with("PlayerPos")) { |
| @@ -720,10 +735,6 @@ bool AP_HasCheckedGameLocation(int location_id) { | |||
| 720 | return GetState().HasCheckedGameLocation(location_id); | 735 | return GetState().HasCheckedGameLocation(location_id); |
| 721 | } | 736 | } |
| 722 | 737 | ||
| 723 | bool AP_HasCheckedHuntPanel(int location_id) { | ||
| 724 | return GetState().HasCheckedHuntPanel(location_id); | ||
| 725 | } | ||
| 726 | |||
| 727 | bool AP_HasItem(int item_id, int quantity) { | 738 | bool AP_HasItem(int item_id, int quantity) { |
| 728 | return GetState().HasItem(item_id, quantity); | 739 | return GetState().HasItem(item_id, quantity); |
| 729 | } | 740 | } |
| @@ -892,3 +903,7 @@ std::optional<std::tuple<int, int>> AP_GetPlayerPosition() { | |||
| 892 | 903 | ||
| 893 | return GetState().player_pos; | 904 | return GetState().player_pos; |
| 894 | } | 905 | } |
| 906 | |||
| 907 | bool AP_IsPanelSolved(int solve_index) { | ||
| 908 | return GetState().IsPanelSolved(solve_index); | ||
| 909 | } | ||
