about summary refs log tree commit diff stats
path: root/src/tracker_state.cpp
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2024-05-12 15:26:39 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2024-05-12 15:26:39 -0400
commit8edd1bfd4ed2a42c28830f6c6575684aa3461b77 (patch)
treeb2139f17a929300d2aa59da6f81abd92e22fbe0d /src/tracker_state.cpp
parent5f7069d480022b115bee585724d41ff827f80f2f (diff)
parent98487c58c31bf0ce49d89c0bb9c7c173f2ad978d (diff)
downloadlingo-ap-tracker-8edd1bfd4ed2a42c28830f6c6575684aa3461b77.tar.gz
lingo-ap-tracker-8edd1bfd4ed2a42c28830f6c6575684aa3461b77.tar.bz2
lingo-ap-tracker-8edd1bfd4ed2a42c28830f6c6575684aa3461b77.zip
Merge branch 'main' into subway
Diffstat (limited to 'src/tracker_state.cpp')
-rw-r--r--src/tracker_state.cpp451
1 files changed, 315 insertions, 136 deletions
diff --git a/src/tracker_state.cpp b/src/tracker_state.cpp index e02ee14..640a159 100644 --- a/src/tracker_state.cpp +++ b/src/tracker_state.cpp
@@ -24,27 +24,150 @@ TrackerState& GetState() {
24 return *instance; 24 return *instance;
25} 25}
26 26
27Decision IsDoorReachable_Helper(int door_id, 27class StateCalculator;
28 const std::set<int>& reachable_rooms,
29 const std::set<int>& solveable_panels) {
30 const Door& door_obj = GD_GetDoor(door_id);
31 28
32 if (AP_GetDoorShuffleMode() == kNO_DOORS || door_obj.skip_item) { 29struct StateCalculatorOptions {
33 if (!reachable_rooms.count(door_obj.room)) { 30 int start;
34 return kMaybe; 31 bool pilgrimage = false;
35 } 32 StateCalculator* parent = nullptr;
33};
36 34
37 for (int panel_id : door_obj.panels) { 35class StateCalculator {
38 if (!solveable_panels.count(panel_id)) { 36 public:
39 return kMaybe; 37 StateCalculator() = default;
38
39 explicit StateCalculator(StateCalculatorOptions options)
40 : options_(options) {}
41
42 void Calculate() {
43 std::list<int> panel_boundary;
44 std::list<Exit> flood_boundary;
45 flood_boundary.push_back({.destination_room = options_.start});
46
47 bool reachable_changed = true;
48 while (reachable_changed) {
49 reachable_changed = false;
50
51 std::list<int> new_panel_boundary;
52 for (int panel_id : panel_boundary) {
53 if (solveable_panels_.count(panel_id)) {
54 continue;
55 }
56
57 Decision panel_reachable = IsPanelReachable(panel_id);
58 if (panel_reachable == kYes) {
59 solveable_panels_.insert(panel_id);
60 reachable_changed = true;
61 } else if (panel_reachable == kMaybe) {
62 new_panel_boundary.push_back(panel_id);
63 }
64 }
65
66 std::list<Exit> new_boundary;
67 for (const Exit& room_exit : flood_boundary) {
68 if (reachable_rooms_.count(room_exit.destination_room)) {
69 continue;
70 }
71
72 bool valid_transition = false;
73
74 Decision exit_usable = IsExitUsable(room_exit);
75 if (exit_usable == kYes) {
76 valid_transition = true;
77 } else if (exit_usable == kMaybe) {
78 new_boundary.push_back(room_exit);
79 }
80
81 if (valid_transition) {
82 reachable_rooms_.insert(room_exit.destination_room);
83 reachable_changed = true;
84
85 const Room& room_obj = GD_GetRoom(room_exit.destination_room);
86 for (const Exit& out_edge : room_obj.exits) {
87 if (out_edge.type == EntranceType::kPainting &&
88 AP_IsPaintingShuffle()) {
89 continue;
90 }
91
92 if (out_edge.type == EntranceType::kSunwarp &&
93 AP_IsSunwarpShuffle()) {
94 continue;
95 }
96
97 new_boundary.push_back(out_edge);
98 }
99
100 if (AP_IsPaintingShuffle()) {
101 for (const PaintingExit& out_edge : room_obj.paintings) {
102 if (AP_GetPaintingMapping().count(out_edge.id)) {
103 Exit painting_exit;
104 painting_exit.destination_room = GD_GetRoomForPainting(
105 AP_GetPaintingMapping().at(out_edge.id));
106 painting_exit.door = out_edge.door;
107
108 new_boundary.push_back(painting_exit);
109 }
110 }
111 }
112
113 if (AP_IsSunwarpShuffle()) {
114 for (int index : room_obj.sunwarps) {
115 if (AP_GetSunwarpMapping().count(index)) {
116 const SunwarpMapping& sm = AP_GetSunwarpMapping().at(index);
117
118 Exit sunwarp_exit;
119 sunwarp_exit.destination_room =
120 GD_GetRoomForSunwarp(sm.exit_index);
121 sunwarp_exit.door = GD_GetSunwarpDoors().at(sm.dots - 1);
122
123 new_boundary.push_back(sunwarp_exit);
124 }
125 }
126 }
127
128 if (AP_HasEarlyColorHallways() && room_obj.name == "Starting Room") {
129 new_boundary.push_back(
130 {.destination_room = GD_GetRoomByName("Outside The Undeterred"),
131 .type = EntranceType::kPainting});
132 }
133
134 if (AP_IsPilgrimageEnabled()) {
135 if (room_obj.name == "Hub Room") {
136 new_boundary.push_back(
137 {.destination_room = GD_GetRoomByName("Pilgrim Antechamber"),
138 .type = EntranceType::kPilgrimage});
139 }
140 } else {
141 if (room_obj.name == "Starting Room") {
142 new_boundary.push_back(
143 {.destination_room = GD_GetRoomByName("Pilgrim Antechamber"),
144 .door =
145 GD_GetDoorByName("Pilgrim Antechamber - Sun Painting"),
146 .type = EntranceType::kPainting});
147 }
148 }
149
150 for (int panel_id : room_obj.panels) {
151 new_panel_boundary.push_back(panel_id);
152 }
153 }
40 } 154 }
155
156 flood_boundary = new_boundary;
157 panel_boundary = new_panel_boundary;
41 } 158 }
159 }
42 160
43 return kYes; 161 const std::set<int>& GetReachableRooms() const { return reachable_rooms_; }
44 } else if (AP_GetDoorShuffleMode() == kSIMPLE_DOORS && 162
45 !door_obj.group_name.empty()) { 163 const std::map<int, Decision>& GetDoorDecisions() const {
46 return AP_HasItem(door_obj.group_ap_item_id) ? kYes : kNo; 164 return door_decisions_;
47 } else { 165 }
166
167 const std::set<int>& GetSolveablePanels() const { return solveable_panels_; }
168
169 private:
170 Decision IsNonGroupedDoorReachable(const Door& door_obj) {
48 bool has_item = AP_HasItem(door_obj.ap_item_id); 171 bool has_item = AP_HasItem(door_obj.ap_item_id);
49 172
50 if (!has_item) { 173 if (!has_item) {
@@ -58,175 +181,231 @@ Decision IsDoorReachable_Helper(int door_id,
58 181
59 return has_item ? kYes : kNo; 182 return has_item ? kYes : kNo;
60 } 183 }
61}
62
63Decision IsPanelReachable_Helper(int panel_id,
64 const std::set<int>& reachable_rooms,
65 const std::set<int>& solveable_panels) {
66 const Panel& panel_obj = GD_GetPanel(panel_id);
67 184
68 if (!reachable_rooms.count(panel_obj.room)) { 185 Decision IsDoorReachable_Helper(int door_id) {
69 return kMaybe; 186 const Door& door_obj = GD_GetDoor(door_id);
70 } 187
71 188 if (!AP_IsPilgrimageEnabled() && door_obj.type == DoorType::kSunPainting) {
72 if (panel_obj.name == "THE MASTER") { 189 return AP_HasItem(door_obj.ap_item_id) ? kYes : kNo;
73 int achievements_accessible = 0; 190 } else if (door_obj.type == DoorType::kSunwarp) {
74 191 switch (AP_GetSunwarpAccess()) {
75 for (int achieve_id : GD_GetAchievementPanels()) { 192 case kSUNWARP_ACCESS_NORMAL:
76 if (solveable_panels.count(achieve_id)) { 193 return kYes;
77 achievements_accessible++; 194 case kSUNWARP_ACCESS_DISABLED:
195 return kNo;
196 case kSUNWARP_ACCESS_UNLOCK:
197 return AP_HasItem(door_obj.group_ap_item_id) ? kYes : kNo;
198 case kSUNWARP_ACCESS_INDIVIDUAL:
199 case kSUNWARP_ACCESS_PROGRESSIVE:
200 return IsNonGroupedDoorReachable(door_obj);
201 }
202 } else if (AP_GetDoorShuffleMode() == kNO_DOORS || door_obj.skip_item) {
203 if (!reachable_rooms_.count(door_obj.room)) {
204 return kMaybe;
205 }
78 206
79 if (achievements_accessible >= AP_GetMasteryRequirement()) { 207 for (int panel_id : door_obj.panels) {
80 break; 208 if (!solveable_panels_.count(panel_id)) {
209 return kMaybe;
81 } 210 }
82 } 211 }
83 }
84 212
85 return (achievements_accessible >= AP_GetMasteryRequirement()) ? kYes 213 return kYes;
86 : kMaybe; 214 } else if (AP_GetDoorShuffleMode() == kSIMPLE_DOORS &&
215 !door_obj.group_name.empty()) {
216 return AP_HasItem(door_obj.group_ap_item_id) ? kYes : kNo;
217 } else {
218 return IsNonGroupedDoorReachable(door_obj);
219 }
87 } 220 }
88 221
89 if ((panel_obj.name == "ANOTHER TRY" || panel_obj.name == "LEVEL 2") && 222 Decision IsDoorReachable(int door_id) {
90 AP_GetLevel2Requirement() > 1) { 223 if (options_.parent) {
91 int counting_panels_accessible = 0; 224 return options_.parent->IsDoorReachable(door_id);
225 }
92 226
93 for (int solved_panel_id : solveable_panels) { 227 if (door_decisions_.count(door_id)) {
94 const Panel& solved_panel = GD_GetPanel(solved_panel_id); 228 return door_decisions_.at(door_id);
229 }
95 230
96 if (!solved_panel.non_counting) { 231 Decision result = IsDoorReachable_Helper(door_id);
97 counting_panels_accessible++; 232 if (result != kMaybe) {
98 } 233 door_decisions_[door_id] = result;
99 } 234 }
100 235
101 return (counting_panels_accessible >= AP_GetLevel2Requirement() - 1) 236 return result;
102 ? kYes
103 : kMaybe;
104 } 237 }
105 238
106 for (int room_id : panel_obj.required_rooms) { 239 Decision IsPanelReachable(int panel_id) {
107 if (!reachable_rooms.count(room_id)) { 240 const Panel& panel_obj = GD_GetPanel(panel_id);
108 return kMaybe;
109 }
110 }
111 241
112 for (int door_id : panel_obj.required_doors) { 242 if (!reachable_rooms_.count(panel_obj.room)) {
113 Decision door_reachable =
114 IsDoorReachable_Helper(door_id, reachable_rooms, solveable_panels);
115 if (door_reachable == kNo) {
116 const Door& door_obj = GD_GetDoor(door_id);
117 return (door_obj.is_event || AP_GetDoorShuffleMode() == kNO_DOORS)
118 ? kMaybe
119 : kNo;
120 } else if (door_reachable == kMaybe) {
121 return kMaybe; 243 return kMaybe;
122 } 244 }
123 }
124 245
125 for (int panel_id : panel_obj.required_panels) { 246 if (panel_obj.name == "THE MASTER") {
126 if (!solveable_panels.count(panel_id)) { 247 int achievements_accessible = 0;
127 return kMaybe;
128 }
129 }
130 248
131 if (AP_IsColorShuffle()) { 249 for (int achieve_id : GD_GetAchievementPanels()) {
132 for (LingoColor color : panel_obj.colors) { 250 if (solveable_panels_.count(achieve_id)) {
133 if (!AP_HasItem(GD_GetItemIdForColor(color))) { 251 achievements_accessible++;
134 return kNo;
135 }
136 }
137 }
138 252
139 return kYes; 253 if (achievements_accessible >= AP_GetMasteryRequirement()) {
140} 254 break;
255 }
256 }
257 }
141 258
142} // namespace 259 return (achievements_accessible >= AP_GetMasteryRequirement()) ? kYes
260 : kMaybe;
261 }
143 262
144void RecalculateReachability() { 263 if ((panel_obj.name == "ANOTHER TRY" || panel_obj.name == "LEVEL 2") &&
145 std::set<int> reachable_rooms; 264 AP_GetLevel2Requirement() > 1) {
146 std::set<int> solveable_panels; 265 int counting_panels_accessible = 0;
147 266
148 std::list<int> panel_boundary; 267 for (int solved_panel_id : solveable_panels_) {
149 std::list<Exit> flood_boundary; 268 const Panel& solved_panel = GD_GetPanel(solved_panel_id);
150 flood_boundary.push_back({.destination_room = GD_GetRoomByName("Menu")});
151 269
152 if (AP_HasEarlyColorHallways()) { 270 if (!solved_panel.non_counting) {
153 flood_boundary.push_back( 271 counting_panels_accessible++;
154 {.destination_room = GD_GetRoomByName("Outside The Undeterred")}); 272 }
155 } 273 }
156 274
157 bool reachable_changed = true; 275 return (counting_panels_accessible >= AP_GetLevel2Requirement() - 1)
158 while (reachable_changed) { 276 ? kYes
159 reachable_changed = false; 277 : kMaybe;
278 }
160 279
161 std::list<int> new_panel_boundary; 280 for (int room_id : panel_obj.required_rooms) {
162 for (int panel_id : panel_boundary) { 281 if (!reachable_rooms_.count(room_id)) {
163 if (solveable_panels.count(panel_id)) { 282 return kMaybe;
164 continue;
165 } 283 }
284 }
166 285
167 Decision panel_reachable = 286 for (int door_id : panel_obj.required_doors) {
168 IsPanelReachable_Helper(panel_id, reachable_rooms, solveable_panels); 287 Decision door_reachable = IsDoorReachable(door_id);
169 if (panel_reachable == kYes) { 288 if (door_reachable == kNo) {
170 solveable_panels.insert(panel_id); 289 const Door& door_obj = GD_GetDoor(door_id);
171 reachable_changed = true; 290 return (door_obj.is_event || AP_GetDoorShuffleMode() == kNO_DOORS)
172 } else if (panel_reachable == kMaybe) { 291 ? kMaybe
173 new_panel_boundary.push_back(panel_id); 292 : kNo;
293 } else if (door_reachable == kMaybe) {
294 return kMaybe;
174 } 295 }
175 } 296 }
176 297
177 std::list<Exit> new_boundary; 298 for (int panel_id : panel_obj.required_panels) {
178 for (const Exit& room_exit : flood_boundary) { 299 if (!solveable_panels_.count(panel_id)) {
179 if (reachable_rooms.count(room_exit.destination_room)) { 300 return kMaybe;
180 continue;
181 } 301 }
302 }
182 303
183 bool valid_transition = false; 304 if (AP_IsColorShuffle()) {
184 if (room_exit.door.has_value()) { 305 for (LingoColor color : panel_obj.colors) {
185 Decision door_reachable = IsDoorReachable_Helper( 306 if (!AP_HasItem(GD_GetItemIdForColor(color))) {
186 *room_exit.door, reachable_rooms, solveable_panels); 307 return kNo;
187 if (door_reachable == kYes) {
188 valid_transition = true;
189 } else if (door_reachable == kMaybe) {
190 new_boundary.push_back(room_exit);
191 } 308 }
192 } else {
193 valid_transition = true;
194 } 309 }
310 }
195 311
196 if (valid_transition) { 312 return kYes;
197 reachable_rooms.insert(room_exit.destination_room); 313 }
198 reachable_changed = true;
199 314
200 const Room& room_obj = GD_GetRoom(room_exit.destination_room); 315 Decision IsExitUsable(const Exit& room_exit) {
201 for (const Exit& out_edge : room_obj.exits) { 316 if (room_exit.type == EntranceType::kPilgrimage) {
202 if (!out_edge.painting || !AP_IsPaintingShuffle()) { 317 if (options_.pilgrimage || !AP_IsPilgrimageEnabled()) {
203 new_boundary.push_back(out_edge); 318 return kNo;
319 }
320
321 if (AP_GetSunwarpAccess() != kSUNWARP_ACCESS_NORMAL) {
322 for (int door_id : GD_GetSunwarpDoors()) {
323 Decision sub_decision = IsDoorReachable(door_id);
324 if (sub_decision != kYes) {
325 return sub_decision;
204 } 326 }
205 } 327 }
328 }
206 329
207 if (AP_IsPaintingShuffle()) { 330 std::vector<std::tuple<int, int>> pilgrimage_pairs;
208 for (const PaintingExit& out_edge : room_obj.paintings) { 331 if (AP_IsSunwarpShuffle()) {
209 if (AP_GetPaintingMapping().count(out_edge.id)) { 332 pilgrimage_pairs = std::vector<std::tuple<int, int>>(5);
210 Exit painting_exit;
211 painting_exit.destination_room = GD_GetRoomForPainting(
212 AP_GetPaintingMapping().at(out_edge.id));
213 painting_exit.door = out_edge.door;
214 333
215 new_boundary.push_back(painting_exit); 334 for (const auto& [start_index, mapping] : AP_GetSunwarpMapping()) {
216 } 335 if (mapping.dots > 1) {
336 std::get<1>(pilgrimage_pairs[mapping.dots - 2]) = start_index;
337 }
338 if (mapping.dots < 6) {
339 std::get<0>(pilgrimage_pairs[mapping.dots - 1]) =
340 mapping.exit_index;
217 } 341 }
218 } 342 }
343 } else {
344 pilgrimage_pairs = {{6, 1}, {8, 3}, {9, 4}, {10, 5}};
345 }
219 346
220 for (int panel_id : room_obj.panels) { 347 for (const auto& [from_sunwarp, to_sunwarp] : pilgrimage_pairs) {
221 new_panel_boundary.push_back(panel_id); 348 StateCalculator pilgrimage_calculator(
349 {.start = GD_GetRoomForSunwarp(from_sunwarp),
350 .pilgrimage = true,
351 .parent = this});
352 pilgrimage_calculator.Calculate();
353
354 if (!pilgrimage_calculator.GetReachableRooms().count(
355 GD_GetRoomForSunwarp(to_sunwarp))) {
356 return kMaybe;
222 } 357 }
223 } 358 }
359
360 return kYes;
361 }
362
363 if (options_.pilgrimage) {
364 if (room_exit.type == EntranceType::kWarp ||
365 room_exit.type == EntranceType::kSunwarp) {
366 return kNo;
367 }
368 if (room_exit.type == EntranceType::kCrossroadsRoofAccess &&
369 !AP_DoesPilgrimageAllowRoofAccess()) {
370 return kNo;
371 }
372 if (room_exit.type == EntranceType::kPainting &&
373 !AP_DoesPilgrimageAllowPaintings()) {
374 return kNo;
375 }
224 } 376 }
225 377
226 flood_boundary = new_boundary; 378 if (room_exit.type == EntranceType::kSunwarp) {
227 panel_boundary = new_panel_boundary; 379 if (AP_GetSunwarpAccess() == kSUNWARP_ACCESS_NORMAL) {
380 return kYes;
381 } else if (AP_GetSunwarpAccess() == kSUNWARP_ACCESS_DISABLED) {
382 return kNo;
383 }
384 }
385
386 if (room_exit.door.has_value()) {
387 return IsDoorReachable(*room_exit.door);
388 }
389
390 return kYes;
228 } 391 }
229 392
393 StateCalculatorOptions options_;
394
395 std::set<int> reachable_rooms_;
396 std::map<int, Decision> door_decisions_;
397 std::set<int> solveable_panels_;
398};
399
400} // namespace
401
402void RecalculateReachability() {
403 StateCalculator state_calculator({.start = GD_GetRoomByName("Menu")});
404 state_calculator.Calculate();
405
406 const std::set<int>& reachable_rooms = state_calculator.GetReachableRooms();
407 const std::set<int>& solveable_panels = state_calculator.GetSolveablePanels();
408
230 std::map<int, bool> new_reachability; 409 std::map<int, bool> new_reachability;
231 for (const MapArea& map_area : GD_GetMapAreas()) { 410 for (const MapArea& map_area : GD_GetMapAreas()) {
232 for (size_t section_id = 0; section_id < map_area.locations.size(); 411 for (size_t section_id = 0; section_id < map_area.locations.size();