From 5f3e1f3b1b021cbee243236ad8947f203d0416be Mon Sep 17 00:00:00 2001 From: Hop311 Date: Thu, 14 Sep 2023 09:34:54 +0100 Subject: Region + localisation loading --- src/openvic-simulation/map/Map.cpp | 24 ++++++++++++++++++++++++ src/openvic-simulation/map/Map.hpp | 1 + 2 files changed, 25 insertions(+) (limited to 'src/openvic-simulation/map') diff --git a/src/openvic-simulation/map/Map.cpp b/src/openvic-simulation/map/Map.cpp index 728fc42..74764d2 100644 --- a/src/openvic-simulation/map/Map.cpp +++ b/src/openvic-simulation/map/Map.cpp @@ -7,6 +7,7 @@ #include "openvic-simulation/utility/Logger.hpp" using namespace OpenVic; +using namespace OpenVic::NodeTools; Mapmode::Mapmode(const std::string_view new_identifier, index_t new_index, colour_func_t new_colour_func) : HasIdentifier { new_identifier }, @@ -503,3 +504,26 @@ bool Map::load_province_definitions(std::vector const& lines) { lock_provinces(); return ret; } + +/* TODO - add support for non-state province groupings used by some mods + * (currently they trigger "province already in other region" errors). + */ +bool Map::load_region_file(ast::NodeCPtr root) { + const bool ret = expect_dictionary_reserve_length( + regions, + [this](std::string_view region_identifier, ast::NodeCPtr region_node) -> bool { + std::vector province_identifiers; + bool ret = expect_list_reserve_length( + province_identifiers, + expect_identifier([&province_identifiers](std::string_view identifier) -> bool { + province_identifiers.push_back(identifier); + return true; + }) + )(region_node); + ret &= add_region(region_identifier, province_identifiers); + return ret; + } + )(root); + lock_regions(); + return ret; +} diff --git a/src/openvic-simulation/map/Map.hpp b/src/openvic-simulation/map/Map.hpp index 71719e2..d5157ef 100644 --- a/src/openvic-simulation/map/Map.hpp +++ b/src/openvic-simulation/map/Map.hpp @@ -113,5 +113,6 @@ namespace OpenVic { void tick(Date const& today); bool load_province_definitions(std::vector const& lines); + bool load_region_file(ast::NodeCPtr root); }; } -- cgit v1.2.3-56-ga3b1