#	Example:
#
#	example_trigger = {
#		tag = GER
#		is_ai = no
#	}
#
#
#	In a script file:
#
#	trigger = {
#		example_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
			}
		}
	}
}

#State scope
is_not_controlled_by_ROOT_or_ally = {
	custom_trigger_tooltip = {
		tooltip = is_not_controlled_by_ROOT_or_ally
		CONTROLLER = {
			NOT = {
				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
	}
}

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

anti_submarine_strategy_required_trigger = {
	OR = {
		AND = {
			has_war = yes
			any_enemy_country = {
				has_navy_size = {
					type = submarine
					size > 30
				}
			}
		}
		convoy_threat > 0.3
	}
}

should_USA_invade_europe_or_africa = {
	surrender_progress < 0.05
}

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
	is_subject = no
	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
	}
}

has_specialist_level_trigger = {
	skill > 5
	skill < 6
}

has_expert_level_trigger = {
	skill > 6
	skill < 7
}

has_genius_level_trigger = {
	skill > 7
}

is_league_of_nations_member = {
	custom_trigger_tooltip = {
		tooltip = is_league_of_nations_member_tt
		has_idea = league_of_nations_member_idea
	}
}

state_is_in_the_mediterranean_sea = {
	custom_trigger_tooltip = {
		tooltip = state_is_in_the_mediterranean_sea_tt
		OR = {
			state = 118 #GIBRALTAR
			state = 173
			state = 168
			state = 167
			state = 165
			state = 177
			state = 31
			state = 22
			state = 21
			state = 851
			state = 911
			state = 735
			state = 162
			state = 2
			state = 117
			state = 156
			state = 115
			state = 1
			state = 114
			state = 116
			state = 849
			state = 157
			state = 158
			state = 161
			state = 160
			state = 736
			state = 852
			state = 103
			state = 163
			state = 105
			state = 44
			state = 805
			state = 185
			state = 186
			state = 47
			state = 731
			state = 184
			state = 187
			state = 182
			state = 164
			state = 341
			state = 797
			state = 340
			state = 339
			state = 342
			state = 345
			state = 344
			state = 799
			state = 677
			state = 553
			state = 183
			state = 454
			state = 453
			state = 446
			state = 907
			state = 447
			state = 452
			state = 451
			state = 450
			state = 449
			state = 448
			state = 665
			state = 458
			state = 460
			state = 459
			state = 461
			state = 290
			state = 934
		}
	}
}

state_is_in_the_baltic_sea = { # Checks if the state borders the Baltic Sea  
	OR = {	
		state = 37 # Sjaelland
		state = 911 # Fyn
		state = 912 # Sonderjylland
		state = 909
		state = 58
		state = 61
		state = 62
		state = 63
		state = 807
		state = 85
		state = 5
		state = 763
		state = 188
		state = 189
		state = 190
		state = 809
		state = 808
		state = 12
		state = 13
		state = 811 
		state = 812
		state = 813
		state = 208
		state = 195
		state = 146
		state = 928
		state = 111
		state = 926
		state = 145
		state = 149
		state = 929 
		state = 148 # Lappi
		state = 666 # Norrbotten
		state = 918 # Vasterbotten
		state = 38 # Gavleborg
		state = 141 # Sodermaland
		state = 913 # Ostergotland
		state = 139 # Smaland
		state = 138 # Skane
		state = 124 # Gotland
	}
}

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

is_initial_ethiopian_state = {
	OR = {
		state = 271
		state = 835
		state = 836
		state = 837
		state = 838
		state = 839
		state = 840
		state = 841
		state = 842
		state = 843
	}
}

has_subject_autonomy_feature = {
	has_dlc = "Together for Victory"
}

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

is_alpine_state = {
	custom_trigger_tooltip = {
		tooltip = is_alpine_TT
	}
	hidden_trigger = {
		OR = {
			state = 21 #Bouche-du-Rhone - FRA
			state = 851 #Var - FRA 
			state = 735 #Savoy - FRA 
			state = 32 #Alpes - FRA 
			state = 158 #Piemonte - ITA
			state = 159 #Lombardia - ITA 
			state = 850 #Trentino - ITA 
			state = 39 #Alto Adige - ITA
			state = 847 #Western Swiss Alps - SWI
			state = 151 #Eastern Swiss Alps - SWI 
			state = 846 #Ticino - SWI
			state = 848 #Vorarlberg - AUS
			state = 153 #Tyrol - AUS 
			state = 152 #Upper Austria - AUS 
			state = 4 #Lower Austria 
		}
	}
}

state_has_any_resource = {
	OR = {
		has_resources_amount = {
			resource = liquid_dust
			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
	}
}

has_lar = {
	has_dlc = "La Resistance"
}

has_mtg = {
	has_dlc = "Man the Guns"
}

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

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

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

has_aat = {
	has_dlc = "Arms Against Tyranny"
}

is_trotsky_valid_for_mexico = {
	has_global_flag = flag_mexico_invited_trotsky_to_government
	NOT = {
		OR = {
			has_global_flag = trotsky_not_welcome_in_mexico
			has_global_flag = flag_trotsky_dead
			has_global_flag = flag_trotsky_has_returned_to_ussr_from_mexico
		}
	}
	if = {
		limit = {
			has_aat = yes 
		}
		has_global_flag = AAT_trotsky_in_mexico
	}	
}

NOR_trotsky_not_in_mex = {
	NOT = { 
		has_global_flag = AAT_trotsky_in_mexico 
		has_global_flag = flag_trotsky_dead
		has_global_flag = flag_trotsky_has_returned_to_ussr_from_mexico
	} 
}

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

is_danish_belt_state = { # Checks if state should be considered to be around the Danish Belt  
	OR = {
		state = 922 # Agder
		state = 921 # Telemark
		state = 110 # Oslofjord
		state = 915 # Bohuslan
		state = 140 # Vastergotland 
		state = 138 # Skane 
		state = 99 # Norrejylland
		state = 911 # Fyn
		state = 912 # Sonderjylland 
		state = 37 # Sjaelland 
		state = 909 # Schleswig 
		state = 58 # Holstein 
		state = 61 # Mecklenburg
		state = 62 # Vorpommern   
	}
} 

is_scandinavian_northern_sea_state = {
	OR = {
		state = 909 # Schleswig 
		state = 58 # Holstein 
		state = 912 # Sonderjylland		
		state = 99 # Norrejylland
		state = 922 # Agder
		state = 142 # Vestlandet 
		state = 143 # Trondelag
		state = 923 # Helgeland
		state = 144 # Nordland 
		state = 924 # Troms 
		state = 925 # Finnmark
	}
}

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

### 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_allied_seller_trigger = {
	custom_trigger_tooltip = {
		tooltip = subsidy_allied_nation_tt
		FROM = { is_in_faction_with = ROOT }
	}
}

