aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic2/map/Building.hpp
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-04-23 20:49:01 +0200
committer Hop311 <hop3114@gmail.com>2023-04-23 20:49:01 +0200
commitd3f3187209cb4085f27f95ce8ad2a77af25704fd (patch)
tree60971db586e78761341f2b48110d149b1ba0db9d /extension/src/openvic2/map/Building.hpp
parent1084a5d64df5d3465ef90b3b85fe3374636a3fe8 (diff)
C++ refactoring + simulation prototype
Diffstat (limited to 'extension/src/openvic2/map/Building.hpp')
-rw-r--r--extension/src/openvic2/map/Building.hpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/extension/src/openvic2/map/Building.hpp b/extension/src/openvic2/map/Building.hpp
new file mode 100644
index 0000000..7a1a777
--- /dev/null
+++ b/extension/src/openvic2/map/Building.hpp
@@ -0,0 +1,63 @@
+#pragma once
+
+#include <vector>
+
+#include "openvic2/Types.hpp"
+#include "openvic2/Date.hpp"
+
+namespace OpenVic2 {
+ struct BuildingManager;
+ struct BuildingType;
+
+ struct Building {
+ friend struct BuildingManager;
+
+ using level_t = int8_t;
+
+ enum class ExpansionState { CannotExpand, CanExpand, Preparing, Expanding };
+ private:
+ BuildingType const& type;
+ level_t level = 0;
+ ExpansionState expansion_state = ExpansionState::CannotExpand;
+ Date start, end;
+ float expansion_progress;
+
+ Building(BuildingType const& new_type);
+
+ bool _can_expand() const;
+ public:
+ BuildingType const& get_type() const;
+ level_t get_level() const;
+ ExpansionState get_expansion_state() const;
+ Date const& get_start_date() const;
+ Date const& get_end_date() const;
+ float get_expansion_progress() const;
+
+ return_t expand();
+ void update_state(Date const& today);
+ void tick(Date const& today);
+ };
+
+ struct BuildingType : HasIdentifier {
+ friend struct BuildingManager;
+ private:
+ Building::level_t max_level;
+ Timespan build_time;
+
+ BuildingType(std::string const& new_identifier, Building::level_t new_max_level, Timespan new_build_time);
+ public:
+ Building::level_t get_max_level() const;
+ Timespan get_build_time() const;
+ };
+
+ struct BuildingManager {
+ private:
+ std::vector<BuildingType> building_types;
+ bool building_types_locked = false;
+ public:
+ return_t add_building_type(std::string const& identifier, Building::level_t max_level, Timespan build_time);
+ void lock_building_types();
+ BuildingType const* get_building_type_by_identifier(std::string const& identifier) const;
+ void generate_province_buildings(std::vector<Building>& buildings) const;
+ };
+}