aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map
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
parent64d134ad20c333afa60373526d6fab27a07c6adc (diff)
Scaffolding for `positions.txt` + modifier loading
Diffstat (limited to 'src/openvic-simulation/map')
-rw-r--r--src/openvic-simulation/map/Map.cpp21
-rw-r--r--src/openvic-simulation/map/Map.hpp2
-rw-r--r--src/openvic-simulation/map/Province.cpp6
-rw-r--r--src/openvic-simulation/map/Province.hpp2
4 files changed, 30 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,
diff --git a/src/openvic-simulation/map/Map.hpp b/src/openvic-simulation/map/Map.hpp
index d5157ef..0e00055 100644
--- a/src/openvic-simulation/map/Map.hpp
+++ b/src/openvic-simulation/map/Map.hpp
@@ -112,7 +112,9 @@ namespace OpenVic {
void update_state(Date const& today);
void tick(Date const& today);
+ NodeTools::node_callback_t expect_province_dictionary(NodeTools::callback_t<Province&, ast::NodeCPtr> callback);
bool load_province_definitions(std::vector<ovdl::csv::LineObject> const& lines);
+ bool load_province_positions(ast::NodeCPtr root);
bool load_region_file(ast::NodeCPtr root);
};
}
diff --git a/src/openvic-simulation/map/Province.cpp b/src/openvic-simulation/map/Province.cpp
index 49a9bfc..5a3543b 100644
--- a/src/openvic-simulation/map/Province.cpp
+++ b/src/openvic-simulation/map/Province.cpp
@@ -34,6 +34,12 @@ Province::life_rating_t Province::get_life_rating() const {
return life_rating;
}
+bool Province::load_positions(ast::NodeCPtr root) {
+ // TODO - implement province position loading
+ // (root is the dictionary after the province identifier)
+ return true;
+}
+
bool Province::add_building(Building&& building) {
return buildings.add_item(std::move(building));
}
diff --git a/src/openvic-simulation/map/Province.hpp b/src/openvic-simulation/map/Province.hpp
index ca8138f..d4e34c5 100644
--- a/src/openvic-simulation/map/Province.hpp
+++ b/src/openvic-simulation/map/Province.hpp
@@ -43,6 +43,8 @@ namespace OpenVic {
bool get_has_region() const;
bool get_water() const;
life_rating_t get_life_rating() const;
+ bool load_positions(ast::NodeCPtr root);
+
bool add_building(Building&& building);
IDENTIFIER_REGISTRY_ACCESSORS(Building, building)
void reset_buildings();