namespace = ta_event



# Until I figure out a way to pass the ethos data from a purged pop to a new pop without creating a mess, each ethos needs a separate event

planet_event = { #materialist pop perfection
	id = ta_event.10
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		FROM = {
			has_edict = ta_edict_assimilate
			owner_species = {
				has_trait = trait_mechanical
			}
		}
		FROMFROM = {
			is_robot_pop = no #can't perfect whats perfected
			pop_has_ethic = "ethic_materialist"
		}
		is_controlled_by = FROM
	}
	
	immediate = {
		create_pop = { ## replaces pop with same-ethos synth
			species = owner
		}
		last_created_pop = {
			pop_change_ethic = "ethic_materialist"
			add_modifier = {
				modifier = "ta_pop_hooray_assimilation"
				days = 360
			}
		}
		every_country = { #clean up genocide opinion modifiers and add different modifiers
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				NOT = { is_same_species = ROOT }
				NOT = { has_ai_personality_behaviour = purger }
				OR = {
					is_country_type = default
					has_ai_personality = awakened_fallen_empire_xenophile				
				}	
			}
			remove_opinion_modifier = { who = FROM modifier = opinion_genocidal }
			add_opinion_modifier = { who = FROM modifier = ta_opinion_assimilated }
		}
		every_country = {
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				is_same_species = ROOT
			}
			remove_opinion_modifier = { who = FROM modifier = opinion_genocidal_our_species }
			add_opinion_modifier = { who = FROM modifier = ta_opinion_assimilated_our_species }
		}		
	}
}

planet_event = { #spiritualist pop perfection
	id = ta_event.11
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		FROM = {
			has_edict = ta_edict_assimilate
			owner_species = {
				has_trait = trait_mechanical
			}
		}
		FROMFROM = {
			is_robot_pop = no #can't perfect whats perfected
			pop_has_ethic = "ethic_spiritualist"
		}
		is_controlled_by = FROM
	}
	
	immediate = {
		create_pop = { ## replaces pop with same-ethos synth
			species = owner
		}
		last_created_pop = {
			pop_change_ethic = "ethic_spiritualist"
			add_modifier = {
			modifier = "ta_pop_boo_assimilation"
				days = 360
			}
		}
		random = {
			chance = 10
			last_created_pop = {
				kill_pop = yes # WHAT HAVE YOU DONE TO ME
			}
		}
		every_country = { #clean up genocide opinion modifiers and add different modifiers
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				NOT = { is_same_species = ROOT }
				NOT = { has_ai_personality_behaviour = purger }
				OR = {
					is_country_type = default
					has_ai_personality = awakened_fallen_empire_xenophile				
				}	
			}
			remove_opinion_modifier = { who = FROM modifier = opinion_genocidal }
			add_opinion_modifier = { who = FROM modifier = ta_opinion_assimilated }
		}
		every_country = {
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				is_same_species = ROOT
			}
			remove_opinion_modifier = { who = FROM modifier = opinion_genocidal_our_species }
			add_opinion_modifier = { who = FROM modifier = ta_opinion_assimilated_our_species }
		}		
	}
}

planet_event = { #authoritarian pop perfection
	id = ta_event.12
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		FROM = {
			has_edict = ta_edict_assimilate
			owner_species = {
				has_trait = trait_mechanical
			}
		}
		FROMFROM = {
			is_robot_pop = no #can't perfect whats perfected
			pop_has_ethic = "ethic_authoritarian"
		}
		is_controlled_by = FROM
	}
	
	immediate = {
		create_pop = { ## replaces pop with same-ethos synth
			species = owner

		}
		last_created_pop = {
			pop_change_ethic = "ethic_authoritarian"
			add_modifier = {
				modifier = "ta_pop_mildly_peeved_assimilation"
				days = 360
			}
		}
		every_country = { #clean up genocide opinion modifiers and add different modifiers
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				NOT = { is_same_species = ROOT }
				NOT = { has_ai_personality_behaviour = purger }
				OR = {
					is_country_type = default
					has_ai_personality = awakened_fallen_empire_xenophile				
				}	
			}
			remove_opinion_modifier = { who = FROM modifier = opinion_genocidal }
			add_opinion_modifier = { who = FROM modifier = ta_opinion_assimilated }
		}
		every_country = {
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				is_same_species = ROOT
			}
			remove_opinion_modifier = { who = FROM modifier = opinion_genocidal_our_species }
			add_opinion_modifier = { who = FROM modifier = ta_opinion_assimilated_our_species }
		}		
	}
}

planet_event = { #egalitarian pop perfection
	id = ta_event.13
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		FROM = {
			has_edict = ta_edict_assimilate
			owner_species = {
				has_trait = trait_mechanical
			}
		}
		FROMFROM = {
			is_robot_pop = no #can't perfect whats perfected
			pop_has_ethic = "ethic_egalitarian"
		}
		is_controlled_by = FROM
	}
	
	immediate = {
		create_pop = { ## replaces pop with same-ethos synth
			species = owner
		}
		last_created_pop = {
			pop_change_ethic = "ethic_egalitarian"
			add_modifier = {
				modifier = "ta_pop_mildly_peeved_assimilation"
				days = 360
			}
		}
	}
}

planet_event = { #pacifist pop perfection
	id = ta_event.14
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		FROM = {
			has_edict = ta_edict_assimilate
			owner_species = {
				has_trait = trait_mechanical
			}
		}
		FROMFROM = {
			is_robot_pop = no #can't perfect whats perfected
			pop_has_ethic = "ethic_pacifist"
		}
		is_controlled_by = FROM
	}
	
	immediate = {
		create_pop = { ## replaces pop with same-ethos synth
			species = owner
		}
		last_created_pop = {
			pop_change_ethic = "ethic_pacifist"
			add_modifier = {
				modifier = "ta_pop_mildly_peeved_assimilation"
				days = 360
			}
		}
		every_country = { #clean up genocide opinion modifiers and add different modifiers
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				NOT = { is_same_species = ROOT }
				NOT = { has_ai_personality_behaviour = purger }
				OR = {
					is_country_type = default
					has_ai_personality = awakened_fallen_empire_xenophile				
				}	
			}
			remove_opinion_modifier = { who = FROM modifier = opinion_genocidal }
			add_opinion_modifier = { who = FROM modifier = ta_opinion_assimilated }
		}
		every_country = {
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				is_same_species = ROOT
			}
			remove_opinion_modifier = { who = FROM modifier = opinion_genocidal_our_species }
			add_opinion_modifier = { who = FROM modifier = ta_opinion_assimilated_our_species }
		}		
	}
}

planet_event = { #militarist pop perfection
	id = ta_event.15
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		FROM = {
			has_edict = ta_edict_assimilate
			owner_species = {
				has_trait = trait_mechanical
			}
		}
		FROMFROM = {
			is_robot_pop = no #can't perfect whats perfected
			pop_has_ethic = "ethic_militarist"
		}
		is_controlled_by = FROM
	}
	
	immediate = {
		create_pop = { ## replaces pop with same-ethos synth
			species = owner
		}
		last_created_pop = {
			pop_change_ethic = "ethic_militarist"
			add_modifier = {
				modifier = "ta_pop_mildly_peeved_assimilation"
				days = 360
			}
		}
		every_country = { #clean up genocide opinion modifiers and add different modifiers
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				NOT = { is_same_species = ROOT }
				NOT = { has_ai_personality_behaviour = purger }
				OR = {
					is_country_type = default
					has_ai_personality = awakened_fallen_empire_xenophile				
				}	
			}
			remove_opinion_modifier = { who = FROM modifier = opinion_genocidal }
			add_opinion_modifier = { who = FROM modifier = ta_opinion_assimilated }
		}
		every_country = {
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				is_same_species = ROOT
			}
			remove_opinion_modifier = { who = FROM modifier = opinion_genocidal_our_species }
			add_opinion_modifier = { who = FROM modifier = ta_opinion_assimilated_our_species }
		}		
	}
}

planet_event = { #xenophobe pop perfection
	id = ta_event.16
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		FROM = {
			has_edict = ta_edict_assimilate
			owner_species = {
				has_trait = trait_mechanical
			}
		}
		FROMFROM = {
			is_robot_pop = no #can't perfect whats perfected
			pop_has_ethic = "ethic_xenophobe"
		}
		is_controlled_by = FROM
	}
	
	immediate = {
		create_pop = { ## replaces pop with same-ethos synth
			species = owner
		}
		last_created_pop = {
			pop_change_ethic = "ethic_xenophobe"
			add_modifier = {
				modifier = "ta_pop_boo_assimilation"
				days = 360
			}
		}
		random = {
			chance = 10
			last_created_pop = {
				kill_pop = yes # WHAT HAVE YOU DONE TO ME
			}
		}
		every_country = { #clean up genocide opinion modifiers and add different modifiers
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				NOT = { is_same_species = ROOT }
				NOT = { has_ai_personality_behaviour = purger }
				OR = {
					is_country_type = default
					has_ai_personality = awakened_fallen_empire_xenophile				
				}	
			}
			remove_opinion_modifier = { who = FROM modifier = opinion_genocidal }
			add_opinion_modifier = { who = FROM modifier = ta_opinion_assimilated }
		}
		every_country = {
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				is_same_species = ROOT
			}
			remove_opinion_modifier = { who = FROM modifier = opinion_genocidal_our_species }
			add_opinion_modifier = { who = FROM modifier = ta_opinion_assimilated_our_species }
		}		
	}
}

planet_event = { #xenophile pop perfection
	id = ta_event.17
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		FROM = {
			has_edict = ta_edict_assimilate
			owner_species = {
				has_trait = trait_mechanical
			}
		}
		FROMFROM = {
			is_robot_pop = no #can't perfect whats perfected
			pop_has_ethic = "ethic_xenophile"
		}
		is_controlled_by = FROM
	}
	
	immediate = {
		create_pop = { ## replaces pop with same-ethos synth
			species = owner
		}
		last_created_pop = {
			pop_change_ethic = "ethic_xenophile"
			add_modifier = {
				modifier = "ta_pop_boo_assimilation"
				days = 360
			}
		}
		every_country = { #clean up genocide opinion modifiers and add different modifiers
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				NOT = { is_same_species = ROOT }
				NOT = { has_ai_personality_behaviour = purger }
				OR = {
					is_country_type = default
					has_ai_personality = awakened_fallen_empire_xenophile				
				}	
			}
			remove_opinion_modifier = { who = FROM modifier = opinion_genocidal }
			add_opinion_modifier = { who = FROM modifier = ta_opinion_assimilated }
		}
		every_country = {
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				is_same_species = ROOT
			}
			remove_opinion_modifier = { who = FROM modifier = opinion_genocidal_our_species }
			add_opinion_modifier = { who = FROM modifier = ta_opinion_assimilated_our_species }
		}		
	}
}

planet_event = { #hivemind pop perfection, for modded in robotic hive minds
	id = ta_event.18
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		FROM = {
			has_edict = ta_edict_assimilate
			owner_species = {
				has_trait = trait_mechanical
				has_trait = trait_hive_mind
			}
		}
		FROMFROM = {
			is_robot_pop = no #can't perfect whats perfected
			pop_has_ethic = "ethic_hive_mind"
		}
		is_controlled_by = FROM
	}
	
	immediate = {
		create_pop = { ## replaces pop with same-ethos synth
			species = owner
		}
		every_country = { #clean up genocide opinion modifiers and add different modifiers
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				NOT = { is_same_species = ROOT }
				NOT = { has_ai_personality_behaviour = purger }
				OR = {
					is_country_type = default
					has_ai_personality = awakened_fallen_empire_xenophile				
				}	
			}
			remove_opinion_modifier = { who = FROM modifier = opinion_genocidal }
			add_opinion_modifier = { who = FROM modifier = ta_opinion_assimilated }
		}
		every_country = {
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				is_same_species = ROOT
			}
			remove_opinion_modifier = { who = FROM modifier = opinion_genocidal_our_species }
			add_opinion_modifier = { who = FROM modifier = ta_opinion_assimilated_our_species }
		}		
	}
}

planet_event = { #for mods that change base ethics or add new ones, the only real solution is to randomize
	id = ta_event.19
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		FROM = {
			has_edict = ta_edict_assimilate
			owner_species = {
				has_trait = trait_mechanical
			}

			
		}
		FROMFROM = {
			is_robot_pop = no #can't perfect whats perfected
			NOT = { pop_has_ethic = ethic_hive_mind }
			NOT = { pop_has_ethic = ethic_materialist }
			NOT = { pop_has_ethic = ethic_spiritualist }
			NOT = { pop_has_ethic = ethic_egalitarian }
			NOT = { pop_has_ethic = ethic_authoritarian }
			NOT = { pop_has_ethic = ethic_pacifist }
			NOT = { pop_has_ethic = ethic_militarist }
			NOT = { pop_has_ethic = ethic_xenophobe }
			NOT = { pop_has_ethic = ethic_xenophile }
		}
		is_controlled_by = FROM
	}
	
	immediate = {
		create_pop = { ## replaces pop with same-ethos synth
			species = owner
			ethos = random
		}
		every_country = { #clean up genocide opinion modifiers and add different modifiers
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				NOT = { is_same_species = ROOT }
				NOT = { has_ai_personality_behaviour = purger }
				OR = {
					is_country_type = default
					has_ai_personality = awakened_fallen_empire_xenophile				
				}	
			}
			remove_opinion_modifier = { who = FROM modifier = opinion_genocidal }
			add_opinion_modifier = { who = FROM modifier = ta_opinion_assimilated }
		}
		every_country = {
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				is_same_species = ROOT
			}
			remove_opinion_modifier = { who = FROM modifier = opinion_genocidal_our_species }
			add_opinion_modifier = { who = FROM modifier = ta_opinion_assimilated_our_species }
		}		
	}
}

pop_event = { #resistance is unnecessary
	id = ta_event.21
	hide_window = yes
	
	trigger = {
		is_enslaved = no
		is_being_purged = no
		is_robot_pop = no
		NOT = {
			OR = {
				pop_has_ethic = "ethic_xenophobe"
				pop_has_ethic = "ethic_spiritualist"
				pop_has_ethic = "ethic_hive_mind"
			}
		}
				
		happiness > 0.80
		
		planet = {
			has_owner = yes
			owner = {
				is_country_type = default
				owner_species = {
					has_trait = trait_mechanical
				}
				OR = {
					has_policy_flag = grant_ascension_manual
					has_policy_flag = grant_ascension_automatic
				}
			}
		}

	}
	
	mean_time_to_happen = {
		months = 36
	}
	immediate = {
		IF = {
			limit = {
				planet = { 
					owner = { 
						has_policy_flag = grant_ascension_manual
					}
				}
			}
			root = { pop_event = { id = ta_event.20 days = 0 } }
		}
		IF = {
			limit = {
				owner = { 
					has_policy_flag = grant_ascension_automatic
				}
			}
			planet = {
				root = {
					kill_pop = yes
				}
				create_pop = { ## replaces pop with same-ethos synth
					species = owner
				}
				last_created_pop = {
					add_modifier = {
						modifier = "ta_pop_hooray_ascension"
						days = 360
					}
					IF = {
						limit = {
							owner = {
								has_country_flag = ta_perfect_mat
							}
						}
						last_created_pop = { pop_change_ethic = "ethic_materialist" }
						owner = { remove_country_flag = ta_perfect_mat }
					}
					IF = {
						limit = {
							owner = {
								has_country_flag = ta_perfect_aut
							}
						}
						last_created_pop = { pop_change_ethic = "ethic_authoritarian" }
						owner = { remove_country_flag = ta_perfect_aut }
					}
					IF = {
						limit = {
							owner = {
								has_country_flag = ta_perfect_ega
							}
						}
						last_created_pop = { pop_change_ethic = "ethic_egalitarian" }
						owner = { remove_country_flag = ta_perfect_ega }
					}
					IF = {
						limit = {
							owner = {
								has_country_flag = ta_perfect_mil
							}
						}
						last_created_pop = { pop_change_ethic = "ethic_militarist" }
						owner = { remove_country_flag = ta_perfect_mil }
					}
					IF = {
						limit = {
							owner = {
								has_country_flag = ta_perfect_pac
							}
						}
						last_created_pop = { pop_change_ethic = "ethic_pacifist" }
						owner = { remove_country_flag = ta_perfect_pac }
					}
					IF = {
						limit = {
							owner = {
								has_country_flag = ta_perfect_phi
							}
						}
						last_created_pop = { pop_change_ethic = "ethic_xenophile" }
						owner = { remove_country_flag = ta_perfect_phi }
					}
				}
			}
		}
	}
}




pop_event = { #resistance is unnecessary event
	id = "ta_event.20"
	title = "ta_event.20.name"
	desc = "ta_event.20.desc"
	picture = GFX_evt_cybernetics
	
	is_triggered_only = yes



	option = {
		name = "ta_event.20.a" # Ascension Granted
		custom_tooltip = ta_event.20.a.tooltip
		hidden_effect = {
			planet = {
				owner = {
					IF = {
						limit = {
							root = { pop_has_ethic = "ethic_materialist" }
						}
						set_country_flag = ta_perfect_mat
					}
					IF = {
						limit = {
							root = { pop_has_ethic = "ethic_authoritarian" }
						}
						set_country_flag = ta_perfect_aut
					}
					IF = {
						limit = {
							root = { pop_has_ethic = "ethic_egalitarian" }
						}
						set_country_flag = ta_perfect_ega
					}
					IF = {
						limit = {
							root = { pop_has_ethic = "ethic_militarist" }
						}
						set_country_flag = ta_perfect_mil
					}
					IF = {
						limit = {
							root = { pop_has_ethic = "ethic_pacifist" }
						}
						set_country_flag = ta_perfect_pac
					}
					IF = {
						limit = {
							root = { pop_has_ethic = "ethic_xenophile" }
						}
						set_country_flag = ta_perfect_phi
					}
				}
			}
				
			planet = {
				root = {
					kill_pop = yes
				}
				create_pop = { ## replaces pop with same-ethos synth
					species = owner
				}
				last_created_pop = {
					add_modifier = {
						modifier = "ta_pop_hooray_ascension"
						days = 360
					}
					IF = {
						limit = {
							owner = {
								has_country_flag = ta_perfect_mat
							}
						}
						last_created_pop = { pop_change_ethic = "ethic_materialist" }
						owner = { remove_country_flag = ta_perfect_mat }
					}
					IF = {
						limit = {
							owner = {
								has_country_flag = ta_perfect_aut
							}
						}
						last_created_pop = { pop_change_ethic = "ethic_authoritarian" }
						owner = { remove_country_flag = ta_perfect_aut }
					}
					IF = {
						limit = {
							owner = {
								has_country_flag = ta_perfect_ega
							}
						}
						last_created_pop = { pop_change_ethic = "ethic_egalitarian" }
						owner = { remove_country_flag = ta_perfect_ega }
					}
					IF = {
						limit = {
							owner = {
								has_country_flag = ta_perfect_mil
							}
						}
						last_created_pop = { pop_change_ethic = "ethic_militarist" }
						owner = { remove_country_flag = ta_perfect_mil }
					}
					IF = {
						limit = {
							owner = {
								has_country_flag = ta_perfect_pac
							}
						}
						last_created_pop = { pop_change_ethic = "ethic_pacifist" }
						owner = { remove_country_flag = ta_perfect_pac }
					}
					IF = {
						limit = {
							owner = {
								has_country_flag = ta_perfect_phi
							}
						}
						last_created_pop = { pop_change_ethic = "ethic_xenophile" }
						owner = { remove_country_flag = ta_perfect_phi }
					}
				}
			}
		}
	}
	option = {
		name = "ta_event.20.b" # Ascension Denied
		custom_tooltip = ta_event.20.b.tooltip
		hidden_effect = {	
			root = {
				add_modifier = {
					modifier = "ta_pop_whatgivesbro"
					days = 360
				}
			}
		}		
	}
}

