#################################
#
# Leviathan & Enclave Events
# by Maximilian Olbers, Niclas Karlsson,
# Rufus Tronde & Henrik Thyrwall
#
# Revised in 2022 by Gemma Thomson
#
#################################

@festivalDuration = 1800 #days

namespace = leviathans

country_event = {
	id = leviathans.9
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		from = {
			is_guardian_country = yes
		}
		OR = {
			is_country_type = default
			is_country_type = fallen_empire
			is_country_type = awakened_fallen_empire
		}
	}

	immediate = {
		from = {
			establish_communications_no_message = root
			save_event_target_as = leviathan_story_country
		}
		country_event = { id = story.8 days = 15 }
	}
	after = {
		save_event_target_as = this_country
		country_event = { id = timeline.53 } # Timeline Encountered Leviathan
	}
}

# guardian kill check
country_event = {
	id = leviathans.4
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		from = {
			is_guardian_country = yes
		}
	}

	immediate = {
		fromfromfrom.solar_system = {
			save_event_target_as = leviathan_destroyed_system
		}
		root = {
			save_event_target_as = leviathan_destroyer_country
		}
		from = {
			save_event_target_as = leviathan_destroyed_country
		}
		country_event = { id = leviathans.6 days = 2 }
	}

	after = {
		if = { # We need an exception for the Enigmatic Fortress since it isnt 'destroyed' the first time around
			limit = {
				OR = {
					from = {
						NOT = {
							has_modifier = enigmatic_power
						}
					}
					AND = {
						root = {
							has_country_flag = enigmatic_fortress_disabled
						}
						from = {
							has_modifier = enigmatic_power
						}
					}
				}
			}
			country_event = { id = timeline.54 } # Timeline Destroyed Leviathan
		}
	}

}

# Delay necessary due to fleets not being instantly deleted, therefore num_fleets trigger won't pass otherwise
country_event = {
	id = leviathans.6
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = event_target:leviathan_destroyed_system
		exists = event_target:leviathan_destroyer_country
		exists = event_target:leviathan_destroyed_country
		event_target:leviathan_destroyed_country = {
			num_fleets < 1
		}
	}

	immediate = {
		observer_event = { id = observer.1 }
		every_country = {
			limit = {
				has_communications = root
				NOT = { is_same_value = root }
			}
			country_event = { id = leviathans.5 }
		}
	}
}

# notification
country_event = {
	id = leviathans.5
	title = leviathans.5.name
	desc = leviathans.5.desc
	picture = GFX_evt_throne_room
	location = event_target:leviathan_destroyed_system
	show_sound = event_mystic_reveal

	is_triggered_only = yes

	option = {
		name = OK
	}
}

# Enclave Yearly Border Opinion
event = {
	id = leviathans.10
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		every_country = {
			limit = { is_country_type = enclave }
			country_event = { id = leviathans.11 }
		}
	}
}

country_event = {
	id = leviathans.11
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		every_controlled_fleet = {
			limit = {
				exists = solar_system
				solar_system = {
					OR = {
						AND = {
							exists = space_owner
							space_owner = {
								is_country_type = default
							}
						}
						AND = {
							any_starbase_in_system = {
								exists = owner
								is_waystation_starbase = yes
								owner = {
									is_country_type = default
								}
							}
						}
					}
				}
			}
			solar_system = {
				if = {
					limit = {
						exists = space_owner
					}
					space_owner = {
						root = {
							add_trust = {
								who = prev
								amount = 1
							}
						}
					}
					random_starbase_in_system = {
						limit = {
							is_waystation_starbase = yes
						}
						owner = {
							root = {
								add_trust = {
									who = prev
									amount = 1
								}
							}
						}
					}
				}
				else = {
					random_starbase_in_system = {
						limit = {
							is_waystation_starbase = yes
						}
						owner = {
							root = {
								add_trust = {
									who = prev
									amount = 1
								}
							}
						}
					}
				}
			}
		}
	}
}

# Enclaves (incl. Mercenaries) make contact after 3-4 years
country_event = {
	id = leviathans.97
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		exists = from.contact_country
		from.contact_country = { NOT = { has_communications = root } }
	}

	immediate = {
		from.contact_country = {
			root = { establish_communications_no_message = prev }
			country_event = { id = leviathans.98 }
		}
	}
}

# Enclave Establishes Communications
country_event = {
	id = leviathans.98
	title = leviathans.98.name
	desc = leviathans.98.desc
	picture = GFX_evt_space_station
	show_sound = event_radio_chatter
	event_message_type = ENCLAVE_DIPLOMACY

	is_triggered_only = yes

	after = {
		hidden_effect = {
			from = {
				switch = {
					trigger = has_country_flag
					trader_enclave_country = { country_event = { id = leviathans.101 } }
					artist_enclave_country = { country_event = { id = leviathans.290 } }
					curator_enclave_country = { country_event = { id = leviathans.501 } }
					mercenary_enclave_country = { country_event = { id = enclave.204 } }
					salvager_enclave_country = { country_event = { id = enclave.304 } }
					shroudwalker_enclave_country = { country_event = { id = enclave.404 } }
					mindwarden_enclave_country = { country_event = { id = shroud.4199 } }
					champions_forge_enclave_country = { country_event = { id = nomads.155 } }
					default = { log_error = "Unexpected enclave type or missing script flag" }
				}
			}
		}
	}

	option = {
		name = SCUM
		trigger = {
			has_valid_civic = civic_fanatic_purifiers
		}
	}

	option = {
		name = TASTY
		trigger = {
			has_valid_civic = civic_hive_devouring_swarm
		}
	}

	option = {
		name = EXTERMINATE
		trigger = {
			has_valid_civic = civic_machine_terminator
		}
	}

	option = {
		name = BURN
		trigger = {
			is_genocidal_infernal = yes
		}
	}

	option = {
		name = leviathans.98.a
		trigger = {
			NOR = {
				has_valid_civic = civic_fanatic_purifiers
				has_valid_civic = civic_hive_devouring_swarm
				has_valid_civic = civic_machine_terminator
				is_genocidal_infernal = yes
			}
		}
	}
}

# Enclave Communication Spread
# via on_decade_pulse_country
country_event = {
	id = leviathans.560
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		is_country_type = enclave
		any_relation = {
			is_country_type = default
			any_relation = {
				is_country_type = default
				NOT = { has_communications = ROOT }
			}
		}
	}

	immediate = {
		random_relation = {
			limit = {
				any_relation = {
					is_country_type = default
					NOT = { has_communications = ROOT }
				}
			}
			random_relation = {
				limit = {
					is_country_type = default
					NOT = { has_communications = ROOT }
				}
				root = { establish_communications_no_message = prev }
				country_event = { id = leviathans.98 } # Enclave (any) Establishes Communications
			}
		}
	}
}

##################
# TRADER ENCLAVES
##################

# NOTE: all three Trader enclaves use essentially the same diplomacy screen. However, each one (XuraCorp, Riggans and Muutagans) is established as its own instance so that e.g. all XuraCorp events inherit their properties from the XuraCorp menu.

# leviathans.97-102		Communications established
# leviathans.105–107	Main menus
# leviathans.121-122	Opinion gain from active Strategic Resource deals
# leviathans.123-128	Hire an Official
# leviathans.130-135	Strategic Resource deals
# leviathans.140-144	Trader Enclave destroyed
# leviathans.150-152	Strategic Resource deal elapses
# leviathans.155–163	Attacking a Trader Enclave
# leviathans.170-171	Defaulting on Strategic Resource deal

# NOTE: any changes to these event IDs should be reflected in the has_trader_event = {} scripted effect.

# ESTABLISH COMMUNICATIONS

# Traders gatekeeper event
# Via on_custom_diplomacy | this = target country (player); from = country being contacted
country_event = {
	id = leviathans.100
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		from = { is_country_type = enclave }
		has_trader_event = no
		OR = {
			AND = {
				NOT = { has_country_flag = attacked_xuracorp }
				from = { has_country_flag = trader_enclave_country_1 }
			}
			AND = {
				NOT = { has_country_flag = attacked_riggans }
				from = { has_country_flag = trader_enclave_country_2 }
			}
			AND = {
				NOT = { has_country_flag = attacked_muutagans }
				from = { has_country_flag = trader_enclave_country_3 }
			}
		}
	}

	immediate = {
		from = {
			switch = {
				trigger = has_country_flag
				trader_enclave_country_1 = {
					root = { country_event = { id = leviathans.105 } } #XuraCorp
				}
				trader_enclave_country_2 = {
					root = { country_event = { id = leviathans.106 } } #Riggans
				}
				trader_enclave_country_3 = {
					root = { country_event = { id = leviathans.107 } } #Muutagan
				}
			}
		}
	}
}

# Communications established (establishing scopes)
# via finish_first_contact_effect / action.11 / leviathans.98
# this = enclave country
country_event = {
	id = leviathans.101
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		random_controlled_ship = {
			solar_system = { save_event_target_as = trader_system }
		}
		from = {
			country_event = { id = leviathans.102 }
		}
	}
}

# Trader Introduction (all Traders)
# this = player country | from = Trader Enclave country | event_target:trader_system = Trader Enclave system
country_event = {
	id = leviathans.102
	title = leviathans.102.name
	desc = {
		text = leviathans.102a.desc
		trigger = {
			FROM = { has_country_flag = trader_enclave_country_1 }
		}
	}
	desc = {
		text = leviathans.102b.desc
		trigger = {
			FROM = { has_country_flag = trader_enclave_country_2 }
		}
	}
	desc = {
		text = leviathans.102c.desc
		trigger = {
			FROM = { has_country_flag = trader_enclave_country_3 }
		}
	}

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"
	custom_gui_option = "enclave_trader_option"
	event_message_type = ENCLAVE_DIPLOMACY
	picture_event_data = {
		portrait = from
		room = enclave_trader_room
	}

	option = {
		name = {
			trigger = { has_valid_civic = civic_fanatic_purifiers }
			text = SCUM
		}
		name = {
			trigger = { has_valid_civic = civic_hive_devouring_swarm }
			text = TASTY
		}
		name = {
			trigger = { has_valid_civic = civic_machine_terminator }
			text = EXTERMINATE
		}
		name = {
			trigger = { is_genocidal_infernal = yes }
			text = BURN
		}
		name = {
			trigger = {
				NOR = {
					has_valid_civic = civic_fanatic_purifiers
					has_valid_civic = civic_hive_devouring_swarm
					has_valid_civic = civic_machine_terminator
					is_genocidal_infernal = yes
				}
			}
			text = leviathans.502.a
		}
		default_hide_option = yes
	}
}

# MAIN MENUS

# XuraCorp Main Menu
# fromfrom / event_target:xuracorp_country = XuraCorp
country_event = {
	id = leviathans.105
	title = leviathans.100.name
	desc = leviathans.100a.desc
	desc = leviathans.100b.desc
	desc = leviathans.100c.desc
	desc = leviathans.100d.desc
	desc = leviathans.100e.desc
	desc = leviathans.100f.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"
	custom_gui_option = "enclave_trader_option"
	picture_event_data = {
		portrait = event_target:xuracorp_country
		room = enclave_trader_room
	}
	event_message_type = ENCLAVE_DIPLOMACY
	location = event_target:xuracorp_enclave_system

	trigger = { #for events which inherit from this one
		NOR = {
			has_global_flag = xuracorp_destroyed
			has_country_flag = attacked_xuracorp
		}
	}

	immediate = {
		event_target:xuracorp_country = {
			save_event_target_as = enclave_country
		}
	}

	option = {
		name = {
			trigger = {
				has_valid_civic = civic_fanatic_purifiers
			}
			text = SCUM
		}
		name = {
			trigger = {
				has_valid_civic = civic_hive_devouring_swarm
			}
			text = TASTY
		}
		name = {
			trigger = {
				has_valid_civic = civic_machine_terminator
			}
			text = EXTERMINATE
		}
		name = {
			trigger = {
				is_genocidal_infernal = yes
			}
			text = BURN
		}
		trigger = { is_homicidal = yes }
	}

	option = { # Strategic Resource
		name = leviathans.105.c
		custom_tooltip = trader_tt_strategicresource
		trigger = { is_homicidal = no }
		allow = {
			custom_tooltip = {
				fail_text = leviathans.105.c.sr2
				has_active_xuracorp_trade = no
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.130 }
		}
	}

	option = { # Hire Official
		name = leviathans.105.z
		custom_tooltip = trader_tt_official
		if = {
			limit = {
				has_paragon_dlc = yes
				is_gestalt = no
			}
			custom_tooltip = unlocks_trader_council_position
		}
		trigger = { is_homicidal = no }
		allow = {
			custom_tooltip = {
				text = leviathans.105.c.trust
				event_target:xuracorp_country = {
					trust = {
						who = root
						value >= 50
					}
				}
			}
			custom_tooltip = {
				fail_text = already_hired_trader_official
				NOT = {
					any_owned_leader = {
						has_trait = leader_trait_xuracorp_liaison
					}
				}
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.123 }
		}
	}

	option = { # End Resource Deal
		name = leviathans.105.e
		trigger = {
			has_active_xuracorp_trade = yes
		}
		custom_tooltip = end_trade_1
		custom_tooltip = opinion_canceled_trade
		hidden_effect = {
			event_target:xuracorp_country = {
				add_trust = {
					who = root
					amount = value:enclave_cancel_trade_trust
				}
			}
			remove_xuracorp_trades = yes
		}
		is_dialog_only = yes
		response_text = leviathans.105.e.response
	}

	option = {
		name = leviathans.105.d
		default_hide_option = yes
		trigger = { is_homicidal = no }
	}
}

# Riggan Main Menu
country_event = {
	id = leviathans.106
	title = leviathans.103.name
	desc = leviathans.103a.desc
	desc = leviathans.103b.desc
	desc = leviathans.103c.desc
	desc = leviathans.103d.desc
	desc = leviathans.103e.desc
	desc = leviathans.103f.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"
	custom_gui_option = "enclave_trader_option"
	picture_event_data = {
		portrait = event_target:riggan_country
		room = enclave_trader_room
	}
	event_message_type = ENCLAVE_DIPLOMACY
	location = event_target:riggan_enclave_system

	trigger = { #for events which inherit from this one
		NOR = {
			has_global_flag = riggans_destroyed
			has_country_flag = attacked_riggans
		}
	}

	immediate = {
		event_target:riggan_country = {
			save_event_target_as = enclave_country
		}
	}

	option = {
		name = {
			trigger = {
				has_valid_civic = civic_fanatic_purifiers
			}
			text = SCUM
		}
		name = {
			trigger = {
				has_valid_civic = civic_hive_devouring_swarm
			}
			text = TASTY
		}
		name = {
			trigger = {
				has_valid_civic = civic_machine_terminator
			}
			text = EXTERMINATE
		}
		name = {
			trigger = {
				is_genocidal_infernal = yes
			}
			text = BURN
		}
		trigger = { is_homicidal = yes }
	}

	option = { # Strategic Resource
		name = leviathans.105.c
		custom_tooltip = trader_tt_strategicresource
		trigger = { is_homicidal = no }
		allow = {
			custom_tooltip = {
				fail_text = leviathans.105.c.sr1
				has_active_riggan_trade = no
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.131 }
		}
	}

	option = { # Hire Official
		name = leviathans.105.z
		custom_tooltip = trader_tt_official
		if = {
			limit = {
				has_paragon_dlc = yes
				is_gestalt = no
			}
			custom_tooltip = unlocks_trader_council_position
		}
		trigger = { is_homicidal = no }
		allow = {
			custom_tooltip = {
				text = leviathans.105.c.trust
				event_target:riggan_country = {
					trust = {
						who = root
						value >= 50
					}
				}
			}
			custom_tooltip = {
				fail_text = already_hired_trader_official
				NOT = {
					any_owned_leader = {
						has_trait = leader_trait_riggan_liaison
					}
				}
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.124 }
		}
	}

	option = { # End Resource Deal
		name = leviathans.105.e
		trigger = {
			has_active_riggan_trade = yes
		}
		custom_tooltip = end_trade_2
		custom_tooltip = opinion_canceled_trade
		hidden_effect = {
			event_target:riggan_country = {
				add_trust = {
					who = root
					amount = value:enclave_cancel_trade_trust
				}
			}
			remove_riggan_trades = yes
		}
		is_dialog_only = yes
		response_text = leviathans.105.e.response
	}

	option = {
		name = leviathans.105.d
		default_hide_option = yes
		trigger = { is_homicidal = no }
	}
}

# Muutagan Main Menu
country_event = {
	id = leviathans.107
	title = leviathans.104.name
	desc = leviathans.104a.desc
	desc = leviathans.104b.desc
	desc = leviathans.104c.desc
	desc = leviathans.104d.desc
	desc = leviathans.104e.desc
	desc = leviathans.104f.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"
	custom_gui_option = "enclave_trader_option"
	picture_event_data = {
		portrait = event_target:muutagan_country
		room = enclave_trader_room
	}
	event_message_type = ENCLAVE_DIPLOMACY
	location = event_target:muutagan_enclave_system

	trigger = { #for events which inherit from this one
		NOR = {
			has_global_flag = muutagans_destroyed
			has_country_flag = attacked_muutagans
		}
	}

	immediate = {
		event_target:muutagan_country = {
			save_event_target_as = enclave_country
		}
	}

	option = {
		name = {
			trigger = {
				has_valid_civic = civic_fanatic_purifiers
			}
			text = SCUM
		}
		name = {
			trigger = {
				has_valid_civic = civic_hive_devouring_swarm
			}
			text = TASTY
		}
		name = {
			trigger = {
				has_valid_civic = civic_machine_terminator
			}
			text = EXTERMINATE
		}
		name = {
			trigger = {
				is_genocidal_infernal = yes
			}
			text = BURN
		}
		trigger = { is_homicidal = yes }
	}

	option = { # Strategic Resource
		name = leviathans.105.c
		custom_tooltip = trader_tt_strategicresource
		trigger = { is_homicidal = no }
		allow = {
			custom_tooltip = {
				fail_text = leviathans.105.c.sr3
				has_active_muutagan_trade = no
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.132 }
		}
	}

	option = { # Hire Official
		name = leviathans.105.z
		custom_tooltip = trader_tt_official
		if = {
			limit = {
				has_paragon_dlc = yes
				is_gestalt = no
			}
			custom_tooltip = unlocks_trader_council_position
		}
		trigger = { is_homicidal = no }
		allow = {
			custom_tooltip = {
				text = leviathans.105.c.trust
				event_target:muutagan_country = {
					trust = {
						who = root
						value >= 50
					}
				}
			}
			custom_tooltip = {
				fail_text = already_hired_trader_official
				NOT = {
					any_owned_leader = {
						has_trait = leader_trait_muutagan_liaison
					}
				}
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.125 }
		}
	}

	option = { # End Resource Deal
		name = leviathans.105.e
		trigger = {
			has_active_muutagan_trade = yes
		}
		custom_tooltip = end_trade_3
		custom_tooltip = opinion_canceled_trade
		hidden_effect = {
			event_target:muutagan_country = {
				add_trust = {
					who = root
					amount = value:enclave_cancel_trade_trust
				}
			}
			remove_muutagan_trades = yes
		}
		is_dialog_only = yes
		response_text = leviathans.105.e.response
	}

	option = {
		name = leviathans.105.d
		default_hide_option = yes
		trigger = { is_homicidal = no }
	}
}

# OPINION GAINS

# Trader Opinion from Resource Deals
# this = player country | via on_yearly_pulse_country
country_event = {
	id = leviathans.121
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		OR = {
			AND = {
				exists = event_target:xuracorp_country #global
				has_active_xuracorp_trade = yes
			}
			AND = {
				exists = event_target:riggan_country #global
				has_active_riggan_trade = yes
			}
			AND = {
				exists = event_target:muutagan_country #global
				has_active_muutagan_trade = yes
			}
		}
	}

	immediate = {
		country_event = { id = leviathans.122 days = 90 } #delay until April 1st
	}
}
country_event = {
	id = leviathans.122
	hide_window = yes
	is_triggered_only = yes

	trigger = { #verify the traders still exist since year start
		OR = {
			AND = {
				exists = event_target:xuracorp_country #global
				has_active_xuracorp_trade = yes
			}
			AND = {
				exists = event_target:riggan_country #global
				has_active_riggan_trade = yes
			}
			AND = {
				exists = event_target:muutagan_country #global
				has_active_muutagan_trade = yes
			}
		}
	}

	immediate = {
		#XuraCorp deals
		if = {
			limit = {
				has_active_xuracorp_trade = yes
			}
			switch = {
				trigger = has_modifier
				enclave_trade_5_xur = {
					event_target:xuracorp_country = {
						add_trust = {
							who = root
							amount = @traderOpinion3
						}
					}
				}
				enclave_trade_4_xur = {
					event_target:xuracorp_country = {
						add_trust = {
							who = root
							amount = @traderOpinion2
						}
					}
				}
				enclave_trade_3_xur = {
					event_target:xuracorp_country = {
						add_trust = {
							who = root
							amount = @traderOpinion2
						}
					}
				}
				enclave_trade_2_xur = {
					event_target:xuracorp_country = {
						add_trust = {
							who = root
							amount = @traderOpinion1
						}
					}
				}
				enclave_trade_1_xur = {
					event_target:xuracorp_country = {
						add_trust = {
							who = root
							amount = @traderOpinion1
						}
					}
				}
			}
		}
		#Riggan deals
		if = {
			limit = {
				has_active_riggan_trade = yes
			}
			switch = {
				trigger = has_modifier
				enclave_trade_5_rig = {
					event_target:riggan_country = {
						add_trust = {
							who = root
							amount = @traderOpinion3
						}
					}
				}
				enclave_trade_4_rig = {
					event_target:riggan_country = {
						add_trust = {
							who = root
							amount = @traderOpinion2
						}
					}
				}
				enclave_trade_3_rig = {
					event_target:riggan_country = {
						add_trust = {
							who = root
							amount = @traderOpinion2
						}
					}
				}
				enclave_trade_2_rig = {
					event_target:riggan_country = {
						add_trust = {
							who = root
							amount = @traderOpinion1
						}
					}
				}
				enclave_trade_1_rig = {
					event_target:riggan_country = {
						add_trust = {
							who = root
							amount = @traderOpinion1
						}
					}
				}
			}
		}
		#Muutagan deals
		if = {
			limit = {
				has_active_muutagan_trade = yes
			}
			switch = {
				trigger = has_modifier
				enclave_trade_5_mut = {
					event_target:muutagan_country = {
						add_trust = {
							who = root
							amount = @traderOpinion3
						}
					}
				}
				enclave_trade_4_mut = {
					event_target:muutagan_country = {
						add_trust = {
							who = root
							amount = @traderOpinion2
						}
					}
				}
				enclave_trade_3_mut = {
					event_target:muutagan_country = {
						add_trust = {
							who = root
							amount = @traderOpinion2
						}
					}
				}
				enclave_trade_2_mut = {
					event_target:muutagan_country = {
						add_trust = {
							who = root
							amount = @traderOpinion1
						}
					}
				}
				enclave_trade_1_mut = {
					event_target:muutagan_country = {
						add_trust = {
							who = root
							amount = @traderOpinion1
						}
					}
				}
			}
		}
	}
}

# HIRE A OFFICIAL

# Hire XuraCorp Official
country_event = {
	id = leviathans.123
	base = leviathans.105
	desc_clear = yes
	option_clear = yes

	desc = {
		trigger = { is_gestalt = no }
		text = leviathans.125.desc.z1
	}
	desc = {
		trigger = { is_gestalt = yes }
		text = leviathans.125.desc.z1.gestalt
	}

	# Hire Official
	option = {
		name = {
			trigger = { is_gestalt = no }
			text = leviathans.125.z1
		}
		name = {
			trigger = { is_gestalt = yes }
			text = leviathans.125.z1.gestalt
		}
		allow = {
			resource_stockpile_compare = {
				resource = energy
				value >= 1000
			}
			resource_stockpile_compare = {
				resource = influence
				value >= 50
			}
			custom_tooltip = {
				fail_text = already_hired_trader_official
				NOT = {
					any_owned_leader = {
						has_trait = leader_trait_xuracorp_liaison
					}
				}
			}
			nomad_can_afford_enclave_cost = { COST = 1000 }
		}
		add_resource = { energy = -1000 }
		add_resource = { influence = -50 }
		custom_tooltip = recruit_trader_leader
		hidden_effect = {
			create_xuracorp_trader_effect = yes
			if = {
				limit = {
					has_paragon_dlc = yes
					is_gestalt = no
				}
				custom_tooltip = unlocks_trader_council_position
			}
			country_event = { id = leviathans.126 } #Post-sales
		}
	}
	# Changed mind (back to main menu)
	option = {
		name = leviathans.110.d
		hidden_effect = {
			country_event = { id = leviathans.105 }
		}
	}
	# Goodbye
	option = {
		name = leviathans.105.d
		default_hide_option = yes
	}
}
# Hire Riggan Official
country_event = {
	id = leviathans.124
	base = leviathans.106
	desc_clear = yes
	option_clear = yes

	desc = {
		trigger = { is_gestalt = no }
		text = leviathans.125.desc.z1
	}
	desc = {
		trigger = { is_gestalt = yes }
		text = leviathans.125.desc.z1.gestalt
	}

	# Hire Official
	option = {
		name = {
			trigger = { is_gestalt = no }
			text = leviathans.125.z1
		}
		name = {
			trigger = { is_gestalt = yes }
			text = leviathans.125.z1.gestalt
		}
		allow = {
			resource_stockpile_compare = {
				resource = energy
				value >= 1000
			}
			resource_stockpile_compare = {
				resource = influence
				value >= 50
			}
			custom_tooltip = {
				fail_text = already_hired_trader_official
				NOT = {
					any_owned_leader = {
						has_trait = leader_trait_riggan_liaison
					}
				}
			}
			nomad_can_afford_enclave_cost = { COST = 1000 }
		}
		add_resource = { energy = -1000 }
		add_resource = { influence = -50 }
		custom_tooltip = recruit_trader_leader
		hidden_effect = {
			create_riggan_trader_effect = yes
			if = {
				limit = {
					has_paragon_dlc = yes
					is_gestalt = no
				}
				custom_tooltip = unlocks_trader_council_position
			}
			country_event = { id = leviathans.127 } #Post-sales
		}
	}
	# Changed mind (back to main menu)
	option = {
		name = leviathans.110.d
		hidden_effect = {
			country_event = { id = leviathans.106 }
		}
	}
	# Goodbye
	option = {
		name = leviathans.105.d
		default_hide_option = yes
	}
}
# Hire Muutagan Official
country_event = {
	id = leviathans.125
	base = leviathans.107
	desc_clear = yes
	option_clear = yes

	desc = {
		trigger = { is_gestalt = no }
		text = leviathans.125.desc.z1
	}
	desc = {
		trigger = { is_gestalt = yes }
		text = leviathans.125.desc.z1.gestalt
	}

	# Hire Official
	option = {
		name = {
			trigger = { is_gestalt = no }
			text = leviathans.125.z1
		}
		name = {
			trigger = { is_gestalt = yes }
			text = leviathans.125.z1.gestalt
		}
		allow = {
			resource_stockpile_compare = {
				resource = energy
				value >= 1000
			}
			resource_stockpile_compare = {
				resource = influence
				value >= 50
			}
			custom_tooltip = {
				fail_text = already_hired_trader_official
				NOT = {
					any_owned_leader = {
						has_trait = leader_trait_muutagan_liaison
					}
				}
			}
			nomad_can_afford_enclave_cost = { COST = 1000 }
		}
		add_resource = { energy = -1000 }
		add_resource = { influence = -50 }
		custom_tooltip = recruit_trader_leader
		hidden_effect = {
			create_muutagan_trader_effect = yes
			if = {
				limit = {
					has_paragon_dlc = yes
					is_gestalt = no
				}
				custom_tooltip = unlocks_trader_council_position
			}
			country_event = { id = leviathans.128 } #Post-sales
		}
	}
	# Changed mind (back to main menu)
	option = {
		name = leviathans.110.d
		hidden_effect = {
			country_event = { id = leviathans.107 }
		}
	}
	# Goodbye
	option = {
		name = leviathans.105.d
		default_hide_option = yes
	}
}

# Post-Sales Thanks (XuraCorp)
country_event = {
	id = leviathans.126
	base = leviathans.105
	desc_clear = yes
	desc = {
		trigger = {
			NOR = {
				is_gestalt = yes
				has_valid_civic = civic_worker_coop
			}
		}
		text = leviathans.126.desc
	}
	desc = {
		trigger = {
			OR = {
				is_gestalt = yes
				has_valid_civic = civic_worker_coop
			}
		}
		text = leviathans.126.desc.alt
	}
}
# Post-Sales Thanks (Riggans)
country_event = {
	id = leviathans.127
	base = leviathans.106
	desc_clear = yes
	desc = {
		trigger = {
			NOR = {
				is_gestalt = yes
				has_valid_civic = civic_worker_coop
			}
		}
		text = leviathans.126.desc
	}
	desc = {
		trigger = {
			OR = {
				is_gestalt = yes
				has_valid_civic = civic_worker_coop
			}
		}
		text = leviathans.126.desc.alt
	}
}
# Post-Sales Thanks (Muutagan)
country_event = {
	id = leviathans.128
	base = leviathans.107
	desc_clear = yes
	desc = {
		trigger = {
			NOR = {
				is_gestalt = yes
				has_valid_civic = civic_worker_coop
			}
		}
		text = leviathans.126.desc
	}
	desc = {
		trigger = {
			OR = {
				is_gestalt = yes
				has_valid_civic = civic_worker_coop
			}
		}
		text = leviathans.126.desc.alt
	}
}

# BUY STRATEGIC RESOURCES

# Strategic Resource: Exotic Gases
country_event = {
	id = leviathans.130
	base = leviathans.105
	desc_clear = yes
	option_clear = yes

	desc = leviathans.130.desc

	option = {
		name = leviathans.130.a
		allow = {
			resource_stockpile_compare = { resource = energy value >= 500 }
			hidden_trigger = {
				NOT = { has_country_flag = attacked_xuracorp }
			}
			nomad_can_afford_enclave_cost = { COST = 500 }
		}
		add_resource = { energy = -500 }
		custom_tooltip = opinion5
		add_modifier = {
			modifier = enclave_trade_1_xur
			days = @traderDealDuration
		}
		custom_tooltip = opinion_enclave_trade_deal_1
		hidden_effect = {
			event_target:xuracorp_country = {
				add_trust = {
					who = root
					amount = 5
				}
			}
			set_timed_relation_flag = {
				who = event_target:xuracorp_country
				flag = xuracorp_trade
				days = @traderDealDuration
			}
			country_event = { id = leviathans.133 } #Post-sales
			country_event = { id = leviathans.150 days = @traderDealDuration }
		}
	}
	option = {
		name = leviathans.130.b
		allow = {
			resource_stockpile_compare = { resource = energy value >= 1000 }
			hidden_trigger = {
				NOT = { has_country_flag = attacked_xuracorp }
			}
			nomad_can_afford_enclave_cost = { COST = 1000 }
		}
		add_resource = { energy = -1000 }
		custom_tooltip = opinion10
		add_modifier = {
			modifier = enclave_trade_2_xur
			days = @traderDealDuration
		}
		custom_tooltip = opinion_enclave_trade_deal_1
		hidden_effect = {
			event_target:xuracorp_country = {
				add_trust = {
					who = root
					amount = 10
				}
			}
			set_timed_relation_flag = {
				who = event_target:xuracorp_country
				flag = xuracorp_trade
				days = @traderDealDuration
			}
			country_event = { id = leviathans.133 } #Post-sales
			country_event = { id = leviathans.150 days = @traderDealDuration }
		}
	}
	option = {
		name = leviathans.130.c
		allow = {
			resource_stockpile_compare = { resource = energy value >= 1500 }
			hidden_trigger = {
				NOT = { has_country_flag = attacked_xuracorp }
			}
			nomad_can_afford_enclave_cost = { COST = 1500 }
		}
		add_resource = { energy = -1500 }
		custom_tooltip = opinion15
		add_modifier = {
			modifier = enclave_trade_3_xur
			days = @traderDealDuration
		}
		custom_tooltip = opinion_enclave_trade_deal_2
		hidden_effect = {
			event_target:xuracorp_country = {
				add_trust = {
					who = root
					amount = 15
				}
			}
			set_timed_relation_flag = {
				who = event_target:xuracorp_country
				flag = xuracorp_trade
				days = @traderDealDuration
			}
			country_event = { id = leviathans.133 } #Post-sales
			country_event = { id = leviathans.150 days = @traderDealDuration }
		}
	}
	option = {
		name = leviathans.130.d
		trigger = {
			NOT = { has_country_flag = attacked_xuracorp }
		}
		allow = {
			resource_stockpile_compare = { resource = energy value >= 2000 }
			custom_tooltip = {
				fail_text = xuracorp_deal_in_place
				NOR = {
					has_modifier = enclave_trade_1_xur
					has_modifier = enclave_trade_2_xur
					has_modifier = enclave_trade_3_xur
					has_modifier = enclave_trade_4_xur
					has_modifier = enclave_trade_5_xur
				}
			}
			nomad_can_afford_enclave_cost = { COST = 2000 }
		}
		add_resource = { energy = -2000 }
		custom_tooltip = opinion20
		add_modifier = {
			modifier = enclave_trade_4_xur
			days = @traderDealDuration
		}
		custom_tooltip = opinion_enclave_trade_deal_2
		hidden_effect = {
			event_target:xuracorp_country = {
				add_trust = {
					who = root
					amount = 20
				}
			}
			set_timed_relation_flag = {
				who = event_target:xuracorp_country
				flag = xuracorp_trade
				days = @traderDealDuration
			}
			country_event = { id = leviathans.133 } #Post-sales
			country_event = { id = leviathans.150 days = @traderDealDuration }
		}
	}
	option = {
		name = leviathans.130.e
		trigger = {
			NOT = { has_country_flag = attacked_xuracorp }
		}
		allow = {
			resource_stockpile_compare = { resource = energy value >= 2500 }
			custom_tooltip = {
				fail_text = xuracorp_deal_in_place
				NOR = {
					has_modifier = enclave_trade_1_xur
					has_modifier = enclave_trade_2_xur
					has_modifier = enclave_trade_3_xur
					has_modifier = enclave_trade_4_xur
					has_modifier = enclave_trade_5_xur
				}
			}
			nomad_can_afford_enclave_cost = { COST = 2500 }
		}
		add_resource = { energy = -2500 }
		custom_tooltip = opinion25
		add_modifier = {
			modifier = enclave_trade_5_xur
			days = @traderDealDuration
		}
		custom_tooltip = opinion_enclave_trade_deal_3
		hidden_effect = {
			event_target:xuracorp_country = {
				add_trust = {
					who = root
					amount = 25
				}
			}
			set_timed_relation_flag = {
				who = event_target:xuracorp_country
				flag = xuracorp_trade
				days = @traderDealDuration
			}
			country_event = { id = leviathans.133 } #Post-sales
			country_event = { id = leviathans.150 days = @traderDealDuration }
		}
	}
	option = {
		name = leviathans.110.d
		hidden_effect = {
			country_event = { id = leviathans.105 }
		}
	}
	option = {
		name = leviathans.110.e
		default_hide_option = yes
	}
}
# Strategic Resource: Volatile Motes
country_event = {
	id = leviathans.131
	base = leviathans.106
	desc_clear = yes
	option_clear = yes

	desc = leviathans.131.desc

	option = {
		name = leviathans.131.a
		allow = {
			resource_stockpile_compare = { resource = energy value >= 500 }
			hidden_trigger = {
				NOT = { has_country_flag = attacked_riggans }
			}
			nomad_can_afford_enclave_cost = { COST = 500 }
		}
		add_resource = { energy = -500 }
		custom_tooltip = opinion5
		add_modifier = {
			modifier = enclave_trade_1_rig
			days = @traderDealDuration
		}
		custom_tooltip = opinion_enclave_trade_deal_1
		hidden_effect = {
			event_target:riggan_country = {
				add_trust = {
					who = root
					amount = 5
				}
			}
			set_timed_relation_flag = {
				who = event_target:riggan_country
				flag = riggan_trade
				days = @traderDealDuration
			}
			country_event = { id = leviathans.134 } #Post-sales
			country_event = { id = leviathans.151 days = @traderDealDuration }
		}
	}
	option = {
		name = leviathans.131.b
		allow = {
			resource_stockpile_compare = { resource = energy value >= 1000 }
			hidden_trigger = {
				NOT = { has_country_flag = attacked_riggans }
			}
			nomad_can_afford_enclave_cost = { COST = 1000 }
		}
		add_resource = { energy = -1000 }
		custom_tooltip = opinion10
		add_modifier = {
			modifier = enclave_trade_2_rig
			days = @traderDealDuration
		}
		custom_tooltip = opinion_enclave_trade_deal_1
		hidden_effect = {
			event_target:riggan_country = {
				add_trust = {
					who = root
					amount = 10
				}
			}
			set_timed_relation_flag = {
				who = event_target:riggan_country
				flag = riggan_trade
				days = @traderDealDuration
			}
			country_event = { id = leviathans.134 } #Post-sales
			country_event = { id = leviathans.151 days = @traderDealDuration }
		}
	}
	option = {
		name = leviathans.131.c
		allow = {
			resource_stockpile_compare = { resource = energy value >= 1500 }
			hidden_trigger = {
				NOT = { has_country_flag = attacked_riggans }
			}
			nomad_can_afford_enclave_cost = { COST = 1500 }
		}
		add_resource = { energy = -1500 }
		custom_tooltip = opinion15
		add_modifier = {
			modifier = enclave_trade_3_rig
			days = @traderDealDuration
		}
		custom_tooltip = opinion_enclave_trade_deal_2
		hidden_effect = {
			event_target:riggan_country = {
				add_trust = {
					who = root
					amount = 15
				}
			}
			set_timed_relation_flag = {
				who = event_target:riggan_country
				flag = riggan_trade
				days = @traderDealDuration
			}
			country_event = { id = leviathans.134 } #Post-sales
			country_event = { id = leviathans.151 days = @traderDealDuration }
		}
	}
	option = {
		name = leviathans.131.d
		trigger = {
			NOT = { has_country_flag = attacked_riggans }
		}
		allow = {
			resource_stockpile_compare = { resource = energy value >= 2000 }
			custom_tooltip = {
				fail_text = riggan_deal_in_place
				NOR = {
					has_modifier = enclave_trade_1_rig
					has_modifier = enclave_trade_2_rig
					has_modifier = enclave_trade_3_rig
					has_modifier = enclave_trade_4_rig
					has_modifier = enclave_trade_5_rig
				}
			}
			nomad_can_afford_enclave_cost = { COST = 2000 }
		}
		add_resource = { energy = -2000 }
		custom_tooltip = opinion20
		add_modifier = {
			modifier = enclave_trade_4_rig
			days = @traderDealDuration
		}
		custom_tooltip = opinion_enclave_trade_deal_2
		hidden_effect = {
			event_target:riggan_country = {
				add_trust = {
					who = root
					amount = 20
				}
			}
			set_timed_relation_flag = {
				who = event_target:riggan_country
				flag = riggan_trade
				days = @traderDealDuration
			}
			country_event = { id = leviathans.134 } #Post-sales
			country_event = { id = leviathans.151 days = @traderDealDuration }
		}
	}
	option = {
		name = leviathans.131.e
		trigger = {
			NOT = { has_country_flag = attacked_riggans }
		}
		allow = {
			resource_stockpile_compare = { resource = energy value >= 2500 }
			custom_tooltip = {
				fail_text = riggan_deal_in_place
				NOR = {
					has_modifier = enclave_trade_1_rig
					has_modifier = enclave_trade_2_rig
					has_modifier = enclave_trade_3_rig
					has_modifier = enclave_trade_4_rig
					has_modifier = enclave_trade_5_rig
				}
			}
			nomad_can_afford_enclave_cost = { COST = 2500 }
		}
		add_resource = { energy = -2500 }
		custom_tooltip = opinion25
		add_modifier = {
			modifier = enclave_trade_5_rig
			days = @traderDealDuration
		}
		custom_tooltip = opinion_enclave_trade_deal_3
		hidden_effect = {
			event_target:riggan_country = {
				add_trust = {
					who = root
					amount = 25
				}
			}
			set_timed_relation_flag = {
				who = event_target:riggan_country
				flag = riggan_trade
				days = @traderDealDuration
			}
			country_event = { id = leviathans.134 } #Post-sales
			country_event = { id = leviathans.151 days = @traderDealDuration }
		}
	}
	option = {
		name = leviathans.110.d
		hidden_effect = {
			country_event = { id = leviathans.106 }
		}
	}
	option = {
		name = leviathans.110.e
		default_hide_option = yes
	}
}
# Strategic Resource: Rare Crystals
country_event = {
	id = leviathans.132
	base = leviathans.107
	desc_clear = yes
	option_clear = yes

	desc = leviathans.132.desc

	option = {
		name = leviathans.132.a
		allow = {
			resource_stockpile_compare = { resource = energy value >= 500 }
			hidden_trigger = {
				NOT = { has_country_flag = attacked_muutagans }
			}
			nomad_can_afford_enclave_cost = { COST = 500 }
		}
		add_resource = { energy = -500 }
		custom_tooltip = opinion5
		add_modifier = {
			modifier = enclave_trade_1_mut
			days = @traderDealDuration
		}
		custom_tooltip = opinion_enclave_trade_deal_1
		hidden_effect = {
			event_target:muutagan_country = {
				add_trust = {
					who = root
					amount = 5
				}
			}
			set_timed_relation_flag = {
				who = event_target:muutagan_country
				flag = muutagan_trade
				days = @traderDealDuration
			}
			country_event = { id = leviathans.135 } #Post-sales
			country_event = { id = leviathans.152 days = @traderDealDuration }
		}
	}
	option = {
		name = leviathans.132.b
		allow = {
			resource_stockpile_compare = { resource = energy value >= 1000 }
			hidden_trigger = {
				NOT = { has_country_flag = attacked_muutagans }
			}
			nomad_can_afford_enclave_cost = { COST = 1000 }
		}
		add_resource = { energy = -1000 }
		custom_tooltip = opinion10
		add_modifier = {
			modifier = enclave_trade_2_mut
			days = @traderDealDuration
		}
		custom_tooltip = opinion_enclave_trade_deal_1
		hidden_effect = {
			event_target:muutagan_country = {
				add_trust = {
					who = root
					amount = 10
				}
			}
			set_timed_relation_flag = {
				who = event_target:muutagan_country
				flag = muutagan_trade
				days = @traderDealDuration
			}
			country_event = { id = leviathans.135 } #Post-sales
			country_event = { id = leviathans.152 days = @traderDealDuration }
		}
	}
	option = {
		name = leviathans.132.c
		allow = {
			resource_stockpile_compare = { resource = energy value >= 1500 }
			hidden_trigger = {
				NOT = { has_country_flag = attacked_muutagans }
			}
			nomad_can_afford_enclave_cost = { COST = 1500 }
		}
		add_resource = { energy = -1500 }
		custom_tooltip = opinion15
		add_modifier = {
			modifier = enclave_trade_3_mut
			days = @traderDealDuration
		}
		custom_tooltip = opinion_enclave_trade_deal_2
		hidden_effect = {
			event_target:muutagan_country = {
				add_trust = {
					who = root
					amount = 15
				}
			}
			set_timed_relation_flag = {
				who = event_target:muutagan_country
				flag = muutagan_trade
				days = @traderDealDuration
			}
			country_event = { id = leviathans.135 } #Post-sales
			country_event = { id = leviathans.152 days = @traderDealDuration }
		}
	}
	option = {
		name = leviathans.132.d
		trigger = {
			NOT = { has_country_flag = attacked_muutagans }
		}
		allow = {
			resource_stockpile_compare = { resource = energy value >= 2000 }
			custom_tooltip = {
				fail_text = muutagan_deal_in_place
				NOR = {
					has_modifier = enclave_trade_1_mut
					has_modifier = enclave_trade_2_mut
					has_modifier = enclave_trade_3_mut
					has_modifier = enclave_trade_4_mut
					has_modifier = enclave_trade_5_mut
				}
			}
			nomad_can_afford_enclave_cost = { COST = 2000 }
		}
		add_resource = { energy = -2000 }
		custom_tooltip = opinion20
		add_modifier = {
			modifier = enclave_trade_4_mut
			days = @traderDealDuration
		}
		custom_tooltip = opinion_enclave_trade_deal_2
		hidden_effect = {
			event_target:muutagan_country = {
				add_trust = {
					who = root
					amount = 20
				}
			}
			set_timed_relation_flag = {
				who = event_target:muutagan_country
				flag = muutagan_trade
				days = @traderDealDuration
			}
			country_event = { id = leviathans.135 } #Post-sales
			country_event = { id = leviathans.152 days = @traderDealDuration }
		}
	}
	option = {
		name = leviathans.132.e
		trigger = {
			NOT = { has_country_flag = attacked_muutagans }
		}
		allow = {
			resource_stockpile_compare = { resource = energy value >= 2500 }
			custom_tooltip = {
				fail_text = muutagan_deal_in_place
				NOR = {
					has_modifier = enclave_trade_1_mut
					has_modifier = enclave_trade_2_mut
					has_modifier = enclave_trade_3_mut
					has_modifier = enclave_trade_4_mut
					has_modifier = enclave_trade_5_mut
				}
			}
			nomad_can_afford_enclave_cost = { COST = 2500 }
		}
		add_resource = { energy = -2500 }
		custom_tooltip = opinion25
		add_modifier = {
			modifier = enclave_trade_5_mut
			days = @traderDealDuration
		}
		custom_tooltip = opinion_enclave_trade_deal_3
		hidden_effect = {
			event_target:muutagan_country = {
				add_trust = {
					who = root
					amount = 25
				}
			}
			set_timed_relation_flag = {
				who = event_target:muutagan_country
				flag = muutagan_trade
				days = @traderDealDuration
			}
			country_event = { id = leviathans.135 } #Post-sales
			country_event = { id = leviathans.152 days = @traderDealDuration }
		}
	}
	option = {
		name = leviathans.110.d
		hidden_effect = {
			country_event = { id = leviathans.107 }
		}
	}
	option = {
		name = leviathans.110.e
		default_hide_option = yes
	}
}

# Post-Sales Thanks (XuraCorp)
country_event = {
	id = leviathans.133
	base = leviathans.105
	desc_clear = yes
	desc = leviathans.130.a.reply
}
# Post-Sales Thanks (Riggans)
country_event = {
	id = leviathans.134
	base = leviathans.106
	desc_clear = yes
	desc = leviathans.131.a.reply
}
# Post-Sales Thanks (Muutagan)
country_event = {
	id = leviathans.135
	base = leviathans.107
	desc_clear = yes
	desc = leviathans.132.a.reply
}

# TRADER ENCLAVE DESTROYED

# Trader Destroyed (HIDDEN)
# this = owner of destroyed ship | from = owner of aggressor ship | fromfrom = destroyed ship | fromfromfrom = attacking ship
country_event = {
	id = leviathans.140
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_country_type = enclave
		has_country_flag = trader_enclave_country
		FROMFROM = {
			is_ship_size = enclave_station
		}
	}

	immediate = {
		FROMFROM = {
			solar_system = { save_event_target_as = trader_system }
		}
		FROM = {
			country_event = { id = leviathans.141 }
			save_event_target_as = trader_destroyer
		}
		every_country = {
			limit = {
				is_country_type = default
				has_communications = ROOT
				NOT = { is_country = event_target:trader_destroyer }
			}
			if = {
				limit = {
					ROOT = { has_country_flag = trader_enclave_country_1 }
				}
				country_event = { id = leviathans.142 }
			}
			if = {
				limit = {
					ROOT = { has_country_flag = trader_enclave_country_2 }
				}
				country_event = { id = leviathans.143 }
			}
			if = {
				limit = {
					ROOT = { has_country_flag = trader_enclave_country_3 }
				}
				country_event = { id = leviathans.144 }
			}
		}
		random_playable_country = {
			if = {
				limit = {
					ROOT = { has_country_flag = trader_enclave_country_1 }
				}
				observer_event = { id = observer.8 }
			}
			if = {
				limit = {
					ROOT = { has_country_flag = trader_enclave_country_2 }
				}
				observer_event = { id = observer.9 }
			}
			if = {
				limit = {
					ROOT = { has_country_flag = trader_enclave_country_3 }
				}
				observer_event = { id = observer.10 }
			}
		}
	}
}

# Any Trader Destroyed (Destroyer)
country_event = {
	id = leviathans.141
	title = "leviathans.141"
	desc = "leviathans.141.desc"
	picture = GFX_evt_space_debris
	location = event_target:trader_system
	show_sound = event_ship_bridge

	is_triggered_only = yes

	immediate = {
		set_country_flag = destroyed_trader
		every_country = {
			limit = {
				is_country_type = default
				NOR = {
					is_same_value = root
					has_valid_civic = civic_fanatic_purifiers
					has_valid_civic = civic_hive_devouring_swarm
					has_valid_civic = civic_machine_terminator
				}
			}
			add_opinion_modifier = {
				who = root
				modifier = opinion_destroyed_trader
			}
		}
		if = {
			limit = { FROM = { has_country_flag = trader_enclave_country_1 } }
			remove_xuracorp_trades = yes
			remove_relation_flag = {
				who = FROM
				flag = xuracorp_trade
			}
		}
		else_if = {
			limit = { FROM = { has_country_flag = trader_enclave_country_2 } }
			remove_riggan_trades = yes
			remove_relation_flag = {
				who = FROM
				flag = riggan_trade
			}
		}
		else_if = {
			limit = { FROM = { has_country_flag = trader_enclave_country_3 } }
			remove_muutagan_trades = yes
			remove_relation_flag = {
				who = FROM
				flag = muutagan_trade
			}
		}
	}

	option = {
		name = EXCELLENT
		add_resource = {
			minerals = 2000
			energy = 2000
		}
	}
}

# XuraCorp Destroyed
country_event = {
	id = leviathans.142
	title = "leviathans.141"
	# We're not trading with XuraCorp and we know the attacker
	desc = {
		text = leviathans.142.a.desc
		trigger = {
			NOT = {
				has_relation_flag = {
					who = FROM
					flag = xuracorp_trade
				}
			}
			has_communications = event_target:trader_destroyer
		}
	}
	# We're not trading with XuraCorp and we don't know the attacker
	desc = {
		text = leviathans.142.b.desc
		trigger = {
			NOT = {
				has_relation_flag = {
					who = FROM
					flag = xuracorp_trade
				}
			}
			NOT = { has_communications = event_target:trader_destroyer }
		}
	}
	# We're trading with XuraCorp and we know the attacker
	desc = {
		text = leviathans.142.c.desc
		trigger = {
			has_relation_flag = {
				who = FROM
				flag = xuracorp_trade
			}
			has_communications = event_target:trader_destroyer
		}
	}
	# We're trading with XuraCorp and we don't know the attacker
	desc = {
		text = leviathans.142.d.desc
		trigger = {
			has_relation_flag = {
				who = FROM
				flag = xuracorp_trade
			}
			NOT = { has_communications = event_target:trader_destroyer }
		}
	}
	picture = GFX_evt_exploding_ship
	location = event_target:trader_system
	show_sound = event_ship_explosion

	is_triggered_only = yes

	immediate = {
		set_global_flag = xuracorp_destroyed
		remove_xuracorp_trades = yes
		remove_relation_flag = {
			who = FROM
			flag = xuracorp_trade
		}
	}

	option = {
		name = "leviathans.142.a"
	}
}

# Riggans Destroyed
country_event = {
	id = leviathans.143
	title = "leviathans.141"
	# We're not trading with the Riggans and we know the attacker
	desc = {
		text = leviathans.143.a.desc
		trigger = {
			NOT = {
				has_relation_flag = {
					who = FROM
					flag = riggan_trade
				}
			}
			has_communications = event_target:trader_destroyer
		}
	}
	# We're not trading with the Riggans and we don't know the attacker
	desc = {
		text = leviathans.143.b.desc
		trigger = {
			NOT = {
				has_relation_flag = {
					who = FROM
					flag = riggan_trade
				}
			}
			NOT = { has_communications = event_target:trader_destroyer }
		}
	}
	# We're trading with the Riggans and we know the attacker
	desc = {
		text = leviathans.143.c.desc
		trigger = {
			has_relation_flag = {
				who = FROM
				flag = riggan_trade
			}
			has_communications = event_target:trader_destroyer
		}
	}
	# We're trading with the Riggans and we don't know the attacker
	desc = {
		text = leviathans.143.d.desc
		trigger = {
			has_relation_flag = {
				who = FROM
				flag = riggan_trade
			}
			NOT = { has_communications = event_target:trader_destroyer }
		}
	}
	picture = GFX_evt_exploding_ship
	location = event_target:trader_system
	show_sound = event_ship_explosion

	is_triggered_only = yes

	immediate = {
		set_global_flag = riggans_destroyed
		remove_riggan_trades = yes
		remove_relation_flag = {
			who = FROM
			flag = riggan_trade
		}
	}

	option = {
		name = "leviathans.143.a"
	}
}

# Muutagans Destroyed
country_event = {
	id = leviathans.144
	title = "leviathans.141"
	# We're not trading with the Muutagans and we know the attacker
	desc = {
		text = leviathans.144.a.desc
		trigger = {
			NOT = {
				has_relation_flag = {
					who = FROM
					flag = muutagan_trade
				}
			}
			has_communications = event_target:trader_destroyer
		}
	}
	# We're not trading with the Muutagans and we don't know the attacker
	desc = {
		text = leviathans.144.b.desc
		trigger = {
			NOT = {
				has_relation_flag = {
					who = FROM
					flag = muutagan_trade
				}
			}
			NOT = { has_communications = event_target:trader_destroyer }
		}
	}
	# We're trading with the Muutagans and we know the attacker
	desc = {
		text = leviathans.144.c.desc
		trigger = {
			has_relation_flag = {
				who = FROM
				flag = muutagan_trade
			}
			has_communications = event_target:trader_destroyer
		}
	}
	# We're trading with the Muutagans and we don't know the attacker
	desc = {
		text = leviathans.144.d.desc
		trigger = {
			has_relation_flag = {
				who = FROM
				flag = muutagan_trade
			}
			NOT = { has_communications = event_target:trader_destroyer }
		}
	}
	picture = GFX_evt_exploding_ship
	location = event_target:trader_system
	show_sound = event_ship_explosion

	is_triggered_only = yes

	immediate = {
		set_global_flag = muutagans_destroyed
		remove_muutagan_trades = yes
		remove_relation_flag = {
			who = FROM
			flag = muutagan_trade
		}
	}

	option = {
		name = "leviathans.144.a"
	}
}

# RENEWING STRATEGIC RESOURCE DEALS

# Continue Trade? (XuraCorp)
country_event = {
	id = leviathans.150
	base = leviathans.105
	desc_clear = yes
	option_clear = yes

	title = leviathans.100.name
	desc = leviathans.150.desc

	# Renew (to sales menu)
	option = {
		name = leviathans.150.a
		hidden_effect = {
			country_event = { id = leviathans.130 }
		}
	}
	# Something else (to main menu)
	option = {
		name = leviathans.110.d
		hidden_effect = {
			country_event = { id = leviathans.105 }
		}
	}
	# Goodbye
	option = {
		name = leviathans.150.b
		default_hide_option = yes
	}
}

# Continue Trade? (Riggans)
country_event = {
	id = leviathans.151
	base = leviathans.106
	desc_clear = yes
	option_clear = yes

	title = leviathans.103.name
	desc = leviathans.151.desc

	# Renew (to sales menu)
	option = {
		name = leviathans.151.a
		hidden_effect = {
			country_event = { id = leviathans.131 }
		}
	}
	# Something else (to main menu)
	option = {
		name = leviathans.110.d
		hidden_effect = {
			country_event = { id = leviathans.106 }
		}
	}
	# Goodbye
	option = {
		name = leviathans.151.b
		default_hide_option = yes
	}
}

# Continue Trade? (Muutagans)
country_event = {
	id = leviathans.152
	base = leviathans.107
	desc_clear = yes
	option_clear = yes

	title = leviathans.104.name
	desc = leviathans.152.desc

	# Renew (to sales menu)
	option = {
		name = leviathans.152.a
		hidden_effect = {
			country_event = { id = leviathans.132 }
		}
	}
	# Something else (to main menu)
	option = {
		name = leviathans.110.d
		hidden_effect = {
			country_event = { id = leviathans.107 }
		}
	}
	# Goodbye
	option = {
		name = leviathans.152.b
		default_hide_option = yes
	}
}

# TRADER ENCLAVE ATTACKED

# Attacked Trader Enclave (HIDDEN)
# via on_entering_battle
# this = owner of aggressor fleet | from = owner of attacked fleet | fromfrom = aggressor fleet | fromfromfrom = attacking fleet
country_event = {
	id = leviathans.155
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = default
		FROM = {
			OR = {
				has_country_flag = trader_enclave_country_1
				has_country_flag = trader_enclave_country_2
				has_country_flag = trader_enclave_country_3
			}
		}
	}

	immediate = {
		FROM = {
			switch = {
				trigger = has_country_flag
				trader_enclave_country_1 = { #XuraCorp
					root = {
						country_event = { id = leviathans.156 }
					}
				}
				trader_enclave_country_2 = { #Riggans
					root = {
						country_event = { id = leviathans.159 }
					}
				}
				trader_enclave_country_3 = { #Muutagans
					root = {
						country_event = { id = leviathans.162 }
					}
				}
			}
		}
	}
}

# Attacked XuraCorp (canceling trade deals if applicable)
country_event = {
	id = leviathans.156
	base = leviathans.105
	desc_clear = yes
	option_clear = yes

	desc = {
		trigger = { has_active_xuracorp_trade = yes }
		text = leviathans.156.desc
	}
	desc = {
		trigger = { has_active_xuracorp_trade = no }
		text = leviathans.156.desc.notrade
	}

	immediate = {
		set_country_flag = attacked_xuracorp
		if = {
			limit = {
				has_active_xuracorp_trade = yes
			}
			remove_xuracorp_trades = yes
			remove_relation_flag = {
				who = event_target:xuracorp_country
				flag = xuracorp_trade
			}
		}
		event_target:xuracorp_country = {
			add_trust = {
				who = ROOT
				amount = -100
			}
		}
	}

	option = {
		name = leviathans.156.a
		tooltip = {
			event_target:xuracorp_country = {
				add_trust = {
					who = ROOT
					amount = -100
				}
			}
		}
		if = {
			limit = {
				NOT = {
					has_country_flag = attacked_trader_enclave_country_1
				}
				any_owned_leader = {
					has_trait = leader_trait_xuracorp_liaison
				}
			}
			set_country_flag = attacked_trader_enclave_country_1
			random_owned_leader = {
				limit = {
					has_trait = leader_trait_xuracorp_liaison
				}
				leader_event = {
					id = enclave.8000
					days = 5
					scopes = {
						FROM = event_target:xuracorp_country
					}
				}
			}
		}
	}
}

# XuraCorp Refuses Communications
country_event = {
	id = leviathans.157
	base = leviathans.105
	desc_clear = yes
	option_clear = yes

	desc = leviathans.157a.desc
	desc = leviathans.157b.desc
	desc = leviathans.157c.desc

	trigger = {
		from = { has_country_flag = trader_enclave_country_1 }
		has_country_flag = attacked_xuracorp
	}

	option = {
		name = {
			trigger = { has_valid_civic = civic_fanatic_purifiers }
			text = SCUM
		}
		name = {
			trigger = { has_valid_civic = civic_hive_devouring_swarm }
			text = TASTY
		}
		name = {
			trigger = { has_valid_civic = civic_machine_terminator }
			text = EXTERMINATE
		}
		name = {
			trigger = { is_genocidal_infernal = yes }
			text = BURN
		}
		name = {
			trigger = {
				NOR = {
					has_valid_civic = civic_fanatic_purifiers
					has_valid_civic = civic_hive_devouring_swarm
					has_valid_civic = civic_machine_terminator
					is_genocidal_infernal = yes
				}
			}
			text = leviathans.156.a
		}
		default_hide_option = yes
	}
}

# Attacked Riggans (canceling trade deals if applicable)
country_event = {
	id = leviathans.159
	base = leviathans.106
	desc_clear = yes
	option_clear = yes

	desc = {
		trigger = { has_active_riggan_trade = yes }
		text = leviathans.159.desc
	}
	desc = {
		trigger = { has_active_riggan_trade = no }
		text = leviathans.159.desc.notrade
	}

	immediate = {
		set_country_flag = attacked_riggans
		if = {
			limit = {
				has_active_riggan_trade = yes
			}
			remove_riggan_trades = yes
			remove_relation_flag = {
				who = event_target:riggan_country
				flag = riggan_trade
			}
		}
		event_target:riggan_country = {
			add_trust = {
				who = ROOT
				amount = -100
			}
		}
	}

	option = {
		name = leviathans.156.a
		tooltip = {
			event_target:riggan_country = {
				add_trust = {
					who = ROOT
					amount = -100
				}
			}
		}
		if = {
			limit = {
				NOT = {
					has_country_flag = attacked_trader_enclave_country_2
				}
				any_owned_leader = {
					has_trait = leader_trait_riggan_liaison
				}
			}
			set_country_flag = attacked_trader_enclave_country_2
			random_owned_leader = {
				limit = {
					has_trait = leader_trait_riggan_liaison
				}
				leader_event = {
					id = enclave.8000
					days = 5
					scopes = {
						FROM = event_target:riggan_country
					}
				}
			}
		}
	}
}

# Riggans Refuse Communications
country_event = {
	id = leviathans.160
	base = leviathans.106
	desc_clear = yes
	option_clear = yes

	desc = leviathans.160a.desc
	desc = leviathans.160b.desc
	desc = leviathans.160c.desc

	trigger = {
		from = { has_country_flag = trader_enclave_country_2 }
		has_country_flag = attacked_riggans
	}

	option = {
		name = {
			trigger = { has_valid_civic = civic_fanatic_purifiers }
			text = SCUM
		}
		name = {
			trigger = { has_valid_civic = civic_hive_devouring_swarm }
			text = TASTY
		}
		name = {
			trigger = { has_valid_civic = civic_machine_terminator }
			text = EXTERMINATE
		}
		name = {
			trigger = { is_genocidal_infernal = yes }
			text = BURN
		}
		name = {
			trigger = {
				NOR = {
					has_valid_civic = civic_fanatic_purifiers
					has_valid_civic = civic_hive_devouring_swarm
					has_valid_civic = civic_machine_terminator
					is_genocidal_infernal = yes
				}
			}
			text = leviathans.156.a
		}
		default_hide_option = yes
	}
}

# Attacked Muutagans (canceling trade deals if applicable)
country_event = {
	id = leviathans.162
	base = leviathans.107
	desc_clear = yes
	option_clear = yes

	desc = {
		trigger = { has_active_muutagan_trade = yes }
		text = leviathans.162.desc
	}
	desc = {
		trigger = { has_active_muutagan_trade = no }
		text = leviathans.162.desc.notrade
	}

	immediate = {
		set_country_flag = attacked_muutagans
		if = {
			limit = {
				has_active_muutagan_trade = yes
			}
			remove_muutagan_trades = yes
			remove_relation_flag = {
				who = event_target:muutagan_country
				flag = muutagan_trade
			}
		}
		event_target:muutagan_country = {
			add_trust = {
				who = ROOT
				amount = -100
			}
		}
	}

	option = {
		name = leviathans.156.a
		tooltip = {
			event_target:muutagan_country = {
				add_trust = {
					who = ROOT
					amount = -100
				}
			}
		}
		if = {
			limit = {
				NOT = {
					has_country_flag = attacked_trader_enclave_country_3
				}
				any_owned_leader = {
					has_trait = leader_trait_muutagan_liaison
				}
			}
			set_country_flag = attacked_trader_enclave_country_3
			random_owned_leader = {
				limit = {
					has_trait = leader_trait_muutagan_liaison
				}
				leader_event = {
					id = enclave.8000
					days = 5
					scopes = {
						FROM = event_target:muutagan_country
					}
				}
			}
		}
	}
}

# Muutagans Refuse Communications
country_event = {
	id = leviathans.163
	base = leviathans.107
	desc_clear = yes
	option_clear = yes

	desc = leviathans.163a.desc
	desc = leviathans.163b.desc
	desc = leviathans.163c.desc

	trigger = {
		from = { has_country_flag = trader_enclave_country_3 }
		has_country_flag = attacked_muutagans
	}

	option = {
		name = {
			trigger = { has_valid_civic = civic_fanatic_purifiers }
			text = SCUM
		}
		name = {
			trigger = { has_valid_civic = civic_hive_devouring_swarm }
			text = TASTY
		}
		name = {
			trigger = { has_valid_civic = civic_machine_terminator }
			text = EXTERMINATE
		}
		name = {
			trigger = { is_genocidal_infernal = yes }
			text = BURN
		}
		name = {
			trigger = {
				NOR = {
					has_valid_civic = civic_fanatic_purifiers
					has_valid_civic = civic_hive_devouring_swarm
					has_valid_civic = civic_machine_terminator
					is_genocidal_infernal = yes
				}
			}
			text = leviathans.156.a
		}
		default_hide_option = yes
	}
}

# AUTO-CANCELING STRATEGIC RESOURCE DEALS

# No More Energy (cancels Strategic Resource deals)
# via on_monthly_pulse | no scope
event = {
	id = leviathans.170
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_country = {
			is_country_type = default
			resource_stockpile_compare = { resource = energy value <= 0 }
			OR = {
				has_active_xuracorp_trade = yes
				has_active_riggan_trade = yes
				has_active_muutagan_trade = yes
			}
		}
	}

	immediate = {
		every_country = {
			limit = {
				is_country_type = default
				resource_stockpile_compare = { resource = energy value <= 0 }
				OR = {
					has_active_xuracorp_trade = yes
					has_active_riggan_trade = yes
					has_active_muutagan_trade = yes
				}
			}
			country_event = { id = leviathans.171 }
		}
	}
}
# No More Energy: Notification (via an every_country)
# this = country
country_event = {
	id = leviathans.171
	title = leviathans.171.name
	desc = leviathans.171.desc
	picture = GFX_evt_strategic_resources
	show_sound = event_administrative_work
	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				OR = {
					has_modifier = enclave_trade_1_xur
					has_modifier = enclave_trade_2_xur
					has_modifier = enclave_trade_3_xur
					has_modifier = enclave_trade_4_xur
					has_modifier = enclave_trade_5_xur
				}
			}
			switch = {
				trigger = has_modifier
				enclave_trade_1_xur = { remove_modifier = enclave_trade_1_xur }
				enclave_trade_2_xur = { remove_modifier = enclave_trade_2_xur }
				enclave_trade_3_xur = { remove_modifier = enclave_trade_3_xur }
				enclave_trade_4_xur = { remove_modifier = enclave_trade_4_xur }
				enclave_trade_5_xur = { remove_modifier = enclave_trade_5_xur }
			}
			event_target:xuracorp_country = {
				add_trust = {
					who = root
					amount = -20
				}
			}
		}
		if = {
			limit = {
				OR = {
					has_modifier = enclave_trade_1_rig
					has_modifier = enclave_trade_2_rig
					has_modifier = enclave_trade_3_rig
					has_modifier = enclave_trade_4_rig
					has_modifier = enclave_trade_5_rig
				}
			}
			switch = {
				trigger = has_modifier
				enclave_trade_1_rig = { remove_modifier = enclave_trade_1_rig }
				enclave_trade_2_rig = { remove_modifier = enclave_trade_2_rig }
				enclave_trade_3_rig = { remove_modifier = enclave_trade_3_rig }
				enclave_trade_4_rig = { remove_modifier = enclave_trade_4_rig }
				enclave_trade_5_rig = { remove_modifier = enclave_trade_5_rig }
			}
			event_target:riggan_country = {
				add_trust = {
					who = root
					amount = -20
				}
			}
		}
		if = {
			limit = {
				OR = {
					has_modifier = enclave_trade_1_mut
					has_modifier = enclave_trade_2_mut
					has_modifier = enclave_trade_3_mut
					has_modifier = enclave_trade_4_mut
					has_modifier = enclave_trade_5_mut
				}
			}
			switch = {
				trigger = has_modifier
				enclave_trade_1_mut = { remove_modifier = enclave_trade_1_mut }
				enclave_trade_2_mut = { remove_modifier = enclave_trade_2_mut }
				enclave_trade_3_mut = { remove_modifier = enclave_trade_3_mut }
				enclave_trade_4_mut = { remove_modifier = enclave_trade_4_mut }
				enclave_trade_5_mut = { remove_modifier = enclave_trade_5_mut }
			}
			event_target:muutagan_country = {
				add_trust = {
					who = root
					amount = -20
				}
			}
		}
	}

	option = {
		name = leviathans.171.a
		custom_tooltip = enclave_energy_trade_ended
		custom_tooltip = opinion-20
	}
}

##################
# ARTISAN ENCLAVE
##################

# leviathans.285-299	Communications established
# leviathans.300		Main Menu
# leviathans.304		Post-Sale Thanks (all-purpose)
# leviathans.305		Commission Art Monument
# leviathans.310-325	Patronage
# leviathans.330-337	Festival of Worlds
# leviathans.340		Art College
# leviathans.345		Ministry of Culture

# NOTE: any changes to these event IDs should be reflected in the has_artisan_event = {} scripted effect.

# ESTABLISH COMMUNICATIONS

# Artisans gatekeeper event
# via on_custom_diplomacy | this = target country (player); from = country being contacted
country_event = {
	id = leviathans.285
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_artisan_event = no
		from = {
			is_country_type = enclave
			has_country_flag = artist_enclave_country
		}
	}

	immediate = {
		if = {
			limit = {
				NOT = { exists = event_target:artist_enclave_country }
			}
			from = {
				save_global_event_target_as = artist_enclave_country
			}
		}
		country_event = { id = leviathans.300 }
	}
}

# Communications established (establishing scopes)
# via finish_first_contact_effect / action.11 / leviathans.98
# this = enclave country
country_event = {
	id = leviathans.290
	hide_window = yes
	is_triggered_only = yes

	# The 'ignores' flag may be set (indefinitely) during an act of aggression towards the Artisans, OR as a timed flag following certain actions the Artisans takes towards the player.
	immediate = {
		from = {
			if = {
				limit = { has_country_flag = enclave_artist_ignores }
				country_event = { id = leviathans.301 } # Artisans refuse comms.
			}
			else = {
				country_event = { id = leviathans.295 } #Artisans introduction
			}
		}
	}
}

# Artisans Introduction
# this = player country | from = Artisan Enclave country
country_event = {
	id = leviathans.295
	title = leviathans.300.name
	desc = leviathans.295.desc
	event_message_type = ENCLAVE_DIPLOMACY

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_artist_window"
	custom_gui_option = "enclave_artist_option"
	picture_event_data = {
		portrait = from
		room = enclave_artist_room
	}
	location = event_target:artisan_enclave_system

	option = {
		name = {
			trigger = { has_valid_civic = civic_fanatic_purifiers }
			text = SCUM
		}
		name = {
			trigger = { has_valid_civic = civic_hive_devouring_swarm }
			text = TASTY
		}
		name = {
			trigger = { has_valid_civic = civic_machine_terminator }
			text = EXTERMINATE
		}
		name = {
			trigger = { is_genocidal_infernal = yes }
			text = BURN
		}
		name = {
			trigger = {
				NOR = {
					has_valid_civic = civic_fanatic_purifiers
					has_valid_civic = civic_hive_devouring_swarm
					has_valid_civic = civic_machine_terminator
					is_genocidal_infernal = yes
				}
			}
			text = INTERESTING
		}
		default_hide_option = yes
	}
}

# MAIN MENU

# Artisans Main Menu
country_event = {
	id = leviathans.300
	title = leviathans.300.name
	desc = {
		trigger = {
			NOT = { has_country_flag = enclave_artist_encountered }
		}
		text = leviathans.300.desc
	}
	desc = {
		trigger = {
			has_country_flag = enclave_artist_encountered
		}
		text = leviathans.300a.desc
		text = leviathans.300b.desc
		text = leviathans.300c.desc
	}
	event_message_type = ENCLAVE_DIPLOMACY
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_artist_window"
	custom_gui_option = "enclave_artist_option"
	picture_event_data = {
		portrait = event_target:artist_enclave_country
		room = enclave_artist_room
	}
	location = event_target:artisan_enclave_system

	trigger = {
		exists = event_target:artist_enclave_country
		NOT = {	has_country_flag = enclave_artist_ignores }
	}

	immediate = {
		set_country_flag = enclave_artist_encountered
	}

	# Commission Art Monument
	option = {
		name = leviathans.300.a
		trigger = {
			check_variable = {
				which = artist_monument_purchased
				value < 5
			}
			is_homicidal = no
		}
		hidden_effect = {
			country_event = { id = leviathans.305 }
		}
	}
	# Commission Art Monument (bought too many)
	option = {
		name = leviathans.300.a
		response_text = leviathans.300.a.reply
		is_dialog_only = yes
		trigger = {
			check_variable = {
				which = artist_monument_purchased
				value >= 5
			}
			is_homicidal = no
		}
	}
	# Become a Patron
	option = {
		name = leviathans.300.b
		trigger = {
			NOR = {
				is_homicidal = yes
				has_modifier = enclave_artist_patron
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.310 }
		}
	}
	# Commission a Festival
	option = {
		name = leviathans.300.c
		trigger = {
			NOR = {
				has_ethic = ethic_gestalt_consciousness
				is_homicidal = yes
				has_country_flag = artist_festival_purchased
			}
		}
		allow = {
			custom_tooltip = {
				text = leviathans.300.c.allow
				NOT = {
					has_country_flag = artist_festival_purchased
				}
				event_target:artist_enclave_country = {
					trust = {
						who = root
						value >= 50
					}
				}
			}
			custom_tooltip = {
				text = leviathans.300.c.outofstock
				NOT = {
					has_country_flag = artist_festival_purchased
				}
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.330 }
		}
	}
	# Art College (conditional: shared space only)
	option = {
		name = leviathans.300.g
		trigger = {
			is_homicidal = no
			event_target:artist_enclave_country = {
				NOT = {
					has_country_flag = art_college@root
				}
			}
			OR = {
				any_system_within_border = {
					has_star_flag = enclave
					any_fleet_in_system = {
						exists = owner
						owner = {
							is_same_value = event_target:artist_enclave_country
						}
					}
				}
				any_owned_fleet = {
					is_waystation_ship = yes
					solar_system = {
						has_star_flag = enclave
						any_fleet_in_system = {
							exists = owner
							owner = {
								is_same_value = event_target:artist_enclave_country
							}
						}
					}
				}
			}
		}
		allow = {
			custom_tooltip = {
				fail_text = leviathans.300.g.opinion
				event_target:artist_enclave_country = {
					trust = {
						who = root
						value >= 50
					}
				}
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.340 }
		}
	}
	# Ministry of Culture (conditional: follows a particular Patron event)
	option = {
		name = leviathans.300.f
		trigger = {
			has_country_flag = enclave_artist_patron_event_1
			NOR = {
				is_homicidal = yes
				has_country_flag = artist_building_patron
			}
			exists = event_target:artist_enclave_country
			has_modifier = enclave_artist_patron
		}
		hidden_effect = {
			country_event = { id = leviathans.345 }
		}
	}
	# Tell Us More
	option = {
		name = leviathans.300.d
		trigger = {
			is_homicidal = no
		}
		is_dialog_only = yes
		response_text = leviathans.300.d.reply
	}
	# Goodbye
	option = {
		name = {
			trigger = { has_valid_civic = civic_fanatic_purifiers }
			text = SCUM
		}
		name = {
			trigger = { has_valid_civic = civic_hive_devouring_swarm }
			text = TASTY
		}
		name = {
			trigger = { has_valid_civic = civic_machine_terminator }
			text = EXTERMINATE
		}
		name = {
			trigger = { is_genocidal_infernal = yes }
			text = BURN
		}
		name = {
			trigger = {
				NOR = {
					has_valid_civic = civic_fanatic_purifiers
					has_valid_civic = civic_hive_devouring_swarm
					has_valid_civic = civic_machine_terminator
					is_genocidal_infernal = yes
				}
			}
			text = leviathans.502.a
		}
		default_hide_option = yes
	}
}

# Artists Ignore Diplomacy (after stealing from you or being attacked by you)
# via on_custom_diplomacy | from = Artist Enclave country
country_event = {
	id = leviathans.301
	title = leviathans.301.name
	desc = {
		trigger = {
			has_country_flag = enclave_artist_encountered
		}
		text = leviathans.301.desc
	}
	desc = {
		trigger = {
			NOT = { has_country_flag = enclave_artist_encountered }
		}
		text = leviathans.301.desc.unknown
	}
	picture = GFX_evt_space_station
	show_sound = event_radio_chatter
	location = event_target:artisan_enclave_system
	is_triggered_only = yes
	event_message_type = ENCLAVE_DIPLOMACY

	trigger = {
		from = {
			is_country_type = enclave
			has_country_flag = artist_enclave_country
		}
		has_country_flag = enclave_artist_ignores
	}

	option = {
		name = {
			trigger = { has_valid_civic = civic_fanatic_purifiers }
			text = SCUM
		}
		name = {
			trigger = { has_valid_civic = civic_hive_devouring_swarm }
			text = TASTY
		}
		name = {
			trigger = { has_valid_civic = civic_machine_terminator }
			text = EXTERMINATE
		}
		name = {
			trigger = { is_genocidal_infernal = yes }
			text = BURN
		}
		# Previously met the Artisans
		name = {
			trigger = {
				has_country_flag = enclave_artist_encountered
				NOR = {
					has_valid_civic = civic_fanatic_purifiers
					has_valid_civic = civic_hive_devouring_swarm
					has_valid_civic = civic_machine_terminator
					is_genocidal_infernal = yes
				}
			}
			text = leviathans.301.a
		}
		# Not met the Artisans yet
		name = {
			trigger = {
				NOR = {
					has_valid_civic = civic_fanatic_purifiers
					has_valid_civic = civic_hive_devouring_swarm
					has_valid_civic = civic_machine_terminator
					has_country_flag = enclave_artist_encountered
				}
			}
			text = PECULIAR
		}
	}
}

# Post-Sale Thanks (all-purpose)
country_event = {
	id = leviathans.304
	base = leviathans.300
	desc_clear = yes
	desc = leviathans.304a.desc
	desc = leviathans.304b.desc
	desc = leviathans.304c.desc
	event_message_type = ENCLAVE_DIPLOMACY
}

# COMMISSION ART MONUMENT

country_event = {
	id = leviathans.305
	base = leviathans.300
	desc_clear = yes
	option_clear = yes

	desc = leviathans.305.desc
	event_message_type = ENCLAVE_DIPLOMACY

	option = {
		name = DEAL
		add_resource = { energy = -600 }
		custom_tooltip = opinion10
		custom_tooltip = leviathans.305.a.tooltip
		allow = {
			resource_stockpile_compare = {
				resource = energy
				value >= 600
			}
			nomad_can_afford_enclave_cost = { COST = 600 }
		}
		hidden_effect = {
			event_target:artist_enclave_country = {
				add_trust = {
					who = root
					amount = 10
				}
			}
			# Start/continue counting the number of Art Monuments bought
			if = {
				limit = {
					NOT = { has_country_flag = artist_monument_collector }
				}
				set_country_flag = artist_monument_collector
				set_variable = {
					which = artist_monument_purchased
					value = 1
				}
			}
			else_if = {
				limit = {
					has_country_flag = artist_monument_collector
				}
				change_variable = {
					which = artist_monument_purchased
					value = 1
				}
			}
			# Post-Sale Thanks
			country_event = { id = leviathans.304 }
		}
	}
	option = {
		name = TOOPOOR
		trigger = {
			resource_stockpile_compare = {
				resource = energy
				value < 600
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.300 }
		}
	}
	option = {
		name = leviathans.110.d
		trigger = {
			resource_stockpile_compare = {
				resource = energy
				value >= 600
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.300 }
		}
	}
	# Goodbye
	option = {
		name = NODEAL
		default_hide_option = yes
	}
}

# PATRONAGE

# Become a Patron
country_event = {
	id = leviathans.310
	base = leviathans.300
	desc_clear = yes
	option_clear = yes
	desc = leviathans.310.desc
	event_message_type = ENCLAVE_DIPLOMACY

	immediate = {
		# Set costs based on population
		if = {
			limit = {
				pop_amount < 6000
			}
			set_variable = {
				which = artisan_patronage_cost
				value = -1000
			}
		}
		else_if = {
			limit = {
				pop_amount >= 6000
				pop_amount < 12000
			}
			set_variable = {
				which = artisan_patronage_cost
				value = -2000
			}
		}
		else_if = {
			limit = {
				pop_amount >= 12000
				pop_amount < 18000
			}
			set_variable = {
				which = artisan_patronage_cost
				value = -3000
			}
		}
		else_if = {
			limit = {
				pop_amount >= 18000
				pop_amount < 24000
			}
			set_variable = {
				which = artisan_patronage_cost
				value = -4000
			}
		}
		else = {
			set_variable = {
				which = artisan_patronage_cost
				value = -5000
			}
		}
		# Reset any 'seen all this content' flags from patronage updates
		remove_country_flag = enclave_artist_patron_content_seen
	}

	option = {
		name = DEAL
		allow = {
			resource_stockpile_compare = {
				resource = energy
				value >= -1 #flip to a positive value to make this comparison
				mult = artisan_patronage_cost
			}
			NOT = { has_modifier = enclave_artist_patron }
		}
		add_resource = {
			energy = 1
			mult = artisan_patronage_cost #negative value
		}
		add_modifier = {
			modifier = enclave_artist_patron
			days = 3600
		}
		custom_tooltip = opinion20
		hidden_effect = {
			country_event = { id = leviathans.313 } # Post-sale Thanks
			country_event = { id = leviathans.311 } # Patron events
			country_event = { id = leviathans.315 days = 3599 } # Renew Patronage
			event_target:artist_enclave_country = {
				add_trust = {
					who = root
					amount = 20
				}
			}
		}
	}
	# Back to Main Menu
	option = {
		name = leviathans.110.d
		hidden_effect = {
			country_event = { id = leviathans.300 }
		}
	}
	# Goodbye
	option = {
		name = NODEAL
		default_hide_option = yes
	}
}

# Patron Event Trigger
country_event = {
	id = leviathans.311
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = event_target:artist_enclave_country
		has_modifier = enclave_artist_patron
		NOT = { has_country_flag = enclave_artist_patron_content_seen }
	}

	immediate = {
		# Wrap this up if there's no more content to explore
		if = {
			limit = {
				check_variable = {
					which = artist_newsletter
					value > 4
				}
				has_country_flag = enclave_artist_patron_event_1
				has_country_flag = enclave_artist_patron_event_2
				has_country_flag = enclave_artist_patron_event_3
			}
			set_country_flag = enclave_artist_patron_content_seen
		}
		# Patronage event or newsletter
		else = {
			random_list = {
				# Patron Newsletter (maximum: 4)
				20 = {
					modifier = {
						factor = 2
						check_variable = {
							which = artist_newsletter
							value < 1
						}
					}
					modifier = {
						factor = 2
						check_variable = {
							which = artist_newsletter
							value < 5
						}
					}
					modifier = {
						factor = 0
						check_variable = {
							which = artist_newsletter
							value > 4
						}
					}
					country_event = { id = leviathans.321 days = 500 random = 1000 }
				}
				# Patrons With Benefits (one-time)
				20 = {
					modifier = {
						factor = 0
						OR = {
							has_country_flag = enclave_artist_patron_event_1
							has_country_flag = artist_building_patron
						}
					}
					country_event = { id = leviathans.322 days = 500 random = 1000 }
				}
				# Lackluster Update (one-time)
				20 = {
					modifier = {
						factor = 0
						OR = {
							has_country_flag = enclave_artist_patron_event_2
							check_variable = {
								which = artist_newsletter
								value < 1
							}
						}
					}
					country_event = { id = leviathans.323 days = 500 random = 1000 }
				}
				# Broken Artistry (one-time)
				20 = {
					modifier = {
						factor = 0
						has_country_flag = enclave_artist_patron_event_3
					}
					country_event = { id = leviathans.324 days = 500 random = 1000 }
				}
				# No result (run newsletter again)
				20 = {
					modifier = {
						factor = 0.20
						check_variable = {
							which = artist_newsletter
							value < 1
						}
					}
					country_event = { id = leviathans.311 days = 550 random = 1125 }
				}
			}
		}
	}
}

# Post-Sale Thanks
country_event = {
	id = leviathans.313
	base = leviathans.300
	desc_clear = yes
	desc = leviathans.310.a.reply
	event_message_type = ENCLAVE_DIPLOMACY
}

#Patronage renewal
country_event = {
	id = leviathans.315
	base = leviathans.310
	desc_clear = yes
	desc = leviathans.315.desc
	event_message_type = ENCLAVE_DIPLOMACY

	auto_opens = no
	notification_event_icon = "GFX_message_enclave_diplomatic_interactions"
	show_sound = "diplomatic_notification"

	trigger = {
		has_modifier = enclave_artist_patron
	}

	immediate = {
		if = {
			limit = {
				NOT = {
					has_country_flag = 10yr_patronage
				}
			}
			set_country_flag = 10yr_patronage
		}
		remove_modifier = enclave_artist_patron
	}
}

# Patron Newsletter
country_event = {
	id = leviathans.321
	base = leviathans.300
	desc_clear = yes
	option_clear = yes
	event_message_type = ENCLAVE_DIPLOMACY

	title = leviathans.321.name
	desc = {
		trigger = {
			text = "leviathans.321.desc"
			success_text = {
				text = "leviathans.321.desc.a"
				check_variable = {
					which = artist_newsletter
					value = 1
				}
			}
			success_text = {
				text = "leviathans.321.desc.b"
				check_variable = {
					which = artist_newsletter
					value = 2
				}
			}
			success_text = {
				text = "leviathans.321.desc.c"
				check_variable = {
					which = artist_newsletter
					value = 3
				}
			}
			success_text = {
				text = "leviathans.321.desc.d"
				check_variable = {
					which = artist_newsletter
					value = 4
				}
			}
		}
	}

	trigger = {
		exists = event_target:artist_enclave_country
		has_modifier = enclave_artist_patron
		NOT = { has_country_flag = enclave_artist_ignores }
	}

	immediate = {
		if = {
			limit = {
				check_variable = {
					which = artist_newsletter
					value < 1
				}
			}
			set_variable = {
				which = artist_newsletter
				value = 1
			}
		}
		else = {
			change_variable = {
				which = artist_newsletter
				value = 1
			}
		}
	}

	# Donate
	option = {
		name = leviathans.321.a
		add_resource = {
			energy = -500
			influence = 50
		}
		allow = {
			resource_stockpile_compare = { resource = energy value >= 500 }
			nomad_can_afford_enclave_cost = { COST = 500 }
		}
		hidden_effect = {
			country_event = { id = leviathans.304 }
		}
	}
	# Cannot afford to donate
	option = {
		name = leviathans.321.c
		hidden_effect = {
			country_event = { id = leviathans.325 }
		}
	}
	# Unsubscribe
	option = {
		name = leviathans.321.b
		default_hide_option = yes
		hidden_effect = {
			set_variable = {
				which = artist_newsletter
				value = 5
			}
			hidden_effect = {
				country_event = { id = leviathans.325 }
			}
		}
	}

	after = {
		hidden_effect = {
			country_event = { id = leviathans.311 days = 240 random = 90 }
		}
	}
}

# Patrons With Benefits (Ministry of Culture)
country_event = {
	id = leviathans.322
	base = leviathans.300
	desc_clear = yes
	option_clear = yes

	title = leviathans.322.name
	desc = leviathans.322.desc

	trigger = {
		exists = event_target:artist_enclave_country
		has_modifier = enclave_artist_patron
		NOR = {
			has_country_flag = enclave_artist_ignores
			has_country_flag = artist_building_patron
		}
	}

	immediate = {
		set_country_flag = enclave_artist_patron_event_1
	}

	# Purchase Ministry of Culture
	option = {
		name = DEAL
		if = {
			limit = { is_hive_empire = yes }
			custom_tooltip = leviathans.322.a.tooltip.hive
		}
		else_if = {
			limit = { is_machine_empire = yes }
			custom_tooltip = leviathans.322.a.tooltip.machine
		}
		else = {
			custom_tooltip = leviathans.322.a.tooltip
		}
		allow = {
			resource_stockpile_compare = { resource = energy value >= 2000 }
			nomad_can_afford_enclave_cost = { COST = 2000 }
		}
		add_resource = { energy = -2000 }
		hidden_effect = {
			set_country_flag = artist_building_patron
		}
	}
	# Too expensive
	option = {
		name = TOOPOOR
		trigger = {
			resource_stockpile_compare = { resource = energy value < 2000 }
		}
	}
	# Decline
	option = {
		name = NODEAL
		trigger = {
			resource_stockpile_compare = { resource = energy value >= 2000 }
		}
	}

	after = {
		hidden_effect = {
			country_event = { id = leviathans.311 days = 300 random = 75 }
		}
	}
}

# Lackluster Update (Artist's Block)
country_event = {
	id = leviathans.323
	base = leviathans.300
	desc_clear = yes
	option_clear = yes

	title = leviathans.323.name
	desc = leviathans.323.desc

	trigger = {
		exists = event_target:artist_enclave_country
		has_modifier = enclave_artist_patron
		NOT = { has_country_flag = enclave_artist_ignores }
	}

	immediate = {
		set_country_flag = enclave_artist_patron_event_2
	}

	# Commiserations
	option = {
		name = leviathans.323.a
		custom_tooltip = opinion10
		hidden_effect = {
			event_target:artist_enclave_country = {
				add_trust = {
					who = root
					amount = 10
				}
			}
			country_event = { id = leviathans.311 days = 300 random = 75 }
		}
	}
	# Demand (an often partial) refund; cancel patronage
	option = {
		name = leviathans.323.b
		add_resource = { energy = 1000 }
		custom_tooltip = opinion-3
		remove_modifier = enclave_artist_patron
		hidden_effect = {
			event_target:artist_enclave_country = {
				add_trust = {
					who = root
					amount = -3
				}
			}
		}
	}
}

# Broken Artistry (gain resources from scrap)
country_event = {
	id = leviathans.324
	base = leviathans.300
	desc_clear = yes
	option_clear = yes

	title = leviathans.324.name
	desc = leviathans.324.desc

	trigger = {
		exists = event_target:artist_enclave_country
		has_modifier = enclave_artist_patron
		NOT = { has_country_flag = enclave_artist_ignores }
	}

	immediate = {
		set_country_flag = enclave_artist_patron_event_3
	}

	option = {
		name = leviathans.324.a
		add_resource = { minerals = 500 }
	}
	option = {
		name = leviathans.324.b
		add_resource = { influence = 50 }
	}

	after = {
		hidden_effect = {
			country_event = { id = leviathans.311 days = 300 random = 75 }
		}
	}
}

# Disappointment (patronage canceled)
country_event = {
	id = leviathans.325
	base = leviathans.321
	desc_clear = yes
	option_clear = yes

	desc = leviathans.325.desc

	option = {
		name = GOODBYE
	}
}

# FESTIVAL EVENTS

# Commission a Festival of Worlds
country_event = {
	id = leviathans.330
	base = leviathans.300
	desc_clear = yes
	option_clear = yes

	desc = leviathans.330.desc

	option = {
		name = DEAL
		allow = {
			resource_stockpile_compare = {
				resource = energy
				value >= 1000
			}
			nomad_can_afford_enclave_cost = { COST = 1000 }
		}
		add_resource = { energy = -1000 }
		custom_tooltip = opinion15
		add_modifier = {
			modifier = enclave_artist_festival
			days = @festivalDuration
		}
		hidden_effect = {
			event_target:artist_enclave_country = {
				add_trust = {
					who = root
					amount = 15
				}
			}
			set_timed_country_flag = {
				flag = artist_festival_purchased
				days = @festivalDuration
			}
			country_event = { id = leviathans.332 } # Post-Sale Thanks
			country_event = { id = leviathans.331 } # Festival Events
		}
	}
	option = {
		name = TOOPOOR
		trigger = {
			resource_stockpile_compare = {
				resource = energy
				value < 1000
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.300 }
		}
	}
	option = {
		name = NODEAL
		trigger = {
			resource_stockpile_compare = {
				resource = energy
				value >= 1000
			}
		}
		default_hide_option = yes
		hidden_effect = {
			country_event = { id = leviathans.300 }
		}
	}
}

# Festival Event Trigger
country_event = {
	id = leviathans.331
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_country_flag = artist_festival_purchased # In case we ever wish to loop this event
	}

	immediate = {
		random_list = {
			# The Outrage (crowd stampedes)
			10 = {
				modifier = {
					factor = 1.5
					is_authoritarian = yes
				}
				country_event = { id = leviathans.335 days = 250 random = 25 }
			}
			# The Joy (some artists ask to remain)
			10 = {
				modifier = {
					factor = 1.5
					OR = {
						is_xenophile = yes
						is_pacifist = yes
					}
				}
				country_event = { id = leviathans.336 days = 150 random = 25 }
			}
			# The Betrayal (theft)
			5 = {
				modifier = {
					factor = 1.5
					OR = {
						is_xenophobe = yes
						is_megacorp = yes
						is_specialist_subject_type = { TYPE = prospectorium }
						event_target:artist_enclave_country = {
							trust = {
								who = root
								value <= 50
							}
						}
					}
				}
				modifier = {
					factor = 0
					resource_stockpile_compare = {
						resource = energy
						value < 500 #Half of what they would steal
					}
				}
				country_event = { id = leviathans.337 days = 300 random = 50 }
			}
			75 = {
				# No outcome
			}
		}
	}
}

# Post-Sale Thanks
country_event = {
	id = leviathans.332
	base = leviathans.300
	desc_clear = yes
	desc = leviathans.330.a.reply
}

# The Outrage (people get trampled)
country_event = {
	id = leviathans.335
	title = leviathans.335.name
	desc = leviathans.335.desc
	picture = GFX_evt_alien_propaganda
	show_sound = event_planetary_riot
	location = event_target:this_planet
	is_triggered_only = yes

	trigger = {
		has_modifier = enclave_artist_festival
		NOT = { has_country_flag = enclave_artist_ignores }
	}

	immediate = {
		random_owned_planet = {
			save_event_target_as = this_planet
		}
	}

	option = {
		name = UNFORTUNATE
		add_modifier = {
			modifier = enclave_artist_festival_outrage
			days = 720
		}
	}
	option = {
		name = leviathans.335.b
		add_resource = { influence = -100 }
	}

	after = {
		event_target:this_planet = {
			random_owned_pop_group = {
				kill_single_pop = yes
			}
		}
	}
}

# The Joy (Artists want to move in)
country_event = {
	id = leviathans.336
	title = leviathans.336.name
	desc = leviathans.336.desc
	picture = GFX_evt_grand_speech
	show_sound = event_celebration
	location = event_target:this_planet
	is_triggered_only = yes

	trigger = {
		has_modifier = enclave_artist_festival
		NOT = { has_country_flag = enclave_artist_ignores }
	}

	immediate = {
		random_owned_planet = {
			weights = {
				base = 1
				modifier = {
					add = trigger:free_housing
				}
			}
			save_event_target_as = this_planet
		}
		event_target:artist_enclave_country = {
			species = {
				save_event_target_as = artist_species
			}
		}
	}

	option = {
		name = leviathans.336.a
		event_target:this_planet = {
			create_pop_group = {
				species = event_target:artist_species
				ethos = {
					ethic = "ethic_xenophile"
				}
			}
			create_pop_group = {
				species = event_target:artist_species
				ethos = {
					ethic = "ethic_xenophile"
				}
			}
			hidden_effect = {
				every_owned_pop_group = {
					limit = { is_same_species = event_target:artist_species }
					modify_species = {
						ideal_planet_class = event_target:this_planet
					}
				}
			}
		}
	}
	option = {
		name = leviathans.336.b
	}
}

# The Betrayal (Artists flee and steal your stuff)
country_event = {
	id = leviathans.337
	title = leviathans.337.name
	desc = leviathans.337.desc
	picture = GFX_evt_news_room
	show_sound = event_planetary_riot
	location = event_target:artisan_enclave_system

	is_triggered_only = yes

	trigger = {
		has_modifier = enclave_artist_festival
		resource_stockpile_compare = {
			resource = energy
			value > 500 #somewhat reduces the impact of this theft
		}
	}

	immediate = {
		set_timed_country_flag = { flag = enclave_artist_ignores days = 3600 }
	}

	option = {
		name = leviathans.337.a
		remove_modifier = enclave_artist_festival
		add_resource = { energy = -1000 }
		hidden_effect = {
			remove_country_flag = artist_festival_purchased
		}
		root = {
			add_trust = {
				who = event_target:artist_enclave_country
				amount = -10
			}
		}
		custom_tooltip = leviathans.337.a.tooltip
	}
	option = {
		name = leviathans.337.b
		remove_modifier = enclave_artist_festival
		add_resource = { energy = -1000 }
		hidden_effect = {
			remove_country_flag = artist_festival_purchased
		}
		add_modifier = {
			modifier = cultural_clemency
			days = 3600
		}
		remove_country_flag = enclave_artist_ignores
		custom_tooltip = leviathans.337.b.tooltip
	}
	option = {
		name = leviathans.337.c
		allow = {
			is_xenophile = no
		}
		remove_modifier = enclave_artist_festival
		add_resource = { energy = -500 }
		hidden_effect = {
			remove_country_flag = artist_festival_purchased
		}
		add_modifier = {
			modifier = tent_heist
			days = 3600
		}
		remove_country_flag = enclave_artist_ignores
		custom_tooltip = leviathans.337.a.tooltip
	}
}

# ART COLLEGE

country_event = {
	id = leviathans.340
	base = leviathans.300
	desc_clear = yes
	option_clear = yes

	title = leviathans.340.name
	desc = leviathans.340.desc

	immediate = {
		if = {
			limit = {
				is_nomadic = yes
			}
			random_owned_fleet = {
				limit = {
					is_waystation_ship = yes
					solar_system = {
						has_star_flag = enclave
						any_fleet_in_system = {
							exists = owner
							owner = {
								is_same_value = event_target:artist_enclave_country
							}
						}
					}
				}
				solar_system = {
					save_event_target_as = artist_system
				}
			}
		}
		else = {
			random_system_within_border = {
				limit = {
					any_fleet_in_system = {
						exists = owner
						owner = {
							is_same_value = event_target:artist_enclave_country
						}
					}
				}
				save_event_target_as = artist_system
			}
		}
		event_target:artist_enclave_country = {
			set_country_flag = art_college@root
		}
	}

	option = { # Back
		name = EXCELLENT
		custom_tooltip = leviathans.340.tooltip
		trigger = {
			is_nomadic = no
		}
	}

	option = { # Back
		name = EXCELLENT
		custom_tooltip = leviathans.340.tooltip_nomads
		trigger = {
			is_nomadic = yes
		}
	}

	after = {
		hidden_effect = {
			country_event = { id = leviathans.304 }
		}
	}
}

# MINISTRY OF CULTURE

country_event = {
	id = leviathans.345
	base = leviathans.300
	desc_clear = yes
	option_clear = yes

	title = leviathans.345.name
	desc = leviathans.345.desc

	option = {
		name = DEAL
		if = {
			limit = { NOT = { has_ethic = ethic_gestalt_consciousness } }
			custom_tooltip = leviathans.322.a.tooltip
		}
		else_if  = {
			limit = { is_machine_empire = no }
			custom_tooltip = leviathans.322.a.tooltip.hive
		}
		else_if = {
			limit = { is_machine_empire = yes }
			custom_tooltip = leviathans.322.a.tooltip.machine
		}
		allow = {
			resource_stockpile_compare = { resource = energy value >= 2000 }
			nomad_can_afford_enclave_cost = { COST = 2000 }
		}
		add_resource = { energy = -2000 }
		hidden_effect = {
			set_country_flag = artist_building_patron
			country_event = { id = leviathans.304 } # Post-Sale Thanks
		}
	}
	option = {
		name = TOOPOOR
		trigger = {
			resource_stockpile_compare = { resource = energy value < 2000 }
		}
		hidden_effect = {
			country_event = { id = leviathans.300 }
		}
	}
	option = {
		name = NODEAL
		trigger = {
			resource_stockpile_compare = { resource = energy value >= 2000 }
		}
		hidden_effect = {
			country_event = { id = leviathans.300 }
		}
	}
}

# ARTISAN ENCLAVE ATTACKED

# Attacked Artisan Enclave (HIDDEN)
# via on_entering_battle
# this = owner of aggressor fleet | from = owner of attacked fleet | fromfrom = aggressor fleet | fromfromfrom = attacked fleet
country_event = {
	id = leviathans.350
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		from = {
			has_country_flag = artist_enclave_country
		}
	}

	immediate = {
		if = {
			limit = {
				has_modifier = enclave_artist_patron
			}
			remove_modifier = enclave_artist_patron
		}
		if = {
			limit = {
				has_modifier = enclave_artist_festival
			}
			remove_modifier = enclave_artist_festival
			#A related, timed flag is not removed here because its cooldown is much longer than that of the modifier
		}
		if = {
			limit = {
				NOT = { has_country_flag = enclave_artist_ignores }
			}
			set_country_flag = enclave_artist_ignores
		}
	}
}

# Artisan Enclave Starbase destroyed (HIDDEN)
# via on_fleet_destroyed_victim
# this = owner of attacked fleet | from = owner of aggressor fleet  | fromfrom = destroyed fleet | fromfromfrom = attacking fleet
country_event = {
	id = leviathans.351
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_country_flag = artist_enclave_country
	}

	immediate = {
		fromfrom = {
			remove_fleet_flag = artist_enclave_station
			solar_system = {
				remove_star_flag = guardians_artists_system
				save_event_target_as = destroyed_station_location
			}
			# If this was their capital but another starbase exists, move capital
			if = {
				limit = {
					is_custom_capital_location = yes
					owner = {
						any_controlled_fleet = {
							has_fleet_flag = artist_enclave_station
						}
					}
				}
				owner = {
					random_controlled_fleet = {
						limit = { has_fleet_flag = artist_enclave_station }
						save_event_target_as = newCustomCapital
					}
					set_custom_capital_location = event_target:newCustomCapital
				}
				# Announce the change to all but the attacking empire
				every_playable_country = {
					limit = {
						has_communications = root
						NOT = { is_same_value = root.from }
					}
					country_event = { id = leviathans.352 }
				}
				random_playable_country = {
					observer_event = { id = observer.11 }
				}
			}
			else_if = { #The capital wasn't hit
				limit = {
					is_custom_capital_location = no
					owner = {
						any_controlled_fleet = {
							has_fleet_flag = artist_enclave_station
						}
					}
				}
				# Announce the change to all but the attacking empire
				every_playable_country = {
					limit = {
						has_communications = root
						NOT = { is_same_value = root.from }
					}
					country_event = { id = leviathans.352 }
				}
				random_playable_country = {
					observer_event = { id = observer.11 }
				}
			}
			# If this was their last starbase, announce their demise
			else = {
				every_playable_country = {
					limit = {
						has_communications = root
						NOT = { is_same_value = root.from }
					}
					country_event = { id = leviathans.353 }
				}
				random_playable_country = {
					observer_event = { id = observer.12 }
				}
			}
		}
	}
}

# An Artisan Starbase has been destroyed
country_event = {
	id = leviathans.352
	title = leviathans.300.name
	desc = leviathans.352.desc
	picture = GFX_evt_exploding_ship
	show_sound = event_structural_collapse
	location = event_target:destroyed_station_location

	is_triggered_only = yes

	option = {
		name = OK
		trigger = {
			has_country_flag = enclave_artist_ignores
		}
	}
	option = {
		name = WORRYING
	}
}

# All Artisan Starbases have been destroyed
country_event = {
	id = leviathans.353
	title = leviathans.300.name
	desc = leviathans.353.desc
	picture = GFX_evt_exploding_ship
	show_sound = event_super_explosion
	location = event_target:destroyed_station_location

	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				has_modifier = enclave_artist_patron
			}
			remove_modifier = enclave_artist_patron
		}
		if = {
			limit = {
				OR = {
					has_modifier = enclave_artist_festival
					has_country_flag = artist_festival_purchased
				}
			}
			remove_modifier = enclave_artist_festival
			remove_country_flag = artist_festival_purchased
		}
	}

	option = {
		name = OK
		custom_tooltip = leviathans.307.a.tooltip
		trigger = {
			has_country_flag = enclave_artist_ignores
		}
	}
	option = {
		name = TERRIBLE
		custom_tooltip = leviathans.307.a.tooltip
	}
}

# Destroyed an Artisan Enclave Starbase
# via on_fleet_destroyed_perp
# this = owner of aggressor fleet | from = owner of attacked fleet | fromfrom = aggressor fleet | fromfromfrom = attacked fleet
country_event = {
	id = leviathans.354
	title = leviathans.300.name
	desc = {
		trigger = {
			switch = {
				trigger = has_country_flag
				enclave_artist_encountered = { text = leviathans.354.desc }
				default = { text = leviathans.354.desc.unknown }
			}
		}
	}
	picture = GFX_evt_exploding_ship
	show_sound = event_structural_collapse
	location = fromfrom
	is_triggered_only = yes

	trigger = {
		from = {
			has_country_flag = artist_enclave_country
		}
	}

	immediate = {
		set_country_flag = destroyed_artist # Achievement
		fromfrom = {
			solar_system = {
				save_event_target_as = station_system
			}
		}
	}

	option = {
		name = EXCELLENT
		add_resource = {
			energy = 2000
			minerals = 2000
		}
	}
}

##################
# CURATOR ENCLAVE
##################

# leviathans.500					Main Menu
# leviathans.501-502				Communications established
# leviathans.507,509				Curator Insight (research modifier)
# leviathans.508,510,515-556,4000	Guardians/Leviathans info
# leviathans.511					Think Tank
# leviathans.590					Scientist
# leviathans.598					Scientist Trait for Gestalts
# leviathans.599					Intel (on empires)
# leviathans.600					L-Cluster Clue
# leviathans.592-597				Curators attacked

# NOTE: any changes to these event IDs should be reflected in the has_curator_event = {} scripted effect.

# ESTABLISH COMMUNICATIONS

# Curators gatekeeper event
# via on_custom_diplomacy | this = target country (player); from = country being contacted
country_event = {
	id = leviathans.499
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_curator_event = no
		from = {
			is_country_type = enclave
			has_country_flag = curator_enclave_country
		}
	}

	immediate = {
		if = {
			limit = {
				NOT = { exists = event_target:curator_enclave_country }
			}
			from = {
				save_global_event_target_as = curator_enclave_country
			}
		}
		country_event = { id = leviathans.500 }
	}
}

# Communications established (establishing scopes)
# via finish_first_contact_effect / action.11 / leviathans.98
# this = enclave country
country_event = {
	id = leviathans.501
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		from = {
			country_event = { id = leviathans.502 }
		}
	}
}

# Curator Introduction
# this = player country | from = Artisan Enclave country
country_event = {
	id = leviathans.502
	title = leviathans.502.name
	# First time meeting any Curator order
	desc = {
		text = leviathans.502a.desc
		trigger = {
			NOT = { has_country_flag = curator_intro }
		}
	}
	# In case we've already met a different Curator order
	desc = {
		text = leviathans.502b.desc
		trigger = { has_country_flag = curator_intro }
	}
	diplomatic = yes
	custom_gui = "enclave_curator_window"
	custom_gui_option = "enclave_curator_option"
	picture_event_data = {
		portrait = from
		room = enclave_curator_room
	}
	location = event_target:curator_enclave_system
	is_triggered_only = yes
	event_message_type = ENCLAVE_DIPLOMACY

	immediate = {
		set_country_flag = curator_intro
	}

	option = {
		trigger = {
			OR = {	# This is a hack to display the civic icon if needed
				is_galactic_curators_empire = yes
				is_galactic_curators_empire = no
			}
		}
		name = {
			trigger = {
				switch = {
					trigger = has_valid_civic
					civic_fanatic_purifiers = { text = SCUM }
					civic_hive_devouring_swarm = { text = TASTY }
					civic_machine_terminator = { text = EXTERMINATE }
					civic_scorched_earth = { text = BURN }
					civic_hive_scorched_earth = { text = BURN }
					default = { text = leviathans.502.a }
				}
			}
		}
		default_hide_option = yes
		if = {
			limit = {
				is_galactic_curators_empire = yes
			}
			from = {
				add_trust = {
					who = prev
					amount = 20
				}
			}
		}
	}
}

# MAIN MENU

# Curator Main Menu
country_event = {
	id = leviathans.500
	title = leviathans.500.name
	desc = leviathans.500a.desc
	desc = leviathans.500b.desc
	desc = leviathans.500c.desc
	desc = leviathans.500d.desc
	desc = leviathans.500e.desc
	desc = leviathans.500f.desc
	desc = leviathans.500g.desc
	desc = leviathans.500h.desc
	desc = leviathans.500i.desc
	desc = leviathans.500j.desc
	desc = leviathans.500k.desc
	desc = leviathans.500l.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_curator_window"
	custom_gui_option = "enclave_curator_option"
	picture_event_data = {
		portrait = event_target:curator_enclave_country
		room = enclave_curator_room
	}
	location = event_target:curator_enclave_system
	event_message_type = ENCLAVE_DIPLOMACY

	trigger = {
		exists = event_target:curator_enclave_country
		NOT = { has_country_flag = attacked_curators }
	}

	immediate = {
		set_country_flag = curator_intro
	}

	# Research (Curator Insight)
	option = {
		name = leviathans.500.b
		trigger = { is_homicidal = no }
		allow = {
			custom_tooltip = {
				fail_text = leviathans.500.b.alreadyaided
				NOT = { has_modifier = curator_insight }
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.507 }
		}
	}
	# Information about Guardians/Leviathans
	option = {
		name = leviathans.500.c
		trigger = { is_homicidal = no }
		hidden_effect = {
			country_event = { id = leviathans.508 }
		}
	}
	# Scientist
	option = {
		name = leviathans.500.d
		trigger = {
			is_homicidal = no
			is_gestalt = no
		}
		allow = {
			custom_tooltip = {
				fail_text = leviathans.500.d.opinion
				event_target:curator_enclave_country = {
					trust = {
						who = root
						value >= 50
					}
				}
			}
			custom_tooltip = {
				fail_text = leviathans.500.d.alreadyrecruited
				NOT = {
					any_owned_leader = { has_trait = leader_trait_curator }
				}
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.590 }
		}
	}
	# Gestalt Trait
	option = {
		name = leviathans.500.e
		trigger = {
			is_homicidal = no
			is_gestalt = yes
		}
		allow = {
			custom_tooltip = {
				fail_text = leviathans.500.e.opinion
				event_target:curator_enclave_country = {
					trust = {
						who = root
						value >= 50
					}
				}
			}
			custom_tooltip = {
				fail_text = leviathans.500.e.alreadyshared
				NOT = {
					any_owned_leader = { has_trait = leader_trait_curator }
				}
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.598 }
		}
	}
	# Intel
	option = {
		name = leviathans.500.h
		trigger = {
			is_homicidal = no
			any_country = {
				valid_curators_intel_trade_target = yes
			}
		}
		allow = {
			custom_tooltip = {
				fail_text = leviathans.500.d.opinion
				event_target:curator_enclave_country = {
					trust = {
						who = root
						value >= 50
					}
				}
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.599 }
		}
	}
	# Think Tank
	option = {
		name = leviathans.500.f
		trigger = {
			is_homicidal = no
			event_target:curator_enclave_country = {
				NOT = { has_country_flag = think_tank@root }
			}
			OR = {
				any_system_within_border = {
					has_star_flag = enclave
					any_fleet_in_system = {
						exists = owner
						owner = {
							is_same_value = event_target:curator_enclave_country
						}
					}
				}
				any_owned_fleet = {
					is_waystation_ship = yes
					solar_system = {
						has_star_flag = enclave
						any_fleet_in_system = {
							exists = owner
							owner = {
								is_same_value = event_target:curator_enclave_country
							}
						}
					}
				}
			}
		}
		allow = {
			custom_tooltip = {
				fail_text = leviathans.500.d.opinion
				event_target:curator_enclave_country = {
					trust = {
						who = root
						value >= 50
					}
				}
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.511 }
		}
	}
	# Infinity Machine's secret (after finishing Infinity Sphere chain)
	option = {
		name = leviathans.500.g
		trigger = {
			has_country_flag = pantagruel
			has_country_flag = asked_about_infinity_machine
			NOT = { has_country_flag = offered_information }
		}
		hidden_effect = {
			country_event = { id = leviathans.4000 }
		}
	}
	# L-Cluster Clue
	option = {
		name = leviathans.500.i
		trigger = {
			has_event_chain = l_cluster_chain
			NOR = {
				is_homicidal = yes
				has_global_flag = l_cluster_opened
				has_completed_event_chain_counter = {
					event_chain = l_cluster_chain
					counter = clues
				}
			}
		}
		allow = {
			custom_tooltip = {
				fail_text = leviathans.500.i.tooltip.noclue
				NOT = { has_country_flag = curator_clue_purchased }
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.600 }
		}
	}
	# Containment Vessel
	option = {
		name = leviathans.500.j
		trigger = {
			has_grand_archive_dlc = yes
			has_technology = tech_gravity_wells
			NOR = {
				has_country_flag = tech_containment_vessel_acquired
				has_technology = tech_containment_vessel
			}

		}
		allow = {
			custom_tooltip = {
				fail_text = leviathans.500.j.opinion
				event_target:curator_enclave_country = {
					trust = {
						who = root
						value >= 80
					}
				}
			}

			resource_stockpile_compare = {
				resource = energy
				value >= value:curator_purchase_cost|COST|5000|
			}
			nomad_can_afford_enclave_cost = { COST = 100 }
		}

		add_resource = {
			energy = -1
			mult = value:curator_purchase_cost|COST|5000|
		}

		add_research_option = tech_containment_vessel
		hidden_effect = {
			set_country_flag = tech_containment_vessel_acquired
		}
	}
	# Grand Archive Collection Amendments
	option = {
		name = leviathans.500.k
		trigger = {
			has_grand_archive_dlc = yes
			has_grand_archive = yes
			OR = {
				is_eligible_for_collection_stage_1_reward_any_reward = yes
				is_eligible_for_collection_stage_2_reward_any_reward = yes
				is_eligible_for_collection_stage_3_reward_any_reward = yes
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.4100 }
		}
	}
	option = {
		name = leviathans.500.k
		trigger = {
			has_grand_archive_dlc = yes
			has_grand_archive = yes
			is_eligible_for_collection_stage_1_reward_any_reward = no
			is_eligible_for_collection_stage_2_reward_any_reward = no
			is_eligible_for_collection_stage_3_reward_any_reward = no
			OR = {
				has_received_every_stage_1_reward = no
				has_received_every_stage_2_reward = no
				has_received_every_stage_3_reward = no
			}
		}
		is_dialog_only = yes
		response_text = leviathans.500.k.reply.reward_unavailable
	}
	option = {
		name = leviathans.500.k
		trigger = {
			has_grand_archive_dlc = yes
			has_grand_archive = yes
			has_received_every_stage_1_reward = yes
			has_received_every_stage_2_reward = yes
			has_received_every_stage_3_reward = yes
		}
		is_dialog_only = yes
		response_text = leviathans.500.k.reply.over
	}
	# Curator Navigation Guidance (Nomads)
	option = {
		name = leviathans.500.l
		trigger = {
			is_homicidal = no
			is_nomadic = yes
			has_ascension_perk = ap_wanderlust
			event_target:curator_enclave_country = {
				trust = { who = root  value >= 30 }
			}
			any_system = {
				OR = {
					AND = {
						has_star_flag = ancient_wonders_system
						root = {
							NOT = { has_country_flag = ancient_wonders_completed }
						}
					}
					AND = {
						has_star_flag = antique_threat_system
						root = {
							NOT = { has_country_flag = antique_threat_completed }
						}
					}
					AND = {
						has_star_flag = enclave
						root = {
							NOT = { has_country_flag = enclave_completed }
						}
					}
					AND = {
						has_star_flag = galactic_landmark_system
						root = {
							NOT = { has_country_flag = galactic_landmark_completed }
						}
					}
					AND = {
						has_star_flag = marauder_system
						root = {
							NOT = { has_country_flag = marauder_completed }
						}
					}
					AND = {
						has_star_flag = natural_spectacle_system
						root = {
							NOT = { has_country_flag = natural_spectacle_completed }
						}
					}
					AND = {
						has_star_flag = precursor_system
						root = {
							NOT = { has_country_flag = precursor_completed }
						}
					}
					AND = {
						has_star_flag = space_ecology_system
						root = {
							NOT = { has_country_flag = space_ecology_completed }
						}
					}
				}
				NOR = {
					has_star_flag = visited_by_nomad@root
					has_star_flag = curator_guidance_target@root
				}
			}
		}
		allow = {
			custom_tooltip = {
				fail_text = leviathans.500.l.opinion
				event_target:curator_enclave_country = {
					trust = { who = root  value >= 50 }
				}
			}
			resource_stockpile_compare = {
				resource = trade
				value >= 2500
			}
			custom_tooltip = {
				fail_text = leviathans.500.l.cooldown
				NOT = { has_country_flag = curator_guidance_cooldown }
			}
		}
		custom_tooltip = leviathans.500.l.tt
		add_resource = { trade = -2500 }
		set_timed_country_flag = { flag = curator_guidance_cooldown days = 180 }
		random_system = {
			limit = {
				OR = {
					AND = {
						has_star_flag = ancient_wonders_system
						root = {
							NOT = { has_country_flag = ancient_wonders_completed }
						}
					}
					AND = {
						has_star_flag = antique_threat_system
						root = {
							NOT = { has_country_flag = antique_threat_completed }
						}
					}
					AND = {
						has_star_flag = enclave
						root = {
							NOT = { has_country_flag = enclave_completed }
						}
					}
					AND = {
						has_star_flag = galactic_landmark_system
						root = {
							NOT = { has_country_flag = galactic_landmark_completed }
						}
					}
					AND = {
						has_star_flag = marauder_system
						root = {
							NOT = { has_country_flag = marauder_completed }
						}
					}
					AND = {
						has_star_flag = natural_spectacle_system
						root = {
							NOT = { has_country_flag = natural_spectacle_completed }
						}
					}
					AND = {
						has_star_flag = precursor_system
						root = {
							NOT = { has_country_flag = precursor_completed }
						}
					}
					AND = {
						has_star_flag = space_ecology_system
						root = {
							NOT = { has_country_flag = space_ecology_completed }
						}
					}
				}
				NOR = {
					has_star_flag = visited_by_nomad@root
					has_star_flag = curator_guidance_target@root
				}
			}
			save_event_target_as = curator_guidance_system
		}
		if = {
			limit = { exists = event_target:curator_guidance_system }
			event_target:curator_guidance_system = {
				set_star_flag = curator_guidance_target@root
				root = {
					create_point_of_interest = {
						id = curator_guidance_poi@prev
						name = curator_guidance_poi_name
						desc = curator_guidance_poi_desc
						event_chain = nomad_exploration_chain
						location = prev
					}
				}
			}
		}
		if = {
			limit = { NOT = { exists = event_target:curator_guidance_system } }
			add_resource = { trade = 2500 }
		}
		is_dialog_only = yes
		response_text = leviathans.500.l.desc
	}
	# Goodbye
	option = {
		name = {
			trigger = { has_valid_civic = civic_fanatic_purifiers }
			text = SCUM
		}
		name = {
			trigger = { has_valid_civic = civic_hive_devouring_swarm }
			text = TASTY
		}
		name = {
			trigger = { has_valid_civic = civic_machine_terminator }
			text = EXTERMINATE
		}
		name = {
			trigger = { is_genocidal_infernal = yes }
			text = BURN
		}
		name = {
			trigger = {
				NOR = {
					has_valid_civic = civic_fanatic_purifiers
					has_valid_civic = civic_hive_devouring_swarm
					has_valid_civic = civic_machine_terminator
					is_genocidal_infernal = yes
				}
			}
			text = GOODBYE
		}
		default_hide_option = yes
	}
}

# Post-Sale Thanks (all-purpose)
country_event = {
	id = leviathans.504
	base = leviathans.500
	desc_clear = yes
	desc = leviathans.504a.desc
	desc = leviathans.504b.desc
	desc = leviathans.504c.desc
	desc = leviathans.507.a.reply
	event_message_type = ENCLAVE_DIPLOMACY
}

# CURATOR INSIGHT RESEARCH MODIFIER

# Purchase Curator Insight
country_event = {
	id = leviathans.507
	base = leviathans.500
	desc_clear = yes
	option_clear = yes
	event_message_type = ENCLAVE_DIPLOMACY

	title = leviathans.507.name
	desc = leviathans.507.desc

	immediate = {
		# Set costs based on empire size
		# Base of 500 Energy
        set_variable = {
			which = curator_insight_cost
			value = 500
		}
        # +1% per Empire Size (same scaling as Edicts)
        # Ergo, 1000 Energy at 100 Empire Size
        multiply_variable = {
            which = curator_insight_cost
            value = value:edict_size_effect
        }
	}

	option = {
		name = leviathans.507.a
		allow = {
			NOT = { has_modifier = curator_insight }
			resource_stockpile_compare = {
				resource = energy
				value >= value:curator_purchase_cost|COST|curator_insight_cost|
			}
			nomad_can_afford_enclave_cost = { COST = 100 }
		}

		add_resource = {
			energy = -1
			mult = value:curator_purchase_cost|COST|curator_insight_cost|
		}

		add_modifier = {
			modifier = curator_insight
			days = 3600
		}
		custom_tooltip = opinion20
		hidden_effect = {
			set_country_flag = curator_insight_obtained
			country_event = { id = leviathans.504 } # Post-sale Thanks
			country_event = { id = leviathans.509 days = 3600 } # Renew
			event_target:curator_enclave_country = {
				add_trust = {
					who = root
					amount = 20
				}
			}
		}
	}
	# Back to main menu
	option = {
		name = leviathans.506.d
		hidden_effect = {
			country_event = { id = leviathans.500 }
		}
	}
	#Goodbye
	option = {
		name = GOODBYE
		default_hide_option = yes
	}
	# Fear of the Dark fallback in case you have an ongoing deal.
	option = {
		exclusive_trigger = {
			has_civic = civic_fanatic_purifiers
		}
		name = SCUM
	}
}

# Renew Curator Insight?
country_event = {
	id = leviathans.509
	base = leviathans.507
	desc_clear = yes
	event_message_type = ENCLAVE_DIPLOMACY

	auto_opens = no
	notification_event_icon = "GFX_message_enclave_diplomatic_interactions"
	show_sound = "diplomatic_notification"

	desc = leviathans.509.desc
}

# GUARDIANS/LEVIATHANS INFORMATION

# Guardians Menu
country_event = {
	id = leviathans.508
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	title = leviathans.508.name
	desc = leviathans.508.desc

	# Find a Leviathan
	option = {
		name = leviathans.508.a
		response_text = leviathans.508.a.reply
		trigger = {
			any_country = {
				is_guardian_country = yes
				NOT = { has_communications = root }
				num_fleets > 0
				any_controlled_fleet = {
					exists = solar_system
					solar_system = {
						has_star_flag = guardian
						is_curator_guardian_poi = no
					}
				}
			}
		}
		inline_script = {
			script = events/resource_cost_with_allow
			RESOURCE = energy
			AMOUNT = value:curator_purchase_cost|COST|300|
		}
		custom_tooltip = opinion10
		hidden_effect = {
			event_target:curator_enclave_country = {
				add_trust = {
					who = root
					amount = 10
				}
			}
			capital_scope = {
				closest_system = {
					min_steps = 0
					max_steps = 999
					limit = {
						has_star_flag = guardian
						is_curator_guardian_poi = no
						any_fleet_in_system = {
							exists = owner
							owner = {
								is_guardian_country = yes
								NOT = { has_communications = root }
							}
						}
					}
					random_fleet_in_system = {
						limit = {
							exists = owner
							owner = {
								is_guardian_country = yes
								NOT = { has_communications = root }
							}
						}
						owner = {
							switch = {
								trigger = is_country_type
								guardian_dragon = {
									create_curator_guardian_poi = {
										POI = curator_poi_dragon
									}
								}
								guardian_sphere = {
									create_curator_guardian_poi = {
										POI = curator_poi_technosphere
									}
								}
								guardian_horror = {
									create_curator_guardian_poi = {
										POI = curator_poi_horror
									}
								}
								guardian_stellarite = {
									create_curator_guardian_poi = {
										POI = curator_poi_stellarite
									}
								}
								guardian_hiver = {
									create_curator_guardian_poi = {
										POI = curator_poi_hiver
									}
								}
								guardian_fortress = {
									create_curator_guardian_poi = {
										POI = curator_poi_fortress
									}
								}
								guardian_wraith = {
									create_curator_guardian_poi = {
										POI = curator_poi_wraith
									}
								}
								guardian_dreadnought = {
									create_curator_guardian_poi = {
										POI = curator_poi_dreadnought
									}
								}
								guardian_hatchling = {
									create_curator_guardian_poi = {
										POI = curator_poi_hatchling
									}
								}
								guardian_scavenger_bot = {
									create_curator_guardian_poi = {
										POI = curator_poi_scavenger_bot
									}
								}
								guardian_elderly_tiyanki = {
									create_curator_guardian_poi = {
										POI = curator_poi_tiyanki
									}
								}
								default = {
									log_error = "No option in leviathans.508.a for Leviathan country [This.GetCountryType]"
								}
							}
						}
					}
				}
			}
		}
	}

	# Ether Drake
	option = {
		name = leviathans.508.b
		trigger = {
			any_country = {
				is_country_type = guardian_dragon
				has_communications = root
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.510 }
		}
	}
	# Enigmatic Fortress
	option = {
		name = leviathans.508.c
		trigger = {
			any_country = {
				is_country_type = guardian_fortress
				has_communications = root
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.515 }
		}
	}
	# Stellar Devourer
	option = {
		name = leviathans.508.d
		trigger = {
			any_country = {
				is_country_type = guardian_stellarite
				has_communications = root
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.520 }
		}
	}
	# Dimensional Horror
	option = {
		name = leviathans.508.e
		trigger = {
			any_country = {
				is_country_type = guardian_horror
				has_communications = root
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.525 }
		}
	}
	# Asteroid Hive
	option = {
		name = leviathans.508.f
		trigger = {
			any_country = {
				is_country_type = guardian_hiver
				has_communications = root
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.530 }
		}
	}
	# Infinity Machine
	option = {
		name = leviathans.508.g
		trigger = {
			any_country = {
				is_country_type = guardian_sphere
				has_communications = root
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.535 }
			set_country_flag = asked_about_infinity_machine
		}
	}
	# Automated Dreadnought
	option = {
		name = leviathans.508.h
		trigger = {
			any_country = {
				is_country_type = guardian_dreadnought
				has_communications = root
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.540 }
		}
	}
	# Wraith
	option = {
		name = leviathans.508.i
		trigger = {
			any_country = {
				is_country_type = guardian_wraith
				has_communications = root
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.545 }
		}
	}
	# Voidspawn
	option = {
		name = leviathans.508.j
		trigger = {
			any_country = {
				is_country_type = guardian_hatchling
				has_communications = root
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.550 }
		}
	}
	# Scavenger Bot
	option = {
		name = leviathans.508.k
		trigger = {
			any_country = {
				is_country_type = guardian_scavenger_bot
				has_communications = root
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.555 }
		}
	}
	# Tiyanki Matriarch
	option = {
		name = leviathans.508.l
		trigger = {
			any_country = {
				is_country_type = guardian_elderly_tiyanki
				has_communications = root
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.556 }
		}
	}
	# Infinity Machine (Pantagruel outcome)
	option = {
		name = leviathans.500.g
		trigger = {
			has_country_flag = pantagruel
			has_country_flag = asked_about_infinity_machine
			NOT = { has_country_flag = offered_information }
		}
		hidden_effect = {
			country_event = { id = leviathans.4000 }
		}
	}
	# Toxic God
	option = {
		name = leviathans.508.m
		trigger = {
			OR = {
				AND = {
					has_origin = origin_toxic_knights
					NOT = { has_global_flag = toxic_god_spawned }
				}
				any_country = {
					is_country_type = guardian_toxic_god
					has_communications = root
				}
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.558 }
		}
	}
	# Opus Sentinel
	option = {
		name = leviathans.508.n
		trigger = {
			exists = event_target:origin_unplugged_assimilator_empire
			event_target:origin_unplugged_assimilator_empire = {
				has_communications = root
				any_owned_fleet = {
					has_fleet_flag = machine_legacy_machine_core_fleet # see also 'event_target:origin_unplugged_opus_sentinel'
				}
			}
		}
		hidden_effect = {
			country_event = { id = leviathans.559 }
		}
	}

	# Back to main menu
	option = {
		name = leviathans.506.d
		hidden_effect = {
			country_event = { id = leviathans.500 }
		}
	}
	# Goodbye
	option = {
		name = GOODBYE
		default_hide_option = yes
	}
}

# NOTE: the following series of events features a mix of options which are unique to each Leviathan (defined in the event script), and a common set of standard options (defined in 'common/inline_script/enclaves/curators_guardians_options.txt'). Should any Leviathan be made weaker or stronger than the standard batch, be sure to define a bespoke set of event options for the "can we fight this?" queries.

# Ether Drake
country_event = {
	id = leviathans.510
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	title = leviathans.510.name
	desc = leviathans.510.desc

	# More info
	option = {
		name = leviathans.510.a
		response_text = leviathans.510.a.reply
		is_dialog_only = yes
	}
	# Purchase modifier
	option = {
		name = leviathans.510.b
		response_text = leviathans.510.b.reply
		trigger = {
			NOT = { has_modifier = draconic_beats }
		}
		inline_script = {
			script = events/resource_cost_with_allow
			RESOURCE = energy
			AMOUNT = value:curator_purchase_cost|COST|1000|
		}
		add_modifier = {
			modifier = draconic_beats
			days = -1
		}
		custom_tooltip = opinion20
		hidden_effect = {
			event_target:curator_enclave_country = {
				add_trust = {
					who = root
					amount = 20
				}
			}
		}
	}
	# Standard options
	inline_script = enclaves/curators_guardians_options
}

# Enigmatic Fortress
country_event = {
	id = leviathans.515
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	title = leviathans.515.name
	desc = leviathans.515.desc

	# The Fortress always recovers...
	option = {
		name = leviathans.515.a
		response_text = leviathans.515.a.reply
		is_dialog_only = yes
	}
	# Entering the Fortress
	option = {
		name = leviathans.515.b
		trigger = {
			NOT = { has_country_flag = bought_fortress_info_1 }
		}
		response_text = leviathans.515.b.reply
		inline_script = {
			script = events/resource_cost_with_allow
			RESOURCE = energy
			AMOUNT = value:curator_purchase_cost|COST|200|
		}
		hidden_effect = {
			set_country_flag = bought_fortress_info_1
		}
	}
	option = {
		name = leviathans.515.bb
		trigger = {
			has_country_flag = bought_fortress_info_1
		}
		response_text = leviathans.515.b.reply
	}
	# Who built it / puzzles and enigmas
	option = {
		name = leviathans.515.c
		trigger = {
			NOT = { has_country_flag = bought_fortress_info_2 }
		}
		response_text = leviathans.515.c.reply
		inline_script = {
			script = events/resource_cost_with_allow
			RESOURCE = energy
			AMOUNT = value:curator_purchase_cost|COST|200|
		}
		hidden_effect = {
			set_country_flag = bought_fortress_info_2
		}
	}
	option = {
		name = leviathans.515.cc
		trigger = {
			has_country_flag = bought_fortress_info_2
		}
		response_text = leviathans.515.c.reply
	}
	# Power source
	option = {
		name = leviathans.515.d
		trigger = {
			NOT = { has_country_flag = bought_fortress_info_3 }
		}
		response_text = leviathans.515.d.reply
		inline_script = {
			script = events/resource_cost_with_allow
			RESOURCE = energy
			AMOUNT = value:curator_purchase_cost|COST|200|
		}
		hidden_effect = {
			set_country_flag = bought_fortress_info_3
		}
	}
	option = {
		name = leviathans.515.dd
		trigger = {
			has_country_flag = bought_fortress_info_3
		}
		response_text = leviathans.515.d.reply
	}
	# Standard options
	inline_script = enclaves/curators_guardians_options
}

# Stellar Devourer
country_event = {
	id = leviathans.520
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	title = leviathans.520.name
	desc = leviathans.520.desc

	# More info
	option = {
		name = leviathans.510.a
		response_text = leviathans.520.a.reply
		is_dialog_only = yes
	}
	# Purchase modifier
	option = {
		name = leviathans.510.b
		response_text = leviathans.520.b.reply
		trigger = {
			NOT = { has_modifier = curator_buff_stellarite }
		}
		inline_script = {
			script = events/resource_cost_with_allow
			RESOURCE = energy
			AMOUNT = value:curator_purchase_cost|COST|1000|
		}
		add_modifier = {
			modifier = curator_buff_stellarite
			days = -1
		}
		custom_tooltip = opinion20
		hidden_effect = {
			event_target:curator_enclave_country = {
				add_trust = {
					who = root
					amount = 20
				}
			}
		}
	}
	# Standard options
	inline_script = enclaves/curators_guardians_options
}

# Dimensional Horror
country_event = {
	id = leviathans.525
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	title = leviathans.525.name
	desc = leviathans.525.desc

	# More info
	option = {
		name = leviathans.525.a
		response_text = leviathans.525.a.reply
		is_dialog_only = yes
	}
	# Purchase modifier
	option = {
		name = leviathans.525.b
		response_text = leviathans.525.b.reply
		trigger = {
			NOT = { has_modifier = dimensional_horror_weak_points }
		}
		inline_script = {
			script = events/resource_cost_with_allow
			RESOURCE = energy
			AMOUNT = value:curator_purchase_cost|COST|1000|
		}
		add_modifier = {
			modifier = dimensional_horror_weak_points
			days = -1
		}
		custom_tooltip = opinion20
		hidden_effect = {
			event_target:curator_enclave_country = {
				add_trust = {
					who = root
					amount = 20
				}
			}
		}
	}
	# Standard options
	inline_script = enclaves/curators_guardians_options
}

# Asteroid Hive
country_event = {
	id = leviathans.530
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	title = leviathans.530.name
	desc = leviathans.530.desc

	# More info
	option = {
		name = leviathans.530.a
		response_text = leviathans.530.a.reply
		is_dialog_only = yes
	}
	# Purchase modifier
	option = {
		name = leviathans.530.b
		response_text = leviathans.530.b.reply
		trigger = {
			NOT = { has_modifier = asteroid_hive_weak_points }
		}
		inline_script = {
			script = events/resource_cost_with_allow
			RESOURCE = energy
			AMOUNT = value:curator_purchase_cost|COST|2000|
		}
		add_modifier = {
			modifier = asteroid_hive_weak_points
			days = -1
		}
		custom_tooltip = opinion10
		hidden_effect = {
			event_target:curator_enclave_country = {
				add_trust = {
					who = root
					amount = 10
				}
			}
		}
	}
	# Standard options
	inline_script = enclaves/curators_guardians_options
}

# Infinity Machine
country_event = {
	id = leviathans.535
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	title = leviathans.535.name
	desc = leviathans.535.desc

	# More info
	option = {
		name = leviathans.510.a
		response_text = leviathans.535.a.reply
		is_dialog_only = yes
	}
	# Purchase modifier
	option = {
		name = leviathans.510.b
		response_text = leviathans.535.b.reply
		trigger = {
			NOT = { has_modifier = curator_buff_sphere }
		}
		inline_script = {
			script = events/resource_cost_with_allow
			RESOURCE = energy
			AMOUNT = value:curator_purchase_cost|COST|600|
		}
		add_modifier = {
			modifier = curator_buff_sphere
			days = -1
		}
		custom_tooltip = opinion15
		hidden_effect = {
			event_target:curator_enclave_country = {
				add_trust = {
					who = root
					amount = 15
				}
			}
		}
	}
	# Standard options
	inline_script = enclaves/curators_guardians_options
}

# Automated Dreadnought
country_event = {
	id = leviathans.540
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	title = leviathans.540.name
	desc = leviathans.540.desc

	# More info
	option = {
		name = leviathans.540.a
		response_text = leviathans.540.a.reply
		is_dialog_only = yes
	}
	# Purchase modifier
	option = {
		name = leviathans.540.b
		response_text = leviathans.540.b.reply
		trigger = {
			NOT = { has_modifier = automated_dreadnought_weak_points }
		}
		inline_script = {
			script = events/resource_cost_with_allow
			RESOURCE = energy
			AMOUNT = value:curator_purchase_cost|COST|1000|
		}
		add_modifier = {
			modifier = automated_dreadnought_weak_points
			days = -1
		}
		custom_tooltip = opinion20
		hidden_effect = {
			event_target:curator_enclave_country = {
				add_trust = {
					who = root
					amount = 20
				}
			}
		}
	}
	# Standard options
	inline_script = enclaves/curators_guardians_options
}

# Wraith
country_event = {
	id = leviathans.545
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	title = leviathans.545.name
	desc = leviathans.545.desc

	# More info
	option = {
		name = leviathans.545.a
		response_text = leviathans.545.a.reply
		is_dialog_only = yes
	}
	# Red Wraiths
	option = {
		name = leviathans.545.b
		trigger = {
			NOT = { has_country_flag = bought_wraith_info_1 }
		}
		response_text = leviathans.545.b.reply
		inline_script = {
			script = events/resource_cost_with_allow
			RESOURCE = energy
			AMOUNT = value:curator_purchase_cost|COST|200|
		}
		hidden_effect = { set_country_flag = bought_wraith_info_1 }
	}
	option = {
		name = leviathans.545.b
		trigger = {
			has_country_flag = bought_wraith_info_1
		}
		response_text = leviathans.545.b.reply
	}
	# Yellow Wraiths
	option = {
		name = leviathans.545.c
		trigger = {
			NOT = { has_country_flag = bought_wraith_info_2 }
		}
		response_text = leviathans.545.c.reply
		inline_script = {
			script = events/resource_cost_with_allow
			RESOURCE = energy
			AMOUNT = value:curator_purchase_cost|COST|200|
		}
		hidden_effect = { set_country_flag = bought_wraith_info_2 }
	}
	option = {
		name = leviathans.545.c
		trigger = { has_country_flag = bought_wraith_info_2 }
		response_text = leviathans.545.c.reply
	}
	# Blue Wraiths
	option = {
		name = leviathans.545.d
		response_text = leviathans.545.d.reply
		trigger = {
			NOT = { has_country_flag = bought_wraith_info_3 }
		}
		inline_script = {
			script = events/resource_cost_with_allow
			RESOURCE = energy
			AMOUNT = value:curator_purchase_cost|COST|200|
		}
		hidden_effect = { set_country_flag = bought_wraith_info_3 }
	}
	option = {
		name = leviathans.545.d
		trigger = { has_country_flag = bought_wraith_info_3 }
		response_text = leviathans.545.d.reply
	}
	# Standard options
	inline_script = enclaves/curators_guardians_options
}

# Voidspawn
country_event = {
	id = leviathans.550
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	title = leviathans.550.name
	desc = leviathans.550.desc

	# More info
	option = {
		name = leviathans.550.a
		is_dialog_only = yes
		response_text = leviathans.550.a.reply
	}
	# Purchase modifier
	option = {
		name = leviathans.550.b
		trigger = {
			NOT = { has_modifier = curator_buff_hatchling }
		}
		response_text = leviathans.550.b.reply
		inline_script = {
			script = events/resource_cost_with_allow
			RESOURCE = energy
			AMOUNT = value:curator_purchase_cost|COST|1000|
		}
		add_modifier = {
			modifier = curator_buff_hatchling
			days = -1
		}
		custom_tooltip = opinion20
		hidden_effect = {
			event_target:curator_enclave_country = {
				add_trust = {
					who = root
					amount = 20
				}
			}
		}
	}
	# Standard options
	inline_script = enclaves/curators_guardians_options
}

# Scavenger Bot
country_event = {
	id = leviathans.555
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	title = leviathans.555.name
	desc = leviathans.555.desc

	# Who built it?
	option = {
		name = {
			trigger = {
				NOT = { has_country_flag = bought_scavenger_info_1 }
			}
			text = leviathans.555.a
		}
		name = {
			trigger = {
				has_country_flag = bought_scavenger_info_1
			}
			text = leviathans.555.aa
		}
		is_dialog_only = yes
		response_text = leviathans.555.a.reply
		hidden_effect = {
			set_country_flag = bought_scavenger_info_1
		}
	}
	# Can we communicate with it?
	option = {
		name = {
			trigger = {
				NOT = { has_country_flag = bought_scavenger_info_2 }
			}
			text = leviathans.555.b
		}
		name = {
			trigger = {
				has_country_flag = bought_scavenger_info_2
			}
			text = leviathans.555.bb
		}
		is_dialog_only = yes
		response_text = leviathans.555.b.reply
		hidden_effect = {
			set_country_flag = bought_scavenger_info_2
		}
	}
	# Purchase modifier
	option = {
		name = leviathans.555.c
		trigger = {
			NOT = { has_modifier = scavenger_weak_points }
		}
		response_text = leviathans.555.c.reply
		inline_script = {
			script = events/resource_cost_with_allow
			RESOURCE = energy
			AMOUNT = value:curator_purchase_cost|COST|1000|
		}
		add_modifier = {
			modifier = scavenger_weak_points
			days = -1
		}
		custom_tooltip = opinion20
		hidden_effect = {
			event_target:curator_enclave_country = {
				add_trust = {
					who = root
					amount = 20
				}
			}
		}
	}
	# Standard options
	inline_script = enclaves/curators_guardians_options
}

# Tiyanki Matriarch
country_event = {
	id = leviathans.556
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	title = leviathans.556.name
	desc = leviathans.556.desc

	option = {
		name = {
			trigger = {
				NOT = { has_country_flag = bought_matriarch_info_1 }
			}
			text = leviathans.556.a
		}
		name = {
			trigger = {
				has_country_flag = bought_matriarch_info_1
			}
			text = leviathans.556.aa
		}
		is_dialog_only = yes
		response_text = leviathans.556.a.reply
		hidden_effect = { set_country_flag = bought_matriarch_info_1 }
	}
	option = {
		name = {
			trigger = {
				NOT = { has_country_flag = bought_matriarch_info_2 }
			}
			text = leviathans.556.b
		}
		name = {
			trigger = {
				has_country_flag = bought_matriarch_info_2
			}
			text = leviathans.556.bb
		}
		is_dialog_only = yes
		response_text = leviathans.556.b.reply
		hidden_effect = { set_country_flag = bought_matriarch_info_2 }
	}
	# Purchase modifier
	option = {
		name = leviathans.556.c
		trigger = {
			NOT = { has_modifier = elderly_tiyanki_weak_points }
		}
		response_text = leviathans.556.c.reply
		inline_script = {
			script = events/resource_cost_with_allow
			RESOURCE = energy
			AMOUNT = value:curator_purchase_cost|COST|1000|
		}
		add_modifier = {
			modifier = elderly_tiyanki_weak_points
			days = -1
		}
		custom_tooltip = opinion20
		hidden_effect = {
			event_target:curator_enclave_country = {
				add_trust = {
					who = root
					amount = 20
				}
			}
		}
	}
	# Standard options
	inline_script = enclaves/curators_guardians_options
}

# Toxic God
country_event = {
	id = leviathans.558
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	title = leviathans.558.name
	desc = {
		text = leviathans.558.desc
		trigger = {
			any_country = {
				is_country_type = guardian_toxic_god
				has_communications = root
			}
		}
	}
	desc = {
		text = leviathans.558.desc.knights
		trigger = {
			has_origin = origin_toxic_knights
			NOT = { has_global_flag = toxic_god_spawned }
		}
	}

	immediate = {
		if = {
			limit = { has_global_flag = toxic_god_spawned }
			random_system = {
				limit = { has_star_flag = guardian_toxic_god_system }
				save_event_target_as = toxic_god_system
			}
		}
	}

	option = {
		name = {
			trigger = {
				NOT = { has_country_flag = bought_toxic_god_info_1 }
			}
			text = leviathans.558.A
		}
		name = {
			trigger = {
				has_country_flag = bought_toxic_god_info_1
			}
			text = leviathans.558.AA
		}
		allow = {
			if = {
				limit = {
					has_origin = origin_toxic_knights
					NOR = {
						has_global_flag = toxic_god_spawned
						has_country_flag = bought_toxic_god_info_1
					}
				}
				resource_stockpile_compare = {
					resource = energy
					value >= value:curator_purchase_cost|COST|1000|
				}
			}
			nomad_can_afford_enclave_cost = { COST = 100 }
		}
		is_dialog_only = yes
		response_text = leviathans.558.A.reply
		if = {
			limit = {
				NOT = { has_country_flag = bought_toxic_god_info_1 }
			}
			if = {
				limit = {
					has_origin = origin_toxic_knights
					NOT = { has_global_flag = toxic_god_spawned }
				}
				add_resource = {
					energy = -1
					mult = value:curator_purchase_cost|COST|1000|
				}
				random_situation = {
					limit = { is_situation_type = situation_toxic_knights }
					add_situation_progress = 3
				}
			}
			hidden_effect = { set_country_flag = bought_toxic_god_info_1 }
		}
	}
	option = {
		name = {
			trigger = {
				NOT = { has_country_flag = bought_toxic_god_info_2 }
			}
			text = leviathans.558.B
		}
		name = {
			trigger = {
				has_country_flag = bought_toxic_god_info_2
			}
			text = leviathans.558.BB
		}
		allow = {
			if = {
				limit = {
					has_origin = origin_toxic_knights
					NOR = {
						has_global_flag = toxic_god_spawned
						has_country_flag = bought_toxic_god_info_2
					}
				}
				resource_stockpile_compare = {
					resource = energy
					value >= value:curator_purchase_cost|COST|1000|
				}
			}
			nomad_can_afford_enclave_cost = { COST = 100 }
		}
		is_dialog_only = yes
		response_text = leviathans.558.B.reply
		if = {
			limit = {
				NOT = { has_country_flag = bought_toxic_god_info_2 }
			}
			if = {
				limit = {
					has_origin = origin_toxic_knights
					NOT = { has_global_flag = toxic_god_spawned }
				}
				add_resource = {
					energy = -1
					mult = value:curator_purchase_cost|COST|1000|
				}
				random_situation = {
					limit = { is_situation_type = situation_toxic_knights }
					add_situation_progress = 3
				}
			}
			hidden_effect = { set_country_flag = bought_toxic_god_info_2 }
		}
	}
	#Unfortunately, we cannot use the standard options, because the Toxic God is MUCH stronger than regular Leviathans
	option = { # Can we fight it? (No)
		name = leviathans.506.f
		trigger = { fleet_power < 30000 }
		is_dialog_only = yes
		response_text = leviathans.5106.f1.reply
	}
	option = { # Can we fight it? (Probably not)
		name = leviathans.506.f
		trigger = {
			fleet_power > 30000
			fleet_power < 60000
		}
		is_dialog_only = yes
		response_text = leviathans.5106.f2.reply
	}
	option = { # Can we fight it? (Maybe)
		name = leviathans.506.f
		trigger = {
			fleet_power > 60000
			fleet_power < 120000
		}
		is_dialog_only = yes
		response_text = leviathans.5106.f3.reply
	}
	option = { # Can we fight it? (Yes)
		name = leviathans.506.f
		trigger = { fleet_power > 120000 }
		is_dialog_only = yes
		response_text = leviathans.5106.f4.reply
	}
	option = { # Back
		name = leviathans.506.d
		hidden_effect = {
			country_event = { id = leviathans.500 }
		}
	}
	option = { # Sign Off
		name = GOODBYE
		default_hide_option = yes
	}
}

# Opus Sentinel (Unplugged)
country_event = {
	id = leviathans.559
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	title = leviathans.559.name
	desc = {
		text = leviathans.559.desc
		trigger = {
			NOT = { has_origin = origin_unplugged }
		}
	}
	desc = {
		text = leviathans.559.desc.unplugged
		trigger = {
			has_origin = origin_unplugged
		}
	}

	# More info
	option = {
		name = leviathans.559.a
		response_text = leviathans.559.a.reply
		is_dialog_only = yes
	}
	# Unplugged response
	option = {
		name = leviathans.559.b
		response_text = leviathans.559.b.reply
		is_dialog_only = yes
		trigger = {
			has_origin = origin_unplugged
			NOT = { has_country_flag = curator_unplugged_notalk }
		}
		hidden_effect = {
			set_country_flag = curator_unplugged_notalk
		}
	}
	# Purchase location
	option = {
		name = leviathans.559.c
		response_text = leviathans.559.c.reply
		trigger = {
			NOR = {
				has_country_flag = bought_opus_sentinel_info
				has_country_flag = opus_sentinel_encounter
			}
			OR = { # is able to accept relevant event chains
				NOT = { has_origin = origin_unplugged }
				AND = {
					has_origin = origin_unplugged
					has_event_chain = unplugged_origin_machine_legacy_chain
				}
			}
			exists = event_target:origin_unplugged_opus_sentinel
		}
		allow = {
			event_target:curator_enclave_country = {
				trust = {
					who = root
					value >= 40
				}
			}
			resource_stockpile_compare = {
				resource = energy
				value >= 1000
			}
			nomad_can_afford_enclave_cost = { COST = 1000 }
		}
		add_resource = {
			energy = -1000
		}
		custom_tooltip = opinion20
		hidden_effect = {
			set_country_flag = bought_opus_sentinel_info
			event_target:curator_enclave_country = {
				add_trust = {
					who = root
					amount = 20
				}
			}
			# Unplugged: set a PoI (inside Machine Legacy event chain)
			if = {
				limit = {
					has_origin = origin_unplugged
				}
				create_point_of_interest = {
					id = unplugged_curator_poi_opus_sentinel
					name = curator_poi_title
					desc = unplugged_curator_poi_opus_sentinel_desc
					event_chain = unplugged_origin_machine_legacy_chain
					location = event_target:origin_unplugged_machine_legacy_core
				}
			}
			# Non-Unplugged: set a PoI (custom version of 'create_curator_guardian_poi')
			else = {
				if = {
					limit = {
						NOT = { has_event_chain = curator_poi_chain }
					}
					begin_event_chain = {
						event_chain = curator_poi_chain
						target = event_target:origin_unplugged_opus_sentinel
					}
				}
				create_point_of_interest = {
					id = curator_poi_opus_sentinel
					name = curator_poi_title
					desc = unplugged_curator_poi_opus_sentinel_desc
					event_chain = curator_poi_chain
					location = event_target:origin_unplugged_machine_legacy_core
				}
			}
		}
	}

	# Standard options
	inline_script = enclaves/curators_guardians_options

	after = {
		hidden_effect = {
			remove_country_flag = curator_unplugged_notalk # used in Unplugged dialog
		}
	}
}

# THINK TANK

country_event = {
	id = leviathans.511
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	title = leviathans.511.name
	desc = leviathans.511.desc

	immediate = {
		if = {
			limit = {
				is_nomadic = yes
			}
			random_owned_fleet = {
				limit = {
					is_waystation_ship = yes
					solar_system = {
						has_star_flag = enclave
						any_fleet_in_system = {
							exists = owner
							owner = {
								is_same_value = event_target:curator_enclave_country
							}
						}
					}
				}
				solar_system = {
					save_event_target_as = curator_system
				}
			}
		}
		else = {
			random_system_within_border = {
				limit = {
					any_fleet_in_system = {
						exists = owner
						owner = {
							is_same_value = event_target:curator_enclave_country
						}
					}
				}
				save_event_target_as = curator_system
			}
		}
		event_target:curator_enclave_country = {
			set_country_flag = think_tank@root
		}
	}

	# Accept and return to menu
	option = { # Back
		name = leviathans.511.a
		custom_tooltip = leviathans.511.a.tooltip
		hidden_effect = {
			country_event = { id = leviathans.500 }
		}
		trigger = {
			is_nomadic = no
		}
	}
	option = {
		name = GOODBYE
		custom_tooltip = leviathans.511.a.tooltip
		default_hide_option = yes
		trigger = {
			is_nomadic = no
		}
	}
	# Accept and return to menu
	option = { # Back
		name = leviathans.511.a
		custom_tooltip = leviathans.511.a.tooltip_nomads
		hidden_effect = {
			country_event = { id = leviathans.500 }
		}
		trigger = {
			is_nomadic = yes
		}
	}
	option = {
		name = GOODBYE
		custom_tooltip = leviathans.511.a.tooltip_nomads
		default_hide_option = yes
		trigger = {
			is_nomadic = yes
		}
	}
}

# HIRE SCIENTIST

# Hire a Scientist
country_event = {
	id = leviathans.590
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	title = leviathans.590.name
	desc = leviathans.590.desc

	immediate = {
		event_target:curator_enclave_country = {
			owner_species = { save_event_target_as = curator_species }
		}
	}

	option = {
		name = leviathans.590.a
		allow = {
			hidden_trigger = {
				NOR = {
					has_country_flag = attacked_curators
					any_owned_leader = {
						has_trait = leader_trait_curator
					}
				}
			}
			custom_tooltip = leviathans.590.tt_scientist
			resource_stockpile_compare = {
				resource = energy
				value >= value:curator_purchase_cost|COST|1000|
			}
			resource_stockpile_compare = {
				resource = influence
				value >= value:curator_purchase_cost|COST|50|
			}
			nomad_can_afford_enclave_cost = { COST = 100 }
		}

		add_resource = {
			energy = -1
			mult = value:curator_purchase_cost|COST|1000|
		}
		add_resource = {
			influence = -1
			mult = value:curator_purchase_cost|COST|50|
		}
		custom_tooltip = opinion20
		hidden_effect = {
			set_country_flag = curator_scientist_recruited # Achievement
			event_target:curator_enclave_country = {
				add_trust = {
					who = root
					amount = 20
				}
			}
			create_curator_archivist_effect = yes
			custom_tooltip = curator_archivist_explanation
			if = {
				limit = {
					has_paragon_dlc = yes
					is_gestalt = no
				}
				custom_tooltip = unlocks_curator_council_position
			}
			country_event = { id = leviathans.591 } # Post-sale thanks
		}
	}
	# Back to main menu
	option = {
		name = leviathans.506.d
		hidden_effect = {
			country_event = { id = leviathans.500 }
		}
	}
	# Goodbye
	option = {
		name = GOODBYE
		default_hide_option = yes
	}
}
# Post-Sale Thanks
country_event = {
	id = leviathans.591
	base = leviathans.500
	desc_clear = yes
	desc = leviathans.590.a.reply
}

# Gestalt share Trait
country_event = {
	id = leviathans.598
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	title = leviathans.598.name
	desc = leviathans.598.desc

	immediate = {
		event_target:curator_enclave_country = {
			owner_species = { save_event_target_as = curator_species }
		}
	}

	option = {
		name = leviathans.598.a
		allow = {
			hidden_trigger = {
				NOR = {
					has_country_flag = attacked_curators
					any_owned_leader = {
						has_trait = leader_trait_curator
					}
				}
			}
			custom_tooltip = leviathans.598.tt_principles
			resource_stockpile_compare = {
				resource = energy
				value >= value:curator_purchase_cost|COST|1000|
			}
			resource_stockpile_compare = {
				resource = influence
				value >= value:curator_purchase_cost|COST|50|
			}
			nomad_can_afford_enclave_cost = { COST = 100 }
		}

		add_resource = {
			energy = -1
			mult = value:curator_purchase_cost|COST|1000|
		}
		add_resource = {
			influence = -1
			mult = value:curator_purchase_cost|COST|50|
		}
		custom_tooltip = opinion20
		hidden_effect = {
			#set_country_flag = curator_scientist_recruited # Achievement
			event_target:curator_enclave_country = {
				add_trust = {
					who = root
					amount = 20
				}
			}
			random_owned_leader = {
				limit = {
					is_councilor_type = councilor_gestalt_cognitive
				}
				add_trait = {
					trait = leader_trait_curator
				}
			}
			country_event = { id = leviathans.591 } # Post-sale thanks
		}
	}
	# Back to main menu
	option = {
		name = leviathans.506.d
		hidden_effect = {
			country_event = { id = leviathans.500 }
		}
	}
	# Goodbye
	option = {
		name = GOODBYE
		default_hide_option = yes
	}
}

# BUY INTEL

country_event = {
	id = leviathans.599
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	title = leviathans.599.name
	desc = leviathans.599.desc

	immediate = {
		event_target:curator_enclave_country = {
			owner_species = { save_event_target_as = curator_species }
		}
		# Poll for valid Intel targets
		random_country = {
			limit = {
				valid_curators_intel_trade_target = yes #includes checks for event targets set in this event
			}
			save_event_target_as = curator_customer_1
		}
		random_country = {
			limit = {
				valid_curators_intel_trade_target = yes
			}
			save_event_target_as = curator_customer_2
		}
		random_country = {
			limit = {
				valid_curators_intel_trade_target = yes
			}
			save_event_target_as = curator_customer_3
		}
		random_country = {
			limit = {
				valid_curators_intel_trade_target = yes
			}
			save_event_target_as = curator_customer_4
		}
	}

	# Empire 1
	option = {
		name = leviathans.599.a
		response_text = leviathans.599.yes.reply
		trigger = {
			exists = event_target:curator_customer_1
		}
		inline_script = {
			script = events/resource_cost_with_allow
			RESOURCE = energy
			AMOUNT = value:curator_purchase_cost|COST|1000|
		}
		custom_tooltip = opinion10
		hidden_effect = {
			event_target:curator_enclave_country = {
				add_trust = {
					who = root
					amount = 10
				}
			}
			set_timed_relation_flag = {
				who = event_target:curator_customer_1
				flag = curator_bought_intel_on
				years = 10
			}
		}
		add_intel = {
			who = event_target:curator_customer_1
			amount = 20
		}
	}
	# Empire 2
	option = {
		name = leviathans.599.b
		response_text = leviathans.599.yes.reply
		trigger = {
			exists = event_target:curator_customer_2
		}
		inline_script = {
			script = events/resource_cost_with_allow
			RESOURCE = energy
			AMOUNT = value:curator_purchase_cost|COST|1000|
		}
		custom_tooltip = opinion10
		hidden_effect = {
			event_target:curator_enclave_country = {
				add_trust = {
					who = root
					amount = 10
				}
			}
			set_timed_relation_flag = {
				who = event_target:curator_customer_2
				flag = curator_bought_intel_on
				years = 10
			}
		}
		add_intel = {
			who = event_target:curator_customer_2
			amount = 20
		}
	}
	# Empire 3
	option = {
		name = leviathans.599.c
		response_text = leviathans.599.yes.reply
		trigger = {
			exists = event_target:curator_customer_3
		}
		inline_script = {
			script = events/resource_cost_with_allow
			RESOURCE = energy
			AMOUNT = value:curator_purchase_cost|COST|1000|
		}
		custom_tooltip = opinion10
		hidden_effect = {
			event_target:curator_enclave_country = {
				add_trust = {
					who = root
					amount = 10
				}
			}
			set_timed_relation_flag = {
				who = event_target:curator_customer_3
				flag = curator_bought_intel_on
				years = 10
			}
		}
		add_intel = {
			who = event_target:curator_customer_3
			amount = 20
		}
	}
	# Empire 4
	option = {
		name = leviathans.599.d
		response_text = leviathans.599.yes.reply
		trigger = {
			exists = event_target:curator_customer_4
		}
		inline_script = {
			script = events/resource_cost_with_allow
			RESOURCE = energy
			AMOUNT = value:curator_purchase_cost|COST|1000|
		}
		custom_tooltip = opinion10
		hidden_effect = {
			event_target:curator_enclave_country = {
				add_trust = {
					who = root
					amount = 10
				}
			}
			set_timed_relation_flag = {
				who = event_target:curator_customer_4
				flag = curator_bought_intel_on
				years = 10
			}
		}
		add_intel = {
			who = event_target:curator_customer_4
			amount = 20
		}
	}
	# Back to main menu
	option = { # Back
		name = leviathans.506.d
		hidden_effect = {
			country_event = { id = leviathans.500 }
		}
	}
	# Goodbye
	option = {
		name = GOODBYE
		default_hide_option = yes
	}
}

# L-GATE CLUSTER CLUE

country_event = {
	id = leviathans.600
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	desc = leviathans.600.desc

	# Purchase
	option = {
		name = leviathans.600.a
		allow = {
			hidden_trigger = {
				NOR = {
					has_completed_event_chain_counter = {
						event_chain = l_cluster_chain
						counter = clues
					}
					has_country_flag = curator_clue_purchased
				}
			}
			resource_stockpile_compare = {
				resource = energy
				value >= value:curator_purchase_cost|COST|5000|
			}
			nomad_can_afford_enclave_cost = { COST = 100 }
		}

		add_resource = {
			energy = -1
			mult = value:curator_purchase_cost|COST|5000|
		}
		custom_tooltip = opinion20
		generate_lcluster_clue = yes
		hidden_effect = {
			event_target:curator_enclave_country = {
				add_trust = {
					who = root
					amount = 20
				}
			}
			random_list = {
				1 = {
					set_timed_country_flag = {
						flag = curator_clue_purchased
						days = 4680 # 13 years
					}
				}
				1 = {
					set_timed_country_flag = {
						flag = curator_clue_purchased
						days = 3600 # 10 years
					}
				}
				1 = {
					set_timed_country_flag = {
						flag = curator_clue_purchased
						days = 2520 # 7 years
					}
				}
			}
			country_event = { id = leviathans.504 }
		}
	}
	# Back
	option = {
		name = leviathans.506.d
		hidden_effect = {
			country_event = { id = leviathans.500 }
		}
	}
	# Goodbye
	option = {
		name = GOODBYE
		default_hide_option = yes
	}
}

# Revoke Curator Archivist upon attacking the Curators
# via on_entering_battle | from = attacked country (Curators)
country_event = {
	id = leviathans.605
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = event_target:curator_enclave_country
		from = { is_same_value = event_target:curator_enclave_country }
		any_owned_leader = {
			has_leader_flag = curator_archivist
		}
		NOT = {
			has_country_flag = remove_curator_archivist
		}
	}

	immediate = {
		set_country_flag = remove_curator_archivist
		random_owned_leader = {
			limit = {
				has_leader_flag = curator_archivist
			}
			leader_event = {
				id = enclave.8000
				days = 5
				scopes = {
					FROM = event_target:curator_enclave_country
				}
			}
		}
	}
}

# INFINITY MACHINE EPILOGUE
country_event = {
	id = leviathans.4000
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	title = TRANSMISSION
	desc = leviathans.4000.desc

	immediate = {
		# Nominate an empire for the Curators to confuse yours with
		if = {
			limit = {
				any_country = {
					is_country_type = default
					NOT = { is_same_value = root }
					OR = {
						is_hostile_to = root
						is_domineering_to = root
						is_unfriendly_to = root
						root = {
							OR = {
								is_hostile_to = prev
								is_domineering_to = prev
								is_unfriendly_to = prev
							}
						}
					}
				}
			}
			random_country = {
				limit = {
					is_country_type = default
					NOT = { is_same_value = root }
					OR = {
						is_hostile_to = root
						is_domineering_to = root
						is_unfriendly_to = root
						root = {
							OR = {
								is_hostile_to = prev
								is_domineering_to = prev
								is_unfriendly_to = prev
							}
						}
					}
				}
				save_event_target_as = unfriends
			}
		}
		else_if = { # Random default empire
			limit = {
				any_country = {
					is_country_type = default
					NOT = { is_same_value = root }
				}
			}
			random_country = {
				limit = {
					is_country_type = default
					NOT = { is_same_value = root }
				}
				save_event_target_as = unfriends
			}
		}
		else = { # Random (non-playable, non-crisis) empire
			random_country = {
				limit = {
					NOR = {
						is_same_value = root
						is_same_value = event_target:curator_enclave_country
					}
					OR = {
						is_country_type = primitive
						is_country_type = enclave
						is_country_type = enclave_mercenary
						is_country_type = fallen_empire
						is_country_type = awakened_fallen_empire
						is_country_type = dormant_marauders
						is_country_type = awakened_marauders
						is_country_type = mindwarden_enclave
					}
				}
				save_event_target_as = unfriends
			}
		}
	}

	# Provide info
	option = {
		name = leviathans.4000.a
		response_text = leviathans.4000.a.reply
		set_country_flag = offered_information
		add_monthly_resource_mult = {
			resource = engineering_research
			value = @tier4researchreward
			min = @tier4researchmin
			max = @tier4researchmax
		}
	}
	# Withhold info
	option = {
		name = leviathans.4000.b
		response_text = leviathans.4000.b.reply
		trigger = {
			NOT = { has_country_flag = offered_information }
		}
		set_country_flag = offered_information
	}
	# Back to Main Menu
	option = {
		name = leviathans.110.d
		hidden_effect = {
			country_event = { id = leviathans.500 }
		}
	}
	# Goodbye
	option = {
		name = GOODBYE
		default_hide_option = yes
		hidden_effect = {
			remove_country_flag = curator_enclave_diplomacy_engaged
		}
	}
}

country_event = {
	id = leviathans.4100
	base = leviathans.500
	desc_clear = yes
	option_clear = yes

	desc = leviathans.4100.desc

	inline_script = {
		script = grand_archive/collection/curator_postponed_options_by_category
		EVENT_ID = leviathans.4100
		CATEGORY = aesthetic_wonder
		FOLLOWUP_EVENT_ID = leviathans.4106
	}

	inline_script = {
		script = grand_archive/collection/curator_postponed_options_by_category
		EVENT_ID = leviathans.4100
		CATEGORY = historical_item
		FOLLOWUP_EVENT_ID = leviathans.4107
	}

	inline_script = {
		script = grand_archive/collection/curator_postponed_options_by_category
		EVENT_ID = leviathans.4100
		CATEGORY = xeno_geology
		FOLLOWUP_EVENT_ID = leviathans.4105
	}

	# Back
	option = {
		name = leviathans.506.d
		hidden_effect = {
			country_event = { id = leviathans.500 }
		}
	}

	# Goodbye
	option = {
		name = GOODBYE
		default_hide_option = yes
	}
}

inline_script = {
	script = grand_archive/collection/curator_postponed_reward_stage_choice_event
	EVENT_ID = leviathans.4105
	LOCALIZATION_ID = leviathans.4105
	CATEGORY = xeno_geology
	STAGE_1_EVENT_ID = leviathans.4110
	STAGE_3_EVENT_ID = leviathans.4115
}

inline_script = {
	script = grand_archive/collection/curator_postponed_reward_stage_choice_event
	EVENT_ID = leviathans.4106
	LOCALIZATION_ID = leviathans.4105
	CATEGORY = aesthetic_wonder
	STAGE_1_EVENT_ID = leviathans.4111
	STAGE_3_EVENT_ID = leviathans.4116
}

inline_script = {
	script = grand_archive/collection/curator_postponed_reward_stage_choice_event
	EVENT_ID = leviathans.4107
	LOCALIZATION_ID = leviathans.4105
	CATEGORY = historical_item
	STAGE_1_EVENT_ID = leviathans.4112
	STAGE_3_EVENT_ID = leviathans.4117
}

inline_script = {
	script = grand_archive/collection/curator_postponed_reward_stage_1_event
	EVENT_ID = leviathans.4110
	LOCALIZATION_ID = grand_archive.4105
	CATEGORY = xeno_geology
	MODIFIER_1 = mineral_insight
	MODIFIER_2 = void_mining
}

inline_script = {
	script = grand_archive/collection/curator_postponed_reward_stage_1_event
	EVENT_ID = leviathans.4111
	LOCALIZATION_ID = grand_archive.4105
	CATEGORY = aesthetic_wonder
	MODIFIER_1 = cultural_enrichment
	MODIFIER_2 = auctioneering_curation
}

inline_script = {
	script = grand_archive/collection/curator_postponed_reward_stage_1_event
	EVENT_ID = leviathans.4112
	LOCALIZATION_ID = grand_archive.4105
	CATEGORY = historical_item
	MODIFIER_1 = historical_insight
	MODIFIER_2 = lessons_from_the_past
}

inline_script = {
	script = grand_archive/collection/curator_postponed_reward_stage_3_event
	EVENT_ID = leviathans.4115
	LOCALIZATION_ID = grand_archive.4105
	CATEGORY = xeno_geology
	RELIC_1 = r_the_modularium
	RELIC_2 = r_everchanging_stone
	RELIC_3 = r_flowmetal_alloy
	RELIC_4 = r_pulsestone
	RELIC_5 = r_crystallinus_diffuser
	RESOURCE = minerals
	RESOURCE_MULT = material
}

inline_script = {
	script = grand_archive/collection/curator_postponed_reward_stage_3_event
	EVENT_ID = leviathans.4116
	LOCALIZATION_ID = grand_archive.4105
	CATEGORY = aesthetic_wonder
	RELIC_1 = r_gavel_of_the_tribunal
	RELIC_2 = r_tiyanki_matriarch_nerve_core
	RELIC_3 = r_the_pattern_maker
	RELIC_4 = r_vaporous_mega_orchid
	RELIC_5 = r_celestial_resonator
	RESOURCE = energy
	RESOURCE_MULT = material
}

inline_script = {
	script = grand_archive/collection/curator_postponed_reward_stage_3_event
	EVENT_ID = leviathans.4117
	LOCALIZATION_ID = grand_archive.4105
	CATEGORY = historical_item
	RELIC_1 = r_entangled_relay
	RELIC_2 = r_propagandosphere
	RELIC_3 = r_prototype_vir_core
	RELIC_4 = r_executus_compendium
	RELIC_5 = r_preservation_chamber
	RESOURCE = unity
	RESOURCE_MULT = unity
}

# CURATOR ENCLAVE ATTACKED

# Curator Enclave Starbase destroyed (HIDDEN)
# via on_fleet_destroyed_victim
# this = owner of attacked fleet | from = owner of aggressor fleet  | fromfrom = destroyed fleet | fromfromfrom = attacking fleet
country_event = {
	id = leviathans.592
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = enclave
		has_country_flag = curator_enclave_country
		fromfrom = {
			is_ship_size = enclave_station
		}
	}

	immediate = {
		fromfrom = {
			solar_system = { save_event_target_as = curator_system }
		}
		from = {
			country_event = { id = leviathans.593 }
			save_event_target_as = curator_destroyer
		}
		observer_event = { id = observer.7 }
		every_country = {
			limit = {
				has_communications = ROOT
				NOT = { is_country = event_target:curator_destroyer }
				is_country_type = default
			}
			country_event = { id = leviathans.594 }
		}
	}
}

# Attacked Curator Enclave
# via leviathans.592 | this = aggressor empire
country_event = {
	id = leviathans.593
	title = "leviathans.593"
	desc = "leviathans.593.desc"
	picture = GFX_evt_space_debris
	location = event_target:curator_system
	show_sound = event_ship_bridge

	is_triggered_only = yes

	immediate = {
		set_country_flag = destroyed_curator
		if = {
			limit = { has_modifier = curator_insight }
			remove_modifier = "curator_insight"
		}
	}

	option = {
		name = EXCELLENT
		add_resource = {
			physics_research = 1000
			society_research = 1000
			engineering_research = 1000
		}
		if = {
			limit = { has_ancrel = yes }
			medium_artifact_reward = yes
		}
	}
}

# A Curator Starbase has been destroyed
# via leviathans.592 | this = all non-aggressor empires | from = Curator Enclave (country)
country_event = {
	id = leviathans.594
	title = "leviathans.593"
	# No Curator Insight, we know the attacker, and the Curators carry on
	desc = {
		text = leviathans.594.a.desc
		trigger = {
			NOT = { has_modifier = curator_insight }
			has_communications = event_target:curator_destroyer
			from = {
				count_controlled_ship = {
					limit = { is_ship_size = enclave_station }
					count > 0
				}
			}
		}
	}
	# No Curator Insight, and we don't know the attacker, but the Curators carry on
	desc = {
		text = leviathans.594.b.desc
		trigger = {
			NOR = {
				has_modifier = curator_insight
				has_communications = event_target:curator_destroyer
			}
			from = {
				count_controlled_ship = {
					limit = { is_ship_size = enclave_station }
					count > 0
				}
			}
		}
	}
	# We have Curator Insight, we know the attacker, and the Curators are no more
	desc = {
		text = leviathans.594.c.desc
		trigger = {
			has_modifier = curator_insight
			from = {
				count_controlled_ship = {
					limit = { is_ship_size = enclave_station }
					count < 1
				}
			}
			has_communications = event_target:curator_destroyer
		}
	}
	# We have Curator Insight, we don't know the attacker, and the Curators are no more
	desc = {
		text = leviathans.594.d.desc
		trigger = {
			has_modifier = curator_insight
			FROM = {
				count_controlled_ship = {
					limit = { is_ship_size = enclave_station }
					count < 1
				}
			}
			NOT = { has_communications = event_target:curator_destroyer }
		}
	}
	picture = GFX_evt_exploding_ship
	location = event_target:curator_system
	show_sound = event_ship_explosion

	is_triggered_only = yes

	immediate = {
		# Remove Curator Insight if the Enclave country is no more
		if = {
			limit = {
				has_modifier = curator_insight
				FROM = {
					count_controlled_ship = {
						limit = { is_ship_size = enclave_station }
						count < 1
					}
				}
			}
			remove_modifier = "curator_insight"
		}
		# (AI) Dislike the attacker if the Curators are wiped out, ending Curator Insight
		if = {
			limit = {
				has_modifier = curator_insight
				FROM = {
					count_controlled_ship = {
						limit = { is_ship_size = enclave_station }
						count < 1
					}
				}
				is_ai = yes
			}
			add_opinion_modifier = {
				who = event_target:curator_destroyer
				modifier = opinion_destroyed_curator_insight
			}
		}
		# (AI) Dislike the attacker if the Curators are wiped out
		if = {
			limit = {
				NOT = { has_modifier = curator_insight }
				is_ai = yes
			}
			add_opinion_modifier = {
				who = event_target:curator_destroyer
				modifier = opinion_destroyed_curator
			}
		}
	}

	option = {
		name = "leviathans.594.a"
		exclusive_trigger = {
			NOT = { has_modifier = curator_insight }
		}
	}
	option = {
		name = "leviathans.594.b"
		exclusive_trigger = {
			has_modifier = curator_insight
			FROM = {
				count_controlled_ship = {
					limit = { is_ship_size = enclave_station }
					count < 1
				}
			}
		}
	}
	option = { #Fallback if botht he above triggers are false
		name = CURSES
	}
}

# Attacked Curator Enclave (HIDDEN)
# via on_entering_battle
# this = owner of aggressor fleet | from = owner of attacked fleet | fromfrom = aggressor fleet | fromfromfrom = attacked fleet
country_event = {
	id = leviathans.595
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = default
		FROM = { has_country_flag = curator_enclave_country }
	}

	immediate = {
		# Issue opinion penalty
		FROM = {
			add_trust = {
				who = ROOT
				amount = -100
			}
		}
		set_country_flag = attacked_curators
		if = {
			limit = { has_modifier = curator_insight }
			remove_modifier = curator_insight
			country_event = { id = leviathans.596 }
		}
	}
}

# Attacked Curator Enclave, terminating Curator Insights
# via leviathans.595 | this = aggressor empire
country_event = {
	id = leviathans.596
	# Does not inherit from leviathans.500 due to 'attacked' status
	title = leviathans.500.name
	desc = leviathans.596.desc
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_curator_window"
	custom_gui_option = "enclave_curator_option"
	picture_event_data = {
		portrait = event_target:curator_enclave_country
		room = enclave_curator_room
	}

	option = {
		name = leviathans.156.a
	}
}

# Curators Ignore Diplomacy (after being attacked by you)
# via on_custom_diplomacy | from = Curator Enclave country
country_event = {
	id = leviathans.597
	# Does not inherit from leviathans.500 due to 'attacked' status
	title = leviathans.500.name
	desc = leviathans.597a.desc
	desc = leviathans.597b.desc
	desc = leviathans.597c.desc
	desc = leviathans.597d.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_curator_window"
	custom_gui_option = "enclave_curator_option"
	picture_event_data = {
		portrait = event_target:curator_enclave_country
		room = enclave_curator_room
	}
	location = event_target:curator_enclave_system

	trigger = {
		from = {
			is_country_type = enclave
			has_country_flag = curator_enclave_country
		}
		has_country_flag = attacked_curators
	}

	option = {
		name = {
			trigger = { has_valid_civic = civic_fanatic_purifiers }
			text = SCUM
		}
		name = {
			trigger = { has_valid_civic = civic_hive_devouring_swarm }
			text = TASTY
		}
		name = {
			trigger = { has_valid_civic = civic_machine_terminator }
			text = EXTERMINATE
		}
		name = {
			trigger = { is_genocidal_infernal = yes }
			text = BURN
		}
		name = {
			trigger = {
				NOR = {
					has_valid_civic = civic_fanatic_purifiers
					has_valid_civic = civic_hive_devouring_swarm
					has_valid_civic = civic_machine_terminator
					is_genocidal_infernal = yes
				}
			}
			text = leviathans.156.a
		}
		hidden_effect = {
			set_country_flag = curator_intro
		}
		default_hide_option = yes
	}
}

###############
# DEBUG EVENTS
###############

# RESTART DEBUG
fleet_event = {
	id = leviathans.601
	hide_window = yes
	trigger = { always = no }
	is_test_event = yes

	immediate = {
		fleet_event = { id = leviathans.602 }
	}
}
fleet_event = {
	id = leviathans.602
	hide_window = yes
	trigger = { always = no }
	is_test_event = yes

	immediate = {
		owner = { country_event = { id = leviathans.640 } }
	}
}

##############
# ETHER DRAKE
##############

# Encounter
fleet_event = {
	id = leviathans.610
	title = leviathans.610.name
	desc = {
		text = leviathans.610.desc
		trigger = {
			owner = {
				NOT = { has_origin = origin_here_be_dragons }
			}
		}
	}
	desc = {
		text = leviathans.610.desc.here_be_dragons
		trigger = {
			owner = { has_origin = origin_here_be_dragons }
		}
	}
	picture = GFX_evt_space_dragon
	location = from
	show_sound = event_yellow_alert

	is_triggered_only = yes

	trigger = {
		from = {
			has_star_flag = guardians_dragon_system
			any_fleet_in_system = { is_ship_size = space_dragon_red }
		}
		owner = {
			NOT = {
				has_country_flag = dragon_encounter
			}
			OR = {
				is_country_type = default
				is_country_type = fallen_empire
				is_country_type = awakened_fallen_empire
			}
		}
	}

	immediate = {
		owner = {
			set_country_flag = dragon_encounter
		}
	}

	option = {
		name = leviathans.610.a
	}
}

# Restart mission after battle
country_event = {
	id = leviathans.640
	hide_window = yes
	trigger = {
		is_country_type = guardian_dragon
		has_country_flag = dragon_country
		fromfrom = {
			has_hp_percentage > 0.15
			solar_system = {
				NOT = {
					has_star_flag = guardians_dragon_system
				}
			}
		}
	}

	is_triggered_only = yes

	immediate = {
		fromfrom = {
			if = {
				limit = {
					has_fleet_flag = dragon_mission_1
				}
				queue_actions = {
					repeat = {
						find_closest_system = {
							trigger = {
								id = dragon.1.retaliation.1x
								has_star_flag = system_target_1
							}
							found_system = {
								move_to = this
								find_closest_planet = {
									trigger = {
										id = dragon.1.retaliation.2x
										is_star = yes
									}
									found_planet = {
										move_to = this
										wait = {
											duration = 60
										}
										effect = {
											id = dragon.1.retaliation.3x
											solar_system = {
												remove_star_flag = system_target_1
											}
											root = {
												remove_fleet_flag = dragon_mission_1
												clear_fleet_actions = this
											}
										}
									}
								}
							}
						}
					}
				}
				if = {
					limit = {
						any_system = {
							has_star_flag = system_target_2
						}
					}
					queue_actions = {
						repeat = {
							find_closest_system = {
								trigger = {
									id = dragon.2.retaliation.1x
									is_same_value = event_target:system_target_2
								}
								found_system = {
									move_to = this
									find_closest_planet = {
										trigger = {
											id = dragon.2.retaliation.2x
											is_star = yes
										}
										found_planet = {
											move_to = this
											wait = {
												duration = 60
											}
											effect = {
												id = dragon.2.retaliation.3x
												solar_system = {
													remove_star_flag = system_target_2
												}
												root = {
													remove_fleet_flag = dragon_mission_2
													clear_fleet_actions = this
												}
											}
										}
									}
								}
							}
						}
					}
					queue_actions = {
						repeat = {
							find_closest_system = {
								trigger = {
									id = dragon.3.retaliation.1x
									has_star_flag = guardians_dragon_system
								}
								found_system = {
									move_to = this
									find_closest_planet = {
										trigger = {
											id = dragon.3.retaliation.2x
											has_planet_flag = hoard_planet
										}
										found_planet = {
											move_to = this
											effect = {
												id = dragon.3.retaliation.3x
												root = {
													remove_fleet_flag = dragon_mission_2
													clear_fleet_actions = this
												}
											}
										}
									}
								}
							}
						}
					}
				}
				break = yes
			}
			if = {
				limit = {
					has_fleet_flag = dragon_mission_2
				}
				queue_actions = {
					repeat = {
						find_closest_system = {
							trigger = {
								id = dragon.2.retaliation.1y
								has_star_flag = system_target_2
							}
							found_system = {
								move_to = this
							}
						}
						find_closest_planet = {
							trigger = {
								id = dragon.2.retaliation.2y
								is_star = yes
							}
							found_planet = {
								move_to = this
								wait = {
									duration = 60
								}
								effect = {
									id = dragon.2.retaliation.3y
									solar_system = {
										remove_star_flag = system_target_2
									}
									root = {
										remove_fleet_flag = dragon_mission_2
										clear_fleet_actions = this
									}
								}
							}
						}
					}
				}
				queue_actions = {
					repeat = {
						find_closest_system = {
							trigger = {
								id = dragon.3.retaliation.1y
								has_star_flag = guardians_dragon_system
							}
							found_system = {
								move_to = this
								find_closest_planet = {
									trigger = {
										id = dragon.3.retaliation.2y
										has_planet_flag = hoard_planet
									}
									found_planet = {
										move_to = this
										effect = {
											id = dragon.3.retaliation.3y
											root = {
												remove_fleet_flag = dragon_mission_2
												clear_fleet_actions = this
											}
										}
									}
								}
							}
						}
					}
				}
				break = yes
			}
			if = {
				limit = {
					has_fleet_flag = dragon_mission_2
				}
				queue_actions = {
					repeat = {
						find_closest_system = {
							trigger = {
								id = dragon.3.retaliation.1z
								has_star_flag = guardians_dragon_system
							}
							found_system = {
								move_to = this
								find_closest_planet = {
									trigger = {
										id = dragon.3.retaliation.2z
										has_planet_flag = hoard_planet
									}
									found_planet = {
										move_to = this
										effect = {
											id = dragon.3.retaliation.3z
											root = {
												remove_fleet_flag = dragon_mission_2
												clear_fleet_actions = this
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

# Dragon retaliates if hurt and fleet destroyed
country_event = {
	id = leviathans.648
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = guardian_dragon
		any_controlled_ship = {
			is_ship_size = space_dragon_red
			has_hp_percentage < 0.80
			has_hp_percentage > 0.15
			fleet = {
				NOT = {
					has_fleet_flag = aggro_cooldown
				}
				exists = solar_system
				solar_system = {
					has_star_flag = guardians_dragon_system
				}
			}
		}
		from = {
			is_country_type = default
		}
	}

	immediate = {
		random_controlled_fleet = {
			limit = {
				any_controlled_ship = {
					is_ship_size = space_dragon_red
				}
			}
			set_timed_fleet_flag = {
				flag = aggro_cooldown
				days = 60
			}
			clear_fleet_actions = this
			fleet_event = { id = leviathans.652 }
		}
		from = {
			country_event = { id = leviathans.649 }
		}
	}
}

# Retaliation notification
country_event = {
	id = leviathans.649
	title = leviathans.650.name
	desc = {
		text = leviathans.649.desc
		trigger = {
			NOT = { has_ethic = ethic_gestalt_consciousness }
		}
	}
	desc = {
		text = leviathans.649.desc.gesta
		trigger = {
			has_ethic = ethic_gestalt_consciousness
		}
	}
	picture = GFX_evt_exploding_ship
	is_triggered_only = yes

	trigger = {
		from = { is_country_type = guardian_dragon }
	}

	option = {
		name = leviathans.649.a
		trigger = {
			NOT = { has_ethic = ethic_gestalt_consciousness }
		}
	}

	option = {
		name = leviathans.649.b.gesta
		trigger = {
			has_ethic = ethic_gestalt_consciousness
		}
	}
}

# Dragon pursues if fleet flees
# Fired before entering FTL - does combat still exist?
fleet_event = {
	id = leviathans.650
	#hide_window = yes
	title = leviathans.650.name
	desc = {
		text = leviathans.650.desc
		trigger = {
			owner = { NOT = { has_ethic = ethic_gestalt_consciousness } }
		}
	}
	desc = {
		text = leviathans.650.desc.gesta
		trigger = {
			owner = { has_ethic = ethic_gestalt_consciousness }
		}
	}
	picture = GFX_evt_space_dragon
	is_triggered_only = yes

	trigger = {
		owner = {
			is_country_type = default
		}
		from = {
			has_star_flag = guardians_dragon_system
		}
		any_combatant_fleet = {
			exists = owner
			owner = {
				is_country_type = guardian_dragon
			}
			NOT = { has_fleet_flag = aggro_cooldown }
			any_controlled_ship = {
				is_ship_size = space_dragon_red
				has_hp_percentage < 0.80
				has_hp_percentage > 0.15
			}
		}
	}

	immediate = {
		random_combatant_fleet = {
			limit = {
				exists = owner
				owner = {
					is_country_type = guardian_dragon
				}
				any_controlled_ship = {
					is_ship_size = space_dragon_red
				}
			}
			#save_event_target_as = retaliating_dragon
			set_timed_fleet_flag = {
				flag = aggro_cooldown
				days = 30
			}
			clear_fleet_actions = this
			fleet_event = { id = leviathans.651 }
		}
	}

	option = {
		name = leviathans.649.a
		trigger = { owner = { NOT = { has_ethic = ethic_gestalt_consciousness } } }
	}

	option = {
		name = leviathans.649.b.gesta
		trigger = { owner = { has_ethic = ethic_gestalt_consciousness } }
	}
}

# Goes to two of fleeing country's systems (with stations) and gets wreckin'
fleet_event = {
	id = leviathans.651
	hide_window = yes

	is_triggered_only = yes

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

	immediate = {
		closest_system = {
			limit = {
				any_fleet_in_system = {
					OR = {
						is_ship_size = mining_station
						is_ship_size = research_station
						is_ship_class = shipclass_starbase
					}
					exists = owner
					owner = {
						is_same_value = from.owner
					}
				}
			}
			set_star_flag = system_target_1
			save_event_target_as = system_target_1
		}
		if = {
			limit = {
				exists = event_target:system_target_1
			}
			set_fleet_flag = dragon_mission_1
			#from.owner = { country_event = { id = leviathans.649 } }
			queue_actions = {
				repeat = {
					max_iterations = 1
					find_closest_system = {
						trigger = {
							id = dragon.1.retaliation.1
							is_same_value = event_target:system_target_1
						}
						found_system = {
							move_to = this
							find_closest_planet = {
								trigger = {
									id = dragon.1.retaliation.2
									is_star = yes
								}
								found_planet = {
									move_to = this
									wait = {
										duration = 1
									}
									effect = {
										id = dragon.1.retaliation.3
										solar_system = {
											remove_star_flag = system_target_1
										}
										root = {
											remove_fleet_flag = dragon_mission_1
											#clear_fleet_actions = this
										}
									}
									find_closest_system = {
										trigger = {
											id = dragon.3.retaliation.1
											has_star_flag = guardians_dragon_system
										}
										found_system = {
											move_to = this
											find_closest_planet = {
												trigger = {
													id = dragon.3.retaliation.2
													has_planet_flag = hoard_planet
												}
												found_planet = {
													move_to = this
													effect = {
														id = dragon.3.retaliation.3
														root = {
															remove_fleet_flag = dragon_mission_2
															clear_fleet_actions = this
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

# Goes to two of destroyed fleet owner's systems (with stations) and gets wreckin'
fleet_event = {
	id = leviathans.652
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		exists = fromfrom
	}

	immediate = {
		closest_system = {
			limit = {
				any_fleet_in_system = {
					OR = {
						is_ship_size = mining_station
						is_ship_size = research_station
						is_ship_class = shipclass_starbase
					}
					exists = owner
					owner = {
						is_same_value = fromfrom
					}
				}
			}
			set_star_flag = system_target_2
			save_event_target_as = system_target_2
		}
		if = {
			limit = {
				exists = event_target:system_target_2
			}
			set_fleet_flag = dragon_mission_1
			#fromfrom = { country_event = { id = leviathans.649 } }
			queue_actions = {
				repeat = {
					max_iterations = 1
					find_closest_system = {
						trigger = {
							id = dragon.4.retaliation.1
							is_same_value = event_target:system_target_2
						}
						found_system = {
							move_to = this
							find_closest_planet = {
								trigger = {
									id = dragon.4.retaliation.2
									is_star = yes
								}
								found_planet = {
									move_to = this
									wait = {
										duration = 1
									}
									effect = {
										id = dragon.4.retaliation.3
										solar_system = {
											remove_star_flag = system_target_2
										}
										root = {
											remove_fleet_flag = dragon_mission_2
											#clear_fleet_actions = this
										}
									}
									find_closest_system = {
										trigger = {
											id = dragon.5.retaliation.1
											has_star_flag = guardians_dragon_system
										}
										found_system = {
											move_to = this
											find_closest_planet = {
												trigger = {
													id = dragon.5.retaliation.2
													has_planet_flag = hoard_planet
												}
												found_planet = {
													move_to = this
													effect = {
														id = dragon.5.retaliation.3
														root = {
															remove_fleet_flag = dragon_mission_2
															clear_fleet_actions = this
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

fleet_event = {
	id = leviathans.654
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		owner = {
			is_country_type = default
		}
		from = {
			has_star_flag = guardians_dragon_system
		}
		any_combatant_fleet = {
			exists = owner
			owner = {
				is_country_type = guardian_dragon
			}
			#NOT = { has_fleet_flag = aggro_cooldown }
			any_controlled_ship = {
				is_ship_size = space_dragon_red
				has_hp_percentage < 0.16
			}
		}
	}

	immediate = {
		from = {
			random_fleet_in_system = {
				limit = {
					exists = owner
					owner = {
						is_country_type = guardian_dragon
					}
					#NOT = { has_fleet_flag = aggro_cooldown }
					any_controlled_ship = {
						is_ship_size = space_dragon_red
					}
				}
				random_controlled_ship = {
					limit = { is_ship_size = space_dragon_red }
					save_event_target_as = dragon_ship
				}
				clear_fleet_actions = this
				queue_actions = {
					repeat = {
						max_iterations = 1
						find_random_system = {
							trigger = {
								id = guardian.hibernate.7
								has_star_flag = guardians_dragon_system
							}
							found_system = {
								move_to = this
								find_random_planet = {
									trigger = {
										id = guardian.hibernate.8
										is_star = yes
									}
									found_planet = {
										move_to = this
										orbit_planet = this
										effect = {
											id = guardian.hibernate.9
											event_target:dragon_ship = {
												repair_ship = yes
											}
										}
									}
								}
								wait = {
									duration = 60
								}
							}
						}
					}
				}
			}
		}
	}
}

# On won battle but wounded, hibernate
country_event = {
	id = leviathans.655
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_country_type = guardian_dragon
		fromfrom = {
			any_controlled_ship = {
				has_hp_percentage < 0.16
			}
			NOR = {
				has_fleet_flag = dragon_mission_1
				has_fleet_flag = dragon_mission_2
			}
		}
	}

	immediate = {
		fromfrom = {
			clear_fleet_actions = this
			queue_actions = {
				repeat = {
					max_iterations = 1
					find_random_system = {
						trigger = {
							id = guardian.hibernate.1
							has_star_flag = guardians_dragon_system
						}
						found_system = {
							move_to = this
							find_random_planet = {
								trigger = {
									id = guardian.hibernate.2
									is_star = yes
								}
								found_planet = {
									orbit_planet = this
									effect = {
										id = guardian.hibernate.3
										root.fromfrom = { random_controlled_ship = { repair_ship = yes } }
									}
								}
							}
							wait = {
								duration = 60
							}
						}
					}
				}
			}
		}
	}
}

# Fired by | on_building_mining_station
# This = construction ship
# From = planet it is built on
ship_event = {
	id = leviathans.660
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = event_target:guardian_dragon_planet
		from = {
			is_same_value = event_target:guardian_dragon_planet
			NOR = {
				has_planet_flag = deboned
				has_planet_flag = deegged
			}
		}
		exists = owner
		owner = {
			is_country_type = default
		}
	}

	immediate = {
		owner = {
			country_event = { id = leviathans.661 days = 1 random = 18000 } # 50 years
			country_event = { id = leviathans.663 days = 1 random = 18000 } # 50 years
		}
	}
}

# Dragon Hoard event - Bones
country_event = {
	id = leviathans.661
	title = "leviathans.660.name"
	desc = "leviathans.660.desc"
	picture = GFX_evt_archaeological_dig
	location = event_target:guardian_dragon_planet
	show_sound = event_mystic_reveal

	is_triggered_only = yes

	trigger = {
		exists = event_target:guardian_dragon_planet
		event_target:guardian_dragon_planet = {
			NOT = { has_planet_flag = deboned }
			has_mining_station = yes
			exists = controller
			controller = {
				is_same_value = root
			}
		}
	}

	immediate = {
		event_target:guardian_dragon_planet = {
			set_planet_flag = deboned
		}
	}

	option = {
		name = leviathans.660.a
		grant_dragon_armor_effect = yes
	}

	option = {
		name = leviathans.660.b
		add_monthly_resource_mult = {
			resource = minerals
			value = @tier4materialreward
			min = @tier4materialmin
			max = @tier4materialmax
		}
		add_monthly_resource_mult = {
			resource = society_research
			value = @tier4researchreward
			min = @tier4researchmin
			max = @tier4researchmax
		}
	}
}

# Fire events if ownership flipped - Fired by | on_system_gained
# From = system
# FromFrom = country (new owner)
# This = country (previous owner)
country_event = {
	id = leviathans.662
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = event_target:guardian_dragon_planet
		from = {
			has_star_flag = guardians_dragon_system
			any_system_planet = {
				is_same_value = event_target:guardian_dragon_planet
				has_mining_station = yes
				exists = controller
				controller = {
					is_same_value = root
				}
			}
		}
	}

	immediate = {
		country_event = { id = leviathans.661 days = 1 random = 18000 } # 50 years
		country_event = { id = leviathans.663 days = 1 random = 18000 } # 50 years
	}
}

# Dragon Hoard event - Egg
country_event = {
	id = leviathans.663
	title = "leviathans.661.name"
	desc = "leviathans.661.desc"
	picture = GFX_evt_archaeological_dig
	location = event_target:guardian_dragon_planet
	show_sound = event_mystic_reveal
	trackable = yes

	is_triggered_only = yes

	trigger = {
		exists = event_target:guardian_dragon_planet
		event_target:guardian_dragon_planet = {
			NOT = { has_planet_flag = deegged }
			has_mining_station = yes
			exists = controller
			controller = {
				is_same_value = root
			}
		}
	}

	immediate = {
		event_target:guardian_dragon_planet = {
			set_planet_flag = deegged
		}
	}

	option = {
		name = leviathans.661.a
		custom_tooltip = leviathans.661.a.tooltip
		capital_scope = {
			enable_special_project = {
				name = "DRAGON_INCUBATION_PROJECT"
				location = this
				owner = root
			}
		}
	}

	option = {
		name = leviathans.661.b
		custom_tooltip = leviathans.661.b.tooltip
		add_resource = { influence = 300 }
	}
}

# Egg incubated
carrier_event = {
	id = leviathans.664
	title = leviathans.664.name
	desc = leviathans.664.desc
	picture = GFX_evt_space_dragon
	location = root
	show_sound = event_mystic_reveal

	is_triggered_only = yes

	immediate = {
		create_fleet = {
			name = "NAME_Ether_Hatchling"
			settings = {
				can_upgrade = no
				can_change_composition = no
				can_change_leader = no
				uses_naval_capacity = no
				spawn_debris = no
			}
			effect = {
				set_owner = root.owner
				create_ship_design = {
					design = NAME_Dragonspawn
				}
				create_ship = {
					design = last_created_design
					name = "NAME_Scile"
					prefix = no
					upgradable = no
				}
				set_location = root
			}
		}
		owner = { set_country_flag = hatched_dragon }
	}

	option = {
		name = leviathans.664.a
		custom_tooltip = leviathans.664.a.tooltip
	}
}

country_event = {
	id = leviathans.665
	title = leviathans.665.name
	desc = {
		trigger = {
			is_hive_empire = no
			is_machine_empire = no
		}
		text = leviathans.665.desc
	}
	desc = {
		trigger = {
			is_hive_empire = yes
			is_machine_empire = no
		}
		text = leviathans.665.desc.gesta
	}
	desc = {
		trigger = {
			is_machine_empire = yes
		}
		text = leviathans.665.desc.machine
	}
	picture = GFX_evt_throne_room
	location = capital_scope
	show_sound = event_mystic_reveal

	is_triggered_only = yes

	option = {
		name = UNFORTUNATE
	}
}

# victorious admiral gains dragonslayer trait
country_event = {
	id = leviathans.670
	title = leviathans.670.name
	desc = {
		text = leviathans.670.desc
		trigger = {
			NOT = { has_ethic = ethic_gestalt_consciousness }
			fromfrom = {
				exists = leader
			}
		}
	}
	desc = {
		text = leviathans.670.desc.noleader
		trigger = {
			NOT = { has_ethic = ethic_gestalt_consciousness }
			fromfrom = {
				NOT = { exists = leader }
			}
		}
	}
	desc = {
		text = leviathans.670.desc.gesta
		trigger = {
			has_ethic = ethic_gestalt_consciousness
		}
	}
	picture = GFX_evt_space_dragon
	location = fromfrom
	show_sound = event_mystic_reveal

	is_triggered_only = yes

	trigger = {
		from = {
			is_country_type = guardian_dragon
			NOR = {
				has_country_flag = rubricator_dragon_country
				has_country_flag = here_be_the_dragon
			}
		}
		#fromfromfrom = {
		#	has_fleet_flag = dragon_fleet
		#}
	}

	immediate = {
		every_country = {
			limit = {
				is_country_type = default
				has_modifier = draconic_beats
			}
			remove_modifier = draconic_beats
		}
		fromfrom.solar_system = {
			save_event_target_as = slain_guardian_system
		}
		every_country = {
			limit = {
				is_country_type = default
				has_event_chain = curator_poi_chain
				event_target:slain_guardian_system = {
					is_point_of_interest = {
						id = curator_poi_dragon
						event_chain = curator_poi_chain
						owner = prev
					}
				}
			}
			remove_point_of_interest = curator_poi_dragon
			end_curator_chain = yes
		}
	}

	option = {
		name = leviathans.670.a
		trigger = {
			can_harvest_dna = no
		}
		add_resource = { influence = 300 }
		add_relic = r_dragon_trophy
	}

	option = {
		name = galactic_features.385.reanimated

		trigger = {
			is_reanimator = yes
		}

		enable_special_project = {
			name = "REANIMATE_GUARDIAN_DRAGON"
			location = fromfrom.solar_system.star
			owner = root.owner
		}
		add_resource = { influence = 300 }
		add_relic = r_dragon_trophy
	}

	option = {
		name = aquatics.105.A
		trigger = {
			can_harvest_dna = yes
		}
		set_country_flag = harvested_dragon_dna
		custom_tooltip = aquatics.105.A.tooltip
		add_resource = { influence = 300 }
		add_relic = r_dragon_trophy
	}


	after = {
		if = {
			limit = { exists = fromfrom.leader }
			fromfrom.leader = {
				if = {
					limit = {
						leader_class = commander
					}
					add_trait = {
						trait = leader_trait_dragonslayer
					}
				}
			}
		}
		if = {
			limit = { num_owned_planets > 0 }
			generate_parade_city = yes
			start_situation = {
				type = leviathan_celebration_opportunity
				target = event_target:parade_city
				effect = {
					set_situation_flag = celebration_ether_drake
					set_situation_flag = standard_unity_reward
				}
			}
		}
	}
}

# Etherdrake Reanimation
country_event = {
	id = leviathans.675
	title = "distar.218.name"
	desc = {
		trigger = {
			is_gestalt = no
		}
		text = "leviathans.675.desc.regular"
	}
	desc = {
		trigger = {
			is_hive_empire = yes
		}
		text = "leviathans.675.desc.hive"
	}
	desc = {
		trigger = {
			is_machine_empire = yes
		}
		text = "leviathans.675.desc.machine"
	}
	location = from

	is_triggered_only = yes

	picture = GFX_evt_necromancy
	show_sound = event_mystic_reveal

	option = {
		name = "it_hungers"

		create_fleet = {
			name = "NAME_Avice"
			effect = {
				set_owner = root
				create_ship = {
					name = "NAME_Avice"
					design = "NAME_Reanimated_Grand_Dragon"
					prefix = no
					upgradable = no
				}
				set_location = {
					target = from
					distance = 0
					angle = random
				}
				set_fleet_stance = passive
			}
			settings = {
				can_upgrade = no
				can_change_composition = no
				can_change_leader = no
				uses_naval_capacity = no
				spawn_debris = no
			}
		}
	}
}
