Project Alice
Loading...
Searching...
No Matches
nationality.hpp
Go to the documentation of this file.
1#pragma once
2
3std::vector<uint32_t> get_nationality_global_color(sys::state& state) {
4 uint32_t province_size = state.world.province_size() + 1;
5 uint32_t texture_size = province_size + 256 - province_size % 256;
6
7 std::vector<uint32_t> prov_color(texture_size * 2);
8 state.world.for_each_province([&](dcon::province_id prov_id) {
9 auto id = province::to_map_id(prov_id);
10 float total_pops = state.world.province_get_demographics(prov_id, demographics::total);
11
12 dcon::culture_id primary_culture, secondary_culture;
13 float primary_culture_percent = 0.f, secondary_culture_percent = 0.f;
14
15 state.world.for_each_culture([&](dcon::culture_id culture_id) {
16 auto demo_key = demographics::to_key(state, culture_id);
17 auto volume = state.world.province_get_demographics(prov_id, demo_key);
18 float percent = volume / total_pops;
19
20 if(percent > primary_culture_percent) {
21 secondary_culture = primary_culture;
22 secondary_culture_percent = primary_culture_percent;
23 primary_culture = culture_id;
24 primary_culture_percent = percent;
25 } else if(percent > secondary_culture_percent) {
26 secondary_culture = culture_id;
27 secondary_culture_percent = percent;
28 }
29 });
30
31 dcon::culture_fat_id fat_primary_culture = dcon::fatten(state.world, primary_culture);
32
33 uint32_t primary_culture_color = fat_primary_culture.get_color();
34 uint32_t secondary_culture_color = 0xFFAAAAAA; // This color won't be reached
35
36 if(bool(secondary_culture)) {
37 dcon::culture_fat_id fat_secondary_culture = dcon::fatten(state.world, secondary_culture);
38 secondary_culture_color = fat_secondary_culture.get_color();
39 }
40
41 if(secondary_culture_percent >= .35) {
42 prov_color[id] = primary_culture_color;
43 prov_color[id + texture_size] = secondary_culture_color;
44 } else {
45 prov_color[id] = primary_culture_color;
46 prov_color[id + texture_size] = primary_culture_color;
47 }
48 });
49
50 return prov_color;
51}
52
53std::vector<uint32_t> get_nationality_diaspora_color(sys::state& state) {
54 auto fat_selected_id = dcon::fatten(state.world, state.map_state.get_selected_province());
55 auto culture_id = fat_selected_id.get_dominant_culture();
56 auto culture_key = demographics::to_key(state, culture_id.id);
57
58 uint32_t province_size = state.world.province_size() + 1;
59 uint32_t texture_size = province_size + 256 - province_size % 256;
60
61 std::vector<uint32_t> prov_color(texture_size * 2);
62
63 if(bool(culture_id)) {
64 uint32_t full_color = culture_id.get_color();
65 uint32_t empty_color = 0xDDDDDD;
66 // Make the other end of the gradient dark if the color is bright and vice versa.
67 // This should make it easier to see cultures that would otherwise be problematic.
68 if((full_color & 0xFF) + (full_color >> 8 & 0xFF) + (full_color >> 16 & 0xFF) > 140 * 3) {
69 empty_color = 0x222222;
70 }
71
72 state.world.for_each_province([&](dcon::province_id prov_id) {
73 auto i = province::to_map_id(prov_id);
74 auto fat_id = dcon::fatten(state.world, prov_id);
75 auto total_pop = state.world.province_get_demographics(prov_id, demographics::total);
76 auto culture_pop = state.world.province_get_demographics(prov_id, culture_key);
77 auto ratio = culture_pop / total_pop;
78
79 auto color = ogl::color_gradient(ratio, full_color, empty_color);
80
81 prov_color[i] = color;
82 prov_color[i + texture_size] = color;
83 });
84 }
85 return prov_color;
86}
87
88std::vector<uint32_t> nationality_map_from(sys::state& state) {
89 std::vector<uint32_t> prov_color;
90 if(state.map_state.get_selected_province()) {
91 prov_color = get_nationality_diaspora_color(state);
92 } else {
93 prov_color = get_nationality_global_color(state);
94 }
95
96 return prov_color;
97}
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
constexpr dcon::demographics_key total(0)
dcon::demographics_key to_key(sys::state const &state, dcon::pop_type_id v)
uint32_t color_gradient(float percent, uint32_t top_color, uint32_t bot_color)
Definition: color.hpp:42
constexpr uint16_t to_map_id(dcon::province_id id)
Definition: province.hpp:10
std::vector< uint32_t > get_nationality_diaspora_color(sys::state &state)
Definition: nationality.hpp:53
std::vector< uint32_t > nationality_map_from(sys::state &state)
Definition: nationality.hpp:88
std::vector< uint32_t > get_nationality_global_color(sys::state &state)
Definition: nationality.hpp:3
uint uint32_t