@@ -1420,7 +1420,15 @@ fixed_point_t CountryInstance::get_modifier_effect_value(ModifierEffect const& e
14201420}
14211421
14221422void CountryInstance::update_gamestate (InstanceManager& instance_manager) {
1423- if (!is_civilised ()) {
1423+ DefinitionManager const & definition_manager = instance_manager.get_definition_manager ();
1424+ DefineManager const & define_manager = definition_manager.get_define_manager ();
1425+ ModifierEffectCache const & modifier_effect_cache = definition_manager.get_modifier_manager ().get_modifier_effect_cache ();
1426+
1427+ if (is_civilised ()) {
1428+ civilisation_progress = fixed_point_t::_0 ();
1429+ } else {
1430+ civilisation_progress = get_modifier_effect_value (*modifier_effect_cache.get_civilization_progress_modifier ());
1431+
14241432 if (civilisation_progress <= PRIMITIVE_CIVILISATION_PROGRESS) {
14251433 country_status = COUNTRY_STATUS_PRIMITIVE;
14261434 } else if (civilisation_progress <= UNCIVILISED_CIVILISATION_PROGRESS) {
@@ -1449,10 +1457,6 @@ void CountryInstance::update_gamestate(InstanceManager& instance_manager) {
14491457 }
14501458 }
14511459
1452- DefinitionManager const & definition_manager = instance_manager.get_definition_manager ();
1453- DefineManager const & define_manager = definition_manager.get_define_manager ();
1454- ModifierEffectCache const & modifier_effect_cache = definition_manager.get_modifier_manager ().get_modifier_effect_cache ();
1455-
14561460 // Order of updates might need to be changed/functions split up to account for dependencies
14571461 // Updates population stats (including research and leadership points from pops)
14581462 _update_population ();
@@ -1499,7 +1503,7 @@ void CountryInstance::country_reset_before_tick() {
14991503 for (auto pair : goods_data) {
15001504 pair.second .clear_daily_recorded_data ();
15011505 }
1502-
1506+
15031507 taxable_income_by_pop_type.fill (fixed_point_t::_0 ());
15041508}
15051509
@@ -1704,19 +1708,26 @@ void CountryInstanceManager::update_rankings(Date today, DefineManager const& de
17041708 // Demote great powers who have been below the max great power rank for longer than the demotion grace period and
17051709 // remove them from the list. We don't just demote them all and clear the list as when rebuilding we'd need to look
17061710 // ahead for countries below the max great power rank but still within the demotion grace period.
1707- for (CountryInstance* great_power : great_powers) {
1708- if (great_power->get_total_rank () > max_great_power_rank && great_power->get_lose_great_power_date () < today) {
1709- great_power->country_status = COUNTRY_STATUS_CIVILISED;
1711+ std::erase_if (great_powers, [max_great_power_rank, today](CountryInstance* great_power) -> bool {
1712+ if (OV_likely (great_power->get_country_status () == COUNTRY_STATUS_GREAT_POWER)) {
1713+ if (OV_unlikely (
1714+ great_power->get_total_rank () > max_great_power_rank && great_power->get_lose_great_power_date () < today
1715+ )) {
1716+ great_power->country_status = COUNTRY_STATUS_CIVILISED;
1717+ return true ;
1718+ } else {
1719+ return false ;
1720+ }
17101721 }
1711- }
1712- std::erase_if (great_powers, [](CountryInstance const * country) -> bool {
1713- return country->get_country_status () != COUNTRY_STATUS_GREAT_POWER;
1722+ return true ;
17141723 });
17151724
17161725 // Demote all secondary powers and clear the list. We will rebuilt the whole list from scratch, so there's no need to
17171726 // keep countries which are still above the max secondary power rank (they might become great powers instead anyway).
17181727 for (CountryInstance* secondary_power : secondary_powers) {
1719- secondary_power->country_status = COUNTRY_STATUS_CIVILISED;
1728+ if (secondary_power->country_status == COUNTRY_STATUS_SECONDARY_POWER) {
1729+ secondary_power->country_status = COUNTRY_STATUS_CIVILISED;
1730+ }
17201731 }
17211732 secondary_powers.clear ();
17221733
@@ -1845,7 +1856,11 @@ bool CountryInstanceManager::apply_history_to_countries(InstanceManager& instanc
18451856 UnitInstanceManager& unit_instance_manager = instance_manager.get_unit_instance_manager ();
18461857 MapInstance& map_instance = instance_manager.get_map_instance ();
18471858
1859+ const Date starting_last_war_loss_date = today - RECENT_TIME_LIMIT;
1860+
18481861 for (CountryInstance& country_instance : country_instances.get_items ()) {
1862+ country_instance.last_war_loss_date = starting_last_war_loss_date;
1863+
18491864 if (!country_instance.get_country_definition ()->is_dynamic_tag ()) {
18501865 CountryHistoryMap const * history_map =
18511866 history_manager.get_country_history (country_instance.get_country_definition ());
@@ -1931,6 +1946,10 @@ void CountryInstanceManager::update_gamestate(InstanceManager& instance_manager)
19311946 country.update_gamestate (instance_manager);
19321947 }
19331948
1949+ // TODO - work out how to have ranking effects applied (e.g. static modifiers) applied at game start
1950+ // we can't just move update_rankings to the top of this function as it will choose initial GPs based on
1951+ // incomplete scores. Although we should check if the base game includes all info or if it really does choose
1952+ // starting GPs based purely on stuff like prestige which is set by history before the first game update.
19341953 update_rankings (instance_manager.get_today (), instance_manager.get_definition_manager ().get_define_manager ());
19351954}
19361955
0 commit comments