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

put_garrisons_on_high_prio = {
	enable = {
		always = yes
	}
	abort = {
		always = no
	}

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

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

default_stockpile_management = {
	enable = {
		num_divisions > 150
	}

	abort = {
		num_divisions < 130
	}

	ai_strategy = {
		type = equipment_stockpile_surplus_ratio
		value = 30 # add this to default PRODUCTION_EQUIPMENT_SURPLUS_FACTOR
	}
}

default_market_stockpile_management = {
	enable = {
		always = yes
		# NOT = { original_tag = GER } # commented until actually needs override
	}
	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 = {
		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 = 30  # only put up for sale in chunks of 5
	}

	# 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?
		# NOT = { original_tag = GER } # commented until actually needs override
	}
	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
	}
}

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

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

default_become_spymaster_major = {
	allowed = {	
		has_dlc = "La Resistance"
	}
	enable = {
		is_major = yes 
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = become_spymaster
		value = 30
	}
}
default_become_spymaster_minor = {
	allowed = {	
		has_dlc = "La Resistance"
	}
	enable = {
		is_major = no 
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = become_spymaster
		value = 2
	}
}

default_become_head_of_crypto = {
	allowed = {	
		has_dlc = "No Compromise, No Surrender"
		has_dlc = "La Resistance"
	}
	enable = {
		always = yes
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = become_head_of_crypto
		value = 2
	}
}

default_become_head_of_operations = {
	allowed = {	
		has_dlc = "No Compromise, No Surrender"
		has_dlc = "La Resistance"
	}
	enable = {
		always = yes
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = become_head_of_operations
		value = 2
	}
}

default_become_counter_intel = {
	allowed = {	
		has_dlc = "No Compromise, No Surrender"
		has_dlc = "La Resistance"
	}
	enable = {
		always = yes
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = become_head_of_counter_intel
		value = 2
	}
}

default_become_supreme_commander = {
	allowed = {	
		has_dlc = "No Compromise, No Surrender"
		has_dlc = "La Resistance"
	}
	enable = {
		always = yes
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = spent_faction_initiative_priority
		id = unlock_faction_commander
		value = 2
	}
}

default_become_faction_leader = {
	enable = {
		always = yes
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = pp_spend_priority
		id = become_faction_leader
		value = 100
	}
}

default_add_faction_facility = {
	enable = {
		always = yes
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = spent_faction_initiative_priority
		id = program
		value = 5
	}
}

default_unlock_doctrine_sharing = {
	enable = {
		always = yes
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = spent_faction_initiative_priority
		id = unlock_doctrine_sharing
		value = 10
	}
}

default_assign_supportive_scientist = {

	enable = {
		OR = { 
			can_assign_supportive_scientist_to_faction = specialization_land
			can_assign_supportive_scientist_to_faction = specialization_nuclear
			can_assign_supportive_scientist_to_faction = specialization_naval
			can_assign_supportive_scientist_to_faction = specialization_naval
		}
		has_political_power > 74 # mainly to add some time padding for the player to react, and to not spend pp on it if there are cheaper things that we could want to do 
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = pp_spend_priority
		id = supportive_scientist
		value = 25
	}
}

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

# Build some rockets (simple strats to have a minimum production at least )
if_we_can_build_v1_rockets_we_want_rockets = {
	enable = {
		is_special_project_completed = sp:sp_rockets_flying_bomb
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = equipment_production_min_factories_archetype
		id = guided_missile_equipment
		value = 1
	}
}

if_we_can_build_v2_rockets_we_want_v2_rockets = {
	enable = {
		is_special_project_completed = sp:sp_rockets_ballistic_missile
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = equipment_production_min_factories_archetype
		id = ballistic_missile_equipment
		value = 1
	}
}
if_we_can_build_sams_we_want_sams = {
	enable = {
		is_special_project_completed = sp:sp_rockets_ground_to_air_missile
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = equipment_production_min_factories_archetype
		id = sam_missile_equipment
		value = 1
	}
}
if_we_can_build_nuclear_missiles_we_want_nuclear_missiles = {
	enable = {
		is_special_project_completed = sp:sp_nuclear_warheads
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = equipment_production_min_factories_archetype
		id = nuclear_missile_equipment
		value = 1
	}
}
