#########################################
#
# Pre-FTL Situation Events
#
# Written by Byron Aytoun
#
#########################################

namespace = preftl

# Technological Progression
country_event = {
	id = preftl.0
	hide_window = yes

	trigger = {
		is_country_type = primitive
	}

	is_triggered_only = yes

	immediate = {
		switch = {
			trigger = has_pre_ftl_age
			stone_age = {
				country_event = {
					id = preftl.199
				}
			}
			bronze_age = {
				country_event = {
					id = preftl.299
				}
			}
			iron_age = {
				country_event = {
					id = preftl.399
				}
			}
			late_medieval_age = {
				country_event = {
					id = preftl.499
				}
			}
			renaissance_age = {
				country_event = {
					id = preftl.599
				}
			}
			steam_age = {
				country_event = {
					id = preftl.699
				}
			}
			industrial_age = {
				country_event = {
					id = preftl.799
				}
			}
			machine_age = {
				country_event = {
					id = preftl.899
				}
			}
			atomic_age = {
				country_event = {
					id = preftl.999
				}
			}
			early_space_age = {
				country_event = {
					id = preftl.1099
				}
			}
		}
		fire_on_action = {
			on_action = on_ftl_society_enters_new_age
		}
	}
}

# Technological progress & setback gatekeeper
situation_event = {
	id = preftl.5
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		NOR = {
			has_situation_flag = technological_breakthrough
			has_situation_flag = technological_setback
		}
	}

	immediate = {
		random_list = {
			90 = { } # 90% chance for nothing, 5% chance for progress or setback.
			5 = {
				situation_event = { id = preftl.10 }	# Technological progress
			}
			5 = {
				situation_event = { id = preftl.15 }	# Technological setback
			}
		}
	}
}

# Technological progress - How much?
situation_event = {
	id = preftl.10
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		NOR = {
			has_situation_flag = technological_breakthrough
			has_situation_flag = technological_setback
		}
	}

	immediate = {
		random_list = {
			33 = {
				set_timed_situation_flag = {
					flag = technological_breakthrough
					months = 12
				}
			}
			33 = {
				set_timed_situation_flag = {
					flag = technological_breakthrough
					months = 6
				}
			}
			33 = {
				set_timed_situation_flag = {
					flag = technological_breakthrough
					months = 3
				}
			}
		}
	}
}

# Technological Setback - How much?
situation_event = {
	id = preftl.15
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		situation_progress >= 100
		NOR = {
			has_situation_flag = technological_breakthrough
			has_situation_flag = technological_setback
		}
	}

	immediate = {
		random_list = {
			33 = {
				set_timed_situation_flag = {
					flag = technological_setback
					months = 12
				}
			}
			33 = {
				set_timed_situation_flag = {
					flag = technological_setback
					months = 6
				}
			}
			33 = {
				set_timed_situation_flag = {
					flag = technological_setback
					months = 3
				}
			}
		}
	}
}

## Societal Guidance gatekeeper
# Checks if pops are shifting ethics, with a chance of shifting the entire government's ethics
situation_event = {
	id = preftl.20
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		owner = {
			is_country_type = primitive
			# check if it's under Societal Guidance or has been the target of an espionage op
			OR = {
				has_country_flag = preftl_societal_enlightenment_pact
				has_country_flag = preftl_espionage_operation_recent_shift_ethic_target
			}
			capital_scope = {
				pop_ethics_divergence > 0.25
			}
		}
	}

	immediate = {
		owner = {
			fire_on_action = { on_action = on_pre_ftl_pop_ethic_shift }
		}
	}
}

country_event = {
	id = preftl.30
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_primitive = yes
		NOT = {
			any_situation = {
				is_situation_type = pre_ftl_tech_progress_situation
			}
		}
	}

	immediate = {
		add_tech_progress_situation = yes
	}
}

# Sets flag to delay observation events, and establish diplo communications if they have max awareness
# This = construction ship or observation station
# From = planet it is built on
ship_event = {
	id = preftl.40
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = from.owner
		from.owner = {
			any_situation = {
				is_situation_type = pre_ftl_tech_progress_situation
				NOT = {
					has_situation_flag = had_recent_observation_event
				}
			}
		}
	}

	immediate = {
		set_variable = {
			which = observation_event_delay
			value = 0
		}
		set_variable_to_random_value = {
			which = observation_event_delay
			min = 900 # Two years
			max = 1800 # Five years
			rounded = yes
		}
		from.owner = {
			random_situation = {
				limit = {
					is_situation_type = pre_ftl_tech_progress_situation
				}
				set_timed_situation_flag = {
					flag = had_recent_observation_event
					days = root.observation_event_delay
				}
			}
		}
		clear_variable = observation_event_delay
	}
}

# Establish communications if civilization has full awareness
# This = construction ship or observation station
# From = planet it is built on
ship_event = {
	id = preftl.41
	hide_window = yes
	is_triggered_only = yes

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

	immediate = {
		from.owner = {
			save_event_target_as = contact_empire
		}
		if = {
			limit = {
				from.owner = {
					OR = {
						has_country_flag = reached_full_awareness_once
						current_awareness_level = full
					}
				}
			}
			owner = {
				country_event = { id = awareness.920 }
			}
		}
	}
}

# owner = pre-FTL country
situation_event = {
	id = preftl.50
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOR = {
			has_situation_flag = had_recent_observation_event
			has_situation_flag = has_ongoing_observation_event_chain
			owner = {
				OR = {
					has_origin = origin_fear_of_the_dark
					has_country_flag = solarpunk_country
					capital_scope = {
						has_carrier_flag = has_on_going_observation_situation
					}
				}
			}
		}
	}

	immediate = {
		set_timed_situation_flag = {
			flag = had_recent_observation_event
			days = 1800
		}
		# Event target workaround as 'observation_outpost_owner' is not supported by dynamic scope tags (@ID)
		if = {
			limit = {
				owner = {
					capital_scope = {
						has_observation_outpost = yes
						exists = observation_outpost_owner
					}
				}
			}
			owner.capital_scope.observation_outpost_owner = {
				save_event_target_as = observing_country
			}
		}
		# Prevent some Observation situation events from firing for "Broken Shackles" empires observing their original species
		if = {
			limit = {
				exists = event_target:observing_country
				owner = {
					NOT = {
						is_broken_shackles_pre_ftl_to_scope = { SCOPE = event_target:observing_country }
					}
				}
			}
			fire_on_action = {
				on_action = on_monthly_pulse_pre_ftl_observation
			}
		}
		else = {
			fire_on_action = {
				on_action = on_monthly_pulse_pre_ftl_observation_broken_shackles
			}
		}
	}
}

country_event = {
	id = preftl.55
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		last_changed_policy = interference
		OR = {
			has_policy_flag = interference_not_allowed
			has_policy_flag = interference_subtle
			has_policy_flag = interference_aggressive
		}
	}

	immediate = {
		if = {
			limit = {
				OR = {
					has_policy_flag = interference_not_allowed
					has_policy_flag = interference_aggressive
				}
			}
			every_pre_ftl_within_border = {
				limit = {
					has_awareness = 100
				}
				clear_relations = {
					target = root
					relations = {
						is_under_societal_enlightenment
						is_under_open_technological_enlightenment
						has_pre_ftl_trade
					}
				}
				remove_country_flag = preftl_societal_enlightenment_pact
				remove_country_flag = preftl_societal_enlightenment_pact_with@root
				remove_country_flag = open_technological_enlightenment_pact
				remove_country_flag = started_enlightening_from_ancient_era
				capital_scope.observation_outpost? = {
					remove_modifier = preftl_action_trade_pact
				}
			}
			every_envoy = {
				limit = {
					OR = {
						has_envoy_task = {
							task = improve_relations
						}
						has_envoy_task = {
							task = harm_relations
						}
					}
					exists = envoy_location_country
					envoy_location_country = {
						is_primitive = yes
					}
				}
				unassign_leader = this
			}
		}
		else = {
			every_pre_ftl_within_border = {
				limit = {
					has_awareness = 100
				}
				clear_relations = {
					target = root
					relations = {
						is_under_open_technological_enlightenment
					}
				}
				remove_country_flag = open_technological_enlightenment_pact
				remove_country_flag = started_enlightening_from_ancient_era
			}
		}
		if = {
			limit = {
				has_policy_flag = interference_not_allowed
			}
			every_envoy = {
				limit = {
					has_envoy_task = {
						task = spy_network
					}
					exists = envoy_location_country
					envoy_location_country = {
						is_primitive = yes
					}
				}
				unassign_leader = this
			}
		}
	}
}

country_event = {
	id = preftl.60
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		last_changed_policy = enlightenment
		OR = {
			has_policy_flag = enlightenment_covert_only
			has_policy_flag = enlightenment_not_allowed
		}
	}

	immediate = {
		every_pre_ftl_within_border = {
			limit = {
				has_awareness = 100
			}
			clear_relations = {
				target = root
				relations = {
					is_under_societal_enlightenment
					is_under_open_technological_enlightenment
					has_pre_ftl_trade
				}
			}
			remove_country_flag = preftl_societal_enlightenment_pact
			remove_country_flag = preftl_societal_enlightenment_pact_with@root
			remove_country_flag = open_technological_enlightenment_pact
			remove_country_flag = started_enlightening_from_ancient_era
			capital_scope.observation_outpost? = {
				remove_modifier = preftl_action_trade_pact
			}
		}
	}
}

#########################################
#
# Events concerning Primitive Aliens
# Written by Henrik Thyrwall
# Refactored by Byron Aytoun
#
#########################################

# Stone Age Events
# Reserving preftl.100 - 199

# Stone Age -> Bronze Age (HIDDEN)
country_event = {
	id = preftl.199
	hide_window = yes

	trigger = {
		is_country_type = primitive
		has_country_flag = stone_age
	}

	is_triggered_only = yes

	immediate = {
		set_pre_ftl_age_effect = { PRE_FTL_AGE = bronze_age }
		increase_pre_ftl_pops_by_age_effect = { PRE_FTL_AGE = bronze_age }
		capital_scope = {
			if = {
				limit = {
					exists = observation_outpost_owner
					observation_outpost_owner = {
						is_country_type = default
					}
				}
				observation_outpost_owner = {
					country_event = { id = preftl.200 }
				}
			}
		}
	}
}

# Bronze Age Events
# Reserving preftl.200 - preftl.299

# Bronze Age Observation Event
country_event = {
	id = preftl.200
	title = "preftl.200.name"
	desc = {
		trigger = {
			from.owner = {
				is_gestalt = no
			}
		}
		text = preftl.200.desc.normal
	}
	desc = {
		trigger = {
			from.owner = {
				is_gestalt = yes
			}
		}
		text = preftl.200.desc.gestalt
	}
	picture = GFX_evt_alien_cavemen
	location = FROM

	is_triggered_only = yes

	option = {
		name = preftl.200.a
	}
}

# Bronze Age -> Iron Age (HIDDEN)
country_event = {
	id = preftl.299
	hide_window = yes

	trigger = {
		is_country_type = primitive
		has_country_flag = bronze_age
	}

	is_triggered_only = yes

	immediate = {
		set_pre_ftl_age_effect = { PRE_FTL_AGE = iron_age }
		increase_pre_ftl_pops_by_age_effect = { PRE_FTL_AGE = iron_age }
		capital_scope = {
			if = {
				limit = {
					exists = observation_outpost_owner
					observation_outpost_owner = {
						is_country_type = default
					}
				}
				observation_outpost_owner = {
					country_event = { id = preftl.300 }
				}
			}
		}
	}
}

# Iron Age Events
# Reserving preftl.300 - preftl.399

# Iron Age Observation Event
country_event = {
	id = preftl.300
	title = "preftl.300.name"
	desc = {
		trigger = {
			from.owner = {
				is_gestalt = no
			}
		}
		text = preftl.300.desc.normal
	}
	desc = {
		trigger = {
			from.owner = {
				is_gestalt = yes
			}
		}
		text = preftl.300.desc.gestalt
	}
	picture = {
		trigger = {
			from.owner = {
				is_gestalt = no
			}
		}
		picture = GFX_evt_medieval_alien_civilization
	}
	picture = {
		trigger = {
			from.owner = {
				is_gestalt = yes
			}
		}
		picture = GFX_evt_hive_mind_pre_ftl
	}
	location = FROM

	is_triggered_only = yes

	option = {
		name = preftl.300.a
	}
}

# Iron Age -> Medieval Age (HIDDEN)
country_event = {
	id = preftl.399
	hide_window = yes

	trigger = {
		is_country_type = primitive
		has_country_flag = iron_age
	}

	is_triggered_only = yes

	immediate = {
		set_pre_ftl_age_effect = { PRE_FTL_AGE = late_medieval_age }
		increase_pre_ftl_pops_by_age_effect = { PRE_FTL_AGE = late_medieval_age }
		capital_scope = {
			if = {
				limit = {
					exists = observation_outpost_owner
					observation_outpost_owner = {
						is_country_type = default
					}
				}
				observation_outpost_owner = {
					country_event = { id = preftl.400 }
				}
			}
		}
	}
}

# Medieval Age Events
# Reserving preftl.400 - preftl.499

# Medieval Age Observation Event
country_event = {
	id = preftl.400
	title = "preftl.400.name"
	desc = {
		trigger = {
			from.owner = {
				is_gestalt = no
			}
		}
		text = preftl.400.desc.normal
	}
	desc = {
		trigger = {
			from.owner = {
				is_gestalt = yes
			}
		}
		text = preftl.400.desc.gestalt
	}
	picture = {
		trigger = {
			from.owner = {
				is_gestalt = no
			}
		}
		picture = GFX_evt_medieval_alien_civilization
	}
	picture = {
		trigger = {
			from.owner = {
				is_gestalt = yes
			}
		}
		picture = GFX_evt_hive_mind_pre_ftl
	}
	location = FROM

	is_triggered_only = yes

	option = {
		name = preftl.400.a
	}
}

# Medieval Age -> Renaissance Age (HIDDEN)
country_event = {
	id = preftl.499
	hide_window = yes

	trigger = {
		is_country_type = primitive
		has_country_flag = late_medieval_age
	}

	is_triggered_only = yes

	immediate = {
		set_pre_ftl_age_effect = { PRE_FTL_AGE = renaissance_age }
		increase_pre_ftl_pops_by_age_effect = { PRE_FTL_AGE = renaissance_age }
		capital_scope = {
			if = {
				limit = {
					exists = observation_outpost_owner
					observation_outpost_owner = {
						is_country_type = default
					}
				}
				observation_outpost_owner = {
					country_event = { id = preftl.500 }
				}
			}
		}
	}
}

# Renaissance Age Events
# Reserving preftl.500 - preftl.599

# Renaissance Age Observation Event
country_event = {
	id = preftl.500
	title = "preftl.500.name"
	desc = {
		trigger = {
			from.owner = {
				is_gestalt = no
			}
		}
		text = preftl.500.desc.normal
	}
	desc = {
		trigger = {
			from.owner = {
				is_gestalt = yes
			}
		}
		text = preftl.500.desc.gestalt
	}
	picture = {
		trigger = {
			from.owner = {
				is_gestalt = no
			}
		}
		picture = GFX_evt_medieval_alien_civilization
	}
	picture = {
		trigger = {
			from.owner = {
				is_gestalt = yes
			}
		}
		picture = GFX_evt_hive_mind_pre_ftl
	}

	is_triggered_only = yes

	option = {
		name = preftl.500.a
	}
}

# Renaissance Age -> Steam Age (HIDDEN)
country_event = {
	id = preftl.599
	hide_window = yes

	trigger = {
		is_country_type = primitive
		has_country_flag = renaissance_age
	}

	is_triggered_only = yes

	immediate = {
		set_pre_ftl_age_effect = { PRE_FTL_AGE = steam_age }
		increase_pre_ftl_pops_by_age_effect = { PRE_FTL_AGE = steam_age }
		capital_scope = {
			if = {
				limit = {
					exists = observation_outpost_owner
					observation_outpost_owner = {
						is_country_type = default
					}
				}
				observation_outpost_owner = {
					country_event = { id = preftl.600 }
				}
			}
		}
	}
}

# Steam Age Events
# Reserving preftl.600 - preftl.699

# Steam Engine Observation Event
country_event = {
	id = preftl.600
	title = "preftl.600.name"
	desc = {
		trigger = {
			from.owner = {
				is_gestalt = no
			}
		}
		text = preftl.600.desc.normal
	}
	desc = {
		trigger = {
			from.owner = {
				is_gestalt = yes
			}
		}
		text = preftl.600.desc.gestalt
	}
	picture = {
		trigger = {
			from.owner = {
				is_gestalt = no
			}
		}
		picture = GFX_evt_medieval_alien_civilization
	}
	picture = {
		trigger = {
			from.owner = {
				is_gestalt = yes
			}
		}
		picture = GFX_evt_hive_mind_pre_ftl
	}
	location = FROM

	is_triggered_only = yes

	option = {
		name = preftl.600.a
	}
}

# Steam Age -> Industrial Age (HIDDEN)
country_event = {
	id = preftl.699
	hide_window = yes

	trigger = {
		is_country_type = primitive
		has_country_flag = steam_age
	}

	is_triggered_only = yes

	immediate = {
		set_pre_ftl_age_effect = { PRE_FTL_AGE = industrial_age }
		increase_pre_ftl_pops_by_age_effect = { PRE_FTL_AGE = industrial_age }
		set_graphical_culture = industrial_01
		capital_scope = {
			clear_blockers = yes
			add_deposit = d_decrepit_dwellings
			add_deposit = d_failing_infrastructure
			if = {
				limit = {
					exists = observation_outpost_owner
					observation_outpost_owner = {
						is_country_type = default
					}
				}
				observation_outpost_owner = {
					country_event = { id = preftl.700 }
				}
			}
		}
	}
}

# Industrial Age Events
# Reserving preftl.700 - preftl.799

# Industrial Age Observation Event
country_event = {
	id = preftl.700
	title = "preftl.700.name"
	desc = {
		trigger = {
			from.owner = {
				is_gestalt = no
			}
		}
		text = preftl.700.desc.normal
	}
	desc = {
		trigger = {
			from.owner = {
				is_gestalt = yes
			}
		}
		text = preftl.700.desc.gestalt
	}
	picture = {
		trigger = {
			from.owner = {
				is_gestalt = no
			}
		}
		picture = GFX_evt_medieval_alien_civilization
	}
	picture = {
		trigger = {
			from.owner = {
				is_gestalt = yes
			}
		}
		picture = GFX_evt_hive_mind_pre_ftl
	}
	location = FROM

	is_triggered_only = yes

	option = {
		name = preftl.700.a
	}
}

# Industrial Age -> Machine Age (HIDDEN)
country_event = {
	id = preftl.799
	hide_window = yes

	trigger = {
		is_country_type = primitive
		has_country_flag = industrial_age
	}

	is_triggered_only = yes

	immediate = {
		set_pre_ftl_age_effect = { PRE_FTL_AGE = machine_age }
		increase_pre_ftl_pops_by_age_effect = { PRE_FTL_AGE = machine_age }
		capital_scope = {
			if = {
				limit = {
					exists = observation_outpost_owner
					observation_outpost_owner = {
						is_country_type = default
					}
				}
				observation_outpost_owner = {
					country_event = { id = preftl.800 }
				}
			}
		}
	}
}

# Machine Age Events
# Reserving preftl.800 - preftl.899

# Machine Age Observation Event
country_event = {
	id = preftl.800
	title = "preftl.800.name"
	desc = {
		trigger = {
			from.owner = {
				is_gestalt = no
			}
		}
		text = preftl.800.desc.normal
	}
	desc = {
		trigger = {
			from.owner = {
				is_gestalt = yes
			}
		}
		text = preftl.800.desc.gestalt
	}
	picture = {
		trigger = {
			from.owner = {
				is_gestalt = no
			}
		}
		picture = GFX_evt_medieval_alien_civilization
	}
	picture = {
		trigger = {
			from.owner = {
				is_gestalt = yes
			}
		}
		picture = GFX_evt_hive_mind_pre_ftl
	}
	location = FROM

	is_triggered_only = yes

	option = {
		name = preftl.800.a
	}
}

# Machine Age -> Atomic Age (HIDDEN)
country_event = {
	id = preftl.899
	hide_window = yes

	trigger = {
		is_country_type = primitive
		has_country_flag = machine_age
	}

	is_triggered_only = yes

	immediate = {
		set_pre_ftl_age_effect = { PRE_FTL_AGE = atomic_age }
		increase_pre_ftl_pops_by_age_effect = { PRE_FTL_AGE = atomic_age }
		capital_scope = {
			if = {
				limit = {
					exists = observation_outpost_owner
					observation_outpost_owner = {
						is_country_type = default
					}
				}
				observation_outpost_owner = {
					country_event = { id = preftl.900 }
				}
			}
		}
	}
}

# Atomic Age Events
# Reserving preftl.900 - preftl.999

# Atomic Age Observation Event
country_event = {
	id = preftl.900
	title = "preftl.900.name"
	desc = {
		trigger = {
			from.owner = {
				is_gestalt = no
			}
		}
		text = preftl.900.desc.normal
	}
	desc = {
		trigger = {
			from.owner = {
				is_gestalt = yes
			}
		}
		text = preftl.900.desc.gestalt
	}
	picture = {
		trigger = {
			from.owner = {
				is_gestalt = no
			}
		}
		picture = GFX_evt_metropolis
	}
	picture = {
		trigger = {
			from.owner = {
				is_gestalt = yes
			}
		}
		picture = GFX_evt_hive_mind_pre_ftl
	}
	location = FROM

	is_triggered_only = yes

	option = {
		name = preftl.900.a
	}
}

# Atomic Age -> Early Space Age (HIDDEN)
country_event = {
	id = preftl.999
	hide_window = yes

	trigger = {
		is_country_type = primitive
		has_country_flag = atomic_age
	}

	is_triggered_only = yes

	immediate = {
		set_pre_ftl_age_effect = { PRE_FTL_AGE = early_space_age }
		increase_pre_ftl_pops_by_age_effect = { PRE_FTL_AGE = early_space_age }
		capital_scope = {
			if = {
				limit = {
					exists = observation_outpost_owner
					observation_outpost_owner = {
						is_country_type = default
					}
				}
				observation_outpost_owner = {
					country_event = { id = preftl.1000 }
				}
			}
		}
	}
}

# Early Space Age Events
# Reserving preftl.1000 - preftl.1099

# Early Space Age Observation Event
country_event = {
	id = preftl.1000
	title = "preftl.1000.name"
	desc = {
		trigger = {
			from.owner = {
				is_gestalt = no
			}
		}
		text = preftl.1000.desc.normal
	}
	desc = {
		trigger = {
			from.owner = {
				is_gestalt = yes
			}
		}
		text = preftl.1000.desc.gestalt
	}
	picture = GFX_evt_satellite_in_orbit
	location = FROM

	is_triggered_only = yes

	option = {
		name = preftl.1000.a
	}
}

# Pre-FTL Robot Uprising
situation_event = {
	id = preftl.1010
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		situation_progress >= 960
		NOT = { has_situation_flag = has_ongoing_observation_event_chain }
		owner = {
			has_country_flag = early_space_age
			capital_scope = {
				is_artificial = no
			}
			NOR = {
				has_origin = origin_mechanists
				has_country_flag = had_pre_ftl_uprising
				has_country_flag = unplugged_pre_ftl_empire_flag
			}
		}
	}

	immediate = {
		owner = {
			country_event = { id = preftl.1015 }
			capital_scope.observation_outpost? = {
				set_event_locked = yes
			}
		}
		set_situation_flag = has_ongoing_observation_event_chain
	}
}

# Pre-FTL Robot Uprising
country_event = {
	id = preftl.1015
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		has_first_contact_dlc = yes
		has_country_flag = early_space_age
		is_hive_empire = no
	}

	immediate = {
		set_country_flag = had_pre_ftl_uprising
		capital_scope = {
			create_country = {
				name = "NAME_Robot_Uprising"
				type = faction
				effect = {
					set_country_flag = pre_ftl_robot_uprising
					establish_communications_no_message = root
					if = {
						limit = {
							exists = prev.observation_outpost_owner
						}
						establish_communications_no_message = prev.observation_outpost_owner
					}
				}
			}
			random_list = {
				20 = {
					set_variable = {
						which = num_robot_uprising_armies
						value = 1
					}
				}
				20 = {
					set_variable = {
						which = num_robot_uprising_armies
						value = 2
					}
				}
				20 = {
					set_variable = {
						which = num_robot_uprising_armies
						value = 3
					}
				}
				20 = {
					set_variable = {
						which = num_robot_uprising_armies
						value = 4
					}
				}
				20 = {
					set_variable = {
						which = num_robot_uprising_armies
						value = 5
					}
				}
			}
			while = {
				count = num_robot_uprising_armies
				create_army = {
					name = "NAME_Robot_Army"
					owner = last_created_country
					type = "robot_uprising_army"
				}
			}
			clear_variable = num_robot_uprising_armies
			# Notify the owner of the observation post
			if = {
				limit = {
					exists = observation_outpost_owner
				}
				observation_outpost_owner = {
					country_event = { id = preftl.1020 }
				}
			}
		}
	}

	after = {
		custom_tooltip = cannot_reveal_tt
		custom_tooltip = cannot_dismantle_outpost_tt
	}
}

# Observing Robot Uprising
country_event = {
	id = preftl.1020
	title = preftl.1020.name
	desc = preftl.1020.desc
	picture = GFX_evt_organic_oppression
	location = FROM.capital_scope

	is_triggered_only = yes

	option = {
		name = preftl.1020.a
		trigger = {
			is_spiritualist = no
			is_machine_empire = no
			is_individual_machine = no
		}
	}
	option = {
		name = preftl.1020.spiritualist
		trigger = {
			is_individual_machine = no
			is_spiritualist = yes
		}
	}
	option = {
		name = preftl.1020.machine
		trigger = {
			OR = {
				is_machine_empire = yes
				is_individual_machine = yes
			}
		}
	}
}

# This = country, planet owner
# From = country, attack leader
# FromFrom = planet
# Pre-FTL Robot Uprising Won
country_event = {
	id = preftl.1025
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_primitive = yes
		from = { has_country_flag = pre_ftl_robot_uprising }
	}

	immediate = {
		# Set the loser's graphical culture, so the machines can copy it.
		set_species_graphical_culture = yes

		# Remove the original robot rebellion.
		from = {
			every_owned_army = {
				remove_army = yes
			}
		}

		# create machine species
		create_species = {
			name = random
			class = MACHINE
			portrait = random
			homeworld = fromfrom
			traits = {
				trait = trait_machine_unit
				trait = random_traits
			}
			immortal = yes
		}

		# create machine country
		random_list = {
			1 = { # exterminator
				create_terminator_country = yes
			}
			30 = { # assimilator
				create_assimilator_country = yes
			}

			100 = { # regular machine empire
				create_machine_country = yes
			}
		}

		event_target:current_uprising = {
			set_graphical_culture = root
			hidden_effect = {
				establish_communications_no_message = root
			}
		}

		fromfrom = {
			save_event_target_as = pre_ftl_planet

			# Check an empire owns the solar system and grant communications with them.
			solar_system = {
				if = {
					limit = {
						exists = space_owner
						space_owner = {
							is_country_type = default
						}
					}
					space_owner = {
						establish_communications_no_message = event_target:current_uprising
						save_event_target_as = system_owner
					}
				}
			}

			# If the solar system owner has an observation post, notify them.
			if = {
				limit = {
					exists = observation_outpost_owner
					observation_outpost_owner = {
						is_same_value = event_target:system_owner
					}
				}
				event_target:system_owner = {
					hidden_effect = {
						prev = {
							observation_outpost = {
								dismantle = yes
							}
						}
						add_intel = {
							who = event_target:current_uprising
							amount = 60
						}
						country_event = { id = preftl.1110 }
						country_event = { id = preftl.1115 days = 5 }
					}
				}
			}
			else = {
				event_target:system_owner = {
					create_message = {
						type = MESSAGE_SYSTEM_LOST_TO_PRE_FTL
						localization = MESSAGE_SYSTEM_LOST_TO_PRE_FTL
						days = 30
						target = fromfrom.solar_system
						variable = {
							type = name
							localization = SYSTEM
							scope = fromfrom.solar_system
						}
					}
				}
			}
			if = {
				limit = {
					is_planet_class = pc_desert
				}
				set_carrier_flag = tasty_desert
			}

			set_owner = event_target:current_uprising
			set_capital = yes
			while = {
				count = 18
				create_pop_group = {
					species = last_created_species
				}
			}

			# Reformat the planet
			remove_all_districts = yes
			remove_all_buildings = yes
			generate_start_buildings_and_districts = yes

			# Add Culture Shock modifier
			add_modifier = {
				modifier = planet_culture_shock
				years = 10
			}

			# Kill some of the original organic pops
			while = {
				limit = {
					count_owned_pop_amount = {
						limit = {
							NOT = { is_same_species = owner }
						}
						count >= 1100
					}
				}
				random_owned_pop_group = {
					limit = {
						NOT = { is_same_species = owner }
					}
					kill_single_pop = yes
				}
			}

			owner = {
				random_controlled_ship = {
					limit = { is_ship_size = primitive_space_station }
					fleet = { destroy_fleet = THIS }
				}

				# Unity so they can hire some leaders
				add_resource = { unity = 1000 }

				if = {
					limit = {
						NOT = { owner = { has_valid_civic = civic_machine_terminator } }
					}
					# Prevent bankruptcy from food.
					if = {
						limit = {
							any_owned_species = {
								is_archetype = BIOLOGICAL
							}
						}
						add_resource = { food = 100	}
						prev = {
							add_district_and_planet_size_if_needed_effect = {
								district = district_farming
							}
						}
					}
					# Prevent bankruptcy from minerals.
					else_if = {
						limit = {
							any_owned_pop_group = {
								species = {
									is_archetype = LITHOID
								}
							}
						}
						add_resource = { minerals = 100	}
						prev = {
							add_district_and_planet_size_if_needed_effect = {
								district = district_mining
							}
						}
					}
				}
			}

			# Flip control of the solar system
			solar_system = {
				if = {
					limit = { exists = starbase }
					starbase = {
						set_owner = event_target:current_uprising
						if = {
							limit = { has_starbase_size = starbase_outpost }
							set_starbase_size = starbase_starport
							set_starbase_module = {
								slot = 1
								module = shipyard
							}
							set_starbase_module = {
								slot = 2
								module = shipyard
							}
						}
						else_if = {
							limit = {
								NOT = { has_starbase_module = shipyard }
							}
							set_starbase_module = {
								slot = 1
								module = shipyard
							}
							set_starbase_module = {
								slot = 2
								module = shipyard
							}
						}
					}
				}
				else = {
					create_starbase = {
						size = starbase_starport
						module = shipyard
						module = shipyard
						owner = event_target:current_uprising
					}
				}
				every_fleet_in_system = {
					limit = {
						owner = { NOT = { is_same_value = event_target:current_uprising } }
						is_mobile = yes
					}
					set_mia = mia_return_home
				}
				add_claims = {
					who = event_target:system_owner
					num_of_claims = 1
					show_notification = no
				}
			}
		}
	}
}

# Root = country, planet owner
# From = country, attack leader
# FromFrom = planet
# Pre-FTL Robot Uprising Lost
country_event = {
	id = preftl.1030
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_primitive = yes
		from = { has_country_flag = pre_ftl_robot_uprising }
	}

	immediate = {
		random_situation = {
			limit = {
				is_situation_type = pre_ftl_tech_progress_situation
			}
			add_situation_progress = 96
			remove_situation_flag = has_ongoing_observation_event_chain
		}
		fromfrom = {
			# Notify the owner of the observation post
			if = {
				limit = {
					exists = observation_outpost_owner
				}
				observation_outpost_owner = {
					country_event = { id = preftl.1035 }
				}
			}
		}
		capital_scope.observation_outpost? = {
			set_event_locked = no
		}
	}
}

# Observed Robot Uprising Lost
country_event = {
	id = preftl.1035
	title = "preftl.1035.name"
	desc = "preftl.1035.desc"
	picture = GFX_evt_satellite_in_orbit
	location = FROM.capital_scope

	is_triggered_only = yes

	immediate = {
		set_country_flag = engineering_insights
		set_predictive_observation_insight = {
			VALUE = 20
		}
	}

	option = {
		trigger = {
			is_spiritualist = no
			is_machine_empire = no
			is_individual_machine = no
		}
		name = {
			trigger = {
				has_technology = tech_robotic_workers
			}
			text = preftl.1035.a.robot
		}
		name = {
			trigger = {
				NOT = { has_technology = tech_robotic_workers }
			}
			text = preftl.1035.a.norobot
		}
		add_observation_insight_effect = {
			VALUE = 10
			OUTPOST = from.capital_scope.observation_outpost
		}
	}
	option = {
		name = preftl.1035.b.spiritualist
		trigger = {
			is_individual_machine = no
			is_spiritualist = yes
		}
		add_observation_insight_effect = {
			VALUE = 20
			OUTPOST = from.capital_scope.observation_outpost
		}
	}
	option = {
		name = preftl.1035.b.machine
		trigger = {
			OR = {
				is_machine_empire = yes
				is_individual_machine = yes
			}
			NOT = {
				has_valid_civic = civic_machine_terminator
			}
		}
		add_observation_insight_effect = {
			VALUE = 20
			OUTPOST = from.capital_scope.observation_outpost
		}
	}
	option = {
		name = preftl.1035.b.machine.terminator
		trigger = {
			is_machine_empire = yes
			has_valid_civic = civic_machine_terminator
		}
		add_observation_insight_effect = {
			VALUE = 20
			OUTPOST = from.capital_scope.observation_outpost
		}
	}
}

# Early Space Age -> FTL Capable (HIDDEN)
# refactoring of primitive.16
country_event = {
	id = preftl.1099
	hide_window = yes

	trigger = {
		is_country_type = primitive
		OR = {
			has_country_flag = early_space_age
			has_country_flag = ignore_space_age_requirement
		}
	}

	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				has_awareness >= 100
			}
			set_country_flag = knew_of_aliens
		}
		# Clear relations with pre-ftl under observation
		if = {
			limit = {
				pre_ftl_is_observed_by_system_owner = yes
			}
			clear_relations = {
				target = capital_scope.observation_outpost_owner
				relations = {
					is_under_societal_enlightenment
					is_under_open_technological_enlightenment
					is_under_stratified_technological_enlightenment
					has_pre_ftl_trade
				}
			}
		}
		if = { # they got FTL due to an event chain.
			limit = {
				has_country_flag = ignore_space_age_requirement
			}
			capital_scope.solar_system.owner = {
				country_event = { id = preftl.180 days = 1 }
			}
		}
		else_if = { # if they got FTL thanks to us, they become vassals
			limit = {
				pre_ftl_is_observed_by_system_owner = yes
				has_country_flag = open_technological_enlightenment_pact
			}
			capital_scope.observation_outpost_owner = {
				country_event = { id = preftl.1105 }
				# Payback | MSI congratulates you
				country_event = { id = origin.4160 days = 15 }
			}
		}
		else_if = { # if we helped them through espionage or they got FTL alone, they ask to become independent
			limit = {
				pre_ftl_is_observed_by_system_owner = yes
				NOT = { has_country_flag = open_technological_enlightenment_pact }
			}
			capital_scope.observation_outpost_owner = {
				country_event = { id = preftl.1100 }
			}
		}
		else_if = { # if we have no observation post but a starbase, they ask for control of it
			limit = {
				pre_ftl_not_observed_by_system_owner = yes
			}
			capital_scope.solar_system.owner = {
				country_event = { id = preftl.180 days = 1 }
			}
		}
		else = { # if nobody is in the system, they become an empire
			achieve_ftl_effect = {
				PRE_FTL = root
				OWNER = root
			}
		}
	}
}

# FTL Capable Age
# Reserving preftl.1100 - preftl.1199

# They achieved space flight thanks to our guidance
# Refactoring of observation.2000

#They achieved space flight alone - system owner notified
# refactoring of primitive.16
country_event = {
	id = preftl.1100
	title = "preftl.1100.name"
	desc = "preftl.1100.desc"
	picture = GFX_evt_space_station
	show_sound = event_ship_thrusters
	location = FROM.capital_scope

	is_triggered_only = yes

	immediate = {
		establish_communications_no_message = from
		establish_contact = {
			who = from
			location = FROM.capital_scope.solar_system
		}
	}

	option = {
		name = preftl.1100.a
	}

	after = {
		hidden_effect = {
			FROM = {
				capital_scope = {
					if = {
						limit = {
							has_observation_outpost = yes
						}
						observation_outpost = {
							dismantle = yes
						}
					}
				}
			}
			# they will ask us to cede control of our starbase after this event
			country_event = { id = preftl.180 days = 1 scopes = { from = from } }
		}
	}
}

country_event = {
	id = preftl.1105
	title = "observation.2000.name"
	desc = "observation.2000.desc"
	picture = GFX_evt_early_space_age
	show_sound = event_ship_thrusters
	location = FROM.capital_scope

	is_triggered_only = yes

	trigger = {

	}

	immediate = {
		# Xenoist Faction Enlightenment Demand
		set_timed_country_flag = {
			flag = recent_enlightenment_timed
			days = 7200 # 20 years
		}
		# for Enlightened times achievement
		if = {
			limit = {
				FROM = {
					has_country_flag = started_enlightening_from_ancient_era
				}
			}
			FROM = { remove_country_flag = started_enlightening_from_ancient_era }
			set_country_flag = uplifted_ancient_age_preftl
		}

		if = { # if we are broken shackles and they are a former homeworld
			limit = {
				has_origin = origin_broken_shackles
				OR = {
					has_country_flag = uplifting_decision
					has_country_flag = uplifting_decision_main
				}
				FROM = {
					capital_scope = {
						OR = {
							has_planet_flag = broken_shackles_homeworld_@root
							has_carrier_flag = broken_shackles_abductees_world@root
						}
					}
				}
			}
			country_event = {
				id =  origin.5525
			}
		}

		FROM = {
			save_event_target_as = new_ftl_country
			establish_communications_no_message = root
			remove_pre_ftl_flags = yes
			set_country_flag = was_enlightened
			add_opinion_modifier = { who = root modifier = opinion_enlightened_us }
			if = {
				limit = {
					root = { is_country_type = awakened_fallen_empire }
				}
				if = {
					limit = {
						root = {
							is_fanatic_xenophobe = yes
						}
					}
					set_subject_of = {
						who = root
						preset = preset_thrall
					}
				}
				if = {
					limit = {
						root = {
							is_fanatic_xenophile = yes
						}
					}
					set_subject_of = {
						who = root
						preset = preset_signatory
					}
				}
				if = {
					limit = {
						root = {
							is_fanatic_spiritualist = yes
						}
					}
					set_subject_of = {
						who = root
						preset = preset_dominion
					}
					shift_ethic = ethic_fanatic_spiritualist
				}
				if = {
					limit = {
						root = {
							is_fanatic_materialist = yes
						}
					}
					set_subject_of = {
						who = root
						preset = preset_satellite
					}
				}
			}
			random_agreement = {
				limit = {
					owner = { is_same_value = root }
					target = { is_same_value = event_target:new_ftl_country }
				}
				add_loyalty = 100
			}
			capital_scope = {
				observation_outpost = {
					dismantle = yes
				}
				solar_system = {
					if = {
						limit = {
							starbase = { owner = { is_same_value = root } }
						}
						starbase = {
							owner = {
								save_event_target_as = previous_system_owner
							}
							set_owner = event_target:new_ftl_country
							if = {
								limit = { has_starbase_size = starbase_outpost }
								set_starbase_size = starbase_starport
							}
						}
					}
					every_system_planet = {
						limit = {
							exists = owner
							owner = { is_same_value = root }
						}
						set_owner = event_target:new_ftl_country
					}
				}
			}
			achieve_ftl_effect = {
				PRE_FTL = event_target:new_ftl_country
				OWNER = root
			}
		}
		establish_communications_no_message = from
		establish_contact = {
			who = from
			location = FROM.capital_scope.solar_system
		}
	}

	option = {
		name = "observation.2000.a"
		custom_tooltip = observation.2000.a.tt
		set_country_flag = vassalized_the_pre_ftl
		if = {
			limit = {
				root = { is_country_type = awakened_fallen_empire }
			}
			if = {
				limit = {
					root = {
						is_fanatic_xenophobe = yes
					}
				}
				set_subject_of = {
					who = root
					preset = preset_thrall
				}
			}
			if = {
				limit = {
					root = {
						is_fanatic_xenophile = yes
					}
				}
				set_subject_of = {
					who = root
					preset = preset_signatory
				}
			}
			if = {
				limit = {
					root = {
						is_fanatic_spiritualist = yes
					}
				}
				set_subject_of = {
					who = root
					preset = preset_dominion
				}
				shift_ethic = ethic_fanatic_spiritualist
			}
			if = {
				limit = {
					root = {
						is_fanatic_materialist = yes
					}
				}
				set_subject_of = {
					who = root
					preset = preset_satellite
				}
			}
		}
	}

	option = {
		name = observation.2000.b
		add_monthly_resource_mult = {
			resource = unity
			value = @tier3unityreward
			min = @tier3unitymin
			max = @tier3unitymax
		}
	}

	after = {
		if =  {
			limit = {
				has_country_flag = vassalized_the_pre_ftl
			}
			FROM = {
				if = {
					limit = {
						root = { is_country_type = default }
					}
					if = {
						limit = {
							root = { has_valid_civic = "civic_inwards_perfection" }
						}
						set_subject_of = {
							who = root
							preset = preset_tributary
							allow_instant_negotiation = yes
						}
					}
					else = {
						set_subject_of = {
							who = root
							preset = preset_protectorate
							allow_instant_negotiation = yes
						}
					}
				}
			}
		}
		establish_communications_no_message = from
		establish_contact = {
			who = from
			location = FROM.capital_scope.solar_system
		}
	}
}

# They achieved space flight alone - other empires get notified
# refactoring of primitive.16
country_event = {
	id = preftl.1111
	title = "action.13.name"
	desc = "preftl.1111.desc"
	picture = GFX_evt_space_station
	show_sound = event_ship_thrusters
	location = FROM.capital_scope.solar_system
	is_triggered_only = yes

	immediate = {
		from = {
			save_event_target_as = contact_empire
		}
		establish_communications_no_message = from
		establish_contact = {
			who = from
			location = FROM.capital_scope.solar_system
		}
	}

	option = {
		name = ACKNOWLEDGED
	}

	after = {
		hidden_effect = {
			country_event = { id = distar.238 days = 1 }
			country_event = { id = action.1 }
		}
	}
}

# Successful Robot Uprising
country_event = {
	id = preftl.1110
	title = "preftl.1110.name"
	desc = "preftl.1110.desc"
	picture = GFX_evt_satellite_in_orbit
	location = FROM.capital_scope

	is_triggered_only = yes

	immediate = {
		set_country_flag = engineering_insights
		set_predictive_observation_insight = {
			VALUE = 20
		}
	}

	option = {
		name = preftl.1110.a
		trigger = {
			is_spiritualist = no
			is_machine_empire = no
			is_individual_machine = no
		}
	}
	option = {
		name = preftl.1110.b.spiritualist
		trigger = {
			is_individual_machine = no
			is_spiritualist = yes
		}
		add_observation_insight_effect = {
			VALUE = 20
			OUTPOST = from.capital_scope.observation_outpost
		}
	}
	option = {
		name = preftl.1110.b.machine
		trigger = {
			OR = {
				is_machine_empire = yes
				is_individual_machine = yes
			}
			NOT = { has_valid_civic = civic_machine_servitor }
		}
		add_observation_insight_effect = {
			VALUE = 20
			OUTPOST = from.capital_scope.observation_outpost
		}
	}

	option = {
		name = preftl.1110.b.machine.servitor
		trigger = {
			has_valid_civic = civic_machine_servitor
		}
		add_observation_insight_effect = {
			VALUE = 20
			OUTPOST = from.capital_scope.observation_outpost
		}
	}
}

# Robot Uprising makes contact with observer empire
country_event = {
	id = preftl.1115
	title = preftl.1115.name
	location = event_target:current_uprising.capital_scope.solar_system
	desc = preftl.1115.desc

	diplomatic = yes

	is_triggered_only = yes

	picture_event_data = {
		portrait = event_target:current_uprising
		planet_background = event_target:current_uprising
		graphical_culture = event_target:current_uprising
		city_level = event_target:current_uprising
		room = event_target:current_uprising.ruler
	}

	option = {
		name = preftl.1115.recognize
		trigger = {
			is_xenophobe = no
			NOR = {
				has_valid_civic = civic_hive_devouring_swarm
				has_valid_civic = civic_fanatic_purifiers
			}
		}

		custom_tooltip = preftl.1115.recognize.tooltip
		hidden_effect = {
			event_target:current_uprising = {
				add_opinion_modifier = {
					modifier = opinion_respect_independence
					who = root
				}
				capital_scope.solar_system = {
					remove_claims = {
						who = root
					}
				}
			}
		}
	}

	# Xenophobe version
	option = {
		name = preftl.1115.recognize
		trigger = {
			is_xenophobe = yes
			NOR = {
				has_valid_civic = civic_hive_devouring_swarm
				has_valid_civic = civic_fanatic_purifiers
			}
		}

		allow = {
			resource_stockpile_compare = {
				resource = influence
				value >= 200
			}
		}
		add_resource = { influence = -200 }

		custom_tooltip = preftl.1115.recognize.tooltip
		hidden_effect = {
			event_target:current_uprising = {
				add_opinion_modifier = {
					modifier = opinion_respect_independence
					who = root
				}
			}
			capital_scope.solar_system = {
				remove_claims = {
					who = root
				}
			}
		}
	}

	option = {
		name = preftl.1115.claim
		trigger = {
			is_xenophile = no
			NOR = {
				has_valid_civic = civic_hive_devouring_swarm
				has_valid_civic = civic_fanatic_purifiers
			}
		}

		custom_tooltip = preftl.1115.claim.tooltip
		hidden_effect = {
			event_target:current_uprising = {
				add_opinion_modifier = {
					modifier = opinion_disrespect_independence
					who = root
				}
				capital_scope = {
					solar_system = {
						add_claims = {
							who = root
							show_notification = no
						}
					}
				}
			}
		}
	}

	# Xenophile version
	option = {
		name = preftl.1115.claim
		trigger = {
			is_xenophile = yes
			NOR = {
				has_valid_civic = civic_hive_devouring_swarm
				has_valid_civic = civic_fanatic_purifiers
			}
		}

		allow = {
			resource_stockpile_compare = {
				resource = influence
				value >= 200
			}
		}
		add_resource = { influence = -200 }

		custom_tooltip = preftl.1115.claim.tooltip
		hidden_effect = {
			event_target:current_uprising = {
				add_opinion_modifier = {
					modifier = opinion_disrespect_independence
					who = root
				}
				capital_scope = {
					solar_system = {
						add_claims = {
							who = root
							show_notification = no
						}
					}
				}
			}
		}
	}

	option = {
		name = preftl.1115.subjugate
		trigger = {
			is_xenophile = no
			NOR = {
				has_valid_civic = civic_hive_empath
				has_valid_civic = civic_hive_devouring_swarm
				has_valid_civic = civic_fanatic_purifiers
				is_genocidal_infernal = yes
			}
			is_spiritualist = no
			OR = {
				is_machine_empire = yes
				event_target:current_uprising = {
					NOR = {
						has_valid_civic = civic_machine_terminator
						has_valid_civic = civic_machine_assimilator
					}
				}
			}
		}

		allow = {
			resource_stockpile_compare = {
				resource = influence
				value >= 200
			}
		}
		add_resource = { influence = -200 }

		custom_tooltip = preftl.1115.subjugate.tooltip
		hidden_effect = {
			event_target:current_uprising = {
				set_subject_of = {
					who = root
					allow_instant_negotiation = yes
					preset = preset_protectorate
				}
				add_opinion_modifier = {
					modifier = opinion_disrespect_independence
					who = root
				}
			}
		}
	}

	# Xenophile/Emapth version
	option = {
		name = preftl.1115.subjugate
		trigger = {
			OR = {
				is_xenophile = yes
				has_valid_civic = civic_hive_empath
			}
			NOR = {
				has_valid_civic = civic_hive_devouring_swarm
				has_valid_civic = civic_fanatic_purifiers
			}
			is_spiritualist = no
			NOT = {
				event_target:current_uprising = {
					OR = {
						has_valid_civic = civic_machine_terminator
						has_valid_civic = civic_machine_assimilator
					}
				}
			}
		}

		allow = {
			resource_stockpile_compare = {
				resource = influence
				value >= 300
			}
		}
		add_resource = { influence = -300 }

		custom_tooltip = preftl.1115.subjugate.tooltip
		hidden_effect = {
			event_target:current_uprising = {
				set_subject_of = {
					who = root
					allow_instant_negotiation = yes
					preset = preset_protectorate
				}
				add_opinion_modifier = {
					modifier = opinion_disrespect_independence
					who = root
				}
			}
		}
	}

	option = {
		name = preftl.1115.network
		trigger = {
			is_machine_empire = yes
			NOT = {
				event_target:current_uprising = {
					has_valid_civic = civic_machine_servitor
				}
			}
			OR = {
				AND = {
					event_target:current_uprising = {
						has_valid_civic = civic_machine_terminator
					}
					has_valid_civic = civic_machine_terminator
				}
				AND = {
					event_target:current_uprising = {
						has_valid_civic = civic_machine_assimilator
					}
					has_valid_civic = civic_machine_assimilator
				}
				AND = {
					event_target:current_uprising = {
						NOT = { has_valid_civic = civic_machine_terminator }
					}
					event_target:current_uprising = {
						NOT = { has_valid_civic = civic_machine_assimilator }
					}
				}
			}
		}

		allow = {
			resource_stockpile_compare = {
				resource = influence
				value >= 200
			}
			resource_stockpile_compare = {
				resource = unity
				value >= 2000
			}
		}

		add_resource = {
			influence = -200
			unity = -2000
		}

		custom_tooltip = preftl.1115.network.tooltip
		hidden_effect = {
			event_target:current_uprising = {
				integrate_country_effect = {
					OWNER = root
				}
			}
		}
	}

	option = {
		name = TASTY # Prey...
		trigger = {
			has_valid_civic = civic_hive_devouring_swarm
		}
	}

	option = {
		name = SCUM # Xeno Scum
		trigger = {
			has_valid_civic = civic_fanatic_purifiers
		}
	}
}

# # Old MTTH Events that need to refactored

# # Space Station (HIDDEN)
# country_event = {
# 	id = preftl.18
# 	hide_window = yes

# 	trigger = {
# 		is_country_type = primitive
# 		has_country_flag = early_space_age
# 		exists = home_planet
# 		home_planet = {
# 			has_observation_outpost = yes
# 		}
# 		NOT = {
# 			any_controlled_ship = {
# 				is_ship_size = primitive_space_station
# 			}
# 		}
# 	}

# 	mean_time_to_happen = {
# 		years = 60

# 		modifier = {
# 			factor = 0.6
# 			has_country_flag = acquired_tech
# 		}
# 	}

# 	immediate = {
# 		home_planet = {
# 			create_fleet = {
# 				name = "NAME_Space_Station"
# 				effect = {
# 					set_owner = ROOT
# 					create_ship = {
# 						name = "NAME_Space_Station"
# 						design = "NAME_Space_Station"
# 					}
# 					set_location = PREV
# 				}
# 			}
# 			if = {
# 				limit = {
# 					exists = observation_outpost_owner
# 				}
# 				observation_outpost_owner = {
# 					country_event = { id = preftl.19 }
# 				}
# 			}
# 		}
# 	}
# }

# # Space Station
# country_event = {
# 	id = preftl.19
# 	title = "preftl.19.name"
# 	desc = "preftl.19.desc"
# 	picture = GFX_evt_satellite_in_orbit
# 	location = FROM

# 	is_triggered_only = yes

# 	option = {
# 		name = preftl.19.a
# 	}
# }

# Pre-FTL ask system owner for starbase ownership
country_event = {
	id = preftl.180
	title = preftl.180.name
	location = from.capital_scope.solar_system
	desc = {
		trigger = {
			from = {
				NOT = { has_country_flag = knew_of_aliens }
			}
		}
		text = preftl.180.desc.noawarness
	}
	desc = {
		trigger = {
			from = {
				has_country_flag = knew_of_aliens
			}
		}
		text = preftl.180.desc.awarness
	}
	desc = {
		exclusive_trigger = {
			from = {
				NOT = { has_country_flag = knew_of_aliens }
				capital_scope = {
					OR = {
						has_planet_flag = broken_shackles_homeworld_@root
						has_carrier_flag = broken_shackles_abductees_world@root
					}
				}
			}
		}
		text = preftl.180.desc.bshomeworld.noawarness
	}
	desc = {
		exclusive_trigger = {
			from = {
				has_country_flag = knew_of_aliens
				capital_scope = {
					OR = {
						has_planet_flag = broken_shackles_homeworld_@root
						has_carrier_flag = broken_shackles_abductees_world@root
					}
				}
			}
		}
		text = preftl.180.desc.bshomeworld.awarness
	}
	diplomatic = yes

	is_triggered_only = yes

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

	immediate = {
		establish_communications_no_message = from
		establish_contact = {
			who = from
			location = FROM.capital_scope.solar_system
		}
	}

	option = {
		name = preftl.180.a # Cede
		trigger = {
			is_homicidal = no
		}

		if = {
			limit = {
				is_xenophobe = yes
			}
			add_resource = { influence = -200 }
		}

		custom_tooltip = preftl.180.a.tooltip
		root = {
			set_truce = {
				target = from
				type = guarantee
			}
		}
		hidden_effect = {
			from = {
				set_truce = {
					target = root
					type = guarantee
				}
				achieve_ftl_effect = {
					PRE_FTL = root.from
					OWNER = root
				}
				capital_scope.solar_system.starbase = {
					set_owner = root.from
				}

				add_opinion_modifier = {
					modifier = opinion_ceded_starbase
					who = root
				}
			}
		}
	}

	option = {
		name = preftl.180.b # Don't cede
		trigger = {
			is_homicidal = no
		}

		allow = {
			OR = {
				values_others = no
				AND = {
					values_others = yes
					resource_stockpile_compare = {
						resource = influence
						value >= 100
					}
				}
			}
		}
		if = {
			limit = {
				is_xenophile = yes
			}
			add_resource = { influence = -100 }
		}

		custom_tooltip = preftl.180.b.tooltip

		if = {
			limit = {
				From = {
					is_hive_empire = yes
				}
				is_hive_empire = no
			}
			custom_tooltip = preftl.180.b.tt.nothive
		}
		if = {
			limit = {
				from = {
					is_hive_empire = no
				}
				AND = {
					is_gestalt = yes
					NOR = {
						has_valid_civic = civic_machine_servitor
						has_valid_civic = civic_machine_assimilator
					}
				}
			}
			custom_tooltip = preftl.180.b.tt.notregular
		}
		hidden_effect = {
			from = {
				achieve_ftl_effect = {
					PRE_FTL = root.from
					OWNER = root
				}
				add_opinion_modifier = {
					modifier = opinion_not_ceded_starbase
					who = root
				}
			}
			from.capital_scope = {
				remove_modifier = prosp_uni_mod
				remove_modifier = prosp_uni_mod_gestalt
			}
		}
	}

	option = {
		name = preftl.180.c
		trigger = {
			is_homicidal = no
			from.capital_scope.solar_system = {
				any_system_planet = {
					exists = owner
					owner = { is_same_value = root }
				}
			}
		}
		allow = {
			OR = {
				is_xenophile = no
				AND = {
					is_xenophile = yes
					resource_stockpile_compare = {
						resource = influence
						value >= 200
					}
				}
			}
		}
		if = {
			limit = {
				is_xenophile = yes
			}
			add_resource = { influence = -200 }
		}
		from.capital_scope = {
			set_owner = root
			add_modifier = {
				modifier = culture_shock_early_space_age
				days = 3600
			}
		}
	}

	option = {
		name = EXTERMINATE
		trigger = {
			has_valid_civic = civic_machine_terminator
		}
		from.capital_scope = {
			set_owner = root
			add_modifier = {
				modifier = culture_shock_early_space_age
				days = 3600
			}
		}
	}

	option = {
		name = TASTY
		trigger = {
			OR = {
				has_valid_civic = civic_hive_devouring_swarm
				has_menace_perk = menp_behemoth_ever_hungry
			}
		}
		from.capital_scope = {
			set_owner = root
			add_modifier = {
				modifier = culture_shock_early_space_age
				days = 3600
			}
		}
	}

	option = {
		name = SCUM # Xeno Scum
		trigger = {
			has_valid_civic = civic_fanatic_purifiers
		}
		from.capital_scope = {
			set_owner = root
			add_modifier = {
				modifier = culture_shock_early_space_age
				days = 3600
			}
		}
	}

	option = {
		name = INF_SCUM
		trigger = {
			is_genocidal_infernal = yes
		}
		from.capital_scope = {
			set_owner = root
			add_modifier = {
				modifier = culture_shock_early_space_age
				days = 3600
			}
		}
	}
}

# # Diplomatic Objection (HIDDEN)
# country_event = {
# 	id = preftl.173
# 	hide_window = yes

# 	trigger = {
# 		is_ai = yes
# 		is_primitive = no
# 		any_country = {
# 			#reverse_has_opinion_modifier = {
# 			#	who = ROOT
# 			#	modifier = opinion_abducted_aliens
# 			#}
# 		}
# 		NOT = { has_country_flag = abducted_aliens_objection }
# 		has_country_flag = BLABLA_REMOVEME
# 	}

# 	mean_time_to_happen = {
# 		months = 240
# 	}

# 	immediate = {
# 		set_country_flag = abducted_aliens_objection
# 		random_country = {
# 			#limit = {
# 			#	reverse_has_opinion_modifier = {
# 			#		who = ROOT
# 			#		modifier = opinion_abducted_aliens
# 			#	}
# 			#}
# 			country_event = { id = preftl.174 }
# 		}
# 	}
# }

# # Diplomatic Objection
# country_event = {
# 	id = preftl.174
# 	title = "TRANSMISSION_NAME"
# 	desc = "preftl.174.desc"

# 	diplomatic = yes
# 	is_triggered_only = yes

# 	option = {
# 		name = "preftl.174.a"
# 		trigger = { resource_stockpile_compare = { resource = energy value >= 100 } }
# 		response_text = "preftl.174.a.response"
# 		add_resource = { energy = -100 }
# 	}
# 	option = {
# 		name = "preftl.174.b"
# 		response_text = "preftl.174.b.response"
# 	}
# }

# Clear Observation Post after Orbital Bombardment
carrier_event = {
	id = preftl.201
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		has_observation_outpost = yes
	}

	immediate = {
		observation_outpost = { dismantle = yes }
	}
}

# Test event for observation insights.
#	country_event = {
#		id = preftl.9999
#		title = "INSIGHT TEST EVENT"
#		desc = "INSIGHT TEST EVENT"
#		picture = GFX_evt_medieval_alien_civilization
#
#		is_triggered_only = yes
#
#		immediate = {
#			set_variable = {
#				which = observation_insight_loc
#				value = 5
#			}
#			random_list = {
#				1 = { set_country_flag = physics_insights }
#				1 = { set_country_flag = society_insights }
#				1 = { set_country_flag = engineering_insights }
#			}
#		}
#
#		option = {
#			name = "GIMME INSIGHT"
#			custom_tooltip = observation_insight_gained
#			hidden_effect = {
#				add_observation_insight_effect = {
#					VALUE = 5
#				}
#			}
#		}
#	}

### Plague Situation

# Trigger event for Plague
situation_event = {
	id = preftl.2000
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_first_contact_dlc = yes
		owner = {
			is_gestalt = no
			current_awareness_level < full
			has_blocked_random_devastating_pre_ftl_events = no
		}
	}

	immediate = {
		owner.capital_scope = {
			if = {
				limit = {
					exists = observation_outpost_owner
				}
				observation_outpost_owner = {
					country_event = { id = preftl.2001 }
				}
				observation_outpost = {
					set_event_locked = yes
				}
			}
		}
	}
}

# Starting event
country_event = {
	id = preftl.2001
	title = preftl.2001.name
	desc = {
		trigger = {
			NOT = {
				has_country_flag = outbreak_perpetrator
			}
			has_policy_flag = interference_not_allowed
		}
		text = preftl.2001.can_not_help.desc
	}
	desc = {
		trigger = {
			NOR = {
				has_country_flag = outbreak_perpetrator
				has_policy_flag = interference_not_allowed
			}
		}
		text = preftl.2001.can_help.desc
	}
	desc = {
		trigger = {
			has_country_flag = outbreak_perpetrator
		}
		text = preftl.2001.perpetrator.desc
	}
	picture = GFX_evt_disease_outbreak
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = from.owner.capital_scope

	trigger = {
		exists = from.owner
		NOR = {
			has_country_flag = preftl_2000_fired
			has_country_flag = had_observation_situation
			from.owner = {
				current_awareness_level = full
			}
		}
	}

	immediate = {
		set_country_flag = preftl_2000_fired
		set_timed_country_flag = {
			flag = had_observation_situation
			days = 7200
		}
		if = {
			limit = {
				has_country_flag = outbreak_perpetrator
			}
			start_situation = {
				type = situation_pre_ftl_plague
				target = event_target:accidental_outbreak_planet
				effect = {
					save_event_target_as = plague_situation
				}
			}
		}
		else = {
			start_situation = {
				type = situation_pre_ftl_plague
				target = from.owner.capital_scope
				effect = {
					save_event_target_as = plague_situation
				}
			}
		}
	}

	option = { # Watch
		name = preftl.2001.a
		icon = {
			icon = GFX_situation_approach_research
			icon_background = GFX_situation_approach_bg_yellow
			text = set_situation_approach_icon_text
		}
		event_target:plague_situation = {
			set_situation_approach = approach_watch_learn
		}
	}

	option = { # Provide Aid
		name = preftl.2001.b
		icon = {
			icon = GFX_situation_approach_balance_sheet
			icon_background = GFX_situation_approach_bg_green
			text = set_situation_approach_icon_text
		}
		event_target:plague_situation = {
			set_situation_approach = approach_provide_aid
		}
	}

	option = { # Promote Disease
		name = preftl.2001.c
		icon = {
			icon = GFX_situation_approach_this_is_fine
			icon_background = GFX_situation_approach_bg_red
			text = set_situation_approach_icon_text
		}
		event_target:plague_situation = {
			set_situation_approach = approach_promote_disease
		}
	}

	after = {
		hidden_effect = {
			event_target:plague_situation = {
				set_situation_locked = no
			}
		}
	}
}

# Invisible trigger for Stage 2 events (35% Progress)
situation_event = {
	id = preftl.2002
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_situation_flag = situation_event_progress_35_happened }
	}

	immediate = {
		set_situation_flag = situation_event_progress_35_happened
		switch = {
			trigger = current_situation_approach
			approach_watch_learn = {
				random_list = {
					50 = {
						modifier = {
							factor = 2
							target.owner = {
								is_spiritualist = yes
							}
						}
						situation_event = { id = preftl.2006 }
					}
					50 = {
						modifier = {
							factor = 2
							target.owner = {
								is_militarist = yes
							}
						}
						situation_event = { id = preftl.2007 }
					}
				}
			}
			approach_provide_aid = {
				random_list = {
					50 = {
						situation_event = { id = preftl.2008 }
					}
					50 = {
						situation_event = { id = preftl.2009 }
					}
				}
			}
			approach_promote_disease = {
				random_list = {
					70 = {
						situation_event = { id = preftl.2010 }
					}
					30 = {
						situation_event = { id = preftl.2011 }
					}
				}
			}
		}
	}
}

# Invisible trigger for Stage 3 events (70% progress)
situation_event = {
	id = preftl.2003
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_situation_flag = situation_event_progress_70_happened }
	}

	immediate = {
		set_situation_flag = situation_event_progress_70_happened
		owner = {
			switch = {
				trigger = has_country_flag
				religious_mania = {
					prev = {
						situation_event = { id = preftl.2025 }
					}
				}
				rise_of_warlords = {
					prev = {
						situation_event = { id = preftl.2030 }
					}
				}
				angels_of_mercy = {
					prev = {
						situation_event = { id = preftl.2020 }
					}
				}
				demonic_invaders = {
					prev = {
						situation_event = { id = preftl.2021 }
					}
				}
				rampant_contagion = {
					prev = {
						situation_event = { id = preftl.2035 }
					}
				}
				survival_fittest = {
					prev = {
						situation_event = { id = preftl.2040 }
					}
				}
				eyes_wide_open = {
					prev = {
						situation_event = { id = preftl.2065 }
					}
				}
			}
		}
	}
}

# Invisible trigger for final events (100% Progress)
situation_event = {
	id = preftl.2005
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_situation_flag = situation_event_progress_100_happened }
	}

	immediate = {
		set_situation_flag = situation_event_progress_100_happened
		owner = {
			switch = {
				trigger = has_country_flag
				apocalypse_now = {
					prev = {
						situation_event = { id = preftl.2051 }
					}
				}
				eyes_wide_open = {
					prev = {
						situation_event = { id = preftl.2065 }
					}
				}
				fervent_belief = {
					prev = {
						situation_event = { id = preftl.2070 }
					}
				}
				lords_of_the_battlefield = {
					prev = {
						situation_event = { id = preftl.2075 }
					}
				}
				overwhelming_demand = {
					prev = {
						situation_event = { id = preftl.2080 }
					}
				}
				power_of_faith = {
					prev = {
						situation_event = { id = preftl.2085 }
					}
				}
				enhanced_immunity = {
					prev = {
						situation_event = { id = preftl.2090 }
					}
				}
				true_prophet = {
					prev = {
						situation_event = { id = preftl.2026}
					}
				}
				brilliant_banner = {
					prev = {
						situation_event = { id = preftl.2031 }
					}
				}
			}
		}
	}
}

# Religious Mania
situation_event = {
	id = preftl.2006
	title = preftl.2006.name
	desc = preftl.2006.desc
	picture = GFX_evt_hive_mind
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		owner = {
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
	}

	option = {
		name = UNDERSTOOD
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
			set_country_flag = religious_mania
		}
	}

	option = {
		trigger = {
			owner = {
				is_spiritualist = yes
			}
		}
		name = preftl.2006.a
		owner = {
			add_modifier = {
				modifier = plague_01_spiritualist
			}
			set_country_flag = true_prophet
		}
		target.owner = {
			add_awareness = 15
		}
	}
}

# Rise of the Warlords
situation_event = {
	id = preftl.2007
	title = preftl.2007.name
	desc = preftl.2007.desc
	picture = GFX_evt_open_revolt
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		owner = {
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
	}

	option = {
		name = UNDERSTOOD
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
			set_country_flag = rise_of_warlords
		}
	}

	option = {
		trigger = {
			owner = {
				OR = {
					is_militarist = yes
					has_valid_civic = civic_machine_warbots
					has_valid_civic = civic_hive_strength_of_legions
				}
			}
		}
		name = preftl.2007.a
		owner = {
			add_modifier = {
				modifier = plague_01_militarist
			}
			set_country_flag = brilliant_banner
		}
		target.owner = {
			add_awareness = 15
		}
	}
}

# Angels of Mercy
situation_event = {
	id = preftl.2008
	title = preftl.2008.name
	desc = preftl.2008.desc
	picture = GFX_evt_emergency_workers
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		owner = {
			set_country_flag = angels_of_mercy
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
	}

	option = {
		name = preftl.2008.a
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
		}
	}
}

# Demonic Invaders
situation_event = {
	id = preftl.2009
	title = preftl.2009.name
	desc = preftl.2009.desc
	picture = GFX_evt_gunrunning
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		owner = {
			set_country_flag = demonic_invaders
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
	}

	option = {
		name = preftl.2008.a
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
		}
	}
}

# Rampant Contagion
situation_event = {
	id = preftl.2010
	title = preftl.2010.name
	desc = preftl.2010.desc
	picture = GFX_evt_ongoing_disaster
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		owner = {
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
	}

	option = {
		name = UNDERSTOOD
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
			set_country_flag = rampant_contagion
		}
		target.owner = {
			while = {
				count = 2
					weighted_random_owned_pop_group = {
						limit = {
							is_robotic_species = no
						}
						kill_single_pop = yes
					}
				}
			capital_scope = {
				add_blocker = {
					type = d_mass_graves
				}
			}
		}
	}

	option = {
		name = preftl.2010.a
		owner = {
			add_resource = {
				energy = -1000
			}
			set_country_flag = eyes_wide_open
		}
		custom_tooltip = tt_end_the_suffering
		target.owner = {
				weighted_random_owned_pop_group = {
					limit = {
						is_robotic_species = no
					}
					kill_single_pop = yes
				}
			capital_scope = {
				add_blocker = {
					type = d_mass_graves
				}
			}
		}
	}
}

# Survival of the Fittest
situation_event = {
	id = preftl.2011
	title = preftl.2011.name
	desc = preftl.2011.desc
	picture = GFX_evt_ongoing_disaster
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		owner = {
			set_country_flag = survival_fittest
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
	}

	option = {
		name = preftl.2011.a
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
		}
		target.owner = {
			if = {
				limit = {
					species = {
						NOT = {
							has_trait = trait_extremely_adaptive
						}
					}
				}
				modify_species = {
					add_trait = trait_extremely_adaptive
				}
			}
			weighted_random_owned_pop_group = {
				limit = {
					is_robotic_species = no
				}
				kill_single_pop = yes
			}
			add_awareness = 15
		}
	}
}

#Overwhelming Demand
situation_event = {
	id = preftl.2020
	title = preftl.2020.name
	desc = preftl.2020.desc
	picture = GFX_evt_ongoing_disaster
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		owner = {
			remove_country_flag = angels_of_mercy
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
	}

	option = {
		name = preftl.2020.a
		owner = {
			add_resource = {
				energy = -500
			}
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
			set_country_flag = overwhelming_demand
		}
	}

	option = {
		name = preftl.2020.b
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			set_country_flag = eyes_wide_open
		}
	}
}

#The Power of Faith
situation_event = {
	id = preftl.2021
	title = preftl.2021.name
	desc = preftl.2021.desc
	picture = GFX_evt_night_raid
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		owner = {
			remove_country_flag = demonic_invaders
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
	}

	option = {
		name = preftl.2020.a
		owner = {
			add_resource = {
				energy = -500
			}
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
			set_country_flag = power_of_faith
		}
	}

	option = {
		name = preftl.2020.b
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			set_country_flag = eyes_wide_open
		}
	}
}

# Messiah Syndrome
situation_event = {
	id = preftl.2025
	title = preftl.2025.name
	desc = preftl.2025.desc
	picture = GFX_evt_shroudwalker_teachers
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		owner = {
			set_country_flag = fervent_belief
			remove_country_flag = religious_mania
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
		target.owner = {
			hidden_effect = {
				every_owned_pop_group = {
					limit = {
						has_any_ethic = yes
					}
					pop_group_add_ethic_effect = {
						POP_GROUP = this
						ETHOS = ethic_spiritualist
						PERCENTAGE = 0.1
						RANDOM = 0.01
					}
				}
			}
		}
	}

	option = {
		name = UNDERSTOOD
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
		}
	}

	option = {
		trigger = {
			owner = {
				is_spiritualist = yes
			}
		}
		name = preftl.2025.a
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
		}
	}
}

# True Prophet
situation_event = {
	id = preftl.2026
	title = preftl.2026.name
	desc = preftl.2026.desc
	picture = GFX_evt_shroudwalker_teachers
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		owner = {
			remove_modifier = plague_01_spiritualist
			remove_country_flag = true_prophet
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
		target.owner = {
			shift_ethic = ethic_spiritualist
			weighted_random_owned_pop_group = {
					limit = {
						has_any_ethic = yes
					}
					pop_group_add_ethic_effect = {
						POP_GROUP = this
						ETHOS = ethic_spiritualist
						AMOUNT = 100
						RANDOM = 25
					}
				}
		}
	}

	option = {
		name = preftl.2026.a
		custom_tooltip = true_prophet_tt
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
			add_modifier = {
				modifier = plague_03_spiritualist
				days = 1080
			}
			create_leader = {
				class = official
				species = root.target.owner.species
				name = random
				skill = 5
				traits = {
					1 = leader_trait_zealot
				}
				event_leader = yes
				effect = {
					set_leader_flag = true_prophet
				}
			}
		}
		target.owner = {
			add_awareness = 15
		}
	}

	after = {
		destroy_situation = this
		target = {
			planet = { remove_carrier_flag = has_on_going_observation_situation }
		}
	}
}

# Ragged Flags
situation_event = {
	id = preftl.2030
	title = preftl.2030.name
	desc = preftl.2030.desc
	picture = GFX_evt_open_revolt
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		owner = {
			set_country_flag = lords_of_the_battlefield
			remove_country_flag = rise_of_warlords
			set_country_flag = society_insights
		}
	}

	option = {
		name = UNFORTUNATE
		target.owner.capital_scope = {
			add_planet_devastation = 30
			add_modifier = {
				modifier = plague_05
				days = 3600
			}
		}
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
		}
	}
}

# Brilliant Banner
situation_event = {
	id = preftl.2031
	title = preftl.2031.name
	desc = preftl.2031.desc
	picture = GFX_evt_victorious_army
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		owner = {
			remove_modifier = plague_01_militarist
			remove_country_flag = brilliant_banner
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
	}

	option = {
		name = preftl.2031.a
		custom_tooltip = brilliant_banner_tt
		owner = {
			create_leader = {
				class = commander
				species = root.target.owner.species
				name = random
				skill = 5
				traits = {
					1 = leader_trait_plague_hardened
				}
				event_leader = yes
			}
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
			add_modifier = {
				modifier = plague_03_militarist
				days = 1080
			}
		}
		target.owner = {
			add_awareness = 15
		}
	}

	after = {
		destroy_situation = this
		target = {
			planet = { remove_carrier_flag = has_on_going_observation_situation }
		}
	}
}

# Apocalypse Now
situation_event = {
	id = preftl.2035
	title = preftl.2035.name
	desc = preftl.2035.desc
	picture = GFX_evt_scanning_remains
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		owner = {
			set_country_flag = apocalypse_now
			remove_country_flag = rampant_contagion
		}
	}

	option = {
		name = EXCELLENT
	}
}

# Enhanced Immunity
situation_event = {
	id = preftl.2040
	title = preftl.2040.name
	desc = preftl.2040.desc
	picture = GFX_evt_vivisection
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		owner = {
			set_country_flag = enhanced_immunity
			remove_country_flag = survival_fittest
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
	}

	option = {
		name = EXCELLENT
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
		}
	}
}

# Changing Circumstances - Observed Planet is No Longer Primitive
situation_event = {
	id = preftl.2049
	title = preftl.2049.name
	desc = preftl.2049.desc
	picture = GFX_evt_ongoing_disaster
	show_sound = event_bad_omen
	is_triggered_only = yes
	location = target

	trigger = {
		owner = {
			NOT = { has_country_flag = apocalypse_now }
		}
	}

	immediate = {
		target = {
			observation_outpost = {
				set_event_locked = no
			}
		}
	}

	option = {
		name = ACKNOWLEDGED
	}

	after = {
		destroy_situation = this
		target = {
			planet = { remove_carrier_flag = has_on_going_observation_situation }
		}
	}
}

# Dead World
situation_event = {
	id = preftl.2051
	title = preftl.2051.name
	desc = preftl.2051.desc
	picture = GFX_evt_relic_world
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		target = {
			#just going to remove everything here, it wont show up on the tooltip if it doesn't exist
			remove_modifier = plague_01_spiritualist
			remove_modifier = plague_01_militarist
			remove_modifier = plague_05
		}
	}

	option = {
		name = EXCELLENT
		custom_tooltip = dead_world_tt
	}

	after = {
		destroy_situation = this
		hidden_effect = {
			owner = {
				remove_country_flag = apocalypse_now
			}
			target = {
				every_owned_pop_group = {
					kill_all_pop = yes
				}
				planet = { remove_carrier_flag = has_on_going_observation_situation }
				destroy_colony = yes
				observation_outpost = {
					dismantle = yes
				}
			}
		}
	}
}

# Invisible event that has a chance of killing a pop every once in a while
situation_event = {
	id = preftl.2061
	hide_window = yes
	is_triggered_only = yes

	weight_multiplier = {
		factor = 1
		modifier = {
			factor = 2
			current_situation_approach = approach_promote_disease
		}
		modifier = {
			factor = 0.5
			current_situation_approach = approach_provide_aid
		}
	}

	immediate = {
		if = {
			limit = {
				target.owner = {
					pop_amount > 200
				}
			}
			target.owner = {
				random_owned_pop_group = {
					limit = {
						is_robotic_species = no
					}
					kill_single_pop = yes
				}
			}
			situation_event = {
				id = preftl.2062
				days = 2
			}
		}
		if = {
			limit = {
				target.owner = {
					pop_amount = 200
				}
			}
			target.owner = {
				random_owned_pop_group = {
					limit = {
						is_robotic_species = no
					}
					kill_single_pop = yes
				}
			}
			situation_event = {
				id = preftl.2063 # They're all dead Jim
				days = 2
			}
		}
	}
}

#Informs player about random deaths on the plague planet
situation_event = {
	id = preftl.2062
	title = preftl.2062.name
	desc = preftl.2062.desc
	picture = GFX_evt_disease_outbreak
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	trigger = {
		owner = {
			NOT = {
				has_country_flag = bring_out_your_dead
			}
		}
	}

	immediate = {
		owner = {
			set_country_flag = bring_out_your_dead
		}
	}

	option = {
		name = UNDERSTOOD
		tooltip = {
			target.owner = {
				random_owned_pop_group = {
					limit = {
						is_robotic_species = no
					}
					kill_single_pop = yes
				}
			}
		}
	}
}

# Silent World - Informs player about an empty plague planet and kills the last pop
situation_event = {
	id = preftl.2063
	title = preftl.2063.name
	desc = preftl.2063.desc
	picture = GFX_evt_disease_outbreak
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		target = {
			observation_outpost = {
				set_event_locked = no
			}
			random_owned_pop_group = {
				limit = {
					is_robotic_species = no
				}
				kill_single_pop = yes
			}
		}
		owner = {
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
	}

	option = {
		name = ACKNOWLEDGED
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
		}
	}

	after = {
		destroy_situation = this
		target = {
			planet = { remove_carrier_flag = has_on_going_observation_situation }
			observation_outpost = {
				dismantle = yes
			}
		}
	}
}

# Minds Wide Open
situation_event = {
	id = preftl.2065
	title = preftl.2065.name
	desc = preftl.2065.desc
	picture = GFX_evt_friendly_enlightenment
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	trigger = {
		owner = {
			has_country_flag = eyes_wide_open
		}
	}

	immediate = {
		owner = {
			remove_country_flag = eyes_wide_open
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
		target = {
			observation_outpost = {
				set_event_locked = no
			}
		}
	}

	option = {
		name = UNDERSTOOD
		custom_tooltip = minds_open_tt
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
		}
		target.owner = {
			add_opinion_modifier = {
				who = root.owner
				modifier = opinion_plague_situation_01
			}
			set_awareness = 100
		}
	}

	after = {
		destroy_situation = this
		target = {
			planet = { remove_carrier_flag = has_on_going_observation_situation }
		}
	}
}

# Fervent Belief
situation_event = {
	id = preftl.2070
	title = preftl.2070.name
	desc = preftl.2070.desc
	picture = GFX_evt_shroudwalker_teachers
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		owner = {
			remove_country_flag = fervent_belief
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
		target = {
			observation_outpost = {
				set_event_locked = no
			}
		}
	}

	option = {
		name = UNDERSTOOD
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier3researchreward
				min = @tier3researchmin
				max = @tier3researchmax
			}
		}
		target.owner = {
			shift_ethic = ethic_spiritualist
			weighted_random_owned_pop_group = {
				limit = {
					has_any_ethic = yes
				}
				pop_group_add_ethic_effect = {
					POP_GROUP = this
					ETHOS = ethic_spiritualist
					AMOUNT = 100
					RANDOM = 25
				}
			}
		}
	}
	option = {
		name = preftl.2026.a
		trigger = {
			owner = {
				has_ethic = ethic_spiritualist
			}
		}
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_modifier = {
				modifier = plague_03_spiritualist
				days = -1
			}
		}
		target.owner = {
			shift_ethic = ethic_spiritualist
			weighted_random_owned_pop_group = {
				limit = {
					has_any_ethic = yes
				}
				pop_group_add_ethic_effect = {
					POP_GROUP = this
					ETHOS = ethic_spiritualist
					AMOUNT = 100
					RANDOM = 25
				}
			}
		}
	}

	after = {
		destroy_situation = this
		target = {
			planet = { remove_carrier_flag = has_on_going_observation_situation }
		}
	}
}

# Lords of the Battlefield
situation_event = {
	id = preftl.2075
	title = preftl.2075.name
	desc = preftl.2075.desc
	picture = GFX_evt_khan_throne_room
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		owner = {
			remove_country_flag = lords_of_the_battlefield
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
		target = {
			observation_outpost = {
				set_event_locked = no
			}
		}
	}

	option = {
		trigger = {
			owner = {
				is_militarist = no
			}
		}
		name = UNDERSTOOD
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier3researchreward
				min = @tier3researchmin
				max = @tier3researchmax
			}
		}
		target = {
			remove_modifier = plague_05
		}
		target.owner = {
			if = {
				limit = {
					NOT = {
						has_ethic = ethic_militarist
					}
				}
				shift_ethic = ethic_militarist
				weighted_random_owned_pop_group = {
					limit = {
						has_any_ethic = yes
					}
					pop_group_add_ethic_effect = {
						POP_GROUP = this
						ETHOS = ethic_militarist
						AMOUNT = 100
						RANDOM = 25
					}
				}
			}
			if = {
				limit = {
					has_ethic = ethic_militarist
				}
				shift_ethic = ethic_fanatic_militarist
				weighted_random_owned_pop_group = {
					limit = {
						has_any_ethic = yes
					}
					pop_group_add_ethic_effect = {
						POP_GROUP = this
						ETHOS = ethic_militarist
						AMOUNT = 100
						RANDOM = 25
					}
				}
			}
			if = {
				limit = {
					has_ethic = ethic_fanatic_militarist
				}
				every_owned_pop_group = {
					limit = {
						has_any_ethic = yes
					}
					pop_group_add_ethic_effect = {
						POP_GROUP = this
						ETHOS = ethic_militarist
						PERCENTAGE = 0.1
						RANDOM = 0.01
					}
				}
			}
		}
	}

	option = {
		trigger = {
			owner = {
				is_militarist = yes
			}
		}
		name = preftl.2031.a
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_modifier = {
				modifier = plague_03_militarist
				days = -1
			}
		}
		target = {
			remove_modifier = plague_05
		}
		target.owner = {
			if = {
				limit = {
					NOT = {
						has_ethic = ethic_militarist
					}
				}
				shift_ethic = ethic_militarist
				weighted_random_owned_pop_group = {
					limit = {
						has_any_ethic = yes
					}
					pop_group_add_ethic_effect = {
						POP_GROUP = this
						ETHOS = ethic_militarist
						AMOUNT = 100
						RANDOM = 25
					}
				}
			}
			if = {
				limit = {
					has_ethic = ethic_militarist
				}
				shift_ethic = ethic_fanatic_militarist
				weighted_random_owned_pop_group = {
					limit = {
						has_any_ethic = yes
					}
					pop_group_add_ethic_effect = {
						POP_GROUP = this
						ETHOS = ethic_militarist
						AMOUNT = 100
						RANDOM = 25
					}
				}
			}
			if = {
				limit = {
					has_ethic = ethic_fanatic_militarist
				}
				weighted_random_owned_pop_group = {
					limit = {
						has_any_ethic = yes
					}
					pop_group_add_ethic_effect = {
						POP_GROUP = this
						ETHOS = ethic_militarist
						PERCENTAGE = 0.1
						RANDOM = 0.01
					}
				}
			}
		}
	}

	after = {
		destroy_situation = this
		target = {
			planet = { remove_carrier_flag = has_on_going_observation_situation }
		}
	}
}

# Grateful Populace
situation_event = {
	id = preftl.2080
	title = preftl.2080.name
	desc = preftl.2080.desc
	picture = GFX_evt_happy_reunion
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		owner = {
			remove_country_flag = overwhelming_demand
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
		target.owner = {
			capital_scope = {
				observation_outpost = {
					set_event_locked = no
				}
			}
		}
	}

	option = {
		name = EXCELLENT
		custom_tooltip = grateful_populace_tt
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier3researchreward
				min = @tier3researchmin
				max = @tier3researchmax
			}
			add_modifier = {
				modifier = plague_02
				days = -1
			}
		}
		target.owner = {
			add_opinion_modifier = {
				who = root.owner
				modifier = opinion_plague_situation_02
			}
			set_awareness = 100
		}
	}

	after = {
		destroy_situation = this
		target = {
			planet = { remove_carrier_flag = has_on_going_observation_situation }
		}
	}
}

# Mass Exorcism
situation_event = {
	id = preftl.2085
	title = preftl.2085.name
	desc = preftl.2085.desc
	picture = GFX_evt_infiltration_failure
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		owner = {
			remove_country_flag = power_of_faith
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
		target = {
			observation_outpost = {
				set_event_locked = no
			}
		}
	}

	option = {
		name = preftl.2085.a
		custom_tooltip = mass_exorcism_tt
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier3researchreward
				min = @tier3researchmin
				max = @tier3researchmax
			}
			add_modifier = {
				modifier = plague_04
				days = 1080
			}
		}
		target.owner = {
			shift_ethic = ethic_xenophobe
			weighted_random_owned_pop_group = {
				limit = {
					has_any_ethic = yes
				}
				pop_group_add_ethic_effect = {
					POP_GROUP = this
					ETHOS = ethic_spiritualist
					AMOUNT = 100
					RANDOM = 25
				}
			}
			weighted_random_owned_pop_group = {
				limit = {
					has_any_ethic = yes
				}
				pop_group_add_ethic_effect = {
					POP_GROUP = this
					ETHOS = ethic_xenophobe
					AMOUNT = 100
					RANDOM = 25
				}
			}
			add_opinion_modifier = {
				who = root.owner
				modifier = opinion_plague_situation_03
			}
			set_awareness = 80
		}
	}

	after = {
		destroy_situation = this
		target = {
			planet = { remove_carrier_flag = has_on_going_observation_situation }
		}
	}
}

# Fountain of Youth
situation_event = {
	id = preftl.2090
	title = preftl.2090.name
	desc = {
		trigger = {
			owner = {
				is_gestalt = no
			}
		}
		text = preftl.2090.desc
	}
	desc = {
		trigger = {
			owner = {
				is_hive_empire = yes
			}
			NOT = {
				owner = {
					is_machine_empire = yes
				}
			}
		}
		text = preftl.2090.desc.hive
	}
	desc = {
		trigger = {
			owner = {
				is_machine_empire = yes
			}
		}
		text = preftl.2090.desc.machine
	}
	picture = GFX_evt_scientific_experiments
	show_sound = event_wind_ruins
	is_triggered_only = yes
	location = target
	situation = this

	immediate = {
		owner = {
			remove_country_flag = enhanced_immunity
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
		target = {
			observation_outpost = {
				set_event_locked = no
			}
		}
	}

	option = {
		trigger = {
			owner = {
				NOT = {
					is_machine_empire = yes
				}
			}
		}
		name = preftl.2090.a
		owner = {
			add_modifier = {
				modifier = young_leaders
				days = -1
			}
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier3researchreward
				min = @tier3researchmin
				max = @tier3researchmax
			}
		}
	}

	option = {
		trigger = {
			NOT = {
				owner = {
					is_machine_empire = yes
				}
			}
		}
		name = preftl.2090.b
		owner = {
			add_modifier = {
				modifier = young_people
				days = -1
			}
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier3researchreward
				min = @tier3researchmin
				max = @tier3researchmax
			}
		}
	}

	option = {
		trigger = {
			owner = {
				is_machine_empire = yes
			}
		}
		name = EXCELLENT
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier4researchreward
				min = @tier4researchmin
				max = @tier4researchmax
			}
		}
	}

	after = {
		destroy_situation = this
		target = {
			planet = { remove_carrier_flag = has_on_going_observation_situation }
		}
	}
}


### Observation Post Situation - Organic Singularity

# Trigger event for Organic Singularity

situation_event = {
	id = preftl.2100
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_first_contact_dlc = yes
		owner = {
			is_gestalt = no
			current_awareness_level < full
			has_blocked_random_devastating_pre_ftl_events = no
		}
	}

	immediate = {
		owner.capital_scope = {
			if = {
				limit = {
					exists = observation_outpost_owner
				}
				observation_outpost_owner = {
					country_event = { id = preftl.2101 }
				}
				observation_outpost = {
					set_event_locked = yes
				}
			}
		}
	}
}

# Starting event
country_event = {
	id = preftl.2101
	title = preftl.2101.name
	desc = {
		trigger = {
			has_policy_flag = interference_not_allowed
		}
		text = preftl.2101.can_not_help.desc
	}
	desc = {
		trigger = {
			NOT = { has_policy_flag = interference_not_allowed  }
		}
		text = preftl.2101.desc
	}
	picture = GFX_evt_ongoing_disaster
	show_sound = event_bad_omen
	is_triggered_only = yes
	location = from.owner.capital_scope
	situation = event_target:singularity_situation

	trigger = {
		NOR = {
			has_country_flag = preftl_2100_fired
			has_country_flag = had_observation_situation
		}
	}

	immediate = {
		set_country_flag = preftl_2100_fired
		set_country_flag = had_observation_situation
		start_situation = {
			type = situation_pre_ftl_singularity
			target = from.owner.capital_scope
			effect = {
				save_event_target_as = singularity_situation
			}
		}
	}

	option = { # Watch
		name = preftl.2101.a
		icon = {
			icon = GFX_situation_approach_research
			icon_background = GFX_situation_approach_bg_yellow
			text = set_situation_approach_icon_text
		}
		event_target:singularity_situation = {
			set_situation_approach = approach_watch_singularity
		}
	}
	option = { # Prevent Singularity
		name = preftl.2101.b
		icon = {
			icon = GFX_situation_approach_genetics
			icon_background = GFX_situation_approach_bg_yellow
			text = set_situation_approach_icon_text
		}
		if = {
			limit = {
				has_policy_flag = interference_not_allowed
			}
			set_policy = {
				policy = interference
				option = interference_active
				cooldown = yes
			}
		}
		event_target:singularity_situation = {
			set_situation_approach = approach_prevent_singularity
		}
	}
	option = { # Promote Singularity
		name = preftl.2101.c
		icon = {
			icon = GFX_situation_approach_genetics
			icon_background = GFX_situation_approach_bg_yellow
			text = set_situation_approach_icon_text
		}
		if = {
			limit = {
				has_policy_flag = interference_not_allowed
			}
			set_policy = {
				policy = interference
				option = interference_active
				cooldown = yes
			}
		}
		event_target:singularity_situation = {
			set_situation_approach = approach_promote_singularity
		}
	}
	after = {
		hidden_effect = {
			event_target:singularity_situation = {
				set_situation_locked = no
			}
		}
	}
}

# Invisible trigger - 15% Progress
situation_event = {
	id = preftl.2102
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		situation_progress >= 15
		current_situation_approach = approach_prevent_singularity
		NOT = { has_situation_flag = situation_event_progress_15_happened }
	}

	immediate = {
		set_situation_flag = situation_event_progress_15_happened
		situation_event = { id = preftl.2110 }
	}
}

# Invisible trigger - 20% Progress
situation_event = {
	id = preftl.2103
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		situation_progress >= 20
		NOR = {
			current_situation_approach = approach_prevent_singularity
			has_situation_flag = situation_event_progress_20_happened
		}
	}

	immediate = {
		set_situation_flag =  situation_event_progress_20_happened
		if = {
			limit = {
				current_situation_approach = approach_watch_singularity
			}
			situation_event = { id = preftl.2115 }
		}
		if = {
			limit = {
				current_situation_approach = approach_promote_singularity
			}
			situation_event = { id = preftl.2120 }
		}
	}
}

# Invisible trigger - 40% Progress
situation_event = {
	id = preftl.2104
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		situation_progress >= 40
		NOT = { has_situation_flag = situation_event_progress_40_happened }
		current_situation_approach = approach_watch_singularity
	}

	immediate = {
		situation_event = { id = preftl.2120 }
		set_situation_flag = situation_event_progress_40_happened
	}
}

# Invisible trigger - 50% Progress
situation_event = {
	id = preftl.2105
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		situation_progress >= 50
		NOR = {
			current_situation_approach = approach_watch_singularity
			has_situation_flag = situation_event_progress_50_happened
		}
	}

	immediate = {
		set_situation_flag = situation_event_progress_50_happened
		if = {
			limit = {
				current_situation_approach = approach_prevent_singularity
			}
			situation_event = { id = preftl.2125 }
		}
		if = {
			limit = {
				current_situation_approach = approach_promote_singularity
			}
			situation_event = { id = preftl.2130 }
		}
	}
}

# Invisible trigger - 80% Progress
situation_event = {
	id = preftl.2106
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		situation_progress >= 80
		NOR = {
			current_situation_approach = approach_prevent_singularity
			has_situation_flag = situation_event_progress_80_happened
		}
	}

	immediate = {
		set_situation_flag = situation_event_progress_80_happened
		if = {
			limit = {
				current_situation_approach = approach_watch_singularity
			}
			situation_event = { id = preftl.2135 }
		}
		if = {
			limit = {
				current_situation_approach = approach_promote_singularity
			}
			situation_event = { id = preftl.2145 }
		}
	}
}

# 100% Progress
situation_event = {
	id = preftl.2107
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_situation_flag = situation_event_progress_100_happened }
	}

	immediate = {
		set_situation_flag = situation_event_progress_100_happened
		if = {
			limit = {
				current_situation_approach = approach_watch_singularity
			}
			random_list = {
				60 = {
					situation_event = { id = preftl.2136 }
				}
				40 = {
					situation_event = { id = preftl.2140 }
				}
			}
		}
		if = {
			limit = {
				current_situation_approach = approach_prevent_singularity
			}
			random_list = {
				90 = {
					situation_event = { id = preftl.2150 }
				}
				10 = {
					modifier = {
						factor = 0
						target.owner = {
							current_awareness_level = full
						}
					}
					situation_event = { id = preftl.2155 }
				}
			}
		}
		if = {
			limit = {
				current_situation_approach = approach_promote_singularity
			}
			situation_event = { id = preftl.2160 }
		}
	}
}

# Blissful Ignorance
situation_event = {
	id = preftl.2110
	title = preftl.2110.name
	desc = preftl.2110.desc
	picture = GFX_evt_medieval_alien_civilization
	show_sound = event_laboratory_sound
	location = target
	situation = this

	is_triggered_only = yes

	trigger = {
		situation_progress >= 15
		current_situation_approach = approach_prevent_singularity
		NOT = {
			has_situation_flag = stifled_singularity
		}
	}


	immediate = {
		set_situation_flag = stifled_singularity
		owner = {
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
	}

	option = {
		name = preftl.2110.a
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
		}
	}
}

# Biological Calculators
situation_event = {
	id = preftl.2115
	title = preftl.2115.name
	desc = preftl.2115.desc
	picture = GFX_evt_microscopic_life
	show_sound = event_laboratory_sound
	location = target
	situation = this

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_situation_flag = biological_calculators
		}
	}

	immediate = {
		set_situation_flag = biological_calculators
		owner = {
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
	}

	option = {
		name = FASCINATING
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
		}
		target = {
			add_modifier = {
				modifier = singularity_situation_06
				days = -1
			}
		}
	}
}

# Exponential Growth
situation_event = {
	id = preftl.2120
	title = preftl.2120.name
	desc = preftl.2120.desc
	picture = GFX_evt_infested
	show_sound = event_laboratory_sound
	location = target
	situation = this

	is_triggered_only = yes

	immediate = {
		owner = {
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
	}

	trigger = {
		OR = {
			AND = {
				situation_progress >= 20
				current_situation_approach = approach_promote_singularity
			}
			AND = {
				situation_progress >= 40
				current_situation_approach = approach_watch_singularity
			}
		}
		NOT = {
			has_situation_flag = exponential_growth
		}
	}

	option = {
		name = FASCINATING
		target.owner = {
			if = {
				limit = {
					any_owned_species = {
						is_archetype = LITHOID
					}
				}
				capital_scope = {
					add_modifier = {
						modifier = singularity_situation_01
						days = -1
					}
				}
			}
			else_if = {
				limit = {
					any_owned_species = {
						NOT = {
							is_archetype = LITHOID
						}
					}
				}
				capital_scope = {
					add_modifier = {
						modifier = singularity_situation_02
						days = -1
					}
				}
			}
		}
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
		}
	}

	after = {
		set_situation_flag = exponential_growth
	}
}

# Suspicious Minds
situation_event = {
	id = preftl.2125
	title = preftl.2125.name
	desc = preftl.2125.desc
	picture = GFX_evt_microscopic_life
	show_sound = event_bad_omen
	location = target
	situation = this

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_situation_flag = suspicious_minds
		}
	}

	option = {
		name = UNDERSTOOD
		owner = {
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
		}
		target.owner = {
			add_awareness = 15
		}
	}

	after = {
		set_situation_flag = suspicious_minds
	}
}

# Organic Idyll
situation_event = {
	id = preftl.2130
	title = preftl.2130.name
	desc = preftl.2130.desc
	picture = {
		trigger = {
			target = {
				is_planet_class = pc_desert
			}
		}
		picture = GFX_evt_desert
	}
	picture = {
		trigger = {
			target = {
				is_planet_class = pc_tropical
			}
		}
		picture = GFX_evt_tropical
	}
	picture = {
		trigger = {
			target = {
				is_planet_class = pc_arid
			}
		}
		picture = GFX_evt_arid
	}
	picture = {
		trigger = {
			target = {
				OR = {
					is_planet_class = pc_continental
					is_planet_class = pc_alpine
					is_planet_class = pc_savannah
				}
			}
		}
		picture = GFX_evt_continental
	}
	picture = {
		trigger = {
			target = {
				is_planet_class = pc_ocean
			}
		}
		picture = GFX_evt_ocean
	}
	picture = {
		trigger = {
			target = {
				is_planet_class = pc_tundra
			}
		}
		picture = GFX_evt_tundra
	}
	picture = {
		trigger = {
			target = {
				is_planet_class = pc_arctic
			}
		}
		picture = GFX_evt_arctic
	}
	picture = {
		trigger = {
			target = {
				is_planet_class = pc_gaia
			}
		}
		picture = GFX_evt_gaia
	}
	picture = {
		trigger = {
			target = {
				is_planet_class = pc_nuked
			}
		}
		picture = GFX_evt_tomb_world
	}
	show_sound = event_bad_omen
	location = target
	situation = this

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_situation_flag = organic_idyll
		}
	}

	immediate = {
		owner = {
			set_country_flag = society_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
	}

	option = {
		name = EXCELLENT
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
		}
		target.owner = {
			add_awareness = 10
		}
	}

	after = {
		set_situation_flag = organic_idyll
	}
}

# Uneasy Synergy
situation_event = {
	id = preftl.2135
	title = preftl.2135.name
	desc = preftl.2135.desc
	picture = GFX_evt_scientific_experiments
	show_sound = event_laboratory_sound
	location = target
	situation = this

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_situation_flag = uneasy_synergy
		}
	}

	immediate = {
		owner = {
			set_country_flag = engineering_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
	}

	option = {
		name = UNDERSTOOD
		target = {
			add_modifier = {
				modifier = singularity_situation_05
			}
		}
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = engineering_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
		}
	}

	after = {
		set_situation_flag = uneasy_synergy
	}
}

# Thriving Union
situation_event = {
	id = preftl.2136
	title = preftl.2136.name
	desc = {
		trigger = {
			target.owner = {
				has_pre_ftl_age = early_space_age
			}
		}
		text = preftl.2136.ftl.desc
	}
	desc = {
		trigger = {
			target.owner = {
				NOT = {
					has_pre_ftl_age = early_space_age
				}
			}
		}
		text = preftl.2136.preftl.desc
	}
	picture = GFX_evt_animal_wildlife
	show_sound = event_mystic_reveal
	location = target
	situation = this

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_situation_flag = thriving_union
		}
	}

	immediate = {
		set_situation_flag = thriving_union
		target.owner = {
			save_event_target_as = thriving_preftls
		}
		if = {
			limit = {
				target.owner = {
					NOT = {
						has_pre_ftl_age = early_space_age
					}
				}
			}
			target.owner = {
				random_situation = {
					limit = {
						is_situation_type = pre_ftl_tech_progress_situation
					}
					add_situation_progress = 2000
				}
			}
		}
		else = {
			target.owner = { # Flips control of the starbase to the new spacefaring civilization
				achieve_ftl_effect = {
					PRE_FTL = root.target.owner
					OWNER = root.owner
				}
				solar_system = {
					if = {
						limit = { exists = starbase }
						starbase = {
							set_owner = event_target:thriving_preftls
							if = {
								limit = { has_starbase_size = starbase_outpost }
								set_starbase_size = starbase_starport
								set_starbase_module = {
									slot = 1
									module = shipyard
								}
								set_starbase_module = {
									slot = 2
									module = shipyard
								}
							}
							else_if = {
								limit = {
									NOT = { has_starbase_module = shipyard }
								}
								set_starbase_module = {
									slot = 1
									module = shipyard
								}
								set_starbase_module = {
									slot = 2
									module = shipyard
								}
							}
						}
					}
					else = {
						create_starbase = {
							size = starbase_starport
							module = shipyard
							module = shipyard
							owner = event_target:thriving_preftls
						}
					}
					every_fleet_in_system = {
						limit = {
							owner = { NOT = { is_same_value = event_target:thriving_preftls } }
							is_mobile = yes
						}
						set_mia = mia_return_home
					}
					add_claims = {
						who = root.owner
						num_of_claims = 1
						show_notification = no
					}
				}
			}
		}
		target.observation_outpost = {
			set_event_locked = no
			dismantle = yes
		}
		target = {
			remove_modifier = singularity_situation_01
			remove_modifier = singularity_situation_02
			remove_modifier = singularity_situation_05
			remove_modifier = singularity_situation_06
			owner = {
				random_situation = {
					limit = {
						is_situation_type = pre_ftl_tech_progress_situation
					}
					add_situation_progress = 2000
				}
			}
		}
		owner = {
			set_country_flag = engineering_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
	}

	option = {
		name = {
			trigger = {
				target.owner = {
					is_primitive = yes
				}
			}
			text = FASCINATING
		}
		name = {
			trigger = {
				target.owner = {
					is_primitive = no
				}
				owner = {
					values_others = no
				}
			}
			text = preftl.2136.a
		}
		name = {
			trigger = {
				target.owner = {
					is_primitive = no
				}
				owner = {
					values_others = yes
				}
			}
			text = preftl.2136.b
		}
		custom_tooltip = thriving_union_tt
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = engineering_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
		}
	}

	after = {
		destroy_situation = this
		owner = {
			remove_country_flag = had_observation_situation
			set_timed_country_flag = {
				flag = had_observation_situation
				days = 7200
			}
		}
		target = {
			planet = { remove_carrier_flag = has_on_going_observation_situation }
		}
	}
}

# Organic Singularity
situation_event = {
	id = preftl.2140
	title = preftl.2140.name
	desc = preftl.2140.desc
	picture = GFX_evt_progenitor_throne
	show_sound = event_screams
	location = target
	situation = this

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_situation_flag = organic_singularity
		}
	}

	immediate = {
		set_situation_flag = organic_singularity
		target = {
			remove_modifier = singularity_situation_01
			remove_modifier = singularity_situation_02
			remove_modifier = singularity_situation_05
			observation_outpost = {
				set_event_locked = no
			}
		}
		owner = {
			set_country_flag = engineering_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
	}

	option = {
		name = {
			trigger = {
				owner = {
					is_gestalt = yes
				}
			}
			text = preftl.2140.a
		}
		name = {
			trigger = {
				owner = {
					is_gestalt = no
				}
			}
			text = FASCINATING
		}
		target.owner = {
			if = {
				limit = {
					is_fanatic_authoritarian = no
				}
				shift_ethic = ethic_fanatic_authoritarian
			}
			set_policy = {
				policy = slavery
				option = slavery_allowed
				cooldown = yes
			}
		}
		target = {
			add_modifier = {
				modifier = singularity_situation_07
				days = -1
			}
		}
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = engineering_research
				value = @tier3researchreward
				min = @tier3researchmin
				max = @tier3researchmax
			}
		}
	}

	after = {
		destroy_situation = this
		owner = {
			remove_country_flag = had_observation_situation
			set_timed_country_flag = {
				flag = had_observation_situation
				days = 7200
			}
		}
		target = {
			planet = { remove_carrier_flag = has_on_going_observation_situation }
		}
	}
}

# Alternate Agenda
situation_event = {
	id = preftl.2145
	title = preftl.2145.name
	desc = preftl.2145.desc
	picture = GFX_evt_alien_nature
	show_sound = event_laboratory_sound
	location = target
	situation = this

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_situation_flag = alternate_agenda
		}
	}

	immediate = {
		owner = {
			set_country_flag = engineering_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
	}

	option = {
		name = preftl.2145.a
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = engineering_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
		}
		target = {
			add_modifier = {
				modifier = singularity_situation_05
			}
		}
	}

	after = {
		set_situation_flag = alternate_agenda
	}
}

# At Least They're Edible
situation_event = {
	id = preftl.2150
	title = preftl.2150.name
	desc = preftl.2150.desc
	picture = GFX_evt_analyzing_artifacts
	show_sound = event_finding_loot
	location = target
	situation = this

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_situation_flag = edible_computers
		}
	}

	immediate = {
		set_situation_flag = edible_computers
		target = {
			remove_modifier = singularity_situation_01
			remove_modifier = singularity_situation_02
			remove_modifier = singularity_situation_05
			remove_modifier = singularity_situation_06
			observation_outpost = {
				set_event_locked = no
			}
		}
		owner = {
			set_country_flag = engineering_insights
		}
	}

	option = {
		name = preftl.2150.a
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = engineering_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
		}
		target =  {
			if = {
				limit = {
					owner = {
						any_owned_species = {
							is_archetype = LITHOID
						}
					}
				}
				owner.capital_scope = { #showcases location in tooltip
					add_modifier = {
						modifier = singularity_situation_03
						days = -1
					}
				}
			}
			else = {
				owner.capital_scope = { #showcases location in tooltip
					add_modifier = {
						modifier = singularity_situation_04
						days = -1
					}
				}
			}
		}
	}

	after = {
		destroy_situation = this
		owner = {
			remove_country_flag = had_observation_situation
			set_timed_country_flag = {
				flag = had_observation_situation
				days = 7200
			}
		}
		target = {
			planet = { remove_carrier_flag = has_on_going_observation_situation }
		}
	}
}

# Accidental Outbreak
situation_event = {
	id = preftl.2155
	title = preftl.2155.name
	desc = preftl.2155.desc
	picture = GFX_evt_disease_outbreak
	show_sound = event_screams
	location = target
	situation = this

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_situation_flag = accidental_outbreak
		}
	}

	immediate = {
		set_situation_flag = accidental_outbreak
		target = {
			remove_modifier = singularity_situation_01
			remove_modifier = singularity_situation_02
			remove_modifier = singularity_situation_05
			remove_modifier = singularity_situation_06
			observation_outpost = {
				set_event_locked = no
			}
			owner.capital_scope.planet = {
				save_event_target_as = accidental_outbreak_planet
			}
		}
		owner = {
			set_country_flag = outbreak_perpetrator
			set_country_flag = engineering_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
			country_event = {
				id = preftl.2001
				days = 10
			}
		}
	}

	option = {
		name = UNFORTUNATE
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
		}
	}

	after = {
		destroy_situation = this
		owner = {
			remove_country_flag = had_observation_situation
		}
		target = {
			planet = {
				remove_carrier_flag = has_on_going_observation_situation
			}
		}
	}
}

# Communion
situation_event = {
	id = preftl.2160
	title = preftl.2160.name
	desc = preftl.2160.desc
	picture = GFX_evt_progenitor_throne
	show_sound = event_bad_omen
	location = target
	situation = this

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_situation_flag = singular_communion
		}
	}

	immediate = {
		set_situation_flag = singular_communion
		target.observation_outpost = {
			set_event_locked = no
		}
		owner = {
			set_country_flag = engineering_insights
			set_predictive_observation_insight = {
				VALUE = 10
			}
		}
	}

	option = {
		name = EXCELLENT
		custom_tooltip = preftl.2160.tt
		owner = {
			add_observation_insight_effect = {
				VALUE = 10
				OUTPOST = root.target.observation_outpost
			}
			add_monthly_resource_mult = {
				resource = engineering_research
				value = @tier3researchreward
				min = @tier3researchmin
				max = @tier3researchmax
			}
		}
		hidden_effect = {
			target = {
				remove_modifier = singularity_situation_01
				remove_modifier = singularity_situation_02
				remove_modifier = singularity_situation_05
				remove_modifier = singularity_situation_06
				remove_all_buildings = yes
				planet = { set_carrier_flag = organic_singularity_communion } #To avoid clash with observation event Nascent Collective
			}

			target.owner = {
				shift_ethic = ethic_gestalt_consciousness
				change_government = {
					authority = auth_hive_mind
					remove_invalid_civics = yes
					civics = random
				}
				species = {
					modify_species = {
						species = this
						add_trait = trait_hive_mind
						remove_trait = trait_self_modified
						remove_trait = trait_latent_psionic
						remove_trait = trait_robot_latent_psionic
						remove_trait = trait_psionic
						remove_trait = trait_robot_psionic
						change_scoped_species = no

						effect = {
							save_event_target_as = convert_to_species
						}
					}
				}
				set_country_flag = organic_singularity_communion # To identify this country in 'abort' blocks, such as for Espionage Operations

				every_owned_pop_group = {
					limit = {
						is_robotic_species = no
					}
					change_species = event_target:convert_to_species
				}

				ruler = {
					kill_leader = { show_notification = no }
				}

				add_pre_ftl_buildings = yes

				random_list = {
					20 = {
						if = {
							limit = {
								owner = {
									NOT = {
										has_valid_civic = civic_hive_devouring_swarm
									}
								}
							}
							change_government = {
								civics = {
									civic = civic_hive_devouring_swarm
								}
							}
						}
					}
					80 = { }
				}
			}
		}
	}

	after = {
		destroy_situation = this
		target = {
			check_planet_employment = yes
			planet = { remove_carrier_flag = has_on_going_observation_situation }
		}
		owner = {
			remove_country_flag = had_observation_situation
			set_timed_country_flag = {
				flag = had_observation_situation
				days = 7200
			}
		}
	}
}

# Abort Ending
situation_event = {
	id = preftl.2165
	title = preftl.2165.name
	desc = preftl.2165.desc
	picture = GFX_evt_overgrown_city
	show_sound = event_bad_omen
	location = event_target:singularity_planet
	situation = this
	is_triggered_only = yes

	trigger = {
		exists = event_target:singularity_planet # failsafe if the planet is destroyed
	}

	immediate = {
		event_target:singularity_planet = {
			remove_modifier = singularity_situation_01
			remove_modifier = singularity_situation_02
			remove_modifier = singularity_situation_05
			remove_modifier = singularity_situation_06
			if = {
				limit = {
					has_observation_outpost = yes
				}
				observation_outpost = {
					set_event_locked = no
				}
			}
		}
	}

	option = {
		name = UNDERSTOOD
	}

	after = {
		event_target:singularity_planet.owner = {
			remove_country_flag = had_observation_situation
			set_timed_country_flag = {
				flag = had_observation_situation
				days = 7200
			}
		}
	}
}

# Hidden event to remove modifier on Singularity planet if it changes hands

carrier_event = {
	id = preftl.2171
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_modifier = singularity_situation_07
		original_owner = no
	}

	immediate = {
		remove_modifier = singularity_situation_07
	}
}

# Observation Situation - New World Order - Starting Event

# Trigger event for New World Order

# target = Tech Progress Situation on Pre-FTL Planet
# target.owner = the Pre-FTL Planet being observed

situation_event = {
	id = preftl.2166
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_first_contact_dlc = yes
		NOT = {
			has_global_flag = ongoing_nwo_situation
		}
		owner = {
			is_gestalt = no
			has_blocked_random_devastating_pre_ftl_events = no
			NOT = {
				has_pre_ftl_age = stone_age
			}
			capital_scope = {
				has_observation_outpost = yes
				observation_outpost_owner = {
					NOR = {
						has_country_flag = preftl.2166_fired
						has_country_flag = had_observation_situation
					}
				}
			}
		}
	}

	immediate = {
		owner.capital_scope = {
			observation_outpost_owner = {
				country_event = { id = preftl.2167 }
			}
			observation_outpost = {
				set_event_locked = yes
			}
		}
	}
}

# Starting event
country_event = {
	id = preftl.2167
	title = preftl.2167.name
	desc = {
		trigger = {
			has_policy_flag = interference_not_allowed
		}
		text = preftl.2167.can_not_help.desc
	}
	desc = {
		trigger = {
			NOT = { has_policy_flag = interference_not_allowed  }
		}
		text = preftl.2167.desc
	}
	picture = GFX_evt_open_revolt
	show_sound = event_bad_omen
	is_triggered_only = yes
	location = from.owner.capital_scope
	situation = event_target:nwo_situation

	immediate = {
		set_country_flag = preftl.2166_fired
		set_timed_country_flag = {
			flag = had_observation_situation
			days = 5400
		}
		set_global_flag = ongoing_nwo_situation
		owner = {
			start_situation = {
				type = situation_pre_ftl_nwo
				target = from.owner.capital_scope
				effect = {
					save_event_target_as = nwo_situation
				}
			}
		}
		from.owner = {
			create_leader = {
				class = commander
				species = from.owner.species
				name = random
				skill = 4
				traits = {
					1 = leader_trait_iron_fist
				}
			}
			last_created_leader = {
				set_age = 1
			}
			set_leader = last_created_leader
		}
	}

	option = { # Watch
		name = preftl.2167.a
		icon = {
			icon = GFX_situation_approach_research
			icon_background = GFX_situation_approach_bg_yellow
			text = set_situation_approach_icon_text
		}
		event_target:nwo_situation = {
			set_situation_approach = approach_watch_nwo
		}
	}

	option = { # Aid Leader
		name = preftl.2167.b
		icon = {
			icon = GFX_situation_approach_influence
			icon_background = GFX_situation_approach_bg_yellow
			text = set_situation_approach_icon_text
		}
		if = {
			limit = {
				has_policy_flag = interference_not_allowed
			}
			set_policy = {
				policy = interference
				option = interference_active
				cooldown = yes
			}
		}
		event_target:nwo_situation = {
			set_situation_approach = approach_aid_leader
		}
	}

	option = { # Aid Rebels
		name = preftl.2167.c
		icon = {
			icon = GFX_situation_approach_suspicious
			icon_background = GFX_situation_approach_bg_yellow
			text = set_situation_approach_icon_text
		}
		if = {
			limit = {
				has_policy_flag = interference_not_allowed
			}
			set_policy = {
				policy = interference
				option = interference_active
				cooldown = yes
			}
		}
		event_target:nwo_situation = {
			set_situation_approach = approach_aid_rebels
		}
	}

	after = {
		hidden_effect = {
			event_target:nwo_situation = {
				set_situation_locked = no
			}
		}
	}
}

# Consolidation
situation_event = {
	id = preftl.2170
	title = preftl.2170.name
	desc = preftl.2170.desc
	picture = GFX_evt_archaeologists_escaping
	show_sound = event_screams
	location = target
	situation = this

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_situation_flag = consolidation_nwo
		}
	}


	immediate = {
		set_situation_flag = consolidation_nwo
		target = {
			add_planet_devastation = 50
		}
	}

	option = {
		name = UNDERSTOOD
		tooltip = {
			target = {
				add_planet_devastation = 50
			}
		}
	}

	option = {
		trigger = {
			current_situation_approach = approach_aid_rebels
		}
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = alloys
					value >= 200
				}
				resource_stockpile_compare = {
					resource = minerals
					value >= 500
				}
				resource_stockpile_compare = {
					resource = energy
					value >= 500
				}
			}
		}
		name = preftl.2170.a
		set_situation_flag = aid_rebels_01
		owner = {
			add_resource = {
				alloys = -200
				minerals = -500
				energy = -500
			}
		}
		tooltip = {
			target = {
				add_planet_devastation = 50
			}
		}
		custom_tooltip = increase_aid_tt
	}

	option = {
		trigger = {
			current_situation_approach = approach_aid_leader
		}
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = alloys
					value >= 200
				}
				resource_stockpile_compare = {
					resource = minerals
					value >= 500
				}
				resource_stockpile_compare = {
					resource = energy
					value >= 500
				}
			}
		}
		name = preftl.2170.b
		owner = {
			add_resource = {
				alloys = -200
				minerals = -500
				energy = -500
			}
		}
		set_situation_flag = aid_leader_01
		tooltip = {
			target = {
				add_planet_devastation = 50
			}
		}
		custom_tooltip = increase_aid_tt
	}
}

# War Crimes
situation_event = {
	id = preftl.2175
	title = preftl.2175.name
	desc = preftl.2175.desc
	picture = GFX_evt_archaeologists_escaping
	show_sound = event_screams
	location = target
	situation = this

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_situation_flag = war_crimes_nwo
		}
	}


	immediate = {
		set_situation_flag = war_crimes_nwo
		target = {
			add_planet_devastation = 50
		}
	}

	option = {
		name = UNDERSTOOD
		tooltip = {
			target = {
				add_planet_devastation = 50
			}
		}
	}

	option = {
		trigger = {
			current_situation_approach = approach_aid_rebels
		}
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = alloys
					value >= 200
				}
				resource_stockpile_compare = {
					resource = minerals
					value >= 500
				}
				resource_stockpile_compare = {
					resource = energy
					value >= 500
				}
			}
		}
		name = preftl.2175.a
		set_situation_flag = aid_rebels_02
		owner = {
			add_resource = {
				alloys = -200
				minerals = -500
				energy = -500
			}
		}
		tooltip = {
			target = {
				add_planet_devastation = 50
			}
		}
		custom_tooltip = increase_aid_tt
	}

	option = {
		trigger = {
			current_situation_approach = approach_aid_leader
		}
		name = preftl.2175.b
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = alloys
					value >= 200
				}
				resource_stockpile_compare = {
					resource = minerals
					value >= 500
				}
				resource_stockpile_compare = {
					resource = energy
					value >= 500
				}
			}
		}
		set_situation_flag = aid_leader_02
		owner = {
			add_resource = {
				alloys = -200
				minerals = -500
				energy = -500
			}
		}
		tooltip = {
			target = {
				add_planet_devastation = 50
			}
		}
		custom_tooltip = increase_aid_tt
	}
}

# Fat and Happy
situation_event = {
	id = preftl.2180
	title = preftl.2180.name
	desc = {
		trigger = {
			has_situation_flag = consolidation_nwo
		}
		text = preftl.2180.a.desc
	}
	desc = {
		trigger = {
			has_situation_flag = war_crimes_nwo
		}
		text = preftl.2180.b.desc
	}
	picture = GFX_evt_enlightenment_failure
	show_sound = event_screams
	location = target
	situation = this

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_situation_flag = fat_and_happy_nwo
		}
	}

	immediate = {
		set_situation_flag = fat_and_happy_nwo
		target = {
			add_planet_devastation = 20
		}
		if = {
			limit = {
				target.owner = {
					NOT = {
						current_awareness_level = full
					}
				}
			}
			owner = {
				set_country_flag = society_insights
				set_predictive_observation_insight = {
					VALUE = 10
				}
			}
		}
	}

	option = {
		name = UNDERSTOOD
		tooltip = {
			target = {
				add_planet_devastation = 20
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
		}
		if = {
			limit = {
				target.owner = {
					NOT = {
						current_awareness_level = full
					}
				}
			}
			owner = {
				add_observation_insight_effect = {
					VALUE = 10
					OUTPOST = root.target.observation_outpost
				}
			}
		}
	}

	option = {
		trigger = {
			current_situation_approach = approach_aid_rebels
		}
		name = preftl.2180.a
		set_situation_flag = aid_rebels_03
		tooltip = {
			target = {
				add_planet_devastation = 20
			}
		}
		custom_tooltip = increase_aid_tt
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = influence
					value >= 200
				}
			}
		}
		owner = {
			add_resource = {
				influence = -200
			}
		}
	}

	option = {
		trigger = {
			current_situation_approach = approach_aid_leader
		}
		name = preftl.2180.b
		set_situation_flag = aid_leader_03
		tooltip = {
			target = {
				add_planet_devastation = 20
			}
		}
		custom_tooltip = increase_aid_tt
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = influence
					value >= 200
				}
			}
		}
		owner = {
			add_resource = {
				influence = -200
			}
		}
	}
}

# Suppress and Destroy
situation_event = {
	id = preftl.2185
	title = preftl.2185.name
	desc = {
		trigger = {
			has_situation_flag = consolidation_nwo
		}
		text = preftl.2185.a.desc
	}
	desc = {
		trigger = {
			has_situation_flag = war_crimes_nwo
		}
		text = preftl.2185.b.desc
	}
	picture = GFX_evt_burning_city
	show_sound = event_screams
	location = target
	situation = this

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_situation_flag = suppress_destroy_nwo
		}
	}

	immediate = {
		set_situation_flag = suppress_destroy_nwo
		target = {
			add_planet_devastation = 20
		}
		if = {
			limit = {
				target.owner = {
					NOT = {
						current_awareness_level = full
					}
				}
			}
			owner = {
				set_country_flag = society_insights
				set_predictive_observation_insight = {
					VALUE = 10
				}
			}
		}
	}

	option = {
		name = UNFORTUNATE
		tooltip = {
			target = {
				add_planet_devastation = 20
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
		}
		if = {
			limit = {
				target.owner = {
					NOT = {
						current_awareness_level = full
					}
				}
			}
			owner = {
				add_observation_insight_effect = {
					VALUE = 10
					OUTPOST = root.target.observation_outpost
				}
			}
		}
	}

	option = {
		trigger = {
			current_situation_approach = approach_aid_rebels
		}
		name = preftl.2185.a
		set_situation_flag = aid_rebels_04
		tooltip = {
			target = {
				add_planet_devastation = 20
			}
		}
		custom_tooltip = increase_aid_tt
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = influence
					value >= 200
				}
			}
		}
		owner = {
			add_resource = {
				influence = -200
			}
		}
	}

	option = {
		trigger = {
			current_situation_approach = approach_aid_leader
		}
		name = preftl.2185.a
		set_situation_flag = aid_leader_04
		tooltip = {
			target = {
				add_planet_devastation = 20
			}
		}
		custom_tooltip = increase_aid_tt
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = influence
					value >= 200
				}
			}
		}
		owner = {
			add_resource = {
				influence = -200
			}
		}
	}
}

# Power Plays
situation_event = {
	id = preftl.2190
	title = preftl.2190.name
	desc = {
		trigger = {
			has_situation_flag = fat_and_happy_nwo
		}
		text = preftl.2190.a.desc
	}
	desc = {
		trigger = {
			has_situation_flag = suppress_destroy_nwo
		}
		text = preftl.2190.b.desc
	}
	picture = GFX_evt_galactic_empire
	show_sound = event_screams
	location = target
	situation = this

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_situation_flag = power_plays_nwo
		}
	}


	immediate = {
		set_situation_flag = power_plays_nwo
		target = {
			add_planet_devastation = 20
		}
		if = {
			limit = {
				target.owner = {
					NOT = {
						current_awareness_level = full
					}
				}
			}
			owner = {
				set_country_flag = society_insights
				set_predictive_observation_insight = {
					VALUE = 10
				}
			}
		}
	}

	option = {
		name = UNDERSTOOD
		tooltip = {
			target = {
				add_planet_devastation = 20
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
		}
		if = {
			limit = {
				target.owner = {
					NOT = {
						current_awareness_level = full
					}
				}
			}
			owner = {
				add_observation_insight_effect = {
					VALUE = 10
					OUTPOST = root.target.observation_outpost
				}
			}
		}
	}

	option = {
		trigger = {
			current_situation_approach = approach_aid_rebels
		}
		name = preftl.2190.a
		set_situation_flag = aid_rebels_05
		tooltip = {
			target = {
				add_planet_devastation = 20
			}
		}
		custom_tooltip = arm_them_tt
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = energy
					value >= 1000
				}
			}
		}
		owner = {
			add_resource = {
				energy = -1000
			}
		}
	}

	option = {
		trigger = {
			current_situation_approach = approach_aid_leader
		}
		name = preftl.2195.a
		set_situation_flag = aid_leader_05
		tooltip = {
			target = {
				add_planet_devastation = 20
			}
		}
		custom_tooltip = arm_them_tt
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = energy
					value >= 1000
				}
			}
		}
		owner = {
			add_resource = {
				energy = -1000
			}
		}
	}
}

# Total Revolution
situation_event = {
	id = preftl.2195
	title = preftl.2195.name
	desc = {
		trigger = {
			has_situation_flag = fat_and_happy_nwo
		}
		text = preftl.2195.a.desc
	}
	desc = {
		trigger = {
			has_situation_flag = suppress_destroy_nwo
		}
		text = preftl.2195.b.desc
	}
	picture = GFX_evt_night_raid
	show_sound = event_screams
	location = target
	situation = this

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_situation_flag = total_revolution_nwo
		}
	}


	immediate = {
		set_situation_flag = total_revolution_nwo
		target = {
			add_planet_devastation = 20
		}
		if = {
			limit = {
				target.owner = {
					NOT = {
						current_awareness_level = full
					}
				}
			}
			owner = {
				set_country_flag = society_insights
				set_predictive_observation_insight = {
					VALUE = 10
				}
			}
		}
	}

	option = {
		name = UNDERSTOOD
		tooltip = {
			target = {
				add_planet_devastation = 20
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
		}
		if = {
			limit = {
				target.owner = {
					NOT = {
						current_awareness_level = full
					}
				}
			}
			owner = {
				add_observation_insight_effect = {
					VALUE = 10
					OUTPOST = root.target.observation_outpost
				}
			}
		}
	}

	option = {
		trigger = {
			current_situation_approach = approach_aid_rebels
		}
		name = preftl.2190.a
		set_situation_flag = aid_rebels_06
		tooltip = {
			target = {
				add_planet_devastation = 20
			}
		}
		custom_tooltip = arm_them_tt
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = energy
					value >= 1000
				}
			}
		}
		owner = {
			add_resource = {
				energy = -1000
			}
		}
	}

	option = {
		trigger = {
			current_situation_approach = approach_aid_leader
		}
		name = preftl.2195.a
		set_situation_flag = aid_leader_06
		tooltip = {
			target = {
				add_planet_devastation = 20
			}
		}
		custom_tooltip = arm_them_tt
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = energy
					value >= 1000
				}
			}
		}
		owner = {
			add_resource = {
				energy = -1000
			}
		}
	}
}

# Grip of the Autarch
situation_event = {
	id = preftl.2200
	title = preftl.2200.name
	desc = preftl.2200.desc
	picture = GFX_evt_grand_speech
	show_sound = event_screams
	location = target
	situation = this

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_situation_flag = autarch_nwo
		}
	}

	immediate = {
		set_situation_flag = autarch_nwo
		target.owner = {
			every_owned_army = {
				remove_army = yes
			}
			capital_scope = {
				observation_outpost = {
					set_event_locked = no
				}
			}
		}
		if = {
			limit = {
				target.owner = {
					NOT = {
						current_awareness_level = full
					}
				}
			}
			owner = {
				set_country_flag = society_insights
				set_predictive_observation_insight = {
					VALUE = 10
				}
			}
		}
	}

	option = {
		trigger = {
			current_situation_approach = approach_watch_nwo
		}
		name = UNDERSTOOD
		if = {
			limit = {
				target.owner = {
					NOT = {
						current_awareness_level = full
					}
				}
			}
			owner = {
				add_observation_insight_effect = {
					VALUE = 10
					OUTPOST = root.target.observation_outpost
				}
			}
		}
	}

	option = {
		trigger = {
			current_situation_approach = approach_aid_leader
		}
		name = EXCELLENT
		owner = {
			add_modifier = {
				modifier = nwo_situation_01
				days = 3600
			}
		}
		if = {
			limit = {
				target.owner = {
					NOT = {
						current_awareness_level = full
					}
				}
			}
			owner = {
				add_observation_insight_effect = {
					VALUE = 1
					OUTPOST = root.target.observation_outpost
				}
			}
		}
	}

	option = {
		trigger = {
			current_situation_approach = approach_aid_rebels
		}
		name = preftl.2200.a
		if = {
			limit = {
				target.owner = {
					NOT = {
						current_awareness_level = full
					}
				}
			}
			owner = {
				add_observation_insight_effect = {
					VALUE = 10
					OUTPOST = root.target.observation_outpost
				}
			}
		}
	}

	after = {
		target.owner = {
			shift_ethic = ethic_fanatic_authoritarian
			pop_group_add_ethic_effect = {
				ETHOS = ethic_authoritarian
				AMOUNT = 100
				RANDOM = 25
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier3researchreward
				min = @tier3researchmin
				max = @tier3researchmax
			}
		}
		destroy_situation = this
		remove_global_flag = ongoing_nwo_situation
		target = {
			planet = { remove_carrier_flag = has_on_going_observation_situation }
		}
	}
}

# Year Zero
situation_event = {
	id = preftl.2205
	title = preftl.2205.name
	desc = {
		trigger = {
			has_situation_flag = power_plays_nwo
		}
		text = preftl.2205.a.desc
	}
	desc = {
		trigger = {
			has_situation_flag = total_revolution_nwo
		}
		text = preftl.2205.b.desc
	}
	picture = GFX_evt_surrender
	show_sound = event_screams
	location = target
	situation = this

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_situation_flag = year_zero_nwo
		}
	}

	immediate = {
		set_situation_flag = year_zero_nwo
		if = {
			limit = {
				target.owner = {
					NOT = {
						current_awareness_level = full
					}
				}
			}
			owner = {
				set_country_flag = society_insights
				set_predictive_observation_insight = {
					VALUE = 10
				}
			}
		}
	}

	option = {
		trigger = {
			current_situation_approach = approach_watch_nwo
			}
		name = UNDERSTOOD
		if = {
			limit = {
				target.owner = {
					NOT = {
						current_awareness_level = full
					}
				}
			}
			owner = {
				add_observation_insight_effect = {
					VALUE = 10
					OUTPOST = root.target.observation_outpost
				}
			}
		}
	}

	option = {
		trigger = {
			current_situation_approach = approach_aid_rebels
		}
		name = EXCELLENT
		owner = {
			add_modifier = {
				modifier = nwo_situation_02
				days = 3600
			}
		}
		if = {
			limit = {
				target.owner = {
					NOT = {
						current_awareness_level = full
					}
				}
			}
			owner = {
				add_observation_insight_effect = {
					VALUE = 10
					OUTPOST = root.target.observation_outpost
				}
			}
		}
	}

	option = {
		trigger = {
			current_situation_approach = approach_aid_leader
		}
		name = preftl.2205.a
		if = {
			limit = {
				target.owner = {
					NOT = {
						current_awareness_level = full
					}
				}
			}
			owner = {
				add_observation_insight_effect = {
					VALUE = 10
					OUTPOST = root.target.observation_outpost
				}
			}
		}
	}

	after = {
		target.owner = {
			shift_ethic = ethic_egalitarian
			pop_group_add_ethic_effect = {
				ETHOS = ethic_egalitarian
				AMOUNT = 100
				RANDOM = 25
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier3researchreward
				min = @tier3researchmin
				max = @tier3researchmax
			}
		}

		destroy_situation = this
		remove_global_flag = ongoing_nwo_situation
		target = {
			planet = { remove_carrier_flag = has_on_going_observation_situation }
			hidden_effect = {
				owner = {
					ruler = {
						exile_leader_as = deposed_nwo_ruler
					}
					create_leader = {
						class = official
						species = this
						name = random
						skill = 1
					}
					set_leader = last_created_leader
					every_owned_army = {
						remove_army = yes
					}
					capital_scope = {
						observation_outpost = {
							set_event_locked = no
						}
					}
				}
			}
		}
	}
}

################
# GALCOM EVENTS
################

# Violation of Equal Standing
# via resolution_pre_ftl_stances_equal_standing
country_event = {
	id = preftl.10000
	title = "resolution_pre_ftl_stances_equal_standing"
	desc = "preftl.10000.desc"
	picture = GFX_evt_galactic_senate
	show_sound = event_factions
	is_triggered_only = yes

	option = {
		name = FED_WE_MUST_COMPLY
		allow = {
			OR = {
				has_policy_flag = interference_not_allowed
				has_policy_flag = interference_aggressive
			}
			OR = {
				can_set_policy = {
					policy = interference
					option = interference_subtle
				}
				can_set_policy = {
					policy = interference
					option = interference_active
				}
			}
		}
		breach_fix_resolution_resolution_pre_ftl_stances_equal_standing = yes
		ai_chance = {
			factor = 5
		}
	}

	option = {
		name = FED_WE_WILL_RETAIN
		trigger = {
			is_xenophobe = no
			is_materialist = no
		}
		add_monthly_resource_mult = {
			resource = unity
			value = @tier1unityreward
			min = @tier1unitymin
			max = @tier1unitymax
		}
		if = {
			limit = {
				OR = {
					has_policy_flag = interference_not_allowed
					has_policy_flag = interference_aggressive
				}
				OR = {
					can_set_policy = {
						policy = interference
						option = interference_subtle
					}
					can_set_policy = {
						policy = interference
						option = interference_active
					}
				}
			}
			set_policy_cooldown = interference
		}
		custom_tooltip = "FED_WE_WILL_BE_IN_BREACH"
	}

	option = {
		name = FED_WE_WILL_NOT_SUBMIT
		trigger = {
			OR = {
				is_xenophobe = yes
				is_materialist = yes

			}
		}
		add_monthly_resource_mult = {
			resource = unity
			value = @tier2unityreward
			min = @tier2unitymin
			max = @tier2unitymax
		}
		if = {
			limit = {
				OR = {
					has_policy_flag = interference_not_allowed
					has_policy_flag = interference_aggressive
				}
				OR = {
					can_set_policy = {
						policy = interference
						option = interference_subtle
					}
					can_set_policy = {
						policy = interference
						option = interference_active
					}
				}
			}
			set_policy_cooldown = interference
		}
		custom_tooltip = "FED_WE_WILL_BE_IN_BREACH"
		ai_chance = {
			factor = 2
		}
	}
}

# Violation of Equal Standing - Fine
# via on_five_year_pulse_country OR failed Espionage Operations
country_event = {
	id = preftl.10050
	title = "preftl.10050.name"
	desc = "preftl.10050.desc"
	picture = GFX_evt_civil_action
	show_sound = event_assembly_fight
	is_triggered_only = yes

	trigger = {
		is_country_type = default
		any_pre_ftl_within_border = {
			has_country_flag = violation_of_equal_standing@root
		}
		is_galactic_community_formed = yes
		is_galactic_community_member = yes
		is_active_resolution = resolution_pre_ftl_stances_equal_standing
		NOT = {
			has_country_flag = resolution_breached_pre_ftl_stances_equal_standing
		}
	}

	immediate = {
		random_pre_ftl_within_border = {
			limit = {
				has_country_flag = violation_of_equal_standing@root
			}
			save_event_target_as = pre_ftl_country
			remove_country_flag = violation_of_equal_standing@root
		}
		set_timed_country_flag = {
			flag = resolution_breached_pre_ftl_stances_equal_standing
			days = 3600
		}
	}

	option = {
		name = CURSES
		add_resource = { energy = -5000 }
	}
}

# Violation of Equal Standing - Fine (Self Report)
# via failed Espionage Operations | event_target:pre_ftl_country = targeted society
country_event = {
	id = preftl.10055
	title = "preftl.10055.name"
	desc = "preftl.10055.desc"
	picture = GFX_evt_civil_action
	show_sound = event_assembly_fight
	is_triggered_only = yes

	trigger = {
		is_galactic_community_formed = yes
		is_galactic_community_member = yes
		is_active_resolution = resolution_pre_ftl_stances_equal_standing
		NOT = {
			has_country_flag = resolution_breached_pre_ftl_stances_equal_standing
		}
		exists = event_target:pre_ftl_country
	}

	immediate = {
		event_target:pre_ftl_country = {
			remove_country_flag = violation_of_equal_standing_self_report_target
		}
		set_timed_country_flag = {
			flag = resolution_breached_pre_ftl_stances_equal_standing
			days = 1800
		}
	}

	option = {
		name = UNDERSTOOD
		add_resource = { energy = -2500 }
	}
}

# Violation of Non-Interference
# via resolution_pre_ftl_stances_non_interference
country_event = {
	id = preftl.10100
	title = "resolution_pre_ftl_stances_non_interference"
	desc = "preftl.10100.desc"
	picture = GFX_evt_galactic_senate
	show_sound = event_factions
	is_triggered_only = yes

	option = {
		name = FED_WE_MUST_COMPLY
		allow = {
			NOT = {
				has_policy_flag = interference_not_allowed
			}
			can_set_policy = {
				policy = interference
				option = interference_not_allowed
			}
		}
		breach_fix_resolution_resolution_pre_ftl_stances_non_interference = yes
		ai_chance = {
			factor = 5
		}
	}

	option = {
		name = FED_WE_WILL_RETAIN
		trigger = {
			is_xenophobe = no
			is_materialist = no
		}
		add_monthly_resource_mult = {
			resource = unity
			value = @tier1unityreward
			min = @tier1unitymin
			max = @tier1unitymax
		}
		if = {
			limit = {
				NOT = {
					has_policy_flag = interference_not_allowed
				}
				can_set_policy = {
					policy = interference
					option = interference_not_allowed
				}
			}
			set_policy_cooldown = interference
		}
		custom_tooltip = "FED_WE_WILL_BE_IN_BREACH"
	}

	option = {
		name = FED_WE_WILL_NOT_SUBMIT
		trigger = {
			OR = {
				is_xenophobe = yes
				is_materialist = yes
			}
		}
		add_monthly_resource_mult = {
			resource = unity
			value = @tier2unityreward
			min = @tier2unitymin
			max = @tier2unitymax
		}
		if = {
			limit = {
				NOT = {
					has_policy_flag = interference_not_allowed
				}
				can_set_policy = {
					policy = interference
					option = interference_not_allowed
				}
			}
			set_policy_cooldown = interference
		}
		custom_tooltip = "FED_WE_WILL_BE_IN_BREACH"
		ai_chance = {
			factor = 2
		}
	}
}

# Violation of Non-Interference - Fine
# via on_five_year_pulse_country OR failed Espionage Operations
country_event = {
	id = preftl.10150
	title = "preftl.10150.name"
	desc = "preftl.10150.desc"
	picture = GFX_evt_civil_action
	show_sound = event_assembly_fight
	is_triggered_only = yes

	trigger = {
		is_country_type = default
		OR = {
			any_observed_pre_ftl_within_border = {
				OR = {
					is_under_open_technological_enlightenment = root
					is_under_societal_enlightenment = root
					has_pre_ftl_trade = root
					root = {
						is_improving_relations_with = prev
					}
					root = {
						is_harming_relations_with = prev
					}
				}
			}
			any_pre_ftl_within_border = {
				has_country_flag = violation_of_non_interference@root
			}
		}
		is_galactic_community_formed = yes
		is_galactic_community_member = yes
		is_active_resolution = resolution_pre_ftl_stances_non_interference
		NOT = {
			has_country_flag = resolution_breached_pre_ftl_stances_non_interference
		}
	}

	immediate = {
		random_pre_ftl_within_border = {
			limit = {
				OR = {
					has_country_flag = violation_of_non_interference@root
					AND = {
						capital_scope = {
							has_observation_outpost = yes
						}
						OR = {
							is_under_open_technological_enlightenment = root
							is_under_societal_enlightenment = root
							has_pre_ftl_trade = root
							root = {
								is_improving_relations_with = prev
							}
							root = {
								is_harming_relations_with = prev
							}
						}
					}
				}
			}
			save_event_target_as = pre_ftl_country
			remove_country_flag = violation_of_non_interference@root
		}
		set_timed_country_flag = {
			flag = resolution_breached_pre_ftl_stances_non_interference
			days = 3600
		}
	}

	option = {
		name = CURSES
		add_resource = { energy = -5000 }
	}
}

# Violation of Non-Interference - Fine (Self Report)
# via failed Espionage Operations | event_target:pre_ftl_country = targeted society
country_event = {
	id = preftl.10155
	title = "preftl.10155.name"
	desc = "preftl.10155.desc"
	picture = GFX_evt_civil_action
	show_sound = event_assembly_fight
	is_triggered_only = yes

	trigger = {
		is_galactic_community_formed = yes
		is_galactic_community_member = yes
		is_active_resolution = resolution_pre_ftl_stances_non_interference
		NOT = {
			has_country_flag = resolution_breached_pre_ftl_stances_non_interference
		}
		exists = event_target:pre_ftl_country
	}

	immediate = {
		event_target:pre_ftl_country = {
			remove_country_flag = violation_of_non_interference_self_report_target
		}
		set_timed_country_flag = {
			flag = resolution_breached_pre_ftl_stances_non_interference
			days = 1800
		}
	}

	option = {
		name = UNDERSTOOD
		add_resource = { energy = -2500 }
	}
}

# Violation of Non-Interference by Invasion - Fine

# Invasion begun.
carrier_event = {
	id = preftl.10156
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		exists = owner
		owner = {
			is_primitive = yes
			NOT = {
				has_country_flag = invaded_by_@from
			}
		}
		from = {
			is_galactic_community_formed = yes
			is_galactic_community_member = yes
			is_active_resolution = resolution_pre_ftl_stances_non_interference
		}
	}

	immediate = {
		owner = {
			save_event_target_as = pre_ftl_country
			set_timed_country_flag = {
				flag = invaded_by_@from
				days = 360
			}
		}
		from = {
			country_event = {
				id = preftl.10157
			}
		}
	}
}

# Fine issued for Invader
country_event = {
	id = preftl.10157
	title = "preftl.10150.name"
	desc = "preftl.10157.desc"
	picture = GFX_evt_civil_action
	show_sound = event_assembly_fight

	is_triggered_only = yes

	trigger = {
		is_country_type = default
		any_observed_pre_ftl_within_border = {
			is_same_value = event_target:pre_ftl_country
			has_country_flag = invaded_by_@root
		}
		is_galactic_community_formed = yes
		is_galactic_community_member = yes
		is_active_resolution = resolution_pre_ftl_stances_non_interference
	}

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

	option = {
		name = CURSES
		add_resource = { energy = -5000 }
	}
}

# Violation of Non-Interference by Bombardment - Fine

# Bombardment begun.
carrier_event = {
	id = preftl.10160
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		exists = owner
		owner = {
			is_primitive = yes
			NOT = {
				has_country_flag = bombardard_by_@from
			}
		}
		from = {
			is_galactic_community_formed = yes
			is_galactic_community_member = yes
			is_active_resolution = resolution_pre_ftl_stances_non_interference
		}
	}

	immediate = {
		owner = {
			save_event_target_as = pre_ftl_country
			set_timed_country_flag = {
				flag = bombardard_by_@from
				days = 360
			}
		}
		from = {
			country_event = {
				id = preftl.10161
			}
		}
	}
}

# Fine issued for Bombarder
country_event = {
	id = preftl.10161
	title = "preftl.10150.name"
	desc = "preftl.10161.desc"
	picture = GFX_evt_civil_action
	show_sound = event_assembly_fight

	is_triggered_only = yes

	trigger = {
		is_country_type = default
		any_observed_pre_ftl_within_border = {
			is_same_value = event_target:pre_ftl_country
			has_country_flag = bombardard_by_@root
		}
		is_galactic_community_formed = yes
		is_galactic_community_member = yes
		is_active_resolution = resolution_pre_ftl_stances_non_interference
	}

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

	option = {
		name = CURSES
		add_resource = { energy = -5000 }
	}
}

# Violation of Exploitation
country_event = {
	id = preftl.10200
	title = "resolution_pre_ftl_stances_exploitation"

	desc = "preftl.10200.desc"

	picture = GFX_evt_galactic_senate
	show_sound = event_factions

	is_triggered_only = yes

	option = {
		name = FED_WE_MUST_COMPLY

		allow = {
			has_policy_flag = interference_not_allowed
			OR = {
				can_set_policy = {
					policy = interference
					option = interference_active
				}
				can_set_policy = {
					policy = interference
					option = interference_aggressive
				}
			}
		}

		breach_fix_resolution_resolution_pre_ftl_stances_exploitation = yes

		ai_chance = {
			factor = 5
		}
	}

	option = {
		name = FED_WE_WILL_RETAIN

		trigger = {
			is_xenophile = no
			is_egalitarian = no
		}

		add_monthly_resource_mult = {
			resource = unity
			value = @tier1unityreward
			min = @tier1unitymin
			max = @tier1unitymax
		}

		if = {
			limit = {
				has_policy_flag = interference_not_allowed
				OR = {
					can_set_policy = {
						policy = interference
						option = interference_active
					}
					can_set_policy = {
						policy = interference
						option = interference_aggressive
					}
				}
			}
			set_policy_cooldown = interference
		}

		custom_tooltip = "FED_WE_WILL_BE_IN_BREACH"
	}

	option = {
		name = FED_WE_WILL_NOT_SUBMIT

		trigger = {
			OR = {
				is_xenophile = yes
				is_egalitarian = yes
			}
		}

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

		if = {
			limit = {
				has_policy_flag = interference_not_allowed
				OR = {
					can_set_policy = {
						policy = interference
						option = interference_active
					}
					can_set_policy = {
						policy = interference
						option = interference_aggressive
					}
				}
			}
			set_policy_cooldown = interference
		}

		custom_tooltip = "FED_WE_WILL_BE_IN_BREACH"

		ai_chance = {
			factor = 2
		}
	}
}

# Violation of Exploitation - Fine
country_event = {
	id = preftl.10250
	title = "preftl.10250.name"
	desc = "preftl.10250.desc"
	picture = GFX_evt_civil_action
	show_sound = event_assembly_fight

	is_triggered_only = yes

	trigger = {
		is_country_type = default
		OR = {
			any_observed_pre_ftl_within_border = {
				is_under_open_technological_enlightenment = root
			}
			any_pre_ftl_within_border = {
				has_country_flag = violation_of_exploitation@root
			}
		}
		is_galactic_community_formed = yes
		is_galactic_community_member = yes
		is_active_resolution = resolution_pre_ftl_stances_exploitation
		NOT = {
			has_country_flag = resolution_breached_pre_ftl_stances_exploitation
		}
	}

	immediate = {
		random_pre_ftl_within_border = {
			limit = {
				OR = {
					has_country_flag = violation_of_exploitation@root
					AND = {
						capital_scope = {
							has_observation_outpost = yes
						}
						is_under_open_technological_enlightenment = root
					}
				}
			}
			save_event_target_as = pre_ftl_country
			remove_country_flag = violation_of_exploitation@root
		}
		set_timed_country_flag = {
			flag = resolution_breached_pre_ftl_stances_exploitation
			days = 3600
		}
	}

	option = {
		name = CURSES
		add_resource = { energy = -5000 }
	}
}

# Violation of Exploitation - Fine - Self Report
# This event is triggered by failed espionage operations.
# country_event = {
# 	id = preftl.10255
# 	title = "preftl.10255.name"
# 	desc = "preftl.10255.desc"
# 	picture = GFX_evt_civil_action
# 	show_sound = event_assembly_fight

# 	is_triggered_only = yes

# 	trigger = {
# 		is_galactic_community_formed = yes
# 		is_galactic_community_member = yes
# 		is_active_resolution = resolution_pre_ftl_stances_exploitation
# 		NOT = {
# 			has_country_flag = resolution_breached_pre_ftl_stances_exploitation
# 		}
# 	}

# 	immediate = {
# 		random_observed_pre_ftl_within_border = {
# 			limit = {
# 				has_country_flag = violation_of_exploitation_self_report_target
# 			}
# 			save_event_target_as = pre_ftl_country
# 			remove_country_flag = violation_of_exploitation_self_report_target
# 		}
# 		set_timed_country_flag = {
# 			flag = resolution_breached_pre_ftl_stances_exploitation
# 			days = 1800
# 		}
# 	}

# 	option = {
# 		name = UNDERSTOOD
# 		add_resource = { energy = -2500 }
# 	}
# }

carrier_event = {
	id = preftl.10300
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = owner
		owner = {
			is_primitive = yes
			NOT = { has_country_flag = recent_bombarded }
		}
	}

	immediate = {
		owner = {
			set_timed_country_flag = { #Add the modifier every 30 days.
				flag = recent_bombarded
				days = 30
			}
			add_opinion_modifier = {
				who = from
				modifier = opinon_pre_ftl_bombard
			}
		}
	}
}
