Skip to content

Commit

Permalink
AI + cleanup
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Danarca committed Jan 24, 2025
1 parent c70123c commit 0cde9e4
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 30 deletions.
42 changes: 20 additions & 22 deletions common/history/global/imperia_global.txt
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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 = {
Expand Down Expand Up @@ -71,4 +69,4 @@
years = 30
}
}
}
}
2 changes: 1 addition & 1 deletion common/laws/imperia_diplomatic_stance.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions common/on_actions/imperia_on_monthtly_pulse.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
167 changes: 167 additions & 0 deletions common/scripted_effects/imperia_foreign_policy_effects.txt
Original file line number Diff line number Diff line change
@@ -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
}
}
1 change: 1 addition & 0 deletions common/scripted_effects/imperia_political_setup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 1 addition & 5 deletions common/scripted_guis/foreign_policy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions localization/english/imperia_law_l_english.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 0cde9e4

Please sign in to comment.