diff options
Diffstat (limited to 'src/openvic-simulation/pop/Pop.cpp')
-rw-r--r-- | src/openvic-simulation/pop/Pop.cpp | 91 |
1 files changed, 64 insertions, 27 deletions
diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp index dd829d9..89ff609 100644 --- a/src/openvic-simulation/pop/Pop.cpp +++ b/src/openvic-simulation/pop/Pop.cpp @@ -2,12 +2,14 @@ #include "openvic-simulation/country/CountryDefinition.hpp" #include "openvic-simulation/country/CountryInstance.hpp" +#include "openvic-simulation/defines/Define.hpp" #include "openvic-simulation/map/ProvinceInstance.hpp" #include "openvic-simulation/military/UnitType.hpp" -#include "openvic-simulation/misc/Define.hpp" +#include "openvic-simulation/modifier/ModifierManager.hpp" #include "openvic-simulation/politics/Ideology.hpp" #include "openvic-simulation/politics/Issue.hpp" #include "openvic-simulation/politics/Rebel.hpp" +#include "openvic-simulation/utility/Logger.hpp" #include "openvic-simulation/utility/TslHelper.hpp" using namespace OpenVic; @@ -18,7 +20,7 @@ using enum PopType::income_type_t; PopBase::PopBase( 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 }, militancy { new_militancy }, +) : type { &new_type }, culture { new_culture }, religion { new_religion }, size { new_size }, militancy { new_militancy }, consciousness { new_consciousness }, rebel_type { new_rebel_type } {} Pop::Pop(PopBase const& pop_base, decltype(ideologies)::keys_t const& ideology_keys) @@ -114,6 +116,17 @@ void Pop::setup_pop_test_values(IssueManager const& issue_manager) { luxury_needs_fulfilled = test_range(); } +bool Pop::convert_to_equivalent() { + PopType const* const equivalent = get_type()->get_equivalent(); + if (equivalent == nullptr) { + Logger::error("Tried to convert pop of type ", get_type()->get_identifier(), " to equivalent, but there is no equivalent."); + return false; + } + + type = equivalent; + return true; +} + void Pop::set_location(ProvinceInstance const& new_location) { if (location != &new_location) { location = &new_location; @@ -128,22 +141,28 @@ void Pop::set_location(ProvinceInstance const& new_location) { } void Pop::update_gamestate( - DefineManager const& define_manager, CountryInstance const* owner, fixed_point_t const& pop_size_per_regiment_multiplier + DefineManager const& define_manager, CountryInstance const* owner, const fixed_point_t pop_size_per_regiment_multiplier ) { - if (type.get_can_be_recruited()) { + if (type->get_can_be_recruited()) { + MilitaryDefines const& military_defines = define_manager.get_military_defines(); + if ( - size < define_manager.get_min_pop_size_for_regiment() || owner == nullptr || + size < military_defines.get_min_pop_size_for_regiment() || owner == nullptr || !RegimentType::allowed_cultures_check_culture_in_country(owner->get_allowed_regiment_cultures(), culture, *owner) ) { max_supported_regiments = 0; } else { max_supported_regiments = (fixed_point_t::parse(size) / ( - fixed_point_t::parse(define_manager.get_pop_size_per_regiment()) * pop_size_per_regiment_multiplier + fixed_point_t::parse(military_defines.get_pop_size_per_regiment()) * pop_size_per_regiment_multiplier )).to_int64_t() + 1; } } } +//TODO store income +void Pop::add_rgo_owner_income(const fixed_point_t income) {} +void Pop::add_rgo_worker_income(const fixed_point_t income) {} + Strata::Strata(std::string_view new_identifier) : HasIdentifier { new_identifier } {} PopType::PopType( @@ -235,13 +254,13 @@ bool PopType::parse_scripts(DefinitionManager const& definition_manager) { PopManager::PopManager() : slave_sprite { 0 }, administrative_sprite { 0 }, - promotion_chance { scope_t::POP, scope_t::POP, scope_t::NO_SCOPE }, - demotion_chance { scope_t::POP, scope_t::POP, scope_t::NO_SCOPE }, - migration_chance { scope_t::POP, scope_t::POP, scope_t::NO_SCOPE }, - colonialmigration_chance { scope_t::POP, scope_t::POP, scope_t::NO_SCOPE }, - emigration_chance { scope_t::POP, scope_t::POP, scope_t::NO_SCOPE }, - assimilation_chance { scope_t::POP, scope_t::POP, scope_t::NO_SCOPE }, - conversion_chance { scope_t::POP, scope_t::POP, scope_t::NO_SCOPE } {} + promotion_chance { scope_type_t::POP, scope_type_t::POP, scope_type_t::NO_SCOPE }, + demotion_chance { scope_type_t::POP, scope_type_t::POP, scope_type_t::NO_SCOPE }, + migration_chance { scope_type_t::POP, scope_type_t::POP, scope_type_t::NO_SCOPE }, + colonialmigration_chance { scope_type_t::POP, scope_type_t::POP, scope_type_t::NO_SCOPE }, + emigration_chance { scope_type_t::POP, scope_type_t::POP, scope_type_t::NO_SCOPE }, + assimilation_chance { scope_type_t::POP, scope_type_t::POP, scope_type_t::NO_SCOPE }, + conversion_chance { scope_type_t::POP, scope_type_t::POP, scope_type_t::NO_SCOPE } {} bool PopManager::add_strata(std::string_view identifier) { if (identifier.empty()) { @@ -422,6 +441,8 @@ bool PopManager::load_pop_type_file( std::string_view filestem, GoodDefinitionManager const& good_definition_manager, IdeologyManager const& ideology_manager, ast::NodeCPtr root ) { + using enum scope_type_t; + colour_t colour = colour_t::null(); Strata const* strata = nullptr; PopType::sprite_t sprite = 0; @@ -436,8 +457,8 @@ bool PopManager::load_pop_type_file( fixed_point_t research_points = 0, leadership_points = 0, research_leadership_optimum = 0, state_administration_multiplier = 0; ast::NodeCPtr equivalent = nullptr; - ConditionalWeight country_migration_target { scope_t::COUNTRY, scope_t::POP, scope_t::NO_SCOPE }; - ConditionalWeight migration_target { scope_t::PROVINCE, scope_t::POP, scope_t::NO_SCOPE }; + ConditionalWeight country_migration_target { COUNTRY, POP, NO_SCOPE }; + ConditionalWeight migration_target { PROVINCE, POP, NO_SCOPE }; ast::NodeCPtr promote_to_node = nullptr; PopType::ideology_weight_map_t ideologies; ast::NodeCPtr issues_node = nullptr; @@ -486,9 +507,12 @@ bool PopManager::load_pop_type_file( "ideologies", ZERO_OR_ONE, ideology_manager.expect_ideology_dictionary_reserve_length( ideologies, [&filestem, &ideologies](Ideology const& ideology, ast::NodeCPtr node) -> bool { - ConditionalWeight weight { scope_t::POP, scope_t::POP, scope_t::NO_SCOPE }; + ConditionalWeight weight { POP, POP, NO_SCOPE }; + bool ret = weight.expect_conditional_weight(ConditionalWeight::FACTOR)(node); + ret &= map_callback(ideologies, &ideology)(std::move(weight)); + return ret; } ), @@ -545,7 +569,11 @@ bool PopManager::load_pop_type_file( return ret; } -bool PopManager::load_delayed_parse_pop_type_data(UnitTypeManager const& unit_type_manager, IssueManager const& issue_manager) { +bool PopManager::load_delayed_parse_pop_type_data( + UnitTypeManager const& unit_type_manager, IssueManager const& issue_manager +) { + using enum scope_type_t; + bool ret = true; for (size_t index = 0; index < delayed_parse_nodes.size(); ++index) { const auto [rebel_units, equivalent, promote_to_node, issues_node] = delayed_parse_nodes[index]; @@ -572,7 +600,7 @@ bool PopManager::load_delayed_parse_pop_type_data(UnitTypeManager const& unit_ty Logger::error("Pop type ", type, " cannot have promotion weight to itself!"); return false; } - ConditionalWeight weight { scope_t::POP, scope_t::POP, scope_t::NO_SCOPE }; + ConditionalWeight weight { POP, POP, NO_SCOPE }; bool ret = weight.expect_conditional_weight(ConditionalWeight::FACTOR)(node); ret &= map_callback(pop_type->promote_to, &type)(std::move(weight)); return ret; @@ -593,7 +621,7 @@ bool PopManager::load_delayed_parse_pop_type_data(UnitTypeManager const& unit_ty Logger::error("Invalid issue in pop type ", pop_type, " issue weights: ", key); return false; } - ConditionalWeight weight { scope_t::POP, scope_t::POP, scope_t::NO_SCOPE }; + ConditionalWeight weight { POP, POP, NO_SCOPE }; bool ret = weight.expect_conditional_weight(ConditionalWeight::FACTOR)(node); ret &= map_callback(pop_type->issues, issue)(std::move(weight)); return ret; @@ -654,24 +682,33 @@ bool PopManager::load_pop_bases_into_vector( bool PopManager::generate_modifiers(ModifierManager& modifier_manager) const { using enum ModifierEffect::format_t; + using enum ModifierEffect::target_t; + + IndexedMap<Strata, ModifierEffectCache::strata_effects_t>& strata_effects = + modifier_manager.modifier_effect_cache.strata_effects; + + strata_effects.set_keys(&get_stratas()); bool ret = true; for (Strata const& strata : get_stratas()) { const auto strata_modifier = [&modifier_manager, &ret, &strata]( - std::string_view suffix, bool is_positive_good + ModifierEffect const*& effect_cache, std::string_view suffix, bool is_positive_good ) -> void { - ret &= modifier_manager.add_modifier_effect( - StringUtils::append_string_views(strata.get_identifier(), suffix), is_positive_good + ret &= modifier_manager.register_base_country_modifier_effect( + effect_cache, StringUtils::append_string_views(strata.get_identifier(), suffix), is_positive_good, + PROPORTION_DECIMAL ); }; - strata_modifier("_income_modifier", true); - strata_modifier("_vote", true); + ModifierEffectCache::strata_effects_t& this_strata_effects = strata_effects[strata]; + + strata_modifier(this_strata_effects.income_modifier, "_income_modifier", true); // Has no effect in game + strata_modifier(this_strata_effects.vote, "_vote", true); - strata_modifier("_life_needs", false); - strata_modifier("_everyday_needs", false); - strata_modifier("_luxury_needs", false); + strata_modifier(this_strata_effects.life_needs, "_life_needs", false); + strata_modifier(this_strata_effects.everyday_needs, "_everyday_needs", false); + strata_modifier(this_strata_effects.luxury_needs, "_luxury_needs", false); } return ret; |