From 398377011cb3d3c970451dcd215f3610159f1ae2 Mon Sep 17 00:00:00 2001 From: hop311 Date: Wed, 6 Dec 2023 22:10:53 +0000 Subject: Vec/set callbacks + crime file + prov building pos --- src/openvic-simulation/economy/BuildingType.cpp | 13 ++++--------- src/openvic-simulation/economy/BuildingType.hpp | 8 ++++---- src/openvic-simulation/economy/EconomyManager.hpp | 4 ++-- src/openvic-simulation/economy/Good.cpp | 3 +-- src/openvic-simulation/economy/ProductionType.cpp | 11 +++-------- 5 files changed, 14 insertions(+), 25 deletions(-) (limited to 'src/openvic-simulation/economy') diff --git a/src/openvic-simulation/economy/BuildingType.cpp b/src/openvic-simulation/economy/BuildingType.cpp index b80999a..876afd9 100644 --- a/src/openvic-simulation/economy/BuildingType.cpp +++ b/src/openvic-simulation/economy/BuildingType.cpp @@ -14,9 +14,9 @@ BuildingType::BuildingType( colonial_range { colonial_range }, infrastructure { infrastructure }, spawn_railway_track { spawn_railway_track }, sail { sail }, steam { steam }, capital { capital }, port { port } {} -BuildingManager::BuildingManager() : building_types { "building types" } {} +BuildingTypeManager::BuildingTypeManager() : building_types { "building types" } {} -bool BuildingManager::add_building_type(std::string_view identifier, ARGS) { +bool BuildingTypeManager::add_building_type(std::string_view identifier, ARGS) { if (identifier.empty()) { Logger::error("Invalid building identifier - empty!"); return false; @@ -30,7 +30,7 @@ bool BuildingManager::add_building_type(std::string_view identifier, ARGS) { }); } -bool BuildingManager::load_buildings_file( +bool BuildingTypeManager::load_buildings_file( GoodManager const& good_manager, ProductionTypeManager const& production_type_manager, ModifierManager& modifier_manager, ast::NodeCPtr root ) { @@ -70,12 +70,7 @@ bool BuildingManager::load_buildings_file( "advanced_factory", ZERO_OR_ONE, expect_bool(assign_variable_callback(advanced_factory)), "fort_level", ZERO_OR_ONE, expect_uint(assign_variable_callback(fort_level)), "naval_capacity", ZERO_OR_ONE, expect_uint(assign_variable_callback(naval_capacity)), - "colonial_points", ZERO_OR_ONE, expect_list(expect_fixed_point( - [&colonial_points](fixed_point_t points) -> bool { - colonial_points.push_back(points); - return true; - } - )), + "colonial_points", ZERO_OR_ONE, expect_list(expect_fixed_point(vector_callback(colonial_points))), "province", ZERO_OR_ONE, expect_bool(assign_variable_callback(in_province)), "one_per_state", ZERO_OR_ONE, expect_bool(assign_variable_callback(one_per_state)), "colonial_range", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(colonial_range)), diff --git a/src/openvic-simulation/economy/BuildingType.hpp b/src/openvic-simulation/economy/BuildingType.hpp index a49c461..deba77a 100644 --- a/src/openvic-simulation/economy/BuildingType.hpp +++ b/src/openvic-simulation/economy/BuildingType.hpp @@ -17,7 +17,7 @@ namespace OpenVic { - struct BuildingManager; + struct BuildingTypeManager; /* REQUIREMENTS: * MAP-11, MAP-72, MAP-73 @@ -25,7 +25,7 @@ namespace OpenVic { * MAP-13, MAP-78, MAP-79 */ struct BuildingType : HasIdentifier { - friend struct BuildingManager; + friend struct BuildingTypeManager; using level_t = int16_t; @@ -69,14 +69,14 @@ namespace OpenVic { BuildingType(BuildingType&&) = default; }; - struct BuildingManager { + struct BuildingTypeManager { using level_t = BuildingType::level_t; // this is getting ridiculous private: IdentifierRegistry building_types; public: - BuildingManager(); + BuildingTypeManager(); bool add_building_type(std::string_view identifier, ARGS); IDENTIFIER_REGISTRY_ACCESSORS(building_type) diff --git a/src/openvic-simulation/economy/EconomyManager.hpp b/src/openvic-simulation/economy/EconomyManager.hpp index fcde094..adeabd9 100644 --- a/src/openvic-simulation/economy/EconomyManager.hpp +++ b/src/openvic-simulation/economy/EconomyManager.hpp @@ -7,7 +7,7 @@ namespace OpenVic { struct EconomyManager { private: - BuildingManager PROPERTY_REF(building_manager); + BuildingTypeManager PROPERTY_REF(building_type_manager); GoodManager PROPERTY_REF(good_manager); ProductionTypeManager PROPERTY_REF(production_type_manager); @@ -17,7 +17,7 @@ namespace OpenVic { } inline bool load_buildings_file(ModifierManager& modifier_manager, ast::NodeCPtr root) { - return building_manager.load_buildings_file(good_manager, production_type_manager, modifier_manager, root); + return building_type_manager.load_buildings_file(good_manager, production_type_manager, modifier_manager, root); } }; } diff --git a/src/openvic-simulation/economy/Good.cpp b/src/openvic-simulation/economy/Good.cpp index 02c4f0b..ac3c8c7 100644 --- a/src/openvic-simulation/economy/Good.cpp +++ b/src/openvic-simulation/economy/Good.cpp @@ -101,8 +101,7 @@ bool GoodManager::load_goods_file(ast::NodeCPtr root) { for (Good const& good : this->get_goods()) { \ ret &= modifier_manager.add_modifier_effect( \ StringUtils::append_string_views(name, "_", good.get_identifier()), \ - true, \ - ModifierEffect::format_t::PROPORTION_DECIMAL \ + true \ ); \ } diff --git a/src/openvic-simulation/economy/ProductionType.cpp b/src/openvic-simulation/economy/ProductionType.cpp index a862b12..d0b90fa 100644 --- a/src/openvic-simulation/economy/ProductionType.cpp +++ b/src/openvic-simulation/economy/ProductionType.cpp @@ -55,16 +55,11 @@ node_callback_t ProductionTypeManager::_expect_employed_pop( node_callback_t ProductionTypeManager::_expect_employed_pop_list( GoodManager const& good_manager, PopManager const& pop_manager, callback_t&&> cb ) { - return [this, &good_manager, &pop_manager, cb](ast::NodeCPtr node) -> bool { std::vector employed_pops; - bool res = expect_list([this, &good_manager, &pop_manager, &employed_pops](ast::NodeCPtr node) -> bool { - EmployedPop owner; - bool res_partial = _expect_employed_pop(good_manager, pop_manager, assign_variable_callback(owner))(node); - employed_pops.push_back(owner); - return res_partial; - })(node); - return res & cb(std::move(employed_pops)); + bool ret = expect_list(_expect_employed_pop(good_manager, pop_manager, vector_callback(employed_pops)))(node); + ret &= cb(std::move(employed_pops)); + return ret; }; } -- cgit v1.2.3-56-ga3b1