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 ee818c4..c98f532 100644 --- a/src/game_data.cpp +++ b/src/game_data.cpp
@@ -53,11 +53,14 @@ struct GameData {
53 std::vector<int> door_definition_order_; 53 std::vector<int> door_definition_order_;
54 54
55 std::map<std::string, int> room_by_painting_; 55 std::map<std::string, int> room_by_painting_;
56 std::map<int, int> room_by_sunwarp_;
56 57
57 std::vector<int> achievement_panels_; 58 std::vector<int> achievement_panels_;
58 59
59 std::map<LingoColor, int> ap_id_by_color_; 60 std::map<LingoColor, int> ap_id_by_color_;
60 61
62 std::vector<int> sunwarp_doors_;
63
61 bool loaded_area_data_ = false; 64 bool loaded_area_data_ = false;
62 std::set<std::string> malconfigured_areas_; 65 std::set<std::string> malconfigured_areas_;
63 66
@@ -66,8 +69,6 @@ struct GameData {
66 YAML::LoadFile(GetAbsolutePath("assets/LL1.yaml")); 69 YAML::LoadFile(GetAbsolutePath("assets/LL1.yaml"));
67 YAML::Node areas_config = 70 YAML::Node areas_config =
68 YAML::LoadFile(GetAbsolutePath("assets/areas.yaml")); 71 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")); 72 YAML::Node ids_config = YAML::LoadFile(GetAbsolutePath("assets/ids.yaml"));
72 73
73 auto init_color_id = [this, &ids_config](const std::string &color_name) { 74 auto init_color_id = [this, &ids_config](const std::string &color_name) {
@@ -102,6 +103,40 @@ struct GameData {
102 for (const auto &entrance_it : room_it.second["entrances"]) { 103 for (const auto &entrance_it : room_it.second["entrances"]) {
103 int from_room_id = AddOrGetRoom(entrance_it.first.as<std::string>()); 104 int from_room_id = AddOrGetRoom(entrance_it.first.as<std::string>());
104 105
106 auto process_single_entrance =
107 [this, room_id, from_room_id](const YAML::Node &option) {
108 Exit exit_obj;
109 exit_obj.destination_room = room_id;
110
111 if (option["door"]) {
112 std::string door_room = rooms_[room_id].name;
113 if (option["room"]) {
114 door_room = option["room"].as<std::string>();
115 }
116 exit_obj.door =
117 AddOrGetDoor(door_room, option["door"].as<std::string>());
118 }
119
120 if (option["painting"] && option["painting"].as<bool>()) {
121 exit_obj.type = EntranceType::kPainting;
122 }
123
124 if (option["sunwarp"] && option["sunwarp"].as<bool>()) {
125 exit_obj.type = EntranceType::kSunwarp;
126 }
127
128 if (option["warp"] && option["warp"].as<bool>()) {
129 exit_obj.type = EntranceType::kWarp;
130 }
131
132 if (rooms_[from_room_id].name == "Crossroads" &&
133 rooms_[room_id].name == "Roof") {
134 exit_obj.type = EntranceType::kCrossroadsRoofAccess;
135 }
136
137 rooms_[from_room_id].exits.push_back(exit_obj);
138 };
139
105 switch (entrance_it.second.Type()) { 140 switch (entrance_it.second.Type()) {
106 case YAML::NodeType::Scalar: { 141 case YAML::NodeType::Scalar: {
107 // This is just "true". 142 // This is just "true".
@@ -109,42 +144,12 @@ struct GameData {
109 break; 144 break;
110 } 145 }
111 case YAML::NodeType::Map: { 146 case YAML::NodeType::Map: {
112 Exit exit_obj; 147 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; 148 break;
130 } 149 }
131 case YAML::NodeType::Sequence: { 150 case YAML::NodeType::Sequence: {
132 for (const auto &option : entrance_it.second) { 151 for (const auto &option : entrance_it.second) {
133 Exit exit_obj; 152 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 } 153 }
149 154
150 break; 155 break;
@@ -405,6 +410,14 @@ struct GameData {
405 doors_[door_id].exclude_reduce = 410 doors_[door_id].exclude_reduce =
406 !door_it.second["include_reduce"].as<bool>(); 411 !door_it.second["include_reduce"].as<bool>();
407 } 412 }
413
414 if (doors_[door_id].name.ends_with(" Sunwarp")) {
415 sunwarp_doors_.push_back(door_id);
416 doors_[door_id].type = DoorType::kSunwarp;
417 } else if (doors_[door_id].item_name ==
418 "Pilgrim Room - Sun Painting") {
419 doors_[door_id].type = DoorType::kSunPainting;
420 }
408 } 421 }
409 } 422 }
410 423
@@ -432,6 +445,18 @@ struct GameData {
432 } 445 }
433 } 446 }
434 447
448 if (room_it.second["sunwarps"]) {
449 for (const auto &sunwarp : room_it.second["sunwarps"]) {
450 int index = sunwarp["dots"].as<int>() - 1;
451 if (sunwarp["direction"].as<std::string>() == "exit") {
452 index += 6;
453 }
454
455 rooms_[room_id].sunwarps.push_back(index);
456 room_by_sunwarp_[index] = room_id;
457 }
458 }
459
435 if (room_it.second["progression"]) { 460 if (room_it.second["progression"]) {
436 for (const auto &progression_it : room_it.second["progression"]) { 461 for (const auto &progression_it : room_it.second["progression"]) {
437 std::string progressive_item_name = 462 std::string progressive_item_name =
@@ -575,33 +600,6 @@ struct GameData {
575 } 600 }
576 } 601 }
577 602
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. 603 // Report errors.
606 for (const std::string &area : malconfigured_areas_) { 604 for (const std::string &area : malconfigured_areas_) {
607 std::ostringstream errstr; 605 std::ostringstream errstr;
@@ -679,6 +677,10 @@ const std::vector<Door> &GD_GetDoors() { return GetState().doors_; }
679 677
680const Door &GD_GetDoor(int door_id) { return GetState().doors_.at(door_id); } 678const Door &GD_GetDoor(int door_id) { return GetState().doors_.at(door_id); }
681 679
680int GD_GetDoorByName(const std::string &name) {
681 return GetState().door_by_id_.at(name);
682}
683
682const Panel &GD_GetPanel(int panel_id) { 684const Panel &GD_GetPanel(int panel_id) {
683 return GetState().panels_.at(panel_id); 685 return GetState().panels_.at(panel_id);
684} 686}
@@ -694,3 +696,11 @@ const std::vector<int> &GD_GetAchievementPanels() {
694int GD_GetItemIdForColor(LingoColor color) { 696int GD_GetItemIdForColor(LingoColor color) {
695 return GetState().ap_id_by_color_.at(color); 697 return GetState().ap_id_by_color_.at(color);
696} 698}
699
700const std::vector<int> &GD_GetSunwarpDoors() {
701 return GetState().sunwarp_doors_;
702}
703
704int GD_GetRoomForSunwarp(int index) {
705 return GetState().room_by_sunwarp_.at(index);
706}