#	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 }
}

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 } }
	}
}

#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
			}
		}
	}
}

is_not_controlled_by_ROOT_or_subject = {
	custom_trigger_tooltip = {
		tooltip = is_not_controlled_by_ROOT_or_subject
		CONTROLLER = {
			NOT = {
				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
	}
}

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 = cavity_magnatron
					}
				}
			}
			FROM = {
				OR = {
					has_tech = radio_detection
					has_tech = cavity_magnatron
				}
			}
		}
		else_if = {
			limit = {
				ROOT = {
					has_tech = cavity_magnatron

				}
			}
			FROM = {
				has_tech = cavity_magnatron
			}
		}
		else_if = {
			limit = {
				ROOT = {
					NOT = {
						has_tech = centimetric_radar
					}
				}
			}
			FROM = {
				has_tech = centimetric_radar
			}
		}
		else_if = {
			limit = {
				ROOT = {
					has_tech = centimetric_radar
					NOT = {
						has_tech = phased_array
					}
				}
			}
			FROM = {
				OR = {
					has_tech = centimetric_radar
					has_tech = phased_array
				}
			}
		}
		else_if = {
			limit = {
				ROOT = {
					has_tech = phased_array
					NOT = {
						has_tech = monopulse_radar
					}
				}
			}
			FROM = {
				OR = {
					has_tech = phased_array
					has_tech = monopulse_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 = {
		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
	}
}

owns_or_subject_of = {
	custom_trigger_tooltip = {
		tooltip = owns_or_subject_of_tt
		owner = {
			OR = {
				tag = ROOT
				is_subject_of = ROOT
			}
		}
	}
}

controls_or_subject_of = {
	custom_trigger_tooltip = {
		tooltip = controls_or_subject_of_tt
		controller = {
			OR = {
				tag = ROOT
				is_subject_of = ROOT
			}
		}
	}
}

is_core_or_compliance_60 = {
	custom_trigger_tooltip = {
		tooltip = is_core_or_compliance_60_tt
		OR = {
			controller = {
				PREV = { is_core_of = PREV }
			}
			compliance > 60
		}
	}
}

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
	}
}

has_same_ideology = {
	custom_trigger_tooltip = {
		tooltip = has_same_ideology_tt
		OR = {
			AND = {
				has_government = democratic
				ROOT = { has_government = democratic }
			}
			AND = {
				has_government = fascism
				ROOT = { has_government = fascism }
			}
			AND = {
				has_government = communism
				ROOT = { has_government = communism }
			}
			AND = {
				has_government = neutrality
				ROOT = { has_government = neutrality }
			}
		}
	}
}

has_specialist_level_trigger = {
	skill > 5
	skill < 6
}

has_expert_level_trigger = {
	skill > 6
	skill < 7
}

has_genius_level_trigger = {
	skill > 7
}

is_major_not_original_tag_root = {
	is_major = yes
	hidden_trigger = {
		NOT = { original_tag = ROOT }
	}
}

has_subject_autonomy_feature = {
	has_dlc = "Together for Victory"
	#TODO_Manu: More DLCs?
}

is_organization_of_african_unity_member = {
	custom_trigger_tooltip = {
		tooltip = is_league_of_nations_member_tt
		has_idea = organization_of_african_unity_member_idea
	}
}

has_tech_sharing_feature = {
	OR = {
		has_dlc = "Together for Victory"
		has_dlc = "Death or Dishonor"
		has_dlc = "Waking the Tiger"
		has_dlc = "La Resistance"
	}
}

has_war_with_non_exiled_country = {
	custom_trigger_tooltip = {
		tooltip = has_war_with_non_exiled_country_tt
		has_war = yes
		any_enemy_country = {
			is_government_in_exile = no
		}
	}

}

is_at_peace_exiled_countries_excluded = {
	custom_trigger_tooltip = {
		tooltip = is_at_peace_exiled_countries_excluded_tt
		NOT = {
			any_enemy_country = {
				is_government_in_exile = no
			}
		}
	}
}

#State scope
state_is_fully_controlled_by_ROOT_or_subject = {
	custom_trigger_tooltip = {
		tooltip = state_is_fully_controlled_by_ROOT_or_subject_tt
		OR = {
			is_fully_controlled_by = ROOT
			controller = {
				is_subject_of = ROOT
				has_full_control_of_state = PREV
			}
		}
	}
}

#State scope
state_is_fully_controlled_by_ROOT_subject_or_faction_member = {
	custom_trigger_tooltip = {
		tooltip = state_is_fully_controlled_by_ROOT_subject_or_faction_member_tt
		OR = {
			is_fully_controlled_by = ROOT
			controller = {
				OR = {
					is_subject_of = ROOT
					is_in_faction_with = ROOT
				}
				has_full_control_of_state = PREV
			}
		}
	}
}

state_has_any_resource = {
	OR = {
		has_resources_amount = {
			resource = oil
			amount > 0
		}
		has_resources_amount = {
			resource = aluminium
			amount > 0
		}
		has_resources_amount = {
			resource = rubber
			amount > 0
		}
		has_resources_amount = {
			resource = tungsten
			amount > 0
		}
		has_resources_amount = {
			resource = steel
			amount > 0
		}
		has_resources_amount = {
			resource = chromium
			amount > 0
		}
	}
}

country_can_be_reasonable_target_of_wargoal = { #Expected scopes: Target country is THIS, country getting wargoal is PREV
	NOT = {
		has_war_with = ROOT
		is_in_faction_with = PREV
		has_guaranteed = PREV
		is_guaranteed_by = PREV
		has_non_aggression_pact_with = PREV
		is_subject_of = PREV
	}
}

is_unlikely_country_tag = {
	OR = {
	    tag = BRI
	    tag = CAT
	    tag = NAV
	    tag = GLC
	    tag = ADU
	    tag = BRI
	    tag = OCC
	    tag = COR
	    tag = DNZ
	    tag = KSH
	    tag = CKK
	    tag = FER
	    tag = YAK
	    tag = VLA
	    tag = KKP
	    tag = YAM
	    tag = TAY
	    tag = OVO
	    tag = NEN
	    tag = KOM
	    tag = CHU
	    tag = MEL
	    tag = RIF
	    tag = HAR
	    tag = TIG
	    tag = AFA
	    tag = BEG
	    tag = GBA
	    tag = SID
	    tag = ORO
	    tag = QEM
	    tag = LBV
	    tag = PAP
	    tag = TOS
	    tag = SPM
	    tag = TTS
		tag = BSK
		tag = TAT
		tag = UDM
		tag = KHA
		tag = VGE
		tag = KAL
		tag = KAR
		tag = SIL
		tag = KSH
		tag = ALT
		tag = BUK
		tag = KHI
		tag = SMI
		tag = QUE
		tag = YUC
		tag = RIG
		tag = WLA
		tag = GRN
		tag = EVE
		tag = SHL
		tag = MEK
		tag = HAN
		tag = SAX
		tag = PRE
		tag = BAY
		tag = WUR
		tag = THU
		tag = HES
		tag = RHI
	}
}

big_communist_exists = {
	any_other_country = {
		is_major = yes 
		has_government = communism
		has_capitulated = no 
		exists = yes 
	}
}

big_fascist_exists = {
	any_other_country = {
		is_major = yes 
		has_government = fascism
		has_capitulated = no 
		exists = yes 
	}
}

has_lar = {
	has_dlc = "La Resistance"
}

has_mtg = {
	has_dlc = "Man the Guns"
}

has_hide_rule = {
	has_game_rule = {
		rule = obsolete_focus_branches_visibility
		option = HIDE
	}
}


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

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

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

has_aat = {
	has_dlc = "Arms Against Tyranny"
}
has_any_tank_tech = {
	if = {
		limit = {
			has_dlc = "No Step Back"
		}
		OR = {
			has_tech = basic_light_tank_chassis
			has_tech = basic_medium_tank_chassis
			has_tech = basic_heavy_tank_chassis
		}
	}
	else = {
		has_tech = gwtank
	}
}

has_any_tanks = {
	if = {
		limit = {
			has_dlc = "No Step Back"
		}
		OR = {
			has_equipment = { light_tank_chassis_0 > 0}
			has_equipment = { medium_tank_chassis > 0 }
			has_equipment = { light_tank_chassis > 0 }
			has_equipment = { heavy_tank_chassis > 0 }
		}
	}
	else = {
		OR = {
			has_equipment = { gw_tank_equipment > 0	}
			has_equipment = { light_tank_equipment_1 > 0	}
			has_equipment = { light_tank_equipment_2 > 0	}
			has_equipment = { light_tank_equipment_3 > 0	}
			has_equipment = { medium_tank_equipment_1 > 0	}
			has_equipment = { medium_tank_equipment_2 > 0	}
			has_equipment = { medium_tank_equipment_3 > 0	}
			has_equipment = { modern_tank_equipment_1 > 0	}
			has_equipment = { heavy_tank_equipment_1 > 0	}
			has_equipment = { heavy_tank_equipment_2 > 0	}
			has_equipment = { heavy_tank_equipment_3 > 0	}
			has_equipment = { super_heavy_tank_equipment_1 > 0	}
		}
	}
}

mio_original_country_exists_and_not_at_war_with_ROOT = { #Used for MIO decisions visibility - THIS is original country
	exists = yes
	has_capitulated = no
	NOT = { has_war_with = ROOT }
}

mio_original_country_available_with_opinion_subject_and_war_requirements_fulfilled = { #Used for MIO decisions availability - THIS is original country
	has_opinion = {
		target = ROOT
		value > 49
	}
	OR = {
		is_subject = no
		is_subject_of = ROOT
	}
	has_capitulated = no
	NOT = { has_war_with = ROOT }
}


can_unlock_new_special_forces_tree = {
	if = {
		limit = { NOT = { has_variable = sf_trees } }
		custom_trigger_tooltip = {
			tooltip = can_unlock_new_special_forces_tree_none
			NOT = { has_variable = sf_trees }
		}
	}
	else_if = {
		limit = { check_variable = { sf_trees > 0 } }
		custom_trigger_tooltip = {
			tooltip = can_unlock_new_special_forces_tree_more_yes
			check_variable = { sf_trees > 0 }
		}
	}
	else = {
		custom_trigger_tooltip = {
			tooltip = can_unlock_new_special_forces_tree_more_no
			always = no
		}
	}
}
# These are to make strength comparisons easier 

FROM_is_stronger = {
	strength_ratio = {
		tag = FROM 
		ratio < 1
	}
}

FROM_is_twice_as_strong = {
	strength_ratio = {
		tag = FROM 
		ratio < 0.5
	}
}

FROM_is_weaker = {
	strength_ratio = {
		tag = FROM 
		ratio > 1
	}
}

FROM_is_twice_as_weak = {
	strength_ratio = {
		tag = FROM 
		ratio > 2
	}
}

ai_has_completed_army_doctrine = {
	is_ai = yes
	OR = {
		has_tech = werwolf_guerillas
		has_tech = modern_blitzkrieg
		has_tech = air_land_battle
		has_tech = shock_and_awe
		has_tech = c3i_theory
		has_tech = infiltration_in_depth
		has_tech = continuous_offensive
		has_tech = guerilla_warfare
	}
}

ai_has_completed_air_doctrine = {
	is_ai = yes
	OR = {
		has_tech = offensive_formations
		has_tech = mass_destruction
		has_tech = forward_interception
		has_tech = high_level_bombing
	}
}

ai_has_completed_naval_doctrine = {
	is_ai = yes
	OR = {
		has_tech = grand_battlefleet
		has_tech = submarine_offensive
		has_tech = floating_airfield
		has_tech = combined_operations_raiding
		has_tech = integrated_convoy_defence
		has_tech = submarine_offensive_bs
		has_tech = carrier_battlegroups
	}
}

### Neutrality Act - only trade with countries at peace 
trade_partner_not_at_war = {
	custom_trigger_tooltip = {
		tooltip = trade_partner_not_at_war_tt
		FROM = { 
			has_war = yes 
		}
	}
}

is_democratic_seller_trigger = {
	custom_trigger_tooltip = {
		tooltip = "Democratic Countries"
		FROM = {
			has_government = democratic
		}
	}
}

#Subsidy Seller Triggers
is_fascist_seller_trigger = {
	NOT = { has_war_with = ROOT	}
	has_government = fascism 
}

is_democracy_seller_trigger = {
	NOT = { has_war_with = ROOT	}
	has_government = democratic 
}

is_communist_seller_trigger = {
	NOT = { has_war_with = ROOT }
	has_government = communism
}

is_allied_seller_trigger = {
	custom_trigger_tooltip = {
		tooltip = subsidy_allied_nation_tt
		FROM = { is_in_faction_with = ROOT }
	}
}

