From 67a2efe7be6f4872adca8d944ebf403046472a98 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Thu, 6 Jun 2024 13:53:20 -0400 Subject: Proper painting reachability detection --- src/game_data.cpp | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'src/game_data.cpp') diff --git a/src/game_data.cpp b/src/game_data.cpp index 4dd69e2..71b8629 100644 --- a/src/game_data.cpp +++ b/src/game_data.cpp @@ -48,11 +48,13 @@ struct GameData { std::vector panels_; std::vector map_areas_; std::vector subway_items_; + std::vector paintings_; std::map room_by_id_; std::map door_by_id_; std::map panel_by_id_; std::map area_by_id_; + std::map painting_by_id_; std::vector door_definition_order_; @@ -419,13 +421,13 @@ struct GameData { if (room_it.second["paintings"]) { for (const auto &painting : room_it.second["paintings"]) { - std::string painting_id = painting["id"].as(); - room_by_painting_[painting_id] = room_id; + std::string internal_id = painting["id"].as(); if ((!painting["exit_only"] || !painting["exit_only"].as()) && (!painting["disable"] || !painting["disable"].as())) { - PaintingExit painting_exit; - painting_exit.id = painting_id; + int painting_id = AddOrGetPainting(internal_id); + PaintingExit &painting_exit = paintings_[painting_id]; + painting_exit.room = room_id; if (painting["required_door"]) { std::string rd_room = rooms_[room_id].name; @@ -437,7 +439,7 @@ struct GameData { rd_room, painting["required_door"]["door"].as()); } - rooms_[room_id].paintings.push_back(painting_exit); + rooms_[room_id].paintings.push_back(painting_exit.id); } } } @@ -606,8 +608,8 @@ struct GameData { int area_id = AddOrGetArea(area_name); MapArea &map_area = map_areas_[area_id]; - for (const PaintingExit &painting : room.paintings) { - map_area.paintings.push_back(painting); + for (int painting_id : room.paintings) { + map_area.paintings.push_back(painting_id); } } } @@ -738,6 +740,16 @@ struct GameData { return area_by_id_[area]; } + + int AddOrGetPainting(std::string internal_id) { + if (!painting_by_id_.count(internal_id)) { + int painting_id = paintings_.size(); + painting_by_id_[internal_id] = painting_id; + paintings_.push_back({.id = painting_id, .internal_id = internal_id}); + } + + return painting_by_id_[internal_id]; + } }; GameData &GetState() { @@ -773,8 +785,12 @@ const Panel &GD_GetPanel(int panel_id) { return GetState().panels_.at(panel_id); } -int GD_GetRoomForPainting(const std::string &painting_id) { - return GetState().room_by_painting_.at(painting_id); +const PaintingExit &GD_GetPaintingExit(int painting_id) { + return GetState().paintings_.at(painting_id); +} + +int GD_GetPaintingByName(const std::string &name) { + return GetState().painting_by_id_.at(name); } const std::vector &GD_GetAchievementPanels() { -- cgit 1.4.1