aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map/Map.cpp
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-09-16 17:27:41 +0200
committer Hop311 <hop3114@gmail.com>2023-09-16 17:28:01 +0200
commitf95902fdd85f86c10b9c300099c67312fc81f11b (patch)
tree1655119602f39a366de8248cb4651321b6dfdda0 /src/openvic-simulation/map/Map.cpp
parent64d134ad20c333afa60373526d6fab27a07c6adc (diff)
Scaffolding for `positions.txt` + modifier loading
Diffstat (limited to 'src/openvic-simulation/map/Map.cpp')
-rw-r--r--src/openvic-simulation/map/Map.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/openvic-simulation/map/Map.cpp b/src/openvic-simulation/map/Map.cpp
index e8178e9..29bec7b 100644
--- a/src/openvic-simulation/map/Map.cpp
+++ b/src/openvic-simulation/map/Map.cpp
@@ -428,7 +428,7 @@ bool Map::setup(GoodManager const& good_manager, BuildingManager const& building
for (Province& province : provinces.get_items()) {
province.clear_pops();
// Set all land provinces to have an RGO based on their index to test them
- if (!province.get_water() && !good_manager.get_good_count() > 0)
+ if (!province.get_water() && good_manager.get_good_count() > 0)
province.rgo = good_manager.get_good_by_index(province.get_index() % good_manager.get_good_count());
ret &= building_manager.generate_province_buildings(province);
}
@@ -476,6 +476,17 @@ static bool parse_province_colour(colour_t& colour, std::array<std::string_view,
return ret;
}
+node_callback_t Map::expect_province_dictionary(callback_t<Province&, ast::NodeCPtr> callback) {
+ return expect_dictionary([this, callback](std::string_view key, ast::NodeCPtr value) -> bool {
+ Province* province = get_province_by_identifier(key);
+ if (province != nullptr) {
+ return callback(*province, value);
+ }
+ Logger::error("Invalid province identifier: ", key);
+ return false;
+ });
+}
+
bool Map::load_province_definitions(std::vector<LineObject> const& lines) {
if (lines.empty()) {
Logger::error("No header or entries in province definition file!");
@@ -512,6 +523,14 @@ bool Map::load_province_definitions(std::vector<LineObject> const& lines) {
return ret;
}
+bool Map::load_province_positions(ast::NodeCPtr root) {
+ return expect_province_dictionary(
+ [](Province& province, ast::NodeCPtr node) -> bool {
+ return province.load_positions(node);
+ }
+ )(root);
+}
+
bool Map::load_region_file(ast::NodeCPtr root) {
const bool ret = expect_dictionary_reserve_length(
regions,