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.cpp384
1 files changed, 237 insertions, 147 deletions
diff --git a/src/tracker_state.cpp b/src/tracker_state.cpp index e02ee14..cc941ef 100644 --- a/src/tracker_state.cpp +++ b/src/tracker_state.cpp
@@ -24,209 +24,299 @@ TrackerState& GetState() {
24 return *instance; 24 return *instance;
25} 25}
26 26
27Decision IsDoorReachable_Helper(int door_id, 27struct StateCalculatorOptions {
28 const std::set<int>& reachable_rooms, 28 std::string start = "Menu";
29 const std::set<int>& solveable_panels) { 29 bool pilgrimage = false;
30 const Door& door_obj = GD_GetDoor(door_id); 30};
31 31
32 if (AP_GetDoorShuffleMode() == kNO_DOORS || door_obj.skip_item) { 32class StateCalculator {
33 if (!reachable_rooms.count(door_obj.room)) { 33 public:
34 return kMaybe; 34 StateCalculator() = default;
35 }
36 35
37 for (int panel_id : door_obj.panels) { 36 explicit StateCalculator(StateCalculatorOptions options)
38 if (!solveable_panels.count(panel_id)) { 37 : options_(options) {}
39 return kMaybe;
40 }
41 }
42 38
43 return kYes; 39 void Calculate() {
44 } else if (AP_GetDoorShuffleMode() == kSIMPLE_DOORS && 40 std::list<int> panel_boundary;
45 !door_obj.group_name.empty()) { 41 std::list<Exit> flood_boundary;
46 return AP_HasItem(door_obj.group_ap_item_id) ? kYes : kNo; 42 flood_boundary.push_back(
47 } else { 43 {.destination_room = GD_GetRoomByName(options_.start)});
48 bool has_item = AP_HasItem(door_obj.ap_item_id); 44
45 bool reachable_changed = true;
46 while (reachable_changed) {
47 reachable_changed = false;
49 48
50 if (!has_item) { 49 std::list<int> new_panel_boundary;
51 for (const ProgressiveRequirement& prog_req : door_obj.progressives) { 50 for (int panel_id : panel_boundary) {
52 if (AP_HasItem(prog_req.ap_item_id, prog_req.quantity)) { 51 if (solveable_panels_.count(panel_id)) {
53 has_item = true; 52 continue;
54 break; 53 }
54
55 Decision panel_reachable = IsPanelReachable(panel_id);
56 if (panel_reachable == kYes) {
57 solveable_panels_.insert(panel_id);
58 reachable_changed = true;
59 } else if (panel_reachable == kMaybe) {
60 new_panel_boundary.push_back(panel_id);
55 } 61 }
56 } 62 }
57 }
58 63
59 return has_item ? kYes : kNo; 64 std::list<Exit> new_boundary;
60 } 65 for (const Exit& room_exit : flood_boundary) {
61} 66 if (reachable_rooms_.count(room_exit.destination_room)) {
67 continue;
68 }
62 69
63Decision IsPanelReachable_Helper(int panel_id, 70 bool valid_transition = false;
64 const std::set<int>& reachable_rooms,
65 const std::set<int>& solveable_panels) {
66 const Panel& panel_obj = GD_GetPanel(panel_id);
67 71
68 if (!reachable_rooms.count(panel_obj.room)) { 72 Decision exit_usable = IsExitUsable(room_exit);
69 return kMaybe; 73 if (exit_usable == kYes) {
70 } 74 valid_transition = true;
75 } else if (exit_usable == kMaybe) {
76 new_boundary.push_back(room_exit);
77 }
78
79 if (valid_transition) {
80 reachable_rooms_.insert(room_exit.destination_room);
81 reachable_changed = true;
82
83 const Room& room_obj = GD_GetRoom(room_exit.destination_room);
84 for (const Exit& out_edge : room_obj.exits) {
85 if (out_edge.type != EntranceType::kPainting ||
86 !AP_IsPaintingShuffle()) {
87 new_boundary.push_back(out_edge);
88 }
89 }
90
91 if (AP_IsPaintingShuffle()) {
92 for (const PaintingExit& out_edge : room_obj.paintings) {
93 if (AP_GetPaintingMapping().count(out_edge.id)) {
94 Exit painting_exit;
95 painting_exit.destination_room = GD_GetRoomForPainting(
96 AP_GetPaintingMapping().at(out_edge.id));
97 painting_exit.door = out_edge.door;
71 98
72 if (panel_obj.name == "THE MASTER") { 99 new_boundary.push_back(painting_exit);
73 int achievements_accessible = 0; 100 }
101 }
102 }
103
104 if (AP_HasEarlyColorHallways() && room_obj.name == "Starting Room") {
105 new_boundary.push_back(
106 {.destination_room = GD_GetRoomByName("Outside The Undeterred"),
107 .type = EntranceType::kPainting});
108 }
74 109
75 for (int achieve_id : GD_GetAchievementPanels()) { 110 if (AP_IsPilgrimageEnabled()) {
76 if (solveable_panels.count(achieve_id)) { 111 if (room_obj.name == "Hub Room") {
77 achievements_accessible++; 112 new_boundary.push_back(
113 {.destination_room = GD_GetRoomByName("Pilgrim Antechamber"),
114 .type = EntranceType::kPilgrimage});
115 }
116 } else {
117 if (room_obj.name == "Starting Room") {
118 new_boundary.push_back(
119 {.destination_room = GD_GetRoomByName("Pilgrim Antechamber"),
120 .door =
121 GD_GetDoorByName("Pilgrim Antechamber - Sun Painting"),
122 .type = EntranceType::kPainting});
123 }
124 }
78 125
79 if (achievements_accessible >= AP_GetMasteryRequirement()) { 126 for (int panel_id : room_obj.panels) {
80 break; 127 new_panel_boundary.push_back(panel_id);
128 }
81 } 129 }
82 } 130 }
83 }
84 131
85 return (achievements_accessible >= AP_GetMasteryRequirement()) ? kYes 132 flood_boundary = new_boundary;
86 : kMaybe; 133 panel_boundary = new_panel_boundary;
134 }
87 } 135 }
88 136
89 if ((panel_obj.name == "ANOTHER TRY" || panel_obj.name == "LEVEL 2") && 137 const std::set<int>& GetReachableRooms() const { return reachable_rooms_; }
90 AP_GetLevel2Requirement() > 1) {
91 int counting_panels_accessible = 0;
92 138
93 for (int solved_panel_id : solveable_panels) { 139 const std::set<int>& GetSolveablePanels() const { return solveable_panels_; }
94 const Panel& solved_panel = GD_GetPanel(solved_panel_id);
95 140
96 if (!solved_panel.non_counting) { 141 private:
97 counting_panels_accessible++; 142 Decision IsDoorReachable(int door_id) {
143 const Door& door_obj = GD_GetDoor(door_id);
144
145 if (!AP_IsPilgrimageEnabled() &&
146 door_obj.item_name == "Pilgrim Room - Sun Painting") {
147 return AP_HasItem(door_obj.ap_item_id) ? kYes : kNo;
148 } else if (AP_GetDoorShuffleMode() == kNO_DOORS || door_obj.skip_item) {
149 if (!reachable_rooms_.count(door_obj.room)) {
150 return kMaybe;
98 } 151 }
99 }
100 152
101 return (counting_panels_accessible >= AP_GetLevel2Requirement() - 1) 153 for (int panel_id : door_obj.panels) {
102 ? kYes 154 if (!solveable_panels_.count(panel_id)) {
103 : kMaybe; 155 return kMaybe;
104 } 156 }
157 }
105 158
106 for (int room_id : panel_obj.required_rooms) { 159 return kYes;
107 if (!reachable_rooms.count(room_id)) { 160 } else if (AP_GetDoorShuffleMode() == kSIMPLE_DOORS &&
108 return kMaybe; 161 !door_obj.group_name.empty()) {
109 } 162 return AP_HasItem(door_obj.group_ap_item_id) ? kYes : kNo;
110 } 163 } else {
164 bool has_item = AP_HasItem(door_obj.ap_item_id);
165
166 if (!has_item) {
167 for (const ProgressiveRequirement& prog_req : door_obj.progressives) {
168 if (AP_HasItem(prog_req.ap_item_id, prog_req.quantity)) {
169 has_item = true;
170 break;
171 }
172 }
173 }
111 174
112 for (int door_id : panel_obj.required_doors) { 175 return has_item ? kYes : kNo;
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;
122 } 176 }
123 } 177 }
124 178
125 for (int panel_id : panel_obj.required_panels) { 179 Decision IsPanelReachable(int panel_id) {
126 if (!solveable_panels.count(panel_id)) { 180 const Panel& panel_obj = GD_GetPanel(panel_id);
181
182 if (!reachable_rooms_.count(panel_obj.room)) {
127 return kMaybe; 183 return kMaybe;
128 } 184 }
129 }
130 185
131 if (AP_IsColorShuffle()) { 186 if (panel_obj.name == "THE MASTER") {
132 for (LingoColor color : panel_obj.colors) { 187 int achievements_accessible = 0;
133 if (!AP_HasItem(GD_GetItemIdForColor(color))) {
134 return kNo;
135 }
136 }
137 }
138 188
139 return kYes; 189 for (int achieve_id : GD_GetAchievementPanels()) {
140} 190 if (solveable_panels_.count(achieve_id)) {
191 achievements_accessible++;
141 192
142} // namespace 193 if (achievements_accessible >= AP_GetMasteryRequirement()) {
194 break;
195 }
196 }
197 }
143 198
144void RecalculateReachability() { 199 return (achievements_accessible >= AP_GetMasteryRequirement()) ? kYes
145 std::set<int> reachable_rooms; 200 : kMaybe;
146 std::set<int> solveable_panels; 201 }
147 202
148 std::list<int> panel_boundary; 203 if ((panel_obj.name == "ANOTHER TRY" || panel_obj.name == "LEVEL 2") &&
149 std::list<Exit> flood_boundary; 204 AP_GetLevel2Requirement() > 1) {
150 flood_boundary.push_back({.destination_room = GD_GetRoomByName("Menu")}); 205 int counting_panels_accessible = 0;
151 206
152 if (AP_HasEarlyColorHallways()) { 207 for (int solved_panel_id : solveable_panels_) {
153 flood_boundary.push_back( 208 const Panel& solved_panel = GD_GetPanel(solved_panel_id);
154 {.destination_room = GD_GetRoomByName("Outside The Undeterred")}); 209
155 } 210 if (!solved_panel.non_counting) {
211 counting_panels_accessible++;
212 }
213 }
156 214
157 bool reachable_changed = true; 215 return (counting_panels_accessible >= AP_GetLevel2Requirement() - 1)
158 while (reachable_changed) { 216 ? kYes
159 reachable_changed = false; 217 : kMaybe;
218 }
160 219
161 std::list<int> new_panel_boundary; 220 for (int room_id : panel_obj.required_rooms) {
162 for (int panel_id : panel_boundary) { 221 if (!reachable_rooms_.count(room_id)) {
163 if (solveable_panels.count(panel_id)) { 222 return kMaybe;
164 continue;
165 } 223 }
224 }
166 225
167 Decision panel_reachable = 226 for (int door_id : panel_obj.required_doors) {
168 IsPanelReachable_Helper(panel_id, reachable_rooms, solveable_panels); 227 Decision door_reachable = IsDoorReachable(door_id);
169 if (panel_reachable == kYes) { 228 if (door_reachable == kNo) {
170 solveable_panels.insert(panel_id); 229 const Door& door_obj = GD_GetDoor(door_id);
171 reachable_changed = true; 230 return (door_obj.is_event || AP_GetDoorShuffleMode() == kNO_DOORS)
172 } else if (panel_reachable == kMaybe) { 231 ? kMaybe
173 new_panel_boundary.push_back(panel_id); 232 : kNo;
233 } else if (door_reachable == kMaybe) {
234 return kMaybe;
174 } 235 }
175 } 236 }
176 237
177 std::list<Exit> new_boundary; 238 for (int panel_id : panel_obj.required_panels) {
178 for (const Exit& room_exit : flood_boundary) { 239 if (!solveable_panels_.count(panel_id)) {
179 if (reachable_rooms.count(room_exit.destination_room)) { 240 return kMaybe;
180 continue;
181 } 241 }
242 }
182 243
183 bool valid_transition = false; 244 if (AP_IsColorShuffle()) {
184 if (room_exit.door.has_value()) { 245 for (LingoColor color : panel_obj.colors) {
185 Decision door_reachable = IsDoorReachable_Helper( 246 if (!AP_HasItem(GD_GetItemIdForColor(color))) {
186 *room_exit.door, reachable_rooms, solveable_panels); 247 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 } 248 }
192 } else {
193 valid_transition = true;
194 } 249 }
250 }
251
252 return kYes;
253 }
195 254
196 if (valid_transition) { 255 Decision IsExitUsable(const Exit& room_exit) {
197 reachable_rooms.insert(room_exit.destination_room); 256 if (room_exit.type == EntranceType::kPilgrimage) {
198 reachable_changed = true; 257 if (options_.pilgrimage || !AP_IsPilgrimageEnabled()) {
258 return kNo;
259 }
199 260
200 const Room& room_obj = GD_GetRoom(room_exit.destination_room); 261 static const std::vector<std::tuple<std::string, std::string>>
201 for (const Exit& out_edge : room_obj.exits) { 262 pilgrimage_pairs = {
202 if (!out_edge.painting || !AP_IsPaintingShuffle()) { 263 {"Crossroads", "Hot Crusts Area"},
203 new_boundary.push_back(out_edge); 264 // {"Orange Tower Third Floor", "Orange Tower Third Floor"},
204 } 265 {"Outside The Initiated", "Orange Tower First Floor"},
266 {"Outside The Undeterred", "Orange Tower Fourth Floor"},
267 {"Color Hunt", "Outside The Agreeable"}};
268
269 for (const auto& [from_room, to_room] : pilgrimage_pairs) {
270 StateCalculator pilgrimage_calculator(
271 {.start = from_room, .pilgrimage = true});
272 pilgrimage_calculator.Calculate();
273
274 if (!pilgrimage_calculator.GetReachableRooms().count(
275 GD_GetRoomByName(to_room))) {
276 return kMaybe;
205 } 277 }
278 }
206 279
207 if (AP_IsPaintingShuffle()) { 280 return kYes;
208 for (const PaintingExit& out_edge : room_obj.paintings) { 281 }
209 if (AP_GetPaintingMapping().count(out_edge.id)) {
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 282
215 new_boundary.push_back(painting_exit); 283 if (options_.pilgrimage) {
216 } 284 if (room_exit.type == EntranceType::kWarp ||
217 } 285 room_exit.type == EntranceType::kSunwarp) {
218 } 286 return kNo;
287 }
288 }
219 289
220 for (int panel_id : room_obj.panels) { 290 if (room_exit.type == EntranceType::kSunwarp) {
221 new_panel_boundary.push_back(panel_id); 291 if (AP_GetSunwarpAccess() == kSUNWARP_ACCESS_NORMAL) {
222 } 292 return kYes;
293 } else if (AP_GetSunwarpAccess() == kSUNWARP_ACCESS_DISABLED) {
294 return kNo;
223 } 295 }
224 } 296 }
225 297
226 flood_boundary = new_boundary; 298 if (room_exit.door.has_value()) {
227 panel_boundary = new_panel_boundary; 299 return IsDoorReachable(*room_exit.door);
300 }
301
302 return kYes;
228 } 303 }
229 304
305 StateCalculatorOptions options_;
306
307 std::set<int> reachable_rooms_;
308 std::set<int> solveable_panels_;
309};
310
311} // namespace
312
313void RecalculateReachability() {
314 StateCalculator state_calculator;
315 state_calculator.Calculate();
316
317 const std::set<int>& reachable_rooms = state_calculator.GetReachableRooms();
318 const std::set<int>& solveable_panels = state_calculator.GetSolveablePanels();
319
230 std::map<int, bool> new_reachability; 320 std::map<int, bool> new_reachability;
231 for (const MapArea& map_area : GD_GetMapAreas()) { 321 for (const MapArea& map_area : GD_GetMapAreas()) {
232 for (size_t section_id = 0; section_id < map_area.locations.size(); 322 for (size_t section_id = 0; section_id < map_area.locations.size();