44
55#include " openvic-simulation/country/CountryDefinition.hpp"
66#include " openvic-simulation/defines/Define.hpp"
7+ #include " openvic-simulation/DefinitionManager.hpp"
78#include " openvic-simulation/history/CountryHistory.hpp"
9+ #include " openvic-simulation/InstanceManager.hpp"
810#include " openvic-simulation/map/Crime.hpp"
911#include " openvic-simulation/map/MapInstance.hpp"
1012#include " openvic-simulation/modifier/ModifierEffectCache.hpp"
@@ -41,6 +43,7 @@ CountryInstance::CountryInstance(
4143 capital { nullptr },
4244 ai { true },
4345 releasable_vassal { true },
46+ owns_colonial_province { false },
4447 country_status { COUNTRY_STATUS_UNCIVILISED },
4548 lose_great_power_date {},
4649 total_score { 0 },
@@ -207,6 +210,11 @@ bool CountryInstance::is_secondary_power() const {
207210 return country_status == COUNTRY_STATUS_SECONDARY_POWER;
208211}
209212
213+ bool CountryInstance::is_at_war () const {
214+ // TODO - implement this properly once we have wars
215+ return false ;
216+ }
217+
210218fixed_point_t CountryInstance::get_pop_type_proportion (PopType const & pop_type) const {
211219 return pop_type_distribution[pop_type];
212220}
@@ -763,9 +771,7 @@ void CountryInstance::apply_foreign_investments(
763771 }
764772}
765773
766- bool CountryInstance::apply_history_to_country (
767- CountryHistoryEntry const & entry, MapInstance& map_instance, CountryInstanceManager const & country_instance_manager
768- ) {
774+ bool CountryInstance::apply_history_to_country (CountryHistoryEntry const & entry, InstanceManager const & instance_manager) {
769775 constexpr auto set_optional = []<typename T>(T& target, std::optional<T> const & source) {
770776 if (source) {
771777 target = *source;
@@ -789,7 +795,7 @@ bool CountryInstance::apply_history_to_country(
789795 set_optional (last_election, entry.get_last_election ());
790796 ret &= upper_house.copy (entry.get_upper_house ());
791797 if (entry.get_capital ()) {
792- capital = &map_instance .get_province_instance_from_definition (**entry.get_capital ());
798+ capital = &instance_manager. get_map_instance () .get_province_instance_from_definition (**entry.get_capital ());
793799 }
794800 set_optional (government_type, entry.get_government_type ());
795801 set_optional (plurality, entry.get_plurality ());
@@ -811,10 +817,24 @@ bool CountryInstance::apply_history_to_country(
811817 for (auto const & [technology, level] : entry.get_technologies ()) {
812818 ret &= set_technology_unlock_level (*technology, level);
813819 }
820+
821+ for (
822+ Invention const & invention :
823+ instance_manager.get_definition_manager ().get_research_manager ().get_invention_manager ().get_inventions ()
824+ ) {
825+ if (
826+ invention.get_limit ().execute (instance_manager, this , this ) &&
827+ invention.get_chance ().execute (instance_manager, this , this ) > 0
828+ ) {
829+ ret &= unlock_invention (invention);
830+ // Logger::info("Unlocked invention ", invention.get_identifier(), " for country ", get_identifier());
831+ }
832+ }
833+
814834 for (auto const & [invention, activated] : entry.get_inventions ()) {
815835 ret &= set_invention_unlock_level (*invention, activated ? 1 : 0 );
816836 }
817- apply_foreign_investments (entry.get_foreign_investment (), country_instance_manager );
837+ apply_foreign_investments (entry.get_foreign_investment (), instance_manager. get_country_instance_manager () );
818838
819839 // These need to be applied to pops
820840 // entry.get_consciousness();
@@ -1162,6 +1182,14 @@ void CountryInstance::update_gamestate(
11621182 DefineManager const & define_manager, UnitTypeManager const & unit_type_manager,
11631183 ModifierEffectCache const & modifier_effect_cache
11641184) {
1185+ owns_colonial_province = std::any_of (
1186+ owned_provinces.begin (), owned_provinces.end (),
1187+ [](ProvinceInstance const * province) -> bool {
1188+ using enum ProvinceInstance::colony_status_t ;
1189+ return province->get_colony_status () != STATE;
1190+ }
1191+ );
1192+
11651193 // Order of updates might need to be changed/functions split up to account for dependencies
11661194 _update_production (define_manager);
11671195 _update_budget ();
@@ -1363,10 +1391,13 @@ bool CountryInstanceManager::generate_country_instances(
13631391 return ret;
13641392}
13651393
1366- bool CountryInstanceManager::apply_history_to_countries (
1367- CountryHistoryManager const & history_manager, Date date, UnitInstanceManager& unit_instance_manager,
1368- MapInstance& map_instance
1369- ) {
1394+ bool CountryInstanceManager::apply_history_to_countries (InstanceManager& instance_manager) {
1395+ CountryHistoryManager const & history_manager =
1396+ instance_manager.get_definition_manager ().get_history_manager ().get_country_manager ();
1397+ const Date today = instance_manager.get_today ();
1398+ UnitInstanceManager& unit_instance_manager = instance_manager.get_unit_instance_manager ();
1399+ MapInstance& map_instance = instance_manager.get_map_instance ();
1400+
13701401 bool ret = true ;
13711402
13721403 for (CountryInstance& country_instance : country_instances.get_items ()) {
@@ -1378,8 +1409,8 @@ bool CountryInstanceManager::apply_history_to_countries(
13781409 CountryHistoryEntry const * oob_history_entry = nullptr ;
13791410
13801411 for (auto const & [entry_date, entry] : history_map->get_entries ()) {
1381- if (entry_date <= date ) {
1382- ret &= country_instance.apply_history_to_country (*entry, map_instance, * this );
1412+ if (entry_date <= today ) {
1413+ ret &= country_instance.apply_history_to_country (*entry, instance_manager );
13831414
13841415 if (entry->get_inital_oob ()) {
13851416 oob_history_entry = entry.get ();
0 commit comments