#	Example:
# 
#	example_trigger = {
#		tag = GER
#		is_ai = no
#	}
#
#
#	In a script file:
#
#	trigger = {
#		exampel_trigger = yes
#	}
#

can_ROOT_get_wargoal_on_THIS = {
	exists = yes
	NOT = { is_in_faction_with = ROOT }
	NOT = { is_subject_of = ROOT }
}

#Country scope
is_JAP_or_ally_of_JAP = {
	OR = {
		tag = JAP
		is_in_faction_with = JAP
		is_subject_of = JAP
	}
}

is_border_conflict_defender_vs_FROM = {
	has_variable = ROOT.defender_state_vs_@FROM
}

has_not_initiated_border_incident_with_FROM = {
	custom_trigger_tooltip = {
		tooltip = not_initiated_border_incident_with_FROM
		NOT = {		
			any_state = {
				check_variable = { FROM.defender_state_vs_@PREV = id }
			}
		}
	}
}

has_not_initiated_border_incident_with_ROOT = {
	custom_trigger_tooltip = {
		tooltip = not_initiated_border_incident_with_ROOT
		NOT = {
			any_state = {
				check_variable = { ROOT.defender_state_vs_@PREV = id }
			}
		}
	}
}

#State scope
has_ROOT_at_least_1_div_in_current_state_scope = {
	custom_trigger_tooltip = {
		tooltip = at_least_one_division_in_state
		ROOT = { divisions_in_state = { state = PREV size > 0 } }
	}
}

check_has_focus_tree_to_switch_to_fascism = {
	NOT = { tag = JAP }
	NOT = { tag = GER }
	NOT = { tag = MAN }
	NOT = { tag = ITA }
	OR = {
		NOT = {
			AND = {
				tag = SAF
				has_dlc = "Together for Victory"
			}
		}
		AND = {
			tag = SAF
			has_dlc = "Together for Victory"
			has_completed_focus = SAF_south_africa_first
		}
	}
	NOT = {
		AND = {
			tag = RAJ
			has_dlc = "Together for Victory"
		}
	}
	NOT = {
		AND = {
			tag = USA
			has_dlc = "Man the Guns"
		}
	}
	NOT = {
		AND = {
			tag = ENG
			has_dlc = "Man the Guns"
		}
	}
	NOT = {
		AND = {
			tag = FRA
			has_dlc = "La Resistance"
		}
	}
	NOT = {
		AND = {
			original_tag = SPR
			OR = {
				has_completed_focus = SPA_the_phalanx_ascendant
				has_completed_focus = SPA_supremacy_of_the_communion
				has_completed_focus = SPR_the_popular_front
			}
			has_dlc = "La Resistance"
		}
	}
}

check_has_focus_tree_to_switch_to_democratic = {
	NOT = { tag = MAN }
	NOT = { tag = FRA }
	NOT = { tag = USA }
	NOT = { tag = ENG }
	NOT = { tag = CAN }
	NOT = { tag = SAF }
	NOT = { tag = AST }
	NOT = { tag = NZL }
	NOT = { tag = RAJ }
	NOT = { tag = CZE }
	NOT = {
		AND = {
			tag = HUN
			has_dlc = "Death or Dishonor"
		}
	}
	NOT = {
		AND = {
			tag = JAP
			has_dlc = "Waking the Tiger"
		}
	}
	NOT = {
		AND = {
			tag = GER
			has_dlc = "Waking the Tiger"
		} 
	}
}

check_has_focus_tree_to_switch_to_communism = {
	NOT = { tag = PRC }
	NOT = { tag = SIK }
	NOT = { tag = MAN }
	NOT = { tag = SOV }
	NOT = {
		AND = {
			tag = RAJ
			has_dlc = "Together for Victory"
		}
	}
	NOT = {
		AND = {
			tag = JAP
			has_dlc = "Waking the Tiger"
		}
	}
	NOT = {
		AND = {
			tag = YUN
			has_dlc = "Waking the Tiger"
		}
	}
	NOT = {
		AND = {
			tag = USA
			has_dlc = "Man the Guns"
		}
	}
	NOT = {
		AND = {
			tag = ENG
			has_dlc = "Man the Guns"
		}
	}
	NOT = {
		AND = {
			tag = FRA
			has_dlc = "La Resistance"
		}
	}
	NOT = {
		AND = {
			original_tag = SPR
			has_dlc = "La Resistance"
		}
	}
}

#State scope
is_controlled_by_ROOT_or_subject = {
	custom_trigger_tooltip = {
		tooltip = is_controlled_by_ROOT_or_subject
		CONTROLLER = {
			OR = {
				tag = ROOT
				is_subject_of = ROOT
			}
		}
	}
}

#Country scope
is_free_or_subject_of_root = {
	OR = {
		is_subject = no
		is_subject_of = ROOT
	}
}

#State scope
is_controlled_by_ROOT_or_ally = {
	custom_trigger_tooltip = {
		tooltip = is_controlled_by_ROOT_or_ally
		CONTROLLER = {
			OR = {
				tag = ROOT
				is_subject_of = ROOT
				is_in_faction_with = ROOT
			}
		}
	}
}

is_csa_state = {
	OR = {
		state = 366
		state = 365
		state = 367
		state = 370
		state = 362
		state = 363
		state = 364
		state = 371
		state = 375
		state = 368
		state = 372
	}
}

has_naval_treaty_trigger = {
	OR = {
		has_idea = MTG_naval_treaty_adherent
		has_idea = MTG_naval_treaty_cheating
		has_idea = MTG_naval_treaty_adherent_reduced
		has_idea = MTG_naval_treaty_cheating_reduced
	}
}

ai_air_doctrine_tier_1_trigger = {
	OR = {
		has_tech = naval_strike_tactics
		has_tech = direct_ground_support
		has_tech = low_echelon_support
	}
}

ai_air_doctrine_tier_2_trigger = {
	OR = {
		has_tech = multialtitude_flying
		has_tech = hunt_and_destroy
		has_tech = operational_destruction
	}
}
ai_air_doctrine_tier_3_trigger = {
	OR = {
		has_tech = flying_fortress
		has_tech = naval_strike_torpedo_tactics
		has_tech = infiltration_bombing
	}
}

ai_land_doctrine_tier_1_trigger = {
	OR = {
		has_tech = elastic_defence
		has_tech = mobile_defence
		has_tech = grand_assault
		has_tech = defence_in_depth
	}
}

ai_land_doctrine_tier_2_trigger = {
	OR = {
		has_tech = kampfgruppe
		has_tech = mechanised_offensive
		has_tech = branch_interoperation
		has_tech = infiltration_assault
		has_tech = vast_offensives
		has_tech = large_front_offensive
	}
}

CHI_is_on_historical_plan_trigger = {
	has_dlc = "Waking the Tiger"
	OR = {
		AND = {
			is_historical_focus_on = yes
			has_game_rule = {
				rule = CHI_ai_behavior
				option = DEFAULT
			}	
		}
		has_country_flag = CHI_AI_RANDOM_HISTORICAL
		has_game_rule = {
			rule = CHI_ai_behavior
			option = HISTORICAL
		}
	}
}
SOV_is_on_historical_plan_trigger = {
	OR = {
		AND = {
			is_historical_focus_on = yes
			has_game_rule = {
				rule = SOV_ai_behavior
				option = DEFAULT
			}
		}
		has_country_flag = SOV_AI_RANDOM_COMMUNIST_HISTORICAL
		has_game_rule = {
			rule = SOV_ai_behavior
			option = HISTORICAL
		}
	}
}
USA_is_on_historical_plan_trigger = {
	OR = {
		AND = {
			is_historical_focus_on = yes
			has_game_rule = {
				rule = USA_ai_behavior
				option = DEFAULT
			}
		}
		has_country_flag = USA_AI_DEMOCRATIC_HISTORICAL
		has_game_rule = {
			rule = USA_ai_behavior
			option = DEMOCRATIC_HISTORICAL
		}
	}
}
ROM_is_on_historical_plan_trigger = {
	has_dlc = "Death or Dishonor"
	OR = {
		AND = {
			is_historical_focus_on = yes
			has_game_rule = {
				rule = ROM_ai_behavior
				option = DEFAULT
			}
		}
		has_country_flag = ROM_AI_RANDOM_FASCIST_HISTORICAL
		has_game_rule = {
			rule = ROM_ai_behavior
			option = FASCIST_HISTORICAL
		}
	}
}
HUN_is_on_historical_plan_trigger = {
	has_dlc = "Death or Dishonor"
	OR = {
		AND = {
			is_historical_focus_on = yes
			has_game_rule = {
				rule = HUN_ai_behavior
				option = DEFAULT
			}
		}
		has_country_flag = HUN_AI_RANDOM_FASCIST_HISTORICAL
		has_game_rule = {
			rule = HUN_ai_behavior
			option = FASCIST_HISTORICAL
		}
	}
}
ENG_is_on_historical_plan_trigger = {
	OR = {
		AND = {
			is_historical_focus_on = yes
			has_game_rule = {
				rule = ENG_ai_behavior
				option = DEFAULT
			}
		}
		has_country_flag = ENG_AI_DEMOCRATIC_HISTORICAL
		has_game_rule = {
			rule = eng_ai_behavior
			option = DEMOCRATIC_HISTORICAL
		}
	}
}

SOV_save_pp_for_manpower_trouble = {
	has_manpower < 1000000
	has_political_power < 200
	surrender_progress > 0	
}

anti_submarine_strategy_required_trigger = {
	OR = {
		AND = {
			tag = ENG
			not = { is_in_faction_with = GER }
			GER = {
				has_navy_size = {
					type = submarine
					size > 30
				}
			}
		}
		AND = {
			tag = USA
			not = { is_in_faction_with = GER }
			GER = {
				has_navy_size = {
					type = submarine
					size > 30
				}
			}
		}
		AND = {
			tag = JAP
			not = { is_in_faction_with = USA }
		}
		AND = {
			has_war = yes
			any_enemy_country = {
				has_navy_size = {
					type = submarine
					size > 30
				}
			}
		}
		convoy_threat > 0.3
	}
}

should_USA_invade_europe_or_africa = {
	USA = {
		OR = {
			is_in_faction_with = ENG
			has_military_access_to = ENG
		}
	}
	surrender_progress < 0.05
	FRA = {
		has_capitulated = yes
	}
	OR = {
		GER = {
			exists = yes
			has_war_with = USA
		}
		ITA = {
			exists = yes
			has_war_with = USA
		}
		SPR = {
			exists = yes
			has_war_with = USA
		}
		USA = {
			OR = {
				AND = {
					has_government = democratic
					ENG = { has_government = democratic } 
					OR = {
						GER = { has_government = fascism }
						ITA = { has_government = fascism }
					}
				}
				is_in_array = { potential_and_current_enemies = GER }
				is_in_array = { potential_and_current_enemies = ITA }
				is_in_array = { potential_and_current_enemies = SPR }
			}
		}
	}
}

enemy_has_equal_or_better_radar_tech_trigger = {
	custom_trigger_tooltip = {
		tooltip = enemy_has_equal_or_better_radar_tech_trigger_tt
		if = {
			limit = {
				ROOT = { 
					has_tech = radio_detection 
					NOT = {
						has_tech = decimetric_radar
					}
				} 
			}
			FROM = { 
				OR = {
					has_tech = radio_detection 
					has_tech = decimetric_radar
				}
			}
		}
		else_if = {
			limit = {
				ROOT = { 
					has_tech = decimetric_radar 
					NOT = {
						has_tech = improved_decimetric_radar
					}
				} 
			}
			FROM = { 
				OR = {
					has_tech = decimetric_radar 
					has_tech = improved_decimetric_radar
				}
			}
		}
		else_if = {
			limit = {
				ROOT = { 
					has_tech = improved_decimetric_radar 
					NOT = {
						has_tech = centimetric_radar
					}
				} 
			}
			FROM = { 
				OR = {
					has_tech = improved_decimetric_radar 
					has_tech = centimetric_radar
				}
			}
		}
		else_if = {
			limit = {
				ROOT = { 
					has_tech = centimetric_radar 
					NOT = {
						has_tech = improved_centimetric_radar
					}
				} 
			}
			FROM = { 
				OR = {
					has_tech = centimetric_radar 
					has_tech = improved_centimetric_radar
				}
			}
		}
		else_if = {
			limit = {
				ROOT = { 
					has_tech = improved_centimetric_radar 
					NOT = {
						has_tech = advanced_centimetric_radar
					}
				} 
			}
			FROM = { 
				OR = {
					has_tech = improved_centimetric_radar 
					has_tech = advanced_centimetric_radar
				}
			}
		}
		#no more steps needed because end of research tree is reached
	}
}

is_available_to_collaboration_government = { # occupied_countries.1 should be updated along with this
	NOT = {
		AND = {
			FROM = { original_tag = YUG }
			original_tag = ITA
		}
		TUR_cannot_form_kurdish_collaboration_government = yes
		any_country_with_original_tag = {
			original_tag_to_check = FROM
			is_puppet_of = PREV # if already created one do not create another
			has_autonomy_state = autonomy_collaboration_government
		}
	}
}

has_large_ally_not_pick_closed_economy = {
	any_of_scopes = {
		array = faction_members
		
		NOT = { tag = PREV }
		num_of_military_factories > 30
	}
}

has_any_byz_cosmetic_tag = {
	OR = {
		has_cosmetic_tag = BYZ_UNIFIED
		has_cosmetic_tag = BYZ_UNIFIED_communism
		has_cosmetic_tag = BYZ_UNIFIED_democratic
		has_cosmetic_tag = BYZ_UNIFIED_fascism
		has_cosmetic_tag = BYZ_UNIFIED_neutrality
	}
}