about summary refs log tree commit diff stats
path: root/tools/util/godot_scene.h
blob: 17f3f508edc1189b279fe228d6bbe575e1dba7fe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef TOOLS_UTIL_TSCN_H_
#define TOOLS_UTIL_TSCN_H_

#include <map>
#include <memory>
#include <string>
#include <utility>
#include <variant>
#include <vector>

namespace com::fourisland::lingo2_archipelago {

struct GodotExtResource {
  std::string type;
  std::string path;
};

struct GodotExtResourceRef {
  std::string id;
};

using GodotInstanceType = std::variant<std::monostate, GodotExtResourceRef>;

struct GodotNode {
  std::string name;
  std::string parent;
  GodotInstanceType instance_type;

  std::string GetPath() const;
};

class GodotScene {
 public:
  GodotScene(std::map<std::string, GodotExtResource> ext_resources,
             std::vector<GodotNode> nodes)
      : ext_resources_(std::move(ext_resources)), nodes_(std::move(nodes)) {}

  const GodotExtResource* GetExtResource(const std::string& id) const {
    auto it = ext_resources_.find(id);
    if (it != ext_resources_.end()) {
      return &it->second;
    } else {
      return nullptr;
    }
  }
  const std::vector<GodotNode>& GetNodes() const { return nodes_; }

 private:
  std::map<std::string, GodotExtResource> ext_resources_;
  std::vector<GodotNode> nodes_;
};

GodotScene ReadGodotSceneFromFile(const std::string& path);

}  // namespace com::fourisland::lingo2_archipelago

#endif /* TOOLS_UTIL_TSCN_H_ */
"p">{ int achievements_accessible = 0; for (int achieve_id : GD_GetAchievementPanels()) { if (IsPanelReachable_Helper(achieve_id, reachable_rooms)) { achievements_accessible++; if (achievements_accessible >= AP_GetMasteryRequirement()) { break; } } } return (achievements_accessible >= AP_GetMasteryRequirement()); } for (int room_id : panel_obj.required_rooms) { if (!reachable_rooms.count(room_id)) { return false; } } for (int door_id : panel_obj.required_doors) { if (!IsDoorReachable_Helper(door_id, reachable_rooms)) { return false; } } if (AP_IsColorShuffle()) { for (LingoColor color : panel_obj.colors) { if (!AP_HasColorItem(color)) { return false; } } } return true; } bool IsDoorReachable_Helper(int door_id, const std::set<int>& reachable_rooms) { const Door& door_obj = GD_GetDoor(door_id); if (AP_GetDoorShuffleMode() == kNO_DOORS || door_obj.skip_item) { if (!reachable_rooms.count(door_obj.room)) { return false; } for (int panel_id : door_obj.panels) { if (!IsPanelReachable_Helper(panel_id, reachable_rooms)) { return false; } } return true; } else if (AP_GetDoorShuffleMode() == kSIMPLE_DOORS && !door_obj.group_name.empty()) { return AP_HasItem(door_obj.group_name); } else { bool has_item = AP_HasItem(door_obj.item_name); if (!has_item) { for (const ProgressiveRequirement& prog_req : door_obj.progressives) { if (AP_HasItem(prog_req.item_name, prog_req.quantity)) { has_item = true; break; } } } return has_item; } } } // namespace void RecalculateReachability() { GetState().reachability.clear(); std::set<int> reachable_rooms; std::list<Exit> flood_boundary; flood_boundary.push_back({.destination_room = GD_GetRoomByName("Menu")}); bool reachable_changed = true; while (reachable_changed) { reachable_changed = false; std::list<Exit> new_boundary; for (const Exit& room_exit : flood_boundary) { if (reachable_rooms.count(room_exit.destination_room)) { continue; } bool valid_transition = false; if (room_exit.door.has_value()) { if (IsDoorReachable_Helper(*room_exit.door, reachable_rooms)) { valid_transition = true; } else if (AP_GetDoorShuffleMode() == kNO_DOORS) { new_boundary.push_back(room_exit); } } else { valid_transition = true; } if (valid_transition) { reachable_rooms.insert(room_exit.destination_room); reachable_changed = true; const Room& room_obj = GD_GetRoom(room_exit.destination_room); for (const Exit& out_edge : room_obj.exits) { if (!out_edge.painting || !AP_IsPaintingShuffle()) { new_boundary.push_back(out_edge); } } if (AP_IsPaintingShuffle()) { for (const PaintingExit& out_edge : room_obj.paintings) { if (AP_GetPaintingMapping().count(out_edge.id)) { Exit painting_exit; painting_exit.destination_room = GD_GetRoomForPainting( AP_GetPaintingMapping().at(out_edge.id)); painting_exit.door = out_edge.door; new_boundary.push_back(painting_exit); } } } } } flood_boundary = new_boundary; } for (const MapArea& map_area : GD_GetMapAreas()) { for (int section_id = 0; section_id < map_area.locations.size(); section_id++) { const Location& location_section = map_area.locations.at(section_id); bool reachable = reachable_rooms.count(location_section.room); if (reachable) { for (int panel_id : location_section.panels) { reachable &= IsPanelReachable_Helper(panel_id, reachable_rooms); } } GetState().reachability[{map_area.id, section_id}] = reachable; } } } bool IsLocationReachable(int area_id, int section_id) { std::tuple<int, int> key = {area_id, section_id}; if (GetState().reachability.count(key)) { return GetState().reachability.at(key); } else { return false; } }