aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/map')
-rw-r--r--src/openvic-simulation/map/Map.cpp14
-rw-r--r--src/openvic-simulation/map/Map.hpp4
-rw-r--r--src/openvic-simulation/map/Province.cpp36
-rw-r--r--src/openvic-simulation/map/Province.hpp17
-rw-r--r--src/openvic-simulation/map/TerrainType.cpp2
5 files changed, 39 insertions, 34 deletions
diff --git a/src/openvic-simulation/map/Map.cpp b/src/openvic-simulation/map/Map.cpp
index 4df17bf..7e2213e 100644
--- a/src/openvic-simulation/map/Map.cpp
+++ b/src/openvic-simulation/map/Map.cpp
@@ -42,6 +42,12 @@ bool Map::add_province(std::string_view identifier, colour_t colour) {
Logger::error("Invalid province identifier - empty!");
return false;
}
+ if (!valid_basic_identifier(identifier)) {
+ Logger::error(
+ "Invalid province identifier: ", identifier, " (can only contain alphanumeric characters and underscores)"
+ );
+ return false;
+ }
if (colour == NULL_COLOUR || colour > MAX_COLOUR_RGB) {
Logger::error("Invalid province colour for ", identifier, ": ", colour_to_hex_string(colour));
return false;
@@ -292,7 +298,7 @@ bool Map::setup(BuildingManager const& building_manager, PopManager const& pop_m
return ret;
}
-void Map::update_state(Date const& today) {
+void Map::update_state(Date today) {
for (Province& province : provinces.get_items()) {
province.update_state(today);
}
@@ -300,7 +306,7 @@ void Map::update_state(Date const& today) {
update_total_map_population();
}
-void Map::tick(Date const& today) {
+void Map::tick(Date today) {
for (Province& province : provinces.get_items()) {
province.tick(today);
}
@@ -483,7 +489,7 @@ bool Map::load_map_images(fs::path const& province_path, fs::path const& terrain
uint8_t const* terrain_data = terrain_bmp.get_pixel_data().data();
std::vector<bool> province_checklist(provinces.size());
- std::vector<distribution_t> terrain_type_pixels_list(provinces.size());
+ std::vector<decimal_map_t<TerrainType const*>> terrain_type_pixels_list(provinces.size());
bool ret = true;
std::unordered_set<colour_t> unrecognised_province_colours;
@@ -514,7 +520,7 @@ bool Map::load_map_images(fs::path const& province_path, fs::path const& terrain
goto set_terrain;
}
}
- if (unrecognised_province_colours.find(province_colour) == unrecognised_province_colours.end()) {
+ if (!unrecognised_province_colours.contains(province_colour)) {
unrecognised_province_colours.insert(province_colour);
if (detailed_errors) {
Logger::warning(
diff --git a/src/openvic-simulation/map/Map.hpp b/src/openvic-simulation/map/Map.hpp
index 61b7b48..d11ad8e 100644
--- a/src/openvic-simulation/map/Map.hpp
+++ b/src/openvic-simulation/map/Map.hpp
@@ -108,8 +108,8 @@ namespace OpenVic {
void update_total_map_population();
Pop::pop_size_t get_total_map_population() const;
- void update_state(Date const& today);
- void tick(Date const& today);
+ void update_state(Date today);
+ void tick(Date today);
bool load_province_definitions(std::vector<ovdl::csv::LineObject> const& lines);
bool load_province_positions(BuildingManager const& building_manager, ast::NodeCPtr root);
diff --git a/src/openvic-simulation/map/Province.cpp b/src/openvic-simulation/map/Province.cpp
index 225d4c0..77bf33f 100644
--- a/src/openvic-simulation/map/Province.cpp
+++ b/src/openvic-simulation/map/Province.cpp
@@ -5,7 +5,7 @@ using namespace OpenVic::NodeTools;
Province::Province(
std::string_view new_identifier, colour_t new_colour, index_t new_index
-) : HasIdentifierAndColour { new_identifier, new_colour, false, false }, index { new_index },
+) : HasIdentifierAndColour { new_identifier, new_colour, true, false }, index { new_index },
buildings { "buildings", false } {
assert(index != NULL_INDEX);
}
@@ -38,6 +38,10 @@ Province::life_rating_t Province::get_life_rating() const {
return life_rating;
}
+Province::colony_status_t Province::get_colony_status() const {
+ return colony_status;
+}
+
bool Province::load_positions(BuildingManager const& building_manager, ast::NodeCPtr root) {
return expect_dictionary_keys(
"text_position", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(positions.text)),
@@ -127,42 +131,32 @@ Pop::pop_size_t Province::get_total_population() const {
return total_population;
}
-distribution_t const& Province::get_pop_type_distribution() const {
- return pop_types;
-}
-
-distribution_t const& Province::get_culture_distribution() const {
- return cultures;
-}
-
-distribution_t const& Province::get_religion_distribution() const {
- return religions;
-}
-
/* REQUIREMENTS:
* MAP-65, MAP-68, MAP-70, MAP-234
*/
void Province::update_pops() {
total_population = 0;
- pop_types.clear();
- cultures.clear();
- religions.clear();
+ pop_type_distribution.clear();
+ ideology_distribution.clear();
+ culture_distribution.clear();
+ religion_distribution.clear();
for (Pop const& pop : pops) {
total_population += pop.get_size();
- pop_types[&pop.get_type()] += pop.get_size();
- cultures[&pop.get_culture()] += pop.get_size();
- religions[&pop.get_religion()] += pop.get_size();
+ pop_type_distribution[&pop.get_type()] += pop.get_size();
+ //ideology_distribution[&pop.get_???()] += pop.get_size();
+ culture_distribution[&pop.get_culture()] += pop.get_size();
+ religion_distribution[&pop.get_religion()] += pop.get_size();
}
}
-void Province::update_state(Date const& today) {
+void Province::update_state(Date today) {
for (BuildingInstance& building : buildings.get_items()) {
building.update_state(today);
}
update_pops();
}
-void Province::tick(Date const& today) {
+void Province::tick(Date today) {
for (BuildingInstance& building : buildings.get_items()) {
building.tick(today);
}
diff --git a/src/openvic-simulation/map/Province.hpp b/src/openvic-simulation/map/Province.hpp
index 2704354..2fd15c9 100644
--- a/src/openvic-simulation/map/Province.hpp
+++ b/src/openvic-simulation/map/Province.hpp
@@ -3,6 +3,7 @@
#include <cassert>
#include "openvic-simulation/economy/Building.hpp"
+#include "openvic-simulation/politics/Ideology.hpp"
#include "openvic-simulation/pop/Pop.hpp"
namespace OpenVic {
@@ -24,6 +25,8 @@ namespace OpenVic {
using distance_t = uint16_t;
using flags_t = uint16_t;
+ enum struct colony_status_t : int8_t { STATE, PROTECTORATE, COLONY };
+
struct adjacency_t {
friend struct Province;
@@ -63,13 +66,17 @@ namespace OpenVic {
Region* region = nullptr;
bool on_map = false, has_region = false, water = false;
life_rating_t life_rating = 0;
+ colony_status_t colony_status = colony_status_t::STATE;
IdentifierRegistry<BuildingInstance> buildings;
// TODO - change this into a factory-like structure
Good const* rgo = nullptr;
std::vector<Pop> pops;
Pop::pop_size_t total_population;
- distribution_t pop_types, cultures, religions;
+ decimal_map_t<PopType const*> PROPERTY(pop_type_distribution);
+ decimal_map_t<Ideology const*> PROPERTY(ideology_distribution);
+ decimal_map_t<Culture const*> PROPERTY(culture_distribution);
+ decimal_map_t<Religion const*> PROPERTY(religion_distribution);
std::vector<adjacency_t> adjacencies;
province_positions_t positions;
@@ -90,6 +97,7 @@ namespace OpenVic {
bool get_water() const;
TerrainType const* get_terrain_type() const;
life_rating_t get_life_rating() const;
+ colony_status_t get_colony_status() const;
bool load_positions(BuildingManager const& building_manager, ast::NodeCPtr root);
bool add_building(BuildingInstance&& building_instance);
@@ -105,13 +113,10 @@ namespace OpenVic {
size_t get_pop_count() const;
std::vector<Pop> const& get_pops() const;
Pop::pop_size_t get_total_population() const;
- distribution_t const& get_pop_type_distribution() const;
- distribution_t const& get_culture_distribution() const;
- distribution_t const& get_religion_distribution() const;
void update_pops();
- void update_state(Date const& today);
- void tick(Date const& today);
+ void update_state(Date today);
+ void tick(Date today);
bool is_adjacent_to(Province const* province);
bool add_adjacency(Province const* province, distance_t distance, flags_t flags);
diff --git a/src/openvic-simulation/map/TerrainType.cpp b/src/openvic-simulation/map/TerrainType.cpp
index 1753246..796089e 100644
--- a/src/openvic-simulation/map/TerrainType.cpp
+++ b/src/openvic-simulation/map/TerrainType.cpp
@@ -7,7 +7,7 @@ using namespace OpenVic::NodeTools;
TerrainType::TerrainType(
std::string_view new_identifier, colour_t new_colour, ModifierValue&& new_modifier, bool new_is_water
-) : HasIdentifierAndColour { new_identifier, new_colour, true, false }, modifier { std::move(new_modifier) },
+) : HasIdentifierAndColour { new_identifier, new_colour, false, false }, modifier { std::move(new_modifier) },
is_water { new_is_water } {}
ModifierValue const& TerrainType::get_modifier() const {