diff options
Diffstat (limited to 'src/openvic/map')
-rw-r--r-- | src/openvic/map/Building.cpp | 2 | ||||
-rw-r--r-- | src/openvic/map/Building.hpp | 9 | ||||
-rw-r--r-- | src/openvic/map/Map.cpp | 28 | ||||
-rw-r--r-- | src/openvic/map/Map.hpp | 9 | ||||
-rw-r--r-- | src/openvic/map/Province.cpp | 23 | ||||
-rw-r--r-- | src/openvic/map/Province.hpp | 10 |
6 files changed, 71 insertions, 10 deletions
diff --git a/src/openvic/map/Building.cpp b/src/openvic/map/Building.cpp index 07cbac9..81532c4 100644 --- a/src/openvic/map/Building.cpp +++ b/src/openvic/map/Building.cpp @@ -127,7 +127,7 @@ return_t BuildingManager::generate_province_buildings(Province& province) const if (province.is_water()) return SUCCESS; return_t ret = SUCCESS; for (BuildingType const& type : building_types.get_items()) - if (province.add_building(type) != SUCCESS) ret = FAILURE; + if (province.add_building({ type }) != SUCCESS) ret = FAILURE; province.lock_buildings(); return ret; } diff --git a/src/openvic/map/Building.hpp b/src/openvic/map/Building.hpp index 98c3991..c4f8950 100644 --- a/src/openvic/map/Building.hpp +++ b/src/openvic/map/Building.hpp @@ -6,7 +6,8 @@ #include "../Types.hpp" namespace OpenVic { - struct Province; + + struct BuildingManager; struct BuildingType; /* REQUIREMENTS: @@ -15,7 +16,7 @@ namespace OpenVic { * MAP-13, MAP-78, MAP-79 */ struct Building : HasIdentifier { - friend struct Province; + friend struct BuildingManager; using level_t = int8_t; @@ -52,8 +53,6 @@ namespace OpenVic { void tick(Date const& today); }; - struct BuildingManager; - struct BuildingType : HasIdentifier { friend struct BuildingManager; @@ -70,6 +69,8 @@ namespace OpenVic { Timespan get_build_time() const; }; + struct Province; + struct BuildingManager { private: IdentifierRegistry<BuildingType> building_types; diff --git a/src/openvic/map/Map.cpp b/src/openvic/map/Map.cpp index 936add0..0f4ed46 100644 --- a/src/openvic/map/Map.cpp +++ b/src/openvic/map/Map.cpp @@ -341,13 +341,37 @@ return_t Map::generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) return ret; } -return_t Map::setup(GoodManager const& good_manager, BuildingManager const& building_manager) { +void Map::update_highest_province_population() { + highest_province_population = 0; + for (Province const& province : provinces.get_items()) { + highest_province_population = std::max(highest_province_population, province.get_total_population()); + } +} + +Pop::pop_size_t Map::get_highest_province_population() const { + return highest_province_population; +} + +void Map::update_total_map_population() { + total_map_population = 0; + for (Province const& province : provinces.get_items()) { + total_map_population += province.get_total_population(); + } +} + +Pop::pop_size_t Map::get_total_map_population() const { + return total_map_population; +} + +return_t Map::setup(GoodManager const& good_manager, BuildingManager const& building_manager, PopManager const& pop_manager) { return_t ret = SUCCESS; for (Province& province : provinces.get_items()) { // Set all land provinces to have an RGO based on their index to test them if (!province.is_water() && good_manager.get_good_count() > 0) province.rgo = good_manager.get_good_by_index(province.get_index() % good_manager.get_good_count()); if (building_manager.generate_province_buildings(province) != SUCCESS) ret = FAILURE; + // Add some pops to the province (for testing purposes) + pop_manager.generate_test_pops(province); } return ret; } @@ -355,6 +379,8 @@ return_t Map::setup(GoodManager const& good_manager, BuildingManager const& buil void Map::update_state(Date const& today) { for (Province& province : provinces.get_items()) province.update_state(today); + update_highest_province_population(); + update_total_map_population(); } void Map::tick(Date const& today) { diff --git a/src/openvic/map/Map.hpp b/src/openvic/map/Map.hpp index 3533a14..3e1370b 100644 --- a/src/openvic/map/Map.hpp +++ b/src/openvic/map/Map.hpp @@ -54,6 +54,8 @@ namespace OpenVic { colour_index_map_t colour_index_map; index_t selected_province = NULL_INDEX; + Pop::pop_size_t highest_province_population, total_map_population; + index_t get_index_from_colour(colour_t colour) const; public: @@ -93,7 +95,12 @@ namespace OpenVic { static constexpr size_t MAPMODE_COLOUR_SIZE = 4; return_t generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) const; - return_t setup(GoodManager const& good_manager, BuildingManager const& building_manager); + return_t 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); diff --git a/src/openvic/map/Province.cpp b/src/openvic/map/Province.cpp index 06f1c98..75612ad 100644 --- a/src/openvic/map/Province.cpp +++ b/src/openvic/map/Province.cpp @@ -30,8 +30,8 @@ Province::life_rating_t Province::get_life_rating() const { return life_rating; } -return_t Province::add_building(BuildingType const& type) { - return buildings.add_item({ type }); +return_t Province::add_building(Building&& building) { + return buildings.add_item(std::move(building)); } void Province::lock_buildings() { @@ -66,9 +66,28 @@ std::string Province::to_string() const { return stream.str(); } +void Province::add_pop(Pop&& pop) { + pops.push_back(std::move(pop)); +} + +/* REQUIREMENTS: + * MAP-65 + */ +void Province::update_total_population() { + total_population = 0; + for (Pop const& pop : pops) { + total_population += pop.get_size(); + } +} + +Pop::pop_size_t Province::get_total_population() const { + return total_population; +} + void Province::update_state(Date const& today) { for (Building& building : buildings.get_items()) building.update_state(today); + update_total_population(); } void Province::tick(Date const& today) { diff --git a/src/openvic/map/Province.hpp b/src/openvic/map/Province.hpp index f1f87a2..cd90f7d 100644 --- a/src/openvic/map/Province.hpp +++ b/src/openvic/map/Province.hpp @@ -1,5 +1,6 @@ #pragma once +#include "../pop/Pop.hpp" #include "Building.hpp" namespace OpenVic { @@ -24,6 +25,9 @@ namespace OpenVic { // TODO - change this into a factory-like structure Good const* rgo = nullptr; + std::vector<Pop> pops; + Pop::pop_size_t total_population; + Province(index_t new_index, std::string const& new_identifier, colour_t new_colour); public: @@ -33,7 +37,7 @@ namespace OpenVic { Region* get_region() const; bool is_water() const; life_rating_t get_life_rating() const; - return_t add_building(BuildingType const& type); + return_t add_building(Building&& building); void lock_buildings(); void reset_buildings(); Building const* get_building_by_identifier(std::string const& identifier) const; @@ -42,6 +46,10 @@ namespace OpenVic { Good const* get_rgo() const; std::string to_string() const; + void add_pop(Pop&& pop); + void update_total_population(); + Pop::pop_size_t get_total_population() const; + void update_state(Date const& today); void tick(Date const& today); }; |