diff options
Diffstat (limited to 'src/openvic-simulation/tech')
-rw-r--r-- | src/openvic-simulation/tech/Technology.cpp | 77 | ||||
-rw-r--r-- | src/openvic-simulation/tech/Technology.hpp | 25 |
2 files changed, 66 insertions, 36 deletions
diff --git a/src/openvic-simulation/tech/Technology.cpp b/src/openvic-simulation/tech/Technology.cpp index aa96fe2..1234ff3 100644 --- a/src/openvic-simulation/tech/Technology.cpp +++ b/src/openvic-simulation/tech/Technology.cpp @@ -3,18 +3,25 @@ using namespace OpenVic; using namespace OpenVic::NodeTools; -TechnologyFolder::TechnologyFolder(std::string_view identifier) : HasIdentifier { identifier } {} +TechnologyFolder::TechnologyFolder(std::string_view new_identifier) : HasIdentifier { new_identifier } {} -TechnologyArea::TechnologyArea(std::string_view identifier, TechnologyFolder const& folder) : HasIdentifier { identifier }, folder { folder } {} +TechnologyArea::TechnologyArea(std::string_view new_identifier, TechnologyFolder const& new_folder) + : HasIdentifier { new_identifier }, folder { new_folder } {} -Technology::Technology(std::string_view identifier, TechnologyArea const& area, year_t year, fixed_point_t cost, bool unciv_military, uint8_t unit, unit_set_t activated_units, building_set_t activated_buildings, ModifierValue&& values) - : Modifier { identifier, std::move(values), 0 }, area { area }, year { year }, cost { cost }, unciv_military { unciv_military }, unit { unit }, activated_buildings { std::move(activated_units) }, activated_units { std::move(activated_buildings) } {} +Technology::Technology( + std::string_view new_identifier, TechnologyArea const& new_area, 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 +) : 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) } {} -TechnologySchool::TechnologySchool(std::string_view new_identifier, ModifierValue&& new_values) - : Modifier { new_identifier, std::move(new_values), 0 } {} //TODO: school icon +TechnologySchool::TechnologySchool(std::string_view new_identifier, ModifierValue&& new_values) + : Modifier { new_identifier, std::move(new_values), 0 } {} -TechnologyManager::TechnologyManager() : technology_folders { "technology folders" }, technology_areas { "technology areas" }, - technologies { "technologies" }, technology_schools { "technology schools" } {} +TechnologyManager::TechnologyManager() + : technology_folders { "technology folders" }, technology_areas { "technology areas" }, technologies { "technologies" }, + technology_schools { "technology schools" } {} bool TechnologyManager::add_technology_folder(std::string_view identifier) { if (identifier.empty()) { @@ -39,7 +46,11 @@ bool TechnologyManager::add_technology_area(std::string_view identifier, Technol return technology_areas.add_item({ identifier, *folder }); } -bool TechnologyManager::add_technology(std::string_view identifier, TechnologyArea const* area, Technology::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) { +bool TechnologyManager::add_technology( + std::string_view identifier, TechnologyArea const* area, Technology::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 +) { if (identifier.empty()) { Logger::error("Invalid technology identifier - empty!"); return false; @@ -50,7 +61,10 @@ bool TechnologyManager::add_technology(std::string_view identifier, TechnologyAr return false; } - return technologies.add_item({ identifier, *area, year, cost, unciv_military, unit, activated_units, activated_buildings, std::move(values) }); + return technologies.add_item({ + identifier, *area, year, cost, unciv_military, unit, std::move(activated_units), std::move(activated_buildings), + std::move(values) + }); } bool TechnologyManager::add_technology_school(std::string_view identifier, ModifierValue&& values) { @@ -100,34 +114,37 @@ bool TechnologyManager::load_technology_file_schools(ModifierManager const& modi 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 { ModifierValue modifiers; - std::string_view area_identifier; - Technology::year_t year; - fixed_point_t cost; + TechnologyArea const* area = nullptr; + Technology::year_t year = 0; + fixed_point_t cost = 0; bool unciv_military = false; - uint8_t unit = 0; + uint8_t unit = 0; Technology::unit_set_t activated_units; Technology::building_set_t activated_buildings; - + bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(modifiers), - "area", ONE_EXACTLY, expect_identifier(assign_variable_callback(area_identifier)), + "area", ONE_EXACTLY, expect_technology_area_identifier(assign_variable_callback_pointer(area)), "year", ONE_EXACTLY, expect_uint(assign_variable_callback(year)), "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, expect_identifier([this, &unit_manager, &activated_units](std::string_view identifier) -> bool { - activated_units.insert(unit_manager.get_unit_by_identifier(identifier)); - return true; - }), - "activate_building", ZERO_OR_MORE, expect_identifier([this, &building_manager, &activated_buildings](std::string_view identifier) -> bool { - activated_buildings.insert(building_manager.get_building_type_by_identifier(identifier)); + "activate_unit", ZERO_OR_MORE, unit_manager.expect_unit_identifier([&activated_units](Unit const& unit) -> bool { + activated_units.insert(&unit); return true; }), - "ai_chance", ONE_EXACTLY, expect_dictionary([this](std::string_view identifier, ast::NodeCPtr value) -> bool { return true; }) //TODO + "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; + } + ), + "ai_chance", ONE_EXACTLY, success_callback //TODO )(tech_value); - TechnologyArea const* area = get_technology_area_by_identifier(area_identifier); - - ret &= add_technology(tech_key, area, year, cost, unciv_military, unit, activated_units, activated_buildings, std::move(modifiers)); + ret &= add_technology( + tech_key, area, year, cost, unciv_military, unit, std::move(activated_units), std::move(activated_buildings), + std::move(modifiers) + ); return ret; })(root); } @@ -135,12 +152,14 @@ bool TechnologyManager::load_technologies_file(ModifierManager const& modifier_m bool TechnologyManager::generate_modifiers(ModifierManager& modifier_manager) { bool ret = true; - ret &= modifier_manager.add_modifier_effect("unciv_military_modifier", true, ModifierEffect::format_t::PROPORTION_DECIMAL); - ret &= modifier_manager.add_modifier_effect("unciv_economic_modifier", true, ModifierEffect::format_t::PROPORTION_DECIMAL); + ret &= modifier_manager.add_modifier_effect("unciv_military_modifier", true); + ret &= modifier_manager.add_modifier_effect("unciv_economic_modifier", true); + ret &= modifier_manager.add_modifier_effect("self_unciv_economic_modifier", true); + ret &= modifier_manager.add_modifier_effect("self_unciv_military_modifier", true); for (TechnologyFolder const& folder : get_technology_folders()) { std::string folder_name = std::string(folder.get_identifier()) + "_research_bonus"; - ret &= modifier_manager.add_modifier_effect(folder_name, true, ModifierEffect::format_t::PROPORTION_DECIMAL); + ret &= modifier_manager.add_modifier_effect(folder_name, true); } return ret; }
\ No newline at end of file diff --git a/src/openvic-simulation/tech/Technology.hpp b/src/openvic-simulation/tech/Technology.hpp index 0aca1f6..6f50f01 100644 --- a/src/openvic-simulation/tech/Technology.hpp +++ b/src/openvic-simulation/tech/Technology.hpp @@ -11,7 +11,7 @@ namespace OpenVic { friend struct TechnologyManager; private: - TechnologyFolder(std::string_view identifier); + TechnologyFolder(std::string_view new_identifier); public: TechnologyFolder(TechnologyFolder&&) = default; @@ -23,7 +23,7 @@ namespace OpenVic { private: TechnologyFolder const& PROPERTY(folder); - TechnologyArea(std::string_view identifier, TechnologyFolder const& folder); + TechnologyArea(std::string_view new_identifier, TechnologyFolder const& new_folder); public: TechnologyArea(TechnologyArea&&) = default; @@ -31,6 +31,7 @@ namespace OpenVic { struct Technology : Modifier { friend struct TechnologyManager; + using year_t = Date::year_t; using unit_set_t = std::unordered_set<Unit const*>; using building_set_t = std::unordered_set<BuildingType const*>; @@ -46,8 +47,12 @@ namespace OpenVic { //TODO: implement rules/modifiers and ai_chance - Technology(std::string_view identifier, TechnologyArea const& area, year_t year, fixed_point_t cost, bool unciv_military, uint8_t unit, unit_set_t activated_units, building_set_t activated_buildings, ModifierValue&& values); - + Technology( + std::string_view new_identifier, TechnologyArea const& new_area, 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 + ); + public: Technology(Technology&&) = default; }; @@ -74,15 +79,21 @@ namespace OpenVic { bool add_technology_area(std::string_view identifier, TechnologyFolder const* folder); IDENTIFIER_REGISTRY_ACCESSORS(technology_area) - bool add_technology(std::string_view identifier, TechnologyArea const* area, Technology::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); + bool add_technology( + std::string_view identifier, TechnologyArea const* area, Technology::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); IDENTIFIER_REGISTRY_ACCESSORS_CUSTOM_PLURAL(technology, technologies) - bool add_technology_school(std::string_view identifier, ModifierValue&& values); //, Modifier::icon_t icon); + bool add_technology_school(std::string_view identifier, ModifierValue&& values); 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); // technologies/*.txt + bool load_technologies_file( + ModifierManager const& modifier_manager, UnitManager const& unit_manager, BuildingManager const& building_manager, + ast::NodeCPtr root + ); // technologies/*.txt bool generate_modifiers(ModifierManager& modifier_manager); }; }
\ No newline at end of file |