###########################
# FIRST CONTACT STORY PACK
###########################

# First Contact feature scripted triggers may be found in 02_scripted_triggers_first_contact.txt

# Decide which diplomacy room to use (country scope)
pre_ftl_ancient_era = {
	OR = {
		has_pre_ftl_age = stone_age
		has_pre_ftl_age = bronze_age
		has_pre_ftl_age = iron_age
	}
}

pre_ftl_medieval_era = {
	OR = {
		has_pre_ftl_age = late_medieval_age
		has_pre_ftl_age = renaissance_age
	}
}

pre_ftl_victorian_era = {
	OR = {
		has_pre_ftl_age = steam_age
		has_pre_ftl_age = industrial_age
	}
}

pre_ftl_modern_era = {
	OR = {
		has_pre_ftl_age = machine_age
		has_pre_ftl_age = atomic_age
		has_pre_ftl_age = early_space_age
	}
}

pre_ftl_in_age_is_observed_with = {
	is_country_type = primitive
	has_pre_ftl_age = $AGE$
	capital_scope = {
		has_observation_outpost = yes
		observation_outpost = {
			exists = owner
			has_mission = $MISSION$
		}
	}
}

pre_ftl_is_observed_with = {
	is_country_type = primitive
	capital_scope = {
		has_observation_outpost = yes
		observation_outpost = {
			exists = owner
			has_mission = $MISSION$
		}
	}
}

pre_ftl_is_observed_by_system_owner = {
	is_country_type = primitive
	capital_scope = {
		has_observation_outpost = yes
		observation_outpost = {
			exists = owner
		}
	}
}

pre_ftl_not_observed_by_system_owner = {
	is_country_type = primitive
	capital_scope = {
		solar_system = {
			exists = owner
		}
		has_observation_outpost = no
	}
}

is_pre_renaissance = {
	OR = {
		has_pre_ftl_age = stone_age
		has_pre_ftl_age = bronze_age
		has_pre_ftl_age = iron_age
		has_pre_ftl_age = late_medieval_age
	}
}
is_pre_industrial = {
	OR = {
		has_pre_ftl_age = stone_age
		has_pre_ftl_age = bronze_age
		has_pre_ftl_age = iron_age
		has_pre_ftl_age = late_medieval_age
		has_pre_ftl_age = renaissance_age
		has_pre_ftl_age = steam_age
	}
}

is_regular_pre_ftl = {
	is_primitive = yes
	is_gestalt = no
}
is_gestalt_pre_ftl = {
	is_primitive = yes
	is_gestalt = yes
}
is_hive_mind_pre_ftl = {
	is_primitive = yes
	is_hive_empire = yes
}

has_active_observation_post = {
	is_country_type = default
	has_country_flag = built_observation_post
	any_system_within_border = {
		any_system_planet_colony = {
			has_observation_outpost = yes
		}
	}
}

has_cloaking_component_regular = {
	OR = {
		has_component = CORVETTE_CLOAKING_1
		has_component = SCIENCE_CLOAKING_1
		has_component = GRAVITY_SNARE_CLOAKING_1
		has_component = CORVETTE_CLOAKING_2
		has_component = DESTROYER_CLOAKING_2
		has_component = SCIENCE_CLOAKING_2
		has_component = GRAVITY_SNARE_CLOAKING_2
		has_component = CORVETTE_CLOAKING_3
		has_component = DESTROYER_CLOAKING_3
		has_component = CRUISER_CLOAKING_3
		has_component = SCIENCE_CLOAKING_3
		has_component = GRAVITY_SNARE_CLOAKING_3
	}
}

has_cloaking_component_dark_matter = {
	OR = {
		has_component = CORVETTE_CLOAKING_DARK_MATTER
		has_component = DESTROYER_CLOAKING_DARK_MATTER
		has_component = CRUISER_CLOAKING_DARK_MATTER
		has_component = BATTLESHIP_CLOAKING_DARK_MATTER
		has_component = SCIENCE_CLOAKING_DARK_MATTER
		has_component = GRAVITY_SNARE_CLOAKING_DARK_MATTER
	}
}

has_cloaking_component_psi = {
	OR = {
		has_component = CORVETTE_CLOAKING_PSI
		has_component = DESTROYER_CLOAKING_PSI
		has_component = CRUISER_CLOAKING_PSI
		has_component = BATTLESHIP_CLOAKING_PSI
		has_component = SCIENCE_CLOAKING_PSI
		has_component = GRAVITY_SNARE_CLOAKING_PSI
	}
}

has_cloaking_component = {
	OR = {
		has_cloaking_component_regular = yes
		has_cloaking_component_dark_matter = yes
		has_cloaking_component_psi = yes
	}
}

has_stealth_ship_role = {
	OR = {
		has_role = gunship_stealth
		has_role = explosive_stealth
		has_role = carrier_stealth
		has_role = screen_stealth
		has_role = artillery_stealth
		has_role = brawler_stealth
		has_role = energy_torpedoes_stealth
		has_role = buffer_role_stealth
		has_role = debuffer_role_stealth
	}
}

has_non_psionic_shields = {
	OR = {
		has_component = SMALL_SHIELD_1
		has_component = MEDIUM_SHIELD_1
		has_component = LARGE_SHIELD_1
		has_component = SMALL_SHIELD_2
		has_component = MEDIUM_SHIELD_2
		has_component = LARGE_SHIELD_2
		has_component = MEDIUM_SHIELD_3
		has_component = LARGE_SHIELD_3
		has_component = SMALL_SHIELD_3
		has_component = MEDIUM_SHIELD_4
		has_component = LARGE_SHIELD_4
		has_component = SMALL_SHIELD_4
		has_component = MEDIUM_SHIELD_5
		has_component = LARGE_SHIELD_5
		has_component = SMALL_SHIELD_5
		has_component = SMALL_DARK_MATTER_DEFLECTOR
		has_component = MEDIUM_DARK_MATTER_DEFLECTOR
		has_component = LARGE_DARK_MATTER_DEFLECTOR
		has_component = SMALL_ARCHAEO_SHIELD
		has_component = MEDIUM_ARCHAEO_SHIELD
		has_component = LARGE_ARCHAEO_SHIELD
		has_component = SMALL_ARCHAEO_ARMOR
		has_component = MEDIUM_ARCHAEO_ARMOR
		has_component = LARGE_ARCHAEO_ARMOR
	}
}

has_battleship_cloaking_tech = {
	OR = {
		has_technology = tech_cloaking_dark_matter
		has_technology = tech_cloaking_psi
	}
}

is_eager_explorer_ship = {
	OR = {
		is_ship_size = explorer_vessel
		is_ship_size = engineer_vessel
		is_ship_size = colony_vessel
		is_ship_size = nomads_engineer_vessel
	}
}

has_any_active_pre_ftl_agreement = {
	any_observed_pre_ftl_within_border = {
		OR = {
			is_under_open_technological_enlightenment = root
			is_under_societal_enlightenment = root
			has_pre_ftl_trade = root
		}
	}
}

has_pre_ftl_tech_enlightenment_agreement = {
	any_observed_pre_ftl_within_border = {
		is_under_open_technological_enlightenment = root
	}
}

has_pre_ftl_tech_enlightenment_agreement_no_gestalt = {
	any_observed_pre_ftl_within_border = {
		NOT = { has_ethic = ethic_gestalt_consciousness }
		is_under_open_technological_enlightenment = root
	}
}

has_pre_ftl_societal_enlightenment_agreement = {
	any_observed_pre_ftl_within_border = {
		is_under_societal_enlightenment = root
	}
}

has_pre_ftl_societal_enlightenment_agreement_no_gestalt = {
	any_observed_pre_ftl_within_border = {
		NOT = { has_ethic = ethic_gestalt_consciousness }
		is_under_societal_enlightenment = root
	}
}

has_pre_ftl_trade_agreement = {
	any_observed_pre_ftl_within_border = {
		has_pre_ftl_trade = root
	}
}

has_pre_ftl_trade_agreement_gestalt = {
	any_observed_pre_ftl_within_border = {
		is_gestalt = yes
		has_pre_ftl_trade = root
	}
}

has_pre_ftl_trade_agreement_no_gestalt = {
	any_observed_pre_ftl_within_border = {
		NOT = { has_ethic = ethic_gestalt_consciousness }
		has_pre_ftl_trade = root
	}
}

has_pre_ftl_recent_tech_development = {
	any_observed_pre_ftl_within_border = {
		OR = {
			is_under_open_technological_enlightenment = root
			has_country_flag = recently_planeted_knowlege
		}
	}
}

has_blocked_random_devastating_pre_ftl_events = {
	OR = {
		has_origin = origin_fear_of_the_dark
		has_country_flag = fotd_hunter
		has_country_flag = solarpunk_country
		has_country_flag = unplugged_prevent_pre_ftl_devastation
	}
}

support_seperatist_deficit_trigger = {
	switch = {
		trigger = has_country_flag
		mineral_seperatist_deficit = {
			resource_stockpile_compare = {
				resource = minerals
				value >= 3
				mult = value:fotd_support_cost|RESOURCE|minerals|
			}
		}
		food_seperatist_deficit = {
			resource_stockpile_compare = {
				resource = food
				value >= 3
				mult = value:fotd_support_cost|RESOURCE|food|
			}
		}
		energy_seperatist_deficit = {
			resource_stockpile_compare = {
				resource = energy
				value >= 3
				mult = value:fotd_support_cost|RESOURCE|energy|
			}
		}
		alloy_seperatist_deficit = {
			resource_stockpile_compare = {
				resource = alloys
				value >= 3
				mult = value:fotd_support_cost|RESOURCE|alloys|
			}
		}
		consumer_goods_seperatist_deficit = {
			resource_stockpile_compare = {
				resource = consumer_goods
				value >= 3
				mult = value:fotd_support_cost|RESOURCE|consumer_goods|
			}
		}
	}
}

has_deficit_situation = {
	any_situation = {
		is_situation_type = situation_energy_deficit
		is_situation_type = situation_food_deficit
		is_situation_type = situation_alloys_deficit
		is_situation_type = situation_mineral_deficit
		is_situation_type = situation_exotic_gases_deficit
		is_situation_type = situation_rare_crystals_deficit
		is_situation_type = situation_consumer_goods_deficit
		is_situation_type = situation_volatile_motes_deficit
	}
}

has_deficit_situation_stage_2 = {
	any_situation = {
		OR = {
			is_situation_type = situation_energy_deficit
			is_situation_type = situation_food_deficit
			is_situation_type = situation_alloys_deficit
			is_situation_type = situation_mineral_deficit
			is_situation_type = situation_exotic_gases_deficit
			is_situation_type = situation_rare_crystals_deficit
			is_situation_type = situation_consumer_goods_deficit
			is_situation_type = situation_volatile_motes_deficit
		}
		current_stage = deficit_second
	}
}

has_deficit_situation_stage_3 = {
	any_situation = {
		OR = {
			is_situation_type = situation_energy_deficit
			is_situation_type = situation_food_deficit
			is_situation_type = situation_alloys_deficit
			is_situation_type = situation_mineral_deficit
			is_situation_type = situation_exotic_gases_deficit
			is_situation_type = situation_rare_crystals_deficit
			is_situation_type = situation_consumer_goods_deficit
			is_situation_type = situation_volatile_motes_deficit
		}
		current_stage = deficit_third
	}
}

has_deficit_situation_stage_4 = {
	any_situation = {
		OR = {
			is_situation_type = situation_energy_deficit
			is_situation_type = situation_food_deficit
			is_situation_type = situation_alloys_deficit
			is_situation_type = situation_mineral_deficit
			is_situation_type = situation_exotic_gases_deficit
			is_situation_type = situation_rare_crystals_deficit
			is_situation_type = situation_consumer_goods_deficit
			is_situation_type = situation_volatile_motes_deficit
		}
		current_stage = deficit_fourth
	}
}

has_all_physics_insights = {
	AND = {
		OR = {
			has_technology = tech_unusual_senses
			NOT = { has_technology = tech_detection_array }
		}
		has_technology = tech_new_numbers
		has_technology = tech_trinary_computing
		has_technology = tech_atmospheric_orbital_mechanics
	}
}

has_all_society_insights = {
	AND = {
		OR = {
			has_technology = tech_predatory_tactics
			NOT = { has_technology = tech_cloaking_1 }
		}
		has_technology = tech_satisfying_insults
		has_technology = tech_compact_living
		has_technology = tech_alien_topography
		has_technology = tech_xeno_aesthetics
	}
}

has_all_engineering_insights = {
	AND = {
		has_technology = tech_lost_building_methods
		has_technology = tech_supreme_alloy
		has_technology = tech_ordered_retreat
		OR = {
			has_technology = tech_temple_of_transportation
			has_overlord_dlc = no
			NOT = { has_technology = tech_hyper_relays }
		}
	}
}

has_all_insights = {
	has_all_physics_insights = yes
	has_all_society_insights = yes
	has_all_engineering_insights = yes
}

has_special_pre_ftl_diplo = {
	OR = {
		has_country_flag = solarpunk_country
	}
}

# May be used to identify pre-FTL countries which serve the "Broken Shackles" Origin. Note that only is_broken_shackles_pre_ftl_to_scope = {} will check for pre-FTL countries which are related to a particular, scoped empire.
# (Pre-FTL) country scope
is_broken_shackles_pre_ftl = {
	OR = {
		has_country_flag = broken_shackles_parent_country
		has_country_flag = broken_shackles_abductees_country
	}
}

# (Pre-FTL) country scope
is_broken_shackles_pre_ftl_to_scope = {
	OR = {
		has_country_flag = broken_shackles_parent_of@$SCOPE$
		has_country_flag = broken_shackles_abductees@$SCOPE$
	}
}

is_pre_ftl_colony_type = {
	OR = {
		colony_type = col_pre_ftl_atomic
		colony_type = col_pre_ftl_stone
		colony_type = col_pre_ftl_bronze
		colony_type = col_pre_ftl_early_space
		colony_type = col_pre_ftl_industrial
		colony_type = col_pre_ftl_iron
		colony_type = col_pre_ftl_machine
		colony_type = col_pre_ftl_medieval
		colony_type = col_pre_ftl_renaissance
		colony_type = col_pre_ftl_steam
	}
}

observation_owner_is_actor = {
	OR = {
		capital_scope = {
			has_observation_outpost = yes
			exists = observation_outpost_owner
			observation_outpost_owner = {
				is_same_value = root
			}
		}
		# Nomads observe via waystations, but only when no observation post is present.
		capital_scope = {
			has_observation_outpost = no
			solar_system = {
				any_starbase_in_system = {
					is_waystation_starbase = yes
					owner? = {
						is_same_value = root
					}
				}
			}
		}
	}
}

has_cloaking_civic_or_origin = {
    OR = {
        has_valid_civic = civic_void_reavers
        has_valid_civic = civic_machine_spybots
        has_valid_civic = civic_criminal_heritage
        is_dark_consortium_empire = yes
        has_origin = origin_fear_of_the_dark
    }
}

# Country scope (pre-FTL country). True if a Nomadic empire has a waystation in the same
# system as this pre-FTL country's capital, the pre-FTL country is in the given age,
# and no observation post is present (observation posts take priority over waystations).
pre_ftl_in_age_has_nomad_waystation_observer = {
	is_country_type = primitive
	has_pre_ftl_age = $AGE$
	capital_scope = {
		has_observation_outpost = no
		solar_system = {
			any_starbase_in_system = {
				is_waystation_starbase = yes
				owner? = { is_nomadic = yes }
			}
		}
	}
}

# Country scope (pre-FTL country). As pre_ftl_in_age_has_nomad_waystation_observer,
# but without an age requirement.
pre_ftl_has_nomad_waystation_observer = {
	is_country_type = primitive
	capital_scope = {
		has_observation_outpost = no
		solar_system = {
			any_starbase_in_system = {
				is_waystation_starbase = yes
				owner? = { is_nomadic = yes }
			}
		}
	}
}
