#########################################
#
# on_action_events
#
#########################################

##############################
# FORMING THE GALACTIC MARKET
##############################

# NOTE: See also 'galcom.64' (Relocate the Galactic Market)

# Market Founder event (resolution accepted)
# via resolution_galactic_market_form = {} | this = Resolution proposer country
country_event = {
	id = action.96
	title = action.96.name
	desc = {
		text = action.96.desc
		trigger = { is_xenophobe = no }
	}
	desc = {
		text = action.96.desc.phobe
		trigger = { is_xenophobe = yes }
	}
	picture = GFX_evt_financial_instruments
	show_sound = event_galactic_market
	is_triggered_only = yes

	immediate = {
		set_global_flag = ongoing_market_nomination
		set_country_flag = market_nomination_eligible
		event_target:global_event_country = {
			country_event = { id = action.98 days = @galactic_market_nomination_period }
		}
		begin_event_chain = {
			event_chain = market_founding_chain
			target = this
		}
		every_playable_country = {
			limit = {
				NOT = { is_same_value = root }
				is_galactic_community_member = yes
			}
			country_event = { id = action.97 } # inform all other concerned countries
		}
	}

	option = {
		name = action.96.a
		trigger = { is_megacorp = yes }
	}

	option = {
		name = action.96.b
		trigger = { is_megacorp = no }
	}

	after = {
		custom_tooltip = enable_decision_market_nomination
		# Notification
		tooltip = {
			begin_event_chain = {
				event_chain = market_founding_chain
				target = this
			}
		}
	}
}

# Market Nomination started (notification event)
# this = every GalCom member except the resolution proposer
country_event = {
	id = action.97
	title = action.97.name
	desc = {
		text = action.97.desc
		trigger = {
			NOR = {
				is_xenophobe = yes
				is_megacorp = yes
			}
		}
	}
	desc = {
		text = action.97.desc.phobe
		trigger = { is_xenophobe = yes }
	}
	desc = {
		text = action.97.desc.corp
		trigger = { is_megacorp = yes }
	}
	picture = GFX_evt_financial_instruments
	show_sound = event_galactic_market
	is_triggered_only = yes

	immediate = {
		set_country_flag = market_nomination_eligible
		begin_event_chain = {
			event_chain = market_founding_chain
			target = this
		}
	}

	option = {
		name = action.96.a
		trigger = { is_megacorp = yes }
		custom_tooltip = enable_decision_market_nomination
	}

	option = {
		name = action.96.b
		trigger = {
			is_megacorp = no
		}
		custom_tooltip = enable_decision_market_nomination
	}

	after = {
		tooltip = {
			begin_event_chain = {
				event_chain = market_founding_chain
				target = this
			}
		}
	}
}

# Appoint a host for the Galactic Market
# this = global country | from = proposing country
country_event = {
	id = action.98
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		remove_global_flag = ongoing_market_nomination
		# If at least one planet was nominated, choose a host planet...
		if = {
			limit = {
				any_galaxy_planet = {
					is_market_nominee_planet = yes
					exists = owner
					owner = {
						is_country_type = default
						has_country_flag = market_nomination_eligible # i.e. they are or were a GalCom member
					}
				}
			}
			every_playable_country = {
				limit = { has_event_chain = market_founding_chain }
				end_event_chain = market_founding_chain
			}
			choose_galactic_market_host = yes
			# Start the process of informing the new founder
			event_target:market_founder = {
				country_event = { id = action.99 }
			}
		}
		# ... else inform the galaxy that nominations were not forthcoming, and reset.
		else = {
			from = {
				country_event = { id = action.1000 } # Our effort failed
			}
			every_playable_country = {
				limit = {
					NOT = {
						is_same_value = from
					}
					has_event_chain = market_founding_chain
				}
				country_event = { id = action.1005 } # The attempt failed
			}
		}
	}
}

# Market did not form (proposing country)
# this = proposing country
country_event = {
	id = action.1000
	title = action.1000.name
	desc = action.1000.desc
	picture = GFX_evt_financial_instruments
	show_sound = event_galactic_market
	is_triggered_only = yes

	immediate = {
		end_event_chain = market_founding_chain
	}

	option = {
		name = action.1000.a
		tooltip = {
			end_event_chain = market_founding_chain
		}
	}
}

# Market did not form (other GalCom countries)
# this = country
country_event = {
	id = action.1005
	title = action.1000.name
	desc = {
		text = action.1005.desc
		trigger = { is_xenophobe = no }
	}
	desc = {
		text = action.1005.desc.phobe
		trigger = { is_xenophobe = yes }
	}
	picture = GFX_evt_financial_instruments
	show_sound = event_galactic_market
	is_triggered_only = yes

	immediate = {
		end_event_chain = market_founding_chain
	}

	option = {
		name = {
			text = UNFORTUNATE
			trigger = {
				is_xenophobe = no
			}
		}
		name = {
			text = action.1005.a.phobe
			trigger = {
				is_xenophobe = yes
			}
		}
		tooltip = {
			end_event_chain = market_founding_chain
		}
	}
}

# Market forms; founder selected (gateway event)
# this = new host country
country_event = {
	id = action.99
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		set_global_flag = galactic_market_founded # code listens for this flag to create market
		country_event = { id = action.104 days = 5 }
	}
	after = {
		country_event = { id = timeline.73 } # Timeline Galactic Market
	}
}

# Market forms (notifying the new host)
# this = new host country
country_event = {
	id = action.104
	title = action.99.name
	desc = action.99.desc
	picture = GFX_evt_financial_instruments
	location = event_target:galactic_market_station
	show_sound = event_galactic_market
	is_triggered_only = yes

	immediate = {
		set_country_flag = has_market_access
		enable_galactic_market = yes
		enable_on_market = energy
		enable_on_market = minerals
		enable_on_market = food
		enable_on_market = consumer_goods
		enable_on_market = alloys
		if = {
			limit = {
				any_country = {
					is_galactic_community_member = yes
					resource_income_compare = {
						resource = volatile_motes
						value > 0
					}
				}
			}
			enable_on_market = volatile_motes
		}
		if = {
			limit = {
				any_country = {
					is_galactic_community_member = yes
					resource_income_compare = {
						resource = rare_crystals
						value > 0
					}
				}
			}
			enable_on_market = rare_crystals
		}
		if = {
			limit = {
				any_country = {
					is_galactic_community_member = yes
					resource_income_compare = {
						resource = exotic_gases
						value > 0
					}
				}
			}
			enable_on_market = exotic_gases
		}
		if = {
			limit = {
				any_country = {
					is_galactic_community_member = yes
					resource_income_compare = {
						resource = sr_dark_matter
						value > 0
					}
				}
			}
			enable_on_market = sr_dark_matter
		}
		if = {
			limit = {
				any_country = {
					is_galactic_community_member = yes
					resource_income_compare = {
						resource = sr_zro
						value > 0
					}
				}
			}
			enable_on_market = sr_zro
		}
		if = {
			limit = {
				any_country = {
					is_galactic_community_member = yes
					resource_income_compare = {
						resource = sr_living_metal
						value > 0
					}
				}
			}
			enable_on_market = sr_living_metal
		}
		add_modifier = {
			modifier = galactic_market_founder
			days = -1
		}
		set_market_leader = yes # Update who owns the market station

		set_timed_global_flag = { flag = resolution_galactic_market_relocated_recently days = 18000 }

		event_target:market_founder_planet.solar_system.star = {
			create_ambient_object = {
				type = galactic_market_station
				location = this
			}
			last_created_ambient_object = {
				save_global_event_target_as = galactic_market_station
				set_ambient_object_flag = galactic_market_station_flag
				set_location = {
					target = event_target:market_founder_planet.solar_system.star
					angle = random
					distance = 40
				}
			}
		}
		every_playable_country = {
			limit = {
				is_galactic_community_member = yes
				NOT = { is_same_value = root }
			}
			country_event = { id = action.101 }
		}
	}

	option = {
		name = OK
		custom_tooltip = established_galactic_market_station
		tooltip = {
			end_event_chain = market_founding_chain
			add_modifier = {
				modifier = galactic_market_founder
				days = -1
			}
		}
	}
}

# Market forms (notification to the wider community)
country_event = {
	id = action.101
	title = action.101.name
	desc = {
		text = action.101.desc
		trigger = {
			NOT = { is_xenophobe = yes }
		}
	}
	desc = {
		text = action.101.desc.phobe
		trigger = { is_xenophobe = yes }
	}
	picture = GFX_evt_financial_instruments
	location = event_target:galactic_market_station

	immediate = {
		set_country_flag = has_market_access
		enable_galactic_market = yes
		event_target:galactic_market_station.solar_system = {
			every_system_planet = {
				set_surveyed = {
					surveyed = yes
					surveyor = root
				}
			}
		}
	}

	is_triggered_only = yes

	option = {
		name = {
			trigger = {
				NOT = { has_valid_civic = civic_worker_coop }
			}
			text = OK
		}
		name = {
			trigger = {
				has_valid_civic = civic_worker_coop
			}
			text = UNDERSTOOD
		}
		tooltip = { end_event_chain = market_founding_chain }
	}
}

##############################################
# GALACTIC MARKET: FORCED RELOCATION/TRANSFER
##############################################

# Market station lost, is conquered or moved
# via on_system_lost | this = system's former owner; from = system; fromfrom = new system owner
country_event = {
	id = action.102
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = event_target:galactic_market_station
		from = {
			any_system_ambient_object = {
				is_same_value = event_target:galactic_market_station
			}
		}
	}

	immediate = {
		# System either has no new owner, or an owner who's homicidal or not a GalCom member
		if = {
			limit = {
				OR = {
					NOT = { exists = fromfrom }
					AND = {
						exists = fromfrom
						fromfrom = {
							OR = {
								is_homicidal = yes
								is_galactic_community_member = no
							}
						}
					}
				}
			}
			# Destroy old Galactic Market
			event_target:galactic_market_station = {
				destroy_ambient_object = this
			}
			clear_global_event_target = galactic_market_station
			clear_global_event_target = market_founder_planet
			remove_modifier = galactic_market_founder
			# Transfer to a contact
			random_playable_country = {
				limit = {
					is_homicidal = no
					is_galactic_community_member = yes
				}
				weights = {
					base = 1
					modifier = {
						factor = 999
						has_communications = root
						has_country_flag = has_market_access
						has_country_flag = market_nomination_eligible # NOTE: this flag is set never removed, even if the contact leaves GalCom
					}
					modifier = {
						factor = 20
						capital_scope = {
							is_planet_class = pc_city
						}
					}
					modifier = {
						factor = 9
						is_megacorp = yes
					}
					modifier = {
						factor = 2
						#trade_income >= 120
					}
					modifier = {
						factor = 0.5
						#trade_income <= 50
					}
					modifier = {
						factor = 0.75
						has_ethic = ethic_gestalt_consciousness
					}
				}
				capital_scope = {
					create_ambient_object = {
						type = "galactic_market_station"
						location = this
					}
					save_global_event_target_as = market_founder_planet
					last_created_ambient_object = {
						save_global_event_target_as = galactic_market_station
						set_ambient_object_flag = galactic_market_station_flag
						set_location = {
							target = event_target:market_founder_planet.solar_system.star
							angle = random
							distance = 40
						}
					}
				}
				add_modifier = {
					modifier = galactic_market_founder
					days = -1
				}
				set_market_leader = yes
				country_event = { id = action.103 }
			}
			# Notification
			create_message = {
				type = MESSAGE_TYPE_LOST_MARKET_STATION
				localization = MESSAGE_LOST_MARKET_STATION
				days = 30
				target = root.from # Sets location marker
				variable = {
					type = name
					localization = SYSTEM
					scope = root.from
				}
			}
		}
		# System has a new owner who somehow lacks access to the Market
		else_if = {
			limit = {
				exists = fromfrom
				fromfrom = {
					is_country_type = default
					NOT = { has_country_flag = has_market_access }
				}
			}
			# Remove empire modifier
			remove_modifier = galactic_market_founder
			# Enable Market access (and host status) for the new owner
			fromfrom = {
				set_country_flag = has_market_access
				enable_galactic_market = yes
				add_modifier = {
					modifier = galactic_market_founder
					days = -1
				}
				set_market_leader = yes
			}
			# Notification
			create_message = {
				type = MESSAGE_TYPE_LOST_MARKET_STATION
				localization = MESSAGE_LOST_MARKET_STATION
				days = 30
				target = root.from # Sets location marker
				variable = {
					type = name
					localization = SYSTEM
					scope = root.from
				}
			}
		}
		# System has a new owner (non-homicidal, member of GalCom) who can take control of the Galactic Market
		else = {
			remove_modifier = galactic_market_founder
			fromfrom = {
				add_modifier = {
					modifier = galactic_market_founder
					days = -1
				}
				set_market_leader = yes
			}
			# Notification
			create_message = {
				type = MESSAGE_TYPE_LOST_MARKET_STATION
				localization = MESSAGE_LOST_MARKET_STATION
				days = 30
				target = root.from # Sets location marker
				variable = {
					type = name
					localization = SYSTEM
					scope = root.from
				}
			}
		}
	}
}

# Market station moved to our system
country_event = {
	id = action.103
	title = action.103.name
	desc = action.103.desc
	picture = GFX_evt_financial_instruments
	location = event_target:galactic_market_station

	is_triggered_only = yes

	option = {
		name = OK
		custom_tooltip = established_galactic_market_station
		tooltip = {
			add_modifier = {
				modifier = galactic_market_founder
				days = -1
			}
		}
	}
}

# Catch non-standard comms ending up outside the Market, on yearly pulse
event = {
	id = action.105
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_global_flag = galactic_market_founded
		any_playable_country = {
			is_homicidal = no
			NOT = { has_country_flag = has_market_access }
		}
	}

	immediate = {
		every_playable_country = {
			limit = {
				is_homicidal = no
				is_galactic_community_member = yes
				NOT = { has_country_flag = has_market_access }
				any_playable_country = {
					has_communications = prev
					has_country_flag = has_market_access
				}
			}
			country_event = { id = action.115 random = 40 }
		}
	}
}

# via on_post_communications_established = {}
country_event = {
	id = action.110
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = default
		from = { is_country_type = default }
		OR = {
			AND = {
				is_galactic_community_member = yes
				from = {
					is_galactic_community_member = no
					NOT = { has_country_flag = galcom_form_nay }
				}
			}
			AND = {
				NOT = { has_country_flag = galcom_form_nay }
				is_galactic_community_member = no
				from = { is_galactic_community_member = yes }
			}
		}
	}

	immediate = {
		if = {
			limit = {
				NOT = { has_country_flag = galcom_form_nay }
				is_galactic_community_member = no
				from = { is_galactic_community_member = yes }
			}
			country_event = { id = galcom.16 days = 15 }
		}
		else_if = {
			limit = {
				is_galactic_community_member = yes
				from = {
					is_galactic_community_member = no
					NOT = { has_country_flag = galcom_form_nay }
				}
			}
			from = { country_event = { id = galcom.16 days = 15 } }
		}
	}
}

# Enable market when having comms with market participant
country_event = {
	id = action.115
	title = action.106.name
	desc = {
		text = action.106.desc
		trigger = { is_xenophobe = no }
	}
	desc = {
		text = action.106.desc.phobe
		trigger = { is_xenophobe = yes }
	}
	picture = GFX_evt_financial_instruments
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = has_market_access }
	}

	immediate = {
		enable_galactic_market = yes
		set_country_flag = has_market_access
	}

	option = {
		name = OK
	}
}

# Enable resources for Galactic Market
event = {
	id = action.116
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_global_flag = galactic_market_founded

		OR = {
			NOT = { is_on_market = volatile_motes }
			NOT = { is_on_market = exotic_gases }
			NOT = { is_on_market = rare_crystals }
			NOT = { is_on_market = sr_living_metal }
			NOT = { is_on_market = sr_zro }
			NOT = { is_on_market = sr_dark_matter }
		}
	}

	immediate = {
		if = {
			limit = {
				NOT = { is_on_market = volatile_motes }
				any_playable_country = {
					is_galactic_community_member = yes
					resource_stockpile_compare = { resource = volatile_motes value >= 1 }
				}
			}
			enable_on_market = volatile_motes
		}
		else_if = {
			limit = {
				NOT = { is_on_market = exotic_gases }
				any_playable_country = {
					is_galactic_community_member = yes
					resource_stockpile_compare = { resource = exotic_gases value >= 1 }
				}
			}
			enable_on_market = exotic_gases
		}
		else_if = {
			limit = {
				NOT = { is_on_market = rare_crystals }
				any_playable_country = {
					is_galactic_community_member = yes
					resource_stockpile_compare = { resource = rare_crystals value >= 1 }
				}
			}
			enable_on_market = rare_crystals
		}
		else_if = {
			limit = {
				NOT = { is_on_market = sr_living_metal }
				any_playable_country = {
					is_galactic_community_member = yes
					resource_stockpile_compare = { resource = sr_living_metal value >= 1 }
				}
			}
			enable_on_market = sr_living_metal
		}
		else_if = {
			limit = {
				NOT = { is_on_market = sr_zro }
				any_playable_country = {
					is_galactic_community_member = yes
					resource_stockpile_compare = { resource = sr_zro value >= 1 }
				}
			}
			enable_on_market = sr_zro
		}
		else_if = {
			limit = {
				NOT = { is_on_market = sr_dark_matter }
				any_playable_country = {
					is_galactic_community_member = yes
					resource_stockpile_compare = { resource = sr_dark_matter value >= 1 }
				}
			}
			enable_on_market = sr_dark_matter
		}
	}
}

#########################
# ASSORTED NOTIFICATIONS
#########################

# Megastructure completed notification for contacts
country_event = {
	id = action.120
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		from = {
			OR = {
				is_megastructure_type = dyson_sphere_5
				is_megastructure_type = dyson_sphere_restored
				is_megastructure_type = spy_orb_4
				is_megastructure_type = spy_orb_restored
				is_megastructure_type = think_tank_3
				is_megastructure_type = think_tank_restored
				is_megastructure_type = gateway_final
				is_megastructure_type = gateway_restored
				is_megastructure_type = matter_decompressor_4
				is_megastructure_type = strategic_coordination_center_3
				is_megastructure_type = mega_art_installation_3
				is_megastructure_type = interstellar_assembly_4
			}
		}
	}

	immediate = {
		if = {
			limit = {
				has_country_flag = did_not_repair_gateway
				from = {
					OR = {
						is_megastructure_type = gateway_final
						is_megastructure_type = gateway_restored
					}
				}
			}
			remove_country_flag = did_not_repair_gateway
		}
		else = {
			every_relation = {
				limit = {
					is_country_type = default
					OR = {
						has_intel_level = {
							who = root
							category = economy
							level >= 1
						}
						has_intel_level = {
							who = root
							category = technology
							level >= 1
						}
					}
				}
				create_message = {
					type = ALIEN_MEGASTRUCTURE_BUILT
					localization = MESSAGE_ALIEN_MEGASTRUCTURE_BUILT
					days = 30
					target = fromfrom #Go to system since you might not have enough intel for the megastructure
					variable = {
						type = name
						localization = COUNTRY
						scope = root
					}
					variable = {
						type = name
						localization = MEGASTRUCTURE
						scope = root.from
					}
					variable = {
						type = name
						localization = SYSTEM
						scope = root.fromfrom
					}
				}
			}
		}
	}
}

# Pop Abducted
pop_group_event = {
	id = action.121
	title = OK
	desc = OK

	hide_window = yes
	is_triggered_only = yes

	trigger = {
		from = { NOT = { has_carrier_flag = recently_raided } } #So that you will not have multiples of the same notification pending
	}

	immediate = {
		from = {
			set_timed_carrier_flag = {
				flag = recently_raided
				months = 6
			}
		}
		create_message = {
			type = MESSAGE_TYPE_POP_ABDUCTED
			localization = MESSAGE_POP_ABDUCTED
			days = 30
			target = from
			variable = {
				type = name
				localization = SPECIES
				scope = root.species
			}
			variable = {
				type = name
				localization = TARGET_PLANET
				scope = root.planet
			}
			variable = {
				type = name
				localization = PLANET
				scope = from
			}
		}
		if = {
			limit = {
				exists = from.owner
			}
			from.owner = {
				create_message = {
					type = MESSAGE_TYPE_POP_ABDUCTED_FROM_US
					localization = MESSAGE_POP_ABDUCTED_FROM_US
					days = 30
					target = from
					variable = {
						type = name
						localization = SPECIES
						scope = root.species
					}
					variable = {
						type = name
						localization = ABDUCTER
						scope = root.planet.owner
					}
					variable = {
						type = name
						localization = PLANET
						scope = from
					}
				}
			}
		}
	}
}

# Last Primitive Pop Abducted (HIDDEN)
pop_group_event = {
	id = action.122
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		from = { pop_amount = 0 }
	}

	immediate = {
		from = {
			if = {
				limit = { has_observation_outpost = yes }
				observation_outpost = {
					owner = {
						save_event_target_as = obsv_post_owner
						country_event = { id = action.123 }
					}
					dismantle = yes
				}
			}
		}
		owner = {
			if = {
				limit = {
					OR = {
						NOT = { exists = event_target:obsv_post_owner }
						NOT = { is_same_value = event_target:obsv_post_owner }
					}
				}
				save_event_target_as = abductor
				country_event = { id = action.123 }
			}
		}
		from = {
			solar_system = {
				if = {
					limit = { exists = space_owner }
					space_owner = {
						if = {
							limit = {
								NOT = { is_same_value = event_target:abductor }
								OR = {
									NOT = { exists = event_target:obsv_post_owner }
									NOT = { is_same_value = event_target:obsv_post_owner }
								}
							}
							country_event = { id = action.123 }
						}
					}
				}
			}
		}
	}
}

# Last Primitive Pop Abducted
country_event = {
	id = action.123
	title = "action.123.name"
	desc = "action.123.desc"
	picture = GFX_evt_surrender
	show_sound = event_screams
	location = fromfrom

	is_triggered_only = yes

	option = {
		trigger = {
			NOT = {
				from = {
					owner = { is_same_value = root }
				}
			}
		}
		name = DISCONCERTING
	}
	option = {
		trigger = {
			from = {
				owner = { is_same_value = root }
			}
		}
		name = action.123.a
	}
}

# Won War (Imperial Crusade)
country_event = {
	id = action.150
	title = action.37.name
	message_desc = action.37.message

	desc = {
		trigger = { is_gestalt = no }
		text = action.150.1.desc
		text = action.150.2.desc
		text = action.150.3.desc
	}
	desc = {
		trigger = { is_gestalt = yes }
		text = action.150.gestalt.1.desc
	}

	picture_event_data = {
		portrait = FROM
		planet_background = FROM
		graphical_culture = FROM
		city_level = FROM
		room = FROM.ruler
	}

	diplomatic = yes
	is_triggered_only = yes

	trigger = {
		is_ai = no
		fromfrom = {
			using_war_goal = {
				type = wg_imperial_crusade
				owner = root
			}
		}
	}

	option = {
		name = action.37.a
	}
}

# Lost War (Imperial Crusade)
country_event = {
	id = action.151
	title = action.38.name
	message_desc = action.38.message

	desc = {
		text = action.151.1.desc
		text = action.151.2.desc
		text = action.151.3.desc
	}

	picture_event_data = {
		portrait = FROM
		planet_background = FROM
		graphical_culture = FROM
		city_level = FROM
		room = FROM.ruler
	}

	diplomatic = yes
	is_triggered_only = yes

	trigger = {
		is_ai = no
		fromfrom = {
			using_war_goal = {
				type = wg_imperial_crusade
				owner = root.from
			}
		}
	}

	option = {
		name = action.38.a
	}
}

# Loyalists Won Civil War (Emperor)
country_event = {
	id = action.152
	title = action.37.name
	message_desc = action.37.message

	desc = {
		trigger = { is_gestalt = no }
		text = action.152.1.desc
		text = action.152.2.desc
		text = action.152.3.desc
	}
	desc = {
		trigger = { is_gestalt = yes }
		text = action.152.gestalt.1.desc
	}

	picture_event_data = {
		portrait = FROM
		planet_background = FROM
		graphical_culture = FROM
		city_level = FROM
		room = FROM.ruler
	}

	diplomatic = yes
	is_triggered_only = yes

	trigger = {
		is_ai = no
		fromfrom = {
			using_war_goal = {
				type = wg_galactic_civil_war_loyalists
				owner = root
			}
		}
	}

	option = {
		name = action.37.a
	}
}

# Loyalists Won Civil War (Rebels)
country_event = {
	id = action.153
	title = action.38.name
	message_desc = action.38.message

	desc = {
		trigger = { is_gestalt = no }
		text = action.153.1.desc
		text = action.153.2.desc
		text = action.153.3.desc
	}
	desc = {
		trigger = { is_gestalt = yes }
		text = action.153.gestalt.1.desc
	}

	picture_event_data = {
		portrait = FROM
		planet_background = FROM
		graphical_culture = FROM
		city_level = FROM
		room = FROM.ruler
	}

	diplomatic = yes
	is_triggered_only = yes

	trigger = {
		is_ai = no
		fromfrom = {
			using_war_goal = {
				type = wg_galactic_civil_war_loyalists
				owner = root.from
			}
		}
	}

	option = {
		name = action.38.a
	}
}

# Rebels Won Civil War (Rebels)
country_event = {
	id = action.154
	title = action.37.name
	message_desc = action.37.message

	desc = {
		trigger = { is_gestalt = no }
		text = action.154.1.desc
		text = action.154.2.desc
		text = action.154.3.desc
	}
	desc = {
		trigger = { is_gestalt = yes }
		text = action.154.gestalt.1.desc
	}

	picture_event_data = {
		portrait = FROM
		planet_background = FROM
		graphical_culture = FROM
		city_level = FROM
		room = FROM.ruler
	}

	diplomatic = yes
	is_triggered_only = yes

	trigger = {
		is_ai = no
		fromfrom = {
			using_war_goal = {
				type = wg_galactic_civil_war_rebels
				owner = root
			}
		}
	}

	option = {
		name = action.37.a
	}
}

# Rebels Won Civil War & Dissolve Empire (Emperor)
country_event = {
	id = action.155
	title = action.38.name
	message_desc = action.38.message

	desc = {
		trigger = { is_gestalt = no }
		text = action.155.1.desc
		text = action.155.2.desc
		text = action.155.3.desc
	}
	desc = {
		trigger = { is_gestalt = yes }
		text = action.155.gestalt.1.desc
	}

	picture_event_data = {
		portrait = FROM
		planet_background = FROM
		graphical_culture = FROM
		city_level = FROM
		room = FROM.ruler
	}

	diplomatic = yes
	is_triggered_only = yes

	trigger = {
		is_ai = no
		fromfrom = {
			OR = {
				using_war_goal = {
					type = wg_galactic_civil_war_rebels
					owner = root.from
				}
				using_war_goal = {
					type = wg_restore_the_community
					owner = root.from
				}
			}
		}
	}

	option = {
		name = action.38.a
	}
}

## Seize Throne (Usurper)
#country_event = {
#	id = action.156
#	title = action.37.name
#	message_desc = action.37.message
#
#	desc = {
#		trigger = { is_gestalt = no }
#		text = action.156.1.desc
#		text = action.156.2.desc
#		text = action.156.3.desc
#	}
#	desc = {
#		trigger = { is_gestalt = yes }
#		text = action.156.gestalt.1.desc
#	}
#
#	picture_event_data = {
#		portrait = FROM
#		planet_background = FROM
#		graphical_culture = FROM
#		city_level = FROM
#		room = FROM.ruler
#	}
#
#	diplomatic = yes
#	is_triggered_only = yes
#
#	trigger = {
#		is_ai = no
#		fromfrom = {
#			using_war_goal = {
#				type = wg_seize_imperial_throne
#				owner = root
#			}
#		}
#	}
#
#	option = {
#		name = action.37.a
#	}
#}
#
## Seize Throne (Former Emperor)
#country_event = {
#	id = action.157
#	title = action.38.name
#	message_desc = action.38.message
#
#	desc = {
#		trigger = { is_gestalt = no }
#		text = action.157.1.desc
#		text = action.157.2.desc
#		text = action.157.3.desc
#	}
#	desc = {
#		trigger = { is_gestalt = yes }
#		text = action.157.gestalt.1.desc
#	}
#
#	picture_event_data = {
#		portrait = FROM
#		planet_background = FROM
#		graphical_culture = FROM
#		city_level = FROM
#		room = FROM.ruler
#	}
#
#	diplomatic = yes
#	is_triggered_only = yes
#
#	trigger = {
#		is_ai = no
#		fromfrom = {
#			using_war_goal = {
#				type = wg_seize_imperial_throne
#				owner = root.from
#			}
#		}
#	}
#
#	option = {
#		name = action.38.a
#	}
#}

# Dissolve Empire (Dissolver)
country_event = {
	id = action.158
	title = action.37.name
	message_desc = action.37.message

	desc = {
		trigger = { is_gestalt = no }
		text = action.158.1.desc
		text = action.158.2.desc
		text = action.158.3.desc
	}
	desc = {
		trigger = { is_gestalt = yes }
		text = action.158.gestalt.1.desc
	}

	picture_event_data = {
		portrait = FROM
		planet_background = FROM
		graphical_culture = FROM
		city_level = FROM
		room = FROM.ruler
	}

	diplomatic = yes
	is_triggered_only = yes

	trigger = {
		is_ai = no
		fromfrom = {
			using_war_goal = {
				type = wg_restore_the_community
				owner = root
			}
		}
	}

	option = {
		name = action.37.a
	}
}



# Recalculate strategic data for attack/defense ( chokepoints etc. )
country_event = {
	id = action.200
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		from = { #So you don't have to survey a system you just lost again
			set_surveyed = {
				surveyor = root
				surveyed = yes
			}
		}
		run_ai_strategic_war_data = yes
	}
}

# Left a federation
country_event = {
	id = action.201
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		from = {
			set_country_flag = whatever_it_is_im_against_it_left_federation
		}
	}
}

# Hegemony Member's Request to Leave was Rejected
country_event = {
	id = action.205
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		set_timed_country_flag = {
			flag = asked_to_leave_hegemony
			days = 3600
		}
		add_opinion_modifier = {
			who = from
			modifier = opinion_denied_to_leave_hegemony
		}
		from = {
			add_opinion_modifier = {
				who = root
				modifier = opinion_wanted_to_leave_hegemony
			}
		}
	}
}

# Federation On Subjects Can Join Law Change
country_event = {
	id = action.212
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		federation = {
			any_member = {
				is_overlord = yes
				any_subject = {
					NOT = { is_in_federation_with = prev }
				}
			}
		}
	}

	immediate = {
		federation = {
			every_member = {
				limit = {
					is_overlord = yes
					any_subject = {
						NOT = { is_in_federation_with = prev }
					}
				}
				every_subject = {
					limit = {
						NOT = { is_in_federation_with = prev }
					}
					join_alliance = { who = root override_requirements = yes }
				}
			}
		}
	}
}

# Federation On Subjects Can NOT Join Law Change
country_event = {
	id = action.213
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		federation = {
			any_member = {
				is_overlord = yes
				any_subject = { is_in_federation_with = prev }
			}
		}
	}

	immediate = {
		federation = {
			every_member = {
				limit = {
					is_overlord = yes
					any_subject = { is_in_federation_with = prev }
				}
				every_subject = {
					limit = { is_in_federation_with = prev }
					leave_alliance = { override_requirements = yes }
				}
			}
		}
	}
}

# Federation Member Gains Subject
country_event = {
	id = action.214
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		NOT = { is_country_type = champions_forge_contestant }
		from = {
			has_federation = yes
			federation = { has_federation_law = allow_subjects_to_join_yes }
		}
	}

	immediate = {
		join_alliance = { who = from override_requirements = yes }
	}
}

# Federation Clear Outside Treaties
country_event = {
	id = action.215
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		every_country = {
			limit = {
				has_communications = root
				NOT = { is_in_federation_with = root }
			}
			end_all_treaties_with = root
			root = {
				end_all_treaties_with = prev
			}
		}
	}
}

# Random pulse (set up the delay) - on_five_year_pulse_country
country_event = {
	id = action.220
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		country_event = { id = action.221 random = 360 }
	}
}

# Random pulse part 2 (fire the on action) - on_five_year_pulse_country
country_event = {
	id = action.221
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		fire_on_action = { on_action = on_five_year_random_pulse_country }
	}
}

# Random pulse for communication spread (set up the delay) - on_five_year_pulse_country
country_event = {
	id = action.250
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		country_event = { id = action.251 random = 360 }
	}
}

# Random pulse for communication spread part 2 (fire the on action) - on_five_year_pulse_country
country_event = {
	id = action.251
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		fire_on_action = { on_action = on_five_years_communication_spread_country }
	}
}

# Random pulse part 3 (fire the on action for negative events) - on_five_year_random_pulse_country
country_event = {
	id = action.2211
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		fire_on_action = { on_action = on_five_year_random_pulse_country_negative_list }
	}
}

# Random pulse part 4 - null effect event if fired via espionage operation
country_event = {
	id = action.2212
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		OR = {
			NOT = { exists = from }
			from = {
				NOT = { is_scope_type = espionage_operation }
			}
		}
	}
}


# Random pulse part 3 (fire the on action for Fallen Empire events) - on_five_year_random_pulse_country
country_event = {
	id = action.2213
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		fire_on_action = { on_action = on_five_year_random_pulse_country_fe_list }
	}
}

# on_colony_5_year_pulse
carrier_event = {
	id = action.222
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		if = { #save the AI from doomsday if it manages to colonise
			limit = {
				exists = owner
				owner = {
					has_origin = origin_doomsday
					is_ai = yes
					any_owned_planet = {
						has_carrier_flag = doomed_planet_origin
					}
				}
				NOT = { has_carrier_flag = doomed_planet_origin }
			}
			owner = {
				random_owned_planet = {
					limit = {
						has_carrier_flag = doomed_planet_origin
						pop_amount > 300
					}
					while = {
						count = 3
						random_owned_pop_group = {
							limit = {
								OR = {
									prev = { has_modifier = doomsday_5 }
									root = {
										habitability = {
											who = prev.species
											value > 0.3
										}
									}
								}
							}
							resettle_pop_group = {
								POP_GROUP = this
								PLANET = root
								AMOUNT = 100
							}
						}
					}
				}
			}
		}
	}
}


# Called when a Starbase changes owner
# THIS = Ship (Starbase)
# FROM = Former Owner (Country)
ship_event = {
	id = action.223
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		exists = starbase
	}

	immediate = {
		starbase = {
			if = {
				limit = {
					owner = {
						is_gestalt = yes
					}
				}
				remove_starbase_building = {
					building = offworld_trading_company
				}
				remove_starbase_module = {
					module = trading_hub
				}
			}
		}
	}
}

# This = starbase being destroyed
# From = fleet that destroyed the starbase
starbase_event = {
	id = action.225
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		if = {
			limit = { exists = root.owner }
			solar_system = {
				set_surveyed = {
					surveyed = yes
					surveyor = root.owner
				}
			}
		}
		solar_system = {
			set_surveyed = {
				surveyed = yes
				surveyor = from.owner
			}
		}
		#remove leftovers
		solar_system = {
			every_fleet_in_system = {
				limit = {
					is_owned_by = root.owner
					OR = {
						is_ship_size = mining_station
						is_ship_size = research_station
						is_ship_size = observation_station
					}
				}
				destroy_fleet = this
			}
		}
		if = {
			limit = {
				is_orbital_ring = yes
				exists = planet
				planet = {
					NOT = {
						has_planet_flag = ruined_orbital_ring_planet
					}
				}
			}
			planet = {
				set_planet_flag = ruined_orbital_ring_planet
				remove_planet_flag = has_megastructure
				save_event_target_as = ruined_orbital_ring_planet
			}
			solar_system = {
				spawn_megastructure = {
					type = "orbital_ring_ruined"
					planet = event_target:ruined_orbital_ring_planet

					init_effect = {
						if = {
							limit = {
								exists = prev.owner
							}
							set_owner = prev.owner
						}
						create_ambient_object = {
							type = "medium_debris_01_object"
							location = this
							use_3d_location = yes
						}
						last_created_ambient_object = {
							set_location = {
								target = prev
								distance = 8
								angle = 90
							}
						}
						create_ambient_object = {
							type = "medium_debris_02_object"
							location = this
							use_3d_location = yes
						}
						last_created_ambient_object = {
							set_location = {
								target = prev
								distance = 3
								angle = 270
							}
						}
					}
				}
			}
		}
	}
}

# From = system
# FromFrom = country (new owner)
# This = country (previous owner)
country_event = {
	id = action.226
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		NOT = { exists = from.owner }
	}

	immediate = {
		#remove leftovers
		from = {
			every_system_planet = {
				if = {
					limit = {
						has_mining_station = yes
					}
					mining_station = { delete_fleet = this }
				}
				if = {
					limit = {
						has_research_station = yes
					}
					research_station = { delete_fleet = this }
				}
				if = {
					limit = {
						has_observation_outpost = yes
					}
					observation_outpost = { delete_fleet = this }
				}
			}
		}
	}
}



# on_released_as_vassal
# This = released vassal
# From = overlord
country_event = {
	id = action.229
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		set_origin_effect = { SOURCE_COUNTRY = from }
		if = {
			limit = {
				has_civic = civic_galactic_sovereign
			}
			force_remove_civic = civic_galactic_sovereign
		}
		if = {
			limit = {
				has_civic = civic_galactic_sovereign_megacorp
			}
			force_remove_civic = civic_galactic_sovereign_megacorp
		}
		if = {
			limit = {
				has_civic = civic_psionic_sovereign
			}
			force_remove_civic = civic_psionic_sovereign
		}
		if = {
			limit = {
				has_civic = civic_pompous_purists
			}
			force_remove_civic = civic_pompous_purists
			change_government = {
				cooldown = no
				civics = { civic = random }
			}
		}
		if = {
			limit = {
				has_civic = civic_great_khans_vision
			}
			force_remove_civic = civic_great_khans_vision
		}
		# Overlord has 90 Intel on released sectors
		from = {
			add_intel = {
				who = root
				amount = 80
			}
		}
	}
}

# Convert sectors released as subjects by megacorps into oligarchies
country_event = {
	id = action.230
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_megacorp = yes
		from = { is_megacorp = yes }
	}

	immediate = {
		set_merchant_government_effect = yes
	}
}

# If Overlord has a governement swap, so should the subject
country_event = {
	id = action.231
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		from = {
			OR = {
				has_country_flag = cyber_creed_advanced_government
				has_country_flag = cyber_individualist
				has_country_flag = cyber_collectivist
				has_country_flag = synth_physical
				has_country_flag = synth_virtual
				has_country_flag = cyber_hive_volitional
				has_country_flag = cyber_hive_integrated
				has_country_flag = driven_memory_aggregator
				has_country_flag = driven_neural_chorus
			}
		}
	}

	immediate = {
		set_subject_advanced_authority = yes
	}
}

# Via 'on_decade_pulse_country'
# Event for error-logging broken communications: flagging empires which have met each other, but failed to established communications nor are engaged in first contact.
country_event = {
	id = action.240
	is_triggered_only = yes
	hide_window = yes

	immediate = {
		if = {
			limit = {
				is_country_type = default
			}
			every_country = {
				limit = {
					NOR = {
						is_same_value = root
						has_communications = root
						has_country_flag = suppress_first_contact_comms # i.e. The Shroud
						is_primitive = yes
					}
					root = {
						has_established_contact = prev
						NOR = {
							has_active_first_contact_with = prev
							has_relation_flag = {
								who = prev
								flag = has_logged_first_contact_error
							}
							has_relation_flag = {
								who = prev
								flag = just_encountered
							}
						}
						# The following triggers should match game rule 'can_have_first_contact'
						if = {
							limit = { prev = { is_amoeba_country_type = yes } }
							NOT = {
								any_active_first_contact = {
									contact_country = { is_amoeba_country_type = yes }
								}
							}
						}
						else_if = {
							limit = { prev = { is_tiyanki_country_type = yes } }
							NOT = {
								any_active_first_contact = {
									contact_country = { is_tiyanki_country_type = yes }
								}
							}
						}
						else_if = {
							limit = { prev = { is_crystal_country_type = yes } }
							NOT = {
								any_active_first_contact = {
									contact_country = { is_crystal_country_type = yes }
								}
							}
						}
						else_if = {
							limit = { prev = { is_drone_country_type = yes } }
							NOT = {
								any_active_first_contact = {
									contact_country = { is_drone_country_type = yes }
								}
							}
						}
						else_if = {
							limit = { prev = { is_country_type = cloud } }
							NOT = {
								any_active_first_contact = {
									contact_country = { is_country_type = cloud }
								}
							}
						}
						else_if = {
							limit = {
								prev = {
									OR = {
										is_country_type = caravaneer_fleet
										is_country_type = caravaneer_home
									}
								}
							}
							NOT = {
								any_active_first_contact = {
									contact_country = {
										OR = {
											is_country_type = caravaneer_fleet
											is_country_type = caravaneer_home
										}
									}
								}
							}
						}
						else_if = {
							limit = {
								prev = { is_country_type = dragon_dummy }
							}
							has_origin = origin_here_be_dragons
							prev = { has_country_flag = dragon_of@root }
						}
						else_if = {
							limit = {
								prev = { is_country_type = jaunting_traveler_dummy }
							}
							prev = { has_country_flag = jaunting_traveler_of@root }
						}
					}
				}
				#log_error = "[Root.GetRealName] has encountered [This.GetRealName] (country type: [This.GetCountryType]) but has neither communications with them nor an active First Contact site to do so."
				root = {
					set_relation_flag = {
						who = prev
						flag = has_logged_first_contact_error
					}
					establish_communications_no_message = prev
				}
			}
		}
	}
}

system_event = {
	id=action.301
	is_triggered_only=yes
	hide_window=yes
	immediate = {
		every_system_megastructure = {
			limit = {
				OR = {
					is_megastructure_type = gateway_ruined
					is_megastructure_type = gateway_restored
					is_megastructure_type = gateway_final
					is_megastructure_type = hyper_relay_ruined
					is_megastructure_type = hyper_relay_restored
					is_megastructure_type = hyper_relay
				}
			}
			set_owner = FROM
		}
	}
}

system_event = {
	id=action.300
	is_triggered_only=yes
	hide_window=yes
	immediate = {
		every_system_megastructure = {
			limit = {
				OR = {
					is_megastructure_type = gateway_ruined
					is_megastructure_type = gateway_restored
					is_megastructure_type = gateway_final
					is_megastructure_type = hyper_relay_ruined
					is_megastructure_type = hyper_relay_restored
					is_megastructure_type = hyper_relay
				}
			}
			set_owner = FROM
		}
	}
}


country_event = {
	id = action.310
	is_triggered_only = yes
	hide_window = yes
	trigger = {
		NOT = {
			federation = {
				any_member = {
					is_fallen_empire = yes
				}
			}
		}
	}
	immediate = {
		federation = {
			every_member = {
				create_message = {
					type = MESSAGE_NEW_FEDERATION_PRESIDENT_CHOSEN
					localization = NEW_FEDERATION_PRESIDENT_CHOSEN
					days = 60
					target = root.federation
					variable = {
						type = name
						localization = PRESIDENT
						scope = root
					}
					variable = {
						type = name
						localization = FEDERATION
						scope = root.federation
					}
				}
			}
		}
	}
}

# on_country_released_in_war
# Root = new country
# From = country forcing the release
# FromFrom = country they are released from
# FromFromFrom = war
country_event = {
	id = action.320
	is_triggered_only = yes
	hide_window = yes

	immediate = {
		if = {
			limit = {
				has_civic = civic_galactic_sovereign
			}
			force_remove_civic = civic_galactic_sovereign
		}
		if = {
			limit = {
				has_civic = civic_galactic_sovereign_megacorp
			}
			force_remove_civic = civic_galactic_sovereign_megacorp
		}
		if = {
			limit = {
				has_civic = civic_psionic_sovereign
			}
			force_remove_civic = civic_psionic_sovereign
		}
	}
}

#on_monthly_pulse_country: give favours for envoys
country_event = {
	id = action.325
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		has_active_tradition = tr_diplomacy_eminent_diplomats
	}

	immediate = {
		every_envoy = {
			limit = {
				has_envoy_task = { task = improve_relations }
				root = {
					num_favors = {
						target = prev.envoy_location_country
						value < 10
					}
				}
			}
			random_list = {
				1 = {
					root = {
						add_favors = {
							target = prev.envoy_location_country
							value = 1
						}
						create_message = {
							type = MESSAGE_FAVOR_GAINED_TRADITION
							localization = MESSAGE_FAVOR_GAINED_TRADITION_DESC
							days = 30
							target = prev.envoy_location_country.capital_scope
							variable = {
								type = name
								localization = WHO
								scope = prev.envoy_location_country
							}
						}
					}
				}
				99 = {}
			}
		}
	}
}

#on_operation_cancelled: if you have the right tradition, they get some intel
espionage_operation_event = {
	id = action.330
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		exists = spynetwork.target
		spynetwork.target = {
			has_active_tradition = tr_subterfuge_double_agents
		}
	}

	immediate = {
		spynetwork.target = {
			add_intel = {
				who = root.owner
				amount = 10
			}
			create_message = {
				type = ESPIONAGE_INTEL_GAINED
				localization = ESPIONAGE_INTEL_GAINED_DESC
				variable = {
					type = name
					localization = COUNTRY
					scope = root.owner
				}
				days = 30
				target = root.owner.capital_scope
			}
		}
	}
}

# On research Societal Unification
country_event = {
	id = action.400
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		last_increased_tech = tech_planetary_unification
	}

	immediate = {
		add_monthly_resource_mult = {
			resource = unity
			value = @tier2unityreward
			min = @tier2unitymin
			max = @tier2unitymax
		}
	}
}

country_event = { # Random leader pool variations
	id = action.406
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		from = {
			random_list = {
				90 = { }
				10 = {
					add_trait = {
						trait = random_common
						show_message = no
					}
					add_trait = {
						trait = random_negative
						show_message = no
					}
					# Variable "leader_pending_negative_traits_unmodified" doesn't exist yet, can't reduce it yet. Checked now made in paragon_2.2200.
				}
			}
			random_list = {
				900 = { }
				75 = {
					add_skill_without_trait_selection = 1
					add_age = value:skill_scaled_age_increase|SKILL|1|
				}
				25 = {
					add_skill_without_trait_selection = 2
					add_age = value:skill_scaled_age_increase|SKILL|2|
				}
			}
		}

		# Additional effects from modifier
		from = { add_age = value:leader_recruitment_age|OWNER|root| }
	}
}

# Random pulse (set up the delay) - on_five_year_pulse_country - for overlords
country_event = {
	id = action.420
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_overlord = yes
	}

	immediate = {
		country_event = { id = action.421 random = 360 }
	}
}

# Random pulse part 2 (fire the on action) - on_five_year_pulse_country - for overlords
country_event = {
	id = action.421
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_overlord = yes
	}

	immediate = {
		fire_on_action = { on_action = on_five_year_random_pulse_overlord }
	}
}

#Yeet the Fleet achievement
fleet_event = {
	id = action.425
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		any_controlled_ship = {
			is_civilian = no
		}
		solar_system = {
			is_capital_system = yes
			space_owner = { is_at_war_with = root.owner }
		}
	}

	immediate = {
		owner = { set_country_flag = yeet_the_fleet_achievement }
	}
}

# Into the Unknown Achievement
fleet_event = {
	id = action.430
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		owner = { has_origin = origin_star_slingshot }
		any_controlled_ship = {
			is_ship_class = shipclass_science_ship
		}
		exists = leader
		solar_system = {
			NOT = { has_star_flag = into_the_unknown_flag_@root.owner }
			is_surveyed = {
				who = root.owner
				status = no
			}
		}
	}

	immediate = {
		solar_system = {
			set_star_flag = into_the_unknown_flag_@root.owner
		}
		owner = {
			change_variable = {
				which = into_the_unknown_counter
				value = 1
			}
			if = {
				limit = {
					check_variable = {
						which = into_the_unknown_counter
						value >= 10
					}
				}
				set_country_flag = into_the_unknown_achievement
			}
		}
	}
}

# This = agreement
# owner = overlord
# target = subject
# Fine Print achievement
agreement_event = {
	id = action.435
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		always = yes
	}

	immediate = {
		owner = { set_country_flag = fine_print_achievement }
		target = { set_country_flag = fine_print_achievement }
	}
}

# This = agreement
# owner = overlord
# target = subject
# Force Subjects to join GalCom, on Agreement Change.
agreement_event = {
	id = action.440
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		has_term_value = {
			term = subject_diplomacy
			value = subject_can_do_diplomacy_but_not_vote
		}
		owner = {
			is_galactic_community_member = yes
		}
		target = {
			is_galactic_community_member = no
		}
	}

	immediate = {
		target = {
			add_to_galactic_community = yes
		}
	}
}

# This = subject
# From = subject's overlord
# Force Subjects to join GalCom, on Subjugation
country_event = {
	id = action.441
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		from = {
			is_galactic_community_member = yes
		}
		this = {
			is_galactic_community_member = no
			any_agreement = {
				has_term_value = {
					term = subject_diplomacy
					value = subject_can_do_diplomacy_but_not_vote
				}
			}
		}
	}

	immediate = {
		add_to_galactic_community = yes
	}
}

# This = agreement
# owner = overlord
# target = subject
# Force Subjects to join Federation, on Agreement Change.
agreement_event = {
	id = action.442
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		has_term_value = {
			term = subject_diplomacy
			value = subject_can_do_diplomacy_but_not_vote
		}
		owner = {
			has_federation = yes
			federation = { has_federation_law = allow_subjects_to_join_yes }
		}
		target = {
			has_federation = no
		}
	}

	immediate = {
		target = {
			join_alliance = {
				who = this
				override_requirements = yes
			}
		}
	}
}

# This = agreement
# owner = overlord
# target = subject
# Force Subjects to join Federation, on Agreement Change.
agreement_event = {
	id = action.443
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		has_term_value = {
			term = subject_diplomacy
			value = subject_can_do_diplomacy_but_not_vote
		}
		owner = {
			has_federation = yes
			federation = { has_federation_law = allow_subjects_to_join_yes }
		}
		target = {
			has_federation = yes
			NOT = { is_in_federation_with = owner }
		}
	}

	immediate = {
		target = {
			leave_alliance = {
				override_requirements = yes
				apply_opinion_penalty = no
			}
			join_alliance = {
				who = this
				override_requirements = yes
			}
		}
	}
}

# Recalculate divided patronage on government reform if you have Feudal Society or Franchising.
country_event = {
	id = action.445
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		OR = {
			has_civic = civic_feudal_realm
			has_civic = civic_franchising
		}
	}

	immediate = {
		refresh_subject_count_loyalty_penalty = yes
	}
}

# Recalculate divided patronage on taking Shared Destiny AP.
country_event = {
	id = action.446
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		refresh_subject_count_loyalty_penalty = yes
	}
}

# This = agreement
# owner = overlord
# target = subject
agreement_event = {
	id = action.450
	hide_window = yes

	is_triggered_only = yes

	trigger = {
	}

	immediate = {
		target = { set_country_flag = specialistion_subject_conversion_flag }
	}
}

agreement_event = {
	id = action.451
	hide_window = yes

	is_triggered_only = yes

	trigger = {
	}

	immediate = {
		target = { remove_country_flag = specialistion_subject_conversion_flag }
	}
}

# On country created, set up Imperial Ruler
country_event = {
	id = action.501
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_imperial_authority = yes
	}

	immediate = {
		ruler? = {
			if = {
				limit = {
					NOT = { has_trait = trait_imperial_heir }
				}
				add_trait = {
					trait = trait_imperial_heir
					show_message = no
				}
			}

			set_variable_to_random_value = {
				which = ruler_age_mod
				min = 5
				max = 15
				rounded = yes
			}
			add_age = ruler_age_mod

			random_list = {
				95 = { }
				5 = {
					add_trait = {
						trait = random_common
						show_message = no
					}
					add_trait = {
						trait = random_negative
						show_message = no
					}
					# Variable "leader_pending_negative_traits_unmodified" doesn't exist yet, can't reduce it yet. Checked now made in paragon_2.2200.
					modifier = {
						factor = 0
						exists = owner
						owner = { has_valid_civic = civic_philosopher_king }
					}
				}
			}
		}
	}
}

# Remove Imperial Heir trait on changing away from Imperial authority.
country_event = {
	id = action.502
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		any_owned_leader = {
			has_trait = trait_imperial_heir
		}
		NOT = {
			is_imperial_authority = yes
		}
	}

	immediate = {
		every_owned_leader = {
			limit = {
				has_trait = trait_imperial_heir
			}
			remove_trait = trait_imperial_heir

			# Treasure Hunters origin - Adds the Adventurous Spirit trait
			if = {
				limit = {
					root = { has_origin = origin_treasure_hunters }
				}
				add_trait = {
					trait = leader_trait_adventurous_spirit_3
					show_message = no
				}
			}
		}
	}
}

# Strange Mood achievement
country_event = {
	id = action.460
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_crafter_empire = yes
		OR = {
			has_modifier = covenant_whisperers_in_the_void
			has_modifier = covenant_composer_of_strands
			has_modifier = covenant_instrument_of_desire
			has_modifier = covenant_eater_of_worlds
			has_modifier = covenant_end_of_the_cycle
			has_any_covenant = yes # Shroud DLC check
		}
		has_country_flag = has_built_or_repaired_megastructure
	}

	immediate = {
		set_country_flag = strange_mood_achievement
	}
}

# Directive 67 achievement
country_event = {
	id = action.465
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		has_country_flag = declared_crisis
		OR = {
			has_ai_personality = fallen_empire_spiritualist
			has_ai_personality = awakened_fallen_empire_spiritualist
		}

	}

	immediate = {
		from = {
			set_country_flag = directive_67_achievement
		}
	}
}

# Destroy People of Earth achievement
country_event = {
	id = action.470
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		has_country_flag = human_1
		from = {
			has_country_flag = human_2
			ruler = {
				has_trait = leader_trait_brainslug
				species = {
					is_human_species = yes
				}
			}
		}
	}

	immediate = {
		from = {
			set_country_flag = destroy_people_of_earth_achievement
		}
	}
}

# Fishing for Trouble
country_event = {
	id = action.475
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_anglers_empire = yes
		fromfrom = {
			OR = {
				using_war_goal = { type = wg_fe_humiliation				owner = attacker }
				using_war_goal = { type = wg_fe_stop_atrocities			owner = attacker }
				using_war_goal = { type = wg_fe_stop_ai					owner = attacker }
				using_war_goal = { type = wg_fe_cleanse_holy_worlds		owner = attacker }
				using_war_goal = { type = wg_fe_cleanse_border_worlds	owner = attacker }
			}
		}
	}

	immediate = {
		set_country_flag = fishing_for_trouble_achievement
	}
}

# Zombie on my Lawn
country_event = {
	id = action.480
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_country_type = default
		exists = from
		from = { is_country_type = default }
		OR = {
			# Either, they're plants and we're zombies
			AND = {
				is_species_class = PLANT
				from = { is_species_class = NECROID }
			}
			# or we're plants and they're zombies.
			AND = {
				is_species_class = NECROID
				from = { is_species_class = PLANT }
			}
		}
	}

	immediate = {
		from = { set_country_flag = zombie_on_my_lawn_achievement }
	}
}

# With Great Power Achievement
carrier_event = {
	id = action.485
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		from = { has_origin = origin_necrophage }
		this.owner = { is_primitive = yes }
	}

	immediate = {
		from = { set_country_flag = with_great_power_achievement_locked }
	}
}

# Could Be Worse Achievement
carrier_event = {
	id = action.490
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		exists = owner
		planet = { has_carrier_flag = toxic_terraforming_candidate }
		is_planet_class = pc_nuked
	}

	immediate = {
		owner = {
			set_country_flag = could_be_worse_achievement
		}
	}
}

# Tend the Garden Achievement
carrier_event = {
	id = action.495
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		exists = event_target:wenkwort_artem
		is_same_value = event_target:wenkwort_artem
	}

	immediate = {
		set_carrier_flag = disrupted_garden
	}
}

country_event = {
	id = action.500
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		from = {
			num_owned_relics > 0
		}
	}

	immediate = {
		if = {
			limit = {
				from = {
					has_relic = r_war_forge
				}
			}
			set_variable = {
				which = cybrex_count
				value = 1
			}
		}
		steal_relic = {
			target = from
			relic = all
		}
		create_message = {
			type = MESSAGE_TYPE_RELICS_GAINED_INTEGRATION
			localization = MESSAGE_RELICS_GAINED_INTEGRATION
			days = 30
			target = root
		}
	}
}

carrier_event = {
	id = action.601

	show_sound = event_default
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		exists = owner
		NOT = {
			has_planet_flag = biomechanical_world
		}
		owner = {
			is_homicidal = no
			is_gestalt = no
			is_primitive = no
		}
		from = {
			not = { has_country_flag = picked_orbital_bombardment_policy_flag }
			is_ai = no
			is_gestalt = no
			is_homicidal = no #locked to "forbidden"
			is_crisis_faction = no
			can_change_policy = orbital_bombardment_accept_surrender #player has already made their own choice, no need to draw attention to this
		}
	}

	immediate = {
		from = { set_country_flag = picked_orbital_bombardment_policy_flag }
		from = { country_event = { id = action.600 } }
	}
}

country_event = {
	id = action.600
	title = action.600.name

	desc = {
		text = action.600.desc
	}

	picture = GFX_evt_board_meeting
	show_sound = event_default
	hide_window = no

	is_triggered_only = yes

	option = {
		name = action.600.A
		allow = {
			can_set_policy = {
				policy = orbital_bombardment_accept_surrender
				option = orbital_bombardment_surrender_forbidden
			}
		}

		set_policy = {
			policy = orbital_bombardment_accept_surrender
			option = orbital_bombardment_surrender_forbidden
			cooldown = yes
		}
	}

	option = {
		name = action.600.B
		allow = {
			can_set_policy = {
				policy = orbital_bombardment_accept_surrender
				option = orbital_bombardment_surrender_allowed
			}
		}
		set_policy = {
			policy = orbital_bombardment_accept_surrender
			option = orbital_bombardment_surrender_allowed
			cooldown = yes
		}
	}
}

# A planet has been rendered ownerless, it has an orbital ring or similar, though. The orbital ring is still there, but is about to be deleted
# this = starbase
# from = planet
# fromfrom = old owner
starbase_event = {
	id = action.503
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		is_orbital_ring = yes
	}

	immediate = {
		from = {
			solar_system = {
				spawn_megastructure = {
					type = orbital_ring_ruined
					planet = prev
				}
			}
			set_planet_flag = ruined_orbital_ring_planet
		}
	}
}

# Random pulse (set up the delay) - on_five_year_pulse_country - for pre-ftl diplo events
country_event = {
	id = action.620
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_country_type = default
		has_first_contact_dlc = yes
		has_any_active_pre_ftl_agreement = yes
	}

	immediate = {
		country_event = { id = action.621 random = 360 }
	}
}

# Random pulse part 2 (fire the on action) - on_five_year_pulse_country - for pre-ftl diplo events
country_event = {
	id = action.621
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_country_type = default
		has_first_contact_dlc = yes
		has_any_active_pre_ftl_agreement = yes
	}

	immediate = {
		fire_on_action = { on_action = on_five_year_random_pulse_pre_ftl }
	}
}

# Random pulse (set up the delay) - on_five_year_pulse_country - for pre-ftl tech events
country_event = {
	id = action.630
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_country_type = default
		has_pre_ftl_recent_tech_development = yes
	}

	immediate = {
		country_event = { id = action.631 random = 360 }
	}
}

# Random pulse part 2 (fire the on action) - on_five_year_pulse_country - for pre-ftl tech events
country_event = {
	id = action.631
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_country_type = default
		has_pre_ftl_recent_tech_development = yes
	}

	immediate = {
		fire_on_action = { on_action = on_five_year_random_pulse_pre_ftl_tech_events }
	}
}

# Random pulse (set up the delay) - on_bi_yearly_pulse_country - for Payback and Broken Shackles interactions
country_event = {
	id = action.632
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_country_type = default
		has_origin = origin_payback
		any_playable_country = {
			has_origin = origin_broken_shackles
			has_country_flag = broken_shackles_recognized_payback@root
			has_communications = prev
		}
	}

	immediate = {
		country_event = { id = action.633 random = 30 }
	}
}

# Random pulse (fire the on action) - on_five_year_pulse_country - for Payback and Broken Shackles interactions
country_event = {
	id = action.633
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_country_type = default
		has_origin = origin_payback
		any_playable_country = {
			has_origin = origin_broken_shackles
			has_country_flag = broken_shackles_recognized_payback@root
			has_communications = prev
		}
	}

	immediate = {
		fire_on_action = { on_action = on_decade_random_pulse_country_payback_broken_shackles }
	}
}

# Contact report follow-up (fire the on action) - on_first_contact_started
first_contact_event = {
	id = action.635
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		owner = {
			is_country_type = default
			NOT = { has_country_flag = Story7 }
		}
		contact_country = {
			NOR = {
				has_country_flag = radical_cult
				is_country_type = fallen_empire
				is_country_type = awakened_fallen_empire
				is_country_type = primitive
				is_guardian_country = yes
				has_relation_flag = { flag = no_coms who = owner }
				has_relation_flag = { flag = AbandonedRefugees who = owner }
				has_relation_flag = { flag = pirate_relation who = owner }
				has_country_flag = day_0
			}
		}
	}

	immediate = {
		contact_country = {
			save_event_target_as = contact_country
		}
		owner = {
			country_event = { id = story.7 days = 1 scopes = { from = event_target:contact_country } }
		}
	}
}

# Root = Country
# From = War
country_event = {
	id = action.640
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_war_participant = {
			war = from
			side = attackers
		}
		any_owned_fleet = {
			is_cloaked = yes
			any_owned_ship = {
				is_ship_class = shipclass_military
			}
			exists = solar_system
			solar_system = {
				is_capital_system = yes
				owner = {
					is_war_participant = {
						war = root.from
						side = defenders
					}
				}
			}
		}
	}

	immediate = {
		set_country_flag = nothing_to_see_here_achievement
	}
}

# Galatron activated for the first time - fired from the r_galatron relic - unlocks the CB to steal it
country_event = {
	id = action.650
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		NOT = { has_global_flag = galatron_activated_first_time }
	}

	immediate = {
		set_global_flag = galatron_activated_first_time
	}
}

event = {
	id = action.720
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_lithoids = yes
		any_playable_country = {
			has_valid_civic = civic_void_hive
		}
	}

	immediate = {
		every_playable_country = {
			limit = {
				has_valid_civic = civic_void_hive
				NOT = { has_country_flag = void_hive_cooldown }
			}
			random_system_within_border = {
				limit = {
					any_system_planet = {
						NOT = {
							has_planet_flag = has_megastructure
						}
						OR = {
							AND = {
								has_deposit_for = shipclass_mining_station
								has_mining_station = no
							}
							AND = {
								has_deposit_for = shipclass_research_station
								has_research_station = no
							}
						}
					}
				}
				system_event = { id = action.725 }
			}
			set_timed_country_flag = {
				flag = void_hive_cooldown
				days = 95
			}
		}
	}
}

system_event = {
	id = action.725
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		random_system_planet = {
			limit = {
				NOT = {
					has_planet_flag = has_megastructure
				}
				OR = {
					AND = {
						has_deposit_for = shipclass_mining_station
						has_mining_station = no
					}
					AND = {
						has_deposit_for = shipclass_research_station
						has_research_station = no
					}
				}
			}
			if = {
				limit = {
					has_deposit_for = shipclass_mining_station
				}
				create_mining_station = { owner = space_owner }
				if = {
					limit = {
						has_resource = { type = exotic_gases amount > 0 }
						space_owner = {
							NOR = {
								has_technology = tech_mine_exotic_gases
								has_modifier = reduce_gas_output
							}
						}
					}
					space_owner = {
						add_modifier = { modifier = reduce_gas_output }
					}
				}
				if = {
					limit = {
						has_resource = { type = rare_crystals amount > 0 }
						space_owner = {
							NOR = {
								has_technology = tech_mine_rare_crystals
								has_modifier = reduce_crystal_output
							}
						}
					}
					space_owner = {
						add_modifier = { modifier = reduce_crystal_output }
					}
				}
				if = {
					limit = {
						has_resource = { type = volatile_motes amount > 0 }
						space_owner = {
							NOR = {
								has_technology = tech_mine_volatile_motes
								has_modifier = reduce_motes_output
							}
						}
					}
					space_owner = {
						add_modifier = { modifier = reduce_motes_output }
					}
				}
				if = {
					limit = {
						has_resource = { type = sr_living_metal amount > 0 }
						space_owner = {
							NOR = {
								has_technology = tech_mine_living_metal
								has_modifier = reduce_living_metal_output
							}
						}
					}
					space_owner = {
						add_modifier = { modifier = reduce_living_metal_output }
					}
				}
			}
			else = {
				create_research_station = { owner = space_owner }
				if = {
					limit = {
						has_resource = { type = sr_zro amount > 0 }
						space_owner = {
							NOR = {
								has_technology = tech_mine_zro
								has_modifier = reduce_zro_output
							}
						}
					}
					space_owner = {
						add_modifier = { modifier = reduce_zro_output }
					}
				}
				if = {
					limit = {
						has_resource = { type = sr_dark_matter amount > 0 }
						space_owner = {
							NOR = {
								has_technology = tech_mine_dark_matter
								has_modifier = reduce_dark_matter_output
							}
						}
					}
					space_owner = {
						add_modifier = { modifier = reduce_dark_matter_output }
					}
				}
			}
		}
	}
}

# A country has increased the level of a tech, use last_increased_tech trigger to check tech and level.
# This = Country
country_event = {
	id = action.730
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		has_valid_civic = civic_void_hive
		OR = {
			last_increased_tech = tech_mine_exotic_gases
			last_increased_tech = tech_mine_rare_crystals
			last_increased_tech = tech_mine_volatile_motes
			last_increased_tech = tech_mine_zro
			last_increased_tech = tech_mine_dark_matter
			last_increased_tech = tech_mine_living_metal
		}
	}

	immediate = {
		if = {
			limit = {
				last_increased_tech = tech_mine_exotic_gases
			}
			remove_modifier = reduce_gas_output
		}
		if = {
			limit = {
				last_increased_tech = tech_mine_rare_crystals
			}
			remove_modifier = reduce_crystal_output
		}
		if = {
			limit = {
				last_increased_tech = tech_mine_volatile_motes
			}
			remove_modifier = reduce_motes_output
		}
		if = {
			limit = {
				last_increased_tech = tech_mine_zro
			}
			remove_modifier = reduce_zro_output
		}
		if = {
			limit = {
				last_increased_tech = tech_mine_dark_matter
			}
			remove_modifier = reduce_dark_matter_output
		}
		if = {
			limit = {
				last_increased_tech = tech_mine_living_metal
			}
			remove_modifier = reduce_living_metal_output
		}
	}
}

country_event = {
	id = action.735
	is_triggered_only = yes
	hide_window = yes
	trigger = {
		NOT = {
			has_valid_civic = civic_void_hive
		}
		OR = {
			has_modifier = reduce_gas_output
			has_modifier = reduce_crystal_output
			has_modifier = reduce_motes_output
			has_modifier = reduce_zro_output
			has_modifier = reduce_dark_matter_output
			has_modifier = reduce_living_metal_output
		}
	}

	immediate = {
		if = {
			limit = {
				has_modifier = reduce_gas_output
			}
			every_planet_within_border = {
				limit = {
					has_mining_station = yes
					has_resource = { type = exotic_gases amount > 0 }
				}
				mining_station = {
					dismantle = yes
				}
			}
			remove_modifier = reduce_gas_output
		}
		if = {
			limit = {
				has_modifier = reduce_crystal_output
			}
			every_planet_within_border = {
				limit = {
					has_mining_station = yes
					has_resource = { type = rare_crystals amount > 0 }
				}
				mining_station = {
					dismantle = yes
				}
			}
			remove_modifier = reduce_crystal_output
		}
		if = {
			limit = {
				has_modifier = reduce_motes_output
			}
			every_planet_within_border = {
				limit = {
					has_mining_station = yes
					has_resource = { type = volatile_motes amount > 0 }
				}
				mining_station = {
					dismantle = yes
				}
			}
			remove_modifier = reduce_motes_output
		}
		if = {
			limit = {
				has_modifier = reduce_zro_output
			}
			every_planet_within_border = {
				limit = {
					has_mining_station = yes
					has_resource = { type = sr_zro amount > 0 }
				}
				mining_station = {
					dismantle = yes
				}
			}
			remove_modifier = reduce_zro_output
		}
		if = {
			limit = {
				has_modifier = reduce_dark_matter_output
			}
			every_planet_within_border = {
				limit = {
					has_mining_station = yes
					has_resource = { type = sr_dark_matter amount > 0 }
				}
				mining_station = {
					dismantle = yes
				}
			}
			remove_modifier = reduce_dark_matter_output
		}
		if = {
			limit = {
				has_modifier = reduce_living_metal_output
			}
			every_planet_within_border = {
				limit = {
					has_mining_station = yes
					has_resource = { type = sr_living_metal amount > 0 }
				}
				mining_station = {
					dismantle = yes
				}
			}
			remove_modifier = reduce_living_metal_output
		}
	}
}

# Fired when a truce is over
# This = owner of the truce
# From = target of the truce
country_event = {
	id = action.740
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		exists = from
	}

	immediate = {
		if = {
			limit = {
				exists = this
			}
			create_message = {
				type = TOAST_TRUCE_IS_OVER
				localization = TOAST_TRUCE_IS_OVER_DESC
				days = @toast_important_message_days
				variable = {
					type = name
					localization = ENEMY
					scope = from
				}
			}
			from = {
				create_message = {
					type = TOAST_TRUCE_IS_OVER
					localization = TOAST_TRUCE_IS_OVER_DESC
					days = @toast_important_message_days
					variable = {
						type = name
						localization = ENEMY
						scope = root
					}
				}
			}
		}
	}
}
