aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/history
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/history')
-rw-r--r--src/openvic-simulation/history/CountryHistory.cpp6
-rw-r--r--src/openvic-simulation/history/CountryHistory.hpp34
-rw-r--r--src/openvic-simulation/history/DiplomaticHistory.cpp203
-rw-r--r--src/openvic-simulation/history/DiplomaticHistory.hpp37
-rw-r--r--src/openvic-simulation/history/Period.cpp6
-rw-r--r--src/openvic-simulation/history/Period.hpp4
-rw-r--r--src/openvic-simulation/history/ProvinceHistory.cpp32
-rw-r--r--src/openvic-simulation/history/ProvinceHistory.hpp44
8 files changed, 233 insertions, 133 deletions
diff --git a/src/openvic-simulation/history/CountryHistory.cpp b/src/openvic-simulation/history/CountryHistory.cpp
index 1bd3dd0..90fe995 100644
--- a/src/openvic-simulation/history/CountryHistory.cpp
+++ b/src/openvic-simulation/history/CountryHistory.cpp
@@ -68,7 +68,7 @@ bool CountryHistoryMap::_load_history_entry(
);
},
"capital", ZERO_OR_ONE,
- game_manager.get_map().expect_province_identifier(assign_variable_callback_pointer_opt(entry.capital)),
+ game_manager.get_map().expect_province_definition_identifier(assign_variable_callback_pointer_opt(entry.capital)),
"primary_culture", ZERO_OR_ONE,
culture_manager.expect_culture_identifier(assign_variable_callback_pointer_opt(entry.primary_culture)),
"culture", ZERO_OR_MORE, culture_manager.expect_culture_identifier(
@@ -148,7 +148,9 @@ bool CountryHistoryMap::_load_history_entry(
/* If the first government type is null, the "government" section will have already output
* an error, so no need to output another one here. */
if (government_type != nullptr && flag_override_government_type != nullptr) {
- ret &= map_callback(entry.government_flag_overrides, government_type)(flag_override_government_type);
+ ret &= map_callback(
+ entry.government_flag_overrides, government_type)(flag_override_government_type
+ );
}
return ret;
} else {
diff --git a/src/openvic-simulation/history/CountryHistory.hpp b/src/openvic-simulation/history/CountryHistory.hpp
index 1c1b7f1..b183ea8 100644
--- a/src/openvic-simulation/history/CountryHistory.hpp
+++ b/src/openvic-simulation/history/CountryHistory.hpp
@@ -1,25 +1,29 @@
#pragma once
#include <optional>
+#include <vector>
-#include "openvic-simulation/country/Country.hpp"
#include "openvic-simulation/history/HistoryMap.hpp"
-#include "openvic-simulation/map/Province.hpp"
-#include "openvic-simulation/military/Deployment.hpp"
-#include "openvic-simulation/misc/Decision.hpp"
-#include "openvic-simulation/politics/Government.hpp"
-#include "openvic-simulation/politics/Ideology.hpp"
-#include "openvic-simulation/politics/Issue.hpp"
-#include "openvic-simulation/politics/NationalValue.hpp"
-#include "openvic-simulation/pop/Culture.hpp"
-#include "openvic-simulation/pop/Religion.hpp"
-#include "openvic-simulation/research/Invention.hpp"
-#include "openvic-simulation/research/Technology.hpp"
#include "openvic-simulation/types/Date.hpp"
+#include "openvic-simulation/types/fixed_point/FixedPointMap.hpp"
#include "openvic-simulation/types/OrderedContainers.hpp"
namespace OpenVic {
struct CountryHistoryMap;
+ struct Country;
+ struct Culture;
+ struct Religion;
+ struct CountryParty;
+ struct Ideology;
+ struct ProvinceDefinition;
+ struct GovernmentType;
+ struct NationalValue;
+ struct Reform;
+ struct Deployment;
+ struct TechnologySchool;
+ struct Technology;
+ struct Invention;
+ struct Decision;
struct CountryHistoryEntry : HistoryEntry {
friend struct CountryHistoryMap;
@@ -33,7 +37,7 @@ namespace OpenVic {
std::optional<CountryParty const*> PROPERTY(ruling_party);
std::optional<Date> PROPERTY(last_election);
fixed_point_map_t<Ideology const*> PROPERTY(upper_house);
- std::optional<Province const*> PROPERTY(capital);
+ std::optional<ProvinceDefinition const*> PROPERTY(capital);
std::optional<GovernmentType const*> PROPERTY(government_type);
std::optional<fixed_point_t> PROPERTY(plurality);
std::optional<NationalValue const*> PROPERTY(national_value);
@@ -59,6 +63,8 @@ namespace OpenVic {
CountryHistoryEntry(Country const& new_country, Date new_date);
};
+ class Dataloader;
+ struct DeploymentManager;
struct CountryHistoryManager;
struct CountryHistoryMap : HistoryMap<CountryHistoryEntry, Dataloader const&, DeploymentManager&> {
@@ -96,4 +102,4 @@ namespace OpenVic {
);
};
-} // namespace OpenVic
+}
diff --git a/src/openvic-simulation/history/DiplomaticHistory.cpp b/src/openvic-simulation/history/DiplomaticHistory.cpp
index 22ee765..f56b3dc 100644
--- a/src/openvic-simulation/history/DiplomaticHistory.cpp
+++ b/src/openvic-simulation/history/DiplomaticHistory.cpp
@@ -1,8 +1,6 @@
#include "DiplomaticHistory.hpp"
#include "openvic-simulation/GameManager.hpp"
-#include "openvic-simulation/dataloader/NodeTools.hpp"
-#include "openvic-simulation/history/Period.hpp"
using namespace OpenVic;
using namespace OpenVic::NodeTools;
@@ -13,8 +11,9 @@ WarHistory::added_wargoal_t::added_wargoal_t(
Country const* new_receiver,
WargoalType const* new_wargoal,
std::optional<Country const*> new_third_party,
- std::optional<Province const*> new_target
-) : added { new_added }, actor { new_actor }, receiver { new_receiver }, wargoal { new_wargoal }, third_party { new_third_party }, target { new_target } {}
+ std::optional<ProvinceDefinition const*> new_target
+) : added { new_added }, actor { new_actor }, receiver { new_receiver }, wargoal { new_wargoal },
+ third_party { new_third_party }, target { new_target } {}
WarHistory::war_participant_t::war_participant_t(
Country const* new_country,
@@ -26,7 +25,8 @@ WarHistory::WarHistory(
std::vector<war_participant_t>&& new_attackers,
std::vector<war_participant_t>&& new_defenders,
std::vector<added_wargoal_t>&& new_wargoals
-) : war_name { new_war_name }, attackers { std::move(new_attackers) }, defenders { std::move(new_defenders) }, wargoals { std::move(new_wargoals) } {}
+) : war_name { new_war_name }, attackers { std::move(new_attackers) }, defenders { std::move(new_defenders) },
+ wargoals { std::move(new_wargoals) } {}
AllianceHistory::AllianceHistory(
Country const* new_first,
@@ -56,7 +56,9 @@ void DiplomaticHistoryManager::reserve_more_wars(size_t size) {
}
void DiplomaticHistoryManager::lock_diplomatic_history() {
- Logger::info("Locked diplomacy history registry after registering ", alliances.size() + subjects.size() + wars.size(), " items");
+ Logger::info(
+ "Locked diplomacy history registry after registering ", alliances.size() + subjects.size() + wars.size(), " items"
+ );
locked = true;
}
@@ -66,7 +68,7 @@ bool DiplomaticHistoryManager::is_locked() const {
std::vector<AllianceHistory const*> DiplomaticHistoryManager::get_alliances(Date date) const {
std::vector<AllianceHistory const*> ret {};
- for (const auto& alliance : alliances) {
+ for (auto const& alliance : alliances) {
if (alliance.period.is_date_in_period(date)) {
ret.push_back(&alliance);
}
@@ -76,7 +78,7 @@ std::vector<AllianceHistory const*> DiplomaticHistoryManager::get_alliances(Date
std::vector<ReparationsHistory const*> DiplomaticHistoryManager::get_reparations(Date date) const {
std::vector<ReparationsHistory const*> ret {};
- for (const auto& reparation : reparations) {
+ for (auto const& reparation : reparations) {
if (reparation.period.is_date_in_period(date)) {
ret.push_back(&reparation);
}
@@ -86,7 +88,7 @@ std::vector<ReparationsHistory const*> DiplomaticHistoryManager::get_reparations
std::vector<SubjectHistory const*> DiplomaticHistoryManager::get_subjects(Date date) const {
std::vector<SubjectHistory const*> ret {};
- for (const auto& subject : subjects) {
+ for (auto const& subject : subjects) {
if (subject.period.is_date_in_period(date)) {
ret.push_back(&subject);
}
@@ -96,9 +98,9 @@ std::vector<SubjectHistory const*> DiplomaticHistoryManager::get_subjects(Date d
std::vector<WarHistory const*> DiplomaticHistoryManager::get_wars(Date date) const {
std::vector<WarHistory const*> ret;
- for (const auto& war : wars) {
+ for (auto const& war : wars) {
Date start {};
- for (const auto& wargoal : war.wargoals) {
+ for (auto const& wargoal : war.wargoals) {
if (wargoal.added < start) start = wargoal.added;
}
if (start >= date) ret.push_back(&war);
@@ -115,8 +117,10 @@ bool DiplomaticHistoryManager::load_diplomacy_history_file(CountryManager const&
std::optional<Date> end {};
bool ret = expect_dictionary_keys(
- "first", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(first)),
- "second", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(second)),
+ "first", ONE_EXACTLY,
+ country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(first)),
+ "second", ONE_EXACTLY,
+ country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(second)),
"start_date", ONE_EXACTLY, expect_date_identifier_or_string(assign_variable_callback(start)),
"end_date", ZERO_OR_ONE, expect_date_identifier_or_string(assign_variable_callback(end))
)(node);
@@ -131,8 +135,10 @@ bool DiplomaticHistoryManager::load_diplomacy_history_file(CountryManager const&
std::optional<Date> end {};
bool ret = expect_dictionary_keys(
- "first", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(overlord)),
- "second", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(subject)),
+ "first", ONE_EXACTLY,
+ country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(overlord)),
+ "second", ONE_EXACTLY,
+ country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(subject)),
"start_date", ONE_EXACTLY, expect_date_identifier_or_string(assign_variable_callback(start)),
"end_date", ZERO_OR_ONE, expect_date_identifier_or_string(assign_variable_callback(end))
)(node);
@@ -147,8 +153,10 @@ bool DiplomaticHistoryManager::load_diplomacy_history_file(CountryManager const&
std::optional<Date> end {};
bool ret = expect_dictionary_keys(
- "first", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(overlord)),
- "second", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(subject)),
+ "first", ONE_EXACTLY,
+ country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(overlord)),
+ "second", ONE_EXACTLY,
+ country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(subject)),
"start_date", ONE_EXACTLY, expect_date_identifier_or_string(assign_variable_callback(start)),
"end_date", ZERO_OR_ONE, expect_date_identifier_or_string(assign_variable_callback(end))
)(node);
@@ -163,8 +171,10 @@ bool DiplomaticHistoryManager::load_diplomacy_history_file(CountryManager const&
std::optional<Date> end {};
bool ret = expect_dictionary_keys(
- "first", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(overlord)),
- "second", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(subject)),
+ "first", ONE_EXACTLY,
+ country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(overlord)),
+ "second", ONE_EXACTLY,
+ country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(subject)),
"start_date", ONE_EXACTLY, expect_date_identifier_or_string(assign_variable_callback(start)),
"end_date", ZERO_OR_ONE, expect_date_identifier_or_string(assign_variable_callback(end))
)(node);
@@ -179,8 +189,10 @@ bool DiplomaticHistoryManager::load_diplomacy_history_file(CountryManager const&
std::optional<Date> end {};
bool ret = expect_dictionary_keys(
- "first", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(receiver)),
- "second", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(sender)),
+ "first", ONE_EXACTLY,
+ country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(receiver)),
+ "second", ONE_EXACTLY,
+ country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(sender)),
"start_date", ONE_EXACTLY, expect_date_identifier_or_string(assign_variable_callback(start)),
"end_date", ZERO_OR_ONE, expect_date_identifier_or_string(assign_variable_callback(end))
)(node);
@@ -199,88 +211,133 @@ bool DiplomaticHistoryManager::load_war_history_file(GameManager const& game_man
Date current_date {};
bool ret = expect_dictionary_keys_and_default(
- [&game_manager, &attackers, &defenders, &wargoals, &current_date, &name](std::string_view key, ast::NodeCPtr node) -> bool {
+ [&game_manager, &attackers, &defenders, &wargoals, &current_date, &name](
+ std::string_view key, ast::NodeCPtr node
+ ) -> bool {
bool ret = expect_date_str(assign_variable_callback(current_date))(key);
+
ret &= expect_dictionary_keys(
- "add_attacker", ZERO_OR_MORE, game_manager.get_country_manager().expect_country_identifier([&attackers, &current_date, &name](Country const& country) -> bool {
- for (const auto& attacker : attackers) {
- if (attacker.get_country() == &country) {
- Logger::error("In history of war ", name, " at date ", current_date.to_string(), ": Attempted to add attacking country ", attacker.get_country()->get_identifier(), " which is already present!");
- return false;
+ "add_attacker", ZERO_OR_MORE, game_manager.get_country_manager().expect_country_identifier(
+ [&attackers, &current_date, &name](Country const& country) -> bool {
+ for (auto const& attacker : attackers) {
+ if (attacker.get_country() == &country) {
+ Logger::error(
+ "In history of war ", name, " at date ", current_date.to_string(),
+ ": Attempted to add attacking country ", attacker.get_country()->get_identifier(),
+ " which is already present!"
+ );
+ return false;
+ }
}
- }
- attackers.push_back({ &country, { current_date, {} } });
- return true;
- }),
- "add_defender", ZERO_OR_MORE, game_manager.get_country_manager().expect_country_identifier([&defenders, &current_date, &name](Country const& country) -> bool {
- for (const auto& defender : defenders) {
- if (defender.get_country() == &country) {
- Logger::error("In history of war ", name, " at date ", current_date.to_string(), ": Attempted to add defending country ", defender.get_country()->get_identifier(), " which is already present!");
- return false;
- }
+ attackers.push_back({ &country, { current_date, {} } });
+ return true;
}
-
- defenders.push_back({ &country, { current_date, {} } });
- return true;
- }),
- "rem_attacker", ZERO_OR_MORE, game_manager.get_country_manager().expect_country_identifier([&attackers, &current_date, &name](Country const& country) -> bool {
- WarHistory::war_participant_t* participant_to_remove = nullptr;
-
- for (auto& attacker : attackers) {
- if (attacker.country == &country) {
- participant_to_remove = &attacker;
- break;
+ ),
+ "add_defender", ZERO_OR_MORE, game_manager.get_country_manager().expect_country_identifier(
+ [&defenders, &current_date, &name](Country const& country) -> bool {
+ for (auto const& defender : defenders) {
+ if (defender.get_country() == &country) {
+ Logger::error(
+ "In history of war ", name, " at date ", current_date.to_string(),
+ ": Attempted to add defending country ", defender.get_country()->get_identifier(),
+ " which is already present!"
+ );
+ return false;
+ }
}
- }
- if (participant_to_remove == nullptr) {
- Logger::warning("In history of war ", name, " at date ", current_date.to_string(), ": Attempted to remove attacking country ", country.get_identifier(), " which was not present!");
+ defenders.push_back({ &country, { current_date, {} } });
return true;
}
+ ),
+ "rem_attacker", ZERO_OR_MORE, game_manager.get_country_manager().expect_country_identifier(
+ [&attackers, &current_date, &name](Country const& country) -> bool {
+ WarHistory::war_participant_t* participant_to_remove = nullptr;
+
+ for (auto& attacker : attackers) {
+ if (attacker.country == &country) {
+ participant_to_remove = &attacker;
+ break;
+ }
+ }
- return participant_to_remove->period.try_set_end(current_date);
- }),
- "rem_defender", ZERO_OR_MORE, game_manager.get_country_manager().expect_country_identifier([&defenders, &current_date, &name](Country const& country) -> bool {
- WarHistory::war_participant_t* participant_to_remove = nullptr;
-
- for (auto& defender : defenders) {
- if (defender.country == &country) {
- participant_to_remove = &defender;
- break;
+ if (participant_to_remove == nullptr) {
+ Logger::warning(
+ "In history of war ", name, " at date ", current_date.to_string(),
+ ": Attempted to remove attacking country ", country.get_identifier(),
+ " which was not present!"
+ );
+ return true;
}
- }
- if (participant_to_remove == nullptr) {
- Logger::warning("In history of war ", name, " at date ", current_date.to_string(), ": Attempted to remove attacking country ", country.get_identifier(), " which was not present!");
- return true;
+ return participant_to_remove->period.try_set_end(current_date);
}
+ ),
+ "rem_defender", ZERO_OR_MORE, game_manager.get_country_manager().expect_country_identifier(
+ [&defenders, &current_date, &name](Country const& country) -> bool {
+ WarHistory::war_participant_t* participant_to_remove = nullptr;
+
+ for (auto& defender : defenders) {
+ if (defender.country == &country) {
+ participant_to_remove = &defender;
+ break;
+ }
+ }
- return participant_to_remove->period.try_set_end(current_date);
- }),
+ if (participant_to_remove == nullptr) {
+ Logger::warning(
+ "In history of war ", name, " at date ", current_date.to_string(),
+ ": Attempted to remove attacking country ", country.get_identifier(),
+ " which was not present!"
+ );
+ return true;
+ }
+
+ return participant_to_remove->period.try_set_end(current_date);
+ }
+ ),
"war_goal", ZERO_OR_MORE, [&game_manager, &wargoals, &current_date](ast::NodeCPtr value) -> bool {
Country const* actor = nullptr;
Country const* receiver = nullptr;
WargoalType const* type = nullptr;
std::optional<Country const*> third_party {};
- std::optional<Province const*> target {};
+ std::optional<ProvinceDefinition const*> target {};
bool ret = expect_dictionary_keys(
- "actor", ONE_EXACTLY, game_manager.get_country_manager().expect_country_identifier(assign_variable_callback_pointer(actor)),
- "receiver", ONE_EXACTLY, game_manager.get_country_manager().expect_country_identifier(assign_variable_callback_pointer(receiver)),
- "casus_belli", ONE_EXACTLY, game_manager.get_military_manager().get_wargoal_type_manager().expect_wargoal_type_identifier(assign_variable_callback_pointer(type)),
- "country", ZERO_OR_ONE, game_manager.get_country_manager().expect_country_identifier(assign_variable_callback_pointer(*third_party)),
- "state_province_id", ZERO_OR_ONE, game_manager.get_map().expect_province_identifier(assign_variable_callback_pointer(*target))
+ "actor", ONE_EXACTLY,
+ game_manager.get_country_manager().expect_country_identifier(
+ assign_variable_callback_pointer(actor)
+ ),
+ "receiver", ONE_EXACTLY,
+ game_manager.get_country_manager().expect_country_identifier(
+ assign_variable_callback_pointer(receiver)
+ ),
+ "casus_belli", ONE_EXACTLY,
+ game_manager.get_military_manager().get_wargoal_type_manager().expect_wargoal_type_identifier(
+ assign_variable_callback_pointer(type)
+ ),
+ "country", ZERO_OR_ONE,
+ game_manager.get_country_manager().expect_country_identifier(
+ assign_variable_callback_pointer(*third_party)
+ ),
+ "state_province_id", ZERO_OR_ONE,
+ game_manager.get_map().expect_province_definition_identifier(
+ assign_variable_callback_pointer(*target)
+ )
)(value);
+
wargoals.push_back({ current_date, actor, receiver, type, third_party, target });
return ret;
}
)(node);
+
return ret;
},
"name", ZERO_OR_ONE, expect_string(assign_variable_callback(name))
)(root);
wars.push_back({ name, std::move(attackers), std::move(defenders), std::move(wargoals) });
+
return ret;
-} \ No newline at end of file
+}
diff --git a/src/openvic-simulation/history/DiplomaticHistory.hpp b/src/openvic-simulation/history/DiplomaticHistory.hpp
index 35ba6fb..7ae5114 100644
--- a/src/openvic-simulation/history/DiplomaticHistory.hpp
+++ b/src/openvic-simulation/history/DiplomaticHistory.hpp
@@ -1,15 +1,18 @@
#pragma once
-#include <vector>
#include <optional>
+#include <vector>
-#include "openvic-simulation/country/Country.hpp"
-#include "openvic-simulation/military/Wargoal.hpp"
-#include "openvic-simulation/map/Province.hpp"
+#include "openvic-simulation/dataloader/NodeTools.hpp"
#include "openvic-simulation/history/Period.hpp"
+#include "openvic-simulation/types/Date.hpp"
+#include "openvic-simulation/utility/Getters.hpp"
namespace OpenVic {
struct DiplomaticHistoryManager;
+ struct Country;
+ struct WargoalType;
+ struct ProvinceDefinition;
struct WarHistory {
friend struct DiplomaticHistoryManager;
@@ -22,10 +25,15 @@ namespace OpenVic {
Country const* PROPERTY(actor);
Country const* PROPERTY(receiver);
WargoalType const* PROPERTY(wargoal);
+
+ // TODO - could these just be nullptr when unset rather than using optionals?
std::optional<Country const*> PROPERTY(third_party);
- std::optional<Province const*> PROPERTY(target);
+ std::optional<ProvinceDefinition const*> PROPERTY(target);
- added_wargoal_t(Date new_added, Country const* new_actor, Country const* new_receiver, WargoalType const* new_wargoal, std::optional<Country const*> new_third_party, std::optional<Province const*> new_target);
+ added_wargoal_t(
+ Date new_added, Country const* new_actor, Country const* new_receiver, WargoalType const* new_wargoal,
+ std::optional<Country const*> new_third_party, std::optional<ProvinceDefinition const*> new_target
+ );
};
struct war_participant_t {
@@ -39,12 +47,17 @@ namespace OpenVic {
};
private:
- std::string PROPERTY(war_name); // edge cases where this is empty/undef for some reason, probably need to just generate war names like usual for that.
+ /* Edge cases where this is empty/undef for some reason,
+ * probably need to just generate war names like usual for that. */
+ std::string PROPERTY(war_name);
std::vector<war_participant_t> PROPERTY(attackers);
std::vector<war_participant_t> PROPERTY(defenders);
std::vector<added_wargoal_t> PROPERTY(wargoals);
- WarHistory(std::string_view new_war_name, std::vector<war_participant_t>&& new_attackers, std::vector<war_participant_t>&& new_defenders, std::vector<added_wargoal_t>&& new_wargoals);
+ WarHistory(
+ std::string_view new_war_name, std::vector<war_participant_t>&& new_attackers,
+ std::vector<war_participant_t>&& new_defenders, std::vector<added_wargoal_t>&& new_wargoals
+ );
};
struct AllianceHistory {
@@ -87,6 +100,9 @@ namespace OpenVic {
SubjectHistory(Country const* new_overlord, Country const* new_subject, const type_t new_type, const Period period);
};
+ struct CountryManager;
+ struct GameManager;
+
struct DiplomaticHistoryManager {
private:
std::vector<AllianceHistory> alliances;
@@ -105,10 +121,11 @@ namespace OpenVic {
std::vector<AllianceHistory const*> get_alliances(Date date) const;
std::vector<ReparationsHistory const*> get_reparations(Date date) const;
std::vector<SubjectHistory const*> get_subjects(Date date) const;
- /* Returns all wars that begin before date. NOTE: Some wargoals may be added or countries may join after date, should be checked for by functions that use get_wars() */
+ /* Returns all wars that begin before date. NOTE: Some wargoals may be added or countries may join after date,
+ * should be checked for by functions that use get_wars() */
std::vector<WarHistory const*> get_wars(Date date) const;
bool load_diplomacy_history_file(CountryManager const& country_manager, ast::NodeCPtr root);
bool load_war_history_file(GameManager const& game_manager, ast::NodeCPtr root);
};
-} // namespace OpenVic \ No newline at end of file
+}
diff --git a/src/openvic-simulation/history/Period.cpp b/src/openvic-simulation/history/Period.cpp
index 37758a1..2c6589c 100644
--- a/src/openvic-simulation/history/Period.cpp
+++ b/src/openvic-simulation/history/Period.cpp
@@ -1,4 +1,6 @@
-#include "openvic-simulation/history/Period.hpp"
+#include "Period.hpp"
+
+#include "openvic-simulation/utility/Logger.hpp"
using namespace OpenVic;
@@ -24,4 +26,4 @@ bool Period::try_set_end(const Date date) {
end_date = date;
return true;
-} \ No newline at end of file
+}
diff --git a/src/openvic-simulation/history/Period.hpp b/src/openvic-simulation/history/Period.hpp
index c788be9..d8b5ade 100644
--- a/src/openvic-simulation/history/Period.hpp
+++ b/src/openvic-simulation/history/Period.hpp
@@ -1,8 +1,8 @@
#pragma once
#include <optional>
+
#include "openvic-simulation/types/Date.hpp"
-#include "openvic-simulation/utility/Logger.hpp"
namespace OpenVic {
struct Period {
@@ -15,4 +15,4 @@ namespace OpenVic {
bool is_date_in_period(const Date date) const;
bool try_set_end(const Date date);
};
-} \ No newline at end of file
+}
diff --git a/src/openvic-simulation/history/ProvinceHistory.cpp b/src/openvic-simulation/history/ProvinceHistory.cpp
index c22567b..645cf8d 100644
--- a/src/openvic-simulation/history/ProvinceHistory.cpp
+++ b/src/openvic-simulation/history/ProvinceHistory.cpp
@@ -1,15 +1,15 @@
#include "ProvinceHistory.hpp"
#include "openvic-simulation/GameManager.hpp"
-#include "openvic-simulation/dataloader/NodeTools.hpp"
+#include "openvic-simulation/map/ProvinceDefinition.hpp"
using namespace OpenVic;
using namespace OpenVic::NodeTools;
-ProvinceHistoryEntry::ProvinceHistoryEntry(Province const& new_province, Date new_date)
+ProvinceHistoryEntry::ProvinceHistoryEntry(ProvinceDefinition const& new_province, Date new_date)
: HistoryEntry { new_date }, province { new_province } {}
-ProvinceHistoryMap::ProvinceHistoryMap(Province const& new_province) : province { new_province } {}
+ProvinceHistoryMap::ProvinceHistoryMap(ProvinceDefinition const& new_province) : province { new_province } {}
std::unique_ptr<ProvinceHistoryEntry> ProvinceHistoryMap::_make_entry(Date date) const {
return std::unique_ptr<ProvinceHistoryEntry> { new ProvinceHistoryEntry { province, date } };
@@ -24,8 +24,8 @@ bool ProvinceHistoryMap::_load_history_entry(
IdeologyManager const& ideology_manager = game_manager.get_politics_manager().get_ideology_manager();
TerrainTypeManager const& terrain_type_manager = game_manager.get_map().get_terrain_type_manager();
- using enum Province::colony_status_t;
- static const string_map_t<Province::colony_status_t> colony_status_map {
+ using enum ProvinceInstance::colony_status_t;
+ static const string_map_t<ProvinceInstance::colony_status_t> colony_status_map {
{ "0", STATE }, { "1", PROTECTORATE }, { "2", COLONY }
};
@@ -66,7 +66,7 @@ bool ProvinceHistoryMap::_load_history_entry(
expect_identifier(expect_mapped_string(colony_status_map, assign_variable_callback(entry.colonial))),
"is_slave", ZERO_OR_ONE, expect_bool(assign_variable_callback(entry.slave)),
"trade_goods", ZERO_OR_ONE, good_manager.expect_good_identifier(assign_variable_callback_pointer_opt(entry.rgo)),
- "life_rating", ZERO_OR_ONE, expect_uint<Province::life_rating_t>(assign_variable_callback(entry.life_rating)),
+ "life_rating", ZERO_OR_ONE, expect_uint<ProvinceInstance::life_rating_t>(assign_variable_callback(entry.life_rating)),
"terrain", ZERO_OR_ONE, terrain_type_manager.expect_terrain_type_identifier(
assign_variable_callback_pointer_opt(entry.terrain_type)
),
@@ -101,8 +101,8 @@ bool ProvinceHistoryMap::_load_history_entry(
ret &= map_callback(entry.state_buildings, building_type)(level);
} else {
Logger::error(
- "Attempted to add province building \"", building_type, "\" to state building list of province history for ",
- entry.get_province()
+ "Attempted to add province building \"", building_type,
+ "\" to state building list of province history for ", entry.get_province()
);
ret = false;
}
@@ -121,7 +121,9 @@ void ProvinceHistoryManager::reserve_more_province_histories(size_t size) {
}
void ProvinceHistoryManager::lock_province_histories(Map const& map, bool detailed_errors) {
- std::vector<bool> province_checklist(map.get_province_count());
+ std::vector<ProvinceDefinition> const& provinces = map.get_province_definitions();
+
+ std::vector<bool> province_checklist(provinces.size());
for (decltype(province_histories)::value_type const& entry : province_histories) {
province_checklist[entry.first->get_index() - 1] = true;
}
@@ -129,7 +131,7 @@ void ProvinceHistoryManager::lock_province_histories(Map const& map, bool detail
size_t missing = 0;
for (size_t idx = 0; idx < province_checklist.size(); ++idx) {
if (!province_checklist[idx]) {
- Province const& province = *map.get_province_by_index(idx + 1);
+ ProvinceDefinition const& province = provinces[idx];
if (!province.is_water()) {
if (detailed_errors) {
Logger::warning("Province history missing for province: ", province.get_identifier());
@@ -150,7 +152,7 @@ bool ProvinceHistoryManager::is_locked() const {
return locked;
}
-ProvinceHistoryMap const* ProvinceHistoryManager::get_province_history(Province const* province) const {
+ProvinceHistoryMap const* ProvinceHistoryManager::get_province_history(ProvinceDefinition const* province) const {
if (province == nullptr) {
Logger::error("Attempted to access history of null province");
return nullptr;
@@ -164,7 +166,7 @@ ProvinceHistoryMap const* ProvinceHistoryManager::get_province_history(Province
}
}
-ProvinceHistoryMap* ProvinceHistoryManager::_get_or_make_province_history(Province const& province) {
+ProvinceHistoryMap* ProvinceHistoryManager::_get_or_make_province_history(ProvinceDefinition const& province) {
decltype(province_histories)::iterator it = province_histories.find(&province);
if (it == province_histories.end()) {
const std::pair<decltype(province_histories)::iterator, bool> result =
@@ -180,7 +182,7 @@ ProvinceHistoryMap* ProvinceHistoryManager::_get_or_make_province_history(Provin
}
bool ProvinceHistoryManager::load_province_history_file(
- GameManager const& game_manager, Province const& province, ast::NodeCPtr root
+ GameManager const& game_manager, ProvinceDefinition const& province, ast::NodeCPtr root
) {
if (locked) {
Logger::error(
@@ -229,8 +231,8 @@ bool ProvinceHistoryManager::load_pop_history_file(
Logger::error("Attempted to load pop history file after province history registry was locked!");
return false;
}
- return game_manager.get_map().expect_province_dictionary(
- [this, &game_manager, date, non_integer_size](Province const& province, ast::NodeCPtr node) -> bool {
+ return game_manager.get_map().expect_province_definition_dictionary(
+ [this, &game_manager, date, non_integer_size](ProvinceDefinition const& province, ast::NodeCPtr node) -> bool {
ProvinceHistoryMap* province_history = _get_or_make_province_history(province);
if (province_history != nullptr) {
return province_history->_load_province_pop_history(game_manager, date, node, non_integer_size);
diff --git a/src/openvic-simulation/history/ProvinceHistory.hpp b/src/openvic-simulation/history/ProvinceHistory.hpp
index 7611907..27d744d 100644
--- a/src/openvic-simulation/history/ProvinceHistory.hpp
+++ b/src/openvic-simulation/history/ProvinceHistory.hpp
@@ -1,39 +1,49 @@
#pragma once
+#include <optional>
#include <vector>
-#include "openvic-simulation/country/Country.hpp"
#include "openvic-simulation/economy/BuildingType.hpp"
-#include "openvic-simulation/economy/Good.hpp"
#include "openvic-simulation/history/HistoryMap.hpp"
-#include "openvic-simulation/map/Province.hpp"
-#include "openvic-simulation/map/TerrainType.hpp"
+#include "openvic-simulation/map/ProvinceInstance.hpp"
+#include "openvic-simulation/pop/Pop.hpp"
+#include "openvic-simulation/types/Date.hpp"
+#include "openvic-simulation/types/fixed_point/FixedPointMap.hpp"
#include "openvic-simulation/types/OrderedContainers.hpp"
+#include "openvic-simulation/utility/Getters.hpp"
namespace OpenVic {
struct ProvinceHistoryMap;
+ struct ProvinceDefinition;
+ struct Country;
+ struct Good;
+ struct TerrainType;
+ struct Ideology;
+ struct GameManager;
struct ProvinceHistoryEntry : HistoryEntry {
friend struct ProvinceHistoryMap;
private:
- Province const& PROPERTY(province);
+ ProvinceDefinition const& PROPERTY(province);
std::optional<Country const*> PROPERTY(owner);
std::optional<Country const*> PROPERTY(controller);
- std::optional<Province::colony_status_t> PROPERTY(colonial);
+ std::optional<ProvinceInstance::colony_status_t> PROPERTY(colonial);
std::optional<bool> PROPERTY(slave);
std::vector<Country const*> PROPERTY(add_cores);
std::vector<Country const*> PROPERTY(remove_cores);
std::optional<Good const*> PROPERTY(rgo);
- std::optional<Province::life_rating_t> PROPERTY(life_rating);
+ std::optional<ProvinceInstance::life_rating_t> PROPERTY(life_rating);
std::optional<TerrainType const*> PROPERTY(terrain_type);
ordered_map<BuildingType const*, BuildingType::level_t> PROPERTY(province_buildings);
ordered_map<BuildingType const*, BuildingType::level_t> PROPERTY(state_buildings);
fixed_point_map_t<Ideology const*> PROPERTY(party_loyalties);
+
+ // TODO - use minimal pop representation (size, type, culture, religion, consciousness, militancy, rebel type)
std::vector<Pop> PROPERTY(pops);
- ProvinceHistoryEntry(Province const& new_province, Date new_date);
+ ProvinceHistoryEntry(ProvinceDefinition const& new_province, Date new_date);
bool _load_province_pop_history(GameManager const& game_manager, ast::NodeCPtr root, bool *non_integer_size);
};
@@ -44,10 +54,10 @@ namespace OpenVic {
friend struct ProvinceHistoryManager;
private:
- Province const& PROPERTY(province);
+ ProvinceDefinition const& PROPERTY(province);
protected:
- ProvinceHistoryMap(Province const& new_province);
+ ProvinceHistoryMap(ProvinceDefinition const& new_province);
std::unique_ptr<ProvinceHistoryEntry> _make_entry(Date date) const override;
bool _load_history_entry(GameManager const& game_manager, ProvinceHistoryEntry& entry, ast::NodeCPtr root) override;
@@ -58,12 +68,14 @@ namespace OpenVic {
);
};
+ struct Map;
+
struct ProvinceHistoryManager {
private:
- ordered_map<Province const*, ProvinceHistoryMap> province_histories;
+ ordered_map<ProvinceDefinition const*, ProvinceHistoryMap> province_histories;
bool locked = false;
- ProvinceHistoryMap* _get_or_make_province_history(Province const& province);
+ ProvinceHistoryMap* _get_or_make_province_history(ProvinceDefinition const& province);
public:
ProvinceHistoryManager() = default;
@@ -72,9 +84,11 @@ namespace OpenVic {
void lock_province_histories(Map const& map, bool detailed_errors);
bool is_locked() const;
- ProvinceHistoryMap const* get_province_history(Province const* province) const;
+ ProvinceHistoryMap const* get_province_history(ProvinceDefinition const* province) const;
- bool load_province_history_file(GameManager const& game_manager, Province const& province, ast::NodeCPtr root);
+ bool load_province_history_file(
+ GameManager const& game_manager, ProvinceDefinition const& province, ast::NodeCPtr root
+ );
bool load_pop_history_file(GameManager const& game_manager, Date date, ast::NodeCPtr root, bool *non_integer_size);
};
-} // namespace OpenVic
+}