##############################################################################################################################
#	Expert AI mod - Construction strategies
##############################################################################################################################

############################################################################################################
#	Expert AI mod - old regular construction AI - mostly deprecated
############################################################################################################

# EAI_queue_AIR
# EAI_queue_INF: queue INF anywhere possible
# EAI_queue_INF_2: see if there is a good place for infrastructure, else queue factories
# EAI_queue_INF_resource: for building INF to increase resource extraction
# EAI_queue_INF_supply: for building INF to increase supply
# EAI_queue_RADAR: queue radar with location priorities
# EAI_queue_RADAR_random: queue radar in a good random location
# EAI_queue_AA: build AA on synth factories if facing strategic bombers
# EAI_queue_CIC: queue CIC in higher INF states, else queue INF
# EAI_queue_CIC_2: queue CIC in any state
# EAI_queue_MIC: queue MIC in higher INF states, else queue INF
# EAI_queue_MIC_2: queue MIC in any state
# EAI_queue_NIC: queue NIC if possible, else queue MIC
# EAI_queue_REF: build REF only in home area, else queue MIC
# EAI_queue_SILO
# EAI_queue_FORT_CITIES
# EAI_queue_FORT_BORDER
# EAI_queue_CFORT_BASES
# EAI_queue_CFORT_COAST

EAI_construction_strategy_COMMON = {

	if = {
		limit = {
			date > 1937.1.1
		}

		# Forts
		if = { 
			limit = { 
				threat > 0.5 
				NOT = { any_of_scopes = { array = controlled_states EAI_available_SHARED = yes } }
			} 
			
			random_list = {
				1 = { EAI_queue_CFORT_BASES = yes }
				1 = { EAI_queue_FORT_CITIES = yes }
				1 = { EAI_queue_FORT_BORDER = yes }
			}
		}

		# Silos
		# if = { limit = { check_variable = { EAI_max_fuel_consumption_estimate > 5000 } }

		# 	set_temp_variable = { EAI_num_silos_needed = num_of_military_factories }
		# 	subtract_from_temp_variable = { EAI_num_silos_needed = resource_produced@oil }
		# 	divide_temp_variable = { EAI_num_silos_needed = 6 }

		# 	if = {
		# 		limit = {
		# 			meta_trigger = {
		# 				text = { fuel_silo < [x] }
		# 				x = "[?EAI_num_silos_needed|.0]"
		# 			}
		# 		}

		# 		EAI_queue_SILO = yes
		# 	}
		# }

		# Resources needed
		if = {
			limit = {
				num_of_civilian_factories_available_for_projects > 15

				any_of_scopes = { array = controlled_states

					EAI_available_INF = yes

					OR = {
						AND = { has_resources_amount = { resource = oil amount > 50 } 			ROOT = { has_war = yes fuel_ratio < 0.5 } }
						AND = { has_resources_amount = { resource = aluminium amount > 50 } 	check_variable = { ROOT.EAI_needs_aluminium = 3 } }
						AND = { has_resources_amount = { resource = rubber amount > 50 } 		check_variable = { ROOT.EAI_needs_rubber = 3 } }
						AND = { has_resources_amount = { resource = tungsten amount > 50 } 		check_variable = { ROOT.EAI_needs_tungsten = 3 } }
						AND = { has_resources_amount = { resource = steel amount > 50 } 		check_variable = { ROOT.EAI_needs_steel = 3 } }
						AND = { has_resources_amount = { resource = chromium amount > 50 } 		check_variable = { ROOT.EAI_needs_chromium = 3 } }
					}
				}

				OR = { # Avoid using too much CIC on this

					AND = {
						NOT = { EAI_major_country = yes }
					}

					AND = {
						EAI_major_country = yes
						
						if = { limit = { OR = { has_idea = free_trade has_idea = export_focus } }

							has_war = yes
						}
					}
				}

				NOT = { 
					has_idea = free_trade
					AND = {
						has_idea = export_focus
						has_war = no
					}
				}
			}

			EAI_priority_queue_INF_resource = yes
		}
	}

	#########
	
	set_variable = { EAI_available_CIC_ratio = num_of_civilian_factories_available_for_projects }
	divide_variable = { EAI_available_CIC_ratio = num_of_factories }
}

### Country specific strategies

EAI_construction_strategy_ENG = {

	if = { 
		limit = { 
			num_of_civilian_factories_available_for_projects > 40
			any_enemy_country = { has_deployed_air_force_size = { size > 200 type = strategic_bomber } }
			is_major = yes
		} 
		EAI_queue_AA = yes
	}
	
	# if = { 
	# 	limit = { 
	# 		check_variable = { resource_consumed@rubber > 8 }
	# 		OR = { check_variable = { resource@rubber < 8 } check_variable = { resource_imported@rubber > 8 } }
	# 		has_tech = synth_oil_experiments 
	# 	}

	# 	EAI_queue_REF = yes
	# 	EAI_queue_REF = yes
	# }
	# else_if = { limit = { fuel_ratio < 0.25 }

	# 	EAI_queue_REF = yes
	# }
	
	# if = { limit = { date > 1940.1.1 num_of_civilian_factories_available_for_projects < 100 check_variable = { EAI_available_CIC_ratio < 0.25 } }
	
	# 	EAI_queue_CIC = yes
	# }

	if = { limit = { has_war = yes } 
		EAI_queue_CFORT_BASES = yes
	}

	# if = {
	# 	limit = {
	# 		num_of_military_factories < 400

	# 		num_of_naval_factories < 50
	# 	}

	# 	if = { limit = { date < 1937.1.1 }
	# 		EAI_queue_CIC = yes
	# 		EAI_queue_CIC = yes
	# 		EAI_queue_CIC = yes
	# 		EAI_queue_CIC = yes
			
	# 		EAI_queue_CIC = yes
	# 		EAI_queue_CIC = yes
			
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes

	# 		if = { limit = { fuel_silo < 10 }
	# 			EAI_queue_SILO = yes
	# 			EAI_queue_SILO = yes

	# 			else = {
	# 				EAI_queue_CIC = yes
	# 			}
	# 		}
	# 	}
	# 	else_if = { limit = { num_of_military_factories < 100 }
	# 		EAI_queue_RADAR = yes
	# 		EAI_queue_RADAR = yes

	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes

	# 		if = { limit = { fuel_silo < 10 }
	# 			EAI_queue_SILO = yes

	# 			else = {
	# 				EAI_queue_MIC = yes
	# 			}
	# 		}
			
	# 		if = { limit = { num_of_naval_factories < 30 }
	# 			EAI_queue_NIC = yes

	# 			else = {
	# 				EAI_queue_MIC = yes
	# 			}
	# 		}
	# 	}
	# 	else_if = { limit = {}
	# 		EAI_queue_RADAR = yes
	# 		EAI_queue_RADAR = yes

	# 		if = { limit = { num_of_naval_factories < 30 }
	# 			EAI_queue_NIC = yes

	# 			else = {
	# 				EAI_queue_MIC = yes
	# 			}
	# 		}

	# 		if = { limit = { fuel_silo < 10 }
	# 			EAI_queue_SILO = yes

	# 			else = {
	# 				EAI_queue_MIC = yes
	# 			}
	# 		}

	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 	}
	# }
	# else_if = {
	# 	limit = {
	# 		num_of_naval_factories < 50
	# 	}

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	if = { limit = { fuel_silo < 10 }
	# 		EAI_queue_SILO = yes
	# 		EAI_queue_SILO = yes

	# 		else = {
	# 			EAI_queue_NIC = yes
	# 			EAI_queue_NIC = yes
	# 		}
	# 	}

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# }
	# else_if = {
	# 	limit = { }

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# }
}

EAI_construction_strategy_FRA = {

	EAI_queue_RADAR = yes

	if = { 
		limit = { 
			num_of_civilian_factories_available_for_projects > 40
			any_enemy_country = { has_deployed_air_force_size = { size > 200 type = strategic_bomber } }
			is_major = yes
		} 
		EAI_queue_AA = yes
	}

	# if = { 
	# 	limit = { 
	# 		check_variable = { resource_consumed@rubber > 8 }
	# 		OR = { check_variable = { resource@rubber < 8 } check_variable = { resource_imported@rubber > 8 } }
	# 		has_tech = synth_oil_experiments 
	# 	}

	# 	EAI_queue_REF = yes
	# }
	# else_if = { limit = { fuel_ratio < 0.25 }

	# 	EAI_queue_REF = yes
	# }
	
	# if = { limit = { date > 1940.1.1 num_of_civilian_factories_available_for_projects < 100 check_variable = { EAI_available_CIC_ratio < 0.25 } }
	
	# 	EAI_queue_CIC = yes
	# }

	# if = {
	# 	limit = {
	# 		num_of_military_factories < 400

	# 		num_of_naval_factories < 50
	# 	}

	# 	if = { limit = { date < 1938.1.1 }
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes

	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 	}
	# 	else_if = { limit = { num_of_military_factories < 100 }
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes

	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 	}
	# 	else_if = { limit = {}
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes

	# 		EAI_queue_NIC = yes
	# 	}
	# }
	# else_if = {
	# 	limit = {
	# 		num_of_naval_factories < 50
	# 	}

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# }
	# else_if = {
	# 	limit = { }

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# }
}

EAI_construction_strategy_USA = {

	EAI_queue_RADAR = yes
	EAI_queue_RADAR = yes

	# if = { 
	# 	limit = { 
	# 		synthetic_refinery > 19
	# 		check_variable = { resource_consumed@rubber > 8 }
	# 		OR = { check_variable = { resource@rubber < 8 } check_variable = { resource_imported@rubber > 8 } }
	# 		has_tech = synth_oil_experiments 
	# 	}
	# 	EAI_queue_REF = yes
	# 	EAI_queue_REF = yes
	# 	EAI_queue_REF = yes
	# }

	if = { limit = { has_war = yes } 
		EAI_queue_CFORT_COAST = yes
	}

	if = { 
		limit = { 
			num_of_civilian_factories_available_for_projects > 40
			any_enemy_country = { has_deployed_air_force_size = { size > 200 type = strategic_bomber } }
			is_major = yes
		} 
		EAI_queue_AA = yes
		EAI_queue_AA = yes
	}

	# if = { limit = { num_of_military_factories < 400 }

	# 	if = { limit = { date < 1939.1.1 }
	# 		EAI_queue_MIC_2 = yes
	# 		EAI_queue_MIC_2 = yes
	# 		EAI_queue_MIC_2 = yes
	# 		EAI_queue_MIC_2 = yes

	# 		EAI_queue_MIC_2 = yes
	# 		EAI_queue_MIC_2 = yes

	# 		if = { limit = { synthetic_refinery < 20 }
	# 			EAI_queue_REF = yes
	# 			EAI_queue_REF = yes

	# 			else = { 
	# 				EAI_queue_MIC_2 = yes
	# 				EAI_queue_MIC_2 = yes
	# 				EAI_queue_MIC_2 = yes
	# 			}
	# 		}
	# 	}
	# 	else_if = { limit = {}
	# 		EAI_queue_INF_resource = yes
	# 		EAI_queue_INF_resource = yes

	# 		if = { limit = { synthetic_refinery < 20 }
	# 			EAI_queue_REF = yes
	# 			EAI_queue_REF = yes

	# 			else = { 
	# 				EAI_queue_MIC_2 = yes 
	# 				EAI_queue_MIC_2 = yes 
	# 				EAI_queue_MIC_2 = yes 
	# 				EAI_queue_MIC_2 = yes 
	# 				EAI_queue_MIC_2 = yes 
	# 				EAI_queue_MIC_2 = yes 
	# 			}
	# 		}

	# 		EAI_queue_MIC_2 = yes
	# 		EAI_queue_MIC_2 = yes
	# 		EAI_queue_MIC_2 = yes
	# 		EAI_queue_MIC_2 = yes

	# 		EAI_queue_MIC_2 = yes
	# 		EAI_queue_MIC_2 = yes
	# 		EAI_queue_MIC_2 = yes
	# 		EAI_queue_MIC_2 = yes

	# 		EAI_queue_MIC_2 = yes
	# 		EAI_queue_MIC_2 = yes
	# 		EAI_queue_MIC_2 = yes
	# 		EAI_queue_MIC_2 = yes

	# 		EAI_queue_MIC_2 = yes
	# 		EAI_queue_MIC_2 = yes
	# 		EAI_queue_MIC_2 = yes
	# 		EAI_queue_MIC_2 = yes

	# 		EAI_queue_MIC_2 = yes
	# 		EAI_queue_MIC_2 = yes
	# 	}
	# }
	# else_if = { limit = { num_of_naval_factories < 50 }

	# 	if = { limit = { synthetic_refinery < 20 }
	# 		EAI_queue_REF = yes
	# 		EAI_queue_REF = yes

	# 		else = { 
	# 			EAI_queue_NIC = yes 
	# 			EAI_queue_NIC = yes 
	# 			EAI_queue_NIC = yes 
	# 			EAI_queue_NIC = yes 
	# 		}
	# 	}

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# }
	# else_if = {
	# 	limit = { }

	# 	if = { limit = { synthetic_refinery < 20 }
	# 		EAI_queue_REF = yes
	# 		EAI_queue_REF = yes

	# 		else = { 
	# 			EAI_queue_MIC_2 = yes 
	# 			EAI_queue_MIC_2 = yes 
	# 			EAI_queue_MIC_2 = yes 
	# 			EAI_queue_MIC_2 = yes 
	# 			EAI_queue_MIC_2 = yes 
	# 			EAI_queue_MIC_2 = yes 
	# 		}
	# 	}

	# 	EAI_queue_MIC_2 = yes
	# 	EAI_queue_MIC_2 = yes
	# 	EAI_queue_MIC_2 = yes
	# 	EAI_queue_MIC_2 = yes

	# 	EAI_queue_MIC_2 = yes
	# 	EAI_queue_MIC_2 = yes
	# }
}

EAI_construction_strategy_GER = {

	EAI_queue_RADAR = yes
	EAI_queue_RADAR = yes

	if = { 
		limit = { 
			num_of_civilian_factories_available_for_projects > 40
			any_enemy_country = { has_deployed_air_force_size = { size > 200 type = strategic_bomber } }
			is_major = yes
		} 
		
		EAI_queue_AA = yes
		EAI_queue_AA = yes
	}
	
	# if = { 
	# 	limit = { 
	# 		check_variable = { EAI_needs_rubber = 3 }
	# 		has_tech = synth_oil_experiments 
	# 	}

	# 	EAI_priority_queue_REF = yes
	# }
}

EAI_construction_strategy_ITA = {

	EAI_queue_RADAR = yes

	if = { 
		limit = { 
			num_of_civilian_factories_available_for_projects > 40
			any_enemy_country = { has_deployed_air_force_size = { size > 200 type = strategic_bomber } }
			is_major = yes
		} 
		EAI_queue_AA = yes
	}
	
	# if = { 
	# 	limit = { 
	# 		check_variable = { resource_consumed@rubber > 8 }
	# 		OR = { check_variable = { resource@rubber < 8 } check_variable = { resource_imported@rubber > 8 } }
	# 		has_tech = synth_oil_experiments 
	# 	}

	# 	EAI_queue_REF = yes
	# }

	# else_if = { limit = { fuel_ratio < 0.25 }

	# 	EAI_queue_REF = yes
	# }
	
	# if = { limit = { date > 1940.1.1 num_of_civilian_factories_available_for_projects < 100 check_variable = { EAI_available_CIC_ratio < 0.25 } }
	
	# 	EAI_queue_CIC = yes
	# }

	# if = {
	# 	limit = {
	# 		num_of_military_factories < 400

	# 		num_of_naval_factories < 50
	# 	}

	# 	if = { limit = { num_of_civilian_factories_available_for_projects < 40 }
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes

	# 		EAI_queue_MIC = yes
			
	# 		if = { limit = { num_of_naval_factories < 25 }
	# 			EAI_queue_NIC = yes

	# 			else = {
	# 				EAI_queue_MIC = yes
	# 			}
	# 		}
	# 	}
	# 	else_if = { limit = { num_of_military_factories < 150 }
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
			
	# 		if = { limit = { num_of_naval_factories < 25 }
	# 			EAI_queue_NIC = yes

	# 			else = {
	# 				EAI_queue_MIC = yes
	# 			}
	# 		}
	# 	}
	# 	else_if = { limit = {}
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes

	# 		if = { limit = { num_of_naval_factories < 25 }
	# 			EAI_queue_NIC = yes

	# 			else = {
	# 				EAI_queue_MIC = yes
	# 			}
	# 		}
	# 	}
	# }
	# else_if = {
	# 	limit = {
	# 		num_of_naval_factories < 50
	# 	}

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# }
	# else_if = {
	# 	limit = { }

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# }
}

EAI_construction_strategy_JAP = {

	if = { limit = { num_of_civilian_factories_available_for_projects > 35 }
		EAI_queue_RADAR = yes
	}
	
	if = { 
		limit = { 
			num_of_civilian_factories_available_for_projects > 40
			any_enemy_country = { has_deployed_air_force_size = { size > 200 type = strategic_bomber } }
			is_major = yes
		} 
		EAI_queue_AA = yes
	}
	
	# if = { 
	# 	limit = { 
	# 		check_variable = { resource_consumed@rubber > 8 }
	# 		OR = { check_variable = { resource@rubber < 8 } check_variable = { resource_imported@rubber > 8 } }
	# 		has_tech = synth_oil_experiments 
	# 	}

	# 	EAI_queue_REF = yes
	# 	EAI_queue_REF = yes
	# }

	# else_if = { limit = { fuel_ratio < 0.25 }

	# 	EAI_queue_REF = yes
	# }
	
	# if = { limit = { date > 1940.1.1 num_of_civilian_factories_available_for_projects < 100 check_variable = { EAI_available_CIC_ratio < 0.25 } }
	
	# 	EAI_queue_CIC = yes
	# }

	# if = {
	# 	limit = {
	# 		num_of_military_factories < 400

	# 		num_of_naval_factories < 50
	# 	}

	# 	if = { limit = { num_of_civilian_factories_available_for_projects < 25 }
	# 		EAI_queue_CIC_2 = yes

	# 		EAI_queue_MIC_2 = yes
	# 		EAI_queue_MIC_2 = yes

	# 		if = { limit = { fuel_silo < 15 }
	# 			EAI_queue_SILO = yes

	# 			else = {
	# 				EAI_queue_MIC = yes
	# 			}
	# 		}

	# 		if = { limit = { num_of_naval_factories < 35 }
	# 			EAI_queue_NIC = yes

	# 			else = {
	# 				EAI_queue_MIC_2 = yes
	# 			}
	# 		}
	# 	}
	# 	else_if = { limit = { num_of_military_factories < 150 }
	# 		EAI_queue_MIC_2 = yes
	# 		EAI_queue_MIC_2 = yes

	# 		if = { limit = { fuel_silo < 15 }
	# 			EAI_queue_SILO = yes

	# 			else = {
	# 				EAI_queue_MIC = yes
	# 			}
	# 		}

	# 		if = { limit = { num_of_naval_factories < 35 }
	# 			EAI_queue_NIC = yes

	# 			else = {
	# 				EAI_queue_MIC = yes
	# 			}
	# 		}
	# 	}
	# 	else_if = { limit = {}
	# 		EAI_queue_NIC = yes
	# 		EAI_queue_NIC = yes

	# 		EAI_queue_MIC_2 = yes
	# 		EAI_queue_MIC_2 = yes
			
	# 		if = { limit = { fuel_silo < 15 }
	# 			EAI_queue_SILO = yes

	# 			else = {
	# 				EAI_queue_MIC = yes
	# 			}
	# 		}
	# 	}
	# }
	# else_if = {
	# 	limit = {
	# 		num_of_naval_factories < 50
	# 	}

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
		
	# 	if = { limit = { fuel_silo < 15 }
	# 		EAI_queue_SILO = yes

	# 		else = {
	# 			EAI_queue_NIC = yes
	# 		}
	# 	}

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# }
	# else_if = {
	# 	limit = { }

	# 	if = { limit = { fuel_silo < 15 }
	# 		EAI_queue_SILO = yes

	# 		else = {
	# 			EAI_queue_NIC = yes
	# 		}
	# 	}

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# }
}

EAI_construction_strategy_SOV = {

	EAI_queue_RADAR = yes

	###
		
	# if = { 
	# 	limit = { 
	# 		check_variable = { resource_consumed@rubber > 8 }
	# 		OR = { check_variable = { resource@rubber < 8 } check_variable = { resource_imported@rubber > 8 } }
	# 		has_tech = synth_oil_experiments 

	# 		set_temp_variable = { ref_limit = global.EAI_years_elapsed }
	# 		multiply_temp_variable = { ref_limit = 1 }
	# 		check_variable = { EAI_construction_REF_added < ref_limit }

	# 		date > 1942.1.1
	# 	}

	# 	EAI_queue_REF = yes
	# }
	# else_if = { limit = { fuel_ratio < 0.25 }

	# 	EAI_queue_REF = yes
	# }

	###

	if = { 
		limit = { 
			num_of_civilian_factories_available_for_projects > 40
			any_enemy_country = { has_deployed_air_force_size = { size > 200 type = strategic_bomber } }
			is_major = yes
		} 
		EAI_queue_AA = yes
	}
}

EAI_construction_strategy_CHI = {

	if = { 
		limit = { 
			num_of_civilian_factories_available_for_projects > 40
			any_enemy_country = { has_deployed_air_force_size = { size > 200 type = strategic_bomber } }
			is_major = yes
		} 
		EAI_queue_AA = yes
	}

	# if = { 
	# 	limit = { 
	# 		check_variable = { resource_consumed@rubber > 8 }
	# 		OR = { check_variable = { resource@rubber < 8 } check_variable = { resource_imported@rubber > 8 } }
	# 		has_tech = synth_oil_experiments 
	# 	}

	# 	EAI_queue_REF = yes
	# }
	# else_if = { limit = { fuel_ratio < 0.25 }

	# 	EAI_queue_REF = yes
	# }

	# if = {
	# 	limit = {
	# 		num_of_military_factories < 400

	# 		num_of_naval_factories < 50
	# 	}

	# 	if = { limit = { is_subject = no }
	# 		EAI_queue_CIC = yes

	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes

	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 	}
	# 	else_if = { limit = { is_subject = no num_of_civilian_factories_available_for_projects < 30 }
	# 		EAI_queue_CIC = yes
	# 		EAI_queue_CIC = yes
	# 		EAI_queue_CIC = yes
	# 		EAI_queue_CIC = yes

	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 	}
	# 	else_if = { limit = {}
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes

	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 	}
	# }
	# else_if = {
	# 	limit = {
	# 		num_of_naval_factories < 50
	# 	}

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# }
	# else_if = {
	# 	limit = { }

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# }
}

EAI_construction_strategy_SPR = {

	if = { limit = { OR = { oil > 80 rubber > 80 steel > 80 tungsten > 80 chromium > 80 aluminium > 80 } }
		EAI_queue_INF_resource = yes
		EAI_queue_INF_resource = yes
	}

	# if = { 
	# 	limit = { 
	# 		check_variable = { resource_consumed@rubber > 8 }
	# 		OR = { check_variable = { resource@rubber < 8 } check_variable = { resource_imported@rubber > 8 } }
	# 		has_tech = synth_oil_experiments 
	# 	}

	# 	EAI_queue_REF = yes
	# }
	# else_if = { limit = { fuel_ratio < 0.25 }

	# 	EAI_queue_REF = yes
	# }

	# if = {
	# 	limit = {
	# 		num_of_military_factories < 400

	# 		num_of_naval_factories < 50
	# 	}

	# 	if = { limit = { has_civil_war = yes }
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 	}
	# 	else_if = { limit = { check_variable = { num_of_civilian_factories_available_for_projects < 100 } check_variable = { EAI_available_CIC_ratio < 0.25 } }
	# 		EAI_queue_CIC = yes
	# 		EAI_queue_CIC = yes
	# 	}
	# 	else_if = { limit = {}
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 	}

	# 	if = { limit = { has_civil_war = yes }
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 	}
	# 	else_if = { limit = { check_variable = { num_of_civilian_factories_available_for_projects < 100 } check_variable = { EAI_available_CIC_ratio < 0.25 } }
	# 		EAI_queue_CIC = yes
	# 		EAI_queue_CIC = yes
	# 	}
	# 	else_if = { limit = {}
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 	}

	# 	if = { limit = { has_civil_war = yes }
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 	}
	# 	else_if = { limit = { check_variable = { num_of_civilian_factories_available_for_projects < 100 } check_variable = { EAI_available_CIC_ratio < 0.25 } }
	# 		EAI_queue_CIC = yes
	# 		EAI_queue_CIC = yes
	# 	}
	# 	else_if = { limit = {}
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 		EAI_queue_MIC = yes
	# 	}

	# 	if = { limit = { any_owned_state = { is_controlled_by = ROOT is_coastal = yes } num_of_naval_factories < 1 }

	# 		EAI_queue_NIC = yes
	# 	}
	# }
	# else_if = {
	# 	limit = {
	# 		num_of_naval_factories < 50
	# 	}

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# }
	# else_if = {
	# 	limit = { }

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes

	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# 	EAI_queue_INF_resource = yes
	# }
}

### Generic country strategy

EAI_construction_strategy_GENERIC = {

	if = { limit = { OR = { oil > 80 rubber > 80 steel > 80 tungsten > 80 chromium > 80 aluminium > 80 } }
		EAI_queue_INF_resource = yes
		EAI_queue_INF_resource = yes
	}

	# if = { 
	# 	limit = { 
	# 		check_variable = { resource_consumed@rubber > 8 }
	# 		OR = { check_variable = { resource@rubber < 8 } check_variable = { resource_imported@rubber > 8 } }
	# 		has_tech = synth_oil_experiments 
	# 	}

	# 	EAI_queue_REF = yes
	# }
	# else_if = { limit = { fuel_ratio < 0.25 }

	# 	EAI_queue_REF = yes
	# }
}

### Constructions at the start of the game

EAI_construction_startup = {
	
	if = { limit = { has_country_flag = EAI_construction_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | CONSTRUCTION: startup queue" } 

	set_variable = { EAI_available_CIC_ratio = num_of_civilian_factories_available_for_projects }
	divide_variable = { EAI_available_CIC_ratio = num_of_factories }

	####################################################################################################################################################
	#	ENG
	####################################################################################################################################################

	# if = { limit = { original_tag = ENG }

	# 	set_country_flag = { flag = EAI_construction_timer days = 300 value = 1 }

	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes

	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes

	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# }

	####################################################################################################################################################
	#	FRA
	####################################################################################################################################################

	# else_if = { limit = { original_tag = FRA }

	# 	set_country_flag = { flag = EAI_construction_timer days = 360 value = 1 }

	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes

	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# }

	####################################################################################################################################################
	#	USA
	####################################################################################################################################################

	# else_if = { limit = { original_tag = USA }

	# 	set_country_flag = { flag = EAI_construction_timer days = 360 value = 1 }

	# 	### AI wont train its navy if its fuel cap is too low

	# 	EAI_queue_SILO = yes
	# 	EAI_queue_SILO = yes
	# 	EAI_queue_SILO = yes
	# 	EAI_queue_SILO = yes

	# 	###

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes

	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# 	EAI_queue_NIC = yes
	# }

	####################################################################################################################################################
	#	GER
	####################################################################################################################################################

	# else_if = { limit = { original_tag = GER }

	# 	set_country_flag = { flag = EAI_construction_timer days = 300 value = 1 }

	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
		
	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# }

	####################################################################################################################################################
	#	ITA
	####################################################################################################################################################

	# else_if = { limit = { original_tag = ITA }

	# 	set_country_flag = { flag = EAI_construction_timer days = 270 value = 1 }

	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes

	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# }

	####################################################################################################################################################
	#	JAP
	####################################################################################################################################################

	# else_if = { limit = { original_tag = JAP }

	# 	set_country_flag = { flag = EAI_construction_timer days = 300 value = 1 }

	# 	EAI_queue_CIC = yes
	# 	EAI_queue_CIC = yes
	# 	EAI_queue_MIC = yes
	# 	EAI_queue_MIC = yes

	# 	EAI_queue_MIC = yes
	# 	EAI_queue_MIC = yes
	# 	EAI_queue_MIC = yes
	# 	EAI_queue_MIC = yes
	# }

	####################################################################################################################################################
	#	SOV
	####################################################################################################################################################

	# if = { limit = { original_tag = SOV }

	# 	# moscow
	# 	219 = { EAI_add_CIC = yes EAI_add_CIC = yes }

	# 	# leningrad
	# 	195 = {  }

	# 	# kharkov
	# 	221 = { EAI_add_CIC = yes EAI_add_CIC = yes EAI_add_CIC = yes EAI_add_CIC = yes EAI_add_CIC = yes }

	# 	# stalingrad
	# 	217 = { EAI_add_CIC = yes EAI_add_CIC = yes EAI_add_CIC = yes EAI_add_CIC = yes }

	# 	# stalino
	# 	227 = { EAI_add_CIC = yes EAI_add_CIC = yes EAI_add_CIC = yes EAI_add_CIC = yes EAI_add_CIC = yes EAI_add_CIC = yes }

	# 	# kursk
	# 	220 = { EAI_add_CIC = yes EAI_add_CIC = yes EAI_add_CIC = yes EAI_add_CIC = yes EAI_add_CIC = yes EAI_add_CIC = yes }
	# }

	####################################################################################################################################################

	EAI_clear_construction_scores = yes
}

### Misc

EAI_construction_use_free_CIC = {

	if = {
		limit = {
			num_of_available_civilian_factories > 1
		}

		if = { 
			limit = { 
				any_of_scopes = { array = controlled_states
					free_building_slots = { building = infrastructure size > 0 include_locked = no } 
				}
			}
			EAI_queue_INF = yes
		}
		
		else_if = { limit = { threat > 0.5 NOT = { any_of_scopes = { array = controlled_states EAI_available_SHARED = yes } } } 
			random_list = {
				1 = { EAI_queue_CFORT_BASES = yes }
				1 = { EAI_queue_FORT_CITIES = yes }
				1 = { EAI_queue_FORT_BORDER = yes }
			}
		}

		if = { limit = { has_country_flag = EAI_construction_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | CONSTRUCTION: queuing INF with free factories" } 
	}
}

EAI_construction_build_forts = {

	if = {
		limit = {
			original_tag = ITA

			date > 1940.6.1

			surrender_progress < 0.1
		}

		if = { limit = { has_country_flag = EAI_construction_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | CONSTRUCTION: fort construction" } 
		
		for_each_scope_loop = { array = controlled_states

			if = { limit = { is_in_home_area = yes } EAI_add_CFORT_BASE = yes }
		}
	}

	if = {
		limit = {
			original_tag = SWI

			NOT = { any_of_scopes = { array = controlled_states EAI_available_SHARED = yes } }
		}

		if = { limit = { has_country_flag = EAI_construction_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | CONSTRUCTION: fort construction" } 
		
		EAI_queue_FORT_BORDER = yes
		EAI_queue_FORT_BORDER = yes
		
		capital_scope = {
			EAI_add_FORT_CITY = yes
			EAI_add_FORT_CITY = yes
		}
	}

	if = {
		limit = {
			original_tag = SPR

			has_war = no

			date > 1938.1.1
		}

		if = { limit = { has_country_flag = EAI_construction_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | CONSTRUCTION: fort construction" } 

		for_each_scope_loop = { array = controlled_states

			if = { limit = { OR = { state = 165 state = 166 state = 172 } }
				
				EAI_add_FORT_BORDER = yes
				EAI_add_FORT_BORDER = yes
			}
		}
	}

	if = {
		limit = {
			original_tag = TUR

			date > 1938.1.1
		}

		if = { limit = { has_country_flag = EAI_construction_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | CONSTRUCTION: fort construction" } 

		for_each_scope_loop = { array = controlled_states

			if = { limit = { OR = { state = 341 } }
				
				EAI_add_FORT_BORDER = yes
				EAI_add_FORT_BORDER = yes
			}
		}
	}

	if = {
		limit = {
			num_of_civilian_factories_available_for_projects > 10

			enemies_strength_ratio > 0.75
			
			OR = {
				surrender_progress > 0.05
				has_defensive_war = yes
			}

			any_neighbor_country = {
				has_war_with = ROOT
			}
			
			any_of_scopes = { array = controlled_states
				OR = {
					AND = {
						is_in_home_area = yes
						any_neighbor_state = {
							OR = {
								CONTROLLER = { has_war_with = ROOT }
								any_neighbor_state = { CONTROLLER = { has_war_with = ROOT } }
							}
						}
						NOT = { has_state_flag = EAI_generic_fort_construction_state_triggered_@ROOT }
					}
					
					AND = {
						is_capital = yes
						NOT = { has_state_flag = EAI_generic_fort_construction_state_triggered_@ROOT }
					}
				}
			}
		}

		if = { limit = { has_country_flag = EAI_construction_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | CONSTRUCTION: fort construction (dynamic)" } 

		for_each_scope_loop = { array = controlled_states # build forts on victory points near enemy borders

			if = {
				limit = {
					is_in_home_area = yes
					any_neighbor_state = {
						OR = {
							CONTROLLER = { has_war_with = ROOT }
							any_neighbor_state = { CONTROLLER = { has_war_with = ROOT } }
						}
					}
					NOT = { has_state_flag = EAI_generic_fort_construction_state_triggered_@ROOT }
				}
				
				set_state_flag = { flag = EAI_generic_fort_construction_state_triggered_@ROOT value = 1 days = 1000 }
				
				EAI_add_FORT_CITY = yes
			}
		}
		
		capital_scope = { # build forts on capital
			if = {
				limit = { NOT = { has_state_flag = EAI_generic_fort_construction_state_triggered_@ROOT } }
			
				set_state_flag = { flag = EAI_generic_fort_construction_state_triggered_@ROOT value = 1 days = 1000 }
		
				EAI_add_FORT_CITY = yes
				EAI_add_FORT_CITY = yes
			}
		}
	}

	if = {
		limit = {
			tag = ROM

			79 = {
				any_neighbor_state = {
					CONTROLLER = { tag = SOV }
				}
			}
		}

		if = { limit = { has_country_flag = EAI_construction_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | CONSTRUCTION: fort construction" } 

		46 = {
			add_building_construction = {
				type = bunker
				province = {
					id = 687
					id = 3076
					limit_to_border = yes
				}
				level = 1
				instant_build = no
			}
			add_building_construction = {
				type = bunker
				province = {
					id = 687
					id = 3076
					limit_to_border = yes
				}
				level = 1
				instant_build = no
			}
			add_building_construction = {
				type = bunker
				province = {
					id = 687
					id = 3076
					limit_to_border = yes
				}
				level = 1
				instant_build = no
			}
		}
	}
}

EAI_delete_excess_MIC = {
	
	if = {
		limit = {
			num_of_military_factories > 600
		}

		set_temp_variable = { t1 = num_of_military_factories }
		subtract_from_temp_variable = { t1 = 450 }

		if = {
			limit = {
				any_of_scopes = { array = controlled_states
					NOT = { is_core_of = ROOT }
					arms_factory > 0
				}
			}

			for_each_scope_loop = { array = controlled_states

				if = {
					limit = {
						NOT = { is_core_of = ROOT }
						arms_factory > 0
					}

					set_temp_variable = { t2 = building_level@arms_factory }
					clamp_temp_variable = { var = t2 min = 0 max = t1 }
					remove_building = { type = arms_factory level = t2 }
					subtract_from_temp_variable = { t1 = t2 }
				}

				if = { limit = { NOT = { check_variable = { t1 > 0 } } }

					set_temp_variable = { break = 1 }
				}
			}
		}
		else = {

			for_each_scope_loop = { array = controlled_states

				if = {
					limit = {
						arms_factory > 0
					}

					set_temp_variable = { t2 = building_level@arms_factory }
					clamp_temp_variable = { var = t2 min = 0 max = t1 }
					remove_building = { type = arms_factory level = t2 }
					subtract_from_temp_variable = { t1 = t2 }
				}

				if = { limit = { NOT = { check_variable = { t1 > 0 } } }

					set_temp_variable = { break = 1 }
				}
			}
		}

		if = { limit = { has_country_flag = EAI_construction_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | deleting factories" } 
	}
}