FAI_industry_minor_equipment_production = {
	enable = { is_major = no }
	abort_when_not_enabled = yes
	# Land equipment factors
		ai_strategy = {
			type = role_ratio
			id = garrison
			value = 4
		}
		ai_strategy = {
			type = role_ratio
			id = paratroopers
			value = 0
		}
		ai_strategy = {
			type = role_ratio
			id = mountaineers
			value = 10
		}
		ai_strategy = {
			type = role_ratio
			id = marines
			value = 10
		}
		ai_strategy = {
			type = role_ratio
			id = cavalry
			value = -100
		}
		ai_strategy = {
			type = role_ratio
			id = infantry
			value = 90
		}
		ai_strategy = {
			type = equipment_variant_production_factor
			id = support_equipment
			value = 15
		}
	# Arty equipment factors
		ai_strategy = {
			type = equipment_production_factor
			id = artillery
			value = 80
		}
		ai_strategy = {
			type = equipment_production_factor
			id = anti_air
			value = 23
		}
		ai_strategy = {
			type = equipment_production_factor
			id = anti_tank
			value = 15
		}
	# Tank equipment factors
		ai_strategy = {
			type = role_ratio
			id = motorized
			value = 2
		}
		ai_strategy = {
			type = equipment_production_factor
			id = motorized
			value = 12
		}
		ai_strategy = {
			type = role_ratio
			id = mechanized
			value = 7
		}
		ai_strategy = {
			type = role_ratio
			id = armor
			value = 3
		}
		ai_strategy = {
			type = equipment_production_factor
			id = armor
			value = 12
		}
	# Special equipment factors
		ai_strategy = { # Added to railway gun define (Set to 0 by default, increased in default strategies)
			type = railway_gun_divisions_ratio
			value = 10
		}
}

FAI_industry_major_equipment_production = {
	enable = { is_major = yes }
	abort_when_not_enabled = yes
	# Land equipment factors
		ai_strategy = {
			type = role_ratio
			id = garrison
			value = 4
		}
		ai_strategy = {
			type = role_ratio
			id = paratroopers
			value = 0
		}
		ai_strategy = {
			type = role_ratio
			id = mountaineers
			value = 20
		}
		ai_strategy = {
			type = role_ratio
			id = marines
			value = 20
		}
		ai_strategy = {
			type = role_ratio
			id = cavalry
			value = -100
		}
		ai_strategy = {
			type = role_ratio
			id = infantry
			value = 70
		}
		ai_strategy = {
			type = equipment_variant_production_factor
			id = support_equipment
			value = 30
		}
	# Arty equipment factors
		ai_strategy = {
			type = equipment_production_factor
			id = artillery
			value = 60
		}
		ai_strategy = {
			type = equipment_production_factor
			id = anti_air
			value = 35
		}
		ai_strategy = {
			type = equipment_production_factor
			id = anti_tank
			value = 40
		}
		ai_strategy = { # Build these up over time, don't stall
			type = equipment_production_min_factories
			id = anti_air
			value = 1
		}
		ai_strategy = { # Build these up over time, don't stall
			type = equipment_production_min_factories
			id = anti_tank
			value = 1
		}
	# Tank equipment factors
		ai_strategy = {
			type = role_ratio
			id = motorized
			value = 3
		}
		ai_strategy = {
			type = equipment_production_factor
			id = motorized
			value = 8
		}
		ai_strategy = {
			type = role_ratio
			id = mechanized
			value = 12
		}
		ai_strategy = {
			type = role_ratio
			id = armor
			value = 6
		}
		ai_strategy = {
			type = equipment_production_factor
			id = armor
			value = 16
		}
}


######################################
#	BUILDING CONSTRUCTION PRIORITIES
######################################

# Peace time - Build civs
peacetime_industrialization = {
	enable = {
		threat < 0.15
		has_war = no
		num_of_civilian_factories < 50  # Stop when we have enough
		OR = {
			do_expand_oil = no
			do_expand_rubber = no
		}
		check_variable = { resource@rubber > 0 }
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = added_military_to_civilian_factory_ratio
		value = -50  # Was -100, too extreme
	}
	ai_strategy = {
		type = building_target
		id = industrial_complex
		value = 150  # Was 300
	}
	ai_strategy = {
		type = building_target
		id = fuel_silo
		value = -100
	}
	##ai_strategy = {
	##	type = building_target
	##	id = synthetic_refinery
	##	value = -100
	##}
}

# Preparation phase - Balance civs and mils
preparation_phase = {
	enable = {
		threat > 0.15
		threat < 0.40
		has_war = no
		OR = {
			do_expand_oil = no
			do_expand_rubber = no
		}
		check_variable = { resource@rubber > 0 }
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = added_military_to_civilian_factory_ratio
		value = 25  # Slightly favor mils
	}
	ai_strategy = {
		type = building_target
		id = arms_factory
		value = 100
	}
	ai_strategy = {
		type = building_target
		id = industrial_complex
		value = 50
	}
}

# War preparation - Focus on mils
war_preparation = {
	enable = {
		OR = {
			threat > 0.40
			AND = {
				threat > 0.25
				any_enemy_country = { always = yes }
			}
		}
		has_war = no
		OR = {
			do_expand_oil = no
			do_expand_rubber = no
		}
		check_variable = { resource@rubber > 0 }
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = added_military_to_civilian_factory_ratio
		value = 100
	}
	ai_strategy = {
		type = building_target
		id = arms_factory
		value = 200
	}
	ai_strategy = {
		type = building_target
		id = industrial_complex
		value = -50
	}
}

# Total war - All mils
total_war_effort = {
	enable = {
		has_war = yes
		OR = {
			do_expand_oil = no
			do_expand_rubber = no
		}
		check_variable = { resource@rubber > 0 }
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = added_military_to_civilian_factory_ratio
		value = 200  # Was 300
	}
	ai_strategy = {
		type = building_target
		id = arms_factory
		value = 300
	}
	ai_strategy = {
		type = building_target
		id = industrial_complex
		value = -100
	}
	ai_strategy = {
		type = building_target
		id = fuel_silo
		value = -200
	}
}

# Post-war demobilization
demobilization_effort = {
	enable = {
		has_war = no
		threat < 0.10
		### date > 1739.1.1  # Don't demobilize too early
		num_of_military_factories > num_of_civilian_factories
		OR = {
			do_expand_oil = no
			do_expand_rubber = no
		}
		check_variable = { resource@rubber > 0 }
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = building_target
		id = industrial_complex
		value = 100
	}
	ai_strategy = {
		type = building_target
		id = arms_factory
		value = -50  # Was -100
	}
}

######################################
#	SYNTHETIC REFINERIES
######################################
# Resource-Based Production Adjustments
FIA_industry_synth_oil_experiments_desire = {
	enable = {
		NOT = { has_tech = synth_oil_experiments }
		OR = {
			do_expand_oil = yes
			do_expand_rubber = yes
		}
	}
	abort_when_not_enabled = yes
	ai_strategy = {
	    type = research_weight_factor
	    id = synth_oil_experiments
	    value = 1500
	}
}

FIA_industry_more_synth_rubber_low = {
	enable = {
		check_variable = { resource@rubber < 0 }
		do_expand_rubber = yes
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = building_target
		id = synthetic_refinery
		value = 10
	}
}

FIA_industry_more_synth_rubber_medium = {
	enable = {
		##is_erly_game = no
		check_variable = { resource@rubber < -20 }
		do_expand_rubber = yes
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = building_target
		id = synthetic_refinery
		value = 15
	}
}

FIA_industry_more_synth_rubber_high = {
	enable = {
		##is_erly_game = no
		check_variable = { resource@rubber < -35 }
		do_expand_rubber = yes
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = building_target
		id = synthetic_refinery
		value = 25
	}
}

FIA_industry_more_synth_rubber_extreme = {
	enable = {
		##is_erly_game = no
		check_variable = { resource@rubber < -60 }
		do_expand_rubber = yes
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = building_target
		id = synthetic_refinery
		value = 50
	}
}

FIA_industry_more_synth_oil_low = {
	enable = {
		num_of_military_factories > 30
		do_expand_oil = yes
		fuel_ratio < 0.4
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = building_target
		id = synthetic_refinery
		value = 10
	}
}

FIA_industry_more_synth_oil_medium = {
	enable = {
		##is_erly_game = no
		num_of_military_factories > 65
		do_expand_oil = yes
		fuel_ratio < 0.2
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = building_target
		id = synthetic_refinery
		value = 15
	}
}

FIA_industry_more_synth_oil_high = {
	enable = {
		##is_erly_game = no
		num_of_military_factories > 110
		do_expand_oil = yes
		fuel_ratio < 0.1
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = building_target
		id = synthetic_refinery
		value = 25
	}
}

######################################
#	DOCKYARDS
######################################

limit_dockyards_for_minors = {
	enable = {
		is_major = no
		num_of_naval_factories > 20
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = building_target
		id = dockyard
		value = -50
	}
}

limit_dockyards_for_majors = {
	enable = {
		is_major = yes
		num_of_naval_factories > 60
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = building_target
		id = dockyard
		value = -30
	}
}

max_100_naval_factories = {
	enable = {
		num_of_naval_factories > 100
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = building_target
		id = dockyard
		value = -100
	}
}

nuclear_we_must_know = {
	enable = {
		is_major = yes
		num_of_civilian_factories > 70
		NOT = { 
			OR = {
				surrender_progress > 0.2 
				nuclear_facility > 1
			}
		}
	}

	abort_when_not_enabled = yes

	
	ai_strategy = {
		type = build_building
		id = nuclear_facility
		value = 999
	}
}

nuclear_powers_arise = {
	enable = {
		num_of_available_civilian_factories > 44
		has_tech = atomic_research
		NOT = {
			has_tech = commercial_nuclear_reactor_tech
			OR = {
				surrender_progress > 0.2 
				nuclear_reactor_heavy_water > 1
				nuclear_reactor > 1
			}
		}
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = build_building
		id = nuclear_reactor
		value = 999
	}
	ai_strategy = {
		type = build_building
		id = nuclear_reactor_heavy_water
		value = 999
	}
}

nuclear_commercial_reactors = {
	enable = {
		num_of_available_civilian_factories > 44
		has_tech = atomic_research
		has_tech = commercial_nuclear_reactor_tech
		NOT = { 
			OR = {
				surrender_progress > 0.2 
				commercial_nuclear_reactor > 1
			}
		}
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = building_target
		id = commercial_nuclear_reactor
		value = 999
	}
}

max_100_naval_factories = {
	enable = {
		num_of_naval_factories > 100
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = building_target
		id = dockyard
		value = -34
	}
}

create_armor_when_used_offset = { # Create Armor
	enable = {
		OR = {
			estimated_intel_max_armor = { tag = ROOT value > 10 }
			#division_has_battalion_in_template = light_armor
			#division_has_battalion_in_template = medium_armor
			#division_has_battalion_in_template = heavy_armor
			#division_has_battalion_in_template = modern_armor
		}
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = equipment_production_factor
		id = armor
		value = 10
	}
}

default_anti_armor = {
	enable = {
		any_enemy_country = {
			ROOT = {
				estimated_intel_max_armor = {
					tag = PREV
					value > 25
				}
			}
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = role_ratio
		id = anti_tank
		value = 8
	}
}

default_stockpile_management = {
	enable = {
		num_divisions > 150
	}
	abort = {
		num_divisions < 130
	}

	ai_strategy = {
		type = equipment_stockpile_surplus_ratio
		value = 35 # add this to default PRODUCTION_EQUIPMENT_SURPLUS_FACTOR
	}
}

default_produce_floating_harbors = {
	enable = {
		has_war = yes
		num_of_naval_factories > 24
		num_of_military_factories > 48
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = unit_ratio
		id = floating_harbor
		value = 10
	}
}

default_railway_gun_management = {
	enable = {
		num_divisions > 180
		is_major = yes
		has_dlc = "No Step Back"
	}
	abort = {
		num_divisions < 120
	}

	ai_strategy = {
		type = railway_gun_divisions_ratio
		value = 8
	}
}

default_sh_railway_gun_management = {
    enable = {
        num_divisions > 100
        #is_major = yes
        has_dlc = "No Step Back"
		is_special_project_completed = sp:sp_land_super_heavy_railway_gun
    }
    abort = {
		OR = {
			num_divisions < 90
		}
    }

    ai_strategy = { # This will add the specified value to the RAILWAY_GUN_PRODUCTION_BASE_DIVISIONS_RATIO_PERCENT define and use that as the desired railway guns / divisions ratio (in %)
        type = railway_gun_divisions_ratio
        value = 5
    }

    ai_strategy = {
        type = unit_ratio
        id = super_heavy_railway_gun
        value = 10
    }

    ai_strategy = {
        type = equipment_variant_production_factor
        id = super_heavy_railway_gun_equipment_1
        value = 10
    }
}


# Build some rockets (simple strats to have a minimum production at least )
if_we_can_build_v1_rockets_we_want_rockets = {
	enable = {
		is_special_project_completed = sp:sp_rockets_flying_bomb
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = equipment_production_min_factories_archetype 
		id = guided_missile_equipment
		value = 1
	}
}

if_we_can_build_v2_rockets_we_want_v2_rockets = {
	enable = {
		is_special_project_completed = sp:sp_rockets_ballistic_missile
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = equipment_production_min_factories_archetype 
		id = ballistic_missile_equipment
		value = 1
	}
}

if_we_can_build_sams_we_want_sams = {
	enable = {
		is_special_project_completed = sp:sp_rockets_ground_to_air_missile
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = equipment_production_min_factories_archetype 
		id = sam_missile_equipment
		value = 1
	}
}

if_we_can_build_nuclear_missiles_we_want_nuclear_missiles = {
	enable = {
		is_special_project_completed = sp:sp_nuclear_warheads
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = equipment_production_min_factories_archetype 
		id = nuclear_missile_equipment
		value = 1
	}
}


AI_build_no_mega_gun_emplacement = {
	enable = {
		always = yes
	}
	abort = {
		always = no
	}
	ai_strategy = {
		type = building_target
		id = mega_gun_emplacement
		value = -1000
	}
}

# INTELLIGENCE AGENCY
	build_intelligence_agency_as_major = {
		enable = {
			is_major = yes
			OR = {
				has_war = yes
			}
		}
		abort_when_not_enabled = yes

		ai_strategy = {
			type = intelligence_agency_usable_factories
			value = 5
		}
	}

	build_intelligence_agency = {
		enable = {
			has_war = no
			num_of_civilian_factories > 25
		}
		abort = {
			OR = {
				has_war = yes
				num_of_civilian_factories < 25
			}
		}

		ai_strategy = {
			type = intelligence_agency_usable_factories
			value = 5
		}
	}

	upgrade_intelligence_agency = {
		enable = {
			date > 1730.1.1
			num_of_civilian_factories > 50
		}
		abort = {
			OR = {
				num_of_civilian_factories < 40
			}
		}

		ai_strategy = {
			type = intelligence_agency_usable_factories
			value = 5
		}
	}

	upgrade_intelligence_agency_as_spy_master = {
		enable = {
			is_spymaster = yes
			OR = {
				has_war = no
				num_of_civilian_factories > 50
			}
		}
		abort = {
			is_spymaster = no
			num_of_civilian_factories < 40
		}

		ai_strategy = {
			type = intelligence_agency_usable_factories
			value = 10
		}
	}

	addintelligence_agency_normal_upgrade_prio = {
		enable = {
			always = yes
		}
		abort_when_not_enabled = yes

		ai_strategy = {
			type = intelligence_agency_branch_desire_factor
			id = branch_intelligence
			value = 1000
		}
		ai_strategy = {
			type = intelligence_agency_branch_desire_factor
			id = branch_defense
			value = 1000
		}
		ai_strategy = {
			type = intelligence_agency_branch_desire_factor
			id = branch_operation
			value = 500
		}
		ai_strategy = {
			type = intelligence_agency_branch_desire_factor
			id = branch_operative
			value = 100
		}
		ai_strategy = {
			type = intelligence_agency_branch_desire_factor
			id = branch_crypto
			value = 2000
		}	
	}

	more_upgrades_as_spymaster = {
		enable = {
			is_spymaster = yes
		}
		abort = {
			is_spymaster = no
		}

		ai_strategy = {
			type = agency_ai_base_num_factories_factor
			value = -50
		}

		ai_strategy = {
			type = agency_ai_per_upgrade_factories_factor
			value = -25
		}
	}
	
# SPECIAL PROJECT STRATEGIES
	minor_build_a_nl_facility = {
		enable = {
			has_tech = atomic_research
			num_of_civilian_factories > 25
			num_of_military_factories > 25 # Even if we have the base tech, let's wait until we have some kind of capacity
			nuclear_facility < 1  # one is enough
		}
		abort_when_not_enabled = yes
		ai_strategy = {
			type = build_building
			id = nuclear_facility
			value = 100
		}
	}

	minor_build_a_nav_facility = {
		enable = {
			num_of_naval_factories > 25 # Only Naval Powers should bother with these unless specifically told to do otherwise
			naval_facility < 1 # one is enough
		}
		abort_when_not_enabled = yes
		ai_strategy = {
			type = build_building
			id = naval_facility
			value = 100
		}
	}

	minor_build_a_lw_facility = {
		enable = {
			is_major = yes
			num_of_civilian_factories > 40
			num_of_military_factories > 40
			OR = { # Don't start until we can build decent tanks of some kind
				has_tech = improved_light_tank_chassis
				has_tech = basic_medium_tank_chassis
				has_tech = improved_heavy_tank_chassis
			}
			land_facility < 1 # one is enough
		}
		abort_when_not_enabled = yes
		ai_strategy = {
			type = build_building
			id = land_facility
			value = 100
		}
	}

	minor_build_an_air_facility = {
		enable = {
			is_major = yes # Minors don't bother until strong enough to be considered major
			num_of_military_factories > 40 # We should first build up our military industry 
			
			OR = { # Don't start until we can build decent aircraft
				has_tech = basic_small_airframe
				has_tech = basic_medium_airframe
				has_tech = basic_large_airframe
			}
			air_facility < 1 # one is enough
		}
		abort_when_not_enabled = yes
		ai_strategy = {
			type = build_building
			id = air_facility
			value = 100
		}
	}

	major_build_a_nl_facility = {
		enable = {
			has_tech = atomic_research
			num_of_civilian_factories > 50
			num_of_military_factories > 50 # Even if we have the base tech, let's wait until we have some kind of capacity
			nuclear_facility < 3  # one is enough
		}
		abort_when_not_enabled = yes
		ai_strategy = {
			type = build_building
			id = nuclear_facility
			value = 100
		}
	}

	major_build_a_nav_facility = {
		enable = {
			num_of_naval_factories > 50 # Only Naval Powers should bother with these unless specifically told to do otherwise
			naval_facility < 3 # one is enough
		}
		abort_when_not_enabled = yes
		ai_strategy = {
			type = build_building
			id = naval_facility
			value = 100
		}
	}

	major_build_a_lw_facility = {
		enable = {
			is_major = yes
			num_of_civilian_factories > 80
			num_of_military_factories > 80
			OR = { # Don't start until we can build decent tanks of some kind
				has_tech = improved_light_tank_chassis
				has_tech = basic_medium_tank_chassis
				has_tech = improved_heavy_tank_chassis
			}
			land_facility < 3 # one is enough
		}
		abort_when_not_enabled = yes
		ai_strategy = {
			type = build_building
			id = land_facility
			value = 100
		}
	}

	major_build_an_air_facility = {
		enable = {
			is_major = yes # Minors don't bother until strong enough to be considered major
			num_of_military_factories > 80 # We should first build up our military industry 
			OR = { # Don't start until we can build decent aircraft
				has_tech = basic_small_airframe
				has_tech = basic_medium_airframe
				has_tech = basic_large_airframe
			}
			air_facility < 3 # one is enough
		}
		abort_when_not_enabled = yes
		ai_strategy = {
			type = build_building
			id = air_facility
			value = 100
		}
	}

	default_recruit_land_scientist = {
		enable = {
			land_facility > 0
		}
		abort_when_not_enabled = yes
		ai_strategy = {
			type = recruit_scientist
			id = specialization_land
			value = 100
		}
	}

	default_recruit_nuclear_scientist = {
		enable = {
			nuclear_facility > 0
		}
		abort_when_not_enabled = yes
		ai_strategy = {
			type = recruit_scientist
			id = specialization_nuclear
			value = 100
		}
	}

	default_recruit_naval_scientist = {
		enable = {
			naval_facility > 0
		}
		abort_when_not_enabled = yes
		ai_strategy = {
			type = recruit_scientist
			id = specialization_naval
			value = 100
		}
	}

	default_recruit_air_scientist = {
		enable = {
			air_facility > 0
		}
		abort_when_not_enabled = yes
		ai_strategy = {
			type = recruit_scientist
			id = specialization_air
			value = 100
		}
	}