# Written by Henrik "Groogy" Hansson
# Modified by Daniel "Da9L" Sjöberg

default_unit_production = {
	# If adding country-unique ones, bear in mind that they STACK unless excluding countries in the enable
	enable = {
		always = yes
	}
	abort_when_not_enabled = yes

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

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

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

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

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

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

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

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

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

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

	ai_strategy = {
		type = equipment_production_factor
		id = heavy_fighter
		value = -40 #Just build a few slowly
	}

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

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

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

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

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

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

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

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

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

default_role_ratios = {
	enable = {
		not = {
			has_dlc = "Man the Guns"
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = role_ratio
		id = naval_capital
		value = 100
	}

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

	ai_strategy = {
		type = role_ratio
		id = naval_sub
		value = 100
	}

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

default_role_ratios = {
	enable = {
		has_dlc = "Man the Guns"
	}
	abort_when_not_enabled = yes

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

	ai_strategy = {
		type = role_ratio
		id = naval_capital_bc
		value = -20
	}

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

	ai_strategy = {
		type = role_ratio
		id = naval_submarine
		value = 100
	}

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

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

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

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

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

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

default_surplus_management = {
	# If we manage to get all equipment we want, keep producing more stuff according to this
	enable = {
		always = yes  # For now, applies to everyone
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = equipment_production_surplus_management
		id = infantry_equipment
		value = 10
	}

	ai_strategy = {
		type = equipment_production_surplus_management
		id = support_equipment
		value = 5
	}

	ai_strategy = {
		type = equipment_production_surplus_management
		id = artillery_equipment
		value = 5
	}

	ai_strategy = {  # Potentially move into a "specialization" strategy
		type = equipment_production_surplus_management
		id = anti_air_equipment
		value = 3
	}

	ai_strategy = {  # Potentially move into a "specialization" strategy
		type = equipment_production_surplus_management
		id = anti_tank_equipment
		value = 2
	}

	ai_strategy = {
		type = equipment_production_surplus_management
		id = convoy
		value = 5
	}
}

bba_air_prod_1 = {
	# TODO BFW: this was moved from germany's strats

	enable = {
		always = yes
	}

	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 = 10
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

}

bba_support_boosts = {

	enable = {
		is_historical_focus_on = yes
		date < 1939.1.1
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = equipment_variant_production_factor
		id = support_equipment
		value = 15
	}
}

convoy_voy_voy_voy = {
	enable = {
		has_dlc = "Man the Guns"
		convoy_threat > 0.2
	}
	abort = {
		convoy_threat < 0.2
	}

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

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

	ai_strategy = {
		type = role_ratio
		id = naval_mine_layer
		value = -10
	}
	ai_strategy = {
		type = unit_ratio
		id = screen_ship
		value = 30
	}

	ai_strategy = {
		type = unit_ratio
		id = capital_ship
		value = -10
	}

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

ill_show_you_mine = {
	enable = {
		has_dlc = "Man the Guns"
		mine_threat > 0.2
	}
	abort = {
		mine_threat < 0.2
	}

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

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

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

ill_show_you_mine_2 = {
	enable = {
		has_dlc = "Man the Guns"
		mine_threat > 0.5
	}
	abort = {
		mine_threat < 0.5
	}

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

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

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

default_pp_spend_amount = {
	enable = {
		always = yes
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = pp_spend_amount
		id = idea
		value = 100
	}

	ai_strategy = {
		type = pp_spend_amount
		id = decision
		value = 100
	}
}

default_paratroopers_production = {
	enable = {
		ai_wants_divisions >  12 #Massively decreasing the amount of paratroopers the AI wants
	}
	abort = {
		ai_wants_divisions < 13 #Massively decreasing the amount of paratroopers the AI wants
	}

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

default_major_SF_para = {
	enable = {
		is_major = yes
		has_tech = special_forces_paratroopers
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = role_ratio
		id = paratroopers
		value = 4
	}
}

default_major_SF_marines = {
	enable = {
		is_major = yes
		has_tech = special_forces_marines
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = role_ratio
		id = marines
		value = 2
	}
}

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

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

default_garrison_production = {
	enable = {
		ai_wants_divisions >  12 #Massively decreasing the amount of garrison and suppression the AI wants
		is_major = yes
	}
	abort = {
		ai_wants_divisions < 13 #Massively decreasing the amount of garrison and suppression the AI wants
		is_major = no
	}

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

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

default_mountaineers_production = {
	enable = {
		ai_wants_divisions > 11 #Decreasing the amount of mountaineers the AI wants
	}
	abort = {
		ai_wants_divisions < 12 #Decreasing the amount of mountaineers the AI wants
	}

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

#default_marines_production = {
#	enable = {
#		ai_wants_divisions > 49
#	}
#	abort = {
#		ai_wants_divisions < 50
#	}
#
#	ai_strategy = {
#		type = role_ratio
#		id = marines
#		value = 0
#	}
#
#	#ai_strategy = {
#	#	type = role_ratio
#	#	id = infantry
#	#	value = 0
#	#}
#}

default_mobile_production = {
	enable = {
		ai_wants_divisions > 11
		has_tech = motorised_infantry
	}
	abort = {
		ai_wants_divisions < 12
	}

	ai_strategy = {
		type = role_ratio
		id = mobile
		value = 2
	}
}

default_armored_production = {
	enable = {
		ai_wants_divisions > 49
	}
	abort = {
		ai_wants_divisions < 50
	}

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

highered_armored_production = {
	enable = {
		num_of_military_factories > 69
	}
	abort = {
		num_of_military_factories < 70
	}

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

more_naval_focused_nation = {
	enable = {
		date > "1941.1.1"  # Delaying it by a couple of years
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = unit_ratio
		id = capital_ship
		value = 2		 #1 to 2
	}

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

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

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

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

	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 = 4
	}

}

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_market_stockpile_management = {
	enable = {
		always = yes
	}
	abort_when_not_enabled = yes

	# Hold your trains there, partner
	ai_strategy = {
		type = equipment_market_for_sale_threshold
		id = train
		value = 20  # only start considering selling trains if surplus more than 20
	}
	ai_strategy = {
		type = equipment_market_min_for_sale
		id = train
		value = 5  # only put up for sale in chunks of 5
	}
	ai_strategy = {
		type = equipment_market_for_sale_factor
		id = train
		value = -50  # put fewer trains up for sale
	}

	# Better not put all your boats up for sail
	# ai_strategy = {  # Commented because handled dynamically in code through the EQUIPMENT_MARKET_WANTED_CONVOY_USAGE_RATIO define
	# 	type = equipment_market_for_sale_threshold
	# 	id = convoy
	# 	value = 100  # only start considering selling convoys if surplus more than 100
	# }
	ai_strategy = {
		type = equipment_market_min_for_sale
		id = convoy
		value = 20  # only put up for sale in chunks of 20
	}

	# Don't let all your planes just fly out the window.
	# Only sell planes if we have more than one airwing in surplus.
	ai_strategy = {
		type = equipment_market_for_sale_threshold
		id = fighter
		value = 100
	}
	ai_strategy = {
		type = equipment_market_for_sale_threshold
		id = cas
		value = 100
	}
	ai_strategy = {
		type = equipment_market_for_sale_threshold
		id = cv_fighter
		value = 100
	}
	ai_strategy = {
		type = equipment_market_for_sale_threshold
		id = cv_cas
		value = 100
	}
	ai_strategy = {
		type = equipment_market_for_sale_threshold
		id = tactical_bomber
		value = 100
	}
	ai_strategy = {
		type = equipment_market_for_sale_threshold
		id = strategic_bomber
		value = 100
	}
}

default_market_stockpile_management_if_at_war = {
	enable = {
		has_war = yes
		# something something preparing for war?
	}
	abort_when_not_enabled = yes

	# Don't sell stuff that we need for the war
	ai_strategy = {
		type = equipment_market_for_sale_threshold
		id = infantry
		value = 20000
	}
	ai_strategy = {
		type = equipment_market_for_sale_threshold
		id = support
		value = 6000
	}
	ai_strategy = {
		type = equipment_market_for_sale_threshold
		id = artillery
		value = 1000
	}
	ai_strategy = {
		type = equipment_market_for_sale_threshold
		id = fighter
		value = 200
	}
	ai_strategy = {
		type = equipment_market_for_sale_threshold
		id = motorized
		value = 1000
	}
	ai_strategy = {
		type = equipment_market_for_sale_threshold
		id = train
		value = 50
	}
	ai_strategy = {
		type = equipment_market_for_sale_threshold
		id = convoy
		value = 50
	}
}

default_market_convoy_purchases = {
	enable = {
		naval_base > 0  # not land-locked
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = equipment_market_buying_threshold
		id = convoy
		value = 30  # Consider buying if we have too few (less than 30) convoys. Also interacts with the EQUIPMENT_MARKET_WANTED_CONVOY_USAGE_RATIO define.
	}
}

DEFAULT_early_template_design = {
	enable = {
		date < 1940.1.1
	}
	abort = {
		date > 1940.1.1
	}

	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 = 50
	}

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

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

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

	ai_strategy = {
		type = template_prio
		id = infantry
		value = 60
	}
}

DEFAULT_midlate_template_design = {
	enable = {
		date > 1940.1.1
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = template_prio
		id = mechanized
		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 = 20
	}

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

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

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

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

save_admiral_pp_for_later = {
	enable = {
		has_war = no
		threat < 0.3
		has_political_power < 200
	}
	abort = {
		OR = {
			has_war = yes
			threat > 0.3
			has_political_power > 200
		}
	}

	ai_strategy = { # dont burn PP on admirals (can still get free ones)
		type = pp_spend_priority
		id = admiral
		value = -100
	}
}

do_not_waste_pp_if_saving_for_manpower_laws = {

	enable = {
		manpower_per_military_factory < 500
		has_war = yes
	}
	abort = {
		OR = {
			manpower_per_military_factory > 500
			has_war = no
		}
	}

	ai_strategy = {
		type = pp_spend_priority
		id = relation
		value = -9999
	}

	ai_strategy = {
		type = pp_spend_priority
		id = guarantee
		value = -9999
	}
}

build_intelligence_agency_as_major = {
	enable = {
		is_major = yes
		OR = {
			has_war = yes
			date > 1938.1.1
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = intelligence_agency_usable_factories
		value = 5
	}

}

build_intelligence_agency = {
	enable = {
		date > 1940.1.1
		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 > 1940.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
	}
}

add_intelligence_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
	}
}

ask_foreign_manpower_as_major = {
	enable = {
		is_major = yes
		garrison_manpower_need > 200000
	}

	abort = {
		garrison_manpower_need < 100000
	}

	ai_strategy = {
		type = asking_foreign_garrison
		value = 100
		# id = ITA # id is optionnal. If it is filled, the value will just apply for this country. If not, the value will apply for all countries.
	}
}

more_upgrades_as_spymaster = {

	enable = {
		is_spymaster = yes
	}

	abort = {
		is_spymaster = no
	}

	ai_strategy = {
		type = agency_ai_base_num_factories_factor
		value = -50    # -50% on the define
	}

	ai_strategy = {
		type = agency_ai_per_upgrade_factories_factor
		value = -25    # -25% on the define
	}
}


put_garrisons_on_high_prio = {
	enable = {
		always = yes
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = garrison_reinforcement_priority
		value = 100 # positive is high prio, negative is low prio
	}
}

default_spyplanes_production = {
	enable = {
		OR = {
			has_tech = scout_plane1
			has_tech = photo_reconnaisance
		}
		is_major = yes
		#OR = {
		#	has_equipment = {
		#		scout_plane_equipment > 50
		#	}
		#	has_deployed_air_force_size = {
		#		size > 50
		#		type = scout_plane
		#	}
		#}
	}

	abort_when_not_enabled = yes

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

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

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

minors_dont_spy = {
	enable = {
		OR = {
			has_tech = scout_plane1
			has_tech = photo_reconnaisance
		}
		is_major = no
	}

	abort_when_not_enabled = yes

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

default_produce_some_trucks_for_buffer = {
	enable = {
		num_of_military_factories > 12
		has_tech = tech_trucks
		has_equipment = { motorized_equipment < 3000 }
	}
	abort_when_not_enabled = yes

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

default_produce_floating_harbors = {
	enable = {
		is_historical_focus_on = no
		has_war = yes
		num_of_naval_factories > 25
		num_of_military_factories > 40 # floating harbors are used for invasions. Why do large invasions if you don't have the industrial capacity?
	}
	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
	}
}