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

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

# Example of strategy for intelligence agency
#example_strategy = {
#
#	enable = {
#		original_tag = FRA
#	}
#
#	ai_strategy = {
#		type = intelligence_agency_usable_factories
#		# no need of id for this one
#		value = 10
#	}
#
#	ai_strategy = {
#		type = intelligence_agency_branch_desire_factor
#		id = branch_defense
#		value = -50    # -50% on the AI weight
#	}
#}


# example unit buffer strategy. this strategy will make ai buffer/garrison some units in a target area  which can be used in orders that is in target areas
# 
# ai_strategy = {
# 	type = put_unit_buffers
# 	
#	# ratio of total armeis in country to be buffered
# 	ratio = 0.4
#
#	# 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 = { 
# 		125
# 		126
# 		127
# 		128
# 		129
# 		338
# 		123
# 		122 
# 	}
# 	
#	# ai areas that the orders will use these buffers in
# 	area = europe
# 	area = asia
# 	
# 	# by default if you have orders in target areas, the buffer will request less units. 
#	# you can override this to disable the feature
# 	subtract_invasions_from_need = yes
# 	subtract_fronts_from_need = yes
# }


#used for controlling invasion or regular fronts
#ai_strategy = {
# 	type = front_control
#
#	#you can define a target in following ways. you can define more than one
#
#	tag = GER 				# target against a specific country
#	state = 42 				# target on a state
#	strategic_region = 65	# target on a strategic region
#	area = europe			# target on a specific ai area
#	country_trigger = { always = no } 	# a trigger to check agaisnt a specific country. scope is enemy country from scope is our country
#	state_trigger = { always = no } 	# a trigger to check agaisnt a state. scope is state. from scope is enemy country from.from scope is our country
#
#	ratio = 0.0 # the strategy is enabled only if ratio of the front covered by this strat's targets greater than this ratio
#
#	priority = 0 # default 0, higher prio strats will override lower
#	ordertype = front # front or invasion. if set this strategy will only apply to that specific order type
#	execution_type = careful # one of careful balanced rush rush_weak. if set will override the execution type of front (only for front orders)
#	execute_order = yes # yes or no. if set will override execute or not decision of front
#	manual_attack = yes # default yes. if no ai will not do manual pokes at enemy (only for front orders)
#}

#used for increasing/decreasing unit requests for invasions or fronts
#ai_strategy = {
#	# use one of them
# 	type = front_unit_request
# 	type = invasion_unit_request
#
#	#invasions will check invasion target, fronts will check provinces at front
#
#	tag = GER 				# province of a specific country
#	state = 42 				# province on a state
#	strategic_region = 65	# province on a strategic region
#	area = europe			# province on a specific ai area
#	country_trigger = { always = no } 	# a trigger to check agaisnt a specific country. scope is enemy country from scope is our country
#	state_trigger = { always = no } 	# a trigger to check agaisnt a state. scope is state. from scope is enemy country from.from scope is our country
#
#	value = 40				# will be added as a factor over regular requests
#}

# makes ai do an operation 
# ai_strategy = {
# 	type = operative_operation
# 	operation = operation_id
# 	value = 900 # score compared to other operations & missions
# 	operation_target = GER # target
#	state = 1 # if specified ai will prefer this states for targeted operations assuming they are valid target
#	state = 2
#	region = 1 # if specified ai will prefer this regions for targeted operations assuming they are valid
#	region = 2
#	priority = 100 # ai will prefer state/region of the highest prio strategy
# }

# ai_strategy = {
# 	type = operative_mission
# 	mission = build_intel_network # mission token
# 	value = 800 # score compared to other operations & missions
# 	mission_target = GER # target
#	state = 1 # if specified ai will prefer this states for targeted operations assuming they are valid target
#	state = 2
#	priority = 100 # ai will prefer state of the highest prio strategy
# }

default_unit_production = {
	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 = 5
	}
	
	ai_strategy = {
		type = unit_ratio
		id = naval_bomber
		value = 5
	}
	
	
	# 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
	}
}

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

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

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

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

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

	ai_strategy = {
		type = area_priority
		id = scandinavia
		value = 100
	}
	
	ai_strategy = {
		type = area_priority
		id = north_america
		value = 100
	}
	
	ai_strategy = {
		type = area_priority
		id = south_america
		value = 50
	}
	
	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 = suez
		value = 50
	}
	
	ai_strategy = {
		type = area_priority
		id = pacific
		value = 300
	}
	
	ai_strategy = {
		type = area_priority
		id = oceania
		value = 80
	}

}

default_area_priority_non_africa = {
    enable = {
        NOT = { capital_scope = { is_on_continent = africa } }
    }

    ai_strategy = {
        type = area_priority
        id = africa
        value = -90
    }
    ai_strategy = {
        type = area_priority
        id = suez
        value = -90
    }
}

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_naval_treaty_trigger = yes
	}

	abort = {
		not = { has_naval_treaty_trigger = yes }
	}

	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_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_template_design = {
	enable = {
		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
		}
	}

	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 = {
		has_tech = scout_plane1
		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 = {
		has_tech = scout_plane1
		is_major = no
	}

	abort_when_not_enabled = yes

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