namespace = est_friendship

#Friendship Opener, gives unity and remove penalty for first contact.
country_event = {
	id = est_friendship.1
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {	
		Or = {
			has_active_tradition = tr_est_friendship_adopt
			from = {
				has_active_tradition = tr_est_friendship_adopt
			}
		}
	}
	immediate = {
		if = {
			limit = {
				has_opinion_modifier = { 
					who = from
					modifier = opinion_new_contact
				}
			}
			remove_opinion_modifier = { 
				who = from
				modifier = opinion_new_contact
			}
		}
		if = {
			limit = {
				has_active_tradition = tr_est_friendship_adopt
			}
			add_monthly_resource_mult = { 
				resource = unity
				value = 12
				max = 1000000
				min = 4
			}
		}
		from = {
			if = {
				limit = {
					has_opinion_modifier = { 
						who = root
						modifier = opinion_new_contact
					}
				}
				remove_opinion_modifier = { 
					who = root
					modifier = opinion_new_contact
				}
			}
			if = {
				limit = {
					has_active_tradition = tr_est_friendship_adopt
				}
				add_monthly_resource_mult = { 
					resource = unity
					value = 12
					max = 1000000
					min = 4
				}
			}
		}
	}
}

#Friendship 4 militarist, potentially adds bonus when entering war.
country_event = {
	id = est_friendship.2
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {	
		has_active_tradition = tr_est_friendship_4_militarist
		Not = {
			has_modifier = mod_est_friendship_4_militarist
		}
		from = {
			Or = {
				And = {
					any_defender = {
						is_same_value = root
					}
					any_defender = {
						Not = {
							is_same_value = root
						}
					}
				}
				And = {
					any_attacker = {
						is_same_value = root
					}
					any_attacker = {
						Not = {
							is_same_value = root
						}
					}
				}
			}
		}
	}
	
	immediate = {
		add_modifier = {
			modifier = "mod_est_friendship_4_militarist"
			days = -1
		}		
	}
}

#Friendship 4 militarist, potentially removes bonus when war ends.
country_event = {
	id = est_friendship.3
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {	
		has_active_tradition = tr_est_friendship_4_militarist
		has_modifier = mod_est_friendship_4_militarist
	}
	
	immediate = {
		if = {
			limit = {
				is_at_war = no
			}
			remove_modifier = "mod_est_friendship_4_militarist"
			break = yes
		}
		if = {
			limit = {
				Not = {
					any_war = {
						Or = {
							And = {
								any_defender = {
									is_same_value = root
								}
								any_defender = {
									Not = {
										is_same_value = root
									}
								}
							}
							And = {
								any_attacker = {
									is_same_value = root
								}
								any_attacker = {
									Not = {
										is_same_value = root
									}
								}
							}
						}
					}
				}
			}
			remove_modifier = "mod_est_friendship_4_militarist"
		}
	}
}

#Friendship finish, bonus to planets with at least 3 species.
country_event = {
	id = est_friendship.4
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		has_active_tradition = tr_est_friendship_finish
	}
	
	immediate = {
		every_owned_planet = {
			if = {
				limit = {
					num_species > 2
				}
				if = {
					limit = {
						Not = {
							has_modifier = mod_est_friendship_finish
						}
					}
					add_modifier = {
						modifier = "mod_est_friendship_finish"
						days = -1
					}
				}
			}
			else = {
				if = {
					limit = {
						has_modifier = mod_est_friendship_finish					
					}
					remove_modifier = "mod_est_friendship_finish"
				}				
			}
		}
	}
}

