diff options
Diffstat (limited to 'src/openvic-simulation/economy')
-rw-r--r-- | src/openvic-simulation/economy/EconomyManager.hpp | 10 | ||||
-rw-r--r-- | src/openvic-simulation/economy/Good.cpp | 25 | ||||
-rw-r--r-- | src/openvic-simulation/economy/Good.hpp | 14 | ||||
-rw-r--r-- | src/openvic-simulation/economy/ProductionType.cpp | 9 | ||||
-rw-r--r-- | src/openvic-simulation/economy/ProductionType.hpp | 7 |
5 files changed, 45 insertions, 20 deletions
diff --git a/src/openvic-simulation/economy/EconomyManager.hpp b/src/openvic-simulation/economy/EconomyManager.hpp index d53aa7e..fcde094 100644 --- a/src/openvic-simulation/economy/EconomyManager.hpp +++ b/src/openvic-simulation/economy/EconomyManager.hpp @@ -7,15 +7,11 @@ namespace OpenVic { struct EconomyManager { private: - BuildingManager building_manager; - GoodManager good_manager; - ProductionTypeManager production_type_manager; + BuildingManager PROPERTY_REF(building_manager); + GoodManager PROPERTY_REF(good_manager); + ProductionTypeManager PROPERTY_REF(production_type_manager); public: - REF_GETTERS(building_manager) - REF_GETTERS(good_manager) - REF_GETTERS(production_type_manager) - 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); } diff --git a/src/openvic-simulation/economy/Good.cpp b/src/openvic-simulation/economy/Good.cpp index b068644..2aa5d42 100644 --- a/src/openvic-simulation/economy/Good.cpp +++ b/src/openvic-simulation/economy/Good.cpp @@ -8,9 +8,9 @@ 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, false, false }, category { new_category }, + 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, false }, index { new_index }, 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); @@ -48,7 +48,7 @@ bool GoodManager::add_good( return false; } return goods.add_item({ - identifier, colour, category, base_price, available_from_start, + identifier, colour, get_good_count(), category, base_price, available_from_start, tradeable, money, overseas_penalty }); } @@ -95,3 +95,20 @@ bool GoodManager::load_goods_file(ast::NodeCPtr root) { lock_goods(); return ret; } + +#define GOOD_MODIFIER(name) \ + modifier_manager.register_complex_modifier(name); \ + for (Good const& good : this->get_goods()) { \ + std::string modifier_name = name; \ + modifier_name += "_"; \ + modifier_name += good.get_identifier(); \ + ret &= modifier_manager.add_modifier_effect(modifier_name, true, ModifierEffect::format_t::PROPORTION_DECIMAL); \ + } + +bool GoodManager::generate_modifiers(ModifierManager& modifier_manager) { + bool ret = true; + GOOD_MODIFIER("factory_goods_output"); + GOOD_MODIFIER("rgo_goods_output"); + GOOD_MODIFIER("rgo_size"); + return ret; +}
\ No newline at end of file diff --git a/src/openvic-simulation/economy/Good.hpp b/src/openvic-simulation/economy/Good.hpp index ac85cbd..1537514 100644 --- a/src/openvic-simulation/economy/Good.hpp +++ b/src/openvic-simulation/economy/Good.hpp @@ -1,5 +1,6 @@ #pragma once +#include "openvic-simulation/misc/Modifier.hpp" #include "openvic-simulation/types/IdentifierRegistry.hpp" namespace OpenVic { @@ -30,16 +31,19 @@ namespace OpenVic { struct Good : HasIdentifierAndColour { friend struct GoodManager; + 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*>; private: + const index_t PROPERTY(index); GoodCategory const& PROPERTY(category); const price_t PROPERTY(base_price); - const bool PROPERTY_CUSTOM_NAME(available_from_start, is_available_from_start); - const bool PROPERTY_CUSTOM_NAME(tradeable, is_tradeable); + const bool PROPERTY_CUSTOM_PREFIX(available_from_start, is); + const bool PROPERTY_CUSTOM_PREFIX(tradeable, is); const bool PROPERTY(money); const bool PROPERTY(overseas_penalty); @@ -47,8 +51,9 @@ namespace OpenVic { bool PROPERTY_RW(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 + 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: @@ -75,5 +80,6 @@ namespace OpenVic { void reset_to_defaults(); bool load_goods_file(ast::NodeCPtr root); + bool generate_modifiers(ModifierManager& modifier_manager); }; } diff --git a/src/openvic-simulation/economy/ProductionType.cpp b/src/openvic-simulation/economy/ProductionType.cpp index 6bd3858..a862b12 100644 --- a/src/openvic-simulation/economy/ProductionType.cpp +++ b/src/openvic-simulation/economy/ProductionType.cpp @@ -14,7 +14,7 @@ ProductionType::ProductionType( 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 } {} -ProductionTypeManager::ProductionTypeManager() : production_types { "production types" } {} +ProductionTypeManager::ProductionTypeManager() : production_types { "production types" }, rgo_owner_sprite { 0 } {} node_callback_t ProductionTypeManager::_expect_employed_pop( GoodManager const& good_manager, PopManager const& pop_manager, callback_t<EmployedPop&&> cb @@ -102,10 +102,15 @@ bool ProductionTypeManager::add_production_type(PRODUCTION_TYPE_ARGS) { return false; } - return production_types.add_item({ + const bool ret = production_types.add_item({ identifier, owner, employees, type, workforce, std::move(input_goods), output_goods, value, std::move(bonuses), std::move(efficiency), coastal, farm, mine }); + if (rgo_owner_sprite <= 0 && ret && type == ProductionType::type_t::RGO && owner.get_pop_type() != nullptr) { + /* Set rgo owner sprite to that of the first RGO owner we find. */ + rgo_owner_sprite = owner.get_pop_type()->get_sprite(); + } + return ret; } #define PARSE_NODE \ diff --git a/src/openvic-simulation/economy/ProductionType.hpp b/src/openvic-simulation/economy/ProductionType.hpp index b03f16b..bce3698 100644 --- a/src/openvic-simulation/economy/ProductionType.hpp +++ b/src/openvic-simulation/economy/ProductionType.hpp @@ -53,10 +53,10 @@ namespace OpenVic { const std::vector<Bonus> PROPERTY(bonuses); const Good::good_map_t PROPERTY(efficiency); - const bool PROPERTY_CUSTOM_NAME(coastal, is_coastal); // is_coastal + const bool PROPERTY_CUSTOM_PREFIX(coastal, is); // is_coastal - const bool PROPERTY_CUSTOM_NAME(farm, is_farm); - const bool PROPERTY_CUSTOM_NAME(mine, is_mine); + const bool PROPERTY_CUSTOM_PREFIX(farm, is); + const bool PROPERTY_CUSTOM_PREFIX(mine, is); ProductionType(PRODUCTION_TYPE_ARGS); @@ -67,6 +67,7 @@ namespace OpenVic { struct ProductionTypeManager { private: IdentifierRegistry<ProductionType> production_types; + PopType::sprite_t PROPERTY(rgo_owner_sprite); NodeTools::node_callback_t _expect_employed_pop( GoodManager const& good_manager, PopManager const& pop_manager, NodeTools::callback_t<EmployedPop&&> cb |