# befriend
# conquer
# antagonize
# build_ship
# build_army
# unit_ratio
# build_building
# research_tech
# garrison
# protect
# influence

ENG_unit_production = {

	allowed = {	original_tag = ENG }
	enable = {
		always = yes
	}
	abort = {
		always = no
	}

	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 7
	}

	# Old garrison system against resistance
	# ai_strategy = {
	# 	type = role_ratio
	# 	id = suppression
	# 	value = 1
	# }


	ai_strategy = {
		type = role_ratio
		id = paratroopers
		value = 0
	}

	ai_strategy = {
		type = role_ratio
		id = mountaineers
		value = 0
	}

	ai_strategy = {
		type = role_ratio
		id = marines
		value = 5
	}

	ai_strategy = {
		type = role_ratio
		id = cavalry
		value = 0
	}

	ai_strategy = {
		type = role_ratio
		id = armor
		value = 5
	}

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

	# Naval unit factors
	ai_strategy = {
		type = unit_ratio
		id = capital_ship
		value = 20
	}

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

	ai_strategy = {
		type = unit_ratio
		id = submarine
		value = 5
	}

	ai_strategy = {
		type = unit_ratio
		id = screen_ship
		value = 55
	}

	ai_strategy = {
		type = unit_ratio
		id = convoy
		value = 100
	}

	ai_strategy = {
		type = equipment_production_factor
		id = infantry
		value = 10
	}

	ai_strategy = {
		type = equipment_production_factor
		id = artillery
		value = 45
	}

	ai_strategy = {
		type = equipment_production_factor
		id = armor
		value = 10
	}

}

ENG_bomber_production = {
	allowed = {
		original_tag = ENG
	}
	enable = {
		num_of_military_factories > 30
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = equipment_production_min_factories
		id = tactical_bomber
		value = 1
	}

	ai_strategy = {
		type = equipment_production_min_factories
		id = strategic_bomber
		value = 1
	}
}

ENG_bba_air_prod_1 = {
	# TODO BFW:
	allowed = { original_tag = ENG }
	enable = {
		date < 1940.1.1
	}
	abort_when_not_enabled = yes

	#Air unit factors
	ai_strategy = {
		type = unit_ratio
		id = fighter
		value = 200
	}

	ai_strategy = {
		type = equipment_production_factor
		id = fighter
		value = 20
	}

	ai_strategy = {
		type = equipment_production_min_factories
		id = fighter
		value = 1
	}

	ai_strategy = {
		type = unit_ratio
		id = cas
		value = 15 #because doctrine this = 15
	}

 	ai_strategy = {
		type = equipment_production_factor
		id = cas
		value = 10
	}

	ai_strategy = {
		type = equipment_production_min_factories
		id = cas
		value = 1
	}

	ai_strategy = {
		type = unit_ratio
		id = naval_bomber
		value = 2
	}

	ai_strategy = {
		type = unit_ratio
		id = tactical_bomber
		value = 25
	}

	ai_strategy = {
		type = equipment_production_factor
		id = tactical_bomber
		value = 10
	}

	ai_strategy = {
		type = unit_ratio
		id = strategic_bomber
		value = 25
	}

	ai_strategy = {
		type = equipment_production_factor
		id = strategic_bomber
		value = 5
	}

	ai_strategy = {
		type = equipment_variant_production_factor
		id = large_plane_airframe
		value = 1
	}

	ai_strategy = {
		type = equipment_production_factor
		id = heavy_fighter
		value = 2
	}

	ai_strategy = {
		type = unit_ratio
		id = heavy_fighter
		value = 2
	}

	ai_strategy = {
		type = unit_ratio
		id = scout_plane
		value = 1
	}

	ai_strategy = {
		type = unit_ratio
		id = cv_fighter
		value = 25
	}

	ai_strategy = {
		type = unit_ratio
		id = cv_naval_bomber
		value = 25
	}
}

ENG_bba_air_prod_2 = {
	# TODO BFW:
	allowed = { original_tag = ENG }
	enable = {
		date > 1940.1.1
	}
	abort_when_not_enabled = yes

	#Air unit factors
	ai_strategy = {
		type = unit_ratio
		id = fighter
		value = 200
	}

	ai_strategy = {
		type = equipment_production_factor
		id = fighter
		value = 25
	}

	ai_strategy = {
		type = equipment_production_min_factories
		id = fighter
		value = 5
	}

	ai_strategy = {
		type = unit_ratio
		id = cas
		value = 25
	}

	ai_strategy = {
		type = equipment_production_factor
		id = cas
		value = 15
	}

	ai_strategy = {
		type = equipment_production_min_factories
		id = cas
		value = 3
	}
 
	ai_strategy = {
		type = unit_ratio
		id = naval_bomber
		value = 5
	}

	ai_strategy = {
		type = unit_ratio
		id = tactical_bomber
		value = 25
	}

	ai_strategy = {
		type = equipment_production_factor
		id = tactical_bomber
		value = 10
	}

	ai_strategy = {
		type = unit_ratio
		id = strategic_bomber
		value = 25
	}

	ai_strategy = {
		type = equipment_production_factor
		id = strategic_bomber
		value = 15
	}

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

	ai_strategy = {
		type = equipment_production_factor
		id = heavy_fighter
		value = 5
	}

	ai_strategy = {
		type = unit_ratio
		id = heavy_fighter
		value = 5
	}

	ai_strategy = {
		type = unit_ratio
		id = scout_plane
		value = 1
	}

	ai_strategy = {
		type = unit_ratio
		id = cv_fighter
		value = 25
	}

	ai_strategy = {
		type = unit_ratio
		id = cv_naval_bomber
		value = 25
	}

}

ENG_build_more_patrol_bombers = {

	enable = {
		has_dlc = "By Blood Alone"
		has_navy_size = {
			size > 1
		}
		tag = ENG
	}
	abort_when_not_enabled = yes

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

	ai_strategy = {
		type = equipment_production_factor
		id = maritime_patrol_plane
		value = 15
	}
}

ENG_fighter_enhanced_production = {
	allowed = { original_tag = ENG }

	enable = {
		date < 1943.1.1
	}

	abort = {
		has_equipment = { small_plane_airframe > 4000 }
	}

	ai_strategy = {
		type = equipment_production_factor
		id = fighter
		value = 20
	}

	ai_strategy = {
		type = air_xp_spend_priority
		id = upgrade_xp_cutoff
		value = 100
	}

}

ENG_the_home_fleet  = {
	allowed = { original_tag = ENG }

	enable = {
		has_war = yes
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = strike_force_home_base
		id = 16 # north sea
	}
}

ENG_the_med_fleet  = {
	allowed = { original_tag = ENG }

	enable = {
		has_war = yes
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = strike_force_home_base
		id = 69 # nice #eastern med
	}
}

ENG_build_kgv_battleships = {
	allowed = { original_tag = ENG }

	enable = {
		date > 1936.1.1
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = role_ratio
		id = naval_capital_bb
		value = 20
	}

	ai_strategy = {
		type = navy_xp_spend_priority
		id = upgrade_xp_cutoff
		value = 100
	}
}

ENG_upgrade_from_interwar_tanks_asap = {
	allowed = {
		original_tag = ENG
	}
	enable = {
		is_historical_focus_on = yes
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = production_upgrade_desire_offset
		id = medium_tank_chassis_1
		value = 100  # 100 essentially means we don't require a stockpile surplus
	}
	ai_strategy = {
		type = production_upgrade_desire_offset
		id = medium_tank_equipment_1
		value = 100  # 100 essentially means we don't require a stockpile surplus
	}
}

ENG_protect_poland_against_germany = {
	allowed = { original_tag = ENG }

	enable = {
		GER = { has_completed_focus = GER_fate_of_czechoslovakia }
		GER = { NOT = { has_war_with = POL } }
		country_exists = POL
	}
	abort = {
		OR = {
			NOT = { country_exists = POL }
			has_war_with = POL
		}
	}

	ai_strategy = {
		type = protect
		id = "POL"
		value = 200
	}
	ai_strategy = {
		type = alliance
		id = "POL"
		value = 200
	}
	ai_strategy = {
		type = diplo_action_desire
		id = POL
		target = guarantee
		value = 20
	}
}

ENG_trade_with_poland = {
	# Poland has a mirrored version of this
	allowed = {
		original_tag = ENG
	}
	enable = {
		OR = {
			POL = { has_government = neutrality }
			POL = { has_government = democratic }
		}
		has_government = democratic
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = equipment_market_trade_desire
		id = POL
		value = 60
	}
}

ENG_less_weapon_purchases_more_for_construction = {
	allowed = {
		original_tag = ENG
	}
	enable = {
		date < 1939.1.1
		has_war = no
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = equipment_market_spend_factories
		value = -80  # 80 % less factories
	}
	ai_strategy = {  # Don't even try buying infantry equipment too early
		type = equipment_market_buying_threshold
		id = infantry_equipment
		value = -20000  # Absolute number of units
	}
}

ENG_fewer_factories_for_purchases_please = {
	allowed = {
		original_tag = ENG
	}
	enable = {
		date > 1939.1.1
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = equipment_market_spend_factories
		value = -50  # 50 % less factories
	}
}

ENG_protect_poland_against_germany_even_more = {
	allowed = { original_tag = ENG }
	enable = {
		GER = { has_completed_focus = GER_fate_of_czechoslovakia }
		GER = { NOT = { has_war_with = POL } }
		country_exists = POL
	}
	abort = {
		NOT = { country_exists = POL }
	}

	ai_strategy = {
		type = protect
		id = "POL"
		value = 200
	}
	ai_strategy = {
		type = alliance
		id = "POL"
		value = 200
	}
}

ENG_defend_poland_against_germany = {
	allowed = { original_tag = ENG }
	enable = {
		GER = { has_war_with = POL }
		country_exists = POL
	}
	abort = {
		OR = {
			NOT = { country_exists = POL }
			has_war_with = POL
		}
	}

	ai_strategy = {
		type = befriend
		id = "POL"
		value = 200
	}
	ai_strategy = {
		type = alliance
		id = "POL"
		value = 200
	}
}

ENG_royal_air_force = {
	allowed = { original_tag = ENG }
	enable = {
		date > 1939.4.1
	}
	abort = {
		date < 1939.4.1
	}

	ai_strategy = {
		type = air_factory_balance
		value = 50
	}

}

ENG_template_design_1 = {
	allowed = { original_tag = ENG }
	enable = {
		date < 1940.1.1
	}
	abort = {
		date > 1940.1.1
	}
	ai_strategy = {
		type = template_prio
		id = infantry
		value = 40
	}

	ai_strategy = {
		type = template_prio
		id = motorized
		value = -50
	}

	ai_strategy = {
		type = template_prio
		id = cavalry
		value = -100
	}

	ai_strategy = {
		type = template_prio
		id = light_armor
		value = 50
	}

	ai_strategy = {
		type = template_prio
		id = medium_armor
		value = 30
	}

	ai_strategy = {
		type = template_prio
		id = heavy_armor
		value = -100
	}

	ai_strategy = {
		type = template_prio
		id = paratroopers
		value = -10
	}

	ai_strategy = {
		type = template_prio
		id = mechanized
		value = -50
	}
}

ENG_template_design_2 = {
	allowed = { original_tag = ENG }
	enable = {
		date > 1940.1.1
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = template_prio
		id = infantry
		value = -10
	}

	ai_strategy = {
		type = template_prio
		id = motorized
		value = 10
	}

	ai_strategy = {
		type = template_prio
		id = cavalry
		value = -100
	}

	ai_strategy = {
		type = template_prio
		id = light_armor
		value = -10
	}

	ai_strategy = {
		type = template_prio
		id = medium_armor
		value = 40
	}

	ai_strategy = {
		type = template_prio
		id = modern_armor
		value = 50
	}

	ai_strategy = {
		type = template_prio
		id = heavy_armor
		value = -100
	}

	ai_strategy = {
		type = template_prio
		id = paratroopers
		value = -10
	}

	ai_strategy = {
		type = template_prio
		id = mechanized
		value = 10
	}
}

# lets make sure the allies dont overcommit to invasions early on
ENG_Allies_careful_with_early_invasions = {
	enable = {
		date < 1942.8.1
		NOT = { original_tag = USA }
		#if = { # commented in case we want to add it back
		#	limit = { NOT = { has_dlc = "Man the Guns"} }
		#	NOT = { has_tech = landing_craft }
		#}
		#else = {
		#	NOT = { has_tech = mtg_landing_craft }
		#}

		OR = {
			is_in_faction_with = ENG # anyone in allies
			tag = FRA
		}

		NOT = {
			SOV = {
				has_war_with = GER
				surrender_progress > 0.15
			}
		}
	}
	abort = {
		#OR = { # commented in case we want to add it back
		#	has_tech = landing_craft
		#	has_tech = mtg_landing_craft
		#}
		OR = {
			SOV = {
				has_war_with = GER
				surrender_progress > 0.23
			}
			date > 1942.8.1
		}
	}

	ai_strategy = {
		type = invade
		id = "ITA"
		value = -500
	}

	ai_strategy = {
		type = invade
		id = "GER"
		value = -500
	}

	ai_strategy = {
		type = invade
		id = "VIC"
		value = -500
	}

	ai_strategy = { #TODO why does this crash
		type = invade
		id = "JAP"
		value = -500
	}

	ai_strategy = {
		type = area_priority
		id = scandinavia
		value = -300
	}
}

ENG_USA_careful_with_early_invasions = { #Same as above, alter in tandem

	allowed = { original_tag = USA }  # TODO this strategy seems bugged

	enable = {
		date < 1942.8.1
		
		#if = { # commented in case we want to add it back
		#	limit = { NOT = { has_dlc = "Man the Guns"} }
		#	NOT = { has_tech = landing_craft }
		#}
		#else = {
		#	NOT = { has_tech = mtg_landing_craft }
		#}

		OR = {
			is_in_faction_with = ENG # anyone in allies
			tag = FRA
		}

		NOT = {
			SOV = {
				has_war_with = GER
				surrender_progress > 0.15
			}
		}
	}
	abort = {
		#OR = { # commented in case we want to add it back
		#	has_tech = landing_craft
		#	has_tech = mtg_landing_craft
		#}
		OR = {
			SOV = {
				has_war_with = GER
				surrender_progress > 0.23
			}
			date > 1942.8.1
		}
	}

	ai_strategy = {
		type = invade
		id = "ITA"
		value = -500
	}

	ai_strategy = {
		type = invade
		id = "GER"
		value = -500
	}

	ai_strategy = {
		type = invade
		id = "VIC"
		value = -500
	}
	
	ai_strategy = {
		type = area_priority
		id = scandinavia
		value = -300
	}
	
}

ENG_Allies_east_prussia_invasion_is_death_trap = {
	enable = {

		OR = {
			is_in_faction_with = ENG # anyone in allies
			tag = FRA
		}

		GER = { has_war_with = POL }
		POL = {
			OR = {
				exists = yes
				has_capitulated = no
			}
		}

		date < 1940.1.1
	}

	abort = {
		OR = {
			NOT = { GER = { has_war_with = POL } }
			POL = {
				OR = {
					exists = no
					has_capitulated = yes
				}
			}
			date > 1940.1.1
		}
	}

	ai_strategy = {
		type = invade
		id = "GER"
		value = -2000
	}
	ai_strategy = {
		type = dont_defend_ally_borders
		id = "POL"
		value = 100
	}
}

# AI gets trapped here and dies to germany, although this takes a big toll
# on germany as well leading to bad attack on soviet as well as no UK troops
# to invade them later when they are busy.
ENG_trying_to_save_benelux_is_deathtrap = {
	allowed = { original_tag = ENG }
	enable = {
		has_war_with = GER
		date < 1940.3.1
		OR = {
			HOL = { has_capitulated = no }
			BEL = { has_capitulated = no }
		}
	}

	abort = {
		OR = {
			date > 1940.3.1
			AND = {
				HOL = { has_capitulated = yes }
				BEL = { has_capitulated = yes }
			}
		}
	}

	ai_strategy = {
		type = dont_defend_ally_borders
		id = "HOL"
		value = 70
	}
	ai_strategy = {
		type = dont_defend_ally_borders
		id = "BEL"
		value = 50
	}
	ai_strategy = {
		type = dont_defend_ally_borders
		id = "LUX"
		value = 50
	}
	ai_strategy = {
		type = put_unit_buffers
		# french states bordering benelux
		states = {
			29
			785
			18
		}
		ratio = 0.1
		area = europe
		subtract_invasions_from_need = no
		subtract_fronts_from_need = yes
	}
}

ENG_naval_role_ratios_historical = {
	allowed = {
		has_dlc = "Man the Guns"
		original_tag = ENG
	}
	enable = { always = yes }
	abort_when_not_enabled = yes

	ai_strategy = {
		type = role_ratio
		id = naval_capital_bb
		value = 20
	}
	ai_strategy = {
		type = dockyard_to_military_factory_ratio
		value = 20  #aim for a 2-1 ratio on naval factories
	}
	ai_strategy = {
		type = role_ratio
		id = naval_capital_bc
		value = -10
	}

	ai_strategy = {
		type = role_ratio
		id = naval_carrier
		value = 20
	}

	ai_strategy = {
		type = role_ratio
		id = naval_carrier_light
		value = 15
	}

	ai_strategy = {
		type = role_ratio
		id = naval_submarine
		value = -150
	}

	ai_strategy = {
		type = role_ratio
		id = naval_screen
		value = 250
	}

	ai_strategy = {
		type = role_ratio
		id = naval_escort
		value = 10
	}

	ai_strategy = {
		type = role_ratio
		id = naval_cruiser_light
		value = 60
	}

	ai_strategy = {
		type = role_ratio
		id = naval_cruiser_heavy
		value = 5
	}

	ai_strategy = {
		type = role_ratio
		id = naval_mine_sweeper
		value = 20
	}

	ai_strategy = {
		type = role_ratio
		id = naval_mine_layer
		value = 10
	}
}

ENG_naval_role_ratios_anti_submarines = {
	allowed = {
		has_dlc = "Man the Guns"
		original_tag = ENG
	}
	enable = {
		anti_submarine_strategy_required_trigger = yes
	}
	abort = {
		not = { anti_submarine_strategy_required_trigger = yes }
	}
	ai_strategy = {
		type = role_ratio
		id = naval_capital_bb
		value = 10
	}
	ai_strategy = {
		type = dockyard_to_military_factory_ratio
		value = 20  #aim for a 2-1 ratio on naval factories
	}
	ai_strategy = {
		type = role_ratio
		id = naval_capital_bc
		value = -10
	}

	ai_strategy = {
		type = role_ratio
		id = naval_carrier
		value = 20
	}

	ai_strategy = {
		type = role_ratio
		id = naval_carrier_light
		value = -25
	}

	ai_strategy = {
		type = role_ratio
		id = naval_submarine
		value = -150
	}

	ai_strategy = {
		type = role_ratio
		id = naval_screen
		value = -70
	}

	ai_strategy = {
		type = role_ratio
		id = naval_escort
		value = 50
	}

	ai_strategy = {
		type = role_ratio
		id = naval_cruiser_light
		value = -25
	}

	ai_strategy = {
		type = role_ratio
		id = naval_cruiser_heavy
		value = -10
	}
}


ENG_the_adriatic_is_dangerous = {
	allowed = { original_tag = ENG }
	enable = {
		has_war_with = ITA
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = naval_avoid_region
		id = 168 #adriatic
		value = 75
	}
}

ENG_the_channel_is_dangerous = {
	allowed = { original_tag = ENG }
	enable = {
		has_war_with = GER
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = naval_avoid_region
		id = 18 #english channel
		value = 75
	}
}

ENG_baltic_is_a_trap = {
	allowed = { original_tag = ENG }
	enable = {
		has_war_with = GER
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = naval_avoid_region
		id = 9 #northern baltic
		value = 600
	}
	ai_strategy = {
		type = naval_avoid_region
		id = 206 #central baltic
		value = 600
	}
	ai_strategy = {
		type = naval_avoid_region
		id = 207 #danish belts
		value = 600
	}
	#ai_strategy = {
	#	type = naval_avoid_region
	#	id = 279 #Bothnia
	#	value = 600
	#}
	ai_strategy = {
		type = naval_avoid_region
		id = 9 #gulf of finland
		value = 600
	}
}

ENG_lifeline_of_the_empire = {
	allowed = { original_tag = ENG }
	enable = {
		always = yes
	}
	abort = {
		always = no
	}

	ai_strategy = {
		type = area_priority
		id = suez
		value = 80 # this is extra on top of 50 base (now equal to other territory)
	}
}

ENG_USA_focus_on_europe = {
	allowed = {
		OR = {
			tag = USA
			tag = ENG
		}
	}

	enable = {
		is_historical_focus_on = yes
		OR = {
			date > 1941.6.1
			SOV = {
				surrender_progress > 0.50
			}
		}
		has_global_flag = FRA_already_surrendered
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = front_unit_request
		tag = GER
		value = 10
	}

	ai_strategy = {
		type = front_unit_request
		area = italy
		value = 20
	}

	ai_strategy = {
		type = front_unit_request
		area = north_africa
		value = 15
	}
}

ENG_USA_focus_on_europe_more = {
	allowed = {
		OR = {
			tag = USA
			tag = ENG
		}
	}

	enable = {
		is_historical_focus_on = yes
		OR = {
			date > 1942.6.1
			SOV = {
				surrender_progress > 0.65
			}
		}
		has_global_flag = FRA_already_surrendered
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = front_unit_request
		tag = GER
		value = 20
	}

	ai_strategy = {
		type = front_unit_request
		area = italy
		value = 20
	}

	ai_strategy = {
		type = front_unit_request
		area = north_africa
		value = 15
	}
	
}

ENG_USA_focus_on_europe_loads_more = {
	allowed = {
		OR = {
			tag = USA
			tag = ENG
		}
	}

	enable = {
		is_historical_focus_on = yes
		date > 1943.6.1
		has_global_flag = FRA_already_surrendered
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = front_unit_request
		area = mainland_europe
		value = 50
	}
}

ENG_evacuate_troops_after_fall_of_france = {
	allowed = {
		OR = {
			tag = ENG
			tag = USA
		}
	}

	abort_when_not_enabled = yes

	enable = {
		is_historical_focus_on = yes
		OR = {
			date < 1942.6.1
			SOV = {
				surrender_progress < 0.65
				date < 1942.6.1
			}
		}
		has_global_flag = FRA_already_surrendered
	}

	ai_strategy = {
		type = front_unit_request
		area = mainland_europe
		value = -100
	}
}

ENG_time_to_ditch_FRA = {
	allowed = {
		original_tag = ENG
	}

	enable = {
		is_historical_focus_on = yes
		FRA = {
			has_capitulated = no
			surrender_progress > 0.25
		}
		OR = {
			NOT = { has_global_flag = FRA_already_surrendered }
			#lets give a month of retreat time after capitulation
			set_temp_variable = { t = global.num_days }
			subtract_from_temp_variable = { t = global.FRA_capitulation_days }
			check_variable = { t < 30 }
		}
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = dont_defend_ally_borders
		id = FRA
		value = 100
	}
	ai_strategy = {
		type = dont_defend_ally_borders
		id = BEL
		value = 100
	}
	ai_strategy = {
		type = dont_defend_ally_borders
		id = HOL
		value = 100
	}
	ai_strategy = {
		type = dont_defend_ally_borders
		id = LUX
		value = 100
	}
}

ENG_gang_up_GER_with_USA = {
	allowed = { original_tag = ENG }
	enable = {
		FRA = {
			OR = {
				has_capitulated = yes
				exists = no
			}
		}
	}
	abort_when_not_enabled = yes

	# after FRA falls, both ENG and USA will try to help in europe and africa
	ai_strategy = {
		type = force_defend_ally_borders
		value = 100
		target = europe
	}
	ai_strategy = {
		type = force_defend_ally_borders
		value = 100
		target = africa
	}
}

ENG_accept_USA_access = {
	allowed = {
		original_tag = ENG
	}
	enable = {
		tag = ENG
		date > 1940.9.9
		USA = {
			is_ai = yes
			NOT = {
				OR = {
					is_in_faction_with = ENG
					has_military_access_to = ENG
				}
			}
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = diplo_action_acceptance
		id = USA
		target = military_access
		value = 1000
	}
}


ENG_Commonwealth_dont_get_sucked_into_FRA_and_die = {

	enable = {
		OR = {
			tag = ENG
			is_subject_of = ENG
		}
		has_war_with = GER
		has_war_together_with = FRA

		date < 1941.9.9

		NOT = { has_global_flag = FRA_already_surrendered }
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = front_unit_request
		area = europe
		value = -60
	}

	ai_strategy = {
  		type = garrison
   		value = 70
   	}
}

ENG_please_stop_stomping_italy_so_hard_in_africa_ty = {

	enable = {
		OR = {
			tag = ENG
			is_subject_of = ENG
		}

		date < 1942.1.1

		has_global_flag = FRA_already_surrendered
	}
	abort_when_not_enabled = yes

   	ai_strategy = {
		type = put_unit_buffers
		area = UK
		ratio = 0.5
		subtract_invasions_from_need = no
		subtract_fronts_from_need = yes
	}
}

ENG_in_for_the_long_haul_bruv = {
	allowed = { original_tag = ENG }
	enable = {
		has_government = democratic
		date < 1937.10.1
		has_war = no
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = building_target
		id = industrial_complex
		value = 49
	}
	ai_strategy = {
		type = air_factory_balance
		value = 15
	}
}

ENG_industry_we_on_an_island_bruv = {
	allowed = { original_tag = ENG }
	enable = {
		has_government = democratic
		has_war = no
		date > 1937.10.1
	}
	abort_when_not_enabled = yes

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

	ai_strategy = {
		type = building_target
		id = dockyard
		value = 50
	}

	ai_strategy = {
		type = air_factory_balance
		value = 30
	}
}

ENG_if_the_best_arrangements_are_made_as_they_are_being_made = {
	allowed = {
		original_tag = ENG
	}
	enable = {
		date > 1940.1.1
		has_war_with = GER
		num_of_military_factories < 150
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = added_military_to_civilian_factory_ratio
		value = 50
	}

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

ENG_the_best_arrangements_are_made = {
	allowed = {
		original_tag = ENG
	}
	enable = {
		date > 1940.1.1
		has_war_with = GER
		num_of_military_factories > 150
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = added_military_to_civilian_factory_ratio
		value = 20
	}
}

ENG_growing_confidence_in_the_air = {
	allowed = { original_tag = ENG }
	enable = {
		has_war = yes
		has_government = democratic
		date > 1938.1.1
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = air_factory_balance
		value = 30
	}
}

ENG_allies_dont_ask_for_diplo_access_to_SOV = {
	enable = {
		ENG = {
			has_government = democratic
		}
		SOV = {
			has_government = communism
		}
		is_in_faction_with = ENG
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = diplo_action_desire
		id = SOV
		target = military_access
		value = -5000
	}
	ai_strategy = {
		type = diplo_action_desire
		id = TAN
		target = military_access
		value = -5000
	}
	ai_strategy = {
		type = diplo_action_desire
		id = MON
		target = military_access
		value = -5000
	}
	ai_strategy = {
		type = diplo_action_desire
		id = SOV
		target = docking_rights
		value = -5000
	}
	ai_strategy = {
		type = diplo_action_desire
		id = TAN
		target = docking_rights
		value = -5000
	}
	ai_strategy = {
		type = diplo_action_desire
		id = MON
		target = docking_rights
		value = -5000
	}
}

ENG_Defends_Mediterranean = {
	allowed = {
		tag = ENG
	}

	enable = {
		always = yes
	}
	abort_when_not_enabled = yes

	# Alexandria
	ai_strategy = {
		type = theatre_distribution_demand_increase
		id = 447
		value = 10
	}

	# Gibraltar
	ai_strategy = {
		type = theatre_distribution_demand_increase
		id = 118
		value = 4
	}

	# Malta
	ai_strategy = {
		type = theatre_distribution_demand_increase
		id = 116
		value = 4
	}
}


ENG_convoy_raids_german_italian_convoys = {
	allowed = {
		tag = ENG
	}

	enable = {
		OR = {
			has_war_with = GER
			has_war_with = ITA
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = naval_convoy_raid_region
		id = 61 # cape verde plain
		value = 100
	}

	ai_strategy = {
		type = naval_convoy_raid_region
		id = 45 # norwegian sea
		value = 100
	}
}

ENG_produce_floating_harbors = {
	allowed = {	original_tag = ENG }
	enable = {
		is_historical_focus_on = yes
		date > 1941.1.1
		has_war = yes
		num_of_naval_factories > 25
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = unit_ratio
		id = floating_harbor # for floating harbors, 'unit_ratio' is actually not a ratio but an absolute desired number
		value = 10
	}
}

ENG_unit_buffer_for_african_defense = {
	allowed = {
		original_tag = ENG
	}
	enable = {
		OR = {
			has_war = no
			AND = {
				has_war = yes
				surrender_progress < 0.5

			}
		}
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = put_unit_buffers

		# ratio of total armies in country to be buffered
		ratio = 0.1

		# 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 = {
			446
			447
			452
		}

		area = suez

		subtract_invasions_from_need = yes
		subtract_fronts_from_need = yes
	}
}

ENG_ALLIES_norway_is_not_THAT_important = {
	allowed = {
		always = yes
	}
	enable = {
		date < 1945.1.1
		is_in_faction_with = ENG
		NOT = { original_tag = NOR }  # Let (exiled) Norway do what they want if they are in the Allies
		any_allied_country = { 
			NORDIC_is_nordic = yes 
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = area_priority
		id = scandinavia
		value = -150
	}
	
	ai_strategy = {
		type = front_unit_request
		area = scandinavia
		value = -40
	}
	
	#ai_strategy = {
	#	type = naval_invasion_focus
	#	value = -100
	#}

	ai_strategy = {
		type = naval_avoid_region
		id = 173 #eastern north sea
		value = 600
	}
}

ENG_super_boost_armor_div = { #lets make sure the uk upgrades rtr to divs
	allowed = {
		original_tag = ENG
	}
	enable = {
		OR = {
			has_tech = basic_medium_tank
			has_tech = basic_medium_tank_chassis
		}
		NOT = { has_template_ai_majority_unit = medium_armor }
		has_war = no
		date > 1937.1.1

	}

	abort = {
		has_template_ai_majority_unit = medium_armor
		date > 1940.1.1
	}

	# lets do changes more often during this period too
	ai_strategy = {
		type = land_xp_spend_priority
		id = division_template
		value = 100
	}

	# this is gateway
	ai_strategy = {
		type = template_prio
		id = light_armor
		value = 100
	}
}

ENG_super_boost_armor_div_med = { #lets make sure the uk upgrades armor divs to mediums
	allowed = {
		original_tag = ENG
	}
	enable = {
		OR = {
			has_tech = basic_medium_tank
			has_tech = basic_medium_tank_chassis
		}
		NOT = { has_template_ai_majority_unit = medium_armor }

		date > 1940.1.1
	}

	abort = {
		has_template_ai_majority_unit = medium_armor
	}

	# lets do changes more often during this period too
	ai_strategy = {
		type = land_xp_spend_priority
		id = division_template
		value = 100
	}

	# this is gateway
	ai_strategy = {
		type = template_prio
		id = light_armor
		value = 100
	}

	ai_strategy = {
		type = template_prio
		id = medium_armor
		value = 150
	}

	ai_strategy = {
		type = template_prio
		id = motorized
		value = 200
	}
}

ENG_take_italys_spaghetti = {
	allowed = {
		OR = {
			original_tag = USA
			original_tag = ENG
		}
		is_historical_focus_on = yes
	}
	enable = {
		date > 1942.6.1
		ITA = {
			surrender_progress < 0.2
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = area_priority
		id = italy
		value = 60
	}
	
	ai_strategy = {
		type = area_priority
		id = north_africa
		value = 100
	}

	ai_strategy = {
		type = area_priority
		id = normandy_landing_zone
		value = -100
	}
}

ENG_onto_the_beaches = {
	allowed = {
		OR = {
			original_tag = USA
			original_tag = ENG
		}
		is_historical_focus_on = yes
	}
	enable = {
		date > 1942.6.1
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = naval_invasion_focus
		value = 10
	}

	ai_strategy = {
		type = invasion_unit_request
		area = normandy_landing_zone
		value = 10
	}

}

ENG_onto_the_beaches_2 = {
	allowed = {
		OR = {
			original_tag = USA
			original_tag = ENG
		}
		is_historical_focus_on = yes
	}
	enable = {
		date > 1943.1.1
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = naval_invasion_focus
		value = 20
	}
	
	ai_strategy = {
		type = invasion_unit_request
		area = normandy_landing_zone
		value = 6
	}
	
	ai_strategy = {
		type = area_priority
		id = normandy_landing_zone
		value = 80
	}
}

ENG_onto_the_beaches_3 = {
	allowed = {
		OR = {
			original_tag = USA
			original_tag = ENG
		}
		is_historical_focus_on = yes
	}
	enable = {
		date > 1943.6.1
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = naval_invasion_focus
		value = 30
	}
}

ENG_onto_the_beaches_4 = {
	allowed = {
		OR = {
			original_tag = USA
			original_tag = ENG
		}
		is_historical_focus_on = yes
	}
	enable = {
		date > 1944.1.1
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = naval_invasion_focus
		value = 20
	}
}

ENG_USA_d_day = {
	allowed = {
		OR = {
			original_tag = USA
			original_tag = ENG
		}
		is_historical_focus_on = yes
	}
	enable = {
		date > 1943.9.1
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = area_priority
		id = normandy_landing_zone
		value = 60
	}

	ai_strategy = {
		type = invasion_unit_request
		area = normandy_landing_zone
		value = 5
	}

}

ENG_RAJ_the_hot_gates = {
	allowed = {
		OR = {
			original_tag = ENG
			original_tag = RAJ
		}
	}
	enable = {
		OR = {
			671 = { is_controlled_by = JAP }
			670 = { is_controlled_by = JAP }
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = area_priority
		id = burma
		value = 60
	}

	ai_strategy = {
		type = front_unit_request
		area = burma
		value = 8
	}

	ai_strategy = {
		type = put_unit_buffers
		# burmese states
		states = {
			288
			640
			430
		}
		ratio = 0.05
		area = burma
		subtract_invasions_from_need = no
		subtract_fronts_from_need = yes
	}

}

ENG_we_hate_fighting_in_the_balkans = {

	allowed = {
		original_tag = ENG
	}
	enable = {
		date < 1943.1.1
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = dont_defend_ally_borders #Just a bit, we wait for greece
		id = YUG
		value = 30
	}

	ai_strategy = {
		type = dont_defend_ally_borders #Just a bit, we wait for greece
		id = GRE
		value = 30
	}

	ai_strategy = {
		type = front_unit_request
		area = albania
		value = -50
	}

	ai_strategy = {
		type = area_priority
		id = albania
		value = -50
	}
}

ENG_sardinia_is_a_stupid_island = {

	allowed = {
		original_tag = ENG
	}
	enable = {
		date < 1943.1.1
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = front_unit_request
		area = sardinia
		value = -50
	}

	ai_strategy = {
		type = area_priority
		id = sardinia
		value = -50
	}

	ai_strategy = {
		type = invasion_unit_request
		area = sardinia
		value = -50
	}
}

COMMONWEALTH_disregard_france_a_bit = {
	allowed = {
		is_in_faction_with = ENG
		is_subject_of = ENG
	}
	enable = {
		is_historical_focus_on = yes
	}
	abort = {
		FRA = { 
			OR = {
				has_capitulated = yes
				is_government_in_exile = yes 
			}
		}
	}
	ai_strategy = {
		type = strategic_air_importance
		id = 19 #Strategic Region ID - Northern France
		value = -30000 #value of stocked main front in active combat is usually around 35,000
	}
	ai_strategy = {
		type = strategic_air_importance
		id = 5 #Strategic Region ID - benelux
		value = -30000 #value of stocked main front in active combat is usually around 35,000
	}
}

ENG_disregard_france_a_bit = {
	allowed = {
		original_tag = ENG
	}
	enable = {
		is_historical_focus_on = yes
	}
	abort = {
		FRA = { 
			OR = {
				has_capitulated = yes
				is_government_in_exile = yes 
			}
		}
	}
	ai_strategy = {
		type = strategic_air_importance
		id = 19 #Strategic Region ID - Northern France
		value = -20000 #value of stocked main front in active combat is usually around 35,000
	}
	ai_strategy = {
		type = strategic_air_importance
		id = 5 #Strategic Region ID - benelux
		value = -20000 #value of stocked main front in active combat is usually around 35,000
	}
}

ENG_dont_kick_russia_out_from_triple_entente_due_to_gobbling_up_breakaway_states = {
	allowed = {
		original_tag = ENG
	}

	enable = {
		is_in_faction_with = SOV
		SOV = { has_completed_focus = SOV_the_triple_entente }
	}

	abort = {
		NOT = { is_in_faction_with = SOV }
	}

	ai_strategy = {
		type =  alliance
		id = SOV
		value = 200
	}

	ai_strategy = {
		type =  befriend
		id = SOV
		value = 200
	}
}

ENG_the_baltic_is_a_terrible_holiday_destination = {
	
	allowed = {
		original_tag = ENG
	}

	enable = {
		OR = {
			has_war_with = GER
			has_war_with = DEN
			GER = {
				OR = {
					has_war_with = POL
					has_war_with = HOL
					has_war_with = DEN
				}
			}
		}
	}
	
	abort = {
		GER = { has_war = no }
	}
	
	ai_strategy = {
		type = naval_avoid_region
		id = 9 #northern baltic
		value = 200
	}
	ai_strategy = {
		type = naval_avoid_region
		id = 206 #central baltic
		value = 200
	}
	ai_strategy = {
		type = naval_avoid_region
		id = 207 #danish belts
		value = 200
	}
	#ai_strategy = {
	#	type = naval_avoid_region
	#	id = 279 #Bothnia
	#	value = 200
	#}
	ai_strategy = {
		type = naval_avoid_region
		id = 9 #gulf of finland
		value = 200
	}
}

ENG_chill_on_the_pacific = {
	allowed = {
		original_tag = ENG
	}
	enable = {
		is_historical_focus_on = yes
		has_war_with = JAP
		has_war_with = GER
		GER = { has_capitulated = no }
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = area_priority
		id = pacific
		value = -50
	}
	
	ai_strategy = { #Invade japan after germany has capitulated
		type = invade
		id = "JAP"
		value = -500
	}
	
}

ENG_to_tobruk = {
	allowed = { original_tag = ENG }
	enable = { 
		is_historical_focus_on = yes
		date > 1941.6.6
		date < 1943.6.6
		451 = { is_controlled_by = ITA }
		ITA = { is_ai = yes }
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = front_control

		state = 451 #derna

		ratio = 0.1

		priority = 100
		ordertype = front
		execution_type = rush
		execute_order = yes
	}
	
	ai_strategy = {
		type = invasion_unit_request
		area = north_africa
		value = 15
	}
	
	ai_strategy = {
		type = area_priority
		id = north_africa
		value = 50
	}
	
	ai_strategy = {
		type = invade
		id = "ITA"
		value = 550 #counterbalances...
	}
}

ENG_avoid_balkans_until_africa_is_secure = {
	allowed = { original_tag = ENG }
	enable = {
		is_historical_focus_on = yes
		date > 1939.6.6
		date < 1943.6.6

		# The check below should really be a scripted trigger or something
		OR = { # Check whole north-african coast
			448 = { CONTROLLER = { has_war_with = ROOT } } # tripoli
			450 = { CONTROLLER = { has_war_with = ROOT } } # benghazi
			458 = { CONTROLLER = { has_war_with = ROOT } } # tunisia
			461 = { CONTROLLER = { has_war_with = ROOT } } # casablanca
			462 = { CONTROLLER = { has_war_with = ROOT } } # marrakech
			459 = { CONTROLLER = { has_war_with = ROOT } } # algiers
			460 = { CONTROLLER = { has_war_with = ROOT } } # constantine
			665 = { CONTROLLER = { has_war_with = ROOT } } # gabès
			449 = { CONTROLLER = { has_war_with = ROOT } } # el agheila
			451 = { CONTROLLER = { has_war_with = ROOT } } # derna
			452 = { CONTROLLER = { has_war_with = ROOT } } # matrouh
			447 = { CONTROLLER = { has_war_with = ROOT } } # alexandria
			446 = { CONTROLLER = { has_war_with = ROOT } } # cairo
			290 = { CONTROLLER = { has_war_with = ROOT } } # spanish africa
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = invasion_unit_request
		area = albania
		value = -50
	}

	ai_strategy = {
		type = area_priority
		id = albania
		value = -50
	}
}

ENG_ALLIES_dont_invade_norway = {
	allowed = {
		always = yes
	}
	enable = {
		is_historical_focus_on = yes
		date < 1943.2.1
		is_in_faction_with = ENG
		has_war_with = NOR
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = invade
		id = "NOR"
		value = -500
	}
	
	ai_strategy = {
		type = area_priority
		id = scandinavia
		value = -100
	}
	
	ai_strategy = {
		type = front_unit_request
		area = scandinavia
		value = -100
	}
}

ENG_prepare_for_naval_invasion_capability = {
	allowed = {
		original_tag = ENG
		has_dlc = "Man the Guns"
	}
	enable = {
		is_historical_focus_on = yes
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = research_weight_factor
		id = mtg_landing_craft  # Make sure we can do larger invasions
		value = 100
	}
}


ENG_conquer_SAU = {
	allowed = {
		original_tag = ENG
	}
	enable = {
		SAU = {
			focus_progress = {
				focus = SAU_consolidation
				progress > 0.1
			}
		}
		country_exists = SAU
	}
	abort = {
		OR = {
			ENG = {
				NOT = {
					owns_state = 656
					owns_state = 765
					owns_state = 658
					owns_state = 659
					owns_state = 455
					owns_state = 453
					owns_state = 446
					owns_state = 907
				}
			}
			SAU = { has_country_flag = ai_failed_invasion }
		}
	}

	ai_strategy = {
		type = conquer
		id = SAU
		value = 1000
	}
	ai_strategy = {
		type = antagonize
		id = SAU
		value = 1000
	}
}