From 0cde9e4819184de0e5592ae407e4ff8d4234ac02 Mon Sep 17 00:00:00 2001 From: Danarca <44327039+Danarca@users.noreply.github.com> Date: Fri, 24 Jan 2025 14:18:24 +0100 Subject: [PATCH] AI + cleanup AI can now change policy through an on_monthly. Their current diplomatic agenda/strategy is usually the deciding factor, with the exception of true neutrality (requires the modifier/status) and isolationism (which requires the trade law of the same name). Also re-configured the GLOBAL so it only goes through each country once. Small performance gain on starting the game, I assume :s Since this GLOBAL is fired immediately before the player takes control, even player countries get a relatively correct law! Just in case, the restricting variable is removed after firing in the GLOBAL, so players can select their own. --- common/history/global/imperia_global.txt | 42 +++-- common/laws/imperia_diplomatic_stance.txt | 2 +- .../on_actions/imperia_on_monthtly_pulse.txt | 3 + .../imperia_foreign_policy_effects.txt | 167 ++++++++++++++++++ .../imperia_political_setup.txt | 1 + common/scripted_guis/foreign_policy.txt | 6 +- .../english/imperia_law_l_english.yml | 4 +- 7 files changed, 195 insertions(+), 30 deletions(-) create mode 100644 common/scripted_effects/imperia_foreign_policy_effects.txt diff --git a/common/history/global/imperia_global.txt b/common/history/global/imperia_global.txt index 7f851c612..e2b108c84 100644 --- a/common/history/global/imperia_global.txt +++ b/common/history/global/imperia_global.txt @@ -1,15 +1,26 @@ GLOBAL = { - ### Infamy setup ### every_country = { + ### Infamy setup ### set_variable = { name = infamy_on_month_start value = infamy } - } - ### STRATEGIC REGIONS LIST FOR VIENNA CONGRESS ### - make_strategic_region_list = yes - ### TECHNOLOGIES ### - every_country = { + ### GAME START BUREAUCURACY BONUS ### + add_modifier = { + name = game_start_bureaucracy_bonus + is_decaying = yes + months = 121 + } + ### MONEY TRANSFER ### + set_variable = { + name = imperia_money_transfer_amount + value = 0 + } + ### SET STARTING FOREIGN POLICY ### + ## TEST ON PLAYERS ## + update_foreign_policy = yes + remove_variable ?= modifier_imperia_foreign_policy_cooldown # To allow players to change from the get-go + ### TECHNOLOGIES ### if = { limit = { any_state = { @@ -25,21 +36,8 @@ add_technology_researched = propellers } } - ### GAME START BUREAUCURACY BONUS ### - every_country = { - add_modifier = { - name = game_start_bureaucracy_bonus - is_decaying = yes - months = 121 - } - } - ### MONEY TRANSFER ### - every_country = { - set_variable = { - name = imperia_money_transfer_amount - value = 0 - } - } + ### STRATEGIC REGIONS LIST FOR VIENNA CONGRESS ### + make_strategic_region_list = yes # British East India Company subjects start with a mortality modifier c:BIC ?= { every_subject_or_below = { @@ -71,4 +69,4 @@ years = 30 } } -} \ No newline at end of file +} diff --git a/common/laws/imperia_diplomatic_stance.txt b/common/laws/imperia_diplomatic_stance.txt index 697845022..9142e2590 100644 --- a/common/laws/imperia_diplomatic_stance.txt +++ b/common/laws/imperia_diplomatic_stance.txt @@ -170,7 +170,7 @@ law_unification_nationalism = { } } -law_isolationism = { +law_foreign_isolationism = { group = lawgroup_diplomatic_stance icon = "gfx/interface/icons/law_icons/isolationism.dds" progressiveness = 0 diff --git a/common/on_actions/imperia_on_monthtly_pulse.txt b/common/on_actions/imperia_on_monthtly_pulse.txt index 637fcc505..0cb800481 100644 --- a/common/on_actions/imperia_on_monthtly_pulse.txt +++ b/common/on_actions/imperia_on_monthtly_pulse.txt @@ -440,6 +440,9 @@ else = { remove_modifier ?= imperia_invalid_mobilization_option_penalty } + # Change AI foreign policy if applicable + ai_update_foreign_policy = yes + } random_events = { 23 = 0 diff --git a/common/scripted_effects/imperia_foreign_policy_effects.txt b/common/scripted_effects/imperia_foreign_policy_effects.txt new file mode 100644 index 000000000..e58e61cb9 --- /dev/null +++ b/common/scripted_effects/imperia_foreign_policy_effects.txt @@ -0,0 +1,167 @@ +ai_update_foreign_policy = { + # This only works for AI countries + if = { + limit = { + is_player = no + } + update_foreign_policy = yes + } +} + +update_foreign_policy = { + # This one also works for players, used in the initial GLOBAL + if = { + # This should only work if theres no cooldown currently active + limit = { + NOT = { + has_variable = modifier_imperia_foreign_policy_cooldown + } + } + # First check for true neutrality + if = { + limit = { + has_modifier = imperia_true_neutral + NOT = { + has_law = law_type:law_true_neutrality + } + } + activate_law = law_type:law_true_neutrality + add_foreign_policy_cooldown = yes + } + # Check for isolationism (trade policy) + else_if = { + limit = { + has_law = law_type:law_isolationism + NOT = { + has_law = law_type:law_foreign_isolationism + } + } + activate_law = law_type:law_foreign_isolationism + add_foreign_policy_cooldown = yes + } + else_if = { + limit = { + has_strategy = ai_strategy_maintain_power_balance + NOT = { + has_law = law_type:law_realpolitik + } + } + activate_law = law_type:law_realpolitik + add_foreign_policy_cooldown = yes + } + else_if = { + limit = { + OR = { + has_strategy = ai_strategy_territorial_expansion + has_strategy = ai_strategy_restore_natural_borders # French unique strategy for the Rhine + } + NOT = { + has_law = law_type:law_expansionism + } + } + activate_law = law_type:law_expansionism + add_foreign_policy_cooldown = yes + } + else_if = { + limit = { + has_strategy = ai_strategy_colonial_expansion + NOT = { + has_law = law_type:law_imperialism + } + } + activate_law = law_type:law_imperialism + add_foreign_policy_cooldown = yes + } + else_if = { + limit = { + has_strategy = ai_strategy_armed_isolationism + NOT = { + has_law = law_type:law_armed_neutrality + } + } + activate_law = law_type:law_armed_neutrality + add_foreign_policy_cooldown = yes + } + else_if = { + limit = { + has_strategy = ai_strategy_economic_imperialism + NOT = { + has_law = law_type:law_splendid_isolationism + } + } + activate_law = law_type:law_splendid_isolationism + add_foreign_policy_cooldown = yes + } + else_if = { + limit = { + OR = { + has_strategy = ai_strategy_unify_germany + has_strategy = ai_strategy_unify_italy + has_strategy = ai_strategy_unify_ethiopia + has_strategy = ai_strategy_unify_china + } + NOT = { + has_law = law_type:law_unification_nationalism + } + } + activate_law = law_type:law_unification_nationalism + add_foreign_policy_cooldown = yes + } + else_if = { + limit = { + OR = { + has_strategy = ai_strategy_anti_imperialism + has_strategy = ai_strategy_world_revolution + has_strategy = ai_strategy_socialism_in_one_country + } + NOT = { + has_law = law_type:law_anti_imperialist + } + } + activate_law = law_type:law_anti_imperialist + add_foreign_policy_cooldown = yes + } + # Subject-specific laws + else_if = { + limit = { + has_strategy = ai_strategy_subject_overlord_compliance + NOT = { + has_law = law_type:law_subject_loyalty + } + } + activate_law = law_type:law_subject_loyalty + add_foreign_policy_cooldown = yes + } + else_if = { + limit = { + OR = { + has_strategy = ai_strategy_subject_maintain_autonomy + has_strategy = ai_strategy_subject_strengthen_self + } + NOT = { + has_law = law_type:law_subject_maintain_autonomy + } + } + activate_law = law_type:law_subject_maintain_autonomy + add_foreign_policy_cooldown = yes + } + else_if = { + limit = { + has_strategy = ai_strategy_subject_break_free + NOT = { + has_law = law_type:law_subject_break_free + } + } + activate_law = law_type:law_subject_break_free + add_foreign_policy_cooldown = yes + } + } +} + +add_foreign_policy_cooldown = { + set_variable = { + name = modifier_imperia_foreign_policy_cooldown + value = yes + months = 6 + } +} diff --git a/common/scripted_effects/imperia_political_setup.txt b/common/scripted_effects/imperia_political_setup.txt index 809a9874e..9d76cc9c2 100644 --- a/common/scripted_effects/imperia_political_setup.txt +++ b/common/scripted_effects/imperia_political_setup.txt @@ -3,4 +3,5 @@ # Any later change in the history file will then overwrite it effect_starting_politics_base_imperia = { activate_law = law_type:law_no_workers_rights + activate_law = law_type:law_armed_neutrality } diff --git a/common/scripted_guis/foreign_policy.txt b/common/scripted_guis/foreign_policy.txt index 00248c64c..e7b5ec2f1 100644 --- a/common/scripted_guis/foreign_policy.txt +++ b/common/scripted_guis/foreign_policy.txt @@ -16,11 +16,7 @@ text = EXECUTIVE_ORDER_DESC activate_law = prev.type } - set_variable = { - name = modifier_imperia_foreign_policy_cooldown - value = yes - months = 6 - } + add_foreign_policy_cooldown = yes } } } diff --git a/localization/english/imperia_law_l_english.yml b/localization/english/imperia_law_l_english.yml index af380bd65..2be6cf238 100644 --- a/localization/english/imperia_law_l_english.yml +++ b/localization/english/imperia_law_l_english.yml @@ -90,8 +90,8 @@ law_unification_nationalism: "Unification Nationalism" law_unification_nationalism_desc: "We will unify our people under one banner." - law_isolationism: "Isolationism" - law_isolationism_desc: "We will remain isolated from the world." + law_foreign_isolationism: "Isolationism" + law_foreign_isolationism_desc: "We will remain isolated from the world." law_splendid_isolationism: "Splendid Isolationism" law_splendid_isolationism_desc: "We will remain isolated from the world, for they are our lessers."