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 = {
					pop_amount >= 10000
				}
				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 = {
						pop_amount >= 5000
					}
					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 = {
							pop_amount >= 2500
						}
						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_official_est_cognition_central
				has_trait = leader_trait_scientist_est_cognition_central
			}		
		}
	}

	immediate = {
		from = {
			if = {
				limit = {
					has_trait = subclass_commander_admiral
				}
				add_trait = { trait = leader_trait_admiral_est_cognition_central }
				break = yes
			}
#			if = {
#				limit = {
#					has_trait = subclass_commander_general
#				}
#				add_trait = { trait = leader_trait_general_est_cognition_central }
#				break = yes
#			}
			if = {
				limit = { leader_class = official }
				add_trait = { trait = leader_trait_official_est_cognition_central }
				break = yes
			}
			if = {
				limit = { leader_class = scientist }
				add_trait = { 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 #(Ben_D): sub-classes need to be assigned first
				has_trait = leader_trait_official_est_cognition_central
				has_trait = leader_trait_scientist_est_cognition_central
			}		
		}
	}

	immediate = {
		from = {
			if = {
				limit = { leader_class = commander }
				add_trait = { trait = leader_trait_admiral_est_cognition_central }
				break = yes
			}
			if = {
				limit = { leader_class = official }
				add_trait = { trait = leader_trait_official_est_cognition_central }
				break = yes
			}
			if = {
				limit = { leader_class = scientist }
				add_trait = { trait = leader_trait_scientist_est_cognition_central }
				break = yes
			}
		}
	}
}

country_event = {
	id = est_cooperativity.4
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_tradition = tr_est_cooperativity_4
		from = {
			leader_class = commander 
			Not = {
				has_leader_flag = flag_est_cooperativity_4
			}
		}
	}
	
	immediate = {
		from = {
			set_leader_flag = flag_est_cooperativity_4
		}
		if = {
			limit = {
				has_active_tradition = tr_est_cooperativity_4
			}
			from = {
				if = {
					limit = {
						NOR = {
							has_trait = leader_trait_admiral_est_cognition_central
							has_leader_flag = flag_est_cooperativity_4
						}
						has_trait = subclass_commander_admiral
					}
					add_trait = { trait = leader_trait_admiral_est_cognition_central }
				}
#				else_if = {
#					limit = { 
#						NOR = {
#							has_trait = leader_trait_general_est_cognition_central
#							has_leader_flag = flag_est_cooperativity_4
#						}
#						has_trait = subclass_commander_general
#					}
#					add_trait = { trait = leader_trait_general_est_cognition_central }
#				}
			}
		}
	}
}

country_event = {
	id = est_cooperativity.5
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		has_active_tradition = tr_est_cooperativity_adopt_wilderness
	}
	
	immediate = {
		every_owned_planet = {
			if = {
				limit = {
					free_district_slots = 0
				}
				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 = {
						free_district_slots <= 5
					}
					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 = {
							free_district_slots <= 10
						}
						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"
						}
					}					
				}				
			}
		}
	}
}