diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2023-08-25 22:14:51 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2023-08-25 22:14:51 -0400 |
commit | 9bf6a50624284ab7422f56375b3e57c894200faf (patch) | |
tree | 9951ee08e5ebbed1363d190b57fa01606e0fbb94 /src/game_data.cpp | |
parent | baf43ede759f9ff0ca8c71de764e0389469f9ae1 (diff) | |
download | lingo-ap-tracker-9bf6a50624284ab7422f56375b3e57c894200faf.tar.gz lingo-ap-tracker-9bf6a50624284ab7422f56375b3e57c894200faf.tar.bz2 lingo-ap-tracker-9bf6a50624284ab7422f56375b3e57c894200faf.zip |
Panelsanity support
Diffstat (limited to 'src/game_data.cpp')
-rw-r--r-- | src/game_data.cpp | 132 |
1 files changed, 84 insertions, 48 deletions
diff --git a/src/game_data.cpp b/src/game_data.cpp index 4393373..06eb80a 100644 --- a/src/game_data.cpp +++ b/src/game_data.cpp | |||
@@ -4,6 +4,9 @@ | |||
4 | #include <yaml-cpp/yaml.h> | 4 | #include <yaml-cpp/yaml.h> |
5 | 5 | ||
6 | #include <iostream> | 6 | #include <iostream> |
7 | #include <sstream> | ||
8 | |||
9 | #include "logger.h" | ||
7 | 10 | ||
8 | namespace { | 11 | namespace { |
9 | 12 | ||
@@ -49,6 +52,9 @@ struct GameData { | |||
49 | 52 | ||
50 | std::vector<int> achievement_panels_; | 53 | std::vector<int> achievement_panels_; |
51 | 54 | ||
55 | bool loaded_area_data_ = false; | ||
56 | std::set<std::string> malconfigured_areas_; | ||
57 | |||
52 | GameData() { | 58 | GameData() { |
53 | YAML::Node lingo_config = YAML::LoadFile("assets/LL1.yaml"); | 59 | YAML::Node lingo_config = YAML::LoadFile("assets/LL1.yaml"); |
54 | YAML::Node areas_config = YAML::LoadFile("assets/areas.yaml"); | 60 | YAML::Node areas_config = YAML::LoadFile("assets/areas.yaml"); |
@@ -179,7 +185,8 @@ struct GameData { | |||
179 | if (panel_it.second["required_panel"].IsMap()) { | 185 | if (panel_it.second["required_panel"].IsMap()) { |
180 | std::string rp_room = room_obj.name; | 186 | std::string rp_room = room_obj.name; |
181 | if (panel_it.second["required_panel"]["room"]) { | 187 | if (panel_it.second["required_panel"]["room"]) { |
182 | rp_room = panel_it.second["required_panel"]["room"].as<std::string>(); | 188 | rp_room = |
189 | panel_it.second["required_panel"]["room"].as<std::string>(); | ||
183 | } | 190 | } |
184 | 191 | ||
185 | panel_obj.required_panels.push_back(AddOrGetPanel( | 192 | panel_obj.required_panels.push_back(AddOrGetPanel( |
@@ -204,7 +211,8 @@ struct GameData { | |||
204 | 211 | ||
205 | if (panel_it.second["achievement"]) { | 212 | if (panel_it.second["achievement"]) { |
206 | panel_obj.achievement = true; | 213 | panel_obj.achievement = true; |
207 | panel_obj.achievement_name = panel_it.second["achievement"].as<std::string>(); | 214 | panel_obj.achievement_name = |
215 | panel_it.second["achievement"].as<std::string>(); | ||
208 | 216 | ||
209 | achievement_panels_.push_back(panel_id); | 217 | achievement_panels_.push_back(panel_id); |
210 | } | 218 | } |
@@ -356,71 +364,88 @@ struct GameData { | |||
356 | } | 364 | } |
357 | } | 365 | } |
358 | 366 | ||
367 | loaded_area_data_ = true; | ||
368 | |||
369 | // Only locations for the panels are kept here. | ||
370 | std::map<std::string, std::tuple<int, int>> locations_by_name; | ||
371 | |||
359 | for (const Panel &panel : panels_) { | 372 | for (const Panel &panel : panels_) { |
360 | if (panel.check) { | 373 | int room_id = panel.room; |
361 | int room_id = panel.room; | 374 | std::string room_name = rooms_[room_id].name; |
362 | std::string room_name = rooms_[room_id].name; | ||
363 | 375 | ||
364 | std::string area_name = room_name; | 376 | std::string area_name = room_name; |
365 | if (fold_areas.count(room_name)) { | 377 | if (fold_areas.count(room_name)) { |
366 | int fold_area_id = fold_areas[room_name]; | 378 | int fold_area_id = fold_areas[room_name]; |
367 | area_name = map_areas_[fold_area_id].name; | 379 | area_name = map_areas_[fold_area_id].name; |
368 | } | 380 | } |
369 | 381 | ||
370 | int area_id = AddOrGetArea(area_name); | 382 | int classification = kLOCATION_INSANITY; |
371 | MapArea &map_area = map_areas_[area_id]; | 383 | if (panel.check) { |
372 | // room field should be the original room ID | 384 | classification |= kLOCATION_NORMAL; |
373 | map_area.locations.push_back( | 385 | if (!panel.exclude_reduce) { |
374 | {.name = panel.name, | 386 | classification |= kLOCATION_REDUCED; |
375 | .ap_location_name = room_name + " - " + panel.name, | 387 | } |
376 | .room = panel.room, | ||
377 | .panels = {panel.id}, | ||
378 | .exclude_reduce = panel.exclude_reduce}); | ||
379 | } | 388 | } |
389 | |||
390 | int area_id = AddOrGetArea(area_name); | ||
391 | MapArea &map_area = map_areas_[area_id]; | ||
392 | // room field should be the original room ID | ||
393 | map_area.locations.push_back( | ||
394 | {.name = panel.name, | ||
395 | .ap_location_name = room_name + " - " + panel.name, | ||
396 | .room = panel.room, | ||
397 | .panels = {panel.id}, | ||
398 | .classification = classification}); | ||
399 | locations_by_name[map_area.locations.back().ap_location_name] = { | ||
400 | area_id, map_area.locations.size() - 1}; | ||
380 | } | 401 | } |
381 | 402 | ||
382 | for (int door_id : door_definition_order_) { | 403 | for (int door_id : door_definition_order_) { |
383 | const Door &door = doors_.at(door_id); | 404 | const Door &door = doors_.at(door_id); |
384 | 405 | ||
385 | if (!door.skip_location) { | 406 | if (!door.skip_location) { |
386 | int room_id = door.room; | 407 | int classification = kLOCATION_NORMAL; |
387 | std::string area_name = rooms_[room_id].name; | 408 | if (!door.exclude_reduce) { |
388 | std::string section_name; | 409 | classification |= kLOCATION_REDUCED; |
410 | } | ||
389 | 411 | ||
390 | size_t divider_pos = door.location_name.find(" - "); | 412 | if (locations_by_name.count(door.location_name)) { |
391 | if (divider_pos == std::string::npos) { | 413 | auto [area_id, section_id] = locations_by_name[door.location_name]; |
392 | section_name = door.location_name; | 414 | map_areas_[area_id].locations[section_id].classification |= |
415 | classification; | ||
393 | } else { | 416 | } else { |
394 | area_name = door.location_name.substr(0, divider_pos); | 417 | int room_id = door.room; |
395 | section_name = door.location_name.substr(divider_pos + 3); | 418 | std::string area_name = rooms_[room_id].name; |
396 | } | 419 | std::string section_name; |
420 | |||
421 | size_t divider_pos = door.location_name.find(" - "); | ||
422 | if (divider_pos == std::string::npos) { | ||
423 | section_name = door.location_name; | ||
424 | } else { | ||
425 | area_name = door.location_name.substr(0, divider_pos); | ||
426 | section_name = door.location_name.substr(divider_pos + 3); | ||
427 | } | ||
397 | 428 | ||
398 | if (fold_areas.count(area_name)) { | 429 | if (fold_areas.count(area_name)) { |
399 | int fold_area_id = fold_areas[area_name]; | 430 | int fold_area_id = fold_areas[area_name]; |
400 | area_name = map_areas_[fold_area_id].name; | 431 | area_name = map_areas_[fold_area_id].name; |
401 | } | 432 | } |
402 | 433 | ||
403 | int area_id = AddOrGetArea(area_name); | 434 | int area_id = AddOrGetArea(area_name); |
404 | MapArea &map_area = map_areas_[area_id]; | 435 | MapArea &map_area = map_areas_[area_id]; |
405 | // room field should be the original room ID | 436 | // room field should be the original room ID |
406 | map_area.locations.push_back({.name = section_name, | 437 | map_area.locations.push_back({.name = section_name, |
407 | .ap_location_name = door.location_name, | 438 | .ap_location_name = door.location_name, |
408 | .room = door.room, | 439 | .room = door.room, |
409 | .panels = door.panels, | 440 | .panels = door.panels, |
410 | .exclude_reduce = door.exclude_reduce}); | 441 | .classification = classification}); |
442 | } | ||
411 | } | 443 | } |
412 | } | 444 | } |
413 | 445 | ||
414 | for (MapArea &map_area : map_areas_) { | 446 | for (MapArea &map_area : map_areas_) { |
415 | bool all_exclude_reduce = true; | ||
416 | for (const Location &location : map_area.locations) { | 447 | for (const Location &location : map_area.locations) { |
417 | if (!location.exclude_reduce) { | 448 | map_area.classification |= location.classification; |
418 | all_exclude_reduce = false; | ||
419 | break; | ||
420 | } | ||
421 | } | ||
422 | if (all_exclude_reduce) { | ||
423 | map_area.exclude_reduce = true; | ||
424 | } | 449 | } |
425 | } | 450 | } |
426 | 451 | ||
@@ -450,6 +475,13 @@ struct GameData { | |||
450 | starting_room_obj.exits.push_back( | 475 | starting_room_obj.exits.push_back( |
451 | Exit{.destination_room = AddOrGetRoom("Pilgrim Antechamber"), | 476 | Exit{.destination_room = AddOrGetRoom("Pilgrim Antechamber"), |
452 | .door = fake_pilgrim_door_id}); | 477 | .door = fake_pilgrim_door_id}); |
478 | |||
479 | // Report errors. | ||
480 | for (const std::string &area : malconfigured_areas_) { | ||
481 | std::ostringstream errstr; | ||
482 | errstr << "Area data not found for: " << area; | ||
483 | TrackerLog(errstr.str()); | ||
484 | } | ||
453 | } | 485 | } |
454 | 486 | ||
455 | int AddOrGetRoom(std::string room) { | 487 | int AddOrGetRoom(std::string room) { |
@@ -487,6 +519,10 @@ struct GameData { | |||
487 | 519 | ||
488 | int AddOrGetArea(std::string area) { | 520 | int AddOrGetArea(std::string area) { |
489 | if (!area_by_id_.count(area)) { | 521 | if (!area_by_id_.count(area)) { |
522 | if (loaded_area_data_) { | ||
523 | malconfigured_areas_.insert(area); | ||
524 | } | ||
525 | |||
490 | int area_id = map_areas_.size(); | 526 | int area_id = map_areas_.size(); |
491 | area_by_id_[area] = area_id; | 527 | area_by_id_[area] = area_id; |
492 | map_areas_.push_back({.id = area_id, .name = area}); | 528 | map_areas_.push_back({.id = area_id, .name = area}); |