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.cpp95
1 files changed, 34 insertions, 61 deletions
diff --git a/src/game_data.cpp b/src/game_data.cpp index 8f237b0..28ca598 100644 --- a/src/game_data.cpp +++ b/src/game_data.cpp
@@ -66,8 +66,6 @@ struct GameData {
66 YAML::LoadFile(GetAbsolutePath("assets/LL1.yaml")); 66 YAML::LoadFile(GetAbsolutePath("assets/LL1.yaml"));
67 YAML::Node areas_config = 67 YAML::Node areas_config =
68 YAML::LoadFile(GetAbsolutePath("assets/areas.yaml")); 68 YAML::LoadFile(GetAbsolutePath("assets/areas.yaml"));
69 YAML::Node pilgrimage_config =
70 YAML::LoadFile(GetAbsolutePath("assets/pilgrimage.yaml"));
71 YAML::Node ids_config = YAML::LoadFile(GetAbsolutePath("assets/ids.yaml")); 69 YAML::Node ids_config = YAML::LoadFile(GetAbsolutePath("assets/ids.yaml"));
72 70
73 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) {
@@ -102,6 +100,34 @@ struct GameData {
102 for (const auto &entrance_it : room_it.second["entrances"]) { 100 for (const auto &entrance_it : room_it.second["entrances"]) {
103 int from_room_id = AddOrGetRoom(entrance_it.first.as<std::string>()); 101 int from_room_id = AddOrGetRoom(entrance_it.first.as<std::string>());
104 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
105 switch (entrance_it.second.Type()) { 131 switch (entrance_it.second.Type()) {
106 case YAML::NodeType::Scalar: { 132 case YAML::NodeType::Scalar: {
107 // This is just "true". 133 // This is just "true".
@@ -109,42 +135,12 @@ struct GameData {
109 break; 135 break;
110 } 136 }
111 case YAML::NodeType::Map: { 137 case YAML::NodeType::Map: {
112 Exit exit_obj; 138 process_single_entrance(entrance_it.second);
113 exit_obj.destination_room = room_id;
114
115 if (entrance_it.second["door"]) {
116 std::string door_room = rooms_[room_id].name;
117 if (entrance_it.second["room"]) {
118 door_room = entrance_it.second["room"].as<std::string>();
119 }
120 exit_obj.door = AddOrGetDoor(
121 door_room, entrance_it.second["door"].as<std::string>());
122 }
123
124 if (entrance_it.second["painting"]) {
125 exit_obj.painting = entrance_it.second["painting"].as<bool>();
126 }
127
128 rooms_[from_room_id].exits.push_back(exit_obj);
129 break; 139 break;
130 } 140 }
131 case YAML::NodeType::Sequence: { 141 case YAML::NodeType::Sequence: {
132 for (const auto &option : entrance_it.second) { 142 for (const auto &option : entrance_it.second) {
133 Exit exit_obj; 143 process_single_entrance(option);
134 exit_obj.destination_room = room_id;
135
136 std::string door_room = rooms_[room_id].name;
137 if (option["room"]) {
138 door_room = option["room"].as<std::string>();
139 }
140 exit_obj.door =
141 AddOrGetDoor(door_room, option["door"].as<std::string>());
142
143 if (option["painting"]) {
144 exit_obj.painting = option["painting"].as<bool>();
145 }
146
147 rooms_[from_room_id].exits.push_back(exit_obj);
148 } 144 }
149 145
150 break; 146 break;
@@ -575,33 +571,6 @@ struct GameData {
575 } 571 }
576 } 572 }
577 573
578 // Set up fake pilgrimage.
579 int fake_pilgrim_panel_id =
580 AddOrGetPanel("Starting Room", "!! Fake Pilgrimage Panel");
581 Panel &fake_pilgrim_panel_obj = panels_[fake_pilgrim_panel_id];
582 fake_pilgrim_panel_obj.non_counting = true;
583
584 for (const auto &config_node : pilgrimage_config) {
585 fake_pilgrim_panel_obj.required_doors.push_back(
586 AddOrGetDoor(config_node["room"].as<std::string>(),
587 config_node["door"].as<std::string>()));
588 }
589
590 int fake_pilgrim_door_id =
591 AddOrGetDoor("Starting Room", "!! Fake Pilgrimage Door");
592 Door &fake_pilgrim_door_obj = doors_[fake_pilgrim_door_id];
593 fake_pilgrim_door_obj.panels.push_back(fake_pilgrim_panel_id);
594 fake_pilgrim_door_obj.skip_location = true;
595 fake_pilgrim_door_obj.skip_item = true;
596 fake_pilgrim_door_obj.is_event = true;
597
598 int starting_room_id = AddOrGetRoom("Starting Room");
599 Room &starting_room_obj = rooms_[starting_room_id];
600 starting_room_obj.panels.push_back(fake_pilgrim_panel_id);
601 starting_room_obj.exits.push_back(
602 Exit{.destination_room = AddOrGetRoom("Pilgrim Antechamber"),
603 .door = fake_pilgrim_door_id});
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}