###Volcano Triggers###
agassiz_state_has_volcano = {
	has_state_trait = dubois_state_trait_volcano
}

dubois_has_volcano = {
	any_scope_state = {
		has_state_trait = dubois_state_trait_volcano
	}
}

# Age
ztr_global_warming_active = {
	has_global_variable = ztr_global_warming_initialized
}

ztr_decolonization_age_active = {
	has_global_variable = ztr_global_decolonization_pressure_var
}

# Building Triggers
has_research_center = {
	any_scope_state = {
		any_scope_building = {
			is_building_type = building_research_center
			is_under_construction = no
		}
	}
}

has_research_center_target = {
	any_scope_building = {
		is_building_type = building_research_center
		is_under_construction = no
	}
}

has_fusion_reactor_target = {
	any_scope_building = {
		is_building_type = building_fusion_power_plant
		is_under_construction = no
	}
}

# Liberty Index Triggers
is_distopia = {
	custom_tooltip = {
		text = ztr_tooltip_is_distopia
		has_variable = liberty_index_var
		var:liberty_index_var < 15
	}
}

ztr_is_totalitarian = {
	custom_tooltip = {
		text = ztr_tooltip_ztr_is_totalitarian
		has_variable = liberty_index_var
		var:liberty_index_var < 25
	}
}

ztr_is_authoritarian = {
	custom_tooltip = {
		text = ztr_tooltip_ztr_is_authoritarian
		has_variable = liberty_index_var
		var:liberty_index_var >= 25
		var:liberty_index_var < 50
	}
}

ztr_is_flawed_democratic = {
	custom_tooltip = {
		text = ztr_tooltip_ztr_is_flawed_democratic
		has_variable = liberty_index_var
		var:liberty_index_var >= 50
		var:liberty_index_var < 75
	}
}

ztr_is_full_democratic = {
	custom_tooltip = {
		text = ztr_tooltip_ztr_is_full_democratic
		has_variable = liberty_index_var
		var:liberty_index_var >= 75
	}
}

ztr_is_democratic = {
	custom_tooltip = {
		text = ztr_tooltip_ztr_is_democratic
		has_variable = liberty_index_var
		var:liberty_index_var >= 50
	}
}

# Negatives
is_not_distopia = {
	custom_tooltip = {
		text = ztr_tooltip_is_not_distopia
		has_variable = liberty_index_var
		var:liberty_index_var >= 10
	}
}

ztr_is_not_totalitarian = {
	custom_tooltip = {
		text = ztr_tooltip_ztr_is_not_totalitarian
		has_variable = liberty_index_var
		var:liberty_index_var >= 25
	}
}

ztr_is_not_democratic = {
	custom_tooltip = {
		text = ztr_tooltip_ztr_is_not_democratic
		has_variable = liberty_index_var
		var:liberty_index_var < 50
	}
}

ztr_is_not_full_democratic = {
	custom_tooltip = {
		text = ztr_tooltip_ztr_is_not_full_democratic
		has_variable = liberty_index_var
		var:liberty_index_var < 75
	}
}

# Equality Index Triggers
ztr_is_individualist = {
	custom_tooltip = {
		text = ztr_tooltip_is_individualist_state
		has_variable = equality_index_var
		var:equality_index_var < 50
	}
}

ztr_is_socialist = {
	custom_tooltip = {
		text = ztr_tooltip_is_egalitarian_state
		has_variable = equality_index_var
		var:equality_index_var >= 50
	}
}

ztr_is_communist = {
	custom_tooltip = {
		text = ztr_tooltip_is_communist_state
		has_law_or_variant = law_type:law_council_republic
	}
}

# Similar Index Triggers
ztr_is_very_similar_liberty_index = {
	OR = {
		AND = {
			scope:actor = {
				ztr_is_full_democratic = yes
				ztr_is_communist = no
			}
			scope:target_country = {
				ztr_is_full_democratic = yes
				ztr_is_communist = no
			}
		}
		AND = {
			scope:actor = {
				ztr_is_totalitarian = yes
				ztr_is_communist = no
			}
			scope:target_country = {
				ztr_is_totalitarian = yes
				ztr_is_communist = no
			}
		}
	}
}

ztr_similar_liberty_index = {
	OR = {
		AND = {
			scope:actor = {
				ztr_is_democratic = yes
			}
			scope:target_country = {
				ztr_is_democratic = yes
			}
		}
		AND = {
			scope:actor = {
				ztr_is_not_democratic = yes
			}
			scope:target_country = {
				ztr_is_not_democratic = yes
			}
		}
		AND = {
			scope:actor = {
				ztr_is_communist = yes
			}
			scope:target_country = {
				ztr_is_communist = yes
			}
		}
	}
}

ztr_neutral_liberty_index = {
	OR = {
		AND = {
			scope:actor = {
				ztr_is_flawed_democratic = yes
			}
			scope:target_country = {
				ztr_is_authoritarian = yes
			}
		}
		AND = {
			scope:actor = {
				ztr_is_authoritarian = yes
			}
			scope:target_country = {
				ztr_is_flawed_democratic = yes
			}
		}
	}
}

ztr_similar_equality_index = {
	OR = {
		AND = {
			scope:actor = {
				ztr_is_socialist = yes
			}
			scope:target_country = {
				ztr_is_socialist = yes
			}
		}
		AND = {
			scope:actor = {
				ztr_is_individualist = yes
			}
			scope:target_country = {
				ztr_is_individualist = yes
			}
		}
	}
}

# Unification Triggers
# Actor and target share a primary culture, so assimilation would be effectively automatic.
ztr_countries_share_primary_culture = {
	custom_tooltip = {
		text = ztr_tooltip_countries_share_primary_culture
		scope:actor = {
			any_primary_culture = {
				is_primary_culture_of = scope:target_country
			}
		}
	}
}

# Actor has a homeland state for its own primary culture that is adjacent to, or in the same state region as, the target.
# Filters out candidates where the actor has no territorial claim that could reach the target without crossing a stranger.
ztr_countries_state_contiguity = {
	custom_tooltip = {
		text = ztr_tooltip_countries_state_contiguity
		scope:actor = {
			any_scope_state = {
				is_homeland_of_country_cultures = scope:actor
				OR = {
					region = {
						any_scope_state = {
							is_incorporated = yes
							owner = scope:target_country
						}
					}
					any_neighbouring_state = {
						is_incorporated = yes
						owner = scope:target_country
					}
				}
			}
		}
	}
}

# Blocks unification between countries sitting on opposite ends of the liberty or equality index spectrum.
ztr_both_democratic = {
	custom_tooltip = {
		text = ztr_tooltip_both_not_totalitarian
		AND = {
			scope:actor = {
				ztr_is_not_totalitarian = yes
			}
			scope:target_country = {
				ztr_is_not_totalitarian = yes
			}
		}
	}
}

# Master trigger: every rigid precondition for a peaceful country unification.
ztr_countries_can_unify_trigger = {
	# The target must be a small leftover country, not a peer or superior.
	scope:actor = {
		prestige > scope:target_country.prestige
	}
	# Identity prerequisites
	custom_tooltip = {
		text = ztr_tooltip_countries_have_cultural_or_relations_ground
		ztr_countries_share_primary_culture = yes
		scope:actor = {
			"relations(scope:target_country)" >= relations_threshold:neutral
		}
	}
	ztr_both_democratic = yes
	# Geographic prerequisite: actor's homeland must border or overlap target's territory
	ztr_countries_state_contiguity = yes
}
