Project Alice
Loading...
Searching...
No Matches
revolt.hpp
Go to the documentation of this file.
1#pragma once
2
3
4std::vector<uint32_t> revolt_map_from(sys::state& state) {
5 uint32_t province_size = state.world.province_size();
6 uint32_t texture_size = province_size + 256 - province_size % 256;
7 std::vector<uint32_t> prov_color(texture_size * 2);
8 auto sel_nation = state.world.province_get_nation_from_province_ownership(state.map_state.get_selected_province());
9 std::unordered_map<uint16_t, float> rebels_in_province = {};
10 std::unordered_map<int32_t, float> continent_max_rebels = {};
11 state.world.for_each_rebel_faction([&](dcon::rebel_faction_id id) {
12 auto rebellion = dcon::fatten(state.world, id);
13 if((sel_nation && sel_nation == rebellion.get_ruler_from_rebellion_within().id) || !sel_nation) {
14 for(auto members : state.world.rebel_faction_get_pop_rebellion_membership(id)) {
15 rebels_in_province[province::to_map_id(members.get_pop().get_province_from_pop_location().id)] += members.get_pop().get_size();
16 }
17 }
18 });
19 for(auto& [p, value] : rebels_in_province) {
20 auto pid = province::from_map_id(p);
21 auto cid = dcon::fatten(state.world, pid).get_continent().id.index();
22 continent_max_rebels[cid] = std::max(continent_max_rebels[cid], value);
23 }
24 state.world.for_each_province([&](dcon::province_id prov_id) {
25 auto nation = state.world.province_get_nation_from_province_ownership(prov_id);
26 if((sel_nation && nation == sel_nation) || !sel_nation) {
27 auto fat_id = dcon::fatten(state.world, prov_id);
28 auto i = province::to_map_id(prov_id);
29 auto cid = fat_id.get_continent().id.index();
30
31 uint32_t color = 0xDDDDDD; // white
32 if(rebels_in_province[i] > 0.0f) {
33 float gradient_index = (continent_max_rebels[cid] == 0.f ? 0.f : (rebels_in_province[i] / continent_max_rebels[cid]));
34 color = ogl::color_gradient(gradient_index,
35 sys::pack_color(247, 15, 15), // red
36 sys::pack_color(46, 247, 15) // green
37 );
38 }
39 prov_color[i] = color;
40 prov_color[i + texture_size] = color;
41 }
42 });
43 return prov_color;
44}
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
uint32_t color_gradient(float percent, uint32_t top_color, uint32_t bot_color)
Definition: color.hpp:42
constexpr dcon::province_id from_map_id(uint16_t id)
Definition: province.hpp:13
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 > revolt_map_from(sys::state &state)
Definition: revolt.hpp:4