###STOLEN FROM 00_SCRIPTED_EFFECTS###

effect_extsynth_leader_trait_tweaks = {
	switch = {
		trigger = leader_class
		ruler = {
		
		}
		admiral = {
			random_list = {
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_cautious
					}
					add_trait = {
						trait = leader_trait_cautious
						show_message = no
					}
				}
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_scout
					}
					add_trait = {
						trait = leader_trait_scout
						show_message = no
					}
				}
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_unyielding
					}
					add_trait = {
						trait = leader_trait_unyielding
						show_message = no
					}
				}
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_gale_speed
					}
					add_trait = {
						trait = leader_trait_gale_speed
						show_message = no
					}
				}
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_aggressive
					}
					add_trait = {
						trait = leader_trait_aggressive
						show_message = no
					}
				}
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_fleet_logistician
					}
					add_trait = {
						trait = leader_trait_fleet_logistician
						show_message = no
					}
				}
			}
		}
		governor = {
			random_list = {
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_army_veteran
					}
					add_trait = {
						trait = leader_trait_army_veteran
						show_message = no
					}
				}
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_retired_fleet_officer
					}
					add_trait = {
						trait = leader_trait_retired_fleet_officer
						show_message = no
					}
				}
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_architectural_interest
					}
					add_trait = {
						trait = leader_trait_architectural_interest
						show_message = no
					}
				}
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_agrarian_upbringing
					}
					add_trait = {
						trait = leader_trait_agrarian_upbringing
						show_message = no
					}
				}
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_intellectual
					}
					add_trait = {
						trait = leader_trait_intellectual
						show_message = no
					}
				}
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_environmental_engineer
					}
					add_trait = {
						trait = leader_trait_environmental_engineer
						show_message = no
					}
				}
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_bureaucrat
					}
					add_trait = {
						trait = leader_trait_bureaucrat
						show_message = no
					}
				}
			}
		}
		scientist = {
			random_list = {
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_meticulous
					}
					add_trait = {
						trait = leader_trait_meticulous
						show_message = no
					}
				}
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_spark_of_genius
					}
					add_trait = {
						trait = leader_trait_spark_of_genius
						show_message = no
					}
				}
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_carefree
					}
					add_trait = {
						trait = leader_trait_carefree
						show_message = no
					}
				}
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_roamer
					}
					add_trait = {
						trait = leader_trait_roamer
						show_message = no
					}
				}
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_maniacal
					}
					add_trait = {
						trait = leader_trait_maniacal
						show_message = no
					}
				}
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_sapient_AI_assistant
					}
					add_trait = {
						trait = leader_trait_sapient_AI_assistant
						show_message = no
					}
				}
			}
		}
		general = {
			random_list = {
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_restrained
					}
					add_trait = {
						trait = leader_trait_restrained
						show_message = no
					}
				}
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_butcher
					}
					add_trait = {
						trait = leader_trait_butcher
						show_message = no
					}
				}
				1 = {
					modifier = {
						factor = 0
						has_trait = leader_trait_army_logistician
					}
					add_trait = {
						trait = leader_trait_army_logistician
						show_message = no
					}
				}
			}
		}
	}
}
effect_extsynth_leader_trait_tweaks_scientist = {
	random_list = {
		1 = {
			modifier = {
				factor = 0
				has_trait = leader_trait_meticulous
			}
			add_trait = {
				trait = leader_trait_meticulous
				show_message = no
			}
		}
		1 = {
			modifier = {
				factor = 0
				has_trait = leader_trait_spark_of_genius
			}
			add_trait = {
				trait = leader_trait_spark_of_genius
				show_message = no
			}
		}
		1 = {
			modifier = {
				factor = 0
				has_trait = leader_trait_carefree
			}
			add_trait = {
				trait = leader_trait_carefree
				show_message = no
			}
		}
		1 = {
			modifier = {
				factor = 0
				has_trait = leader_trait_roamer
			}
			add_trait = {
				trait = leader_trait_roamer
				show_message = no
			}
		}
		1 = {
			modifier = {
				factor = 0
				has_trait = leader_trait_maniacal
			}
			add_trait = {
				trait = leader_trait_maniacal
				show_message = no
			}
		}
		1 = {
			modifier = {
				factor = 0
				has_trait = leader_trait_sapient_AI_assistant
			}
			add_trait = {
				trait = leader_trait_sapient_AI_assistant
				show_message = no
			}
		}
	}
}

create_synth_species_effect = {
	if = {
		limit = {
			NOT = {
				exists = event_target:synthspecies@root.owner
			}
		}
		if = {
			limit = {
				owner_main_species = {
					has_trait = trait_psionic
				}
			}
			owner_main_species = {
				create_species = {
					is_mod = yes
					name = this
					plural = this
					class = "ROBOT"
					portrait = "default_robot"
					traits = {
						trait = trait_mechanical
						trait = trait_psionic
					}
					can_be_modified = this
					homeworld = this
					namelist = this
					gender = this
	
					effect = {
						set_synth_origin_traits_effect = yes
						if = {
							limit = {
								prevprevprevprev = {
									NOT = {
										has_country_flag = extsynths_option_16
									}
								}
							}
							set_synth_or_robot_portrait_effect = yes
						}
						save_global_event_target_as = synthspecies@root.owner
					}
				}
			}
		}
		else_if = {
			limit = {
				owner_main_species = {
					has_trait = trait_latent_psionic
				}
			}
			owner_main_species = {
				create_species = {
					is_mod = yes
					name = this
					plural = this
					class = "ROBOT"
					portrait = "default_robot"
					traits = {
						trait = trait_mechanical
						trait = trait_latent_psionic
					}
					can_be_modified = this
					homeworld = this
					namelist = this
					gender = this
	
					effect = {
						set_synth_origin_traits_effect = yes
						if = {
							limit = {
								prevprevprevprev = {
									NOT = {
										has_country_flag = extsynths_option_16
									}
								}
							}
							set_synth_or_robot_portrait_effect = yes
						}
						save_global_event_target_as = synthspecies@root.owner
					}
				}
			}
		}
		else = {
			owner_main_species = {
				create_species = {
					is_mod = yes
					name = this
					plural = this
					class = "ROBOT"
					portrait = "default_robot"
					traits = {
						trait = trait_mechanical
					}
					can_be_modified = this
					homeworld = this
					namelist = this
					gender = this
	
					effect = {
						set_synth_origin_traits_effect = yes
						if = {
							limit = {
								prevprevprevprev = {
									NOT = {
										has_country_flag = extsynths_option_16
									}
								}
							}
							set_synth_or_robot_portrait_effect = yes
						}
						save_global_event_target_as = synthspecies@root.owner
					}
				}
			}
		}
		owner = {
			if = {
				limit = {
					has_policy_flag = robots_outlawed
				}
				set_policy = {
					policy = robot_pop_policy
					option = robot_pops_allowed
					cooldown = yes
				}
			}
			if = {
				limit = {
					OR = {
						has_policy_flag = ai_servitude
						has_policy_flag = ai_outlawed
					}
				}
				set_policy = {
					policy = artificial_intelligence_policy
					option = ai_full_rights
					cooldown = yes
				}
			}
		}
	}
}

create_extsynth_robots = {
	if = {
		limit = {
			NOT = {
				exists = event_target:synthspecies@root.owner
			}
		}
		if = {
			limit = {
				owner_main_species = {
					has_trait = trait_psionic
				}
			}
			owner_main_species = {
				create_species = {
					is_mod = yes
					name = this
					plural = this
					class = "ROBOT"
					portrait = "default_robot"
					traits = {
						trait = trait_mechanical
						trait = trait_psionic
					}
					can_be_modified = this
					homeworld = this
					namelist = this
					gender = this
	
					effect = {
						set_synth_origin_traits_effect = yes
						if = {
							limit = {
								prevprevprevprev = {
									NOT = {
										has_country_flag = extsynths_option_16
									}
								}
							}
							set_synth_or_robot_portrait_effect = yes
						}
						save_global_event_target_as = synthspecies@root.owner
					}
				}
			}
		}
		else_if = {
			limit = {
				owner_main_species = {
					has_trait = trait_latent_psionic
				}
			}
			owner_main_species = {
				create_species = {
					is_mod = yes
					name = this
					plural = this
					class = "ROBOT"
					portrait = "default_robot"
					traits = {
						trait = trait_mechanical
						trait = trait_latent_psionic
					}
					can_be_modified = this
					homeworld = this
					namelist = this
					gender = this
	
					effect = {
						set_synth_origin_traits_effect = yes
						if = {
							limit = {
								prevprevprevprev = {
									NOT = {
										has_country_flag = extsynths_option_16
									}
								}
							}
							set_synth_or_robot_portrait_effect = yes
						}
						save_global_event_target_as = synthspecies@root.owner
					}
				}
			}
		}
		else = {
			owner_main_species = {
				create_species = {
					is_mod = yes
					name = this
					plural = this
					class = "ROBOT"
					portrait = "default_robot"
					traits = {
						trait = trait_mechanical
					}
					can_be_modified = this
					homeworld = this
					namelist = this
					gender = this
	
					effect = {
						set_synth_origin_traits_effect = yes
						if = {
							limit = {
								prevprevprevprev = {
									NOT = {
										has_country_flag = extsynths_option_16
									}
								}
							}
							set_synth_or_robot_portrait_effect = yes
						}
						save_global_event_target_as = synthspecies@root.owner
					}
				}
			}
		}
		owner = {
			if = {
				limit = {
					has_policy_flag = robots_outlawed
				}
				set_policy = {
					policy = robot_pop_policy
					option = robot_pops_allowed
					cooldown = yes
				}
			}
			if = {
				limit = {
					OR = {
						has_policy_flag = ai_servitude
						has_policy_flag = ai_outlawed
					}
				}
				set_policy = {
					policy = artificial_intelligence_policy
					option = ai_full_rights
					cooldown = yes
				}
			}
		}
	}
}