aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/InstanceManager.hpp
blob: 418515b68c34737b91476966e645dd38be1bdafa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#pragma once

#include <functional>

#include "openvic-simulation/country/CountryInstance.hpp"
#include "openvic-simulation/diplomacy/CountryRelation.hpp"
#include "openvic-simulation/economy/GoodInstance.hpp"
#include "openvic-simulation/economy/trading/MarketInstance.hpp"
#include "openvic-simulation/map/MapInstance.hpp"
#include "openvic-simulation/map/Mapmode.hpp"
#include "openvic-simulation/military/UnitInstanceGroup.hpp"
#include "openvic-simulation/misc/SimulationClock.hpp"
#include "openvic-simulation/types/Date.hpp"

namespace OpenVic {
   struct DefinitionManager;
   struct Bookmark;

   struct InstanceManager {
      using gamestate_updated_func_t = std::function<void()>;

   private:
      DefinitionManager const& PROPERTY(definition_manager);

      CountryInstanceManager PROPERTY_REF(country_instance_manager);
      CountryRelationManager PROPERTY_REF(country_relation_manager);
      GoodInstanceManager PROPERTY_REF(good_instance_manager);
      MarketInstance PROPERTY_REF(market_instance);
      UnitInstanceManager PROPERTY_REF(unit_instance_manager);
      /* Near the end so it is freed after other managers that may depend on it,
       * e.g. if we want to remove military units from the province they're in when they're destructed. */
      MapInstance PROPERTY_REF(map_instance);
      SimulationClock PROPERTY_REF(simulation_clock);

      bool PROPERTY_CUSTOM_PREFIX(game_instance_setup, is);
      bool PROPERTY_CUSTOM_PREFIX(game_session_started, is);

      void update_modifier_sums();
   public:
      inline constexpr bool is_bookmark_loaded() const {
         return bookmark != nullptr;
      }

   private:
      time_t session_start; /* SS-54, as well as allowing time-tracking */
      Bookmark const* PROPERTY(bookmark);
      Date PROPERTY(today);
      gamestate_updated_func_t gamestate_updated;
      bool gamestate_needs_update, currently_updating_gamestate;

      void set_gamestate_needs_update();
      void update_gamestate();
      void tick();

   public:
      InstanceManager(
         DefinitionManager const& new_definition_manager, gamestate_updated_func_t gamestate_updated_callback,
         SimulationClock::state_changed_function_t clock_state_changed_callback
      );

      bool setup();
      bool load_bookmark(Bookmark const* new_bookmark);
      bool start_game_session();
      bool update_clock();

      bool expand_selected_province_building(size_t building_index);
   };
}