diff options
author | ClarkeCode <clarke.john.robert@gmail.com> | 2023-04-27 22:13:52 +0200 |
---|---|---|
committer | ClarkeCode <clarke.john.robert@gmail.com> | 2023-04-27 22:13:52 +0200 |
commit | 0b273743b480874281a8987c72b2f1b666bc289a (patch) | |
tree | 3f5d5a6316ac66407e61c8a56fe732cdf06209e5 /extension/src/openvic2/GameManager.cpp | |
parent | 98dd680a641a2cbe0f1f93202a5beffdfd35c9f7 (diff) | |
parent | 10053cf259c55ee45803268a844edf1011d8a16b (diff) |
Merge branch 'main' of github.com:OpenVic2Project/OpenVic2 into goods
Diffstat (limited to 'extension/src/openvic2/GameManager.cpp')
-rw-r--r-- | extension/src/openvic2/GameManager.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/extension/src/openvic2/GameManager.cpp b/extension/src/openvic2/GameManager.cpp new file mode 100644 index 0000000..78992f1 --- /dev/null +++ b/extension/src/openvic2/GameManager.cpp @@ -0,0 +1,46 @@ +#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(); } }, 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(); +} + +return_t GameManager::setup() { + clock.reset(); + today = { 1836 }; + set_needs_update(); + return 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); +} |