############################################################################################################
#	Expert AI mod - effects
############################################################################################################

EAI_difficulty_bimonthly_update = {

	EAI_difficulty_static_bonus = yes

	EAI_difficulty_dynamic_bonus = yes

	###

	EAI_difficulty_attrition_reduction = yes

	###

	EAI_difficulty_free_convoys = yes

	###

	EAI_difficulty_reinforcements = yes
}

EAI_difficulty_weekly_update = {

	EAI_difficulty_static_desperate_defense = yes

	EAI_difficulty_dynamic_desperate_defense = yes

	EAI_DIFFICULTY_grant_resources = yes

	EAI_DIFFICULTY_supply_units = yes
}

############################################################################################################

EAI_difficulty_static_bonus = {

	if = {
		limit = {
			has_variable = EAI_difficulty_bonus
		}

		if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [Root.GetName] | DIFFICULTY BONUS: updating static" } 

		set_country_flag = EAI_difficulty_bonus_active

		if = { limit = { NOT = { has_dynamic_modifier = { modifier = EAI_difficulty_bonus_modifier } } } 
		
			add_dynamic_modifier = { modifier = EAI_difficulty_bonus_modifier } 
		}

		###

		if = { limit = { check_variable = { EAI_difficulty_equipment_bonus_active = 1 } }

			EAI_DIFFICULTY_clear_equipment_modifier_HARD = yes
		}
		else_if = { limit = { check_variable = { EAI_difficulty_equipment_bonus_active = 2 } }

			EAI_DIFFICULTY_clear_equipment_modifier_VERY_HARD = yes
		}
		else_if = { limit = { check_variable = { EAI_difficulty_equipment_bonus_active = 3 } }

			EAI_DIFFICULTY_clear_equipment_modifier_INSANE = yes
		}

		###
		
		if = { limit = { check_variable = { EAI_custom_bonus_25 = 1 } }

			EAI_DIFFICULTY_apply_equipment_modifier_HARD = yes
		}
		else_if = { limit = { check_variable = { EAI_custom_bonus_25 = 2 } }

			EAI_DIFFICULTY_apply_equipment_modifier_VERY_HARD = yes
		}
		else_if = { limit = { check_variable = { EAI_custom_bonus_25 = 3 } }

			EAI_DIFFICULTY_apply_equipment_modifier_INSANE = yes
		}
	}
}

EAI_difficulty_dynamic_bonus = {

	if = {
		limit = {
			has_variable = global.EAI_dynamic_difficulty_bonus

			NOT = { 
				has_variable = EAI_difficulty_bonus 
				has_country_flag = EAI_disable_dynamic_difficulty_bonus 
			}
		}

		if = { 
			limit = { 
				EAI_DIFFICULTY_dynamic_bonus_trigger = yes 
			}

			if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [Root.GetName] | DIFFICULTY BONUS: updating dynamic" } 
		
			set_country_flag = EAI_dynamic_difficulty_bonus_active

			if = { limit = { NOT = { has_dynamic_modifier = { modifier = EAI_dynamic_difficulty_bonus_modifier } } } 

				add_dynamic_modifier = { modifier = EAI_dynamic_difficulty_bonus_modifier }
			}

			###

			if = { limit = { check_variable = { EAI_difficulty_equipment_bonus_active = 1 } }

				EAI_DIFFICULTY_clear_equipment_modifier_HARD = yes
			}
			else_if = { limit = { check_variable = { EAI_difficulty_equipment_bonus_active = 2 } }

				EAI_DIFFICULTY_clear_equipment_modifier_VERY_HARD = yes
			}
			else_if = { limit = { check_variable = { EAI_difficulty_equipment_bonus_active = 3 } }

				EAI_DIFFICULTY_clear_equipment_modifier_INSANE = yes
			}

			###

			if = { limit = { check_variable = { global.EAI_custom_bonus_25 = 1 } }

				EAI_DIFFICULTY_apply_equipment_modifier_HARD = yes
			}
			else_if = { limit = { check_variable = { global.EAI_custom_bonus_25 = 2 } }

				EAI_DIFFICULTY_apply_equipment_modifier_VERY_HARD = yes
			}
			else_if = { limit = { check_variable = { global.EAI_custom_bonus_25 = 3 } }

				EAI_DIFFICULTY_apply_equipment_modifier_INSANE = yes
			}
		}
		else_if = { limit = { has_country_flag = EAI_dynamic_difficulty_bonus_active }

			if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [Root.GetName] | DIFFICULTY BONUS: removing dynamic" } 

			EAI_DIFFICULTY_clear_active_difficulty_bonus = yes
		}
	}
}

###

EAI_difficulty_attrition_reduction = {

	if = {
		limit = {
			NOT = {
				has_idea = EAI_attrition_reduction
				has_idea = EAI_attrition_reduction2
				has_idea = EAI_attrition_reduction3
			}

			OR = {
				has_global_flag = EAI_attrition_1
				has_global_flag = EAI_attrition_2
				has_global_flag = EAI_attrition_3
			}
		}

		if = { limit = { has_global_flag = EAI_attrition_1 }
			add_ideas = EAI_attrition_reduction
		}
		if = { limit = { has_global_flag = EAI_attrition_2 }
			add_ideas = EAI_attrition_reduction2
		}
		if = { limit = { has_global_flag = EAI_attrition_3 }
			add_ideas = EAI_attrition_reduction3
		}

		if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [Root.GetName] | ATTRITION: adding idea" } 
	}
}

###

EAI_difficulty_free_convoys = {

	if = {
		limit = {
			OR = {
				check_variable = { EAI_custom_bonus_26 > 0 }

				AND = { check_variable = { global.EAI_custom_bonus_26 > 0 } EAI_DIFFICULTY_dynamic_bonus_trigger = yes }

				has_global_flag = EAI_free_convoys
			}

			stockpile_ratio = { archetype = convoy ratio < 50 } # this trigger actually checks the number of free convoys in stockpile
		}

		if = { limit = { check_variable = { EAI_custom_bonus_26 > 0 } }

			add_equipment_to_stockpile = { type = convoy_1 amount = EAI_custom_bonus_26 }

			if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [Root.GetName] | adding convoys (country) ([?EAI_custom_bonus_26])" } 
		}
		else_if = { limit = { check_variable = { global.EAI_custom_bonus_26 > 0 } EAI_DIFFICULTY_dynamic_bonus_trigger = yes }

			add_equipment_to_stockpile = { type = convoy_1 amount = global.EAI_custom_bonus_26 }

			if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [Root.GetName] | adding convoys (dynamic) ([?global.EAI_custom_bonus_26])" } 
		}
		else = {
			add_equipment_to_stockpile = { type = convoy_1 amount = 50 }

			if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [Root.GetName] | adding convoys (global)" } 
		}
	}
}

EAI_DIFFICULTY_grant_resources = {

	if = { limit = { NOT = { has_global_flag = EAI_DIFFICULTY_grant_resources_update } }

		set_global_flag = { flag = EAI_DIFFICULTY_grant_resources_update value = 1 days = 6 }	

		###

			every_state = { limit = { has_state_flag = EAI_DIFFICULTY_grant_resources }
				clr_state_flag = EAI_DIFFICULTY_grant_resources
				add_resource = { type = aluminium amount = var:EAI_DIFFICULTY_grant_resources_remove_aluminium show_state_in_tooltip = no }
				add_resource = { type = rubber amount = var:EAI_DIFFICULTY_grant_resources_remove_rubber show_state_in_tooltip = no }
				add_resource = { type = tungsten amount = var:EAI_DIFFICULTY_grant_resources_remove_tungsten show_state_in_tooltip = no }
				add_resource = { type = steel amount = var:EAI_DIFFICULTY_grant_resources_remove_steel show_state_in_tooltip = no }
				add_resource = { type = chromium amount = var:EAI_DIFFICULTY_grant_resources_remove_chromium show_state_in_tooltip = no }
			}

		###

			every_country = {
				if = { 
					limit = {
						is_ai = yes
						OR = {
							check_variable = { EAI_custom_bonus_34 = 1 }
							AND = { check_variable = { global.EAI_custom_bonus_34 = 1 } EAI_DIFFICULTY_dynamic_bonus_trigger = yes }
						}
					}

					### Get deficit

						set_temp_variable = { deficit_aluminium = resource@aluminium }
						set_temp_variable = { deficit_rubber = resource@rubber }
						set_temp_variable = { deficit_tungsten = resource@tungsten }
						set_temp_variable = { deficit_steel = resource@steel }
						set_temp_variable = { deficit_chromium = resource@chromium }

						capital_scope = {
							set_temp_variable = { res_factor = building_level@infrastructure }
							divide_temp_variable = { res_factor = 5 }
							add_to_temp_variable = { res_factor = 1 }
						}

						if = { limit = { check_variable = { modifier@min_export > 0 } }
							multiply_temp_variable = { res_factor = modifier@min_export }
						}

						set_temp_variable = { grant_aluminium = 0 }
						set_temp_variable = { grant_rubber = 0 }
						set_temp_variable = { grant_tungsten = 0 }
						set_temp_variable = { grant_steel = 0 }
						set_temp_variable = { grant_chromium = 0 }

						if = { limit = { check_variable = { deficit_aluminium < 0 } } set_temp_variable = { grant_aluminium = deficit_aluminium } multiply_temp_variable = { grant_aluminium = -1 } }
						if = { limit = { check_variable = { deficit_rubber < 0 } } set_temp_variable = { grant_rubber = deficit_rubber } multiply_temp_variable = { grant_rubber = -1 } }
						if = { limit = { check_variable = { deficit_tungsten < 0 } } set_temp_variable = { grant_tungsten = deficit_tungsten } multiply_temp_variable = { grant_tungsten = -1 } }
						if = { limit = { check_variable = { deficit_steel < 0 } } set_temp_variable = { grant_steel = deficit_steel } multiply_temp_variable = { grant_steel = -1 } }
						if = { limit = { check_variable = { deficit_chromium < 0 } } set_temp_variable = { grant_chromium = deficit_chromium } multiply_temp_variable = { grant_chromium = -1 } }

						divide_temp_variable = { grant_aluminium = res_factor }
						divide_temp_variable = { grant_rubber = res_factor }
						divide_temp_variable = { grant_tungsten = res_factor }
						divide_temp_variable = { grant_steel = res_factor }
						divide_temp_variable = { grant_chromium = res_factor }

					### Add resources equal to deficit

						capital_scope = {
							set_state_flag = EAI_DIFFICULTY_grant_resources
							add_resource = { type = aluminium amount = grant_aluminium show_state_in_tooltip = no }
							add_resource = { type = rubber amount = grant_rubber show_state_in_tooltip = no }
							add_resource = { type = tungsten amount = grant_tungsten show_state_in_tooltip = no }
							add_resource = { type = steel amount = grant_steel show_state_in_tooltip = no }
							add_resource = { type = chromium amount = grant_chromium show_state_in_tooltip = no }

							set_variable = { EAI_DIFFICULTY_grant_resources_remove_aluminium = grant_aluminium }
							set_variable = { EAI_DIFFICULTY_grant_resources_remove_rubber = grant_rubber }
							set_variable = { EAI_DIFFICULTY_grant_resources_remove_tungsten = grant_tungsten }
							set_variable = { EAI_DIFFICULTY_grant_resources_remove_steel = grant_steel }
							set_variable = { EAI_DIFFICULTY_grant_resources_remove_chromium = grant_chromium }

							multiply_variable = { EAI_DIFFICULTY_grant_resources_remove_aluminium = -1 }
							multiply_variable = { EAI_DIFFICULTY_grant_resources_remove_rubber = -1 }
							multiply_variable = { EAI_DIFFICULTY_grant_resources_remove_tungsten = -1 }
							multiply_variable = { EAI_DIFFICULTY_grant_resources_remove_steel = -1 }
							multiply_variable = { EAI_DIFFICULTY_grant_resources_remove_chromium = -1 }
						}

					###
				}
			}

			###
	}
}

EAI_DIFFICULTY_supply_units = {
	if = { limit = { NOT = { has_global_flag = EAI_DIFFICULTY_supply_units_update } }

		set_global_flag = { flag = EAI_DIFFICULTY_supply_units_update value = 1 days = 6 }	

		every_country = {
			if = { 
				limit = {
					is_ai = yes
					OR = {
						NOT = { check_variable = { EAI_custom_bonus_37 = 0 } }
						AND = { NOT = { check_variable = { global.EAI_custom_bonus_37 = 0 } } EAI_DIFFICULTY_dynamic_bonus_trigger = yes }
					}
				}

				set_temp_variable = { tmp = EAI_custom_bonus_37 }
				if = { 
					limit = { 
						check_variable = { global.EAI_custom_bonus_37 > EAI_custom_bonus_37 } 
						EAI_DIFFICULTY_dynamic_bonus_trigger = yes 
					}
					set_temp_variable = { tmp = global.EAI_custom_bonus_37 }
				}
				every_army_leader = { limit = { check_variable = { num_units > 0 } }
					supply_units = tmp
				}
			}
		}
	}
}

###

EAI_difficulty_static_desperate_defense = {

	if = {
		limit = {
			has_variable = EAI_desperate_defense
		}

		if = { 
			limit = {
				has_capitulated = no
				surrender_progress > 0
			}

			if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [Root.GetName] | DD: updating static" }

			set_country_flag = EAI_desperate_defense_active

			if = { limit = { check_variable = { EAI_desperate_defense = 1 } } 

				EAI_desperate_defense_setting_1 = yes
			}
			else_if = { limit = { check_variable = { EAI_desperate_defense = 2 } } 

				EAI_desperate_defense_setting_2 = yes
			}
			else_if = { limit = { check_variable = { EAI_desperate_defense = 3 } } 

				EAI_desperate_defense_setting_3 = yes
			}
		}
		else_if = { limit = { has_country_flag = EAI_desperate_defense_active }

			if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [Root.GetName] | DD: removing static" }

			EAI_DIFFICULTY_clear_active_desperate_defense = yes
		}
	}
}

EAI_difficulty_dynamic_desperate_defense = {

	if = {
		limit = {
			has_variable = global.EAI_dynamic_desperate_defense

			NOT = { 
				has_variable = EAI_desperate_defense
				has_country_flag = EAI_disable_dynamic_desperate_defense
			}
		}

		if = { 
			limit = {
				has_capitulated = no
				surrender_progress > 0
				EAI_DIFFICULTY_dynamic_bonus_trigger = yes 
			}

			if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [Root.GetName] | DD: updating dynamic" }

			set_country_flag = EAI_dynamic_desperate_defense_active

			if = { limit = { check_variable = { global.EAI_dynamic_desperate_defense = 1 } } 

				EAI_desperate_defense_setting_1 = yes
			}
			else_if = { limit = { check_variable = { global.EAI_dynamic_desperate_defense = 2 } } 

				EAI_desperate_defense_setting_2 = yes
			}
			else_if = { limit = { check_variable = { global.EAI_dynamic_desperate_defense = 3 } } 

				EAI_desperate_defense_setting_3 = yes
			}
		}
		else_if = { limit = { has_country_flag = EAI_dynamic_desperate_defense_active }

			if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [Root.GetName] | DD: removing dynamic" }
		
			EAI_DIFFICULTY_clear_active_desperate_defense = yes
		}
	}
}

EAI_desperate_defense_setting_1 = { # 0%-50%, levels 1-10

	set_temp_variable = { updated_desperate_defense_level = surrender_progress }
	multiply_temp_variable = { updated_desperate_defense_level = 100 }
	clamp_temp_variable = { var = updated_desperate_defense_level min = 0 max = 50 }
	divide_temp_variable = { updated_desperate_defense_level = 5 } # 50/5=10 levels
	round_temp_variable = updated_desperate_defense_level

	set_variable = { EAI_desperate_defense_level = updated_desperate_defense_level }

	EAI_DIFFICULTY_clear_equipment_modifier_DD = yes
	
	if = { limit = { check_variable = { updated_desperate_defense_level > 0 } }

		EAI_DIFFICULTY_apply_equipment_modifier_DD = yes
	}
}

EAI_desperate_defense_setting_2 = { # 0%-25%, levels 1-20

	set_temp_variable = { updated_desperate_defense_level = surrender_progress }
	multiply_temp_variable = { updated_desperate_defense_level = 100 }
	clamp_temp_variable = { var = updated_desperate_defense_level min = 0 max = 25 }
	divide_temp_variable = { updated_desperate_defense_level = 1.25 } # 25/1.25=20 levels
	round_temp_variable = updated_desperate_defense_level

	set_variable = { EAI_desperate_defense_level = updated_desperate_defense_level }

	EAI_DIFFICULTY_clear_equipment_modifier_DD = yes
	
	if = { limit = { check_variable = { updated_desperate_defense_level > 0 } }

		EAI_DIFFICULTY_apply_equipment_modifier_DD = yes
	}
}

EAI_desperate_defense_setting_3 = { # 0%-25%, levels 11-20

	set_temp_variable = { updated_desperate_defense_level = surrender_progress }
	multiply_temp_variable = { updated_desperate_defense_level = 100 }
	clamp_temp_variable = { var = updated_desperate_defense_level min = 0 max = 25 }
	divide_temp_variable = { updated_desperate_defense_level = 2.5 } # 25/2.5=10 levels
	round_temp_variable = updated_desperate_defense_level
	add_to_temp_variable = { updated_desperate_defense_level = 10 } # levels 10-20

	set_variable = { EAI_desperate_defense_level = updated_desperate_defense_level }

	EAI_DIFFICULTY_clear_equipment_modifier_DD = yes
	
	if = { limit = { check_variable = { updated_desperate_defense_level > 10 } }

		EAI_DIFFICULTY_apply_equipment_modifier_DD = yes
	}
}

###

EAI_difficulty_reinforcements = {

	if = {
		limit = {
			has_capitulated = no

			OR = { 
				has_country_flag = EAI_reinforcements_mode

				AND = { 
					has_global_flag = EAI_dynamic_reinforcements_mode 
					NOT = { has_country_flag = EAI_disable_dynamic_reinforcements_mode } 
					any_enemy_country = { is_ai = no }
				} 
			}

			NOT = { has_civil_war = yes }

			surrender_progress > 0
		}

		# EQUIPMENT

		#####################################################################################################
		if = {
			limit = { has_equipment = { infantry_equipment < 250 } }

			add_equipment_to_stockpile = { type = infantry_equipment amount = 5000 }
		}

		if = {
			limit = { has_tech = tech_support has_equipment = { support_equipment < 250 } }

			add_equipment_to_stockpile = { type = support_equipment amount = 1000 }
		}

		if = {
			limit = { has_tech = gw_artillery has_equipment = { artillery_equipment < 250 } }

			add_equipment_to_stockpile = { type = artillery_equipment amount = 1000 }
		}

		#####################################################################################################
		if = {
			limit = { has_tech = motorised_infantry has_equipment = { motorized_equipment < 250 } }

			add_equipment_to_stockpile = { type = motorized_equipment amount = 1000 }
		}

		if = {
			limit = { has_tech = mechanised_infantry has_equipment = { mechanized_equipment < 250 } }

			add_equipment_to_stockpile = { type = mechanized_equipment amount = 250 }
		}
		
		#####################################################################################################
		if = {
			limit = {
				OR = { has_tech = basic_light_tank_chassis has_tech = improved_light_tank_chassis has_tech = advanced_light_tank_chassis }
				has_equipment = { light_tank_chassis < 250 }
			}

			add_equipment_to_stockpile = { type = light_tank_chassis amount = 250 }
		}
		if = {
			limit = {
				OR = { has_tech = basic_light_tank_chassis has_tech = improved_light_tank_chassis has_tech = advanced_light_tank_chassis }
				has_equipment = { light_tank_destroyer_chassis < 250 }
			}

			add_equipment_to_stockpile = { type = light_tank_destroyer_chassis amount = 250 }
		}
		if = {
			limit = {
				OR = { has_tech = basic_light_tank_chassis has_tech = improved_light_tank_chassis has_tech = advanced_light_tank_chassis }
				has_equipment = { light_tank_artillery_chassis < 250 }
			}

			add_equipment_to_stockpile = { type = light_tank_artillery_chassis amount = 250 }
		}
		if = {
			limit = {
				OR = { has_tech = basic_light_tank_chassis has_tech = improved_light_tank_chassis has_tech = advanced_light_tank_chassis }
				has_equipment = { light_tank_aa_chassis < 250 }
			}

			add_equipment_to_stockpile = { type = light_tank_aa_chassis amount = 250 }
		}

		#####################################################################################################
		if = {
			limit = {
				OR = { has_tech = basic_medium_tank_chassis has_tech = improved_medium_tank_chassis has_tech = advanced_medium_tank_chassis }
				has_equipment = { medium_tank_chassis < 250 }
			}

			add_equipment_to_stockpile = { type = medium_tank_chassis amount = 250 }
		}
		if = {
			limit = {
				OR = { has_tech = basic_medium_tank_chassis has_tech = improved_medium_tank_chassis has_tech = advanced_medium_tank_chassis }
				has_equipment = { medium_tank_destroyer_chassis < 250 }
			}

			add_equipment_to_stockpile = { type = medium_tank_destroyer_chassis amount = 250 }
		}
		if = {
			limit = {
				OR = { has_tech = basic_medium_tank_chassis has_tech = improved_medium_tank_chassis has_tech = advanced_medium_tank_chassis }
				has_equipment = { medium_tank_artillery_chassis < 250 }
			}

			add_equipment_to_stockpile = { type = medium_tank_artillery_chassis amount = 250 }
		}
		if = {
			limit = {
				OR = { has_tech = basic_medium_tank_chassis has_tech = improved_medium_tank_chassis has_tech = advanced_medium_tank_chassis }
				has_equipment = { medium_tank_aa_chassis < 250 }
			}

			add_equipment_to_stockpile = { type = medium_tank_aa_chassis amount = 250 }
		}

		#####################################################################################################
		if = {
			limit = {
				OR = { has_tech = basic_heavy_tank_chassis has_tech = improved_heavy_tank_chassis has_tech = advanced_heavy_tank_chassis }
				has_equipment = { heavy_tank_chassis < 250 }
			}

			add_equipment_to_stockpile = { type = heavy_tank_chassis amount = 250 }
		}
		if = {
			limit = {
				OR = { has_tech = basic_heavy_tank_chassis has_tech = improved_heavy_tank_chassis has_tech = advanced_heavy_tank_chassis }
				has_equipment = { heavy_tank_destroyer_chassis < 250 }
			}

			add_equipment_to_stockpile = { type = heavy_tank_destroyer_chassis amount = 250 }
		}
		if = {
			limit = {
				OR = { has_tech = basic_heavy_tank_chassis has_tech = improved_heavy_tank_chassis has_tech = advanced_heavy_tank_chassis }
				has_equipment = { heavy_tank_artillery_chassis < 250 }
			}

			add_equipment_to_stockpile = { type = heavy_tank_artillery_chassis amount = 250 }
		}
		if = {
			limit = {
				OR = { has_tech = basic_heavy_tank_chassis has_tech = improved_heavy_tank_chassis has_tech = advanced_heavy_tank_chassis }
				has_equipment = { heavy_tank_aa_chassis < 250 }
			}

			add_equipment_to_stockpile = { type = heavy_tank_aa_chassis amount = 250 }
		}

		#####################################################################################################
		if = {
			limit = {
				has_tech = main_battle_tank
				has_equipment = { modern_tank_chassis < 250 }
			}

			add_equipment_to_stockpile = { type = modern_tank_chassis amount = 250 }
		}
		if = {
			limit = {
				has_tech = modern_td
				has_equipment = { modern_tank_destroyer_chassis < 250 }
			}

			add_equipment_to_stockpile = { type = modern_tank_destroyer_chassis amount = 250 }
		}
		if = {
			limit = {
				has_tech = modern_art
				has_equipment = { modern_tank_artillery_chassis < 250 }
			}

			add_equipment_to_stockpile = { type = modern_tank_artillery_chassis amount = 250 }
		}
		if = {
			limit = {
				has_tech = modern_spaa
				has_equipment = { modern_tank_aa_chassis < 250 }
			}

			add_equipment_to_stockpile = { type = modern_tank_aa_chassis amount = 250 }
		}

		#####################################################################################################

		# UNITS

		if = { limit = { NOT = { has_country_flag = EAI_infantry_division_limit } }

			EAI_DIFFICULTY_get_templates = yes

			if = {
				limit = {
					any_owned_state = {
						is_fully_controlled_by = ROOT

						is_in_home_area = yes

						any_neighbor_state = {
							is_controlled_by = ROOT

							any_neighbor_state = {
								OR = {
									CONTROLLER = { has_war_with = ROOT }
									AND = { is_controlled_by = ROOT NOT = { is_fully_controlled_by = ROOT } }
								}
							}
						}

						NOT = {
							any_neighbor_state = {
								OR = {
									CONTROLLER = { has_war_with = ROOT }
									AND = { is_controlled_by = ROOT NOT = { is_fully_controlled_by = ROOT } }
								}
							}
						}
					}
				}
				random_owned_state = {
					limit = {
						is_fully_controlled_by = ROOT

						is_in_home_area = yes

						any_neighbor_state = {
							is_controlled_by = ROOT

							any_neighbor_state = {
								OR = {
									CONTROLLER = { has_war_with = ROOT }
									AND = { is_controlled_by = ROOT NOT = { is_fully_controlled_by = ROOT } }
								}
							}
						}

						NOT = {
							any_neighbor_state = {
								OR = {
									CONTROLLER = { has_war_with = ROOT }
									AND = { is_controlled_by = ROOT NOT = { is_fully_controlled_by = ROOT } }
								}
							}
						}
					}

					if = { limit = { ROOT = { has_country_flag = EAI_difficulty_logging } } log = "[GetYear] [GetMonth] | DIFFICULTY | [Root.GetName] | REINFORCEMENTS: spawning units (prio 1)" } 

					random_list = {
						1 = {
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
						}
						1 = {
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
						}
						1 = {
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
						}
					}
				}
			}
			else_if = {
				limit = {
					any_owned_state = {
						is_fully_controlled_by = ROOT

						is_in_home_area = yes

						NOT = {
							any_neighbor_state = {
								OR = {
									CONTROLLER = { has_war_with = ROOT }
									AND = { is_controlled_by = ROOT NOT = { is_fully_controlled_by = ROOT } }
								}
							}
						}
					}
				}

				if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [Root.GetName] | REINFORCEMENTS: spawning units (prio 2)" } 
				
				random_owned_state = {
					limit = {
						is_fully_controlled_by = ROOT

						is_in_home_area = yes

						NOT = {
							any_neighbor_state = {
								OR = {
									CONTROLLER = { has_war_with = ROOT }
									AND = { is_controlled_by = ROOT NOT = { is_fully_controlled_by = ROOT } }
								}
							}
						}
					}

					random_list = {
						1 = {
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
						}
						1 = {
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
						}
						1 = {
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
						}
					}
				}
			}
			else_if = {
				limit = {
					any_owned_state = {
						is_fully_controlled_by = ROOT

						is_in_home_area = yes
					}
				}

				if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [Root.GetName] | REINFORCEMENTS: spawning units (prio 3)" } 
				
				random_owned_state = {
					limit = {
						is_fully_controlled_by = ROOT

						is_in_home_area = yes
					}

					random_list = {
						1 = {
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
						}
						1 = {
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
						}
						1 = {
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
						}
					}
				}
			}
			else_if = {
				limit = {
					any_owned_state = {
						is_fully_controlled_by = ROOT

						NOT = {
							any_neighbor_state = {
								OR = {
									CONTROLLER = { has_war_with = ROOT }
									AND = { is_controlled_by = ROOT NOT = { is_fully_controlled_by = ROOT } }
								}
							}
						}
					}
				}

				if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [Root.GetName] | REINFORCEMENTS: spawning units (prio 4)" } 

				random_owned_state = {
					limit = {
						is_fully_controlled_by = ROOT

						NOT = {
							any_neighbor_state = {
								OR = {
									CONTROLLER = { has_war_with = ROOT }
									AND = { is_controlled_by = ROOT NOT = { is_fully_controlled_by = ROOT } }
								}
							}
						}
					}

					random_list = {
						1 = {
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
						}
						1 = {
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
						}
						1 = {
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
						}
					}
				}
			}
			else_if = {
				limit = {}

				if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [Root.GetName] | REINFORCEMENTS: spawning units (prio 5)" } 

				random_owned_state = {
					limit = {
						ROOT = { has_full_control_of_state = PREV }
					}

					random_list = {
						1 = {
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
						}
						1 = {
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
						}
						1 = {
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
							EAI_DIFFICULTY_spawn_unit = yes
						}
					}
				}
			}
		}
	}
}