aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp21
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.hpp2
-rw-r--r--src/openvic-simulation/pop/Pop.cpp49
-rw-r--r--src/openvic-simulation/pop/Pop.hpp22
4 files changed, 70 insertions, 24 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp
index f2e94d7..0c60524 100644
--- a/src/openvic-simulation/dataloader/Dataloader.cpp
+++ b/src/openvic-simulation/dataloader/Dataloader.cpp
@@ -452,10 +452,10 @@ csv::Windows1252Parser Dataloader::parse_csv(fs::path const& path) {
return _run_ovdl_parser<csv::Windows1252Parser, &_csv_parse>(path);
}
-bool Dataloader::_load_pop_types(PopManager& pop_manager, fs::path const& pop_type_directory) const {
+bool Dataloader::_load_pop_types(PopManager& pop_manager, UnitManager const& unit_manager, GoodManager const& good_manager, fs::path const& pop_type_directory) const {
const bool ret = apply_to_files_in_dir(pop_type_directory, ".txt",
- [&pop_manager](fs::path const& file) -> bool {
- return pop_manager.load_pop_type_file(file.stem().string(), parse_defines(file).get_file_node());
+ [&pop_manager, &unit_manager, &good_manager](fs::path const& file) -> bool {
+ return pop_manager.load_pop_type_file(file.stem().string(), unit_manager, good_manager, parse_defines(file).get_file_node());
}
);
pop_manager.lock_pop_types();
@@ -609,7 +609,15 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
Logger::error("Failed to load goods!");
ret = false;
}
- if (!_load_pop_types(game_manager.get_pop_manager(), pop_type_directory)) {
+ if (!_load_units(game_manager.get_military_manager().get_unit_manager(),
+ game_manager.get_economy_manager().get_good_manager(), units_directory)) {
+ Logger::error("Failed to load units!");
+ ret = false;
+ }
+ if (!_load_pop_types(game_manager.get_pop_manager(),
+ game_manager.get_military_manager().get_unit_manager(),
+ game_manager.get_economy_manager().get_good_manager(),
+ pop_type_directory)) {
Logger::error("Failed to load pop types!");
ret = false;
}
@@ -659,11 +667,6 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
Logger::error("Failed to load map!");
ret = false;
}
- if (!_load_units(game_manager.get_military_manager().get_unit_manager(),
- game_manager.get_economy_manager().get_good_manager(), units_directory)) {
- Logger::error("Failed to load units!");
- ret = false;
- }
if (!game_manager.get_military_manager().get_leader_trait_manager().load_leader_traits_file(game_manager.get_modifier_manager(), parse_defines(lookup_file(leader_traits_file)).get_file_node())) {
Logger::error("Failed to load leader traits!");
ret = false;
diff --git a/src/openvic-simulation/dataloader/Dataloader.hpp b/src/openvic-simulation/dataloader/Dataloader.hpp
index c268a94..45c1d46 100644
--- a/src/openvic-simulation/dataloader/Dataloader.hpp
+++ b/src/openvic-simulation/dataloader/Dataloader.hpp
@@ -23,7 +23,7 @@ namespace OpenVic {
private:
path_vector_t roots;
- bool _load_pop_types(PopManager& pop_manager, fs::path const& pop_type_directory) const;
+ bool _load_pop_types(PopManager& pop_manager, UnitManager const& unit_manager, GoodManager const& good_manager, fs::path const& pop_type_directory) const;
bool _load_units(UnitManager& unit_manager, GoodManager const& good_manager, fs::path const& units_directory) const;
bool _load_map_dir(GameManager& game_manager, fs::path const& map_directory) const;
diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp
index 14c2a41..dc53201 100644
--- a/src/openvic-simulation/pop/Pop.cpp
+++ b/src/openvic-simulation/pop/Pop.cpp
@@ -51,11 +51,17 @@ Pop::pop_size_t Pop::get_pop_daily_change() const {
PopType::PopType(std::string_view new_identifier, colour_t new_colour,
strata_t new_strata, sprite_t new_sprite,
+ Good::good_map_t&& new_life_needs, Good::good_map_t&& new_everyday_needs,
+ Good::good_map_t&& new_luxury_needs, rebel_units_t&& new_rebel_units,
Pop::pop_size_t new_max_size, Pop::pop_size_t new_merge_max_size,
bool new_state_capital_only, bool new_demote_migrant, bool new_is_artisan, bool new_is_slave)
: HasIdentifierAndColour { new_identifier, new_colour, true, false },
strata { new_strata },
sprite { new_sprite },
+ life_needs { std::move(new_life_needs) },
+ everyday_needs { std::move(new_everyday_needs) },
+ luxury_needs { std::move(new_luxury_needs) },
+ rebel_units { std::move(new_rebel_units) },
max_size { new_max_size },
merge_max_size { new_merge_max_size },
state_capital_only { new_state_capital_only },
@@ -71,6 +77,22 @@ PopType::sprite_t PopType::get_sprite() const {
return sprite;
}
+Good::good_map_t const& PopType::get_life_needs() const {
+ return life_needs;
+}
+
+Good::good_map_t const& PopType::get_everyday_needs() const {
+ return everyday_needs;
+}
+
+Good::good_map_t const& PopType::get_luxury_needs() const {
+ return luxury_needs;
+}
+
+PopType::rebel_units_t const& PopType::get_rebel_units() const {
+ return rebel_units;
+}
+
PopType::strata_t PopType::get_strata() const {
return strata;
}
@@ -117,8 +139,10 @@ ReligionManager const& PopManager::get_religion_manager() const {
return religion_manager;
}
-bool PopManager::add_pop_type(std::string_view identifier, colour_t colour, PopType::strata_t strata, PopType::sprite_t sprite,
- Pop::pop_size_t max_size, Pop::pop_size_t merge_max_size, bool state_capital_only, bool demote_migrant, bool is_artisan, bool is_slave) {
+bool PopManager::add_pop_type(std::string_view identifier, colour_t colour, PopType::strata_t strata,
+ PopType::sprite_t sprite, Good::good_map_t&& life_needs, Good::good_map_t&& everyday_needs,
+ Good::good_map_t&& luxury_needs, PopType::rebel_units_t&& rebel_units, Pop::pop_size_t max_size,
+ Pop::pop_size_t merge_max_size, bool state_capital_only, bool demote_migrant, bool is_artisan, bool is_slave) {
if (identifier.empty()) {
Logger::error("Invalid pop type identifier - empty!");
return false;
@@ -139,13 +163,15 @@ bool PopManager::add_pop_type(std::string_view identifier, colour_t colour, PopT
Logger::error("Invalid pop type merge max size for ", identifier, ": ", merge_max_size);
return false;
}
- return pop_types.add_item({ identifier, colour, strata, sprite, max_size, merge_max_size, state_capital_only, demote_migrant, is_artisan, is_slave });
+ return pop_types.add_item({ identifier, colour, strata, sprite, std::move(life_needs), std::move(everyday_needs),
+ std::move(luxury_needs), std::move(rebel_units), max_size, merge_max_size, state_capital_only, demote_migrant,
+ is_artisan, is_slave });
}
/* REQUIREMENTS:
* POP-3, POP-4, POP-5, POP-6, POP-7, POP-8, POP-9, POP-10, POP-11, POP-12, POP-13, POP-14
*/
-bool PopManager::load_pop_type_file(std::string_view filestem, ast::NodeCPtr root) {
+bool PopManager::load_pop_type_file(std::string_view filestem, UnitManager const& unit_manager, GoodManager const& good_manager, ast::NodeCPtr root) {
static const string_map_t<PopType::strata_t> strata_map = {
{ "poor", PopType::strata_t::POOR },
{ "middle", PopType::strata_t::MIDDLE },
@@ -155,6 +181,8 @@ bool PopManager::load_pop_type_file(std::string_view filestem, ast::NodeCPtr roo
colour_t colour = NULL_COLOUR;
PopType::strata_t strata = PopType::strata_t::POOR;
PopType::sprite_t sprite = 0;
+ Good::good_map_t life_needs, everyday_needs, luxury_needs;
+ PopType::rebel_units_t rebel_units;
bool state_capital_only = false, is_artisan = false, is_slave = false, demote_migrant = false;
Pop::pop_size_t max_size = 0, merge_max_size = 0;
bool ret = expect_dictionary_keys(
@@ -167,7 +195,7 @@ bool PopManager::load_pop_type_file(std::string_view filestem, ast::NodeCPtr roo
"state_capital_only", ZERO_OR_ONE, expect_bool(assign_variable_callback(state_capital_only)),
"research_points", ZERO_OR_ONE, success_callback,
"research_optimum", ZERO_OR_ONE, success_callback,
- "rebel", ZERO_OR_ONE, success_callback,
+ "rebel", ZERO_OR_ONE, unit_manager.expect_unit_decimal_map(move_variable_callback(rebel_units)),
"equivalent", ZERO_OR_ONE, success_callback,
"leadership", ZERO_OR_ONE, success_callback,
"allowed_to_vote", ZERO_OR_ONE, success_callback,
@@ -177,9 +205,9 @@ bool PopManager::load_pop_type_file(std::string_view filestem, ast::NodeCPtr roo
"life_needs_income", ZERO_OR_ONE, success_callback,
"everyday_needs_income", ZERO_OR_ONE, success_callback,
"luxury_needs_income", ZERO_OR_ONE, success_callback,
- "luxury_needs", ZERO_OR_ONE, success_callback,
- "everyday_needs", ZERO_OR_ONE, success_callback,
- "life_needs", ZERO_OR_ONE, success_callback,
+ "luxury_needs", ZERO_OR_ONE, good_manager.expect_good_decimal_map(move_variable_callback(luxury_needs)),
+ "everyday_needs", ZERO_OR_ONE, good_manager.expect_good_decimal_map(move_variable_callback(everyday_needs)),
+ "life_needs", ZERO_OR_ONE, good_manager.expect_good_decimal_map(move_variable_callback(life_needs)),
"country_migration_target", ZERO_OR_ONE, success_callback,
"migration_target", ZERO_OR_ONE, success_callback,
"promote_to", ZERO_OR_ONE, success_callback,
@@ -196,7 +224,10 @@ bool PopManager::load_pop_type_file(std::string_view filestem, ast::NodeCPtr roo
"can_work_factory", ZERO_OR_ONE, success_callback,
"unemployment", ZERO_OR_ONE, success_callback
)(root);
- ret &= add_pop_type(filestem, colour, strata, sprite, max_size, merge_max_size, state_capital_only, demote_migrant, is_artisan, is_slave);
+
+ ret &= add_pop_type(filestem, colour, strata, sprite, std::move(life_needs), std::move(everyday_needs),
+ std::move(luxury_needs), std::move(rebel_units), max_size, merge_max_size, state_capital_only, demote_migrant,
+ is_artisan, is_slave);
return ret;
}
diff --git a/src/openvic-simulation/pop/Pop.hpp b/src/openvic-simulation/pop/Pop.hpp
index e299468..26f89db 100644
--- a/src/openvic-simulation/pop/Pop.hpp
+++ b/src/openvic-simulation/pop/Pop.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include "openvic-simulation/economy/Good.hpp"
+#include "openvic-simulation/military/Unit.hpp"
#include "openvic-simulation/pop/Culture.hpp"
#include "openvic-simulation/pop/Religion.hpp"
@@ -47,6 +49,7 @@ namespace OpenVic {
friend struct PopManager;
using sprite_t = uint8_t;
+ using rebel_units_t = decimal_map_t<Unit const*>;
private:
const enum class strata_t {
@@ -55,12 +58,16 @@ namespace OpenVic {
RICH
} strata;
const sprite_t sprite;
+ const Good::good_map_t life_needs, everyday_needs, luxury_needs;
+ const rebel_units_t rebel_units;
const Pop::pop_size_t max_size, merge_max_size;
const bool state_capital_only, demote_migrant, is_artisan, is_slave;
- // TODO - rebel composition, life/everyday/luxury needs, country and province migration targets, promote_to targets, ideologies and issues
+ // TODO - country and province migration targets, promote_to targets, ideologies and issues
- PopType(std::string_view new_identifier, colour_t new_colour, strata_t new_strata, sprite_t new_sprite, Pop::pop_size_t new_max_size, Pop::pop_size_t new_merge_max_size,
+ PopType(std::string_view new_identifier, colour_t new_colour, strata_t new_strata, sprite_t new_sprite,
+ Good::good_map_t&& new_life_needs, Good::good_map_t&& new_everyday_needs, Good::good_map_t&& new_luxury_needs,
+ rebel_units_t&& new_rebel_units, Pop::pop_size_t new_max_size, Pop::pop_size_t new_merge_max_size,
bool new_state_capital_only, bool new_demote_migrant, bool new_is_artisan, bool new_is_slave);
public:
@@ -68,6 +75,10 @@ namespace OpenVic {
strata_t get_strata() const;
sprite_t get_sprite() const;
+ Good::good_map_t const& get_life_needs() const;
+ Good::good_map_t const& get_everyday_needs() const;
+ Good::good_map_t const& get_luxury_needs() const;
+ rebel_units_t const& get_rebel_units() const;
Pop::pop_size_t get_max_size() const;
Pop::pop_size_t get_merge_max_size() const;
bool get_state_capital_only() const;
@@ -94,11 +105,12 @@ namespace OpenVic {
ReligionManager const& get_religion_manager() const;
bool add_pop_type(std::string_view identifier, colour_t new_colour, PopType::strata_t strata, PopType::sprite_t sprite,
- Pop::pop_size_t max_size, Pop::pop_size_t merge_max_size, bool state_capital_only, bool demote_migrant,
- bool is_artisan, bool is_slave);
+ Good::good_map_t&& life_needs, Good::good_map_t&& everyday_needs, Good::good_map_t&& luxury_needs,
+ PopType::rebel_units_t&& rebel_units, Pop::pop_size_t max_size, Pop::pop_size_t merge_max_size,
+ bool state_capital_only, bool demote_migrant, bool is_artisan, bool is_slave);
IDENTIFIER_REGISTRY_ACCESSORS(pop_type)
- bool load_pop_type_file(std::string_view filestem, ast::NodeCPtr root);
+ 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;
};
}