aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/pop
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-12-13 21:09:27 +0100
committer GitHub <noreply@github.com>2023-12-13 21:09:27 +0100
commite79ad08e28c07bac5d28d0653cbe374cd51e6bbe (patch)
tree4dbbbc2c10b8bbc6670b36f3d4ecd4d5f7e765f9 /src/openvic-simulation/pop
parentce45aaae79199e07f9249799884cbba1b3d581eb (diff)
parent89c93f98b865c20cd3c3486a9b91323565e759fc (diff)
Merge pull request #89 from OpenVicProject/dataloading-pop-history
Pop History Loading (with the new system)
Diffstat (limited to 'src/openvic-simulation/pop')
-rw-r--r--src/openvic-simulation/pop/Pop.cpp38
-rw-r--r--src/openvic-simulation/pop/Pop.hpp18
2 files changed, 40 insertions, 16 deletions
diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp
index cf54c2b..2d85dce 100644
--- a/src/openvic-simulation/pop/Pop.cpp
+++ b/src/openvic-simulation/pop/Pop.cpp
@@ -4,14 +4,18 @@
#include "openvic-simulation/dataloader/NodeTools.hpp"
#include "openvic-simulation/map/Province.hpp"
+#include "openvic-simulation/politics/Rebel.hpp"
#include "openvic-simulation/utility/Logger.hpp"
using namespace OpenVic;
using namespace OpenVic::NodeTools;
Pop::Pop(
- PopType const& new_type, Culture const& new_culture, Religion const& new_religion, pop_size_t new_size
-) : type { new_type }, culture { new_culture }, religion { new_religion }, size { new_size } {
+ PopType const& new_type, Culture const& new_culture, Religion const& new_religion, pop_size_t new_size,
+ fixed_point_t new_militancy, fixed_point_t new_consciousness, RebelType const* new_rebel_type
+) : type { new_type }, culture { new_culture }, religion { new_religion }, size { new_size }, num_promoted { 0 },
+ num_demoted { 0 }, num_migrated { 0 }, militancy { new_militancy }, consciousness { new_consciousness },
+ rebel_type { new_rebel_type } {
assert(size > 0);
}
@@ -157,26 +161,34 @@ bool PopManager::load_pop_type_file(
return ret;
}
-bool PopManager::load_pop_into_province(Province& province, std::string_view pop_type_identifier, ast::NodeCPtr pop_node)
- const {
- PopType const* type = get_pop_type_by_identifier(pop_type_identifier);
+bool PopManager::load_pop_into_vector(
+ RebelManager const& rebel_manager, std::vector<Pop>& vec, PopType const& type, ast::NodeCPtr pop_node,
+ bool *non_integer_size
+) const {
Culture const* culture = nullptr;
Religion const* religion = nullptr;
- Pop::pop_size_t size = 0;
+ fixed_point_t size = 0; /* Some genius filled later start dates with non-integer sized pops */
+ fixed_point_t militancy = 0, consciousness = 0;
+ RebelType const* rebel_type = nullptr;
+
bool ret = expect_dictionary_keys(
"culture", ONE_EXACTLY, culture_manager.expect_culture_identifier(assign_variable_callback_pointer(culture)),
"religion", ONE_EXACTLY, religion_manager.expect_religion_identifier(assign_variable_callback_pointer(religion)),
- "size", ONE_EXACTLY, expect_uint(assign_variable_callback(size)),
- "militancy", ZERO_OR_ONE, success_callback,
- "rebel_type", ZERO_OR_ONE, success_callback
+ "size", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(size)),
+ "militancy", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(militancy)),
+ "consciousness", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(consciousness)),
+ "rebel_type", ZERO_OR_ONE, rebel_manager.expect_rebel_type_identifier(assign_variable_callback_pointer(rebel_type))
)(pop_node);
- if (type != nullptr && culture != nullptr && religion != nullptr && size > 0) {
- ret &= province.add_pop({ *type, *culture, *religion, size });
+ if (non_integer_size != nullptr && !size.is_integer()) {
+ *non_integer_size = true;
+ }
+
+ if (culture != nullptr && religion != nullptr && size >= 1) {
+ vec.emplace_back(Pop { type, *culture, *religion, size.to_int64_t(), militancy, consciousness, rebel_type });
} else {
Logger::warning(
- "Some pop arguments are invalid: province = ", province, ", type = ", type, ", culture = ", culture,
- ", religion = ", religion, ", size = ", size
+ "Some pop arguments are invalid: culture = ", culture, ", religion = ", religion, ", size = ", size
);
}
return ret;
diff --git a/src/openvic-simulation/pop/Pop.hpp b/src/openvic-simulation/pop/Pop.hpp
index 736b77d..6302a58 100644
--- a/src/openvic-simulation/pop/Pop.hpp
+++ b/src/openvic-simulation/pop/Pop.hpp
@@ -9,6 +9,8 @@ namespace OpenVic {
struct PopManager;
struct PopType;
+ struct RebelType;
+ struct RebelManager;
/* REQUIREMENTS:
* POP-18, POP-19, POP-20, POP-21, POP-34, POP-35, POP-36, POP-37
@@ -27,10 +29,17 @@ namespace OpenVic {
pop_size_t PROPERTY(num_demoted);
pop_size_t PROPERTY(num_migrated);
- Pop(PopType const& new_type, Culture const& new_culture, Religion const& new_religion, pop_size_t new_size);
+ fixed_point_t PROPERTY(militancy);
+ fixed_point_t PROPERTY(consciousness);
+ RebelType const* PROPERTY(rebel_type);
+
+ Pop(
+ PopType const& new_type, Culture const& new_culture, Religion const& new_religion, pop_size_t new_size,
+ fixed_point_t new_militancy, fixed_point_t new_consciousness, RebelType const* new_rebel_type
+ );
public:
- Pop(Pop const&) = delete;
+ Pop(Pop const&) = default;
Pop(Pop&&) = default;
Pop& operator=(Pop const&) = delete;
Pop& operator=(Pop&&) = delete;
@@ -111,6 +120,9 @@ namespace OpenVic {
bool load_pop_type_file(
std::string_view filestem, UnitManager const& unit_manager, GoodManager const& good_manager, ast::NodeCPtr root
);
- bool load_pop_into_province(Province& province, std::string_view pop_type_identifier, ast::NodeCPtr pop_node) const;
+ bool load_pop_into_vector(
+ RebelManager const& rebel_manager, std::vector<Pop>& vec, PopType const& type, ast::NodeCPtr pop_node,
+ bool *non_integer_size
+ ) const;
};
}