namespace = f93_galcro_copy_events
# Set starting planet governors
country_event = {
	id = f93_galcro_copy_events.1 #game_start.71
	hide_window = yes
	trigger = {
		is_country_type = f93_shrouded_region_crisis
	}

	is_triggered_only = yes

	immediate = {
		#log_error = "GalCro copy event 1 / Game Start.71 on [GetDate] by [Root.GetName]"
		assign_governor_effect = yes
		every_owned_leader = {
			limit = {
				leader_class = commander
				is_idle = yes
			}
			owner = {
				random_owned_fleet = {
					limit = {
						is_ship_class = shipclass_military
						NOT = {
							exists = leader
						}
					}
					assign_leader = prevprev
				}
			}
		}
		every_owned_leader = {
			limit = {
				leader_class = scientist
				is_idle = yes
			}
			owner = {
				random_owned_fleet = {
					limit = {
						is_ship_class = shipclass_science_ship
						NOT = {
							exists = leader
						}
					}
					assign_leader = prevprev
				}
			}
		}
		# In case mysterious leaders are spawned.
		every_owned_leader = {
			limit = {
				is_idle = yes
				is_councilor = no
			}
			kill_leader = {
				show_notification = no
			}
		}
	}
}

# Create Regular Council.
country_event = {
	id = f93_galcro_copy_events.2 #game_start.72
	hide_window = yes
	trigger = {
		is_country_type = f93_shrouded_region_crisis
	}

	is_triggered_only = yes

	immediate = {
		#log_error = "GalCro copy event 2 / Game Start.72 on [GetDate] by [Root.GetName]"
		# Add Minister of Defense Position
		if = {
			limit = {
				NOT = {
					has_councilor = {
						COUNCILOR = councilor_defense
					}
				}
			}
			if = {
				limit = { has_paragon_dlc = yes	}
				unlock_council_slots = 1
				set_council_position_to_council = councilor_defense
			}
			if = {
				limit = {
					any_owned_leader = {
						leader_class = commander
						is_councilor = no
						is_ruler = no
					}
				}
				random_owned_leader = {
					limit = {
						leader_class = commander
						is_councilor = no
						is_ruler = no
					}
					set_council_position = councilor_defense
				}
			}
			else = {
				create_leader = {
					class = commander
					name = random
					species = owner_main_species
				}
				last_created_leader = {
					if = {
						limit = {
							has_base_skill > 1
							num_traits = 0
						}
						 add_trait = { trait = random_common }
					}
				}
				last_created_leader = {
					set_council_position = councilor_defense
				}
			}
		}

		# Add Head of Research Position
		if = {
			limit = {
				NOT = {
					has_councilor = {
						COUNCILOR = councilor_research
					}
				}
			}
			if = {
				limit = { has_paragon_dlc = yes	}
				unlock_council_slots = 1
				set_council_position_to_council = councilor_research
			}
			if = {
				limit = {
					any_owned_leader = {
						leader_class = scientist
						is_councilor = no
						is_ruler = no
					}
				}
				random_owned_leader = {
					limit = {
						leader_class = scientist
						is_councilor = no
						is_ruler = no
					}
					set_council_position = councilor_research
				}
			}
			else = {
				create_leader = {
					class = scientist
					name = random
					species = owner_main_species
				}
				last_created_leader = {
					if = {
						limit = {
							has_base_skill > 1
							num_traits = 0
						}
						add_trait = { trait = random_common }
					}
				}
				last_created_leader = {
					set_council_position = councilor_research
				}
			}
		}

		# Add Minister of State Position
		if = {
			limit = {
				blocks_minister_of_state = no
			}
			if = {
				limit = {
					NOT = {
						has_councilor = {
							COUNCILOR = councilor_state
						}
					}
				}
				if = {
					limit = { has_paragon_dlc = yes	}
					unlock_council_slots = 1
					set_council_position_to_council = councilor_state
				}
				if = {
					limit = {
						any_owned_leader = {
							leader_class = official
							is_councilor = no
							is_ruler = no
						}
					}
					random_owned_leader = {
						limit = {
							leader_class = official
							is_councilor = no
							is_ruler = no
						}
						set_council_position = councilor_state
					}
				}
				else = {
					create_leader = {
						class = official
						name = random
						species = owner_main_species
					}
					last_created_leader = {
						if = {
							limit = {
								has_base_skill > 1
								num_traits = 0
							}
							 add_trait = { trait = random_common }
						}
					}
					last_created_leader = {
						set_council_position = councilor_state
					}
				}
			}
		}
		else_if = {
			limit = {
				has_valid_civic = civic_inwards_perfection
				has_paragon_dlc = yes
				NOT = {
					has_councilor = {
						COUNCILOR = councilor_inwards_perfection
					}
				}
			}
			unlock_council_slots = 1
			set_council_position_to_council = councilor_inwards_perfection
			if = {
				limit = {
					any_owned_leader = {
						leader_class = commander
						is_councilor = no
						is_ruler = no
					}
				}
				random_owned_leader = {
					limit = {
						leader_class = commander
						is_councilor = no
						is_ruler = no
					}
					set_council_position = councilor_inwards_perfection
				}
			}
			else = {
				create_leader = {
					class = commander
					name = random
					species = owner_main_species
				}
				last_created_leader = {
					if = {
						limit = {
							has_base_skill > 1
							num_traits = 0
						}
						 add_trait = { trait = random_common }
					}
				}
				last_created_leader = {
					set_council_position = councilor_inwards_perfection
				}
			}
		}
		else_if = {
			limit = {
				has_valid_civic = civic_fanatic_purifiers
				has_paragon_dlc = yes
				NOT = {
					has_councilor = {
						COUNCILOR = councilor_fanatic_purifiers
					}
				}
			}
			unlock_council_slots = 1
			set_council_position_to_council = councilor_fanatic_purifiers
			if = {
				limit = {
					any_owned_leader = {
						leader_class = commander
						is_councilor = no
						is_ruler = no
					}
				}
				random_owned_leader = {
					limit = {
						leader_class = commander
						is_councilor = no
						is_ruler = no
					}
					set_council_position = councilor_fanatic_purifiers
				}
			}
			else = {
				create_leader = {
					class = commander
					name = random
					species = owner_main_species
				}
				last_created_leader = {
					if = {
						limit = {
							has_base_skill > 1
							num_traits = 0
						}
						 add_trait = { trait = random_common }
					}
				}
				last_created_leader = {
					set_council_position = councilor_fanatic_purifiers
				}
			}
		}
	}
}
