

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
		GER = { 
			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 = 0.8
		states = {
			10
			88
			90
		}
		area = europe
		subtract_invasions_from_need = no
		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.8
		is_historical_focus_on = yes
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = put_unit_buffers
		ratio = 2
		states = {
			107
		}
		area = europe
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}

}

minor_prep_for_war_against_player = {
	enable = { 
		difficulty > 1
		AND = {
			OR = {
				original_tag = PER
				original_tag = IRQ
				original_tag = AFG
			}
			num_divisions < 60	
		}
		is_historical_focus_on = yes
		OR = {
			SOV = { is_ai = no }
			ENG = { is_ai = no }
			GER = { is_ai = no }
		}
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
       		type = force_build_armies
        	value = 300
    	}
}
minor_prep_for_war_nonhist = {
	enable = { 
		difficulty > 1
		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
				original_tag = LUX
			}
			num_divisions < 30	
		}
		is_historical_focus_on = no
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
       		type = force_build_armies
        	value = 300
    	}
}
super_axis_minor_prep_for_war = {
	enable = { 
		difficulty > 1
		AND = {
			OR = {
				original_tag = ITA
				original_tag = BUL
				original_tag = VIC
			}
			num_divisions < 150	
		}
		is_historical_focus_on = yes
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
       		type = force_build_armies
        	value = 300
    	}
}
minor_prep_for_war_against_axis = {
	enable = { 
		difficulty > 1
		OR  = {
			AND = {
				OR = {
					GER = { is_ai = no }
					ITA = { is_ai = no }
					JAP = { is_ai = no }
				}
			}
			has_global_flag = mp_difficulty
		}
		AND = {
			OR = {
				AND = {
					original_tag = POL
					NOT = { has_global_flag = allies_mainland_withdrawal }
				}
				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 = PER
				original_tag = AFG
				original_tag = IRQ
				original_tag = TUR
				original_tag = LUX
			}
			OR = {
				has_global_flag = mp_difficulty
				num_divisions < 200
				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_war_against_allies = {
	enable = { 
		difficulty > 1
		OR  = {
			AND = {
				OR = {
					ENG = { is_ai = no }
					SOV = { is_ai = no }
					USA = { is_ai = no }
					FRA = { is_ai = no }
				}
			}
			has_global_flag = mp_difficulty
		}
		AND = {
			OR = {
				original_tag = LIT
				original_tag = LAT
				original_tag = EST
				original_tag = FIN
				original_tag = SIA
				original_tag = AOI
				original_tag = LBA
			}
			OR = {
				has_global_flag = mp_difficulty
				num_divisions < 80
			}	
		}
		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
    	}
}
nubir_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
		num_of_military_factories < 50
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = role_ratio
		id = armor
		value = -80
	}

	ai_strategy = {
		type = role_ratio
		id = infantry
		value = 80
	}

	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
		num_of_military_factories < 30
	}	
	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_no_aifc = {
	enable = {
		is_historical_focus_on = yes
		is_ai_mass_mob = yes
		has_war = no
	}

	abort_when_not_enabled = yes


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

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 = {
				original_tag = RAJ
				has_manpower < 2000000
				has_equipment = { infantry_equipment < 50000 }
			}
		}
		OR = {
			has_war = no
			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 }
				NOT = {
					AND = {
						original_tag = RAJ
						OR = {
							has_manpower < 2000000
							has_equipment = { infantry_equipment < 50000 }
						}
					}
				}
			}
			enemies_strength_ratio < 1.0
		}
	}


	ai_strategy = {
		type = force_concentration_factor
		value = -100
	}

	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
		SOV = { is_ai = no }
		has_army_manpower = { size > 50000 }
		has_equipment = { infantry_equipment > 5000 }
		OR = {
			winter_months_are_so_peak = yes
			AND = {
				GER = { has_idea = GER_barbarossa }
				has_country_flag = FIN_pact_for_continuation_war_flag
			}
		}
		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
				AND = {
					is_owned_by = SOV
					any_neighbor_state = {
						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 }
			}
			AND = {
				original_tag = FIN
				has_country_flag = FIN_pact_for_continuation_war_flag
				GER = { has_idea = GER_barbarossa }
				SOV = { is_ai = no }
			}
		}
	}

	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
		is_ai_mass_mob = yes
		is_ai_amtrac = no
	}

	abort = {
		always = no
	}

	ai_strategy = {
		type = role_ratio
		id = armor
		value = -50
	}

	ai_strategy = {
		type = role_ratio
		id = paratroopers
		value = -50
	}

	ai_strategy = {
		type = role_ratio
		id = infantry
		value = 100
	}
}
axis_mass_mob_ai_focus_on_infantry_defense = {
	enable = {
		is_historical_focus_on = yes
		OR = {
			is_ai_mech_mob = yes
			AND = {
				is_ai_mass_mob = yes
				is_ai_amtrac = yes
			}
		}
	}

	abort = {
		always = no
	}

	ai_strategy = {
		type = role_ratio
		id = armor
		value = -50
	}

	ai_strategy = {
		type = role_ratio
		id = paratroopers
		value = -50
	}

	ai_strategy = {
		type = role_ratio
		id = marines
		value = 100
	}
}
ai_minor_tank_only = {
	enable = {
		is_ai_tank_minor = yes
		is_historical_focus_on = yes
	}

	abort_when_not_enabled = yes
	
	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 = garrison
   		value = -9999
   	}

}

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

	abort = {
		OR = {
			date > 1940.6.1
			has_global_flag = allies_mainland_withdrawal
			surrender_progress > 0.8
		}
	}
	ai_strategy = {
		type = put_unit_buffers
		# core states
		states = {
			7
			35
		}
		ratio = 2
		area = europe
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
}

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

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

	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 = {
		check_if_is_allied_historical = yes
		OR = {
			any_country = {
				has_war_with = ROOT
				is_ai = no
			}
			AND = {
				GER = { is_ai = no }
				is_historical_focus_on = yes
			}
			AND = {
				FRA = { is_ai = no }	
				has_global_flag = mp_selected
			}
		}
		is_major = yes
		OR = {
			has_war_with = GER
			AND = {
				OR = {
					GER = { is_ai = no }
					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 }
			has_global_flag = allies_mainland_withdrawal
		}
	}
	ai_strategy = {
		type = front_unit_request
		state_trigger = { 
			is_on_continent = europe
			OR = {
				is_core_of = GER
			}
		}
		value = -10
	}
	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 = no
		subtract_fronts_from_need = no
	}

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

allies_benelux_race = {
	enable = {
		check_if_is_allied_historical = yes
		check_if_minor_tag_applies_2 = yes
		OR = {
			any_country = {
				has_war_with = ROOT
				is_major = yes
				is_ai = no
			}
			AND = {
				GER = { is_ai = no }
				is_historical_focus_on = yes
			}
			AND = {
				FRA = { is_ai = no }	
				has_global_flag = mp_selected
			}
		}
	}

	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.2 }
				NOT = { FRA = { has_country_flag = paradrop_grace } }
			}
			NOT = { country_exists = BEL }
			has_global_flag = allies_mainland_withdrawal
		}
	}
	ai_strategy = {
		type = put_unit_buffers
		# french states bordering benelux
		states = {
			29
			785
			18
			15
			16
		}
		ratio = 0.85
		area = europe
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}

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

allies_benelux_race_2 = {
	enable = {
		check_if_is_allied_historical = yes
		check_if_all_tag_applies = yes
		OR = {
			any_country = {
				has_war_with = ROOT
				is_ai = no
			}
			AND = {
				GER = { is_ai = no }
				is_historical_focus_on = yes
			}
			AND = {
				FRA = { is_ai = no }	
				has_global_flag = mp_selected
			}
		}
		GER = { has_war_with = BEL }
	}

	abort = {
		OR = {
			date_check_benelux_1 = yes
			date_check_benelux_2 = yes
			has_global_flag = allies_mainland_withdrawal
			foreign_countries_have_surrender_progress = yes
		}
	}

	ai_strategy = {
		type = force_defend_ally_borders
		value = 9999
		target = mainland_europe
	}
	ai_strategy = {
		type = area_priority
		id = mainland_europe
		value = 200
	}
	ai_strategy = {
		type = area_priority
		id = asia
		value = -200
	}
	ai_strategy = {
		type = area_priority
		id = north_america
		value = -200
	}
	ai_strategy = {
		type = front_unit_request
		state_trigger = {
			OR = {
				is_core_of = BEL
				is_core_of = FRA
				any_neighbor_state = {
					is_core_of = BEL
				}
				any_neighbor_state = {
					is_core_of = FRA
				}
			}
		}
		area = mainland_europe		
		value = 35
	}
	ai_strategy = {
  		type = garrison
   		value = -9999
   	}
}
allies_benelux_race_hold_fra = {
	enable = {
		check_if_is_allied_historical = yes
		tag = FRA
		OR = {
			any_country = {
				has_war_with = ROOT
				is_major = yes
				is_ai = no
			}
			AND = {
				GER = { is_ai = no }
				is_historical_focus_on = yes
			}
			AND = {
				FRA = { is_ai = no }	
				has_global_flag = mp_selected
			}
		}
	}

	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.2 }
				NOT = { FRA = { has_country_flag = paradrop_grace } }
			}
			NOT = { country_exists = BEL }
			has_global_flag = allies_mainland_withdrawal
			GER = { surrender_progress > 0.02 }
		}
	}
	ai_strategy = {
		type = put_unit_buffers
		# french states bordering benelux
		states = {
			29
			785
			18
			15
			16
		}
		ratio = 0.3
		area = europe
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}

	ai_strategy = {
  		type = garrison
   		value = -100
   	}
}
allies_benelux_race_fra = {
	enable = {
		check_if_is_allied_historical = yes
		check_if_fra_tag_applies = yes
		OR = {
			any_country = {
				has_war_with = ROOT
				is_ai = no
			}
			AND = {
				OR = {
					GER = { is_ai = no }
				}
				is_historical_focus_on = yes
			}
			AND = {
				FRA = { is_ai = no }	
				has_global_flag = mp_selected
			}
		}
		GER = { has_war_with = BEL }
	}

	abort = {
		OR = {
			date_check_benelux_1 = yes
			date_check_benelux_2 = yes
			has_global_flag = allies_mainland_withdrawal
		}
	}
	ai_strategy = {
		type = area_priority
		id = mainland_europe
		value = 50
	}
	ai_strategy = {
		type = area_priority
		id = asia
		value = -200
	}
	ai_strategy = {
		type = area_priority
		id = north_america
		value = -200
	}
	ai_strategy = {
		type = front_unit_request
		state_trigger = {
			OR = {
				is_core_of = BEL
				is_core_of = FRA
				any_neighbor_state = {
					is_core_of = BEL
				}
				any_neighbor_state = {
					is_core_of = FRA
				}
			}
		}
		area = mainland_europe		
		value = 15
	}
	ai_strategy = {
  		type = garrison
   		value = -9999
   	}
}
allies_benelux_race_hold_eng = {
	enable = {
		check_if_is_allied_historical = yes
		tag = ENG
		OR = {
			any_country = {
				has_war_with = ROOT
				is_major = yes
				is_ai = no
			}
			AND = {
				OR = {
					GER = { is_ai = no }
					AND = {
						ITA = { is_ai = no }
						has_global_flag = mp_difficulty 
					}
				}
				is_historical_focus_on = yes
			}
			AND = {
				FRA = { is_ai = no }	
				has_global_flag = mp_selected
			}
		}
	}

	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.2 }
				NOT = { FRA = { has_country_flag = paradrop_grace } }
			}
			NOT = { country_exists = BEL }
			has_global_flag = allies_mainland_withdrawal
			GER = { surrender_progress > 0.02 }
		}
	}
	ai_strategy = {
		type = put_unit_buffers
		# french states bordering benelux
		states = {
			29
			785
			18
			15
			16
		}
		ratio = 0.3
		area = europe
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}

	ai_strategy = {
  		type = garrison
   		value = -100
   	}
}
allies_benelux_race_eng = {
	enable = {
		check_if_is_allied_historical = yes
		tag = ENG
		OR = {
			any_country = {
				has_war_with = ROOT
				is_ai = no
			}
			AND = {
				OR = {
					GER = { is_ai = no }
					AND = {
						ITA = { is_ai = no }
						has_global_flag = mp_difficulty
						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
			}
		}
		GER = { has_war_with = BEL }
	}

	abort = {
		OR = {
			date_check_benelux_1 = yes
			date_check_benelux_2 = yes
			has_global_flag = allies_mainland_withdrawal
			foreign_countries_have_surrender_progress = yes
		}
	}

	ai_strategy = {
		type = force_defend_ally_borders
		value = 9999
		target = mainland_europe
	}

	ai_strategy = {
		type = area_priority
		id = mainland_europe
		value = 200
	}
	ai_strategy = {
		type = area_priority
		id = asia
		value = -200
	}
	ai_strategy = {
		type = area_priority
		id = north_america
		value = -200
	}
	ai_strategy = {
		type = front_unit_request
		state_trigger = {
			OR = {
				is_core_of = BEL
				is_core_of = FRA
				any_neighbor_state = {
					is_core_of = BEL
				}
				any_neighbor_state = {
					is_core_of = FRA
				}
			}
		}
		area = mainland_europe		
		value = 35
	}

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

allies_benelux_race_the_french_gambit = {
	enable = {
		is_in_faction_with = ENG
		is_in_faction_with = FRA
		FRA = { surrender_progress > 0.01 }
		FRA = { surrender_progress < 0.30 }
		OR = {
			any_country = {
				has_war_with = ROOT
				is_ai = no
			}
			AND = {
				OR = {
					GER = { is_ai = no }
					AND = {
						ITA = { is_ai = no }
						has_global_flag = mp_difficulty
						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
			}
		}
	}

	abort = {
		OR = {
			date_check_benelux_1 = yes
			date_check_benelux_2 = yes
			has_global_flag = allies_mainland_withdrawal
		}
	}
	ai_strategy = {
		type = front_unit_request
		state_trigger = {
			is_core_of = FRA
			NOT = { is_fully_controlled_by = FRA }
			is_on_continent = europe 
		}
		area = mainland_europe
		value = 35
	}
}

