aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/economy
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2023-11-14 22:42:00 +0100
committer hop311 <hop3114@gmail.com>2023-11-15 21:06:20 +0100
commit8271b1519e095ee3e7245cde2f0b54561c3ec619 (patch)
tree0168ea3d3125f68b700d53e3fa0ebdd80b337653 /src/openvic-simulation/economy
parente031758cf68535e97045c07f36e2524676447778 (diff)
Bookmark loading + province and building cleanup
Diffstat (limited to 'src/openvic-simulation/economy')
-rw-r--r--src/openvic-simulation/economy/Building.cpp155
-rw-r--r--src/openvic-simulation/economy/Building.hpp138
2 files changed, 62 insertions, 231 deletions
diff --git a/src/openvic-simulation/economy/Building.cpp b/src/openvic-simulation/economy/Building.cpp
index bade4a5..c5707ea 100644
--- a/src/openvic-simulation/economy/Building.cpp
+++ b/src/openvic-simulation/economy/Building.cpp
@@ -1,10 +1,10 @@
#include "Building.hpp"
-#include "openvic-simulation/map/Province.hpp" //imported here so the hpp doesn't get circular imports
-
using namespace OpenVic;
using namespace OpenVic::NodeTools;
+BuildingType::BuildingType(std::string_view new_identifier) : HasIdentifier { new_identifier } {}
+
Building::Building(
std::string_view identifier, BuildingType const& type, ARGS
) : HasIdentifier { identifier }, type { type }, modifier { std::move(modifier) }, on_completion { on_completion },
@@ -16,135 +16,18 @@ Building::Building(
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;
-}
-
-ModifierValue const& Building::get_modifier() const {
- return modifier;
-}
-
-std::string_view Building::get_on_completion() const {
- return on_completion;
-}
-
-fixed_point_t Building::get_completion_size() const {
- return completion_size;
-}
-
-Building::level_t Building::get_max_level() const {
- return max_level;
-}
-
-Good::good_map_t const& Building::get_goods_cost() const {
- return goods_cost;
-}
-
-fixed_point_t Building::get_cost() const {
- return cost;
-}
-
-Timespan Building::get_build_time() const {
- return build_time;
-}
-
-bool Building::has_visibility() const {
- return visibility;
-}
-
-bool Building::is_on_map() const {
- return on_map;
-}
-
-bool Building::is_default_enabled() const {
- return default_enabled;
-}
-
-ProductionType const* Building::get_production_type() const {
- return production_type;
-}
-
-bool Building::is_pop_built_factory() const {
- return pop_build_factory;
-}
-
-bool Building::is_strategic_factory() const {
- return strategic_factory;
-}
-
-bool Building::is_advanced_factory() const {
- return advanced_factory;
-}
-
-Building::level_t Building::get_fort_level() const {
- return fort_level;
-}
-
-uint64_t Building::get_naval_capacity() const {
- return naval_capacity;
-}
-
-std::vector<fixed_point_t> const& Building::get_colonial_points() const {
- return colonial_points;
-}
-
-bool Building::is_in_province() const {
- return in_province;
-}
-
-bool Building::is_one_per_state() const {
- return one_per_state;
-}
-
-fixed_point_t Building::get_colonial_range() const {
- return colonial_range;
-}
-
-fixed_point_t Building::get_infrastructure() const {
- return infrastructure;
-}
-
-bool Building::spawned_railway_track() const {
- return spawn_railway_track;
-}
-
-BuildingType::BuildingType(std::string_view new_identifier) : HasIdentifier { new_identifier } {}
-
-BuildingInstance::BuildingInstance(Building const& building)
- : HasIdentifier { building.get_identifier() }, building { building } {}
-
-Building const& BuildingInstance::get_building() const {
- return building;
-}
+BuildingInstance::BuildingInstance(Building const& new_building, level_t new_level)
+ : HasIdentifier { building.get_identifier() }, building { new_building }, level { new_level },
+ expansion_state { ExpansionState::CannotExpand } {}
bool BuildingInstance::_can_expand() const {
return level < building.get_max_level();
}
-BuildingInstance::level_t BuildingInstance::get_current_level() const {
- return level;
-}
-
void BuildingInstance::set_level(BuildingInstance::level_t new_level) {
level = new_level;
}
-ExpansionState BuildingInstance::get_expansion_state() const {
- return expansion_state;
-}
-
-Date BuildingInstance::get_start_date() const {
- return start;
-}
-
-Date BuildingInstance::get_end_date() const {
- return end;
-}
-
-float BuildingInstance::get_expansion_progress() const {
- return expansion_progress;
-}
-
bool BuildingInstance::expand() {
if (expansion_state == ExpansionState::CanExpand) {
expansion_state = ExpansionState::Preparing;
@@ -160,11 +43,11 @@ bool BuildingInstance::expand() {
void BuildingInstance::update_state(Date today) {
switch (expansion_state) {
case ExpansionState::Preparing:
- start = today;
- end = start + building.get_build_time();
+ start_date = today;
+ end_date = start_date + building.get_build_time();
break;
case ExpansionState::Expanding:
- expansion_progress = static_cast<double>(today - start) / static_cast<double>(end - start);
+ expansion_progress = static_cast<double>(today - start_date) / static_cast<double>(end_date - start_date);
break;
default: expansion_state = _can_expand() ? ExpansionState::CanExpand : ExpansionState::CannotExpand;
}
@@ -175,7 +58,7 @@ void BuildingInstance::tick(Date today) {
expansion_state = ExpansionState::Expanding;
}
if (expansion_state == ExpansionState::Expanding) {
- if (end <= today) {
+ if (end_date <= today) {
level++;
expansion_state = ExpansionState::CannotExpand;
}
@@ -193,6 +76,10 @@ bool BuildingManager::add_building_type(std::string_view identifier) {
}
bool BuildingManager::add_building(std::string_view identifier, BuildingType const* type, ARGS) {
+ if (!building_types.is_locked()) {
+ Logger::error("Cannot add buildings until building types are locked!");
+ return false;
+ }
if (identifier.empty()) {
Logger::error("Invalid building identifier - empty!");
return false;
@@ -298,19 +185,3 @@ bool BuildingManager::load_buildings_file(
return ret;
}
-
-bool BuildingManager::generate_province_buildings(Province& province) const {
- province.reset_buildings();
- if (!building_types.is_locked()) {
- Logger::error("Cannot generate buildings until building types are locked!");
- return false;
- }
- bool ret = true;
- if (!province.get_water()) {
- for (Building const& building : buildings.get_items()) {
- ret &= province.add_building({ building });
- }
- }
- province.lock_buildings();
- return ret;
-}
diff --git a/src/openvic-simulation/economy/Building.hpp b/src/openvic-simulation/economy/Building.hpp
index c2eb1ef..ed1190b 100644
--- a/src/openvic-simulation/economy/Building.hpp
+++ b/src/openvic-simulation/economy/Building.hpp
@@ -18,7 +18,16 @@
namespace OpenVic {
struct BuildingManager;
- struct BuildingType;
+
+ struct BuildingType : HasIdentifier {
+ friend struct BuildingManager;
+
+ private:
+ BuildingType(std::string_view new_identifier);
+
+ public:
+ BuildingType(BuildingType&&) = default;
+ };
/* REQUIREMENTS:
* MAP-11, MAP-72, MAP-73
@@ -31,81 +40,43 @@ namespace OpenVic {
using level_t = int16_t;
private:
- BuildingType const& type;
- const ModifierValue modifier;
- 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 bool visibility;
- const bool on_map; // onmap
-
- const bool default_enabled;
- ProductionType const* production_type;
- const bool pop_build_factory;
- const bool strategic_factory;
- const bool advanced_factory;
-
- 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 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
+ BuildingType const& PROPERTY(type);
+ ModifierValue PROPERTY(modifier);
+ 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);
+ fixed_point_t PROPERTY(cost);
+ Timespan PROPERTY(build_time); // time
+ bool PROPERTY(visibility);
+ bool PROPERTY(on_map); // onmap
+
+ bool PROPERTY(default_enabled);
+ ProductionType const* PROPERTY(production_type);
+ bool PROPERTY(pop_build_factory);
+ bool PROPERTY(strategic_factory);
+ bool PROPERTY(advanced_factory);
+
+ level_t PROPERTY(fort_level); // probably the step-per-level
+
+ uint64_t PROPERTY(naval_capacity);
+ std::vector<fixed_point_t> PROPERTY(colonial_points);
+ bool PROPERTY(in_province); // province
+ bool PROPERTY(one_per_state);
+ fixed_point_t PROPERTY(colonial_range);
+
+ fixed_point_t PROPERTY(infrastructure);
+ bool PROPERTY(spawn_railway_track);
+
+ bool PROPERTY(sail); // only in clipper shipyard
+ bool PROPERTY(steam); // only in steamer shipyard
+ bool PROPERTY(capital); // only in naval base
+ bool PROPERTY(port); // only in naval base
Building(std::string_view identifier, BuildingType const& type, ARGS);
public:
Building(Building&&) = default;
-
- BuildingType const& get_type() const;
- ModifierValue const& get_modifier() const;
- std::string_view get_on_completion() const;
- fixed_point_t get_completion_size() const;
- level_t get_max_level() const;
- Good::good_map_t const& get_goods_cost() const;
- fixed_point_t get_cost() const;
- Timespan get_build_time() const;
- bool has_visibility() const;
- bool is_on_map() const;
-
- bool is_default_enabled() const;
- ProductionType const* get_production_type() const;
- bool is_pop_built_factory() const;
- bool is_strategic_factory() const;
- bool is_advanced_factory() const;
-
- level_t get_fort_level() const;
-
- uint64_t get_naval_capacity() const;
- std::vector<fixed_point_t> const& get_colonial_points() const;
- bool is_in_province() const;
- bool is_one_per_state() const;
- fixed_point_t get_colonial_range() const;
-
- fixed_point_t get_infrastructure() const;
- bool spawned_railway_track() const;
- };
-
- struct BuildingType : HasIdentifier {
- friend struct BuildingManager;
-
- private:
- BuildingType(std::string_view new_identifier);
-
- public:
- BuildingType(BuildingType&&) = default;
};
enum class ExpansionState { CannotExpand, CanExpand, Preparing, Expanding };
@@ -115,36 +86,27 @@ namespace OpenVic {
using level_t = Building::level_t;
private:
- Building const& building;
+ Building const& PROPERTY(building);
- level_t level = 0;
- ExpansionState expansion_state = ExpansionState::CannotExpand;
- Date start, end;
- float expansion_progress;
+ level_t PROPERTY(level);
+ ExpansionState PROPERTY(expansion_state);
+ Date PROPERTY(start_date)
+ Date PROPERTY(end_date);
+ float PROPERTY(expansion_progress);
bool _can_expand() const;
public:
- BuildingInstance(Building const& building);
+ BuildingInstance(Building const& new_building, level_t new_level = 0);
BuildingInstance(BuildingInstance&&) = default;
- Building const& get_building() const;
-
- level_t get_current_level() const;
void set_level(level_t new_level);
- ExpansionState get_expansion_state() const;
- Date get_start_date() const;
- Date get_end_date() const;
- float get_expansion_progress() const;
-
bool expand();
void update_state(Date today);
void tick(Date today);
};
- struct Province;
-
struct BuildingManager {
using level_t = Building::level_t; // this is getting ridiculous
@@ -165,7 +127,5 @@ namespace OpenVic {
GoodManager const& good_manager, ProductionTypeManager const& production_type_manager,
ModifierManager& modifier_manager, ast::NodeCPtr root
);
-
- bool generate_province_buildings(Province& province) const;
};
}