Project Alice
Loading...
Searching...
No Matches
infrastructure.hpp
Go to the documentation of this file.
1#pragma once
2
3std::vector<uint32_t> infrastructure_map_from(sys::state& state) {
4 uint32_t province_size = state.world.province_size();
5 uint32_t texture_size = province_size + 256 - province_size % 256;
6
7 std::vector<uint32_t> prov_color(texture_size * 2);
8
9 int32_t max_rails_lvl = state.economy_definitions.building_definitions[int32_t(economy::province_building_type::railroad)].max_level;
10 state.world.for_each_province([&](dcon::province_id prov_id) {
11 auto nation = state.world.province_get_nation_from_province_ownership(prov_id);
12
13 int32_t current_rails_lvl = state.world.province_get_building_level(prov_id, uint8_t(economy::province_building_type::railroad));
14 int32_t max_local_rails_lvl = state.world.nation_get_max_building_level(state.local_player_nation, uint8_t(economy::province_building_type::railroad));
15 bool party_allows_building_railroads =
16 (nation == state.local_player_nation &&
17 (state.world.nation_get_combined_issue_rules(nation) & issue_rule::build_railway) != 0) ||
18 (nation != state.local_player_nation &&
19 (state.world.nation_get_combined_issue_rules(nation) & issue_rule::allow_foreign_investment) != 0);
20 uint32_t color;
21
22 if(party_allows_building_railroads) {
23
24 if(province::can_build_railroads(state, prov_id, state.local_player_nation)) {
25
26 color = ogl::color_gradient(float(current_rails_lvl) / float(max_rails_lvl), sys::pack_color(14, 240, 44), // green
27 sys::pack_color(41, 5, 245) // blue
28
29 );
30
31 } else if(current_rails_lvl == max_local_rails_lvl) {
32 color = sys::pack_color(232, 228, 111); // yellow
33 } else {
34 color = sys::pack_color(222, 7, 46); // red
35 }
36
37 } else {
38 color = sys::pack_color(222, 7, 46); // red
39 }
40 auto i = province::to_map_id(prov_id);
41
42 prov_color[i] = color;
43
44 if(province::has_railroads_being_built(state, prov_id)) {
45 prov_color[i + texture_size] = sys::pack_color(232, 228, 111); // yellow
46 } else {
47 prov_color[i + texture_size] = color;
48 }
49 });
50
51 return prov_color;
52}
std::vector< uint32_t > infrastructure_map_from(sys::state &state)
constexpr uint32_t build_railway
Definition: culture.hpp:38
constexpr uint32_t allow_foreign_investment
Definition: culture.hpp:26
uint32_t color_gradient(float percent, uint32_t top_color, uint32_t bot_color)
Definition: color.hpp:42
bool can_build_railroads(sys::state &state, dcon::province_id id, dcon::nation_id n)
Definition: province.cpp:330
bool has_railroads_being_built(sys::state &state, dcon::province_id id)
Definition: province.cpp:309
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
uchar uint8_t