namespace = est_spaceborn

#Spaceborn 4, energy from stars, update when a system lost.
country_event = {
	id = est_spaceborn.1
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {		
		has_tradition = tr_est_spaceborn_4	
	}
	
	immediate = {	
		from = {
			every_system_planet = {
				limit = {
					Or = {
						is_planet_class = pc_b_star
						is_planet_class = pc_a_star
						is_planet_class = pc_f_star
						is_planet_class = pc_g_star
						is_planet_class = pc_k_star
						is_planet_class = pc_m_star
						is_planet_class = pc_m_giant_star
						is_planet_class = pc_t_star
					}
					has_resource = { 
						type = energy
						amount > 0 
					}
				}
				if = {
					limit = {
						Nand = {
							exists = owner
							owner = {
								has_tradition = tr_est_spaceborn_4
							}
						}
						has_deposit = d_est_spaceborn_4_sun
					}
					remove_deposit = d_est_spaceborn_4_sun
				}
			}
		}
	}
}

#Spaceborn 4, energy from stars, update when a system gained.
country_event = {
	id = est_spaceborn.2
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {		
		has_tradition = tr_est_spaceborn_4	
	}
	
	immediate = {	
		from = {
			every_system_planet = {
				limit = {
					Or = {
						is_planet_class = pc_b_star
						is_planet_class = pc_a_star
						is_planet_class = pc_f_star
						is_planet_class = pc_g_star
						is_planet_class = pc_k_star
						is_planet_class = pc_m_star
						is_planet_class = pc_m_giant_star
						is_planet_class = pc_t_star
					}
					has_resource = { 
						type = energy
						amount > 0 
					}
				}
				if = {
					limit = {
						Not = {
							has_deposit = d_est_spaceborn_4_sun				
						}
					}
					add_deposit = d_est_spaceborn_4_sun
				}
			}
		}
	}
}

#Spaceborn 5, bonus production on habitats
planet_event = {
	id = est_spaceborn.3
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {		
		is_planet_class = pc_habitat	
	}
	
	immediate = {
		if = {
			limit = {
				owner = {
					Or = {
						has_active_tradition = tr_est_spaceborn_5_habitat
						has_active_tradition = tr_est_spaceborn_5_habitat_megastruct
					}
				}			
			}
			if = {
				limit = {
					Not = {
						has_modifier = mod_est_spaceborn_5_habitat
					}
				}
				add_modifier = {
					modifier = mod_est_spaceborn_5_habitat
					days = -1
				}
			}
		}
		else = {
			if = {
				limit = {
					has_modifier = mod_est_spaceborn_5_habitat
				}
				remove_modifier = mod_est_spaceborn_5_habitat
			}
		}
	}
}