aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/misc/Event.hpp
blob: a518f7815843c1b1b1c3fad1286fe49b008f27c1 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#pragma once

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

namespace OpenVic {
   struct EventManager;
   struct IssueGroup;
   struct IssueManager;

   struct Event : HasIdentifier {
      friend struct EventManager;

      enum struct event_type_t : uint8_t { COUNTRY, PROVINCE };

      struct EventOption {
         friend struct EventManager;

      private:
         std::string PROPERTY(title);
         // TODO: option effects

         EventOption(std::string_view new_title);

      public:
         EventOption(EventOption const&) = delete;
         EventOption(EventOption&&) = default;
         EventOption& operator=(EventOption const&) = delete;
         EventOption& operator=(EventOption&&) = delete;
      };

   private:
      std::string PROPERTY(title);
      std::string PROPERTY(description);
      std::string PROPERTY(image);
      event_type_t PROPERTY(type);
      bool PROPERTY_CUSTOM_PREFIX(triggered_only, is);
      bool PROPERTY_CUSTOM_PREFIX(major, is);
      bool PROPERTY(fire_only_once);
      bool PROPERTY(allows_multiple_instances);

      bool PROPERTY_CUSTOM_PREFIX(news, is);
      std::string PROPERTY(news_title);
      std::string PROPERTY(news_desc_long);
      std::string PROPERTY(news_desc_medium);
      std::string PROPERTY(news_desc_short);

      bool PROPERTY_CUSTOM_PREFIX(election, is);
      IssueGroup const* PROPERTY(election_issue_group);

      std::vector<EventOption> PROPERTY(options);

      // TODO: triggers, MTTH, immediate effects

      Event(
         std::string_view new_identifier, std::string_view new_title, std::string_view new_description,
         std::string_view new_image, event_type_t new_type, bool new_triggered_only, bool new_major,
         bool new_fire_only_once, bool new_allows_multiple_instances, bool new_news, std::string_view new_news_title,
         std::string_view new_news_desc_long, std::string_view new_news_desc_medium, std::string_view new_news_desc_short,
         bool new_election, IssueGroup const* new_election_issue_group, std::vector<EventOption>&& new_options
      );

   public:
      Event(Event&&) = default;
   };

   struct OnAction : HasIdentifier {
      friend struct EventManager;
      using weight_map_t = std::map<Event const*, uint64_t>; 

   private:
      weight_map_t PROPERTY(weighted_events);

      OnAction(std::string_view new_identifier, weight_map_t new_weighted_events);
   
   public:
      OnAction(OnAction&&) = default;
   };

   struct EventManager {
   private:
      IdentifierRegistry<Event> IDENTIFIER_REGISTRY(event);
      IdentifierRegistry<OnAction> IDENTIFIER_REGISTRY(on_action);

   public:
      bool register_event(
         std::string_view identifier, std::string_view title, std::string_view description, std::string_view image,
         Event::event_type_t type, bool triggered_only, bool major, bool fire_only_once, bool allows_multiple_instances,
         bool news, std::string_view news_title, std::string_view news_desc_long, std::string_view news_desc_medium,
         std::string_view news_desc_short, bool election, IssueGroup const* election_issue_group,
         std::vector<Event::EventOption>&& options
      );

      bool add_on_action(std::string_view identifier, OnAction::weight_map_t new_weighted_events);

      bool load_event_file(IssueManager const& issue_manager, ast::NodeCPtr root);
      bool load_on_action_file(ast::NodeCPtr root);
   };
} // namespace OpenVic