namespace = est_foundation

#Foundation 2, bonus to capital.
country_event = {
	id = est_foundation.1
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		has_active_tradition = tr_est_foundation_2
		exists = capital_scope
	}
	
	immediate = { 
		capital_scope = {		
			if = {
				limit = {
					owner = {
						has_technology = tech_galactic_administration
					}
				}	
				if = {
					limit = {
						Not = {
							has_modifier = mod_est_foundation_2_3
						}
					}
					add_modifier = {
						modifier = "mod_est_foundation_2_3"
					}	
					owner = {
						country_event = {
							id = est_foundation.2
						}
					}
				}
			}
			else = {
				if = {
					limit = {
						owner = {
							has_technology = tech_colonial_centralization
						}
					}
					if = {
						limit = {
							Not = {
								has_modifier = mod_est_foundation_2_2
							}
						}
						add_modifier = {
							modifier = "mod_est_foundation_2_2"
						}	
						owner = {
							country_event = {
								id = est_foundation.2
							}
						}
					}
				}
				else = {
					if = {
						limit = {
							Not = {
								has_modifier = mod_est_foundation_2_1
							}
						}
						add_modifier = {
							modifier = "mod_est_foundation_2_1"
						}	
						owner = {
							country_event = {
								id = est_foundation.2
							}
						}
					}
				}
			}
		}
	}
}

#Foundation 2, we have changed capital, remove bonus from old capital.
country_event = {
	id = est_foundation.2
	hide_window = yes
	is_triggered_only = yes
	
	immediate = { 
		every_owned_planet = {
			limit = {
				is_capital = no
				Or = {
					has_modifier = mod_est_foundation_2_1
					has_modifier = mod_est_foundation_2_2
					has_modifier = mod_est_foundation_2_3
				}
			}
			switch = {
				trigger = has_modifier
				
				mod_est_foundation_2_1 = { remove_modifier = "mod_est_foundation_2_1" }	
				mod_est_foundation_2_2 = { remove_modifier = "mod_est_foundation_2_2" }	
				mod_est_foundation_2_3 = { remove_modifier = "mod_est_foundation_2_3" }	
			}
		}
	}
}

#Foundation 2, update bonus to capital with tech.
country_event = {
	id = est_foundation.3
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		has_active_tradition = tr_est_foundation_2
	}
	
	immediate = { 
		if = {
			limit = {
				last_increased_tech = tech_galactic_administration
			}
			capital_scope = {
				if = {
					limit = {
						has_modifier = mod_est_foundation_2_2
					}				
					remove_modifier = "mod_est_foundation_2_2"
				}
				else = {
					owner = {
						country_event = {
							id = est_foundation.2
						}
					}
				}
				add_modifier = {
					modifier = "mod_est_foundation_2_3"
				}					
			}
		}
		if = {
			limit = {
				last_increased_tech = tech_colonial_centralization
			}
			capital_scope = {
				if = {
					limit = {
						has_modifier = mod_est_foundation_2_1
					}				
					remove_modifier = "mod_est_foundation_2_1"
				}
				else = {
					owner = {
						country_event = {
							id = est_foundation.2
						}
					}
				}
				add_modifier = {
					modifier = "mod_est_foundation_2_2"
				}					
			}
		}
	}
}
