diff options
author | Hop311 <hop3114@gmail.com> | 2023-09-08 18:12:22 +0200 |
---|---|---|
committer | Hop311 <hop3114@gmail.com> | 2023-09-08 18:12:22 +0200 |
commit | 7772f8871348b7b52cb0a478bb76df68d8799a07 (patch) | |
tree | fd8c4626b2cee69a9fe9250365af6b18eea63c70 /src/openvic-simulation/map/Map.hpp | |
parent | 7f9a9a8241ba81be9213e6606b8be4a48f1cbaab (diff) |
More refactoring and duplicate code removal
Diffstat (limited to 'src/openvic-simulation/map/Map.hpp')
-rw-r--r-- | src/openvic-simulation/map/Map.hpp | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/src/openvic-simulation/map/Map.hpp b/src/openvic-simulation/map/Map.hpp new file mode 100644 index 0000000..71719e2 --- /dev/null +++ b/src/openvic-simulation/map/Map.hpp @@ -0,0 +1,117 @@ +#pragma once + +#include <functional> + +#include <openvic-dataloader/csv/LineObject.hpp> + +#include "openvic-simulation/map/Region.hpp" + +namespace OpenVic { + + struct Mapmode : HasIdentifier { + friend struct Map; + + using colour_func_t = std::function<colour_t(Map const&, Province const&)>; + using index_t = size_t; + + private: + const index_t index; + const colour_func_t colour_func; + + Mapmode(const std::string_view new_identifier, index_t new_index, colour_func_t new_colour_func); + + public: + static const Mapmode ERROR_MAPMODE; + + Mapmode(Mapmode&&) = default; + + index_t get_index() const; + colour_t get_colour(Map const& map, Province const& province) const; + }; + + struct GoodManager; + + /* REQUIREMENTS: + * MAP-4 + */ + struct Map { + using terrain_t = uint8_t; + using terrain_variant_map_t = std::map<colour_t, terrain_t>; + +#pragma pack(push, 1) + struct shape_pixel_t { + Province::index_t index; + terrain_t terrain; + }; +#pragma pack(pop) + private: + using colour_index_map_t = std::map<colour_t, Province::index_t>; + + IdentifierRegistry<Province> provinces; + IdentifierRegistry<Region> regions; + IdentifierRegistry<Mapmode> mapmodes; + ProvinceSet water_provinces; + + size_t width = 0, height = 0; + std::vector<shape_pixel_t> province_shape_image; + colour_index_map_t colour_index_map; + Province::index_t max_provinces = Province::MAX_INDEX; + Province::index_t selected_province = Province::NULL_INDEX; + + Pop::pop_size_t highest_province_population, total_map_population; + + Province::index_t get_index_from_colour(colour_t colour) const; + + public: + Map(); + + bool add_province(const std::string_view identifier, colour_t colour); + void lock_provinces(); + bool set_water_province(const std::string_view identifier); + bool set_water_province_list(std::vector<std::string_view> const& list); + void lock_water_provinces(); + bool add_region(const std::string_view identifier, std::vector<std::string_view> const& province_identifiers); + void lock_regions(); + + size_t get_province_count() const; + std::vector<Province> const& get_provinces() const; + Province* get_province_by_index(Province::index_t index); + Province const* get_province_by_index(Province::index_t index) const; + Province* get_province_by_identifier(const std::string_view identifier); + Province const* get_province_by_identifier(const std::string_view identifier) 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; + void set_selected_province(Province::index_t index); + Province::index_t get_selected_province_index() const; + Province const* get_selected_province() const; + + Region* get_region_by_identifier(const std::string_view identifier); + Region const* get_region_by_identifier(const std::string_view identifier) const; + size_t get_region_count() const; + std::vector<Region> const& get_regions() const; + + bool generate_province_shape_image(size_t new_width, size_t new_height, uint8_t const* colour_data, + uint8_t const* terrain_data, terrain_variant_map_t const& terrain_variant_map, bool detailed_errors); + size_t get_width() const; + size_t get_height() const; + std::vector<shape_pixel_t> const& get_province_shape_image() const; + + bool add_mapmode(const std::string_view identifier, Mapmode::colour_func_t colour_func); + IDENTIFIER_REGISTRY_ACCESSORS(Mapmode, mapmode) + static constexpr size_t MAPMODE_COLOUR_SIZE = 4; + bool generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) const; + + bool setup(GoodManager const& good_manager, BuildingManager const& building_manager, PopManager const& pop_manager); + + void update_highest_province_population(); + Pop::pop_size_t get_highest_province_population() const; + void update_total_map_population(); + Pop::pop_size_t get_total_map_population() const; + + void update_state(Date const& today); + void tick(Date const& today); + + bool load_province_definitions(std::vector<ovdl::csv::LineObject> const& lines); + }; +} |