diff options
Diffstat (limited to 'src/openvic-simulation/economy')
-rw-r--r-- | src/openvic-simulation/economy/ArtisanalProducer.cpp | 13 | ||||
-rw-r--r-- | src/openvic-simulation/economy/ArtisanalProducer.hpp | 12 | ||||
-rw-r--r-- | src/openvic-simulation/economy/BuildingInstance.cpp | 9 | ||||
-rw-r--r-- | src/openvic-simulation/economy/BuildingType.cpp | 53 | ||||
-rw-r--r-- | src/openvic-simulation/economy/BuildingType.hpp | 8 | ||||
-rw-r--r-- | src/openvic-simulation/economy/EconomyManager.hpp | 16 | ||||
-rw-r--r-- | src/openvic-simulation/economy/FactoryProducer.cpp | 55 | ||||
-rw-r--r-- | src/openvic-simulation/economy/FactoryProducer.hpp | 32 | ||||
-rw-r--r-- | src/openvic-simulation/economy/GoodDefinition.cpp (renamed from src/openvic-simulation/economy/Good.cpp) | 43 | ||||
-rw-r--r-- | src/openvic-simulation/economy/GoodDefinition.hpp (renamed from src/openvic-simulation/economy/Good.hpp) | 27 | ||||
-rw-r--r-- | src/openvic-simulation/economy/GoodInstance.cpp | 20 | ||||
-rw-r--r-- | src/openvic-simulation/economy/GoodInstance.hpp | 33 | ||||
-rw-r--r-- | src/openvic-simulation/economy/ProductionType.cpp | 72 | ||||
-rw-r--r-- | src/openvic-simulation/economy/ProductionType.hpp | 30 |
14 files changed, 273 insertions, 150 deletions
diff --git a/src/openvic-simulation/economy/ArtisanalProducer.cpp b/src/openvic-simulation/economy/ArtisanalProducer.cpp index 52cfa4f..d5cc3d3 100644 --- a/src/openvic-simulation/economy/ArtisanalProducer.cpp +++ b/src/openvic-simulation/economy/ArtisanalProducer.cpp @@ -3,8 +3,11 @@ using namespace OpenVic; ArtisanalProducer::ArtisanalProducer( - ProductionType const& new_production_type, Good::good_map_t&& new_stockpile, const fixed_point_t new_current_production, - Good::good_map_t&& new_current_needs -) - : production_type { new_production_type }, stockpile { std::move(new_stockpile) }, - current_production { new_current_production }, current_needs { std::move(new_current_needs) } {} + ProductionType const& new_production_type, + GoodDefinition::good_definition_map_t&& new_stockpile, + fixed_point_t new_current_production, + GoodDefinition::good_definition_map_t&& new_current_needs +) : production_type { new_production_type }, + stockpile { std::move(new_stockpile) }, + current_production { new_current_production }, + current_needs { std::move(new_current_needs) } {} diff --git a/src/openvic-simulation/economy/ArtisanalProducer.hpp b/src/openvic-simulation/economy/ArtisanalProducer.hpp index 36de2f2..ed5b231 100644 --- a/src/openvic-simulation/economy/ArtisanalProducer.hpp +++ b/src/openvic-simulation/economy/ArtisanalProducer.hpp @@ -1,6 +1,6 @@ #pragma once -#include "openvic-simulation/economy/Good.hpp" +#include "openvic-simulation/economy/GoodDefinition.hpp" #include "openvic-simulation/economy/ProductionType.hpp" #include "openvic-simulation/types/fixed_point/FixedPoint.hpp" #include "openvic-simulation/utility/Getters.hpp" @@ -9,14 +9,16 @@ namespace OpenVic { class ArtisanalProducer final { private: ProductionType const& PROPERTY(production_type); - Good::good_map_t PROPERTY(stockpile); + GoodDefinition::good_definition_map_t PROPERTY(stockpile); fixed_point_t PROPERTY(current_production); - Good::good_map_t PROPERTY(current_needs); + GoodDefinition::good_definition_map_t PROPERTY(current_needs); public: ArtisanalProducer( - ProductionType const& new_production_type, Good::good_map_t&& new_stockpile, - const fixed_point_t new_current_production, Good::good_map_t&& new_current_needs + ProductionType const& new_production_type, + GoodDefinition::good_definition_map_t&& new_stockpile, + fixed_point_t new_current_production, + GoodDefinition::good_definition_map_t&& new_current_needs ); }; } diff --git a/src/openvic-simulation/economy/BuildingInstance.cpp b/src/openvic-simulation/economy/BuildingInstance.cpp index f72c713..7616e09 100644 --- a/src/openvic-simulation/economy/BuildingInstance.cpp +++ b/src/openvic-simulation/economy/BuildingInstance.cpp @@ -3,8 +3,13 @@ using namespace OpenVic; BuildingInstance::BuildingInstance(BuildingType const& new_building_type, level_t new_level) - : HasIdentifier { new_building_type.get_identifier() }, building_type { new_building_type }, level { new_level }, - expansion_state { ExpansionState::CannotExpand }, start_date {}, end_date {}, expansion_progress { 0.0f } {} + : HasIdentifier { new_building_type }, + building_type { new_building_type }, + level { new_level }, + expansion_state { ExpansionState::CannotExpand }, + start_date {}, + end_date {}, + expansion_progress { 0.0f } {} bool BuildingInstance::_can_expand() const { return level < building_type.get_max_level(); diff --git a/src/openvic-simulation/economy/BuildingType.cpp b/src/openvic-simulation/economy/BuildingType.cpp index e7d358a..d096166 100644 --- a/src/openvic-simulation/economy/BuildingType.cpp +++ b/src/openvic-simulation/economy/BuildingType.cpp @@ -5,18 +5,33 @@ using namespace OpenVic::NodeTools; BuildingType::BuildingType( std::string_view identifier, building_type_args_t& building_type_args -) : HasIdentifier { identifier }, type { building_type_args.type }, modifier { std::move(building_type_args.modifier) }, - on_completion { building_type_args.on_completion }, completion_size { building_type_args.completion_size }, - max_level { building_type_args.max_level }, goods_cost { std::move(building_type_args.goods_cost) }, - cost { building_type_args.cost }, build_time { building_type_args.build_time }, on_map { building_type_args.on_map }, - default_enabled { building_type_args.default_enabled }, production_type { building_type_args.production_type }, - pop_build_factory { building_type_args.pop_build_factory }, strategic_factory { building_type_args.strategic_factory }, - advanced_factory { building_type_args.advanced_factory }, fort_level { building_type_args.fort_level }, - naval_capacity { building_type_args.naval_capacity }, colonial_points { std::move(building_type_args.colonial_points) }, - in_province { building_type_args.in_province }, one_per_state { building_type_args.one_per_state }, - colonial_range { building_type_args.colonial_range }, infrastructure { building_type_args.infrastructure }, - spawn_railway_track { building_type_args.spawn_railway_track }, sail { building_type_args.sail }, - steam { building_type_args.steam }, capital { building_type_args.capital }, port { building_type_args.port } {} +) : HasIdentifier { identifier }, + type { building_type_args.type }, + modifier { std::move(building_type_args.modifier) }, + on_completion { building_type_args.on_completion }, + completion_size { building_type_args.completion_size }, + max_level { building_type_args.max_level }, + goods_cost { std::move(building_type_args.goods_cost) }, + cost { building_type_args.cost }, + build_time { building_type_args.build_time }, + on_map { building_type_args.on_map }, + default_enabled { building_type_args.default_enabled }, + production_type { building_type_args.production_type }, + pop_build_factory { building_type_args.pop_build_factory }, + strategic_factory { building_type_args.strategic_factory }, + advanced_factory { building_type_args.advanced_factory }, + fort_level { building_type_args.fort_level }, + naval_capacity { building_type_args.naval_capacity }, + colonial_points { std::move(building_type_args.colonial_points) }, + in_province { building_type_args.in_province }, + one_per_state { building_type_args.one_per_state }, + colonial_range { building_type_args.colonial_range }, + infrastructure { building_type_args.infrastructure }, + spawn_railway_track { building_type_args.spawn_railway_track }, + sail { building_type_args.sail }, + steam { building_type_args.steam }, + capital { building_type_args.capital }, + port { building_type_args.port } {} BuildingTypeManager::BuildingTypeManager() : port_building_type { nullptr } {} @@ -38,12 +53,13 @@ bool BuildingTypeManager::add_building_type( } bool BuildingTypeManager::load_buildings_file( - GoodManager const& good_manager, ProductionTypeManager const& production_type_manager, ModifierManager& modifier_manager, - ast::NodeCPtr root + GoodDefinitionManager const& good_definition_manager, ProductionTypeManager const& production_type_manager, + ModifierManager& modifier_manager, ast::NodeCPtr root ) { bool ret = expect_dictionary_reserve_length( - building_types, - [this, &good_manager, &production_type_manager, &modifier_manager](std::string_view key, ast::NodeCPtr value) -> bool { + building_types, [this, &good_definition_manager, &production_type_manager, &modifier_manager]( + std::string_view key, ast::NodeCPtr value + ) -> bool { BuildingType::building_type_args_t building_type_args {}; bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(building_type_args.modifier), @@ -52,8 +68,9 @@ bool BuildingTypeManager::load_buildings_file( "completion_size", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(building_type_args.completion_size)), "max_level", ONE_EXACTLY, expect_uint(assign_variable_callback(building_type_args.max_level)), - "goods_cost", ONE_EXACTLY, - good_manager.expect_good_decimal_map(move_variable_callback(building_type_args.goods_cost)), + "goods_cost", ONE_EXACTLY, good_definition_manager.expect_good_definition_decimal_map( + move_variable_callback(building_type_args.goods_cost) + ), "cost", ZERO_OR_MORE, expect_fixed_point(assign_variable_callback(building_type_args.cost)), "time", ONE_EXACTLY, expect_days(assign_variable_callback(building_type_args.build_time)), "visibility", ONE_EXACTLY, expect_bool([key](bool visibility) -> bool { diff --git a/src/openvic-simulation/economy/BuildingType.hpp b/src/openvic-simulation/economy/BuildingType.hpp index 38b7c50..977d6ec 100644 --- a/src/openvic-simulation/economy/BuildingType.hpp +++ b/src/openvic-simulation/economy/BuildingType.hpp @@ -1,7 +1,7 @@ #pragma once #include "openvic-simulation/misc/Modifier.hpp" -#include "openvic-simulation/economy/Good.hpp" +#include "openvic-simulation/economy/GoodDefinition.hpp" #include "openvic-simulation/economy/ProductionType.hpp" #include "openvic-simulation/types/Date.hpp" #include "openvic-simulation/types/IdentifierRegistry.hpp" @@ -27,7 +27,7 @@ namespace OpenVic { ModifierValue modifier; fixed_point_t completion_size = 0, cost = 0, colonial_range = 0, infrastructure = 0; BuildingType::level_t max_level = 0, fort_level = 0; - Good::good_map_t goods_cost; + GoodDefinition::good_definition_map_t goods_cost; Timespan build_time; bool on_map = false, default_enabled = false, pop_build_factory = false, strategic_factory = false, advanced_factory = false, in_province = false, one_per_state = false, spawn_railway_track = false, @@ -46,7 +46,7 @@ namespace OpenVic { std::string PROPERTY(on_completion); // probably sound played on completion fixed_point_t PROPERTY(completion_size); level_t PROPERTY(max_level); - Good::good_map_t PROPERTY(goods_cost); + GoodDefinition::good_definition_map_t PROPERTY(goods_cost); fixed_point_t PROPERTY(cost); Timespan PROPERTY(build_time); // time bool PROPERTY(on_map); // onmap @@ -94,7 +94,7 @@ namespace OpenVic { bool add_building_type(std::string_view identifier, BuildingType::building_type_args_t& building_type_args); bool load_buildings_file( - GoodManager const& good_manager, ProductionTypeManager const& production_type_manager, + GoodDefinitionManager const& good_definition_manager, ProductionTypeManager const& production_type_manager, ModifierManager& modifier_manager, ast::NodeCPtr root ); }; diff --git a/src/openvic-simulation/economy/EconomyManager.hpp b/src/openvic-simulation/economy/EconomyManager.hpp index adeabd9..caac9c2 100644 --- a/src/openvic-simulation/economy/EconomyManager.hpp +++ b/src/openvic-simulation/economy/EconomyManager.hpp @@ -1,23 +1,31 @@ #pragma once #include "openvic-simulation/economy/BuildingType.hpp" -#include "openvic-simulation/economy/Good.hpp" +#include "openvic-simulation/economy/GoodDefinition.hpp" +#include "openvic-simulation/economy/GoodInstance.hpp" #include "openvic-simulation/economy/ProductionType.hpp" namespace OpenVic { struct EconomyManager { private: BuildingTypeManager PROPERTY_REF(building_type_manager); - GoodManager PROPERTY_REF(good_manager); + GoodDefinitionManager PROPERTY_REF(good_definition_manager); + GoodInstanceManager PROPERTY_REF(good_instance_manager); ProductionTypeManager PROPERTY_REF(production_type_manager); public: inline bool load_production_types_file(PopManager const& pop_manager, ast::NodeCPtr root) { - return production_type_manager.load_production_types_file(good_manager, pop_manager, root); + return production_type_manager.load_production_types_file(good_definition_manager, pop_manager, root); } inline bool load_buildings_file(ModifierManager& modifier_manager, ast::NodeCPtr root) { - return building_type_manager.load_buildings_file(good_manager, production_type_manager, modifier_manager, root); + return building_type_manager.load_buildings_file( + good_definition_manager, production_type_manager, modifier_manager, root + ); + } + + inline bool setup_good_instances() { + return good_instance_manager.setup_good_instances(good_definition_manager); } }; } diff --git a/src/openvic-simulation/economy/FactoryProducer.cpp b/src/openvic-simulation/economy/FactoryProducer.cpp index 81ebd4a..2ef9fa8 100644 --- a/src/openvic-simulation/economy/FactoryProducer.cpp +++ b/src/openvic-simulation/economy/FactoryProducer.cpp @@ -3,25 +3,44 @@ using namespace OpenVic; FactoryProducer::FactoryProducer( - ProductionType const& new_production_type, const fixed_point_t new_size_multiplier, - const fixed_point_t new_revenue_yesterday, const fixed_point_t new_output_quantity_yesterday, - const fixed_point_t new_unsold_quantity_yesterday, ordered_map<Pop*, Pop::pop_size_t>&& new_employees, - Good::good_map_t&& new_stockpile, fixed_point_t new_budget, const fixed_point_t new_balance_yesterday, - const fixed_point_t new_received_investments_yesterday, const fixed_point_t new_market_spendings_yesterday, - const fixed_point_t new_paychecks_yesterday, const uint32_t new_unprofitable_days, const uint32_t new_subsidised_days, - const uint32_t new_days_without_input, const uint8_t new_hiring_priority, const uint8_t new_profit_history_current, + ProductionType const& new_production_type, + fixed_point_t new_size_multiplier, + fixed_point_t new_revenue_yesterday, + fixed_point_t new_output_quantity_yesterday, + fixed_point_t new_unsold_quantity_yesterday, + ordered_map<Pop*, Pop::pop_size_t>&& new_employees, + GoodDefinition::good_definition_map_t&& new_stockpile, + fixed_point_t new_budget, + fixed_point_t new_balance_yesterday, + fixed_point_t new_received_investments_yesterday, + fixed_point_t new_market_spendings_yesterday, + fixed_point_t new_paychecks_yesterday, + uint32_t new_unprofitable_days, + uint32_t new_subsidised_days, + uint32_t new_days_without_input, + uint8_t new_hiring_priority, + uint8_t new_profit_history_current, daily_profit_history_t&& new_daily_profit_history -) - : production_type { new_production_type }, size_multiplier { new_size_multiplier }, - revenue_yesterday { new_revenue_yesterday }, output_quantity_yesterday { new_output_quantity_yesterday }, - unsold_quantity_yesterday { new_unsold_quantity_yesterday }, employees { std::move(new_employees) }, - stockpile { std::move(new_stockpile) }, budget { new_budget }, balance_yesterday { new_balance_yesterday }, - received_investments_yesterday { new_received_investments_yesterday }, - market_spendings_yesterday { new_market_spendings_yesterday }, paychecks_yesterday { new_paychecks_yesterday }, - unprofitable_days { new_unprofitable_days }, subsidised_days { new_subsidised_days }, - days_without_input { new_days_without_input }, hiring_priority { new_hiring_priority }, - profit_history_current { new_profit_history_current }, daily_profit_history { std::move(new_daily_profit_history) } {} -FactoryProducer::FactoryProducer(ProductionType const& new_production_type, const fixed_point_t new_size_multiplier) +) : production_type { new_production_type }, + size_multiplier { new_size_multiplier }, + revenue_yesterday { new_revenue_yesterday }, + output_quantity_yesterday { new_output_quantity_yesterday }, + unsold_quantity_yesterday { new_unsold_quantity_yesterday }, + employees { std::move(new_employees) }, + stockpile { std::move(new_stockpile) }, + budget { new_budget }, + balance_yesterday { new_balance_yesterday }, + received_investments_yesterday { new_received_investments_yesterday }, + market_spendings_yesterday { new_market_spendings_yesterday }, + paychecks_yesterday { new_paychecks_yesterday }, + unprofitable_days { new_unprofitable_days }, + subsidised_days { new_subsidised_days }, + days_without_input { new_days_without_input }, + hiring_priority { new_hiring_priority }, + profit_history_current { new_profit_history_current }, + daily_profit_history { std::move(new_daily_profit_history) } {} + +FactoryProducer::FactoryProducer(ProductionType const& new_production_type, fixed_point_t new_size_multiplier) : FactoryProducer { new_production_type, new_size_multiplier, 0, 0, 0, {}, {}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {} } {} fixed_point_t FactoryProducer::get_profitability_yesterday() const { diff --git a/src/openvic-simulation/economy/FactoryProducer.hpp b/src/openvic-simulation/economy/FactoryProducer.hpp index 623ec48..ee658a5 100644 --- a/src/openvic-simulation/economy/FactoryProducer.hpp +++ b/src/openvic-simulation/economy/FactoryProducer.hpp @@ -2,7 +2,7 @@ #include <cstdint> -#include "openvic-simulation/economy/Good.hpp" +#include "openvic-simulation/economy/GoodDefinition.hpp" #include "openvic-simulation/economy/ProductionType.hpp" #include "openvic-simulation/types/fixed_point/FixedPoint.hpp" #include "openvic-simulation/utility/Getters.hpp" @@ -21,7 +21,7 @@ namespace OpenVic { fixed_point_t PROPERTY(unsold_quantity_yesterday); fixed_point_t PROPERTY(size_multiplier); ordered_map<Pop*, Pop::pop_size_t> PROPERTY(employees); - Good::good_map_t PROPERTY(stockpile); + GoodDefinition::good_definition_map_t PROPERTY(stockpile); fixed_point_t PROPERTY(budget); fixed_point_t PROPERTY(balance_yesterday); fixed_point_t PROPERTY(received_investments_yesterday); @@ -34,16 +34,26 @@ namespace OpenVic { public: FactoryProducer( - ProductionType const& new_production_type, const fixed_point_t new_size_multiplier, - const fixed_point_t new_revenue_yesterday, const fixed_point_t new_output_quantity_yesterday, - const fixed_point_t new_unsold_quantity_yesterday, ordered_map<Pop*, Pop::pop_size_t>&& new_employees, - Good::good_map_t&& new_stockpile, fixed_point_t new_budget, const fixed_point_t new_balance_yesterday, - const fixed_point_t new_received_investments_yesterday, const fixed_point_t new_market_spendings_yesterday, - const fixed_point_t new_paychecks_yesterday, const uint32_t new_unprofitable_days, - const uint32_t new_subsidised_days, const uint32_t new_days_without_input, const uint8_t new_hiring_priority, - const uint8_t new_profit_history_current, daily_profit_history_t&& new_daily_profit_history + ProductionType const& new_production_type, + fixed_point_t new_size_multiplier, + fixed_point_t new_revenue_yesterday, + fixed_point_t new_output_quantity_yesterday, + fixed_point_t new_unsold_quantity_yesterday, + ordered_map<Pop*, Pop::pop_size_t>&& new_employees, + GoodDefinition::good_definition_map_t&& new_stockpile, + fixed_point_t new_budget, + fixed_point_t new_balance_yesterday, + fixed_point_t new_received_investments_yesterday, + fixed_point_t new_market_spendings_yesterday, + fixed_point_t new_paychecks_yesterday, + uint32_t new_unprofitable_days, + uint32_t new_subsidised_days, + uint32_t new_days_without_input, + uint8_t new_hiring_priority, + uint8_t new_profit_history_current, + daily_profit_history_t&& new_daily_profit_history ); - FactoryProducer(ProductionType const& new_production_type, const fixed_point_t new_size_multiplier); + FactoryProducer(ProductionType const& new_production_type, fixed_point_t new_size_multiplier); fixed_point_t get_profitability_yesterday() const; fixed_point_t get_average_profitability_last_seven_days() const; diff --git a/src/openvic-simulation/economy/Good.cpp b/src/openvic-simulation/economy/GoodDefinition.cpp index 961a82d..5a3d632 100644 --- a/src/openvic-simulation/economy/Good.cpp +++ b/src/openvic-simulation/economy/GoodDefinition.cpp @@ -1,4 +1,4 @@ -#include "Good.hpp" +#include "GoodDefinition.hpp" #include <cassert> @@ -7,7 +7,7 @@ using namespace OpenVic::NodeTools; GoodCategory::GoodCategory(std::string_view new_identifier) : HasIdentifier { new_identifier } {} -Good::Good( +GoodDefinition::GoodDefinition( std::string_view new_identifier, colour_t new_colour, index_t new_index, 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, false }, index { new_index }, category { new_category }, @@ -16,12 +16,7 @@ Good::Good( assert(base_price > NULL_PRICE); } -void Good::reset_to_defaults() { - available = available_from_start; - price = base_price; -} - -bool GoodManager::add_good_category(std::string_view identifier) { +bool GoodDefinitionManager::add_good_category(std::string_view identifier) { if (identifier.empty()) { Logger::error("Invalid good category identifier - empty!"); return false; @@ -29,31 +24,25 @@ 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 GoodDefinitionManager::add_good_definition( + std::string_view identifier, colour_t colour, GoodCategory const& category, GoodDefinition::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; } - if (base_price <= Good::NULL_PRICE) { + if (base_price <= GoodDefinition::NULL_PRICE) { Logger::error("Invalid base price for ", identifier, ": ", base_price); return false; } - return goods.add_item({ - identifier, colour, get_good_count(), category, base_price, available_from_start, + return good_definitions.add_item({ + identifier, colour, get_good_definition_count(), category, base_price, available_from_start, tradeable, money, overseas_penalty }); } -void GoodManager::reset_to_defaults() { - for (Good& good : goods.get_items()) { - good.reset_to_defaults(); - } -} - -bool GoodManager::load_goods_file(ast::NodeCPtr root) { +bool GoodDefinitionManager::load_goods_file(ast::NodeCPtr root) { size_t total_expected_goods = 0; bool ret = expect_dictionary_reserve_length( good_categories, @@ -64,11 +53,11 @@ bool GoodManager::load_goods_file(ast::NodeCPtr root) { } )(root); lock_good_categories(); - reserve_more_goods(total_expected_goods); + reserve_more_good_definitions(total_expected_goods); ret &= expect_good_category_dictionary([this](GoodCategory const& good_category, ast::NodeCPtr good_category_value) -> bool { return expect_dictionary([this, &good_category](std::string_view key, ast::NodeCPtr value) -> bool { colour_t colour = colour_t::null(); - Good::price_t base_price; + GoodDefinition::price_t base_price; bool available_from_start = true, tradeable = true; bool money = false, overseas_penalty = false; @@ -80,22 +69,22 @@ bool GoodManager::load_goods_file(ast::NodeCPtr root) { "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( + ret &= add_good_definition( key, colour, good_category, base_price, available_from_start, tradeable, money, overseas_penalty ); return ret; })(good_category_value); })(root); - lock_goods(); + lock_good_definitions(); return ret; } -bool GoodManager::generate_modifiers(ModifierManager& modifier_manager) const { +bool GoodDefinitionManager::generate_modifiers(ModifierManager& modifier_manager) const { bool ret = true; const auto good_modifier = [this, &modifier_manager, &ret](std::string_view name, bool is_positive_good) -> void { ret &= modifier_manager.register_complex_modifier(name); - for (Good const& good : get_goods()) { + for (GoodDefinition const& good : get_good_definitions()) { ret &= modifier_manager.add_modifier_effect( ModifierManager::get_flat_identifier(name, good.get_identifier()), is_positive_good ); @@ -112,7 +101,7 @@ bool GoodManager::generate_modifiers(ModifierManager& modifier_manager) const { good_modifier("rgo_goods_throughput", true); good_modifier("rgo_size", true); - for (Good const& good : get_goods()) { + for (GoodDefinition const& good : get_good_definitions()) { ret &= modifier_manager.add_modifier_effect(good.get_identifier(), true, ModifierEffect::format_t::PERCENTAGE_DECIMAL); } diff --git a/src/openvic-simulation/economy/Good.hpp b/src/openvic-simulation/economy/GoodDefinition.hpp index d9d4251..0a3ad5c 100644 --- a/src/openvic-simulation/economy/Good.hpp +++ b/src/openvic-simulation/economy/GoodDefinition.hpp @@ -4,10 +4,10 @@ #include "openvic-simulation/types/IdentifierRegistry.hpp" namespace OpenVic { - struct GoodManager; + struct GoodDefinitionManager; struct GoodCategory : HasIdentifier { - friend struct GoodManager; + friend struct GoodDefinitionManager; private: GoodCategory(std::string_view new_identifier); @@ -28,15 +28,15 @@ namespace OpenVic { * ECON-238, ECON-239, ECON-240, ECON-241, ECON-242, ECON-243, ECON-244, ECON-245, ECON-246, ECON-247, ECON-248, ECON-249, * ECON-250, ECON-251, ECON-252, ECON-253, ECON-254, ECON-255, ECON-256, ECON-257, ECON-258, ECON-259, ECON-260, ECON-261 */ - struct Good : HasIdentifierAndColour { - friend struct GoodManager; + struct GoodDefinition : HasIdentifierAndColour { + friend struct GoodDefinitionManager; using index_t = size_t; using price_t = fixed_point_t; static constexpr price_t NULL_PRICE = fixed_point_t::_0(); - using good_map_t = fixed_point_map_t<Good const*>; + using good_definition_map_t = fixed_point_map_t<GoodDefinition const*>; private: const index_t PROPERTY(index); @@ -47,34 +47,29 @@ namespace OpenVic { const bool PROPERTY(money); const bool PROPERTY(overseas_penalty); - price_t PROPERTY_RW(price); - bool PROPERTY_RW(available); - - Good( + GoodDefinition( std::string_view new_identifier, colour_t new_colour, index_t new_index, 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; - void reset_to_defaults(); + GoodDefinition(GoodDefinition&&) = default; }; - struct GoodManager { + struct GoodDefinitionManager { private: IdentifierRegistry<GoodCategory> IDENTIFIER_REGISTRY_CUSTOM_PLURAL(good_category, good_categories); - IdentifierRegistry<Good> IDENTIFIER_REGISTRY(good); + IdentifierRegistry<GoodDefinition> IDENTIFIER_REGISTRY(good_definition); public: bool add_good_category(std::string_view identifier); - bool add_good( - std::string_view identifier, colour_t colour, GoodCategory const& category, Good::price_t base_price, + bool add_good_definition( + std::string_view identifier, colour_t colour, GoodCategory const& category, GoodDefinition::price_t base_price, bool available_from_start, bool tradeable, bool money, bool overseas_penalty ); - void reset_to_defaults(); bool load_goods_file(ast::NodeCPtr root); bool generate_modifiers(ModifierManager& modifier_manager) const; }; diff --git a/src/openvic-simulation/economy/GoodInstance.cpp b/src/openvic-simulation/economy/GoodInstance.cpp new file mode 100644 index 0000000..937706d --- /dev/null +++ b/src/openvic-simulation/economy/GoodInstance.cpp @@ -0,0 +1,20 @@ +#include "GoodInstance.hpp" + +using namespace OpenVic; + +GoodInstance::GoodInstance(GoodDefinition const& new_good_definition) + : HasIdentifierAndColour { new_good_definition }, good_definition { new_good_definition }, + price { new_good_definition.get_base_price() }, available { new_good_definition.is_available_from_start() } {} + +bool GoodInstanceManager::setup_good_instances(GoodDefinitionManager const& good_definition_manager) { + good_instances.reset(); + good_instances.reserve(good_definition_manager.get_good_definition_count()); + + bool ret = true; + + for (GoodDefinition const& good : good_definition_manager.get_good_definitions()) { + ret &= good_instances.add_item({ good }); + } + + return ret; +} diff --git a/src/openvic-simulation/economy/GoodInstance.hpp b/src/openvic-simulation/economy/GoodInstance.hpp new file mode 100644 index 0000000..3c27209 --- /dev/null +++ b/src/openvic-simulation/economy/GoodInstance.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include "openvic-simulation/economy/GoodDefinition.hpp" +#include "openvic-simulation/types/HasIdentifier.hpp" +#include "openvic-simulation/types/IdentifierRegistry.hpp" +#include "openvic-simulation/utility/Getters.hpp" + +namespace OpenVic { + struct GoodInstanceManager; + + struct GoodInstance : HasIdentifierAndColour { + friend struct GoodInstanceManager; + + private: + GoodDefinition const& PROPERTY(good_definition); + GoodDefinition::price_t PROPERTY(price); + bool PROPERTY(available); + // TODO - supply, demand, actual bought + + GoodInstance(GoodDefinition const& new_good_definition); + + public: + GoodInstance(GoodInstance&&) = default; + }; + + struct GoodInstanceManager { + private: + IdentifierRegistry<GoodInstance> IDENTIFIER_REGISTRY(good_instance); + + public: + bool setup_good_instances(GoodDefinitionManager const& good_definition_manager); + }; +} diff --git a/src/openvic-simulation/economy/ProductionType.cpp b/src/openvic-simulation/economy/ProductionType.cpp index 7029fd1..4f87ba5 100644 --- a/src/openvic-simulation/economy/ProductionType.cpp +++ b/src/openvic-simulation/economy/ProductionType.cpp @@ -4,9 +4,13 @@ using namespace OpenVic; using namespace OpenVic::NodeTools; Job::Job( - PopType const* new_pop_type, effect_t new_effect_type, fixed_point_t new_effect_multiplier, + PopType const* new_pop_type, + effect_t new_effect_type, + fixed_point_t new_effect_multiplier, fixed_point_t new_desired_workforce_share -) : pop_type { new_pop_type }, effect_type { new_effect_type }, effect_multiplier { new_effect_multiplier }, +) : pop_type { new_pop_type }, + effect_type { new_effect_type }, + effect_multiplier { new_effect_multiplier }, desired_workforce_share { new_desired_workforce_share } {} ProductionType::ProductionType( @@ -15,18 +19,26 @@ ProductionType::ProductionType( std::vector<Job>&& new_jobs, template_type_t new_template_type, Pop::pop_size_t new_base_workforce_size, - Good::good_map_t&& new_input_goods, - Good const* new_output_goods, + GoodDefinition::good_definition_map_t&& new_input_goods, + GoodDefinition const* new_output_goods, fixed_point_t new_base_output_quantity, std::vector<bonus_t>&& new_bonuses, - Good::good_map_t&& new_maintenance_requirements, + GoodDefinition::good_definition_map_t&& new_maintenance_requirements, bool new_is_coastal, bool new_is_farm, bool new_is_mine -) : HasIdentifier { new_identifier }, owner { new_owner }, jobs { std::move(new_jobs) }, template_type { new_template_type }, - base_workforce_size { new_base_workforce_size }, input_goods { std::move(new_input_goods) }, - output_goods { new_output_goods }, base_output_quantity { new_base_output_quantity }, bonuses { std::move(new_bonuses) }, - maintenance_requirements { std::move(new_maintenance_requirements) }, coastal { new_is_coastal }, farm { new_is_farm }, +) : HasIdentifier { new_identifier }, + owner { new_owner }, + jobs { std::move(new_jobs) }, + template_type { new_template_type }, + base_workforce_size { new_base_workforce_size }, + input_goods { std::move(new_input_goods) }, + output_goods { new_output_goods }, + base_output_quantity { new_base_output_quantity }, + bonuses { std::move(new_bonuses) }, + maintenance_requirements { std::move(new_maintenance_requirements) }, + coastal { new_is_coastal }, + farm { new_is_farm }, mine { new_is_mine } {} bool ProductionType::parse_scripts(GameManager const& game_manager) { @@ -40,9 +52,9 @@ bool ProductionType::parse_scripts(GameManager const& game_manager) { ProductionTypeManager::ProductionTypeManager() : rgo_owner_sprite { 0 } {} node_callback_t ProductionTypeManager::_expect_job( - GoodManager const& good_manager, PopManager const& pop_manager, callback_t<Job&&> callback + GoodDefinitionManager const& good_definition_manager, PopManager const& pop_manager, callback_t<Job&&> callback ) { - return [this, &good_manager, &pop_manager, callback](ast::NodeCPtr node) -> bool { + return [this, &good_definition_manager, &pop_manager, callback](ast::NodeCPtr node) -> bool { using enum Job::effect_t; std::string_view pop_type {}; @@ -66,11 +78,12 @@ node_callback_t ProductionTypeManager::_expect_job( } node_callback_t ProductionTypeManager::_expect_job_list( - GoodManager const& good_manager, PopManager const& pop_manager, callback_t<std::vector<Job>&&> callback + GoodDefinitionManager const& good_definition_manager, PopManager const& pop_manager, + callback_t<std::vector<Job>&&> callback ) { - return [this, &good_manager, &pop_manager, callback](ast::NodeCPtr node) -> bool { + return [this, &good_definition_manager, &pop_manager, callback](ast::NodeCPtr node) -> bool { std::vector<Job> jobs; - bool ret = expect_list(_expect_job(good_manager, pop_manager, vector_callback(jobs)))(node); + bool ret = expect_list(_expect_job(good_definition_manager, pop_manager, vector_callback(jobs)))(node); ret &= callback(std::move(jobs)); return ret; }; @@ -82,11 +95,11 @@ bool ProductionTypeManager::add_production_type( std::vector<Job>&& jobs, ProductionType::template_type_t template_type, Pop::pop_size_t base_workforce_size, - Good::good_map_t&& input_goods, - Good const* output_goods, + GoodDefinition::good_definition_map_t&& input_goods, + GoodDefinition const* output_goods, fixed_point_t base_output_quantity, std::vector<ProductionType::bonus_t>&& bonuses, - Good::good_map_t&& maintenance_requirements, + GoodDefinition::good_definition_map_t&& maintenance_requirements, bool is_coastal, bool is_farm, bool is_mine @@ -163,7 +176,7 @@ bool ProductionTypeManager::add_production_type( } bool ProductionTypeManager::load_production_types_file( - GoodManager const& good_manager, PopManager const& pop_manager, ast::NodeCPtr root + GoodDefinitionManager const& good_definition_manager, PopManager const& pop_manager, ast::NodeCPtr root ) { size_t expected_types = 0; @@ -206,7 +219,7 @@ bool ProductionTypeManager::load_production_types_file( /* Pass #3: actually load production types */ reserve_more_production_types(expected_types); ret &= expect_dictionary( - [this, &good_manager, &pop_manager, &template_target_map, &template_node_map]( + [this, &good_definition_manager, &pop_manager, &template_target_map, &template_node_map]( std::string_view key, ast::NodeCPtr node) -> bool { using enum ProductionType::template_type_t; @@ -217,9 +230,9 @@ bool ProductionTypeManager::load_production_types_file( std::optional<Job> owner; std::vector<Job> jobs; ProductionType::template_type_t template_type { FACTORY }; - Good const* output_goods = nullptr; + GoodDefinition const* output_goods = nullptr; Pop::pop_size_t base_workforce_size = 0; - Good::good_map_t input_goods, maintenance_requirements; + GoodDefinition::good_definition_map_t input_goods, maintenance_requirements; fixed_point_t base_output_quantity = 0; std::vector<ProductionType::bonus_t> bonuses; bool is_coastal = false, is_farm = false, is_mine = false; @@ -242,14 +255,19 @@ bool ProductionTypeManager::load_production_types_file( bonuses.emplace_back(std::move(trigger), bonus_value); return ret; }, - "owner", ZERO_OR_ONE, _expect_job(good_manager, pop_manager, move_variable_callback(owner)), - "employees", ZERO_OR_ONE, _expect_job_list(good_manager, pop_manager, move_variable_callback(jobs)), - "type", ZERO_OR_ONE, expect_identifier(expect_mapped_string(template_type_map, assign_variable_callback(template_type))), + "owner", ZERO_OR_ONE, _expect_job(good_definition_manager, pop_manager, move_variable_callback(owner)), + "employees", ZERO_OR_ONE, _expect_job_list(good_definition_manager, pop_manager, move_variable_callback(jobs)), + "type", ZERO_OR_ONE, + expect_identifier(expect_mapped_string(template_type_map, assign_variable_callback(template_type))), "workforce", ZERO_OR_ONE, expect_uint(assign_variable_callback(base_workforce_size)), - "input_goods", ZERO_OR_ONE, good_manager.expect_good_decimal_map(move_variable_callback(input_goods)), - "output_goods", ZERO_OR_ONE, good_manager.expect_good_identifier(assign_variable_callback_pointer(output_goods)), + "input_goods", ZERO_OR_ONE, + good_definition_manager.expect_good_definition_decimal_map(move_variable_callback(input_goods)), + "output_goods", ZERO_OR_ONE, + good_definition_manager.expect_good_definition_identifier(assign_variable_callback_pointer(output_goods)), "value", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(base_output_quantity)), - "efficiency", ZERO_OR_ONE, good_manager.expect_good_decimal_map(move_variable_callback(maintenance_requirements)), + "efficiency", ZERO_OR_ONE, good_definition_manager.expect_good_definition_decimal_map( + move_variable_callback(maintenance_requirements) + ), "is_coastal", ZERO_OR_ONE, expect_bool(assign_variable_callback(is_coastal)), "farm", ZERO_OR_ONE, expect_bool(assign_variable_callback(is_farm)), "mine", ZERO_OR_ONE, expect_bool(assign_variable_callback(is_mine)) diff --git a/src/openvic-simulation/economy/ProductionType.hpp b/src/openvic-simulation/economy/ProductionType.hpp index 3c0bf3f..7480206 100644 --- a/src/openvic-simulation/economy/ProductionType.hpp +++ b/src/openvic-simulation/economy/ProductionType.hpp @@ -1,6 +1,6 @@ #pragma once -#include "openvic-simulation/economy/Good.hpp" +#include "openvic-simulation/economy/GoodDefinition.hpp" #include "openvic-simulation/pop/Pop.hpp" #include "openvic-simulation/scripts/ConditionScript.hpp" #include "openvic-simulation/types/IdentifierRegistry.hpp" @@ -44,12 +44,12 @@ namespace OpenVic { const template_type_t PROPERTY(template_type); const Pop::pop_size_t PROPERTY(base_workforce_size); - Good::good_map_t PROPERTY(input_goods); - Good const* PROPERTY(output_goods); + GoodDefinition::good_definition_map_t PROPERTY(input_goods); + GoodDefinition const* PROPERTY(output_goods); const fixed_point_t PROPERTY(base_output_quantity); std::vector<bonus_t> PROPERTY(bonuses); - Good::good_map_t PROPERTY(maintenance_requirements); + GoodDefinition::good_definition_map_t PROPERTY(maintenance_requirements); const bool PROPERTY_CUSTOM_PREFIX(coastal, is); const bool PROPERTY_CUSTOM_PREFIX(farm, is); @@ -61,11 +61,11 @@ namespace OpenVic { std::vector<Job>&& new_jobs, template_type_t new_template_type, Pop::pop_size_t new_base_workforce_size, - Good::good_map_t&& new_input_goods, - Good const* new_output_goods, + GoodDefinition::good_definition_map_t&& new_input_goods, + GoodDefinition const* new_output_goods, fixed_point_t new_base_output_quantity, std::vector<bonus_t>&& new_bonuses, - Good::good_map_t&& new_maintenance_requirements, + GoodDefinition::good_definition_map_t&& new_maintenance_requirements, bool new_is_coastal, bool new_is_farm, bool new_is_mine @@ -83,10 +83,12 @@ namespace OpenVic { PopType::sprite_t PROPERTY(rgo_owner_sprite); NodeTools::node_callback_t _expect_job( - GoodManager const& good_manager, PopManager const& pop_manager, NodeTools::callback_t<Job&&> callback + GoodDefinitionManager const& good_definition_manager, PopManager const& pop_manager, + NodeTools::callback_t<Job&&> callback ); NodeTools::node_callback_t _expect_job_list( - GoodManager const& good_manager, PopManager const& pop_manager, NodeTools::callback_t<std::vector<Job>&&> callback + GoodDefinitionManager const& good_definition_manager, PopManager const& pop_manager, + NodeTools::callback_t<std::vector<Job>&&> callback ); public: @@ -98,17 +100,19 @@ namespace OpenVic { std::vector<Job>&& employees, ProductionType::template_type_t template_type, Pop::pop_size_t workforce, - Good::good_map_t&& input_goods, - Good const* output_goods, + GoodDefinition::good_definition_map_t&& input_goods, + GoodDefinition const* output_goods, fixed_point_t value, std::vector<ProductionType::bonus_t>&& bonuses, - Good::good_map_t&& maintenance_requirements, + GoodDefinition::good_definition_map_t&& maintenance_requirements, bool coastal, bool farm, bool mine ); - bool load_production_types_file(GoodManager const& good_manager, PopManager const& pop_manager, ast::NodeCPtr root); + bool load_production_types_file( + GoodDefinitionManager const& good_definition_manager, PopManager const& pop_manager, ast::NodeCPtr root + ); bool parse_scripts(GameManager const& game_manager); }; |