

minor_count_til_10 = {
	enable = {
		is_major = no
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = building_target
		id = arms_factory
		value = 10
	}
}

POL_count_til_die = {
	enable = {
		is_ai_mass_mob = yes
		tag = POL
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = building_target
		id = arms_factory
		value = 30
	}
}

POL_hug_your_cities = {
	enable = {
		tag = POL
		OR = {
			GER = { 
				NOT = { surrender_progress > 0 } 
				is_ai = no 
			}
			ITA = { 
				NOT = { surrender_progress > 0 } 
				is_ai = no 
			}
		}
		surrender_progress < 0.5
		is_historical_focus_on = yes
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = put_unit_buffers

		# ratio of total armeis in country to be buffered
		ratio = 0.5

		# you can specify an order id. ratio of same orders ids will be share same ratio
		#order_id = 2

		# states to put garrison orders (if no state is friendly, strat is invalid)
		states = {
			10
			88
			90
		}

		# ai areas that the orders will use these buffers in
		area = europe

		# by default if you have orders in target areas, the buffer will request less units.
		# you can override this to disable the feature
		subtract_invasions_from_need = yes
		subtract_fronts_from_need = no
	}

}

YUG_hug_your_cities = {
	enable = {
		tag = YUG
		OR = {
			GER = { 
				NOT = { surrender_progress > 0 } 
				is_ai = no 
			}
			ITA = { 
				NOT = { surrender_progress > 0 } 
				is_ai = no 
			}
		}
		surrender_progress < 0.7
		is_historical_focus_on = yes
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = put_unit_buffers

		# ratio of total armeis in country to be buffered
		ratio = 0.5

		# you can specify an order id. ratio of same orders ids will be share same ratio
		#order_id = 2

		# states to put garrison orders (if no state is friendly, strat is invalid)
		states = {
			107
		}

		# ai areas that the orders will use these buffers in
		area = europe

		# by default if you have orders in target areas, the buffer will request less units.
		# you can override this to disable the feature
		subtract_invasions_from_need = yes
		subtract_fronts_from_need = no
	}

}

minor_prep_for_war = {
	enable = { 
		difficulty > 1
		OR  = {
			AND = {
				SOV = { is_ai = yes }
				OR = {
					GER = { is_ai = no }
					ITA = { is_ai = no }
				}
			}
			has_global_flag = mp_difficulty
		}
		AND = {
			OR = {
				original_tag = POL
				original_tag = BEL
				original_tag = HOL
				original_tag = GRE
				original_tag = YUG
				original_tag = SAF
				original_tag = CAN
				original_tag = RAJ
				original_tag = PHI
				original_tag = MAL
				original_tag = INS
				original_tag = LIT
				original_tag = LAT
				original_tag = EST
				original_tag = FIN
				original_tag = SIA
				original_tag = AOI
			}
			OR = {
				has_global_flag = mp_difficulty
				num_divisions < 80
				AND = {
					tag = POL
					OR = {
						GER = { is_ai = no }
						ITA = { is_ai = no }
					}
				}
				AND = {
					tag = YUG
					OR = {
						GER = { is_ai = no }
						ITA = { is_ai = no }
					}
				}
			}	
		}
		has_war = no
		NOT = { has_global_flag = vanilla_history }
		is_historical_focus_on = yes
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
       		type = force_build_armies
        	value = 300
    	}
}

minor_prep_for_wartime_capped = {
	enable = { 
		is_in_faction = yes
		has_capitulated = yes
		has_army_manpower = { size < 100000 }
		has_manpower > 100000
		has_war = yes
		is_historical_focus_on = yes
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
       		type = force_build_armies
        	value = 50
    	}
}
POL_more_men_is_good = {
	allowed = {
		OR = {
			original_tag = POL
			original_tag = FIN
			original_tag = RAJ
			original_tag = CHI
			original_tag = GXC
		}
	}
	enable = {
		has_war = no
		NOT = { has_global_flag = vanilla_history }
		is_historical_focus_on = yes
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
       		type = force_build_armies
        	value = 300
    	}

	ai_strategy = {
		type = ai_wanted_divisions_factor
		value = 500
	}
}

BRA_prep_for_war = {
	allowed = {
		OR = {
			original_tag = BRA
			original_tag = ARG
			original_tag = URG
			original_tag = CHL
		}
	}
	enable = {
		has_war = no
		has_tech = mechanised_infantry
		is_historical_focus_on = yes
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
       		type = force_build_armies
        	value = 500
    	}

	ai_strategy = {
		type = ai_wanted_divisions_factor
		value = 300
	}
}

AI_mech_does_mech = {

	enable = {
		OR = {
			is_ai_mech_mob = yes
			AND = {
				is_ai_mass_mob = yes
				is_allied_ai = yes
			}
		}
		is_major = no
		NOT = { is_in_faction_with = GER }
		NOT = { any_neighbor_country = { is_ai = no } }
		has_dlc = "By Blood Alone"
		is_historical_focus_on = yes
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = air_factory_balance
		value = 0
	}

	ai_strategy = {
		type = unit_ratio
		id = fighter
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = fighter
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = cas
		value = -999 
	}

	ai_strategy = {
		type = equipment_production_factor
		id = fighter
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = tactical_bomber
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = tactical_bomber
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = strategic_bomber
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = strategic_bomber
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = cv_fighter
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = cv_fighter
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = cv_cas
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = cv_cas
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = cv_naval_bomber
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = cv_naval_bomber
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = naval_bomber
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = naval_bomber
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = heavy_fighter
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = heavy_fighter
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = scout_plane 
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = scout_plane 
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = maritime_patrol_plane
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = maritime_patrol_plane
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = air_transport
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = air_transport
		value = -999
	}

}


AI_mass_mob_handle_infantry = {

	enable = {
		is_ai_mass_mob = yes
		is_in_faction_with = GER
		OR = {
			is_major = no
			tag = BUL
		}
		OR = {
			NOT = { has_tech = improved_small_airframe }
			NOT = { has_tech = engines_3 }
			NOT = { has_tech = aa_hmg }
		}
		has_dlc = "By Blood Alone"
		is_historical_focus_on = yes
	}	
	abort_when_not_enabled = yes

	ai_strategy = {
		type = air_factory_balance
		value = 0
	}

	ai_strategy = {
		type = unit_ratio
		id = fighter
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = fighter
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = cas
		value = -999 
	}

	ai_strategy = {
		type = equipment_production_factor
		id = fighter
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = tactical_bomber
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = tactical_bomber
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = strategic_bomber
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = strategic_bomber
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = cv_fighter
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = cv_fighter
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = cv_cas
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = cv_cas
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = cv_naval_bomber
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = cv_naval_bomber
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = naval_bomber
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = naval_bomber
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = heavy_fighter
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = heavy_fighter
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = scout_plane 
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = scout_plane 
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = maritime_patrol_plane
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = maritime_patrol_plane
		value = -999
	}

	ai_strategy = {
		type = unit_ratio
		id = air_transport
		value = -999
	}

	ai_strategy = {
		type = equipment_production_factor
		id = air_transport
		value = -999
	}

}

mass_mob_ai_focus_on_defense = {
	enable = {
		is_historical_focus_on = yes
		is_ai_mass_mob = yes
		might_need_to_have_aggro = no
		OR = {
			has_manpower < 1000000
			has_army_manpower = { size < 1000000 }
		}
		AND = {
			has_war = yes
			enemies_strength_ratio > 1.2
		}
	}

	abort = {
		OR = {
			is_historical_focus_on = no
			might_need_to_have_aggro = yes
			AND = {
				has_manpower > 1500000
				has_army_manpower = { size > 1500000 }
			}
			enemies_strength_ratio < 1.0
		}
	}

	ai_strategy = {
		type = front_control

		country_trigger = {
			NOT = { tag = SOV }
			is_major = yes
		}

		ratio = 0.3

		priority = 100
		ordertype = front
		execution_type = careful
		execute_order = no
	}
}


mass_mob_ai_i_am_finland = {
	enable = {
		is_historical_focus_on = yes
		is_ai_mass_mob = yes
		tag = FIN
		date > 1940.1.1
		has_army_manpower = { size > 100000 }
		has_equipment = { infantry_equipment > 10000 }
		check_variable = {
			num_divisions > 50
		}
		winter_months_are_so_peak = yes
		has_war_with = SOV
		SOV = { has_war_with = GER }
		GER = { surrender_progress < 0.1 }
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = front_control

		state_trigger = {
			OR = {
				is_core_of = FIN
				is_claimed_by = FIN
			}
		}

		ratio = 0.3

		priority = 1000
		ordertype = front
		execution_type = balanced
		execute_order = yes
	}
}
mass_mob_ai_focus_on_defense_SOV = {
	enable = {
		is_historical_focus_on = yes
		OR = {
			is_ai_mass_mob = yes
			original_tag = ITA
			original_tag = BUL
		}
		OR = {
			has_manpower < 1200000
			has_army_manpower = { size < 1200000 }
		}
	}

	abort = {
		OR = {
			is_historical_focus_on = no
			AND = {
				has_manpower > 1800000
				has_army_manpower = { size > 1800000 }
			}
			AND = {
				has_idea = anti_soviet_pact
				has_manpower > 120000
				has_equipment = { infantry_equipment > 10000 }
			}
			AND = {
				is_in_faction_with = GER
				GER = { has_idea = GER_barbarossa }
				has_equipment = { infantry_equipment > 1000 }
			}
		}
	}

	ai_strategy = {
		type = front_control

		tag = SOV

		ratio = 0.3

		priority = 100
		ordertype = front
		execution_type = careful
		execute_order = no
	}
}


mech_mob_ai_focus_on_defense = {
	allowed = {
		OR = {
			is_ai_mech_mob = yes
		}
	}
	enable = {
		is_historical_focus_on = yes
		OR = {
			has_manpower < 500000
			has_army_manpower = { size < 500000 }
		}
	}

	abort = {
		OR = {
			is_historical_focus_on = no
			AND = {
				has_manpower > 1000000
				has_army_manpower = { size > 1000000 }
			}
		}
	}

	ai_strategy = {
		type = front_control

		country_trigger = {
			NOT = { tag = SOV }
			is_major = yes
		}

		ratio = 0.3

		priority = 100
		ordertype = front
		execution_type = careful
	}

	ai_strategy = {
		type = front_control

		tag = SOV

		ratio = 0.3

		priority = 100
		ordertype = front
		execution_type = careful
	}
}

axis_mass_mob_ai_focus_on_infantry_defense = {
	enable = {
		is_historical_focus_on = yes
		OR = {
			is_ai_mass_mob = yes
			is_ai_mech_mob = yes
		}
	}

	abort = {
		always = no
	}

	ai_strategy = {
		type = build_army
		id = armor
		value = -25
	}

	ai_strategy = {
		type = build_army
		id = paratroopers
		value = -25
	}
}
ai_minor_tank_only = {
	allowed = {
		is_ai_tank_minor = yes
	}
	enable = { 
		has_global_flag = AI_is_done
		is_historical_focus_on = yes
		OR = {
			has_war = yes
			date > 1940.1.1
		}
		has_equipment = { heavy_tank_destroyer_chassis > -50 }
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = build_army
		id = armor
		value = 20
	}

	ai_strategy = {
		type = build_army
		id = infantry
		value = -300
	}
	
	ai_strategy = {
		type = role_ratio #even more tanks
		id = armor
		value = 100
	}
	
	ai_strategy = {
		type = role_ratio #even more tanks
		id = infantry
		value = -30
	}

	ai_strategy = {
		type = build_army
		id = paratroopers
		value = -500
	}

	ai_strategy = {
		type = build_army
		id = mountaineers
		value = -500
	}


}
ai_minor_tank_only2 = {
	allowed = {
		is_ai_tank_minor = yes
	}
	enable = { 
		has_global_flag = AI_is_done
		is_historical_focus_on = yes
		OR = {
			has_war = yes
			date > 1940.1.1
		}
		has_equipment = { heavy_tank_destroyer_chassis < -50 }
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = build_army
		id = armor
		value = -300
	}

	ai_strategy = {
		type = build_army
		id = infantry
		value = -300
	}
}

ai_minor_tank_only_peace = {
	allowed = {
		is_ai_tank_minor = yes
	}
	enable = { 
		has_global_flag = AI_is_done
		is_historical_focus_on = yes
		has_war = no
		date < 1940.1.1
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = build_army
		id = armor
		value = -300
	}

	ai_strategy = {
		type = build_army
		id = infantry
		value = -300
	}
}



HOL_trouble_is_coming = {
	allowed = { original_tag = HOL }
	enable = {
		is_historical_focus_on = yes
		SOV = { is_ai = yes }
		has_global_flag = mp_difficulty
		NOT = { has_global_flag = vanilla_history }
	}

	abort = {
		date > 1940.6.1
	}
	ai_strategy = {
		type = put_unit_buffers
		# core states
		states = {
			7
			35
		}
		ratio = 1
		area = europe
		subtract_invasions_from_need = yes
		subtract_fronts_from_need = yes
	}
}

BEL_trouble_is_coming = {
	allowed = { original_tag = BEL }
	enable = {
		is_historical_focus_on = yes
		SOV = { is_ai = yes }
		has_global_flag = mp_difficulty
		NOT = { has_global_flag = vanilla_history }
	}

	abort = {
		OR = {
			has_war = yes
			date > 1941.1.1
		}
	}

	ai_strategy = {
		type = prepare_for_war
		id = GER
		value = 200
	}

	ai_strategy = {
		type = prepare_for_war
		id = HOL #guard the Benelux borders
		value = 200
	}
	
}

allies_benelux_race_major = {
	enable = {
		is_historical_focus_on = yes
		is_in_faction_with = FRA
		is_in_faction_with = ENG
		NOT = { 
			OR = {
				tag = SAF
				tag = NZL
			}
		}
		OR = {
			any_country = {
				has_war_with = ROOT
				is_ai = no
			}
			AND = {
				OR = {
					GER = { is_ai = no }
					ITA = { is_ai = no }
				}
				is_historical_focus_on = yes
			}
			AND = {
				FRA = { is_ai = no }	
				has_global_flag = mp_selected
			}
		}
		NOT = { has_global_flag = vanilla_history }
		SOV = { is_ai = yes }
		has_global_flag = mp_difficulty
		is_major = yes
		OR = {
			has_war_with = GER
			AND = {
				OR = {
					GER = { is_ai = no }
					FRA = { is_ai = no }
					AND = {
						ITA = { is_ai = no }
						ITA = { has_government = fascism }
						NOT = { ITA = { is_in_faction_with = ENG } }
					}
				}
				GER = { has_government = fascism }
			}
		}
		NOT = { 
			any_country = {
				original_tag = GER
				has_war_with = BEL
			}
		}
		NOT = { 
			any_country = {
				original_tag = GER
				is_in_faction_with = ROOT 
			}
		}
	}

	abort = {
		OR = {
			AND = {
				is_in_faction_with = BEL
				GER = { has_war_with = BEL }
			}
			any_country = {
				original_tag = GER
				is_in_faction_with = ROOT 
			}
			has_country_flag = era_of_transition
			AND = {
				FRA = { surrender_progress > 0.1 }
				NOT = { FRA = { has_country_flag = paradrop_grace } }
			}
			NOT = { country_exists = BEL }
		}
	}
	ai_strategy = {
		type = front_unit_request
		state_trigger = { 
			is_on_continent = europe
			OR = {
				is_core_of = GER
			}
		}
		value = -25
	}
	ai_strategy = {
		type = front_unit_request
		state_trigger = { 
			is_on_continent = europe
			OR = {
				is_core_of = BEL
				is_core_of = LUX
			}
		}
		value = 25
	}
	ai_strategy = {
		type = put_unit_buffers
		# french states bordering benelux
		states = {
			29
			785
			18
			15
			16
		}
		ratio = 0.25
		area = europe
		subtract_invasions_from_need = yes
		subtract_fronts_from_need = yes
	}

	ai_strategy = {
  		type = garrison
   		value = -100
   	}
}

allies_benelux_race = {
	enable = {
		is_in_faction_with = FRA
		is_in_faction_with = ENG
		NOT = { 
			OR = {
				tag = SAF
				tag = NZL
			}
		}
		OR = {
			any_country = {
				has_war_with = ROOT
				is_ai = no
			}
			AND = {
				OR = {
					GER = { is_ai = no }
					ITA = { is_ai = no }
				}
				is_historical_focus_on = yes
			}
			AND = {
				FRA = { is_ai = no }	
				has_global_flag = mp_selected
			}
		}
		NOT = { has_global_flag = vanilla_history }
		SOV = { is_ai = yes }
		has_global_flag = mp_difficulty
		is_historical_focus_on = yes
		is_major = no
		OR = {
			has_war_with = GER
			AND = {
				OR = {
					GER = { is_ai = no }
					AND = {
						has_global_flag = mp_selected
						FRA = { is_ai = no }
					}
				}
				GER = { has_government = fascism }
			}
		}
		NOT = { 
			any_country = {
				original_tag = GER
				has_war_with = BEL
			}
		}
		NOT = { 
			any_country = {
				original_tag = GER
				is_in_faction_with = ROOT 
			}
		}
	}

	abort = {
		OR = {
			AND = {
				is_in_faction_with = BEL
				GER = { has_war_with = BEL }
			}
			any_country = {
				original_tag = GER
				is_in_faction_with = ROOT 
			}
			has_country_flag = era_of_transition
			AND = {
				FRA = { surrender_progress > 0.1 }
				NOT = { FRA = { has_country_flag = paradrop_grace } }
			}
			NOT = { country_exists = BEL }
		}
	}
	ai_strategy = {
		type = put_unit_buffers
		# french states bordering benelux
		states = {
			29
			785
			18
			15
			16
		}
		ratio = 0.8
		area = europe
		subtract_invasions_from_need = yes
		subtract_fronts_from_need = yes
	}

	ai_strategy = {
  		type = garrison
   		value = -100
   	}
}

allies_benelux_race_2 = {
	enable = {
		is_historical_focus_on = yes
		is_in_faction_with = FRA
		is_in_faction_with = ENG
		NOT = { 
			OR = {
				tag = SAF
				tag = NZL
			}
		}
		NOT = { has_global_flag = vanilla_history }
		SOV = { is_ai = yes }
		has_global_flag = mp_difficulty
		OR = {
			any_country = {
				has_war_with = ROOT
				is_ai = no
			}
			AND = {
				OR = {
					GER = { is_ai = no }
					AND = {
						ITA = { is_ai = no }
						ITA = { has_government = fascism }
						NOT = { ITA = { is_in_faction_with = ENG } }
					}
				}
				is_historical_focus_on = yes
			}
			AND = {
				FRA = { is_ai = no }	
				has_global_flag = mp_selected
			}
		}
		is_major = no
		has_war_with = GER
		GER = { has_war_with = BEL }
	}

	abort = {
		OR = {
			AND = {
				date > 1940.6.1
				NOT = { capital_scope = { is_on_continent = europe } }
				NOT = { capital_scope = { is_on_continent = south_america } }
				NOT = { capital_scope = { is_on_continent = north_america } }
				NOT = { capital_scope = { is_on_continent = africa } }
			}
			AND = {
				FRA = { surrender_progress > 0.2 }
				NOT = { FRA = { has_country_flag = paradrop_grace } }
			}
			has_war_with = JAP
			AND = {
				FRA = { surrender_progress < 0.05 }
				ENG = { surrender_progress > 0.15 }
			}
			NOT = {
				any_country = {
					capital_scope = { is_on_continent = europe }
					has_war_with = ENG
					is_major = yes
					has_capitulated = no
				}
			}
		}
	}

	ai_strategy = {
		type = force_defend_ally_borders
		value = 200
		target = europe
	}

	ai_strategy = {
		type = area_priority
		id = europe
		value = 500
	}
	ai_strategy = {
		type = front_unit_request
		state_trigger = { 
			is_on_continent = europe
			OR = {
				is_core_of = HOL
				is_core_of = BEL
				is_core_of = LUX
				is_core_of = FRA
			}
		}
		value = 25
	}
	ai_strategy = {
		type = front_unit_request
		state_trigger = { 
			is_on_continent = europe
			OR = {
				is_core_of = ITA
			}
		}
		value = 25
	}

	ai_strategy = {
		type = force_defend_ally_borders
		value = 200
		id = "FRA"
	}

	ai_strategy = {
		type = force_defend_ally_borders
		value = 200
		id = "HOL"
	}

	ai_strategy = {
		type = force_defend_ally_borders
		value = 200
		id = "BEL"
	}

	ai_strategy = {
  		type = garrison
   		value = -200
   	}
}

