###########################
# tier On-Action Events #
###########################
namespace = tier
country_event = {
	id = tier.1
	title = tier.1.name
	desc = tier.1.desc
	picture = GFX_evt_announcement
	show_sound = event_announcement
	location = root
	is_triggered_only = yes
	trigger = {
		is_ai = no
	}
	immediate = {
		set_global_flag = apb_tier_unlocked
	}
	option = {
		name = tier.1.unlocked
		hidden_effect = {
			set_global_flag = apb_tier_unlocked
			remove_global_flag = apb_tier_locked
		}
	}
	option = {
		name = tier.1.locked
		hidden_effect = {
			set_global_flag = apb_tier_locked
			remove_global_flag = apb_tier_unlocked
		}
	}
}

###########################
# Fountain On-Action Events #
###########################
namespace = fountain
country_event = {
	id = fountain.100
	title = "fountain.100.name"
	desc = "fountain.100.desc"
	picture = GFX_evt_fountain
	show_sound = event_engineered_evolution
	is_triggered_only = yes
	option = {
		name = "fountain.100.a"
		capital_scope = {
			enable_special_project = {
				name = "FOUNTAIN_OF_YOUTH_PROJECT"
				location = this
				owner = root
			}
		}
	}
}

country_event = {
	id = fountain.101
	title = "fountain.101.name"
	desc = "fountain.101.desc"
	picture = "GFX_evt_fountain"
	show_sound = event_engineered_evolution
	is_triggered_only = yes
	immediate = {
		add_research_option = tech_synthetic_youth
		give_technology = {
			tech = tech_synthetic_youth
		}
	}
	option = {
		name = "fountain.101.a"
	}
}

# Handle leader traits after species modification
# (Forever Young for trait_youth, Perpetually Maintained for trait_apb_perpetual_maintenance)
country_event = {
	id = fountain.200
	is_triggered_only = yes
	hide_window = yes
	immediate = {
		every_owned_leader = {
			apb_sync_all_leader_traits = yes
		}
		every_pool_leader = {
			apb_sync_all_leader_traits = yes
		}
	}
}

# Scope: country, from: the new leader
country_event = {
	id = fountain.201
	is_triggered_only = yes
	hide_window = yes
	trigger = {
		from = {
			species = {
				OR = {
					has_trait = trait_youth
					has_trait = trait_apb_perpetual_maintenance
				}
			}
		}
	}
	immediate = {
		from = { apb_sync_all_leader_traits = yes }
	}
}

###########################
# Perpetual Maintenance (synthetic counterpart of the Fountain of Youth chain)
###########################
namespace = apb_maintenance

country_event = {
	id = apb_maintenance.100
	title = "apb_maintenance.100.name"
	desc = "apb_maintenance.100.desc"
	picture = GFX_evt_robot_assembly_plant
	show_sound = event_default
	is_triggered_only = yes
	option = {
		name = "apb_maintenance.100.a"
		capital_scope = {
			enable_special_project = {
				name = "APB_PERPETUAL_MAINTENANCE_PROJECT"
				location = this
				owner = root
			}
		}
	}
}

country_event = {
	id = apb_maintenance.101
	title = "apb_maintenance.101.name"
	desc = "apb_maintenance.101.desc"
	picture = GFX_evt_robot_assembly_plant
	show_sound = event_default
	is_triggered_only = yes
	immediate = {
		give_technology = {
			tech = tech_apb_perpetual_maintenance
		}
	}
	option = {
		name = "apb_maintenance.101.a"
	}
}

###########################
# General mod events
###########################
namespace = lucasif_apb

# Marks that this mod is active (other mods can check the flag)
event = {
	id = lucasif_apb.01
	hide_window = yes
	is_triggered_only = yes
	fire_only_once = yes
	immediate = { set_global_flag = apb_ap_merger }
}

# Colonising Efforts: extra starting pops on each new colony.
# Replaces colony_start_num_pops_add (removed in 4.0). Fired by on_colonized, whose scope is the
# colony's carrier (planet, or ship for arkships); carrier_event is what vanilla and Gigastructures
# use there. Tiers stack, so the amounts are running totals of 2/3/4/5/6 pops, x100 for 4.x pop counts.
carrier_event = {
	id = lucasif_apb.10
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		exists = owner
		is_scope_type = planet	# nomad arks can be ship carriers; pops only exist on planets
		owner = { has_ascension_perk = ap_colonising_efforts }
	}
	immediate = {
		if = {
			limit = { owner = { has_ascension_perk = ap_colonising_efforts_tier_5 } }
			random_owned_pop_group = { add_pop_amount = 2000 }
		}
		else_if = {
			limit = { owner = { has_ascension_perk = ap_colonising_efforts_tier_4 } }
			random_owned_pop_group = { add_pop_amount = 1400 }
		}
		else_if = {
			limit = { owner = { has_ascension_perk = ap_colonising_efforts_tier_3 } }
			random_owned_pop_group = { add_pop_amount = 900 }
		}
		else_if = {
			limit = { owner = { has_ascension_perk = ap_colonising_efforts_tier_2 } }
			random_owned_pop_group = { add_pop_amount = 500 }
		}
		else = {
			random_owned_pop_group = { add_pop_amount = 200 }
		}
	}
}
