namespace = est_cooperativity

#Cooperativity Adopt. Bonus to planets with many pops.
country_event = {
	id = est_cooperativity.1
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		has_active_tradition = tr_est_cooperativity_adopt
	}
	
	immediate = {
		every_owned_planet = {
			if = {
				limit = {
					num_pops > 23
				}
				if = {
					limit = {
						Not = {	
							has_modifier = mod_est_cooperativity_adopt_3
						}
					}
					add_modifier = {
						modifier = "mod_est_cooperativity_adopt_3"
						days = -1
					}
				}
				if = {
					limit = {
						has_modifier = mod_est_cooperativity_adopt_2
					}
					remove_modifier = "mod_est_cooperativity_adopt_2"
				}
				if = {
					limit = {
						has_modifier = mod_est_cooperativity_adopt_1
					}
					remove_modifier = "mod_est_cooperativity_adopt_1"
				}
			}
			else = {
				if = {
					limit = {
						num_pops > 19
					}
					if = {
						limit = {
							Not = {	
								has_modifier = mod_est_cooperativity_adopt_2
							}
						}
						add_modifier = {
							modifier = "mod_est_cooperativity_adopt_2"
							days = -1
						}
					}
					if = {
						limit = {
							has_modifier = mod_est_cooperativity_adopt_3
						}
						remove_modifier = "mod_est_cooperativity_adopt_3"
					}
					if = {
						limit = {
							has_modifier = mod_est_cooperativity_adopt_1
						}
						remove_modifier = "mod_est_cooperativity_adopt_1"
					}
				}	
				else = {
					if = {
						limit = {
							num_pops > 15
						}
						if = {
							limit = {
								Not = {	
									has_modifier = mod_est_cooperativity_adopt_1
								}
							}
							add_modifier = {
								modifier = "mod_est_cooperativity_adopt_1"
								days = -1
							}
						}
						if = {
							limit = {
								has_modifier = mod_est_cooperativity_adopt_2
							}
							remove_modifier = "mod_est_cooperativity_adopt_2"
						}
						if = {
							limit = {
								has_modifier = mod_est_cooperativity_adopt_3
							}
							remove_modifier = "mod_est_cooperativity_adopt_3"
						}
					}		
					else = {
						if = {
							limit = {
								has_modifier = mod_est_cooperativity_adopt_1
							}
							remove_modifier = "mod_est_cooperativity_adopt_1"
						}
						if = {
							limit = {
								has_modifier = mod_est_cooperativity_adopt_2
							}
							remove_modifier = "mod_est_cooperativity_adopt_2"
						}
						if = {
							limit = {
								has_modifier = mod_est_cooperativity_adopt_3
							}
							remove_modifier = "mod_est_cooperativity_adopt_3"
						}
					}					
				}				
			}
		}
	}
}

#Cooperativity 4, previous ruler gets cognition_central trait.
country_event = {
	id = est_cooperativity.2
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		has_active_tradition = tr_est_cooperativity_4
		from = {
			Not = {
				has_trait = leader_trait_admiral_est_cognition_central
				has_trait = leader_trait_general_est_cognition_central
				has_trait = leader_trait_governor_est_cognition_central
				has_trait = leader_trait_scientist_est_cognition_central
			}		
		}
	}

	immediate = {
		from = {
			if = {
				limit = { leader_class = admiral }
				add_trait = leader_trait_admiral_est_cognition_central
				break = yes
			}
			if = {
				limit = { leader_class = general }
				add_trait = leader_trait_general_est_cognition_central
				break = yes
			}
			if = {
				limit = { leader_class = governor }
				add_trait = leader_trait_governor_est_cognition_central
				break = yes
			}
			if = {
				limit = { leader_class = scientist }
				add_trait = leader_trait_scientist_est_cognition_central
				break = yes
			}
		}
	}
}
	
#Cooperativity 4, spawned leader gets cognition_central trait.
country_event = {
	id = est_cooperativity.3
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		has_active_tradition = tr_est_cooperativity_4
		from = {
			Not = {
				has_trait = leader_trait_admiral_est_cognition_central
				has_trait = leader_trait_general_est_cognition_central
				has_trait = leader_trait_governor_est_cognition_central
				has_trait = leader_trait_scientist_est_cognition_central
			}		
		}
	}

	immediate = {
		from = {
			if = {
				limit = { leader_class = admiral }
				add_trait = leader_trait_admiral_est_cognition_central
				add_ruler_trait = leader_trait_ruler_est_cognition_central
				break = yes
			}
			if = {
				limit = { leader_class = general }
				add_trait = leader_trait_general_est_cognition_central
				add_ruler_trait = leader_trait_ruler_est_cognition_central
				break = yes
			}
			if = {
				limit = { leader_class = governor }
				add_trait = leader_trait_governor_est_cognition_central
				add_ruler_trait = leader_trait_ruler_est_cognition_central
				break = yes
			}
			if = {
				limit = { leader_class = scientist }
				add_trait = leader_trait_scientist_est_cognition_central
				add_ruler_trait = leader_trait_ruler_est_cognition_central
				break = yes
			}
			if = {
				limit = { leader_class = ruler }
				add_ruler_trait = leader_trait_ruler_est_cognition_central
				break = yes
			}
		}
	}
}

