Project Alice
Loading...
Searching...
No Matches
province.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "dcon_generated.hpp"
4#include "constants.hpp"
5
6namespace province {
7
8inline constexpr float world_circumference = 40075.0f / 10.0f; // in arbitrary units
9
10inline constexpr uint16_t to_map_id(dcon::province_id id) {
11 return uint16_t(id.index() + 1);
12}
13inline constexpr dcon::province_id from_map_id(uint16_t id) {
14 if(id == 0)
15 return dcon::province_id();
16 else
17 return dcon::province_id(id - 1);
18}
19
21 std::vector<dcon::province_adjacency_id> canals;
22 std::vector<dcon::province_id> canal_provinces;
23 ankerl::unordered_dense::map<dcon::modifier_id, dcon::gfx_object_id, sys::modifier_hash> terrain_to_gfx_map;
24 std::vector<bool> connected_region_is_coastal;
25
26 dcon::province_id first_sea_province;
27 dcon::modifier_id europe;
28 dcon::modifier_id asia;
29 dcon::modifier_id africa;
30 dcon::modifier_id north_america;
31 dcon::modifier_id south_america;
32 dcon::modifier_id oceania;
33};
34
35bool nations_are_adjacent(sys::state& state, dcon::nation_id a, dcon::nation_id b);
40void restore_distances(sys::state& state);
41
42bool is_overseas(sys::state const& state, dcon::province_id ids);
43bool can_integrate_colony(sys::state& state, dcon::state_instance_id id);
44dcon::province_id get_connected_province(sys::state& state, dcon::province_adjacency_id adj, dcon::province_id curr);
45float colony_integration_cost(sys::state& state, dcon::state_instance_id id);
46float state_accepted_bureaucrat_size(sys::state& state, dcon::state_instance_id id);
47
48// can we just do without this?
49// void update_state_administrative_efficiency(sys::state& state);
50
51bool has_railroads_being_built(sys::state& state, dcon::province_id id);
52bool can_build_railroads(sys::state& state, dcon::province_id id, dcon::nation_id n);
53bool generic_can_build_railroads(sys::state& state, dcon::province_id id, dcon::nation_id n);
54bool has_fort_being_built(sys::state& state, dcon::province_id id);
55bool can_build_fort(sys::state& state, dcon::province_id id, dcon::nation_id n);
56bool has_naval_base_being_built(sys::state& state, dcon::province_id id);
57bool can_build_naval_base(sys::state& state, dcon::province_id id, dcon::nation_id n);
59bool can_build_province_building(sys::state& state, dcon::province_id id, dcon::nation_id n, economy::province_building_type t);
60bool has_an_owner(sys::state& state, dcon::province_id id);
61bool state_is_coastal(sys::state& state, dcon::state_instance_id s);
62bool state_is_coastal_non_core_nb(sys::state& state, dcon::state_instance_id s);
63bool state_borders_nation(sys::state& state, dcon::nation_id n, dcon::state_instance_id si);
64
65dcon::province_id pick_capital(sys::state& state, dcon::nation_id n);
66
67float land_maximum_employment(sys::state& state, dcon::province_id id);
68float land_employment(sys::state& state, dcon::province_id id);
69float rgo_maximum_employment(sys::state& state, dcon::province_id id);
70float rgo_employment(sys::state& state, dcon::province_id id);
71float rgo_income(sys::state& state, dcon::province_id id);
72float rgo_production_quantity(sys::state& state, dcon::province_id id, dcon::commodity_id c);
73float rgo_size(sys::state& state, dcon::province_id prov_id);
74float state_admin_efficiency(sys::state& state, dcon::state_instance_id id);
75float crime_fighting_efficiency(sys::state& state, dcon::province_id id);
76float revolt_risk(sys::state& state, dcon::province_id id);
77
78void change_province_owner(sys::state& state, dcon::province_id id, dcon::nation_id new_owner);
79void conquer_province(sys::state& state, dcon::province_id id, dcon::nation_id new_owner);
80
81void update_crimes(sys::state& state);
83
84bool can_start_colony(sys::state& state, dcon::nation_id n, dcon::state_definition_id d);
85bool fast_can_start_colony(sys::state& state, dcon::nation_id n, dcon::state_definition_id d, int32_t free_points, dcon::province_id coastal_target, bool& adjacent);
86bool can_invest_in_colony(sys::state& state, dcon::nation_id n, dcon::state_definition_id d);
87bool is_colonizing(sys::state& state, dcon::nation_id n, dcon::state_definition_id d);
89void increase_colonial_investment(sys::state& state, dcon::nation_id source, dcon::state_definition_id state_def);
90
91void add_core(sys::state& state, dcon::province_id prov, dcon::national_identity_id tag);
92void remove_core(sys::state& state, dcon::province_id prov, dcon::national_identity_id tag);
93void set_rgo(sys::state& state, dcon::province_id prov, dcon::commodity_id c);
94void enable_canal(sys::state& state, int32_t id);
95void upgrade_colonial_state(sys::state& state, dcon::nation_id owner, dcon::state_instance_id si);
96
97// distance from a state to a given province (does not pathfind)
98float state_distance(sys::state& state, dcon::state_instance_id state_id, dcon::province_id prov_id);
99// distance between to adjacent provinces
100float distance(sys::state& state, dcon::province_adjacency_id pair);
101// direct distance between two provinces; does not pathfind
102float direct_distance(sys::state& state, dcon::province_id a, dcon::province_id b);
103// sorting distance returns values such that a smaller sorting distance between two provinces
104// means that they are closer, but does not translate 1 to 1 to actual distances (i.e. is the negative dot product)
105float sorting_distance(sys::state& state, dcon::province_id a, dcon::province_id b);
106float state_sorting_distance(sys::state& state, dcon::state_instance_id state_id, dcon::province_id prov_id);
107
108// determines whether a land unit is allowed to move to / be in a province
109bool has_access_to_province(sys::state& state, dcon::nation_id nation_as, dcon::province_id prov);
110// whether a ship can dock at a land province
111bool has_naval_access_to_province(sys::state& state, dcon::nation_id nation_as, dcon::province_id prov);
112// determines whether a land unit is allowed to move to / be in a province that isn't an active enemy
113bool has_safe_access_to_province(sys::state& state, dcon::nation_id nation_as, dcon::province_id prov);
114
115//
116// when pathfinding, check that the destination province is valid on its own (i.e. accessible for normal, or embark-able for sea)
117//
118
119// normal pathfinding
120std::vector<dcon::province_id> make_land_path(sys::state& state, dcon::province_id start, dcon::province_id end, dcon::nation_id nation_as, dcon::army_id a);
121// pathfind through non-enemy controlled, not under siege provinces
122std::vector<dcon::province_id> make_safe_land_path(sys::state& state, dcon::province_id start, dcon::province_id end, dcon::nation_id nation_as);
123// used for rebel unit and black-flagged unit pathfinding
124std::vector<dcon::province_id> make_unowned_land_path(sys::state& state, dcon::province_id start, dcon::province_id end);
125// naval unit pathfinding; start and end provinces may be land provinces; function assumes you have naval access to both
126std::vector<dcon::province_id> make_naval_path(sys::state& state, dcon::province_id start, dcon::province_id end);
127
128std::vector<dcon::province_id> make_naval_retreat_path(sys::state& state, dcon::nation_id nation_as, dcon::province_id start);
129std::vector<dcon::province_id> make_land_retreat_path(sys::state& state, dcon::nation_id nation_as, dcon::province_id start);
130
131std::vector<dcon::province_id> make_path_to_nearest_coast(sys::state& state, dcon::nation_id nation_as, dcon::province_id start);
132std::vector<dcon::province_id> make_unowned_path_to_nearest_coast(sys::state& state, dcon::province_id start);
133
134void set_province_controller(sys::state& state, dcon::province_id p, dcon::nation_id n);
135void set_province_controller(sys::state& state, dcon::province_id p, dcon::rebel_faction_id rf);
136
137} // namespace province
province_building_type
Definition: constants.hpp:578
std::vector< dcon::province_id > make_land_path(sys::state &state, dcon::province_id start, dcon::province_id end, dcon::nation_id nation_as, dcon::army_id a)
Definition: province.cpp:1673
float direct_distance(sys::state &state, dcon::province_id a, dcon::province_id b)
Definition: province.cpp:1555
float sorting_distance(sys::state &state, dcon::province_id a, dcon::province_id b)
Definition: province.cpp:1562
void upgrade_colonial_state(sys::state &state, dcon::nation_id source, dcon::state_instance_id si)
Definition: province.cpp:629
float state_sorting_distance(sys::state &state, dcon::state_instance_id state_id, dcon::province_id prov_id)
Definition: province.cpp:589
bool has_an_owner(sys::state &state, dcon::province_id id)
Definition: province.cpp:452
bool can_build_railroads(sys::state &state, dcon::province_id id, dcon::nation_id n)
Definition: province.cpp:330
void update_connected_regions(sys::state &state)
Definition: province.cpp:29
void update_blockaded_cache(sys::state &state)
Definition: province.cpp:264
void update_nationalism(sys::state &state)
Definition: province.cpp:957
void update_crimes(sys::state &state)
Definition: province.cpp:965
std::vector< dcon::province_id > make_safe_land_path(sys::state &state, dcon::province_id start, dcon::province_id end, dcon::nation_id nation_as)
Definition: province.cpp:1740
std::vector< dcon::province_id > make_naval_retreat_path(sys::state &state, dcon::nation_id nation_as, dcon::province_id start)
Definition: province.cpp:1932
bool has_access_to_province(sys::state &state, dcon::nation_id nation_as, dcon::province_id prov)
Definition: province.cpp:1597
bool has_naval_base_being_built(sys::state &state, dcon::province_id id)
Definition: province.cpp:384
void enable_canal(sys::state &state, int32_t id)
Definition: province.cpp:1545
void add_core(sys::state &state, dcon::province_id prov, dcon::national_identity_id tag)
Definition: province.cpp:1504
float state_distance(sys::state &state, dcon::state_instance_id state_id, dcon::province_id prov_id)
Definition: province.cpp:585
bool is_overseas(sys::state const &state, dcon::province_id ids)
Definition: province.cpp:18
bool has_safe_access_to_province(sys::state &state, dcon::nation_id nation_as, dcon::province_id prov)
Definition: province.cpp:1626
void remove_core(sys::state &state, dcon::province_id prov, dcon::national_identity_id tag)
Definition: province.cpp:1514
bool is_colonizing(sys::state &state, dcon::nation_id n, dcon::state_definition_id d)
Definition: province.cpp:1014
constexpr dcon::province_id from_map_id(uint16_t id)
Definition: province.hpp:13
bool can_build_province_building(sys::state &state, dcon::province_id id, dcon::nation_id n, economy::province_building_type t)
Definition: province.cpp:418
float state_accepted_bureaucrat_size(sys::state &state, dcon::state_instance_id id)
Definition: province.cpp:490
void set_rgo(sys::state &state, dcon::province_id prov, dcon::commodity_id c)
Definition: province.cpp:1525
std::vector< dcon::province_id > make_path_to_nearest_coast(sys::state &state, dcon::nation_id nation_as, dcon::province_id start)
Definition: province.cpp:2036
float distance(sys::state &state, dcon::province_adjacency_id pair)
Definition: province.cpp:1550
bool has_province_building_being_built(sys::state &state, dcon::province_id id, economy::province_building_type t)
Definition: province.cpp:410
float rgo_employment(sys::state &state, dcon::province_id id)
Definition: province.cpp:467
bool can_integrate_colony(sys::state &state, dcon::state_instance_id id)
Definition: province.cpp:593
std::vector< dcon::province_id > make_land_retreat_path(sys::state &state, dcon::nation_id nation_as, dcon::province_id start)
Definition: province.cpp:1986
void restore_unsaved_values(sys::state &state)
Definition: province.cpp:280
bool fast_can_start_colony(sys::state &state, dcon::nation_id n, dcon::state_definition_id d, int32_t free_points, dcon::province_id coastal_target, bool &adjacent)
Definition: province.cpp:1223
float rgo_production_quantity(sys::state &state, dcon::province_id id, dcon::commodity_id c)
Definition: province.cpp:473
float crime_fighting_efficiency(sys::state &state, dcon::province_id id)
Definition: province.cpp:536
bool state_is_coastal(sys::state &state, dcon::state_instance_id s)
Definition: province.cpp:1476
float rgo_maximum_employment(sys::state &state, dcon::province_id id)
Definition: province.cpp:463
bool has_railroads_being_built(sys::state &state, dcon::province_id id)
Definition: province.cpp:309
float land_maximum_employment(sys::state &state, dcon::province_id id)
Definition: province.cpp:455
bool can_build_fort(sys::state &state, dcon::province_id id, dcon::nation_id n)
Definition: province.cpp:370
bool can_start_colony(sys::state &state, dcon::nation_id n, dcon::state_definition_id d)
Definition: province.cpp:1097
float rgo_size(sys::state &state, dcon::province_id prov_id)
Definition: province.cpp:477
void update_cached_values(sys::state &state)
Definition: province.cpp:255
std::vector< dcon::province_id > make_naval_path(sys::state &state, dcon::province_id start, dcon::province_id end)
Definition: province.cpp:1848
std::vector< dcon::province_id > make_unowned_land_path(sys::state &state, dcon::province_id start, dcon::province_id end)
Definition: province.cpp:1798
bool can_invest_in_colony(sys::state &state, dcon::nation_id n, dcon::state_definition_id d)
Definition: province.cpp:1023
void set_province_controller(sys::state &state, dcon::province_id p, dcon::nation_id n)
Definition: province.cpp:107
void update_colonization(sys::state &state)
Definition: province.cpp:1386
float land_employment(sys::state &state, dcon::province_id id)
Definition: province.cpp:459
bool has_naval_access_to_province(sys::state &state, dcon::nation_id nation_as, dcon::province_id prov)
Definition: province.cpp:1570
float rgo_income(sys::state &state, dcon::province_id id)
Definition: province.cpp:470
void conquer_province(sys::state &state, dcon::province_id id, dcon::nation_id new_owner)
Definition: province.cpp:907
constexpr float world_circumference
Definition: province.hpp:8
bool state_is_coastal_non_core_nb(sys::state &state, dcon::state_instance_id s)
Definition: province.cpp:1488
bool has_fort_being_built(sys::state &state, dcon::province_id id)
Definition: province.cpp:363
bool nations_are_adjacent(sys::state &state, dcon::nation_id a, dcon::nation_id b)
Definition: province.cpp:25
bool can_build_naval_base(sys::state &state, dcon::province_id id, dcon::nation_id n)
Definition: province.cpp:391
dcon::province_id get_connected_province(sys::state &state, dcon::province_adjacency_id adj, dcon::province_id curr)
Definition: province.cpp:571
float revolt_risk(sys::state &state, dcon::province_id id)
Definition: province.cpp:561
float colony_integration_cost(sys::state &state, dcon::state_instance_id id)
Definition: province.cpp:609
float state_admin_efficiency(sys::state &state, dcon::state_instance_id id)
Definition: province.cpp:503
void change_province_owner(sys::state &state, dcon::province_id id, dcon::nation_id new_owner)
Definition: province.cpp:666
constexpr uint16_t to_map_id(dcon::province_id id)
Definition: province.hpp:10
std::vector< dcon::province_id > make_unowned_path_to_nearest_coast(sys::state &state, dcon::province_id start)
Definition: province.cpp:2088
dcon::province_id pick_capital(sys::state &state, dcon::nation_id n)
Definition: province.cpp:89
void restore_distances(sys::state &state)
Definition: province.cpp:2137
bool state_borders_nation(sys::state &state, dcon::nation_id n, dcon::state_instance_id si)
Definition: province.cpp:1079
void increase_colonial_investment(sys::state &state, dcon::nation_id source, dcon::state_definition_id state_def)
Definition: province.cpp:1323
bool generic_can_build_railroads(sys::state &state, dcon::province_id id, dcon::nation_id n)
Definition: province.cpp:317
dcon::modifier_id south_america
Definition: province.hpp:31
std::vector< bool > connected_region_is_coastal
Definition: province.hpp:24
ankerl::unordered_dense::map< dcon::modifier_id, dcon::gfx_object_id, sys::modifier_hash > terrain_to_gfx_map
Definition: province.hpp:23
std::vector< dcon::province_adjacency_id > canals
Definition: province.hpp:21
dcon::province_id first_sea_province
Definition: province.hpp:26
dcon::modifier_id north_america
Definition: province.hpp:30
std::vector< dcon::province_id > canal_provinces
Definition: province.hpp:22