#########################################################
#	Production Strategies
#########################################################

EAI_ITA_air_production = {
	allowed = { tag = ITA }
	enable = { always = yes }
	abort_when_not_enabled = yes

	ai_strategy = { type = air_factory_balance value = 50 }
}

EAI_ITA_naval_bombers = {
	allowed = { tag = ITA }
	enable = { 
		EAI_NAV_equipment_production = yes
		num_of_military_factories > 25
	}
	abort = {
		NOT = {
			AND = {
				EAI_NAV_equipment_production = yes
				num_of_military_factories > 25
			}
		}	
	}

	ai_strategy = { type = equipment_production_min_factories id = naval_bomber value = 3 }
}

EAI_ITA_naval_bombers_2 = {
	allowed = { tag = ITA }
	enable = { 
		EAI_NAV_equipment_production = yes
		has_deployed_air_force_size = { size < 400 type = naval_bomber }
		num_of_military_factories > 45
	}
	abort = {
		NOT = {
			AND = {
				EAI_NAV_equipment_production = yes
				has_deployed_air_force_size = { size < 600 type = naval_bomber }
				num_of_military_factories > 45
			}
		}	
	}

	ai_strategy = { type = equipment_production_min_factories id = naval_bomber value = 10 }
}

#########################################################
#	Diplomacy Strategies
#########################################################

EAI_ITA_no_docking_rights_for_ITA_outside_europe = {
	enable = { 
		NOT = {
			capital_scope = { is_on_continent = europe }
			has_war_together_with = ITA
			is_in_faction_with = ITA
			any_neighbor_country = { is_in_faction_with = ITA }
		}
	}

	abort_when_not_enabled = yes

	ai_strategy = { type = diplo_action_desire id = ITA target = docking_rights value = -200 }
	ai_strategy = { type = diplo_action_acceptance id = ITA target = docking_rights value = -200 }
}

EAI_GER_want_to_invade_FRA_without_ITA = {
	allowed = {
		OR = {
			original_tag = GER
			original_tag = ITA
		}
	}
	enable = {
		is_historical_focus_on = yes

		ITA = { is_in_faction_with = GER }

		date > 1939.1.1
		date < 1941.1.1

		NOT = {
			# Fallback
			date > 1940.6.1

			# Check progress vs France
			OR = {

				# Breakthrough in France
				FRA = { surrender_progress > 0.50 }
				FRA = { has_country_flag = EAI_MILITARY_trend_losing_war }
				FRA = { has_capitulated = yes }

				# Breakthrough in Benelux
				BEL = { has_capitulated = yes }
				HOL = { has_capitulated = yes }

				# Enemies in FRA northern provinces except Maginot
				FRA = { 
					any_of_scopes = { array = owned_states 
						region = 19
						NOT = { state = 28 }
						NOT = { is_fully_controlled_by = FRA }
					}
				}

				# Axis puts more pressure on when the player is on the other side
				GER = { 
					any_enemy_country = { is_major = yes is_ai = no }
					OR = { 
						has_war_with = BEL 
						has_war_with = HOL 
					}
				} 
			}
		}
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = dont_join_wars_with
		id = ITA
		target_country = FRA
		value = 500
	}
	ai_strategy = {
		type = dont_join_wars_with
		id = GER
		target_country = FRA
		value = 500
	}
}

EAI_ITA_ignore_yug = {
	allowed = { tag = ITA }
	enable = {
		tag = ITA
		is_historical_focus_on = yes
		NOT = { YUG = { has_country_flag = EAI_declare_war_from_ITA } }
		NOT = { has_war_with = YUG date > 1941.4.1 }
	}

	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = ignore
		id = "YUG"
		value = 500
	}
}

EAI_ITA_ignore_SWI = {
	allowed = { tag = ITA }
	enable = { 
		is_historical_focus_on = yes 
		SOV = { EAI_THIS_is_threat_to_PREV = yes }
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = ignore_claim
		id = "SWI"
		value = 5000
	}
	ai_strategy = {
		type = ignore
		id = "SWI"
		value = 5000
	}
}

EAI_ITA_dont_justify_vs_GRE = { # Use national focus
	enable = { 
		is_historical_focus_on = yes 
		original_tag = ITA
		OR = {
			AND = {
				date > 1939.1.1
				date < 1941.1.1
			}
			AND = {
				has_war = no
				date > 1943.1.1
			}
		}
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = ignore_claim
		id = "GRE"
		value = 5000
	}
}

#########################################################
#	Unit Strategies
#########################################################

EAI_ITA_area_priority = {
	allowed = { tag = ITA }
	enable = {
		always = yes
	}
	abort = { always = no }

	ai_strategy = { type = area_priority id = suez value = 200 }
}

EAI_ITA_garrison_home_AI = {
	allowed = { tag = ITA }
	enable = {
		has_capitulated = no

		any_enemy_country = { is_major = yes naval_strength_ratio = { tag = ITA ratio > 1.0 } }
		NOT = { any_enemy_country = { is_major = yes is_ai = no naval_strength_ratio = { tag = ITA ratio > 1.0 } } }
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = strategic_air_importance id = 23 value = 25000 }
	ai_strategy = { type = strategic_air_importance id = 31 value = 25000 }
	ai_strategy = { type = strategic_air_importance id = 169 value = 25000 }
	ai_strategy = { type = strategic_air_importance id = 168 value = 25000 }
	ai_strategy = { type = strategic_air_importance id = 29 value = 25000 }

	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.10
		states = { 
			115
			156
			117
			157
			162
			161
			158
			160
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}

	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.05
		order_id = 9
		states = { 
			2
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
}

EAI_ITA_garrison_home = {
	allowed = { tag = ITA }
	enable = {
		has_capitulated = no

		any_enemy_country = { is_major = yes naval_strength_ratio = { tag = ITA ratio > 1.0 } }
		any_enemy_country = { is_major = yes is_ai = no naval_strength_ratio = { tag = ITA ratio > 1.0 } }
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = strategic_air_importance id = 23 value = 25000 }
	ai_strategy = { type = strategic_air_importance id = 31 value = 25000 }
	ai_strategy = { type = strategic_air_importance id = 169 value = 25000 }
	ai_strategy = { type = strategic_air_importance id = 168 value = 25000 }
	ai_strategy = { type = strategic_air_importance id = 29 value = 25000 }

	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.25
		states = { 
			115
			156
			117
			157
			162
			161
			158
			160
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}

	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.05
		order_id = 9
		states = { 
			2
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
}

EAI_ITA_garrison_north_africa = {
	allowed = { tag = ITA }
	enable = {
		always = yes
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.10
		
		states = { 
			451
			663
			450
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
}

EAI_ITA_dont_invade_NOR = {
	allowed = { tag = ITA }
	enable = {
		has_global_flag = EAI_GER_blitz_denmark_365d
	}
	
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = invade
		id = NOR
		value = -5000
	}

	ai_strategy = {
		type = front_unit_request
		value = -200
		
		tag = NOR
	}
}

###########################
# 	2nd Ethiopian War
###########################

EAI_ITA_war_in_ethiopia_DEPLOY = {
	allowed = { tag = ITA }
	enable = { 
		has_war_with = ETH
		ETH = { has_capitulated = no }
		date < 1938.1.1
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = front_unit_request
		value = 100

		tag = ETH
	}
}

EAI_ITA_war_in_ethiopia_OFFENSIVE_blitz = { 
	allowed = { tag = ITA }
	enable = { 
		has_war_with = ETH
		ETH = { has_capitulated = no }
		date < 1938.1.1
		EAI_MILITARY_army_readiness_HIGH = yes
	}
	abort = {
		NOT = {
			AND = {
				has_war_with = ETH
				ETH = { has_capitulated = no }
				date < 1938.1.1
				EAI_MILITARY_army_readiness_HIGH_abort = yes
			}
		}
	}

	ai_strategy = {
		type = front_control
		ordertype = front
		ratio = 0.5
		priority = 600
		execution_type = rush_weak
		execute_order = yes

		tag = ETH
	}
}

EAI_ETH_war_in_ethiopia_OFFENSIVE_dumb = { # Force ETH to make bad attacks vs AI ITA
	allowed = { tag = ETH }
	enable = { 
		has_war_with = ITA
		ITA = { is_ai = yes }
		date < 1938.1.1
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = front_control
		ordertype = front
		ratio = 0.5
		priority = 600
		execution_type = rush
		execute_order = yes
		
		tag = ITA
	}

	ai_strategy = {
		type = front_unit_request
		value = -200

		tag = ITA
	}

	ai_strategy = { 
		type = put_unit_buffers 
		ratio = 0.75
		order_id = 9 
		states = { 838 } 
		subtract_invasions_from_need = no 
		subtract_fronts_from_need = no
	}
}

###########################
# 	Europe
###########################

EAI_ITA_europe_PREPARE_ENG = {
	allowed = { original_tag = ITA }
	enable = {
		NOT = { has_war_with = ENG }
		has_global_flag = EAI_GER_blitz_poland_365d
		GER = { EAI_PREV_on_same_side_with_THIS = yes }
		ENG = { EAI_THIS_is_threat_to_PREV = yes }
	}
	
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = prepare_for_war
		id = "ENG"
		value = 100
	}
}

EAI_ITA_europe_PREPARE_FRA = {
	allowed = { original_tag = ITA }
	enable = {
		NOT = { has_war_with = FRA }
		has_global_flag = EAI_GER_blitz_poland_365d
		GER = { EAI_PREV_on_same_side_with_THIS = yes }
		FRA = { EAI_THIS_is_threat_to_PREV = yes }
	}
	
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = prepare_for_war
		id = "FRA"
		value = 100
	}
}

EAI_ITA_garrison_atlantic_wall = {
	allowed = { tag = ITA }
	enable = {
		is_in_faction_with = GER
		any_enemy_country = { is_major = yes naval_strength_ratio = { tag = GER ratio > 1.0 } }
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.30
		states = { 
			99
			58
			59
			56
			36
			7
			35
			6
			29
			758
			15
			14
			30
			23
			19
			31
			22
			21
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
}

###########################
# 	North Africa
###########################

EAI_ITA_north_africa_DEPLOY_west = {
	allowed = { tag = ITA }
	enable = {
		NOT = { EAI_MILITARY_home_threatened_TRIGGER = yes }
		OR = {
			AND = {
				NOT = { has_war_with = FRA }
				has_global_flag = EAI_GER_blitz_poland_365d
				NOT = { GER = { EAI_THIS_is_threat_to_PREV = yes } }
				FRA = { EAI_THIS_is_threat_to_PREV = yes }
			}
			AND = {
				has_war_with = FRA
			}
		}
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = front_unit_request
		value = 50

		state_trigger = {
			OR = {
				region = 225
				region = 126
			}
			OR = {
				any_neighbor_state = { CONTROLLER = { original_tag = FRA } }
				CONTROLLER = { original_tag = FRA }
			}
		}
	}
}

EAI_ITA_north_africa_DEPLOY_east = {
	allowed = { tag = ITA }
	enable = {
		NOT = { EAI_MILITARY_home_threatened_TRIGGER = yes }
		OR = {
			AND = {
				NOT = { has_war_with = ENG }
				has_global_flag = EAI_GER_blitz_poland_365d
				NOT = { GER = { EAI_THIS_is_threat_to_PREV = yes } }
				ENG = { EAI_THIS_is_threat_to_PREV = yes }
			}
			AND = {
				has_war_with = ENG
			}
		}
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = front_unit_request
		value = 75

		state_trigger = {
			OR = {
				region = 225
				region = 128
			}
			OR = {
				any_neighbor_state = { CONTROLLER = { original_tag = ENG } }
				CONTROLLER = { original_tag = ENG }
			}
		}
	}
}

EAI_MILITARY_north_africa_LIMITER = {
	allowed = { OR = { tag = ITA tag = ENG } }
	enable = {
		has_country_flag = EAI_MILITARY_north_africa_LIMITER
		NOT = { has_country_flag = EAI_operational_initial_resume_timer }
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = front_control
		ordertype = front
		ratio = 0.5
		priority = 900
		execution_type = careful
		
		state_trigger = {
			is_in_array = { global.EAI_MAP_north_africa_theatre = THIS.id }
			OR = {
				AND = { FROM.FROM = { tag = ITA } is_controlled_by = ENG }
				AND = { FROM.FROM = { tag = ENG } is_controlled_by = ITA }
			}
		}
	}
}

EAI_ITA_ENG_north_africa_OFFENSIVE_operational_resume = {
	allowed = { OR = { tag = ITA tag = ENG } }
	enable = {
		is_historical_focus_on = yes
		OR = {
			has_war_with = ENG
			has_war_with = ITA
		}
		ITA = { is_ai = yes }
		ENG = { is_ai = yes }
		has_country_flag = EAI_operational_initial_resume_timer
		NOT = { has_country_flag = EAI_MILITARY_operational_pause_timer }
		EAI_MILITARY_army_readiness_HIGH = yes
	}
	abort = {
		NOT = {
			AND = {
				is_historical_focus_on = yes
				OR = {
					has_war_with = ENG
					has_war_with = ITA
				}
				ITA = { is_ai = yes }
				ENG = { is_ai = yes }
				has_country_flag = EAI_operational_initial_resume_timer
				NOT = { has_country_flag = EAI_MILITARY_operational_pause_timer }
				EAI_MILITARY_army_readiness_HIGH_abort = yes
			}
		}
	}
	ai_strategy = {
		type = front_control
		ordertype = front
		ratio = 0.75
		priority = 800
		execution_type = rush_weak
		execute_order = yes

		state_trigger = {
			region = 128
			region = 225
		}
	}
}

###########################
# 	Ethiopia
###########################

EAI_ITA_ethiopia_DEPLOY = {
	allowed = { tag = ITA }
	enable = {
		AOI = { is_puppet_of = ITA }
		NOT = { has_country_flag = EAI_path_exists_from_east_africa_to_north_africa }
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = dont_defend_ally_borders id = "AOI" value = 500 }

	ai_strategy = {
		type = front_unit_request
		value = -50000

		state_trigger = {
			CONTROLLER = {
				OR = {
					tag = AOI 
					tag = FRA
					tag = ENG
					has_war_with = AOI
				}
			}
			OR = {
				region = 17    
				region = 274    
				region = 273    
				region = 216    
				region = 217    
			}
		}
	}
}

EAI_AOI_ethiopia_DEPLOY = {
	allowed = { tag = AOI }
	enable = {
		AOI = { is_puppet_of = ITA }
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = force_defend_ally_borders id = "ITA" value = 500 }

	ai_strategy = {
		type = front_unit_request
		value = -2000

		state_trigger = {
			NOT = { is_on_continent = africa }
		}
	}
}

EAI_AOI_ethiopia_DEPLOY_2 = {
	allowed = { tag = AOI }
	enable = {
		AOI = { is_puppet_of = ITA }
		NOT = { has_country_flag = EAI_path_exists_from_east_africa_to_north_africa }
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = force_defend_ally_borders id = "ITA" value = 500 }

	ai_strategy = {
		type = front_unit_request
		value = -2000

		state_trigger = {
			is_in_array = { global.EAI_MAP_north_africa_theatre = THIS.id }
		}
	}
}

###########################
# 	Greece
###########################

EAI_ITA_balkans_DEPLOY_GRE = {
	allowed = { tag = GER }
	enable = {
		has_global_flag = { flag = EAI_GER_blitz_yugoslavia_365d days < 180 }
		GRE = { EAI_PREV_deploy_against_THIS = yes }
	}
	abort_when_not_enabled = yes

	### Deploy

	ai_strategy = { type = front_armor_score id = GRE value = 50000 }

	ai_strategy = {
		type = force_concentration_factor
		value = 20
	}
	ai_strategy = {
		type = force_concentration_front_factor
		ratio = 0.5
		value = 50
		
		strategic_region = 25
	}
	ai_strategy = {
		type = force_concentration_target_weight
		value = 50
		
		state = 47
	}

	### Avoid
}

EAI_ITA_balkans_OFFENSIVE_push_GRE = {
	allowed = { tag = GER }
	enable = {
		has_global_flag = { flag = EAI_GER_blitz_yugoslavia_365d days < 180 }
		NOT = { YUG = { EAI_PREV_deploy_against_THIS = yes } }
		GRE = { EAI_PREV_deploy_against_THIS = yes }
		EAI_MILITARY_army_readiness_MEDIUM = yes
	}
	
	abort = {
		NOT = {
			AND = {
				has_global_flag = { flag = EAI_GER_blitz_yugoslavia_365d days < 180 }
				NOT = { YUG = { EAI_PREV_deploy_against_THIS = yes } }
				GRE = { EAI_PREV_deploy_against_THIS = yes }
				EAI_MILITARY_army_readiness_MEDIUM_abort = yes
			}
		}
	}

	ai_strategy = {
		type = front_control
		ordertype = front
		ratio = 0.5
		priority = 500
		execution_type = rush
		
		tag = GRE
	}
}

#########################################################
#	Naval
#########################################################

EAI_ITA_avoid_ETH = {
	enable = {
		has_war = yes
		original_tag = ITA 
		enemies_naval_strength_ratio > 1.0 
		NOT = { ETH = { has_country_flag = EAI_naval_invasion_from_ITA } }
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = naval_avoid_region id = 47 value = 500 }
	ai_strategy = { type = naval_avoid_region id = 48 value = 500 }
	ai_strategy = { type = naval_avoid_region id = 61 value = 500 }
	ai_strategy = { type = naval_avoid_region id = 62 value = 500 }
	ai_strategy = { type = naval_avoid_region id = 65 value = 500 }
	ai_strategy = { type = naval_avoid_region id = 103 value = 500 }
	ai_strategy = { type = naval_avoid_region id = 102 value = 500 }
	ai_strategy = { type = naval_avoid_region id = 104 value = 500 }
}

EAI_ITA_protect_navy = {
	allowed = { tag = ITA }
	enable = {
		EAI_NAV_equipment_production = yes
		has_deployed_air_force_size = { size < 200 type = naval_bomber }

		num_of_military_factories > 25

		alliance_naval_strength_ratio < 1.0

		NOT = {
			any_state = {
				region = 23
				OR = {
					CONTROLLER = { has_war_with = ROOT }
					ROOT = { 
						controls_state = PREV
						NOT = { has_full_control_of_state = PREV } 
					}
				}
			}
		}
	}
	abort = {
		NOT = {
			AND = {
				EAI_NAV_equipment_production = yes
				has_deployed_air_force_size = { size < 400 type = naval_bomber }
		
				num_of_military_factories > 25
		
				alliance_naval_strength_ratio < 1.0
		
				NOT = {
					any_state = {
						region = 23
						OR = {
							CONTROLLER = { has_war_with = ROOT }
							ROOT = { 
								controls_state = PREV
								NOT = { has_full_control_of_state = PREV } 
							}
						}
					}
				}
			}
		}
	}

	ai_strategy = { type = naval_mission_threshold id = "MISSION_PATROL" value = 500000 }
	ai_strategy = { type = naval_mission_threshold id = "MISSION_STRIKE_FORCE" value = 500000 }
	ai_strategy = { type = naval_mission_threshold id = "MISSION_CONVOY_ESCORT" value = 500000 }
	ai_strategy = { type = naval_mission_threshold id = "MISSION_CONVOY_RAIDING" value = 500000 }
	ai_strategy = { type = naval_mission_threshold id = "MISSION_NAVAL_INVASION_SUPPORT" value = 500000 }
}