aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic2/GameManager.cpp
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/GameManager.cpp
parent1084a5d64df5d3465ef90b3b85fe3374636a3fe8 (diff)
C++ refactoring + simulation prototype
Diffstat (limited to 'extension/src/openvic2/GameManager.cpp')
-rw-r--r--extension/src/openvic2/GameManager.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/extension/src/openvic2/GameManager.cpp b/extension/src/openvic2/GameManager.cpp
new file mode 100644
index 0000000..da742ca
--- /dev/null
+++ b/extension/src/openvic2/GameManager.cpp
@@ -0,0 +1,43 @@
+#include "openvic2/GameManager.hpp"
+
+#include "openvic2/Logger.hpp"
+
+using namespace OpenVic2;
+
+GameManager::GameManager(state_updated_func_t state_updated_callback)
+ : clock{ [this]() { tick(); }, [this]() { update_state(); }, true }, today{ 1836 }, state_updated{ state_updated_callback } {}
+
+void GameManager::set_needs_update() {
+ needs_update = true;
+}
+
+void GameManager::update_state() {
+ if (needs_update) {
+ Logger::info("Update: ", today);
+ map.update_state(today);
+ if (state_updated) state_updated();
+ needs_update = false;
+ }
+}
+
+void GameManager::tick() {
+ today++;
+ Logger::info("Tick: ", today);
+ map.tick(today);
+ set_needs_update();
+}
+
+void GameManager::finished_loading_data() {
+ map.generate_province_buildings(building_manager);
+}
+
+Date const& GameManager::get_today() const {
+ return today;
+}
+
+return_t GameManager::expand_building(Province::index_t province_index, std::string const& building_type_identifier) {
+ set_needs_update();
+ Province* province = map.get_province_by_index(province_index);
+ if (province == nullptr) return FAILURE;
+ return province->expand_building(building_type_identifier);
+}