############################################################################################################
#	Expert AI mod - diplomacy
############################################################################################################

EAI_BUL_civil_war_dont_join_allies = {
	enable = {
		is_historical_focus_on = yes
		original_tag = ROM
		OR = {
			has_civil_war = yes
			has_government = communism
		}
	}
	abort_when_not_enabled = yes
	
	ai_strategy = { type = diplo_action_desire id = ENG target = join_faction value = -5000 }
	ai_strategy = { type = diplo_action_acceptance id = ENG target = offer_join_faction value = -5000 }

	ai_strategy = { type = diplo_action_desire id = USA target = join_faction value = -5000 }
	ai_strategy = { type = diplo_action_acceptance id = USA target = offer_join_faction value = -5000 }
}

EAI_dont_declare_on_IRQ = {
	enable = {
		IRQ = { 
			OR = {
				is_in_faction = yes
				is_subject = yes
			}
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = ignore_claim
		id = "IRQ"
		value = 5000
	}
}

EAI_DIPLO_PER_dont_join_JAP = {
	allowed = { tag = PER }
	enable = {
		is_historical_focus_on = yes
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = diplo_action_desire id = JAP target = join_faction value = -5000 }
	ai_strategy = { type = diplo_action_acceptance id = JAP target = offer_join_faction value = -5000 }
}

### neutral countries join axis/allies

# stay neutral
EAI_DIPLO_neutral_south_america = {
	enable = {
		is_historical_focus_on = yes
	
		capital_scope = { is_on_continent = south_america }

		NOT = {
			is_in_faction = yes
			has_war = yes
		}

		NOT = {
			has_country_flag = EAI_neutral_joins_allies
			has_country_flag = EAI_neutral_joins_axis
		}
	}

	abort_when_not_enabled = yes

	ai_strategy = { type = diplo_action_desire id = ENG target = join_faction value = -500 }
	ai_strategy = { type = diplo_action_acceptance id = ENG target = offer_join_faction value = -500 }

	ai_strategy = { type = diplo_action_desire id = USA target = join_faction value = -500 }
	ai_strategy = { type = diplo_action_acceptance id = USA target = offer_join_faction value = -500 }

	ai_strategy = { type = diplo_action_desire id = GER target = join_faction value = -500 }
	ai_strategy = { type = diplo_action_acceptance id = GER target = offer_join_faction value = -500 }

	ai_strategy = { type = diplo_action_desire id = JAP target = join_faction value = -500 }
	ai_strategy = { type = diplo_action_acceptance id = JAP target = offer_join_faction value = -500 }

	ai_strategy = { type = diplo_action_desire id = SOV target = join_faction value = -500 }
	ai_strategy = { type = diplo_action_acceptance id = SOV target = offer_join_faction value = -500 }
}

EAI_DIPLO_south_america_troops = {
	enable = { 
		is_historical_focus_on = yes 
		capital_scope = { OR = { is_on_continent = south_america is_on_continent = north_america } } 
		NOT = { original_tag = CAN original_tag = USA }
		is_in_faction_with = USA
	}
	
	abort_when_not_enabled = yes

	ai_strategy = { type = area_priority id = scandinavia value = -200 }
	ai_strategy = { type = area_priority id = europe value = -200 }
	ai_strategy = { type = area_priority id = africa value = -200 }
	ai_strategy = { type = area_priority id = asia value = -200 }
	ai_strategy = { type = area_priority id = middle_east value = -200 }
	ai_strategy = { type = area_priority id = pacific value = -200 }
	ai_strategy = { type = area_priority id = oceania value = -200 }
}

# join allies
EAI_DIPLO_neutral_joins_allies = {
	enable = {
		is_historical_focus_on = yes

		has_country_flag = EAI_neutral_joins_allies

		NOT = { is_in_faction_with = ENG is_in_faction_with = USA }

		OR = { has_government = neutrality has_government = democratic }

		OR = {
			ENG = { is_faction_leader = yes any_enemy_country = { is_major = yes } }
			USA = { is_faction_leader = yes any_enemy_country = { is_major = yes } }
		}

		threat > 0.99
	}
	
	abort_when_not_enabled = yes

	ai_strategy = { type = diplo_action_acceptance id = ENG target = offer_join_faction value = 700 }
	ai_strategy = { type = diplo_action_acceptance id = USA target = offer_join_faction value = 700 }
}
EAI_DIPLO_neutral_joins_allies_2 = {
	enable_reverse = {
		is_faction_leader = yes
	}

	enable = {
		is_historical_focus_on = yes

		has_country_flag = EAI_neutral_joins_allies

		NOT = { is_in_faction_with = ENG is_in_faction_with = USA }

		OR = { has_government = neutrality has_government = democratic }

		OR = {
			ENG = { is_faction_leader = yes any_enemy_country = { is_major = yes } }
			USA = { is_faction_leader = yes any_enemy_country = { is_major = yes } }
		}

		threat > 0.99
	}

	abort_when_not_enabled = yes

	reversed = yes

	ai_strategy = { type = diplo_action_desire id = ENG target = offer_join_faction value = 700 }
	ai_strategy = { type = diplo_action_desire id = USA target = offer_join_faction value = 700 }
}

# join axis
EAI_DIPLO_neutral_joins_axis = {
	enable = {
		is_historical_focus_on = yes

		has_country_flag = EAI_neutral_joins_axis

		NOT = { is_in_faction_with = GER }

		has_government = fascism

		GER = { 
			has_war = yes 
			surrender_progress < 0.1 
			NOT = { has_country_flag = EAI_MILITARY_trend_losing_war }
			any_enemy_country = { is_major = yes }
		}

		threat > 0.99
	}

	abort_when_not_enabled = yes

	ai_strategy = { type = diplo_action_acceptance id = GER target = offer_join_faction value = 700 }
}
EAI_DIPLO_neutral_joins_axis_2 = {
	enable = {
		is_historical_focus_on = yes

		has_country_flag = EAI_neutral_joins_axis

		NOT = { is_in_faction_with = GER }

		has_government = fascism

		GER = { has_war = yes }

		threat > 0.99
	}

	abort_when_not_enabled = yes

	reversed = yes

	ai_strategy = { type = diplo_action_desire id = GER target = offer_join_faction value = 700 }
}

###

# iceland joins allies
EAI_DIPLO_ICE_joins_allies = {
	allowed = { 
		OR = {
			tag = ENG
			tag = ICE
		}
	}
	enable = {
		is_historical_focus_on = yes
	
		NOT = { ICE = { is_in_faction_with = ENG } }
		
		ENG = { ICE = { EAI_PREV_has_same_ideology_with_THIS = yes } }

		ENG = { any_enemy_country = { is_major = yes } }

		date > 1940.5.1
	}
	
	abort_when_not_enabled = yes

	ai_strategy = { type = diplo_action_desire id = ICE target = offer_join_faction value = 1000 }
	ai_strategy = { type = diplo_action_acceptance id = ENG target = offer_join_faction value = 1000 }
}

### ROM HUN BUL join axis

EAI_DIPLO_ROM_joins_axis_0 = {
	allowed = { tag = ROM }
	enable = {
		is_historical_focus_on = yes

		NOT = { 
			ROM = { is_in_faction = yes }
			ROM = { has_war_together_with = GER }
		}
	}
	
	abort_when_not_enabled = yes

	ai_strategy = { type = diplo_action_desire id = GER target = join_faction value = -500 }
	ai_strategy = { type = diplo_action_acceptance id = GER target = offer_join_faction value = -500 }
}
EAI_DIPLO_ROM_joins_axis_1 = {
	allowed = { 
		OR = { 
			tag = ROM 
			tag = GER 
		} 
	}
	enable = {
		is_historical_focus_on = yes

		OR = { tag = ROM AND = { ROM = { is_ai = yes } tag = GER } }

		NOT = { ROM = { is_in_faction_with = GER } }
		
		if = { limit = { has_dlc = "Death or Dishonor" }
		
			OR = {
				ROM = { has_completed_focus = ROM_join_axis }
			}
		}
		else = {
			date > 1940.9.1
		}

		ROM = { GER = { EAI_PREV_has_same_ideology_with_THIS = yes } }

		ROM = { NOT = { EAI_is_not_independent = yes } }
				
		GER = { NOT = { EAI_is_not_independent = yes } }
	}
	
	abort_when_not_enabled = yes

	ai_strategy = { type = diplo_action_desire id = ROM target = offer_join_faction value = 1000 }
	ai_strategy = { type = diplo_action_acceptance id = GER target = offer_join_faction value = 1000 }
}

EAI_DIPLO_HUN_joins_axis_0 = {
	allowed = { tag = HUN }
	enable = {
		is_historical_focus_on = yes

		NOT = { 
			HUN = { is_in_faction = yes }
			HUN = { has_war_together_with = GER }
		}
	}
	
	abort_when_not_enabled = yes

	ai_strategy = { type = diplo_action_desire id = GER target = join_faction value = -500 }
	ai_strategy = { type = diplo_action_acceptance id = GER target = offer_join_faction value = -500 }
}
EAI_DIPLO_HUN_joins_axis_1 = {
	allowed = { 
		OR = { 
			tag = HUN 
			tag = GER 
		} 
	}
	enable = {
		is_historical_focus_on = yes
	
		OR = { tag = HUN AND = { HUN = { is_ai = yes } tag = GER } }

		NOT = { HUN = { is_in_faction_with = GER } }
		
		if = { limit = { has_dlc = "Death or Dishonor" }
		
			OR = {
				HUN = { has_completed_focus = HUN_join_axis }
			}
		}
		else = {
			date > 1940.9.1
		}

		HUN = { GER = { EAI_PREV_has_same_ideology_with_THIS = yes } }

		HUN = { NOT = { EAI_is_not_independent = yes } }
				
		GER = { NOT = { EAI_is_not_independent = yes } }
	}
	
	abort_when_not_enabled = yes

	ai_strategy = { type = diplo_action_desire id = HUN target = offer_join_faction value = 1000 }
	ai_strategy = { type = diplo_action_acceptance id = GER target = offer_join_faction value = 1000 }
}

EAI_DIPLO_BUL_joins_axis_0 = {
	allowed = { tag = BUL }
	enable = {
		is_historical_focus_on = yes

		NOT = { 
			BUL = { is_in_faction = yes }
			BUL = { has_war_together_with = GER }
		}
	}
	
	abort_when_not_enabled = yes

	ai_strategy = { type = diplo_action_desire id = GER target = join_faction value = -500 }
	ai_strategy = { type = diplo_action_acceptance id = GER target = offer_join_faction value = -500 }
}
EAI_DIPLO_BUL_joins_axis_1 = {
	allowed = { 
		OR = { 
			tag = BUL 
			tag = GER 
		} 
	}
	enable = {
		is_historical_focus_on = yes

		OR = { tag = BUL AND = { BUL = { is_ai = yes } tag = GER } }

		NOT = { BUL = { is_in_faction_with = GER } }
		
		BUL = {
			any_neighbor_country = {
				is_in_faction_with = GER
				has_war = yes
			}
		}

		if = { limit = { has_dlc = "Battle for the Bosporus" }
		
			BUL = { has_completed_focus = BUL_join_the_tripartite_pact }
		}
		else = {
			BUL = { GER = { EAI_PREV_has_same_ideology_with_THIS = yes } }
		}

		BUL = { NOT = { EAI_is_not_independent = yes } }
				
		GER = { NOT = { EAI_is_not_independent = yes } }
	}
	
	abort_when_not_enabled = yes

	ai_strategy = { type = diplo_action_desire id = BUL target = offer_join_faction value = 1000 }
	ai_strategy = { type = diplo_action_acceptance id = GER target = offer_join_faction value = 1000 }
}
EAI_DIPLO_BUL_befriend_GER = {
	allowed = { 
		tag = BUL 
	}
	enable = {
		is_historical_focus_on = yes

		country_exists = GER

		OR = {
			has_government = neutrality
			has_government = fascism
		}

		focus_progress = {
			focus = BUL_bulgarian_irredentism
			progress > 0.1
		}

		NOT = {
			GER = {
				has_opinion	= {
					target = ROOT
					value > 40
				}
			}
		}

		GER = {
			has_war = yes
			is_major = yes
			is_faction_leader = yes
			NOT = { POL = { EAI_THIS_is_threat_to_PREV = yes } }
			NOT = { FRA = { EAI_THIS_is_threat_to_PREV = yes } }
		}
	}
	
	abort_when_not_enabled = yes

	ai_strategy = { type = diplo_action_desire id = GER target = improve_relation value = 20000 }
}

###

EAI_DIPLO_BUL_stop_doing_crazy_things = {
	allowed = { tag = BUL }
	enable = { is_historical_focus_on = yes }
	abort = { always = no }

	ai_strategy = { type = ignore     	id = "GRE"     value = 1000 }
	ai_strategy = { type = ignore     	id = "YUG"     value = 1000 }
	ai_strategy = { type = ignore     	id = "ROM"     value = 1000 }
	ai_strategy = { type = ignore     	id = "TUR"     value = 1000 }
	
	ai_strategy = { type = alliance     id = "JAP"     value = -1000 }
}

EAI_DIPLO_ROM_ignore_BUL = {
	allowed = { tag = ROM }
	enable = { 
		original_tag = ROM
		is_historical_focus_on = yes
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = ignore_claim id = "BUL" value = 1 }
	ai_strategy = { type = ignore     	id = "BUL" value = 1000 }
}

EAI_DIPLO_china_dont_join_comintern = {
	allowed = { 
		OR = {
			original_tag = CHI
			original_tag = PRC
			original_tag = GXC
			original_tag = YUN
			original_tag = SHX
			original_tag = XSM
			# original_tag = SIK
		}
	}
	enable = {
		is_historical_focus_on = yes
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = diplo_action_desire id = SOV target = join_faction value = -5000 }
	ai_strategy = { type = diplo_action_acceptance id = SOV target = offer_join_faction value = -5000 }

	ai_strategy = { type = diplo_action_desire id = ENG target = join_faction value = -5000 }
	ai_strategy = { type = diplo_action_acceptance id = ENG target = offer_join_faction value = -5000 }

	ai_strategy = { type = diplo_action_desire id = USA target = join_faction value = -5000 }
	ai_strategy = { type = diplo_action_acceptance id = USA target = offer_join_faction value = -5000 }
}