aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map/Map.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/map/Map.hpp')
-rw-r--r--src/openvic-simulation/map/Map.hpp87
1 files changed, 50 insertions, 37 deletions
diff --git a/src/openvic-simulation/map/Map.hpp b/src/openvic-simulation/map/Map.hpp
index 2a3f224..d42b3fb 100644
--- a/src/openvic-simulation/map/Map.hpp
+++ b/src/openvic-simulation/map/Map.hpp
@@ -5,7 +5,8 @@
#include <openvic-dataloader/csv/LineObject.hpp>
-#include "openvic-simulation/map/Province.hpp"
+#include "openvic-simulation/map/ProvinceDefinition.hpp"
+#include "openvic-simulation/map/ProvinceInstance.hpp"
#include "openvic-simulation/map/Region.hpp"
#include "openvic-simulation/map/State.hpp"
#include "openvic-simulation/map/TerrainType.hpp"
@@ -27,7 +28,7 @@ namespace OpenVic {
: base_colour { base }, stripe_colour { stripe } {}
constexpr base_stripe_t(colour_argb_t both) : base_stripe_t { both, both } {}
};
- using colour_func_t = std::function<base_stripe_t(Map const&, Province const&)>;
+ using colour_func_t = std::function<base_stripe_t(Map const&, ProvinceInstance const&)>;
using index_t = size_t;
private:
@@ -41,7 +42,7 @@ namespace OpenVic {
Mapmode(Mapmode&&) = default;
- base_stripe_t get_base_stripe_colours(Map const& map, Province const& province) const;
+ base_stripe_t get_base_stripe_colours(Map const& map, ProvinceInstance const& province) const;
};
struct GoodManager;
@@ -54,14 +55,15 @@ namespace OpenVic {
#pragma pack(push, 1)
/* Used to represent tightly packed 3-byte integer pixel information. */
struct shape_pixel_t {
- Province::index_t index;
+ ProvinceDefinition::index_t index;
TerrainTypeMapping::index_t terrain;
};
#pragma pack(pop)
private:
- using colour_index_map_t = ordered_map<colour_t, Province::index_t>;
+ using colour_index_map_t = ordered_map<colour_t, ProvinceDefinition::index_t>;
- IdentifierRegistry<Province> IDENTIFIER_REGISTRY_CUSTOM_INDEX_OFFSET(province, 1);
+ IdentifierRegistry<ProvinceDefinition> IDENTIFIER_REGISTRY_CUSTOM_INDEX_OFFSET(province_definition, 1);
+ IdentifierRegistry<ProvinceInstance> IDENTIFIER_REGISTRY_CUSTOM_INDEX_OFFSET(province_instance, 1);
IdentifierRegistry<Region> IDENTIFIER_REGISTRY(region);
IdentifierRegistry<Mapmode> IDENTIFIER_REGISTRY(mapmode);
IdentifierRegistry<Climate> IDENTIFIER_REGISTRY(climate);
@@ -73,12 +75,12 @@ namespace OpenVic {
std::vector<shape_pixel_t> PROPERTY(province_shape_image);
colour_index_map_t colour_index_map;
- Province::index_t PROPERTY(max_provinces);
- Province* PROPERTY(selected_province);
+ ProvinceDefinition::index_t PROPERTY(max_provinces);
+ ProvinceInstance* PROPERTY(selected_province); // is it right for this to be mutable? how about using an index instead?
Pop::pop_size_t PROPERTY(highest_province_population);
Pop::pop_size_t PROPERTY(total_map_population);
- Province::index_t get_index_from_colour(colour_t colour) const;
+ ProvinceDefinition::index_t get_index_from_colour(colour_t colour) const;
bool _generate_standard_province_adjacencies();
StateManager PROPERTY_REF(state_manager);
@@ -93,46 +95,60 @@ namespace OpenVic {
inline constexpr int32_t get_width() const { return dims.x; }
inline constexpr int32_t get_height() const { return dims.y; }
- bool add_province(std::string_view identifier, colour_t colour);
- IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS_CUSTOM_INDEX_OFFSET(province, 1);
+ bool add_province_definition(std::string_view identifier, colour_t colour);
- Province::distance_t calculate_distance_between(Province const& from, Province const& to) const;
- bool add_standard_adjacency(Province& from, Province& to) const;
+ private:
+ IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS_CUSTOM_INDEX_OFFSET(province_definition, 1);
+
+ public:
+ IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS_CUSTOM_INDEX_OFFSET(province_instance, 1);
+
+ ProvinceInstance* get_province_instance_from_const(ProvinceDefinition const* province);
+ ProvinceInstance const* get_province_instance_from_const(ProvinceDefinition const* province) const;
+
+ ProvinceDefinition::distance_t calculate_distance_between(
+ ProvinceDefinition const& from, ProvinceDefinition const& to
+ ) const;
+ bool add_standard_adjacency(ProvinceDefinition& from, ProvinceDefinition& to) const;
bool add_special_adjacency(
- Province& from, Province& to, Province::adjacency_t::type_t type, Province const* through,
- Province::adjacency_t::data_t data
+ ProvinceDefinition& from, ProvinceDefinition& to, ProvinceDefinition::adjacency_t::type_t type,
+ ProvinceDefinition const* through, ProvinceDefinition::adjacency_t::data_t data
) const;
- /* This provides a safe way to remove the const qualifier of a Province const*, via a non-const Map.
- * It uses a const_cast (the fastest/simplest solution), but this could also be done without it by looking up the
- * Province* using the Province const*'s index. Requiring a non-const Map ensures that this function can only be
- * used where the Province* could already be accessed by other means, such as the index method, preventing
- * misleading code, or in the worst case undefined behaviour. */
- constexpr Province* remove_province_const(Province const* province) {
- return const_cast<Province*>(province);
- }
-
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::index_t get_province_index_at(ivec2_t pos) const;
- Province* get_province_at(ivec2_t pos);
- Province const* get_province_at(ivec2_t pos) const;
- bool set_max_provinces(Province::index_t new_max_provinces);
- void set_selected_province(Province::index_t index);
- Province* get_selected_province();
- Province::index_t get_selected_province_index() const;
+ ProvinceDefinition::index_t get_province_index_at(ivec2_t pos) const;
- bool add_region(std::string_view identifier, Region::provinces_t const& provinces, colour_t colour);
+ private:
+ ProvinceDefinition* get_province_definition_at(ivec2_t pos);
+
+ /* This provides a safe way to remove the const qualifier of a ProvinceDefinition const*, via a non-const Map.
+ * It uses a const_cast (the fastest/simplest solution), but this could also be done without it by looking up the
+ * ProvinceDefinition* using the ProvinceDefinition const*'s index. Requiring a non-const Map ensures that this
+ * function can only be used where the ProvinceDefinition* could already be accessed by other means, such as the
+ * index method, preventing misleading code, or in the worst case undefined behaviour. */
+ constexpr ProvinceDefinition* remove_province_definition_const(ProvinceDefinition const* province) {
+ return const_cast<ProvinceDefinition*>(province);
+ }
+
+ public:
+ ProvinceDefinition const* get_province_definition_at(ivec2_t pos) const;
+ bool set_max_provinces(ProvinceDefinition::index_t new_max_provinces);
+ void set_selected_province(ProvinceDefinition::index_t index);
+ ProvinceInstance* get_selected_province();
+ ProvinceDefinition::index_t get_selected_province_index() const;
+
+ bool add_region(std::string_view identifier, std::vector<ProvinceDefinition const*>&& provinces, colour_t colour);
bool add_mapmode(std::string_view identifier, Mapmode::colour_func_t colour_func);
/* 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
* and A = 255 is fully the RGB colour packaged with A. The base and stripe colours for each province are packed
- * together adjacently, so each province's entry is 8 bytes long. The list contains Province::MAX_INDEX + 1 entries,
- * that is the maximum allowed number of provinces plus one for the index-zero "null province". */
+ * together adjacently, so each province's entry is 8 bytes long. The list contains ProvinceDefinition::MAX_INDEX + 1
+ * entries, that is the maximum allowed number of provinces plus one for the index-zero "null province". */
bool generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) const;
bool reset(BuildingTypeManager const& building_type_manager);
@@ -141,9 +157,6 @@ namespace OpenVic {
IssueManager const& issue_manager, Country const& country
);
- void update_highest_province_population();
- void update_total_map_population();
-
void update_gamestate(Date today);
void tick(Date today);