namespace = MT_royalty

# A pop amount has been assembled, try to transfer it to assimilation target if applicable
# This = Planet scope
# From = Country
# FromFrom = Pop group
# local_pop_amount = variable of how much was assembled
carrier_event = {
	id = MT_royalty.1
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		owner = { has_active_tradition = tr_mt_royalty_broodmother_machine }
		fromfrom = {
			is_robot_pop = yes
			NOT = { has_trait = trait_MT_special_care }
		}
		is_homeworld = yes
	}

	immediate = {
		fromfrom = {
			save_event_target_as = old_pop_group
			species = {
				save_event_target_as = old_species
			}
		}
		if = {
			limit = {
				any_galaxy_species = {
					has_species_flag = MT_lovingly_crafted@root.owner
				}
			}
			random_galaxy_species = {
				limit = { has_species_flag = MT_lovingly_crafted@root.owner }
				save_event_target_as = lovingly_crafted_species
			}
		}
		else = {
			modify_species = {
				species = event_target:old_species # species to modify
				base = root.owner
				add_trait = trait_MT_special_care # optional, can specify multiple
				add_traits_at_start_of_list = yes # optional, pushes out other traits if needed
				change_scoped_species = no
				effect = {
					set_species_flag = MT_lovingly_crafted@root.owner
				} # optional effect to run on the resulting new species, is executed after any handling of change_scoped_species
			}
		}
		random_galaxy_species = {
			limit = {
				has_species_flag = MT_lovingly_crafted@root.owner
			}
			save_event_target_as = target_species
		}
		this = {
			create_pop_group = {
				pop_group = event_target:old_pop_group
				species = event_target:target_species
				size = 0
				effect = {
					transfer_pop_amount = {
						source = event_target:old_pop_group
						target = this
						amount = root.local_pop_amount
						growth_category = "GROWTH_CAT_ASSEMBLY"
					}
					apply_post_assimilation_effects = yes
				}
			}
		}
	}
}

country_event = {
	id = MT_royalty.2
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		has_tradition = tr_mt_royalty_grand_entrance
	}

	immediate = {
		if = {
			limit = { has_modifier = MT_grand_entrance_modifier }
			remove_modifier = MT_grand_entrance_modifier
		}
		add_modifier = {
			modifier = MT_grand_entrance_modifier
			days = 1800
		}
	}
}