about summary refs log tree commit diff stats
path: root/src/game_data.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game_data.cpp')
-rw-r--r--src/game_data.cpp103
1 files changed, 34 insertions, 69 deletions
diff --git a/src/game_data.cpp b/src/game_data.cpp index dd6e924..28ca598 100644 --- a/src/game_data.cpp +++ b/src/game_data.cpp
@@ -58,9 +58,6 @@ struct GameData {
58 58
59 std::map<LingoColor, int> ap_id_by_color_; 59 std::map<LingoColor, int> ap_id_by_color_;
60 60
61 std::vector<int> pilgrimage_;
62 std::vector<int> pilgrimage_with_sunwarps_;
63
64 bool loaded_area_data_ = false; 61 bool loaded_area_data_ = false;
65 std::set<std::string> malconfigured_areas_; 62 std::set<std::string> malconfigured_areas_;
66 63
@@ -69,8 +66,6 @@ struct GameData {
69 YAML::LoadFile(GetAbsolutePath("assets/LL1.yaml")); 66 YAML::LoadFile(GetAbsolutePath("assets/LL1.yaml"));
70 YAML::Node areas_config = 67 YAML::Node areas_config =
71 YAML::LoadFile(GetAbsolutePath("assets/areas.yaml")); 68 YAML::LoadFile(GetAbsolutePath("assets/areas.yaml"));
72 YAML::Node pilgrimage_config =
73 YAML::LoadFile(GetAbsolutePath("assets/pilgrimage.yaml"));
74 YAML::Node ids_config = YAML::LoadFile(GetAbsolutePath("assets/ids.yaml")); 69 YAML::Node ids_config = YAML::LoadFile(GetAbsolutePath("assets/ids.yaml"));
75 70
76 auto init_color_id = [this, &ids_config](const std::string &color_name) { 71 auto init_color_id = [this, &ids_config](const std::string &color_name) {
@@ -105,6 +100,34 @@ struct GameData {
105 for (const auto &entrance_it : room_it.second["entrances"]) { 100 for (const auto &entrance_it : room_it.second["entrances"]) {
106 int from_room_id = AddOrGetRoom(entrance_it.first.as<std::string>()); 101 int from_room_id = AddOrGetRoom(entrance_it.first.as<std::string>());
107 102
103 auto process_single_entrance =
104 [this, room_id, from_room_id](const YAML::Node &option) {
105 Exit exit_obj;
106 exit_obj.destination_room = room_id;
107
108 if (option["door"]) {
109 std::string door_room = rooms_[room_id].name;
110 if (option["room"]) {
111 door_room = option["room"].as<std::string>();
112 }
113 exit_obj.door = AddOrGetDoor(door_room, option["door"].as<std::string>());
114 }
115
116 if (option["painting"] && option["painting"].as<bool>()) {
117 exit_obj.type = EntranceType::kPainting;
118 }
119
120 if (option["sunwarp"] && option["sunwarp"].as<bool>()) {
121 exit_obj.type = EntranceType::kSunwarp;
122 }
123
124 if (option["warp"] && option["warp"].as<bool>()) {
125 exit_obj.type = EntranceType::kWarp;
126 }
127
128 rooms_[from_room_id].exits.push_back(exit_obj);
129 };
130
108 switch (entrance_it.second.Type()) { 131 switch (entrance_it.second.Type()) {
109 case YAML::NodeType::Scalar: { 132 case YAML::NodeType::Scalar: {
110 // This is just "true". 133 // This is just "true".
@@ -112,50 +135,12 @@ struct GameData {
112 break; 135 break;
113 } 136 }
114 case YAML::NodeType::Map: { 137 case YAML::NodeType::Map: {
115 Exit exit_obj; 138 process_single_entrance(entrance_it.second);
116 exit_obj.destination_room = room_id;
117
118 if (entrance_it.second["door"]) {
119 std::string door_room = rooms_[room_id].name;
120 if (entrance_it.second["room"]) {
121 door_room = entrance_it.second["room"].as<std::string>();
122 }
123 exit_obj.door = AddOrGetDoor(
124 door_room, entrance_it.second["door"].as<std::string>());
125 }
126
127 if (entrance_it.second["painting"]) {
128 exit_obj.painting = entrance_it.second["painting"].as<bool>();
129 }
130
131 if (entrance_it.second["sunwarp"]) {
132 exit_obj.sunwarp = entrance_it.second["sunwarp"].as<bool>();
133 }
134
135 rooms_[from_room_id].exits.push_back(exit_obj);
136 break; 139 break;
137 } 140 }
138 case YAML::NodeType::Sequence: { 141 case YAML::NodeType::Sequence: {
139 for (const auto &option : entrance_it.second) { 142 for (const auto &option : entrance_it.second) {
140 Exit exit_obj; 143 process_single_entrance(option);
141 exit_obj.destination_room = room_id;
142
143 std::string door_room = rooms_[room_id].name;
144 if (option["room"]) {
145 door_room = option["room"].as<std::string>();
146 }
147 exit_obj.door =
148 AddOrGetDoor(door_room, option["door"].as<std::string>());
149
150 if (option["painting"]) {
151 exit_obj.painting = option["painting"].as<bool>();
152 }
153
154 if (option["sunwarp"]) {
155 exit_obj.sunwarp = option["sunwarp"].as<bool>();
156 }
157
158 rooms_[from_room_id].exits.push_back(exit_obj);
159 } 144 }
160 145
161 break; 146 break;
@@ -586,22 +571,6 @@ struct GameData {
586 } 571 }
587 } 572 }
588 573
589 // Set up fake pilgrimage.
590 for (const auto &config_node : pilgrimage_config) {
591 int door_id = AddOrGetDoor(config_node["room"].as<std::string>(),
592 config_node["door"].as<std::string>());
593 if (config_node["sunwarp"] && config_node["sunwarp"].as<bool>()) {
594 pilgrimage_with_sunwarps_.push_back(door_id);
595 }
596 pilgrimage_.push_back(door_id);
597 }
598
599 int starting_room_id = AddOrGetRoom("Starting Room");
600 Room &starting_room_obj = rooms_[starting_room_id];
601 starting_room_obj.exits.push_back(
602 Exit{.destination_room = AddOrGetRoom("Pilgrim Antechamber"),
603 .pilgrimage = true});
604
605 // Report errors. 574 // Report errors.
606 for (const std::string &area : malconfigured_areas_) { 575 for (const std::string &area : malconfigured_areas_) {
607 std::ostringstream errstr; 576 std::ostringstream errstr;
@@ -679,6 +648,10 @@ const std::vector<Door> &GD_GetDoors() { return GetState().doors_; }
679 648
680const Door &GD_GetDoor(int door_id) { return GetState().doors_.at(door_id); } 649const Door &GD_GetDoor(int door_id) { return GetState().doors_.at(door_id); }
681 650
651int GD_GetDoorByName(const std::string &name) {
652 return GetState().door_by_id_.at(name);
653}
654
682const Panel &GD_GetPanel(int panel_id) { 655const Panel &GD_GetPanel(int panel_id) {
683 return GetState().panels_.at(panel_id); 656 return GetState().panels_.at(panel_id);
684} 657}
@@ -694,11 +667,3 @@ const std::vector<int> &GD_GetAchievementPanels() {
694int GD_GetItemIdForColor(LingoColor color) { 667int GD_GetItemIdForColor(LingoColor color) {
695 return GetState().ap_id_by_color_.at(color); 668 return GetState().ap_id_by_color_.at(color);
696} 669}
697
698const std::vector<int> &GD_GetPilgrimageDoors(bool include_sunwarps) {
699 if (include_sunwarps) {
700 return GetState().pilgrimage_with_sunwarps_;
701 } else {
702 return GetState().pilgrimage_;
703 }
704}