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