aboutsummaryrefslogtreecommitdiff
path: root/src/openvic/pop/Pop.cpp
blob: babcd252d3853187d080b552ab68441fc1f89345 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "Pop.hpp"

#include <cassert>

#include "../map/Province.hpp"
#include "../utility/Logger.hpp"

using namespace OpenVic;

Pop::Pop(PopType const& new_type, Culture const& new_culture, Religion const& new_religion, pop_size_t new_size)
   : type { new_type },
     culture { new_culture },
     religion { new_religion },
     size { new_size } {
   assert(size > 0);
}

PopType const& Pop::get_type() const {
   return type;
}

Culture const& Pop::get_culture() const {
   return culture;
}

Religion const& Pop::get_religion() const {
   return religion;
}

Pop::pop_size_t Pop::get_size() const {
   return size;
}

PopType::PopType(std::string const& new_identifier, colour_t new_colour,
   strata_t new_strata, sprite_t new_sprite,
   Pop::pop_size_t new_max_size, Pop::pop_size_t new_merge_max_size,
   bool new_state_capital_only, bool new_demote_migrant, bool new_is_artisan, bool new_is_slave)
   : HasIdentifier { new_identifier },
     HasColour { new_colour, true },
     strata { new_strata },
     sprite { new_sprite },
     max_size { new_max_size },
     merge_max_size { new_merge_max_size },
     state_capital_only { new_state_capital_only },
     demote_migrant { new_demote_migrant },
     is_artisan { new_is_artisan },
     is_slave { new_is_slave } {
   assert(sprite > 0);
   assert(max_size > 0);
   assert(merge_max_size > 0);
}

PopType::sprite_t PopType::get_sprite() const {
   return sprite;
}

Pop::pop_size_t PopType::get_max_size() const {
   return max_size;
}

Pop::pop_size_t PopType::get_merge_max_size() const {
   return merge_max_size;
}

bool PopType::get_state_capital_only() const {
   return state_capital_only;
}

bool PopType::get_demote_migrant() const {
   return demote_migrant;
}

bool PopType::get_is_artisan() const {
   return is_artisan;
}

bool PopType::get_is_slave() const {
   return is_slave;
}

PopManager::PopManager() : pop_types { "pop types" } {
   culture_manager.add_graphical_culture_type("test_graphical_culture_type");
   culture_manager.lock_graphical_culture_types();

   culture_manager.add_culture_group("test_culture_group", culture_manager.get_graphical_culture_type_by_identifier("test_graphical_culture_type"));
   culture_manager.lock_culture_groups();

   culture_manager.add_culture("test_culture", 0x0000FF, culture_manager.get_culture_group_by_identifier("test_culture_group"),
      { "john" }, { "smith" });
   culture_manager.lock_cultures();

   religion_manager.add_religion_group("test_religion_group");
   religion_manager.lock_religion_groups();

   religion_manager.add_religion("test_religion", 0xFF0000, religion_manager.get_religion_group_by_identifier("test_religion_group"), 1, false);
   religion_manager.lock_religions();

   add_pop_type("test_pop_type_poor", 0xFF0000, PopType::strata_t::POOR, 1, 1, 1, false, false, false, false);
   add_pop_type("test_pop_type_middle", 0x00FF00, PopType::strata_t::MIDDLE, 1, 1, 1, false, false, false, false);
   add_pop_type("test_pop_type_rich", 0x0000FF, PopType::strata_t::RICH, 1, 1, 1, false, false, false, false);
   lock_pop_types();
}

return_t PopManager::add_pop_type(std::string const& identifier, colour_t colour, PopType::strata_t strata, PopType::sprite_t sprite,
   Pop::pop_size_t max_size, Pop::pop_size_t merge_max_size, bool state_capital_only, bool demote_migrant, bool is_artisan, bool is_slave) {
   if (identifier.empty()) {
      Logger::error("Invalid pop type identifier - empty!");
      return FAILURE;
   }
   if (colour > MAX_COLOUR_RGB) {
      Logger::error("Invalid pop type colour for ", identifier, ": ", PopType::colour_to_hex_string(colour));
      return FAILURE;
   }
   if (sprite <= 0) {
      Logger::error("Invalid pop type sprite index for ", identifier, ": ", sprite);
      return FAILURE;
   }
   if (max_size <= 0) {
      Logger::error("Invalid pop type max size for ", identifier, ": ", max_size);
      return FAILURE;
   }
   if (merge_max_size <= 0) {
      Logger::error("Invalid pop type merge max size for ", identifier, ": ", merge_max_size);
      return FAILURE;
   }
   return pop_types.add_item({ identifier, colour, strata, sprite, max_size, merge_max_size, state_capital_only, demote_migrant, is_artisan, is_slave });
}

void PopManager::lock_pop_types() {
   pop_types.lock();
}

PopType const* PopManager::get_pop_type_by_identifier(std::string const& identifier) const {
   return pop_types.get_item_by_identifier(identifier);
}

void PopManager::generate_test_pops(Province& province) const {
   if (pop_types.is_locked()) {
      static PopType const& type_poor = *get_pop_type_by_identifier("test_pop_type_poor");
      static PopType const& type_middle = *get_pop_type_by_identifier("test_pop_type_middle");
      static PopType const& type_rich = *get_pop_type_by_identifier("test_pop_type_rich");
      static Culture const& culture = *culture_manager.get_culture_by_identifier("test_culture");
      static Religion const& religion = *religion_manager.get_religion_by_identifier("test_religion");
      province.add_pop({ type_poor, culture, religion, static_cast<Pop::pop_size_t>(province.get_index() * province.get_index() * province.get_index()) * 1000 });
      province.add_pop({ type_middle, culture, religion, static_cast<Pop::pop_size_t>(province.get_index() * province.get_index()) * 1000 });
      province.add_pop({ type_rich, culture, religion, static_cast<Pop::pop_size_t>(province.get_index()) * 1000 });
   } else {
      Logger::error("Cannot generate pops before pop types registry is locked!");
   }
}