From 48204950cd8d48e6df26ed6892f57b3d9da823de Mon Sep 17 00:00:00 2001 From: hop311 Date: Mon, 25 Dec 2023 00:22:01 +0000 Subject: Province building scaffolding --- .../economy/BuildingInstance.cpp | 5 ++-- src/openvic-simulation/economy/BuildingType.cpp | 35 ++++++++++++++++++---- src/openvic-simulation/economy/BuildingType.hpp | 5 ++-- src/openvic-simulation/economy/ProductionType.cpp | 5 ++++ 4 files changed, 40 insertions(+), 10 deletions(-) (limited to 'src/openvic-simulation/economy') diff --git a/src/openvic-simulation/economy/BuildingInstance.cpp b/src/openvic-simulation/economy/BuildingInstance.cpp index 597b89e..047b759 100644 --- a/src/openvic-simulation/economy/BuildingInstance.cpp +++ b/src/openvic-simulation/economy/BuildingInstance.cpp @@ -4,7 +4,7 @@ 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 } {} + expansion_state { ExpansionState::CannotExpand }, start_date {}, end_date {}, expansion_progress { 0.0f } {} bool BuildingInstance::_can_expand() const { return level < building_type.get_max_level(); @@ -29,7 +29,8 @@ void BuildingInstance::update_state(Date today) { end_date = start_date + building_type.get_build_time(); break; case ExpansionState::Expanding: - expansion_progress = static_cast(today - start_date) / static_cast(end_date - start_date); + expansion_progress = + static_cast((today - start_date).to_int()) / static_cast((end_date - start_date).to_int()); break; default: expansion_state = _can_expand() ? ExpansionState::CanExpand : ExpansionState::CannotExpand; } diff --git a/src/openvic-simulation/economy/BuildingType.cpp b/src/openvic-simulation/economy/BuildingType.cpp index 3d44c8c..c11933f 100644 --- a/src/openvic-simulation/economy/BuildingType.cpp +++ b/src/openvic-simulation/economy/BuildingType.cpp @@ -104,18 +104,41 @@ bool BuildingTypeManager::load_buildings_file( min_modifier_prefix.append(building_type.get_identifier()), false, ModifierEffect::format_t::INT ); + if (building_type.is_in_province()) { + province_building_types.emplace_back(&building_type); + } + if (building_type.is_port()) { - if (port_building_type == nullptr) { - port_building_type = &building_type; + if (building_type.is_in_province()) { + if (port_building_type == nullptr) { + port_building_type = &building_type; + } else { + Logger::error( + "Building type ", building_type, " is marked as a port, but we are already using ", port_building_type, + " as the port building type!" + ); + ret = false; + } } else { - Logger::error( - "Building type ", building_type, " is marked as a port, but we are already using ", port_building_type, - " as the port building type!" - ); + Logger::error("Building type ", building_type, " is marked as a port, but is not a province building!"); ret = false; } } } + if (port_building_type == nullptr) { + Logger::error("No port building type found!"); + ret = false; + } + if (province_building_types.empty()) { + Logger::error("No province building types found!"); + ret = false; + } else { + Logger::info( + "Found ", province_building_types.size(), " province building types out of ", get_building_type_count(), + " total building types" + ); + } + return ret; } diff --git a/src/openvic-simulation/economy/BuildingType.hpp b/src/openvic-simulation/economy/BuildingType.hpp index 27cedfd..b1eb6f8 100644 --- a/src/openvic-simulation/economy/BuildingType.hpp +++ b/src/openvic-simulation/economy/BuildingType.hpp @@ -47,11 +47,11 @@ namespace OpenVic { bool PROPERTY(strategic_factory); bool PROPERTY(advanced_factory); - level_t PROPERTY(fort_level); // probably the step-per-level + level_t PROPERTY(fort_level); // fort bonus step-per-level uint64_t PROPERTY(naval_capacity); std::vector PROPERTY(colonial_points); - bool PROPERTY(in_province); // province + bool PROPERTY_CUSTOM_PREFIX(in_province, is); // province bool PROPERTY(one_per_state); fixed_point_t PROPERTY(colonial_range); @@ -74,6 +74,7 @@ namespace OpenVic { private: IdentifierRegistry IDENTIFIER_REGISTRY(building_type); + std::vector PROPERTY(province_building_types); BuildingType const* PROPERTY(port_building_type); public: diff --git a/src/openvic-simulation/economy/ProductionType.cpp b/src/openvic-simulation/economy/ProductionType.cpp index a19b7bf..05529f5 100644 --- a/src/openvic-simulation/economy/ProductionType.cpp +++ b/src/openvic-simulation/economy/ProductionType.cpp @@ -212,5 +212,10 @@ bool ProductionTypeManager::load_production_types_file( production_types.lock(); + if (rgo_owner_sprite <= 0) { + Logger::error("No RGO owner pop type sprite found!"); + ret = false; + } + return ret; } -- cgit v1.2.3-56-ga3b1