aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/economy
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/economy')
-rw-r--r--src/openvic-simulation/economy/Building.cpp57
-rw-r--r--src/openvic-simulation/economy/Building.hpp4
-rw-r--r--src/openvic-simulation/economy/Good.cpp9
-rw-r--r--src/openvic-simulation/economy/ProductionType.cpp12
-rw-r--r--src/openvic-simulation/economy/ProductionType.hpp8
5 files changed, 53 insertions, 37 deletions
diff --git a/src/openvic-simulation/economy/Building.cpp b/src/openvic-simulation/economy/Building.cpp
index 4a99249..29eb50e 100644
--- a/src/openvic-simulation/economy/Building.cpp
+++ b/src/openvic-simulation/economy/Building.cpp
@@ -7,13 +7,13 @@ 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 },
- 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 },
- advanced_factory { advanced_factory }, fort_level { fort_level }, naval_capacity { naval_capacity },
- colonial_points { std::move(colonial_points) }, in_province { in_province }, one_per_state { one_per_state },
- colonial_range { colonial_range }, infrastructure { infrastructure }, spawn_railway_track { spawn_railway_track },
- sail { sail }, steam { steam }, capital { capital }, port { port } {}
+ 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 },
+ advanced_factory { advanced_factory }, fort_level { fort_level }, naval_capacity { naval_capacity },
+ colonial_points { std::move(colonial_points) }, in_province { in_province }, one_per_state { one_per_state },
+ colonial_range { colonial_range }, infrastructure { infrastructure }, spawn_railway_track { spawn_railway_track },
+ sail { sail }, steam { steam }, capital { capital }, port { port } {}
BuildingType const& Building::get_type() const {
return type;
@@ -154,14 +154,15 @@ 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,16 @@ 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,7 +216,8 @@ 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 {
+ 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;
@@ -220,8 +225,10 @@ bool BuildingManager::load_buildings_file(GoodManager const& good_manager, Produ
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;
+ 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;
@@ -260,10 +267,10 @@ bool BuildingManager::load_buildings_file(GoodManager const& good_manager, Produ
)(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
+ 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;
diff --git a/src/openvic-simulation/economy/Building.hpp b/src/openvic-simulation/economy/Building.hpp
index b56c9a2..bbf97fb 100644
--- a/src/openvic-simulation/economy/Building.hpp
+++ b/src/openvic-simulation/economy/Building.hpp
@@ -166,7 +166,9 @@ 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/Good.cpp b/src/openvic-simulation/economy/Good.cpp
index 0fd4618..60a85d0 100644
--- a/src/openvic-simulation/economy/Good.cpp
+++ b/src/openvic-simulation/economy/Good.cpp
@@ -84,12 +84,14 @@ 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) {
@@ -123,7 +125,8 @@ 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(key, colour, good_category, base_price, available_from_start, tradeable, money, overseas_penalty);
+ ret &= add_good(key, colour, good_category, base_price,
+ available_from_start, tradeable, money, overseas_penalty);
return ret;
}
)(good_category_value);
diff --git a/src/openvic-simulation/economy/ProductionType.cpp b/src/openvic-simulation/economy/ProductionType.cpp
index f31ea59..6b7d757 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;
@@ -186,7 +188,8 @@ 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
@@ -227,7 +230,8 @@ 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 {
+ [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;
diff --git a/src/openvic-simulation/economy/ProductionType.hpp b/src/openvic-simulation/economy/ProductionType.hpp
index 2deb461..d84be01 100644
--- a/src/openvic-simulation/economy/ProductionType.hpp
+++ b/src/openvic-simulation/economy/ProductionType.hpp
@@ -96,10 +96,10 @@ 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();