#################################
### Guardian & Enclave Events ###
### by Maximilian Olbers	  ###
### & Niclas Karlsson		  ###
### & Rufus Tronde			  ###
### & Henrik Eklund			  ###
#################################

namespace = guardian

@tier1influencecontact = 7
@tier1influencecontactxenophile = 8
@tier1influencecontactmin = 20
@tier1influencecontactmax = 80

@tier2influencecontact = 10
@tier2influencecontactxenophile = 12
@tier2influencecontactmin = 40
@tier2influencecontactmax = 100

@tier1materialreward = 6
@tier1materialmin = 100
@tier1materialmax = 500
@tier2materialreward = 12
@tier2materialmin = 150
@tier2materialmax = 1000
@tier3materialreward = 18
@tier3materialmin = 250
@tier3materialmax = 1500
@tier4materialreward = 24
@tier4materialmin = 350
@tier4materialmax = 2000
@tier5materialreward = 48
@tier5materialmin = 700
@tier5materialmax = 4000

@tier1influencereward = 6
@tier1influencemin = 40
@tier1influencemax = 100
@tier2influencereward = 12
@tier2influencemin = 80
@tier2influencemax = 175
@tier3influencereward = 18
@tier3influencemin = 125
@tier3influencemax = 250
@tier4influencereward = 24
@tier4influencemin = 150
@tier4influencemax = 300
@tier5influencereward = 36
@tier5influencemin = 250
@tier5influencemax = 500
@tier6influencereward = 48
@tier6influencemin = 300
@tier6influencemax = 600

@tier1researchreward = 6
@tier1researchmin = 60
@tier1researchmax = 150
@tier2researchreward = 12
@tier2researchmin = 90
@tier2researchmax = 250
@tier3researchreward = 18
@tier3researchmin = 120
@tier3researchmax = 350
@tier4researchreward = 24
@tier4researchmin = 150
@tier4researchmax = 500
@tier5researchreward = 48
@tier5researchmin = 300
@tier5researchmax = 1000

country_event = {
	id = guardian.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
		}
	}
}

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

	trigger = {
		from = {
			is_guardian_country = yes
			num_fleets < 1
		}
	}

	immediate = {
		every_country = {
			limit = {
				has_communications = root
				NOT = { is_same_value = root }
			}
			country_event = { id = guardian.5 }
		}
	}
}

# notification
country_event = {
	id = guardian.5
	title = guardian.5.name
	desc = guardian.5.desc
	picture = GFX_evt_throne_room
	location = fromfromfrom
	show_sound = event_mystic_reveal

	is_triggered_only = yes

	option = {
		name = OK
	}
}

# Enclave Monthly Border Opinion
event = {
	id = guardian.10
	hide_window = yes
	is_triggered_only = yes

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

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

	immediate = {
		every_owned_fleet = {
			limit = {
				exists = solar_system
				solar_system = {
					exists = space_owner
					space_owner = {
						is_country_type = default
					}
				}
			}
			solar_system = {
				space_owner = {
					root = {
						add_trust = {
							who = prev
							amount = 1
						}
					}
				}
			}
		}
	}
}

fleet_event = {
	id = guardian.96
	title = "action.10.name"
	desc = "action.15.desc"
	picture = GFX_evt_star_chart
	location = FROM
	
	is_triggered_only = yes
	
	trigger = {
		owner = {
			is_country_type = default
			exists = capital_scope
		}
		from = {
			has_star_flag = enclave
			any_ship_in_system = {
				exists = owner
				owner = {
					is_country_type = enclave
					NOR = {
						has_communications = root.owner
						reverse_has_relation_flag = {
							flag = ongoing_enclave_investigation
							who = root.owner
						}
					}
				}
			}
		}
	}

	immediate = {
		owner = {
			capital_scope = { save_event_target_as = pc_home }
			from = {
				random_fleet_in_system = {
					limit = {
						exists = owner
						owner = { is_country_type = enclave }
					}
					owner = {
						save_event_target_as = target_enclave
						country_event = { id = guardian.97 days = 300 random = 50 }
						enable_special_project = {
							name = "INVESTIGATE_ENCLAVE"
							location = event_target:pc_home
							owner = root.owner
						}
					}
				}
			}
			set_relation_flag = {
				flag = ongoing_enclave_investigation
				who = event_target:target_enclave
			}
		}
	}
	
	option = {
		name = "action.10.a"
		owner = {
			tooltip = {
				enable_special_project = {
					name = "INVESTIGATE_ENCLAVE"
					location = event_target:pc_home
					owner = ROOT
				}
			}
		}
	}
}

# Enclaves make contact after 300 days
country_event = {
	id = guardian.97
	hide_window = yes

	trigger = {
		exists = event_target:pc_home
		event_target:pc_home = {
			exists = owner
			owner = {
				NOT = { has_communications = root }
				has_relation_flag = {
					flag = ongoing_enclave_investigation
					who = root
				}
			}
		}
	}

	immediate = {
		event_target:pc_home = {
			if = {
				limit = {
					exists = owner
					owner = {
						NOT = {
							has_communications = root
						}
						has_relation_flag = {
							flag = ongoing_enclave_investigation
							who = root
						}
					}
				}
				owner = {
					root = { establish_communications_no_message = prev }
					country_event = { id = guardian.98 }
				}
			}
		}
	}
}

# Enclave Establishes Communications
country_event = {
	id = guardian.98
	title = guardian.98.name
	desc = guardian.98.desc
	picture = GFX_evt_throne_room
	show_sound = event_radio_chatter
	
	is_triggered_only = yes

	after = {
		if = {
			limit = {
				OR = {
					has_ethic = ethic_xenophile
					has_ethic = ethic_fanatic_xenophile
				}
			}
			add_monthly_resource_mult = {
				resource = influence
				value = @tier1influencecontactxenophile
				min = @tier1influencecontactmin
				max = @tier1influencecontactmax
			}
			else = {
				add_monthly_resource_mult = {
					resource = influence
					value = @tier1influencecontact
					min = @tier1influencecontactmin
					max = @tier1influencecontactmax
				}
			}
		}
		hidden_effect = {
			if = {
				limit = {
					from = { has_country_flag = trader_enclave_country }
				}
				from = { country_event = { id = guardian.101 } }
				break = yes
			}
			if = {
				limit = { from = { has_country_flag = artist_enclave_country } }
				from = { country_event = { id = guardian.301 } }
				break = yes
			}
			if = {
				limit = { from = { has_country_flag = curator_enclave_country } }
				from = { country_event = { id = guardian.501 } }
				break = yes
			}
		}
	}

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

	option = {
		name = guardian.98.a
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
	}
}

# Communication Established
country_event = {
	id = guardian.99
	title = "guardian.99.name"
	desc = guardian.99.desc
	picture = GFX_evt_throne_room
	show_sound = event_radio_chatter
	
	is_triggered_only = yes

	immediate = { establish_communications_no_message = FROMFROM }

	after = {
		if = {
			limit = {
				OR = {
					has_ethic = ethic_xenophile
					has_ethic = ethic_fanatic_xenophile
				}
			}
			add_monthly_resource_mult = {
				resource = influence
				value = @tier2influencecontactxenophile
				min = @tier2influencecontactmin
				max = @tier2influencecontactmax
			}
			else = {
				add_monthly_resource_mult = {
					resource = influence
					value = @tier2influencecontact
					min = @tier2influencecontactmin
					max = @tier2influencecontactmax
				}
			}
		}
		hidden_effect = {
			if = {
				limit = {
					fromfrom = {
						has_country_flag = trader_enclave_country
					}
				}
				fromfrom = { country_event = { id = guardian.101 } }
				break = yes
			}
			if = {
				limit = {
					fromfrom = {
						has_country_flag = artist_enclave_country
					}
				}
				fromfrom = {
					country_event = { id = guardian.301 }
				}
				set_country_flag = enclave_artist_encountered
				break = yes
			}
			if = {
				limit = {
					fromfrom = {
						has_country_flag = curator_enclave_country
					}
				}
				fromfrom = { country_event = { id = guardian.501 } }
				break = yes
			}
		}
	}

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

	option = {
		name = "guardian.98.a"
		trigger = {
			NOT = { has_valid_civic = civic_fanatic_purifiers }
		}
	}
}

# Traders Main Menu #1 (Initial)
country_event = {
	id = guardian.100
	title = guardian.100.name
	desc = guardian.100a.desc
	desc = guardian.100b.desc
	desc = guardian.100c.desc
	desc = guardian.100d.desc
	desc = guardian.100e.desc
	desc = guardian.100f.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"
	force_open = yes

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}
	
	trigger = {
		from = {
			is_country_type = enclave
			has_country_flag = trader_enclave_country_1
		}
		NOT = { has_country_flag = attacked_xuracorp }
		NOT = { has_country_flag = trader_enclave_diplomacy_engaged }
	}

	immediate = {
		set_country_flag = trader_enclave_diplomacy_engaged
		FROM = { save_event_target_as = traders }
	}

	after = {
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}

	option = {
		name = SCUM
		custom_gui = "enclave_trader_option"
		trigger = { has_valid_civic = civic_fanatic_purifiers }
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}

	option = { # Minerals
		name = guardian.105.a
		custom_gui = "enclave_trader_option"
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		hidden_effect = {
			country_event = { id = guardian.110 }
		}
	}

	option = { # Energy
		name = guardian.105.b
		custom_gui = "enclave_trader_option"
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		hidden_effect = {
			country_event = { id = guardian.120 }
		}
	}

	option = { # Strategic Resource
		name = guardian.105.c
		custom_gui = "enclave_trader_option"
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		allow = {
			custom_tooltip = {
				fail_text = guardian.105.c.sr2
				NOT = { has_modifier = enclave_traders_sr2 }
			}
			custom_tooltip = {
				text = guardian.105.c.trust
				event_target:traders = {
					trust = {
						who = root
						value > 49 
					}
				}	
			}
		}
		hidden_effect = {
			country_event = { id = guardian.131 }
		}
	}

	option = {
		name = guardian.105.d
		custom_gui = "enclave_trader_option"
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		default_hide_option = yes
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}
}

# Traders Main Menu #2 (Initial)
country_event = {
	id = guardian.103
	title = guardian.103.name
	desc = guardian.103a.desc
	desc = guardian.103b.desc
	desc = guardian.103c.desc
	desc = guardian.103d.desc
	desc = guardian.103e.desc
	desc = guardian.103f.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"
	force_open = yes

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}
	
	trigger = {
		from = {
			is_country_type = enclave
			has_country_flag = trader_enclave_country_2
		}
		NOT = { has_country_flag = trader_enclave_diplomacy_engaged }
		NOT = { has_country_flag = attacked_riggans }
	}

	immediate = {
		set_country_flag = trader_enclave_diplomacy_engaged
		FROM = { save_event_target_as = traders }
	}

	after = {
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}

	option = {
		name = SCUM
		custom_gui = "enclave_trader_option"
		trigger = { has_valid_civic = civic_fanatic_purifiers }
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}

	option = { # Minerals
		name = guardian.105.a
		custom_gui = "enclave_trader_option"
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		hidden_effect = {
			country_event = { id = guardian.110 }
		}
	}

	option = { # Energy
		name = guardian.105.b
		custom_gui = "enclave_trader_option"
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		hidden_effect = {
			country_event = { id = guardian.120 }
		}
	}

	option = { # Strategic Resource
		name = guardian.105.c
		custom_gui = "enclave_trader_option"
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		allow = {
			custom_tooltip = {
				fail_text = guardian.105.c.sr1
				NOT = { has_modifier = enclave_traders_sr1 }
			}
			custom_tooltip = {
				text = guardian.105.c.trust
				event_target:traders = {
					trust = {
						who = root
						value > 49
					}
				}
			}
		}
		hidden_effect = {
			country_event = { id = guardian.130 }
		}
	}

	option = {
		name = guardian.105.d
		custom_gui = "enclave_trader_option"
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		default_hide_option = yes
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}
}

# Traders Main Menu #3 (Initial)
country_event = {
	id = guardian.104
	title = guardian.104.name
	desc = guardian.104a.desc
	desc = guardian.104b.desc
	desc = guardian.104c.desc
	desc = guardian.104d.desc
	desc = guardian.104e.desc
	desc = guardian.104f.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"
	force_open = yes

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}
	
	trigger = {
		from = {
			is_country_type = enclave
			has_country_flag = trader_enclave_country_3
		}
		NOT = { has_country_flag = trader_enclave_diplomacy_engaged }
		NOT = { has_country_flag = attacked_muutagans }
	}

	immediate = {
		set_country_flag = trader_enclave_diplomacy_engaged
		FROM = { save_event_target_as = traders }
	}

	after = {
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}

	option = {
		name = SCUM
		custom_gui = "enclave_trader_option"
		trigger = { has_valid_civic = civic_fanatic_purifiers }
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}

	option = { # Minerals
		name = guardian.105.a
		custom_gui = "enclave_trader_option"
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		hidden_effect = {
			country_event = { id = guardian.110 }
		}
	}

	option = { # Energy
		name = guardian.105.b
		custom_gui = "enclave_trader_option"
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		hidden_effect = {
			country_event = { id = guardian.120 }
		}
	}

	option = { # Strategic Resource
		name = guardian.105.c
		custom_gui = "enclave_trader_option"
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		allow = {
			custom_tooltip = {
				fail_text = guardian.105.c.sr3
				NOT = { has_modifier = enclave_traders_sr3 }
			}
			custom_tooltip = {
				text = guardian.105.c.trust
				event_target:traders = {
					trust = { 
						who = root
						value > 49 
					}
				}	
			}
		}
		hidden_effect = {
			country_event = { id = guardian.132 }
		}
	}

	option = {
		name = guardian.105.d
		custom_gui = "enclave_trader_option"
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		default_hide_option = yes
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}
}

# Traders Main Menu #1
country_event = {
	id = guardian.105
	title = guardian.100.name
	desc = guardian.100a.desc
	desc = guardian.100b.desc
	desc = guardian.100c.desc
	desc = guardian.100d.desc
	desc = guardian.100e.desc
	desc = guardian.100f.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}

	immediate = {
		set_country_flag = trader_enclave_diplomacy_engaged
	}

	after = {
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}

	option = { # Minerals
		name = guardian.105.a
		custom_gui = "enclave_trader_option"
		hidden_effect = {
			country_event = { id = guardian.110 }
		}
	}

	option = { # Energy
		name = guardian.105.b
		custom_gui = "enclave_trader_option"
		hidden_effect = {
			country_event = { id = guardian.120 }
		}
	}

	option = { # Strategic Resource
		name = guardian.105.c
		custom_gui = "enclave_trader_option"
		allow = {
			custom_tooltip = {
				fail_text = guardian.105.c.sr2
				NOT = { has_modifier = enclave_traders_sr2 }
			}
			custom_tooltip = {
				text = guardian.105.c.trust
				event_target:traders = {
					trust = { 
						who = root
						value > 49 
					}
				}	
			}
		}
		hidden_effect = {
			country_event = { id = guardian.131 }
		}
	}

	option = {
		name = guardian.105.d
		default_hide_option = yes
		custom_gui = "enclave_trader_option"
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}
}

# Traders Main Menu #2
country_event = {
	id = guardian.106
	title = guardian.103.name
	desc = guardian.103a.desc
	desc = guardian.103b.desc
	desc = guardian.103c.desc
	desc = guardian.103d.desc
	desc = guardian.103e.desc
	desc = guardian.103f.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}

	immediate = {
		set_country_flag = trader_enclave_diplomacy_engaged
	}

	after = {
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}

	option = { # Minerals
		name = guardian.105.a
		custom_gui = "enclave_trader_option"
		hidden_effect = {
			country_event = { id = guardian.110 }
		}
	}

	option = { # Energy
		name = guardian.105.b
		custom_gui = "enclave_trader_option"
		hidden_effect = {
			country_event = { id = guardian.120 }
		}
	}

	option = { # Strategic Resource
		name = guardian.105.c
		custom_gui = "enclave_trader_option"
		allow = {
			custom_tooltip = {
				fail_text = guardian.105.c.sr1
				NOT = { has_modifier = enclave_traders_sr1 }
			}
			custom_tooltip = {
				text = guardian.105.c.trust
				event_target:traders = {
					trust = { 
						who = root
						value > 49 
					}
				}	
			}
		}
		hidden_effect = {
			country_event = { id = guardian.130 }
		}
	}

	option = {
		name = guardian.105.d
		default_hide_option = yes
		custom_gui = "enclave_trader_option"
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}
}

# Traders Main Menu #3
country_event = {
	id = guardian.107
	title = guardian.104.name
	desc = guardian.104a.desc
	desc = guardian.104b.desc
	desc = guardian.104c.desc
	desc = guardian.104d.desc
	desc = guardian.104e.desc
	desc = guardian.104f.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}

	immediate = {
		set_country_flag = trader_enclave_diplomacy_engaged
	}

	after = {
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}

	option = { # Minerals
		name = guardian.105.a
		custom_gui = "enclave_trader_option"
		hidden_effect = {
			country_event = { id = guardian.110 }
		}
	}

	option = { # Energy
		name = guardian.105.b
		custom_gui = "enclave_trader_option"
		hidden_effect = {
			country_event = { id = guardian.120 }
		}
	}

	option = { # Strategic Resource
		name = guardian.105.c
		custom_gui = "enclave_trader_option"
		allow = {
			custom_tooltip = {
				fail_text = guardian.105.c.sr3
				NOT = { has_modifier = enclave_traders_sr3 }
			}
			custom_tooltip = {
				text = guardian.105.c.trust
				event_target:traders = {
					trust = { 
						who = root
						value > 49 
					}
				}	
			}
		}
		hidden_effect = {
			country_event = { id = guardian.132 }
		}
	}

	option = {
		name = guardian.105.d
		default_hide_option = yes
		custom_gui = "enclave_trader_option"
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}
}

# Minerals
country_event = {
	id = guardian.110
	title = guardian.110.name
	desc = guardian.110.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"
	force_open = yes

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}

	option = {
		name = guardian.110.a
		custom_gui = "enclave_trader_option"
		allow = { 
			energy > 200 
			hidden_trigger = {
				NOT = {
					AND = {
						has_country_flag = attacked_xuracorp
						event_target:traders = { has_country_flag = trader_enclave_country_1 }
					}
					AND = {
						has_country_flag = attacked_riggans
						event_target:traders = { has_country_flag = trader_enclave_country_2 }
					}
					AND = {
						has_country_flag = attacked_muutagans
						event_target:traders = { has_country_flag = trader_enclave_country_3 }
					}
				}
			}			
		}
		is_dialog_only = yes
		response_text = guardian.110.a.reply

		add_minerals = 100
		add_energy = -200
		custom_tooltip = opinion1
		hidden_effect = {
			event_target:traders = {
				add_trust = {
					who = root
					amount = 1
				}
			}
		}
	}

	option = {
		name = guardian.110.b
		custom_gui = "enclave_trader_option"
		allow = { 
			energy > 1000 
			hidden_trigger = {
				NOT = {
					AND = {
						has_country_flag = attacked_xuracorp
						event_target:traders = { has_country_flag = trader_enclave_country_1 }
					}
					AND = {
						has_country_flag = attacked_riggans
						event_target:traders = { has_country_flag = trader_enclave_country_2 }
					}
					AND = {
						has_country_flag = attacked_muutagans
						event_target:traders = { has_country_flag = trader_enclave_country_3 }
					}
				}
			}
		}
		is_dialog_only = yes
		response_text = guardian.110.b.reply

		add_minerals = 500
		add_energy = -1000
		custom_tooltip = opinion7
		hidden_effect = {
			event_target:traders = {
				add_trust = {
					who = root
					amount = 7
				}
			}
		}
	}

	option = {
		name = guardian.110.c
		custom_gui = "enclave_trader_option"
		allow = { 
			energy > 2000
			hidden_trigger = {
				NOT = {
					AND = {
						has_country_flag = attacked_xuracorp
						event_target:traders = { has_country_flag = trader_enclave_country_1 }
					}
					AND = {
						has_country_flag = attacked_riggans
						event_target:traders = { has_country_flag = trader_enclave_country_2 }
					}
					AND = {
						has_country_flag = attacked_muutagans
						event_target:traders = { has_country_flag = trader_enclave_country_3 }
					}
				}
			}
		}
		is_dialog_only = yes
		response_text = guardian.110.c.reply

		add_minerals = 1000
		add_energy = -2000
		custom_tooltip = opinion15
		hidden_effect = {
			event_target:traders = {
				add_trust = {
					who = root
					amount = 15
				}
			}
		}
	}

	option = {
		name = guardian.110.d
		custom_gui = "enclave_trader_option"
		hidden_effect = {
			if = {
				limit = { event_target:traders = { has_country_flag = trader_enclave_country_1 } }
				country_event = { id = guardian.105 }
			}
			if = {
				limit = { event_target:traders = { has_country_flag = trader_enclave_country_2 } }
				country_event = { id = guardian.106 }
			}
			if = {
				limit = { event_target:traders = { has_country_flag = trader_enclave_country_3 } }
				country_event = { id = guardian.107 }
			}
		}
	}

	option = {
		name = guardian.110.e
		custom_gui = "enclave_trader_option"
		default_hide_option = yes
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}
}

# Energy
country_event = {
	id = guardian.120
	title = guardian.120.name
	desc = guardian.120.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"
	force_open = yes

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}

	option = {
		name = guardian.120.a
		custom_gui = "enclave_trader_option"
		allow = { 
			minerals > 200
			hidden_trigger = {
				NOT = {
					AND = {
						has_country_flag = attacked_xuracorp
						event_target:traders = { has_country_flag = trader_enclave_country_1 }
					}
					AND = {
						has_country_flag = attacked_riggans
						event_target:traders = { has_country_flag = trader_enclave_country_2 }
					}
					AND = {
						has_country_flag = attacked_muutagans
						event_target:traders = { has_country_flag = trader_enclave_country_3 }
					}
				}
			}
		}
		is_dialog_only = yes
		response_text = guardian.120.a.reply

		add_energy = 100
		add_minerals = -200
		custom_tooltip = opinion1
		hidden_effect = {
			event_target:traders = {
				add_trust = {
					who = root
					amount = 1
				}
			}
		}
	}

	option = {
		name = guardian.120.b
		custom_gui = "enclave_trader_option"
		allow = { 
			minerals > 1000 
			hidden_trigger = {
				NOT = {
					AND = {
						has_country_flag = attacked_xuracorp
						event_target:traders = { has_country_flag = trader_enclave_country_1 }
					}
					AND = {
						has_country_flag = attacked_riggans
						event_target:traders = { has_country_flag = trader_enclave_country_2 }
					}
					AND = {
						has_country_flag = attacked_muutagans
						event_target:traders = { has_country_flag = trader_enclave_country_3 }
					}
				}
			}
		}
		is_dialog_only = yes
		response_text = guardian.120.b.reply

		add_energy = 500
		add_minerals = -1000
		custom_tooltip = opinion7
		hidden_effect = {
			event_target:traders = {
				add_trust = {
					who = root
					amount = 7
				}
			}
		}
	}

	option = {
		name = guardian.120.c
		custom_gui = "enclave_trader_option"
		allow = { 
			minerals > 2000 
			hidden_trigger = {
				NOT = {
					AND = {
						has_country_flag = attacked_xuracorp
						event_target:traders = { has_country_flag = trader_enclave_country_1 }
					}
					AND = {
						has_country_flag = attacked_riggans
						event_target:traders = { has_country_flag = trader_enclave_country_2 }
					}
					AND = {
						has_country_flag = attacked_muutagans
						event_target:traders = { has_country_flag = trader_enclave_country_3 }
					}
				}
			}
		}
		is_dialog_only = yes
		response_text = guardian.120.c.reply

		add_energy = 1000
		add_minerals = -2000
		custom_tooltip = opinion15
		hidden_effect = {
			event_target:traders = {
				add_trust = {
					who = root
					amount = 15
				}
			}
		}
	}

	option = {
		name = guardian.110.d
		custom_gui = "enclave_trader_option"
		hidden_effect = {
			if = {
				limit = { event_target:traders = { has_country_flag = trader_enclave_country_1 } }
				country_event = { id = guardian.105 }
			}
			if = {
				limit = { event_target:traders = { has_country_flag = trader_enclave_country_2 } }
				country_event = { id = guardian.106 }
			}
			if = {
				limit = { event_target:traders = { has_country_flag = trader_enclave_country_3 } }
				country_event = { id = guardian.107 }
			}
		}
	}

	option = {
		name = guardian.110.e
		custom_gui = "enclave_trader_option"
		default_hide_option = yes
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}
}

# Strategic Resource 1
country_event = {
	id = guardian.130
	title = guardian.103.name
	desc = guardian.130.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"
	force_open = yes

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}

	option = {
		name = guardian.130.a
		custom_gui = "enclave_trader_option"
		allow = { 
			energy > 1000 
			hidden_trigger = {
				NOT = { has_country_flag = attacked_riggans }
			}
		}
		#response_text = guardian.130.a.reply
		add_energy = -1000
		custom_tooltip = opinion20
		add_modifier = {
			modifier = "enclave_traders_sr1"
			days = 3600
		}
		custom_tooltip = riggan_spice_effect
		hidden_effect = {
			event_target:traders = {
				add_trust = {
					who = root
					amount = 20
				}
			}
			set_relation_flag = {
				who = event_target:traders
				flag = riggan_trade
			}
			country_event = { id = guardian.135 days = 3600 }
			country_event = { id = guardian.133 }
		}
	}
	option = {
		name = guardian.110.d
		custom_gui = "enclave_trader_option"
		hidden_effect = {
			if = {
				limit = { event_target:traders = { has_country_flag = trader_enclave_country_1 } }
				country_event = { id = guardian.105 }
			}
			if = {
				limit = { event_target:traders = { has_country_flag = trader_enclave_country_2 } }
				country_event = { id = guardian.106 }
			}
			if = {
				limit = { event_target:traders = { has_country_flag = trader_enclave_country_3 } }
				country_event = { id = guardian.107 }
			}
		}
	}
	option = {
		name = guardian.110.e
		custom_gui = "enclave_trader_option"
		default_hide_option = yes
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}
}

# Strategic Resource 2
country_event = {
	id = guardian.131
	title = guardian.100.name
	desc = guardian.131.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"
	force_open = yes

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}

	option = {
		name = guardian.131.a
		custom_gui = "enclave_trader_option"
		allow = { 
			energy > 1000 
			hidden_trigger = {
				NOT = { has_country_flag = attacked_xuracorp }
			}
		}
		#response_text = guardian.131.a.reply
		add_energy = -1000
		custom_tooltip = opinion20
		add_modifier = {
			modifier = "enclave_traders_sr2"
			days = 3600
		}
		custom_tooltip = xuragel_effect
		hidden_effect = {
			event_target:traders = {
				add_trust = {
					who = root
					amount = 20
				}
			}
			set_relation_flag = {
				who = event_target:traders
				flag = xuracorp_trade
			}
			country_event = { id = guardian.136 days = 3600 }
			country_event = { id = guardian.133 }
		}
	}
	option = {
		name = guardian.110.d
		custom_gui = "enclave_trader_option"
		hidden_effect = {
			if = {
				limit = { event_target:traders = { has_country_flag = trader_enclave_country_1 } }
				country_event = { id = guardian.105 }
			}
			if = {
				limit = { event_target:traders = { has_country_flag = trader_enclave_country_2 } }
				country_event = { id = guardian.106 }
			}
			if = {
				limit = { event_target:traders = { has_country_flag = trader_enclave_country_3 } }
				country_event = { id = guardian.107 }
			}
		}
	}
	option = {
		name = guardian.110.e
		custom_gui = "enclave_trader_option"
		default_hide_option = yes
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}
}

# Strategic Resource 3
country_event = {
	id = guardian.132
	title = guardian.104.name
	desc = guardian.132.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"
	force_open = yes

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}

	option = {
		name = guardian.132.a
		custom_gui = "enclave_trader_option"
		allow = { 
			energy > 1000 
			hidden_trigger = {
				NOT = { has_country_flag = attacked_muutagans }
			}
		}
		#response_text = guardian.132.a.reply
		add_energy = -1000
		custom_tooltip = opinion20
		add_modifier = {
			modifier = "enclave_traders_sr3"
			days = 3600
		}
		custom_tooltip = muutagan_crystals_effect
		hidden_effect = {
			event_target:traders = {
				add_trust = {
					who = root
					amount = 20
				}
			}
			set_relation_flag = {
				who = event_target:traders
				flag = muutagan_trade
			}
			country_event = { id = guardian.137 days = 3600 }
			country_event = { id = guardian.133 }
		}
	}
	option = {
		name = guardian.110.d
		custom_gui = "enclave_trader_option"
		hidden_effect = {
			if = {
				limit = { event_target:traders = { has_country_flag = trader_enclave_country_1 } }
				country_event = { id = guardian.105 }
			}
			if = {
				limit = { event_target:traders = { has_country_flag = trader_enclave_country_2 } }
				country_event = { id = guardian.106 }
			}
			if = {
				limit = { event_target:traders = { has_country_flag = trader_enclave_country_3 } }
				country_event = { id = guardian.107 }
			}
		}
	}
	option = {
		name = guardian.110.e
		custom_gui = "enclave_trader_option"
		default_hide_option = yes
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}
}

# Strategic Resource Reply Event
country_event = {
	id = guardian.133
	title = guardian.133.name
	desc = {
		text = guardian.131.a.reply
		trigger = {
			event_target:traders = {
				has_country_flag = trader_enclave_country_1
			}
		}
	}
	desc = {
		text = guardian.130.a.reply
		trigger = {
			event_target:traders = {
				has_country_flag = trader_enclave_country_2
			}
		}
	}
	desc = {
		text = guardian.132.a.reply
		trigger = {
			event_target:traders = {
				has_country_flag = trader_enclave_country_3
			}
		}
	}

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"
	force_open = yes

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}


	option = {
		name = guardian.110.d
		custom_gui = "enclave_trader_option"
		hidden_effect = {
			if = {
				limit = { event_target:traders = { has_country_flag = trader_enclave_country_1 } }
				country_event = { id = guardian.105 }
			}
			if = {
				limit = { event_target:traders = { has_country_flag = trader_enclave_country_2 } }
				country_event = { id = guardian.106 }
			}
			if = {
				limit = { event_target:traders = { has_country_flag = trader_enclave_country_3 } }
				country_event = { id = guardian.107 }
			}
		}
	}
	option = {
		name = guardian.110.e
		custom_gui = "enclave_trader_option"
		default_hide_option = yes
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}
}

# Remove Riggan Trade Relation Flag (HIDDEN)
country_event = {
	id = guardian.135
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		remove_relation_flag = {
			who = event_target:traders
			flag = riggan_trade 
		}
		country_event = { id = guardian.151 }
	}
}

# Remove XuraCorp Trade Relation Flag (HIDDEN)
country_event = {
	id = guardian.136
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		remove_relation_flag = {
			who = event_target:traders
			flag = xuracorp_trade 
		}
		country_event = { id = guardian.150 }
	}
}

# Remove Muutagan Trade Relation Flag (HIDDEN)
country_event = {
	id = guardian.137
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		remove_relation_flag = {
			who = event_target:traders
			flag = muutagan_trade 
		}
		country_event = { id = guardian.152 }
	}
}

# Port
country_event = {
	id = guardian.101
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		random_owned_ship = {
			solar_system = { save_event_target_as = trader_system }
		}
		from = {
			country_event = { id = guardian.102 }
		}
	}
}

# Trader Introduction
country_event = {
	id = guardian.102
	title = guardian.102.name
	
	desc = {
		text = guardian.102a.desc
		trigger = {
			FROM = { has_country_flag = trader_enclave_country_1 }
		}
	}
	desc = {
		text = guardian.102b.desc
		trigger = {
			FROM = { has_country_flag = trader_enclave_country_2 }
		}
	}
	desc = {
		text = guardian.102c.desc
		trigger = {
			FROM = { has_country_flag = trader_enclave_country_3 }
		}
	}
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"

	picture_event_data = {
		portrait = from
		room = enclave_trader_room
	}

	option = {
		name = SCUM
		trigger = { has_valid_civic = civic_fanatic_purifiers }
		custom_gui = "enclave_trader_option"
	}

	option = {
		name = guardian.502.a
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		custom_gui = "enclave_trader_option"
	}
}

# Trader Destroyed (HIDDEN)
country_event = {
	id = guardian.140
	hide_window = yes
	
	is_triggered_only = yes
	
	trigger = {
		is_country_type = enclave
		has_country_flag = trader_enclave_country
		FROMFROM = { 
			any_ship = { is_ship_size = enclave_station }
		}
	}
	
	immediate = {
		FROMFROM = {
			solar_system = { save_event_target_as = trader_system }
		}
		FROM = { 
			country_event = { id = guardian.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 = guardian.142 }
			}
			if = {
				limit = {
					ROOT = { has_country_flag = trader_enclave_country_2 }
				}
				country_event = { id = guardian.143 }
			}
			if = {
				limit = {
					ROOT = { has_country_flag = trader_enclave_country_3 }
				}
				country_event = { id = guardian.144 }
			}
		}
	}
}

# Any Trader Destroyed (Destroyer)
country_event = {
	id = guardian.141
	title = "guardian.141"
	desc = "guardian.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
		if = {
			limit = { 
				has_modifier = enclave_traders_sr2
				has_relation_flag = { 
					who = FROM
					flag = xuracorp_trade 
				}
			}
			remove_modifier = "enclave_traders_sr2"
			remove_relation_flag = {
				who = FROM
				flag = xuracorp_trade 
			}
		}
		if = {
			limit = { 
				has_modifier = enclave_traders_sr1
				has_relation_flag = { 
					who = FROM
					flag = riggan_trade 
				}
			}
			remove_modifier = "enclave_traders_sr1"
			remove_relation_flag = {
				who = FROM
				flag = riggan_trade 
			}
		}
		if = {
			limit = { 
				has_modifier = enclave_traders_sr3
				has_relation_flag = { 
					who = FROM
					flag = muutagan_trade 
				}
			}
			remove_modifier = "enclave_traders_sr3"
			remove_relation_flag = {
				who = FROM
				flag = muutagan_trade 
			}
		}
	}
	
	option = {
		name = EXCELLENT
		add_minerals = 2000
		add_energy = 2000
	}
}

# XuraCorp Destroyed
country_event = {
	id = guardian.142
	title = "guardian.141"
	desc = {
		text = guardian.142.a.desc
		trigger = {
			NOT = {
				has_relation_flag = { 
					who = FROM
					flag = xuracorp_trade 
				}
			}
			has_communications = event_target:trader_destroyer
		}
	}
	desc = {
		text = guardian.142.b.desc
		trigger = {
			NOT = { 
				has_relation_flag = { 
					who = FROM
					flag = xuracorp_trade 
				}
			}
			NOT = { has_communications = event_target:trader_destroyer }
		}
	}
	desc = {
		text = guardian.142.c.desc
		trigger = {
			has_relation_flag = { 
				who = FROM
				flag = xuracorp_trade 
			}
			has_communications = event_target:trader_destroyer
		}
	}
	desc = {
		text = guardian.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
		if = {
			limit = { 
				has_modifier = enclave_traders_sr2
				has_relation_flag = { 
					who = FROM
					flag = xuracorp_trade
				}
			}
			remove_modifier = "enclave_traders_sr2"
		}
		if = {
			limit = {
				has_relation_flag = { 
					who = FROM
					flag = xuracorp_trade
				}
				is_ai = yes
			}
			add_opinion_modifier = {
				who = event_target:trader_destroyer
				modifier = opinion_destroyed_trader_sr
			}
		}
		if = {
			limit = {
				NOT = {
					has_relation_flag = { 
						who = FROM
						flag = xuracorp_trade
					}
				}
				is_ai = yes
			}
			add_opinion_modifier = {
				who = event_target:trader_destroyer
				modifier = opinion_destroyed_trader
			}
		}
	}
	
	option = {
		name = "guardian.142.a"
		trigger = {
			NOT = { 
				has_relation_flag = { 
					who = FROM
					flag = xuracorp_trade 
				}
			}
		}
	}
	option = {
		name = "guardian.142.b"
		trigger = {
			has_relation_flag = { 
				who = FROM
				flag = xuracorp_trade 
			}
		}
		hidden_effect = {
			remove_relation_flag = {
				who = FROM
				flag = xuracorp_trade 
			}
		}
	}
}

# Riggans Destroyed
country_event = {
	id = guardian.143
	title = "guardian.141"
	desc = {
		text = guardian.143.a.desc
		trigger = {
			NOT = {
				has_relation_flag = { 
					who = FROM
					flag = riggan_trade 
				}
			}
			has_communications = event_target:trader_destroyer
		}
	}
	desc = {
		text = guardian.143.b.desc
		trigger = {
			NOT = { 
				has_relation_flag = { 
					who = FROM
					flag = riggan_trade 
				}
			}
			NOT = { has_communications = event_target:trader_destroyer }
		}
	}
	desc = {
		text = guardian.143.c.desc
		trigger = {
			has_relation_flag = { 
				who = FROM
				flag = riggan_trade 
			}
			has_communications = event_target:trader_destroyer
		}
	}
	desc = {
		text = guardian.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
		if = {
			limit = { 
				has_modifier = enclave_traders_sr1
				has_relation_flag = { 
					who = FROM
					flag = riggan_trade
				}
			}
			remove_modifier = "enclave_traders_sr1"
		}
		if = {
			limit = {
				has_relation_flag = { 
					who = FROM
					flag = riggan_trade
				}
				is_ai = yes
			}
			add_opinion_modifier = {
				who = event_target:trader_destroyer
				modifier = opinion_destroyed_trader_sr
			}
		}
		if = {
			limit = {
				NOT = {
					has_relation_flag = { 
						who = FROM
						flag = riggan_trade
					}
				}
				is_ai = yes
			}
			add_opinion_modifier = {
				who = event_target:trader_destroyer
				modifier = opinion_destroyed_trader
			}
		}
	}
	
	option = {
		name = "guardian.143.a"
		trigger = {
			NOT = { 
				has_relation_flag = { 
					who = FROM
					flag = riggan_trade 
				}
			}
		}
	}
	option = {
		name = "guardian.143.b"
		trigger = {
			has_relation_flag = { 
				who = FROM
				flag = riggan_trade 
			}
		}
		hidden_effect = {
			remove_relation_flag = {
				who = FROM
				flag = riggan_trade 
			}
		}
	}
}

# Muutagans Destroyed
country_event = {
	id = guardian.144
	title = "guardian.141"
	desc = {
		text = guardian.144.a.desc
		trigger = {
			NOT = {
				has_relation_flag = { 
					who = FROM
					flag = muutagan_trade 
				}
			}
			has_communications = event_target:trader_destroyer
		}
	}
	desc = {
		text = guardian.144.b.desc
		trigger = {
			NOT = { 
				has_relation_flag = { 
					who = FROM
					flag = muutagan_trade 
				}
			}
			NOT = { has_communications = event_target:trader_destroyer }
		}
	}
	desc = {
		text = guardian.144.c.desc
		trigger = {
			has_relation_flag = { 
				who = FROM
				flag = muutagan_trade 
			}
			has_communications = event_target:trader_destroyer
		}
	}
	desc = {
		text = guardian.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
		if = {
			limit = { 
				has_modifier = enclave_traders_sr3
				has_relation_flag = { 
					who = FROM
					flag = muutagan_trade
				}
			}
			remove_modifier = "enclave_traders_sr3"
		}
		if = {
			limit = {
				has_relation_flag = { 
					who = FROM
					flag = muutagan_trade
				}
				is_ai = yes
			}
			add_opinion_modifier = {
				who = event_target:trader_destroyer
				modifier = opinion_destroyed_trader_sr
			}
		}
		if = {
			limit = {
				NOT = {
					has_relation_flag = { 
						who = FROM
						flag = muutagan_trade
					}
				}
				is_ai = yes
			}
			add_opinion_modifier = {
				who = event_target:trader_destroyer
				modifier = opinion_destroyed_trader
			}
		}
	}
	
	option = {
		name = "guardian.144.a"
		trigger = {
			NOT = { 
				has_relation_flag = { 
					who = FROM
					flag = muutagan_trade 
				}
			}
		}
	}
	option = {
		name = "guardian.144.b"
		trigger = {
			has_relation_flag = { 
				who = FROM
				flag = muutagan_trade 
			}
		}
		hidden_effect = {
			remove_relation_flag = {
				who = FROM
				flag = muutagan_trade 
			}
		}
	}
}

# Continue Trade? (XuraCorp)
country_event = {
	id = guardian.150
	title = guardian.100.name
	desc = guardian.150.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}
	
	trigger = {
		NOT = { has_global_flag = xuracorp_destroyed }
		event_target:traders = {
			trust = { 
				who = root
				value > 49 
			}
		}
	}

	option = {
		name = guardian.150.a
		custom_gui = "enclave_trader_option"
		trigger = { energy > 1000 }
		add_energy = -1000
		add_modifier = {
			modifier = "enclave_traders_sr2"
			days = 3600
		}
		custom_tooltip = xuragel_effect
		hidden_effect = {
			event_target:traders = {
				add_trust = {
					who = root
					amount = 20
				}
			}
			set_relation_flag = {
				who = event_target:traders
				flag = xuracorp_trade
			}
			country_event = { id = guardian.136 days = 3600 }
		}
	}
	option = {
		name = guardian.150.b
		custom_gui = "enclave_trader_option"
		trigger = { energy > 1000 }
	}
	option = {
		name = guardian.150.c
		custom_gui = "enclave_trader_option"
		trigger = { energy < 1000 }
	}
}

# Continue Trade? (Riggans)
country_event = {
	id = guardian.151
	title = guardian.103.name
	desc = guardian.151.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}
	
	trigger = {
		NOT = { has_global_flag = riggans_destroyed }
		event_target:traders = {
			trust = { 
				who = root
				value > 49 
			}
		}	
	}

	option = {
		name = guardian.151.a
		custom_gui = "enclave_trader_option"
		trigger = { energy > 1000 }
		add_energy = -1000
		add_modifier = {
			modifier = "enclave_traders_sr1"
			days = 3600
		}
		custom_tooltip = riggan_spice_effect
		hidden_effect = {
			event_target:traders = {
				add_trust = {
					who = root
					amount = 20
				}
			}
			set_relation_flag = {
				who = event_target:traders
				flag = riggan_trade
			}
			country_event = { id = guardian.135 days = 3600 }
		}
	}
	option = {
		name = guardian.151.b
		custom_gui = "enclave_trader_option"
		trigger = { energy > 1000 }
	}
	option = {
		name = guardian.150.c
		custom_gui = "enclave_trader_option"
		trigger = { energy < 1000 }
	}
}

# Continue Trade? (Muutagans)
country_event = {
	id = guardian.152
	title = guardian.104.name
	desc = guardian.152.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}
	
	trigger = {
		NOT = { has_global_flag = muutagans_destroyed }
		event_target:traders = {
			trust = { 
				who = root
				value > 49 
			}
		}	
	}

	option = {
		name = guardian.152.a
		custom_gui = "enclave_trader_option"
		trigger = { energy > 1000 }
		add_energy = -1000
		add_modifier = {
			modifier = "enclave_traders_sr3"
			days = 3600
		}
		custom_tooltip = muutagan_crystals_effect
		hidden_effect = {
			event_target:traders = {
				add_trust = {
					who = root
					amount = 20
				}
			}
			set_relation_flag = {
				who = event_target:traders
				flag = muutagan_trade
			}
			country_event = { id = guardian.137 days = 3600 }
		}
	}
	option = {
		name = guardian.152.b
		custom_gui = "enclave_trader_option"
		trigger = { energy > 1000 }
	}
	option = {
		name = guardian.150.c
		custom_gui = "enclave_trader_option"
		trigger = { energy < 1000 }
	}
}

# Attacked XuraCorp (HIDDEN)
country_event = {
	id = guardian.155
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		is_country_type = default
		FROM = { has_country_flag = trader_enclave_country_1 }
	}

	immediate = {
		FROM = { 
			save_event_target_as = traders
			add_trust = {
				who = ROOT
				amount = -100
			}
		}
		set_country_flag = attacked_xuracorp
		if = {
			limit = { has_modifier = enclave_traders_sr2 }
			remove_modifier = enclave_traders_sr2
			remove_relation_flag = {
				who = FROM
				flag = xuracorp_trade
			}
			country_event = { id = guardian.156 }
		}
	}
}

# Attacked XuraCorp - Trade Agreement Terminated
country_event = {
	id = guardian.156
	title = guardian.100.name
	desc = guardian.156.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}

	option = {
		name = guardian.156.a
		custom_gui = "enclave_trader_option"
	}
}

# Attacked XuraCorp - Refuses Communications
country_event = {
	id = guardian.157
	title = guardian.100.name
	desc = guardian.157a.desc
	desc = guardian.157b.desc
	desc = guardian.157c.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"
	force_open = yes

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}
	
	trigger = {
		FROM = {
			is_country_type = enclave
			has_country_flag = trader_enclave_country_1
		}
		has_country_flag = attacked_xuracorp
		NOT = { has_country_flag = trader_enclave_diplomacy_engaged }
	}
	
	immediate = {
		set_country_flag = trader_enclave_diplomacy_engaged
		FROM = { save_event_target_as = traders }
	}
	
	after = {
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}

	option = {
		name = SCUM
		trigger = { has_valid_civic = civic_fanatic_purifiers }
		custom_gui = "enclave_trader_option"
	}

	option = {
		name = guardian.156.a
		custom_gui = "enclave_trader_option"
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		default_hide_option = yes
	}
}

# Attacked Riggans (HIDDEN)
country_event = {
	id = guardian.158
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		is_country_type = default
		FROM = { has_country_flag = trader_enclave_country_2 }
	}

	immediate = {
		FROM = { 
			save_event_target_as = traders
			add_trust = {
				who = ROOT
				amount = -100
			}
		}
		set_country_flag = attacked_riggans
		if = {
			limit = { has_modifier = enclave_traders_sr1 }
			remove_modifier = enclave_traders_sr1
			remove_relation_flag = {
				who = FROM
				flag = riggan_trade
			}
			country_event = { id = guardian.159}
		}
	}
}

# Attacked Riggans - Trade Agreement Terminated
country_event = {
	id = guardian.159
	title = guardian.103.name
	desc = guardian.159.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}

	option = {
		name = guardian.156.a
		custom_gui = "enclave_trader_option"
	}
}

# Attacked Riggans - Refuses Communications
country_event = {
	id = guardian.160
	title = guardian.103.name
	desc = guardian.160a.desc
	desc = guardian.160b.desc
	desc = guardian.160c.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"
	force_open = yes

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}
	
	trigger = {
		FROM = {
			is_country_type = enclave
			has_country_flag = trader_enclave_country_2
		}
		has_country_flag = attacked_riggans
		NOT = { has_country_flag = trader_enclave_diplomacy_engaged }
	}
	
	immediate = {
		set_country_flag = trader_enclave_diplomacy_engaged
		FROM = { save_event_target_as = traders }
	}
	
	after = {
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}

	option = {
		name = SCUM
		trigger = { has_valid_civic = civic_fanatic_purifiers }
		custom_gui = "enclave_trader_option"
	}

	option = {
		name = guardian.156.a
		custom_gui = "enclave_trader_option"
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		default_hide_option = yes
	}
}

# Attacked Muutagans (HIDDEN)
country_event = {
	id = guardian.161
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		is_country_type = default
		FROM = { has_country_flag = trader_enclave_country_3 }
	}

	immediate = {
		FROM = { 
			save_event_target_as = traders
			add_trust = {
				who = ROOT
				amount = -100
			}
		}
		set_country_flag = attacked_muutagans
		if = {
			limit = { has_modifier = enclave_traders_sr3 }
			remove_modifier = enclave_traders_sr3
			remove_relation_flag = {
				who = FROM
				flag = muutagan_trade
			}
			country_event = { id = guardian.162}
		}
	}
}

# Attacked Muutagans - Trade Agreement Terminated
country_event = {
	id = guardian.162
	title = guardian.104.name
	desc = guardian.162.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}

	option = {
		name = guardian.156.a
		custom_gui = "enclave_trader_option"
	}
}

# Attacked Muutagans - Refuses Communications
country_event = {
	id = guardian.163
	title = guardian.104.name
	desc = guardian.163a.desc
	desc = guardian.163b.desc
	desc = guardian.163c.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"
	force_open = yes

	picture_event_data = {
		portrait = event_target:traders
		room = enclave_trader_room
	}
	
	trigger = {
		FROM = {
			is_country_type = enclave
			has_country_flag = trader_enclave_country_3
		}
		has_country_flag = attacked_muutagans
		NOT = { has_country_flag = trader_enclave_diplomacy_engaged }
	}
	
	immediate = {
		set_country_flag = trader_enclave_diplomacy_engaged
		FROM = { save_event_target_as = traders }
	}
	
	after = {
		hidden_effect = {
			remove_country_flag = trader_enclave_diplomacy_engaged
		}
	}

	option = {
		name = SCUM
		trigger = { has_valid_civic = civic_fanatic_purifiers }
		custom_gui = "enclave_trader_option"
	}

	option = {
		name = guardian.156.a
		custom_gui = "enclave_trader_option"
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		default_hide_option = yes
	}
}

# Artists
country_event = {
	id = guardian.300
	title = guardian.300.name
	desc = {
		trigger = {
			switch = {
				trigger = has_country_flag
				artist_enclave_diplomacy_continued = { text = guardian.300.desc.continued }
				recently_purchased_art = { text = guardian.302.a.reply }
				recently_purchased_patron = { text = guardian.304.a.reply }
				recently_purchased_festival = { text = guardian.303.a.reply }
				default = { text = guardian.300.desc }
			}
		}
	}
	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
		room = enclave_artist_room
	}
	
	trigger = {
		from = {
			is_country_type = enclave
			has_country_flag = artist_enclave_country
		}
		OR = {
			OR = {
				has_country_flag = artist_enclave_diplomacy_continued
				NOT = { has_country_flag = artist_enclave_diplomacy_engaged }
			}
			has_country_flag = recently_purchased_art
			has_country_flag = recently_purchased_patron
			has_country_flag = recently_purchased_festival
		}
		NOT = {	has_country_flag = enclave_artist_ignores }
	}

	immediate = {
		save_event_target_as = my_country
		set_country_flag = artist_enclave_diplomacy_engaged
		if = {
			limit = {
				NOT = { exists = event_target:artist_enclave }
			}
			from = {
				save_event_target_as = artist_enclave
			}
		}
	}

	option = {
		name = guardian.300.a
		trigger = {
			check_variable = {
				which = artist_monument_purchased
				value < 5
			}
			NOT = { has_valid_civic = civic_fanatic_purifiers }
		}
		hidden_effect = {
			country_event = { id = guardian.302 }
		}
	}
	option = {
		name = guardian.300.a
		response_text = guardian.300.a.reply
		is_dialog_only = yes
		trigger = {
			check_variable = {
				which = artist_monument_purchased
				value = 5
			}
			NOT = { has_valid_civic = civic_fanatic_purifiers }
		}
	}
	option = {
		name = guardian.300.b
		trigger = {
			NOT = { has_modifier = enclave_artist_patron }
			NOT = { has_valid_civic = civic_fanatic_purifiers }
		}
		hidden_effect = {
			country_event = { id = guardian.304 }
		}
	}
	option = {
		name = guardian.300.b.stop
		response_text = guardian.300.b.reply
		trigger = {
			has_modifier = enclave_artist_patron
			NOT = { has_valid_civic = civic_fanatic_purifiers }
		}
		custom_tooltip = opinion-5
		custom_tooltip = guardian.300.b.stop.tooltip
		remove_modifier = enclave_artist_patron
		hidden_effect = {
			remove_country_flag = artist_enclave_diplomacy_engaged
			remove_country_flag = artist_patron
			set_country_flag = enclave_stopped_patronage
			event_target:artist_enclave_country = {
				add_trust = {
					who = root
					amount = -5
				}
			}
		}
	}
	option = {
		name = guardian.300.c
		trigger = {
			NOT = {
				has_valid_civic = civic_fanatic_purifiers
				has_country_flag = artist_festival_purchased
				has_authority = auth_hive_mind
			}
		}
		allow = {
			custom_tooltip = {
				text = guardian.300.c.allow
				NOT = {
					has_country_flag = artist_festival_purchased
				}
				event_target:artist_enclave_country = {
					trust = {
						who = root
						value > 49.99
					}
				}
			}
		}
		hidden_effect = {
			country_event = { id = guardian.303 }
		}
	}
	option = {
		name = guardian.300.c
		trigger = {
			has_country_flag = artist_festival_purchased
			NOT = { 
				has_valid_civic = civic_fanatic_purifiers 
				has_authority = auth_hive_mind
			}
		}
		allow = {
			custom_tooltip = {
				text = guardian.300.c.outofstock
				NOT = {
					has_country_flag = artist_festival_purchased
				}
			}
		}
		hidden_effect = {
			country_event = { id = guardian.303 }
		}
	}
	option = {
		name = guardian.300.d
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		is_dialog_only = yes
		response_text = guardian.300.d.reply
	}
	option = {
		name = GOODBYE
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		default_hide_option = yes
		hidden_effect = {
			remove_country_flag = artist_enclave_diplomacy_engaged
			remove_country_flag = artist_enclave_diplomacy_continued
		}
	}

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

	after = {
		hidden_effect = {
			remove_country_flag = artist_enclave_diplomacy_engaged
			remove_country_flag = artist_enclave_diplomacy_continued
			remove_country_flag = recently_purchased_art
			remove_country_flag = recently_purchased_patron
			remove_country_flag = recently_purchased_festival
		}
	}
}
# Port
country_event = {
	id = guardian.301
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		from = {
			if = {
				limit = {
					NOT = { has_country_flag = enclave_artist_ignores }
				}
				country_event = { id = guardian.315 }
				else = {
					country_event = { id = guardian.313 }
				}
			}
		}
	}
}

# Artist Introduction
country_event = {
	id = guardian.315
	title = guardian.300.name
	desc = guardian.315.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_trader_window"

	picture_event_data = {
		portrait = from
		room = enclave_artist_room
	}

	option = {
		name = INTERESTING
		custom_gui = "enclave_artist_option"
		trigger = {
			NOT = { has_valid_civic = civic_fanatic_purifiers }
		}
	}

	option = {
		name = SCUM
		custom_gui = "enclave_artist_option"
		trigger = {
			has_valid_civic = civic_fanatic_purifiers
		}
	}
}

#Trying to buy an Art Piece
country_event = {
	id = guardian.302
	title = guardian.300.name
	desc = guardian.302.desc
	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
		room = enclave_artist_room
	}
	
	trigger = {
		has_country_flag = artist_enclave_diplomacy_engaged
	}

	option = {
		name = DEAL
		add_minerals = -1000
		add_influence = -25
		custom_tooltip = opinion10
		custom_tooltip = guardian.302.a.tooltip
		allow = {
			custom_tooltip = {
				text = guardian.deal.tooltip
				minerals > 999.99
				influence > 24.99
			}
		}
		hidden_effect = {
			event_target:artist_enclave = {
				add_trust = {
					who = root
					amount = 10
				}
			}
			set_country_flag = recently_purchased_art
			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
						}
					}
				}
			}
		}
	}
	option = {
		name = TOOPOOR
		trigger = {
			OR = {
				minerals < 1000
				influence < 25
			}
		}
		hidden_effect = {
			set_country_flag = artist_enclave_diplomacy_continued
		}
	}
	option = {
		name = NODEAL
		default_hide_option = yes
		trigger = {
			NOR = {
				minerals < 1000
				influence < 25
			}
		}
		hidden_effect = {
			set_country_flag = artist_enclave_diplomacy_continued
		}
	}

	after = {
		hidden_effect = {
			country_event = { id = guardian.300 }
		}
	}
}
#Trying to hire Artist for a festival
country_event = {
	id = guardian.303
	title = guardian.300.name
	desc = guardian.303.desc
	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
		room = enclave_artist_room
	}
	
	trigger = {
		has_country_flag = artist_enclave_diplomacy_engaged
		event_target:artist_enclave = {
			trust = {
				who = root
				value > 50
			}
		}
	}

	option = {
		name = DEAL
		allow = {
			custom_tooltip = {
				text = guardian.deal.tooltip
				energy > 499.99
				minerals > 499.99
				influence > 99.99
			}
		}
		add_energy = -500
		add_minerals = -500
		add_influence = -100
		custom_tooltip = opinion5
		add_modifier = {
			modifier = enclave_artist_festival
			days = 1800
		}
		hidden_effect = {
			event_target:artist_enclave = {
				add_trust = {
					who = root
					amount = 5
				}
			}
			set_timed_country_flag = { flag = artist_festival_purchased days = 7200 }
			country_event = { id = guardian.314 days = 1800 }
			set_country_flag = recently_purchased_festival
			country_event = { id = guardian.309 }
		}
	}
	option = {
		name = TOOPOOR
		trigger = {
			OR = {
				energy < 500
				minerals < 750
				influence < 100
			}
		}
		hidden_effect = {
			set_country_flag = artist_enclave_diplomacy_continued
		}
	}
	option = {
		name = NODEAL
		default_hide_option = yes
		hidden_effect = {
			set_country_flag = artist_enclave_diplomacy_continued
		}
	}
	after = {
		hidden_effect = {
			remove_country_flag = artist_enclave_diplomacy_engaged
			country_event = { id = guardian.300 }
		}
	}
}
#Trying to become a patron
country_event = {
	id = guardian.304
	title = guardian.300.name
	desc = guardian.304.desc
	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
		room = enclave_artist_room
	}
	
	trigger = {
		has_country_flag = artist_enclave_diplomacy_engaged
	}

	#option = {
	#	name = DEAL
	#	custom_tooltip = guardian.304.a.tooltip
	#	add_modifier = {
	#		modifier = enclave_artist_patron
	#		days = 3600
	#	}
	#	allow = {
	#		custom_tooltip = {
	#			text = guardian.deal.tooltip
	#			OR = {
	#				has_monthly_income = { resource = energy value > 24.99 }
	#				energy > 24.99
	#			}
	#			OR = {
	#				has_monthly_income = { resource = minerals value > 24.99 }
	#				minerals > 24.99
	#			}
	#			OR = {
	#				has_monthly_income = { resource = influence value > 0.99 }
	#				influence > 0.99
	#			}
	#		}
	#	}
	#	hidden_effect = {
	#		if = {
	#			limit = {
	#				has_country_flag = enclave_stopped_patronage
	#			}
	#			remove_country_flag = enclave_stopped_patronage
	#		}
	#		set_country_flag = artist_patron
	#		set_country_flag = recently_purchased_patron
	#		country_event = { id = guardian.306 days = 30 } #check if still patron in a month
	#		country_event = { id = guardian.320 } #trigger patron followup events
	#		country_event = { id = guardian.308 days = 359 }
	#	}
	#}

	option = {
		name = DEAL
		custom_tooltip = guardian.304.a.tooltip
		trigger = {
			num_pops < 61
		}		
		allow = {
			energy > 1000
		}
		add_energy = -1000
		add_modifier = {
			modifier = enclave_artist_patron
			days = 3600
		}
		hidden_effect = {
			if = {
				limit = {
					has_country_flag = enclave_stopped_patronage
				}
				remove_country_flag = enclave_stopped_patronage
			}
			set_country_flag = artist_patron
			set_country_flag = recently_purchased_patron
			country_event = { id = guardian.306 days = 30 } #check if still patron in a month
			country_event = { id = guardian.320 } #trigger patron followup events
			country_event = { id = guardian.308 days = 360 }
			country_event = { id = guardian.319 days = 3600 } #patronage renewal
		}
	}

	option = {
		name = DEAL
		custom_tooltip = guardian.304.a.tooltip
		trigger = {
			num_pops > 60
			num_pops < 121
		}
		allow = {
			energy > 2000
		}
		add_energy = -2000
		add_modifier = {
			modifier = enclave_artist_patron
			days = 3600
		}
		hidden_effect = {
			if = {
				limit = {
					has_country_flag = enclave_stopped_patronage
				}
				remove_country_flag = enclave_stopped_patronage
			}
			set_country_flag = artist_patron
			set_country_flag = recently_purchased_patron
			country_event = { id = guardian.306 days = 30 } #check if still patron in a month
			country_event = { id = guardian.320 } #trigger patron followup events
			country_event = { id = guardian.308 days = 360 }
			country_event = { id = guardian.319 days = 3600 } #patronage renewal
		}
	}

	option = {
		name = DEAL
		custom_tooltip = guardian.304.a.tooltip
		trigger = {
			num_pops > 120
			num_pops < 181
		}
		allow = {
			energy > 3000
			hidden_trigger = {
				NOT = { has_country_flag = attacked_curators }
			}
		}
		add_energy = -3000
		add_modifier = {
			modifier = enclave_artist_patron
			days = 3600
		}
		hidden_effect = {
			if = {
				limit = {
					has_country_flag = enclave_stopped_patronage
				}
				remove_country_flag = enclave_stopped_patronage
			}
			set_country_flag = artist_patron
			set_country_flag = recently_purchased_patron
			country_event = { id = guardian.306 days = 30 } #check if still patron in a month
			country_event = { id = guardian.320 } #trigger patron followup events
			country_event = { id = guardian.308 days = 360 }
			country_event = { id = guardian.319 days = 3600 } #patronage renewal
		}
	}

	option = {
		name = DEAL
		custom_tooltip = guardian.304.a.tooltip
		trigger = {
			num_pops > 180
			num_pops < 241
		}
		allow = {
			energy > 4000
		}
		add_energy = -4000
		add_modifier = {
			modifier = enclave_artist_patron
			days = 3600
		}
		custom_tooltip = opinion20
		hidden_effect = {
			if = {
				limit = {
					has_country_flag = enclave_stopped_patronage
				}
				remove_country_flag = enclave_stopped_patronage
			}
			set_country_flag = artist_patron
			set_country_flag = recently_purchased_patron
			country_event = { id = guardian.306 days = 30 } #check if still patron in a month
			country_event = { id = guardian.320 } #trigger patron followup events
			country_event = { id = guardian.308 days = 360 }
			country_event = { id = guardian.319 days = 3600 } #patronage renewal
		}
	}

	option = {
		name = DEAL
		custom_tooltip = guardian.304.a.tooltip
		trigger = { num_pops > 240 }
		allow = {
			energy > 5000
		}
		add_energy = -5000
		add_modifier = {
			modifier = enclave_artist_patron
			days = 3600
		}
		custom_tooltip = opinion20
		hidden_effect = {
			if = {
				limit = {
					has_country_flag = enclave_stopped_patronage
				}
				remove_country_flag = enclave_stopped_patronage
			}
			set_country_flag = artist_patron
			set_country_flag = recently_purchased_patron
			country_event = { id = guardian.306 days = 30 } #check if still patron in a month
			country_event = { id = guardian.320 } #trigger patron followup events
			country_event = { id = guardian.308 days = 360 }
			country_event = { id = guardian.319 days = 3600 } #patronage renewal
		}
	}

	option = {
		name = NODEAL
		default_hide_option = yes
		hidden_effect = {
			set_country_flag = artist_enclave_diplomacy_continued
		}
	}
	
	after = {
		hidden_effect = {
			remove_country_flag = artist_enclave_diplomacy_engaged
			country_event = { id = guardian.300 }
		}
	}
}
#building stuff
planet_event = {
	id = guardian.305
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		from = {
			has_prev_building = building_artist
		}
	}

	immediate = {
		owner = {
			change_variable = {
				which = artist_monuments_built
				value = -1
			}
		}
	}
}
#Patron modifier checks
country_event = {
	id = guardian.306
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		has_modifier = enclave_artist_patron
		has_country_flag = artist_patron
		NOT = { has_country_flag = enclave_stopped_patronage }
	}

	immediate = {
		#if = {
		#	limit = {
		#		OR = {
		#			has_monthly_income = { resource = energy value > 24.99 }
		#			energy > 24.99
		#		}
		#		OR = {
		#			has_monthly_income = { resource = minerals value > 24.99 }
		#			minerals > 24.99
		#		}
		#		OR = {
		#			has_monthly_income = { resource = influence value > 0.99 }
		#			influence > 0.99
		#		}
		#	}
			event_target:artist_enclave_country = {
				add_trust = {
					who = root
					amount = 1
				}
			}
			country_event = { id = guardian.306 days = 30 }
		#	else = {
		#		event_target:artist_enclave_country = {
		#			add_trust = {
		#				who = root
		#				amount = -5
		#			}
		#		}
		#		remove_modifier = enclave_artist_patron
		#		remove_country_flag = artist_patron
		#		country_event = { id = guardian.307 }
		#	}
		#}
	}
}
#Patronage ended because not enough resources
#country_event = {
#	id = guardian.307
#	title = guardian.300.name
#	desc = guardian.307.desc
#	picture = GFX_evt_space_station
#	show_sound = event_planetary_riot
#	location = event_target:this_planet
#
#	is_triggered_only = yes
#
#	immediate = {
#		random_planet = {
#			limit = {
#				has_planet_flag = guardians_artists_planet
#			}
#			save_event_target_as = this_planet
#		}
#	}
#	option = {
#		name = UNFORTUNATE
#		custom_tooltip = guardian.307.a.tooltip
#	}
#}

# Patronage year counter for achievement
country_event = {
	id = guardian.308
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				has_modifier = enclave_artist_patron
				check_variable = {
					which = patronage_duration
					value = 9
				}
			}
			set_country_flag = 10yr_patronage
			break = yes
		}
		if = {
			limit = {
				NOT = { has_modifier = enclave_artist_patron }
			}
			set_variable = {
				which = patronage_duration
				value = 0
			}
			break = yes
		}
		if = {
			limit = { has_modifier = enclave_artist_patron }
			if = {
				limit = { check_variable = { which = patronage_duration value < 1 } }
				set_variable = {
					which = patronage_duration
					value = 1
				}
				else = {
					change_variable = {
						which = patronage_duration
						value = 1
					}
				}
			}
			country_event = { id = guardian.308 days = 360 }
		}
	}
}

#Festival Event Trigger
country_event = {
	id = guardian.309
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		random_list = {
			10 = {
				modifier = {
					factor = 1.5
					OR = {
						has_ethic = ethic_fanatic_materialist
						has_ethic = ethic_materialist
					}
				}
				country_event = { id = guardian.310 days = 250 random = 25 }
			}
			10 = {
				modifier = {
					factor = 1.5
					OR = {
						has_ethic = ethic_fanatic_xenophile
						has_ethic = ethic_xenophile
						has_ethic = ethic_fanatic_pacifist
						has_ethic = ethic_pacifist
					}
				}
				country_event = { id = guardian.311 days = 150 random = 25 }
			}
			5 = {
				modifier = {
					factor = 1.5
					OR = {
						has_ethic = ethic_fanatic_xenophobe
						has_ethic = ethic_xenophobe
						has_ethic = ethic_fanatic_materialist
						has_ethic = ethic_materialist
					}
				}
				country_event = { id = guardian.312 days = 300 random = 50 }
			}
			75 = { }
		}
	}
}

#Artist Festival events
#People get trampled
country_event = {
	id = guardian.310
	title = guardian.310.name
	desc = guardian.310.desc
	picture = GFX_evt_alien_ruins
	show_sound = event_planetary_riot
	location = event_target:this_planet

	is_triggered_only = yes
	
	trigger = {
		has_modifier = enclave_artist_festival
	}

	immediate = {
		random_owned_planet = {
			save_event_target_as = this_planet
		}
	}
	option = {
		name = UNFORTUNATE
		add_modifier = {
			modifier = enclave_artist_festival_outrage
			days = 720
		}
	}
	option = {
		name = guardian.310.b
		add_influence = -100
	}

	after = {
		event_target:this_planet = {
			random_pop = {
				kill_pop = yes
			}
		}
	}
}
#Artists want to move in
country_event = {
	id = guardian.311
	title = guardian.311.name
	desc = guardian.311.desc
	picture = GFX_evt_metropolis
	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
			has_authority = auth_hive_mind
		}
	}

	immediate = {
		random_owned_planet = {
			limit = {
				free_pop_tiles > 2
			}
			save_event_target_as = this_planet
		}
		random_country = {
			limit = {
				has_country_flag = artist_enclave_country
			}
			species = {
				save_event_target_as = artist_species
			}
		}
	}
	option = {
		name = guardian.311.a
		event_target:this_planet = {
			best_tile_for_pop = {
				create_pop = {
					species = event_target:artist_species
					ethos = {
						ethic = "ethic_xenophile"
					}
				}
			}
			best_tile_for_pop = {
				create_pop = {
					species = event_target:artist_species
					ethos = {
						ethic = "ethic_xenophile"
					}
				}
			}
			every_owned_pop = {
				limit = { is_same_species = event_target:artist_species }
				modify_species = {
					ideal_planet_class = event_target:this_planet
				}
			}
		}
	}
	option = {
		name = guardian.311.b
	}
}
#The artists flee and steal your stuff
country_event = {
	id = guardian.312
	title = guardian.312.name
	desc = guardian.312.desc
	picture = GFX_evt_metropolis
	show_sound = event_planetary_riot
	location = event_target:location

	is_triggered_only = yes
	
	trigger = {
		has_modifier = enclave_artist_festival
	}
	
	immediate = {
		set_timed_country_flag = { flag = enclave_artist_ignores days = 3600 }
		random_planet = {
			limit = {
				has_planet_flag = guardians_artists_planet
			}
			save_event_target_as = location
		}
	}

	option = {
		name = guardian.312.a
		remove_modifier = enclave_artist_festival
		add_energy = -500
		add_minerals = -500
		hidden_effect = {
			remove_country_flag = artist_festival_purchased
		}
	}
}
#Artists don't answer your calls after stealing your stuff or being attacked
country_event = {
	id = guardian.313
	title = guardian.300.name
	desc = guardian.313.desc
	desc = {
		trigger = {
			switch = {
				trigger = has_country_flag
				enclave_artist_encountered = { text = guardian.313.desc }
				default = { text = guardian.313.desc.unknown }
			}
		}
	}
	picture = GFX_evt_space_station
	show_sound = event_radio_chatter
	location = event_target:location

	is_triggered_only = yes
	
	trigger = {
		from = {
			AND = {
				is_country_type = enclave
				has_country_flag = artist_enclave_country
			}
		}
		has_country_flag = enclave_artist_ignores
		NOT = {
			has_country_flag = artist_enclave_diplomacy_engaged
		}
	}

	immediate = {
		random_planet = {
			limit = {
				has_planet_flag = guardians_artists_planet
			}
			save_event_target_as = location
		}
		set_country_flag = artist_enclave_diplomacy_engaged
	}

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

	option = {
		name = guardian.313.a
		default_hide_option = yes
		trigger = {
			has_country_flag = enclave_artist_encountered
			NOT = { has_valid_civic = civic_fanatic_purifiers }
		}
		hidden_effect = {
			remove_country_flag = artist_enclave_diplomacy_engaged
		}
	}
	option = {
		name = PECULIAR
		trigger = {
			NOT = { has_country_flag = enclave_artist_encountered }
			NOT = { has_valid_civic = civic_fanatic_purifiers }
		}
		hidden_effect = {
			remove_country_flag = artist_enclave_diplomacy_engaged
		}
	}
}
#Festival ends stuff
country_event = {
	id = guardian.314
	hide_window = yes

	is_triggered_only = yes
	
	trigger = {
		has_country_flag = artist_festival_purchased
	}
	
	immediate = {
		remove_country_flag = artist_festival_purchased
	}
}

#Patronage renewal
country_event = {
	id = guardian.319
	title = guardian.300.name
	desc = guardian.319.desc
	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
		room = enclave_artist_room
	}

	#option = {
	#	name = DEAL
	#	custom_tooltip = guardian.304.a.tooltip
	#	add_modifier = {
	#		modifier = enclave_artist_patron
	#		days = 3600
	#	}
	#	allow = {
	#		custom_tooltip = {
	#			text = guardian.deal.tooltip
	#			OR = {
	#				has_monthly_income = { resource = energy value > 24.99 }
	#				energy > 24.99
	#			}
	#			OR = {
	#				has_monthly_income = { resource = minerals value > 24.99 }
	#				minerals > 24.99
	#			}
	#			OR = {
	#				has_monthly_income = { resource = influence value > 0.99 }
	#				influence > 0.99
	#			}
	#		}
	#	}
	#	hidden_effect = {
	#		if = {
	#			limit = {
	#				has_country_flag = enclave_stopped_patronage
	#			}
	#			remove_country_flag = enclave_stopped_patronage
	#		}
	#		set_country_flag = artist_patron
	#		set_country_flag = recently_purchased_patron
	#		country_event = { id = guardian.306 days = 30 } #check if still patron in a month
	#		country_event = { id = guardian.320 } #trigger patron followup events
	#		country_event = { id = guardian.308 days = 359 }
	#	}
	#}

	option = {
		name = DEAL
		custom_tooltip = guardian.304.a.tooltip
		allow = {
			energy > 1000
		}
		add_energy = -1000
		add_modifier = {
			modifier = enclave_artist_patron
			days = 3600
		}
		custom_tooltip = opinion20
		hidden_effect = {
			event_target:artist_enclave_country = {
				add_trust = {
					who = root
					amount = 20
				}
			}
			hidden_effect = {
				if = {
					limit = {
						has_country_flag = enclave_stopped_patronage
					}
					remove_country_flag = enclave_stopped_patronage
				}
				set_country_flag = artist_patron
				set_country_flag = recently_purchased_patron
				country_event = { id = guardian.306 days = 30 } #check if still patron in a month
				country_event = { id = guardian.320 } #trigger patron followup events
				country_event = { id = guardian.308 days = 359 }
				country_event = { id = guardian.319 days = 3600 } #patronage renewal
			}
		}
	}

	option = {
		name = NODEAL
		default_hide_option = yes
	}
}

#Patron Event Trigger
country_event = {
	id = guardian.320
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		has_modifier = enclave_artist_patron
		has_country_flag = artist_patron
		NOT = {
			has_country_flag = enclave_stopped_patronage
			has_country_flag = enclave_artist_ignores
		}
	}

	immediate = {
		random_list = {
			20 = {
				modifier = {
					factor = 2
					NOT = { has_country_flag = enclave_artist_patron_events }
				}
				modifier = {
					factor = 2
					check_variable = {
						which = artist_newsletter
						value < 5
					}
				}
				modifier = {
					factor = 0
					check_variable = {
						which = artist_newsletter
						value > 4
					}
				}
				country_event = { id = guardian.321 days = 500 random = 1000 }
			}
			20 = {
				modifier = {
					factor = 0
					has_country_flag = enclave_artist_patron_event_1
				}
				country_event = { id = guardian.322 days = 500 random = 1000 }
			}
			20 = {
				modifier = {
					factor = 0
					has_country_flag = enclave_artist_patron_event_2
				}
				country_event = { id = guardian.323 days = 500 random = 1000 }
			}
			20 = {
				modifier = {
					factor = 0
					has_country_flag = enclave_artist_patron_event_3
				}
				country_event = { id = guardian.324 days = 500 random = 1000 }
			}
			20 = {
				modifier = {
					factor = 0.20
					NOT = { has_country_flag = enclave_artist_patron_events }
				}
				modifier = {
					factor = 1.10
					has_country_flag = enclave_artist_patron_event_1
				}
				modifier = {
					factor = 1.10
					has_country_flag = enclave_artist_patron_event_2
				}
				modifier = {
					factor = 1.10
					has_country_flag = enclave_artist_patron_event_3
				}
				#DO NOTHING
			}
		}
	}
}
#Patron Newsletter
country_event = {
	id = guardian.321
	title = guardian.321.name
	desc = {
		trigger = {
			text = "guardian.321.desc"
			text = "newline"
			success_text = {
				text = "guardian.321.desc.a"
				check_variable = {
					which = artist_newsletter
					value = 1
				}
			}
			success_text = {
				text = "guardian.321.desc.b"
				check_variable = {
					which = artist_newsletter
					value = 2
				}
			}
			success_text = {
				text = "guardian.321.desc.c"
				check_variable = {
					which = artist_newsletter
					value = 3
				}
			}
			success_text = {
				text = "guardian.321.desc.d"
				check_variable = {
					which = artist_newsletter
					value = 4
				}
			}
		}
	}
	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
	}

	is_triggered_only = yes
	
	trigger = {
		has_modifier = enclave_artist_patron
		has_country_flag = artist_patron
		NOT = {
			has_country_flag = enclave_stopped_patronage
			has_country_flag = enclave_artist_ignores
		}
		check_variable = {
			which = artist_newsletter
			value < 5
		}
	}

	immediate = {
		set_country_flag = enclave_artist_patron_events
		if = {
			limit = {
				check_variable = {
					which = artist_newsletter
					value < 1
				}
			}
			set_variable = {
				which = artist_newsletter
				value = 1
			}
			else = {
				change_variable = {
					which = artist_newsletter
					value = 1
				}
			}
		}
		random_system = {
			limit = {
				any_planet = {
					has_planet_flag = guardians_artists_planet
				}
				root = {
					intel_level = {
						level > none
						system = prev
					}
				}
			}
			save_event_target_as = this_planet
		}
	}

	option = {
		name = guardian.321.a
		response_text = guardian.321.a.reply
		add_minerals = -500
		add_influence = 50
		allow = {
			custom_tooltip = {
				text = guardian.deal.tooltip
				minerals > 499.99
			}
		}
	}
	option = {
		name = guardian.321.b
		response_text = guardian.321.b.reply
		hidden_effect = {
			set_variable = {
				which = artist_newsletter
				value = 5
			}
		}
	}
	
	after = {
		hidden_effect = {
			country_event = { id = guardian.320 days = 60 random = 30 }
		}
	}
}
#Patron commission
country_event = {
	id = guardian.322
	title = guardian.322.name
	desc = guardian.322.desc
	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
	}

	is_triggered_only = yes
	
	trigger = {
		has_modifier = enclave_artist_patron
		has_country_flag = artist_patron
		NOT = {
			has_country_flag = enclave_stopped_patronage
			has_country_flag = enclave_artist_ignores
			has_country_flag = artist_building_patron
		}
	}

	immediate = {
		set_country_flag = enclave_artist_patron_events
		set_country_flag = enclave_artist_patron_event_1
		random_system = {
			limit = {
				any_planet = {
					has_planet_flag = guardians_artists_planet
				}
				root = {
					intel_level = {
						level > none
						system = prev
					}
				}
			}
			save_event_target_as = this_planet
		}
	}
	option = {
		name = DEAL
		custom_tooltip = guardian.322.a.tooltip
		response_text = guardian.302.a.reply
		allow = {
			custom_tooltip = {
				text = guardian.deal.tooltip
				energy > 999.99
				minerals > 999.99
			}
		}
		hidden_effect = {
			add_energy = -1000
			add_minerals = -1000
			set_country_flag = artist_building_patron
		}
	}
	option = {
		name = TOOPOOR
		trigger = {
			OR = {
				minerals < 1000
				energy < 1000
			}
		}
	}
	option = {
		name = NODEAL
		trigger = {
			minerals > 999.99
			energy > 999.99
		}
	}

	after = {
		hidden_effect = {
			country_event = { id = guardian.320 days = 100 random = 25 }
		}
	}
}
#I became a patron and all I got was this t-shirt
country_event = {
	id = guardian.323
	title = guardian.323.name
	desc = guardian.323.desc
	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
	}

	is_triggered_only = yes
	
	trigger = {
		has_modifier = enclave_artist_patron
		has_country_flag = artist_patron
		NOT = {
			has_country_flag = enclave_stopped_patronage
			has_country_flag = enclave_artist_ignores
		}
	}

	immediate = {
		set_country_flag = enclave_artist_patron_events
		set_country_flag = enclave_artist_patron_event_2
		random_system = {
			limit = {
				any_planet = {
					has_planet_flag = guardians_artists_planet
				}
				root = {
					intel_level = {
						level > none
						system = prev
					}
				}
			}
			save_event_target_as = this_planet
		}
	}
	option = {
		name = guardian.323.a
		custom_tooltip = opinion10
		response_text = guardian.323.a.reply
		hidden_effect = {
			event_target:artist_enclave_country = {
				add_trust = {
					who = root
					amount = 10
				}
			}
			country_event = { id = guardian.320 days = 100 random = 25 }
		}
	}
	option = {
		name = guardian.323.b
		add_energy = 500
		add_minerals = 500
		custom_tooltip = opinion-3
		remove_modifier = enclave_artist_patron
		hidden_effect = {
			event_target:artist_enclave_country = {
				add_trust = {
					who = root
					amount = -3
				}
			}
		}
		response_text = guardian.323.b.reply
	}
}
#Artist asks if you want some resources
country_event = {
	id = guardian.324
	title = guardian.324.name
	desc = guardian.324.desc
	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
	}

	is_triggered_only = yes
	
	trigger = {
		has_modifier = enclave_artist_patron
		has_country_flag = artist_patron
		NOT = {
			has_country_flag = enclave_stopped_patronage
			has_country_flag = enclave_artist_ignores
		}
	}

	immediate = {
		set_country_flag = enclave_artist_patron_events
		set_country_flag = enclave_artist_patron_event_3
		random_system = {
			limit = {
				any_planet = {
					has_planet_flag = guardians_artists_planet
				}
				root = {
					intel_level = {
						level > none
						system = prev
					}
				}
			}
			save_event_target_as = this_planet
		}
	}
	option = {
		name = guardian.324.a
		add_minerals = 500
		response_text = guardian.324.a.reply
	}
	option = {
		name = guardian.324.b
		add_influence = 50
		response_text = guardian.324.b.reply
	}

	after = {
		hidden_effect = {
			country_event = { id = guardian.320 days = 100 random = 25 }
		}
	}
}
country_event = {
	id = guardian.330
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		from = {
			has_country_flag = artist_enclave_country
		}
	}

	immediate = {
		if = {
			limit = {
				OR = {
					has_modifier = enclave_artist_patron
					has_country_flag = artist_patron
				}
			}
			remove_modifier = enclave_artist_patron
			remove_country_flag = artist_patron
		}
		if = {
			limit = {
				NOT = { has_country_flag = enclave_artist_ignores }
			}
			set_country_flag = enclave_artist_ignores
		}
	}
}
country_event = {
	id = guardian.331
	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 = { #Change capital
				limit = { is_custom_capital_location = yes }
				owner = {
					random_owned_fleet = {
						limit = { has_fleet_flag = artist_enclave_station }
						save_event_target_as = newCustomCapital
					}
					set_custom_capital_location = event_target:newCustomCapital
				}
			}
		}
		every_country = {
			limit = {
				has_country_flag = enclave_artist_encountered
				NOT = { is_same_value = from }
			}
			if = {
				limit = {
					fromfrom = {
						owner = {
							any_owned_fleet = {
								has_fleet_flag = artist_enclave_station
							}
						}
					}
				}
				country_event = { id = guardian.332 }
				else = {
					country_event = { id = guardian.333 }
				}
			}
		}
	}
}
# An artist station has been destroyed
country_event = {
	id = guardian.332
	title = guardian.300.name
	desc = guardian.332.desc
	picture = GFX_evt_exploding_ship
	show_sound = event_structural_collapse
	location = event_target:destroyed_station_location

	is_triggered_only = yes

	option = {
		name = WORRYING
		trigger = {
			NOT = { has_country_flag = enclave_artist_ignores }
		}
	}
	option = {
		name = OK
		trigger = {
			has_country_flag = enclave_artist_ignores
		}
	}
}
# All artist stations have been destroyed
country_event = {
	id = guardian.333
	title = guardian.300.name
	desc = guardian.333.desc
	picture = GFX_evt_exploding_ship
	show_sound = event_super_explosion
	location = event_target:destroyed_station_location

	is_triggered_only = yes
	
	trigger = {
		has_country_flag = enclave_artist_encountered
	}

	immediate = {
		if = {
			limit = {
				OR = {
					has_modifier = enclave_artist_patron
					has_country_flag = artist_patron
				}
			}
			remove_modifier = enclave_artist_patron
			remove_country_flag = 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 = TERRIBLE
		custom_tooltip = guardian.307.a.tooltip
		trigger = {
			NOT = { has_country_flag = enclave_artist_ignores }
		}
	}
	option = {
		name = OK
		custom_tooltip = guardian.307.a.tooltip
		trigger = {
			has_country_flag = enclave_artist_ignores
		}
	}
}
# You destroyed an artist station
country_event = {
	id = guardian.334
	title = guardian.300.name
	desc = {
		trigger = {
			switch = {
				trigger = has_country_flag
				enclave_artist_encountered = { text = guardian.334.desc }
				default = { text = guardian.334.desc.unknown }
			}
		}
	}
	picture = GFX_evt_exploding_ship
	show_sound = event_structural_collapse
	location = fromfrom

	is_triggered_only = yes

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

	trigger = {
		from = {
			has_country_flag = artist_enclave_country
		}
	}

	option = {
		name = EXCELLENT
		add_energy = 2000
		add_minerals = 2000
	}
}

# Curator Main Menu (Initial)
country_event = {
	id = guardian.500
	title = guardian.500.name
	desc = guardian.500a.desc
	desc = guardian.500b.desc
	desc = guardian.500c.desc
	desc = guardian.500d.desc
	desc = guardian.500e.desc
	desc = guardian.500f.desc
	desc = guardian.500g.desc
	desc = guardian.500h.desc
	desc = guardian.500i.desc
	desc = guardian.500j.desc
	desc = guardian.500k.desc
	desc = guardian.500l.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_curator_window"
	force_open = yes

	picture_event_data = {
		portrait = from
		room = enclave_curator_room
	}
	
	trigger = {
		from = {
			is_country_type = enclave
			has_country_flag = curator_enclave_country
		}
		NOT = { has_country_flag = curator_enclave_diplomacy_engaged }
		NOT = { has_country_flag = attacked_curators }
	}

	immediate = {
		set_country_flag = curator_enclave_diplomacy_engaged
		FROM = { save_event_target_as = curators }
	}

	after = {
		hidden_effect = {
			remove_country_flag = curator_enclave_diplomacy_engaged
		}
	}

	option = {
		name = SCUM
		trigger = { has_valid_civic = civic_fanatic_purifiers }
		custom_gui = "enclave_curator_option"
		hidden_effect = {
			remove_country_flag = curator_enclave_diplomacy_engaged
		}
	}

	option = { # Star Charts
		name = guardian.500.a
		custom_gui = "enclave_curator_option"
		trigger = {
			NOT = { has_valid_civic = civic_fanatic_purifiers }
			any_system = {
				any_planet = {
					is_surveyed = {
						who = ROOT
						status = no
					}
				}
			}
		}
		hidden_effect = {
			country_event = { id = guardian.506 }
		}
	}
	
	option = { # Research
		name = guardian.500.b
		custom_gui = "enclave_curator_option"
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		allow = {
			custom_tooltip = {
				fail_text = guardian.500.b.alreadyaided
				NOT = { has_modifier = curator_insight }
			}
		}
		hidden_effect = {
			country_event = { id = guardian.507 }
		}
	}
	
	option = { # Guardians
		name = guardian.500.c
		custom_gui = "enclave_curator_option"
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		hidden_effect = {
			country_event = { id = guardian.508 }
		}
	}
	
	option = { # Hire Scientist
		name = guardian.500.d
		custom_gui = "enclave_curator_option"
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		allow = {
			custom_tooltip = {
				fail_text = guardian.500.d.opinion
				event_target:curators = {
					trust = { 
						who = root
						value > 49 
					}
				}
			}
			custom_tooltip = {
				fail_text = guardian.500.d.alreadyrecruited
				NOT = {
					any_owned_leader = { has_trait = leader_trait_curator }
				}
			}
		}
		hidden_effect = {
			country_event = { id = guardian.590 }
		}
	}

	option = {
		name = guardian.500.e
		default_hide_option = yes
		custom_gui = "enclave_curator_option"
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		hidden_effect = {
			remove_country_flag = curator_enclave_diplomacy_engaged
		}
	}
}

# Curator Main Menu
country_event = {
	id = guardian.505
	title = guardian.500.name
	desc = guardian.500a.desc
	desc = guardian.500b.desc
	desc = guardian.500c.desc
	desc = guardian.500d.desc
	desc = guardian.500e.desc
	desc = guardian.500f.desc
	desc = guardian.500g.desc
	desc = guardian.500h.desc
	desc = guardian.500i.desc
	desc = guardian.500j.desc
	desc = guardian.500k.desc
	desc = guardian.500l.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_curator_window"

	picture_event_data = {
		portrait = event_target:curators
		room = enclave_curator_room
	}
	
	trigger = {
		NOT = { has_country_flag = curator_enclave_diplomacy_engaged }
	}

	immediate = {
		set_country_flag = curator_enclave_diplomacy_engaged
	}

	after = {
		hidden_effect = {
			remove_country_flag = curator_enclave_diplomacy_engaged
		}
	}

	option = { # Star Charts
		name = guardian.500.a
		custom_gui = "enclave_curator_option"
		trigger = {
			any_system = {
				any_planet = {
					is_surveyed = {
						who = ROOT
						status = no
					}
				}
			}
		}
		hidden_effect = {
			country_event = { id = guardian.506 }
		}
	}
	
	option = { # Research
		name = guardian.500.b
		custom_gui = "enclave_curator_option"
		allow = {
			custom_tooltip = {
				fail_text = guardian.500.b.alreadyaided
				NOT = { has_modifier = curator_insight }
			}
		}
		hidden_effect = {
			country_event = { id = guardian.507 }
		}
	}
	
	option = { # Guardians
		name = guardian.500.c
		custom_gui = "enclave_curator_option"
		hidden_effect = {
			country_event = { id = guardian.508 }
		}
	}
	
	option = { # Hire Scientist
		name = guardian.500.d
		custom_gui = "enclave_curator_option"
		allow = {
			custom_tooltip = {
				fail_text = guardian.500.d.opinion
				event_target:curators = {
					trust = { 
						who = root
						value > 49 
					}
				}
			}
			custom_tooltip = {
				fail_text = guardian.500.d.alreadyrecruited
				NOT = {
					any_owned_leader = { has_trait = leader_trait_curator }
				}
			}
		}
		hidden_effect = {
			country_event = { id = guardian.590 }
		}
	}

	option = {
		name = guardian.500.e
		default_hide_option = yes
		custom_gui = "enclave_curator_option"
		hidden_effect = {
			remove_country_flag = curator_enclave_diplomacy_engaged
		}
	}
}

# Curator Star Charts Menu
country_event = {
	id = guardian.506
	title = guardian.506.name
	desc = guardian.506a.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_curator_window"

	picture_event_data = {
		portrait = event_target:curators
		room = enclave_curator_room
	}

	immediate = {
		set_country_flag = curator_enclave_diplomacy_engaged
	}

	after = {
		hidden_effect = {
			remove_country_flag = curator_enclave_diplomacy_engaged
		}
	}

	option = {
		name = guardian.506.a
		response_text = guardian.506.a.reply
		custom_gui = "enclave_curator_option"
		allow = { energy > 1500 }
		add_energy = -1500
		custom_tooltip = opinion15
		hidden_effect = {
			while = {
				count = 15
				capital_scope = {
					closest_system = {
						limit = {
							any_planet = {
								is_surveyed = {
									who = ROOT
									status = no
								}
							}
						}
						every_system_planet = {
							limit = {
								NOT = { has_planet_flag = guardians_wraith_pulsar }
							}
							surveyed = {
								set_surveyed = yes
								surveyor = ROOT
							}
						}
						root = {
							clear_uncharted_space = {
								from = prev
								radius = 20
							}
						}
					}
				}
			}
			event_target:curators = {
				add_trust = {
					who = root
					amount = 15
				}
			}
		}
	}

	option = {
		name = guardian.506.b
		response_text = guardian.506.a.reply
		custom_gui = "enclave_curator_option"
		allow = { energy > 1000 }
		add_energy = -1000
		custom_tooltip = opinion10
		hidden_effect = {
			while = {
				count = 10
				capital_scope = {
					closest_system = {
						limit = {
							any_planet = {
								is_surveyed = {
									who = ROOT
									status = no
								}
							}
						}
						every_system_planet = {
							limit = {
								NOT = { has_planet_flag = guardians_wraith_pulsar }
							}
							surveyed = {
								set_surveyed = yes
								surveyor = ROOT
							}
						}
						root = {
							clear_uncharted_space = {
								from = prev
								radius = 20
							}
						}
					}
				}
			}
			event_target:curators = {
				add_trust = {
					who = root
					amount = 10
				}
			}
		}
	}

	option = {
		name = guardian.506.c
		response_text = guardian.506.a.reply
		custom_gui = "enclave_curator_option"
		allow = { energy > 500 }
		add_energy = -500
		custom_tooltip = opinion5
		hidden_effect = {
			while = {
				count = 5
				capital_scope = {
					closest_system = {
						limit = {
							any_planet = {
								is_surveyed = {
									who = ROOT
									status = no
								}
							}
						}
						every_system_planet = {
							limit = {
								NOT = { has_planet_flag = guardians_wraith_pulsar }
							}
							surveyed = {
								set_surveyed = yes
								surveyor = ROOT
							}
						}
						root = {
							clear_uncharted_space = {
								from = prev
								radius = 20
							}
						}
					}
				}
			}
			event_target:curators = {
				add_trust = {
					who = root
					amount = 5
				}
			}
		}
	}
	
	option = { # Back
		name = guardian.506.d
		custom_gui = "enclave_curator_option"
		hidden_effect = {
			country_event = { id = guardian.505 }
		}
	}
	
	option = { # Sign Off
		name = guardian.500.e
		custom_gui = "enclave_curator_option"
		default_hide_option = yes
	}
}

# Curator Research Aid Menu
country_event = {
	id = guardian.507
	title = guardian.507.name
	desc = guardian.507.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_curator_window"

	picture_event_data = {
		portrait = event_target:curators
		room = enclave_curator_room
	}

	immediate = {
		set_country_flag = curator_enclave_diplomacy_engaged
	}

	after = {
		hidden_effect = {
			remove_country_flag = curator_enclave_diplomacy_engaged
		}
	}

	option = {
		name = guardian.507.a
		response_text = guardian.507.a.reply
		custom_gui = "enclave_curator_option"
		trigger = { num_pops < 61 }
		allow = {
			energy > 1000
			hidden_trigger = {
				NOT = { has_country_flag = attacked_curators }
			}
		}
		add_energy = -1000
		custom_tooltip = opinion20
		add_modifier = {
			modifier = curator_insight
			days = 3600
		}
		hidden_effect = {
			event_target:curators = {
				add_trust = {
					who = root
					amount = 20
				}
			}
			set_relation_flag = {
				who = event_target:curators
				flag = curator_trade
			}
			country_event = { id = guardian.509 days = 3600 }
		}
	}

	option = {
		name = guardian.507.a
		response_text = guardian.507.a.reply
		custom_gui = "enclave_curator_option"
		trigger = {
			num_pops > 60
			num_pops < 121
		}
		allow = {
			energy > 2000
			hidden_trigger = {
				NOT = { has_country_flag = attacked_curators }
			}
		}
		add_energy = -2000
		add_modifier = {
			modifier = curator_insight
			days = 3600
		}
		custom_tooltip = opinion20
		hidden_effect = {
			event_target:curators = {
				add_trust = {
					who = root
					amount = 20
				}
			}
			set_relation_flag = {
				who = event_target:curators
				flag = curator_trade
			}
			country_event = { id = guardian.509 days = 3600 }
		}
	}

	option = {
		name = guardian.507.a
		response_text = guardian.507.a.reply
		custom_gui = "enclave_curator_option"
		trigger = {
			num_pops > 120
			num_pops < 181
		}
		allow = {
			energy > 3000
			hidden_trigger = {
				NOT = { has_country_flag = attacked_curators }
			}
		}
		add_energy = -3000
		add_modifier = {
			modifier = curator_insight
			days = 3600
		}
		custom_tooltip = opinion20
		hidden_effect = {
			event_target:curators = {
				add_trust = {
					who = root
					amount = 20
				}
			}
			set_relation_flag = {
				who = event_target:curators
				flag = curator_trade
			}
			country_event = { id = guardian.509 days = 3600 }
		}
	}

	option = {
		name = guardian.507.a
		response_text = guardian.507.a.reply
		custom_gui = "enclave_curator_option"
		trigger = {
			num_pops > 180
			num_pops < 241
		}
		allow = {
			energy > 4000
			hidden_trigger = {
				NOT = { has_country_flag = attacked_curators }
			}
		}
		add_energy = -4000
		add_modifier = {
			modifier = curator_insight
			days = 3600
		}
		custom_tooltip = opinion20
		hidden_effect = {
			event_target:curators = {
				add_trust = {
					who = root
					amount = 20
				}
			}
			set_relation_flag = {
				who = event_target:curators
				flag = curator_trade
			}
			country_event = { id = guardian.509 days = 3600 }
		}
	}

	option = {
		name = guardian.507.a
		response_text = guardian.507.a.reply
		custom_gui = "enclave_curator_option"
		trigger = { num_pops > 240 }
		allow = {
			energy > 5000
			hidden_trigger = {
				NOT = { has_country_flag = attacked_curators }
			}
		}
		add_energy = -5000
		add_modifier = {
			modifier = curator_insight
			days = 3600
		}
		custom_tooltip = opinion20
		hidden_effect = {
			event_target:curators = {
				add_trust = {
					who = root
					amount = 20
				}
			}
			set_relation_flag = {
				who = event_target:curators
				flag = curator_trade
			}
			country_event = { id = guardian.509 days = 3600 }
		}
	}
	option = { # Back
		name = guardian.506.d
		custom_gui = "enclave_curator_option"
		hidden_effect = {
			country_event = { id = guardian.505 }
		}
	}
	option = { # Sign Off
		name = guardian.506.e
		custom_gui = "enclave_curator_option"
		default_hide_option = yes
	}
}

# Curator Guardians Menu
country_event = {
	id = guardian.508
	title = guardian.508.name
	desc = guardian.508.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_curator_window"

	picture_event_data = {
		portrait = event_target:curators
		room = enclave_curator_room
	}

	immediate = {
		set_country_flag = curator_enclave_diplomacy_engaged
	}

	after = {
		hidden_effect = {
			remove_country_flag = curator_enclave_diplomacy_engaged
		}
	}

	# "Find" option
	option = {
		name = guardian.508.a
		response_text = guardian.508.a.reply
		custom_gui = "enclave_curator_option"
		trigger = {
			event_target:curators = { #debug_scope_type = country
				any_owned_fleet = {
					closest_system = {
						min_steps = 0
						max_steps = 999
						limit = {
							has_star_flag = guardian
							any_ship_in_system = {
								exists = owner
								owner = {
									NOT = {
										has_communications = root
									}
									OR = {
										is_country_type = guardian
										is_country_type = guardian_dragon
										is_country_type = guardian_sphere
										is_country_type = guardian_wraith
										is_country_type = guardian_horror
										is_country_type = guardian_fortress
										is_country_type = guardian_hiver
										is_country_type = guardian_stellarite
										is_country_type = guardian_dreadnought
									}
								}
							}
							NOR = {
								is_point_of_interest = {
									id = curator_poi_dragon
									owner = root
									event_chain = curator_poi_chain
								}
								is_point_of_interest = {
									id = curator_poi_technosphere
									owner = root
									event_chain = curator_poi_chain
								}
								is_point_of_interest = {
									id = curator_poi_wraith
									owner = root
									event_chain = curator_poi_chain
								}
								is_point_of_interest = {
									id = curator_poi_horror
									owner = root
									event_chain = curator_poi_chain
								}
								is_point_of_interest = {
									id = curator_poi_fortress
									owner = root
									event_chain = curator_poi_chain
								}
								is_point_of_interest = {
									id = curator_poi_hiver
									owner = root
									event_chain = curator_poi_chain
								}
								is_point_of_interest = {
									id = curator_poi_stellarite
									owner = root
									event_chain = curator_poi_chain
								}
								is_point_of_interest = {
									id = curator_poi_dreadnought
									owner = root
									event_chain = curator_poi_chain
								}
							}
						}
					}
				}
			}
		}
		allow = {
			energy > 300
		}
		add_energy = -300
		hidden_effect = {
			event_target:curators = {
				random_owned_fleet = {
					limit = {}
					closest_system = {
						min_steps = 0
						max_steps = 999
						limit = {
							has_star_flag = guardian
							any_ship_in_system = {
								exists = owner
								owner = {
									is_guardian_country = yes
									NOT = {
										has_communications = root
									}
								}
							}
							NOR = {
								is_point_of_interest = {
									id = curator_poi_dragon
									owner = root
									event_chain = curator_poi_chain
								}
								is_point_of_interest = {
									id = curator_poi_technosphere
									owner = root
									event_chain = curator_poi_chain
								}
								is_point_of_interest = {
									id = curator_poi_wraith
									owner = root
									event_chain = curator_poi_chain
								}
								is_point_of_interest = {
									id = curator_poi_horror
									owner = root
									event_chain = curator_poi_chain
								}
								is_point_of_interest = {
									id = curator_poi_fortress
									owner = root
									event_chain = curator_poi_chain
								}
								is_point_of_interest = {
									id = curator_poi_hiver
									owner = root
									event_chain = curator_poi_chain
								}
								is_point_of_interest = {
									id = curator_poi_stellarite
									owner = root
									event_chain = curator_poi_chain
								}
								is_point_of_interest = {
									id = curator_poi_dreadnought
									owner = root
									event_chain = curator_poi_chain
								}
							}
						}
						if = {
							limit = {
								any_ship_in_system = {
									exists = owner
									owner = {
										NOT = {
											has_communications = root
										}
										is_country_type = guardian_dragon
									}
								}
							}
							root = {
								if = {
									limit = {
										NOT = {
											has_event_chain = curator_poi_chain
										}
									}
									begin_event_chain = {
										event_chain = curator_poi_chain
										target = this
									}
								}
								create_point_of_interest = {
									id = curator_poi_dragon
									name = curator_poi_title
									desc = curator_poi_desc
									event_chain = curator_poi_chain
									location = prev
								}
							}
							break = yes
						}
						if = {
							limit = {
								any_ship_in_system = {
									exists = owner
									owner = {
										NOT = {
											has_communications = root
										}
										is_country_type = guardian_sphere
									}
								}
							}
							root = {
								if = {
									limit = {
										NOT = {
											has_event_chain = curator_poi_chain
										}
									}
									begin_event_chain = {
										event_chain = curator_poi_chain
										target = this
									}
								}
								create_point_of_interest = {
									id = curator_poi_technosphere
									name = curator_poi_title
									desc = curator_poi_desc
									event_chain = curator_poi_chain
									location = prev
								}
							}
							break = yes
						}
						if = {
							limit = {
								any_ship_in_system = {
									exists = owner
									owner = {
										NOT = {
											has_communications = root
										}
										is_country_type = guardian_horror
									}
								}
							}
							root = {
								if = {
									limit = {
										NOT = {
											has_event_chain = curator_poi_chain
										}
									}
									begin_event_chain = {
										event_chain = curator_poi_chain
										target = this
									}
								}
								create_point_of_interest = {
									id = curator_poi_horror
									name = curator_poi_title
									desc = curator_poi_desc
									event_chain = curator_poi_chain
									location = prev
								}
							}
							break = yes
						}
						if = {
							limit = {
								any_ship_in_system = {
									exists = owner
									owner = {
										NOT = {
											has_communications = root
										}
										is_country_type = guardian_stellarite
									}
								}
							}
							root = {
								if = {
									limit = {
										NOT = {
											has_event_chain = curator_poi_chain
										}
									}
									begin_event_chain = {
										event_chain = curator_poi_chain
										target = this
									}
								}
								create_point_of_interest = {
									id = curator_poi_stellarite
									name = curator_poi_title
									desc = curator_poi_desc
									event_chain = curator_poi_chain
									location = prev
								}
							}
							break = yes
						}
						if = {
							limit = {
								any_ship_in_system = {
									exists = owner
									owner = {
										NOT = {
											has_communications = root
										}
										is_country_type = guardian_hiver
									}
								}
							}
							root = {
								if = {
									limit = {
										NOT = {
											has_event_chain = curator_poi_chain
										}
									}
									begin_event_chain = {
										event_chain = curator_poi_chain
										target = this
									}
								}
								create_point_of_interest = {
									id = curator_poi_hiver
									name = curator_poi_title
									desc = curator_poi_desc
									event_chain = curator_poi_chain
									location = prev
								}
							}
							break = yes
						}
						if = {
							limit = {
								any_ship_in_system = {
									exists = owner
									owner = {
										NOT = {
											has_communications = root
										}
										is_country_type = guardian_fortress
									}
								}
							}
							root = {
								if = {
									limit = {
										NOT = {
											has_event_chain = curator_poi_chain
										}
									}
									begin_event_chain = {
										event_chain = curator_poi_chain
										target = this
									}
								}
								create_point_of_interest = {
									id = curator_poi_fortress
									name = curator_poi_title
									desc = curator_poi_desc
									event_chain = curator_poi_chain
									location = prev
								}
							}
							break = yes
						}
						if = {
							limit = {
								any_ship_in_system = {
									exists = owner
									owner = {
										NOT = {
											has_communications = root
										}
										is_country_type = guardian_wraith
									}
								}
							}
							root = {
								if = {
									limit = {
										NOT = {
											has_event_chain = curator_poi_chain
										}
									}
									begin_event_chain = {
										event_chain = curator_poi_chain
										target = this
									}
								}
								create_point_of_interest = {
									id = curator_poi_wraith
									name = curator_poi_title
									desc = curator_poi_desc
									event_chain = curator_poi_chain
									location = prev
								}
							}
							break = yes
						}
						if = {
							limit = {
								any_ship_in_system = {
									exists = owner
									owner = {
										NOT = {
											has_communications = root
										}
										is_country_type = guardian_dreadnought
									}
								}
							}
							root = {
								if = {
									limit = {
										NOT = {
											has_event_chain = curator_poi_chain
										}
									}
									begin_event_chain = {
										event_chain = curator_poi_chain
										target = this
									}
								}
								create_point_of_interest = {
									id = curator_poi_dreadnought
									name = curator_poi_title
									desc = curator_poi_desc
									event_chain = curator_poi_chain
									location = prev
								}
							}
						}
					}
				}
			}
		}
	}

	# "Poison" options
	# Dragon
	option = {
		name = guardian.508.b
		custom_gui = "enclave_curator_option"
		trigger = {
			any_country = {
				is_country_type = guardian_dragon
				has_communications = root
			}
		}
		hidden_effect = {
			country_event = { id = guardian.510 }
		}
	}
	# Enigmatic Fortress
	option = {
		name = guardian.508.c
		custom_gui = "enclave_curator_option"
		trigger = {
			any_country = {
				is_country_type = guardian_fortress
				has_communications = root
			}
		}
		hidden_effect = {
			country_event = { id = guardian.515 }
		}
	}
	# Stellarite
	option = {
		name = guardian.508.d
		custom_gui = "enclave_curator_option"
		trigger = {
			any_country = {
				is_country_type = guardian_stellarite
				has_communications = root
			}
		}
		hidden_effect = {
			country_event = { id = guardian.520 }
		}
	}
	# Dimensional Horror
	option = {
		name = guardian.508.e
		custom_gui = "enclave_curator_option"
		trigger = {
			any_country = {
				is_country_type = guardian_horror
				has_communications = root
			}
		}
		hidden_effect = {
			country_event = { id = guardian.525 }
		}
	}
	# Hiver
	option = {
		name = guardian.508.f
		custom_gui = "enclave_curator_option"
		trigger = {
			any_country = {
				is_country_type = guardian_hiver
				has_communications = root
			}
		}
		hidden_effect = {
			country_event = { id = guardian.530 }
		}
	}
	# Technosphere
	option = {
		name = guardian.508.g
		custom_gui = "enclave_curator_option"
		trigger = {
			any_country = {
				is_country_type = guardian_sphere
				has_communications = root
			}
		}
		hidden_effect = {
			country_event = { id = guardian.535 }
		}
	}
	# Automated Dreadnought
	option = {
		name = guardian.508.h
		custom_gui = "enclave_curator_option"
		trigger = {
			any_country = {
				is_country_type = guardian_dreadnought
				has_communications = root
			}
		}
		hidden_effect = {
			country_event = { id = guardian.540 }
		}
	}
	# Wraith
	option = {
		name = guardian.508.i
		custom_gui = "enclave_curator_option"
		trigger = {
			any_country = {
				is_country_type = guardian_wraith
				has_communications = root
			}
		}
		hidden_effect = {
			country_event = { id = guardian.545 }
		}
	}
	option = { # Back
		name = guardian.506.d
		custom_gui = "enclave_curator_option"
		hidden_effect = {
			country_event = { id = guardian.505 }
		}
	}
	option = { # Sign Off
		name = guardian.506.e
		default_hide_option = yes
		custom_gui = "enclave_curator_option"
	}
}

# Remove Trade Relation Flag (HIDDEN)
country_event = {
	id = guardian.509
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		remove_relation_flag = {
			who = event_target:curators
			flag = curator_trade 
		}
	}
}

# Space Dragon
# Curator Guardians Menu
country_event = {
	id = guardian.510
	title = guardian.510.name
	desc = guardian.510.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_curator_window"

	picture_event_data = {
		portrait = event_target:curators
		room = enclave_curator_room
	}

	immediate = {
		set_country_flag = curator_enclave_diplomacy_engaged
	}

	after = {
		hidden_effect = {
			remove_country_flag = curator_enclave_diplomacy_engaged
		}
	}

	option = {
		name = guardian.510.a
		response_text = guardian.510.a.reply
		is_dialog_only = yes
		custom_gui = "enclave_curator_option"
	}
	option = {
		name = guardian.510.b
		response_text = guardian.510.b.reply
		trigger = {
			NOT = { has_modifier = draconic_beats }
		}
		custom_gui = "enclave_curator_option"
		allow = {
			energy > 5000
		}
		add_energy = -5000
		add_modifier = {
			modifier = draconic_beats
			days = -1
		}
	}
	option = { # Can we fight it? (No)
		name = guardian.506.f
		trigger = { fleet_power < 5000	}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f1.reply
	}
	option = { # Can we fight it? (Probably not)
		name = guardian.506.f
		trigger = {
			fleet_power > 5000
			fleet_power < 15000
		}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f2.reply
	}
	option = { # Can we fight it? (Maybe)
		name = guardian.506.f
		trigger = {
			fleet_power > 15000
			fleet_power < 30000
		}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f3.reply
	}
	option = { # Can we fight it? (Yes)
		name = guardian.506.f
		trigger = { fleet_power > 30000 }
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f4.reply
	}
	option = { # Back
		name = guardian.506.d
		custom_gui = "enclave_curator_option"
		hidden_effect = {
			country_event = { id = guardian.505 }
		}
	}
	option = { # Sign Off
		name = guardian.506.e
		default_hide_option = yes
		custom_gui = "enclave_curator_option"
	}
}

# Enigmatic Fortress
# Curator Guardians Menu
country_event = {
	id = guardian.515
	title = guardian.515.name
	desc = guardian.515.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_curator_window"

	picture_event_data = {
		portrait = event_target:curators
		room = enclave_curator_room
	}

	immediate = {
		set_country_flag = curator_enclave_diplomacy_engaged
	}

	after = {
		hidden_effect = {
			remove_country_flag = curator_enclave_diplomacy_engaged
		}
	}

	option = {
		name = guardian.515.a
		response_text = guardian.515.a.reply
		is_dialog_only = yes
		custom_gui = "enclave_curator_option"
	}
	option = {
		name = guardian.515.b
		response_text = guardian.515.b.reply
		custom_gui = "enclave_curator_option"
		trigger = {
			NOT = { has_country_flag = bought_fortress_info_1 }
		}
		allow = {
			energy > 1000
		}
		hidden_effect = { set_country_flag = bought_fortress_info_1 }
		add_energy = -1000
	}
	option = {
		name = guardian.515.c
		response_text = guardian.515.c.reply
		custom_gui = "enclave_curator_option"
		trigger = {
			NOT = { has_country_flag = bought_fortress_info_2 }
		}
		allow = {
			energy > 1000
		}
		hidden_effect = { set_country_flag = bought_fortress_info_2 }
		add_energy = -1000
	}
	option = {
		name = guardian.515.d
		response_text = guardian.515.d.reply
		custom_gui = "enclave_curator_option"
		trigger = {
			NOT = { has_country_flag = bought_fortress_info_3 }
		}
		allow = {
			energy > 1000
		}
		hidden_effect = { set_country_flag = bought_fortress_info_3 }
		add_energy = -1000
	}
	option = {
		name = guardian.515.bb
		response_text = guardian.515.b.reply
		custom_gui = "enclave_curator_option"
		trigger = {
			has_country_flag = bought_fortress_info_1
		}
	}
	option = {
		name = guardian.515.cc
		response_text = guardian.515.c.reply
		custom_gui = "enclave_curator_option"
		trigger = {
			has_country_flag = bought_fortress_info_2
		}
	}
	option = {
		name = guardian.515.dd
		response_text = guardian.515.d.reply
		custom_gui = "enclave_curator_option"
		trigger = {
			has_country_flag = bought_fortress_info_3
		}
	}
	option = { # Can we fight it? (No)
		name = guardian.506.f
		trigger = { fleet_power < 5000	}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f1.reply
	}
	option = { # Can we fight it? (Probably not)
		name = guardian.506.f
		trigger = {
			fleet_power > 5000
			fleet_power < 15000
		}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f2.reply
	}
	option = { # Can we fight it? (Maybe)
		name = guardian.506.f
		trigger = {
			fleet_power > 15000
			fleet_power < 30000
		}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f3.reply
	}
	option = { # Can we fight it? (Yes)
		name = guardian.506.f
		trigger = { fleet_power > 30000 }
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f4.reply
	}
	option = { # Back
		name = guardian.506.d
		custom_gui = "enclave_curator_option"
		hidden_effect = {
			country_event = { id = guardian.505 }
		}
	}
	option = { # Sign Off
		name = guardian.506.e
		default_hide_option = yes
		custom_gui = "enclave_curator_option"
	}
}

# Stellarite
# Curator Guardians Menu
country_event = {
	id = guardian.520
	title = guardian.520.name
	desc = guardian.520.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_curator_window"

	picture_event_data = {
		portrait = event_target:curators
		room = enclave_curator_room
	}

	immediate = {
		set_country_flag = curator_enclave_diplomacy_engaged
	}

	after = {
		hidden_effect = {
			remove_country_flag = curator_enclave_diplomacy_engaged
		}
	}

	option = {
		name = guardian.510.a
		response_text = guardian.520.a.reply
		is_dialog_only = yes
		custom_gui = "enclave_curator_option"
	}
	option = {
		name = guardian.510.b
		response_text = guardian.520.b.reply
		trigger = {
			NOT = { has_modifier = curator_buff_stellarite }
		}
		custom_gui = "enclave_curator_option"
		allow = {
			energy > 5000
		}
		add_energy = -5000
		add_modifier = {
			modifier = curator_buff_stellarite
			days = -1
		}
	}
	option = { # Can we fight it? (No)
		name = guardian.506.f
		trigger = { fleet_power < 5000	}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f1.reply
	}
	option = { # Can we fight it? (Probably not)
		name = guardian.506.f
		trigger = {
			fleet_power > 5000
			fleet_power < 15000
		}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f2.reply
	}
	option = { # Can we fight it? (Maybe)
		name = guardian.506.f
		trigger = {
			fleet_power > 15000
			fleet_power < 30000
		}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f3.reply
	}
	option = { # Can we fight it? (Yes)
		name = guardian.506.f
		trigger = { fleet_power > 30000 }
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f4.reply
	}
	option = { # Back
		name = guardian.506.d
		custom_gui = "enclave_curator_option"
		hidden_effect = {
			country_event = { id = guardian.505 }
		}
	}
	option = { # Sign Off
		name = guardian.506.e
		default_hide_option = yes
		custom_gui = "enclave_curator_option"
	}
}

# Dimensional Horror
# Curator Guardians Menu
country_event = {
	id = guardian.525
	title = guardian.525.name
	desc = guardian.525.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_curator_window"

	picture_event_data = {
		portrait = event_target:curators
		room = enclave_curator_room
	}

	immediate = {
		set_country_flag = curator_enclave_diplomacy_engaged
	}

	after = {
		hidden_effect = {
			remove_country_flag = curator_enclave_diplomacy_engaged
		}
	}

	option = {
		name = guardian.525.a
		response_text = guardian.525.a.reply
		is_dialog_only = yes
		custom_gui = "enclave_curator_option"
	}
	option = {
		name = guardian.525.b
		response_text = guardian.525.b.reply
		trigger = {
			NOT = { has_modifier = dimensional_horror_weak_points }
		}
		custom_gui = "enclave_curator_option"
		allow = {
			energy > 5000
		}
		add_energy = -5000
		add_modifier = {
			modifier = dimensional_horror_weak_points
			days = -1
		}
	}
	option = { # Can we fight it? (No)
		name = guardian.506.f
		trigger = { fleet_power < 5000	}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f1.reply
	}
	option = { # Can we fight it? (Probably not)
		name = guardian.506.f
		trigger = {
			fleet_power > 5000
			fleet_power < 15000
		}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f2.reply
	}
	option = { # Can we fight it? (Maybe)
		name = guardian.506.f
		trigger = {
			fleet_power > 15000
			fleet_power < 30000
		}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f3.reply
	}
	option = { # Can we fight it? (Yes)
		name = guardian.506.f
		trigger = { fleet_power > 30000 }
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f4.reply
	}
	option = { # Back
		name = guardian.506.d
		custom_gui = "enclave_curator_option"
		hidden_effect = {
			country_event = { id = guardian.505 }
		}
	}
	option = { # Sign Off
		name = guardian.506.e
		default_hide_option = yes
		custom_gui = "enclave_curator_option"
	}
}

# Hiver
# Curator Guardians Menu
country_event = {
	id = guardian.530
	title = guardian.530.name
	desc = guardian.530.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_curator_window"

	picture_event_data = {
		portrait = event_target:curators
		room = enclave_curator_room
	}

	immediate = {
		set_country_flag = curator_enclave_diplomacy_engaged
	}

	after = {
		hidden_effect = {
			remove_country_flag = curator_enclave_diplomacy_engaged
		}
	}

	option = {
		name = guardian.530.a
		response_text = guardian.530.a.reply
		is_dialog_only = yes
		custom_gui = "enclave_curator_option"
	}
	option = {
		name = guardian.530.b
		response_text = guardian.530.b.reply
		trigger = {
			NOT = { has_modifier = asteroid_hive_weak_points }
		}
		custom_gui = "enclave_curator_option"
		allow = {
			energy > 5000
		}
		add_energy = -5000
		add_modifier = {
			modifier = asteroid_hive_weak_points
			days = -1
		}
	}
	option = { # Can we fight it? (No)
		name = guardian.506.f
		trigger = { fleet_power < 5000	}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f1.reply
	}
	option = { # Can we fight it? (Probably not)
		name = guardian.506.f
		trigger = {
			fleet_power > 5000
			fleet_power < 15000
		}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f2.reply
	}
	option = { # Can we fight it? (Maybe)
		name = guardian.506.f
		trigger = {
			fleet_power > 15000
			fleet_power < 30000
		}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f3.reply
	}
	option = { # Can we fight it? (Yes)
		name = guardian.506.f
		trigger = { fleet_power > 30000 }
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f4.reply
	}
	option = { # Back
		name = guardian.506.d
		custom_gui = "enclave_curator_option"
		hidden_effect = {
			country_event = { id = guardian.505 }
		}
	}
	option = { # Sign Off
		name = guardian.506.e
		default_hide_option = yes
		custom_gui = "enclave_curator_option"
	}
}

# Technosphere
# Curator Guardians Menu
country_event = {
	id = guardian.535
	title = guardian.535.name
	desc = guardian.535.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_curator_window"

	picture_event_data = {
		portrait = event_target:curators
		room = enclave_curator_room
	}

	immediate = {
		set_country_flag = curator_enclave_diplomacy_engaged
	}

	after = {
		hidden_effect = {
			remove_country_flag = curator_enclave_diplomacy_engaged
		}
	}

	option = {
		name = guardian.510.a
		response_text = guardian.535.a.reply
		is_dialog_only = yes
		custom_gui = "enclave_curator_option"
	}
	option = {
		name = guardian.510.b
		response_text = guardian.535.b.reply
		trigger = {
			NOT = { has_modifier = curator_buff_sphere }
		}
		custom_gui = "enclave_curator_option"
		allow = {
			energy > 5000
		}
		add_energy = -5000
		add_modifier = {
			modifier = curator_buff_sphere
			days = -1
		}
	}
	option = { # Can we fight it? (No)
		name = guardian.506.f
		trigger = { fleet_power < 5000	}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f1.reply
	}
	option = { # Can we fight it? (Probably not)
		name = guardian.506.f
		trigger = {
			fleet_power > 5000
			fleet_power < 15000
		}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f2.reply
	}
	option = { # Can we fight it? (Maybe)
		name = guardian.506.f
		trigger = {
			fleet_power > 15000
			fleet_power < 30000
		}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f3.reply
	}
	option = { # Can we fight it? (Yes)
		name = guardian.506.f
		trigger = { fleet_power > 30000 }
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f4.reply
	}
	option = { # Back
		name = guardian.506.d
		custom_gui = "enclave_curator_option"
		hidden_effect = {
			country_event = { id = guardian.505 }
		}
	}
	option = { # Sign Off
		name = guardian.506.e
		default_hide_option = yes
		custom_gui = "enclave_curator_option"
	}
}

# Automated Dreadnought
# Curator Guardians Menu
country_event = {
	id = guardian.540
	title = guardian.540.name
	desc = guardian.540.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_curator_window"

	picture_event_data = {
		portrait = event_target:curators
		room = enclave_curator_room
	}

	immediate = {
		set_country_flag = curator_enclave_diplomacy_engaged
	}

	after = {
		hidden_effect = {
			remove_country_flag = curator_enclave_diplomacy_engaged
		}
	}

	option = {
		name = guardian.540.a
		response_text = guardian.540.a.reply
		is_dialog_only = yes
		custom_gui = "enclave_curator_option"
	}
	option = {
		name = guardian.540.b
		response_text = guardian.540.b.reply
		trigger = {
			NOT = { has_modifier = automated_dreadnought_weak_points }
		}
		custom_gui = "enclave_curator_option"
		allow = {
			energy > 5000
		}
		add_energy = -5000
		add_modifier = {
			modifier = automated_dreadnought_weak_points
			days = -1
		}
	}
	option = { # Can we fight it? (No)
		name = guardian.506.f
		trigger = { fleet_power < 5000	}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f1.reply
	}
	option = { # Can we fight it? (Probably not)
		name = guardian.506.f
		trigger = {
			fleet_power > 5000
			fleet_power < 15000
		}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f2.reply
	}
	option = { # Can we fight it? (Maybe)
		name = guardian.506.f
		trigger = {
			fleet_power > 15000
			fleet_power < 30000
		}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f3.reply
	}
	option = { # Can we fight it? (Yes)
		name = guardian.506.f
		trigger = { fleet_power > 30000 }
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f4.reply
	}
	option = { # Back
		name = guardian.506.d
		custom_gui = "enclave_curator_option"
		hidden_effect = {
			country_event = { id = guardian.505 }
		}
	}
	option = { # Sign Off
		name = guardian.506.e
		default_hide_option = yes
		custom_gui = "enclave_curator_option"
	}
}

# Wraith
# Curator Guardians Menu
country_event = {
	id = guardian.545
	title = guardian.545.name
	desc = guardian.545.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_curator_window"

	picture_event_data = {
		portrait = event_target:curators
		room = enclave_curator_room
	}

	immediate = {
		set_country_flag = curator_enclave_diplomacy_engaged
	}

	after = {
		hidden_effect = {
			remove_country_flag = curator_enclave_diplomacy_engaged
		}
	}

	option = {
		name = guardian.545.a
		response_text = guardian.545.a.reply
		is_dialog_only = yes
		custom_gui = "enclave_curator_option"
	}
	option = {
		name = guardian.545.b
		response_text = guardian.545.b.reply
		trigger = {
			NOT = { has_country_flag = bought_wraith_info_1 }
		}
		custom_gui = "enclave_curator_option"
		allow = {
			energy > 1000
		}
		hidden_effect = { set_country_flag = bought_wraith_info_1 }
		add_energy = -1000
	}
	option = {
		name = guardian.545.c
		response_text = guardian.545.b.reply
		trigger = {
			NOT = { has_country_flag = bought_wraith_info_2 }
		}
		custom_gui = "enclave_curator_option"
		allow = {
			energy > 1000
		}
		hidden_effect = { set_country_flag = bought_wraith_info_2 }
		add_energy = -1000
	}
	option = {
		name = guardian.545.d
		response_text = guardian.545.d.reply
		trigger = {
			NOT = { has_country_flag = bought_wraith_info_3 }
		}
		custom_gui = "enclave_curator_option"
		allow = {
			energy > 1000
		}
		hidden_effect = { set_country_flag = bought_wraith_info_3 }
		add_energy = -1000
	}
	option = {
		name = guardian.545.b
		response_text = guardian.545.b.reply
		custom_gui = "enclave_curator_option"
		trigger = { has_country_flag = bought_wraith_info_1 }
	}
	option = {
		name = guardian.545.c
		response_text = guardian.545.c.reply
		custom_gui = "enclave_curator_option"
		trigger = { has_country_flag = bought_wraith_info_2 }
	}
	option = {
		name = guardian.545.d
		response_text = guardian.545.d.reply
		custom_gui = "enclave_curator_option"
		trigger = { has_country_flag = bought_wraith_info_3 }
	}
	option = { # Can we fight it? (No)
		name = guardian.506.f
		trigger = { fleet_power < 5000	}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f1.reply
	}
	option = { # Can we fight it? (Probably not)
		name = guardian.506.f
		trigger = {
			fleet_power > 5000
			fleet_power < 15000
		}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f2.reply
	}
	option = { # Can we fight it? (Maybe)
		name = guardian.506.f
		trigger = {
			fleet_power > 15000
			fleet_power < 30000
		}
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f3.reply
	}
	option = { # Can we fight it? (Yes)
		name = guardian.506.f
		trigger = { fleet_power > 30000 }
		custom_gui = "enclave_curator_option"
		response_text = guardian.5106.f4.reply
	}
	option = { # Back
		name = guardian.506.d
		custom_gui = "enclave_curator_option"
		hidden_effect = {
			country_event = { id = guardian.505 }
		}
	}
	option = { # Sign Off
		name = guardian.506.e
		default_hide_option = yes
		custom_gui = "enclave_curator_option"
	}
}

# Curator Hire Scientist Menu
country_event = {
	id = guardian.590
	title = guardian.590.name
	desc = guardian.590.desc
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_curator_window"

	picture_event_data = {
		portrait = event_target:curators
		room = enclave_curator_room
	}

	immediate = {
		set_country_flag = curator_enclave_diplomacy_engaged
		event_target:curators = {
			owner_species = { save_event_target_as = curator_species }
		}
	}

	after = {
		hidden_effect = {
			remove_country_flag = curator_enclave_diplomacy_engaged
		}
	}

	option = {
		name = guardian.590.a
		response_text = guardian.590.a.reply
		custom_gui = "enclave_curator_option"
		allow = { 
			energy > 2500 
			free_leader_slots > 0 
			hidden_trigger = {
				NOT = { has_country_flag = attacked_curators }
			}
		}
		add_energy = -2500
		custom_tooltip = opinion20
		hidden_effect = {
			set_country_flag = curator_scientist_recruited
			event_target:curators = {
				add_trust = {
					who = root
					amount = 20
				}
			}
			random_list = {
				20 = {
					create_leader = {
						type = scientist
						species = event_target:curator_species
						name = "NAME_Professor_Zarg"
						skill = 5000
						traits = {
							trait = leader_trait_curator
						}
					}
					last_created_leader = {
						set_age = 41
					}
				}
				20 = {
					create_leader = {
						type = scientist
						species = event_target:curator_species
						name = "NAME_Doctor_Xib"
						skill = 5000
						traits = {
							trait = leader_trait_curator
						}
					}
					last_created_leader = {
						set_age = 45
					}
				}
				20 = {
					create_leader = {
						type = scientist
						species = event_target:curator_species
						name = "NAME_The_Mentat"
						skill = 5000
						traits = {
							trait = leader_trait_curator
						}
					}
					last_created_leader = {
						set_age = 43
					}
				}
				20 = {
					create_leader = {
						type = scientist
						species = event_target:curator_species
						name = "NAME_Kix_the_Brilliant"
						skill = 5000
						traits = {
							trait = leader_trait_curator
						}
					}
					last_created_leader = {
						set_age = 47
					}
				}
				20 = {
					create_leader = {
						type = scientist
						species = event_target:curator_species
						name = "NAME_Sensei_Borkaz"
						skill = 5000
						traits = {
							trait = leader_trait_curator
						}
					}
					last_created_leader = {
						set_age = 42
					}
				}
			}
		}
	}
	option = { # Back
		name = guardian.506.d
		custom_gui = "enclave_curator_option"
		hidden_effect = {
			country_event = { id = guardian.505 }
		}
	}
	option = { # Sign Off
		name = guardian.506.e
		custom_gui = "enclave_curator_option"
		default_hide_option = yes
	}
}

# Port
country_event = {
	id = guardian.501
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		from = {
			country_event = { id = guardian.502 }
		}
	}
}

# Curator Introduction
country_event = {
	id = guardian.502
	title = guardian.502.name
	
	desc = {
		text = guardian.502a.desc
		trigger = {
			NOT = { has_country_flag = curator_intro }
		}
	}
	desc = {
		text = guardian.502b.desc
		trigger = { has_country_flag = curator_intro }
	}
	
	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_curator_window"

	picture_event_data = {
		portrait = from
		room = enclave_curator_room
	}
	
	is_triggered_only = yes
	
	after = {
		if = {
			limit = {
				NOT = { has_country_flag = curator_intro }
			}
			set_country_flag = curator_intro
		}
	}

	option = {
		name = guardian.502.a
		custom_gui = "enclave_curator_option"
		trigger = {
			NOT = { has_valid_civic = civic_fanatic_purifiers }
		}
	}

	option = {
		name = SCUM
		custom_gui = "enclave_curator_option"
		trigger = {
			has_valid_civic = civic_fanatic_purifiers
		}
	}
}

# Enclave Communication Spread
country_event = {
	id = guardian.560
	hide_window = yes
	
	trigger = {
		is_country_type = enclave
		any_relation = {
			is_country_type = default
			any_relation = {
				is_country_type = default
				NOT = { has_communications = ROOT }
			}
		}
	}
	
	mean_time_to_happen = {
		months = 80
	}
	
	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 = guardian.98 }
			}
		}
	}	
}

# Curator Destroyed (HIDDEN)
country_event = {
	id = guardian.592
	hide_window = yes
	
	is_triggered_only = yes
	
	trigger = {
		is_country_type = enclave
		has_country_flag = curator_enclave_country
		FROMFROM = { 
			any_ship = { is_ship_size = enclave_station }
		}
	}
	
	immediate = {
		FROMFROM = {
			solar_system = { save_event_target_as = curator_system }
		}
		FROM = { 
			country_event = { id = guardian.593 }
			save_event_target_as = curator_destroyer
		}
		every_country = {
			limit = {
				has_communications = ROOT
				NOT = { is_country = event_target:curator_destroyer }
				is_country_type = default
			}
			country_event = { id = guardian.594 }
		}
	}
}

# Curator Destroyed (Destroyer)
country_event = {
	id = guardian.593
	title = "guardian.593"
	desc = "guardian.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 
				has_relation_flag = { 
					who = FROM
					flag = curator_trade 
				}
			}
			remove_modifier = "curator_insight"
			remove_relation_flag = {
				who = FROM
				flag = curator_trade 
			}
		}
	}
	
	option = {
		name = EXCELLENT
		add_physics_research = 1000
		add_society_research = 1000
		add_engineering_research = 1000
	}
}

# Curator Destroyed
country_event = {
	id = guardian.594
	title = "guardian.593"
	desc = {
		text = guardian.594.a.desc
		trigger = {
			NOT = {
				has_relation_flag = { 
					who = FROM
					flag = curator_trade 
				}
			}
			has_communications = event_target:curator_destroyer
		}
	}
	desc = {
		text = guardian.594.b.desc
		trigger = {
			NOT = { 
				has_relation_flag = { 
					who = FROM
					flag = curator_trade 
				}
			}
			NOT = { has_communications = event_target:curator_destroyer }
		}
	}
	desc = {
		text = guardian.594.c.desc
		trigger = {
			has_relation_flag = { 
				who = FROM
				flag = curator_trade 
			}
			has_communications = event_target:curator_destroyer
		}
	}
	desc = {
		text = guardian.594.d.desc
		trigger = {
			has_relation_flag = { 
				who = FROM
				flag = curator_trade 
			}
			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 = {
		if = {
			limit = { 
				has_modifier = curator_insight 
				has_relation_flag = { 
					who = FROM
					flag = curator_trade 
				}
			}
			remove_modifier = "curator_insight"
		}
		if = {
			limit = {
				has_relation_flag = { 
					who = FROM
					flag = curator_trade 
				}
				is_ai = yes
			}
			add_opinion_modifier = {
				who = event_target:curator_destroyer
				modifier = opinion_destroyed_curator_insight
			}
		}
		if = {
			limit = {
				NOT = {
					has_relation_flag = { 
						who = FROM
						flag = curator_trade 
					}
				}
				is_ai = yes
			}
			add_opinion_modifier = {
				who = event_target:curator_destroyer
				modifier = opinion_destroyed_curator
			}
		}
	}
	
	option = {
		name = "guardian.594.a"
		trigger = {
			NOT = { 
				has_relation_flag = { 
					who = FROM
					flag = curator_trade 
				}
			}
		}
	}
	option = {
		name = "guardian.594.b"
		trigger = {
			has_relation_flag = { 
				who = FROM
				flag = curator_trade 
			}
		}
		hidden_effect = {
			remove_relation_flag = {
				who = FROM
				flag = curator_trade 
			}
		}
	}
}

# Attacked Curators (HIDDEN)
country_event = {
	id = guardian.595
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		is_country_type = default
		FROM = { has_country_flag = curator_enclave_country }
	}

	immediate = {
		FROM = { 
			save_event_target_as = curators
			add_trust = {
				who = ROOT
				amount = -100
			}
		}
		set_country_flag = attacked_curators
		if = {
			limit = { has_modifier = curator_insight }
			remove_modifier = curator_insight
			country_event = { id = guardian.596}
		}
	}
}

# Attacked Curators - Research Agreement Terminated
country_event = {
	id = guardian.596
	title = guardian.500.name
	desc = guardian.596.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_curator_window"

	picture_event_data = {
		portrait = event_target:curators
		room = enclave_curator_room
	}

	option = {
		name = guardian.156.a
		custom_gui = "enclave_curator_option"
	}
}

# Attacked Curators - Refuses Communications
country_event = {
	id = guardian.597
	title = guardian.500.name
	desc = guardian.597a.desc
	desc = guardian.597b.desc
	desc = guardian.597c.desc
	desc = guardian.597d.desc

	is_triggered_only = yes
	diplomatic = yes
	custom_gui = "enclave_curator_window"
	force_open = yes

	picture_event_data = {
		portrait = event_target:curators
		room = enclave_curator_room
	}
	
	trigger = {
		FROM = {
			is_country_type = enclave
			has_country_flag = curator_enclave_country
		}
		has_country_flag = attacked_curators
		NOT = { has_country_flag = curator_enclave_diplomacy_engaged }
	}
	
	immediate = {
		set_country_flag = curator_enclave_diplomacy_engaged
		FROM = { save_event_target_as = curators }
	}
	
	after = {
		hidden_effect = {
			remove_country_flag = curator_enclave_diplomacy_engaged
		}
	}

	option = {
		name = SCUM
		trigger = { has_valid_civic = civic_fanatic_purifiers }
		custom_gui = "enclave_curator_option"
	}

	option = {
		name = guardian.156.a
		custom_gui = "enclave_curator_option"
		trigger = { NOT = { has_valid_civic = civic_fanatic_purifiers } }
		default_hide_option = yes
	}
}

# RESTART DEBUG
fleet_event = {
	id = guardian.601
	hide_window = yes
	trigger = { always = no }
	immediate = { fleet_event = { id = guardian.602 } }
}
fleet_event = {
	id = guardian.602
	hide_window = yes
	trigger = { always = no }
	immediate = { owner = { country_event = { id = guardian.640 } } }
}

# Encounter
fleet_event = {
	id = guardian.610
	title = guardian.610.name
	desc = guardian.610.desc
	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_ship_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 = guardian.610.a
	}
}

# Restart mission after battle
country_event = {
	id = guardian.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_3
													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_3
												clear_fleet_actions = this
											}
										}
									}
								}
							}
						}
					}
				}
				break = yes
			}
			if = {
				limit = {
					has_fleet_flag = dragon_mission_3
				}
				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_3
												clear_fleet_actions = this
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

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

	trigger = {
		is_country_type = guardian_dragon
		any_owned_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_owned_fleet = {
			limit = {
				any_owned_ship = {
					is_ship_size = space_dragon_red
				}
			}
			set_timed_fleet_flag = {
				flag = aggro_cooldown
				days = 60
			}
			clear_fleet_actions = this
			fleet_event = { id = guardian.652 }
		}
		from = {
			country_event = { id = guardian.649 }
		}
	}
}

# Retaliation notification
country_event = {
	id = guardian.649
	title = guardian.650.name
	desc = guardian.649.desc
	picture = GFX_evt_exploding_ship
	is_triggered_only = yes

	trigger = {
		from = { is_country_type = guardian_dragon }
	}

	option = {
		name = guardian.649.a
	}
}

# Dragon pursues if fleet flees
# Fired before entering FTL - does combat still exist?
fleet_event = {
	id = guardian.650
	#hide_window = yes
	title = guardian.650.name
	desc = guardian.650.desc
	picture = GFX_evt_federation_fleet
	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_owned_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_owned_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 = guardian.651 }
		}
	}

	option = {
		name = guardian.649.a
	}
}

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

	is_triggered_only = yes

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

	immediate = {
		closest_system = {
			limit = {
				any_ship_in_system = {
					OR = {
						is_ship_size = mining_station
						is_ship_size = research_station
						is_ship_size = outpost_station
					}
					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 = guardian.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_3
															clear_fleet_actions = this
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

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

	is_triggered_only = yes

	trigger = {
		exists = fromfrom
	}

	immediate = {
		closest_system = {
			limit = {
				any_ship_in_system = {
					OR = {
						is_ship_size = mining_station
						is_ship_size = research_station
						is_ship_size = outpost_station
					}
					exists = owner
					owner = {
						is_same_value = fromfrom
					}
				}
			}
			set_star_flag = system_target_3
			save_event_target_as = system_target_3
		}
		if = {
			limit = {
				exists = event_target:system_target_3
			}
			set_fleet_flag = dragon_mission_1
			#fromfrom = { country_event = { id = guardian.649 } }
			queue_actions = {
				repeat = {
					max_iterations = 1
					find_closest_system = {
						trigger = {
							id = dragon.4.retaliation.1
							is_same_value = event_target:system_target_3
						}
						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_3
										}
										root = {
											remove_fleet_flag = dragon_mission_3
											#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_3
															clear_fleet_actions = this
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

fleet_event = {
	id = guardian.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_owned_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_owned_ship = {
						is_ship_size = space_dragon_red
					}
				}
				random_owned_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 = {
										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 = guardian.655
	hide_window = yes

	is_triggered_only = yes

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

	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_owned_ship = { repair_ship = yes } }
									}
								}
							}
							wait = {
								duration = 60
							}
						}
					}
				}
			}
		}
	}
}

fleet_event = {
	id = guardian.1
	hide_window = yes

	trigger = { always = no }

	immediate = {
		destroy_fleet = this
	}
}

planet_event = {
	id = guardian.660
	hide_window = yes
	mean_time_to_happen = {
		months = 1200
	}

	trigger = {
		has_planet_flag = hoard_planet
		#has_deposit = d_guardian_dragon_hoard
		NOT = {
			has_planet_flag = deboned
		}
		has_mining_station = yes
		exists = controller
		controller = {
			is_country_type = default
		}
	}

	immediate = {
		set_planet_flag = deboned
		controller = {
			country_event = { id = guardian.661 }
		}
	}
}

# Dragon Hoard event - Bones
country_event = {
	id = guardian.661
	title = "guardian.660.name"
	desc = "guardian.660.desc"
	picture = GFX_evt_archaeological_dig
	location = from
	show_sound = event_mystic_reveal

	is_triggered_only = yes

	option = {
		name = guardian.660.a
		add_research_option = tech_dragon_armor
		add_tech_progress = {
			tech = tech_dragon_armor
			progress = 0.3
		}
		add_monthly_resource_mult = {
			resource = society_research
			value = 12
			min = 300
			max = 1000
		}
	}

	option = {
		name = guardian.660.b
		add_monthly_resource_mult = {
			resource = minerals
			value = 36
			min = 100
			max = 4000
		}
	}
}

planet_event = {
	id = guardian.662
	hide_window = yes

	mean_time_to_happen = {
		months = 2400
	}

	trigger = {
		has_planet_flag = hoard_planet
		#has_deposit = d_guardian_dragon_hoard
		NOT = {
			has_planet_flag = deegged
		}
		has_mining_station = yes
		exists = controller
		controller = {
			is_country_type = default
		}
	}

	immediate = {
		set_planet_flag = deegged
		controller = {
			country_event = { id = guardian.663 }
		}
	}
}

# Dragon Hoard event - Egg
country_event = {
	id = guardian.663
	title = "guardian.661.name"
	desc = "guardian.661.desc"
	picture = GFX_evt_archaeological_dig
	location = root
	show_sound = event_mystic_reveal

	is_triggered_only = yes

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

	option = {
		name = guardian.661.b
		custom_tooltip = guardian.661.b.tooltip
		add_influence = 300
	}
}

# Egg incubated
planet_event = {
	id = guardian.664
	title = guardian.664.name
	desc = guardian.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 = { spawn_debris = no }
			effect = {
				set_owner = root.owner
				create_ship_design = {
					design = NAME_Dragonspawn
					ftl = root.owner
				}
				create_ship = {
					design = last_created_design
					name = "NAME_Scile"
					prefix = no
					upgradable = no
				}
				#add_modifier = {
				#	modifier = immature_dragon
				#	days = -1
				#}
				set_location = root
			}
		}
		owner = { set_country_flag = hatched_dragon }
	}

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

country_event = {
	id = guardian.665
	title = guardian.665.name
	desc = guardian.665.desc
	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 = guardian.670
	title = guardian.670.name
	desc = {
		text = guardian.670.desc
		trigger = {
			fromfrom = {
				exists = leader
			}
		}
	}
	desc = {
		text = guardian.670.desc.noleader
		trigger = {
			fromfrom = {
				NOT = { exists = leader }
			}
		}
	}
	picture = GFX_evt_space_dragon
	location = fromfrom
	show_sound = event_mystic_reveal

	is_triggered_only = yes

	trigger = {
		from = {
			is_country_type = guardian_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 = guardian.670.a
		trigger = {
			fromfrom = {
				exists = leader
			}
			OR = {
				has_ethic = ethic_fanatic_spiritualist
				has_ethic = ethic_spiritualist
				has_ethic = ethic_fanatic_xenophile
				has_ethic = ethic_xenophile
			}
		}
		fromfrom = {
			leader = {
				add_trait = leader_trait_dragonslayer
			}
		}
		add_influence = 300
		custom_tooltip = guardian.670.spiritphile.tooltip
		hidden_effect = {
			set_country_flag = dragon_slayer
		}
	}

	option = {
		name = guardian.670.a
		trigger = {
			fromfrom = {
				NOT = {
					exists = leader
				}
			}
			OR = {
				has_ethic = ethic_fanatic_spiritualist
				has_ethic = ethic_spiritualist
				has_ethic = ethic_fanatic_xenophile
				has_ethic = ethic_xenophile
			}
		}
		add_influence = 300
		custom_tooltip = guardian.670.spiritphile.tooltip
		hidden_effect = {
			set_country_flag = dragon_slayer
		}
	}

	option = {
		name = guardian.670.a
		trigger = {
			fromfrom = {
				exists = leader
			}
			NOR = {
				has_ethic = ethic_fanatic_spiritualist
				has_ethic = ethic_spiritualist
				has_ethic = ethic_fanatic_xenophile
				has_ethic = ethic_xenophile
			}
		}
		fromfrom = {
			leader = {
				add_trait = leader_trait_dragonslayer
			}
		}
		add_influence = 300
		custom_tooltip = guardian.670.tooltip
		hidden_effect = {
			set_country_flag = dragon_slayer
		}
	}

	option = {
		name = guardian.670.a
		trigger = {
			fromfrom = {
				NOT = {
					exists = leader
				}
			}
			NOR = {
				has_ethic = ethic_fanatic_spiritualist
				has_ethic = ethic_spiritualist
				has_ethic = ethic_fanatic_xenophile
				has_ethic = ethic_xenophile
			}
		}
		add_influence = 300
		custom_tooltip = guardian.670.tooltip
		hidden_effect = {
			set_country_flag = dragon_slayer
		}
	}
}

country_event = {
	id = guardian.671
	hide_window = yes
	trigger = { always = no }

	immediate = {
		set_country_flag = dragon_slayer
	}
}

### STELLARITE ###
# Stellarite spawns as an empire enters its system
ship_event = {
	id = guardian.999
	title = guardian.999.name
	desc = guardian.999.desc
	picture = GFX_evt_star_yellow
	show_sound = event_radio_chatter
	location = root

	is_triggered_only = yes

	trigger = {
		from = {
			has_star_flag = guardians_stellarite_system
			NOT = {
				has_star_flag = guardians_stellarite_about_to_spawn
			}
		}
	}

	immediate = {
		from = {
			set_star_flag = guardians_stellarite_about_to_spawn
			save_event_target_as = stellarite_system
			set_star_flag = stellarite_present
			every_system_planet = {
				limit = {
					is_star = no
					is_asteroid = no
				}
				add_modifier = {
					modifier = stellarite_low_temp
					days = -1
				}
			}
		}
	}

	option = {
		name = guardian.999.a
		hidden_effect = {
			owner = {
				country_event = { id = guardian.1000 days = 7 }		
			}
		}
	}
}
# Stellarite spawns
country_event = {
	id = guardian.1000
	title = guardian.1000.name
	desc = guardian.1000.desc
	picture = GFX_evt_stellarites
	show_sound = event_radio_chatter
	location = fromfrom

	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = guardians_stellarite_encountered }
		any_system = {
			has_star_flag = guardians_stellarite_about_to_spawn
			has_star_flag = guardians_stellarite_system
		}
	}

	option = {
		name = BATTLESTATIONS
		hidden_effect = {
			set_country_flag = guardians_stellarite_encountered
			country_event = { id = story.8 days = 15 }
			event_target:stellarite_system = {
				random_system_planet = {
					limit = {
						is_star = yes
					}
					change_planet_size = -5
					spawn_sun_temperature_effect = yes
					create_country = {
						name = "NAME_Stellarite"
						type = guardian_stellarite
						flag = {
							icon = {
								category = "zoological"
								file = "flag_zoological_1.dds"
							}
							background= {
								category = "backgrounds"
								file = "00_solid.dds"
							}
							colors={
								"black"
								"black"
								"null"
								"null"
							}
						}
					}
					last_created_country = {
						save_global_event_target_as = stellarite_country
						set_country_flag = guardian_stellarite_country
						#ISB Balance
						country_event = { id = isb.5 days = 1 }		
						create_fleet = {
							name = "NAME_Stellarite_Devourer"
							settings = {
								spawn_debris = no 
								is_boss = yes
							}
							effect = {
								set_owner = event_target:stellarite_country
								create_ship = {
									name = "NAME_Stellar_Devourer"
									design = "NAME_Stellarite"
									effect = {
										set_ship_flag = stellarite_ship
										save_global_event_target_as = stellarite
									}
								}
								set_location = PREVPREV
								set_fleet_stance = aggressive
								set_aggro_range_measure_from = self
								set_aggro_range = 100
							}
						}
					}
				}
			}
			establish_communications_no_message = event_target:stellarite_country
		}
	}
}

# Players who haven't encountered the stellarite gets a message
ship_event = {
	id = guardian.1001
	title = guardian.1000.name
	desc = {
		trigger = {
			hidden:fromfromfrom = {
				hidden:solar_system = {
					switch = {
						trigger = has_star_flag
						guardians_stellarite_system = { text = guardian.1000.desc }
						default = { text = guardian.1001.desc }
					}
				}
			}
		}
	}
	picture = GFX_evt_stellarites
	show_sound = event_radio_chatter
	location = root

	is_triggered_only = yes

	trigger = {
		fromfrom = {
			is_ai = no
			NOT = { has_country_flag = guardians_stellarite_encountered }
		}
		from = {
			any_ship_in_system = {
				exists = owner
				owner = {
					is_country_type = guardian_stellarite
					has_country_flag = guardian_stellarite_country
				}
			}
		}
	}

	immediate = {
		fromfrom = {
			set_country_flag = guardians_stellarite_encountered
			establish_communications_no_message = event_target:stellarite_country
		}
	}

	option = {
		name = DISCONCERTING
	}
}

# Stellarite enter system - temperature change
fleet_event = {
	id = guardian.1005
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = owner
		owner = {
			is_country_type = guardian_stellarite
			has_country_flag = guardian_stellarite_country
		}
		solar_system = {
			NOT = { has_star_flag = guardians_stellarite_system }
		}
	}

	immediate = {
		if = {
			limit = {
				any_system = {
					has_star_flag = stellarite_present
					NOT = {
						any_ship_in_system = {
							owner = {
								has_country_flag = guardian_stellarite_country
							}
						}
					}
				}
			}
			random_system = {
				limit = {
					has_star_flag = stellarite_present
				}
				remove_star_flag = stellarite_present
				every_system_planet = {
					limit = {
						has_modifier = stellarite_high_temp
					}
					remove_modifier = stellarite_high_temp
				}
			}
		}
		solar_system = {
			set_star_flag = stellarite_present
			every_system_planet = {
				limit = {
					is_star = no
					is_asteroid = no
				}
				add_modifier = {
					modifier = stellarite_high_temp
					days = -1
				}
			}
		}
	}
}
# Stellarite behaviour - chase aggressor setup - from destroyed fleet
country_event = {
	id = guardian.1009
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		fromfrom = {
			owner = {
				is_country_type = guardian_stellarite
			}
			any_owned_ship = {
				has_ship_flag = stellarite_ship
			}
			has_hp_percentage < 0.995
			has_hp_percentage > 0.33
		}
	}

	immediate = {
		from = {
			save_event_target_as = attacker_country
			set_timed_country_flag = { flag = stellarite_in_pursuit days = 90 } #set so the stellarite finds them
		}
		fromfrom = {
			clear_fleet_actions = this
			save_event_target_as = stellarite_fleet
			set_timed_fleet_flag = { flag = stellarite_in_pursuit days = 90 } #set so the stellarite knows when to stop chase
			queue_actions = {
				repeat = {
					while = {
						id = guardian.1009.trigger.1
						has_hp_percentage > 0.33
						has_fleet_flag = stellarite_in_pursuit
					}
					find_closest_system = {
						trigger = {
							id = guardian.1009.trigger.2
							exists = space_owner
							space_owner = { has_country_flag = stellarite_in_pursuit }
							any_planet = {
								OR = {
									has_mining_station = yes
									has_research_station = yes
									has_spaceport = yes
								}
								is_owned_by = event_target:attacker_country
							}
						}
						found_system = {
							move_to = this
							find_closest_planet = {
								trigger = {
									id = guardian.1009.trigger.3
									OR = {
										has_mining_station = yes
										has_research_station = yes
										has_spaceport = yes
									}
									is_owned_by = event_target:attacker_country
								}
								found_planet = {
									move_to = this
									effect = {
										id = guardian.1009.effect.3
										event_target:stellarite_fleet = {
											fleet_event = { id = guardian.1011 }
											owner = { country_event = { id = guardian.1015 } }
										}
									}
								}
								failed = {
									effect = {
										id = guardian.1009.effect.2
										event_target:stellarite_fleet = {
											set_timed_fleet_flag = { flag = returning_home days = 7 }
											owner = { country_event = { id = guardian.1015 } }
										}
									}
								}
							}
						}
						failed = {
							effect = {
								id = guardian.1009.effect.1
								event_target:stellarite_fleet = {
									set_timed_fleet_flag = { flag = returning_home days = 7 }
									owner = { country_event = { id = guardian.1015 } }
								}
							}
						}
					}
				}
			}
		}
	}
}
# Stellarite behaviour - chase aggressor setup - from emergency ftl
fleet_event = {
	id = guardian.1010
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_combatant_fleet = {
			owner =  {
				is_country_type = guardian_stellarite
			}
			any_owned_ship = {
				has_ship_flag = stellarite_ship
			}
			has_hp_percentage < 0.995
			has_hp_percentage > 0.33
		}
	}

	immediate = {
		owner = {
			save_event_target_as = attacker_country
			set_timed_country_flag = { flag = stellarite_in_pursuit days = 90 } #set so the stellarite finds them
		}
		random_combatant_fleet = {
			limit = {
				any_owned_ship = {
					has_ship_flag = stellarite_ship
				}
			}
			clear_fleet_actions = this
			save_event_target_as = stellarite_fleet
			set_timed_fleet_flag = { flag = stellarite_in_pursuit days = 90 } #set so the stellarite knows when to stop chase
			queue_actions = {
				repeat = {
					while = {
						id = guardian.1010.trigger.1
						has_hp_percentage > 0.33
						has_fleet_flag = stellarite_in_pursuit
					}
					find_closest_system = {
						trigger = {
							id = guardian.1010.trigger.2
							exists = space_owner
							space_owner = { has_country_flag = stellarite_in_pursuit }
							any_planet = {
								OR = {
									has_mining_station = yes
									has_research_station = yes
									has_spaceport = yes
								}
								is_owned_by = event_target:attacker_country
							}
						}
						found_system = {
							move_to = this
							find_closest_planet = {
								trigger = {
									id = guardian.1010.trigger.3
									OR = {
										has_mining_station = yes
										has_research_station = yes
										has_spaceport = yes
									}
									is_owned_by = event_target:attacker_country
								}
								found_planet = {
									move_to = this
									effect = {
										id = guardian.1010.effect.3
										event_target:stellarite_fleet = {
											fleet_event = { id = guardian.1011 }
											owner = { country_event = { id = guardian.1015 } }
										}
									}
								}
								failed = {
									effect = {
										id = guardian.1010.effect.2
										event_target:stellarite_fleet = {
											set_timed_fleet_flag = { flag = returning_home days = 7 }
											owner = { country_event = { id = guardian.1015 } }
										}
									}
								}
							}
						}
						failed = {
							effect = {
								id = guardian.1010.effect.1
								event_target:stellarite_fleet = {
									set_timed_fleet_flag = { flag = returning_home days = 7 }
									owner = { country_event = { id = guardian.1015 } }
								}
							}
						}
					}
				}
			}
		}
	}
}

# Stellarite behaviour - chase aggressor continuation
fleet_event = {
	id = guardian.1011
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		owner = {
			is_country_type = guardian_stellarite
		}
		has_fleet_flag = stellarite_in_pursuit
		has_hp_percentage < 0.995
		has_hp_percentage > 0.33
	}

	immediate = {
		clear_fleet_actions = this
		save_event_target_as = stellarite_fleet
		queue_actions = {
			repeat = {
				while = {
					id = guardian.1011.trigger.1
					has_hp_percentage > 0.33
					has_fleet_flag = stellarite_in_pursuit
				}
				find_closest_system = {
					trigger = {
						id = guardian.1011.trigger.2
						exists = space_owner
						space_owner = { has_country_flag = stellarite_in_pursuit }
						any_planet = {
							OR = {
								has_mining_station = yes
								has_research_station = yes
								has_spaceport = yes
							}
							is_owned_by = event_target:attacker_country
						}
					}
					found_system = {
						move_to = this
						find_closest_planet = {
							trigger = {
								id = guardian.1011.trigger.3
								OR = {
									has_mining_station = yes
									has_research_station = yes
									has_spaceport = yes
								}
								is_owned_by = event_target:attacker_country
							}
							found_planet = {
								move_to = this
								effect = {
									id = guardian.1011.effect.3
									event_target:stellarite_fleet = {
										fleet_event = { id = guardian.1011 }
										owner = { country_event = { id = guardian.1015 } }
									}
								}
							}
							failed = {
								effect = {
									id = guardian.1011.effect.2
									event_target:stellarite_fleet = {
										set_timed_fleet_flag = { flag = returning_home days = 7 }
										owner = { country_event = { id = guardian.1015 } }
									}
								}
							}
						}
					}
					failed = {
						effect = {
							id = guardian.1011.effect.1
							event_target:stellarite_fleet = {
								set_timed_fleet_flag = { flag = returning_home days = 7 }
								owner = { country_event = { id = guardian.1015 } }
							}
						}
					}
				}
			}
		}
	}
}
# Stellarite behaviour - chase aggressor continuation from combat
country_event = {
	id = guardian.1012
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = guardian_stellarite
		any_owned_ship = {
			has_ship_flag = stellarite_ship
			fleet = {
				has_hp_percentage < 0.995
				has_hp_percentage > 0.33
			}
		}
	}

	immediate = {
		from = {
			if = {
				limit = {
					NOT = { has_country_flag = stellarite_in_pursuit }
				}
				set_timed_country_flag = { flag = stellarite_in_pursuit days = 90 }
			}
		}
		fromfrom = {
			set_timed_fleet_flag = { flag = stellarite_in_pursuit days = 90 }
			save_event_target_as = stellarite_fleet
			clear_fleet_actions = this
			queue_actions = {
				repeat = {
					while = {
						id = guardian.1012.trigger.1
						has_hp_percentage > 0.33
						has_fleet_flag = stellarite_in_pursuit
					}
					find_closest_system = {
						trigger = {
							id = guardian.1012.trigger.2
							exists = space_owner
							space_owner = { has_country_flag = stellarite_in_pursuit }
							any_planet = {
								OR = {
									has_mining_station = yes
									has_research_station = yes
									has_spaceport = yes
								}
								is_owned_by = event_target:attacker_country
							}
						}
						found_system = {
							move_to = this
							find_closest_planet = {
								trigger = {
									id = guardian.1012.trigger.3
									OR = {
										has_mining_station = yes
										has_research_station = yes
										has_spaceport = yes
									}
									is_owned_by = event_target:attacker_country
								}
								found_planet = {
									move_to = this
									effect = {
										id = guardian.1012.effect.3
										event_target:stellarite_fleet = {
											fleet_event = { id = guardian.1011 }
											owner = { country_event = { id = guardian.1015 } }
										}
									}
								}
								failed = {
									effect = {
										id = guardian.1012.effect.2
										event_target:stellarite_fleet = {
											set_timed_fleet_flag = { flag = returning_home days = 7 }
											owner = { country_event = { id = guardian.1015 } }
										}
									}
								}
							}
						}
						failed = {
							effect = {
								id = guardian.1012.effect.1
								event_target:stellarite_fleet = {
									set_timed_fleet_flag = { flag = returning_home days = 7 }
									owner = { country_event = { id = guardian.1015 } }
								}
							}
						}
					}
				}
			}
		}
	}
}

# Stellarite behaviour - chase aggressor setup
fleet_event = {
	id = guardian.1013
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_combatant_fleet = {
			any_owned_ship = {
				has_ship_flag = stellarite_ship
			}
			has_hp_percentage < 0.995
			has_hp_percentage > 0.33
		}
	}

	immediate = {
		random_combatant_fleet = {
			owner = { country_event = { id = guardian.1015 } }
		}
	}
}

# Stellarite behavior - chase aggressor setup
fleet_event = {
	id = guardian.1014
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_combatant_fleet = {
			any_owned_ship = {
				has_ship_flag = stellarite_ship
			}
			has_hp_percentage < 0.995
			has_hp_percentage > 0.33
		}
	}

	immediate = {
		random_combatant_fleet = {
			limit = {
				any_owned_ship = {
					has_ship_flag = stellarite_ship
				}
			}
			fleet_event = { id = guardian.1011 }
		}
	}
}
# Stellarite behavior - return home if bored with weak opponent
fleet_event = {
	id = guardian.1020
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_combatant_fleet = {
			any_owned_ship = {
				has_ship_flag = stellarite_ship
			}
			has_hp_percentage > 0.995
			has_hp_percentage < 0.33
		}
	}

	immediate = {
		random_combatant_fleet = {
			limit = {
				any_owned_ship = {
					has_ship_flag = stellarite_ship
				}
			}
			owner = { country_event = { id = guardian.1015 } }
		}
	}
}

# Stellarite behavior - return home to feed
country_event = {
	id = guardian.1015
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_owned_fleet = {
			any_owned_ship = { has_ship_flag = stellarite_ship }
			OR = {
				has_hp_percentage < 0.33
				has_fleet_flag = returning_home
			}
		}
	}

	immediate = {
		random_owned_fleet = {
			limit = {
				any_ship = { has_ship_flag = stellarite_ship }
			}
			clear_fleet_actions = this
			queue_actions = {
				repeat = {
					max_iterations = 1
					find_random_system = {
						trigger = {
							id = guardian.1004.trigger.1
							has_star_flag = guardians_stellarite_system
						}
						found_system = {
							move_to = this
							find_random_planet = {
								trigger = {
									id = guardian.1004.trigger.2
									is_star = yes
								}
								found_planet = {
									orbit_planet = this
								}
							}
						}
					}		
					repeat = {
						while = {
							id = guardian.1004.trigger.3
							has_hp_percentage < 1.0
						}
						wait = {
							duration = 30
						}
						effect = {
							id = guardian.1004.trigger.4
							repair_percentage = 0.075
						}
					}
				}
			}
		}
	}
}

# Stellarite dies and creates special project
country_event = {
	id = guardian.1016
	title = guardian.1000.name
	desc = guardian.1016.desc
	picture = GFX_evt_stellarites
	show_sound = event_radio_chatter
	location = event_target:stellarite_project_object

	is_triggered_only = yes

	trigger = {
		is_country_type = default
		from = { is_country_type = guardian_stellarite }
		fromfromfrom = {
			has_ship_flag = stellarite_ship
			solar_system = {
				has_star_flag = stellarite_present
				NOT = {
					has_star_flag = stellarite_slain
				}
			}
		}
	}

	immediate = {
		fromfromfrom = {
			solar_system = {
				save_event_target_as = slain_guardian_system
			}
			create_ambient_object = {
				type = stellarite_object
				location = this
			}
		}
		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_stellarite
						event_chain = curator_poi_chain
						owner = prev
					}
				}
			}
			remove_point_of_interest = curator_poi_stellarite
			end_curator_chain = yes
		}
		last_created_ambient_object = {
			save_event_target_as = stellarite_project_object
			set_ambient_object_flag = stellarite_project_object
			solar_system = {
				set_star_flag = stellarite_slain
			}
		}

		random_system = {
			limit = {
				has_star_flag = stellarite_present
			}
			every_system_planet = {
				limit = {
					has_modifier = stellarite_high_temp
				}
				remove_modifier = stellarite_high_temp
			}
		}
	}

	option = {
		name = guardian.1016.a
		#hidden_effect = {
			event_target:stellarite_project_object = {
				enable_special_project = {
					name = "STELLARITE_DEAD_PROJECT"
			 		location = this
			 		owner = root
				}
			}
		#}
	}
	option = {
		name = guardian.1016.b
		trigger = {
			OR = {
				has_ethic = ethic_militarist
				has_ethic = ethic_fanatic_militarist
				has_ethic = ethic_xenophobe
				has_ethic = ethic_fanatic_xenophobe
			} 
		}
		custom_tooltip = guardian.1016.b.tooltip
		add_influence = 500
		hidden_effect = {
			set_country_flag = stellarite_trophy_allowed
			random_ambient_object = {
				limit = {
					has_ambient_object_flag = stellarite_project_object
				}
				destroy_ambient_object = this
			}
		}
	}

	after = {
		hidden_effect = {
			random_system = {
				limit = {
					has_star_flag = stellarite_present
				}
				remove_star_flag = stellarite_present
			}
		}
	}
}

# Stellarite sun project to increase temperature
ship_event = {
	id = guardian.1017
	title = guardian.1000.name
	desc = guardian.1017.desc
	picture = GFX_evt_star_yellow
	show_sound = event_radio_chatter
	location = root

	is_triggered_only = yes

	immediate = {
		solar_system = {
			random_system_ambient_object = {
				limit = { has_ambient_object_flag = stellarite_project_object }
				destroy_ambient_object = this
			}
		}
		random_system = {
			limit = {
				has_star_flag = guardians_stellarite_system
			}
			save_event_target_as = guardians_stellarite_home_system
		}
	}

	option = {
		name = guardian.1017.a
		random_system = {
			limit = {
				has_star_flag = guardians_stellarite_system
			}
			random_system_planet = {
				limit = {
					is_star = yes
				}
				enable_special_project = {
					name = "STELLARITE_STAR_PROJECT"
		 			location = this
		 			owner = root.owner
				}
			}
		}
	}
	option = {
		name = guardian.1017.b
		owner = {
			add_monthly_resource_mult = {
				resource = energy
				value = @tier4materialreward
				min = @tier4materialmin
				max = @tier4materialmax
			}
			add_monthly_resource_mult = {
				resource = minerals
				value = @tier2materialreward
				min = @tier2materialmin
				max = @tier2materialmax
			}
			add_monthly_resource_mult = {
				resource = influence
				value = @tier2influencereward
				min = @tier2influencemin
				max = @tier2influencemax
			}
		}
	}
}

# Stellarite system is updated and Gaia world unlocks
ship_event = {
	id = guardian.1018
	title = guardian.1000.name
	desc = {
		trigger = {
			hidden:owner = {
				switch = {
					trigger = has_country_flag
					stellarite_project_success = { text = guardian.1018.desc }
					default = { text = guardian.1018.alt.desc }
				}
			}
		}
	}
	picture = GFX_evt_star_yellow
	show_sound = event_radio_chatter
	location = root

	is_triggered_only = yes

	immediate = {
		random_system = {
			limit = {
				has_star_flag = guardians_stellarite_system
			}
			save_event_target_as = guardians_stellarite_home_system
			random_system_planet = {
				limit = {
					is_planet_class = pc_frozen
				}
				save_event_target_as = stellarite_rich_planet
			}
		}
		random_list = {
			70 = { owner = { set_country_flag = stellarite_project_success } }
			30 = {
				root = {
					kill_leader = { type = scientist show_notification = no }
					fleet = {
						destroy_fleet = this
					}
				}
			}
		}
	}

	option = {
		name = EXCELLENT
		custom_tooltip = guardian.1018.a.tooltip
		trigger = {
			owner = {
				has_country_flag = stellarite_project_success
			}
		}
		hidden_effect = {
			owner = { remove_country_flag = stellarite_project_success }
			random_system = {
				limit = {
					has_star_flag = guardians_stellarite_system
				}
				random_system_planet = {
					limit = {
						is_star = yes
					}
					change_planet_size = 12
					spawn_sun_temperature_effect = yes
				}
				every_system_planet = {
					limit = {
						is_star = no
						is_asteroid = no
					}
					spawn_planet_temperature_effect = yes
					remove_modifier = stellarite_low_temp
					if = {
						limit = {
							is_planet_class = pc_frozen
							NOT = { has_planet_flag = stellarite_terraformed }
							solar_system = {
								NOT = { has_star_flag = gaia_planet_gained }
							}
						}
						change_pc = pc_gaia
						set_planet_flag = stellarite_terraformed
						reroll_planet = yes
						#random_tile = {
						#	limit = { has_blocker = no has_building = no }
						#	set_blocker = "tb_mountain_range"
						#	add_resource = {
						#		resource = energy
						#		amount = 5
						#	}
						#}
						#random_tile = {
						#	limit = { has_blocker = no has_building = no }
						#	set_blocker = "tb_massive_glacier"
						#	add_resource = {
						#		resource = energy
						#		amount = 5
						#	}
						#}
						#random_tile = {
						#	limit = { has_blocker = no has_building = no }
						#	set_blocker = "tb_massive_glacier"
						#	add_resource = {
						#		resource = energy
						#		amount = 5
						#	}
						#}
						#random_tile = {
						#	limit = { has_blocker = no has_building = no }
						#	set_blocker = "tb_active_volcano"
						#}
						#random_tile = {
						#	limit = { has_blocker = no has_building = no }
						#	set_blocker = "tb_mountain_range"
						#}
						#random_tile = {
						#	add_resource = {
						#		resource = energy
						#		amount = 5
						#	}
						#}
						#random_tile = {
						#	add_resource = {
						#		resource = energy
						#		amount = 5
						#	}
						#}
						#random_tile = {
						#	add_resource = {
						#		resource = minerals
						#		amount = 5
						#	}
						#}
						#random_tile = {
						#	add_resource = {
						#		resource = minerals
						#		amount = 5
						#	}
						#}
						solar_system = { set_star_flag = gaia_planet_gained }
						else = {
							if = {
								limit = {
									is_planet_class = pc_frozen
									NOT = { has_planet_flag = stellarite_terraformed }
									solar_system = {
										has_star_flag = gaia_planet_gained
									}
								}
								increase_planet_temperature = yes
								set_planet_flag = stellarite_terraformed
								else = {
									increase_planet_temperature = yes
									set_planet_flag = stellarite_terraformed
								}
							}
						}
					}
				}
			}
		}
	}
	option = {
		name = UNFORTUNATE
		custom_tooltip = guardian.1018.b.tooltip
		trigger = {
			owner = {
				NOT = { has_country_flag = stellarite_project_success }
			}
		}
		hidden_effect = {
			random_system = {
				limit = {
					has_star_flag = guardians_stellarite_system
				}
				random_system_planet = {
					limit = {
						is_star = yes
					}
					change_planet_size = 8
					planet_event = { id = guardian.1019 }
				}
				every_system_planet = {
					limit = {
						is_star = no
						is_asteroid = no
					}
					spawn_planet_temperature_effect = yes
					remove_modifier = stellarite_low_temp
					if = {
						limit = {
							is_planet_class = pc_frozen
							NOT = { has_planet_flag = stellarite_terraformed }
						}
						change_pc = pc_tundra
						set_planet_flag = stellarite_terraformed
						reroll_planet = yes
						#random_tile = {
						#	limit = { has_blocker = no has_building = no }
						#	set_blocker = "tb_mountain_range"
						#	add_resource = {
						#		resource = energy
						#		amount = 5
						#	}
						#}
						#random_tile = {
						#	limit = { has_blocker = no has_building = no }
						#	set_blocker = "tb_massive_glacier"
						#	add_resource = {
						#		resource = energy
						#		amount = 3
						#	}
						#}
						#random_tile = {
						#	limit = { has_blocker = no has_building = no }
						#	set_blocker = "tb_massive_glacier"
						#	add_resource = {
						#		resource = energy
						#		amount = 2
						#	}
						#}
						#random_tile = {
						#	limit = { has_blocker = no has_building = no }
						#	set_blocker = "tb_massive_glacier"
						#}
						#random_tile = {
						#	limit = { has_blocker = no has_building = no }
						#	set_blocker = "tb_mountain_range"
						#}
						#random_tile = {
						#	add_resource = {
						#		resource = minerals
						#		amount = 5
						#	}
						#}
						#random_tile = {
						#	add_resource = {
						#		resource = minerals
						#		amount = 5
						#	}
						#}
						#random_tile = {
						#	add_resource = {
						#		resource = minerals
						#		amount = 5
						#	}
						#}
						else = {
							if = {
								limit = {
									is_planet_class = pc_frozen
									NOT = { has_planet_flag = stellarite_terraformed }
									solar_system = {
										has_star_flag = gaia_planet_gained
									}
								}
								increase_planet_temperature = yes
								set_planet_flag = stellarite_terraformed
								reroll_planet = yes
								else = {
									increase_planet_temperature = yes
									set_planet_flag = stellarite_terraformed
									reroll_planet = yes
								}
							}
						}
					}
				}
			}
		}
	}
}

planet_event = {
	id = guardian.1019
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		spawn_sun_temperature_effect = yes
	}
}

### TECHNOSPHERE ###
#Encountering Technosphere for the first time
fleet_event = {
	id = guardian.1030
	title = guardian.1030.name
	desc = {
		trigger = {
			hidden:from = {
				switch = {
					trigger = has_star_flag
					guardians_technosphere_system = { text = guardian.1030.desc }
					default = { text = guardian.1030.desc.alt }
				}
			}
		}
	}
	picture = GFX_evt_technosphere
	show_sound = event_yellow_alert
	location = from

	is_triggered_only = yes

	trigger = {
		from = {
			any_ship_in_system = {
				exists = owner
				owner = {
					is_country_type = guardian_sphere
				}
			}
		}
		owner = {
			is_ai = no
			NOR = {
				has_country_flag = guardians_technosphere_encountered
				has_country_flag = worm_events_available
			}
		}
	}

	immediate = {
		owner = {
			country_event = { id = story.8 days = 15 }
			set_country_flag = guardians_technosphere_encountered
			establish_communications_no_message = event_target:guardian_technosphere_country
		}
	}

	option = {
		name = INTERESTING
		owner = {
			begin_event_chain = {
				event_chain = technosphere_chain
				target = root.owner
			}
		}
		hidden_effect = {
			owner = {
				create_point_of_interest = {
					id = technosphere_chain_poi
					name = technosphere_chain_title
					desc = technosphere_chain_desc
					event_chain = technosphere_chain
					location = root.solar_system
				}
				country_event = { id = guardian.1050 days = 520 random = 200 }
			}
		}
	}
}

#Technosphere return to black hole to heal
fleet_event = {
	id = guardian.1031
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_combatant_fleet = {
			has_fleet_flag = technosphere_fleet
		}
	}

	immediate = {
		random_combatant_fleet = {
			limit = {
				has_fleet_flag = technosphere_fleet
			}
			clear_fleet_actions = this
			queue_actions = {
				repeat = {
					max_iterations = 1
					find_random_system = {
						trigger = {
							id = guardian.1031.trigger.1
							has_star_flag = guardians_technosphere_system
						}
						found_system = {
							move_to = this
							#find_random_planet = {
							#	trigger = {
							#		id = guardian.1031.trigger.2
							#		is_star = yes
							#	}
							#	found_planet = {
							#		orbit_planet = this
							#	}
							#}
						}
					}
					repeat = {
						while = {
							id = guardian.1031.trigger.3
							has_hp_percentage < 1.0
						}
						wait = {
							duration = 30
						}
						effect = {
							id = guardian.1031.trigger.4
							repair_percentage = 0.075
						}
					}
				}
			}
		}
	}
}

country_event = {
	id = guardian.1032
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		fromfrom = {
			has_fleet_flag = technosphere_fleet
		}
	}

	immediate = {
		fromfrom = {
			clear_fleet_actions = this
			queue_actions = {
				repeat = {
					max_iterations = 1
					find_random_system = {
						trigger = {
							id = guardian.1032.trigger.1
							has_star_flag = guardians_technosphere_system
						}
						found_system = {
							move_to = this
							find_random_planet = {
								trigger = {
									id = guardian.1032.trigger.2
									is_star = yes
								}
								found_planet = {
									orbit_planet = this
								}
							}
						}
					}
					repeat = {
						while = {
							id = guardian.1032.trigger.3
							has_hp_percentage < 1.0
						}
						wait = {
							duration = 30
						}
						effect = {
							id = guardian.1032.trigger.4
							repair_percentage = 0.075
						}
					}
				}
			}
		}
	}
}

#Killing the Technosphere
country_event = {
	id = guardian.1039
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		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_technosphere
						event_chain = curator_poi_chain
						owner = prev
					}
				}
			}
			remove_point_of_interest = curator_poi_technosphere
			end_curator_chain = yes
		}
		every_country = {
			limit = {
				is_country_type = default
				has_event_chain = technosphere_chain
			}
			end_event_chain = technosphere_chain
		}
		every_country = {
			limit = {
				NOR = {
					is_same_value = root
					is_hostile = event_target:guardian_technosphere_country
				}
				is_country_type = default
				OR = {
					has_modifier = infinity_calculations
					has_modifier = technosphere_praising
					has_country_flag = guardians_technosphere_encountered
				}
			}
			country_event = { id = guardian.1041 }
		}
	}

	after = {
		if = {
			limit = {
				has_modifier = infinity_calculations
			}
			remove_modifier = infinity_calculations
		}
		if = {
			limit = {
				has_modifier = technosphere_praising
			}
			remove_modifier = technosphere_praising
		}
	}
}

country_event = {
	id = guardian.1040
	title = guardian.1030.name
	desc = {
		trigger = {
			switch = {
				trigger = has_country_flag
				technosphere_sabotaged = { text = guardian.1040.desc.alt }
				technosphere_studied = { text = guardian.1040.desc.detail }
				default = { text = guardian.1040.desc }
			}
		}
	}
	picture = GFX_evt_technosphere
	show_sound = event_super_explosion
	location = fromfrom

	is_triggered_only = yes

	trigger = {
		OR = {
			AND = {
				has_country_flag = technosphere_sabotaged
				fromfrom = { owner = { is_country_type = guardian_sphere } }
			}
			AND = {
				from = {
					is_country_type = guardian_sphere
				}
			}
		}
	}

	immediate = {
		fromfrom = {
			solar_system = {
				save_event_target_as = technosphere_location
				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_technosphere
						event_chain = curator_poi_chain
						owner = prev
					}
				}
			}
			remove_point_of_interest = curator_poi_technosphere
			end_curator_chain = yes
		}
		every_country = {
			limit = {
				is_country_type = default
				has_event_chain = technosphere_chain
			}
			end_event_chain = technosphere_chain
		}
		every_country = {
			limit = {
				NOR = {
					is_same_value = root
					is_hostile = event_target:guardian_technosphere_country
				}
				is_country_type = default
				OR = {
					has_modifier = infinity_calculations
					has_modifier = technosphere_praising
					has_country_flag = guardians_technosphere_encountered
				}
			}
			country_event = { id = guardian.1041 }
		}
	}

	after = {
		if = {
			limit = {
				has_modifier = infinity_calculations
			}
			remove_modifier = infinity_calculations
		}
		if = {
			limit = {
				has_modifier = technosphere_praising
			}
			remove_modifier = technosphere_praising
		}
	}

	option = {
		name = guardian.1040.a
		add_monthly_resource_mult = {
			resource = influence
			value = @tier5influencereward
			min = @tier5influencemin
			max = @tier5influencemax
		}
		add_monthly_resource_mult = {
			resource = minerals
			value = @tier5materialreward
			min = @tier5materialmin
			max = @tier5materialmax
		}
	}
	option = {
		name = guardian.1040.c
		trigger = {
			NOT = {
				has_technology = tech_robotic_workers
				has_technology = tech_droid_workers
				has_technology = tech_synthetic_workers
				has_technology = tech_synthetic_leaders
			}
		}
		add_research_option = tech_robotic_workers
		add_tech_progress = {
			tech = tech_robotic_workers
			progress = 0.50
		}
	}
	option = {
		name = guardian.1040.c
		trigger = {
			has_technology = tech_robotic_workers
			NOT = {
				has_technology = tech_droid_workers
				has_technology = tech_synthetic_workers
				has_technology = tech_synthetic_leaders
			}
		}
		add_research_option = tech_droid_workers
		add_tech_progress = {
			tech = tech_droid_workers
			progress = 0.50
		}
	}
	option = {
		name = guardian.1040.c
		trigger = {
			has_technology = tech_robotic_workers
			has_technology = tech_droid_workers
			NOT = {
				has_technology = tech_synthetic_workers
				has_technology = tech_synthetic_leaders
			}
		}
		add_research_option = tech_synthetic_workers
		add_tech_progress = {
			tech = tech_synthetic_workers
			progress = 0.50
		}
	}
	option = {
		name = guardian.1040.c
		trigger = {
			has_technology = tech_robotic_workers
			has_technology = tech_droid_workers
			has_technology = tech_synthetic_workers
			NOT = {
				has_technology = tech_synthetic_leaders
			}
		}
		add_research_option = tech_synthetic_leaders
		add_tech_progress = {
			tech = tech_synthetic_leaders
			progress = 0.50
		}
	}
}

country_event = {
	id = guardian.1041
	title = guardian.1030.name
	desc = guardian.1041.desc
	picture = GFX_evt_technosphere
	show_sound = event_super_explosion
	location = event_target:technosphere_ship

	is_triggered_only = yes

	after = {
		if = {
			limit = {
				has_modifier = infinity_calculations
			}
			remove_modifier = infinity_calculations
		}
		if = {
			limit = {
				has_modifier = technosphere_praising
			}
			remove_modifier = technosphere_praising
		}
	}

	option = {
		name = TERRIBLE
		trigger = {
			NOT = {
				has_ethic = ethic_fanatic_militarist
				has_ethic = ethic_militarist
				has_ethic = ethic_fanatic_materialist
				has_ethic = ethic_materialist
			}
		}
	}
	option = {
		name = CURSES
		trigger = {
			OR = {
				has_ethic = ethic_fanatic_militarist
				has_ethic = ethic_militarist
				has_ethic = ethic_fanatic_materialist
				has_ethic = ethic_materialist
			}
		}
	}
}

#Investigating the Technosphere
country_event = {
	id = guardian.1050
	title = guardian.1050.name
	desc = guardian.1050.desc
	picture = GFX_evt_technosphere
	show_sound = event_sensor_ping
	location = event_target:technosphere_ship

	is_triggered_only = yes

	trigger = {
		exists = event_target:technosphere_ship
		is_ai = no
		has_country_flag = guardians_technosphere_encountered
		any_system = {
			has_star_flag = guardians_technosphere_system
			any_ship_in_system = {
				exists = owner
				owner = {
					is_country_type = guardian_sphere
				}
			}
		}
		NOT = {
			has_country_flag = worm_events_available
			event_target:guardian_technosphere_country = {
				is_hostile = root
			}
		}
	}

	immediate = {
		event_target:guardian_technosphere_country = {
			random_owned_ship = {
				limit = {
					is_ship_size = sphere
				}
				save_event_target_as = technosphere_location
			}
		}
		end_event_chain = technosphere_chain
	}

	option = {
		name = FASCINATING
		enable_special_project = {
			name = "TECHNOSPHERE_PROJECT"
			location = event_target:technosphere_ship
			owner = root
		}
	}
	option = {
		name = NOTIME
		add_influence = 50
	}
}

#Succeeded in researching the Technosphere
country_event = {
	id = guardian.1051
	title = guardian.1050.name
	desc = guardian.1051.desc
	picture = GFX_evt_technosphere
	show_sound = event_mystic_reveal
	location = event_target:technosphere_ship

	is_triggered_only = yes

	trigger = {
		exists = event_target:technosphere_ship
		NOT = { has_country_flag = worm_events_available }
	}

	immediate = {
		set_country_flag = technosphere_studied
		event_target:guardian_technosphere_country = {
			random_owned_ship = {
				limit = {
					is_ship_size = sphere
				}
				save_event_target_as = technosphere_location
			}
		}
	}

	option = {
		name = guardian.1051.a
		hidden_effect = {
			country_event = { id = guardian.1055 }
		}
	}
	option = {
		name = guardian.1051.c #praise it as your god
		trigger = {
			OR = {
				has_ethic = ethic_fanatic_spiritualist
				has_ethic = ethic_spiritualist
			}
		}
		add_modifier = {
			modifier = technosphere_praising
			days = -1
		}
	}
	option = {
		name = guardian.1051.b #hack it
		trigger = {
			OR = {
				has_ethic = ethic_fanatic_materialist
				has_ethic = ethic_materialist
			}
		}
		enable_special_project = {
			name = TECHNOSPHERE_HACKING
			location = event_target:technosphere_ship
			owner = root 
		}
	}
	option = {
		name = guardian.1051.d #sabotage it
		#custom_tooltip = guardian.1051.d.tooltip
		trigger = {
			OR = {
				has_ethic = ethic_fanatic_militarist
				has_ethic = ethic_militarist
			}
		}
		hidden_effect = {
			set_country_flag = technosphere_sabotaged
		}
		event_target:technosphere_ship = {
			enable_special_project = {
				name = TECHNOSPHERE_DESTRUCTION
				location = this
				owner = root 
			}
		}
	}
}

#Hacking the technosphere - success
country_event = {
	id = guardian.1052
	title = guardian.1050.name
	desc = guardian.1052.desc
	picture = GFX_evt_technosphere
	show_sound = event_ai_started
	location = event_target:technosphere_ship
	is_triggered_only = yes

	trigger = {
		exists = event_target:technosphere_ship
	}

	immediate = {
		event_target:guardian_technosphere_country = {
			random_owned_ship = {
				limit = {
					is_ship_size = sphere
				}
				save_event_target_as = technosphere_location
			}
		}
	}
	after = {
		add_modifier = {
			modifier = infinity_calculations_hacked
			days = -1
		}
		event_target:technosphere_location = {
			solar_system = {
				save_event_target_as = slain_guardian_system
			}
			fleet = {
				destroy_fleet = this
			}
		}
		hidden_effect = {
			country_event = { id = guardian.1039 }
		}
	}
	option = {
		name = guardian.1052.a
		give_technology = { tech = tech_sentient_ai }
		trigger = {
			NOT = {
				has_technology = tech_sentient_ai
			}
		}
	}
	option = {
		name = guardian.1052.a
		trigger = {
			has_technology = tech_sentient_ai
			NOT = {
				has_technology = tech_zero_point_power
			}
		}
		give_technology = { tech = tech_zero_point_power }
	}
	option = {
		name = guardian.1052.a
		trigger = {
			has_technology = tech_sentient_ai
			has_technology = tech_zero_point_power
		}
		add_monthly_resource_mult = {
			resource = society_research
			value = 24
			min = 1000
			max = 2000
		}
	}
}

#Hacking the technosphere - fail
country_event = {
	id = guardian.1053
	title = sphere
	desc = guardian.1053.desc 
	is_triggered_only = yes
	diplomatic = yes

	trigger = { exists = event_target:technosphere_ship }

	picture_event_data = {
		room = technosphere_room
	}

	option = {
		name = guardian.1053.a
		response_text = guardian.1053.a.reply
		default_hide_option = yes
	}
	option = {
		name = guardian.1053.b
		response_text = guardian.1053.b.reply
	}
}

#Contacting the technosphere
country_event = {
	id = guardian.1055
	title = sphere
	desc = guardian.1055.desc
	is_triggered_only = yes
	diplomatic = yes

	trigger = {
		exists = event_target:technosphere_ship
		NOT = { has_country_flag = worm_events_available }
	}

	picture_event_data = {
		room = technosphere_room
	}

	option = {
		name = guardian.1055.a
		#default_hide_option = yes
		hidden_effect = {
			country_event = { id = guardian.1056 }
		}
	}
}

#Dialogue with the Technosphere
country_event = {
	id = guardian.1056
	title = sphere
	desc = guardian.1056.desc
	is_triggered_only = yes
	diplomatic = yes

	trigger = { exists = event_target:technosphere_ship }

	picture_event_data = {
		room = technosphere_room
	}

	option = {
		name = guardian.1056.a
		response_text = guardian.1056.a.reply
		is_dialog_only = yes
	}
	option = {
		name = guardian.1056.b
		response_text = guardian.1056.b.reply
		is_dialog_only = yes
	}
	option = {
		name = guardian.1056.c
		response_text = guardian.1056.c.reply
		is_dialog_only = yes
		trigger = {
			OR = {
				has_ethic = ethic_fanatic_militarist
				has_ethic = ethic_militarist
				has_ethic = ethic_fanatic_egalitarian
			}
		}
	}
	option = {
		name = guardian.1056.d
		hidden_effect = {
			random_list = {
				70 = { }
				30 = { set_country_flag = technosphere_secrets }
			}
			country_event = { id = guardian.1060 }
			
		}
	}
	option = {
		name = guardian.1056.e
		response_text = guardian.1056.e.reply
		add_influence = 100
	}
}

#Offer your services to the Technosphere
country_event = {
	id = guardian.1060
	title = sphere
	desc = guardian.1060.desc
	is_triggered_only = yes
	diplomatic = yes

	trigger = { exists = event_target:technosphere_ship }

	picture_event_data = {
		room = technosphere_room
	}

	immediate = {
		random_system = {
			limit = {
				has_star_flag = guardians_technosphere_system
			}
			random_system_planet = {
				limit = {
					is_star = yes
				}
				save_event_target_as = technosphere_blackhole
			}
		}
	}

	option = {
		name = guardian.1060.a
		response_text = guardian.1060.a.reply
		enable_special_project = {
			name = TECHNOSPHERE_BLACKHOLE
			location = event_target:technosphere_blackhole
			owner = root 
		}
	}
	option = {
		name = guardian.1056.e #GOODBYE
		response_text = guardian.1056.e.reply
		add_influence = 100
	}
}

#Researching the black hole - success
country_event = {
	id = guardian.1061
	title = sphere
	desc = guardian.1061.desc
	is_triggered_only = yes
	diplomatic = yes

	trigger = { exists = event_target:technosphere_ship }

	picture_event_data = {
		room = technosphere_room
	}

	immediate = {
		random_system = {
			limit = {
				has_star_flag = guardians_technosphere_system
			}
			random_system_planet = {
				limit = {
					is_star = yes
				}
				save_event_target_as = technosphere_blackhole
			}
		}
	}

	option = {
		name = guardian.1061.a
		response_text = guardian.1061.a.reply
		give_technology = { tech = tech_sentient_ai }
		add_influence = 150
		trigger = {
			NOT = {
				has_technology = tech_sentient_ai
			}
		}
	}
	option = {
		name = guardian.1061.a
		response_text = guardian.1061.a.reply
		give_technology = { tech = tech_zero_point_power }
		add_influence = 150
		trigger = {
			has_technology = tech_sentient_ai
			NOT = {
				has_technology = tech_zero_point_power
			}
		}
	}
	option = {
		name = guardian.1061.b
		response_text = guardian.1061.b.reply
		add_modifier = {
			modifier = infinity_calculations
			days = -1
		}
		trigger = {
			NOR = {
				has_technology = tech_sentient_ai
				has_technology = tech_zero_point_power
			}
		}
	}
	option = {
		name = guardian.1061.b.alt
		response_text = guardian.1061.b.reply
		add_modifier = {
			modifier = infinity_calculations
			days = -1
		}
		trigger = {
			has_technology = tech_sentient_ai
			has_technology = tech_zero_point_power
		}
	}
}

#Researching the black hole - submerge check (fail or special event)
country_event = {
	id = guardian.1062
	title = sphere
	desc = guardian.1062.desc
	is_triggered_only = yes
	show_sound = event_mystic_reveal
	location = event_target:technosphere_ship
	diplomatic = yes

	trigger = { exists = event_target:technosphere_ship }

	picture_event_data = {
		room = technosphere_room
	}

	is_triggered_only = yes

	immediate = {
		set_country_flag = technosphere_studied
		event_target:guardian_technosphere_country = {
			random_owned_ship = {
				limit = {
					is_ship_size = sphere
				}
				save_event_target_as = technosphere_location
			}
		}
		
		random_system = {
			limit = {
				has_star_flag = guardians_technosphere_system
			}
			random_system_planet = {
				limit = {
					is_star = yes
				}
				save_event_target_as = technosphere_blackhole
			}
		}
	}

	option = {
		name = guardian.1062.a
		hidden_effect = {
			event_target:guardian_technosphere_country = {
				random_owned_ship = {
					limit = {
						is_ship_size = sphere
					}
					fleet = {
						queue_actions = {
							find_closest_planet = {
								trigger = {
									id = guardian.1062.trigger.1
									is_planet_class = pc_black_hole
									solar_system = {
										has_star_flag = guardians_technosphere_system
									}
								}
								found_planet = {
									move_to = this
									effect = {
										id = guardian.1062.effect.1
										root = {
											if = {
												limit = {
													has_country_flag = technosphere_special
												}
												remove_country_flag = technosphere_special
												country_event = { id = guardian.1065 }
												else = {
													country_event = { id = guardian.1063 }
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

#The technosphere submerges itself into the hole - FAIL
country_event = {
	id = guardian.1063
	title = sphere
	desc = guardian.1063.desc
	is_triggered_only = yes
	picture = GFX_evt_technosphere
	show_sound = event_mystic_reveal
	location = event_target:technosphere_ship

	is_triggered_only = yes

	trigger = { exists = event_target:technosphere_ship }

	option = {
		name = PECULIAR
		custom_tooltip = guardian.1063.a.tooltip
		add_influence = 150
		if = {
			limit = {
				NOT = {
					has_technology = tech_sentient_ai
				}
			}
			give_technology = { tech = tech_sentient_ai }
			else = {
				if = {
					limit = {
						NOT = { has_technology = tech_zero_point_power }
					}
					give_technology = { tech = tech_zero_point_power }
					else = {
						add_influence = 150
					}
				}
			}
		}
		hidden_effect = {
			event_target:technosphere_ship = {
				solar_system = {
					random_system_planet = {
						limit = { is_star = yes }
						orbital_deposit_tile = {
							add_deposit =  d_immense_physics_deposit
							add_deposit =  d_immense_engineering_deposit
							add_deposit =  d_immense_society_deposit
						}
					}
				}
			}
			event_target:technosphere_ship = {
				solar_system = {
					save_event_target_as = slain_guardian_system
				}
				delete_fleet = this
			}
			country_event = { id = guardian.1039 }
		}
	}
}

#The technosphere submerges itself into the hole - secret
country_event = {
	id = guardian.1065
	title = sphere
	desc = guardian.1065.desc
	is_triggered_only = yes
	picture = GFX_evt_technosphere
	show_sound = event_mystic_reveal
	location = event_target:technosphere_ship

	is_triggered_only = yes

	trigger = { exists = event_target:technosphere_ship }

	immediate = {
		set_country_flag = pantagruel
	}

	option = {
		name = AMAZING
		custom_tooltip = guardian.1065.a.tooltip
		hidden_effect = {
			add_influence = 200
			event_target:technosphere_ship.solar_system = {
				random_system_planet = {
					limit = { is_star = yes }
					solar_system = {
						set_name = "NAME_Pantagruel"
					}
					set_name = "NAME_Pantagruel"
					change_planet_size = -30
					create_ambient_object = {
						type = explosion_particle_object
						location = this
						duration = 5
						
						use_3d_location = yes
						
						entity_offset = { min = 0 max = 0 }
						entity_offset_angle = { min = 0 max = 0 }
						entity_offset_height = { min = 0 max = 0 }
						
						entity_scale_to_size = yes
						scale = 100
					}
					orbital_deposit_tile = {
						add_deposit =  d_rich_physics_deposit
						add_deposit =  d_immense_physics_deposit
						add_deposit =  d_immense_physics_deposit
						add_deposit =  d_rich_engineering_deposit
						add_deposit =  d_immense_engineering_deposit
						add_deposit =  d_immense_engineering_deposit
						add_deposit =  d_rich_society_deposit
						add_deposit =  d_immense_society_deposit
						add_deposit =  d_immense_society_deposit
					}
					add_modifier = {
						modifier = black_hole_pantagruel
						days = -1
					}
					if = {
						limit = {
							OR = {
								has_frontier_station = yes
								has_research_station = yes
							}
						}
						controller = {
							add_modifier = {
								modifier = black_hole_pantagruel_research
								days = -1
							}
						}
					}
					if = {
						limit = {
							is_surveyed = {
								who = root
								status = no
							}
						}
						surveyed = {
							set_surveyed = yes
							surveyor = root
						}
					}
				}
			}
			event_target:technosphere_ship = {
				solar_system = {
					save_event_target_as = slain_guardian_system
				}
				#fleet = {
					delete_fleet = this
				#}
			}
			country_event = { id = guardian.1039 }
		}
	}
}

#Black hole adds modifier when building a research station 
ship_event = {
	id = guardian.1070
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		from = {
			is_planet_class = pc_black_hole
			has_modifier = black_hole_pantagruel
		}
		owner = {
			NOT = { has_modifier = black_hole_pantagruel_research }
		}
	}

	immediate = {
		owner = {
			add_modifier = {
				modifier = black_hole_pantagruel_research
				days = -1
			}
		}
	}
}

#Black hole removes modifier when a research station is lost 
country_event = {
	id = guardian.1071
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_modifier = black_hole_pantagruel_research
		from = { #if triggered by on_fleet_disbanded
			orbit = {
				planet = {
					is_planet_class = pc_black_hole
					has_modifier = black_hole_pantagruel
				}
			}
		}
	}

	immediate = {
		remove_modifier = black_hole_pantagruel_research
	}
}

#Black hole removes modifier when a research station is lost 
country_event = {
	id = guardian.1072
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_modifier = black_hole_pantagruel_research
		fromfrom = { #if triggered by on_fleet_destroyed_victim
			orbit = {
				planet = {
					is_planet_class = pc_black_hole
					has_modifier = black_hole_pantagruel
				}
			}
		}
	}

	immediate = {
		remove_modifier = black_hole_pantagruel_research
	}
}

#Black hole removes modifier when a research station is lost
ship_event = {
	id = guardian.1073
	hide_window = yes
	
	is_triggered_only = yes

	trigger = {
		exists = orbit
		orbit = {
			planet = {
				is_planet_class = pc_black_hole
				has_modifier = black_hole_pantagruel
			}
		}
		from = { has_modifier = black_hole_pantagruel_research }
	}

	immediate = {
		from = { country_event = { id = guardian.1074 } }
	}
}

country_event = {
	id = guardian.1074
	title = guardian.1074.name
	desc = guardian.1074.desc
	picture = GFX_evt_space_station
	show_sound = event_yellow_alert
	location = root

	is_triggered_only = yes

	option = {
		name = UNFORTUNATE
		remove_modifier = black_hole_pantagruel_research
	}
}

ship_event = {
	id = guardian.1075
	hide_window = yes
	
	is_triggered_only = yes

	trigger = {
		orbit = {
			planet = {
				is_planet_class = pc_black_hole
				has_modifier = black_hole_pantagruel
			}
		}
		from = { NOT = { has_modifier = black_hole_pantagruel_research } }
	}

	immediate = {
		from = { country_event = { id = guardian.1076 } }
	}
}

#Black hole removes modifier when a research station is lost 
country_event = {
	id = guardian.1076
	title = guardian.1074.name
	desc = guardian.1076.desc
	picture = GFX_evt_space_station
	show_sound = event_mystic_reveal
	location = root

	is_triggered_only = yes

	option = {
		name = EXCELLENT
		add_modifier = {
			modifier = black_hole_pantagruel_research
			days = -1
		}
	}
}

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

### WRAITH ###
# First scan of the neutron star, sets Wraith spawn timer
ship_event = {
	id = guardian.2010
	title = "guardian.2010.name"
	desc = guardian.2010.desc
	picture = GFX_evt_star_pulsar
	show_sound = event_mystic_reveal
	
	is_triggered_only = yes

	trigger = {
		from = { has_planet_flag = guardians_wraith_pulsar }
	}

	immediate = { from = { remove_planet_flag = guardians_wraith_pulsar } }

	option = {
		name = guardian.2010.a
		custom_tooltip = guardian.2010.c
		hidden_effect = {
			from = {
				planet_event = { id = guardian.2011 days = 14400 } # 40 Years
			}
		}
	}
}

# Wraith is born
planet_event = {
	id = guardian.2011
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		name = guardian.2011.a
		create_country = {
			name = "NAME_Wraith"
			type = guardian_wraith
			flag = {
				icon = {
					category = "zoological"
					file = "flag_zoological_5.dds"
				}
				background= {
					category = "backgrounds"
					file = "00_solid.dds"
				}
				colors={
					"red"
					"red"
					"null"
					"null"
				}
			}
		}
		last_created_country = {
			set_country_flag = wraith_country
			guardian_difficulty = yes
			save_global_event_target_as = wraith_country
			#ISB Balance
			country_event = { id = isb.5 days = 1 }
			create_fleet = {
				name = "NAME_Specter"
				settings = {
					spawn_debris = no
					is_boss = yes
				}
				effect = {
					set_owner = event_target:wraith_country
					random_list = {
						33 = {
							create_ship = {
								name = "NAME_Wraith_650THz"
								design = "NAME_Spectral_Wraith_650THz"
								effect = {
									set_ship_flag = wraith_ship
									set_ship_flag = wraith_freq_blue
								}
							}
						}
						33 = {
							create_ship = {
								name = "NAME_Wraith_450THz"
								design = "NAME_Spectral_Wraith_450THz"
								effect = {
									set_ship_flag = wraith_ship
									set_ship_flag = wraith_freq_red
								}
							}
						}
						33 = {
							create_ship = {
								name = "NAME_Wraith_520THz"
								design = "NAME_Spectral_Wraith_520THz"
								effect = {
									set_ship_flag = wraith_ship
									set_ship_flag = wraith_freq_yellow
								}
							}
						}
					}
					save_global_event_target_as = wraith_fleet
					set_location = root
					set_fleet_stance = aggressive
					set_aggro_range_measure_from = self
					set_aggro_range = 20
					queue_actions = {
						repeat = {
							find_closest_system = {
								trigger = {
									id = wraith.1.trigger.1
									NOT = {
										exists = space_owner
										any_ship_in_system = {
											fleet = { is_same_value = event_target:wraith_fleet }
										}
										has_star_flag = guardians_wraith_visited
									}
								}
								found_system = {
									move_to = this
									find_closest_planet = {
										trigger = {
											id = wraith.1.trigger.2
											is_star = yes
										}
										found_planet = {
											move_to = this
											#orbit_planet = this
											wait = {
												duration = 10
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		if = {
			limit = { exists = space_owner }
			space_owner = {
				country_event = { id = guardian.2012 }
			}
		}
	}
}

# Wraith Spawned in Territory
country_event = {
	id = guardian.2012
	title = "guardian.2012.name"
	desc = guardian.2012.desc
	picture = GFX_evt_wraith
	show_sound = event_space_whale

	is_triggered_only = yes

	immediate = {
		establish_communications_no_message = event_target:wraith_country
		set_country_flag = guardians_wraith_encountered
	}

	option = {
		name = guardian.2012.a
	}
}

# Wraith Enters Territory
country_event = {
	id = guardian.2013
	title = "guardian.2012.name"
	desc = guardian.2013.desc
	picture = GFX_evt_wraith
	show_sound = event_space_whale

	is_triggered_only = yes

	trigger = {
		FROM.OWNER = { has_country_flag = wraith_country }
		NOT = { has_country_flag = guardians_wraith_encountered }
	}

	immediate = {
		establish_communications_no_message = event_target:wraith_country
		set_country_flag = guardians_wraith_encountered
	}

	option = {
		name = guardian.2013.a
	}
}

# Wraith killed
country_event = {
	id = guardian.2014
	title = "guardian.2014.name"
	desc = guardian.2014.desc
	picture = GFX_evt_wraith
	show_sound = event_space_whale

	is_triggered_only = yes

	trigger = {
		from = { has_country_flag = wraith_country }
	}

	immediate = {
		set_country_flag = killed_wraith
		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_wraith
						event_chain = curator_poi_chain
						owner = prev
					}
				}
			}
			remove_point_of_interest = curator_poi_wraith
			end_curator_chain = yes
		}
	}

	option = {
		name = guardian.2014.a
		add_modifier = {
			modifier = "spectral_residue_studies"
			days = -1
		}
	}
}

# Wraith Frequency Modifier Mechanics
ship_event = {
	id = guardian.2061
	hide_window = yes
	is_triggered_only = yes

	trigger = { has_ship_flag = wraith_ship } #TODO WRAITH

	immediate = {
		solar_system = {
			set_star_flag = guardians_wraith_visited
			if = {
				limit = {
					exists = space_owner
					space_owner = { NOT = { has_country_flag = guardians_wraith_encountered } }
				}
				space_owner = {
					country_event = { id = guardian.2013 }
				}
			}
		}
		if = {
			limit = { has_modifier = wraith_frequency_sync }
			# Removes the modifier when the right star class is not present
			if = {
				limit = {
					has_ship_flag = wraith_freq_blue
					NOT = {
						solar_system = {
							OR = {
								is_star_class = sc_b
								is_star_class = sc_a
							}
						}
					}
				}
				remove_modifier = "wraith_frequency_sync"
			}
			if = {
				limit = {
					has_ship_flag = wraith_freq_yellow
					NOT = {
						solar_system = {
							is_star_class = sc_g
						}
					}
				}
				remove_modifier = "wraith_frequency_sync"
			}
			if = {
				limit = {
					has_ship_flag = wraith_freq_red
					NOT = {
						solar_system = {
							is_star_class = sc_m
						}
					}
				}
				remove_modifier = "wraith_frequency_sync"
			}
		}
		if = {
			limit = { NOT = { has_modifier = wraith_frequency_sync } }
			# Adds the modifier when the right star class is present
			if = {
				limit = {
					has_ship_flag = wraith_freq_blue
					solar_system = {
						OR = {
							is_star_class = sc_b
							is_star_class = sc_a
						}
					}
				}
				add_modifier = { modifier = "wraith_frequency_sync" days = -1 }
			}
			if = {
				limit = {
					has_ship_flag = wraith_freq_yellow
					solar_system = {
						is_star_class = sc_g
					}
				}
				add_modifier = { modifier = "wraith_frequency_sync" days = -1 }
			}
			if = {
				limit = {
					has_ship_flag = wraith_freq_red
					solar_system = {
						is_star_class = sc_m
					}
				}
				add_modifier = { modifier = "wraith_frequency_sync" days = -1 }
			}
		}
	}
}

# Enigmatic Fortress Disabled (HIDDEN)
ship_event = {
	id = guardian.2100
	hide_window = yes
	
	is_triggered_only = yes

	trigger = {
		has_ship_flag = fortress_vault
		from.owner = { is_country_type = default }
	}

	immediate = {
		from.owner = { country_event = { id = guardian.2101 } }
	}
}

# Ship destroyed perp port
country_event = {
	id = guardian.2099
	title = "guardian.2101.name"
	desc = "guardian.2101.desc"
	picture = GFX_evt_enigmatic_fortress
	show_sound = event_space_battle
	location = fromfrom

	is_triggered_only = yes

	trigger = {
		exists = event_target:fortress_country
		from = { is_same_value = event_target:fortress_country }
		exists = event_target:fortress_vault_core
		event_target:fortress_country = {
			count_owned_ships = { # Check that all ships are disabled
				limit = { is_disabled = no }
				count < 1
			}
		}
	}

	immediate = {
		establish_communications_no_message = event_target:fortress_country
		#event_target:fortress_country = {
			event_target:fortress_vault_core = {
				#limit = { has_ship_flag = fortress_vault }
				save_global_event_target_as = disabled_enigmatic_fortress
			}
		#}
		every_playable_country = {
			limit = { has_event_chain = "enigmatic_fortress_chain" }
			end_event_chain = "enigmatic_fortress_chain"
		}
	}

	option = {
		name = "guardian.2101.a"
		begin_event_chain = {
			event_chain = "enigmatic_fortress_chain"
			target = root
		}
		hidden_effect = { country_event = { id = guardian.2111 } }
	}

	option = {
		name = "guardian.2101.b"
		hidden_effect = { country_event = { id = guardian.2160 days = 360 } }
	}

}

# The Enigmatic Fortress
country_event = {
	id = guardian.2101
	title = "guardian.2101.name"
	desc = "guardian.2101.desc"
	picture = GFX_evt_enigmatic_fortress
	show_sound = event_space_battle
	location = from
	
	is_triggered_only = yes

	trigger = {
		from.owner = { is_same_value = event_target:fortress_country }
		event_target:fortress_country = {
			count_owned_ships = { # Check that all ships are disabled
				limit = { is_disabled = no }
				count < 1
			}
		}
	}

	immediate = {
		establish_communications_no_message = event_target:fortress_country
		event_target:fortress_country = {
			random_owned_ship = {
				limit = { has_ship_flag = fortress_vault }
				save_global_event_target_as = disabled_enigmatic_fortress
			}
		}
	}

	option = {
		name = "guardian.2101.a"
		begin_event_chain = {
			event_chain = "enigmatic_fortress_chain"
			target = root
		}
		hidden_effect = { country_event = { id = guardian.2111 } }
	}

	option = {
		name = "guardian.2101.b"
		hidden_effect = { country_event = { id = guardian.2160 days = 360 } }
	}

}

# Entering System
ship_event = {
	id = guardian.2105
	title = "guardian.2105.name"
	desc = "guardian.2105.desc"
	picture = GFX_evt_enigmatic_fortress
	show_sound = event_ship_bridge
	location = FROM
	
	is_triggered_only = yes
	
	trigger = {
		FROM = {
			has_star_flag = guardians_fortress_system
			any_ship = { 
				AND = {
					is_ship_size = station_xl
					is_disabled = no
				}
			}
		}
		owner = {
			NOT = { has_country_flag = encountered_fortress }
			is_ai = no
		}
	}
	
	immediate = {
		FROM = { save_event_target_as = fortress_system }
		owner = { set_country_flag = encountered_fortress }
	}		
	
	option = {
		name = "guardian.2105.a"
	}
}

# Entering the Fortress
country_event = {
	id = guardian.2111
	title = "guardian.2111.name"
	desc = "guardian.2111.desc"
	picture = GFX_evt_enigmatic_fortress
	show_sound = event_mystic_reveal
	location = event_target:disabled_enigmatic_fortress
	
	is_triggered_only = yes

	option = {
		name = "guardian.2111.a"
		custom_tooltip = guardian.2111.a.tooltip
		hidden_effect = {
			event_target:disabled_enigmatic_fortress = {
				enable_special_project = {
					name = "ENIGMATIC_FORTRESS_1A"
					location = this
					owner = ROOT
				}
			}
			event_target:disabled_enigmatic_fortress = {
				enable_special_project = {
					name = "ENIGMATIC_FORTRESS_1B"
					location = this
					owner = ROOT
				}
			}
		}
	}
}

# Uncontrolled Demolition
ship_event = {
	id = guardian.2112
	title = "guardian.2112.name"
	desc = "guardian.2112.desc"
	picture = GFX_evt_enigmatic_fortress
	show_sound = event_ground_battle
	location = fromfrom
	
	is_triggered_only = yes
	
	option = {
		name = "guardian.2112.a"
		custom_tooltip = guardian.2112.a.tooltip
		hidden_effect = {
			owner = { country_event = { id = guardian.2131 days = 30 } }
			fleet = { destroy_fleet = this }
		}
	}
}

# Adjusting Energy Supply
ship_event = {
	id = guardian.2113
	title = "guardian.2113.name"
	desc = "guardian.2113.desc"
	picture = GFX_evt_enigmatic_fortress
	show_sound = event_laboratory_sound
	location = fromfrom
	
	is_triggered_only = yes
	
	option = {
		name = "guardian.2113.a"
		trigger = { owner = { energy > 500 } }
		owner = {
			add_energy = -500
			hidden_effect = { country_event = { id = guardian.2114 } }
		}
	}
	option = {
		name = "guardian.2113.b"
		owner = {
			add_energy = -50
			hidden_effect = { country_event = { id = guardian.2115 } }
		}
	}
}

# Fortress Repowers (Energy Surge)
country_event = {
	id = guardian.2114
	title = "guardian.2114.name"
	desc = "guardian.2114.desc"
	picture = GFX_evt_enigmatic_fortress
	show_sound = event_activating_unknown_technology
	location = event_target:disabled_enigmatic_fortress
	
	is_triggered_only = yes
	
	option = {
		name = "guardian.2114.a"
		hidden_effect = {
			event_target:disabled_enigmatic_fortress = {
				set_disabled = no
				repair_ship = yes
			}
		}
		end_event_chain = "enigmatic_fortress_chain"
	}
}

# Airlock Opened
country_event = {
	id = guardian.2115
	title = "guardian.2115.name"
	desc = "guardian.2115.desc"
	picture = GFX_evt_enigmatic_fortress
	show_sound = event_airlock
	location = event_target:disabled_enigmatic_fortress
	
	is_triggered_only = yes
	
	option = {
		name = "guardian.2115.a"
		custom_tooltip = guardian.2112.a.tooltip
		hidden_effect = { country_event = { id = guardian.2131 days = 30 } }
	}
}

# The Tower
country_event = {
	id = guardian.2131
	title = "guardian.2131.name"
	desc = "guardian.2131.desc"
	picture = GFX_evt_enigmatic_fortress
	show_sound = event_mystic_reveal
	location = event_target:disabled_enigmatic_fortress
	
	is_triggered_only = yes
	
	option = {
		name = "guardian.2131.a"
		hidden_effect = { country_event = { id = guardian.2132 } }
	}
	option = {
		name = "guardian.2131.b"
		hidden_effect = { country_event = { id = guardian.2132 } }
	}
	option = {
		name = "guardian.2131.c"
		hidden_effect = { country_event = { id = guardian.2133 } }
	}
	option = {
		name = "guardian.2131.d"
		hidden_effect = { country_event = { id = guardian.2132 } }
	}
}

# Disturbing Noises
country_event = {
	id = guardian.2132
	title = "guardian.2132.name"
	desc = "guardian.2132.desc"
	picture = GFX_evt_enigmatic_fortress
	show_sound = event_activating_unknown_technology
	location = event_target:disabled_enigmatic_fortress
	
	is_triggered_only = yes
	
	option = {
		name = "guardian.2132.a"
		hidden_effect = {
			event_target:disabled_enigmatic_fortress = {
				set_disabled = no
				repair_ship = yes
			}
		}
		end_event_chain = "enigmatic_fortress_chain"
	}
}

# Tower Rebuilt
country_event = {
	id = guardian.2133
	title = "guardian.2133.name"
	desc = "guardian.2133.desc"
	picture = GFX_evt_enigmatic_fortress
	show_sound = event_radio_chatter
	location = event_target:disabled_enigmatic_fortress
	
	is_triggered_only = yes
	
	option = {
		name = "guardian.2133.a"
		custom_tooltip = guardian.fortress.continue
		hidden_effect = {
			country_event = { id = guardian.2150 days = 30 }
		}
	}
}

# The Pivot
country_event = {
	id = guardian.2150
	title = "guardian.2150.name"
	desc = "guardian.2150.desc"
	picture = GFX_evt_enigmatic_fortress
	show_sound = event_mystic_reveal
	location = event_target:disabled_enigmatic_fortress
	
	is_triggered_only = yes

	option = {
		name = "guardian.2150.a"
		event_target:disabled_enigmatic_fortress = {
			solar_system = {
				random_system_planet = {
					limit = { is_star = yes }
					enable_special_project = {
						name = "ENIGMATIC_FORTRESS_5B"
						location = this
						owner = ROOT
					}
				}
			}
			if = {
				limit = {
					ROOT = {
						has_country_strategic_resource = {
							type = sr_dark_matter
							amount > 0
						}
					}
				}
				enable_special_project = {
					name = "ENIGMATIC_FORTRESS_5C"
					location = this
					owner = ROOT
				}
			}
			enable_special_project = {
				name = "ENIGMATIC_FORTRESS_5D"
				location = this
				owner = ROOT
			}
		}
		capital_scope = {
			closest_system = {
				limit = {
					has_access_fleet = ROOT
					has_planet_class = pc_black_hole
				}
				random_system_planet = {
					limit = { is_planet_class = pc_black_hole }
					enable_special_project = {
						name = "ENIGMATIC_FORTRESS_5A"
						location = this
						owner = ROOT
					}
				}
			}
		}
	}
}

# The Heart of Dark Matter
country_event = {
	id = guardian.2151
	title = "guardian.2151.name"
	desc = "guardian.2151.desc"
	picture = GFX_evt_enigmatic_fortress
	show_sound = event_laboratory_sound
	location = from
	
	is_triggered_only = yes

	immediate = {
		set_country_flag = fortress_solved
		event_target:disabled_enigmatic_fortress = {
			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_fortress
						event_chain = curator_poi_chain
						owner = prev
					}
				}
			}
			remove_point_of_interest = curator_poi_fortress
			end_curator_chain = yes
		}
		event_target:disabled_enigmatic_fortress = {
			solar_system = {
				random_system_planet = {
					limit = { is_star = yes }
					create_ambient_object = {
						type = "dead_enigmatic_fortress_object"
						location = solar_system
					}
					last_created_ambient_object = {
						save_global_event_target_as = fortress_ambient
						set_location = {
							target = PREV
							distance = 110
							angle = 110
						}
					}
				}

			}
			fleet = {
				delete_fleet = this
			}
		}
	}
	
	option = {
		name = "guardian.2151.a"
		add_monthly_resource_mult = {
			resource = engineering_research
			value = 24
			min = 2000
			max = 4000
		}
		add_monthly_resource_mult = {
			resource = physics_research
			value = 24
			min = 1600
			max = 3200
		}
		add_monthly_resource_mult = {
			resource = society_research
			value = 24
			min = 1000
			max = 2000
		}
		random_list = {
			15 = {
				add_research_option = tech_enigmatic_deflector
				add_tech_progress = {
					tech = tech_enigmatic_deflector
					progress = 0.30
				}
			}
			15 = {
				add_research_option = tech_enigmatic_power_core
				add_tech_progress = {
					tech = tech_enigmatic_power_core
					progress = 0.30
				}
			}
			30 = {
				add_research_option = tech_enigmatic_encoder
				add_tech_progress = {
					tech = tech_enigmatic_encoder
					progress = 0.30
				}
			}
			30 = {
				add_research_option = tech_enigmatic_decoder
				add_tech_progress = {
					tech = tech_enigmatic_decoder
					progress = 0.30
				}
			}
			#10 = {
			#	add_research_option = tech_enigmatic_disruption_field
			#	add_tech_progress = {
			#		tech = tech_enigmatic_disruption_field
			#		progress = 0.30
			#	}
			#}
		}
		end_event_chain = "enigmatic_fortress_chain"
	}
}

# Our Star Witness
country_event = {
	id = guardian.2152
	title = "guardian.2152.name"
	desc = "guardian.2152.desc"
	picture = GFX_evt_enigmatic_fortress
	show_sound = event_alien_signal
	location = event_target:disabled_enigmatic_fortress
	
	is_triggered_only = yes
	
	option = {
		name = "guardian.2152.a"
		hidden_effect = { country_event = { id = guardian.2153 } }
	}
	option = {
		name = "guardian.2152.b"
		hidden_effect = { country_event = { id = guardian.2154 } }
	}
	option = {
		name = "guardian.2152.c"
		hidden_effect = { country_event = { id = guardian.2155 } }
	}
}

# Fruitless Beginnings
country_event = {
	id = guardian.2153
	title = "guardian.2153.name"
	desc = "guardian.2153.desc"
	picture = GFX_evt_enigmatic_fortress
	show_sound = event_activating_unknown_technology
	location = event_target:disabled_enigmatic_fortress
	
	is_triggered_only = yes
	
	option = {
		name = "guardian.2153.a"
		end_event_chain = "enigmatic_fortress_chain"
		hidden_effect = {
			event_target:disabled_enigmatic_fortress = {
				set_disabled = no
				repair_ship = yes
			}
		}
	}
}

# The Middle Path
country_event = {
	id = guardian.2154
	title = "guardian.2154.name"
	desc = "guardian.2154.desc"
	picture = GFX_evt_enigmatic_fortress
	show_sound = event_laboratory_sound
	location = event_target:disabled_enigmatic_fortress
	
	is_triggered_only = yes

	immediate = {
		set_country_flag = fortress_solved
		event_target:disabled_enigmatic_fortress = {
			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_fortress
						event_chain = curator_poi_chain
						owner = prev
					}
				}
			}
			remove_point_of_interest = curator_poi_fortress
			end_curator_chain = yes
		}
		event_target:disabled_enigmatic_fortress = {
			solar_system = {
				random_system_planet = {
					limit = { is_star = yes }
					create_ambient_object = {
						type = "dead_enigmatic_fortress_object"
						location = solar_system
					}
					last_created_ambient_object = {
						save_global_event_target_as = fortress_ambient
						set_location = {
							target = PREV
							distance = 110
							angle = 110
						}
					}
					#create_ambient_object = {
					#	type = explosion_particle_object
					#	location = this
					#	use_3d_location = yes
					#	duration = 10
					#	scale = 20
					#}
					#last_created_ambient_object = {
					#	set_location = {
					#		target = PREV
					#		distance = 110
					#		angle = 110
					#	}
					#}
				}
			}
			fleet = {
				delete_fleet = this
			}
		}
	}
	
	option = {
		name = "guardian.2154.a"
		add_monthly_resource_mult = {
			resource = engineering_research
			value = 24
			min = 2000
			max = 4000
		}
		add_monthly_resource_mult = {
			resource = physics_research
			value = 24
			min = 1600
			max = 3200
		}
		add_monthly_resource_mult = {
			resource = society_research
			value = 24
			min = 1000
			max = 2000
		}
		random_list = {
			15 = {
				add_research_option = tech_enigmatic_deflector
				add_tech_progress = {
					tech = tech_enigmatic_deflector
					progress = 0.30
				}
			}
			15 = {
				add_research_option = tech_enigmatic_power_core
				add_tech_progress = {
					tech = tech_enigmatic_power_core
					progress = 0.30
				}
			}
			30 = {
				add_research_option = tech_enigmatic_encoder
				add_tech_progress = {
					tech = tech_enigmatic_encoder
					progress = 0.30
				}
			}
			30 = {
				add_research_option = tech_enigmatic_decoder
				add_tech_progress = {
					tech = tech_enigmatic_decoder
					progress = 0.30
				}
			}
		}
		end_event_chain = "enigmatic_fortress_chain"
	}
}

# The End
country_event = {
	id = guardian.2155
	title = "guardian.2155.name"
	desc = "guardian.2155.desc"
	picture = GFX_evt_enigmatic_fortress
	show_sound = event_activating_unknown_technology
	location = event_target:disabled_enigmatic_fortress
	
	is_triggered_only = yes
	
	option = {
		name = "guardian.2155.a"
		end_event_chain = "enigmatic_fortress_chain"
		hidden_effect = {
			event_target:disabled_enigmatic_fortress = {
				set_disabled = no
				repair_ship = yes
			}
		}
	}
}

# Dark Matter Gambit
country_event = {
	id = guardian.2156
	title = "guardian.2156.name"
	desc = "guardian.2156.desc"
	picture = GFX_evt_enigmatic_fortress
	show_sound = event_laboratory_sound
	location = event_target:disabled_enigmatic_fortress
	
	is_triggered_only = yes

	immediate = {
		set_country_flag = fortress_solved
		event_target:disabled_enigmatic_fortress = {
			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_fortress
						event_chain = curator_poi_chain
						owner = prev
					}
				}
			}
			remove_point_of_interest = curator_poi_fortress
			end_curator_chain = yes
		}
		event_target:disabled_enigmatic_fortress = {
			solar_system = {
				random_system_planet = {
					limit = { is_star = yes }
					create_ambient_object = {
						type = "dead_enigmatic_fortress_object"
						location = solar_system
					}
					last_created_ambient_object = {
						save_global_event_target_as = fortress_ambient
						set_location = {
							target = PREV
							distance = 110
							angle = 110
						}
					}
				}

			}
			fleet = {
				delete_fleet = this
			}
		}
	}
	
	option = {
		name = "guardian.2156.a"
		add_monthly_resource_mult = {
			resource = engineering_research
			value = 24
			min = 2000
			max = 4000
		}
		add_monthly_resource_mult = {
			resource = physics_research
			value = 24
			min = 1600
			max = 3200
		}
		add_monthly_resource_mult = {
			resource = society_research
			value = 24
			min = 1000
			max = 2000
		}
		random_list = {
			15 = {
				add_research_option = tech_enigmatic_deflector
				add_tech_progress = {
					tech = tech_enigmatic_deflector
					progress = 0.30
				}
			}
			15 = {
				add_research_option = tech_enigmatic_power_core
				add_tech_progress = {
					tech = tech_enigmatic_power_core
					progress = 0.30
				}
			}
			30 = {
				add_research_option = tech_enigmatic_encoder
				add_tech_progress = {
					tech = tech_enigmatic_encoder
					progress = 0.30
				}
			}
			30 = {
				add_research_option = tech_enigmatic_decoder
				add_tech_progress = {
					tech = tech_enigmatic_decoder
					progress = 0.30
				}
			}
		}
		end_event_chain = "enigmatic_fortress_chain"
	}
}

# Shot Through the Heart
country_event = {
	id = guardian.2157
	title = "guardian.2157.name"
	desc = "guardian.2157.desc"
	picture = GFX_evt_exploding_ship
	show_sound = event_super_explosion
	location = event_target:disabled_enigmatic_fortress
	
	is_triggered_only = yes

	immediate = {
		event_target:disabled_enigmatic_fortress = {
			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_fortress
						event_chain = curator_poi_chain
						owner = prev
					}
				}
			}
			remove_point_of_interest = curator_poi_fortress
			end_curator_chain = yes
		}
		event_target:disabled_enigmatic_fortress = {
			solar_system = {
				random_system_planet = {
					limit = { is_star = yes }
					create_ambient_object = {
						type = "large_debris_object" # Actually explosion
						location = solar_system
					}
					last_created_ambient_object = {
						save_global_event_target_as = fortress_ambient
						set_location = {
							target = PREV
							distance = 110
							angle = 110
						}
					}
				}

			}
			create_ambient_object = {
				type = explosion_particle_object
				location = this
				use_3d_location = yes
				duration = 10
				scale = 30
			}
			fleet = {
				delete_fleet = this
			}
		}
	}
	
	option = {
		name = "guardian.2157.a"
		custom_tooltip = guardian.2157.a.tooltip
		end_event_chain = "enigmatic_fortress_chain"
		hidden_effect = {
			event_target:disabled_enigmatic_fortress = {
				solar_system = {
					every_system_planet = {
						limit = {
							habitable_planet = yes
							NOR = {
								is_planet_class = pc_ringworld_habitable
								is_planet_class = pc_habitat
							}
						}
						create_ambient_object = {
							type = explosion_particle_object
							location = this
							use_3d_location = yes
							duration = 10
							scale = 20
						}
						change_pc = pc_nuked
					}
					every_system_planet = {
						limit = {
							habitable_planet = no
							is_asteroid = no
							is_star = no
							NOT = { is_planet_class = pc_gas_giant }
						}
						create_ambient_object = {
							type = explosion_particle_object
							location = this
							use_3d_location = yes
							duration = 10
							scale = 20
						}
						change_pc = pc_molten
					}
					every_fleet_in_system = { destroy_fleet = this }
				}
			}
		}
	}
}

# Fortress Repowers (Generic)
country_event = {
	id = guardian.2160
	title = "guardian.2160.name"
	desc = "guardian.2160.desc"
	picture = GFX_evt_enigmatic_fortress
	show_sound = event_activating_unknown_technology
	location = event_target:disabled_enigmatic_fortress
	
	is_triggered_only = yes
	
	option = {
		name = "guardian.2160.a"
		end_event_chain = "enigmatic_fortress_chain"
		hidden_effect = {
			event_target:disabled_enigmatic_fortress = {
				set_disabled = no
				repair_ship = yes
			}
		}
	}
}

# 3000 DIMENSIONAL HORROR

# Entering System
ship_event = {
	id = guardian.3000
	hide_window = yes
	
	is_triggered_only = yes
	
	trigger = {
		owner = {
			NOT = { has_country_flag = encountered_horror }
		}
		FROM = {
			has_star_flag = guardians_horror_system
			OR = {
				NOT = { has_star_flag = horror_spawned }
				any_ship = { is_ship_size = dimensional_horror }
			}
		}
	}
	
	immediate = {
		if = {
			limit = {
				solar_system = {
					NOT = { has_star_flag = horror_spawned }
				}
			}
			solar_system = {
				set_star_flag = horror_spawned
				save_event_target_as = horror_system
				random_system_planet = {
					limit = { is_planet_class = pc_black_hole }
					create_country = {
						name = "NAME_Dimensional_Horror"
						type = guardian_horror
						flag = {
							icon = {
								category = "zoological"
								file = "flag_zoological_3.dds"
							}
							background = {
								category = "backgrounds"
								file = "00_solid.dds"
							}
							colors={
								"red"
								"red"
								"null"
								"null"
							}
						}
					}
					last_created_country = {
						guardian_difficulty = yes
						save_global_event_target_as = dimensional_horror_country
						set_country_flag = dimensional_horror_country
						#ISB Balance
						country_event = { id = isb.5 days = 1 }
					}
					create_fleet = {
						name = "NAME_Dimensional_Horror"
						settings = {
							spawn_debris = no
							is_boss = yes
						}
						effect = {
							set_owner = event_target:dimensional_horror_country
							save_global_event_target_as = dimensional_horror
							create_ship = {
								name = "NAME_Dimensional_Horror"
								design = "NAME_Dimensional_Horror"
								effect = { set_disabled = yes }
							}
							set_location = {
								target = PREV
								distance = 100
								angle = random
							}
						}
					}
					last_created_fleet = {
						create_ambient_object = {
							type = "horror_spawn_object"
							location = THIS
							use_3d_location = yes
							duration = 10
						}
						fleet_event = { id = guardian.3220 days = 8 }
					}
				}
			}
		}
		owner = { 
			set_country_flag = encountered_horror
			establish_communications_no_message = event_target:dimensional_horror_country
			country_event = { id = guardian.3001 }
		}
	}
}

# Entering System
country_event = {
	id = guardian.3001
	title = "guardian.3001"
	desc = "guardian.3001.desc"
	picture = GFX_evt_dimensional_horror
	show_sound = event_activating_unknown_technology
	location = event_target:horror_system
	
	is_triggered_only = yes
	
	option = {
		name = "guardian.3001.a"
	}
}

# Horror Destroyed (HIDDEN)
country_event = {
	id = guardian.3002
	hide_window = yes
	
	fire_only_once = yes
	is_triggered_only = yes
	
	trigger = {
		is_country_type = guardian_horror
		has_country_flag = dimensional_horror_country
		FROMFROM = { is_ship_size = dimensional_horror }
	}
	
	immediate = {
		FROMFROM = {
			solar_system = { save_event_target_as = guardians_horror_system }
		}
		create_ambient_object = {
			type = "horror_energy_object"
			location = FROMFROM
		}
		last_created_ambient_object = { 
			save_event_target_as = horror_energy
			set_ambient_object_flag = horror_energy
		}
		FROM = {
			country_event = { id = guardian.3003 days = 6 }
		}
		destroy_country = yes
		every_country = {
			limit = { 
				is_country_type = default
				has_modifier = dimensional_horror_weak_points
			}
			remove_modifier = "dimensional_horror_weak_points"
		}
		every_country = {
			limit = {
				is_country_type = default
				has_event_chain = curator_poi_chain
				event_target:guardians_horror_system = {
					is_point_of_interest = {
						id = curator_poi_horror
						event_chain = curator_poi_chain
						owner = prev
					}
				}
			}
			remove_point_of_interest = curator_poi_horror
			end_curator_chain = yes
		}
	}
}

# Horror Destroyed
country_event = {
	id = guardian.3003
	title = "guardian.3003"
	desc = "guardian.3003.desc"
	picture = GFX_evt_dimensional_horror
	show_sound = event_super_explosion
	location = event_target:guardians_horror_system
	
	is_triggered_only = yes

	immediate = { set_country_flag = horror_killed }
	
	option = {
		name = "guardian.3003.a"
		event_target:horror_energy = {
			enable_special_project = {
				name = "DIMENSIONAL_HORROR_PROJECT"
				location = THIS
				owner = ROOT
			}
		}
	}
}

# Special Project Completed
ship_event = {
	id = guardian.3004
	title = "PROJECT_COMPLETE"
	picture = GFX_evt_dimensional_horror
	show_sound = event_laboratory_sound
	
	desc = {
		text = "guardian.3004a.desc"
		trigger = {
			owner = {
				NOT = { 
					has_technology = tech_jump_drive_1
					has_technology = tech_psi_jump_drive_1
				}
			}
		}
	}
	desc = {
		text = "guardian.3004b.desc"
		trigger = {
			owner = {
				OR = {
					has_technology = tech_jump_drive_1
					has_technology = tech_psi_jump_drive_1
				}
			}
		}
	}
	
	is_triggered_only = yes
	
	immediate = {
		random_ambient_object = {
			limit = { has_ambient_object_flag = horror_energy }
			destroy_ambient_object = this
		}
	}
	
	option = {
		name = "EXCELLENT"
		trigger = {
			owner = {
				NOT = { 
					has_technology = tech_jump_drive_1
					has_technology = tech_psi_jump_drive_1
				}
			}
		}
		owner = {
			add_research_option = tech_jump_drive_1
			add_tech_progress = {
				tech = tech_jump_drive_1
				progress = 0.5
			}
			add_monthly_resource_mult = {
				resource = physics_research
				value = 24
				min = 4000
				max = 6000
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = 24
				min = 4000
				max = 6000
			}
		}
	}
	option = {
		name = "EXCELLENT"
		trigger = {
			owner = {
				OR = {
					has_technology = tech_jump_drive_1
					has_technology = tech_psi_jump_drive_1
				}
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = physics_research
				value = 24
				min = 4000
				max = 6000
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = 24
				min = 4000
				max = 6000
			}
		}
	}
}

# 3100 AUTOMATED DREADNOUGHT

# Entering System
ship_event = {
	id = guardian.3100
	title = "guardian.3100"
	desc = "guardian.3100.desc"
	picture = GFX_evt_automated_dreadnought
	show_sound = event_radio_chatter
	location = FROM
	
	is_triggered_only = yes
	
	trigger = {
		owner = {
			NOT = { has_country_flag = encountered_dreadnought }
		}
		FROM = {
			has_star_flag = guardians_dreadnought_system
			any_ship = { 
				AND = {
					is_ship_size = npc_warship_01
					owner = { is_country_type = guardian_dreadnought }
				}
			}
		}
	}
	
	immediate = {
		FROM = { save_event_target_as = dreadnought_system }
		owner = { 
			set_country_flag = encountered_dreadnought
		}
	}		
	
	option = {
		name = "guardian.3100.a"
	}
}

# Dreadnought Disabled (HIDDEN)
country_event = {
	id = guardian.3101
	hide_window = yes
	
	fire_only_once = yes
	is_triggered_only = yes
	
	trigger = {
		is_country_type = guardian_dreadnought
		has_country_flag = automated_dreadnought_country
		FROMFROM = { is_ship_size = npc_warship_01 }
		FROM = { is_ai = no }
	}
	
	immediate = {
		FROMFROM = {
			solar_system = { save_event_target_as = guardians_dreadnought_system }
			create_ambient_object = {
				type = "dreadnought_object"
				location = THIS
			}
			last_created_ambient_object = { save_global_event_target_as = disabled_dreadnought_object }
			create_ambient_object = {
				type = "large_debris_object"
				location = THIS
			}
			last_created_ambient_object = { set_ambient_object_flag = dreadnought_debris }
		}
		FROM = {
			country_event = { id = guardian.3102 }
		}
		destroy_country = yes
		every_country = {
			limit = { 
				is_country_type = default
				has_modifier = automated_dreadnought_weak_points
			}
			remove_modifier = "automated_dreadnought_weak_points"
		}
		every_country = {
			limit = {
				is_country_type = default
				has_event_chain = curator_poi_chain
				event_target:guardians_dreadnought_system = {
					is_point_of_interest = {
						id = curator_poi_dreadnought
						event_chain = curator_poi_chain
						owner = prev
					}
				}
			}
			remove_point_of_interest = curator_poi_dreadnought
			end_curator_chain = yes
		}
	}
}

# Dreadnought Disabled
country_event = {
	id = guardian.3102
	title = "guardian.3102"
	desc = "guardian.3102.desc"
	picture = GFX_evt_automated_dreadnought
	show_sound = event_ship_bridge
	location = event_target:guardians_dreadnought_system
	
	is_triggered_only = yes
	
	option = {
		name = "guardian.3102.a"
		event_target:disabled_dreadnought_object = {
			enable_special_project = {
				name = "DISABLED_DREADNOUGHT_PROJECT"
				location = THIS
				owner = ROOT
			}
		}
	}
	option = {
		name = "guardian.3102.b"
		add_minerals = 5000
		add_energy = 5000
		add_monthly_resource_mult = {
			resource = engineering_research
			value = 30
			min = 200
			max = 1000
		}
	}
}

# Dreadnought Rebuilt
ship_event = {
	id = guardian.3103
	title = "guardian.3103"
	desc = "guardian.3103.desc"
	picture = GFX_evt_automated_dreadnought
	show_sound = event_construction
	location = event_target:guardians_dreadnought_system
	
	is_triggered_only = yes
	
	immediate = {
		owner = {
			save_event_target_as = project_owner
			set_country_flag = restored_dreadnought
		}
	}
	
	option = {
		name = "guardian.3103.a"
		
		# Psi Jump Dreadnought if owner has it
		if = {
			limit = {
				owner = { has_technology = "tech_psi_jump_drive_1" }
			}
			create_fleet = {
				name = "NAME_Dreadnought"
				effect = {
					set_owner = event_target:project_owner
					create_ship = {
						name = random
						design = "NAME_Type_37" # Psi Jump Dreadnought
						graphical_culture = "npf_01"
						upgradable = no
					}
					set_location = {
						target = event_target:disabled_dreadnought_object
						distance = 0
						angle = random
					}
				}
			}
			hidden_effect = {
				event_target:disabled_dreadnought_object = { destroy_ambient_object = this }
				solar_system = {
					random_system_ambient_object = {
						limit = { has_ambient_object_flag = dreadnought_debris }
						destroy_ambient_object = this
					}
				}
			}
			break = yes
		}
		# Jump Dreadnought if owner has it
		if = {
			limit = {
				owner = { has_technology = "tech_jump_drive_1" }
			}
			create_fleet = {
				name = "NAME_Dreadnought"
				effect = {
					set_owner = event_target:project_owner
					create_ship = {
						name = random
						design = "NAME_Type_46" # Jump Dreadnought
						graphical_culture = "npf_01"
						upgradable = no
					}
					set_location = {
						target = event_target:disabled_dreadnought_object
						distance = 0
						angle = random
					}
				}
			}
			hidden_effect = {
				event_target:disabled_dreadnought_object = { destroy_ambient_object = this }
				solar_system = {
					random_system_ambient_object = {
						limit = { has_ambient_object_flag = dreadnought_debris }
						destroy_ambient_object = this
					}
				}
			}
			break = yes
		}
		# Warp Dreadnought if owner has it
		if = {
			limit = {
				owner = { 
					OR = {
						has_technology = "tech_warp_drive_1"
						has_technology = "tech_warp_drive_2"
						has_technology = "tech_warp_drive_3"
					}
				}
			}
			create_fleet = {
				name = "NAME_Dreadnought"
				effect = {
					set_owner = event_target:project_owner
					create_ship = {
						name = random
						design = "NAME_Type_14" # Warp Dreadnought
						graphical_culture = "npf_01"
						upgradable = no
					}
					set_location = {
						target = event_target:disabled_dreadnought_object
						distance = 0
						angle = random
					}
				}
			}
			hidden_effect = {
				event_target:disabled_dreadnought_object = { destroy_ambient_object = this }
				solar_system = {
					random_system_ambient_object = {
						limit = { has_ambient_object_flag = dreadnought_debris }
						destroy_ambient_object = this
					}
				}
			}
			break = yes
		}
		# Hyper Dreadnought if owner has it
		if = {
			limit = {
				owner = { 
					OR = {
						has_technology = "tech_hyper_drive_1"
						has_technology = "tech_hyper_drive_2"
						has_technology = "tech_hyper_drive_3"
					}
				}
			}
			create_fleet = {
				name = "NAME_Dreadnought"
				effect = {
					set_owner = event_target:project_owner
					create_ship = {
						name = random
						design = "NAME_Type_92" # Hyper Dreadnought
						graphical_culture = "npf_01"
						upgradable = no
					}
					set_location = {
						target = event_target:disabled_dreadnought_object
						distance = 0
						angle = random
					}
				}
			}
			hidden_effect = {
				event_target:disabled_dreadnought_object = { destroy_ambient_object = this }
				solar_system = {
					random_system_ambient_object = {
						limit = { has_ambient_object_flag = dreadnought_debris }
						destroy_ambient_object = this
					}
				}
			}
			break = yes
		}
		# Wormhole Dreadnought if owner has it
		if = {
			limit = {
				owner = { 
					OR = {
						has_technology = "tech_wormhole_generation_1"
						has_technology = "tech_wormhole_generation_2"
						has_technology = "tech_wormhole_generation_3"
					}
				}
			}
			create_fleet = {
				name = "NAME_Dreadnought"
				effect = {
					set_owner = event_target:project_owner
					create_ship = {
						name = random
						design = "NAME_Type_69" # Wormhole Dreadnought
						graphical_culture = "npf_01"
						upgradable = no
					}
					set_location = {
						target = event_target:disabled_dreadnought_object
						distance = 0
						angle = random
					}
				}
			}
			hidden_effect = {
				event_target:disabled_dreadnought_object = { destroy_ambient_object = this }
				solar_system = {
					random_system_ambient_object = {
						limit = { has_ambient_object_flag = dreadnought_debris }
						destroy_ambient_object = this
					}
				}
			}
			break = yes
		}
	}
}

# 3200 HIVE ASTEROID

# Built Hive Mine (HIDDEN)
ship_event = {
	id = guardian.3200
	hide_window = yes
	
	is_triggered_only = yes
	
	trigger = {
		FROM = {
			is_planet_class = pc_crystal_asteroid
		}
	}
	
	immediate = {
		owner = {
			set_country_flag = built_hiver_mine
		}
	}
}

# Hivers Appear (HIDDEN)
country_event = {
	id = guardian.3210
	hide_window = yes
	
	fire_only_once = yes
	
	trigger = {
		is_country_type = default
		has_country_flag = built_hiver_mine
		any_planet_within_border = {
			OR = {
				has_planet_flag = hiver_asteroid_1
				has_planet_flag = hiver_asteroid_2
				has_planet_flag = hiver_asteroid_3
				has_planet_flag = hiver_asteroid_4
				has_planet_flag = hiver_asteroid_5
			}
			has_mining_station = yes
		}	
	}
	
	mean_time_to_happen = {
		years = 100
		
		modifier = {
			factor = 0.3
			any_planet_within_border = {
				has_mining_station = yes
				has_planet_flag = hiver_asteroid_1
			}
		}
		modifier = {
			factor = 0.3
			any_planet_within_border = {
				has_mining_station = yes
				has_planet_flag = hiver_asteroid_2
			}
		}
		modifier = {
			factor = 0.3
			any_planet_within_border = {
				has_mining_station = yes
				has_planet_flag = hiver_asteroid_3
			}
		}
		modifier = {
			factor = 0.3
			any_planet_within_border = {
				has_mining_station = yes
				has_planet_flag = hiver_asteroid_4
			}
		}
		modifier = {
			factor = 0.3
			any_planet_within_border = {
				has_mining_station = yes
				has_planet_flag = hiver_asteroid_5
			}
		}
	}
	
	immediate = {
		random_system = {
			limit = { has_star_flag = guardians_hive_system }
			save_event_target_as = hiver_system
		}
		country_event = { id = guardian.3201 }
		set_global_flag = hivers_appeared
	}
}

# Hivers Appear
country_event = {
	id = guardian.3201
	title = "guardian.3201"
	desc = "guardian.3201.desc"
	picture = GFX_evt_hive
	show_sound = event_red_alert
	location = event_target:hiver_system
	
	is_triggered_only = yes
	
	immediate = {
		event_target:hiver_system = {
			random_system_ambient_object = {
				limit = { has_ambient_object_flag = hive_asteroid_1 }
				save_event_target_as = ambient_hive_1
			}
			random_system_ambient_object = {
				limit = { has_ambient_object_flag = hive_asteroid_2 }
				save_event_target_as = ambient_hive_2
			}
			random_system_ambient_object = {
				limit = { has_ambient_object_flag = hive_asteroid_3 }
				save_event_target_as = ambient_hive_3
			}
			random_system_ambient_object = {
				limit = { has_ambient_object_flag = hive_asteroid_4 }
				save_event_target_as = ambient_hive_4
			}
			random_system_ambient_object = {
				limit = { has_ambient_object_flag = hive_asteroid_5 }
				save_event_target_as = ambient_hive_5
			}
			random_system_ambient_object = {
				limit = { has_ambient_object_flag = hive_asteroid_6 }
				save_event_target_as = ambient_hive_6
			}
		}
		create_country = {
			name = "NAME_Alien_Hive"
			type = guardian_hiver
			flag = {
				icon = {
					category = "spherical"
					file = "flag_spherical_6.dds"
				}
				background= {
					category = "backgrounds"
					file = "00_solid.dds"
				}
				colors={
					"red"
					"red"
					"null"
					"null"
				}
			}
		}
		last_created_country = {
			save_global_event_target_as = hive_country
			set_country_flag = hive_country
			#ISB Balance
			country_event = { id = isb.5 days = 1 }
		}
		create_fleet = {
			name = "NAME_Hiver_Nest"
			settings = { spawn_debris = no }
			effect = {
				set_owner = event_target:hive_country
				create_ship = {
					name = "NAME_Hiver_Nest"
					design = "NAME_Hive_Asteroid"
				}
				set_location = event_target:ambient_hive_1			
			}
		}
		event_target:ambient_hive_1 = { destroy_ambient_object = this }
		create_fleet = {
			name = "NAME_Hiver_Nest"
			settings = { spawn_debris = no }
			effect = {
				set_owner = event_target:hive_country
				create_ship = {
					name = "NAME_Hiver_Nest"
					design = "NAME_Hive_Asteroid"
				}
				set_location = event_target:ambient_hive_2	
			}
		}
		event_target:ambient_hive_2 = { destroy_ambient_object = this }
		create_fleet = {
			name = "NAME_Hiver_Nest"
			settings = { spawn_debris = no }
			effect = {
				set_owner = event_target:hive_country
				create_ship = {
					name = "NAME_Hiver_Nest"
					design = "NAME_Hive_Asteroid"
				}
				set_location = event_target:ambient_hive_3	
			}
		}
		event_target:ambient_hive_3 = { destroy_ambient_object = this }
		create_fleet = {
			name = "NAME_Hiver_Nest"
			settings = { spawn_debris = no }
			effect = {
				set_owner = event_target:hive_country
				create_ship = {
					name = "NAME_Hiver_Nest"
					design = "NAME_Hive_Asteroid"
				}
				set_location = event_target:ambient_hive_4		
			}
		}
		event_target:ambient_hive_4 = { destroy_ambient_object = this }
		create_fleet = {
			name = "NAME_Hiver_Nest"
			settings = { spawn_debris = no }
			effect = {
				set_owner = event_target:hive_country
				create_ship = {
					name = "NAME_Hiver_Nest"
					design = "NAME_Hive_Asteroid"
				}
				set_location = event_target:ambient_hive_5	
			}
		}
		event_target:ambient_hive_5 = { destroy_ambient_object = this }
		create_fleet = {
			name = "NAME_Hiver_Nest"
			settings = { spawn_debris = no }
			effect = {
				set_owner = event_target:hive_country
				create_ship = {
					name = "NAME_Hiver_Nest"
					design = "NAME_Hive_Asteroid"
				}
				set_location = event_target:ambient_hive_6
			}
		}
		event_target:ambient_hive_6 = { destroy_ambient_object = this }
		set_country_flag = provoked_hivers
	}
	
	option = {
		name = "guardian.3201.a"
	}
}

# Entering System
ship_event = {
	id = guardian.3202
	title = "guardian.3202"
	desc = "guardian.3202.desc"
	picture = GFX_evt_hive
	show_sound = event_ship_bridge
	location = FROM
	
	is_triggered_only = yes
	
	trigger = {
		NOT = { has_global_flag = hivers_appeared }
		owner = {
			NOT = { has_country_flag = encountered_hivers }
			is_ai = no
		}
		FROM = {
			has_star_flag = guardians_hive_system
			NOT = { has_star_flag = hivers_defeated }
		}
	}
	
	immediate = {
		FROM = { save_event_target_as = hiver_system }
		owner = { 
			set_country_flag = encountered_hivers
		}
	}		
	
	option = {
		name = "guardian.3202.a"
	}
}

# Hivers Destroyed (HIDDEN)
country_event = {
	id = guardian.3203
	hide_window = yes
	
	fire_only_once = yes
	is_triggered_only = yes
	
	trigger = {
		is_country_type = guardian_hiver
		has_country_flag = hive_country
		count_owned_ships = {
			limit = { is_ship_size = hive_asteroid }
			count < 2 # The asteroid just destroyed counts as alive apparently
		}
		FROM = { 
			has_country_flag = provoked_hivers 
			is_ai = no
		}
	}
	
	immediate = {
		random_system = {
			limit = { has_star_flag = guardians_hive_system }
			save_event_target_as = hive_system
			set_star_flag = hivers_defeated
		}
		create_ambient_object = {
			type = "dormant_hive_base_2_object"
		}
		last_created_ambient_object = {
			set_location = FROMFROM
			set_ambient_object_flag = boardable_hive_asteroid
			save_event_target_as = boardable_hive_asteroid
		}
		FROM = {
			country_event = { id = guardian.3204 }
		}
		every_country = {
			limit = { 
				is_country_type = default
				has_modifier = asteroid_hive_weak_points
			}
			remove_modifier = "asteroid_hive_weak_points"
		}
		every_country = {
			limit = {
				is_country_type = default
				has_event_chain = curator_poi_chain
				event_target:hive_system = {
					is_point_of_interest = {
						id = curator_poi_hiver
						event_chain = curator_poi_chain
						owner = prev
					}
				}
			}
			remove_point_of_interest = curator_poi_hiver
			end_curator_chain = yes
		}
	}
}

# Hivers Destroyed
country_event = {
	id = guardian.3204
	title = "guardian.3204"
	desc = "guardian.3204.desc"
	picture = GFX_evt_hive
	show_sound = event_scanner
	location = event_target:hive_system
	
	is_triggered_only = yes
	
	option = {
		name = "guardian.3204.a"
		event_target:boardable_hive_asteroid = {
			enable_special_project = {
				name = "HIVE_ASTEROID_PROJECT"
				location = THIS
				owner = ROOT
			}
		}
	}
}

# Special Project Completed
ship_event = {
	id = guardian.3205
	title = "PROJECT_COMPLETE"
	desc = "guardian.3205.desc"
	picture = GFX_evt_hive
	show_sound = event_airlock
	location = event_target:boardable_hive_asteroid
	
	is_triggered_only = yes
	
	option = {
		name = "EXCELLENT"
		owner = {
			add_society_research = 2000
			add_energy = 500
		}
		hidden_effect = {
			random_ambient_object = {
				limit = { has_ambient_object_flag = boardable_hive_asteroid }
				destroy_ambient_object = this
			}
		}
	}
}

# Undisable Horror
fleet_event = {
	id = guardian.3220
	hide_window = yes

	is_triggered_only = yes
	
	immediate = {
		owner = {
			random_owned_ship = {
				set_disabled = no
			}
		}
	}
}