Ragnarok_home_land_is_safe = {
	enable = {
		has_war_with = GER
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = -100
	}

	ai_strategy = {
		type = garrison
		value = -500
	}
	ai_strategy = {
		type = spare_unit_factor
		value = 200
	}
}

#####################################################################################################
### FRANCE
#####################################################################################################

Ragnarok_FRA_prepare_forces = {
	allowed = {
		original_tag = FRA
	}
	enable = {
		GER = { has_completed_focus = GER_rhineland }
	}
	abort = {
		has_war_with = GER
	}
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 25
	}

	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.65
		states = {
			29 # Nord-Pas-de-Calais
			18 # Champagne
			785 # Picardy
			16 # Ile de France
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
	
	ai_strategy = {
		type = front_unit_request
		tag = GER
		value = 120
	}
	ai_strategy = {
		type = front_unit_request
		tag = BEL
		value = 60
	}
	ai_strategy = {
		type = front_unit_request
		tag = LUX
		value = 60
	}
	ai_strategy = {
		type = front_unit_request
		tag = SWI
		value = 20
	}
}

Ragnarok_FRA_defend_north = {
	allowed = {
		original_tag = FRA
	}
	enable = {
		has_war_with = GER
	}
	abort = {
		has_capitulated = yes
	}
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 115 # to offset Ragnarok_home_land_is_safe
	}

	ai_strategy = {
		type = put_unit_buffers
		ratio = 1.0
		states = {
			29 # Nord-Pas-de-Calais
			18 # Champagne
			785 # Picardy
			16 # Ile de France
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
}

#####################################################################################################
### ENGLAND
#####################################################################################################

Ragnarok_defend_northern_france = {
	allowed = {
		original_tag = ENG
	}
	enable = {
		has_war_with = GER
	}
	abort = {
		FRA = { has_capitulated = yes }
	}
	
	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.5
		states = {
			29 # Nord-Pas-de-Calais
			18 # Champagne
			785 # Picardy
			16 # Ile de France
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
}

Ragnarok_ENG_defend_london = {
	allowed = {
		original_tag = ENG
	}
	enable = {
		has_war_with = GER
	}
	abort = {
		FRA = { has_capitulated = yes }
	}
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 105 # to offset Ragnarok_home_land_is_safe
	}

	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.4
		states = {
			126 # Greater London Area
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
}

Ragnarok_ENG_defend_ports = {
	allowed = {
		original_tag = ENG
	}
	enable = {
		FRA = { has_capitulated = yes }
	}
	abort = {
		has_capitulated = yes
	}
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 112 # to offset Ragnarok_home_land_is_safe
	}

	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.8
		states = {
			126 # Greater London Area
			127 # Sussex
			123 # South-West England
			338 # Gloucestershire
			122 # Wales
			125 # East Anglia
			130 # Yorkshire
			132 # Lancashire
			131 # Northumberland
			121 # Lothian
			133 # Lanark
			120 # Scottish Highlands
		}
		subtract_invasions_from_need = yes
		subtract_fronts_from_need = no
	}

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

Ragnarok_ENG_defend_mediterranean = {
	allowed = {
		original_tag = ENG
	}
	enable = {
		OR = {
			GRE = { has_capitulated = yes }
			TUR = { has_capitulated = yes }
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = area_priority
		id = suez
		value = 30
	}
	
	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.1
		states = {
			446 # Suez
			447 # Alexandria
		}
		subtract_invasions_from_need = yes
		subtract_fronts_from_need = yes
	}

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

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

#####################################################################################################
### UNITED STATES
#####################################################################################################

Ragnarok_USA_defend_belgium_north_france = {
	allowed = {
		original_tag = USA
	}
	enable = {
		has_war_with = GER
	}
	abort = {
		OR = {
			BEL = { has_capitulated = yes }
			FRA = { has_capitulated = yes }
		}
	}
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 115 # to offset Ragnarok_home_land_is_safe
	}

	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.5
		states = {
			6 # Vlaanderen
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.5
		states = {
			29 # Nord-Pas-de-Calais
			18 # Champagne
			785 # Picardy
			16 # Ile de France
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
}

Ragnarok_USA_defend_north_france = {
	allowed = {
		original_tag = USA
	}
	enable = {
		BEL = { has_capitulated = yes }
	}
	abort = {
		FRA = { has_capitulated = yes }
	}
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 110 # to offset Ragnarok_home_land_is_safe
	}
	
	ai_strategy = {
		type = put_unit_buffers
		ratio = 1.0
		states = {
			29 # Nord-Pas-de-Calais
			18 # Champagne
			785 # Picardy
			16 # Ile de France
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
}

# Prepare forces for invading Europe
Ragnarok_USA_defend_england = {
	allowed = {
		original_tag = USA
	}
	enable = {
		FRA = { has_capitulated = yes }
	}
	abort = {
		OR = {
			ENG = { has_capitulated = yes }
			ENG = { surrender_progress > 0.8 }
		}
	}
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 125 # to offset Ragnarok_home_land_is_safe
	}

	ai_strategy = {
		type = put_unit_buffers

		order_id = 2

		# Southern England
		states = {
			125
			126
			127
			128
			129
			338
			123
			122
		}

		ratio = 0.6

		area = europe

		subtract_invasions_from_need = yes
	}

	ai_strategy = {
		type = put_unit_buffers

		order_id = 1

		# North Africa
		states = {
			290
			461
			459
			460
			458
			665
			448
			449
			450
			451
			452
			447
		}

		ratio = 0.4

		area = europe

		subtract_invasions_from_need = yes
	}
}

Ragnarok_USA_defend_home_land = {
	allowed = {
		original_tag = USA
	}
	enable = {
		OR = {
			ENG = { has_capitulated = yes }
			ENG = { surrender_progress > 0.8 }
		}
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 112 # to offset Ragnarok_home_land_is_safe
	}
}

#####################################################################################################
### ITALY
#####################################################################################################

Ragnarok_ITA_prepare_forces = {
	allowed = {
		original_tag = ITA
	}
	enable = {
		has_war = no
		GER = { has_completed_focus = GER_anschluss }
	}
	abort = {
		has_war_with = GER
	}	
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 20
	}

	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.4
		states = {
			158 # Piemonte
			159 # Lombardia
			160 # Veneto
			161 # Emilia Romagna
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
	
	ai_strategy = {
		type = front_unit_request
		tag = GER
		value = 300
	}
	ai_strategy = {
		type = front_unit_request
		tag = YUG
		value = 60
	}
	ai_strategy = {
		type = front_unit_request
		tag = SWI
		value = -40
	}
	ai_strategy = {
		type = front_unit_request
		tag = FRA
		value = -20
	}
}

Ragnarok_ITA_defence_in_depth = {
	allowed = {
		original_tag = ITA
	}
	enable = {
		has_war_with = GER
	}
	abort = {
		OR = {
			has_capitulated = yes
			surrender_progress > 0.8
		}
	}
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 110 # to offset Ragnarok_home_land_is_safe
	}

	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.7
		states = {
			158 # Piemonte
			159 # Lombardia
			160 # Veneto
			161 # Emilia Romagna
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.3
		states = {
			162 # Toscana
			2 # Lazio
			117 # Campania
			849 # Puglia
			115 # Sicilia
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
}

#####################################################################################################
### BELGIUM
#####################################################################################################

Ragnarok_BEL_defend_critical_areas = {
	allowed = {
		original_tag = BEL
	}
	enable = {
		GER = { has_completed_focus = GER_rhineland }
	}
	abort = {
		has_capitulated = yes
	}
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 50
	}
	
	ai_strategy = {
		type = put_unit_buffers
		ratio = 1.0
		states = {
			6 # Vlaanderen
			34 # Wallonie
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
	
	ai_strategy = {
		type = front_unit_request
		tag = GER
		value = 100
	}
	ai_strategy = {
		type = front_unit_request
		tag = HOL
		value = 60
	}
	ai_strategy = {
		type = front_unit_request
		tag = LUX
		value = 60
	}
	ai_strategy = {
		type = front_unit_request
		tag = FRA
		value = -100
	}
}

#####################################################################################################
### NETHERLANDS
#####################################################################################################

Ragnarok_HOL_defend_critical_areas = {
	allowed = {
		original_tag = HOL
	}
	enable = {
		GER = { has_completed_focus = GER_rhineland }
	}
	abort = {
		has_capitulated = yes
	}
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 50
	}
	
	ai_strategy = {
		type = put_unit_buffers
		ratio = 1.0
		states = {
			36 # Friesland
			7 # Holland
			35 # Brabant
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
	
	ai_strategy = {
		type = front_unit_request
		tag = GER
		value = 100
	}
	ai_strategy = {
		type = front_unit_request
		tag = BEL
		value = -100
	}
}

#####################################################################################################
### POLAND
#####################################################################################################

Ragnarok_POL_defend_critical_areas = {
	allowed = {
		original_tag = POL
	}
	enable = {
		always = yes
	}
	abort = {
		has_war_with = GER
	}
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 5
	}

	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.2
		states = {
			10 # Warszawa
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
}

Ragnarok_POL_defend_critical_areas_war = {
	allowed = {
		original_tag = POL
	}
	enable = {
		has_war_with = GER
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 105 # to offset Ragnarok_home_land_is_safe
	}

	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.15
		states = {
			10 # Warszawa
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
}

#####################################################################################################
### HUNGARY/YUGOSLAVIA
#####################################################################################################

Ragnarok_HUN_YUG_garrisons = {
	allowed = {
		OR = {
			original_tag = HUN
			original_tag = YUG
		}
	}
	enable = {
		OR = {
			GER = { has_completed_focus = GER_anschluss }
			has_war_with = GER
		}
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 115 # to offset Ragnarok_home_land_is_safe
	}
}

#####################################################################################################
### TURKEY
#####################################################################################################

Ragnarok_TUR_defend_critical_areas = {
	allowed = {
		original_tag = TUR
	}
	enable = {
		has_war_with = GER
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 105 # to offset Ragnarok_home_land_is_safe
	}

	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.1
		states = {
			797 # Istanbul
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
}

#####################################################################################################
### NORWAY/SWEDEN/FINLAND
#####################################################################################################

Ragnarok_NOR_SWE_FIN_garrisons = {
	allowed = {
		OR = {
			original_tag = NOR
			original_tag = SWE
			original_tag = FIN
		}
	}
	enable = {
		has_war_with = GER
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 120 # to offset Ragnarok_home_land_is_safe
	}
}

#####################################################################################################
### SOVIET UNION
#####################################################################################################
Ragnarok_SOV_defend_key_areas = {
	allowed = {
		original_tag = SOV
	}
	enable = {
		is_neighbor_of = GER
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 105 # to offset Ragnarok_home_land_is_safe
	}

	ai_strategy = {
		type = put_unit_buffers
		ratio = 1.0
		states = {
			219 # Moscow
			246 # Rzhev
			242 # Smolensk
			224 # Bryansk
			223 # Tula
			195 # Leningrad
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
}

#####################################################################################################
### MANCHUKUO/MENGKUKUO/TANNU TUVA
#####################################################################################################
Ragnarok_MAN_defend_soviet_union = {
	allowed = {
		original_tag = MAN
	}
	enable = {
		has_war_with = GER
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 200 # to offset Ragnarok_home_land_is_safe
	}

	ai_strategy = {
		type = put_unit_buffers
		ratio = 1.0
		states = {
			195 # Leningrad
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
}

Ragnarok_MEN_TAN_defend_soviet_union = {
	allowed = {
		OR = {
			original_tag = MEN
			original_tag = TAN
		}
	}
	enable = {
		has_war_with = GER
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 200 # to offset Ragnarok_home_land_is_safe
	}

	ai_strategy = {
		type = put_unit_buffers
		ratio = 1.0
		states = {
			219 # Moscow
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
}

#####################################################################################################
### JAPAN
#####################################################################################################

Ragnarok_JAP_garrison_prewar = {
	allowed = {
		original_tag = JAP
	}
	enable = {
		always = yes
	}
	abort = {
		has_war_with = GER
	}
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 12
	}
}

Ragnarok_JAP_garrison_late_war = {
	allowed = {
		original_tag = JAP
	}
	enable = {
		SOV = { has_capitulated = yes }
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = role_ratio
		id = garrison
		value = 108 # to offset Ragnarok_home_land_is_safe
	}
}