diff options
Diffstat (limited to 'src/openvic-simulation/pop')
-rw-r--r-- | src/openvic-simulation/pop/Culture.cpp | 18 | ||||
-rw-r--r-- | src/openvic-simulation/pop/Culture.hpp | 8 | ||||
-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, 28 insertions, 42 deletions
diff --git a/src/openvic-simulation/pop/Culture.cpp b/src/openvic-simulation/pop/Culture.cpp index 6285305..e3ba5dd 100644 --- a/src/openvic-simulation/pop/Culture.cpp +++ b/src/openvic-simulation/pop/Culture.cpp @@ -15,7 +15,7 @@ CultureGroup::CultureGroup(std::string_view new_identifier, std::string_view new unit_graphical_culture_type { new_unit_graphical_culture_type }, is_overseas { new_is_overseas } {} -std::string const& CultureGroup::get_leader() const { +std::string_view CultureGroup::get_leader() const { return leader; } @@ -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..d36a90b 100644 --- a/src/openvic-simulation/pop/Culture.hpp +++ b/src/openvic-simulation/pop/Culture.hpp @@ -31,7 +31,7 @@ namespace OpenVic { public: CultureGroup(CultureGroup&&) = default; - std::string const& get_leader() const; + std::string_view get_leader() const; GraphicalCultureType const& get_unit_graphical_culture_type() const; bool get_is_overseas() const; }; @@ -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); }; |