######################################################
#	Expert AI mod - AI template design triggers
######################################################

EAI_TEMPLATE_use_cheap_garrison = {
	num_of_military_factories < 100
}

EAI_TEMPLATE_use_regular_garrison = {
	num_of_military_factories < 200
}

EAI_TEMPLATE_use_expensive_garrison = {
	NOT = { num_of_military_factories < 200 }
}

EAI_TEMPLATE_use_mass_infantry = {
	if = { limit = { NOT = { has_country_flag = EAI_MASS_INFANTRY_TEMPLATE } }
	
		OR = {

			### Strategies

				AND = {
					tag = SOV
					check_variable = { deployed_army_manpower_k < 4000 }

					any_enemy_country = { is_major = yes }
					NOT = { EAI_MILITARY_not_losing_TRIGGER = yes }
					EAI_MILITARY_home_threatened_TRIGGER = yes

					set_temp_variable = { mass_infantry_target_size_ = 4500 }
				}

			### Generic

				AND = {
					surrender_progress > 0.05
					check_variable = { EAI_MILITARY_deployed_army_k_trend_value < -0.1 }
					has_country_flag = { flag = EAI_MILITARY_trend_losing_war value = 1 days > 30 }
			
					check_variable = { num_equipment@infantry_equipment > 10000 }
					OR = {
						check_variable = { num_equipment@support_equipment < 1 }
						check_variable = { num_equipment@artillery_equipment < 1 }
					}
					
					set_temp_variable = { last = EAI_MILITARY_army_size_k_weekly^num }
					subtract_from_temp_variable = { last = 1 }
					set_temp_variable = { mass_infantry_target_size_ = EAI_MILITARY_army_size_k_weekly^last }
				}

			###
		}
	}
	else = {
		always = no
	}
}

EAI_TEMPLATE_use_mass_infantry_abort = {
	if = { limit = { has_country_flag = EAI_MASS_INFANTRY_TEMPLATE }

		NOT = { check_variable = { deployed_army_manpower_k < EAI_TEMPLATE_use_mass_infantry_target } }
	}
	else = {
		always = no
	}
}

EAI_amphibious_division_focus = {

	check_variable = { EAI_FOCUS/LAND/spec_ops = global.EAI_MAR_SPEC_OPS }

	OR = {
		EAI_LARM_military_focus = yes
		EAI_MARM_military_focus = yes
		EAI_HARM_military_focus = yes
	}

	OR = {
		AND = {
			num_of_military_factories > 200
			amount_research_slots > 4
		}
		AND = {
			EAI_MODE_challenging = yes
			original_tag = USA
		}
	}
}

EAI_light_amphibious_armor_focus = {
	EAI_amphibious_division_focus = yes
	EAI_LARM_military_focus = yes
}

EAI_medium_amphibious_armor_focus = {
	EAI_amphibious_division_focus = yes
	EAI_MARM_military_focus = yes
}

EAI_heavy_amphibious_armor_focus = {
	EAI_amphibious_division_focus = yes
	EAI_HARM_military_focus = yes
}

# true if artillery designs are preferable
EAI_prefer_artillery_design = { 
	OR = {
		has_idea_with_trait = army_artillery_3 has_available_idea_with_traits = { idea = army_artillery_3 limit = 1 }
		has_idea_with_trait = army_artillery_2 has_available_idea_with_traits = { idea = army_artillery_2 limit = 1 }
	}
}

# triggers to control designs
EAI_infantry_design_priorities = {

	# GER needs to build up its army first
	if = { limit = { original_tag = GER }
		has_army_manpower = { size > 550000 }
	}
}

EAI_motorized_template_upgrade_prio = {

	OR = {
		AND = {
			set_temp_variable = { _check_xp = 200 } EAI_XP_has_army_check_xp = yes
			check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_MOT_FOCUS }
		}
	}
}

EAI_suppression_template_upgrade_prio = {

	OR = {
		set_temp_variable = { _check_xp = 200 } EAI_XP_has_army_check_xp = yes
	}
}

EAI_anti_tank_template_upgrade_prio = {

	OR = {
		AND = {
			set_temp_variable = { _check_xp = 200 } EAI_XP_has_army_check_xp = yes
			check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_AT_FOCUS }
		}
	}
}

EAI_mountaineer_template_upgrade_prio = {

	OR = {
		set_temp_variable = { _check_xp = 200 } EAI_XP_has_army_check_xp = yes
	}
}

EAI_40w_template_unlocked = {

	# Note that due to AI having issues reserving columns for brigade types when creating large templates, it may get stuck and never finish the target template. This can help work around it.
	# OR = {
	# 	has_tech = peoples_army
	# 	has_tech = large_front_operations

	# 	has_tech = infantry_offensive
	# 	has_tech = grand_mechanized_offensive

	# 	has_tech = advanced_firebases
	# 	has_tech = tactical_control

	# 	has_tech = kampfgruppe
	# }

	# always = yes #Changed by Aigle2 : As of early 2025, 40w templates can be achieved without those doctrines

	always = no
}