#########################################################
#	Production Strategies
#########################################################

EAI_SOV_CHL_focus_on_infantry_equipment_over_armor = {
	allowed = { tag = SOV }
	enable = {
		EAI_MODE_challenging = yes
		check_variable = { deployed_army_manpower_k < 3950 }
	}
	abort = {
		NOT = {
			AND = {
				EAI_MODE_challenging = yes
				check_variable = { deployed_army_manpower_k < 4000 }
			}
		}
	}

	ai_strategy = { type = build_army id = infantry value = 500 }
	ai_strategy = { type = equipment_production_factor id = armor value = -10 }
	ai_strategy = { type = role_ratio id = armor value = -20 }
	ai_strategy = { type = equipment_production_min_factories_archetype id = infantry_equipment value = 10 }
}

EAI_SOV_focus_on_infantry_equipment_over_armor = {
	allowed = { tag = SOV }
	enable = {
		EAI_MODE_normal = yes
		check_variable = { deployed_army_manpower_k < 2950 }
	}
	abort = {
		NOT = {
			AND = {
				EAI_MODE_normal = yes
				check_variable = { deployed_army_manpower_k < 3000 }
			}
		}
	}

	ai_strategy = { type = build_army id = infantry value = 500 }
	ai_strategy = { type = equipment_production_factor id = armor value = -10 }
	ai_strategy = { type = role_ratio id = armor value = -20 }
	ai_strategy = { type = equipment_production_min_factories_archetype id = infantry_equipment value = 10 }
}

EAI_SOV_CHL_focus_on_infantry_equipment_min_production = {
	allowed = { tag = SOV }
	enable = {
		EAI_MODE_challenging = yes
		check_variable = { deployed_army_manpower_k < 4450 }
		num_of_military_factories > 50
	}
	abort = {
		NOT = {
			AND = {
				EAI_MODE_challenging = yes
				check_variable = { deployed_army_manpower_k < 4500 }
				num_of_military_factories > 40
			}
		}
	}

	ai_strategy = { type = equipment_production_min_factories_archetype id = artillery_equipment value = 1 }
	ai_strategy = { type = equipment_production_min_factories_archetype id = support_equipment value = 12 }
	ai_strategy = { type = equipment_production_min_factories_archetype id = motorized_equipment value = 2 }
	ai_strategy = { type = equipment_production_min_factories_archetype id = anti_air_equipment value = 2 }
}

EAI_SOV_focus_on_infantry_equipment_min_production = {
	allowed = { tag = SOV }
	enable = {
		EAI_MODE_normal = yes
		check_variable = { deployed_army_manpower_k < 2950 }
		num_of_military_factories > 50
	}
	abort = {
		NOT = {
			AND = {
				EAI_MODE_normal = yes
				check_variable = { deployed_army_manpower_k < 3000 }
				num_of_military_factories > 40
			}
		}
	}

	ai_strategy = { type = equipment_production_min_factories_archetype id = artillery_equipment value = 3 }
	ai_strategy = { type = equipment_production_min_factories_archetype id = support_equipment value = 4 }
	ai_strategy = { type = equipment_production_min_factories_archetype id = motorized_equipment value = 2 }
	ai_strategy = { type = equipment_production_min_factories_archetype id = anti_air_equipment value = 2 }
}

EAI_SOV_air_production = {
	allowed = { tag = SOV }
	enable = { always = yes }
	abort_when_not_enabled = yes

	ai_strategy = { type = air_factory_balance value = 75 }
}

EAI_SOV_reduce_air_production = {
	allowed = { tag = SOV }
	enable = {
		surrender_progress > 0
		OR = {
			AND = {
				check_variable = { EAI_FOCUS/AIR/fighter = global.EAI_ON }
				has_deployed_air_force_size = { size > 6000 type = fighter }
			}
			AND = {
				check_variable = { EAI_FOCUS/AIR/heavy_fighter = global.EAI_ON }
				has_deployed_air_force_size = { size > 4000 type = heavy_fighter }
			}
		}
	}
	abort = {
		NOT = {
			surrender_progress > 0
			OR = {
				AND = {
					check_variable = { EAI_FOCUS/AIR/fighter = global.EAI_ON }
					has_deployed_air_force_size = { size > 3000 type = fighter }
				}
				AND = {
					check_variable = { EAI_FOCUS/AIR/heavy_fighter = global.EAI_ON }
					has_deployed_air_force_size = { size > 2000 type = heavy_fighter }
				}
			}
		}
	}
	
	ai_strategy = { type = air_factory_balance value = -50 }
}

EAI_SOV_emergency_increase_air_production_over_armor = {
	allowed = { tag = SOV }
	enable = {
		surrender_progress > 0
		has_deployed_air_force_size = { size < 1500 type = fighter }
	}
	abort = {
		NOT = {
			AND = {
				has_deployed_air_force_size = { size < 3000 type = fighter }
			}
		}
	}
	
	ai_strategy = { type = air_factory_balance value = 25 }
	ai_strategy = { type = equipment_production_factor id = armor value = -10 }
	# ai_strategy = { type = role_ratio id = armor value = -20 }
}

EAI_SOV_emergency_increase_infantry_production_over_armor = {
	allowed = { tag = SOV }
	enable = {
		surrender_progress > 0
		OR = {
			AND = {
				has_country_flag = EAI_fielded_eq_ratio_artillery_wanted
				check_variable = { EAI_fielded_eq_ratio_artillery < 0.8 }
			}
			AND = {
				has_country_flag = EAI_fielded_eq_ratio_support_wanted
				check_variable = { EAI_fielded_eq_ratio_support < 0.8 }
			}
		}
	}
	abort = {
		NOT = {
			AND = {
				OR = {
					AND = {
						has_country_flag = EAI_fielded_eq_ratio_artillery_wanted
						check_variable = { EAI_fielded_eq_ratio_artillery < 0.95 }
					}
					AND = {
						has_country_flag = EAI_fielded_eq_ratio_support_wanted
						check_variable = { EAI_fielded_eq_ratio_support < 0.95 }
					}
				}
			}
		}
	}
	
	ai_strategy = { type = equipment_production_factor id = armor value = -25 }
	# ai_strategy = { type = role_ratio id = armor value = -20 }
}

EAI_SOV_CHL_enough_infantry = {
	allowed = { tag = SOV }
	enable = {
		EAI_MODE_challenging = yes
		NOT = { check_variable = { deployed_army_manpower_k < 5000 } }
		OR = {
			check_variable = { num_equipment@support_equipment < 250 }
			check_variable = { num_equipment@anti_air_equipment < 250 }
			check_variable = { num_equipment@motorized_equipment < 250 }
		}
	}
	abort =  {
		NOT = {
			AND = {
				EAI_MODE_challenging = yes
				check_variable = { deployed_army_manpower_k > 4950 }
				OR = {
					check_variable = { num_equipment@support_equipment < 1000 }
					check_variable = { num_equipment@anti_air_equipment < 1000 }
					check_variable = { num_equipment@motorized_equipment < 1000 }
				}
			}
		}
	}

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

EAI_SOV_enough_infantry = {
	allowed = { tag = SOV }
	enable = {
		EAI_MODE_normal = yes
		NOT = { check_variable = { deployed_army_manpower_k < 3350 } }
		OR = {
			check_variable = { num_equipment@support_equipment < 250 }
			check_variable = { num_equipment@anti_air_equipment < 250 }
			check_variable = { num_equipment@motorized_equipment < 250 }
		}
	}
	abort =  {
		NOT = {
			AND = {
				EAI_MODE_normal = yes
				NOT = { check_variable = { deployed_army_manpower_k < 3000 } }
				OR = {
					check_variable = { num_equipment@support_equipment < 1000 }
					check_variable = { num_equipment@anti_air_equipment < 1000 }
					check_variable = { num_equipment@motorized_equipment < 1000 }
				}
			}
		}
	}

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

EAI_SOV_focus_on_convoys = {
	allowed = { tag = SOV }
	enable = {
		has_war = no

		stockpile_ratio = { archetype = convoy ratio < 400 }
	}
	abort = {
		NOT = { stockpile_ratio = { archetype = convoy ratio < 450 } }
	}

	ai_strategy = { type = equipment_production_factor id = capital_ship 	                    value = -200 }
	ai_strategy = { type = equipment_production_factor id = convoy 			                    value = 200 }
}

EAI_SOV_naval_bombers = {
	allowed = { tag = SOV }
	enable = {
		GER = { EAI_THIS_is_threat_to_PREV = yes }
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = unit_ratio id = naval_bomber value = -200 }
}

# Part of SOV industry build strategy
EAI_SOV_market = {
	allowed = { tag = SOV }
	enable = {
		date < 1941.1.1
		OR = {
			check_variable = { EAI_PC_strategy_state = 1 }
			check_variable = { EAI_PC_strategy_state = 1.5 }
			check_variable = { EAI_PC_strategy_state = 2 }
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = equipment_market_spend_factories value = -200 }
}

# Part of SOV industry build strategy
EAI_SOV_avoid_rubber_imports = {
	allowed = { tag = SOV }
	enable = {
		has_war = no
		is_historical_focus_on = yes
		NOT = { has_completed_focus = SOV_finish_the_five_year_plan }
		OR = {
			check_variable = { EAI_PC_strategy_state = 1 }
			check_variable = { EAI_PC_strategy_state = 1.5 }
			check_variable = { EAI_PC_strategy_state = 2 }
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = equipment_variant_production_factor id = motorized_equipment value = -200 }
}

EAI_SOV_timoshenko_over_scientist = {
	allowed = { tag = SOV }
	enable = {
		is_historical_focus_on = yes
		has_political_power < 300
		has_character = SOV_semyon_timoshenko 
		SOV_semyon_timoshenko = {
			is_hired_as_advisor = no
			is_advisor = yes
			NOT = {
				has_character_flag = SOV_exiled_flag 
				has_character_flag = SOV_character_purged_flag 
			}
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = recruit_scientist id = specialization_nuclear value = -500 }
	ai_strategy = { type = recruit_scientist id = specialization_air value = -500 }
	ai_strategy = { type = recruit_scientist id = specialization_naval value = -500 }
	ai_strategy = { type = recruit_scientist id = specialization_land value = -500 }
}

#########################################################
#	Diplomacy Strategies
#########################################################

EAI_SOV_wardec_FIN_on_historical_date = {
	allowed = { original_tag = SOV }
	enable = {
		is_historical_focus_on = yes
		has_completed_focus = SOV_secure_leningrad
		NOT = { has_country_flag = EAI_SOV_declared_war_on_FIN }
	}
	abort_when_not_enabled = yes
	ai_strategy = { type = ignore_claim id = "FIN" value = 5000 }
	ai_strategy = { type = ignore id = "FIN" value = 5000 }
	ai_strategy = { type = declare_war id = "FIN" value = -5000 }
}

EAI_SOV_ignore_pol = {
	allowed = { tag = SOV }
	enable = {
		is_historical_focus_on = yes
		date < 1940.2.1
		NOT = { POL = { has_country_flag = EAI_declare_war_from_SOV } }
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = ignore
		id = "POL"			
		value = 1000
	}	
}

EAI_SOV_ignore_fin_2 = {
	allowed = { tag = SOV }
	enable = {
		is_historical_focus_on = yes
		
		146 = { is_owned_by = SOV }
		
		NOT = { 
			FIN = { has_country_flag = EAI_declare_war_from_SOV }
			SWE = { has_country_flag = EAI_declare_war_from_SOV }
			NOR = { has_country_flag = EAI_declare_war_from_SOV }

			GER = { has_capitulated = yes }
			GER = { exists = no }
			GER = { is_subject = yes }
			is_in_faction_with = GER
		}

		GER = { has_government = fascism }
	}
	
	abort_when_not_enabled = yes

	ai_strategy = {
		type = ignore_claim
		id = "FIN"			
		value = 5000
	}
}

EAI_SOV_ignore_claims = {
	allowed = { tag = SOV }
	enable = {
		is_historical_focus_on = yes
		GER = { EAI_THIS_is_threat_to_PREV = yes }
	}
	
	abort_when_not_enabled = yes
	
	ai_strategy = { type = ignore_claim id = "EST" value = 5000 }
	ai_strategy = { type = declare_war id = "EST" value = -5000 }
	ai_strategy = { type = conquer id = "EST" value = -200 }

	ai_strategy = { type = ignore_claim id = "LAT" value = 5000 }
	ai_strategy = { type = declare_war id = "LAT" value = -5000 }
	ai_strategy = { type = conquer id = "LAT" value = -200 }

	ai_strategy = { type = ignore_claim id = "LIT" value = 5000 }
	ai_strategy = { type = declare_war id = "LIT" value = -5000 }
	ai_strategy = { type = conquer id = "LIT" value = -200 }

	ai_strategy = { type = ignore_claim id = "ROM" value = 5000 }
	ai_strategy = { type = declare_war id = "ROM" value = -5000 }
	ai_strategy = { type = conquer id = "ROM" value = -200 }
}

EAI_SOV_ignore_baltic = {
	allowed = { tag = SOV }
	enable = {
		is_historical_focus_on = yes
		date < 1940.6.1
		NOT = {
			LIT = { has_country_flag = EAI_declare_war_from_SOV }
			LAT = { has_country_flag = EAI_declare_war_from_SOV }
			EST = { has_country_flag = EAI_declare_war_from_SOV }
		}
		OR = { has_completed_focus = SOV_baltic_security has_global_flag = sov_yes_pact }
		146 = { is_controlled_by = FIN }
		has_war = no
	}
	abort = {
		OR = {
			has_war = yes
			LIT = { has_country_flag = EAI_declare_war_from_SOV }
			LAT = { has_country_flag = EAI_declare_war_from_SOV }
			EST = { has_country_flag = EAI_declare_war_from_SOV }
			NOT = { date < 1940.6.1 }
			NOT = { 146 = { is_controlled_by = FIN } }
		}
	}
	
	ai_strategy = {
		type = ignore_claim
		id = LIT			
		value = 1000
	}	
	ai_strategy = {
		type = ignore_claim
		id = LAT			
		value = 1000
	}
	ai_strategy = {
		type = ignore_claim
		id = EST			
		value = 1000
	}	
}

EAI_SOV_stop_early_conquest = {
	enable = {
		tag = SOV
		NOT = { date > 1939.11.1 }
		is_historical_focus_on = yes

		NOT = {
			FIN = { has_country_flag = EAI_declare_war_from_SOV }
			EST = { has_country_flag = EAI_declare_war_from_SOV }
			LIT = { has_country_flag = EAI_declare_war_from_SOV }
			LAT = { has_country_flag = EAI_declare_war_from_SOV }
		}
	}
	abort = {
		OR = {
			date > 1939.11.1

			FIN = { has_country_flag = EAI_declare_war_from_SOV }
			EST = { has_country_flag = EAI_declare_war_from_SOV }
			LIT = { has_country_flag = EAI_declare_war_from_SOV }
			LAT = { has_country_flag = EAI_declare_war_from_SOV }
		}
	}
	
 	ai_strategy = {
 		type = ignore_claim
 		id = FIN			
 		value = 1000
 	}	
 	ai_strategy = {
 		type = ignore_claim
 		id = EST			
 		value = 1000
 	}
 	ai_strategy = {
 		type = ignore_claim
 		id = LAT			
 		value = 1000
 	}
 	ai_strategy = {
 		type = ignore_claim
 		id = LIT			
 		value = 1000
 	}
 	ai_strategy = {
 		type = ignore_claim
 		id = ROM			
 		value = 1000
 	}
}

EAI_SOV_dont_declare_war_on_PER = {
	allowed = { tag = SOV }
	enable = { 
		is_historical_focus_on = yes 
		NOT = { PER = { EAI_THIS_is_threat_to_PREV = yes } }
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = ignore_claim
		id = "PER"
		value = 5000
	}
}

EAI_SOV_dont_declare_war_on_SIK = {
	allowed = { tag = SOV }
	enable = { 
		is_historical_focus_on = yes 
		OR = {
			any_enemy_country = { is_major = yes }
			NOT = { SIK = { EAI_THIS_is_threat_to_PREV = yes } }
		}
	}
	abort_when_not_enabled = yes
	ai_strategy = {
		type = ignore_claim
		id = "SIK"
		value = 5000
	}
}

EAI_SIK_avoid_factions = {
	enable = {
		is_historical_focus_on = yes 
		is_faction_leader = yes
		NOT = { 
			tag = CHI
			tag = PRC
		}
	}
	abort_when_not_enabled = yes
	ai_strategy = { type = alliance id = "SIK" value = -1000 }
	ai_strategy = { type = diplo_action_acceptance id = SIK target = offer_join_faction value = -1000 }
	ai_strategy = { type = diplo_action_desire id = SIK target = offer_join_faction value = -1000 }
}

EAI_SOV_JAP_non_aggression_pact = { 
	allowed = {
		OR = {
			tag = SOV
			tag = MON
			tag = SIK
		}
	}
	enable = {
		is_historical_focus_on = yes

		OR = {
			tag = SOV
			is_in_faction_with = SOV
			is_subject_of = SOV
		}

		GER = { EAI_THIS_is_threat_to_PREV = yes }

		JAP = { has_completed_focus = JAP_soviet_japanese_neutrality_pact }

		NOT = {
			JAP = { has_war_with = SOV }
			JAP = { has_capitulated = yes is_subject = yes }
			SOV = { has_capitulated = yes is_subject = yes }
			JAP = { is_in_faction_with = SOV }
		}
	}
	
	abort_when_not_enabled = yes

	ai_strategy = { type = diplo_action_acceptance id = JAP target = non_aggression_pact value = 1000 }
	ai_strategy = { type = diplo_action_acceptance id = MAN target = non_aggression_pact value = 1000 }
	ai_strategy = { type = diplo_action_acceptance id = MEN target = non_aggression_pact value = 1000 }
	ai_strategy = { type = diplo_action_acceptance id = CHI target = non_aggression_pact value = 1000 }
}

### Comintern should not give access to allies

EAI_SOV_no_access_to_allies = {
	enable = {
		OR = { tag = ENG is_in_faction_with = ENG }
		has_war_together_with = SOV
		NOT = { is_in_faction_with = SOV }
		ENG = { SOV = { NOT = { EAI_PREV_has_same_ideology_with_THIS = yes } } }
	}

	abort_when_not_enabled = yes
	
	reversed = yes

	ai_strategy = { type = diplo_action_desire id = SOV target = offer_military_access value = -2000 }
	ai_strategy = { type = diplo_action_acceptance id = SOV target = military_access value = -2000 }
}

EAI_MON_no_access_to_allies = {
	enable = {
		OR = { tag = ENG is_in_faction_with = ENG }
		has_war_together_with = MON
		NOT = { is_in_faction_with = MON }
		MON = { is_in_faction_with = SOV }
		ENG = { SOV = { NOT = { EAI_PREV_has_same_ideology_with_THIS = yes } } }
	}

	abort_when_not_enabled = yes
	
	reversed = yes

	ai_strategy = { type = diplo_action_desire id = MON target = offer_military_access value = -2000 }
	ai_strategy = { type = diplo_action_acceptance id = MON target = military_access value = -2000 }
}

EAI_SIK_no_access_to_allies = {
	enable = {
		OR = { tag = ENG is_in_faction_with = ENG }
		has_war_together_with = SIK
		NOT = { is_in_faction_with = SIK }
		SIK = { is_in_faction_with = SOV }
		ENG = { SOV = { NOT = { EAI_PREV_has_same_ideology_with_THIS = yes } } }
	}
	
	abort_when_not_enabled = yes
	
	reversed = yes

	ai_strategy = { type = diplo_action_desire id = SIK target = offer_military_access value = -2000 }
	ai_strategy = { type = diplo_action_acceptance id = SIK target = military_access value = -2000 }
}

#########################################################
#	Unit Strategies
#########################################################

EAI_SOV_winter_war_OFFENSIVE_push = {
	allowed = { original_tag = SOV }
	enable = {
		NOT = {
			any_enemy_country = {
				NOT = { tag = FIN }
				exists = yes
			}
		}
		OR = {
			has_war_with = FIN
			AND = {
				focus_progress = { focus = SOV_secure_leningrad progress > 0 }
				NOT = { has_completed_focus = SOV_secure_leningrad }
			}
			has_country_flag = EAI_SOV_take_finland
		}
		FIN = { is_in_faction = no }
		EAI_MILITARY_army_readiness_MEDIUM = yes
	}
	abort = {
		NOT = {
			AND = {
				NOT = {
					any_enemy_country = {
						NOT = { tag = FIN }
						exists = yes
					}
				}
				OR = {
					has_war_with = FIN
					AND = {
						focus_progress = { focus = SOV_secure_leningrad progress > 0 }
						NOT = { has_completed_focus = SOV_secure_leningrad }
					}
					has_country_flag = EAI_SOV_take_finland
				}
				FIN = { is_in_faction = no }
				EAI_MILITARY_army_readiness_MEDIUM_abort = yes
			}
		}
	}
	

	ai_strategy = {
		type = front_control
		ordertype = front
		ratio = 0.5
		priority = 900
		execute_order = yes
		execution_type = rush

		tag = FIN
	}
	ai_strategy = {
		type = front_unit_request
		value = 100
		
		tag = FIN
	}
}

###########################
# 	Operation Barbarossa
###########################

## Defense in depth

EAI_SOV_defense_in_depth_217 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_217 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 217 states = { 217 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_219 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_219 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 219 states = { 219 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_137 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_137 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 137 states = { 137 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_241 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_241 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 241 states = { 241 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_808 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_808 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 808 states = { 808 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_810 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_810 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 810 states = { 810 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_193 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_193 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 193 states = { 193 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_196 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_196 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 196 states = { 196 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_200 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_200 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 200 states = { 200 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_208 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_208 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 208 states = { 208 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_209 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_209 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 209 states = { 209 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_210 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_210 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 210 states = { 210 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_265 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_265 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 265 states = { 265 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_238 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_238 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 238 states = { 238 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_220 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_220 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 220 states = { 220 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_221 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_221 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 221 states = { 221 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_218 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_218 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 218 states = { 218 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_263 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_263 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 263 states = { 263 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_242 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_242 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 242 states = { 242 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_224 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_224 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 224 states = { 224 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_260 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_260 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 260 states = { 260 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_217 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_217 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 217 states = { 217 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_220 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_220 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 220 states = { 220 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_242 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_242 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 242 states = { 242 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_137 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_137 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 137 states = { 137 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_221 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_221 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 221 states = { 221 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_202 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_202 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 202 states = { 202 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_226 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_226 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 226 states = { 226 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_227 = { allowed = { tag = SOV } enable = { any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_227 CONTROLLER = { has_war_with = ROOT } } } abort_when_not_enabled = yes ai_strategy = { type = put_unit_buffers ratio = 0.02 order_id = 227 states = { 227 } subtract_invasions_from_need = no subtract_fronts_from_need = no } }
EAI_SOV_defense_in_depth_195 = { # Leningrad
	allowed = { tag = SOV } 
	enable = { 
		OR = {
			any_of_scopes = { array = global.EAI_MAP_SOV_garrison_strategy_195 CONTROLLER = { has_war_with = ROOT } } 
			AND = {
				has_war_with = GER
				has_country_flag = { flag = EAI_barbarossa_defensive days < 135 }
			}
			AND = {
				NOT = { has_war_with = GER }
				OR = {
					has_global_flag = { flag = EAI_GER_blitz_russia_365d days < 135 }
					GER = { 
						focus_progress = { focus = GER_war_with_the_ussr progress > 0 } 
						NOT = { has_completed_focus = GER_war_with_the_ussr }
					}
				}
			}
			AND = {
				NOT = { has_war_with = GER }
				GER = { has_country_flag = EAI_barbarossa_blitz }
			}
			AND = {
				NOT = { has_war_with = GER }
				GER = { is_justifying_wargoal_against = SOV }
			}
		}
	} 
	abort_when_not_enabled = yes 
	ai_strategy = { type = put_unit_buffers ratio = 0.05 order_id = 195 states = { 195 } subtract_invasions_from_need = no subtract_fronts_from_need = no } 
}

### Prepare

### Deploy

EAI_SOV_barbarossa_DEPLOY = {
	allowed = { tag = SOV }
	enable = {
		GER = {
			is_major = yes
			EAI_THIS_is_threat_to_PREV = yes
		}
		OR = {
			AND = {
				is_historical_focus_on = yes
				date > 1941.1.1
				date < 1942.6.1
			}
			NOT = { GER = { EAI_PREV_defeated_THIS = yes } }
		}
		OR = {
			has_war_with = GER
			GER = { has_wargoal_against = SOV }
			GER = { SOV = { EAI_PREV_imminent_war_against_THIS = yes } }
		}
	}
	abort_when_not_enabled = yes

	### Deploy

	ai_strategy = { type = front_armor_score id = GER value = 50000 }

	ai_strategy = {
		type = force_concentration_factor
		value = 10
	}

	### Avoid

	ai_strategy = { type = garrison value = -50 }

	ai_strategy = {
		type = force_concentration_front_factor
		ratio = 0.25
		value = -50
		
		country_trigger = {
			NOT = { tag = GER }
		}
	}

	ai_strategy = {
	    type = front_unit_request
	    value = -50
		
	    country_trigger = {
			NOT = { is_in_faction_with = GER }
		}
	}

	ai_strategy = {
	    type = invasion_unit_request
	    value = -2000
		
	    country_trigger = { always = yes }
	}
}

EAI_SOV_barbarossa_DEPLOY_dumb = {
	allowed = { tag = SOV }
	enable = {
		OR = {
			has_country_flag = EAI_barbarossa_defensive
			has_country_flag = EAI_SOV_eastern_garrison
		}

		surrender_progress < 0.30

		check_variable = { global.EAI_eastern_front = 0 } # favor germany

		NOT = { any_enemy_country = { is_ai = no is_major = yes } } # cancel if any enemy is a player major
	}
	abort = {
		NOT = {
			AND = {
				OR = {
					has_country_flag = EAI_barbarossa_defensive
					has_country_flag = EAI_SOV_eastern_garrison
				}

				surrender_progress < 0.15

				check_variable = { global.EAI_eastern_front = 0 } # favor germany

				NOT = { any_enemy_country = { is_ai = no is_major = yes } } # cancel if any enemy is a player major
			}
		}
	}

	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.4
		states = { 
			253
			219
			254
			248
			408
			409
			560
			561
			657
			563
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
	ai_strategy = {
		type = front_unit_request
		value = 450
		
		tag = MAN
	}
	ai_strategy = {
		type = front_unit_request
		value = -60
		
		tag = GER
	}
	ai_strategy = {
		type = front_unit_request
		value = -60
		
		tag = ROM
	}
	ai_strategy = {
		type = front_unit_request
		value = -60
		
		tag = HUN
	}
}

EAI_SOV_barbarossa_DEPLOY_dumb_historical = {
	allowed = { tag = SOV }
	enable = {
		OR = {
			has_country_flag = EAI_barbarossa_defensive
			has_country_flag = EAI_SOV_eastern_garrison
		}

		surrender_progress < 0.30

		check_variable = { global.EAI_eastern_front = 2 } # historical

		NOT = { any_enemy_country = { is_ai = no is_major = yes } } # cancel if any enemy is a player major
	}
	abort = {
		NOT = {
			AND = {
				OR = {
					has_country_flag = EAI_barbarossa_defensive
					has_country_flag = EAI_SOV_eastern_garrison
				}

				surrender_progress < 0.035

				check_variable = { global.EAI_eastern_front = 2 } # historical

				NOT = { any_enemy_country = { is_ai = no is_major = yes } } # cancel if any enemy is a player major
			}
		}
	}

	ai_strategy = {
		type = put_unit_buffers
		ratio = 0.4
		states = { 
			253
			219
			254
			248
			408
			409
			560
			561
			657
			563
		}
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
	ai_strategy = {
		type = front_unit_request
		value = 450
		
		tag = MAN
	}
	ai_strategy = {
		type = front_unit_request
		value = -60
		
		tag = GER
	}
	ai_strategy = {
		type = front_unit_request
		value = -60
		
		tag = ROM
	}
	ai_strategy = {
		type = front_unit_request
		value = -60
		
		tag = HUN
	}
}

EAI_SOV_barbarossa_DEPLOY_FIN = {
	allowed = { tag = SOV }
	enable = {
		FIN = { EAI_THIS_is_threat_to_PREV = yes }
		NOT = { has_war_with = FIN }

		OR = {
			AND = {
				has_war_with = GER
				has_country_flag = { flag = EAI_barbarossa_defensive days < 135 }
			}
			AND = {
				NOT = { has_war_with = GER }
				OR = {
					has_global_flag = { flag = EAI_GER_blitz_russia_365d days < 135 }
					GER = { 
						focus_progress = { focus = GER_war_with_the_ussr progress > 0 } 
						NOT = { has_completed_focus = GER_war_with_the_ussr }
					}
				}
			}
			AND = {
				NOT = { has_war_with = GER }
				GER = { has_country_flag = EAI_barbarossa_blitz }
			}
			AND = {
				NOT = { has_war_with = GER }
				GER = { is_justifying_wargoal_against = SOV }
			}
		}
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = front_unit_request
		value = 50

		area = winter_war_front
		area = just_finland
	}
	ai_strategy = {
		type = theatre_distribution_demand_increase
		id = 146 
		value = 10
	}
	ai_strategy = {
		type = prepare_for_war # Careful, makes the AI stop using air volunteers
		id = FIN
		value = 100
	}
}

### Defensive

EAI_SOV_barbarossa_DEFENSIVE_FIN = {
	allowed = { tag = SOV }
	enable = {
		has_war_with = FIN
		any_enemy_country = {
			is_major = yes
			has_capitulated = no
			is_neighbor_of = ROOT
		}
		OR = {
			has_country_flag = EAI_MILITARY_trend_losing_war
			has_country_flag = EAI_MILITARY_trend_stagnant_war
		}
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = front_control
		ordertype = front
		ratio > 0.75
		priority = 500
		ordertype = front
		execution_type = careful

		strategic_region = 13
		strategic_region = 265
		strategic_region = 12
		strategic_region = 277
	}
}

EAI_SOV_barbarossa_DEFENSIVE_dont_naval_invade_FIN = {
	allowed = { tag = SOV }
	enable = {
		OR = {
			AND = {
				has_war_with = GER
				has_country_flag = EAI_barbarossa_defensive
			}
			AND = {
				NOT = { has_war_with = GER }
				GER = { 
					focus_progress = { focus = GER_war_with_the_ussr progress > 0 } 
					NOT = { has_completed_focus = GER_war_with_the_ussr }
				}
			}
		}
	}

	abort_when_not_enabled = yes

	ai_strategy = { type = invade id = "FIN" value = -3000 } 
}

EAI_SOV_barbarossa_DEFENSIVE_losing_war = {
	allowed = { tag = SOV }
	enable = {
		has_war_with = GER
		has_defensive_war = yes
		surrender_progress > 0
		has_country_flag = EAI_MILITARY_trend_losing_war

		EAI_MILITARY_army_shortage_MINOR = yes

		if = { # only when losing badly vs AI ger
			limit = { 
				NOT = { any_enemy_country = { is_ai = no is_major = yes } }
				check_variable = { global.EAI_eastern_front = 0 } # favor ger
			} 

			surrender_progress > 0.30
		}
	}
	abort = {
		NOT = {
			AND = {
				has_war_with = GER
				has_defensive_war = yes
				surrender_progress > 0
				has_country_flag = EAI_MILITARY_trend_losing_war

				EAI_MILITARY_army_shortage_MINOR_abort = yes

				if = { # only when losing badly vs AI ger
					limit = { 
						NOT = { any_enemy_country = { is_ai = no is_major = yes } }
						check_variable = { global.EAI_eastern_front = 0 } # favor ger
					} 

					surrender_progress > 0.30
				}
			}
		}
	}

	ai_strategy = {
		type = front_control
		ordertype = front
		ratio = 0.5
		priority = 500
		execution_type = careful
		
		country_trigger = {
			OR = {
				tag = GER
				is_in_faction_with = GER
			}
		}
	}
}

EAI_SOV_barbarossa_DEFENSIVE_crimea = {
	allowed = { tag = SOV }
	enable = {
		OR = {
			has_country_flag = EAI_MILITARY_trend_stagnant_war
			has_country_flag = EAI_MILITARY_trend_losing_war
		}
		137 = { is_fully_controlled_by = ROOT }
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = front_control
		ordertype = front
		ratio = 0.9
		priority = 5000
		execution_type = careful
		execute_order = no
		manual_attack = no
		
		state = 196
		state = 137
		state = 234
	}

	ai_strategy = {
		type = front_unit_request
		value = 50

		state = 196
		state = 137
		state = 234
	}
}

EAI_SOV_barbarossa_DEFENSIVE_initial_defense_careful = {
	allowed = { tag = SOV }
	enable = {
		has_country_flag = { flag = EAI_barbarossa_defensive days < 35 }
		GER = {
			NOT = { 
				AND = {
					surrender_progress > 0.05
					has_country_flag = EAI_MILITARY_trend_losing_war
				}
			}
		}
		any_enemy_country = { is_ai = no is_major = yes }
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = front_control
		ordertype = front
		ratio = 0.5
		priority = 1000
		execute_order = no
		
		country_trigger = {
			is_in_faction_with = GER
		}
	}
}

EAI_SOV_barbarossa_DEFENSIVE_initial_defense_hold = {
	allowed = { tag = SOV }
	enable = {
		OR = {
			AND = {
				has_war_with = GER
				EAI_MODE_challenging = yes
				has_country_flag = { flag = EAI_barbarossa_defensive days < 180 }
			}
			AND = {
				has_war_with = GER
				has_country_flag = { flag = EAI_barbarossa_defensive days < 135 }
			}
			AND = {
				NOT = { has_war_with = GER }
				OR = {
					has_global_flag = { flag = EAI_GER_blitz_russia_365d days < 135 }
					GER = { 
						focus_progress = { focus = GER_war_with_the_ussr progress > 0 } 
						NOT = { has_completed_focus = GER_war_with_the_ussr }
					}
				}
			}
			AND = {
				NOT = { has_war_with = GER }
				GER = { has_country_flag = EAI_barbarossa_blitz }
			}
			AND = {
				NOT = { has_war_with = GER }
				GER = { is_justifying_wargoal_against = SOV }
			}
		}
		NOT = { GER = { surrender_progress > 0.2 } }
		OR = {
			any_enemy_country = { is_ai = no is_major = yes }
			NOT = { has_war_with = GER }
			has_country_flag = { flag = EAI_barbarossa_defensive days < 30 }
		}
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = front_control
		ordertype = front
		ratio = 0.5
		priority = 1100
		execute_order = no
		manual_attack = no
		
		country_trigger = {
			is_in_faction_with = GER
		}
	}
}

EAI_SOV_barbarossa_DEFENSIVE_initial_fc = {
	allowed = { tag = SOV }
	enable = {
		OR = {
			AND = {
				has_war_with = GER
				has_country_flag = { flag = EAI_barbarossa_defensive days < 135 }
			}
			AND = {
				NOT = { has_war_with = GER }
				OR = {
					has_global_flag = { flag = EAI_GER_blitz_russia_365d days < 135 }
					GER = { 
						focus_progress = { focus = GER_war_with_the_ussr progress > 0 } 
						NOT = { has_completed_focus = GER_war_with_the_ussr }
					}
				}
			}
			AND = {
				NOT = { has_war_with = GER }
				GER = { has_country_flag = EAI_barbarossa_blitz }
			}
			AND = {
				NOT = { has_war_with = GER }
				GER = { is_justifying_wargoal_against = SOV }
			}
		}
		NOT = { GER = { surrender_progress > 0.2 } }
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = force_concentration_factor
		value = -100
	}
}

EAI_SOV_barbarossa_DEFENSIVE_major_shortage = {
	enable = {
		is_in_faction_with = SOV
		has_war_with = GER
		EAI_MILITARY_army_shortage_CRITICAL = yes
	}
	abort = {
		NOT = { 
			AND = {
				has_war_with = GER
				is_in_faction_with = SOV
				EAI_MILITARY_army_shortage_CRITICAL_abort = yes
			}
		}
	} 	

	ai_strategy = {
		type = front_control
		ordertype = front
		ratio > 0.75
		priority = 900
		execution_type = careful
		execute_order = no
		
		country_trigger = { is_in_faction_with = GER }
	}
}

EAI_SOV_barbarossa_DEFENSIVE_minor_shortage = {
	enable = {
		is_in_faction_with = SOV
		has_war_with = GER
		EAI_MILITARY_army_shortage_MAJOR = yes
	}
	abort = {
		NOT = { 
			AND = {
				has_war_with = GER
				is_in_faction_with = SOV
				EAI_MILITARY_army_shortage_MAJOR_abort = yes
			}
		}
	} 	

	ai_strategy = {
		type = front_control
		ordertype = front
		ratio > 0.75
		priority = 600
		execution_type = careful
		
		country_trigger = { is_in_faction_with = GER }
	}
}

EAI_SOV_barbarossa_DEFENSIVE_operational_pause = {
	enable = {
		is_in_faction_with = SOV
		has_war_with = GER
		has_country_flag = EAI_MILITARY_operational_pause_timer
	}
	abort_when_not_enabled = yes	

	ai_strategy = {
		type = front_control
		ordertype = front
		ratio > 0.75
		priority = 700
		execution_type = careful
		execute_order = no
		
		country_trigger = { is_in_faction_with = GER }
	}
}

### Offensive

EAI_SOV_barbarossa_OFFENSIVE_operational_resume = {
	enable = {
		is_in_faction_with = SOV
		has_war_with = GER
		has_country_flag = EAI_operational_initial_resume_timer
		NOT = { has_country_flag = EAI_MILITARY_operational_pause_timer }
		EAI_MILITARY_army_readiness_HIGH = yes
		NOT = { EAI_MILITARY_north_mud_season = yes }
	}
	abort = {
		NOT = {
			AND = {
				is_in_faction_with = SOV
				has_war_with = GER
				has_country_flag = EAI_operational_initial_resume_timer
				NOT = { has_country_flag = EAI_MILITARY_operational_pause_timer }
				EAI_MILITARY_army_readiness_HIGH_abort = yes
				NOT = { EAI_MILITARY_north_mud_season = yes }
			}
		}
	}

	ai_strategy = {
		type = front_control
		ordertype = front
		ratio > 0.75
		priority = 800
		execution_type = rush_weak
		execute_order = yes
		
		country_trigger = { is_in_faction_with = GER }
	}
}

EAI_SOV_barbarossa_OFFENSIVE_sector = {
	allowed = { tag = SOV }
	enable = {
		NOT = { has_country_flag = { flag = EAI_barbarossa_defensive days < 135 } }
		has_variable = EAI_MILITARY_SECTOR_id
	}
	abort = {
		NOT = {
			AND = {
				NOT = { has_country_flag = { flag = EAI_barbarossa_defensive days < 135 } }
				has_variable = EAI_MILITARY_SECTOR_id
			}
		}
	}

	ai_strategy = {
		type = force_concentration_front_factor
		ratio = 0.5
		value = 50
		
		state_trigger = { is_in_array = { FROM.FROM.EAI_MILITARY_SECTOR_target_states = THIS.id } }
	}
	ai_strategy = {
		type = force_concentration_target_weight
		value = 50
		
		state_trigger = { is_in_array = { FROM.FROM.EAI_MILITARY_SECTOR_target_objectives = THIS.id } }
	}
	ai_strategy = {
		type = force_concentration_target_weight
		value = -99
		
		state_trigger = { NOT = { is_in_array = { FROM.FROM.EAI_MILITARY_SECTOR_target_states = THIS.id } } }
	}
}

EAI_SOV_barbarossa_OFFENSIVE_sector_NORTH_DEBUG = {
	allowed = { tag = SOV }
	enable = {
		NOT = { has_country_flag = { flag = EAI_barbarossa_defensive days < 135 } }
		has_variable = EAI_MILITARY_SECTOR_id
		check_variable = { EAI_MILITARY_SECTOR_id = 0 }
	}
	abort_when_not_enabled = yes
}

EAI_SOV_barbarossa_OFFENSIVE_sector_CENTER_DEBUG = {
	allowed = { tag = SOV }
	enable = {
		NOT = { has_country_flag = { flag = EAI_barbarossa_defensive days < 135 } }
		has_variable = EAI_MILITARY_SECTOR_id
		check_variable = { EAI_MILITARY_SECTOR_id = 1 }
	}
	abort_when_not_enabled = yes
}

EAI_SOV_barbarossa_OFFENSIVE_sector_SOUTH_DEBUG = {
	allowed = { tag = SOV }
	enable = {
		NOT = { has_country_flag = { flag = EAI_barbarossa_defensive days < 135 } }
		has_variable = EAI_MILITARY_SECTOR_id
		check_variable = { EAI_MILITARY_SECTOR_id = 2 }
	}
	abort_when_not_enabled = yes
}

### Seasonal behavior

EAI_SOV_barbarossa_SEASONAL_mud = {
	enable = {
		is_in_faction_with = SOV
		has_war_with = GER
		EAI_MILITARY_north_mud_season = yes
		EAI_MILITARY_army_shortage_MINOR = yes
	}
	abort = {
		NOT = {
			AND = {
				is_in_faction_with = SOV
				has_war_with = GER
				EAI_MILITARY_north_mud_season = yes
				EAI_MILITARY_army_shortage_MINOR_abort = yes
			}
		}
	}

	ai_strategy = {
		type = front_control
		ordertype = front
		ratio > 0.75
		priority = 500
		execution_type = careful

		area = EAI_russia_plains
	}
}

EAI_SOV_barbarossa_SEASONAL_winter = {
	enable = {
		is_in_faction_with = SOV
		has_war_with = GER
		EAI_MILITARY_north_winter_season = yes
	}
	abort_when_not_enabled = yes	

	ai_strategy = {
		type = front_control
		ordertype = front
		ratio > 0.75
		priority = 500
		execution_type = balanced

		area = EAI_russia_plains
	}
}

EAI_SOV_barbarossa_SEASONAL_summer = {
	enable = {
		is_in_faction_with = SOV
		has_war_with = GER
		EAI_MILITARY_north_summer_season = yes
		EAI_MILITARY_army_readiness_HIGH = yes
	}
	abort = {
		NOT = {
			AND = {
				is_in_faction_with = SOV
				has_war_with = GER
				EAI_MILITARY_north_summer_season = yes
				EAI_MILITARY_army_readiness_HIGH_abort = yes
			}
		}
	}

	ai_strategy = {
		type = front_control
		ordertype = front
		ratio > 0.75
		priority = 500
		execution_type = rush_weak

		area = EAI_russia_plains
	}
}

### Misc

EAI_SOV_barbarossa_HISTORICAL_careful_limiter = {
	enable = {
		has_war_with = GER
		GER = { is_ai = yes }
		is_in_faction_with = SOV
		SOV = { check_variable = { EAI_MILITARY_barbarossa_LIMITER = 1 } }
		check_variable = { global.EAI_eastern_front = 2 }
	}
	abort_when_not_enabled = yes	

	ai_strategy = {
		type = front_control
		ordertype = front
		ratio = 0.5
		priority = 1200
		execution_type = careful
		manual_attack = no
		
		tag = GER
	}
}

EAI_SOV_barbarossa_HISTORICAL_hold_limiter = {
	enable = {
		has_war_with = GER
		GER = { is_ai = yes }
		is_in_faction_with = SOV
		SOV = { check_variable = { EAI_MILITARY_barbarossa_LIMITER = 2 } }
		check_variable = { global.EAI_eastern_front = 2 }
	}
	abort_when_not_enabled = yes	

	ai_strategy = {
		type = front_control
		ordertype = front
		ratio = 0.5
		priority = 1200
		execution_type = careful
		manual_attack = no
		execute_order = no
		
		tag = GER
	}
	ai_strategy = {
		type = force_concentration_front_factor
		ratio = 0.5
		value = -100
		
		state_trigger = {
			CONTROLLER = { is_in_faction_with = GER }
			is_in_array = { global.EAI_MAP_barbarossa_theatre = THIS.id }
		}
	}
	ai_strategy = {
		type = force_concentration_target_weight
		value = -100
		
		state_trigger = {
			CONTROLLER = { is_in_faction_with = GER }
			is_in_array = { global.EAI_MAP_barbarossa_theatre = THIS.id }
		}
	}
}

### Naval

EAI_SOV_barbarossa_NAVAL_convoy_route = {
	enable = {
		is_in_faction_with = SOV
		has_war_with = GER
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = naval_avoid_region id = 174 value = 50 }
	ai_strategy = { type = naval_avoid_region id = 16 value = 50 }
	ai_strategy = { type = naval_avoid_region id = 173 value = 50 }

	ai_strategy = { type = naval_avoid_region id = 49 value = 5000 }
	ai_strategy = { type = naval_avoid_region id = 44 value = 5000 }
	ai_strategy = { type = naval_avoid_region id = 51 value = 5000 }
	ai_strategy = { type = naval_avoid_region id = 58 value = 5000 }
	# ai_strategy = { type = naval_avoid_region id = 50 value = 50 }
	ai_strategy = { type = naval_avoid_region id = 56 value = 5000 }
	ai_strategy = { type = naval_avoid_region id = 57 value = 50 }

	ai_strategy = { type = naval_avoid_region id = 66 value = 5000 }
}