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

######################################################
#	reinforcements mode
######################################################

EAI_DIFFICULTY_get_templates = {

	### inf

	set_temp_variable = { t1 = 1 }

	while_loop_effect = { limit = { check_variable = { t1 < 50 } }

		if = {
			limit = {
				meta_trigger = {
					text = { has_template = "Infantry template [x]" }
					x = "[?t1]"
				}
			}

			set_temp_variable = { EAI_dd_inf_template = t1 }
			add_to_temp_variable = { t1 = 1 }
		}
		else = { set_temp_variable = { break = 1 } }
	}
	
	### mot

	set_temp_variable = { t1 = 1 }

	while_loop_effect = { limit = { check_variable = { t1 < 50 } }

		if = {
			limit = {
				meta_trigger = {
					text = { has_template = "Motorized Infantry template [x]" }
					x = "[?t1]"
				}
			}

			set_temp_variable = { EAI_dd_mot_template = t1 }
			add_to_temp_variable = { t1 = 1 }
		}
		else = { set_temp_variable = { break = 1 } }
	}

	### arm

	if = { 
		limit = { 
			ROOT = { 
				NOT = { has_country_flag = EAI_mod_template_upgrade }
				OR = { 
					check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_MARM_FOCUS } 
					AND = { check_variable = { EAI_FOCUS/LAND/attachment = global.EAI_MARM_ATTACHMENT } NOT = { check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_HARM_FOCUS } } } 
				}
			} 
		}

		set_temp_variable = { t1 = 1 }

		while_loop_effect = { limit = { check_variable = { t1 < 50 } }

			if = {
				limit = {
					meta_trigger = {
						text = { has_template = "Medium Tank template [x]" }
						x = "[?t1]"
					}
				}

				set_temp_variable = { EAI_dd_arm_template = t1 }
				add_to_temp_variable = { t1 = 1 }
			}
			else = { set_temp_variable = { break = 1 } }
		}
	}
	else_if = { 
		limit = { 
			ROOT = { 
				NOT = { has_country_flag = EAI_mod_template_upgrade }
				OR = { 
					check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_HARM_FOCUS } 
					AND = { check_variable = { EAI_FOCUS/LAND/attachment = global.EAI_HARM_ATTACHMENT } NOT = { check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_MARM_FOCUS } } } 
				}
			} 
		}

		set_temp_variable = { t1 = 1 }

		while_loop_effect = { limit = { check_variable = { t1 < 50 } }

			if = {
				limit = {
					meta_trigger = {
						text = { has_template = "Heavy Tank template [x]" }
						x = "[?t1]"
					}
				}

				set_temp_variable = { EAI_dd_arm_template = t1 }
				add_to_temp_variable = { t1 = 1 }
			}
			else = { set_temp_variable = { break = 1 } }
		}
	}
	else_if = { 
		limit = { 
			ROOT = { 
				has_country_flag = EAI_mod_template_upgrade
				OR = { 
					check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_MARM_FOCUS } check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_HARM_FOCUS } 
					check_variable = { EAI_FOCUS/LAND/attachment = global.EAI_MARM_ATTACHMENT } check_variable = { EAI_FOCUS/LAND/attachment = global.EAI_HARM_ATTACHMENT } 
				}
			} 
		}

		set_temp_variable = { t1 = 1 }

		while_loop_effect = { limit = { check_variable = { t1 < 50 } }

			if = {
				limit = {
					meta_trigger = {
						text = { has_template = "Modern Tank template [x]" }
						x = "[?t1]"
					}
				}

				set_temp_variable = { EAI_dd_arm_template = t1 }
				add_to_temp_variable = { t1 = 1 }
			}
			else = { set_temp_variable = { break = 1 } }
		}
	}
	else_if = { 
		limit = { 
			ROOT = { 
				OR = {
					check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_LARM_FOCUS }
					check_variable = { EAI_FOCUS/LAND/attachment = global.EAI_LARM_ATTACHMENT }
				}
				NOT = { check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_MARM_FOCUS } check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_HARM_FOCUS } }
			} 
		}

		set_temp_variable = { t1 = 1 }

		while_loop_effect = { limit = { check_variable = { t1 < 50 } }

			if = {
				limit = {
					meta_trigger = {
						text = { has_template = "Light Tank template [x]" }
						x = "[?t1]"
					}
				}

				set_temp_variable = { EAI_dd_arm_template = t1 }
				add_to_temp_variable = { t1 = 1 }
			}
			else = { set_temp_variable = { break = 1 } }
		}
	}
}

EAI_DIFFICULTY_spawn_unit = {

	ROOT = { add_to_variable = { var = EAI_dd_unit_count value = 1 } }
	ROOT = { add_to_variable = { var = global.EAI_global_dd_unit_count value = 1 } }
	
	random_list = {
		7 = { EAI_DIFFICULTY_spawn_inf = yes }
		2 = { EAI_DIFFICULTY_spawn_mot = yes }
		1 = { EAI_DIFFICULTY_spawn_arm = yes }
	}
}

EAI_DIFFICULTY_spawn_inf = {

	if = { limit = { check_variable = { EAI_dd_inf_template > 0 } ROOT = { has_manpower > 9000 } }

		if = { limit = { ROOT = { has_country_flag = EAI_difficulty_logging } } log = "[GetYear] [GetMonth] | DIFFICULTY | [Root.GetName] | REINFORCEMENTS: inf" } 

		ROOT = { add_manpower = -9000 }
		
		meta_effect = {
			text = { create_unit = { division = "division_template = \"Infantry template [x]\" start_experience_factor = [y]" owner = ROOT } }
			x = "[?EAI_dd_inf_template]"
			y = "[?random|.2]"
		}
	}
	else_if = { limit = { ROOT = { has_manpower > 9000 } }
		
		if = { limit = { ROOT = { NOT = { has_template = "Infantry reinforement" } } }

			ROOT = { add_manpower = -9000 }
		
			ROOT = {
				division_template = {
					name = "Infantry reinforement"

					regiments = {
						infantry = { x = 0 y = 0 }
						infantry = { x = 0 y = 1 }
						infantry = { x = 0 y = 2 }

						infantry = { x = 1 y = 0 }
						infantry = { x = 1 y = 1 }
						infantry = { x = 1 y = 2 }

						infantry = { x = 2 y = 0 }
						infantry = { x = 2 y = 1 }
						infantry = { x = 2 y = 2 }
					}
				}
			}
		}

		meta_effect = {
			text = { create_unit = { division = "division_template = \"Infantry reinforement\" start_experience_factor = [y]" owner = ROOT } }
			y = "[?random|.2]"
		}
	}
}

EAI_DIFFICULTY_spawn_mot = {

	if = { limit = { check_variable = { EAI_dd_mot_template > 0 } ROOT = { has_manpower > 9000 } }

		if = { limit = { ROOT = { has_country_flag = EAI_difficulty_logging } } log = "[GetYear] [GetMonth] | DIFFICULTY | [Root.GetName] | REINFORCEMENTS: mot" } 

		ROOT = { add_manpower = -9000 }
		
		meta_effect = {
			text = { create_unit = { division = "division_template = \"Motorized Infantry template [x]\" start_experience_factor = [y]" owner = ROOT } }
			x = "[?EAI_dd_mot_template]"
			y = "[?random|.2]"
		}
	}
	else = { EAI_DIFFICULTY_spawn_inf = yes }
}

EAI_DIFFICULTY_spawn_arm = {

	if = { limit = { check_variable = { EAI_dd_arm_template > 0 } ROOT = { has_manpower > 9000 } }

		if = { limit = { ROOT = { has_country_flag = EAI_difficulty_logging } } log = "[GetYear] [GetMonth] | DIFFICULTY | [Root.GetName] | REINFORCEMENTS: arm" } 

		ROOT = { add_manpower = -9000 }

		if = { 
			limit = { 
				ROOT = { 
					NOT = { has_country_flag = EAI_mod_template_upgrade }
					OR = { 
						check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_MARM_FOCUS } 
						AND = { check_variable = { EAI_FOCUS/LAND/attachment = global.EAI_MARM_ATTACHMENT } NOT = { check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_HARM_FOCUS } } } 
					}
				} 
			}

			meta_effect = {
				text = { create_unit = { division = "division_template = \"Medium Tank template [x]\" start_experience_factor = [y]" owner = ROOT } }
				x = "[?EAI_dd_arm_template]"
				y = "[?random|.2]"
			}
		}
		else_if = { 
			limit = { 
				ROOT = { 
					NOT = { has_country_flag = EAI_mod_template_upgrade }
					OR = { 
						check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_HARM_FOCUS } 
						AND = { check_variable = { EAI_FOCUS/LAND/attachment = global.EAI_HARM_ATTACHMENT } NOT = { check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_MARM_FOCUS } } } 
					}
				} 
			}

			meta_effect = {
				text = { create_unit = { division = "division_template = \"Heavy Tank template [x]\" start_experience_factor = [y]" owner = ROOT } }
				x = "[?EAI_dd_arm_template]"
				y = "[?random|.2]"
			}
		}
		else_if = { 
			limit = { 
				ROOT = { 
					has_country_flag = EAI_mod_template_upgrade
					OR = { 
						check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_MARM_FOCUS } check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_HARM_FOCUS } 
						check_variable = { EAI_FOCUS/LAND/attachment = global.EAI_MARM_ATTACHMENT } check_variable = { EAI_FOCUS/LAND/attachment = global.EAI_HARM_ATTACHMENT } 
					}
				} 
			}

			meta_effect = {
				text = { create_unit = { division = "division_template = \"Modern Tank template [x]\" start_experience_factor = [y]" owner = ROOT } }
				x = "[?EAI_dd_arm_template]"
				y = "[?random|.2]"
			}
		}
		else_if = { 
			limit = { 
				ROOT = { 
					OR = {
						check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_LARM_FOCUS }
						check_variable = { EAI_FOCUS/LAND/attachment = global.EAI_LARM_ATTACHMENT }
					}
					NOT = { check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_MARM_FOCUS } check_variable = { EAI_FOCUS/LAND/armor_focus = global.EAI_HARM_FOCUS } }
				} 
			}

			meta_effect = {
				text = { create_unit = { division = "division_template = \"Light Tank template [x]\" start_experience_factor = [y]" owner = ROOT } }
				x = "[?EAI_dd_arm_template]"
				y = "[?random|.2]"
			}
		}
	}
	else = { EAI_DIFFICULTY_spawn_mot = yes }
}

######################################################
#	custom bonus #CB
######################################################

EAI_DIFFICULTY_custom_bonus_shift_click = { 

	meta_effect = {
		text = {
			set_temp_variable = { t1 = 0.2 }
			multiply_temp_variable = { t1 = [y] }
			subtract_from_variable = { [z]EAI_custom_bonus_[x][w] = t1 }
			clamp_variable = { var = [z]EAI_custom_bonus_[x][w] min = [a] max = [b] }
		}
		x = "[?EAI_selected_custom_bonus_setting]"
		y = "[EAI_GetCustomBonusAmountMultiplier]"
		z = "[EAI_GetDifficultyBonusMode]"
		a = "[EAI_GetCustomBonusAmountMin]"
		b = "[EAI_GetCustomBonusAmountMax]"
		w = "[EAI_GetDifficultyBonusMode2]"
	}

	EAI_refresh_gui = yes
}
EAI_DIFFICULTY_custom_bonus_control_click = { 

	meta_effect = {
		text = {
			set_temp_variable = { t1 = 0.05 }
			multiply_temp_variable = { t1 = [y] }
			subtract_from_variable = { [z]EAI_custom_bonus_[x][w] = t1 }
			clamp_variable = { var = [z]EAI_custom_bonus_[x][w] min = [a] max = [b] }
		}
		x = "[?EAI_selected_custom_bonus_setting]"
		y = "[EAI_GetCustomBonusAmountMultiplier]"
		z = "[EAI_GetDifficultyBonusMode]"
		a = "[EAI_GetCustomBonusAmountMin]"
		b = "[EAI_GetCustomBonusAmountMax]"
		w = "[EAI_GetDifficultyBonusMode2]"
	}

	EAI_refresh_gui = yes
}
EAI_DIFFICULTY_custom_bonus_click = { 

	meta_effect = {
		text = {
			set_temp_variable = { t1 = 0.01 }
			multiply_temp_variable = { t1 = [y] }
			subtract_from_variable = { [z]EAI_custom_bonus_[x][w] = t1 }
			clamp_variable = { var = [z]EAI_custom_bonus_[x][w] min = [a] max = [b] }
		}
		x = "[?EAI_selected_custom_bonus_setting]"
		y = "[EAI_GetCustomBonusAmountMultiplier]"
		z = "[EAI_GetDifficultyBonusMode]"
		a = "[EAI_GetCustomBonusAmountMin]"
		b = "[EAI_GetCustomBonusAmountMax]"
		w = "[EAI_GetDifficultyBonusMode2]"
	}

	EAI_refresh_gui = yes
}
EAI_DIFFICULTY_custom_bonus_shift_right_click = {

	meta_effect = {
		text = {
			set_temp_variable = { t1 = 0.2 }
			multiply_temp_variable = { t1 = [y] }
			add_to_variable = { [z]EAI_custom_bonus_[x][w] = t1 }
			clamp_variable = { var = [z]EAI_custom_bonus_[x][w] min = [a] max = [b] }
		}
		x = "[?EAI_selected_custom_bonus_setting]"
		y = "[EAI_GetCustomBonusAmountMultiplier]"
		z = "[EAI_GetDifficultyBonusMode]"
		a = "[EAI_GetCustomBonusAmountMin]"
		b = "[EAI_GetCustomBonusAmountMax]"
		w = "[EAI_GetDifficultyBonusMode2]"
	}

	EAI_refresh_gui = yes
}
EAI_DIFFICULTY_custom_bonus_control_right_click = { 

	meta_effect = {
		text = {
			set_temp_variable = { t1 = 0.05 }
			multiply_temp_variable = { t1 = [y] }
			add_to_variable = { [z]EAI_custom_bonus_[x][w] = t1 }
			clamp_variable = { var = [z]EAI_custom_bonus_[x][w] min = [a] max = [b] }
		}
		x = "[?EAI_selected_custom_bonus_setting]"
		y = "[EAI_GetCustomBonusAmountMultiplier]"
		z = "[EAI_GetDifficultyBonusMode]"
		a = "[EAI_GetCustomBonusAmountMin]"
		b = "[EAI_GetCustomBonusAmountMax]"
		w = "[EAI_GetDifficultyBonusMode2]"
	}

	EAI_refresh_gui = yes
}
EAI_DIFFICULTY_custom_bonus_right_click = { 

	meta_effect = {
		text = {
			set_temp_variable = { t1 = 0.01 }
			multiply_temp_variable = { t1 = [y] }
			add_to_variable = { [z]EAI_custom_bonus_[x][w] = t1 }
			clamp_variable = { var = [z]EAI_custom_bonus_[x][w] min = [a] max = [b] }
		}
		x = "[?EAI_selected_custom_bonus_setting]"
		y = "[EAI_GetCustomBonusAmountMultiplier]"
		z = "[EAI_GetDifficultyBonusMode]"
		a = "[EAI_GetCustomBonusAmountMin]"
		b = "[EAI_GetCustomBonusAmountMax]"
		w = "[EAI_GetDifficultyBonusMode2]"
	}

	EAI_refresh_gui = yes
}

### country variable localization issue fix #CB

@NUM_CUSTOM_BONUSES = 38

EAI_DIFFICULTY_get_custom_bonus_settings = {

	set_temp_variable = { custom_bonus_settings = @NUM_CUSTOM_BONUSES }
	while_loop_effect = { limit = { check_variable = { custom_bonus_settings > 0 } }
		meta_effect = {
			text = { var:EAI_configuration_target = { set_variable = { Root.EAI_custom_bonus_[x]_temp = This.EAI_custom_bonus_[x] } } }
			x = "[?custom_bonus_settings]"
		}
		subtract_from_temp_variable = { custom_bonus_settings = 1 }
	}
}
EAI_DIFFICULTY_set_custom_bonus_settings = {

	set_temp_variable = { custom_bonus_settings = @NUM_CUSTOM_BONUSES }
	while_loop_effect = { limit = { check_variable = { custom_bonus_settings > 0 } }
		meta_effect = {
			text = { 
				var:EAI_configuration_target = { set_variable = { This.EAI_custom_bonus_[x] = Root.EAI_custom_bonus_[x]_temp } } 
			}
			x = "[?custom_bonus_settings]"
		}
		subtract_from_temp_variable = { custom_bonus_settings = 1 }
	}
	var:EAI_configuration_target = { force_update_dynamic_modifier = yes }
}
EAI_DIFFICULTY_clear_custom_bonus_settings = {

	set_temp_variable = { custom_bonus_settings = @NUM_CUSTOM_BONUSES }
	while_loop_effect = { limit = { check_variable = { custom_bonus_settings > 0 } }
		meta_effect = {
			text = { clear_variable = Root.EAI_custom_bonus_[x]_temp }
			x = "[?custom_bonus_settings]"
		}
		subtract_from_temp_variable = { custom_bonus_settings = 1 }
	}
}

###

EAI_config_CUSTOM_BONUS_copy_settings = {
	if = { limit = { has_country_flag = EAI_config_COUNTRY }

		set_temp_variable = { custom_bonus_settings = @NUM_CUSTOM_BONUSES }
		while_loop_effect = { limit = { check_variable = { custom_bonus_settings > 0 } }
			meta_effect = {
				text = { set_variable = { Root.EAI_custom_bonus_[x]_saved = Root.EAI_custom_bonus_[x]_temp } }
				x = "[?custom_bonus_settings]"
			}
			subtract_from_temp_variable = { custom_bonus_settings = 1 }
		}
	}
	else = {

		set_temp_variable = { custom_bonus_settings = @NUM_CUSTOM_BONUSES }
		while_loop_effect = { limit = { check_variable = { custom_bonus_settings > 0 } }
			meta_effect = {
				text = { set_variable = { Root.EAI_custom_bonus_[x]_saved = global.EAI_custom_bonus_[x] } }
				x = "[?custom_bonus_settings]"
			}
			subtract_from_temp_variable = { custom_bonus_settings = 1 }
		}
	}
}

EAI_config_CUSTOM_BONUS_paste_settings = {
	if = { limit = { has_country_flag = EAI_config_COUNTRY }

		set_temp_variable = { custom_bonus_settings = @NUM_CUSTOM_BONUSES }
		while_loop_effect = { limit = { check_variable = { custom_bonus_settings > 0 } }
			meta_effect = {
				text = { set_variable = { Root.EAI_custom_bonus_[x]_temp = Root.EAI_custom_bonus_[x]_saved } }
				x = "[?custom_bonus_settings]"
			}
			subtract_from_temp_variable = { custom_bonus_settings = 1 }
		}
	}
	else = {

		set_temp_variable = { custom_bonus_settings = @NUM_CUSTOM_BONUSES }
		while_loop_effect = { limit = { check_variable = { custom_bonus_settings > 0 } }
			meta_effect = {
				text = { set_variable = { global.EAI_custom_bonus_[x] = Root.EAI_custom_bonus_[x]_saved } }
				x = "[?custom_bonus_settings]"
			}
			subtract_from_temp_variable = { custom_bonus_settings = 1 }
		}
	}
}

######################################################
#	misc
######################################################

# two equipment cost reduction ideas cant be allowed to be active at the same time so the highest is used
EAI_DIFFICULTY_fix_equipment_modifier_conflict = { 
		
	if = { limit = { has_variable = EAI_difficulty_equipment_bonus_active has_variable = EAI_dd_equipment_bonus_active }

		if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [This.GetName] | DD: EAI_DIFFICULTY_fix_equipment_modifier_conflict" } 

		if = { limit = { check_variable = { EAI_difficulty_equipment_bonus_active = 1 } } # -15%

			if = { limit = { check_variable = { EAI_dd_equipment_bonus_active > 6 } }

				EAI_DIFFICULTY_clear_equipment_modifier_HARD = yes	
			}
			else = {
				EAI_DIFFICULTY_clear_equipment_modifier_DD = yes
			}
		}
		
		else_if = { limit = { check_variable = { EAI_difficulty_equipment_bonus_active = 2 } } # -30%

			if = { limit = { check_variable = { EAI_dd_equipment_bonus_active > 12 } }

				EAI_DIFFICULTY_clear_equipment_modifier_VERY_HARD = yes	
			}
			else = {
				EAI_DIFFICULTY_clear_equipment_modifier_DD = yes
			}
		}
		
		else_if = { limit = { check_variable = { EAI_difficulty_equipment_bonus_active = 3 } } # -45%

			if = { limit = { check_variable = { EAI_dd_equipment_bonus_active > 18 } }

				EAI_DIFFICULTY_clear_equipment_modifier_INSANE = yes	
			}
			else = {
				EAI_DIFFICULTY_clear_equipment_modifier_DD = yes
			}
		}
	}
}

######################################################
#	difficulty bonus #CB
######################################################

### custom difficulty bonus presets

EAI_DIFFICULTY_clear_difficulty_custom_modifiers = {

	meta_effect = {
		text = {
			#industrial_capacity_factory 
			clear_variable = [x]EAI_custom_bonus_1
    		#industrial_capacity_dockyard 
			clear_variable = [x]EAI_custom_bonus_2
			#production_factory_efficiency_gain_factor 
			clear_variable = [x]EAI_custom_bonus_3
			#production_speed_buildings_factor 
			clear_variable = [x]EAI_custom_bonus_4
			#local_resources_factor 
			clear_variable = [x]EAI_custom_bonus_5
			#production_lack_of_resource_penalty_factor 
			clear_variable = [x]EAI_custom_bonus_6
			#industry_repair_factor 
			clear_variable = [x]EAI_custom_bonus_7
			#conscription 
			clear_variable = [x]EAI_custom_bonus_8
			#political_power_factor 
			clear_variable = [x]EAI_custom_bonus_9
			#research_speed_factor 
			clear_variable = [x]EAI_custom_bonus_10
			#attrition 
			clear_variable = [x]EAI_custom_bonus_11
			#army_morale_factor 
			clear_variable = [x]EAI_custom_bonus_12
			#supply_consumption_factor 
			clear_variable = [x]EAI_custom_bonus_13
			#dig_in_speed_factor 
			clear_variable = [x]EAI_custom_bonus_14
			#planning_speed 
			clear_variable = [x]EAI_custom_bonus_15
			#army_fuel_consumption_factor 
			clear_variable = [x]EAI_custom_bonus_16
			#air_fuel_consumption_factor 
			clear_variable = [x]EAI_custom_bonus_17
			#navy_fuel_consumption_factor 
			clear_variable = [x]EAI_custom_bonus_18
			#army_core_attack_factor 
			clear_variable = [x]EAI_custom_bonus_19
			#army_core_defence_factor 
			clear_variable = [x]EAI_custom_bonus_20
			#stability_factor 
			clear_variable = [x]EAI_custom_bonus_21
			#army_attack_factor 
			clear_variable = [x]EAI_custom_bonus_22
			#war_support_factor 
			clear_variable = [x]EAI_custom_bonus_23
			#army_defence_factor 
			clear_variable = [x]EAI_custom_bonus_24
			#adaptive eq cost reduction 
			clear_variable = [x]EAI_custom_bonus_25
			#free convoys
			clear_variable = [x]EAI_custom_bonus_26
			#max building slots
			clear_variable = [x]EAI_custom_bonus_27
			#training time
			clear_variable = [x]EAI_custom_bonus_28
			#resistance_target_on_our_occupied_states
			clear_variable = [x]EAI_custom_bonus_29
			#autonomy_gain_global_factor
			clear_variable = [x]EAI_custom_bonus_30
			#resistance_damage_to_garrison
			clear_variable = [x]EAI_custom_bonus_31
			#surrender_limit
			clear_variable = [x]EAI_custom_bonus_32
			#army_org_factor
			clear_variable = [x]EAI_custom_bonus_33
			#negate resource deficits
			clear_variable = [x]EAI_custom_bonus_34
			#invasion_preparation
			clear_variable = [x]EAI_custom_bonus_35
			#naval_invasion_penalty
			clear_variable = [x]EAI_custom_bonus_36
			#supply units
			clear_variable = [x]EAI_custom_bonus_37
			#naval_invasion_division_cap
			clear_variable = [x]EAI_custom_bonus_38
		}
		x = "[EAI_GetDifficultyBonusMode]"
	}

	if = { limit = { has_dynamic_modifier = { modifier = EAI_difficulty_bonus_modifier } } remove_dynamic_modifier = { modifier = EAI_difficulty_bonus_modifier } }
	if = { limit = { has_dynamic_modifier = { modifier = EAI_dynamic_difficulty_bonus_modifier } } remove_dynamic_modifier = { modifier = EAI_dynamic_difficulty_bonus_modifier } }
}
EAI_DIFFICULTY_set_hard_difficulty_custom_modifiers = {

	meta_effect = {
		text = {
			#industrial_capacity_factory 
			set_variable = { [x]EAI_custom_bonus_1 = 0.0 }
   			#industrial_capacity_dockyard 
			set_variable = { [x]EAI_custom_bonus_2 = 0.25 }
			#production_factory_efficiency_gain_factor 
			set_variable = { [x]EAI_custom_bonus_3 = 0.25 }
			#production_speed_buildings_factor 
			set_variable = { [x]EAI_custom_bonus_4 = 0.0 }
			#local_resources_factor 
			set_variable = { [x]EAI_custom_bonus_5 = 0.0 }
			#production_lack_of_resource_penalty_factor 
			set_variable = { [x]EAI_custom_bonus_6 = -0.25 }
			#industry_repair_factor 
			set_variable = { [x]EAI_custom_bonus_7 = 0.2 }
			#conscription 
			set_variable = { [x]EAI_custom_bonus_8 = 0.01 }
			#political_power_factor 
			set_variable = { [x]EAI_custom_bonus_9 = 0.0 }
			#research_speed_factor 
			set_variable = { [x]EAI_custom_bonus_10 = 0.0 }
			#attrition 
			set_variable = { [x]EAI_custom_bonus_11 = 0.0 }
			#army_morale_factor 
			set_variable = { [x]EAI_custom_bonus_12 = 0.0 }
			#supply_consumption_factor 
			set_variable = { [x]EAI_custom_bonus_13 = -0.05 }
			#dig_in_speed_factor 
			set_variable = { [x]EAI_custom_bonus_14 = 0.0 }
			#planning_speed 
			set_variable = { [x]EAI_custom_bonus_15 = 0.0 }
			#army_fuel_consumption_factor 
			set_variable = { [x]EAI_custom_bonus_16 = -0.1 }
			#air_fuel_consumption_factor 
			set_variable = { [x]EAI_custom_bonus_17 = -0.1 }
			#navy_fuel_consumption_factor 
			set_variable = { [x]EAI_custom_bonus_18 = -0.1 }
			#army_core_attack_factor 
			set_variable = { [x]EAI_custom_bonus_19 = 0.0 }
			#army_core_defence_factor 
			set_variable = { [x]EAI_custom_bonus_20 = 0.0 }
			#stability_factor 
			set_variable = { [x]EAI_custom_bonus_21 = 0.0 }
			#army_attack_factor 
			set_variable = { [x]EAI_custom_bonus_22 = 0.0 }
			#war_support 
			set_variable = { [x]EAI_custom_bonus_23 = 0.0 }
			#army_defense_factor 
			set_variable = { [x]EAI_custom_bonus_24 = 0.0 }
			#adaptive eq cost reduction 
			set_variable = { [x]EAI_custom_bonus_25 = 1 }
			#free convoys
			set_variable = { [x]EAI_custom_bonus_26 = 0 }
			#max building slots
			set_variable = { [x]EAI_custom_bonus_27 = 0 }
			#training time
			set_variable = { [x]EAI_custom_bonus_28 = -0.2 }
			#resistance_target_on_our_occupied_states
			set_variable = { [x]EAI_custom_bonus_29 = 0 }
			#autonomy_gain_global_factor
			set_variable = { [x]EAI_custom_bonus_30 = 0 }
			#resistance_damage_to_garrison
			set_variable = { [x]EAI_custom_bonus_31 = -0.25 }
			#surrender_limit
			set_variable = { [x]EAI_custom_bonus_32 = 0.02 }
			#army_org_factor
			set_variable = { [x]EAI_custom_bonus_33 = 0 }
			#negate resource deficits
			set_variable = { [x]EAI_custom_bonus_34 = 0 }
			#invasion_preparation
			set_variable = { [x]EAI_custom_bonus_35 = -0.2 }
			#naval_invasion_penalty
			set_variable = { [x]EAI_custom_bonus_36 = -0.2 }
			#supply units
			set_variable = { [x]EAI_custom_bonus_37 = 1 }
			#naval_invasion_division_cap
			set_variable = { [x]EAI_custom_bonus_38 = 12 }
		}
		x = "[EAI_GetDifficultyBonusMode]"
	}

	if = { limit = { ROOT = { has_country_flag = EAI_config_COUNTRY } NOT = { has_dynamic_modifier = { modifier = EAI_difficulty_bonus_modifier } } } 
		add_dynamic_modifier = { modifier = EAI_difficulty_bonus_modifier } 
	}

	force_update_dynamic_modifier = yes
}
EAI_DIFFICULTY_set_very_hard_difficulty_custom_modifiers = {

	meta_effect = {
		text = {
			#industrial_capacity_factory 
			set_variable = { [x]EAI_custom_bonus_1 = 0.0 }
    		#industrial_capacity_dockyard 
			set_variable = { [x]EAI_custom_bonus_2 = 0.5 }
			#production_factory_efficiency_gain_factor 
			set_variable = { [x]EAI_custom_bonus_3 = 0.5 }
			#production_speed_buildings_factor 
			set_variable = { [x]EAI_custom_bonus_4 = 0.0 }
			#local_resources_factor 
			set_variable = { [x]EAI_custom_bonus_5 = 0.0 }
			#production_lack_of_resource_penalty_factor 
			set_variable = { [x]EAI_custom_bonus_6 = -0.5 }
			#industry_repair_factor 
			set_variable = { [x]EAI_custom_bonus_7 = 0.4 }
			#conscription 
			set_variable = { [x]EAI_custom_bonus_8 = 0.02 }
			#political_power_factor 
			set_variable = { [x]EAI_custom_bonus_9 = 0.0 }
			#research_speed_factor 
			set_variable = { [x]EAI_custom_bonus_10 = 0.0 }
			#attrition 
			set_variable = { [x]EAI_custom_bonus_11 = 0.0 }
			#army_morale_factor 
			set_variable = { [x]EAI_custom_bonus_12 = 0.0 }
			#supply_consumption_factor 
			set_variable = { [x]EAI_custom_bonus_13 = -0.10 }
			#dig_in_speed_factor 
			set_variable = { [x]EAI_custom_bonus_14 = 0.0 }
			#planning_speed 
			set_variable = { [x]EAI_custom_bonus_15 = 0.0 }
			#army_fuel_consumption_factor 
			set_variable = { [x]EAI_custom_bonus_16 = -0.2 }
			#air_fuel_consumption_factor 
			set_variable = { [x]EAI_custom_bonus_17 = -0.2 }
			#navy_fuel_consumption_factor 
			set_variable = { [x]EAI_custom_bonus_18 = -0.2 }
			#army_core_attack_factor 
			set_variable = { [x]EAI_custom_bonus_19 = 0.0 }
			#army_core_defence_factor 
			set_variable = { [x]EAI_custom_bonus_20 = 0.0 }
			#stability_factor 
			set_variable = { [x]EAI_custom_bonus_21 = 0.0 }
			#army_attack_factor 
			set_variable = { [x]EAI_custom_bonus_22 = 0.0 }
			#war_support 
			set_variable = { [x]EAI_custom_bonus_23 = 0.0 }
			#army_defense_factor 
			set_variable = { [x]EAI_custom_bonus_24 = 0.0 }
			#adaptive eq cost reduction 
			set_variable = { [x]EAI_custom_bonus_25 = 2 }
			#free convoys
			set_variable = { [x]EAI_custom_bonus_26 = 0 }
			#max building slots
			set_variable = { [x]EAI_custom_bonus_27 = 0 }
			#training time
			set_variable = { [x]EAI_custom_bonus_28 = -0.4 }
			#resistance_target_on_our_occupied_states
			set_variable = { [x]EAI_custom_bonus_29 = 0 }
			#autonomy_gain_global_factor
			set_variable = { [x]EAI_custom_bonus_30 = 0 }
			#resistance_damage_to_garrison
			set_variable = { [x]EAI_custom_bonus_31 = -0.5 }
			#surrender_limit
			set_variable = { [x]EAI_custom_bonus_32 = 0.04 }
			#army_org_factor
			set_variable = { [x]EAI_custom_bonus_33 = 0 }
			#negate resource deficits
			set_variable = { [x]EAI_custom_bonus_34 = 0 }
			#invasion_preparation
			set_variable = { [x]EAI_custom_bonus_35 = -0.4 }
			#naval_invasion_penalty
			set_variable = { [x]EAI_custom_bonus_36 = -0.4 }
			#supply units
			set_variable = { [x]EAI_custom_bonus_37 = 3 }
			#naval_invasion_division_cap
			set_variable = { [x]EAI_custom_bonus_38 = 18 }
		}
		x = "[EAI_GetDifficultyBonusMode]"
	}

	if = { limit = { ROOT = { has_country_flag = EAI_config_COUNTRY } NOT = { has_dynamic_modifier = { modifier = EAI_difficulty_bonus_modifier } } } 
		add_dynamic_modifier = { modifier = EAI_difficulty_bonus_modifier } 
	}

	force_update_dynamic_modifier = yes
}
EAI_DIFFICULTY_set_insane_difficulty_custom_modifiers = {

	meta_effect = {
		text = {
			#industrial_capacity_factory 
			set_variable = { [x]EAI_custom_bonus_1 = 0.0 }
    		#industrial_capacity_dockyard 
			set_variable = { [x]EAI_custom_bonus_2 = 1.0 }
			#production_factory_efficiency_gain_factor 
			set_variable = { [x]EAI_custom_bonus_3 = 1.0 }
			#production_speed_buildings_factor 
			set_variable = { [x]EAI_custom_bonus_4 = 0.0 }
			#local_resources_factor 
			set_variable = { [x]EAI_custom_bonus_5 = 0.0 }
			#production_lack_of_resource_penalty_factor 
			set_variable = { [x]EAI_custom_bonus_6 = -0.75 }
			#industry_repair_factor 
			set_variable = { [x]EAI_custom_bonus_7 = 0.6 }
			#conscription 
			set_variable = { [x]EAI_custom_bonus_8 = 0.03 }
			#political_power_factor 
			set_variable = { [x]EAI_custom_bonus_9 = 0.0 }
			#research_speed_factor 
			set_variable = { [x]EAI_custom_bonus_10 = 0.0 }
			#attrition 
			set_variable = { [x]EAI_custom_bonus_11 = 0.0 }
			#army_morale_factor 
			set_variable = { [x]EAI_custom_bonus_12 = 0.0 }
			#supply_consumption_factor 
			set_variable = { [x]EAI_custom_bonus_13 = -0.15 }
			#dig_in_speed_factor 
			set_variable = { [x]EAI_custom_bonus_14 = 0.0 }
			#planning_speed 
			set_variable = { [x]EAI_custom_bonus_15 = 0.0 }
			#army_fuel_consumption_factor 
			set_variable = { [x]EAI_custom_bonus_16 = -0.3 }
			#air_fuel_consumption_factor 
			set_variable = { [x]EAI_custom_bonus_17 = -0.3 }
			#navy_fuel_consumption_factor 
			set_variable = { [x]EAI_custom_bonus_18 = -0.3 }
			#army_core_attack_factor 
			set_variable = { [x]EAI_custom_bonus_19 = 0.0 }
			#army_core_defence_factor 
			set_variable = { [x]EAI_custom_bonus_20 = 0.0 }
			#stability_factor 
			set_variable = { [x]EAI_custom_bonus_21 = 0.0 }
			#army_attack_factor 
			set_variable = { [x]EAI_custom_bonus_22 = 0.0 }
			#war_support 
			set_variable = { [x]EAI_custom_bonus_23 = 0.0 }
			#army_defense_factor 
			set_variable = { [x]EAI_custom_bonus_24 = 0.0 }
			#adaptive eq cost reduction 
			set_variable = { [x]EAI_custom_bonus_25 = 3 }
			#free convoys
			set_variable = { [x]EAI_custom_bonus_26 = 1 }
			#max building slots
			set_variable = { [x]EAI_custom_bonus_27 = 0 }
			#training time
			set_variable = { [x]EAI_custom_bonus_28 = -0.6 }
			#resistance_target_on_our_occupied_states
			set_variable = { [x]EAI_custom_bonus_29 = 0 }
			#autonomy_gain_global_factor
			set_variable = { [x]EAI_custom_bonus_30 = 0 }
			#resistance_damage_to_garrison
			set_variable = { [x]EAI_custom_bonus_31 = -0.75 }
			#surrender_limit
			set_variable = { [x]EAI_custom_bonus_32 = 0.06 }
			#army_org_factor
			set_variable = { [x]EAI_custom_bonus_33 = 0 }
			#negate resource deficits
			set_variable = { [x]EAI_custom_bonus_34 = 0 }
			#invasion_preparation
			set_variable = { [x]EAI_custom_bonus_35 = -0.6 }
			#naval_invasion_penalty
			set_variable = { [x]EAI_custom_bonus_36 = -0.6 }
			#supply units
			set_variable = { [x]EAI_custom_bonus_37 = 5 }
			#naval_invasion_division_cap
			set_variable = { [x]EAI_custom_bonus_38 = 24 }
		}
		x = "[EAI_GetDifficultyBonusMode]"
	}

	if = { limit = { ROOT = { has_country_flag = EAI_config_COUNTRY } NOT = { has_dynamic_modifier = { modifier = EAI_difficulty_bonus_modifier } } } 
		add_dynamic_modifier = { modifier = EAI_difficulty_bonus_modifier } 
	}

	force_update_dynamic_modifier = yes
}

###

EAI_DIFFICULTY_clear_active_difficulty_bonus = {

	clr_country_flag = EAI_difficulty_bonus_active
	
	clr_country_flag = EAI_dynamic_difficulty_bonus_active

	EAI_DIFFICULTY_clear_equipment_modifier_HARD = yes
	EAI_DIFFICULTY_clear_equipment_modifier_VERY_HARD = yes
	EAI_DIFFICULTY_clear_equipment_modifier_INSANE = yes

	if = { limit = { ROOT = { has_country_flag = EAI_config_COUNTRY } }
	
		EAI_DIFFICULTY_clear_difficulty_custom_modifiers = yes
	}

	if = { limit = { has_dynamic_modifier = { modifier = EAI_difficulty_bonus_modifier } } 
	
		remove_dynamic_modifier = { modifier = EAI_difficulty_bonus_modifier }
	}
	
	if = { limit = { has_dynamic_modifier = { modifier = EAI_dynamic_difficulty_bonus_modifier } } 
	
		remove_dynamic_modifier = { modifier = EAI_dynamic_difficulty_bonus_modifier }
	}
}

EAI_DIFFICULTY_apply_equipment_modifier_HARD = {

	if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [This.GetName] | EAI_DIFFICULTY_apply_equipment_modifier_HARD" } 

	set_variable = { EAI_difficulty_equipment_bonus_active = 1 }

	if = { limit = { has_equipment = { infantry_equipment < 5000 } } add_ideas = EAI_HARD/infantry_equipment_bonus else = { remove_ideas = EAI_HARD/infantry_equipment_bonus } }
	if = { limit = { has_equipment = { support_equipment < 500 } } add_ideas = EAI_HARD/support_equipment_bonus else = { remove_ideas = EAI_HARD/support_equipment_bonus } }
	if = { limit = { has_equipment = { artillery_equipment < 500 } } add_ideas = EAI_HARD/artillery_equipment_bonus else = { remove_ideas = EAI_HARD/artillery_equipment_bonus } }
	if = { limit = { has_equipment = { rocket_artillery_equipment < 500 } } add_ideas = EAI_HARD/rocket_artillery_equipment_bonus else = { remove_ideas = EAI_HARD/rocket_artillery_equipment_bonus } }
	if = { limit = { has_equipment = { motorized_rocket_equipment < 500 } } add_ideas = EAI_HARD/motorized_rocket_equipment_bonus else = { remove_ideas = EAI_HARD/motorized_rocket_equipment_bonus } }
	if = { limit = { has_equipment = { motorized_equipment < 500 } } add_ideas = EAI_HARD/motorized_equipment_bonus else = { remove_ideas = EAI_HARD/motorized_equipment_bonus } }
	if = { limit = { has_equipment = { mechanized_equipment < 500 } } add_ideas = EAI_HARD/mechanized_equipment_bonus else = { remove_ideas = EAI_HARD/mechanized_equipment_bonus } }
	if = { limit = { has_equipment = { anti_tank_equipment < 500 } } add_ideas = EAI_HARD/anti_tank_equipment_bonus else = { remove_ideas = EAI_HARD/anti_tank_equipment_bonus } }
	if = { limit = { has_equipment = { anti_air_equipment < 500 } } add_ideas = EAI_HARD/anti_air_equipment_bonus else = { remove_ideas = EAI_HARD/anti_air_equipment_bonus } }

	###### 

	if = { limit = { has_equipment = { light_tank_chassis < 500 } } add_ideas = EAI_HARD/light_tank_chassis_bonus else = { remove_ideas = EAI_HARD/light_tank_chassis_bonus } }
	if = { limit = { has_equipment = { medium_tank_chassis < 500 } } add_ideas = EAI_HARD/medium_tank_chassis_bonus else = { remove_ideas = EAI_HARD/medium_tank_chassis_bonus } }
	if = { limit = { has_equipment = { heavy_tank_chassis < 500 } } add_ideas = EAI_HARD/heavy_tank_chassis_bonus else = { remove_ideas = EAI_HARD/heavy_tank_chassis_bonus } }
	if = { limit = { has_equipment = { modern_tank_chassis < 500 } } add_ideas = EAI_HARD/modern_tank_chassis_bonus else = { remove_ideas = EAI_HARD/modern_tank_chassis_bonus } }
	if = { limit = { has_equipment = { super_heavy_tank_chassis < 500 } } add_ideas = EAI_HARD/super_heavy_tank_chassis_bonus else = { remove_ideas = EAI_HARD/super_heavy_tank_chassis_bonus } }
	if = { limit = { has_equipment = { amphibious_tank_chassis < 500 } } add_ideas = EAI_HARD/amphibious_tank_chassis_bonus else = { remove_ideas = EAI_HARD/amphibious_tank_chassis_bonus } }
	if = { limit = { has_equipment = { light_tank_aa_chassis < 500 } } add_ideas = EAI_HARD/light_tank_aa_chassis_bonus else = { remove_ideas = EAI_HARD/light_tank_aa_chassis_bonus } }
	if = { limit = { has_equipment = { light_tank_artillery_chassis < 500 } } add_ideas = EAI_HARD/light_tank_artillery_chassis_bonus else = { remove_ideas = EAI_HARD/light_tank_artillery_chassis_bonus } }
	if = { limit = { has_equipment = { light_tank_destroyer_chassis < 500 } } add_ideas = EAI_HARD/light_tank_destroyer_chassis_bonus else = { remove_ideas = EAI_HARD/light_tank_destroyer_chassis_bonus } }
	if = { limit = { has_equipment = { light_tank_amphibious_chassis < 500 } } add_ideas = EAI_HARD/light_tank_amphibious_chassis_bonus else = { remove_ideas = EAI_HARD/light_tank_amphibious_chassis_bonus } }
	if = { limit = { has_equipment = { light_tank_flame_chassis < 500 } } add_ideas = EAI_HARD/light_tank_flame_chassis_bonus else = { remove_ideas = EAI_HARD/light_tank_flame_chassis_bonus } }
	if = { limit = { has_equipment = { medium_tank_aa_chassis < 500 } } add_ideas = EAI_HARD/medium_tank_aa_chassis_bonus else = { remove_ideas = EAI_HARD/medium_tank_aa_chassis_bonus } }
	if = { limit = { has_equipment = { medium_tank_artillery_chassis < 500 } } add_ideas = EAI_HARD/medium_tank_artillery_chassis_bonus else = { remove_ideas = EAI_HARD/medium_tank_artillery_chassis_bonus } }
	if = { limit = { has_equipment = { medium_tank_destroyer_chassis < 500 } } add_ideas = EAI_HARD/medium_tank_destroyer_chassis_bonus else = { remove_ideas = EAI_HARD/medium_tank_destroyer_chassis_bonus } }
	if = { limit = { has_equipment = { medium_tank_amphibious_chassis < 500 } } add_ideas = EAI_HARD/medium_tank_amphibious_chassis_bonus else = { remove_ideas = EAI_HARD/medium_tank_amphibious_chassis_bonus } }
	if = { limit = { has_equipment = { medium_tank_flame_chassis < 500 } } add_ideas = EAI_HARD/medium_tank_flame_chassis_bonus else = { remove_ideas = EAI_HARD/medium_tank_flame_chassis_bonus } }
	if = { limit = { has_equipment = { heavy_tank_aa_chassis < 500 } } add_ideas = EAI_HARD/heavy_tank_aa_chassis_bonus else = { remove_ideas = EAI_HARD/heavy_tank_aa_chassis_bonus } }
	if = { limit = { has_equipment = { heavy_tank_artillery_chassis < 500 } } add_ideas = EAI_HARD/heavy_tank_artillery_chassis_bonus else = { remove_ideas = EAI_HARD/heavy_tank_artillery_chassis_bonus } }
	if = { limit = { has_equipment = { heavy_tank_destroyer_chassis < 500 } } add_ideas = EAI_HARD/heavy_tank_destroyer_chassis_bonus else = { remove_ideas = EAI_HARD/heavy_tank_destroyer_chassis_bonus } }
	if = { limit = { has_equipment = { heavy_tank_amphibious_chassis < 500 } } add_ideas = EAI_HARD/heavy_tank_amphibious_chassis_bonus else = { remove_ideas = EAI_HARD/heavy_tank_amphibious_chassis_bonus } }
	if = { limit = { has_equipment = { heavy_tank_flame_chassis < 500 } } add_ideas = EAI_HARD/heavy_tank_flame_chassis_bonus else = { remove_ideas = EAI_HARD/heavy_tank_flame_chassis_bonus } }
	if = { limit = { has_equipment = { super_heavy_tank_aa_chassis < 500 } } add_ideas = EAI_HARD/super_heavy_tank_aa_chassis_bonus else = { remove_ideas = EAI_HARD/super_heavy_tank_aa_chassis_bonus } }
	if = { limit = { has_equipment = { super_heavy_tank_artillery_chassis < 500 } } add_ideas = EAI_HARD/super_heavy_tank_artillery_chassis_bonus else = { remove_ideas = EAI_HARD/super_heavy_tank_artillery_chassis_bonus } }
	if = { limit = { has_equipment = { super_heavy_tank_destroyer_chassis < 500 } } add_ideas = EAI_HARD/super_heavy_tank_destroyer_chassis_bonus else = { remove_ideas = EAI_HARD/super_heavy_tank_destroyer_chassis_bonus } }
	if = { limit = { has_equipment = { modern_tank_aa_chassis < 500 } } add_ideas = EAI_HARD/modern_tank_aa_chassis_bonus else = { remove_ideas = EAI_HARD/modern_tank_aa_chassis_bonus } }
	if = { limit = { has_equipment = { modern_tank_artillery_chassis < 500 } } add_ideas = EAI_HARD/modern_tank_artillery_chassis_bonus else = { remove_ideas = EAI_HARD/modern_tank_artillery_chassis_bonus } }
	if = { limit = { has_equipment = { modern_tank_destroyer_chassis < 500 } } add_ideas = EAI_HARD/modern_tank_destroyer_chassis_bonus else = { remove_ideas = EAI_HARD/modern_tank_destroyer_chassis_bonus } }
	if = { limit = { has_equipment = { gw_tank_equipment < 500 } } add_ideas = EAI_HARD/gw_tank_equipment_bonus else = { remove_ideas = EAI_HARD/gw_tank_equipment_bonus } }

	###### 

	if = { limit = { EAI_DIFFICULTY_small_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_HARD/small_plane_airframe_bonus else = { remove_ideas = EAI_HARD/small_plane_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_cv_small_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_HARD/cv_small_plane_airframe_bonus else = { remove_ideas = EAI_HARD/cv_small_plane_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_medium_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_HARD/medium_plane_airframe_bonus else = { remove_ideas = EAI_HARD/medium_plane_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_large_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_HARD/large_plane_airframe_bonus else = { remove_ideas = EAI_HARD/large_plane_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_transport_plane_equipment_BONUS_TRIGGER = yes } add_ideas = EAI_HARD/transport_plane_equipment_bonus else = { remove_ideas = EAI_HARD/transport_plane_equipment_bonus } }
	if = { limit = { EAI_DIFFICULTY_small_plane_cas_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_HARD/small_plane_cas_airframe_bonus else = { remove_ideas = EAI_HARD/small_plane_cas_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_cv_small_plane_cas_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_HARD/cv_small_plane_cas_airframe_bonus else = { remove_ideas = EAI_HARD/cv_small_plane_cas_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_small_plane_naval_bomber_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_HARD/small_plane_naval_bomber_airframe_bonus else = { remove_ideas = EAI_HARD/small_plane_naval_bomber_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_cv_small_plane_naval_bomber_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_HARD/cv_small_plane_naval_bomber_airframe_bonus else = { remove_ideas = EAI_HARD/cv_small_plane_naval_bomber_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_small_plane_suicide_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_HARD/small_plane_suicide_airframe_bonus else = { remove_ideas = EAI_HARD/small_plane_suicide_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_cv_small_plane_suicide_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_HARD/cv_small_plane_suicide_airframe_bonus else = { remove_ideas = EAI_HARD/cv_small_plane_suicide_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_medium_plane_fighter_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_HARD/medium_plane_fighter_airframe_bonus else = { remove_ideas = EAI_HARD/medium_plane_fighter_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_medium_plane_scout_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_HARD/medium_plane_scout_plane_airframe_bonus else = { remove_ideas = EAI_HARD/medium_plane_scout_plane_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_large_plane_maritime_patrol_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_HARD/large_plane_maritime_patrol_plane_airframe_bonus else = { remove_ideas = EAI_HARD/large_plane_maritime_patrol_plane_airframe_bonus } }

	EAI_DIFFICULTY_fix_equipment_modifier_conflict = yes
}
EAI_DIFFICULTY_clear_equipment_modifier_HARD = {

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

		if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [This.GetName] | EAI_DIFFICULTY_clear_equipment_modifier_HARD" } 

		clear_variable = EAI_difficulty_equipment_bonus_active

		remove_ideas = {
			EAI_HARD/infantry_equipment_bonus
			EAI_HARD/support_equipment_bonus
			EAI_HARD/artillery_equipment_bonus
			EAI_HARD/rocket_artillery_equipment_bonus
			EAI_HARD/motorized_rocket_equipment_bonus
			EAI_HARD/motorized_equipment_bonus
			EAI_HARD/mechanized_equipment_bonus
			EAI_HARD/anti_tank_equipment_bonus
			EAI_HARD/anti_air_equipment_bonus
			EAI_HARD/light_tank_chassis_bonus
			EAI_HARD/medium_tank_chassis_bonus
			EAI_HARD/heavy_tank_chassis_bonus
			EAI_HARD/modern_tank_chassis_bonus
			EAI_HARD/super_heavy_tank_chassis_bonus
			EAI_HARD/amphibious_tank_chassis_bonus
			EAI_HARD/light_tank_aa_chassis_bonus
			EAI_HARD/light_tank_artillery_chassis_bonus
			EAI_HARD/light_tank_destroyer_chassis_bonus
			EAI_HARD/light_tank_amphibious_chassis_bonus
			EAI_HARD/light_tank_flame_chassis_bonus
			EAI_HARD/medium_tank_aa_chassis_bonus
			EAI_HARD/medium_tank_artillery_chassis_bonus
			EAI_HARD/medium_tank_destroyer_chassis_bonus
			EAI_HARD/medium_tank_amphibious_chassis_bonus
			EAI_HARD/medium_tank_flame_chassis_bonus
			EAI_HARD/heavy_tank_aa_chassis_bonus
			EAI_HARD/heavy_tank_artillery_chassis_bonus
			EAI_HARD/heavy_tank_destroyer_chassis_bonus
			EAI_HARD/heavy_tank_amphibious_chassis_bonus
			EAI_HARD/heavy_tank_flame_chassis_bonus
			EAI_HARD/super_heavy_tank_aa_chassis_bonus
			EAI_HARD/super_heavy_tank_artillery_chassis_bonus
			EAI_HARD/super_heavy_tank_destroyer_chassis_bonus
			EAI_HARD/modern_tank_aa_chassis_bonus
			EAI_HARD/modern_tank_artillery_chassis_bonus
			EAI_HARD/modern_tank_destroyer_chassis_bonus
			EAI_HARD/gw_tank_equipment_bonus
			EAI_HARD/small_plane_airframe_bonus
			EAI_HARD/cv_small_plane_airframe_bonus
			EAI_HARD/medium_plane_airframe_bonus
			EAI_HARD/large_plane_airframe_bonus
			EAI_HARD/transport_plane_equipment_bonus
			EAI_HARD/small_plane_cas_airframe_bonus
			EAI_HARD/cv_small_plane_cas_airframe_bonus
			EAI_HARD/small_plane_naval_bomber_airframe_bonus
			EAI_HARD/cv_small_plane_naval_bomber_airframe_bonus
			EAI_HARD/small_plane_suicide_airframe_bonus
			EAI_HARD/cv_small_plane_suicide_airframe_bonus
			EAI_HARD/medium_plane_fighter_airframe_bonus
			EAI_HARD/medium_plane_scout_plane_airframe_bonus
			EAI_HARD/large_plane_maritime_patrol_plane_airframe_bonus
		}

		EAI_DIFFICULTY_fix_equipment_modifier_conflict = yes
	}
}

EAI_DIFFICULTY_apply_equipment_modifier_VERY_HARD = {

	if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [This.GetName] | EAI_DIFFICULTY_apply_equipment_modifier_VERY_HARD" } 

	set_variable = { EAI_difficulty_equipment_bonus_active = 2 }

	if = { limit = { has_equipment = { infantry_equipment < 5000 } } add_ideas = EAI_VERY_HARD/infantry_equipment_bonus else = { remove_ideas = EAI_VERY_HARD/infantry_equipment_bonus } }
	if = { limit = { has_equipment = { support_equipment < 500 } } add_ideas = EAI_VERY_HARD/support_equipment_bonus else = { remove_ideas = EAI_VERY_HARD/support_equipment_bonus } }
	if = { limit = { has_equipment = { artillery_equipment < 500 } } add_ideas = EAI_VERY_HARD/artillery_equipment_bonus else = { remove_ideas = EAI_VERY_HARD/artillery_equipment_bonus } }
	if = { limit = { has_equipment = { rocket_artillery_equipment < 500 } } add_ideas = EAI_VERY_HARD/rocket_artillery_equipment_bonus else = { remove_ideas = EAI_VERY_HARD/rocket_artillery_equipment_bonus } }
	if = { limit = { has_equipment = { motorized_rocket_equipment < 500 } } add_ideas = EAI_VERY_HARD/motorized_rocket_equipment_bonus else = { remove_ideas = EAI_VERY_HARD/motorized_rocket_equipment_bonus } }
	if = { limit = { has_equipment = { motorized_equipment < 500 } } add_ideas = EAI_VERY_HARD/motorized_equipment_bonus else = { remove_ideas = EAI_VERY_HARD/motorized_equipment_bonus } }
	if = { limit = { has_equipment = { mechanized_equipment < 500 } } add_ideas = EAI_VERY_HARD/mechanized_equipment_bonus else = { remove_ideas = EAI_VERY_HARD/mechanized_equipment_bonus } }
	if = { limit = { has_equipment = { anti_tank_equipment < 500 } } add_ideas = EAI_VERY_HARD/anti_tank_equipment_bonus else = { remove_ideas = EAI_VERY_HARD/anti_tank_equipment_bonus } }
	if = { limit = { has_equipment = { anti_air_equipment < 500 } } add_ideas = EAI_VERY_HARD/anti_air_equipment_bonus else = { remove_ideas = EAI_VERY_HARD/anti_air_equipment_bonus } }

	###### 

	if = { limit = { has_equipment = { light_tank_chassis < 500 } } add_ideas = EAI_VERY_HARD/light_tank_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/light_tank_chassis_bonus } }
	if = { limit = { has_equipment = { medium_tank_chassis < 500 } } add_ideas = EAI_VERY_HARD/medium_tank_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/medium_tank_chassis_bonus } }
	if = { limit = { has_equipment = { heavy_tank_chassis < 500 } } add_ideas = EAI_VERY_HARD/heavy_tank_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/heavy_tank_chassis_bonus } }
	if = { limit = { has_equipment = { modern_tank_chassis < 500 } } add_ideas = EAI_VERY_HARD/modern_tank_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/modern_tank_chassis_bonus } }
	if = { limit = { has_equipment = { super_heavy_tank_chassis < 500 } } add_ideas = EAI_VERY_HARD/super_heavy_tank_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/super_heavy_tank_chassis_bonus } }
	if = { limit = { has_equipment = { amphibious_tank_chassis < 500 } } add_ideas = EAI_VERY_HARD/amphibious_tank_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/amphibious_tank_chassis_bonus } }
	if = { limit = { has_equipment = { light_tank_aa_chassis < 500 } } add_ideas = EAI_VERY_HARD/light_tank_aa_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/light_tank_aa_chassis_bonus } }
	if = { limit = { has_equipment = { light_tank_artillery_chassis < 500 } } add_ideas = EAI_VERY_HARD/light_tank_artillery_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/light_tank_artillery_chassis_bonus } }
	if = { limit = { has_equipment = { light_tank_destroyer_chassis < 500 } } add_ideas = EAI_VERY_HARD/light_tank_destroyer_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/light_tank_destroyer_chassis_bonus } }
	if = { limit = { has_equipment = { light_tank_amphibious_chassis < 500 } } add_ideas = EAI_VERY_HARD/light_tank_amphibious_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/light_tank_amphibious_chassis_bonus } }
	if = { limit = { has_equipment = { light_tank_flame_chassis < 500 } } add_ideas = EAI_VERY_HARD/light_tank_flame_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/light_tank_flame_chassis_bonus } }
	if = { limit = { has_equipment = { medium_tank_aa_chassis < 500 } } add_ideas = EAI_VERY_HARD/medium_tank_aa_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/medium_tank_aa_chassis_bonus } }
	if = { limit = { has_equipment = { medium_tank_artillery_chassis < 500 } } add_ideas = EAI_VERY_HARD/medium_tank_artillery_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/medium_tank_artillery_chassis_bonus } }
	if = { limit = { has_equipment = { medium_tank_destroyer_chassis < 500 } } add_ideas = EAI_VERY_HARD/medium_tank_destroyer_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/medium_tank_destroyer_chassis_bonus } }
	if = { limit = { has_equipment = { medium_tank_amphibious_chassis < 500 } } add_ideas = EAI_VERY_HARD/medium_tank_amphibious_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/medium_tank_amphibious_chassis_bonus } }
	if = { limit = { has_equipment = { medium_tank_flame_chassis < 500 } } add_ideas = EAI_VERY_HARD/medium_tank_flame_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/medium_tank_flame_chassis_bonus } }
	if = { limit = { has_equipment = { heavy_tank_aa_chassis < 500 } } add_ideas = EAI_VERY_HARD/heavy_tank_aa_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/heavy_tank_aa_chassis_bonus } }
	if = { limit = { has_equipment = { heavy_tank_artillery_chassis < 500 } } add_ideas = EAI_VERY_HARD/heavy_tank_artillery_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/heavy_tank_artillery_chassis_bonus } }
	if = { limit = { has_equipment = { heavy_tank_destroyer_chassis < 500 } } add_ideas = EAI_VERY_HARD/heavy_tank_destroyer_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/heavy_tank_destroyer_chassis_bonus } }
	if = { limit = { has_equipment = { heavy_tank_amphibious_chassis < 500 } } add_ideas = EAI_VERY_HARD/heavy_tank_amphibious_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/heavy_tank_amphibious_chassis_bonus } }
	if = { limit = { has_equipment = { heavy_tank_flame_chassis < 500 } } add_ideas = EAI_VERY_HARD/heavy_tank_flame_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/heavy_tank_flame_chassis_bonus } }
	if = { limit = { has_equipment = { super_heavy_tank_aa_chassis < 500 } } add_ideas = EAI_VERY_HARD/super_heavy_tank_aa_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/super_heavy_tank_aa_chassis_bonus } }
	if = { limit = { has_equipment = { super_heavy_tank_artillery_chassis < 500 } } add_ideas = EAI_VERY_HARD/super_heavy_tank_artillery_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/super_heavy_tank_artillery_chassis_bonus } }
	if = { limit = { has_equipment = { super_heavy_tank_destroyer_chassis < 500 } } add_ideas = EAI_VERY_HARD/super_heavy_tank_destroyer_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/super_heavy_tank_destroyer_chassis_bonus } }
	if = { limit = { has_equipment = { modern_tank_aa_chassis < 500 } } add_ideas = EAI_VERY_HARD/modern_tank_aa_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/modern_tank_aa_chassis_bonus } }
	if = { limit = { has_equipment = { modern_tank_artillery_chassis < 500 } } add_ideas = EAI_VERY_HARD/modern_tank_artillery_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/modern_tank_artillery_chassis_bonus } }
	if = { limit = { has_equipment = { modern_tank_destroyer_chassis < 500 } } add_ideas = EAI_VERY_HARD/modern_tank_destroyer_chassis_bonus else = { remove_ideas = EAI_VERY_HARD/modern_tank_destroyer_chassis_bonus } }
	if = { limit = { has_equipment = { gw_tank_equipment < 500 } } add_ideas = EAI_VERY_HARD/gw_tank_equipment_bonus else = { remove_ideas = EAI_VERY_HARD/gw_tank_equipment_bonus } }

	###### 

	if = { limit = { EAI_DIFFICULTY_small_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_VERY_HARD/small_plane_airframe_bonus else = { remove_ideas = EAI_VERY_HARD/small_plane_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_cv_small_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_VERY_HARD/cv_small_plane_airframe_bonus else = { remove_ideas = EAI_VERY_HARD/cv_small_plane_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_medium_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_VERY_HARD/medium_plane_airframe_bonus else = { remove_ideas = EAI_VERY_HARD/medium_plane_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_large_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_VERY_HARD/large_plane_airframe_bonus else = { remove_ideas = EAI_VERY_HARD/large_plane_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_transport_plane_equipment_BONUS_TRIGGER = yes } add_ideas = EAI_VERY_HARD/transport_plane_equipment_bonus else = { remove_ideas = EAI_VERY_HARD/transport_plane_equipment_bonus } }
	if = { limit = { EAI_DIFFICULTY_small_plane_cas_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_VERY_HARD/small_plane_cas_airframe_bonus else = { remove_ideas = EAI_VERY_HARD/small_plane_cas_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_cv_small_plane_cas_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_VERY_HARD/cv_small_plane_cas_airframe_bonus else = { remove_ideas = EAI_VERY_HARD/cv_small_plane_cas_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_small_plane_naval_bomber_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_VERY_HARD/small_plane_naval_bomber_airframe_bonus else = { remove_ideas = EAI_VERY_HARD/small_plane_naval_bomber_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_cv_small_plane_naval_bomber_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_VERY_HARD/cv_small_plane_naval_bomber_airframe_bonus else = { remove_ideas = EAI_VERY_HARD/cv_small_plane_naval_bomber_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_small_plane_suicide_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_VERY_HARD/small_plane_suicide_airframe_bonus else = { remove_ideas = EAI_VERY_HARD/small_plane_suicide_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_cv_small_plane_suicide_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_VERY_HARD/cv_small_plane_suicide_airframe_bonus else = { remove_ideas = EAI_VERY_HARD/cv_small_plane_suicide_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_medium_plane_fighter_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_VERY_HARD/medium_plane_fighter_airframe_bonus else = { remove_ideas = EAI_VERY_HARD/medium_plane_fighter_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_medium_plane_scout_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_VERY_HARD/medium_plane_scout_plane_airframe_bonus else = { remove_ideas = EAI_VERY_HARD/medium_plane_scout_plane_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_large_plane_maritime_patrol_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_VERY_HARD/large_plane_maritime_patrol_plane_airframe_bonus else = { remove_ideas = EAI_VERY_HARD/large_plane_maritime_patrol_plane_airframe_bonus } }

	EAI_DIFFICULTY_fix_equipment_modifier_conflict = yes
}
EAI_DIFFICULTY_clear_equipment_modifier_VERY_HARD = {

	if = { limit = { check_variable = { EAI_difficulty_equipment_bonus_active = 2 } }

		if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [This.GetName] | EAI_DIFFICULTY_clear_equipment_modifier_VERY_HARD" } 

		clear_variable = EAI_difficulty_equipment_bonus_active

		remove_ideas = {
			EAI_VERY_HARD/infantry_equipment_bonus
			EAI_VERY_HARD/support_equipment_bonus
			EAI_VERY_HARD/artillery_equipment_bonus
			EAI_VERY_HARD/rocket_artillery_equipment_bonus
			EAI_VERY_HARD/motorized_rocket_equipment_bonus
			EAI_VERY_HARD/motorized_equipment_bonus
			EAI_VERY_HARD/mechanized_equipment_bonus
			EAI_VERY_HARD/anti_tank_equipment_bonus
			EAI_VERY_HARD/anti_air_equipment_bonus
			EAI_VERY_HARD/light_tank_chassis_bonus
			EAI_VERY_HARD/medium_tank_chassis_bonus
			EAI_VERY_HARD/heavy_tank_chassis_bonus
			EAI_VERY_HARD/modern_tank_chassis_bonus
			EAI_VERY_HARD/super_heavy_tank_chassis_bonus
			EAI_VERY_HARD/amphibious_tank_chassis_bonus
			EAI_VERY_HARD/light_tank_aa_chassis_bonus
			EAI_VERY_HARD/light_tank_artillery_chassis_bonus
			EAI_VERY_HARD/light_tank_destroyer_chassis_bonus
			EAI_VERY_HARD/light_tank_amphibious_chassis_bonus
			EAI_VERY_HARD/light_tank_flame_chassis_bonus
			EAI_VERY_HARD/medium_tank_aa_chassis_bonus
			EAI_VERY_HARD/medium_tank_artillery_chassis_bonus
			EAI_VERY_HARD/medium_tank_destroyer_chassis_bonus
			EAI_VERY_HARD/medium_tank_amphibious_chassis_bonus
			EAI_VERY_HARD/medium_tank_flame_chassis_bonus
			EAI_VERY_HARD/heavy_tank_aa_chassis_bonus
			EAI_VERY_HARD/heavy_tank_artillery_chassis_bonus
			EAI_VERY_HARD/heavy_tank_destroyer_chassis_bonus
			EAI_VERY_HARD/heavy_tank_amphibious_chassis_bonus
			EAI_VERY_HARD/heavy_tank_flame_chassis_bonus
			EAI_VERY_HARD/super_heavy_tank_aa_chassis_bonus
			EAI_VERY_HARD/super_heavy_tank_artillery_chassis_bonus
			EAI_VERY_HARD/super_heavy_tank_destroyer_chassis_bonus
			EAI_VERY_HARD/modern_tank_aa_chassis_bonus
			EAI_VERY_HARD/modern_tank_artillery_chassis_bonus
			EAI_VERY_HARD/modern_tank_destroyer_chassis_bonus
			EAI_VERY_HARD/gw_tank_equipment_bonus
			EAI_VERY_HARD/small_plane_airframe_bonus
			EAI_VERY_HARD/cv_small_plane_airframe_bonus
			EAI_VERY_HARD/medium_plane_airframe_bonus
			EAI_VERY_HARD/large_plane_airframe_bonus
			EAI_VERY_HARD/transport_plane_equipment_bonus
			EAI_VERY_HARD/small_plane_cas_airframe_bonus
			EAI_VERY_HARD/cv_small_plane_cas_airframe_bonus
			EAI_VERY_HARD/small_plane_naval_bomber_airframe_bonus
			EAI_VERY_HARD/cv_small_plane_naval_bomber_airframe_bonus
			EAI_VERY_HARD/small_plane_suicide_airframe_bonus
			EAI_VERY_HARD/cv_small_plane_suicide_airframe_bonus
			EAI_VERY_HARD/medium_plane_fighter_airframe_bonus
			EAI_VERY_HARD/medium_plane_scout_plane_airframe_bonus
			EAI_VERY_HARD/large_plane_maritime_patrol_plane_airframe_bonus
		}

		EAI_DIFFICULTY_fix_equipment_modifier_conflict = yes
	}
}

EAI_DIFFICULTY_apply_equipment_modifier_INSANE = {

	if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [This.GetName] | EAI_DIFFICULTY_apply_equipment_modifier_INSANE" } 

	set_variable = { EAI_difficulty_equipment_bonus_active = 3 }

	if = { limit = { has_equipment = { infantry_equipment < 5000 } } add_ideas = EAI_INSANE/infantry_equipment_bonus else = { remove_ideas = EAI_INSANE/infantry_equipment_bonus } }
	if = { limit = { has_equipment = { support_equipment < 500 } } add_ideas = EAI_INSANE/support_equipment_bonus else = { remove_ideas = EAI_INSANE/support_equipment_bonus } }
	if = { limit = { has_equipment = { artillery_equipment < 500 } } add_ideas = EAI_INSANE/artillery_equipment_bonus else = { remove_ideas = EAI_INSANE/artillery_equipment_bonus } }
	if = { limit = { has_equipment = { rocket_artillery_equipment < 500 } } add_ideas = EAI_INSANE/rocket_artillery_equipment_bonus else = { remove_ideas = EAI_INSANE/rocket_artillery_equipment_bonus } }
	if = { limit = { has_equipment = { motorized_rocket_equipment < 500 } } add_ideas = EAI_INSANE/motorized_rocket_equipment_bonus else = { remove_ideas = EAI_INSANE/motorized_rocket_equipment_bonus } }
	if = { limit = { has_equipment = { motorized_equipment < 500 } } add_ideas = EAI_INSANE/motorized_equipment_bonus else = { remove_ideas = EAI_INSANE/motorized_equipment_bonus } }
	if = { limit = { has_equipment = { mechanized_equipment < 500 } } add_ideas = EAI_INSANE/mechanized_equipment_bonus else = { remove_ideas = EAI_INSANE/mechanized_equipment_bonus } }
	if = { limit = { has_equipment = { anti_tank_equipment < 500 } } add_ideas = EAI_INSANE/anti_tank_equipment_bonus else = { remove_ideas = EAI_INSANE/anti_tank_equipment_bonus } }
	if = { limit = { has_equipment = { anti_air_equipment < 500 } } add_ideas = EAI_INSANE/anti_air_equipment_bonus else = { remove_ideas = EAI_INSANE/anti_air_equipment_bonus } }

	###### 

	if = { limit = { has_equipment = { light_tank_chassis < 500 } } add_ideas = EAI_INSANE/light_tank_chassis_bonus else = { remove_ideas = EAI_INSANE/light_tank_chassis_bonus } }
	if = { limit = { has_equipment = { medium_tank_chassis < 500 } } add_ideas = EAI_INSANE/medium_tank_chassis_bonus else = { remove_ideas = EAI_INSANE/medium_tank_chassis_bonus } }
	if = { limit = { has_equipment = { heavy_tank_chassis < 500 } } add_ideas = EAI_INSANE/heavy_tank_chassis_bonus else = { remove_ideas = EAI_INSANE/heavy_tank_chassis_bonus } }
	if = { limit = { has_equipment = { modern_tank_chassis < 500 } } add_ideas = EAI_INSANE/modern_tank_chassis_bonus else = { remove_ideas = EAI_INSANE/modern_tank_chassis_bonus } }
	if = { limit = { has_equipment = { super_heavy_tank_chassis < 500 } } add_ideas = EAI_INSANE/super_heavy_tank_chassis_bonus else = { remove_ideas = EAI_INSANE/super_heavy_tank_chassis_bonus } }
	if = { limit = { has_equipment = { amphibious_tank_chassis < 500 } } add_ideas = EAI_INSANE/amphibious_tank_chassis_bonus else = { remove_ideas = EAI_INSANE/amphibious_tank_chassis_bonus } }
	if = { limit = { has_equipment = { light_tank_aa_chassis < 500 } } add_ideas = EAI_INSANE/light_tank_aa_chassis_bonus else = { remove_ideas = EAI_INSANE/light_tank_aa_chassis_bonus } }
	if = { limit = { has_equipment = { light_tank_artillery_chassis < 500 } } add_ideas = EAI_INSANE/light_tank_artillery_chassis_bonus else = { remove_ideas = EAI_INSANE/light_tank_artillery_chassis_bonus } }
	if = { limit = { has_equipment = { light_tank_destroyer_chassis < 500 } } add_ideas = EAI_INSANE/light_tank_destroyer_chassis_bonus else = { remove_ideas = EAI_INSANE/light_tank_destroyer_chassis_bonus } }
	if = { limit = { has_equipment = { light_tank_amphibious_chassis < 500 } } add_ideas = EAI_INSANE/light_tank_amphibious_chassis_bonus else = { remove_ideas = EAI_INSANE/light_tank_amphibious_chassis_bonus } }
	if = { limit = { has_equipment = { light_tank_flame_chassis < 500 } } add_ideas = EAI_INSANE/light_tank_flame_chassis_bonus else = { remove_ideas = EAI_INSANE/light_tank_flame_chassis_bonus } }
	if = { limit = { has_equipment = { medium_tank_aa_chassis < 500 } } add_ideas = EAI_INSANE/medium_tank_aa_chassis_bonus else = { remove_ideas = EAI_INSANE/medium_tank_aa_chassis_bonus } }
	if = { limit = { has_equipment = { medium_tank_artillery_chassis < 500 } } add_ideas = EAI_INSANE/medium_tank_artillery_chassis_bonus else = { remove_ideas = EAI_INSANE/medium_tank_artillery_chassis_bonus } }
	if = { limit = { has_equipment = { medium_tank_destroyer_chassis < 500 } } add_ideas = EAI_INSANE/medium_tank_destroyer_chassis_bonus else = { remove_ideas = EAI_INSANE/medium_tank_destroyer_chassis_bonus } }
	if = { limit = { has_equipment = { medium_tank_amphibious_chassis < 500 } } add_ideas = EAI_INSANE/medium_tank_amphibious_chassis_bonus else = { remove_ideas = EAI_INSANE/medium_tank_amphibious_chassis_bonus } }
	if = { limit = { has_equipment = { medium_tank_flame_chassis < 500 } } add_ideas = EAI_INSANE/medium_tank_flame_chassis_bonus else = { remove_ideas = EAI_INSANE/medium_tank_flame_chassis_bonus } }
	if = { limit = { has_equipment = { heavy_tank_aa_chassis < 500 } } add_ideas = EAI_INSANE/heavy_tank_aa_chassis_bonus else = { remove_ideas = EAI_INSANE/heavy_tank_aa_chassis_bonus } }
	if = { limit = { has_equipment = { heavy_tank_artillery_chassis < 500 } } add_ideas = EAI_INSANE/heavy_tank_artillery_chassis_bonus else = { remove_ideas = EAI_INSANE/heavy_tank_artillery_chassis_bonus } }
	if = { limit = { has_equipment = { heavy_tank_destroyer_chassis < 500 } } add_ideas = EAI_INSANE/heavy_tank_destroyer_chassis_bonus else = { remove_ideas = EAI_INSANE/heavy_tank_destroyer_chassis_bonus } }
	if = { limit = { has_equipment = { heavy_tank_amphibious_chassis < 500 } } add_ideas = EAI_INSANE/heavy_tank_amphibious_chassis_bonus else = { remove_ideas = EAI_INSANE/heavy_tank_amphibious_chassis_bonus } }
	if = { limit = { has_equipment = { heavy_tank_flame_chassis < 500 } } add_ideas = EAI_INSANE/heavy_tank_flame_chassis_bonus else = { remove_ideas = EAI_INSANE/heavy_tank_flame_chassis_bonus } }
	if = { limit = { has_equipment = { super_heavy_tank_aa_chassis < 500 } } add_ideas = EAI_INSANE/super_heavy_tank_aa_chassis_bonus else = { remove_ideas = EAI_INSANE/super_heavy_tank_aa_chassis_bonus } }
	if = { limit = { has_equipment = { super_heavy_tank_artillery_chassis < 500 } } add_ideas = EAI_INSANE/super_heavy_tank_artillery_chassis_bonus else = { remove_ideas = EAI_INSANE/super_heavy_tank_artillery_chassis_bonus } }
	if = { limit = { has_equipment = { super_heavy_tank_destroyer_chassis < 500 } } add_ideas = EAI_INSANE/super_heavy_tank_destroyer_chassis_bonus else = { remove_ideas = EAI_INSANE/super_heavy_tank_destroyer_chassis_bonus } }
	if = { limit = { has_equipment = { modern_tank_aa_chassis < 500 } } add_ideas = EAI_INSANE/modern_tank_aa_chassis_bonus else = { remove_ideas = EAI_INSANE/modern_tank_aa_chassis_bonus } }
	if = { limit = { has_equipment = { modern_tank_artillery_chassis < 500 } } add_ideas = EAI_INSANE/modern_tank_artillery_chassis_bonus else = { remove_ideas = EAI_INSANE/modern_tank_artillery_chassis_bonus } }
	if = { limit = { has_equipment = { modern_tank_destroyer_chassis < 500 } } add_ideas = EAI_INSANE/modern_tank_destroyer_chassis_bonus else = { remove_ideas = EAI_INSANE/modern_tank_destroyer_chassis_bonus } }
	if = { limit = { has_equipment = { gw_tank_equipment < 500 } } add_ideas = EAI_INSANE/gw_tank_equipment_bonus else = { remove_ideas = EAI_INSANE/gw_tank_equipment_bonus } }

	###### 

	if = { limit = { EAI_DIFFICULTY_small_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_INSANE/small_plane_airframe_bonus else = { remove_ideas = EAI_INSANE/small_plane_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_cv_small_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_INSANE/cv_small_plane_airframe_bonus else = { remove_ideas = EAI_INSANE/cv_small_plane_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_medium_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_INSANE/medium_plane_airframe_bonus else = { remove_ideas = EAI_INSANE/medium_plane_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_large_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_INSANE/large_plane_airframe_bonus else = { remove_ideas = EAI_INSANE/large_plane_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_transport_plane_equipment_BONUS_TRIGGER = yes } add_ideas = EAI_INSANE/transport_plane_equipment_bonus else = { remove_ideas = EAI_INSANE/transport_plane_equipment_bonus } }
	if = { limit = { EAI_DIFFICULTY_small_plane_cas_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_INSANE/small_plane_cas_airframe_bonus else = { remove_ideas = EAI_INSANE/small_plane_cas_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_cv_small_plane_cas_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_INSANE/cv_small_plane_cas_airframe_bonus else = { remove_ideas = EAI_INSANE/cv_small_plane_cas_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_small_plane_naval_bomber_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_INSANE/small_plane_naval_bomber_airframe_bonus else = { remove_ideas = EAI_INSANE/small_plane_naval_bomber_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_cv_small_plane_naval_bomber_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_INSANE/cv_small_plane_naval_bomber_airframe_bonus else = { remove_ideas = EAI_INSANE/cv_small_plane_naval_bomber_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_small_plane_suicide_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_INSANE/small_plane_suicide_airframe_bonus else = { remove_ideas = EAI_INSANE/small_plane_suicide_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_cv_small_plane_suicide_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_INSANE/cv_small_plane_suicide_airframe_bonus else = { remove_ideas = EAI_INSANE/cv_small_plane_suicide_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_medium_plane_fighter_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_INSANE/medium_plane_fighter_airframe_bonus else = { remove_ideas = EAI_INSANE/medium_plane_fighter_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_medium_plane_scout_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_INSANE/medium_plane_scout_plane_airframe_bonus else = { remove_ideas = EAI_INSANE/medium_plane_scout_plane_airframe_bonus } }
	if = { limit = { EAI_DIFFICULTY_large_plane_maritime_patrol_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_INSANE/large_plane_maritime_patrol_plane_airframe_bonus else = { remove_ideas = EAI_INSANE/large_plane_maritime_patrol_plane_airframe_bonus } }

	EAI_DIFFICULTY_fix_equipment_modifier_conflict = yes
}
EAI_DIFFICULTY_clear_equipment_modifier_INSANE = {

	if = { limit = { check_variable = { EAI_difficulty_equipment_bonus_active = 3 } }

		if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [This.GetName] | EAI_DIFFICULTY_clear_equipment_modifier_INSANE" } 

		clear_variable = EAI_difficulty_equipment_bonus_active

		remove_ideas = {
			EAI_INSANE/infantry_equipment_bonus
			EAI_INSANE/support_equipment_bonus
			EAI_INSANE/artillery_equipment_bonus
			EAI_INSANE/rocket_artillery_equipment_bonus
			EAI_INSANE/motorized_rocket_equipment_bonus
			EAI_INSANE/motorized_equipment_bonus
			EAI_INSANE/mechanized_equipment_bonus
			EAI_INSANE/anti_tank_equipment_bonus
			EAI_INSANE/anti_air_equipment_bonus
			EAI_INSANE/light_tank_chassis_bonus
			EAI_INSANE/medium_tank_chassis_bonus
			EAI_INSANE/heavy_tank_chassis_bonus
			EAI_INSANE/modern_tank_chassis_bonus
			EAI_INSANE/super_heavy_tank_chassis_bonus
			EAI_INSANE/amphibious_tank_chassis_bonus
			EAI_INSANE/light_tank_aa_chassis_bonus
			EAI_INSANE/light_tank_artillery_chassis_bonus
			EAI_INSANE/light_tank_destroyer_chassis_bonus
			EAI_INSANE/light_tank_amphibious_chassis_bonus
			EAI_INSANE/light_tank_flame_chassis_bonus
			EAI_INSANE/medium_tank_aa_chassis_bonus
			EAI_INSANE/medium_tank_artillery_chassis_bonus
			EAI_INSANE/medium_tank_destroyer_chassis_bonus
			EAI_INSANE/medium_tank_amphibious_chassis_bonus
			EAI_INSANE/medium_tank_flame_chassis_bonus
			EAI_INSANE/heavy_tank_aa_chassis_bonus
			EAI_INSANE/heavy_tank_artillery_chassis_bonus
			EAI_INSANE/heavy_tank_destroyer_chassis_bonus
			EAI_INSANE/heavy_tank_amphibious_chassis_bonus
			EAI_INSANE/heavy_tank_flame_chassis_bonus
			EAI_INSANE/super_heavy_tank_aa_chassis_bonus
			EAI_INSANE/super_heavy_tank_artillery_chassis_bonus
			EAI_INSANE/super_heavy_tank_destroyer_chassis_bonus
			EAI_INSANE/modern_tank_aa_chassis_bonus
			EAI_INSANE/modern_tank_artillery_chassis_bonus
			EAI_INSANE/modern_tank_destroyer_chassis_bonus
			EAI_INSANE/gw_tank_equipment_bonus
			EAI_INSANE/small_plane_airframe_bonus
			EAI_INSANE/cv_small_plane_airframe_bonus
			EAI_INSANE/medium_plane_airframe_bonus
			EAI_INSANE/large_plane_airframe_bonus
			EAI_INSANE/transport_plane_equipment_bonus
			EAI_INSANE/small_plane_cas_airframe_bonus
			EAI_INSANE/cv_small_plane_cas_airframe_bonus
			EAI_INSANE/small_plane_naval_bomber_airframe_bonus
			EAI_INSANE/cv_small_plane_naval_bomber_airframe_bonus
			EAI_INSANE/small_plane_suicide_airframe_bonus
			EAI_INSANE/cv_small_plane_suicide_airframe_bonus
			EAI_INSANE/medium_plane_fighter_airframe_bonus
			EAI_INSANE/medium_plane_scout_plane_airframe_bonus
			EAI_INSANE/large_plane_maritime_patrol_plane_airframe_bonus
		}

		EAI_DIFFICULTY_fix_equipment_modifier_conflict = yes
	}
}

######################################################
#	desperate defense
######################################################

EAI_DIFFICULTY_clear_active_desperate_defense = {

	clr_country_flag = EAI_desperate_defense_active
	
	clr_country_flag = EAI_dynamic_desperate_defense_active
	
	EAI_DIFFICULTY_clear_equipment_modifier_DD = yes

	clear_variable = EAI_desperate_defense_level

	remove_ideas = {
		EAI_desperate_defense_1 
		EAI_desperate_defense_2 
		EAI_desperate_defense_3 
		EAI_desperate_defense_4 
		EAI_desperate_defense_5 
		EAI_desperate_defense_6 
		EAI_desperate_defense_7 
		EAI_desperate_defense_8 
		EAI_desperate_defense_9 
		EAI_desperate_defense_10
		EAI_desperate_defense_11
		EAI_desperate_defense_12
		EAI_desperate_defense_13
		EAI_desperate_defense_14
		EAI_desperate_defense_15
		EAI_desperate_defense_16
		EAI_desperate_defense_17
		EAI_desperate_defense_18
		EAI_desperate_defense_19
		EAI_desperate_defense_20
	}
}

EAI_DIFFICULTY_apply_equipment_modifier_DD = {

	if = { limit = { has_variable = EAI_desperate_defense_level }

		set_variable = { EAI_dd_equipment_bonus_active = EAI_desperate_defense_level }

		if = { limit = { check_variable = { EAI_dd_equipment_bonus_active > 0 } }
		
			meta_effect = {
				text = {
					add_ideas = EAI_desperate_defense_[x]
	
					###### 
	
					if = { limit = { has_equipment = { infantry_equipment < 5000 } } add_ideas = EAI_DD_[x]/infantry_equipment_bonus else = { remove_ideas = EAI_DD_[x]/infantry_equipment_bonus } }
					if = { limit = { has_equipment = { support_equipment < 500 } } add_ideas = EAI_DD_[x]/support_equipment_bonus else = { remove_ideas = EAI_DD_[x]/support_equipment_bonus } }
					if = { limit = { has_equipment = { artillery_equipment < 500 } } add_ideas = EAI_DD_[x]/artillery_equipment_bonus else = { remove_ideas = EAI_DD_[x]/artillery_equipment_bonus } }
					if = { limit = { has_equipment = { rocket_artillery_equipment < 500 } } add_ideas = EAI_DD_[x]/rocket_artillery_equipment_bonus else = { remove_ideas = EAI_DD_[x]/rocket_artillery_equipment_bonus } }
					if = { limit = { has_equipment = { motorized_rocket_equipment < 500 } } add_ideas = EAI_DD_[x]/motorized_rocket_equipment_bonus else = { remove_ideas = EAI_DD_[x]/motorized_rocket_equipment_bonus } }
					if = { limit = { has_equipment = { motorized_equipment < 500 } } add_ideas = EAI_DD_[x]/motorized_equipment_bonus else = { remove_ideas = EAI_DD_[x]/motorized_equipment_bonus } }
					if = { limit = { has_equipment = { mechanized_equipment < 500 } } add_ideas = EAI_DD_[x]/mechanized_equipment_bonus else = { remove_ideas = EAI_DD_[x]/mechanized_equipment_bonus } }
					if = { limit = { has_equipment = { anti_tank_equipment < 500 } } add_ideas = EAI_DD_[x]/anti_tank_equipment_bonus else = { remove_ideas = EAI_DD_[x]/anti_tank_equipment_bonus } }
					if = { limit = { has_equipment = { anti_air_equipment < 500 } } add_ideas = EAI_DD_[x]/anti_air_equipment_bonus else = { remove_ideas = EAI_DD_[x]/anti_air_equipment_bonus } }
	
					###### 
	
					if = { limit = { has_equipment = { light_tank_chassis < 500 } } add_ideas = EAI_DD_[x]/light_tank_chassis_bonus else = { remove_ideas = EAI_DD_[x]/light_tank_chassis_bonus } }
					if = { limit = { has_equipment = { medium_tank_chassis < 500 } } add_ideas = EAI_DD_[x]/medium_tank_chassis_bonus else = { remove_ideas = EAI_DD_[x]/medium_tank_chassis_bonus } }
					if = { limit = { has_equipment = { heavy_tank_chassis < 500 } } add_ideas = EAI_DD_[x]/heavy_tank_chassis_bonus else = { remove_ideas = EAI_DD_[x]/heavy_tank_chassis_bonus } }
					if = { limit = { has_equipment = { modern_tank_chassis < 500 } } add_ideas = EAI_DD_[x]/modern_tank_chassis_bonus else = { remove_ideas = EAI_DD_[x]/modern_tank_chassis_bonus } }
					if = { limit = { has_equipment = { super_heavy_tank_chassis < 500 } } add_ideas = EAI_DD_[x]/super_heavy_tank_chassis_bonus else = { remove_ideas = EAI_DD_[x]/super_heavy_tank_chassis_bonus } }
					if = { limit = { has_equipment = { amphibious_tank_chassis < 500 } } add_ideas = EAI_DD_[x]/amphibious_tank_chassis_bonus else = { remove_ideas = EAI_DD_[x]/amphibious_tank_chassis_bonus } }
					if = { limit = { has_equipment = { light_tank_aa_chassis < 500 } } add_ideas = EAI_DD_[x]/light_tank_aa_chassis_bonus else = { remove_ideas = EAI_DD_[x]/light_tank_aa_chassis_bonus } }
					if = { limit = { has_equipment = { light_tank_artillery_chassis < 500 } } add_ideas = EAI_DD_[x]/light_tank_artillery_chassis_bonus else = { remove_ideas = EAI_DD_[x]/light_tank_artillery_chassis_bonus } }
					if = { limit = { has_equipment = { light_tank_destroyer_chassis < 500 } } add_ideas = EAI_DD_[x]/light_tank_destroyer_chassis_bonus else = { remove_ideas = EAI_DD_[x]/light_tank_destroyer_chassis_bonus } }
					if = { limit = { has_equipment = { light_tank_amphibious_chassis < 500 } } add_ideas = EAI_DD_[x]/light_tank_amphibious_chassis_bonus else = { remove_ideas = EAI_DD_[x]/light_tank_amphibious_chassis_bonus } }
					if = { limit = { has_equipment = { light_tank_flame_chassis < 500 } } add_ideas = EAI_DD_[x]/light_tank_flame_chassis_bonus else = { remove_ideas = EAI_DD_[x]/light_tank_flame_chassis_bonus } }
					if = { limit = { has_equipment = { medium_tank_aa_chassis < 500 } } add_ideas = EAI_DD_[x]/medium_tank_aa_chassis_bonus else = { remove_ideas = EAI_DD_[x]/medium_tank_aa_chassis_bonus } }
					if = { limit = { has_equipment = { medium_tank_artillery_chassis < 500 } } add_ideas = EAI_DD_[x]/medium_tank_artillery_chassis_bonus else = { remove_ideas = EAI_DD_[x]/medium_tank_artillery_chassis_bonus } }
					if = { limit = { has_equipment = { medium_tank_destroyer_chassis < 500 } } add_ideas = EAI_DD_[x]/medium_tank_destroyer_chassis_bonus else = { remove_ideas = EAI_DD_[x]/medium_tank_destroyer_chassis_bonus } }
					if = { limit = { has_equipment = { medium_tank_amphibious_chassis < 500 } } add_ideas = EAI_DD_[x]/medium_tank_amphibious_chassis_bonus else = { remove_ideas = EAI_DD_[x]/medium_tank_amphibious_chassis_bonus } }
					if = { limit = { has_equipment = { medium_tank_flame_chassis < 500 } } add_ideas = EAI_DD_[x]/medium_tank_flame_chassis_bonus else = { remove_ideas = EAI_DD_[x]/medium_tank_flame_chassis_bonus } }
					if = { limit = { has_equipment = { heavy_tank_aa_chassis < 500 } } add_ideas = EAI_DD_[x]/heavy_tank_aa_chassis_bonus else = { remove_ideas = EAI_DD_[x]/heavy_tank_aa_chassis_bonus } }
					if = { limit = { has_equipment = { heavy_tank_artillery_chassis < 500 } } add_ideas = EAI_DD_[x]/heavy_tank_artillery_chassis_bonus else = { remove_ideas = EAI_DD_[x]/heavy_tank_artillery_chassis_bonus } }
					if = { limit = { has_equipment = { heavy_tank_destroyer_chassis < 500 } } add_ideas = EAI_DD_[x]/heavy_tank_destroyer_chassis_bonus else = { remove_ideas = EAI_DD_[x]/heavy_tank_destroyer_chassis_bonus } }
					if = { limit = { has_equipment = { heavy_tank_amphibious_chassis < 500 } } add_ideas = EAI_DD_[x]/heavy_tank_amphibious_chassis_bonus else = { remove_ideas = EAI_DD_[x]/heavy_tank_amphibious_chassis_bonus } }
					if = { limit = { has_equipment = { heavy_tank_flame_chassis < 500 } } add_ideas = EAI_DD_[x]/heavy_tank_flame_chassis_bonus else = { remove_ideas = EAI_DD_[x]/heavy_tank_flame_chassis_bonus } }
					if = { limit = { has_equipment = { super_heavy_tank_aa_chassis < 500 } } add_ideas = EAI_DD_[x]/super_heavy_tank_aa_chassis_bonus else = { remove_ideas = EAI_DD_[x]/super_heavy_tank_aa_chassis_bonus } }
					if = { limit = { has_equipment = { super_heavy_tank_artillery_chassis < 500 } } add_ideas = EAI_DD_[x]/super_heavy_tank_artillery_chassis_bonus else = { remove_ideas = EAI_DD_[x]/super_heavy_tank_artillery_chassis_bonus } }
					if = { limit = { has_equipment = { super_heavy_tank_destroyer_chassis < 500 } } add_ideas = EAI_DD_[x]/super_heavy_tank_destroyer_chassis_bonus else = { remove_ideas = EAI_DD_[x]/super_heavy_tank_destroyer_chassis_bonus } }
					if = { limit = { has_equipment = { modern_tank_aa_chassis < 500 } } add_ideas = EAI_DD_[x]/modern_tank_aa_chassis_bonus else = { remove_ideas = EAI_DD_[x]/modern_tank_aa_chassis_bonus } }
					if = { limit = { has_equipment = { modern_tank_artillery_chassis < 500 } } add_ideas = EAI_DD_[x]/modern_tank_artillery_chassis_bonus else = { remove_ideas = EAI_DD_[x]/modern_tank_artillery_chassis_bonus } }
					if = { limit = { has_equipment = { modern_tank_destroyer_chassis < 500 } } add_ideas = EAI_DD_[x]/modern_tank_destroyer_chassis_bonus else = { remove_ideas = EAI_DD_[x]/modern_tank_destroyer_chassis_bonus } }
					if = { limit = { has_equipment = { gw_tank_equipment < 500 } } add_ideas = EAI_DD_[x]/gw_tank_equipment_bonus else = { remove_ideas = EAI_DD_[x]/gw_tank_equipment_bonus } }
	
					###### 
	
					if = { limit = { EAI_DIFFICULTY_small_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_DD_[x]/small_plane_airframe_bonus else = { remove_ideas = EAI_DD_[x]/small_plane_airframe_bonus } }
					if = { limit = { EAI_DIFFICULTY_cv_small_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_DD_[x]/cv_small_plane_airframe_bonus else = { remove_ideas = EAI_DD_[x]/cv_small_plane_airframe_bonus } }
					if = { limit = { EAI_DIFFICULTY_medium_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_DD_[x]/medium_plane_airframe_bonus else = { remove_ideas = EAI_DD_[x]/medium_plane_airframe_bonus } }
					if = { limit = { EAI_DIFFICULTY_large_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_DD_[x]/large_plane_airframe_bonus else = { remove_ideas = EAI_DD_[x]/large_plane_airframe_bonus } }
					if = { limit = { EAI_DIFFICULTY_transport_plane_equipment_BONUS_TRIGGER = yes } add_ideas = EAI_DD_[x]/transport_plane_equipment_bonus else = { remove_ideas = EAI_DD_[x]/transport_plane_equipment_bonus } }
					if = { limit = { EAI_DIFFICULTY_small_plane_cas_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_DD_[x]/small_plane_cas_airframe_bonus else = { remove_ideas = EAI_DD_[x]/small_plane_cas_airframe_bonus } }
					if = { limit = { EAI_DIFFICULTY_cv_small_plane_cas_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_DD_[x]/cv_small_plane_cas_airframe_bonus else = { remove_ideas = EAI_DD_[x]/cv_small_plane_cas_airframe_bonus } }
					if = { limit = { EAI_DIFFICULTY_small_plane_naval_bomber_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_DD_[x]/small_plane_naval_bomber_airframe_bonus else = { remove_ideas = EAI_DD_[x]/small_plane_naval_bomber_airframe_bonus } }
					if = { limit = { EAI_DIFFICULTY_cv_small_plane_naval_bomber_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_DD_[x]/cv_small_plane_naval_bomber_airframe_bonus else = { remove_ideas = EAI_DD_[x]/cv_small_plane_naval_bomber_airframe_bonus } }
					if = { limit = { EAI_DIFFICULTY_small_plane_suicide_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_DD_[x]/small_plane_suicide_airframe_bonus else = { remove_ideas = EAI_DD_[x]/small_plane_suicide_airframe_bonus } }
					if = { limit = { EAI_DIFFICULTY_cv_small_plane_suicide_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_DD_[x]/cv_small_plane_suicide_airframe_bonus else = { remove_ideas = EAI_DD_[x]/cv_small_plane_suicide_airframe_bonus } }
					if = { limit = { EAI_DIFFICULTY_medium_plane_fighter_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_DD_[x]/medium_plane_fighter_airframe_bonus else = { remove_ideas = EAI_DD_[x]/medium_plane_fighter_airframe_bonus } }
					if = { limit = { EAI_DIFFICULTY_medium_plane_scout_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_DD_[x]/medium_plane_scout_plane_airframe_bonus else = { remove_ideas = EAI_DD_[x]/medium_plane_scout_plane_airframe_bonus } }
					if = { limit = { EAI_DIFFICULTY_large_plane_maritime_patrol_plane_airframe_BONUS_TRIGGER = yes } add_ideas = EAI_DD_[x]/large_plane_maritime_patrol_plane_airframe_bonus else = { remove_ideas = EAI_DD_[x]/large_plane_maritime_patrol_plane_airframe_bonus } }
				}
	
				x = "[?EAI_dd_equipment_bonus_active|.0]"
			}
		}

		if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [This.GetName] | DD: applying equipment modifier [?EAI_desperate_defense_level]" } 
	}

	EAI_DIFFICULTY_fix_equipment_modifier_conflict = yes
}
EAI_DIFFICULTY_clear_equipment_modifier_DD = {

	if = { limit = { has_variable = EAI_desperate_defense_level }

		if = { limit = { check_variable = { EAI_dd_equipment_bonus_active > 0 } }
		
			meta_effect = {
				text = {
					remove_ideas = {
						EAI_desperate_defense_[x]
		
						EAI_DD_[x]/infantry_equipment_bonus
						EAI_DD_[x]/support_equipment_bonus
						EAI_DD_[x]/artillery_equipment_bonus
						EAI_DD_[x]/rocket_artillery_equipment_bonus
						EAI_DD_[x]/motorized_rocket_equipment_bonus
						EAI_DD_[x]/motorized_equipment_bonus
						EAI_DD_[x]/mechanized_equipment_bonus
						EAI_DD_[x]/anti_tank_equipment_bonus
						EAI_DD_[x]/anti_air_equipment_bonus
						EAI_DD_[x]/light_tank_chassis_bonus
						EAI_DD_[x]/medium_tank_chassis_bonus
						EAI_DD_[x]/heavy_tank_chassis_bonus
						EAI_DD_[x]/modern_tank_chassis_bonus
						EAI_DD_[x]/super_heavy_tank_chassis_bonus
						EAI_DD_[x]/amphibious_tank_chassis_bonus
						EAI_DD_[x]/light_tank_aa_chassis_bonus
						EAI_DD_[x]/light_tank_artillery_chassis_bonus
						EAI_DD_[x]/light_tank_destroyer_chassis_bonus
						EAI_DD_[x]/light_tank_amphibious_chassis_bonus
						EAI_DD_[x]/light_tank_flame_chassis_bonus
						EAI_DD_[x]/medium_tank_aa_chassis_bonus
						EAI_DD_[x]/medium_tank_artillery_chassis_bonus
						EAI_DD_[x]/medium_tank_destroyer_chassis_bonus
						EAI_DD_[x]/medium_tank_amphibious_chassis_bonus
						EAI_DD_[x]/medium_tank_flame_chassis_bonus
						EAI_DD_[x]/heavy_tank_aa_chassis_bonus
						EAI_DD_[x]/heavy_tank_artillery_chassis_bonus
						EAI_DD_[x]/heavy_tank_destroyer_chassis_bonus
						EAI_DD_[x]/heavy_tank_amphibious_chassis_bonus
						EAI_DD_[x]/heavy_tank_flame_chassis_bonus
						EAI_DD_[x]/super_heavy_tank_aa_chassis_bonus
						EAI_DD_[x]/super_heavy_tank_artillery_chassis_bonus
						EAI_DD_[x]/super_heavy_tank_destroyer_chassis_bonus
						EAI_DD_[x]/modern_tank_aa_chassis_bonus
						EAI_DD_[x]/modern_tank_artillery_chassis_bonus
						EAI_DD_[x]/modern_tank_destroyer_chassis_bonus
						EAI_DD_[x]/gw_tank_equipment_bonus
						EAI_DD_[x]/small_plane_airframe_bonus
						EAI_DD_[x]/cv_small_plane_airframe_bonus
						EAI_DD_[x]/medium_plane_airframe_bonus
						EAI_DD_[x]/large_plane_airframe_bonus
						EAI_DD_[x]/transport_plane_equipment_bonus
						EAI_DD_[x]/small_plane_cas_airframe_bonus
						EAI_DD_[x]/cv_small_plane_cas_airframe_bonus
						EAI_DD_[x]/small_plane_naval_bomber_airframe_bonus
						EAI_DD_[x]/cv_small_plane_naval_bomber_airframe_bonus
						EAI_DD_[x]/small_plane_suicide_airframe_bonus
						EAI_DD_[x]/cv_small_plane_suicide_airframe_bonus
						EAI_DD_[x]/medium_plane_fighter_airframe_bonus
						EAI_DD_[x]/medium_plane_scout_plane_airframe_bonus
						EAI_DD_[x]/large_plane_maritime_patrol_plane_airframe_bonus
					}
				}
		
				x = "[?EAI_dd_equipment_bonus_active|.0]"
			}
		}

		clear_variable = EAI_dd_equipment_bonus_active
	
		if = { limit = { has_country_flag = EAI_difficulty_logging } log = "[GetYear] [GetMonth] | DIFFICULTY | [This.GetName] | DD: removing equipment modifier [?EAI_desperate_defense_level]" } 
	}

	EAI_DIFFICULTY_fix_equipment_modifier_conflict = yes
}