diff options
Diffstat (limited to 'src/openvic-simulation/economy')
-rw-r--r-- | src/openvic-simulation/economy/Building.cpp | 149 | ||||
-rw-r--r-- | src/openvic-simulation/economy/Building.hpp | 53 | ||||
-rw-r--r-- | src/openvic-simulation/economy/EconomyManager.hpp | 1 | ||||
-rw-r--r-- | src/openvic-simulation/economy/Good.cpp | 77 | ||||
-rw-r--r-- | src/openvic-simulation/economy/Good.hpp | 12 | ||||
-rw-r--r-- | src/openvic-simulation/economy/ProductionType.cpp | 49 | ||||
-rw-r--r-- | src/openvic-simulation/economy/ProductionType.hpp | 29 |
7 files changed, 197 insertions, 173 deletions
diff --git a/src/openvic-simulation/economy/Building.cpp b/src/openvic-simulation/economy/Building.cpp index 4a99249..a79741b 100644 --- a/src/openvic-simulation/economy/Building.cpp +++ b/src/openvic-simulation/economy/Building.cpp @@ -5,8 +5,9 @@ using namespace OpenVic; using namespace OpenVic::NodeTools; -Building::Building(std::string_view identifier, BuildingType const& type, ARGS) - : HasIdentifier { identifier }, type { type }, modifier { std::move(modifier) }, on_completion { on_completion }, +Building::Building( + std::string_view identifier, BuildingType const& type, ARGS +) : HasIdentifier { identifier }, type { type }, modifier { std::move(modifier) }, on_completion { on_completion }, completion_size { completion_size }, max_level { max_level }, goods_cost { std::move(goods_cost) }, cost { cost }, build_time { build_time }, visibility { visibility }, on_map { on_map }, default_enabled { default_enabled }, production_type { production_type }, pop_build_factory { pop_build_factory }, strategic_factory { strategic_factory }, @@ -154,14 +155,14 @@ bool BuildingInstance::expand() { */ void BuildingInstance::update_state(Date const& today) { switch (expansion_state) { - case ExpansionState::Preparing: - start = today; - end = start + building.get_build_time(); - break; - case ExpansionState::Expanding: - expansion_progress = static_cast<double>(today - start) / static_cast<double>(end - start); - break; - default: expansion_state = _can_expand() ? ExpansionState::CanExpand : ExpansionState::CannotExpand; + case ExpansionState::Preparing: + start = today; + end = start + building.get_build_time(); + break; + case ExpansionState::Expanding: + expansion_progress = static_cast<double>(today - start) / static_cast<double>(end - start); + break; + default: expansion_state = _can_expand() ? ExpansionState::CanExpand : ExpansionState::CannotExpand; } } @@ -198,13 +199,17 @@ bool BuildingManager::add_building(std::string_view identifier, BuildingType con } return buildings.add_item({ - identifier, *type, std::move(modifier), on_completion, completion_size, max_level, std::move(goods_cost), cost, build_time, visibility, on_map, default_enabled, - production_type, pop_build_factory, strategic_factory, advanced_factory, fort_level, naval_capacity, std::move(colonial_points), in_province, one_per_state, + identifier, *type, std::move(modifier), on_completion, completion_size, max_level, std::move(goods_cost), + cost, build_time, visibility, on_map, default_enabled, production_type, pop_build_factory, strategic_factory, + advanced_factory, fort_level, naval_capacity, std::move(colonial_points), in_province, one_per_state, colonial_range, infrastructure, spawn_railway_track, sail, steam, capital, port }); } -bool BuildingManager::load_buildings_file(GoodManager const& good_manager, ProductionTypeManager const& production_type_manager, ModifierManager const& modifier_manager, ast::NodeCPtr root) { +bool BuildingManager::load_buildings_file( + GoodManager const& good_manager, ProductionTypeManager const& production_type_manager, + ModifierManager const& modifier_manager, ast::NodeCPtr root +) { bool ret = expect_dictionary_reserve_length(buildings, [this](std::string_view, ast::NodeCPtr value) -> bool { return expect_key("type", expect_identifier( std::bind(&BuildingManager::add_building_type, this, std::placeholders::_1) @@ -212,62 +217,68 @@ bool BuildingManager::load_buildings_file(GoodManager const& good_manager, Produ })(root); lock_building_types(); - ret &= expect_dictionary([this, &good_manager, &production_type_manager, &modifier_manager](std::string_view key, ast::NodeCPtr value) -> bool { - BuildingType const* type = nullptr; - ProductionType const* production_type = nullptr; - std::string_view on_completion; - fixed_point_t completion_size = 0, cost = 0, infrastructure = 0, colonial_range = 0; - Building::level_t max_level = 0, fort_level = 0; - Good::good_map_t goods_cost; - Timespan build_time; - bool visibility = false, on_map = false, default_enabled = false, pop_build_factory = false, strategic_factory = false, advanced_factory = false; - bool in_province = false, one_per_state = false, spawn_railway_track = false, sail = false, steam = false, capital = false, port = false; - uint64_t naval_capacity = 0; - std::vector<fixed_point_t> colonial_points; - ModifierValue modifier; - - bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(modifier), - "type", ONE_EXACTLY, expect_building_type_identifier(assign_variable_callback_pointer(type)), - "on_completion", ZERO_OR_ONE, expect_identifier(assign_variable_callback(on_completion)), - "completion_size", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(completion_size)), - "max_level", ONE_EXACTLY, expect_uint(assign_variable_callback(max_level)), - "goods_cost", ONE_EXACTLY, good_manager.expect_good_decimal_map(move_variable_callback(goods_cost)), - "cost", ZERO_OR_MORE, expect_fixed_point(assign_variable_callback(cost)), - "time", ONE_EXACTLY, expect_days(assign_variable_callback(build_time)), - "visibility", ONE_EXACTLY, expect_bool(assign_variable_callback(visibility)), - "onmap", ONE_EXACTLY, expect_bool(assign_variable_callback(on_map)), - "default_enabled", ZERO_OR_ONE, expect_bool(assign_variable_callback(default_enabled)), - "production_type", ZERO_OR_ONE, production_type_manager.expect_production_type_identifier( - assign_variable_callback_pointer(production_type)), - "pop_build_factory", ZERO_OR_ONE, expect_bool(assign_variable_callback(pop_build_factory)), - "strategic_factory", ZERO_OR_ONE, expect_bool(assign_variable_callback(strategic_factory)), - "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; - })), - "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)), - "infrastructure", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(infrastructure)), - "spawn_railway_track", ZERO_OR_ONE, expect_bool(assign_variable_callback(spawn_railway_track)), - "sail", ZERO_OR_ONE, expect_bool(assign_variable_callback(sail)), - "steam", ZERO_OR_ONE, expect_bool(assign_variable_callback(steam)), - "capital", ZERO_OR_ONE, expect_bool(assign_variable_callback(capital)), - "port", ZERO_OR_ONE, expect_bool(assign_variable_callback(port)) - )(value); - - ret &= add_building( - key, type,std::move(modifier), on_completion, completion_size, max_level, std::move(goods_cost), cost, build_time, - visibility, on_map, default_enabled, production_type, pop_build_factory, strategic_factory, advanced_factory, - fort_level, naval_capacity, std::move(colonial_points), in_province, one_per_state, colonial_range, infrastructure, - spawn_railway_track, sail, steam, capital, port - ); - - return ret; - })(root); + ret &= expect_dictionary( + [this, &good_manager, &production_type_manager, &modifier_manager](std::string_view key, ast::NodeCPtr value) -> bool { + BuildingType const* type = nullptr; + ProductionType const* production_type = nullptr; + std::string_view on_completion; + fixed_point_t completion_size = 0, cost = 0, infrastructure = 0, colonial_range = 0; + Building::level_t max_level = 0, fort_level = 0; + Good::good_map_t goods_cost; + Timespan build_time; + bool visibility = false, on_map = false, default_enabled = false, pop_build_factory = false; + bool strategic_factory = false, advanced_factory = false; + bool in_province = false, one_per_state = false, spawn_railway_track = false, sail = false, steam = false; + bool capital = false, port = false; + uint64_t naval_capacity = 0; + std::vector<fixed_point_t> colonial_points; + ModifierValue modifier; + + bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(modifier), + "type", ONE_EXACTLY, expect_building_type_identifier(assign_variable_callback_pointer(type)), + "on_completion", ZERO_OR_ONE, expect_identifier(assign_variable_callback(on_completion)), + "completion_size", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(completion_size)), + "max_level", ONE_EXACTLY, expect_uint(assign_variable_callback(max_level)), + "goods_cost", ONE_EXACTLY, good_manager.expect_good_decimal_map(move_variable_callback(goods_cost)), + "cost", ZERO_OR_MORE, expect_fixed_point(assign_variable_callback(cost)), + "time", ONE_EXACTLY, expect_days(assign_variable_callback(build_time)), + "visibility", ONE_EXACTLY, expect_bool(assign_variable_callback(visibility)), + "onmap", ONE_EXACTLY, expect_bool(assign_variable_callback(on_map)), + "default_enabled", ZERO_OR_ONE, expect_bool(assign_variable_callback(default_enabled)), + "production_type", ZERO_OR_ONE, production_type_manager.expect_production_type_identifier( + assign_variable_callback_pointer(production_type)), + "pop_build_factory", ZERO_OR_ONE, expect_bool(assign_variable_callback(pop_build_factory)), + "strategic_factory", ZERO_OR_ONE, expect_bool(assign_variable_callback(strategic_factory)), + "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; + } + )), + "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)), + "infrastructure", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(infrastructure)), + "spawn_railway_track", ZERO_OR_ONE, expect_bool(assign_variable_callback(spawn_railway_track)), + "sail", ZERO_OR_ONE, expect_bool(assign_variable_callback(sail)), + "steam", ZERO_OR_ONE, expect_bool(assign_variable_callback(steam)), + "capital", ZERO_OR_ONE, expect_bool(assign_variable_callback(capital)), + "port", ZERO_OR_ONE, expect_bool(assign_variable_callback(port)) + )(value); + + ret &= add_building( + key, type, std::move(modifier), on_completion, completion_size, max_level, std::move(goods_cost), cost, + build_time, visibility, on_map, default_enabled, production_type, pop_build_factory, strategic_factory, + advanced_factory, fort_level, naval_capacity, std::move(colonial_points), in_province, one_per_state, + colonial_range, infrastructure, spawn_railway_track, sail, steam, capital, port + ); + + return ret; + } + )(root); lock_buildings(); return ret; diff --git a/src/openvic-simulation/economy/Building.hpp b/src/openvic-simulation/economy/Building.hpp index b56c9a2..89b6db8 100644 --- a/src/openvic-simulation/economy/Building.hpp +++ b/src/openvic-simulation/economy/Building.hpp @@ -1,19 +1,19 @@ #pragma once -#include "openvic-simulation/types/Date.hpp" -#include "openvic-simulation/types/fixed_point/FixedPoint.hpp" -#include "openvic-simulation/types/IdentifierRegistry.hpp" +#include "openvic-simulation/Modifier.hpp" #include "openvic-simulation/economy/Good.hpp" #include "openvic-simulation/economy/ProductionType.hpp" -#include "openvic-simulation/Modifier.hpp" +#include "openvic-simulation/types/Date.hpp" +#include "openvic-simulation/types/IdentifierRegistry.hpp" +#include "openvic-simulation/types/fixed_point/FixedPoint.hpp" #define ARGS \ ModifierValue&& modifier, std::string_view on_completion, fixed_point_t completion_size, level_t max_level, \ - Good::good_map_t&& goods_cost, fixed_point_t cost, Timespan build_time, bool visibility, bool on_map, bool default_enabled, \ - ProductionType const* production_type, bool pop_build_factory, bool strategic_factory, bool advanced_factory, level_t fort_level, \ - uint64_t naval_capacity, std::vector<fixed_point_t>&& colonial_points, bool in_province, bool one_per_state, fixed_point_t colonial_range, \ - fixed_point_t infrastructure, bool spawn_railway_track, bool sail, bool steam, \ - bool capital, bool port + Good::good_map_t&& goods_cost, fixed_point_t cost, Timespan build_time, bool visibility, bool on_map, \ + bool default_enabled, ProductionType const* production_type, bool pop_build_factory, bool strategic_factory, \ + bool advanced_factory, level_t fort_level, uint64_t naval_capacity, std::vector<fixed_point_t>&& colonial_points, \ + bool in_province, bool one_per_state, fixed_point_t colonial_range, fixed_point_t infrastructure, \ + bool spawn_railway_track, bool sail, bool steam, bool capital, bool port namespace OpenVic { @@ -33,14 +33,14 @@ namespace OpenVic { private: BuildingType const& type; const ModifierValue modifier; - const std::string on_completion; //probably sound played on completion + const std::string on_completion; // probably sound played on completion const fixed_point_t completion_size; const level_t max_level; const Good::good_map_t goods_cost; const fixed_point_t cost; - const Timespan build_time; //time + const Timespan build_time; // time const bool visibility; - const bool on_map; //onmap + const bool on_map; // onmap const bool default_enabled; ProductionType const* production_type; @@ -48,21 +48,21 @@ namespace OpenVic { const bool strategic_factory; const bool advanced_factory; - const level_t fort_level; //probably the step-per-level + const level_t fort_level; // probably the step-per-level const uint64_t naval_capacity; const std::vector<fixed_point_t> colonial_points; - const bool in_province; //province + const bool in_province; // province const bool one_per_state; const fixed_point_t colonial_range; const fixed_point_t infrastructure; const bool spawn_railway_track; - const bool sail; //only in clipper shipyard - const bool steam; //only in steamer shipyard - const bool capital; //only in naval base - const bool port; //only in naval base + const bool sail; // only in clipper shipyard + const bool steam; // only in steamer shipyard + const bool capital; // only in naval base + const bool port; // only in naval base Building(std::string_view identifier, BuildingType const& type, ARGS); @@ -108,14 +108,9 @@ namespace OpenVic { BuildingType(BuildingType&&) = default; }; - enum class ExpansionState { - CannotExpand, - CanExpand, - Preparing, - Expanding - }; + enum class ExpansionState { CannotExpand, CanExpand, Preparing, Expanding }; - struct BuildingInstance : HasIdentifier { //used in the actual game + struct BuildingInstance : HasIdentifier { // used in the actual game friend struct BuildingManager; using level_t = Building::level_t; @@ -145,13 +140,12 @@ namespace OpenVic { bool expand(); void update_state(Date const& today); void tick(Date const& today); - }; struct Province; struct BuildingManager { - using level_t = Building::level_t; //this is getting ridiculous + using level_t = Building::level_t; // this is getting ridiculous private: IdentifierRegistry<BuildingType> building_types; @@ -166,7 +160,10 @@ namespace OpenVic { bool add_building(std::string_view identifier, BuildingType const* type, ARGS); IDENTIFIER_REGISTRY_ACCESSORS(building) - bool load_buildings_file(GoodManager const& good_manager, ProductionTypeManager const& production_type_manager, ModifierManager const& modifier_manager, ast::NodeCPtr root); + bool load_buildings_file( + GoodManager const& good_manager, ProductionTypeManager const& production_type_manager, + ModifierManager const& modifier_manager, ast::NodeCPtr root + ); bool generate_province_buildings(Province& province) const; }; diff --git a/src/openvic-simulation/economy/EconomyManager.hpp b/src/openvic-simulation/economy/EconomyManager.hpp index 05dfc91..b7d45c9 100644 --- a/src/openvic-simulation/economy/EconomyManager.hpp +++ b/src/openvic-simulation/economy/EconomyManager.hpp @@ -10,6 +10,7 @@ namespace OpenVic { BuildingManager building_manager; GoodManager good_manager; ProductionTypeManager production_type_manager; + public: REF_GETTERS(building_manager) REF_GETTERS(good_manager) diff --git a/src/openvic-simulation/economy/Good.cpp b/src/openvic-simulation/economy/Good.cpp index 0fd4618..11230d2 100644 --- a/src/openvic-simulation/economy/Good.cpp +++ b/src/openvic-simulation/economy/Good.cpp @@ -7,15 +7,12 @@ using namespace OpenVic::NodeTools; GoodCategory::GoodCategory(std::string_view new_identifier) : HasIdentifier { new_identifier } {} -Good::Good(std::string_view new_identifier, colour_t new_colour, GoodCategory const& new_category, price_t new_base_price, - bool new_available_from_start, bool new_tradeable, bool new_money, bool new_overseas_penalty) - : HasIdentifierAndColour { new_identifier, new_colour, true, false }, - category { new_category }, - base_price { new_base_price }, - available_from_start { new_available_from_start }, - tradeable { new_tradeable }, - money { new_money }, - overseas_penalty { new_overseas_penalty } { +Good::Good( + std::string_view new_identifier, colour_t new_colour, GoodCategory const& new_category, price_t new_base_price, + bool new_available_from_start, bool new_tradeable, bool new_money, bool new_overseas_penalty +) : HasIdentifierAndColour { new_identifier, new_colour, true, false }, category { new_category }, + base_price { new_base_price }, available_from_start { new_available_from_start }, tradeable { new_tradeable }, + money { new_money }, overseas_penalty { new_overseas_penalty } { assert(base_price > NULL_PRICE); } @@ -66,8 +63,10 @@ bool GoodManager::add_good_category(std::string_view identifier) { return good_categories.add_item({ identifier }); } -bool GoodManager::add_good(std::string_view identifier, colour_t colour, GoodCategory const* category, - Good::price_t base_price, bool available_from_start, bool tradeable, bool money, bool overseas_penalty) { +bool GoodManager::add_good( + std::string_view identifier, colour_t colour, GoodCategory const* category, Good::price_t base_price, + bool available_from_start, bool tradeable, bool money, bool overseas_penalty +) { if (identifier.empty()) { Logger::error("Invalid good identifier - empty!"); return false; @@ -84,12 +83,16 @@ bool GoodManager::add_good(std::string_view identifier, colour_t colour, GoodCat Logger::error("Invalid base price for ", identifier, ": ", base_price); return false; } - return goods.add_item({ identifier, colour, *category, base_price, available_from_start, tradeable, money, overseas_penalty }); + return goods.add_item({ + identifier, colour, *category, base_price, available_from_start, + tradeable, money, overseas_penalty + }); } void GoodManager::reset_to_defaults() { - for (Good& good : goods.get_items()) + for (Good& good : goods.get_items()) { good.reset_to_defaults(); + } } bool GoodManager::load_goods_file(ast::NodeCPtr root) { @@ -104,31 +107,29 @@ bool GoodManager::load_goods_file(ast::NodeCPtr root) { )(root); lock_good_categories(); goods.reserve(goods.size() + total_expected_goods); - ret &= expect_dictionary( - [this](std::string_view good_category_key, ast::NodeCPtr good_category_value) -> bool { - GoodCategory const* good_category = get_good_category_by_identifier(good_category_key); - - return expect_dictionary( - [this, good_category](std::string_view key, ast::NodeCPtr value) -> bool { - colour_t colour = NULL_COLOUR; - Good::price_t base_price; - bool available_from_start = true, tradeable = true; - bool money = false, overseas_penalty = false; - - bool ret = expect_dictionary_keys( - "color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)), - "cost", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(base_price)), - "available_from_start", ZERO_OR_ONE, expect_bool(assign_variable_callback(available_from_start)), - "tradeable", ZERO_OR_ONE, expect_bool(assign_variable_callback(tradeable)), - "money", ZERO_OR_ONE, expect_bool(assign_variable_callback(money)), - "overseas_penalty", ZERO_OR_ONE, expect_bool(assign_variable_callback(overseas_penalty)) - )(value); - ret &= add_good(key, colour, good_category, base_price, available_from_start, tradeable, money, overseas_penalty); - return ret; - } - )(good_category_value); - } - )(root); + ret &= expect_dictionary([this](std::string_view good_category_key, ast::NodeCPtr good_category_value) -> bool { + GoodCategory const* good_category = get_good_category_by_identifier(good_category_key); + + return expect_dictionary([this, good_category](std::string_view key, ast::NodeCPtr value) -> bool { + colour_t colour = NULL_COLOUR; + Good::price_t base_price; + bool available_from_start = true, tradeable = true; + bool money = false, overseas_penalty = false; + + bool ret = expect_dictionary_keys( + "color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)), + "cost", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(base_price)), + "available_from_start", ZERO_OR_ONE, expect_bool(assign_variable_callback(available_from_start)), + "tradeable", ZERO_OR_ONE, expect_bool(assign_variable_callback(tradeable)), + "money", ZERO_OR_ONE, expect_bool(assign_variable_callback(money)), + "overseas_penalty", ZERO_OR_ONE, expect_bool(assign_variable_callback(overseas_penalty)) + )(value); + ret &= add_good( + key, colour, good_category, base_price, available_from_start, tradeable, money, overseas_penalty + ); + return ret; + })(good_category_value); + })(root); lock_goods(); return ret; } diff --git a/src/openvic-simulation/economy/Good.hpp b/src/openvic-simulation/economy/Good.hpp index 2a850fa..ae2d6a9 100644 --- a/src/openvic-simulation/economy/Good.hpp +++ b/src/openvic-simulation/economy/Good.hpp @@ -42,8 +42,10 @@ namespace OpenVic { const bool available_from_start, tradeable, money, overseas_penalty; bool available; - Good(std::string_view new_identifier, colour_t new_colour, GoodCategory const& new_category, price_t new_base_price, - bool new_available_from_start, bool new_tradeable, bool new_money, bool new_overseas_penalty); + Good( + std::string_view new_identifier, colour_t new_colour, GoodCategory const& new_category, price_t new_base_price, + bool new_available_from_start, bool new_tradeable, bool new_money, bool new_overseas_penalty + ); public: Good(Good&&) = default; @@ -70,8 +72,10 @@ namespace OpenVic { bool add_good_category(std::string_view identifier); IDENTIFIER_REGISTRY_ACCESSORS_CUSTOM_PLURAL(good_category, good_categories) - bool add_good(std::string_view identifier, colour_t colour, GoodCategory const* category, Good::price_t base_price, - bool available_from_start, bool tradeable, bool money, bool overseas_penalty); + bool add_good( + std::string_view identifier, colour_t colour, GoodCategory const* category, Good::price_t base_price, + bool available_from_start, bool tradeable, bool money, bool overseas_penalty + ); IDENTIFIER_REGISTRY_ACCESSORS(good) void reset_to_defaults(); diff --git a/src/openvic-simulation/economy/ProductionType.cpp b/src/openvic-simulation/economy/ProductionType.cpp index f31ea59..1c65c4d 100644 --- a/src/openvic-simulation/economy/ProductionType.cpp +++ b/src/openvic-simulation/economy/ProductionType.cpp @@ -5,8 +5,10 @@ using namespace OpenVic; using namespace OpenVic::NodeTools; -EmployedPop::EmployedPop(PopType const* pop_type, bool artisan, effect_t effect, fixed_point_t effect_multiplier, fixed_point_t amount) - : pop_type { pop_type }, artisan { artisan }, effect { effect }, effect_multiplier { effect_multiplier }, amount { amount } {} +EmployedPop::EmployedPop( + PopType const* pop_type, bool artisan, effect_t effect, fixed_point_t effect_multiplier, fixed_point_t amount +) : pop_type { pop_type }, artisan { artisan }, effect { effect }, effect_multiplier { effect_multiplier }, + amount { amount } {} PopType const* EmployedPop::get_pop_type() const { return pop_type; @@ -28,9 +30,11 @@ fixed_point_t EmployedPop::get_amount() const { return amount; } -ProductionType::ProductionType(PRODUCTION_TYPE_ARGS) : HasIdentifier { identifier }, owner { owner }, employees { employees }, - type { type }, workforce { workforce }, input_goods { std::move(input_goods) }, output_goods { output_goods }, - value { value }, bonuses { std::move(bonuses) }, efficiency { std::move(efficiency) }, coastal { coastal }, farm { farm }, mine { mine } {} +ProductionType::ProductionType( + PRODUCTION_TYPE_ARGS +) : HasIdentifier { identifier }, owner { owner }, employees { employees }, type { type }, workforce { workforce }, + input_goods { std::move(input_goods) }, output_goods { output_goods }, value { value }, bonuses { std::move(bonuses) }, + efficiency { std::move(efficiency) }, coastal { coastal }, farm { farm }, mine { mine } {} EmployedPop const& ProductionType::get_owner() const { return owner; @@ -82,8 +86,9 @@ bool ProductionType::is_mine() const { ProductionTypeManager::ProductionTypeManager() : production_types { "production types" } {} -node_callback_t ProductionTypeManager::_expect_employed_pop(GoodManager const& good_manager, PopManager const& pop_manager, - callback_t<EmployedPop&&> cb) { +node_callback_t ProductionTypeManager::_expect_employed_pop( + GoodManager const& good_manager, PopManager const& pop_manager, callback_t<EmployedPop&&> cb +) { return [this, &good_manager, &pop_manager, cb](ast::NodeCPtr node) -> bool { std::string_view pop_type; @@ -117,8 +122,9 @@ node_callback_t ProductionTypeManager::_expect_employed_pop(GoodManager const& g }; } -node_callback_t ProductionTypeManager::_expect_employed_pop_list(GoodManager const& good_manager, PopManager const& pop_manager, - callback_t<std::vector<EmployedPop>&&> cb) { +node_callback_t ProductionTypeManager::_expect_employed_pop_list( + GoodManager const& good_manager, PopManager const& pop_manager, callback_t<std::vector<EmployedPop>&&> cb +) { return [this, &good_manager, &pop_manager, cb](ast::NodeCPtr node) -> bool { std::vector<EmployedPop> employed_pops; @@ -133,7 +139,8 @@ node_callback_t ProductionTypeManager::_expect_employed_pop_list(GoodManager con } #define POPTYPE_CHECK(employed_pop) \ - if ((employed_pop.pop_type == nullptr && !employed_pop.artisan) || (employed_pop.pop_type != nullptr && employed_pop.artisan)) { \ + if ((employed_pop.pop_type == nullptr && !employed_pop.artisan) || \ + (employed_pop.pop_type != nullptr && employed_pop.artisan)) { \ Logger::error("Invalid pop type parsed for owner of production type ", identifier, "!"); \ return false; \ } @@ -171,7 +178,8 @@ bool ProductionTypeManager::add_production_type(PRODUCTION_TYPE_ARGS, GoodManage }); } -#define PARSE_NODE expect_dictionary_keys_and_default( \ +#define PARSE_NODE \ + expect_dictionary_keys_and_default( \ key_value_success_callback, \ "owner", ZERO_OR_ONE, _expect_employed_pop(good_manager, pop_manager, move_variable_callback(owner)), \ "employees", ZERO_OR_ONE, _expect_employed_pop_list(good_manager, pop_manager, move_variable_callback(employees)), \ @@ -186,7 +194,9 @@ bool ProductionTypeManager::add_production_type(PRODUCTION_TYPE_ARGS, GoodManage "mine", ZERO_OR_ONE, expect_bool(assign_variable_callback(mine)) \ ) -bool ProductionTypeManager::load_production_types_file(GoodManager const& good_manager, PopManager const& pop_manager, ast::NodeCPtr root) { +bool ProductionTypeManager::load_production_types_file( + GoodManager const& good_manager, PopManager const& pop_manager, ast::NodeCPtr root +) { size_t expected_types = 0; // pass 1: find and store template identifiers @@ -198,7 +208,8 @@ bool ProductionTypeManager::load_production_types_file(GoodManager const& good_m std::string_view template_id = ""; bool found_template = false; - const bool ret = expect_key("template", expect_identifier(assign_variable_callback(template_id)), &found_template)(value); + const bool ret = + expect_key("template", expect_identifier(assign_variable_callback(template_id)), &found_template)(value); if (found_template) { if (ret) { templates.emplace(template_id); @@ -227,9 +238,11 @@ bool ProductionTypeManager::load_production_types_file(GoodManager const& good_m // pass 3: actually load production types production_types.reserve(production_types.size() + expected_types); ret &= expect_dictionary( - [this, &good_manager, &pop_manager, &template_target_map, &template_node_map](std::string_view key, ast::NodeCPtr node) -> bool { - if (template_node_map.contains(key)) + [this, &good_manager, &pop_manager, &template_target_map, &template_node_map]( + std::string_view key, ast::NodeCPtr node) -> bool { + if (template_node_map.contains(key)) { return true; + } EmployedPop owner; std::vector<EmployedPop> employees; @@ -260,8 +273,8 @@ bool ProductionTypeManager::load_production_types_file(GoodManager const& good_m ret &= PARSE_NODE(node); ret &= add_production_type( - key, owner, employees, type, workforce, std::move(input_goods), output_goods, value, - std::move(bonuses), std::move(efficiency), coastal, farm, mine, good_manager + key, owner, employees, type, workforce, std::move(input_goods), output_goods, value, std::move(bonuses), + std::move(efficiency), coastal, farm, mine, good_manager ); return ret; } @@ -270,4 +283,4 @@ bool ProductionTypeManager::load_production_types_file(GoodManager const& good_m production_types.lock(); return ret; -}
\ No newline at end of file +} diff --git a/src/openvic-simulation/economy/ProductionType.hpp b/src/openvic-simulation/economy/ProductionType.hpp index 2deb461..802580b 100644 --- a/src/openvic-simulation/economy/ProductionType.hpp +++ b/src/openvic-simulation/economy/ProductionType.hpp @@ -16,11 +16,7 @@ namespace OpenVic { struct EmployedPop { friend struct ProductionTypeManager; - enum struct effect_t { - INPUT, - OUTPUT, - THROUGHPUT - }; + enum struct effect_t { INPUT, OUTPUT, THROUGHPUT }; private: PopType const* pop_type; // poptype @@ -29,7 +25,9 @@ namespace OpenVic { fixed_point_t effect_multiplier; fixed_point_t amount; - EmployedPop(PopType const* pop_type, bool artisan, effect_t effect, fixed_point_t effect_multiplier, fixed_point_t amount); + EmployedPop( + PopType const* pop_type, bool artisan, effect_t effect, fixed_point_t effect_multiplier, fixed_point_t amount + ); public: EmployedPop() = default; @@ -52,11 +50,7 @@ namespace OpenVic { private: const EmployedPop owner; const std::vector<EmployedPop> employees; - const enum struct type_t { - FACTORY, - RGO, - ARTISAN - } type; + const enum struct type_t { FACTORY, RGO, ARTISAN } type; const Pop::pop_size_t workforce; const Good::good_map_t input_goods; @@ -96,10 +90,13 @@ namespace OpenVic { private: IdentifierRegistry<ProductionType> production_types; - NodeTools::node_callback_t _expect_employed_pop(GoodManager const& good_manager, PopManager const& pop_manager, - NodeTools::callback_t<EmployedPop&&> cb); - NodeTools::node_callback_t _expect_employed_pop_list(GoodManager const& good_manager, PopManager const& pop_manager, - NodeTools::callback_t<std::vector<EmployedPop>&&> cb); + NodeTools::node_callback_t _expect_employed_pop( + GoodManager const& good_manager, PopManager const& pop_manager, NodeTools::callback_t<EmployedPop&&> cb + ); + NodeTools::node_callback_t _expect_employed_pop_list( + GoodManager const& good_manager, PopManager const& pop_manager, + NodeTools::callback_t<std::vector<EmployedPop>&&> cb + ); public: ProductionTypeManager(); @@ -109,4 +106,4 @@ namespace OpenVic { bool load_production_types_file(GoodManager const& good_manager, PopManager const& pop_manager, ast::NodeCPtr root); }; -}
\ No newline at end of file +} |