diff options
author | hop311 <hop3114@gmail.com> | 2023-10-12 21:19:00 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2023-10-12 21:19:00 +0200 |
commit | e50c67eb1aaa54f5fb31425f81616bea4e6b880a (patch) | |
tree | c4fbc6ee494f8ad33a8de36be5fc300165ce05fc /src/openvic-simulation/pop | |
parent | bb22324da1225a0ac458c1d69893bb3bd28bd6b7 (diff) |
Lots of accumulated changes
Diffstat (limited to 'src/openvic-simulation/pop')
-rw-r--r-- | src/openvic-simulation/pop/Culture.cpp | 16 | ||||
-rw-r--r-- | src/openvic-simulation/pop/Culture.hpp | 6 | ||||
-rw-r--r-- | src/openvic-simulation/pop/Pop.cpp | 36 | ||||
-rw-r--r-- | src/openvic-simulation/pop/Pop.hpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/pop/Religion.cpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/pop/Religion.hpp | 4 |
6 files changed, 26 insertions, 40 deletions
diff --git a/src/openvic-simulation/pop/Culture.cpp b/src/openvic-simulation/pop/Culture.cpp index 6285305..261ad4c 100644 --- a/src/openvic-simulation/pop/Culture.cpp +++ b/src/openvic-simulation/pop/Culture.cpp @@ -118,16 +118,12 @@ bool CultureManager::_load_culture_group(size_t& total_expected_cultures, GraphicalCultureType const* unit_graphical_culture_type = default_unit_graphical_culture_type; bool is_overseas = true; - bool ret = expect_dictionary_keys_and_length( - [&total_expected_cultures](size_t size) -> size_t { - total_expected_cultures += size; - return size; - }, - ALLOW_OTHER_KEYS, - "leader", ONE_EXACTLY, decrement_callback(total_expected_cultures, expect_identifier(assign_variable_callback(leader))), - "unit", ZERO_OR_ONE, decrement_callback(total_expected_cultures, expect_graphical_culture_type_identifier(assign_variable_callback_pointer(unit_graphical_culture_type))), - "union", ZERO_OR_ONE, decrement_callback(total_expected_cultures, success_callback), - "is_overseas", ZERO_OR_ONE, decrement_callback(total_expected_cultures, expect_bool(assign_variable_callback(is_overseas))) + bool ret = expect_dictionary_keys_and_default( + increment_callback(total_expected_cultures), + "leader", ONE_EXACTLY, expect_identifier(assign_variable_callback(leader)), + "unit", ZERO_OR_ONE, expect_identifier(expect_graphical_culture_type_identifier(assign_variable_callback_pointer(unit_graphical_culture_type))), + "union", ZERO_OR_ONE, success_callback, + "is_overseas", ZERO_OR_ONE, expect_bool(assign_variable_callback(is_overseas)) )(culture_group_node); ret &= add_culture_group(culture_group_key, leader, unit_graphical_culture_type, is_overseas); return ret; diff --git a/src/openvic-simulation/pop/Culture.hpp b/src/openvic-simulation/pop/Culture.hpp index becc289..b6b4952 100644 --- a/src/openvic-simulation/pop/Culture.hpp +++ b/src/openvic-simulation/pop/Culture.hpp @@ -69,13 +69,13 @@ namespace OpenVic { CultureManager(); bool add_graphical_culture_type(std::string_view identifier); - IDENTIFIER_REGISTRY_ACCESSORS(GraphicalCultureType, graphical_culture_type) + IDENTIFIER_REGISTRY_ACCESSORS(graphical_culture_type) bool add_culture_group(std::string_view identifier, std::string_view leader, GraphicalCultureType const* new_graphical_culture_type, bool is_overseas); - IDENTIFIER_REGISTRY_ACCESSORS(CultureGroup, culture_group) + IDENTIFIER_REGISTRY_ACCESSORS(culture_group) bool add_culture(std::string_view identifier, colour_t colour, CultureGroup const* group, std::vector<std::string> const& first_names, std::vector<std::string> const& last_names); - IDENTIFIER_REGISTRY_ACCESSORS(Culture, culture) + IDENTIFIER_REGISTRY_ACCESSORS(culture) bool load_graphical_culture_type_file(ast::NodeCPtr root); bool load_culture_file(ast::NodeCPtr root); diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp index 38cd883..14c2a41 100644 --- a/src/openvic-simulation/pop/Pop.cpp +++ b/src/openvic-simulation/pop/Pop.cpp @@ -146,34 +146,24 @@ bool PopManager::add_pop_type(std::string_view identifier, colour_t colour, PopT * 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) { + 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; PopType::sprite_t sprite = 0; 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( - "sprite", ONE_EXACTLY, expect_uint(assign_variable_callback_uint(sprite)), + "sprite", ONE_EXACTLY, expect_uint(assign_variable_callback(sprite)), "color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)), "is_artisan", ZERO_OR_ONE, expect_bool(assign_variable_callback(is_artisan)), - "max_size", ZERO_OR_ONE, expect_uint(assign_variable_callback_uint(max_size)), - "merge_max_size", ZERO_OR_ONE, expect_uint(assign_variable_callback_uint(merge_max_size)), - "strata", ONE_EXACTLY, expect_identifier( - [&strata](std::string_view identifier) -> bool { - using strata_map_t = std::map<std::string, PopType::strata_t, std::less<void>>; - static const strata_map_t strata_map = { - { "poor", PopType::strata_t::POOR }, - { "middle", PopType::strata_t::MIDDLE }, - { "rich", PopType::strata_t::RICH } - }; - const strata_map_t::const_iterator it = strata_map.find(identifier); - if (it != strata_map.end()) { - strata = it->second; - return true; - } - Logger::error("Invalid pop type strata: ", identifier); - return false; - } - ), + "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))), "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, @@ -216,9 +206,9 @@ bool PopManager::load_pop_into_province(Province& province, std::string_view pop Religion const* religion = nullptr; Pop::pop_size_t size = 0; 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_uint(size)), + "culture", ONE_EXACTLY, expect_identifier(culture_manager.expect_culture_identifier(assign_variable_callback_pointer(culture))), + "religion", ONE_EXACTLY, expect_identifier(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 )(pop_node); diff --git a/src/openvic-simulation/pop/Pop.hpp b/src/openvic-simulation/pop/Pop.hpp index 0ab3d06..e299468 100644 --- a/src/openvic-simulation/pop/Pop.hpp +++ b/src/openvic-simulation/pop/Pop.hpp @@ -96,7 +96,7 @@ namespace OpenVic { 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); - IDENTIFIER_REGISTRY_ACCESSORS(PopType, pop_type) + IDENTIFIER_REGISTRY_ACCESSORS(pop_type) bool load_pop_type_file(std::string_view filestem, ast::NodeCPtr root); bool load_pop_into_province(Province& province, std::string_view pop_type_identifier, ast::NodeCPtr pop_node) const; diff --git a/src/openvic-simulation/pop/Religion.cpp b/src/openvic-simulation/pop/Religion.cpp index 32a3219..1152ae5 100644 --- a/src/openvic-simulation/pop/Religion.cpp +++ b/src/openvic-simulation/pop/Religion.cpp @@ -91,7 +91,7 @@ bool ReligionManager::load_religion_file(ast::NodeCPtr root) { bool pagan = false; bool ret = expect_dictionary_keys( - "icon", ONE_EXACTLY, expect_uint(assign_variable_callback_uint(icon)), + "icon", ONE_EXACTLY, expect_uint(assign_variable_callback(icon)), "color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)), "pagan", ZERO_OR_ONE, expect_bool(assign_variable_callback(pagan)) )(value); diff --git a/src/openvic-simulation/pop/Religion.hpp b/src/openvic-simulation/pop/Religion.hpp index 6d1c205..6b17266 100644 --- a/src/openvic-simulation/pop/Religion.hpp +++ b/src/openvic-simulation/pop/Religion.hpp @@ -46,10 +46,10 @@ namespace OpenVic { ReligionManager(); bool add_religion_group(std::string_view identifier); - IDENTIFIER_REGISTRY_ACCESSORS(ReligionGroup, religion_group) + IDENTIFIER_REGISTRY_ACCESSORS(religion_group) bool add_religion(std::string_view identifier, colour_t colour, ReligionGroup const* group, Religion::icon_t icon, bool pagan); - IDENTIFIER_REGISTRY_ACCESSORS(Religion, religion) + IDENTIFIER_REGISTRY_ACCESSORS(religion) bool load_religion_file(ast::NodeCPtr root); }; |