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);
61dcon::province_id state_get_coastal_capital(sys::state& state, dcon::state_instance_id s);
62bool state_is_coastal(sys::state& state, dcon::state_instance_id s);
63bool state_is_coastal_non_core_nb(sys::state& state, dcon::state_instance_id s);
64bool state_borders_nation(sys::state& state, dcon::nation_id n, dcon::state_instance_id si);
65
66dcon::province_id pick_capital(sys::state& state, dcon::nation_id n);
67
68float land_maximum_employment(sys::state& state, dcon::province_id id);
69float land_employment(sys::state& state, dcon::province_id id);
70float rgo_maximum_employment(sys::state& state, dcon::province_id id);
71float rgo_employment(sys::state& state, dcon::province_id id);
72float rgo_income(sys::state& state, dcon::province_id id);
73float rgo_production_quantity(sys::state& state, dcon::province_id id, dcon::commodity_id c);
74float rgo_size(sys::state& state, dcon::province_id prov_id);
75float state_admin_efficiency(sys::state& state, dcon::state_instance_id id);
76float crime_fighting_efficiency(sys::state& state, dcon::province_id id);
77float revolt_risk(sys::state& state, dcon::province_id id);
78
79void change_province_owner(sys::state& state, dcon::province_id id, dcon::nation_id new_owner);
80void conquer_province(sys::state& state, dcon::province_id id, dcon::nation_id new_owner);
81
82void update_crimes(sys::state& state);
84
85bool can_start_colony(sys::state& state, dcon::nation_id n, dcon::state_definition_id d);
86bool 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);
87bool can_invest_in_colony(sys::state& state, dcon::nation_id n, dcon::state_definition_id d);
88bool is_colonizing(sys::state& state, dcon::nation_id n, dcon::state_definition_id d);
90void increase_colonial_investment(sys::state& state, dcon::nation_id source, dcon::state_definition_id state_def);
91
92void add_core(sys::state& state, dcon::province_id prov, dcon::national_identity_id tag);
93void remove_core(sys::state& state, dcon::province_id prov, dcon::national_identity_id tag);
94void set_rgo(sys::state& state, dcon::province_id prov, dcon::commodity_id c);
95void enable_canal(sys::state& state, int32_t id);
96void upgrade_colonial_state(sys::state& state, dcon::nation_id owner, dcon::state_instance_id si);
97
98// distance from a state to a given province (does not pathfind)
99float state_distance(sys::state& state, dcon::state_instance_id state_id, dcon::province_id prov_id);
100// distance between to adjacent provinces
101float distance(sys::state& state, dcon::province_adjacency_id pair);
102// direct distance between two provinces; does not pathfind
103float direct_distance(sys::state& state, dcon::province_id a, dcon::province_id b);
104// sorting distance returns values such that a smaller sorting distance between two provinces
105// means that they are closer, but does not translate 1 to 1 to actual distances (i.e. is the negative dot product)
106float sorting_distance(sys::state& state, dcon::province_id a, dcon::province_id b);
107float state_sorting_distance(sys::state& state, dcon::state_instance_id state_id, dcon::province_id prov_id);
108
109// determines whether a land unit is allowed to move to / be in a province
110bool has_access_to_province(sys::state& state, dcon::nation_id nation_as, dcon::province_id prov);
111// whether a ship can dock at a land province
112bool has_naval_access_to_province(sys::state& state, dcon::nation_id nation_as, dcon::province_id prov);
113// determines whether a land unit is allowed to move to / be in a province that isn't an active enemy
114bool has_safe_access_to_province(sys::state& state, dcon::nation_id nation_as, dcon::province_id prov);
115
116//
117// when pathfinding, check that the destination province is valid on its own (i.e. accessible for normal, or embark-able for sea)
118//
119
120// normal pathfinding
121std::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);
122// pathfind through non-enemy controlled, not under siege provinces
123std::vector<dcon::province_id> make_safe_land_path(sys::state& state, dcon::province_id start, dcon::province_id end, dcon::nation_id nation_as);
124std::vector<dcon::province_id> make_unowned_path(sys::state& state, dcon::province_id start, dcon::province_id end);
125// used for rebel unit and black-flagged unit pathfinding
126std::vector<dcon::province_id> make_unowned_land_path(sys::state& state, dcon::province_id start, dcon::province_id end);
127// naval unit pathfinding; start and end provinces may be land provinces; function assumes you have naval access to both
128std::vector<dcon::province_id> make_naval_path(sys::state& state, dcon::province_id start, dcon::province_id end);
129
130std::vector<dcon::province_id> make_naval_retreat_path(sys::state& state, dcon::nation_id nation_as, dcon::province_id start);
131std::vector<dcon::province_id> make_land_retreat_path(sys::state& state, dcon::nation_id nation_as, dcon::province_id start);
132
133std::vector<dcon::province_id> make_path_to_nearest_coast(sys::state& state, dcon::nation_id nation_as, dcon::province_id start);
134std::vector<dcon::province_id> make_unowned_path_to_nearest_coast(sys::state& state, dcon::province_id start);
135
136void set_province_controller(sys::state& state, dcon::province_id p, dcon::nation_id n);
137void set_province_controller(sys::state& state, dcon::province_id p, dcon::rebel_faction_id rf);
138
139} // 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:1863
dcon::province_id state_get_coastal_capital(sys::state &state, dcon::state_instance_id s)
Definition: province.cpp:1640
float direct_distance(sys::state &state, dcon::province_id a, dcon::province_id b)
Definition: province.cpp:1745
float sorting_distance(sys::state &state, dcon::province_id a, dcon::province_id b)
Definition: province.cpp:1752
void upgrade_colonial_state(sys::state &state, dcon::nation_id source, dcon::state_instance_id si)
Definition: province.cpp:679
float state_sorting_distance(sys::state &state, dcon::state_instance_id state_id, dcon::province_id prov_id)
Definition: province.cpp:639
bool has_an_owner(sys::state &state, dcon::province_id id)
Definition: province.cpp:502
bool can_build_railroads(sys::state &state, dcon::province_id id, dcon::nation_id n)
Definition: province.cpp:380
void update_connected_regions(sys::state &state)
Definition: province.cpp:30
void update_blockaded_cache(sys::state &state)
Definition: province.cpp:314
void update_nationalism(sys::state &state)
Definition: province.cpp:1113
void update_crimes(sys::state &state)
Definition: province.cpp:1121
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:1930
std::vector< dcon::province_id > make_naval_retreat_path(sys::state &state, dcon::nation_id nation_as, dcon::province_id start)
Definition: province.cpp:2178
bool has_access_to_province(sys::state &state, dcon::nation_id nation_as, dcon::province_id prov)
Definition: province.cpp:1787
bool has_naval_base_being_built(sys::state &state, dcon::province_id id)
Definition: province.cpp:434
void enable_canal(sys::state &state, int32_t id)
Definition: province.cpp:1735
void add_core(sys::state &state, dcon::province_id prov, dcon::national_identity_id tag)
Definition: province.cpp:1694
float state_distance(sys::state &state, dcon::state_instance_id state_id, dcon::province_id prov_id)
Definition: province.cpp:635
bool is_overseas(sys::state const &state, dcon::province_id ids)
Definition: province.cpp:19
bool has_safe_access_to_province(sys::state &state, dcon::nation_id nation_as, dcon::province_id prov)
Definition: province.cpp:1816
void remove_core(sys::state &state, dcon::province_id prov, dcon::national_identity_id tag)
Definition: province.cpp:1704
bool is_colonizing(sys::state &state, dcon::nation_id n, dcon::state_definition_id d)
Definition: province.cpp:1170
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:468
float state_accepted_bureaucrat_size(sys::state &state, dcon::state_instance_id id)
Definition: province.cpp:540
void set_rgo(sys::state &state, dcon::province_id prov, dcon::commodity_id c)
Definition: province.cpp:1715
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:2282
float distance(sys::state &state, dcon::province_adjacency_id pair)
Definition: province.cpp:1740
bool has_province_building_being_built(sys::state &state, dcon::province_id id, economy::province_building_type t)
Definition: province.cpp:460
float rgo_employment(sys::state &state, dcon::province_id id)
Definition: province.cpp:517
bool can_integrate_colony(sys::state &state, dcon::state_instance_id id)
Definition: province.cpp:643
std::vector< dcon::province_id > make_land_retreat_path(sys::state &state, dcon::nation_id nation_as, dcon::province_id start)
Definition: province.cpp:2232
void restore_unsaved_values(sys::state &state)
Definition: province.cpp:330
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:1384
float rgo_production_quantity(sys::state &state, dcon::province_id id, dcon::commodity_id c)
Definition: province.cpp:523
float crime_fighting_efficiency(sys::state &state, dcon::province_id id)
Definition: province.cpp:586
bool state_is_coastal(sys::state &state, dcon::state_instance_id s)
Definition: province.cpp:1666
float rgo_maximum_employment(sys::state &state, dcon::province_id id)
Definition: province.cpp:513
bool has_railroads_being_built(sys::state &state, dcon::province_id id)
Definition: province.cpp:359
float land_maximum_employment(sys::state &state, dcon::province_id id)
Definition: province.cpp:505
bool can_build_fort(sys::state &state, dcon::province_id id, dcon::nation_id n)
Definition: province.cpp:420
bool can_start_colony(sys::state &state, dcon::nation_id n, dcon::state_definition_id d)
Definition: province.cpp:1255
float rgo_size(sys::state &state, dcon::province_id prov_id)
Definition: province.cpp:527
void update_cached_values(sys::state &state)
Definition: province.cpp:305
std::vector< dcon::province_id > make_naval_path(sys::state &state, dcon::province_id start, dcon::province_id end)
Definition: province.cpp:2094
std::vector< dcon::province_id > make_unowned_land_path(sys::state &state, dcon::province_id start, dcon::province_id end)
Definition: province.cpp:2044
std::vector< dcon::province_id > make_unowned_path(sys::state &state, dcon::province_id start, dcon::province_id end)
Definition: province.cpp:1988
bool can_invest_in_colony(sys::state &state, dcon::nation_id n, dcon::state_definition_id d)
Definition: province.cpp:1179
void set_province_controller(sys::state &state, dcon::province_id p, dcon::nation_id n)
Definition: province.cpp:157
void update_colonization(sys::state &state)
Definition: province.cpp:1550
float land_employment(sys::state &state, dcon::province_id id)
Definition: province.cpp:509
bool has_naval_access_to_province(sys::state &state, dcon::nation_id nation_as, dcon::province_id prov)
Definition: province.cpp:1760
float rgo_income(sys::state &state, dcon::province_id id)
Definition: province.cpp:520
void conquer_province(sys::state &state, dcon::province_id id, dcon::nation_id new_owner)
Definition: province.cpp:1064
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:1678
bool has_fort_being_built(sys::state &state, dcon::province_id id)
Definition: province.cpp:413
bool nations_are_adjacent(sys::state &state, dcon::nation_id a, dcon::nation_id b)
Definition: province.cpp:26
bool can_build_naval_base(sys::state &state, dcon::province_id id, dcon::nation_id n)
Definition: province.cpp:441
dcon::province_id get_connected_province(sys::state &state, dcon::province_adjacency_id adj, dcon::province_id curr)
Definition: province.cpp:621
float revolt_risk(sys::state &state, dcon::province_id id)
Definition: province.cpp:611
float colony_integration_cost(sys::state &state, dcon::state_instance_id id)
Definition: province.cpp:659
float state_admin_efficiency(sys::state &state, dcon::state_instance_id id)
Definition: province.cpp:553
void change_province_owner(sys::state &state, dcon::province_id id, dcon::nation_id new_owner)
Definition: province.cpp:716
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:2334
dcon::province_id pick_capital(sys::state &state, dcon::nation_id n)
Definition: province.cpp:139
void restore_distances(sys::state &state)
Definition: province.cpp:2383
bool state_borders_nation(sys::state &state, dcon::nation_id n, dcon::state_instance_id si)
Definition: province.cpp:1237
void increase_colonial_investment(sys::state &state, dcon::nation_id source, dcon::state_definition_id state_def)
Definition: province.cpp:1487
bool generic_can_build_railroads(sys::state &state, dcon::province_id id, dcon::nation_id n)
Definition: province.cpp:367
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
Holds important data about the game world, state, and other data regarding windowing,...