Project Alice
Loading...
Searching...
No Matches
population.hpp
Go to the documentation of this file.
1#pragma once
2
3std::vector<uint32_t> get_global_population_color(sys::state& state) {
4 std::vector<float> prov_population(state.world.province_size() + 1);
5 std::unordered_map<int32_t, float> continent_max_pop = {};
6
7 state.world.for_each_province([&](dcon::province_id prov_id) {
8 auto fat_id = dcon::fatten(state.world, prov_id);
9 float population = state.world.province_get_demographics(prov_id, demographics::total);
10 auto cid = fat_id.get_continent().id.index();
11 continent_max_pop[cid] = std::max(continent_max_pop[cid], population);
12 auto i = province::to_map_id(prov_id);
13 prov_population[i] = population;
14 });
15
16 uint32_t province_size = state.world.province_size() + 1;
17 uint32_t texture_size = province_size + 256 - province_size % 256;
18
19 std::vector<uint32_t> prov_color(texture_size * 2);
20
21 state.world.for_each_province([&](dcon::province_id prov_id) {
22 auto fat_id = dcon::fatten(state.world, prov_id);
23 auto cid = fat_id.get_continent().id.index();
24 auto i = province::to_map_id(prov_id);
25 float gradient_index = prov_population[i] / continent_max_pop[cid];
26
27 auto color = ogl::color_gradient(gradient_index, 210, 100 << 8);
28 prov_color[i] = color;
29 prov_color[i + texture_size] = color;
30 });
31
32 return prov_color;
33}
34
35std::vector<uint32_t> get_national_population_color(sys::state& state) {
36 auto fat_selected_id = dcon::fatten(state.world, state.map_state.get_selected_province());
37 auto nat_id = fat_selected_id.get_nation_from_province_ownership();
38 if(!bool(nat_id)) {
39 return get_global_population_color(state);
40 }
41 float max_population = 0.f;
42 std::vector<float> prov_population(state.world.province_size() + 1);
43
44 state.world.for_each_province([&](dcon::province_id prov_id) {
45 auto fat_id = dcon::fatten(state.world, prov_id);
46 auto i = province::to_map_id(prov_id);
47 if(fat_id.get_nation_from_province_ownership().id == nat_id.id) {
48 float population = state.world.province_get_demographics(prov_id, demographics::total);
49 max_population = std::max(max_population, population);
50 prov_population[i] = population;
51 } else {
52 prov_population[i] = -1.f;
53 }
54 });
55
56 uint32_t province_size = state.world.province_size() + 1;
57 uint32_t texture_size = province_size + 256 - province_size % 256;
58
59 std::vector<uint32_t> prov_color(texture_size * 2);
60
61 for(size_t i = 0; i < prov_population.size(); i++) {
62 uint32_t color = 0xFFAAAAAA;
63 if(prov_population[i] > -1.f) {
64 float gradient_index = prov_population[i] / max_population;
65 color = ogl::color_gradient(gradient_index, 210, 100 << 8);
66 }
67 prov_color[i] = color;
68 prov_color[i + texture_size] = color;
69 }
70
71 return prov_color;
72}
73
74std::vector<uint32_t> population_map_from(sys::state& state) {
75 std::vector<uint32_t> prov_color;
76 if(state.map_state.get_selected_province()) {
77 prov_color = get_national_population_color(state);
78 } else {
79 prov_color = get_global_population_color(state);
80 }
81
82 return prov_color;
83}
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
constexpr dcon::demographics_key total(0)
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 > population_map_from(sys::state &state)
Definition: population.hpp:74
std::vector< uint32_t > get_global_population_color(sys::state &state)
Definition: population.hpp:3
std::vector< uint32_t > get_national_population_color(sys::state &state)
Definition: population.hpp:35