Project Alice
Loading...
Searching...
No Matches
rank.hpp
Go to the documentation of this file.
1#pragma once
2
3std::vector<uint32_t> rank_map_from(sys::state& state) {
4 // These colors are arbitrary
5 // 1 to 8 -> green #30f233
6 // 9 to 16 -> blue #242fff
7 // under 16 but civilized -> yellow #eefc26
8 // under 16 but uncivilized -> red #ff2626
9
10 uint32_t province_size = state.world.province_size();
11 uint32_t texture_size = province_size + 256 - province_size % 256;
12
13 std::vector<uint32_t> prov_color(texture_size * 2);
14
15 auto num_nations = state.world.nation_size();
16 auto unciv_rank = num_nations;
17 for(uint32_t i = 0; i < num_nations; ++i) {
18 if(!state.world.nation_get_is_civilized(state.nations_by_rank[i])) {
19 unciv_rank = i;
20 break;
21 }
22 }
23
24 state.world.for_each_province([&](dcon::province_id prov_id) {
25 auto fat_id = dcon::fatten(state.world, prov_id);
26
27 auto nation_id = fat_id.get_nation_from_province_ownership();
28 auto status = nations::get_status(state, nation_id);
29
30 float darkness = 0.0f;
32 darkness = 1.0f - 0.7f * (state.world.nation_get_rank(nation_id)) / state.defines.great_nations_count;
33 else if(status == nations::status::secondary_power)
34 darkness = 1.0f - 0.7f * (state.world.nation_get_rank(nation_id) - state.defines.great_nations_count) /
35 (state.defines.colonial_rank - state.defines.great_nations_count);
36 else if(status == nations::status::civilized)
37 darkness = 1.0f - 0.7f * (state.world.nation_get_rank(nation_id) - state.defines.colonial_rank) /
38 std::max(1.0f, (float(unciv_rank) - state.defines.colonial_rank));
39 else
40 darkness = 1.0f - 0.7f * (state.world.nation_get_rank(nation_id) - unciv_rank) /
41 std::max(1.0f, (float(num_nations) - float(unciv_rank)));
42
43 uint32_t color;
44 if(bool(nation_id)) {
45 switch(status) {
47 color = sys::pack_color(int32_t(48 * darkness), int32_t(242 * darkness), int32_t(51 * darkness));
48 break;
49
51 color = sys::pack_color(int32_t(36 * darkness), int32_t(47 * darkness), int32_t(255 * darkness));
52 break;
53
55 color = sys::pack_color(int32_t(238 * darkness), int32_t(252 * darkness), int32_t(38 * darkness));
56 break;
57
58 // primitive, uncivilized and westernized
59 default:
60 color = sys::pack_color(int32_t(250 * darkness), int32_t(5 * darkness), int32_t(5 * darkness));
61 break;
62 }
63 } else { // If no owner use default color
64 color = 255 << 16 | 255 << 8 | 255;
65 }
66
67 auto i = province::to_map_id(prov_id);
68
69 prov_color[i] = color;
70 prov_color[i + texture_size] = color;
71 });
72 return prov_color;
73}
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
status get_status(sys::state &state, dcon::nation_id n)
Definition: nations.cpp:580
constexpr uint16_t to_map_id(dcon::province_id id)
Definition: province.hpp:10
uint32_t pack_color(float r, float g, float b)
uint uint32_t
std::vector< uint32_t > rank_map_from(sys::state &state)
Definition: rank.hpp:3