diff options
Diffstat (limited to 'src/openvic-simulation/research')
-rw-r--r-- | src/openvic-simulation/research/Invention.cpp | 99 | ||||
-rw-r--r-- | src/openvic-simulation/research/Invention.hpp | 28 | ||||
-rw-r--r-- | src/openvic-simulation/research/Technology.cpp | 24 | ||||
-rw-r--r-- | src/openvic-simulation/research/Technology.hpp | 6 |
4 files changed, 81 insertions, 76 deletions
diff --git a/src/openvic-simulation/research/Invention.cpp b/src/openvic-simulation/research/Invention.cpp index eb4e342..381a249 100644 --- a/src/openvic-simulation/research/Invention.cpp +++ b/src/openvic-simulation/research/Invention.cpp @@ -1,23 +1,26 @@ #include "Invention.hpp" -#include <algorithm> -#include <cstring> -#include <utility> + +#include "openvic-simulation/economy/BuildingType.hpp" +#include "openvic-simulation/map/Crime.hpp" +#include "openvic-simulation/military/Unit.hpp" using namespace OpenVic; using namespace OpenVic::NodeTools; Invention::Invention( - std::string_view identifier, ModifierValue&& values, bool news, unit_set_t activated_units, building_set_t activated_buildings, - crime_set_t enabled_crimes, bool unlock_gas_attack, bool unlock_gas_defence) - : Modifier { identifier, std::move(values), 0 }, - news { news }, activated_units { std::move(activated_units) }, activated_buildings { std::move(activated_buildings) }, - enabled_crimes { std::move(enabled_crimes) }, unlock_gas_attack { unlock_gas_attack }, unlock_gas_defence { unlock_gas_defence } {} //TODO icon + std::string_view new_identifier, ModifierValue&& new_values, bool new_news, unit_set_t&& new_activated_units, + building_set_t&& new_activated_buildings, crime_set_t&& new_enabled_crimes, bool new_unlock_gas_attack, + bool new_unlock_gas_defence +) : Modifier { new_identifier, std::move(new_values), 0 }, news { new_news }, + activated_units { std::move(new_activated_units) }, activated_buildings { std::move(new_activated_buildings) }, + enabled_crimes { std::move(new_enabled_crimes) }, unlock_gas_attack { new_unlock_gas_attack }, + unlock_gas_defence { new_unlock_gas_defence } {} //TODO icon InventionManager::InventionManager() : inventions { "inventions" } {} bool InventionManager::add_invention( - std::string_view identifier, ModifierValue&& values, bool news, Invention::unit_set_t activated_units, - Invention::building_set_t activated_buildings, Invention::crime_set_t enabled_crimes, + std::string_view identifier, ModifierValue&& values, bool news, Invention::unit_set_t&& activated_units, + Invention::building_set_t&& activated_buildings, Invention::crime_set_t&& enabled_crimes, bool unlock_gas_attack, bool unlock_gas_defence ) { if (identifier.empty()) { @@ -32,49 +35,49 @@ bool InventionManager::add_invention( } bool InventionManager::load_inventions_file( - ModifierManager const& modifier_manager, UnitManager const& unit_manager, BuildingManager const& building_manager, ast::NodeCPtr root + ModifierManager const& modifier_manager, UnitManager const& unit_manager, BuildingTypeManager const& building_type_manager, + CrimeManager const& crime_manager, ast::NodeCPtr root ) { - return expect_dictionary_reserve_length(inventions, [this, &modifier_manager, &unit_manager, &building_manager](std::string_view identifier, ast::NodeCPtr value) -> bool { - ModifierValue loose_modifiers; - ModifierValue modifiers; + return expect_dictionary_reserve_length( + inventions, [this, &modifier_manager, &unit_manager, &building_type_manager, &crime_manager]( + std::string_view identifier, ast::NodeCPtr value) -> bool { + ModifierValue loose_modifiers; + ModifierValue modifiers; - Invention::unit_set_t activated_units; - Invention::building_set_t activated_buildings; - Invention::crime_set_t enabled_crimes; + Invention::unit_set_t activated_units; + Invention::building_set_t activated_buildings; + Invention::crime_set_t enabled_crimes; - bool unlock_gas_attack = false; - bool unlock_gas_defence = false; - bool news = true; //defaults to true! + bool unlock_gas_attack = false; + bool unlock_gas_defence = false; + bool news = true; //defaults to true! - bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(loose_modifiers), - "news", ZERO_OR_ONE, expect_bool(assign_variable_callback(news)), - "limit", ONE_EXACTLY, success_callback, - "chance", ONE_EXACTLY, success_callback, - "effect", ZERO_OR_ONE, modifier_manager.expect_modifier_value_and_keys( - move_variable_callback(modifiers), - "gas_attack", ZERO_OR_ONE, expect_bool(assign_variable_callback(unlock_gas_attack)), - "gas_defence", ZERO_OR_ONE, expect_bool(assign_variable_callback(unlock_gas_defence)), - "activate_unit", ZERO_OR_MORE, unit_manager.expect_unit_identifier([this, &activated_units](Unit const& unit) -> bool { - activated_units.insert(&unit); - return true; - }), - "activate_building", ZERO_OR_MORE, building_manager.expect_building_type_identifier([this, &activated_buildings](BuildingType const& type) -> bool { - activated_buildings.insert(&type); - return true; - }), - "enable_crime", ZERO_OR_ONE, modifier_manager.expect_crime_modifier_identifier([this, &enabled_crimes](Crime const& crime) -> bool { - enabled_crimes.insert(&crime); - return true; - })) - )(value); + bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(loose_modifiers), + "news", ZERO_OR_ONE, expect_bool(assign_variable_callback(news)), + "limit", ONE_EXACTLY, success_callback, + "chance", ONE_EXACTLY, success_callback, + "effect", ZERO_OR_ONE, modifier_manager.expect_modifier_value_and_keys( + move_variable_callback(modifiers), + "gas_attack", ZERO_OR_ONE, expect_bool(assign_variable_callback(unlock_gas_attack)), + "gas_defence", ZERO_OR_ONE, expect_bool(assign_variable_callback(unlock_gas_defence)), + "activate_unit", ZERO_OR_MORE, unit_manager.expect_unit_identifier(set_callback_pointer(activated_units)), + "activate_building", ZERO_OR_MORE, building_type_manager.expect_building_type_identifier( + set_callback_pointer(activated_buildings) + ), + "enable_crime", ZERO_OR_ONE, crime_manager.expect_crime_modifier_identifier( + set_callback_pointer(enabled_crimes) + ) + ) + )(value); - modifiers += loose_modifiers; + modifiers += loose_modifiers; - ret &= add_invention( - identifier, std::move(modifiers), news, activated_units, activated_buildings, enabled_crimes, - unlock_gas_attack, unlock_gas_defence - ); + ret &= add_invention( + identifier, std::move(modifiers), news, std::move(activated_units), std::move(activated_buildings), + std::move(enabled_crimes), unlock_gas_attack, unlock_gas_defence + ); - return ret; - })(root); + return ret; + } + )(root); }
\ No newline at end of file diff --git a/src/openvic-simulation/research/Invention.hpp b/src/openvic-simulation/research/Invention.hpp index 321d982..9cc158c 100644 --- a/src/openvic-simulation/research/Invention.hpp +++ b/src/openvic-simulation/research/Invention.hpp @@ -1,13 +1,17 @@ #pragma once -#include "openvic-simulation/economy/BuildingType.hpp" -#include "openvic-simulation/military/Unit.hpp" #include "openvic-simulation/misc/Modifier.hpp" #include "openvic-simulation/types/IdentifierRegistry.hpp" -#include <string_view> -#include <unordered_set> namespace OpenVic { + struct Unit; + struct BuildingType; + struct Crime; + + struct UnitManager; + struct BuildingTypeManager; + struct CrimeManager; + struct Invention : Modifier { friend struct InventionManager; //TODO implement limit and chance @@ -24,9 +28,9 @@ namespace OpenVic { const bool PROPERTY_CUSTOM_PREFIX(unlock_gas_defence, will); Invention( - std::string_view identifier, ModifierValue&& values, bool news, unit_set_t activated_units, - building_set_t activated_buildings, crime_set_t enabled_crimes, bool unlock_gas_attack, - bool unlock_gas_defence + std::string_view new_identifier, ModifierValue&& new_values, bool new_news, unit_set_t&& new_activated_units, + building_set_t&& new_activated_buildings, crime_set_t&& new_enabled_crimes, bool new_unlock_gas_attack, + bool new_unlock_gas_defence ); public: @@ -40,16 +44,16 @@ namespace OpenVic { InventionManager(); bool add_invention( - std::string_view identifier, ModifierValue&& values, bool news, Invention::unit_set_t activated_units, - Invention::building_set_t activated_buildings, Invention::crime_set_t enabled_crimes, bool unlock_gas_attack, + std::string_view identifier, ModifierValue&& values, bool news, Invention::unit_set_t&& activated_units, + Invention::building_set_t&& activated_buildings, Invention::crime_set_t&& enabled_crimes, bool unlock_gas_attack, bool unlock_gas_defence ); - IDENTIFIER_REGISTRY_ACCESSORS(invention); + IDENTIFIER_REGISTRY_ACCESSORS(invention) bool load_inventions_file( - ModifierManager const& modifier_manager, UnitManager const& unit_manager, BuildingManager const& building_manager, - ast::NodeCPtr root + ModifierManager const& modifier_manager, UnitManager const& unit_manager, + BuildingTypeManager const& building_type_manager, CrimeManager const& crime_manager, ast::NodeCPtr root ); // inventions/*.txt }; }
\ No newline at end of file diff --git a/src/openvic-simulation/research/Technology.cpp b/src/openvic-simulation/research/Technology.cpp index 07faaa3..f8ebb4b 100644 --- a/src/openvic-simulation/research/Technology.cpp +++ b/src/openvic-simulation/research/Technology.cpp @@ -111,8 +111,12 @@ bool TechnologyManager::load_technology_file_schools(ModifierManager const& modi })(root); } -bool TechnologyManager::load_technologies_file(ModifierManager const& modifier_manager, UnitManager const& unit_manager, BuildingManager const& building_manager, ast::NodeCPtr root) { - return expect_dictionary_reserve_length(technologies, [this, &modifier_manager, &unit_manager, &building_manager](std::string_view tech_key, ast::NodeCPtr tech_value) -> bool { +bool TechnologyManager::load_technologies_file( + ModifierManager const& modifier_manager, UnitManager const& unit_manager, BuildingTypeManager const& building_type_manager, + ast::NodeCPtr root +) { + return expect_dictionary_reserve_length(technologies, [this, &modifier_manager, &unit_manager, &building_type_manager]( + std::string_view tech_key, ast::NodeCPtr tech_value) -> bool { ModifierValue modifiers; TechnologyArea const* area = nullptr; Date::year_t year = 0; @@ -128,15 +132,9 @@ bool TechnologyManager::load_technologies_file(ModifierManager const& modifier_m "cost", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(cost)), "unciv_military", ZERO_OR_ONE, expect_bool(assign_variable_callback(unciv_military)), "unit", ZERO_OR_ONE, expect_uint(assign_variable_callback(unit)), - "activate_unit", ZERO_OR_MORE, unit_manager.expect_unit_identifier([&activated_units](Unit const& unit) -> bool { - activated_units.insert(&unit); - return true; - }), - "activate_building", ZERO_OR_MORE, building_manager.expect_building_type_identifier( - [&activated_buildings](BuildingType const& building_type) -> bool { - activated_buildings.insert(&building_type); - return true; - } + "activate_unit", ZERO_OR_MORE, unit_manager.expect_unit_identifier(set_callback_pointer(activated_units)), + "activate_building", ZERO_OR_MORE, building_type_manager.expect_building_type_identifier( + set_callback_pointer(activated_buildings) ), "ai_chance", ONE_EXACTLY, success_callback //TODO )(tech_value); @@ -149,7 +147,7 @@ bool TechnologyManager::load_technologies_file(ModifierManager const& modifier_m })(root); } -#define TECH_MODIFIER(NAME, POS) ret &= modifier_manager.add_modifier_effect(NAME, POS, ModifierEffect::format_t::PROPORTION_DECIMAL) +#define TECH_MODIFIER(NAME, POS) ret &= modifier_manager.add_modifier_effect(NAME, POS) #define UNCIV_TECH_MODIFIER(NAME) TECH_MODIFIER(NAME, false); TECH_MODIFIER(StringUtils::append_string_views("self_", NAME), false); bool TechnologyManager::generate_modifiers(ModifierManager& modifier_manager) { bool ret = true; @@ -160,7 +158,7 @@ bool TechnologyManager::generate_modifiers(ModifierManager& modifier_manager) { for (TechnologyFolder const& folder : get_technology_folders()) { TECH_MODIFIER(StringUtils::append_string_views(folder.get_identifier(), "_research_bonus"), true); } - + return ret; } #undef UNCIV_TECH_MODIFIER diff --git a/src/openvic-simulation/research/Technology.hpp b/src/openvic-simulation/research/Technology.hpp index 0939369..540d10f 100644 --- a/src/openvic-simulation/research/Technology.hpp +++ b/src/openvic-simulation/research/Technology.hpp @@ -85,13 +85,13 @@ namespace OpenVic { IDENTIFIER_REGISTRY_ACCESSORS_CUSTOM_PLURAL(technology, technologies) bool add_technology_school(std::string_view identifier, ModifierValue&& values); - IDENTIFIER_REGISTRY_ACCESSORS(technology_school); + IDENTIFIER_REGISTRY_ACCESSORS(technology_school) bool load_technology_file_areas(ast::NodeCPtr root); // common/technology.txt bool load_technology_file_schools(ModifierManager const& modifier_manager, ast::NodeCPtr root); // also common/technology.txt bool load_technologies_file( - ModifierManager const& modifier_manager, UnitManager const& unit_manager, BuildingManager const& building_manager, - ast::NodeCPtr root + ModifierManager const& modifier_manager, UnitManager const& unit_manager, + BuildingTypeManager const& building_type_manager, ast::NodeCPtr root ); // technologies/*.txt bool generate_modifiers(ModifierManager& modifier_manager); }; |