Skip to content

Commit 7f8396c

Browse files
committed
Check starting invention limits with new condition system
1 parent 9137097 commit 7f8396c

File tree

6 files changed

+317
-72
lines changed

6 files changed

+317
-72
lines changed

src/openvic-simulation/InstanceManager.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ bool InstanceManager::load_bookmark(Bookmark const* new_bookmark) {
137137
definition_manager.get_politics_manager().get_issue_manager()
138138
);
139139

140-
ret &= country_instance_manager.apply_history_to_countries(
141-
definition_manager.get_history_manager().get_country_manager(), today, unit_instance_manager, map_instance
142-
);
140+
ret &= country_instance_manager.apply_history_to_countries(*this);
143141

144142
ret &= map_instance.get_state_manager().generate_states(
145143
map_instance,

src/openvic-simulation/country/CountryInstance.cpp

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
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+
210218
fixed_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();

src/openvic-simulation/country/CountryInstance.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ namespace OpenVic {
8181
ProvinceInstance const* PROPERTY(capital);
8282
bool PROPERTY_CUSTOM_PREFIX(ai, is);
8383
bool PROPERTY_CUSTOM_PREFIX(releasable_vassal, is);
84+
bool PROPERTY(owns_colonial_province);
8485

8586
country_status_t PROPERTY(country_status);
8687
Date PROPERTY(lose_great_power_date);
@@ -235,6 +236,7 @@ namespace OpenVic {
235236
bool can_colonise() const;
236237
bool is_great_power() const;
237238
bool is_secondary_power() const;
239+
bool is_at_war() const;
238240

239241
// The values returned by these functions are scaled by population size, so they must be divided by population size
240242
// to get the support as a proportion of 1.0
@@ -340,9 +342,7 @@ namespace OpenVic {
340342
CountryInstanceManager const& country_instance_manager
341343
);
342344

343-
bool apply_history_to_country(
344-
CountryHistoryEntry const& entry, MapInstance& map_instance, CountryInstanceManager const& country_instance_manager
345-
);
345+
bool apply_history_to_country(CountryHistoryEntry const& entry, InstanceManager const& instance_manager);
346346

347347
private:
348348
void _update_production(DefineManager const& define_manager);
@@ -414,10 +414,7 @@ namespace OpenVic {
414414
decltype(CountryInstance::tax_rate_by_strata):: keys_type const& strata_keys
415415
);
416416

417-
bool apply_history_to_countries(
418-
CountryHistoryManager const& history_manager, Date date, UnitInstanceManager& unit_instance_manager,
419-
MapInstance& map_instance
420-
);
417+
bool apply_history_to_countries(InstanceManager& instance_manager);
421418

422419
void update_modifier_sums(Date today, StaticModifierCache const& static_modifier_cache);
423420
void update_gamestate(

0 commit comments

Comments
 (0)