10
10
#include " openvic-simulation/politics/Ideology.hpp"
11
11
#include " openvic-simulation/research/Invention.hpp"
12
12
#include " openvic-simulation/research/Technology.hpp"
13
+ #include " openvic-simulation/scripts/Condition.hpp"
14
+ #include " openvic-simulation/utility/Logger.hpp"
13
15
14
16
using namespace OpenVic ;
15
17
@@ -665,7 +667,8 @@ void CountryInstance::apply_foreign_investments(
665
667
}
666
668
667
669
bool CountryInstance::apply_history_to_country (
668
- CountryHistoryEntry const & entry, MapInstance& map_instance, CountryInstanceManager const & country_instance_manager
670
+ CountryHistoryEntry const & entry, MapInstance& map_instance, CountryInstanceManager const & country_instance_manager,
671
+ TechnologyManager const & technology_manager, InventionManager const & invention_manager
669
672
) {
670
673
constexpr auto set_optional = []<typename T>(T& target, std::optional<T> const & source) {
671
674
if (source) {
@@ -712,6 +715,49 @@ bool CountryInstance::apply_history_to_country(
712
715
for (auto const & [technology, level] : entry.get_technologies ()) {
713
716
ret &= set_technology_unlock_level (*technology, level);
714
717
}
718
+
719
+ const auto inform_limit_parsing_failed = [](Invention const & invention) {
720
+ Logger::warning (" Failed to parse limit for invention " , invention.get_identifier ());
721
+ };
722
+
723
+ for (Invention const & invention : invention_manager.get_inventions ()) {
724
+ ConditionNode const & root_condition_node = invention.get_limit ().get_condition_root ();
725
+ Condition const * const root_condition_ptr = root_condition_node.get_condition ();
726
+ if (root_condition_ptr == nullptr ) {
727
+ continue ;
728
+ }
729
+ Condition const & root_condition = *root_condition_ptr;
730
+ if (root_condition.get_value_type () != value_type_t ::GROUP
731
+ || root_condition.get_identifier () != " AND" ) {
732
+ inform_limit_parsing_failed (invention);
733
+ continue ;
734
+ }
735
+
736
+ ConditionNode::condition_list_t const & condition_list = std::get<ConditionNode::condition_list_t >(root_condition_node.get_value ());
737
+ if (condition_list.size () != 1 ) {
738
+ inform_limit_parsing_failed (invention);
739
+ continue ;
740
+ }
741
+
742
+ ConditionNode const & condition_node = condition_list[0 ];
743
+ Condition const * const condition_ptr = condition_node.get_condition ();
744
+ if (condition_ptr == nullptr ) {
745
+ inform_limit_parsing_failed (invention);
746
+ continue ;
747
+ }
748
+
749
+ Condition const & condition = *condition_ptr;
750
+ if (condition.get_key_identifier_type () != identifier_type_t ::TECHNOLOGY) {
751
+ inform_limit_parsing_failed (invention);
752
+ continue ;
753
+ }
754
+
755
+ Technology const * const required_technology = technology_manager.get_technology_by_identifier (condition_node.get_condition_key_item ()->get_identifier ());
756
+ if (is_technology_unlocked (*required_technology)) {
757
+ ret &= set_invention_unlock_level (invention, 1 );
758
+ }
759
+ }
760
+
715
761
for (auto const & [invention, activated] : entry.get_inventions ()) {
716
762
ret &= set_invention_unlock_level (*invention, activated ? 1 : 0 );
717
763
}
@@ -1256,7 +1302,7 @@ bool CountryInstanceManager::generate_country_instances(
1256
1302
1257
1303
bool CountryInstanceManager::apply_history_to_countries (
1258
1304
CountryHistoryManager const & history_manager, Date date, UnitInstanceManager& unit_instance_manager,
1259
- MapInstance& map_instance
1305
+ MapInstance& map_instance, TechnologyManager const & technology_manager, InventionManager const & invention_manager
1260
1306
) {
1261
1307
bool ret = true ;
1262
1308
@@ -1270,7 +1316,7 @@ bool CountryInstanceManager::apply_history_to_countries(
1270
1316
1271
1317
for (auto const & [entry_date, entry] : history_map->get_entries ()) {
1272
1318
if (entry_date <= date) {
1273
- ret &= country_instance.apply_history_to_country (*entry, map_instance, *this );
1319
+ ret &= country_instance.apply_history_to_country (*entry, map_instance, *this , technology_manager, invention_manager );
1274
1320
1275
1321
if (entry->get_inital_oob ()) {
1276
1322
oob_history_entry = entry.get ();
0 commit comments