aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-12-14 01:21:47 +0100
committer GitHub <noreply@github.com>2023-12-14 01:21:47 +0100
commitdf7c04079a7b5936e1701f37a845199bac94b1fb (patch)
tree83d5a86fe04594feada3c82258d9c08624e542be /src
parent2e4110b26281605dde3e10f2183572d22bf773fc (diff)
parent3b6be81fb327a9c5e7bcc7c2127f513048e67480 (diff)
Merge pull request #97 from OpenVicProject/moddable-strata
Made pop type strata moddable
Diffstat (limited to 'src')
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp21
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.hpp6
-rw-r--r--src/openvic-simulation/economy/Good.cpp32
-rw-r--r--src/openvic-simulation/economy/Good.hpp2
-rw-r--r--src/openvic-simulation/military/Unit.cpp77
-rw-r--r--src/openvic-simulation/military/Unit.hpp2
-rw-r--r--src/openvic-simulation/misc/Modifier.cpp24
-rw-r--r--src/openvic-simulation/misc/Modifier.hpp2
-rw-r--r--src/openvic-simulation/politics/Rebel.cpp9
-rw-r--r--src/openvic-simulation/politics/Rebel.hpp2
-rw-r--r--src/openvic-simulation/pop/Pop.cpp67
-rw-r--r--src/openvic-simulation/pop/Pop.hpp24
-rw-r--r--src/openvic-simulation/research/Technology.cpp19
-rw-r--r--src/openvic-simulation/research/Technology.hpp2
14 files changed, 173 insertions, 116 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp
index 4687925..c23a09b 100644
--- a/src/openvic-simulation/dataloader/Dataloader.cpp
+++ b/src/openvic-simulation/dataloader/Dataloader.cpp
@@ -303,19 +303,25 @@ bool Dataloader::_load_interface_files(UIManager& ui_manager) const {
return ret;
}
-bool Dataloader::_load_pop_types(
- PopManager& pop_manager, UnitManager const& unit_manager, GoodManager const& good_manager
-) const {
+bool Dataloader::_load_pop_types(GameManager& game_manager) const {
+ PopManager& pop_manager = game_manager.get_pop_manager();
+ UnitManager const& unit_manager = game_manager.get_military_manager().get_unit_manager();
+ GoodManager const& good_manager = game_manager.get_economy_manager().get_good_manager();
+
static constexpr std::string_view pop_type_directory = "poptypes";
- const bool ret = apply_to_files(
- lookup_files_in_dir(pop_type_directory, ".txt"),
+ const path_vector_t pop_type_files = lookup_files_in_dir(pop_type_directory, ".txt");
+ pop_manager.reserve_pop_types(pop_type_files.size());
+ bool ret = apply_to_files(
+ pop_type_files,
[&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_stratas();
pop_manager.lock_pop_types();
+ ret &= pop_manager.generate_modifiers(game_manager.get_modifier_manager());
return ret;
}
@@ -726,10 +732,7 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
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()
- )) {
+ if (!_load_pop_types(game_manager)) {
Logger::error("Failed to load pop types!");
ret = false;
}
diff --git a/src/openvic-simulation/dataloader/Dataloader.hpp b/src/openvic-simulation/dataloader/Dataloader.hpp
index 3512e59..107c93a 100644
--- a/src/openvic-simulation/dataloader/Dataloader.hpp
+++ b/src/openvic-simulation/dataloader/Dataloader.hpp
@@ -11,10 +11,6 @@ namespace OpenVic {
struct GameManager;
class UIManager;
- struct PopManager;
- struct UnitManager;
- struct GoodManager;
- struct EventManager;
class Dataloader {
public:
@@ -24,7 +20,7 @@ namespace OpenVic {
path_vector_t roots;
bool _load_interface_files(UIManager& ui_manager) const;
- bool _load_pop_types(PopManager& pop_manager, UnitManager const& unit_manager, GoodManager const& good_manager) const;
+ bool _load_pop_types(GameManager& game_manager) const;
bool _load_units(GameManager& game_manager) const;
bool _load_goods(GameManager& game_manager) const;
bool _load_rebel_types(GameManager& game_manager) const;
diff --git a/src/openvic-simulation/economy/Good.cpp b/src/openvic-simulation/economy/Good.cpp
index 5500483..44b896b 100644
--- a/src/openvic-simulation/economy/Good.cpp
+++ b/src/openvic-simulation/economy/Good.cpp
@@ -94,22 +94,22 @@ bool GoodManager::load_goods_file(ast::NodeCPtr root) {
return ret;
}
-#define GOOD_MODIFIER(name) \
- modifier_manager.register_complex_modifier(name); \
- for (Good const& good : this->get_goods()) { \
- ret &= modifier_manager.add_modifier_effect( \
- StringUtils::append_string_views(name, "_", good.get_identifier()), \
- true \
- ); \
- }
-
-bool GoodManager::generate_modifiers(ModifierManager& modifier_manager) {
+bool GoodManager::generate_modifiers(ModifierManager& modifier_manager) const {
bool ret = true;
- GOOD_MODIFIER("factory_goods_output");
- GOOD_MODIFIER("factory_goods_throughput");
- GOOD_MODIFIER("rgo_goods_output");
- GOOD_MODIFIER("rgo_size");
+
+ const auto good_modifier = [this, &modifier_manager, &ret](std::string_view name) -> void {
+ ret &= modifier_manager.register_complex_modifier(name);
+ for (Good const& good : get_goods()) {
+ ret &= modifier_manager.add_modifier_effect(
+ StringUtils::append_string_views(name, "_", good.get_identifier()), true
+ );
+ }
+ };
+
+ good_modifier("factory_goods_output");
+ good_modifier("factory_goods_throughput");
+ good_modifier("rgo_goods_output");
+ good_modifier("rgo_size");
+
return ret;
}
-
-#undef GOOD_MODIFIER \ No newline at end of file
diff --git a/src/openvic-simulation/economy/Good.hpp b/src/openvic-simulation/economy/Good.hpp
index c595768..d9d4251 100644
--- a/src/openvic-simulation/economy/Good.hpp
+++ b/src/openvic-simulation/economy/Good.hpp
@@ -76,6 +76,6 @@ namespace OpenVic {
void reset_to_defaults();
bool load_goods_file(ast::NodeCPtr root);
- bool generate_modifiers(ModifierManager& modifier_manager);
+ bool generate_modifiers(ModifierManager& modifier_manager) const;
};
}
diff --git a/src/openvic-simulation/military/Unit.cpp b/src/openvic-simulation/military/Unit.cpp
index 01c6f84..98fe392 100644
--- a/src/openvic-simulation/military/Unit.cpp
+++ b/src/openvic-simulation/military/Unit.cpp
@@ -188,52 +188,53 @@ bool UnitManager::load_unit_file(GoodManager const& good_manager, ast::NodeCPtr
})(root);
}
-#define STAT_MODIFIER(name, positive_good, format) \
- ret &= modifier_manager.add_modifier_effect(StringUtils::append_string_views(identifier, "_", name), positive_good, ModifierEffect::format_t::format)
+bool UnitManager::generate_modifiers(ModifierManager& modifier_manager) const {
+ bool ret = true;
+
+ const auto generate_stat_modifiers = [&modifier_manager, &ret](std::string_view identifier, Unit::type_t type) -> void {
+
+ const auto stat_modifier = [&modifier_manager, &ret, &identifier](std::string_view suffix, bool positive_good,
+ ModifierEffect::format_t format) -> void {
+ ret &= modifier_manager.add_modifier_effect(
+ StringUtils::append_string_views(identifier, suffix), positive_good, format
+ );
+ };
-bool UnitManager::generate_modifiers(ModifierManager& modifier_manager) {
- std::function<bool(std::string_view, Unit::type_t)> generate_stat_modifiers = [this, &modifier_manager](std::string_view identifier, Unit::type_t type) -> bool {
- modifier_manager.register_complex_modifier(identifier);
- bool ret = true;
+ using enum ModifierEffect::format_t;
- STAT_MODIFIER("default_organisation", true, RAW_DECIMAL);
- STAT_MODIFIER("maximum_speed", true, RAW_DECIMAL);
- STAT_MODIFIER("build_time", false, INT);
- STAT_MODIFIER("supply_consumption", false, PROPORTION_DECIMAL);
+ ret &= modifier_manager.register_complex_modifier(identifier);
+
+ stat_modifier("_default_organisation", true, RAW_DECIMAL);
+ stat_modifier("_maximum_speed", true, RAW_DECIMAL);
+ stat_modifier("_build_time", false, INT);
+ stat_modifier("_supply_consumption", false, PROPORTION_DECIMAL);
switch (type) {
- case Unit::type_t::LAND: {
- STAT_MODIFIER("reconnaissance", true, RAW_DECIMAL);
- STAT_MODIFIER("attack", true, RAW_DECIMAL);
- STAT_MODIFIER("defence", true, RAW_DECIMAL);
- STAT_MODIFIER("discipline", true, PROPORTION_DECIMAL);
- STAT_MODIFIER("support", true, PROPORTION_DECIMAL);
- STAT_MODIFIER("maneuver", true, INT);
- STAT_MODIFIER("siege", true, RAW_DECIMAL);
+ case Unit::type_t::LAND:
+ stat_modifier("_reconnaissance", true, RAW_DECIMAL);
+ stat_modifier("_attack", true, RAW_DECIMAL);
+ stat_modifier("_defence", true, RAW_DECIMAL);
+ stat_modifier("_discipline", true, PROPORTION_DECIMAL);
+ stat_modifier("_support", true, PROPORTION_DECIMAL);
+ stat_modifier("_maneuver", true, INT);
+ stat_modifier("_siege", true, RAW_DECIMAL);
break;
- }
- case Unit::type_t::NAVAL: {
- STAT_MODIFIER("colonial_points", true, INT);
- STAT_MODIFIER("supply_consumption_score", false, INT);
- STAT_MODIFIER("hull", true, RAW_DECIMAL);
- STAT_MODIFIER("gun_power", true, RAW_DECIMAL);
- STAT_MODIFIER("fire_range", true, RAW_DECIMAL);
- STAT_MODIFIER("evasion", true, PROPORTION_DECIMAL);
- STAT_MODIFIER("torpedo_attack", true, RAW_DECIMAL);
+ case Unit::type_t::NAVAL:
+ stat_modifier("_colonial_points", true, INT);
+ stat_modifier("_supply_consumption_score", false, INT);
+ stat_modifier("_hull", true, RAW_DECIMAL);
+ stat_modifier("_gun_power", true, RAW_DECIMAL);
+ stat_modifier("_fire_range", true, RAW_DECIMAL);
+ stat_modifier("_evasion", true, PROPORTION_DECIMAL);
+ stat_modifier("_torpedo_attack", true, RAW_DECIMAL);
break;
}
- }
-
- return ret;
};
- bool ret = true;
- ret &= generate_stat_modifiers("army_base", Unit::type_t::LAND);
- ret &= generate_stat_modifiers("navy_base", Unit::type_t::NAVAL);
- for (Unit const& unit : this->get_units())
- ret &= generate_stat_modifiers(unit.get_identifier(), unit.get_type());
-
+ generate_stat_modifiers("army_base", Unit::type_t::LAND);
+ generate_stat_modifiers("navy_base", Unit::type_t::NAVAL);
+ for (Unit const& unit : get_units()) {
+ generate_stat_modifiers(unit.get_identifier(), unit.get_type());
+ }
return ret;
}
-
-#undef STAT_MODIFIER \ No newline at end of file
diff --git a/src/openvic-simulation/military/Unit.hpp b/src/openvic-simulation/military/Unit.hpp
index 6e3a6e4..a44f4e5 100644
--- a/src/openvic-simulation/military/Unit.hpp
+++ b/src/openvic-simulation/military/Unit.hpp
@@ -122,6 +122,6 @@ namespace OpenVic {
static NodeTools::callback_t<std::string_view> expect_type_str(NodeTools::Callback<Unit::type_t> auto callback);
bool load_unit_file(GoodManager const& good_manager, ast::NodeCPtr root);
- bool generate_modifiers(ModifierManager& modifier_manager);
+ bool generate_modifiers(ModifierManager& modifier_manager) const;
};
}
diff --git a/src/openvic-simulation/misc/Modifier.cpp b/src/openvic-simulation/misc/Modifier.cpp
index ac052c2..40698e5 100644
--- a/src/openvic-simulation/misc/Modifier.cpp
+++ b/src/openvic-simulation/misc/Modifier.cpp
@@ -132,11 +132,6 @@ bool ModifierManager::setup_modifier_effects() {
ret &= add_modifier_effect("max_tariff", true);
ret &= add_modifier_effect("max_tax", true);
ret &= add_modifier_effect("max_war_exhaustion", true, PERCENTAGE_DECIMAL);
- ret &= add_modifier_effect("middle_income_modifier", true);
- ret &= add_modifier_effect("middle_life_needs", true);
- ret &= add_modifier_effect("middle_everyday_needs", true);
- ret &= add_modifier_effect("middle_luxury_needs", true);
- ret &= add_modifier_effect("middle_vote", true);
ret &= add_modifier_effect("min_military_spending", true);
ret &= add_modifier_effect("min_social_spending", true);
ret &= add_modifier_effect("min_tariff", true);
@@ -150,11 +145,6 @@ bool ModifierManager::setup_modifier_effects() {
ret &= add_modifier_effect("non_accepted_pop_militancy_modifier", false, RAW_DECIMAL);
ret &= add_modifier_effect("org_regain", true);
ret &= add_modifier_effect("political_reform_desire", false);
- ret &= add_modifier_effect("poor_income_modifier", true);
- ret &= add_modifier_effect("poor_life_needs", true);
- ret &= add_modifier_effect("poor_everyday_needs", true);
- ret &= add_modifier_effect("poor_luxury_needs", true);
- ret &= add_modifier_effect("poor_vote", true);
ret &= add_modifier_effect("prestige", true, RAW_DECIMAL);
ret &= add_modifier_effect("research_points", true, RAW_DECIMAL);
ret &= add_modifier_effect("research_points_modifier", true);
@@ -163,11 +153,6 @@ bool ModifierManager::setup_modifier_effects() {
ret &= add_modifier_effect("RGO_output", true);
ret &= add_modifier_effect("rgo_throughput", true);
ret &= add_modifier_effect("RGO_throughput", true);
- ret &= add_modifier_effect("rich_income_modifier", true);
- ret &= add_modifier_effect("rich_life_needs", true);
- ret &= add_modifier_effect("rich_everyday_needs", true);
- ret &= add_modifier_effect("rich_luxury_needs", true);
- ret &= add_modifier_effect("rich_vote", true);
ret &= add_modifier_effect("ruling_party_support", true);
ret &= add_modifier_effect("social_reform_desire", false);
ret &= add_modifier_effect("supply_consumption", false);
@@ -249,8 +234,13 @@ bool ModifierManager::setup_modifier_effects() {
return ret;
}
-void ModifierManager::register_complex_modifier(std::string_view identifier) {
- complex_modifiers.emplace(identifier);
+bool ModifierManager::register_complex_modifier(std::string_view identifier) {
+ if (complex_modifiers.emplace(identifier).second) {
+ return true;
+ } else {
+ Logger::error("Duplicate complex modifier: ", identifier);
+ return false;
+ }
}
bool ModifierManager::add_event_modifier(std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon) {
diff --git a/src/openvic-simulation/misc/Modifier.hpp b/src/openvic-simulation/misc/Modifier.hpp
index a176d6c..f3a2499 100644
--- a/src/openvic-simulation/misc/Modifier.hpp
+++ b/src/openvic-simulation/misc/Modifier.hpp
@@ -129,7 +129,7 @@ namespace OpenVic {
ModifierEffect::format_t format = ModifierEffect::format_t::PROPORTION_DECIMAL
);
- void register_complex_modifier(std::string_view identifier);
+ bool register_complex_modifier(std::string_view identifier);
bool setup_modifier_effects();
diff --git a/src/openvic-simulation/politics/Rebel.cpp b/src/openvic-simulation/politics/Rebel.cpp
index a00b4a8..6850e83 100644
--- a/src/openvic-simulation/politics/Rebel.cpp
+++ b/src/openvic-simulation/politics/Rebel.cpp
@@ -142,16 +142,17 @@ bool RebelManager::load_rebels_file(
return ret;
}
-bool RebelManager::generate_modifiers(ModifierManager& modifier_manager) {
+bool RebelManager::generate_modifiers(ModifierManager& modifier_manager) const {
bool ret = true;
- modifier_manager.register_complex_modifier("rebel_org_gain");
+ ret &= modifier_manager.register_complex_modifier("rebel_org_gain");
ret &= modifier_manager.add_modifier_effect("rebel_org_gain_all", false);
for (RebelType const& rebel_type : get_rebel_types()) {
- std::string modifier_name = StringUtils::append_string_views("rebel_org_gain_", rebel_type.get_identifier());
- ret &= modifier_manager.add_modifier_effect(modifier_name, false);
+ ret &= modifier_manager.add_modifier_effect(
+ StringUtils::append_string_views("rebel_org_gain_", rebel_type.get_identifier()), false
+ );
}
return ret;
} \ No newline at end of file
diff --git a/src/openvic-simulation/politics/Rebel.hpp b/src/openvic-simulation/politics/Rebel.hpp
index c0fc9ff..29ae3ae 100644
--- a/src/openvic-simulation/politics/Rebel.hpp
+++ b/src/openvic-simulation/politics/Rebel.hpp
@@ -77,6 +77,6 @@ namespace OpenVic {
);
bool load_rebels_file(IdeologyManager const& ideology_manager, GovernmentTypeManager const& government_type_manager, ast::NodeCPtr root);
- bool generate_modifiers(ModifierManager& modifier_manager);
+ bool generate_modifiers(ModifierManager& modifier_manager) const;
};
} \ No newline at end of file
diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp
index 2d85dce..39deeaa 100644
--- a/src/openvic-simulation/pop/Pop.cpp
+++ b/src/openvic-simulation/pop/Pop.cpp
@@ -23,8 +23,10 @@ Pop::pop_size_t Pop::get_pop_daily_change() const {
return Pop::get_num_promoted() - (Pop::get_num_demoted() + Pop::get_num_migrated());
}
+Strata::Strata(std::string_view new_identifier) : HasIdentifier { new_identifier } {}
+
PopType::PopType(
- std::string_view new_identifier, colour_t new_colour, strata_t new_strata, sprite_t new_sprite,
+ std::string_view new_identifier, colour_t new_colour, Strata const& 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_allowed_to_vote, bool new_is_slave,
@@ -46,8 +48,16 @@ PopType::PopType(
PopManager::PopManager() : slave_sprite { 0 }, administrative_sprite { 0 } {}
+bool PopManager::add_strata(std::string_view identifier) {
+ if (identifier.empty()) {
+ Logger::error("Invalid strata identifier - empty!");
+ return false;
+ }
+ return stratas.add_item({ identifier });
+}
+
bool PopManager::add_pop_type(
- std::string_view identifier, colour_t colour, PopType::strata_t strata, PopType::sprite_t sprite,
+ std::string_view identifier, colour_t colour, Strata const* 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 allowed_to_vote, bool is_slave, bool can_be_recruited,
@@ -62,6 +72,10 @@ bool PopManager::add_pop_type(
Logger::error("Invalid pop type colour for ", identifier, ": ", colour_to_hex_string(colour));
return false;
}
+ if (strata == nullptr) {
+ Logger::error("Invalid pop type strata for ", identifier, " - null!");
+ return false;
+ }
if (sprite <= 0) {
Logger::error("Invalid pop type sprite index for ", identifier, ": ", sprite);
return false;
@@ -75,7 +89,7 @@ bool PopManager::add_pop_type(
return false;
}
const bool ret = pop_types.add_item({
- identifier, colour, strata, sprite, std::move(life_needs), std::move(everyday_needs),
+ 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, allowed_to_vote, is_slave, can_be_recruited, can_reduce_consciousness,
administrative_efficiency, can_build, factory, can_work_factory, unemployment
@@ -91,20 +105,19 @@ bool PopManager::add_pop_type(
return ret;
}
+void PopManager::reserve_pop_types(size_t count) {
+ stratas.reserve(stratas.size() + count);
+ pop_types.reserve(pop_types.size() + count);
+}
+
/* 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, 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 },
- { "rich", PopType::strata_t::RICH }
- };
-
colour_t colour = NULL_COLOUR;
- PopType::strata_t strata = PopType::strata_t::POOR;
+ Strata const* strata = nullptr;
PopType::sprite_t sprite = 0;
Good::good_map_t life_needs, everyday_needs, luxury_needs;
PopType::rebel_units_t rebel_units;
@@ -118,7 +131,19 @@ bool PopManager::load_pop_type_file(
"is_artisan", ZERO_OR_ONE, expect_bool(assign_variable_callback(is_artisan)),
"max_size", ZERO_OR_ONE, expect_uint(assign_variable_callback(max_size)),
"merge_max_size", ZERO_OR_ONE, expect_uint(assign_variable_callback(merge_max_size)),
- "strata", ONE_EXACTLY, expect_identifier(expect_mapped_string(strata_map, assign_variable_callback(strata))),
+ "strata", ONE_EXACTLY, expect_identifier(
+ [this, &strata](std::string_view identifier) -> bool {
+ strata = get_strata_by_identifier(identifier);
+ if (strata != nullptr) {
+ return true;
+ }
+ if (add_strata(identifier)) {
+ strata = &get_stratas().back();
+ return true;
+ }
+ return false;
+ }
+ ),
"state_capital_only", ZERO_OR_ONE, expect_bool(assign_variable_callback(state_capital_only)),
"research_points", ZERO_OR_ONE, success_callback, // TODO - research points generation
"research_optimum", ZERO_OR_ONE, success_callback, // TODO - bonus research points generation
@@ -193,3 +218,23 @@ bool PopManager::load_pop_into_vector(
}
return ret;
}
+
+bool PopManager::generate_modifiers(ModifierManager& modifier_manager) const {
+ bool ret = true;
+ for (Strata const& strata : get_stratas()) {
+ const auto strata_modifier = [&modifier_manager, &ret, &strata](std::string_view suffix, bool positive_good) -> void {
+ ret &= modifier_manager.add_modifier_effect(
+ StringUtils::append_string_views(strata.get_identifier(), suffix), positive_good
+ );
+ };
+
+ strata_modifier("_income_modifier", true);
+ strata_modifier("_savings_modifier", true);
+ strata_modifier("_vote", true);
+
+ strata_modifier("_life_needs", false);
+ strata_modifier("_everyday_needs", false);
+ strata_modifier("_luxury_needs", false);
+ }
+ return ret;
+}
diff --git a/src/openvic-simulation/pop/Pop.hpp b/src/openvic-simulation/pop/Pop.hpp
index 6302a58..0c84aae 100644
--- a/src/openvic-simulation/pop/Pop.hpp
+++ b/src/openvic-simulation/pop/Pop.hpp
@@ -47,6 +47,16 @@ namespace OpenVic {
pop_size_t get_pop_daily_change() const;
};
+ struct Strata : HasIdentifier {
+ friend struct PopManager;
+
+ private:
+ Strata(std::string_view new_identifier);
+
+ public:
+ Strata(Strata&&) = default;
+ };
+
/* REQUIREMENTS:
* POP-15, POP-16, POP-17, POP-26
*/
@@ -57,7 +67,7 @@ namespace OpenVic {
using rebel_units_t = fixed_point_map_t<Unit const*>;
private:
- const enum class strata_t { POOR, MIDDLE, RICH } PROPERTY(strata);
+ Strata const& PROPERTY(strata);
const sprite_t PROPERTY(sprite);
const Good::good_map_t PROPERTY(life_needs);
const Good::good_map_t PROPERTY(everyday_needs);
@@ -81,7 +91,7 @@ namespace OpenVic {
// 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,
+ std::string_view new_identifier, colour_t new_colour, Strata const& 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_allowed_to_vote,
@@ -98,6 +108,8 @@ namespace OpenVic {
struct PopManager {
private:
+ /* Using strata/stratas instead of stratum/strata to avoid confusion. */
+ IdentifierRegistry<Strata> IDENTIFIER_REGISTRY(strata);
IdentifierRegistry<PopType> IDENTIFIER_REGISTRY(pop_type);
PopType::sprite_t PROPERTY(slave_sprite);
PopType::sprite_t PROPERTY(administrative_sprite);
@@ -108,8 +120,10 @@ namespace OpenVic {
public:
PopManager();
+ bool add_strata(std::string_view identifier);
+
bool add_pop_type(
- std::string_view identifier, colour_t new_colour, PopType::strata_t strata, PopType::sprite_t sprite,
+ std::string_view identifier, colour_t new_colour, Strata const* 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 allowed_to_vote, bool is_slave,
@@ -117,6 +131,8 @@ namespace OpenVic {
bool can_work_factory, bool unemployment
);
+ void reserve_pop_types(size_t count);
+
bool load_pop_type_file(
std::string_view filestem, UnitManager const& unit_manager, GoodManager const& good_manager, ast::NodeCPtr root
);
@@ -124,5 +140,7 @@ namespace OpenVic {
RebelManager const& rebel_manager, std::vector<Pop>& vec, PopType const& type, ast::NodeCPtr pop_node,
bool *non_integer_size
) const;
+
+ bool generate_modifiers(ModifierManager& modifier_manager) const;
};
}
diff --git a/src/openvic-simulation/research/Technology.cpp b/src/openvic-simulation/research/Technology.cpp
index 3ba3624..7851707 100644
--- a/src/openvic-simulation/research/Technology.cpp
+++ b/src/openvic-simulation/research/Technology.cpp
@@ -143,19 +143,22 @@ bool TechnologyManager::load_technologies_file(
})(root);
}
-#define TECH_MODIFIER(NAME, POS) ret &= modifier_manager.add_modifier_effect(NAME, POS)
-#define UNCIV_TECH_MODIFIER(NAME) TECH_MODIFIER(NAME, false); TECH_MODIFIER(StringUtils::append_string_views("self_", NAME), false);
-bool TechnologyManager::generate_modifiers(ModifierManager& modifier_manager) {
+bool TechnologyManager::generate_modifiers(ModifierManager& modifier_manager) const {
bool ret = true;
- UNCIV_TECH_MODIFIER("unciv_military_modifier");
- UNCIV_TECH_MODIFIER("unciv_economic_modifier");
+ const auto unciv_tech_modifier = [&modifier_manager, &ret](std::string_view name) -> void {
+ ret &= modifier_manager.add_modifier_effect(name, false);
+ ret &= modifier_manager.add_modifier_effect(StringUtils::append_string_views("self_", name), false);
+ };
+
+ unciv_tech_modifier("unciv_military_modifier");
+ unciv_tech_modifier("unciv_economic_modifier");
for (TechnologyFolder const& folder : get_technology_folders()) {
- TECH_MODIFIER(StringUtils::append_string_views(folder.get_identifier(), "_research_bonus"), true);
+ ret &= modifier_manager.add_modifier_effect(
+ StringUtils::append_string_views(folder.get_identifier(), "_research_bonus"), true
+ );
}
return ret;
}
-#undef UNCIV_TECH_MODIFIER
-#undef TECH_MODIFIER \ No newline at end of file
diff --git a/src/openvic-simulation/research/Technology.hpp b/src/openvic-simulation/research/Technology.hpp
index 8489e9b..1035a8e 100644
--- a/src/openvic-simulation/research/Technology.hpp
+++ b/src/openvic-simulation/research/Technology.hpp
@@ -87,6 +87,6 @@ namespace OpenVic {
ModifierManager const& modifier_manager, UnitManager const& unit_manager,
BuildingTypeManager const& building_type_manager, ast::NodeCPtr root
); // technologies/*.txt
- bool generate_modifiers(ModifierManager& modifier_manager);
+ bool generate_modifiers(ModifierManager& modifier_manager) const;
};
} \ No newline at end of file