namespace = rg_origin

########
# SCION
########

country_event = {
	id = rg_origin.1
	hide_window = yes

	is_triggered_only = yes
	trigger = {
		AND = {
			has_origin = rg_origin_scion
			# NOT = { has_global_flag = rg_origin_l_cluster }
		}
	}

	immediate = {
		# Scion
		country_event = { id = rg_origin.5 }
	}
}


# Setup
country_event = {
	id = rg_origin.5
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		# set_country_flag = first_contact_event
		# set_country_flag = Story2 # Already encountered spacefarers
		# Spawn mini-FE if player turned off Fallen Empires but picked this Origin anyway...
		if = {
			limit = {
				NOT = {
					exists = event_target:rg_scion_fe
				}
			}
			set_country_flag = rg_scion_needs_fe
			if = {
				limit ={
					OR = {
						rg_all_cluster_mod_check_for_scion = yes
						any_playable_country = {
							has_origin = origin_rg_gray
						}
					}
				}
				random_system = {
					limit = { has_owner = no }
					spawn_system = { initializer = "rg_fallen_machine_1" }
				}
				add_extra_hyperlane_to_spawned_system_effect = yes
			}
			else = {
				rg_lcluster_spawn_effect_scion = yes
				every_system = {
					limit = {
						has_star_flag = lcluster
					}
					rg_create_fe_citadel = yes
				}
			}
			event_target:rg_scion_fe = {
				set_policy = {
					policy = artificial_intelligence_policy
					option = ai_servitude
					cooldown = no
				}
				set_policy = {
					policy = robot_pop_policy
					option = robot_pops_allowed
					cooldown = no
				}
				random_playable_country = {
					limit = {
						has_origin = rg_origin_scion
						has_country_flag = rg_scion_needs_fe
					}
					remove_country_flag = rg_scion_needs_fe
					save_event_target_as = rg_scion_slave
				}
				set_country_flag = rg_scion_master
				save_event_target_as = rg_scion_master
				add_opinion_modifier = {
					who = event_target:rg_scion_slave
					modifier = opinion_scion
				}
				# country_event = { id = origin.20 days = 9000 random = 9000 }
				event_target:rg_scion_slave = {
					establish_communications_no_message = event_target:rg_scion_fe
					set_subject_of = {
						who = event_target:rg_scion_fe
						preset = preset_rg_scion
					}
					overlord = {
						add_opinion_modifier = {
							modifier = opinion_scion
							who = event_target:rg_scion_fe
						}
					}
					country_event = { id = rg_origin.10 days = 3 }
				}
			}
			capital_scope = {
				solar_system = {
					set_star_flag = lgate
					spawn_megastructure = {
						type = lgate_base
						orbit_angle = 225
						orbit_distance = 30
					}
				}
			}
			# add_extra_hyperlane_to_spawned_system_effect = yes
		}
	}
}

# Intro Diplomatic Message
country_event = {
	id = rg_origin.10
	title = TRANSMISSION

	desc = {
		text = "origin.10.b.desc"
	}
	diplomatic = yes
	is_triggered_only = yes

	picture_event_data = {
		portrait = event_target:rg_scion_master
		planet_background = event_target:rg_scion_master
		graphical_culture = event_target:rg_scion_master
		city_level = event_target:rg_scion_master
		room = event_target:rg_scion_master
	}

	immediate = {
		overlord = { save_event_target_as = rg_scion_master }
	}

	option = {
		name = origin.10.b
	}
}
