diff options
author | hop311 <hop3114@gmail.com> | 2023-12-31 01:47:31 +0100 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-01-02 14:41:28 +0100 |
commit | 5f64f983d0cead266a28791be42162c443fd2a75 (patch) | |
tree | da5fbb48d6c01d6faedd16b46ff846c65fdb4c33 /src/openvic-simulation/pop/Pop.hpp | |
parent | 9988b21278dc1c8df044631bd2935a7e450a7bff (diff) |
Added framework for loading all Conditions and Effects
Diffstat (limited to 'src/openvic-simulation/pop/Pop.hpp')
-rw-r--r-- | src/openvic-simulation/pop/Pop.hpp | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/src/openvic-simulation/pop/Pop.hpp b/src/openvic-simulation/pop/Pop.hpp index 0c84aae..2304165 100644 --- a/src/openvic-simulation/pop/Pop.hpp +++ b/src/openvic-simulation/pop/Pop.hpp @@ -4,6 +4,7 @@ #include "openvic-simulation/military/Unit.hpp" #include "openvic-simulation/pop/Culture.hpp" #include "openvic-simulation/pop/Religion.hpp" +#include "openvic-simulation/scripts/ConditionalWeight.hpp" namespace OpenVic { @@ -11,6 +12,10 @@ namespace OpenVic { struct PopType; struct RebelType; struct RebelManager; + struct Ideology; + struct IdeologyManager; + struct Issue; + struct IssueManager; /* REQUIREMENTS: * POP-18, POP-19, POP-20, POP-21, POP-34, POP-35, POP-36, POP-37 @@ -65,14 +70,17 @@ namespace OpenVic { using sprite_t = uint8_t; using rebel_units_t = fixed_point_map_t<Unit const*>; + using poptype_weight_map_t = ordered_map<PopType const*, ConditionalWeight>; + using ideology_weight_map_t = ordered_map<Ideology const*, ConditionalWeight>; + using issue_weight_map_t = ordered_map<Issue const*, ConditionalWeight>; private: 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); - const Good::good_map_t PROPERTY(luxury_needs); - const rebel_units_t PROPERTY(rebel_units); + Good::good_map_t PROPERTY(life_needs); + Good::good_map_t PROPERTY(everyday_needs); + Good::good_map_t PROPERTY(luxury_needs); + rebel_units_t PROPERTY(rebel_units); const Pop::pop_size_t PROPERTY(max_size); const Pop::pop_size_t PROPERTY(merge_max_size); const bool PROPERTY(state_capital_only); @@ -88,7 +96,11 @@ namespace OpenVic { const bool PROPERTY(can_work_factory); const bool PROPERTY(unemployment); - // TODO - country and province migration targets, promote_to targets, ideologies and issues + ConditionalWeight PROPERTY(country_migration_target); /* Scope - country, THIS - pop */ + ConditionalWeight PROPERTY(migration_target); /* Scope - province, THIS - pop */ + poptype_weight_map_t PROPERTY(promote_to); /* Scope - pop */ + ideology_weight_map_t PROPERTY(ideologies); /* Scope - pop */ + issue_weight_map_t PROPERTY(issues); /* Scope - province, THIS - country (?) */ PopType( std::string_view new_identifier, colour_t new_colour, Strata const& new_strata, sprite_t new_sprite, @@ -97,9 +109,12 @@ namespace OpenVic { bool new_state_capital_only, bool new_demote_migrant, bool new_is_artisan, bool new_allowed_to_vote, bool new_is_slave, bool new_can_be_recruited, bool new_can_reduce_consciousness, bool new_administrative_efficiency, bool new_can_build, bool new_factory, bool new_can_work_factory, - bool new_unemployment + bool new_unemployment, ConditionalWeight&& new_country_migration_target, ConditionalWeight&& new_migration_target, + poptype_weight_map_t&& new_promote_to, ideology_weight_map_t&& new_ideologies, issue_weight_map_t&& new_issues ); + bool parse_scripts(GameManager const& game_manager); + public: PopType(PopType&&) = default; }; @@ -111,6 +126,20 @@ namespace OpenVic { /* Using strata/stratas instead of stratum/strata to avoid confusion. */ IdentifierRegistry<Strata> IDENTIFIER_REGISTRY(strata); IdentifierRegistry<PopType> IDENTIFIER_REGISTRY(pop_type); + /* promote_to can't be parsed until after all PopTypes are registered, and issues requires Issues to be loaded, + * which themselves depend on pop strata. To get around this, the nodes for these variables are stored here and + * parsed after both PopTypes and Issues. The nodes will remain valid as PopType files' Parser objects are cached + * to preserve their condition script nodes until all other defines are loaded and the scripts can be parsed. */ + std::vector<std::pair<ast::NodeCPtr, ast::NodeCPtr>> delayed_parse_promote_to_and_issues_nodes; + + ConditionalWeight PROPERTY(promotion_chance); + ConditionalWeight PROPERTY(demotion_chance); + ConditionalWeight PROPERTY(migration_chance); + ConditionalWeight PROPERTY(colonialmigration_chance); + ConditionalWeight PROPERTY(emigration_chance); + ConditionalWeight PROPERTY(assimilation_chance); + ConditionalWeight PROPERTY(conversion_chance); + PopType::sprite_t PROPERTY(slave_sprite); PopType::sprite_t PROPERTY(administrative_sprite); @@ -128,19 +157,28 @@ namespace OpenVic { 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, bool can_reduce_consciousness, bool administrative_efficiency, bool can_build, bool factory, - bool can_work_factory, bool unemployment + bool can_work_factory, bool unemployment, ConditionalWeight&& country_migration_target, + ConditionalWeight&& migration_target, ast::NodeCPtr promote_to_node, PopType::ideology_weight_map_t&& ideologies, + ast::NodeCPtr issues_node ); 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 + std::string_view filestem, UnitManager const& unit_manager, GoodManager const& good_manager, + IdeologyManager const& ideology_manager, ast::NodeCPtr root ); + bool load_delayed_parse_pop_type_data(IssueManager const& issue_manager); + + bool load_pop_type_chances_file(ast::NodeCPtr root); + 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; bool generate_modifiers(ModifierManager& modifier_manager) const; + + bool parse_scripts(GameManager const& game_manager); }; } |