aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/map')
-rw-r--r--src/openvic-simulation/map/Map.cpp12
-rw-r--r--src/openvic-simulation/map/Map.hpp14
-rw-r--r--src/openvic-simulation/map/Province.cpp3
-rw-r--r--src/openvic-simulation/map/Province.hpp1
-rw-r--r--src/openvic-simulation/map/State.cpp114
-rw-r--r--src/openvic-simulation/map/State.hpp13
-rw-r--r--src/openvic-simulation/map/TerrainType.cpp1
7 files changed, 74 insertions, 84 deletions
diff --git a/src/openvic-simulation/map/Map.cpp b/src/openvic-simulation/map/Map.cpp
index 549e539..f854cab 100644
--- a/src/openvic-simulation/map/Map.cpp
+++ b/src/openvic-simulation/map/Map.cpp
@@ -141,14 +141,6 @@ bool Map::add_region(std::string_view identifier, std::vector<std::string_view>
return ret;
}
-Province* Map::get_province_by_index(Province::index_t index) {
- return index != Province::NULL_INDEX ? provinces.get_item_by_index(index - 1) : nullptr;
-}
-
-Province const* Map::get_province_by_index(Province::index_t index) const {
- return index != Province::NULL_INDEX ? provinces.get_item_by_index(index - 1) : nullptr;
-}
-
Province::index_t Map::get_index_from_colour(colour_t colour) const {
const colour_index_map_t::const_iterator it = colour_index_map.find(colour);
if (it != colour_index_map.end()) {
@@ -229,10 +221,6 @@ bool Map::add_mapmode(std::string_view identifier, Mapmode::colour_func_t colour
return mapmodes.add_item({ identifier, mapmodes.size(), colour_func });
}
-Mapmode const* Map::get_mapmode_by_index(size_t index) const {
- return mapmodes.get_item_by_index(index);
-}
-
bool Map::generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) const {
if (target == nullptr) {
Logger::error("Mapmode colour target pointer is null!");
diff --git a/src/openvic-simulation/map/Map.hpp b/src/openvic-simulation/map/Map.hpp
index cef0962..f286276 100644
--- a/src/openvic-simulation/map/Map.hpp
+++ b/src/openvic-simulation/map/Map.hpp
@@ -57,7 +57,7 @@ namespace OpenVic {
IdentifierRegistry<Region> regions;
IdentifierRegistry<Mapmode> mapmodes;
ProvinceSet water_provinces;
- TerrainTypeManager terrain_type_manager;
+ TerrainTypeManager PROPERTY_REF(terrain_type_manager);
size_t width = 0, height = 0;
std::vector<shape_pixel_t> province_shape_image;
@@ -70,21 +70,19 @@ namespace OpenVic {
Province::index_t get_index_from_colour(colour_t colour) const;
bool _generate_province_adjacencies();
- StateManager state_manager;
+ StateManager PROPERTY_REF(state_manager);
public:
Map();
bool add_province(std::string_view identifier, colour_t colour);
- IDENTIFIER_REGISTRY_ACCESSORS(province)
- IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS(province)
+ IDENTIFIER_REGISTRY_ACCESSORS_CUSTOM_INDEX_OFFSET(province, 1)
+ IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS_CUSTOM_INDEX_OFFSET(province, 1);
bool set_water_province(std::string_view identifier);
bool set_water_province_list(std::vector<std::string_view> const& list);
void lock_water_provinces();
- Province* get_province_by_index(Province::index_t index);
- Province const* get_province_by_index(Province::index_t index) const;
Province::index_t get_province_index_at(size_t x, size_t y) const;
bool set_max_provinces(Province::index_t new_max_provinces);
Province::index_t get_max_provinces() const;
@@ -95,7 +93,6 @@ namespace OpenVic {
size_t get_width() const;
size_t get_height() const;
std::vector<shape_pixel_t> const& get_province_shape_image() const;
- REF_GETTERS(terrain_type_manager)
bool add_region(std::string_view identifier, std::vector<std::string_view> const& province_identifiers);
IDENTIFIER_REGISTRY_ACCESSORS(region)
@@ -103,9 +100,6 @@ namespace OpenVic {
bool add_mapmode(std::string_view identifier, Mapmode::colour_func_t colour_func);
IDENTIFIER_REGISTRY_ACCESSORS(mapmode)
- Mapmode const* get_mapmode_by_index(size_t index) const;
-
- REF_GETTERS(state_manager);
/* The mapmode colour image contains of a list of base colours and stripe colours. Each colour is four bytes
* in RGBA format, with the alpha value being used to interpolate with the terrain colour, so A = 0 is fully terrain
diff --git a/src/openvic-simulation/map/Province.cpp b/src/openvic-simulation/map/Province.cpp
index 7277a54..201d3a0 100644
--- a/src/openvic-simulation/map/Province.cpp
+++ b/src/openvic-simulation/map/Province.cpp
@@ -10,7 +10,8 @@ Province::Province(
) : HasIdentifierAndColour { new_identifier, new_colour, true, false }, index { new_index },
region { nullptr }, on_map { false }, has_region { false }, water { false }, default_terrain_type { nullptr },
terrain_type { nullptr }, life_rating { 0 }, colony_status { colony_status_t::STATE }, owner { nullptr },
- controller { nullptr }, slave { false }, buildings { "buildings", false }, rgo { nullptr }, total_population { 0 } {
+ controller { nullptr }, slave { false }, crime { nullptr }, rgo { nullptr }, buildings { "buildings", false },
+ total_population { 0 } {
assert(index != NULL_INDEX);
}
diff --git a/src/openvic-simulation/map/Province.hpp b/src/openvic-simulation/map/Province.hpp
index 02bc8cf..dd440fa 100644
--- a/src/openvic-simulation/map/Province.hpp
+++ b/src/openvic-simulation/map/Province.hpp
@@ -80,6 +80,7 @@ namespace OpenVic {
Country const* PROPERTY(controller);
std::vector<Country const*> PROPERTY(cores);
bool PROPERTY(slave);
+ Crime const* PROPERTY_RW(crime);
// TODO - change this into a factory-like structure
Good const* PROPERTY(rgo);
IdentifierRegistry<BuildingInstance> buildings;
diff --git a/src/openvic-simulation/map/State.cpp b/src/openvic-simulation/map/State.cpp
index 1a7f10d..bc78469 100644
--- a/src/openvic-simulation/map/State.cpp
+++ b/src/openvic-simulation/map/State.cpp
@@ -4,76 +4,80 @@
using namespace OpenVic;
-State::State(Country const* owner, Province const* capital, Region::provinces_t&& provinces, Province::colony_status_t colony_status)
- : owner { owner }, capital { capital }, provinces { std::move(provinces) }, colony_status { colony_status } {}
+State::State(
+ Country const* owner, Province const* capital, Region::provinces_t&& provinces, Province::colony_status_t colony_status
+) : owner { owner }, capital { capital }, provinces { std::move(provinces) }, colony_status { colony_status } {}
StateSet::StateSet(Region const* new_region) {
- if (region->get_meta()) {
- Logger::error("Cannot use meta region as state template!");
- }
- region = new_region;
+ if (region->get_meta()) {
+ Logger::error("Cannot use meta region as state template!");
+ }
+ region = new_region;
- std::vector<Region::provinces_t> temp_provinces;
- bool in_state = false;
+ std::vector<Region::provinces_t> temp_provinces;
+ bool in_state = false;
- for (const auto province : region->get_provinces()) {
- // add to existing state if shared owner & status...
- for (auto& provinces : temp_provinces) {
- if (provinces[0] == province) {
- provinces.push_back(province);
- in_state = true;
- break;
- }
- }
- if (in_state) {
- in_state = false;
- } else {
- // ...otherwise start a new state
- temp_provinces.push_back({ province });
- }
- }
+ for (Province* province : region->get_provinces()) {
+ // add to existing state if shared owner & status...
+ for (Region::provinces_t& provinces : temp_provinces) {
+ if (provinces[0] == province) {
+ provinces.push_back(province);
+ in_state = true;
+ break;
+ }
+ }
+ if (in_state) {
+ in_state = false;
+ } else {
+ // ...otherwise start a new state
+ temp_provinces.push_back({ province });
+ }
+ }
- for (auto& provinces : temp_provinces) {
- states.push_back({ /* TODO: capital province logic */ provinces[0]->get_owner(), provinces[0], std::move(provinces), provinces[0]->get_colony_status() });
- }
+ for (Region::provinces_t& provinces : temp_provinces) {
+ states.push_back({
+ /* TODO: capital province logic */
+ provinces[0]->get_owner(), provinces[0], std::move(provinces), provinces[0]->get_colony_status()
+ });
+ }
- // Go back and assign each new state to its provinces.
- for (const auto& state : states) {
- for (auto province : state.get_provinces()) {
- province->set_state(&state);
- }
- }
+ // Go back and assign each new state to its provinces.
+ for (State const& state : states) {
+ for (Province* province : state.get_provinces()) {
+ province->set_state(&state);
+ }
+ }
}
bool StateSet::add_state(State&& state) {
- const auto existing = std::find(states.begin(), states.end(), state);
- if (existing != states.end()) {
- Logger::error("Attempted to add existing state!");
- return false;
- }
- states.push_back(std::move(state));
- return true;
+ const auto existing = std::find(states.begin(), states.end(), state);
+ if (existing != states.end()) {
+ Logger::error("Attempted to add existing state!");
+ return false;
+ }
+ states.push_back(std::move(state));
+ return true;
}
bool StateSet::remove_state(State const* state) {
- const auto existing = std::find(states.begin(), states.end(), *state);
- if (existing == states.end()) {
- Logger::error("Attempted to remove non-existant state!");
- return false;
- }
- states.erase(existing);
- return true;
+ const auto existing = std::find(states.begin(), states.end(), *state);
+ if (existing == states.end()) {
+ Logger::error("Attempted to remove non-existant state!");
+ return false;
+ }
+ states.erase(existing);
+ return true;
}
StateSet::states_t& StateSet::get_states() {
- return states;
+ return states;
}
void StateManager::generate_states(Map const& map) {
- regions.clear();
- regions.reserve(map.get_region_count());
- for(const auto& region : map.get_regions()) {
- regions.push_back(StateSet(&region));
- }
- Logger::info("Generated states.");
-} \ No newline at end of file
+ regions.clear();
+ regions.reserve(map.get_region_count());
+ for(Region const& region : map.get_regions()) {
+ regions.push_back(StateSet(&region));
+ }
+ Logger::info("Generated states.");
+}
diff --git a/src/openvic-simulation/map/State.hpp b/src/openvic-simulation/map/State.hpp
index e9f41c4..e403580 100644
--- a/src/openvic-simulation/map/State.hpp
+++ b/src/openvic-simulation/map/State.hpp
@@ -15,16 +15,19 @@ namespace OpenVic {
Province::colony_status_t PROPERTY_RW(colony_status);
public:
- State(Country const* owner, Province const* capital, Region::provinces_t&& provinces, Province::colony_status_t colony_status);
+ State(
+ Country const* owner, Province const* capital, Region::provinces_t&& provinces,
+ Province::colony_status_t colony_status
+ );
};
inline bool operator==(const State& lhs, const State& rhs) {
- return (lhs.get_owner() == rhs.get_owner() && lhs.get_colony_status() == rhs.get_colony_status());
+ return (lhs.get_owner() == rhs.get_owner() && lhs.get_colony_status() == rhs.get_colony_status());
}
struct StateSet {
using states_t = std::deque<State>;
-
+
private:
Region const* PROPERTY(region);
states_t states;
@@ -44,8 +47,8 @@ namespace OpenVic {
public:
/* Creates states from current province gamestate & regions, sets province state value.
- After this function, the `regions` property is unmanaged and must be carefully updated and
- validated by functions that modify it. */
+ * After this function, the `regions` property is unmanaged and must be carefully updated and
+ * validated by functions that modify it. */
void generate_states(Map const& map);
};
} // namespace OpenVic
diff --git a/src/openvic-simulation/map/TerrainType.cpp b/src/openvic-simulation/map/TerrainType.cpp
index 3048b66..ae10474 100644
--- a/src/openvic-simulation/map/TerrainType.cpp
+++ b/src/openvic-simulation/map/TerrainType.cpp
@@ -10,7 +10,6 @@ TerrainType::TerrainType(
) : HasIdentifierAndColour { new_identifier, new_colour, false, false }, modifier { std::move(new_modifier) },
is_water { new_is_water } {}
-
TerrainTypeMapping::TerrainTypeMapping(
std::string_view new_identifier, TerrainType const& new_type, std::vector<index_t>&& new_terrain_indicies,
index_t new_priority, bool new_has_texture