namespace = xt

planet_event = { #Event which must be triggered at the planet scope
	id = xt.1
	title = "xt.1.name" #The Event Name
	desc = "xt.1.desc" #This is the full description for the event
	picture = GFX_xt_event1 #This is the event tooltip image
	show_sound = event_xt_bruh #This is the sound that will play when the event fires
	
	is_triggered_only = yes
	
	immediate = {
		set_planet_size = 25
		add_modifier = { #Adds a planetary modifier
			modifier = "xt_queue" #Refers to the xt_queue modifier
			days = 300 #Specifies days that the modifier lasts, (-1 = permanent)
		}
	}
	
	option = { # Defining options
		name = "xt_event1_text" #This is the text for each response option (eg. 'yes')
		custom_tooltip = xt.1.tooltip #This is the response description
	}
	
}

planet_event = {
	id = xt.2
	title = "xt.2.name"
	desc = "xt.2.desc"
	picture = GFX_xt_event2
	show_sound = notification_uplift
	is_triggered_only = yes

	option = {
		name = "xt_event2_1_txt"
		custom_tooltip = xt.2.tooltip
		add_modifier = {
			modifier = "xt_medical_aid_delivered"
			days = 360
		}
		trigger = { 
			owner = {
				OR = {
					has_ethic = ethic_egalitarian
					has_ethic = ethic_fanatic_egalitarian
				}
			} 
		}
	}
	option = { 
		name = "xt_event2_2_txt"
		custom_tooltip = xt.2.2.tooltip
		owner = {
			add_resource = { food = 500}
		}
	}
}
# Provides the empire with 25% progress towards the frontier health tech (Gene Clinics)
country_event = {
	id = xt.4
	is_triggered_only = yes
	hide_window = yes
	
	immediate = {
		add_tech_progress = {
			tech = tech_frontier_health
			progress = 0.25
		}
	}
}
# Provides the empire 20 minerals when a planet is surveyed #
ship_event = {
	is_triggered_only = yes
	hide_window = yes
	id = xt.5
	trigger = {
		orbit = {
			is_star = no
		}
		owner = {
			has_tradition = "tr_xt_extraction_2"
		}
	}
	immediate = {
		owner = {
			add_resource = {
				minerals = 20
			}
		}
	}
}
# Adds +1 minerals to all asteroids currently in empire
country_event = {
	is_triggered_only = yes
	hide_window = yes
	id = xt.6
	trigger = {
		has_tradition = "tr_xt_extraction_4"
	}
	immediate = {
		every_owned_planet = {
			limit = {
				is_asteroid = yes
			}
			add_deposit = d_xt_extraction_4
		}
	}
}
# Adds +1 minerals to asteroid if tr_xt_extraction_4 taken, upon system gain
country_event = {
	id = xt.7
	hide_window = yes
	is_triggered_only = yes

	trigger = { has_tradition = "tr_xt_extraction_4" }

	immediate = {
		from = {
			every_system_planet = {
				limit = {
					is_asteroid = yes
				}
				if = {
					limit = {
						not = {
							has_deposit = d_xt_extraction_4
						}
					}
					add_deposit = d_xt_extraction_4
				}
			}
		}
	}
}
# Removes -1 minerals to asteroid if tr_xt_extraction_4 not taken, upon system loss
country_event = {
	id = xt.8
	hide_window = yes
	is_triggered_only = yes

	trigger = { has_tradition = "tr_xt_extraction_4" }

	immediate = {
		from = {
			every_system_planet = {
				limit = {
					is_asteroid = yes
				}
				if = {
					limit = {
						Nand = {
							exists = owner
							owner = {
								has_tradition = "tr_xt_extraction_4"
							}
						}
						has_deposit = d_xt_extraction_4
					}
					remove_deposit = d_xt_extraction_4
				}
			}
		}
	}
}
# Provides +25% progress towards the tech_mineral_purification_1
country_event = {
	id = xt.9
	hide_window = yes
	is_triggered_only = yes

	trigger = { has_tradition = "tr_xt_extraction_adopt" }

	immediate = {
		add_tech_progress = {
			tech = tech_mineral_purification_1
			progress = 0.25
		}
	}
}
# Adds +4 minerals to all molten worlds that are added to empire
country_event = {
	id = xt.10
	hide_window = yes
	is_triggered_only = yes

	trigger = { has_tradition = "tr_xt_extraction_3" }

	immediate = {
		from = {
			every_system_planet = {
				limit = {
					is_planet_class = pc_molten
				}
				add_deposit = d_xt_extraction_3
				set_planet_flag = xt_extraction_3_done
			}
		}
	}
}
# Removes -4 minerals to all molten worlds that are lost by empire
country_event = {
	id = xt.11
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		from = {
			every_system_planet = {
				limit = {
					is_planet_class = pc_molten
				}
				remove_deposit = d_xt_extraction_3
				remove_planet_flag = xt_extraction_3_done
			}
		}
	}
}
# Adds +25% progress to Food Processing tech when agriculture tradition taken
country_event = {
	id = xt.12
	hide_window = yes
	is_triggered_only = yes

	trigger = { has_tradition = "tr_xt_agriculture_adopt" }

	immediate = {
		add_tech_progress = {
			tech = tech_food_processing_1
			progress = 0.25
		}
	}
}
# Adds one of three local delicacy deposits based on planet class
planet_event = {
	id = xt.13
	is_triggered_only = yes
	hide_window = yes
	immediate = {
		if = {
			limit = {
				OR = {
					is_planet_class = pc_arid
					is_planet_class = pc_desert
					is_planet_class = pc_savannah
					is_planet_class = pc_gaia
				}
				NOT = { has_planet_flag = xt_agriculture_1_deposit_present }
			}
			random_list = {
				1 = { add_deposit = d_xt_agriculture_hot_1 }
				1 = { add_deposit = d_xt_agriculture_hot_2 }
				1 = { add_deposit = d_xt_agriculture_hot_3 }
			}
			set_planet_flag = xt_agriculture_1_deposit_present
		}
		if = {
			limit = {
				OR = {
					is_planet_class = pc_alpine
					is_planet_class = pc_arctic
					is_planet_class = pc_tundra
					is_planet_class = pc_gaia
				}
				NOT = { has_planet_flag = xt_agriculture_1_deposit_present }
			}
			random_list = {
				1 = { add_deposit = d_xt_agriculture_cold_1 }
				1 = { add_deposit = d_xt_agriculture_cold_2 }
				1 = { add_deposit = d_xt_agriculture_cold_3 }
			}
			set_planet_flag = xt_agriculture_1_deposit_present
		}
		if = {
			limit = {
				OR = {
					is_planet_class = pc_continental
					is_planet_class = pc_ocean
					is_planet_class = pc_tropical
					is_planet_class = pc_gaia
				}
				NOT = { has_planet_flag = xt_agriculture_1_deposit_present }
			}
			random_list = {
				1 = { add_deposit = d_xt_agriculture_wet_1 }
				1 = { add_deposit = d_xt_agriculture_wet_2 }
				1 = { add_deposit = d_xt_agriculture_wet_3 }
			}
			set_planet_flag = xt_agriculture_1_deposit_present
		}
	}
}
# Fires xt.13 whenever a system is gained based on if owner has tr_xt_agriculture_1 unlocked
country_event = {
	id = xt.14
	is_triggered_only = yes
	hide_window = yes

	trigger = { owner = { has_tradition = tr_xt_agriculture_1 } }

	immediate = {
		from = {
			every_system_planet = {
				hidden_effect = {
					planet_event = { 
						id = xt.13 
					}
				}
			}
		}
	}
}
# Checks how many differing planet types than the capital are in the empire, then updates variable
country_event = {
	id = xt.15
	is_triggered_only = yes
	hide_window = yes

	trigger = { owner = { has_tradition = tr_xt_agriculture_3 } }
	immediate = {
		set_variable = {
			which = xt_is_pc_arid
			value = 0
		}
		set_variable = {
			which = xt_is_pc_desert
			value = 0
		}
		set_variable = {
			which = xt_is_pc_savannah
			value = 0
		}
		set_variable = {
			which = xt_is_pc_alpine
			value = 0
		}
		set_variable = {
			which = xt_is_pc_arctic
			value = 0
		}
		set_variable = {
			which = xt_is_pc_tundra
			value = 0
		}
		set_variable = {
			which = xt_is_pc_continental
			value = 0
		}
		set_variable = {
			which = xt_is_pc_ocean
			value = 0
		}
		set_variable = {
			which = xt_is_pc_tropical
			value = 0
		}set_variable = {
			which = xt_is_pc_gaia
			value = 0
		}
		set_variable = {
			which = xt_is_pc_nuked
			value = 0
		}
		set_variable = {
			which = xt_is_pc_city
			value = 0
		}
		set_variable = {
			which = xt_is_pc_relic
			value = 0
		}
		set_variable = {
			which = xt_is_pc_hive
			value = 0
		}
		set_variable = {
			which = xt_is_pc_machine
			value = 0
		}
		set_variable = {
			which = xt_is_pc_ringworld_habitable
			value = 0
		}
		set_variable = {
			which = xt_is_pc_shattered_ring_habitable
			value = 0
		}
		set_variable = {
			which = xt_is_other_planet_class_than_capital
			value = 0
		}
		every_owned_planet = {
			limit = { is_planet_class = pc_arid }
			prevprev = { 
				change_variable = {
					which = xt_is_pc_arid
					value = 1
				}
			}
		}
		every_owned_planet = {
			limit = { is_planet_class = pc_desert }
			prevprev = { 
				change_variable = {
					which = xt_is_pc_desert
					value = 1
				}
			}
		}
		every_owned_planet = {
			limit = { is_planet_class = pc_savannah }
			prevprev = { 
				change_variable = {
					which = xt_is_pc_savannah
					value = 1
				}
			}
		}
		every_owned_planet = {
			limit = { is_planet_class = pc_alpine }
			prevprev = { 
				change_variable = {
					which = xt_is_pc_alpine
					value = 1
				}
			}
		}
		every_owned_planet = {
			limit = { is_planet_class = pc_arctic }
			prevprev = { 
				change_variable = {
					which = xt_is_pc_arctic
					value = 1
				}
			}
		}
		every_owned_planet = {
			limit = { is_planet_class = pc_tundra }
			prevprev = { 
				change_variable = {
					which = xt_is_pc_tundra
					value = 1
				}
			}
		}
		every_owned_planet = {
			limit = { is_planet_class = pc_continental }
			prevprev = { 
				change_variable = {
					which = xt_is_pc_continental
					value = 1
				}
			}
		}
		every_owned_planet = {
			limit = { is_planet_class = pc_ocean }
			prevprev = { 
				change_variable = {
					which = xt_is_pc_ocean
					value = 1
				}
			}
		}
		every_owned_planet = {
			limit = { is_planet_class = pc_tropical }
			prevprev = { 
				change_variable = {
					which = xt_is_pc_tropical
					value = 1
				}
			}
		}
		every_owned_planet = {
			limit = { is_planet_class = pc_gaia }
			prevprev = { 
				change_variable = {
					which = xt_is_pc_gaia
					value = 1
				}
			}
		}
		every_owned_planet = {
			limit = { is_planet_class = pc_nuked }
			prevprev = { 
				change_variable = {
					which = xt_is_pc_nuked
					value = 1
				}
			}
		}
		every_owned_planet = {
			limit = { is_planet_class = pc_city }
			prevprev = { 
				change_variable = {
					which = xt_is_pc_city
					value = 1
				}
			}
		}
		every_owned_planet = {
			limit = { is_planet_class = pc_relic }
			prevprev = { 
				change_variable = {
					which = xt_is_pc_relic
					value = 1
				}
			}
		}
		every_owned_planet = {
			limit = { is_planet_class = pc_hive }
			prevprev = { 
				change_variable = {
					which = xt_is_pc_hive
					value = 1
				}
			}
		}
		every_owned_planet = {
			limit = { is_planet_class = pc_machine }
			prevprev = { 
				change_variable = {
					which = xt_is_pc_machine
					value = 1
				}
			}
		}
		every_owned_planet = {
			limit = { is_planet_class = pc_habitat }
			prevprev = { 
				change_variable = {
					which = xt_is_pc_habitat
					value = 1
				}
			}
		}
		every_owned_planet = {
			limit = { is_planet_class = pc_ringworld_habitable }
			prevprev = { 
				change_variable = {
					which = xt_is_pc_ringworld_habitable
					value = 1
				}
			}
		}
		every_owned_planet = {
			limit = { is_planet_class = pc_shattered_ring_habitable }
			prevprev = { 
				change_variable = {
					which = xt_is_pc_shattered_ring_habitable
					value = 1
				}
			}
		}
		if = {
			limit = {
				owner = {
					check_variable = {
						which = xt_is_pc_arid
						value > 0
					}
				}
			}
			owner = {
				change_variable = {
					which = xt_is_other_planet_class_than_capital
					value = 1
				}
			}
		}
		if = {
			limit = {
				owner = {
					check_variable = {
						which = xt_is_pc_desert
						value > 0
					}
				}
			}
			owner = {
				change_variable = {
					which = xt_is_other_planet_class_than_capital
					value = 1
				}
			}
		}
		if = {
			limit = {
				owner = {
					check_variable = {
						which = xt_is_pc_savannah
						value > 0
					}
				}
			}
			owner = {
				change_variable = {
					which = xt_is_other_planet_class_than_capital
					value = 1
				}
			}
		}
		if = {
			limit = {
				owner = {
					check_variable = {
						which = xt_is_pc_alpine
						value > 0
					}
				}
			}
			owner = {
				change_variable = {
					which = xt_is_other_planet_class_than_capital
					value = 1
				}
			}
		}
		if = {
			limit = {
				owner = {
					check_variable = {
						which = xt_is_pc_arctic
						value > 0
					}
				}
			}
			owner = {
				change_variable = {
					which = xt_is_other_planet_class_than_capital
					value = 1
				}
			}
		}
		if = {
			limit = {
				owner = {
					check_variable = {
						which = xt_is_pc_tundra
						value > 0
					}
				}
			}
			owner = {
				change_variable = {
					which = xt_is_other_planet_class_than_capital
					value = 1
				}
			}
		}
		if = {
			limit = {
				owner = {
					check_variable = {
						which = xt_is_pc_continental
						value > 0
					}
				}
			}
			owner = {
				change_variable = {
					which = xt_is_other_planet_class_than_capital
					value = 1
				}
			}
		}
		if = {
			limit = {
				owner = {
					check_variable = {
						which = xt_is_pc_ocean
						value > 0
					}
				}
			}
			owner = {
				change_variable = {
					which = xt_is_other_planet_class_than_capital
					value = 1
				}
			}
		}
		if = {
			limit = {
				owner = {
					check_variable = {
						which = xt_is_pc_tropical
						value > 0
					}
				}
			}
			owner = {
				change_variable = {
					which = xt_is_other_planet_class_than_capital
					value = 1
				}
			}
		}
		if = {
			limit = {
				owner = {
					check_variable = {
						which = xt_is_pc_gaia
						value > 0
					}
				}
			}
			owner = {
				change_variable = {
					which = xt_is_other_planet_class_than_capital
					value = 1
				}
			}
		}
		if = {
			limit = {
				owner = {
					check_variable = {
						which = xt_is_pc_nuked
						value > 0
					}
				}
			}
			owner = {
				change_variable = {
					which = xt_is_other_planet_class_than_capital
					value = 1
				}
			}
		}
		if = {
			limit = {
				owner = {
					check_variable = {
						which = xt_is_pc_city
						value > 0
					}
				}
			}
			owner = {
				change_variable = {
					which = xt_is_other_planet_class_than_capital
					value = 1
				}
			}
		}
		if = {
			limit = {
				owner = {
					check_variable = {
						which = xt_is_pc_relic
						value > 0
					}
				}
			}
			owner = {
				change_variable = {
					which = xt_is_other_planet_class_than_capital
					value = 1
				}
			}
		}
		if = {
			limit = {
				owner = {
					check_variable = {
						which = xt_is_pc_hive
						value > 0
					}
				}
			}
			owner = {
				change_variable = {
					which = xt_is_other_planet_class_than_capital
					value = 1
				}
			}
		}
		if = {
			limit = {
				owner = {
					check_variable = {
						which = xt_is_pc_machine
						value > 0
					}
				}
			}
			owner = {
				change_variable = {
					which = xt_is_other_planet_class_than_capital
					value = 1
				}
			}
		}
		if = {
			limit = {
				owner = {
					check_variable = {
						which = xt_is_pc_habitat
						value > 0
					}
				}
			}
			owner = {
				change_variable = {
					which = xt_is_other_planet_class_than_capital
					value = 1
				}
			}
		}
		if = {
			limit = {
				owner = {
					check_variable = {
						which = xt_is_pc_ringworld_habitable
						value > 0
					}
				}
			}
			owner = {
				change_variable = {
					which = xt_is_other_planet_class_than_capital
					value = 1
				}
			}
		}
		if = {
			limit = {
				owner = {
					check_variable = {
						which = xt_is_pc_shattered_ring_habitable
						value > 0
					}
				}
			}
			owner = {
				change_variable = {
					which = xt_is_other_planet_class_than_capital
					value = 1
				}
			}
		}
		change_variable = {
			which = xt_is_other_planet_class_than_capital
			value = -1
		}
	}
}

# Adds +25% progress towards Global Energy Management tech (tech_power_hub_1)
country_event = {
	id = xt.16
	is_triggered_only = yes
	hide_window = yes

	trigger = { owner = { has_tradition = tr_xt_generation_adopt } }

	immediate = {
		add_tech_progress = {
			tech = tech_power_hub_1
			progress = 0.25
		}
	}
}
# Adds +1 Energy to all stars added to empire
country_event = {
	id = xt.17
	hide_window = yes
	is_triggered_only = yes

	trigger = { has_tradition = "tr_xt_generation_1" }

	immediate = {
		from = {
			every_system_planet = {
				limit = {
					is_star = yes
				}
				add_deposit = d_xt_generation_1
				set_planet_flag = xt_generation_1_done
			}
		}
	}
}
# Removes +1 Energy from all stars lost by empire
country_event = {
	id = xt.18
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		from = {
			every_system_planet = {
				limit = {
					is_star = yes
				}
				remove_deposit = d_xt_generation_1
				remove_planet_flag = xt_generation_1_done
			}
		}
	}
}
# Checks every month to see how many scientists in the empire have the Expertise: Particles trait, and totals up the variable
country_event = {
	id = xt.19
	hide_window = yes
	is_triggered_only = yes

	trigger = { owner = { has_tradition = tr_xt_generation_5 } }

	immediate = {
		owner = {
			set_variable = {
				which = xt_particles_leader_count
				value = 0
			}
			every_owned_leader = {
				limit = {
					or = {
						has_trait = leader_trait_expertise_particles
						has_trait = leader_trait_expertise_particles_2
						has_trait = leader_trait_expertise_particles_3
					}
					leader_class = scientist
				}
				owner = {
					change_variable = {
						which = xt_particles_leader_count
						value = 1
					}
				}
			}
		}
	}
}
# Adds Expertise: Particles trait to leaders if they do not have it already, when added to the leader pool
country_event = {
	id = xt.20
	hide_window = yes
	is_triggered_only = yes

	trigger = { has_tradition = tr_xt_generation_5 }

	immediate = {
		from = {
			if = {
				limit = {
					NOR = {
						has_trait = leader_trait_expertise_particles
						has_trait = leader_trait_expertise_particles_2
						has_trait = leader_trait_expertise_particles_3
					}
				}
				add_trait = leader_trait_expertise_particles
			}
		}
	}
}
# Adds Expertise: Biology trait to leaders if they do not have it already, when added to the leader pool
country_event = {
	id = xt.21
	hide_window = yes
	is_triggered_only = yes

	trigger = { has_tradition = tr_xt_healthcare_2 }

	immediate = {
		from = {
			if = {
				limit = {
					NOR = {
						has_trait = leader_trait_expertise_biology
						has_trait = leader_trait_expertise_biology_2
						has_trait = leader_trait_expertise_biology_3
					}
				}
				add_trait = leader_trait_expertise_biology
			}
		}
	}
}
# Adds +25% progress to Advanced Metallurgy tech when heavy industry tradition taken
country_event = {
	id = xt.22
	hide_window = yes
	is_triggered_only = yes

	trigger = { has_tradition = "tr_xt_heavy_industry_adopt" }

	immediate = {
		add_tech_progress = {
			tech = tech_advanced_metallurgy_1
			progress = 0.25
		}
	}
}
# Adds Metallurgic Apprentice trait to leaders if they do not have it already, when added to the leader pool
country_event = {
	id = xt.23
	hide_window = yes
	is_triggered_only = yes

	trigger = { has_tradition = tr_xt_heavy_industry_4 }

	immediate = {
		from = {
			if = {
				limit = {
					NOR = {
						has_trait = leader_trait_xt_metallurgic_apprentice
						has_trait = leader_trait_xt_metallurgic_expert
						has_trait = leader_trait_xt_metallurgic_master
					}
				}
				add_trait = leader_trait_xt_metallurgic_apprentice
			}
		}
	}
}
# Checks how many planets in border are molten, then updates variable and increases alloy capacity by 5000
country_event = {
	id = xt.24
	hide_window = yes
	is_triggered_only = yes

	trigger = { owner = { has_tradition = tr_xt_heavy_industry_3 } }

	immediate = {
		set_variable = {
			which = xt_molten_in_empire
			value = 0
		}
		every_planet_within_border = {
			limit = {
				is_planet_class = pc_molten
			}
			root = {
				change_variable = {
					which = xt_molten_in_empire
					value = 1
				}
			}
		}
	}
}
# Adds +25% progress to Market Analysis Algorithms tech when consumerism tradition taken
country_event = {
	id = xt.25
	hide_window = yes
	is_triggered_only = yes

	trigger = { has_tradition = "tr_xt_consumerism_adopt" }

	immediate = {
		add_tech_progress = {
			tech = tech_consumer_good_refinement_1
			progress = 0.25
		}
	}
}
# Checks how many consumer goods are in stockpile, divides by 2500, then updates variable
country_event = {
	id = xt.26
	hide_window = yes
	is_triggered_only = yes

	trigger = { has_tradition = tr_xt_consumerism_2 }

	immediate = {
		set_variable = {
			which = xt_consumer_goods_in_stockpile_factor
			value = 0
		}
		export_resource_stockpile_to_variable = {
			resource = consumer_goods
			variable = xt_consumer_goods_in_stockpile_factor
		}
		divide_variable = {
			which = xt_consumer_goods_in_stockpile_factor
			value = 2500
		}
		floor_variable = xt_consumer_goods_in_stockpile_factor
	}
}
# Begins (re)/establishment of planetary heritage craft
planet_event = {
	id = xt.27
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		owner = { has_tradition = tr_xt_consumerism_4 }
		NOR = { 
			has_planet_flag = xt_has_crafting_heritage 
			has_planet_flag = xt_discovering_crafting_heritage
		}
		OR = {
			has_building = building_factory_1
			has_building = building_factory_2
			has_building = building_factory_3
		}
	}
	immediate = {
		planet_event = {
			id = xt.28
			days = 360
		}
		add_modifier = {
			modifier = xt_consumerism_starting
			days = 360
		}
		set_planet_flag = xt_discovering_crafting_heritage
	}
}
# Heritage Craft Selection
planet_event = {
	id = xt.28
	is_triggered_only = yes
	location = from

	title = xt.28.name #The Event Name
	desc = xt.28.desc #This is the full description for the event
	picture = GFX_xt_event_28 #This is the event tooltip image
	show_sound = discovery #This is the sound that will play when the event fires
	immediate = {
		hidden_effect = {
			remove_modifier = xt_consumerism_starting
			remove_planet_flag = xt_discovering_crafting_heritage
		}
	}
	option = {
		name = xt.28.a # Rare Crystals
		#custom_tooltip = xt.28.a.tooltip #This is the custom response description
		allow = {
			owner = {
				has_technology = tech_mine_rare_crystals
			}
		}
		add_modifier = { 
			modifier = xt_consumerism_a 
			days = -1 
		}
		set_planet_flag = xt_has_crafting_heritage
	}
	option = {
		name = xt.28.b # Exotic Gases
		#custom_tooltip = xt.28.b.tooltip #This is the custom response description
		allow = {
			owner = {
				has_technology = tech_mine_exotic_gases
			}
		}
		add_modifier = { 
			modifier = xt_consumerism_b
			days = -1 
		}
		set_planet_flag = xt_has_crafting_heritage
	}
	option = {
		name = xt.28.c # Volatile Motes
		#custom_tooltip = xt.28.c.tooltip #This is the custom response description
		allow = {
			owner = {
				has_technology = tech_mine_volatile_motes
			}
		}
		add_modifier = { 
			modifier = xt_consumerism_c
			days = -1 
		}
		set_planet_flag = xt_has_crafting_heritage
	}
	option = {
		name = xt.28.d # Rare Crystals
		#custom_tooltip = xt.28.d.tooltip #This is the custom response description
		allow = {
			owner = {
				has_technology = tech_mine_living_metal
			}
		}
		add_modifier = { 
			modifier = xt_consumerism_d
			days = -1 
		}
		set_planet_flag = xt_has_crafting_heritage
	}
	option = {
		name = xt.28.e # Rare Crystals
		#custom_tooltip = xt.28.e.tooltip #This is the custom response description
		allow = {
			owner = {
				has_technology = tech_mine_zro
			}
		}
		add_modifier = { 
			modifier = xt_consumerism_e
			days = -1 
		}
		set_planet_flag = xt_has_crafting_heritage
	}
	option = {
		name = xt.28.f # Rare Crystals
		#custom_tooltip = xt.28.f.tooltip #This is the custom response description
		allow = {
			owner = {
				has_technology = tech_mine_dark_matter
			}
		}
		add_modifier = { 
			modifier = xt_consumerism_f
			days = -1 
		}
		set_planet_flag = xt_has_crafting_heritage
	}
	option = {
		name = xt.28.g # Physics
		#custom_tooltip = xt.28.g.tooltip #This is the custom response description
		add_modifier = { 
			modifier = xt_consumerism_g
			days = -1 
		}
		set_planet_flag = xt_has_crafting_heritage
	}
	option = {
		name = xt.28.h # Biology
		#custom_tooltip = xt.28.h.tooltip #This is the custom response description
		add_modifier = { 
			modifier = xt_consumerism_h
			days = -1 
		}
		set_planet_flag = xt_has_crafting_heritage
	}
	option = {
		name = xt.28.i # Engineering
		#custom_tooltip = xt.28.i.tooltip #This is the custom response description
		add_modifier = { 
			modifier = xt_consumerism_i
			days = -1 
		}
		set_planet_flag = xt_has_crafting_heritage
	}
}
# Sets planet as the hyperlane couriers start planet and a different one in the empire as the destination, 
# checks if they exist and if not; spawns them. Spawns a fleet for them, and tells it to go to the destination. 
# Arrives at destination, then adds modifier and adds monthly consumer goods income to the owner
planet_event = {
	id = xt.29
	#is_triggered_only = yes
	hide_window = yes
	location = from

	mean_time_to_happen = {
		months = 3
	}

	# Stops it firing on unowned planets
	pre_triggers = {
		has_owner = yes
	}

	trigger = {
		owner = {
			has_tradition = tr_xt_consumerism_3
			NOT = { has_edict = xt_halt_hyperlane_express }
			check_variable = {
				which = xt_courier_count
				value < xt_courier_depot_count
			}
			check_variable = {
				which = xt_colony_count
				value > 1
			}
		}
		has_building = building_xt_hyperlane_express_depot
	}
	immediate = {
		set_planet_flag = xt_29_spawnplanet
		save_event_target_as = xt_29_spawnpoint
		owner = {
			save_event_target_as = xt_29_host_empire
			change_variable = {
				which = xt_courier_count
				value = 1
			}
			random_controlled_planet = {
				limit = {
					NOT = { has_planet_flag = xt_29_spawnplanet }
					is_colony = yes
				}
				save_event_target_as = xt_29_destination
			}
		}
		every_country = {
			limit = {
				has_country_flag = xt_is_hyperlane_couriers
			}
			save_event_target_as = xt_29_hyperlane_couriers
		}
		create_fleet = {
			name = "xt_29_fleet_name"
			effect = {
				set_owner = event_target:xt_29_hyperlane_couriers #event_target:xt_express_shipping_company
				create_ship = {
					name = "xt_29_ship_name"
					design = "NAME_C1"
					prefix = no
					upgradable = no
				}
				set_location = {
					target = event_target:xt_29_spawnpoint
				}
				set_fleet_stance = passive
				save_event_target_as = xt_29_spawned_fleet
				set_fleet_flag = xt_29_is_courier_fleet
				add_modifier = {
					modifier = xt_29_courier_speed_bonus
				}
			}
		}
		event_target:xt_29_spawned_fleet = {
			queue_actions = {
				wait = { duration = 10 }
				#move_to = event_target:xt_29_destination
				orbit_planet = event_target:xt_29_destination
				wait = { duration = 10 }
				effect = {
					id = "xt_29_fleet_delivered"
					orbit = {
						add_modifier = {
							modifier = xt_consumerism_3_delivered
							days = 180
						}
						planet_owner = {
							set_variable = {
								which = xt_monthly_consumer_goods
								value = 0
							}
							export_resource_income_to_variable = {
								resource = consumer_goods
								variable = xt_monthly_consumer_goods
							}
							if = {
								limit = {
									check_variable = {
										which = xt_monthly_consumer_goods
										value > 0
									}
								}
								add_resource = {
									consumer_goods = 1
									multiplier = xt_monthly_consumer_goods
								}	
							}
							change_variable = {
								which = xt_total_shipments
								value = 1
							}
						}
					}
				}
				effect = {
					id = "xt_29_fleet_vanish"
					set_location = null #so the ship vanishes before being blown up through the effect below. null isn't a valid location target
				}
				effect = {
					id = "xt_29_fleet_remove"
					event_target:xt_29_host_empire = {
						change_variable = {
							which = xt_courier_count
							value = -1
						}
					}
					delete_fleet = this
				}
			}
		}
		remove_planet_flag = xt_29_spawnplanet
	}
}
# Checks how many Hyperlane Express Depots are in empire, then updates variable
country_event = {
	id = xt.30
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		has_tradition = tr_xt_consumerism_3
	}

	immediate = {
		set_variable = {
			which = xt_courier_depot_count
			value = 0
		}
		every_owned_planet = {
			limit = {
				is_colony = yes
				has_building = building_xt_hyperlane_express_depot
			}
			prev = {
				change_variable = {
					which = xt_courier_depot_count
					value = 1
				}
			}
		}
	}
}
#Creates the Hyperlane Express Couriers country
country_event = {
	id = xt.31
	is_triggered_only = yes
	hide_window = yes

	immediate = {
		create_country = {
			name = xt_NAME_Hyperlane_Couriers
			type = xt_transport #faction #nice_faction
			auto_delete = no
			flag = {
				icon = {
					category = "pre_ftl"
					file = "preftl_early_space_age.dds"
				}
				background = {
					category = "backgrounds"
					file = "00_solid.dds"
				}
				colors = {
					"black"
					"orange"
					"null"
					"null"
				}
			}
			effect = {
				establish_communications_no_message = root.owner
				set_country_flag = xt_is_hyperlane_couriers
				set_faction_hostility = {
					target = root.owner
					set_hostile = no
					set_neutral = yes
				}
			}
		}
		add_modifier = { #Adds country modifier so that Hyperlane Express details can be tracked
			modifier = xt_mod_courier_capacity
		}
		set_variable = {
			which = xt_total_shipments
			value = 0
		}
	}
} 
# Checks how many hyperlane courier fleets are active each month
country_event = {
	id = xt.32
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		has_tradition = tr_xt_consumerism_3
	}

	immediate = {
		save_event_target_as = xt_29_host_empire
		set_variable = {
			which = xt_courier_count
			value = 0
		}
		every_country = {
			limit = {
				has_country_flag = xt_is_hyperlane_couriers
			}
			save_event_target_as = xt_29_hyperlane_couriers
		}
		add_intel = {
			who = event_target:xt_29_hyperlane_couriers
			amount = 100
		}
		event_target:xt_29_hyperlane_couriers = {
			every_owned_fleet = {
				limit = {
					has_fleet_flag = xt_29_is_courier_fleet
				}
				prevprevprev = {
					change_variable = {
						which = xt_courier_count
						value = 1
					}
				}
			}
		}
	}
}
# Checks how many colonies are in Empire, so that courier ships from xt.29 don't spawn if there's only one planet in Empire
country_event = {
	id = xt.33
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_tradition = tr_xt_consumerism_3
	}

	immediate = {
		set_variable = {
			which = xt_colony_count
			value = 0
		}
		every_owned_planet = {
			limit = {
				is_colony = yes
			}
			prev = {
				change_variable = {
					which = xt_colony_count
					value = 1
				}
			}
		}
	}
}
# Increases xt_commercial_pact_count variable when commercial pact formed
country_event = {
	id = xt.34
	is_triggered_only = yes
	hide_window = yes

	immediate = {
		this = {
			if = {
				limit = {
					has_tradition = tr_xt_consumerism_5
				}
				change_variable = {
					which = xt_commercial_pact_count
					value = 1
				}
			}
		}
		from = {
			if = {
				limit = {
					has_tradition = tr_xt_consumerism_5
				}
				change_variable = {
					which = xt_commercial_pact_count
					value = 1
				}
			}
		}
	}
}
# Decreases xt_commercial_pact_count variable when commercial pact broken
country_event = {
	id = xt.35
	is_triggered_only = yes
	hide_window = yes

	immediate = {
		this = {
			change_variable = {
				which = xt_commercial_pact_count
				value = -1
			}
		}
	}
}
# Checks how many commercial pacts the empire has with other empires
country_event = {
	id = xt.36
	is_triggered_only = yes
	hide_window = yes

	immediate = {
		set_variable = {
			which = xt_commercial_pact_count
			value = 0
		}
		every_playable_country = {
			limit = {
				has_commercial_pact = root
			}
			root = {
				change_variable = {
					which = xt_commercial_pact_count
					value = 1
				}
			}
		}
	}
}
# Adds +25% progress to Adaptive Bureaucracy tech when propaganda tradition taken
country_event = {
	id = xt.37
	hide_window = yes
	is_triggered_only = yes

	trigger = { has_tradition = "tr_xt_propaganda_adopt" }

	immediate = {
		add_tech_progress = {
			tech = tech_adaptive_bureaucracy
			progress = 0.25
		}
	}
}
# Checks what the current influence income is each month
country_event = {
	id = xt.38
	hide_window = yes
	is_triggered_only = yes

	trigger = { owner = { has_tradition = tr_xt_propaganda_2 } }
	
	immediate = {
		set_variable = {
			which = xt_monthly_influence
			value = 0
		}
		export_resource_income_to_variable = {
			resource = influence
			variable = xt_monthly_influence
		}	
	}
}
# Adds 1 month of influence when triggered (triggered when a pop changes ethics)
pop_event = {
	id = xt.39
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		from = {
			has_tradition = tr_xt_propaganda_2
		}
	}

	immediate = {
		from = {
			add_resource = {
				influence = 1
				multiplier = xt_monthly_influence
			}	
		}
	}
}
# 50% chance of calling xt.41 to change a pop's ethics towards the bombarder, per month, when devastation > 10%
planet_event = {
	id = xt.40
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		from = {
			has_tradition = tr_xt_propaganda_3
		}
		NOT = { has_planet_flag = xt_convert_attempt }
		planet_devastation > 10
	}
	immediate = {
		from = {
			save_event_target_as = xt_40_bombarder
		}
		random_list = {
			1 = { 
				planet_event = { id = xt.41 }
				event_target:xt_40_bombarder = {
					export_resource_income_to_variable = {
						resource = unity
						variable = xt_monthly_unity_bombarding_var
					}
					add_resource = {
						unity = 1
						multiplier = xt_monthly_unity_bombarding_var
					}
				}
			}
			1 = { }
		}
		set_timed_planet_flag = {
			flag = xt_convert_attempt
			days = 30
		}
	}
}
# Changes a pop's ethic when xt.40 calls this event upon daily bombardment (20% chance per month)
planet_event = {
	id = xt.41
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		random_owned_pop = {
			random_list = {
				0 = { 
					modifier = {
						add = 1
						event_target:xt_40_bombarder = { is_authoritarian = yes }
						is_authoritarian = no
					}
					pop_change_ethic = ethic_authoritarian
				}
				0 = { 
					modifier = {
						add = 1
						event_target:xt_40_bombarder = { is_spiritualist = yes }
						is_spiritualist = no
					}
					pop_change_ethic = ethic_spiritualist
				}
				0 = { 
					modifier = {
						add = 1
						event_target:xt_40_bombarder = { is_militarist = yes }
						is_militarist = no
					}
					pop_change_ethic = ethic_militarist
				}
				0 = { 
					modifier = {
						add = 1
						event_target:xt_40_bombarder = { is_xenophobe = yes }
						is_xenophobe = no
					}
					pop_change_ethic = ethic_xenophobe
				}
				0 = { 
					modifier = {
						add = 1
						event_target:xt_40_bombarder = { is_egalitarian = yes }
						is_egalitarian = no
					}
					pop_change_ethic = ethic_egalitarian
				}
				0 = { 
					modifier = {
						add = 1
						event_target:xt_40_bombarder = { is_materialist = yes }
						is_materialist = no
					}
					pop_change_ethic = ethic_materialist
				}
				0 = { 
					modifier = {
						add = 1
						event_target:xt_40_bombarder = { is_pacifist = yes }
						is_pacifist = no
					}
					pop_change_ethic = ethic_pacifist
				}
				0 = { 
					modifier = {
						add = 1
						event_target:xt_40_bombarder = { is_xenophile = yes }
						is_xenophile = no
					}
					pop_change_ethic = ethic_xenophile
				}
			}
		}
	}
}
# Adds the xt_archaeo_site_finished flag to countries that finish an archaeo site
fleet_event = {
	id = xt.42
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		owner = {
			set_country_flag = xt_archaeo_site_finished
		}
	}
}
# Adds +25% progress to the Archaeostudies tech
country_event = {
	id = xt.43
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		add_tech_progress = {
			tech = tech_archaeostudies
			progress = 0.25
		}
	}
}
# Adds the Expertise: Archaeostudies trait to scientists
country_event = {
	id = xt.45
	hide_window = yes
	is_triggered_only = yes

	trigger = { has_tradition = tr_xt_archaeology_1 }

	immediate = {
		from = {
			if = {
				limit = {
					NOR = {
						has_trait = leader_trait_expertise_archaeostudies
						has_trait = leader_trait_expertise_archaeostudies_2
						has_trait = leader_trait_expertise_archaeostudies_3
					}
				}
				add_trait = leader_trait_expertise_archaeostudies
			}
		}
	}
}
# Provides 12 months' worth of unity to the owner of a fleet that finished an archaeological site
fleet_event = {
	id = xt.46
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		owner = { has_tradition = tr_xt_archaeology_4 }
	}

	immediate = {
		owner = {
			export_resource_income_to_variable = {
				resource = unity
				variable = xt_monthly_unity_archaeo_site_finish
			}
			multiply_variable = {
				which = xt_monthly_unity_archaeo_site_finish
				value = 12
			}
			add_resource = {
				unity = 1
				multiplier = xt_monthly_unity_archaeo_site_finish
			}
			add_modifier = {
				modifier = xt_archaeo_site_finished_modifier
				days = 3600
			}
		}
	}
}
# Sets relic count to 0
country_event = {
	id = xt.50
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		set_variable = {
			which = xt_relic_count
			value = 0
		}
	}
}

# Adds 1 to relic count when gaining a relic
country_event = {
	id = xt.48
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		change_variable = {
			which = xt_relic_count
			value = 1
		}
	}
}
# Adds 1 to relic count when losing a relic
country_event = {
	id = xt.49
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		change_variable = {
			which = xt_relic_count
			value = -1
		}
	}
}
# Checks if an empire has a precinct house or judgement hall, but only if they
# don't have the tr_xt_enforcement_adopt tradition, and aren't a player
country_event = {
	id = xt.51
	hide_window = yes
	is_triggered_only = yes

	pre_triggers = {
		is_ai = no
	}

	trigger = {
		NOT = { has_tradition = tr_xt_enforcement_adopt }
	}

	immediate = {
		set_variable =  {
			which = xt_enforcement_adopt_building_count
			value = 0
		}
		every_planet_within_border = {
			limit = {
				OR = {
					has_building = building_precinct_house
					has_building = building_hall_judgment	
				}
				is_colony = yes
			}
			from = {
				change_variable = {
					which = xt_enforcement_adopt_building_count
					value = 1
				}
			}
		}
	}
}
# fires xt.51 whenever a precinct houses or judgement hall building is built
planet_event = {
	id = xt.52
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		owner = {
			NOT = { has_tradition = tr_xt_enforcement_adopt }
		}
		OR = {
			has_building = building_precinct_house
			has_building = building_hall_judgment
		}
	}
	immediate = {
		owner = {
			change_variable = {
				which = xt_enforcement_adopt_building_count
				value = 1
			}
		}
	}
}
# Adds +25% progress to Penal Colonies tech
country_event = {
	id = xt.53
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		add_tech_progress = {
			tech = tech_penal_colonies
			progress = 0.25
		}
	}
}
# Removes Penal Station modifier from planets in a system
system_event = {
	id = xt.54
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		every_system_colony = {
			remove_modifier = xt_penal_station_planet_modifier
		}
	}
}
# Adds Penal Station modifier to planets in a system
system_event = {
	id = xt.55
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		every_system_colony = {
			add_modifier = {
				modifier = xt_penal_station_planet_modifier
			}
		}
	}
}
# Adds Penal Station modifier to A PLANET in a system if penal station is in system
planet_event = {
	id = xt.56
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		solar_system = {
			has_xt_penal_station = yes
		}
	}

	immediate = {
		add_modifier = {
			modifier = xt_penal_station_planet_modifier
		}
	}
}
# Adds the Righteous leader trait to a leader when called
country_event = {
	id = xt.57
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		has_tradition = tr_xt_enforcement_2
	}

	immediate = {
		from = {
			if = {
				limit = {
					leader_class = official
					NOR = {
						has_trait = leader_trait_righteous
						has_trait = leader_trait_righteous_2
					}
				}
				add_trait = leader_trait_righteous
				remove_trait = leader_trait_corrupt
				remove_trait = leader_trait_corrupt_2
				remove_trait = leader_trait_sadistic
				remove_trait = leader_trait_sadistic_2
			}
		}
	}
}
country_event = {
	id = xt.58
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_tradition = tr_xt_enforcement_5
	}

	immediate = {
		set_variable = {
			which = xt_crimeless_planets
			value = 0
		}
		every_owned_planet = {
			limit = {
				is_colony = yes
				planet_crime = 0
			}
			from = {
				change_variable = {
					which = xt_crimeless_planets
					value = 1
				}
			}
		}
	}
}