aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/misc/Define.hpp
blob: 46e48366e4d959de21d4c673c457b5d2832ad717 (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
#pragma once

#include <concepts>
#include <optional>

#include "openvic-simulation/types/IdentifierRegistry.hpp"
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"

namespace OpenVic {
   struct DefineManager;

   struct Define : HasIdentifier {
      friend struct DefineManager;

      enum class Type : unsigned char { None, Country, Economy, Military, Diplomacy, Pops, Ai, Graphics };

   private:
      const std::string PROPERTY(value);
      const Type PROPERTY(type);

      Define(std::string_view new_identifier, std::string&& new_value, Type new_type);

   public:
      Define(Define&&) = default;

      fixed_point_t get_value_as_fp() const;
      int64_t get_value_as_int() const;
      uint64_t get_value_as_uint() const;
   };

   struct DefineManager {
   private:
      IdentifierRegistry<Define> defines;

      std::optional<Date> start_date;
      std::optional<Date> end_date;

   public:
      DefineManager();

      bool add_define(std::string_view name, std::string&& value, Define::Type type);
      bool add_date_define(std::string_view name, Date date);
      IDENTIFIER_REGISTRY_ACCESSORS(define)

      Date get_start_date() const;
      Date get_end_date() const;
      bool in_game_period(Date date) const;

      bool load_defines_file(ast::NodeCPtr root);
   };
}