######################################################
#	Expert AI mod - scripted variant AI triggers
######################################################

EAI_DESIGN_MOTORIZED_upgrade_focus = {
	num_of_military_factories > 80
}

EAI_DESIGN_MOTORIZED_rocket_artillery_upgrade_focus = {
	has_tech = rocket_artillery
}

EAI_DESIGN_MOTORIZED_mechanized_upgrade_focus = {
	num_of_military_factories > 150
	has_tech = mechanised_infantry
	NOT = { 
		check_variable = { EAI_needs_steel > 2 } 
		check_variable = { EAI_steel_resource_shortage > 2 } 
	}

	###

	EAI_DESIGN_MOTORIZED_upgrade_focus = yes

	if = { limit = { check_variable = { EAI_FOCUS/LAND/motorized_design = global.EAI_A_MOT_DESIGN } }
	
		EAI_DESIGN_MOTORIZED_rocket_artillery_upgrade_focus = yes
	}
}

### Enable equipment production

EAI_DESIGN_ARMOR_armored_engineer_production_focus = {
	num_of_military_factories > 80
	has_tech = sp_armored_engineer_tech
	is_special_project_completed = sp:sp_land_flamethrower_tank

	OR = {
		EAI_LARM_equipment_production = yes
		EAI_MARM_equipment_production = yes
		EAI_HARM_equipment_production = yes
		EAI_MODARM_equipment_production = yes
		EAI_DESIGN_MARINE_amphibious_light_armor_production_focus = yes
		EAI_DESIGN_MARINE_amphibious_medium_armor_production_focus = yes
		EAI_DESIGN_MARINE_amphibious_heavy_armor_production_focus = yes
	}
}

EAI_DESIGN_ARMOR_mechanized_production_focus = {
	EAI_DESIGN_ARMOR_armored_engineer_production_focus = yes

	num_of_military_factories > 150
	has_tech = mechanised_infantry
	NOT = { 
		check_variable = { EAI_needs_steel > 2 } 
		check_variable = { EAI_steel_resource_shortage > 2 } 
	}

	OR = {
		EAI_MARM_equipment_production = yes
		EAI_HARM_equipment_production = yes
		EAI_MODARM_equipment_production = yes
	}
}

EAI_DESIGN_MARINE_amphibious_mechanized_production_focus = {

	EAI_amtrac_tech_focus = yes
	has_tech = amphibious_mechanized_infantry

	# NOT = { 
	# 	check_variable = { EAI_needs_steel > 2 } 
	# 	check_variable = { EAI_steel_resource_shortage > 2 } 
	# }
}

EAI_DESIGN_MARINE_amphibious_light_armor_production_focus = {

	EAI_amphibious_tech_focus = yes
	EAI_light_amphibious_armor_focus = yes
	has_tech = amphibious_drive

	# NOT = { 
	# 	check_variable = { EAI_needs_steel > 2 } 
	# 	check_variable = { EAI_steel_resource_shortage > 2 } 
	# }
}

EAI_DESIGN_MARINE_amphibious_medium_armor_production_focus = {

	EAI_amphibious_tech_focus = yes
	EAI_medium_amphibious_armor_focus = yes
	has_tech = amphibious_drive

	# NOT = { 
	# 	check_variable = { EAI_needs_steel > 2 } 
	# 	check_variable = { EAI_steel_resource_shortage > 2 } 
	# }
}

EAI_DESIGN_MARINE_amphibious_heavy_armor_production_focus = {

	EAI_amphibious_tech_focus = yes
	EAI_heavy_amphibious_armor_focus = yes
	has_tech = amphibious_drive

	# NOT = { 
	# 	check_variable = { EAI_needs_steel > 2 } 
	# 	check_variable = { EAI_steel_resource_shortage > 2 } 
	# }
}

EAI_DESIGN_ARMOR_modern_production_focus = {
	EAI_DESIGN_ARMOR_mechanized_production_focus = yes

	num_of_military_factories > 150
	has_tech = main_battle_tank_chassis
	NOT = { 
		check_variable = { EAI_needs_chromium > 2 } 
		check_variable = { EAI_chromium_resource_shortage > 2 } 
	}

	OR = {
		EAI_MODARM_equipment_production = yes
	}
}

### Enable design upgrade

EAI_DESIGN_ARMOR_armored_engineer_upgrade_focus = {
	EAI_DESIGN_ARMOR_armored_engineer_production_focus = yes
	# has_country_flag = EAI_DESIGN_ARMOR_armored_engineer_upgrade_production_started
}

EAI_DESIGN_ARMOR_mechanized_upgrade_focus = {
	EAI_DESIGN_ARMOR_mechanized_production_focus = yes
	has_country_flag = EAI_DESIGN_ARMOR_mechanized_upgrade_production_started
}

EAI_DESIGN_ARMOR_modern_upgrade_focus = {
	EAI_DESIGN_ARMOR_modern_production_focus = yes
	has_country_flag = EAI_DESIGN_ARMOR_modern_upgrade_production_started
}

EAI_DESIGN_INFANTRY_width_reduction_unlocked = { # todo: needs to check that milestone is unlocked
	OR = {
		# has_doctrine = irregulars
		has_doctrine = large_unit_tactics
	}
}

###

# EAI_DESIGN_ARMOR_armored_engineer_upgrade_production_started = {
# 	check_variable = { num_equipment@armored_support_vehicle > 250 }
# 	check_variable = { num_equipment@light_tank_flame_chassis > 250 }
# }

EAI_DESIGN_ARMOR_mechanized_upgrade_production_started = {
	check_variable = { num_equipment@mechanized_equipment > 1000 }
}

EAI_DESIGN_ARMOR_modern_upgrade_production_started = {
	check_variable = { num_equipment@modern_tank_chassis > 1000 }
}

###

EAI_armor_intel_tier_0 = { # < 60

	check_variable = { EAI_max_armor_seen < 60 }
}

EAI_armor_intel_tier_1 = { # 60-69

	NOT = { EAI_armor_intel_tier_0 = yes }

	check_variable = { EAI_max_armor_seen < 70 }
}

EAI_armor_intel_tier_2 = { # > 69

	NOT = {
		EAI_armor_intel_tier_0 = yes
		EAI_armor_intel_tier_1 = yes
	}
}

###

EAI_has_light_tank_TD_design = {

	has_design_based_on = light_tank_destroyer_chassis
}

EAI_has_medium_tank_TD_design = {

	has_design_based_on = medium_tank_destroyer_chassis
}

EAI_has_heavy_tank_TD_design = {

	has_design_based_on = heavy_tank_destroyer_chassis
}

EAI_has_modern_tank_TD_design = {

	has_design_based_on = modern_tank_destroyer_chassis
}

###### Enable design if true

### Light armor

EAI_light_armor_tank_design_focus = {

	EAI_LARM_military_focus = yes
	NOT = { EAI_light_amphibious_armor_focus = yes } #Don't design light tanks as Amphibious light tanks are the one which will be used
}

EAI_light_armor_aa_design_focus = {

	always = no

	OR = {
		# check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_LARM_FOCUS }
		# check_variable = { EAI_FOCUS/LAND/attachment = global.EAI_LARM_ATTACHMENT }

		AND = { 
			check_variable = { EAI_FOCUS/LAND/motorized_design = global.EAI_C_MOT_DESIGN }

			OR = { 
				check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_MOT_FOCUS }
				
				AND = {
					check_variable = { EAI_FOCUS/LAND/attachment = global.EAI_MOT_ATTACHMENT }

					if = { limit = { check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_MARM_FOCUS } }

						OR = { has_country_flag = EAI_marm_template_upgrade set_temp_variable = { _check_xp = 400 } EAI_XP_has_army_check_xp = yes }
					}
			
					if = { limit = { check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_HARM_FOCUS } }

						OR = { has_country_flag = EAI_harm_template_upgrade set_temp_variable = { _check_xp = 400 } EAI_XP_has_army_check_xp = yes }
					}
			
					if = { limit = { check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_LARM_Focus } }

						OR = { has_country_flag = EAI_larm_template_upgrade set_temp_variable = { _check_xp = 400 } EAI_XP_has_army_check_xp = yes }
					}
			
					if = { limit = { check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_AT_FOCUS } }

						OR = { has_country_flag = EAI_anti_tank_template_upgrade set_temp_variable = { _check_xp = 400 } EAI_XP_has_army_check_xp = yes }
					}
				}
			}
		}
	}
}

EAI_light_armor_td_design_focus = {

	always = no
}

EAI_light_armor_art_design_focus = {

	has_army_experience > 75

	check_variable = { EAI_FOCUS/LAND/motorized_design = global.EAI_C_MOT_DESIGN }

	OR = { 
		check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_MOT_FOCUS }
		check_variable = { EAI_FOCUS/LAND/attachment = global.EAI_MOT_ATTACHMENT }
	}

	has_country_flag = EAI_TEMPLATE_mot_template_upgrade
}

EAI_light_flamethrower_support_design_focus = {

	EAI_DESIGN_ARMOR_armored_engineer_production_focus = yes

	EAI_light_flamethrower_support_tech_focus = yes

	OR = {
		AND = { EAI_LARM_equipment_production = yes has_design_based_on = light_tank_chassis }
		AND = { EAI_amphibious_tech_focus = yes has_design_based_on = light_tank_amphibious_chassis }
	}
}

EAI_medium_flamethrower_support_design_focus = {

	EAI_DESIGN_ARMOR_armored_engineer_production_focus = yes

	EAI_medium_flamethrower_support_tech_focus = yes

	OR = {
		AND = { EAI_MARM_equipment_production = yes has_design_based_on = medium_tank_chassis }
		AND = { EAI_HARM_equipment_production = yes has_design_based_on = heavy_tank_chassis }
		AND = { EAI_amphibious_tech_focus = yes has_design_based_on = medium_tank_amphibious_chassis }
		AND = { EAI_amphibious_tech_focus = yes has_design_based_on = heavy_tank_amphibious_chassis }
	}
}

EAI_light_armor_tank_recon_design_focus = {

	EAI_light_armor_tank_recon_tech_focus = yes

	OR = {
		AND = { EAI_LARM_equipment_production = yes has_design_based_on = light_tank_chassis }
		AND = { EAI_MARM_equipment_production = yes has_design_based_on = medium_tank_chassis }
		AND = { EAI_HARM_equipment_production = yes has_design_based_on = heavy_tank_chassis }
	}
}

EAI_light_armor_amphibious_tank_design_focus = {

	has_tech = amphibious_drive

	EAI_light_amphibious_armor_focus = yes
}

### Medium armor

EAI_medium_armor_tank_design_focus = {

	EAI_MARM_military_focus = yes
	NOT = { EAI_medium_amphibious_armor_focus = yes } #Don't design Medium tanks as Amphibious Medium tanks are the one which will be used
}

EAI_medium_armor_aa_design_focus = {

	OR = {
		# AND = { check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_MARM_FOCUS } }
		# AND = { check_variable = { EAI_FOCUS/LAND/attachment = global.EAI_MARM_ATTACHMENT } }

		AND = { 
			check_variable = { EAI_FOCUS/LAND/motorized_design = global.EAI_A_MOT_DESIGN }

			OR = { 
				check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_MOT_FOCUS }
				
				AND = {
					check_variable = { EAI_FOCUS/LAND/attachment = global.EAI_MOT_ATTACHMENT }

					if = { limit = { check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_MARM_FOCUS } }

						has_country_flag = EAI_marm_template_upgrade set_temp_variable = { _check_xp = 400 } EAI_XP_has_army_check_xp = yes
					}
			
					if = { limit = { check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_HARM_FOCUS } }

						has_country_flag = EAI_harm_template_upgrade set_temp_variable = { _check_xp = 400 } EAI_XP_has_army_check_xp = yes
					}
			
					if = { limit = { check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_LARM_Focus } }

						has_country_flag = EAI_larm_template_upgrade set_temp_variable = { _check_xp = 400 } EAI_XP_has_army_check_xp = yes
					}
			
					if = { limit = { check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_AT_FOCUS } }

						has_country_flag = EAI_anti_tank_template_upgrade set_temp_variable = { _check_xp = 400 } EAI_XP_has_army_check_xp = yes
					}
				}
			}
		}
	}
}

EAI_medium_armor_td_design_focus = {

	always = no
	EAI_MARM_military_focus = yes
}

EAI_medium_armor_art_design_focus = {

	has_army_experience > 75

	check_variable = { EAI_FOCUS/LAND/motorized_design = global.EAI_B_MOT_DESIGN }

	OR = { 
		check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_MOT_FOCUS }
		check_variable = { EAI_FOCUS/LAND/attachment = global.EAI_MOT_ATTACHMENT }
	}

	has_country_flag = EAI_TEMPLATE_mot_template_upgrade
}

EAI_medium_armor_amphibious_tank_design_focus = {

	has_tech = amphibious_drive

	EAI_medium_amphibious_armor_focus = yes
}

### Heavy armor

EAI_heavy_armor_tank_design_focus = {

	EAI_HARM_military_focus = yes
	NOT = { EAI_heavy_amphibious_armor_focus = yes } #Don't design Heavy tanks as Amphibious Heavy tanks are the one which will be used
}

EAI_heavy_armor_aa_design_focus = {

	always = no
}

EAI_heavy_armor_td_design_focus = {

	always = no
	EAI_HARM_military_focus = yes
}

EAI_heavy_armor_art_design_focus = {

	always = no
}

EAI_heavy_armor_amphibious_tank_design_focus = {

	has_tech = amphibious_drive

	EAI_heavy_amphibious_armor_focus = yes
}

###### Block design if true

EAI_light_armor_design_priority = { # Block all armor types

	set_temp_variable = { _check_xp = 300 }
	EAI_XP_has_army_check_xp = yes

	# Basic techs should be avoided unless necessary
	OR = {
		AND = {
			NOT = {
				has_tech = improved_light_tank_chassis
			}

			has_war = no

			has_design_based_on = light_tank_chassis
		}
	}
}

EAI_light_armor_tank_design_priority = { # Block all except tank

	set_temp_variable = { _check_xp = 300 }
	EAI_XP_has_army_check_xp = yes

	EAI_light_armor_tank_design_focus = yes

	NOT = { has_design_based_on = light_tank_chassis }
}

EAI_medium_armor_design_priority = { # Block all armor types

	set_temp_variable = { _check_xp = 300 }
	EAI_XP_has_army_check_xp = yes

	# Basic techs should be avoided unless necessary
	OR = {
		AND = {
			NOT = {
				has_tech = improved_medium_tank_chassis
			}

			has_war = no

			has_design_based_on = medium_tank_chassis
		}
	}
}

EAI_medium_armor_tank_design_priority = { # Block all except tank

	set_temp_variable = { _check_xp = 300 }
	EAI_XP_has_army_check_xp = yes

	EAI_medium_armor_tank_design_focus = yes

	NOT = { has_design_based_on = medium_tank_chassis }
}

EAI_heavy_armor_design_priority = { # Block all armor types

	set_temp_variable = { _check_xp = 300 }
	EAI_XP_has_army_check_xp = yes

	# Basic techs should be avoided unless necessary
	OR = {
		AND = {
			NOT = {
				has_tech = improved_heavy_tank_chassis
			}

			has_war = no

			has_design_based_on = heavy_tank_chassis
		}
	}
}

EAI_heavy_armor_tank_design_priority = { # Block all except tank

	set_temp_variable = { _check_xp = 300 }
	EAI_XP_has_army_check_xp = yes

	EAI_heavy_armor_tank_design_focus = yes

	NOT = { has_design_based_on = heavy_tank_chassis }
}

###### Block design if true

EAI_FTR_design_priority = {

	OR = {
		always = no
	}
}

EAI_HFTR_design_priority = {

	OR = {
		always = no
	}
}

EAI_CAS_design_priority = {

	OR = {
		AND = {
			EAI_FTR_aircraft_production = yes
			NOT = { has_design_based_on = small_plane_airframe }
		}

		AND = {
			EAI_HFTR_aircraft_production = yes
			NOT = { has_design_based_on = medium_plane_fighter_airframe }
		}

		AND = {
			EAI_CV_aircraft_production = yes
			NOT = { 
				has_design_based_on = cv_small_plane_airframe 
				has_design_based_on = cv_small_plane_naval_bomber_airframe 
			}
		}
	}
}

EAI_TAC_design_priority = {

	OR = {
		AND = {
			EAI_FTR_aircraft_production = yes
			NOT = { has_design_based_on = small_plane_airframe }
		}

		AND = {
			EAI_HFTR_aircraft_production = yes
			NOT = { has_design_based_on = medium_plane_fighter_airframe }
		}

		AND = {
			EAI_CV_aircraft_production = yes
			NOT = { 
				has_design_based_on = cv_small_plane_airframe 
				has_design_based_on = cv_small_plane_naval_bomber_airframe 
			}
		}
	}
}

EAI_NAV_design_priority = {

	OR = {
		AND = {
			EAI_FTR_aircraft_production = yes
			NOT = { has_design_based_on = small_plane_airframe }
		}

		AND = {
			EAI_HFTR_aircraft_production = yes
			NOT = { has_design_based_on = medium_plane_fighter_airframe }
		}

		AND = {
			EAI_CAS_aircraft_production = yes
			NOT = { has_design_based_on = small_plane_cas_airframe }
		}

		AND = {
			EAI_TAC_aircraft_production = yes
			NOT = { has_design_based_on = medium_plane_airframe }
		}

		AND = {
			EAI_CV_aircraft_production = yes
			NOT = { 
				has_design_based_on = cv_small_plane_airframe 
				has_design_based_on = cv_small_plane_naval_bomber_airframe 
			}
		}
	}
}

EAI_MAR_design_priority = {

	OR = {
		AND = {
			EAI_FTR_aircraft_production = yes
			NOT = { has_design_based_on = small_plane_airframe }
		}

		AND = {
			EAI_HFTR_aircraft_production = yes
			NOT = { has_design_based_on = medium_plane_fighter_airframe }
		}

		AND = {
			EAI_CAS_aircraft_production = yes
			NOT = { has_design_based_on = small_plane_cas_airframe }
		}

		AND = {
			EAI_TAC_aircraft_production = yes
			NOT = { has_design_based_on = medium_plane_airframe }
		}

		AND = {
			EAI_NAV_aircraft_production = yes
			NOT = { has_design_based_on = small_plane_naval_bomber_airframe }
		}

		AND = {
			EAI_STR_aircraft_production = yes
			NOT = { has_design_based_on = large_plane_airframe }
		}

		AND = {
			EAI_CV_aircraft_production = yes
			NOT = { 
				has_design_based_on = cv_small_plane_airframe 
				has_design_based_on = cv_small_plane_naval_bomber_airframe 
			}
		}
	}
}

EAI_STR_design_priority = {

	OR = {
		AND = {
			EAI_FTR_aircraft_production = yes
			NOT = { has_design_based_on = small_plane_airframe }
		}

		AND = {
			EAI_HFTR_aircraft_production = yes
			NOT = { has_design_based_on = medium_plane_fighter_airframe }
		}
	}
}

EAI_CV_AIR_design_priority = {

	OR = {
		AND = {
			EAI_FTR_aircraft_production = yes
			NOT = { has_design_based_on = small_plane_airframe }
		}

		AND = {
			EAI_hFTR_aircraft_production = yes
			NOT = { has_design_based_on = medium_plane_fighter_airframe }
		}
	}
}

###

EAI_save_xp_for_advanced_techs = {
	
	# Early and basic equipment is not important to upgrade
	if = { limit = { check_variable = { EAI_VARIANT/equipment_tech_level < 2 } }
		OR = { 
			is_major = no 
			meta_trigger = { text = { check_variable = { [x]_experience > 450 } } x = "[EAI_GetExperienceType]" }
		} 
	}
}

EAI_has_correct_equipment_to_unlock_MARM_template = {
	if = { limit = { EAI_MODE_challenging = yes }
		if = { limit = { original_tag = USA }
			has_tech = improved_medium_tank_chassis
			has_tech = mechanised_infantry
		}
		else_if = { limit = { original_tag = SOV }
			has_tech = improved_medium_tank_chassis
			has_tech = mechanised_infantry
		}
		else = {
			always = yes
		}
	}
	else = {
		always = yes
	}
}