aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/country
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/country')
-rw-r--r--src/openvic-simulation/country/CountryDefinition.cpp (renamed from src/openvic-simulation/country/Country.cpp)32
-rw-r--r--src/openvic-simulation/country/CountryDefinition.hpp (renamed from src/openvic-simulation/country/Country.hpp)20
-rw-r--r--src/openvic-simulation/country/CountryInstance.cpp43
-rw-r--r--src/openvic-simulation/country/CountryInstance.hpp14
4 files changed, 62 insertions, 47 deletions
diff --git a/src/openvic-simulation/country/Country.cpp b/src/openvic-simulation/country/CountryDefinition.cpp
index d21df89..e414e9e 100644
--- a/src/openvic-simulation/country/Country.cpp
+++ b/src/openvic-simulation/country/CountryDefinition.cpp
@@ -1,4 +1,4 @@
-#include "Country.hpp"
+#include "CountryDefinition.hpp"
#include <string_view>
@@ -22,7 +22,7 @@ CountryParty::CountryParty(
) : HasIdentifierAndColour { new_identifier, new_ideology.get_colour(), false }, start_date { new_start_date },
end_date { new_end_date }, ideology { new_ideology }, policies { std::move(new_policies) } {}
-Country::Country(
+CountryDefinition::CountryDefinition(
std::string_view new_identifier,
colour_t new_colour,
size_t new_index,
@@ -45,10 +45,10 @@ Country::Country(
secondary_unit_colour { new_secondary_unit_colour },
tertiary_unit_colour { new_tertiary_unit_colour } {}
-bool CountryManager::add_country(
+bool CountryDefinitionManager::add_country(
std::string_view identifier, colour_t colour, GraphicalCultureType const* graphical_culture,
- IdentifierRegistry<CountryParty>&& parties, Country::unit_names_map_t&& unit_names, bool dynamic_tag,
- Country::government_colour_map_t&& alternative_colours
+ IdentifierRegistry<CountryParty>&& parties, CountryDefinition::unit_names_map_t&& unit_names, bool dynamic_tag,
+ CountryDefinition::government_colour_map_t&& alternative_colours
) {
if (identifier.empty()) {
Logger::error("Invalid country identifier - empty!");
@@ -67,22 +67,22 @@ bool CountryManager::add_country(
static constexpr colour_t default_colour = colour_t::fill_as(colour_t::max_value);
- return countries.add_item({
- identifier, colour, countries.size(), *graphical_culture, std::move(parties), std::move(unit_names),
+ return country_definitions.add_item({
+ identifier, colour, get_country_definition_count(), *graphical_culture, std::move(parties), std::move(unit_names),
dynamic_tag, std::move(alternative_colours),
/* Default to country colour for the chest and grey for the others. Update later if necessary. */
colour, default_colour, default_colour
});
}
-bool CountryManager::load_countries(
+bool CountryDefinitionManager::load_countries(
DefinitionManager const& definition_manager, Dataloader const& dataloader, ast::NodeCPtr root
) {
static constexpr std::string_view common_dir = "common/";
bool is_dynamic = false;
const bool ret = expect_dictionary_reserve_length(
- countries,
+ country_definitions,
[this, &definition_manager, &is_dynamic, &dataloader](std::string_view key, ast::NodeCPtr value) -> bool {
if (key == "dynamic_tags") {
return expect_bool([&is_dynamic](bool val) -> bool {
@@ -117,12 +117,12 @@ bool CountryManager::load_countries(
return false;
}
)(root);
- lock_countries();
+ lock_country_definitions();
return ret;
}
-bool CountryManager::load_country_colours(ast::NodeCPtr root){
- return countries.expect_item_dictionary([](Country& country, ast::NodeCPtr colour_node) -> bool {
+bool CountryDefinitionManager::load_country_colours(ast::NodeCPtr root){
+ return country_definitions.expect_item_dictionary([](CountryDefinition& country, ast::NodeCPtr colour_node) -> bool {
return expect_dictionary_keys(
"color1", ONE_EXACTLY, expect_colour(assign_variable_callback(country.primary_unit_colour)),
"color2", ONE_EXACTLY, expect_colour(assign_variable_callback(country.secondary_unit_colour)),
@@ -131,7 +131,7 @@ bool CountryManager::load_country_colours(ast::NodeCPtr root){
})(root);
}
-node_callback_t CountryManager::load_country_party(
+node_callback_t CountryDefinitionManager::load_country_party(
PoliticsManager const& politics_manager, IdentifierRegistry<CountryParty>& country_parties
) const {
return [&politics_manager, &country_parties](ast::NodeCPtr value) -> bool {
@@ -177,14 +177,14 @@ node_callback_t CountryManager::load_country_party(
};
}
-bool CountryManager::load_country_data_file(
+bool CountryDefinitionManager::load_country_data_file(
DefinitionManager const& definition_manager, std::string_view name, bool is_dynamic, ast::NodeCPtr root
) {
colour_t colour;
GraphicalCultureType const* graphical_culture;
IdentifierRegistry<CountryParty> parties { "country parties" };
- Country::unit_names_map_t unit_names;
- Country::government_colour_map_t alternative_colours;
+ CountryDefinition::unit_names_map_t unit_names;
+ CountryDefinition::government_colour_map_t alternative_colours;
bool ret = expect_dictionary_keys_and_default(
[&definition_manager, &alternative_colours](std::string_view key, ast::NodeCPtr value) -> bool {
return definition_manager.get_politics_manager().get_government_type_manager().expect_government_type_str(
diff --git a/src/openvic-simulation/country/Country.hpp b/src/openvic-simulation/country/CountryDefinition.hpp
index 001f1ff..70e62b9 100644
--- a/src/openvic-simulation/country/Country.hpp
+++ b/src/openvic-simulation/country/CountryDefinition.hpp
@@ -18,10 +18,10 @@
namespace OpenVic {
struct DefinitionManager;
- struct CountryManager;
+ struct CountryDefinitionManager;
struct CountryParty : HasIdentifierAndColour {
- friend struct CountryManager;
+ friend struct CountryDefinitionManager;
using policy_map_t = ordered_map<IssueGroup const*, Issue const*>;
@@ -41,8 +41,8 @@ namespace OpenVic {
};
/* Generic information about a TAG */
- struct Country : HasIdentifierAndColour {
- friend struct CountryManager;
+ struct CountryDefinition : HasIdentifierAndColour {
+ friend struct CountryDefinitionManager;
using unit_names_map_t = ordered_map<UnitType const*, name_list_t>;
using government_colour_map_t = ordered_map<GovernmentType const*, colour_t>;
@@ -61,7 +61,7 @@ namespace OpenVic {
colour_t PROPERTY(tertiary_unit_colour);
// Unit colours not const due to being added after construction
- Country(
+ CountryDefinition(
std::string_view new_identifier, colour_t new_colour, size_t new_index,
GraphicalCultureType const& new_graphical_culture, IdentifierRegistry<CountryParty>&& new_parties,
unit_names_map_t&& new_unit_names, bool new_dynamic_tag, government_colour_map_t&& new_alternative_colours,
@@ -69,14 +69,14 @@ namespace OpenVic {
);
public:
- Country(Country&&) = default;
+ CountryDefinition(CountryDefinition&&) = default;
// TODO - get_colour including alternative colours
};
- struct CountryManager {
+ struct CountryDefinitionManager {
private:
- IdentifierRegistry<Country> IDENTIFIER_REGISTRY_CUSTOM_PLURAL(country, countries);
+ IdentifierRegistry<CountryDefinition> IDENTIFIER_REGISTRY(country_definition);
NodeTools::node_callback_t load_country_party(
PoliticsManager const& politics_manager, IdentifierRegistry<CountryParty>& country_parties
@@ -85,8 +85,8 @@ namespace OpenVic {
public:
bool add_country(
std::string_view identifier, colour_t colour, GraphicalCultureType const* graphical_culture,
- IdentifierRegistry<CountryParty>&& parties, Country::unit_names_map_t&& unit_names, bool dynamic_tag,
- Country::government_colour_map_t&& alternative_colours
+ IdentifierRegistry<CountryParty>&& parties, CountryDefinition::unit_names_map_t&& unit_names, bool dynamic_tag,
+ CountryDefinition::government_colour_map_t&& alternative_colours
);
bool load_country_colours(ast::NodeCPtr root);
diff --git a/src/openvic-simulation/country/CountryInstance.cpp b/src/openvic-simulation/country/CountryInstance.cpp
index 25f40ed..2debd8a 100644
--- a/src/openvic-simulation/country/CountryInstance.cpp
+++ b/src/openvic-simulation/country/CountryInstance.cpp
@@ -1,23 +1,26 @@
#include "CountryInstance.hpp"
-#include "openvic-simulation/country/Country.hpp"
+#include "openvic-simulation/country/CountryDefinition.hpp"
#include "openvic-simulation/history/CountryHistory.hpp"
#include "openvic-simulation/military/UnitInstance.hpp"
using namespace OpenVic;
-CountryInstance::CountryInstance(Country const* new_base_country)
- : base_country { new_base_country }, primary_culture { nullptr }, religion { nullptr }, ruling_party { nullptr },
+CountryInstance::CountryInstance(CountryDefinition const* new_country_definition)
+ : country_definition { new_country_definition }, primary_culture { nullptr }, religion { nullptr }, ruling_party { nullptr },
last_election {}, capital { nullptr }, government_type { nullptr }, plurality { 0 }, national_value { nullptr },
civilised { false }, prestige { 0 } {}
std::string_view CountryInstance::get_identifier() const {
- return base_country != nullptr ? base_country->get_identifier() : "NULL";
+ return country_definition != nullptr ? country_definition->get_identifier() : "NULL";
}
bool CountryInstance::add_accepted_culture(Culture const* new_accepted_culture) {
if (std::find(accepted_cultures.begin(), accepted_cultures.end(), new_accepted_culture) != accepted_cultures.end()) {
- Logger::warning("Attempted to add accepted culture ", new_accepted_culture->get_identifier(), " to country ", base_country->get_identifier(), ": already present!");
+ Logger::warning(
+ "Attempted to add accepted culture ", new_accepted_culture->get_identifier(), " to country ",
+ country_definition->get_identifier(), ": already present!"
+ );
return false;
}
accepted_cultures.push_back(new_accepted_culture);
@@ -27,7 +30,10 @@ bool CountryInstance::add_accepted_culture(Culture const* new_accepted_culture)
bool CountryInstance::remove_accepted_culture(Culture const* culture_to_remove) {
auto existing_entry = std::find(accepted_cultures.begin(), accepted_cultures.end(), culture_to_remove);
if (existing_entry == accepted_cultures.end()) {
- Logger::warning("Attempted to remove accepted culture ", culture_to_remove->get_identifier(), " from country ", base_country->get_identifier(), ": not present!");
+ Logger::warning(
+ "Attempted to remove accepted culture ", culture_to_remove->get_identifier(), " from country ",
+ country_definition->get_identifier(), ": not present!"
+ );
return false;
}
accepted_cultures.erase(existing_entry);
@@ -44,7 +50,10 @@ bool CountryInstance::remove_from_upper_house(Ideology const* party) {
bool CountryInstance::add_reform(Reform const* new_reform) {
if (std::find(reforms.begin(), reforms.end(), new_reform) != reforms.end()) {
- Logger::warning("Attempted to add reform ", new_reform->get_identifier(), " to country ", base_country->get_identifier(), ": already present!");
+ Logger::warning(
+ "Attempted to add reform ", new_reform->get_identifier(), " to country ", country_definition->get_identifier(),
+ ": already present!"
+ );
return false;
}
reforms.push_back(new_reform);
@@ -54,7 +63,10 @@ bool CountryInstance::add_reform(Reform const* new_reform) {
bool CountryInstance::remove_reform(Reform const* reform_to_remove) {
auto existing_entry = std::find(reforms.begin(), reforms.end(), reform_to_remove);
if (existing_entry == reforms.end()) {
- Logger::warning("Attempted to remove reform ", reform_to_remove->get_identifier(), " from country ", base_country->get_identifier(), ": not present!");
+ Logger::warning(
+ "Attempted to remove reform ", reform_to_remove->get_identifier(), " from country ",
+ country_definition->get_identifier(), ": not present!"
+ );
return false;
}
reforms.erase(existing_entry);
@@ -98,11 +110,11 @@ bool CountryInstance::apply_history_to_country(CountryHistoryEntry const* entry)
return ret;
}
-bool CountryInstanceManager::generate_country_instances(CountryManager const& country_manager) {
- reserve_more(country_instances, country_manager.get_country_count());
+bool CountryInstanceManager::generate_country_instances(CountryDefinitionManager const& country_definition_manager) {
+ reserve_more(country_instances, country_definition_manager.get_country_definition_count());
- for (Country const& country : country_manager.get_countries()) {
- country_instances.push_back({ &country });
+ for (CountryDefinition const& country_definition : country_definition_manager.get_country_definitions()) {
+ country_instances.add_item({ &country_definition });
}
return true;
@@ -114,9 +126,10 @@ bool CountryInstanceManager::apply_history_to_countries(
) {
bool ret = true;
- for (CountryInstance& country_instance : country_instances) {
- if (!country_instance.get_base_country()->is_dynamic_tag()) {
- CountryHistoryMap const* history_map = history_manager.get_country_history(country_instance.get_base_country());
+ for (CountryInstance& country_instance : country_instances.get_items()) {
+ if (!country_instance.get_country_definition()->is_dynamic_tag()) {
+ CountryHistoryMap const* history_map =
+ history_manager.get_country_history(country_instance.get_country_definition());
if (history_map != nullptr) {
CountryHistoryEntry const* oob_history_entry = nullptr;
diff --git a/src/openvic-simulation/country/CountryInstance.hpp b/src/openvic-simulation/country/CountryInstance.hpp
index 68d2bb2..45924b2 100644
--- a/src/openvic-simulation/country/CountryInstance.hpp
+++ b/src/openvic-simulation/country/CountryInstance.hpp
@@ -4,10 +4,11 @@
#include "openvic-simulation/types/Date.hpp"
#include "openvic-simulation/types/fixed_point/FixedPointMap.hpp"
+#include "openvic-simulation/types/IdentifierRegistry.hpp"
#include "openvic-simulation/utility/Getters.hpp"
namespace OpenVic {
- struct Country;
+ struct CountryDefinition;
struct Culture;
struct Religion;
struct CountryParty;
@@ -21,8 +22,9 @@ namespace OpenVic {
/* Representation of an existing country that is currently in-game. */
struct CountryInstance {
friend struct CountryInstanceManager;
+
private:
- Country const* PROPERTY_RW(base_country);
+ CountryDefinition const* PROPERTY_RW(country_definition);
Culture const* PROPERTY_RW(primary_culture);
std::vector<Culture const*> PROPERTY(accepted_cultures);
Religion const* PROPERTY_RW(religion);
@@ -40,7 +42,7 @@ namespace OpenVic {
std::vector<Reform const*> PROPERTY(reforms); // TODO: should be map of reform groups to active reforms: must set defaults & validate applied history
// TODO: Military units + OOBs; will probably need an extensible deployment class
- CountryInstance(Country const* new_base_country);
+ CountryInstance(CountryDefinition const* new_country_definition);
public:
std::string_view get_identifier() const;
@@ -56,17 +58,17 @@ namespace OpenVic {
bool apply_history_to_country(CountryHistoryEntry const* entry);
};
- struct CountryManager;
+ struct CountryDefinitionManager;
struct CountryHistoryManager;
struct UnitInstanceManager;
struct MapInstance;
struct CountryInstanceManager {
private:
- std::vector<CountryInstance> PROPERTY(country_instances);
+ IdentifierRegistry<CountryInstance> IDENTIFIER_REGISTRY(country_instance);
public:
- bool generate_country_instances(CountryManager const& country_manager);
+ bool generate_country_instances(CountryDefinitionManager const& country_definition_manager);
bool apply_history_to_countries(
CountryHistoryManager const& history_manager, Date date, UnitInstanceManager& unit_instance_manager,