diff options
Diffstat (limited to 'src/openvic-simulation/map')
-rw-r--r-- | src/openvic-simulation/map/MapInstance.cpp | 13 | ||||
-rw-r--r-- | src/openvic-simulation/map/MapInstance.hpp | 11 | ||||
-rw-r--r-- | src/openvic-simulation/map/Mapmode.cpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/map/Mapmode.hpp | 4 | ||||
-rw-r--r-- | src/openvic-simulation/map/ProvinceDefinition.cpp | 4 | ||||
-rw-r--r-- | src/openvic-simulation/map/ProvinceDefinition.hpp | 4 | ||||
-rw-r--r-- | src/openvic-simulation/map/ProvinceInstance.cpp | 20 | ||||
-rw-r--r-- | src/openvic-simulation/map/ProvinceInstance.hpp | 14 |
8 files changed, 36 insertions, 36 deletions
diff --git a/src/openvic-simulation/map/MapInstance.cpp b/src/openvic-simulation/map/MapInstance.cpp index 1547ade..986b102 100644 --- a/src/openvic-simulation/map/MapInstance.cpp +++ b/src/openvic-simulation/map/MapInstance.cpp @@ -49,7 +49,11 @@ ProvinceDefinition::index_t MapInstance::get_selected_province_index() const { : ProvinceDefinition::NULL_INDEX; } -bool MapInstance::setup(BuildingTypeManager const& building_type_manager) { +bool MapInstance::setup( + BuildingTypeManager const& building_type_manager, + decltype(ProvinceInstance::pop_type_distribution)::keys_t const& pop_type_keys, + decltype(ProvinceInstance::ideology_distribution)::keys_t const& ideology_keys +) { if (province_instances_are_locked()) { Logger::error("Cannot setup map - province instances are locked!"); return false; @@ -64,7 +68,7 @@ bool MapInstance::setup(BuildingTypeManager const& building_type_manager) { province_instances.reserve(map_definition.get_province_definition_count()); for (ProvinceDefinition const& province : map_definition.get_province_definitions()) { - ret &= province_instances.add_item({ province }); + ret &= province_instances.add_item({ province, pop_type_keys, ideology_keys }); } province_instances.lock(); @@ -85,8 +89,7 @@ bool MapInstance::setup(BuildingTypeManager const& building_type_manager) { } bool MapInstance::apply_history_to_provinces( - ProvinceHistoryManager const& history_manager, Date date, IdeologyManager const& ideology_manager, - IssueManager const& issue_manager, CountryDefinition const& country + ProvinceHistoryManager const& history_manager, Date date, IssueManager const& issue_manager ) { bool ret = true; @@ -109,7 +112,7 @@ bool MapInstance::apply_history_to_provinces( if (pop_history_entry != nullptr) { province.add_pop_vec(pop_history_entry->get_pops()); - province.setup_pop_test_values(ideology_manager, issue_manager, country); + province.setup_pop_test_values(issue_manager); } } } diff --git a/src/openvic-simulation/map/MapInstance.hpp b/src/openvic-simulation/map/MapInstance.hpp index 2c0ff74..00bd638 100644 --- a/src/openvic-simulation/map/MapInstance.hpp +++ b/src/openvic-simulation/map/MapInstance.hpp @@ -10,9 +10,7 @@ namespace OpenVic { struct MapDefinition; struct BuildingTypeManager; struct ProvinceHistoryManager; - struct IdeologyManager; struct IssueManager; - struct CountryDefinition; /* REQUIREMENTS: * MAP-4 @@ -44,10 +42,13 @@ namespace OpenVic { ProvinceInstance* get_selected_province(); ProvinceDefinition::index_t get_selected_province_index() const; - bool setup(BuildingTypeManager const& building_type_manager); + bool setup( + BuildingTypeManager const& building_type_manager, + decltype(ProvinceInstance::pop_type_distribution)::keys_t const& pop_type_keys, + decltype(ProvinceInstance::ideology_distribution)::keys_t const& ideology_keys + ); bool apply_history_to_provinces( - ProvinceHistoryManager const& history_manager, Date date, IdeologyManager const& ideology_manager, - IssueManager const& issue_manager, CountryDefinition const& country + ProvinceHistoryManager const& history_manager, Date date, IssueManager const& issue_manager ); void update_gamestate(Date today); diff --git a/src/openvic-simulation/map/Mapmode.cpp b/src/openvic-simulation/map/Mapmode.cpp index f03b0e8..c47a07a 100644 --- a/src/openvic-simulation/map/Mapmode.cpp +++ b/src/openvic-simulation/map/Mapmode.cpp @@ -14,7 +14,7 @@ using namespace OpenVic::colour_literals; Mapmode::Mapmode( std::string_view new_identifier, index_t new_index, colour_func_t new_colour_func -) : HasIdentifier { new_identifier }, index { new_index }, colour_func { new_colour_func } { +) : HasIdentifier { new_identifier }, HasIndex { new_index }, colour_func { new_colour_func } { assert(colour_func != nullptr); } diff --git a/src/openvic-simulation/map/Mapmode.hpp b/src/openvic-simulation/map/Mapmode.hpp index d514f7a..ad0ed16 100644 --- a/src/openvic-simulation/map/Mapmode.hpp +++ b/src/openvic-simulation/map/Mapmode.hpp @@ -11,7 +11,7 @@ namespace OpenVic { struct MapInstance; struct ProvinceInstance; - struct Mapmode : HasIdentifier { + struct Mapmode : HasIdentifier, HasIndex<> { friend struct MapmodeManager; /* Bottom 32 bits are the base colour, top 32 are the stripe colour, both in ARGB format with the alpha channels @@ -24,10 +24,8 @@ namespace OpenVic { constexpr base_stripe_t(colour_argb_t both) : base_stripe_t { both, both } {} }; using colour_func_t = std::function<base_stripe_t(MapInstance const&, ProvinceInstance const&)>; - using index_t = size_t; private: - const index_t PROPERTY(index); const colour_func_t colour_func; Mapmode(std::string_view new_identifier, index_t new_index, colour_func_t new_colour_func); diff --git a/src/openvic-simulation/map/ProvinceDefinition.cpp b/src/openvic-simulation/map/ProvinceDefinition.cpp index c40f8f0..4f34c1e 100644 --- a/src/openvic-simulation/map/ProvinceDefinition.cpp +++ b/src/openvic-simulation/map/ProvinceDefinition.cpp @@ -9,7 +9,7 @@ using namespace OpenVic::NodeTools; ProvinceDefinition::ProvinceDefinition( std::string_view new_identifier, colour_t new_colour, index_t new_index -) : HasIdentifierAndColour { new_identifier, new_colour, true }, index { new_index }, region { nullptr }, +) : HasIdentifierAndColour { new_identifier, new_colour, true }, HasIndex { new_index }, region { nullptr }, climate { nullptr }, continent { nullptr }, on_map { false }, water { false }, coastal { false }, port { false }, port_adjacent_province { nullptr }, default_terrain_type { nullptr }, adjacencies {}, centre {}, positions {} { @@ -22,7 +22,7 @@ bool ProvinceDefinition::operator==(ProvinceDefinition const& other) const { std::string ProvinceDefinition::to_string() const { std::stringstream stream; - stream << "(#" << std::to_string(index) << ", " << get_identifier() << ", 0x" << get_colour() << ")"; + stream << "(#" << std::to_string(get_index()) << ", " << get_identifier() << ", 0x" << get_colour() << ")"; return stream.str(); } diff --git a/src/openvic-simulation/map/ProvinceDefinition.hpp b/src/openvic-simulation/map/ProvinceDefinition.hpp index c66323c..c79af17 100644 --- a/src/openvic-simulation/map/ProvinceDefinition.hpp +++ b/src/openvic-simulation/map/ProvinceDefinition.hpp @@ -24,10 +24,9 @@ namespace OpenVic { * MAP-5, MAP-7, MAP-8, MAP-43, MAP-47 * POP-22 */ - struct ProvinceDefinition : HasIdentifierAndColour { + struct ProvinceDefinition : HasIdentifierAndColour, HasIndex<uint16_t> { friend struct MapDefinition; - using index_t = uint16_t; using distance_t = fixed_point_t; // should this go inside adjacency_t? struct adjacency_t { @@ -84,7 +83,6 @@ namespace OpenVic { private: /* Immutable attributes (unchanged after initial game load) */ - const index_t PROPERTY(index); Region const* PROPERTY(region); Climate const* PROPERTY(climate); Continent const* PROPERTY(continent); diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp index 8bb5345..1792fe0 100644 --- a/src/openvic-simulation/map/ProvinceInstance.cpp +++ b/src/openvic-simulation/map/ProvinceInstance.cpp @@ -7,8 +7,10 @@ using namespace OpenVic; -ProvinceInstance::ProvinceInstance(ProvinceDefinition const& new_province_definition) - : HasIdentifierAndColour { new_province_definition }, +ProvinceInstance::ProvinceInstance( + ProvinceDefinition const& new_province_definition, decltype(pop_type_distribution)::keys_t const& pop_type_keys, + decltype(ideology_distribution)::keys_t const& ideology_keys +) : HasIdentifierAndColour { new_province_definition }, province_definition { new_province_definition }, terrain_type { new_province_definition.get_default_terrain_type() }, life_rating { 0 }, @@ -25,8 +27,8 @@ ProvinceInstance::ProvinceInstance(ProvinceDefinition const& new_province_defini navies {}, pops {}, total_population { 0 }, - pop_type_distribution {}, - ideology_distribution {}, + pop_type_distribution { &pop_type_keys }, + ideology_distribution { &ideology_keys }, culture_distribution {}, religion_distribution {} {} @@ -58,7 +60,7 @@ bool ProvinceInstance::add_pop_vec(std::vector<PopBase> const& pop_vec) { if (!province_definition.is_water()) { reserve_more(pops, pop_vec.size()); for (PopBase const& pop : pop_vec) { - _add_pop(Pop { pop }); + _add_pop(Pop { pop, *ideology_distribution.get_keys() }); } return true; } else { @@ -82,7 +84,7 @@ void ProvinceInstance::_update_pops() { religion_distribution.clear(); for (Pop const& pop : pops) { total_population += pop.get_size(); - pop_type_distribution[&pop.get_type()] += pop.get_size(); + pop_type_distribution[pop.get_type()] += pop.get_size(); ideology_distribution += pop.get_ideologies(); culture_distribution[&pop.get_culture()] += pop.get_size(); religion_distribution[&pop.get_religion()] += pop.get_size(); @@ -214,10 +216,8 @@ bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const* ent return ret; } -void ProvinceInstance::setup_pop_test_values( - IdeologyManager const& ideology_manager, IssueManager const& issue_manager, CountryDefinition const& country -) { +void ProvinceInstance::setup_pop_test_values(IssueManager const& issue_manager) { for (Pop& pop : pops) { - pop.setup_pop_test_values(ideology_manager, issue_manager, country); + pop.setup_pop_test_values(issue_manager); } } diff --git a/src/openvic-simulation/map/ProvinceInstance.hpp b/src/openvic-simulation/map/ProvinceInstance.hpp index a4f9e98..4398cd4 100644 --- a/src/openvic-simulation/map/ProvinceInstance.hpp +++ b/src/openvic-simulation/map/ProvinceInstance.hpp @@ -21,7 +21,6 @@ namespace OpenVic { struct Religion; struct BuildingTypeManager; struct ProvinceHistoryEntry; - struct IdeologyManager; struct IssueManager; template<UnitType::branch_t> @@ -61,12 +60,15 @@ namespace OpenVic { std::vector<Pop> PROPERTY(pops); Pop::pop_size_t PROPERTY(total_population); - fixed_point_map_t<PopType const*> PROPERTY(pop_type_distribution); - fixed_point_map_t<Ideology const*> PROPERTY(ideology_distribution); + IndexedMap<PopType, fixed_point_t> PROPERTY(pop_type_distribution); + IndexedMap<Ideology, fixed_point_t> PROPERTY(ideology_distribution); fixed_point_map_t<Culture const*> PROPERTY(culture_distribution); fixed_point_map_t<Religion const*> PROPERTY(religion_distribution); - ProvinceInstance(ProvinceDefinition const& new_province_definition); + ProvinceInstance( + ProvinceDefinition const& new_province_definition, decltype(pop_type_distribution)::keys_t const& pop_type_keys, + decltype(ideology_distribution)::keys_t const& ideology_keys + ); void _add_pop(Pop&& pop); void _update_pops(); @@ -116,8 +118,6 @@ namespace OpenVic { bool setup(BuildingTypeManager const& building_type_manager); bool apply_history_to_province(ProvinceHistoryEntry const* entry); - void setup_pop_test_values( - IdeologyManager const& ideology_manager, IssueManager const& issue_manager, CountryDefinition const& country - ); + void setup_pop_test_values(IssueManager const& issue_manager); }; } |