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/Country.cpp15
-rw-r--r--src/openvic-simulation/country/Country.hpp3
-rw-r--r--src/openvic-simulation/country/CountryInstance.cpp104
-rw-r--r--src/openvic-simulation/country/CountryInstance.hpp21
4 files changed, 110 insertions, 33 deletions
diff --git a/src/openvic-simulation/country/Country.cpp b/src/openvic-simulation/country/Country.cpp
index 5ec4aee..0fdeb60 100644
--- a/src/openvic-simulation/country/Country.cpp
+++ b/src/openvic-simulation/country/Country.cpp
@@ -43,14 +43,12 @@ Country::Country(
alternative_colours { std::move(new_alternative_colours) },
primary_unit_colour { new_primary_unit_colour },
secondary_unit_colour { new_secondary_unit_colour },
- tertiary_unit_colour { new_tertiary_unit_colour }
- {}
+ tertiary_unit_colour { new_tertiary_unit_colour } {}
bool CountryManager::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,
- colour_t primary_unit_colour, colour_t secondary_unit_colour, colour_t tertiary_unit_colour
+ Country::government_colour_map_t&& alternative_colours
) {
if (identifier.empty()) {
Logger::error("Invalid country identifier - empty!");
@@ -67,9 +65,13 @@ bool CountryManager::add_country(
return false;
}
+ static constexpr colour_t default_colour = colour_t::fill_as(colour_t::max_value);
+
return countries.add_item({
identifier, colour, *graphical_culture, std::move(parties), std::move(unit_names), dynamic_tag,
- std::move(alternative_colours), primary_unit_colour, secondary_unit_colour, tertiary_unit_colour
+ 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
});
}
@@ -205,8 +207,7 @@ bool CountryManager::load_country_data_file(
)(root);
ret &= add_country(
- name, colour, graphical_culture, std::move(parties), std::move(unit_names), is_dynamic,
- std::move(alternative_colours), colour_t::null(), colour_t::null(), colour_t::null()
+ name, colour, graphical_culture, std::move(parties), std::move(unit_names), is_dynamic, std::move(alternative_colours)
);
return ret;
}
diff --git a/src/openvic-simulation/country/Country.hpp b/src/openvic-simulation/country/Country.hpp
index ea8f732..1d960c2 100644
--- a/src/openvic-simulation/country/Country.hpp
+++ b/src/openvic-simulation/country/Country.hpp
@@ -85,8 +85,7 @@ namespace OpenVic {
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,
- colour_t primary_unit_colour, colour_t secondary_unit_colour, colour_t tertiary_unit_colour
+ Country::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 11b1e90..b7b818e 100644
--- a/src/openvic-simulation/country/CountryInstance.cpp
+++ b/src/openvic-simulation/country/CountryInstance.cpp
@@ -1,7 +1,18 @@
#include "CountryInstance.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 },
+ 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";
+}
+
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!");
@@ -48,32 +59,79 @@ bool CountryInstance::remove_reform(Reform const* reform_to_remove) {
return true;
}
-bool CountryInstance::apply_history_to_country(CountryHistoryMap const& history, Date date) {
- accepted_cultures.clear();
- upper_house.clear();
- reforms.clear();
+bool CountryInstance::apply_history_to_country(CountryHistoryEntry const* entry) {
+ if (entry == nullptr) {
+ Logger::error("Trying to apply null country history to ", get_identifier());
+ return false;
+ }
- bool ret = true;
- for (CountryHistoryEntry const* entry : history.get_entries_up_to(date)) {
- if (entry->get_primary_culture()) primary_culture = *entry->get_primary_culture();
- for (Culture const* culture : entry->get_accepted_cultures()) {
- ret &= add_accepted_culture(culture);
- }
- if (entry->get_religion()) religion = *entry->get_religion();
- if (entry->get_ruling_party()) ruling_party = *entry->get_ruling_party();
- if (entry->get_last_election()) last_election = *entry->get_last_election();
- for (auto const& [ideology, popularity] : entry->get_upper_house()) {
- add_to_upper_house(ideology, popularity);
+ constexpr auto set_optional = []<typename T>(T& target, std::optional<T> const& source) {
+ if (source) {
+ target = *source;
}
- if (entry->get_capital()) capital = *entry->get_capital();
- if (entry->get_government_type()) government_type = *entry->get_government_type();
- if (entry->get_plurality()) plurality = *entry->get_plurality();
- if (entry->get_national_value()) national_value = *entry->get_national_value();
- if (entry->is_civilised()) civilised = *entry->is_civilised();
- if (entry->get_prestige()) prestige = *entry->get_prestige();
- for (Reform const* reform : entry->get_reforms()) {
- ret &= add_reform(reform);
+ };
+
+ bool ret = true;
+
+ set_optional(primary_culture, entry->get_primary_culture());
+ for (Culture const* culture : entry->get_accepted_cultures()) {
+ ret &= add_accepted_culture(culture);
+ }
+ set_optional(religion, entry->get_religion());
+ set_optional(ruling_party, entry->get_ruling_party());
+ set_optional(last_election, entry->get_last_election());
+ for (auto const& [ideology, popularity] : entry->get_upper_house()) {
+ add_to_upper_house(ideology, popularity);
+ }
+ set_optional(capital, entry->get_capital());
+ set_optional(government_type, entry->get_government_type());
+ set_optional(plurality, entry->get_plurality());
+ set_optional(national_value, entry->get_national_value());
+ set_optional(civilised, entry->is_civilised());
+ set_optional(prestige, entry->get_prestige());
+ for (Reform const* reform : entry->get_reforms()) {
+ ret &= add_reform(reform);
+ }
+
+ return ret;
+}
+
+bool CountryInstanceManager::generate_country_instances(CountryManager const& country_manager) {
+ reserve_more(country_instances, country_manager.get_country_count());
+
+ for (Country const& country : country_manager.get_countries()) {
+ country_instances.push_back({ &country });
+ }
+
+ return true;
+}
+
+bool CountryInstanceManager::apply_history_to_countries(
+ CountryHistoryManager const& history_manager, Date date, UnitInstanceManager& unit_instance_manager, Map& map
+) {
+ 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());
+
+ if (history_map != nullptr) {
+ CountryHistoryEntry const* oob_history_entry = nullptr;
+
+ for (CountryHistoryEntry const* entry : history_map->get_entries_up_to(date)) {
+ country_instance.apply_history_to_country(entry);
+
+ if (entry->get_inital_oob()) {
+ oob_history_entry = entry;
+ }
+ }
+
+ if (oob_history_entry != nullptr) {
+ unit_instance_manager.generate_deployment(map, country_instance, *oob_history_entry->get_inital_oob());
+ }
+ }
}
}
+
return ret;
}
diff --git a/src/openvic-simulation/country/CountryInstance.hpp b/src/openvic-simulation/country/CountryInstance.hpp
index 98c6e90..7efd930 100644
--- a/src/openvic-simulation/country/CountryInstance.hpp
+++ b/src/openvic-simulation/country/CountryInstance.hpp
@@ -6,8 +6,11 @@
#include "openvic-simulation/utility/Getters.hpp"
namespace OpenVic {
+ struct UnitInstanceManager;
+
/* Representation of an existing country that is currently in-game. */
struct CountryInstance {
+ friend struct CountryInstanceManager;
private:
Country const* PROPERTY_RW(base_country);
Culture const* PROPERTY_RW(primary_culture);
@@ -25,7 +28,11 @@ 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);
+
public:
+ std::string_view get_identifier() const;
+
bool add_accepted_culture(Culture const* new_accepted_culture);
bool remove_accepted_culture(Culture const* culture_to_remove);
/* Add or modify a party in the upper house. */
@@ -34,6 +41,18 @@ namespace OpenVic {
bool add_reform(Reform const* new_reform);
bool remove_reform(Reform const* reform_to_remove);
- bool apply_history_to_country(CountryHistoryMap const& history, Date date);
+ bool apply_history_to_country(CountryHistoryEntry const* entry);
+ };
+
+ struct CountryInstanceManager {
+ private:
+ std::vector<CountryInstance> PROPERTY(country_instances);
+
+ public:
+ bool generate_country_instances(CountryManager const& country_manager);
+
+ bool apply_history_to_countries(
+ CountryHistoryManager const& history_manager, Date date, UnitInstanceManager& unit_instance_manager, Map& map
+ );
};
} // namespace OpenVic