Project Alice
Loading...
Searching...
No Matches
religion.hpp
Go to the documentation of this file.
1#pragma once
2
3std::vector<uint32_t> get_religion_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::religion_id primary_religion, secondary_religion;
13 float primary_religion_percent = 0.f, secondary_religion_percent = 0.f;
14
15 state.world.for_each_religion([&](dcon::religion_id religion_id) {
16 auto demo_key = demographics::to_key(state, religion_id);
17 auto volume = state.world.province_get_demographics(prov_id, demo_key);
18 float percent = volume / total_pops;
19
20 if(percent > primary_religion_percent) {
21 secondary_religion = primary_religion;
22 secondary_religion_percent = primary_religion_percent;
23 primary_religion = religion_id;
24 primary_religion_percent = percent;
25 } else if(percent > secondary_religion_percent) {
26 secondary_religion = religion_id;
27 secondary_religion_percent = percent;
28 }
29 });
30
31 dcon::religion_fat_id fat_primary_religion = dcon::fatten(state.world, primary_religion);
32
33 uint32_t primary_religion_color = fat_primary_religion.get_color();
34 uint32_t secondary_religion_color = 0xFFAAAAAA; // This color won't be reached
35
36 if(bool(secondary_religion)) {
37 dcon::religion_fat_id fat_secondary_religion = dcon::fatten(state.world, secondary_religion);
38 secondary_religion_color = fat_secondary_religion.get_color();
39 }
40
41 if(secondary_religion_percent >= .35) {
42 prov_color[id] = primary_religion_color;
43 prov_color[id + texture_size] = secondary_religion_color;
44 } else {
45 prov_color[id] = primary_religion_color;
46 prov_color[id + texture_size] = primary_religion_color;
47 }
48 });
49
50 return prov_color;
51}
52
53std::vector<uint32_t> get_religion_diaspora_color(sys::state& state) {
54 auto fat_selected_id = dcon::fatten(state.world, state.map_state.get_selected_province());
55 auto religion_id = fat_selected_id.get_dominant_religion();
56 auto religion_key = demographics::to_key(state, religion_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(religion_id)) {
64 uint32_t full_color = religion_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 religions 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 state.world.for_each_province([&](dcon::province_id prov_id) {
72 auto i = province::to_map_id(prov_id);
73 auto total_pop = state.world.province_get_demographics(prov_id, demographics::total);
74 auto religion_pop = state.world.province_get_demographics(prov_id, religion_key);
75 auto ratio = religion_pop / total_pop;
76 auto color = ogl::color_gradient(ratio, full_color, empty_color);
77 prov_color[i] = color;
78 prov_color[i + texture_size] = color;
79 });
80 }
81 return prov_color;
82}
83
84std::vector<uint32_t> religion_map_from(sys::state& state) {
85 std::vector<uint32_t> prov_color;
86 if(state.map_state.get_selected_province()) {
87 prov_color = get_religion_diaspora_color(state);
88 } else {
89 prov_color = get_religion_global_color(state);
90 }
91 return prov_color;
92}
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
uint uint32_t
std::vector< uint32_t > get_religion_global_color(sys::state &state)
Definition: religion.hpp:3
std::vector< uint32_t > get_religion_diaspora_color(sys::state &state)
Definition: religion.hpp:53
std::vector< uint32_t > religion_map_from(sys::state &state)
Definition: religion.hpp:84