# 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
	enable = {
		always = 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 = 5
	}

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

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

	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_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"
		}
	}

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

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

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

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

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

	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
	}

}

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

	enable = {
		is_historical_focus_on = yes
		date < 1939.1.1
	}

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

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
	}

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

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

default_paratroopers_production = {
	enable = {
		NOT = { original_tag = GER }
		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
	}
}

build_patrol_bombers = {

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

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

default_garrison_production = {
	enable = {
		NOT = {
			original_tag = GER
			original_tag = SOV
			original_tag = USA
			original_tag = CHI
			original_tag = FRA
			original_tag = JAP
			original_tag = ENG
		}
		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 = {
		NOT = { original_tag = GER }
		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 = {
#		NOT = { original_tag = GER }
#		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 = {
		NOT = { original_tag = GER }
		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 = {
		NOT = {
			OR = {
				original_tag = GER
				original_tag = CZE
				original_tag = SOV
			}
		}
		ai_wants_divisions > 49
	}
	abort = {
		ai_wants_divisions < 50
	}

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

highered_armored_production = {
	enable = {
		NOT = { original_tag = GER }
		num_of_military_factories > 69
	}
	abort = {
		num_of_military_factories < 70
	}

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

slightly_naval_focused_nation = {
	enable = {
		OR = {
			tag = JAP
			tag = USA
			tag = ENG
			tag = FRA
			tag = ITA
		}
	}

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

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

more_naval_focused_nation = {
	enable = {
		OR = {
			tag = JAP
			tag = USA
			tag = ENG
		}
		date > "1941.1.1" #Delaying it by a couple of years
	}

	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_area_priority = {
	enable = {
		NOT = { original_tag = GER }
		NOT = { original_tag = FRA }
		NOT = { original_tag = JAP }
	}

	ai_strategy = {
		type = area_priority
		id = europe
		value = 100
	}

	ai_strategy = {
		type = area_priority
		id = scandinavia
		value = 0
	}

	ai_strategy = {
		type = area_priority
		id = north_america
		value = 100
	}

	ai_strategy = {
		type = area_priority
		id = south_america
		value = 40
	}

	ai_strategy = {
		type = area_priority
		id = asia
		value = 75
	}

	ai_strategy = {
		type = area_priority
		id = middle_east
		value = 50
	}

	ai_strategy = {
		type = area_priority
		id = africa
		value = 10
	}

	ai_strategy = {
		type = area_priority
		id = suez
		value = 50
	}

	ai_strategy = {
		type = area_priority
		id = pacific
		value = 50
	}

	ai_strategy = {
		type = area_priority
		id = oceania
		value = 75
	}

}

default_area_priority_non_africa = {
    enable = {
        NOT = { original_tag = ITA }
        NOT = { original_tag = FRA }
        NOT = { original_tag = USA }
        NOT = { original_tag = ENG }
        NOT = { is_subject_of = ENG }
        NOT = { capital_scope = { is_on_continent = africa } }
    }

    ai_strategy = {
        type = area_priority
        id = africa
        value = -70
    }
    ai_strategy = {
        type = area_priority
        id = suez
        value = -40
    }
}

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 # double base stockpile #from 25 to 35
	}
}


dont_build_capitals_if_on_treaty = {
	enable = {
		has_idea = MTG_naval_treaty_adherent
	}

	abort = {
		OR = {
				original_tag = ITA
				original_tag = ENG
				NOT = { has_idea = MTG_naval_treaty_adherent }
			}	
	}

	ai_strategy = {
		type = unit_ratio
		id = capital_ship
		value = -2		 #1 to 2
	}
	ai_strategy = {
		type = role_ratio
		id = naval_capital_bb
		value = -100
	}

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

DEFAULT_early_template_design = {
	enable = {
		NOT = {
			OR = {
				tag = GER
				tag = ENG
				tag = SOV
				tag = ITA
				tag = JAP
				tag = USA
				tag = POL
			}
		}
		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 = {
		NOT = {
			OR = {
				tag = GER
				tag = ENG
				tag = SOV
				tag = ITA
				tag = JAP
				tag = USA
				tag = POL
			}
		}
		date > 1940.1.1
	}

	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
			AND = {
				original_tag = ETH
				is_government_in_exile = yes
			}
		}
	}

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

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

addintelligence_agency_normal_upgrade_prio = {
	enable = {
		always = 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
	}

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

###

comintern_avoid_starting_wars_during_endgame = { #Sov should avoid attacking allies while ww2 is still going on

	allowed = {
		OR = {
			original_tag = SOV
			is_in_faction_with = SOV
		}
	}
	enable = {
		is_historical_focus_on = yes
		SOV = { has_government = communism }
		OR = {
			USA = {
				has_capitulated = no
				has_war_with = JAP
			}
			ENG = {
				has_capitulated = no
				has_war_with = JAP
			}
		}
		date > 1943.1.1
		date < 1945.1.1
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = avoid_starting_wars
		value = -400
	}
	ai_strategy = {
		type = conquer
		id = POL
		value = -400 #REALLY dont try and conquer poland
	}
	ai_strategy = {
		type = befriend
		id = "POL"
		value = 200
	}
	ai_strategy = {
		type = conquer
		id = JAP
		value = 400 #These values offset each other. Basically we won't start wars with anyone except for japan while this strategy is active
	}
	ai_strategy = {
		type = conquer
		id = FIN
		value = 400 #These values offset each other. Basically we won't start wars with anyone except for finland while this strategy is active
	}
	ai_strategy = {
		type = conquer
		id = PER
		value = 400 #These values offset each other. Basically we won't start wars with anyone except for iran while this strategy is active
	}
}

allies_avoid_starting_wars_during_endgame = { #Allies should avoid attacking.. well, anyone while ww2 is in endgame
	allowed = {
		OR = {
			tag = ENG
			is_in_faction_with = ENG
		}
	}
	enable = {
		is_historical_focus_on = yes
		ENG = { has_government = democratic }
		OR = {
			tag = ENG
			is_in_faction_with = ENG
		}
		has_war_with = JAP
		JAP = {
			has_government = fascism #Just to make sure we're not looking at a puppet or sth
		}
		date > 1943.1.1
		date < 1945.1.1
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = avoid_starting_wars
		value = -400
	}
}
