diff options
Diffstat (limited to 'src/openvic-simulation/research')
-rw-r--r-- | src/openvic-simulation/research/Invention.cpp | 34 | ||||
-rw-r--r-- | src/openvic-simulation/research/Invention.hpp | 11 | ||||
-rw-r--r-- | src/openvic-simulation/research/Technology.cpp | 35 | ||||
-rw-r--r-- | src/openvic-simulation/research/Technology.hpp | 17 |
4 files changed, 71 insertions, 26 deletions
diff --git a/src/openvic-simulation/research/Invention.cpp b/src/openvic-simulation/research/Invention.cpp index f9f3f7b..473b0b4 100644 --- a/src/openvic-simulation/research/Invention.cpp +++ b/src/openvic-simulation/research/Invention.cpp @@ -10,16 +10,23 @@ using namespace OpenVic::NodeTools; Invention::Invention( 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 + bool new_unlock_gas_defence, ConditionScript&& new_limit, ConditionalWeight&& new_chance ) : 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 + unlock_gas_defence { new_unlock_gas_defence }, limit { std::move(new_limit) }, chance { std::move(new_chance) } {} + +bool Invention::parse_scripts(GameManager const& game_manager) { + bool ret = true; + ret &= limit.parse_script(false, game_manager); + ret &= chance.parse_scripts(game_manager); + return ret; +} 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, - bool unlock_gas_attack, bool unlock_gas_defence + bool unlock_gas_attack, bool unlock_gas_defence, ConditionScript&& limit, ConditionalWeight&& chance ) { if (identifier.empty()) { Logger::error("Invalid invention identifier - empty!"); @@ -28,7 +35,7 @@ bool InventionManager::add_invention( return inventions.add_item({ identifier, std::move(values), news, std::move(activated_units), std::move(activated_buildings), - std::move(enabled_crimes), unlock_gas_attack, unlock_gas_defence + std::move(enabled_crimes), unlock_gas_attack, unlock_gas_defence, std::move(limit), std::move(chance) }); } @@ -50,10 +57,13 @@ bool InventionManager::load_inventions_file( bool unlock_gas_defence = false; bool news = true; //defaults to true! + ConditionScript limit; + ConditionalWeight chance; + 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, + "limit", ONE_EXACTLY, limit.expect_script(), + "chance", ONE_EXACTLY, chance.expect_conditional_weight(ConditionalWeight::BASE), "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)), @@ -72,10 +82,18 @@ bool InventionManager::load_inventions_file( 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 + std::move(enabled_crimes), unlock_gas_attack, unlock_gas_defence, std::move(limit), std::move(chance) ); return ret; } )(root); -}
\ No newline at end of file +} + +bool InventionManager::parse_scripts(GameManager const& game_manager) { + bool ret = true; + for (Invention& invention : inventions.get_items()) { + ret &= invention.parse_scripts(game_manager); + } + return ret; +} diff --git a/src/openvic-simulation/research/Invention.hpp b/src/openvic-simulation/research/Invention.hpp index 5d31155..2b8100d 100644 --- a/src/openvic-simulation/research/Invention.hpp +++ b/src/openvic-simulation/research/Invention.hpp @@ -1,6 +1,7 @@ #pragma once #include "openvic-simulation/misc/Modifier.hpp" +#include "openvic-simulation/scripts/ConditionalWeight.hpp" #include "openvic-simulation/types/IdentifierRegistry.hpp" #include "openvic-simulation/types/OrderedContainers.hpp" @@ -27,13 +28,17 @@ namespace OpenVic { crime_set_t PROPERTY(enabled_crimes); const bool PROPERTY_CUSTOM_PREFIX(unlock_gas_attack, will); const bool PROPERTY_CUSTOM_PREFIX(unlock_gas_defence, will); + ConditionScript PROPERTY(limit); + ConditionalWeight PROPERTY(chance); Invention( 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 + bool new_unlock_gas_defence, ConditionScript&& new_limit, ConditionalWeight&& new_chance ); + bool parse_scripts(GameManager const& game_manager); + public: Invention(Invention&&) = default; }; @@ -45,12 +50,14 @@ namespace OpenVic { 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, - bool unlock_gas_defence + bool unlock_gas_defence, ConditionScript&& limit, ConditionalWeight&& chance ); bool load_inventions_file( ModifierManager const& modifier_manager, UnitManager const& unit_manager, BuildingTypeManager const& building_type_manager, CrimeManager const& crime_manager, ast::NodeCPtr root ); // inventions/*.txt + + bool parse_scripts(GameManager const& game_manager); }; }
\ No newline at end of file diff --git a/src/openvic-simulation/research/Technology.cpp b/src/openvic-simulation/research/Technology.cpp index 7851707..b151f1a 100644 --- a/src/openvic-simulation/research/Technology.cpp +++ b/src/openvic-simulation/research/Technology.cpp @@ -11,10 +11,14 @@ TechnologyArea::TechnologyArea(std::string_view new_identifier, TechnologyFolder Technology::Technology( std::string_view new_identifier, TechnologyArea const& new_area, Date::year_t new_year, fixed_point_t new_cost, bool new_unciv_military, uint8_t new_unit, unit_set_t&& new_activated_units, building_set_t&& new_activated_buildings, - ModifierValue&& new_values + ModifierValue&& new_values, ConditionalWeight&& new_ai_chance ) : Modifier { new_identifier, std::move(new_values), 0 }, area { new_area }, year { new_year }, cost { new_cost }, unciv_military { new_unciv_military }, unit { new_unit }, activated_buildings { std::move(new_activated_units) }, - activated_units { std::move(new_activated_buildings) } {} + activated_units { std::move(new_activated_buildings) }, ai_chance { std::move(new_ai_chance) } {} + +bool Technology::parse_scripts(GameManager const& game_manager) { + return ai_chance.parse_scripts(game_manager); +} TechnologySchool::TechnologySchool(std::string_view new_identifier, ModifierValue&& new_values) : Modifier { new_identifier, std::move(new_values), 0 } {} @@ -45,7 +49,7 @@ bool TechnologyManager::add_technology_area(std::string_view identifier, Technol bool TechnologyManager::add_technology( std::string_view identifier, TechnologyArea const* area, Date::year_t year, fixed_point_t cost, bool unciv_military, uint8_t unit, Technology::unit_set_t&& activated_units, Technology::building_set_t&& activated_buildings, - ModifierValue&& values + ModifierValue&& values, ConditionalWeight&& ai_chance ) { if (identifier.empty()) { Logger::error("Invalid technology identifier - empty!"); @@ -59,7 +63,7 @@ bool TechnologyManager::add_technology( return technologies.add_item({ identifier, *area, year, cost, unciv_military, unit, std::move(activated_units), std::move(activated_buildings), - std::move(values) + std::move(values), std::move(ai_chance) }); } @@ -87,8 +91,9 @@ bool TechnologyManager::load_technology_file_areas(ast::NodeCPtr root) { })(root_value); lock_technology_folders(); lock_technology_areas(); - } else if (root_key == "schools") return true; //ignore - else return false; + } else { + return root_key == "schools"; /* Ignore schools, error otherwise */ + } })(root); } @@ -102,8 +107,9 @@ bool TechnologyManager::load_technology_file_schools(ModifierManager const& modi return ret; })(root_value); lock_technology_schools(); - } else if (root_key == "folders") return true; //ignore - else return false; + } else { + return root_key == "folders"; /* Ignore folders, error otherwise */ + } })(root); } @@ -121,6 +127,7 @@ bool TechnologyManager::load_technologies_file( uint8_t unit = 0; Technology::unit_set_t activated_units; Technology::building_set_t activated_buildings; + ConditionalWeight ai_chance; bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(modifiers), "area", ONE_EXACTLY, expect_technology_area_identifier(assign_variable_callback_pointer(area)), @@ -132,12 +139,12 @@ bool TechnologyManager::load_technologies_file( "activate_building", ZERO_OR_MORE, building_type_manager.expect_building_type_identifier( set_callback_pointer(activated_buildings) ), - "ai_chance", ONE_EXACTLY, success_callback //TODO + "ai_chance", ONE_EXACTLY, ai_chance.expect_conditional_weight(ConditionalWeight::FACTOR) )(tech_value); ret &= add_technology( tech_key, area, year, cost, unciv_military, unit, std::move(activated_units), std::move(activated_buildings), - std::move(modifiers) + std::move(modifiers), std::move(ai_chance) ); return ret; })(root); @@ -162,3 +169,11 @@ bool TechnologyManager::generate_modifiers(ModifierManager& modifier_manager) co return ret; } + +bool TechnologyManager::parse_scripts(GameManager const& game_manager) { + bool ret = true; + for (Technology& technology : technologies.get_items()) { + ret &= technology.parse_scripts(game_manager); + } + return ret; +} diff --git a/src/openvic-simulation/research/Technology.hpp b/src/openvic-simulation/research/Technology.hpp index 3b0b1da..a4287a5 100644 --- a/src/openvic-simulation/research/Technology.hpp +++ b/src/openvic-simulation/research/Technology.hpp @@ -5,6 +5,7 @@ #include "openvic-simulation/economy/BuildingType.hpp" #include "openvic-simulation/military/Unit.hpp" #include "openvic-simulation/misc/Modifier.hpp" +#include "openvic-simulation/scripts/ConditionalWeight.hpp" #include "openvic-simulation/types/Date.hpp" #include "openvic-simulation/types/OrderedContainers.hpp" @@ -43,17 +44,18 @@ namespace OpenVic { const fixed_point_t PROPERTY(cost); const bool PROPERTY(unciv_military); const uint8_t PROPERTY(unit); - const unit_set_t PROPERTY(activated_buildings); - const building_set_t PROPERTY(activated_units); - - //TODO: implement rules/modifiers and ai_chance + unit_set_t PROPERTY(activated_buildings); + building_set_t PROPERTY(activated_units); + ConditionalWeight PROPERTY(ai_chance); Technology( std::string_view new_identifier, TechnologyArea const& new_area, Date::year_t new_year, fixed_point_t new_cost, bool new_unciv_military, uint8_t new_unit, unit_set_t&& new_activated_units, - building_set_t&& new_activated_buildings, ModifierValue&& new_values + building_set_t&& new_activated_buildings, ModifierValue&& new_values, ConditionalWeight&& new_ai_chance ); + bool parse_scripts(GameManager const& game_manager); + public: Technology(Technology&&) = default; }; @@ -79,7 +81,8 @@ namespace OpenVic { bool add_technology( std::string_view identifier, TechnologyArea const* area, Date::year_t year, fixed_point_t cost, bool unciv_military, uint8_t unit, Technology::unit_set_t&& activated_units, - Technology::building_set_t&& activated_buildings, ModifierValue&& values); + Technology::building_set_t&& activated_buildings, ModifierValue&& values, ConditionalWeight&& ai_chance + ); bool add_technology_school(std::string_view identifier, ModifierValue&& values); @@ -90,5 +93,7 @@ namespace OpenVic { BuildingTypeManager const& building_type_manager, ast::NodeCPtr root ); // technologies/*.txt bool generate_modifiers(ModifierManager& modifier_manager) const; + + bool parse_scripts(GameManager const& game_manager); }; }
\ No newline at end of file |