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.cpp113
1 files changed, 108 insertions, 5 deletions
diff --git a/src/game_data.cpp b/src/game_data.cpp index 06eb80a..f51d7ac 100644 --- a/src/game_data.cpp +++ b/src/game_data.cpp
@@ -30,7 +30,10 @@ LingoColor GetColorForString(const std::string &str) {
30 } else if (str == "purple") { 30 } else if (str == "purple") {
31 return LingoColor::kPurple; 31 return LingoColor::kPurple;
32 } else { 32 } else {
33 std::cout << "Invalid color: " << str << std::endl; 33 std::ostringstream errmsg;
34 errmsg << "Invalid color: " << str;
35 TrackerLog(errmsg.str());
36
34 return LingoColor::kNone; 37 return LingoColor::kNone;
35 } 38 }
36} 39}
@@ -52,6 +55,8 @@ struct GameData {
52 55
53 std::vector<int> achievement_panels_; 56 std::vector<int> achievement_panels_;
54 57
58 std::map<LingoColor, int> ap_id_by_color_;
59
55 bool loaded_area_data_ = false; 60 bool loaded_area_data_ = false;
56 std::set<std::string> malconfigured_areas_; 61 std::set<std::string> malconfigured_areas_;
57 62
@@ -59,6 +64,31 @@ struct GameData {
59 YAML::Node lingo_config = YAML::LoadFile("assets/LL1.yaml"); 64 YAML::Node lingo_config = YAML::LoadFile("assets/LL1.yaml");
60 YAML::Node areas_config = YAML::LoadFile("assets/areas.yaml"); 65 YAML::Node areas_config = YAML::LoadFile("assets/areas.yaml");
61 YAML::Node pilgrimage_config = YAML::LoadFile("assets/pilgrimage.yaml"); 66 YAML::Node pilgrimage_config = YAML::LoadFile("assets/pilgrimage.yaml");
67 YAML::Node ids_config = YAML::LoadFile("assets/ids.yaml");
68
69 auto init_color_id = [this, &ids_config](const std::string &color_name) {
70 if (ids_config["special_items"] &&
71 ids_config["special_items"][color_name]) {
72 std::string input_name = color_name;
73 input_name[0] = std::tolower(input_name[0]);
74 ap_id_by_color_[GetColorForString(input_name)] =
75 ids_config["special_items"][color_name].as<int>();
76 } else {
77 std::ostringstream errmsg;
78 errmsg << "Missing AP item ID for color " << color_name;
79 TrackerLog(errmsg.str());
80 }
81 };
82
83 init_color_id("Black");
84 init_color_id("Red");
85 init_color_id("Blue");
86 init_color_id("Yellow");
87 init_color_id("Green");
88 init_color_id("Orange");
89 init_color_id("Purple");
90 init_color_id("Brown");
91 init_color_id("Gray");
62 92
63 rooms_.reserve(lingo_config.size() * 2); 93 rooms_.reserve(lingo_config.size() * 2);
64 94
@@ -225,6 +255,17 @@ struct GameData {
225 if (panel_it.second["non_counting"]) { 255 if (panel_it.second["non_counting"]) {
226 panel_obj.non_counting = panel_it.second["non_counting"].as<bool>(); 256 panel_obj.non_counting = panel_it.second["non_counting"].as<bool>();
227 } 257 }
258
259 if (ids_config["panels"] && ids_config["panels"][room_obj.name] &&
260 ids_config["panels"][room_obj.name][panel_obj.name]) {
261 panel_obj.ap_location_id =
262 ids_config["panels"][room_obj.name][panel_obj.name].as<int>();
263 } else {
264 std::ostringstream errmsg;
265 errmsg << "Missing AP location ID for panel " << room_obj.name
266 << " - " << panel_obj.name;
267 TrackerLog(errmsg.str());
268 }
228 } 269 }
229 } 270 }
230 271
@@ -272,8 +313,34 @@ struct GameData {
272 door_obj.item_name = room_obj.name + " - " + door_obj.name; 313 door_obj.item_name = room_obj.name + " - " + door_obj.name;
273 } 314 }
274 315
316 if (!door_it.second["skip_item"] && !door_it.second["event"]) {
317 if (ids_config["doors"] && ids_config["doors"][room_obj.name] &&
318 ids_config["doors"][room_obj.name][door_obj.name] &&
319 ids_config["doors"][room_obj.name][door_obj.name]["item"]) {
320 door_obj.ap_item_id =
321 ids_config["doors"][room_obj.name][door_obj.name]["item"]
322 .as<int>();
323 } else {
324 std::ostringstream errmsg;
325 errmsg << "Missing AP item ID for door " << room_obj.name << " - "
326 << door_obj.name;
327 TrackerLog(errmsg.str());
328 }
329 }
330
275 if (door_it.second["group"]) { 331 if (door_it.second["group"]) {
276 door_obj.group_name = door_it.second["group"].as<std::string>(); 332 door_obj.group_name = door_it.second["group"].as<std::string>();
333
334 if (ids_config["door_groups"] &&
335 ids_config["door_groups"][door_obj.group_name]) {
336 door_obj.group_ap_item_id =
337 ids_config["door_groups"][door_obj.group_name].as<int>();
338 } else {
339 std::ostringstream errmsg;
340 errmsg << "Missing AP item ID for door group "
341 << door_obj.group_name;
342 TrackerLog(errmsg.str());
343 }
277 } 344 }
278 345
279 if (door_it.second["location_name"]) { 346 if (door_it.second["location_name"]) {
@@ -282,18 +349,34 @@ struct GameData {
282 } else if (!door_it.second["skip_location"] && 349 } else if (!door_it.second["skip_location"] &&
283 !door_it.second["event"]) { 350 !door_it.second["event"]) {
284 if (has_external_panels) { 351 if (has_external_panels) {
285 std::cout 352 std::ostringstream errmsg;
353 errmsg
286 << room_obj.name << " - " << door_obj.name 354 << room_obj.name << " - " << door_obj.name
287 << " has panels from other rooms but does not have an " 355 << " has panels from other rooms but does not have an "
288 "explicit " 356 "explicit "
289 "location name and is not marked skip_location or event" 357 "location name and is not marked skip_location or event";
290 << std::endl; 358 TrackerLog(errmsg.str());
291 } 359 }
292 360
293 door_obj.location_name = 361 door_obj.location_name =
294 room_obj.name + " - " + hatkirby::implode(panel_names, ", "); 362 room_obj.name + " - " + hatkirby::implode(panel_names, ", ");
295 } 363 }
296 364
365 if (!door_it.second["skip_location"] && !door_it.second["event"]) {
366 if (ids_config["doors"] && ids_config["doors"][room_obj.name] &&
367 ids_config["doors"][room_obj.name][door_obj.name] &&
368 ids_config["doors"][room_obj.name][door_obj.name]["location"]) {
369 door_obj.ap_location_id =
370 ids_config["doors"][room_obj.name][door_obj.name]["location"]
371 .as<int>();
372 } else {
373 std::ostringstream errmsg;
374 errmsg << "Missing AP location ID for door " << room_obj.name
375 << " - " << door_obj.name;
376 TrackerLog(errmsg.str());
377 }
378 }
379
297 if (door_it.second["include_reduce"]) { 380 if (door_it.second["include_reduce"]) {
298 door_obj.exclude_reduce = 381 door_obj.exclude_reduce =
299 !door_it.second["include_reduce"].as<bool>(); 382 !door_it.second["include_reduce"].as<bool>();
@@ -330,6 +413,18 @@ struct GameData {
330 std::string progressive_item_name = 413 std::string progressive_item_name =
331 progression_it.first.as<std::string>(); 414 progression_it.first.as<std::string>();
332 415
416 int progressive_item_id = -1;
417 if (ids_config["progression"] &&
418 ids_config["progression"][progressive_item_name]) {
419 progressive_item_id =
420 ids_config["progression"][progressive_item_name].as<int>();
421 } else {
422 std::ostringstream errmsg;
423 errmsg << "Missing AP item ID for progressive item "
424 << progressive_item_name;
425 TrackerLog(errmsg.str());
426 }
427
333 int index = 1; 428 int index = 1;
334 for (const auto &stage : progression_it.second) { 429 for (const auto &stage : progression_it.second) {
335 int door_id = -1; 430 int door_id = -1;
@@ -342,7 +437,9 @@ struct GameData {
342 } 437 }
343 438
344 doors_[door_id].progressives.push_back( 439 doors_[door_id].progressives.push_back(
345 {.item_name = progressive_item_name, .quantity = index}); 440 {.item_name = progressive_item_name,
441 .ap_item_id = progressive_item_id,
442 .quantity = index});
346 index++; 443 index++;
347 } 444 }
348 } 445 }
@@ -393,6 +490,7 @@ struct GameData {
393 map_area.locations.push_back( 490 map_area.locations.push_back(
394 {.name = panel.name, 491 {.name = panel.name,
395 .ap_location_name = room_name + " - " + panel.name, 492 .ap_location_name = room_name + " - " + panel.name,
493 .ap_location_id = panel.ap_location_id,
396 .room = panel.room, 494 .room = panel.room,
397 .panels = {panel.id}, 495 .panels = {panel.id},
398 .classification = classification}); 496 .classification = classification});
@@ -436,6 +534,7 @@ struct GameData {
436 // room field should be the original room ID 534 // room field should be the original room ID
437 map_area.locations.push_back({.name = section_name, 535 map_area.locations.push_back({.name = section_name,
438 .ap_location_name = door.location_name, 536 .ap_location_name = door.location_name,
537 .ap_location_id = door.ap_location_id,
439 .room = door.room, 538 .room = door.room,
440 .panels = door.panels, 539 .panels = door.panels,
441 .classification = classification}); 540 .classification = classification});
@@ -564,3 +663,7 @@ int GD_GetRoomForPainting(const std::string &painting_id) {
564const std::vector<int> &GD_GetAchievementPanels() { 663const std::vector<int> &GD_GetAchievementPanels() {
565 return GetState().achievement_panels_; 664 return GetState().achievement_panels_;
566} 665}
666
667int GD_GetItemIdForColor(LingoColor color) {
668 return GetState().ap_id_by_color_.at(color);
669}