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

# To avoid opinion penalties from cancelled trades while trying to send attache
EAI_DIPLO_ATTACHE_dont_buy_from_spain_early = {
	allowed = { 
		OR = {
			tag = ENG
			tag = FRA
			tag = GER
			tag = ITA
			tag = SOV
		}
	}
	enable = {
		date < 1937.1.1
		NOT = { has_idea = EAI_attache_sent }
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = equipment_market_trade_desire id = SPD value = -1000 }
	ai_strategy = { type = equipment_market_trade_desire id = SPA value = -1000 }
	ai_strategy = { type = equipment_market_trade_desire id = SPR value = -1000 }

	ai_strategy = { type = equipment_market_trade_desire id = SPD value = -1000 }
	ai_strategy = { type = equipment_market_trade_desire id = SPA value = -1000 }
	ai_strategy = { type = equipment_market_trade_desire id = SPR value = -1000 }
}

# A single strategy that works dynamically using a tag alias would be perfect but it doesn't seem to work with any strategies that improve relations
# EAI_improve_relations_R00 = { enable = { always = yes } ai_strategy = { type = diplo_action_desire id = "R00" target = improve_relation value = 30000 } }

# Alternative would be a strategy for every country that has any need to send attaches
# EAI_improve_relations_from_GER = { enable = { has_country_flag = EAI_improve_relations_from_GER } reversed = yes ai_strategy = { type = diplo_action_desire id = GER target = improve_relation value = 30000 } }

EAI_DIPLO_ATTACHE_SOV_attache_improve_relations_SPD = {
	enable = {

		tag = SPD
		
		has_civil_war = yes

		has_opinion = {
			target = SOV
			value < 30
		}

		NOT = { is_in_array = { EAI_attache_senders = SOV.id } }

		date < 1937.6.1
	}
	abort = {
		
		NOT = {
			AND = {
				has_opinion = {
					target = SOV
					value < 40
				}

				NOT = { is_in_array = { EAI_attache_senders = SOV.id } }
			}
		}
	}
	reversed = yes
	
	ai_strategy = { type = diplo_action_desire id = SOV target = improve_relation value = 30000 }
}

EAI_DIPLO_ATTACHE_ENG_attache_improve_relations_SPD = {
	enable = {

		tag = SPD
		
		has_civil_war = yes

		has_opinion = {
			target = ENG
			value < 30
		}

		NOT = { is_in_array = { EAI_attache_senders = ENG.id } }

		date < 1937.6.1
	}
	abort = {

		NOT = {
			AND = {
				has_opinion = {
					target = ENG
					value < 40
				}

				NOT = { is_in_array = { EAI_attache_senders = ENG.id } }
			}
		}
	}
	reversed = yes
	
	ai_strategy = { type = diplo_action_desire id = ENG target = improve_relation value = 30000 }
	ai_strategy = { type = support id = "ENG" value = 10000 } # AI doesn't want to improve relations so send equipment instead
	ai_strategy = { type = befriend id = "ENG" value = 10000 }
	ai_strategy = { type = alliance id = "ENG" value = 10000 }
}

EAI_DIPLO_ATTACHE_GER_attache_improve_relations_SPA = {
	enable = {

		tag = SPA
		
		has_civil_war = yes

		has_opinion = {
			target = GER
			value < 35
		}

		NOT = { is_in_array = { EAI_attache_senders = GER.id } }

		date < 1937.6.1
	}
	abort = {

		NOT = {
			AND = {
				has_opinion = {
					target = GER
					value < 40
				}

				NOT = { is_in_array = { EAI_attache_senders = GER.id } }
			}
		}
	}
	reversed = yes
	
	ai_strategy = { type = diplo_action_desire id = GER target = improve_relation value = 100000 }
	ai_strategy = { type = support id = "GER" value = 100000 } # AI doesn't want to improve relations so send equipment instead
	ai_strategy = { type = befriend id = "GER" value = 100000 }
	ai_strategy = { type = alliance id = "GER" value = 100000 }

	ai_strategy = { type = diplo_action_desire id = GER target = military_access value = 20000 }
}
EAI_DIPLO_ATTACHE_GER_attache_improve_relations_SPA_2 = {
	allowed = { tag = GER }
	enable = {
		
		SPA = {
			is_ai = yes

			has_civil_war = yes

			has_opinion = {
				target = GER
				value < 35
			}

			NOT = { is_in_array = { EAI_attache_senders = GER.id } }

			date < 1937.6.1
		}
	}
	abort = {

		SPA = {
			is_in_array = { EAI_attache_senders = GER.id }
		}
	}

	ai_strategy = { type = diplo_action_desire id = GER target = improve_relation value = 100000 }
	ai_strategy = { type = support id = "GER" value = 100000 } # AI doesn't want to improve relations so send equipment instead
	ai_strategy = { type = befriend id = "GER" value = 100000 }
	ai_strategy = { type = alliance id = "GER" value = 100000 }
	ai_strategy = {
		type = pp_spend_priority
		id = relation
		value = 50000
	}
}

EAI_DIPLO_ATTACHE_ITA_attache_improve_relations_SPA = {
	enable = {

		tag = SPA
		
		has_civil_war = yes

		has_opinion = {
			target = ITA
			value < 30
		}

		NOT = { is_in_array = { EAI_attache_senders = ITA.id } }

		date < 1937.6.1
	}
	abort = {

		NOT = {
			AND = {
				has_opinion = {
					target = ITA
					value < 40
				}

				NOT = { is_in_array = { EAI_attache_senders = ITA.id } }
			}
		}
	}
	reversed = yes
	
	ai_strategy = { type = diplo_action_desire id = ITA target = improve_relation value = 40000 }
	ai_strategy = { type = support id = "ITA" value = 10000 } # AI doesn't want to improve relations so send equipment instead
	ai_strategy = { type = befriend id = "ITA" value = 10000 }
	ai_strategy = { type = alliance id = "ITA" value = 10000 }
}

EAI_DIPLO_ATTACHE_USA_attache_improve_relations_ENG = {
	enable = {

		tag = ENG
		
		has_war_with = GER

		has_opinion = {
			target = USA
			value < 30
		}

		NOT = { is_in_array = { EAI_attache_senders = ENG.id } }
	}
	abort = {

		NOT = {
			AND = {
				has_opinion = {
					target = USA
					value < 40
				}

				NOT = { is_in_array = { EAI_attache_senders = ENG.id } }
			}
		}
	}
	reversed = yes
	
	ai_strategy = { type = diplo_action_desire id = USA target = improve_relation value = 30000 }
}