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.cpp132
1 files changed, 71 insertions, 61 deletions
diff --git a/src/game_data.cpp b/src/game_data.cpp index eece8d7..0567623 100644 --- a/src/game_data.cpp +++ b/src/game_data.cpp
@@ -55,11 +55,14 @@ struct GameData {
55 std::vector<int> door_definition_order_; 55 std::vector<int> door_definition_order_;
56 56
57 std::map<std::string, int> room_by_painting_; 57 std::map<std::string, int> room_by_painting_;
58 std::map<int, int> room_by_sunwarp_;
58 59
59 std::vector<int> achievement_panels_; 60 std::vector<int> achievement_panels_;
60 61
61 std::map<LingoColor, int> ap_id_by_color_; 62 std::map<LingoColor, int> ap_id_by_color_;
62 63
64 std::vector<int> sunwarp_doors_;
65
63 bool loaded_area_data_ = false; 66 bool loaded_area_data_ = false;
64 std::set<std::string> malconfigured_areas_; 67 std::set<std::string> malconfigured_areas_;
65 68
@@ -68,8 +71,6 @@ struct GameData {
68 YAML::LoadFile(GetAbsolutePath("assets/LL1.yaml")); 71 YAML::LoadFile(GetAbsolutePath("assets/LL1.yaml"));
69 YAML::Node areas_config = 72 YAML::Node areas_config =
70 YAML::LoadFile(GetAbsolutePath("assets/areas.yaml")); 73 YAML::LoadFile(GetAbsolutePath("assets/areas.yaml"));
71 YAML::Node pilgrimage_config =
72 YAML::LoadFile(GetAbsolutePath("assets/pilgrimage.yaml"));
73 YAML::Node ids_config = YAML::LoadFile(GetAbsolutePath("assets/ids.yaml")); 74 YAML::Node ids_config = YAML::LoadFile(GetAbsolutePath("assets/ids.yaml"));
74 75
75 auto init_color_id = [this, &ids_config](const std::string &color_name) { 76 auto init_color_id = [this, &ids_config](const std::string &color_name) {
@@ -104,6 +105,40 @@ struct GameData {
104 for (const auto &entrance_it : room_it.second["entrances"]) { 105 for (const auto &entrance_it : room_it.second["entrances"]) {
105 int from_room_id = AddOrGetRoom(entrance_it.first.as<std::string>()); 106 int from_room_id = AddOrGetRoom(entrance_it.first.as<std::string>());
106 107
108 auto process_single_entrance =
109 [this, room_id, from_room_id](const YAML::Node &option) {
110 Exit exit_obj;
111 exit_obj.destination_room = room_id;
112
113 if (option["door"]) {
114 std::string door_room = rooms_[room_id].name;
115 if (option["room"]) {
116 door_room = option["room"].as<std::string>();
117 }
118 exit_obj.door =
119 AddOrGetDoor(door_room, option["door"].as<std::string>());
120 }
121
122 if (option["painting"] && option["painting"].as<bool>()) {
123 exit_obj.type = EntranceType::kPainting;
124 }
125
126 if (option["sunwarp"] && option["sunwarp"].as<bool>()) {
127 exit_obj.type = EntranceType::kSunwarp;
128 }
129
130 if (option["warp"] && option["warp"].as<bool>()) {
131 exit_obj.type = EntranceType::kWarp;
132 }
133
134 if (rooms_[from_room_id].name == "Crossroads" &&
135 rooms_[room_id].name == "Roof") {
136 exit_obj.type = EntranceType::kCrossroadsRoofAccess;
137 }
138
139 rooms_[from_room_id].exits.push_back(exit_obj);
140 };
141
107 switch (entrance_it.second.Type()) { 142 switch (entrance_it.second.Type()) {
108 case YAML::NodeType::Scalar: { 143 case YAML::NodeType::Scalar: {
109 // This is just "true". 144 // This is just "true".
@@ -111,42 +146,12 @@ struct GameData {
111 break; 146 break;
112 } 147 }
113 case YAML::NodeType::Map: { 148 case YAML::NodeType::Map: {
114 Exit exit_obj; 149 process_single_entrance(entrance_it.second);
115 exit_obj.destination_room = room_id;
116
117 if (entrance_it.second["door"]) {
118 std::string door_room = rooms_[room_id].name;
119 if (entrance_it.second["room"]) {
120 door_room = entrance_it.second["room"].as<std::string>();
121 }
122 exit_obj.door = AddOrGetDoor(
123 door_room, entrance_it.second["door"].as<std::string>());
124 }
125
126 if (entrance_it.second["painting"]) {
127 exit_obj.painting = entrance_it.second["painting"].as<bool>();
128 }
129
130 rooms_[from_room_id].exits.push_back(exit_obj);
131 break; 150 break;
132 } 151 }
133 case YAML::NodeType::Sequence: { 152 case YAML::NodeType::Sequence: {
134 for (const auto &option : entrance_it.second) { 153 for (const auto &option : entrance_it.second) {
135 Exit exit_obj; 154 process_single_entrance(option);
136 exit_obj.destination_room = room_id;
137
138 std::string door_room = rooms_[room_id].name;
139 if (option["room"]) {
140 door_room = option["room"].as<std::string>();
141 }
142 exit_obj.door =
143 AddOrGetDoor(door_room, option["door"].as<std::string>());
144
145 if (option["painting"]) {
146 exit_obj.painting = option["painting"].as<bool>();
147 }
148
149 rooms_[from_room_id].exits.push_back(exit_obj);
150 } 155 }
151 156
152 break; 157 break;
@@ -407,6 +412,14 @@ struct GameData {
407 doors_[door_id].exclude_reduce = 412 doors_[door_id].exclude_reduce =
408 !door_it.second["include_reduce"].as<bool>(); 413 !door_it.second["include_reduce"].as<bool>();
409 } 414 }
415
416 if (doors_[door_id].name.ends_with(" Sunwarp")) {
417 sunwarp_doors_.push_back(door_id);
418 doors_[door_id].type = DoorType::kSunwarp;
419 } else if (doors_[door_id].item_name ==
420 "Pilgrim Room - Sun Painting") {
421 doors_[door_id].type = DoorType::kSunPainting;
422 }
410 } 423 }
411 } 424 }
412 425
@@ -487,6 +500,18 @@ struct GameData {
487 } 500 }
488 } 501 }
489 502
503 if (room_it.second["sunwarps"]) {
504 for (const auto &sunwarp : room_it.second["sunwarps"]) {
505 int index = sunwarp["dots"].as<int>() - 1;
506 if (sunwarp["direction"].as<std::string>() == "exit") {
507 index += 6;
508 }
509
510 rooms_[room_id].sunwarps.push_back(index);
511 room_by_sunwarp_[index] = room_id;
512 }
513 }
514
490 if (room_it.second["progression"]) { 515 if (room_it.second["progression"]) {
491 for (const auto &progression_it : room_it.second["progression"]) { 516 for (const auto &progression_it : room_it.second["progression"]) {
492 std::string progressive_item_name = 517 std::string progressive_item_name =
@@ -654,33 +679,6 @@ struct GameData {
654 } 679 }
655 } 680 }
656 681
657 // Set up fake pilgrimage.
658 int fake_pilgrim_panel_id =
659 AddOrGetPanel("Starting Room", "!! Fake Pilgrimage Panel");
660 Panel &fake_pilgrim_panel_obj = panels_[fake_pilgrim_panel_id];
661 fake_pilgrim_panel_obj.non_counting = true;
662
663 for (const auto &config_node : pilgrimage_config) {
664 fake_pilgrim_panel_obj.required_doors.push_back(
665 AddOrGetDoor(config_node["room"].as<std::string>(),
666 config_node["door"].as<std::string>()));
667 }
668
669 int fake_pilgrim_door_id =
670 AddOrGetDoor("Starting Room", "!! Fake Pilgrimage Door");
671 Door &fake_pilgrim_door_obj = doors_[fake_pilgrim_door_id];
672 fake_pilgrim_door_obj.panels.push_back(fake_pilgrim_panel_id);
673 fake_pilgrim_door_obj.skip_location = true;
674 fake_pilgrim_door_obj.skip_item = true;
675 fake_pilgrim_door_obj.is_event = true;
676
677 int starting_room_id = AddOrGetRoom("Starting Room");
678 Room &starting_room_obj = rooms_[starting_room_id];
679 starting_room_obj.panels.push_back(fake_pilgrim_panel_id);
680 starting_room_obj.exits.push_back(
681 Exit{.destination_room = AddOrGetRoom("Pilgrim Antechamber"),
682 .door = fake_pilgrim_door_id});
683
684 // Report errors. 682 // Report errors.
685 for (const std::string &area : malconfigured_areas_) { 683 for (const std::string &area : malconfigured_areas_) {
686 std::ostringstream errstr; 684 std::ostringstream errstr;
@@ -774,6 +772,10 @@ const PanelDoor &GD_GetPanelDoor(int panel_door_id) {
774 return GetState().panel_doors_.at(panel_door_id); 772 return GetState().panel_doors_.at(panel_door_id);
775} 773}
776 774
775int GD_GetDoorByName(const std::string &name) {
776 return GetState().door_by_id_.at(name);
777}
778
777const Panel &GD_GetPanel(int panel_id) { 779const Panel &GD_GetPanel(int panel_id) {
778 return GetState().panels_.at(panel_id); 780 return GetState().panels_.at(panel_id);
779} 781}
@@ -789,3 +791,11 @@ const std::vector<int> &GD_GetAchievementPanels() {
789int GD_GetItemIdForColor(LingoColor color) { 791int GD_GetItemIdForColor(LingoColor color) {
790 return GetState().ap_id_by_color_.at(color); 792 return GetState().ap_id_by_color_.at(color);
791} 793}
794
795const std::vector<int> &GD_GetSunwarpDoors() {
796 return GetState().sunwarp_doors_;
797}
798
799int GD_GetRoomForSunwarp(int index) {
800 return GetState().room_by_sunwarp_.at(index);
801}