diff options
author | Hop311 <Hop3114@gmail.com> | 2024-09-21 09:03:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-21 09:03:51 +0200 |
commit | e35ff8ed703b0b6a5496a21a29e0b274c6a36874 (patch) | |
tree | 68fca0f77f6b20f3e1fe98d32a5a79311cfd3edc /src | |
parent | 118570dc7cf9ae9daf324c2aaba5a5d86fb2c330 (diff) | |
parent | 3fcdd0c7fce2de4cbe14a0cc3d6fb4c2731b93d9 (diff) |
Merge pull request #205 from OpenVicProject/modifier-typesfix-modifiers
Modifier types
Diffstat (limited to 'src')
-rw-r--r-- | src/openvic-simulation/economy/BuildingType.cpp | 3 | ||||
-rw-r--r-- | src/openvic-simulation/map/Crime.cpp | 12 | ||||
-rw-r--r-- | src/openvic-simulation/map/Crime.hpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/map/MapDefinition.cpp | 4 | ||||
-rw-r--r-- | src/openvic-simulation/map/Region.cpp | 12 | ||||
-rw-r--r-- | src/openvic-simulation/map/Region.hpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/map/TerrainType.cpp | 22 | ||||
-rw-r--r-- | src/openvic-simulation/military/LeaderTrait.cpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/modifier/Modifier.cpp | 45 | ||||
-rw-r--r-- | src/openvic-simulation/modifier/Modifier.hpp | 33 | ||||
-rw-r--r-- | src/openvic-simulation/politics/Issue.cpp | 24 | ||||
-rw-r--r-- | src/openvic-simulation/politics/Issue.hpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/politics/NationalFocus.cpp | 11 | ||||
-rw-r--r-- | src/openvic-simulation/politics/NationalValue.cpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/research/Invention.cpp | 6 | ||||
-rw-r--r-- | src/openvic-simulation/research/Technology.cpp | 4 |
16 files changed, 146 insertions, 40 deletions
diff --git a/src/openvic-simulation/economy/BuildingType.cpp b/src/openvic-simulation/economy/BuildingType.cpp index a20aa36..e7c0d59 100644 --- a/src/openvic-simulation/economy/BuildingType.cpp +++ b/src/openvic-simulation/economy/BuildingType.cpp @@ -5,7 +5,7 @@ using namespace OpenVic::NodeTools; BuildingType::BuildingType( std::string_view identifier, building_type_args_t& building_type_args -) : Modifier { identifier, std::move(building_type_args.modifier) }, +) : Modifier { identifier, std::move(building_type_args.modifier), modifier_type_t::BUILDING }, type { building_type_args.type }, on_completion { building_type_args.on_completion }, completion_size { building_type_args.completion_size }, @@ -154,6 +154,7 @@ bool BuildingTypeManager::load_buildings_file( Logger::error("No port building type found!"); ret = false; } + if (province_building_types.empty()) { Logger::error("No province building types found!"); ret = false; diff --git a/src/openvic-simulation/map/Crime.cpp b/src/openvic-simulation/map/Crime.cpp index 03da0fc..fb521ad 100644 --- a/src/openvic-simulation/map/Crime.cpp +++ b/src/openvic-simulation/map/Crime.cpp @@ -6,16 +6,18 @@ using namespace OpenVic::NodeTools; Crime::Crime( std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon, ConditionScript&& new_trigger, bool new_default_active -) : TriggeredModifier { new_identifier, std::move(new_values), new_icon, std::move(new_trigger) }, +) : TriggeredModifier { new_identifier, std::move(new_values), modifier_type_t::CRIME, new_icon, std::move(new_trigger) }, default_active { new_default_active } {} bool CrimeManager::add_crime_modifier( - std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon, ConditionScript&& trigger, bool default_active + std::string_view identifier, ModifierValue&& values, IconModifier::icon_t icon, ConditionScript&& trigger, + bool default_active ) { if (identifier.empty()) { Logger::error("Invalid crime modifier effect identifier - empty!"); return false; } + return crime_modifiers.add_item( { identifier, std::move(values), icon, std::move(trigger), default_active }, duplicate_warning_callback ); @@ -26,7 +28,7 @@ bool CrimeManager::load_crime_modifiers(ModifierManager const& modifier_manager, crime_modifiers, [this, &modifier_manager](std::string_view key, ast::NodeCPtr value) -> bool { ModifierValue modifier_value; - Modifier::icon_t icon = 0; + IconModifier::icon_t icon = 0; ConditionScript trigger { scope_t::PROVINCE, scope_t::NO_SCOPE, scope_t::NO_SCOPE }; bool default_active = false; bool ret = modifier_manager.expect_modifier_value_and_keys( @@ -39,14 +41,18 @@ bool CrimeManager::load_crime_modifiers(ModifierManager const& modifier_manager, return ret; } )(root); + lock_crime_modifiers(); + return ret; } bool CrimeManager::parse_scripts(DefinitionManager const& definition_manager) { bool ret = true; + for (Crime& crime : crime_modifiers.get_items()) { ret &= crime.parse_scripts(definition_manager); } + return ret; } diff --git a/src/openvic-simulation/map/Crime.hpp b/src/openvic-simulation/map/Crime.hpp index 757a75e..91fc88a 100644 --- a/src/openvic-simulation/map/Crime.hpp +++ b/src/openvic-simulation/map/Crime.hpp @@ -24,7 +24,7 @@ namespace OpenVic { public: bool add_crime_modifier( - std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon, ConditionScript&& trigger, + std::string_view identifier, ModifierValue&& values, IconModifier::icon_t icon, ConditionScript&& trigger, bool default_active ); diff --git a/src/openvic-simulation/map/MapDefinition.cpp b/src/openvic-simulation/map/MapDefinition.cpp index f3bb619..488133c 100644 --- a/src/openvic-simulation/map/MapDefinition.cpp +++ b/src/openvic-simulation/map/MapDefinition.cpp @@ -744,7 +744,7 @@ bool MapDefinition::load_climate_file(ModifierManager const& modifier_manager, a if (cur_climate == nullptr) { ModifierValue values; ret &= modifier_manager.expect_modifier_value(move_variable_callback(values))(node); - ret &= climates.add_item({ identifier, std::move(values) }); + ret &= climates.add_item({ identifier, std::move(values), Modifier::modifier_type_t::CLIMATE }); } else { ret &= expect_list_reserve_length(*cur_climate, expect_province_definition_identifier( [cur_climate, &identifier](ProvinceDefinition& province) { @@ -807,7 +807,7 @@ bool MapDefinition::load_continent_file(ModifierManager const& modifier_manager, )) )(node); - Continent continent = { identifier, std::move(values) }; + Continent continent { identifier, std::move(values), Modifier::modifier_type_t::CONTINENT }; continent.add_provinces(prov_list); continent.lock(); diff --git a/src/openvic-simulation/map/Region.cpp b/src/openvic-simulation/map/Region.cpp index d8c5fc1..d35ff56 100644 --- a/src/openvic-simulation/map/Region.cpp +++ b/src/openvic-simulation/map/Region.cpp @@ -10,15 +10,19 @@ bool ProvinceSet::add_province(ProvinceDefinition const* province) { Logger::error("Cannot add province to province set - locked!"); return false; } + if (province == nullptr) { Logger::error("Cannot add province to province set - null province!"); return false; } + if (contains_province(province)) { Logger::warning("Cannot add province ", province->get_identifier(), " to province set - already in the set!"); return false; } + provinces.push_back(province); + return true; } @@ -27,16 +31,20 @@ bool ProvinceSet::remove_province(ProvinceDefinition const* province) { Logger::error("Cannot remove province from province set - locked!"); return false; } + if (province == nullptr) { Logger::error("Cannot remove province from province set - null province!"); return false; } + const decltype(provinces)::const_iterator it = std::find(provinces.begin(), provinces.end(), province); if (it == provinces.end()) { Logger::warning("Cannot remove province ", province->get_identifier(), " from province set - already not in the set!"); return false; } + provinces.erase(it); + return true; } @@ -84,8 +92,8 @@ bool ProvinceSet::contains_province(ProvinceDefinition const* province) const { return province != nullptr && std::find(provinces.begin(), provinces.end(), province) != provinces.end(); } -ProvinceSetModifier::ProvinceSetModifier(std::string_view new_identifier, ModifierValue&& new_values) - : Modifier { new_identifier, std::move(new_values) } {} +ProvinceSetModifier::ProvinceSetModifier(std::string_view new_identifier, ModifierValue&& new_values, modifier_type_t new_type) + : Modifier { new_identifier, std::move(new_values), new_type } {} Region::Region(std::string_view new_identifier, colour_t new_colour, bool new_meta) : HasIdentifierAndColour { new_identifier, new_colour, false }, meta { new_meta } {} diff --git a/src/openvic-simulation/map/Region.hpp b/src/openvic-simulation/map/Region.hpp index ef25b7b..d08ccc4 100644 --- a/src/openvic-simulation/map/Region.hpp +++ b/src/openvic-simulation/map/Region.hpp @@ -48,7 +48,7 @@ namespace OpenVic { struct ProvinceSetModifier : Modifier, ProvinceSet { friend struct MapDefinition; private: - ProvinceSetModifier(std::string_view new_identifier, ModifierValue&& new_values); + ProvinceSetModifier(std::string_view new_identifier, ModifierValue&& new_values, modifier_type_t new_type); public: ProvinceSetModifier(ProvinceSetModifier&&) = default; }; diff --git a/src/openvic-simulation/map/TerrainType.cpp b/src/openvic-simulation/map/TerrainType.cpp index 704e79e..b4cc430 100644 --- a/src/openvic-simulation/map/TerrainType.cpp +++ b/src/openvic-simulation/map/TerrainType.cpp @@ -7,7 +7,8 @@ using namespace OpenVic::NodeTools; TerrainType::TerrainType( std::string_view new_identifier, colour_t new_colour, ModifierValue&& new_modifier, bool new_is_water -) : Modifier { new_identifier, std::move(new_modifier) }, HasColour { new_colour, false }, is_water { new_is_water } {} +) : Modifier { new_identifier, std::move(new_modifier), modifier_type_t::TERRAIN }, HasColour { new_colour, false }, + is_water { new_is_water } {} TerrainTypeMapping::TerrainTypeMapping( std::string_view new_identifier, TerrainType const& new_type, std::vector<index_t>&& new_terrain_indicies, @@ -22,6 +23,7 @@ bool TerrainTypeManager::add_terrain_type( Logger::error("Invalid terrain type identifier - empty!"); return false; } + return terrain_types.add_item({ identifier, colour, std::move(values), is_water }); } @@ -33,17 +35,22 @@ bool TerrainTypeManager::add_terrain_type_mapping( Logger::error("Cannot register terrain type mappings until terrain types are locked!"); return false; } + if (identifier.empty()) { Logger::error("Invalid terrain type mapping identifier - empty!"); return false; } + if (type == nullptr) { Logger::error("Null terrain type for mapping ", identifier); return false; } + bool ret = true; + for (TerrainTypeMapping::index_t idx : terrain_indicies) { const terrain_type_mappings_map_t::const_iterator it = terrain_type_mappings_map.find(idx); + if (it == terrain_type_mappings_map.end()) { terrain_type_mappings_map.emplace(idx, terrain_type_mappings.size()); } else { @@ -54,7 +61,9 @@ bool TerrainTypeManager::add_terrain_type_mapping( ret = false; } } + ret &= terrain_type_mappings.add_item({ identifier, *type, std::move(terrain_indicies), priority, has_texture }); + return ret; } @@ -73,7 +82,9 @@ node_callback_t TerrainTypeManager::_load_terrain_type_categories(ModifierManage return ret; } )(root); + lock_terrain_types(); + return ret; }; } @@ -83,10 +94,12 @@ bool TerrainTypeManager::_load_terrain_type_mapping(std::string_view mapping_key Logger::error("Cannot define terrain type mapping before terrain texture limit: ", mapping_key); return false; } + if (!terrain_types_are_locked()) { Logger::error("Cannot define terrain type mapping before categories: ", mapping_key); return false; } + TerrainType const* type = nullptr; std::vector<TerrainTypeMapping::index_t> terrain_indicies; TerrainTypeMapping::index_t priority = 0; @@ -107,18 +120,23 @@ bool TerrainTypeManager::_load_terrain_type_mapping(std::string_view mapping_key "priority", ZERO_OR_ONE, expect_uint(assign_variable_callback(priority)), "has_texture", ZERO_OR_ONE, expect_bool(assign_variable_callback(has_texture)) )(mapping_value); + if (has_texture && ++terrain_texture_count == terrain_texture_limit + 1) { Logger::warning("More terrain textures than limit!"); } + ret &= add_terrain_type_mapping(mapping_key, type, std::move(terrain_indicies), priority, has_texture); + return true; } TerrainTypeMapping const* TerrainTypeManager::get_terrain_type_mapping_for(TerrainTypeMapping::index_t idx) const { const terrain_type_mappings_map_t::const_iterator it = terrain_type_mappings_map.find(idx); + if (it != terrain_type_mappings_map.end()) { return terrain_type_mappings.get_item_by_index(it->second); } + return nullptr; } @@ -135,6 +153,8 @@ bool TerrainTypeManager::load_terrain_types(ModifierManager const& modifier_mana "terrain", ONE_EXACTLY, expect_uint(assign_variable_callback(terrain_texture_limit)), "categories", ONE_EXACTLY, _load_terrain_type_categories(modifier_manager) )(root); + lock_terrain_type_mappings(); + return ret; } diff --git a/src/openvic-simulation/military/LeaderTrait.cpp b/src/openvic-simulation/military/LeaderTrait.cpp index e6c0227..da7331a 100644 --- a/src/openvic-simulation/military/LeaderTrait.cpp +++ b/src/openvic-simulation/military/LeaderTrait.cpp @@ -4,7 +4,7 @@ using namespace OpenVic; using namespace OpenVic::NodeTools; LeaderTrait::LeaderTrait(std::string_view new_identifier, trait_type_t new_type, ModifierValue&& new_modifiers) - : Modifier { new_identifier, std::move(new_modifiers) }, trait_type { new_type } {} + : Modifier { new_identifier, std::move(new_modifiers), modifier_type_t::LEADER }, trait_type { new_type } {} bool LeaderTrait::is_personality_trait() const { return trait_type == trait_type_t::PERSONALITY; diff --git a/src/openvic-simulation/modifier/Modifier.cpp b/src/openvic-simulation/modifier/Modifier.cpp index 6d0f42a..b26b8dd 100644 --- a/src/openvic-simulation/modifier/Modifier.cpp +++ b/src/openvic-simulation/modifier/Modifier.cpp @@ -129,12 +129,17 @@ void ModifierValue::multiply_add(ModifierValue const& other, fixed_point_t multi } } -Modifier::Modifier(std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon) - : HasIdentifier { new_identifier }, ModifierValue { std::move(new_values) }, icon { new_icon } {} +Modifier::Modifier(std::string_view new_identifier, ModifierValue&& new_values, modifier_type_t new_type) + : HasIdentifier { new_identifier }, ModifierValue { std::move(new_values) }, type { new_type } {} + +IconModifier::IconModifier( + std::string_view new_identifier, ModifierValue&& new_values, modifier_type_t new_type, icon_t new_icon +) : Modifier { new_identifier, std::move(new_values), new_type }, icon { new_icon } {} TriggeredModifier::TriggeredModifier( - std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon, ConditionScript&& new_trigger -) : Modifier { new_identifier, std::move(new_values), new_icon }, trigger { std::move(new_trigger) } {} + std::string_view new_identifier, ModifierValue&& new_values, modifier_type_t new_type, icon_t new_icon, + ConditionScript&& new_trigger +) : IconModifier { new_identifier, std::move(new_values), new_type, new_icon }, trigger { std::move(new_trigger) } {} bool TriggeredModifier::parse_scripts(DefinitionManager const& definition_manager) { return trigger.parse_script(false, definition_manager); @@ -404,12 +409,15 @@ std::string ModifierManager::get_flat_identifier( return StringUtils::append_string_views(complex_modifier_identifier, " ", variant_identifier); } -bool ModifierManager::add_event_modifier(std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon) { +bool ModifierManager::add_event_modifier(std::string_view identifier, ModifierValue&& values, IconModifier::icon_t icon) { if (identifier.empty()) { Logger::error("Invalid event modifier effect identifier - empty!"); return false; } - return event_modifiers.add_item({ identifier, std::move(values), icon }, duplicate_warning_callback); + + return event_modifiers.add_item( + { identifier, std::move(values), Modifier::modifier_type_t::EVENT, icon }, duplicate_warning_callback + ); } bool ModifierManager::load_event_modifiers(ast::NodeCPtr root) { @@ -417,7 +425,7 @@ bool ModifierManager::load_event_modifiers(ast::NodeCPtr root) { event_modifiers, [this](std::string_view key, ast::NodeCPtr value) -> bool { ModifierValue modifier_value; - Modifier::icon_t icon = 0; + IconModifier::icon_t icon = 0; bool ret = expect_modifier_value_and_keys( move_variable_callback(modifier_value), "icon", ZERO_OR_ONE, expect_uint(assign_variable_callback(icon)) @@ -426,7 +434,9 @@ bool ModifierManager::load_event_modifiers(ast::NodeCPtr root) { return ret; } )(root); + lock_event_modifiers(); + return ret; } @@ -435,7 +445,10 @@ bool ModifierManager::add_static_modifier(std::string_view identifier, ModifierV Logger::error("Invalid static modifier effect identifier - empty!"); return false; } - return static_modifiers.add_item({ identifier, std::move(values), 0 }, duplicate_warning_callback); + + return static_modifiers.add_item( + { identifier, std::move(values), Modifier::modifier_type_t::STATIC }, duplicate_warning_callback + ); } bool ModifierManager::load_static_modifiers(ast::NodeCPtr root) { @@ -448,18 +461,24 @@ bool ModifierManager::load_static_modifiers(ast::NodeCPtr root) { return ret; } )(root); + lock_static_modifiers(); + return ret; } bool ModifierManager::add_triggered_modifier( - std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon, ConditionScript&& trigger + std::string_view identifier, ModifierValue&& values, IconModifier::icon_t icon, ConditionScript&& trigger ) { if (identifier.empty()) { Logger::error("Invalid triggered modifier effect identifier - empty!"); return false; } - return triggered_modifiers.add_item({ identifier, std::move(values), icon, std::move(trigger) }, duplicate_warning_callback); + + return triggered_modifiers.add_item( + { identifier, std::move(values), Modifier::modifier_type_t::TRIGGERED, icon, std::move(trigger) }, + duplicate_warning_callback + ); } bool ModifierManager::load_triggered_modifiers(ast::NodeCPtr root) { @@ -467,7 +486,7 @@ bool ModifierManager::load_triggered_modifiers(ast::NodeCPtr root) { triggered_modifiers, [this](std::string_view key, ast::NodeCPtr value) -> bool { ModifierValue modifier_value; - Modifier::icon_t icon = 0; + IconModifier::icon_t icon = 0; ConditionScript trigger { scope_t::COUNTRY, scope_t::COUNTRY, scope_t::NO_SCOPE }; bool ret = expect_modifier_value_and_keys( @@ -479,15 +498,19 @@ bool ModifierManager::load_triggered_modifiers(ast::NodeCPtr root) { return ret; } )(root); + lock_triggered_modifiers(); + return ret; } bool ModifierManager::parse_scripts(DefinitionManager const& definition_manager) { bool ret = true; + for (TriggeredModifier& modifier : triggered_modifiers.get_items()) { ret &= modifier.parse_scripts(definition_manager); } + return ret; } diff --git a/src/openvic-simulation/modifier/Modifier.hpp b/src/openvic-simulation/modifier/Modifier.hpp index f525d6a..80d2db6 100644 --- a/src/openvic-simulation/modifier/Modifier.hpp +++ b/src/openvic-simulation/modifier/Modifier.hpp @@ -79,6 +79,24 @@ namespace OpenVic { struct Modifier : HasIdentifier, ModifierValue { friend struct ModifierManager; + enum struct modifier_type_t : uint8_t { + EVENT, STATIC, TRIGGERED, CRIME, TERRAIN, CLIMATE, CONTINENT, BUILDING, LEADER, NATIONAL_VALUE, NATIONAL_FOCUS, + ISSUE, REFORM, TECHNOLOGY, INVENTION, TECH_SCHOOL + }; + + private: + const modifier_type_t PROPERTY(type); + + protected: + Modifier(std::string_view new_identifier, ModifierValue&& new_values, modifier_type_t new_type); + + public: + Modifier(Modifier&&) = default; + }; + + struct IconModifier : Modifier { + friend struct ModifierManager; + using icon_t = uint8_t; private: @@ -86,13 +104,13 @@ namespace OpenVic { const icon_t PROPERTY(icon); protected: - Modifier(std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon = 0); + IconModifier(std::string_view new_identifier, ModifierValue&& new_values, modifier_type_t new_type, icon_t new_icon); public: - Modifier(Modifier&&) = default; + IconModifier(IconModifier&&) = default; }; - struct TriggeredModifier : Modifier { + struct TriggeredModifier : IconModifier { friend struct ModifierManager; private: @@ -100,7 +118,8 @@ namespace OpenVic { protected: TriggeredModifier( - std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon, ConditionScript&& new_trigger + std::string_view new_identifier, ModifierValue&& new_values, modifier_type_t new_type, icon_t new_icon, + ConditionScript&& new_trigger ); bool parse_scripts(DefinitionManager const& definition_manager); @@ -131,7 +150,7 @@ namespace OpenVic { CaseInsensitiveIdentifierRegistry<ModifierEffect, RegistryStorageInfoDeque> IDENTIFIER_REGISTRY(modifier_effect); case_insensitive_string_set_t complex_modifiers; - IdentifierRegistry<Modifier> IDENTIFIER_REGISTRY(event_modifier); + IdentifierRegistry<IconModifier> IDENTIFIER_REGISTRY(event_modifier); IdentifierRegistry<Modifier> IDENTIFIER_REGISTRY(static_modifier); IdentifierRegistry<TriggeredModifier> IDENTIFIER_REGISTRY(triggered_modifier); @@ -155,14 +174,14 @@ namespace OpenVic { bool setup_modifier_effects(); - bool add_event_modifier(std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon); + bool add_event_modifier(std::string_view identifier, ModifierValue&& values, IconModifier::icon_t icon); bool load_event_modifiers(ast::NodeCPtr root); bool add_static_modifier(std::string_view identifier, ModifierValue&& values); bool load_static_modifiers(ast::NodeCPtr root); bool add_triggered_modifier( - std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon, ConditionScript&& trigger + std::string_view identifier, ModifierValue&& values, IconModifier::icon_t icon, ConditionScript&& trigger ); bool load_triggered_modifiers(ast::NodeCPtr root); diff --git a/src/openvic-simulation/politics/Issue.cpp b/src/openvic-simulation/politics/Issue.cpp index 4a08dea..3174e23 100644 --- a/src/openvic-simulation/politics/Issue.cpp +++ b/src/openvic-simulation/politics/Issue.cpp @@ -7,8 +7,8 @@ IssueGroup::IssueGroup(std::string_view new_identifier) : HasIdentifier { new_id Issue::Issue( std::string_view new_identifier, colour_t new_colour, ModifierValue&& new_values, IssueGroup const& new_group, - RuleSet&& new_rules, bool new_jingoism -) : Modifier { new_identifier, std::move(new_values) }, HasColour { new_colour, false }, group { new_group }, + RuleSet&& new_rules, bool new_jingoism, modifier_type_t new_type +) : Modifier { new_identifier, std::move(new_values), new_type }, HasColour { new_colour, false }, group { new_group }, rules { std::move(new_rules) }, jingoism { new_jingoism } {} ReformType::ReformType(std::string_view new_identifier, bool new_uncivilised) @@ -21,16 +21,19 @@ Reform::Reform( std::string_view new_identifier, colour_t new_colour, ModifierValue&& new_values, ReformGroup const& new_group, size_t new_ordinal, fixed_point_t new_administrative_multiplier, RuleSet&& new_rules, tech_cost_t new_technology_cost, ConditionScript&& new_allow, ConditionScript&& new_on_execute_trigger, EffectScript&& new_on_execute_effect -) : Issue { new_identifier, new_colour, std::move(new_values), new_group, std::move(new_rules), false }, - reform_group { new_group }, ordinal { new_ordinal }, administrative_multiplier { new_administrative_multiplier }, +) : Issue { + new_identifier, new_colour, std::move(new_values), new_group, std::move(new_rules), false, modifier_type_t::REFORM + }, reform_group { new_group }, ordinal { new_ordinal }, administrative_multiplier { new_administrative_multiplier }, technology_cost { new_technology_cost }, allow { std::move(new_allow) }, on_execute_trigger { std::move(new_on_execute_trigger) }, on_execute_effect { std::move(new_on_execute_effect) } {} bool Reform::parse_scripts(DefinitionManager const& definition_manager) { bool ret = true; + ret &= allow.parse_script(true, definition_manager); ret &= on_execute_trigger.parse_script(true, definition_manager); ret &= on_execute_effect.parse_script(true, definition_manager); + return ret; } @@ -176,14 +179,17 @@ bool IssueManager::_load_issue( ModifierValue values; RuleSet rules; bool jingoism = false; + bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(values), "is_jingoism", ZERO_OR_ONE, expect_bool(assign_variable_callback(jingoism)), "rules", ZERO_OR_ONE, rule_manager.expect_rule_set(move_variable_callback(rules)) )(node); + ret &= add_issue( identifier, create_issue_reform_colour(get_issue_count() + get_reform_count()), std::move(values), group, std::move(rules), jingoism ); + return ret; } @@ -191,12 +197,15 @@ bool IssueManager::_load_reform_group( size_t& expected_reforms, std::string_view identifier, ReformType const* type, ast::NodeCPtr node ) { bool ordered = false, administrative = false; + bool ret = expect_dictionary_keys_and_default( increment_callback(expected_reforms), "next_step_only", ZERO_OR_ONE, expect_bool(assign_variable_callback(ordered)), "administrative", ZERO_OR_ONE, expect_bool(assign_variable_callback(administrative)) )(node); + ret &= add_reform_group(identifier, type, ordered, administrative); + return ret; } @@ -223,11 +232,13 @@ bool IssueManager::_load_reform( "effect", ONE_EXACTLY, on_execute_effect.expect_script() ) )(node); + ret &= add_reform( identifier, create_issue_reform_colour(get_issue_count() + get_reform_count()), std::move(values), group, ordinal, administrative_multiplier, std::move(rules), technology_cost, std::move(allow), std::move(on_execute_trigger), std::move(on_execute_effect) ); + return ret; } @@ -272,6 +283,7 @@ bool IssueManager::load_issues_file( } } )(root); + lock_reform_types(); reserve_more_issue_groups(expected_issue_groups); @@ -306,6 +318,7 @@ bool IssueManager::load_issues_file( } } )(root); + lock_issue_groups(); lock_reform_groups(); @@ -356,6 +369,7 @@ bool IssueManager::load_issues_file( } } )(root); + lock_issues(); lock_reforms(); @@ -364,8 +378,10 @@ bool IssueManager::load_issues_file( bool IssueManager::parse_scripts(DefinitionManager const& definition_manager) { bool ret = true; + for (Reform& reform : reforms.get_items()) { ret &= reform.parse_scripts(definition_manager); } + return ret; } diff --git a/src/openvic-simulation/politics/Issue.hpp b/src/openvic-simulation/politics/Issue.hpp index 9f2d842..c0ab86c 100644 --- a/src/openvic-simulation/politics/Issue.hpp +++ b/src/openvic-simulation/politics/Issue.hpp @@ -32,7 +32,7 @@ namespace OpenVic { protected: Issue( std::string_view new_identifier, colour_t new_colour, ModifierValue&& new_values, IssueGroup const& new_group, - RuleSet&& new_rules, bool new_jingoism + RuleSet&& new_rules, bool new_jingoism, modifier_type_t new_type = modifier_type_t::ISSUE ); public: diff --git a/src/openvic-simulation/politics/NationalFocus.cpp b/src/openvic-simulation/politics/NationalFocus.cpp index bf5d728..4887ed6 100644 --- a/src/openvic-simulation/politics/NationalFocus.cpp +++ b/src/openvic-simulation/politics/NationalFocus.cpp @@ -24,7 +24,7 @@ NationalFocus::NationalFocus( fixed_point_map_t<GoodDefinition const*>&& new_encourage_goods, fixed_point_map_t<PopType const*>&& new_encourage_pop_types, ConditionScript&& new_limit -) : Modifier { new_identifier, std::move(new_modifiers) }, +) : Modifier { new_identifier, std::move(new_modifiers), modifier_type_t::NATIONAL_FOCUS }, group { new_group }, icon { new_icon }, has_flashpoint { new_has_flashpoint }, @@ -47,6 +47,7 @@ inline bool NationalFocusManager::add_national_focus_group(std::string_view iden Logger::error("No identifier for national focus group!"); return false; } + return national_focus_groups.add_item({ identifier }); } @@ -70,16 +71,19 @@ inline bool NationalFocusManager::add_national_focus( Logger::error("No identifier for national focus!"); return false; } + if (icon < 1) { Logger::error("Invalid icon ", icon, " for national focus ", identifier); return false; } + if ((loyalty_ideology == nullptr) != (loyalty_value == 0)) { Logger::warning( "Party loyalty incorrectly defined for national focus ", identifier, ": ideology = ", loyalty_ideology, ", value = ", loyalty_value ); } + return national_foci.add_item({ identifier, group, icon, has_flashpoint, flashpoint_tension, own_provinces, outliner_show_as_percent, std::move(modifiers), loyalty_ideology, loyalty_value, encourage_railroads, std::move(encourage_goods), @@ -92,12 +96,14 @@ bool NationalFocusManager::load_national_foci_file( GoodDefinitionManager const& good_definition_manager, ModifierManager const& modifier_manager, ast::NodeCPtr root ) { size_t expected_national_foci = 0; + bool ret = expect_dictionary_reserve_length( national_focus_groups, [this, &expected_national_foci](std::string_view identifier, ast::NodeCPtr node) -> bool { return expect_length(add_variable_callback(expected_national_foci))(node) & add_national_focus_group(identifier); } )(root); + lock_national_focus_groups(); reserve_more_national_foci(expected_national_foci); @@ -164,6 +170,7 @@ bool NationalFocusManager::load_national_foci_file( )(group_node); } )(root); + lock_national_foci(); return ret; @@ -171,8 +178,10 @@ bool NationalFocusManager::load_national_foci_file( bool NationalFocusManager::parse_scripts(DefinitionManager const& definition_manager) { bool ret = true; + for (NationalFocus& national_focus : national_foci.get_items()) { ret &= national_focus.parse_scripts(definition_manager); } + return ret; } diff --git a/src/openvic-simulation/politics/NationalValue.cpp b/src/openvic-simulation/politics/NationalValue.cpp index b780195..e9f7f2a 100644 --- a/src/openvic-simulation/politics/NationalValue.cpp +++ b/src/openvic-simulation/politics/NationalValue.cpp @@ -4,7 +4,7 @@ using namespace OpenVic; using namespace OpenVic::NodeTools; NationalValue::NationalValue(std::string_view new_identifier, ModifierValue&& new_modifiers) - : Modifier { new_identifier, std::move(new_modifiers) } {} + : Modifier { new_identifier, std::move(new_modifiers), modifier_type_t::NATIONAL_VALUE } {} bool NationalValueManager::add_national_value(std::string_view identifier, ModifierValue&& modifiers) { if (identifier.empty()) { diff --git a/src/openvic-simulation/research/Invention.cpp b/src/openvic-simulation/research/Invention.cpp index 5ecfcdc..299cefb 100644 --- a/src/openvic-simulation/research/Invention.cpp +++ b/src/openvic-simulation/research/Invention.cpp @@ -18,7 +18,7 @@ Invention::Invention( bool new_unlock_gas_defence, ConditionScript&& new_limit, ConditionalWeight&& new_chance -) : Modifier { new_identifier, std::move(new_values) }, +) : Modifier { new_identifier, std::move(new_values), modifier_type_t::INVENTION }, news { new_news }, activated_units { std::move(new_activated_units) }, activated_buildings { std::move(new_activated_buildings) }, @@ -30,8 +30,10 @@ Invention::Invention( bool Invention::parse_scripts(DefinitionManager const& definition_manager) { bool ret = true; + ret &= limit.parse_script(false, definition_manager); ret &= chance.parse_scripts(definition_manager); + return ret; } @@ -104,8 +106,10 @@ bool InventionManager::load_inventions_file( bool InventionManager::parse_scripts(DefinitionManager const& definition_manager) { bool ret = true; + for (Invention& invention : inventions.get_items()) { ret &= invention.parse_scripts(definition_manager); } + return ret; } diff --git a/src/openvic-simulation/research/Technology.cpp b/src/openvic-simulation/research/Technology.cpp index 847c4b0..a5256f3 100644 --- a/src/openvic-simulation/research/Technology.cpp +++ b/src/openvic-simulation/research/Technology.cpp @@ -19,7 +19,7 @@ Technology::Technology( building_set_t&& new_activated_buildings, ModifierValue&& new_values, ConditionalWeight&& new_ai_chance -) : Modifier { new_identifier, std::move(new_values) }, +) : Modifier { new_identifier, std::move(new_values), modifier_type_t::TECHNOLOGY }, area { new_area }, year { new_year }, cost { new_cost }, @@ -34,7 +34,7 @@ bool Technology::parse_scripts(DefinitionManager const& definition_manager) { } TechnologySchool::TechnologySchool(std::string_view new_identifier, ModifierValue&& new_values) - : Modifier { new_identifier, std::move(new_values) } {} + : Modifier { new_identifier, std::move(new_values), modifier_type_t::TECH_SCHOOL } {} bool TechnologyManager::add_technology_folder(std::string_view identifier) { if (identifier.empty()) { |