namespace = est_destruction


#Destruction 1, influence from purging.
planet_event = {
	id = est_destruction.1
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		from = {
			OR = {
				has_active_tradition = tr_est_destruction_1
			}
		}
		fromfrom = {
			is_robot_pop = no
			NOT = {
				is_same_species = owner_species
			}
		}
		is_controlled_by = from
	}
	
	immediate = {
		from = {
			add_resource = {
				influence = 2
			}
		}
	}
}

#Destruction 3, penalty to fleet on entering battle.
country_event = {
	id = est_destruction.2
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_global_flag = est_destruction_3_picked_flag
		Or = {
			has_active_tradition = tr_est_destruction_3
			from = {
				has_active_tradition = tr_est_destruction_3
			}
		}
	}
	
	immediate = {
		if = {
			limit = {
				from = {
					has_active_tradition = tr_est_destruction_3
				}
				fromfrom = {
					Not = {
						has_modifier = mod_est_destruction_3
					}
				}
			}
			fromfrom = {
				add_modifier = {
					modifier = "mod_est_destruction_3"
					years = 1
				}
			}
		}
		fromfromfrom = {
			if = {
				limit = {
					root = {
						has_active_tradition = tr_est_destruction_3
					}
					Not = {
						has_modifier = mod_est_destruction_3
					}
				}
				add_modifier = {
					modifier = "mod_est_destruction_3"
					years = 1
				}
			}
		}
	}
}

#Destruction 3, removes modifier once battle is over.
country_event = {
	id = est_destruction.3
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		always = no #Temporary, developers fix "has_modifier = mod_est_destruction_3" for ships.
		has_global_flag = est_destruction_3_picked_flag
		Or = {
			fromfrom = {
				has_modifier = mod_est_destruction_3
			}
			fromfromfrom = {
				has_modifier = mod_est_destruction_3
			}
		}
	}
	
	immediate = {
		if = {
			limit = {
				fromfrom = {
					has_modifier = mod_est_destruction_3
				}
			}
			fromfrom = {
				remove_modifier = "mod_est_destruction_3"
			}
		}
		if = {
			limit = {
				fromfromfrom = {
					has_modifier = mod_est_destruction_3
				}
			}
			fromfromfrom = {
				remove_modifier = "mod_est_destruction_3"
			}
		}
	}
}

#Destruction 4, penalty to neighbours.
country_event = {
	id = est_destruction.4
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		has_active_tradition = tr_est_destruction_4
	}

	immediate = {
		every_neighbor_country = {
			limit = {
				Not = {
					has_ethic = ethic_gestalt_consciousness					
				}
			}
			set_timed_country_flag = {
				flag = est_destruction_4_flag
				days = 1
			}
			if = {
				limit = {
					Not = {
						has_modifier = mod_est_destruction_4
					}
				}
				add_modifier = {
					modifier = "mod_est_destruction_4"
					days = -1
				}
			}
		}
	}
}

#Destruction 4, removes penalty from those that should not have it anymore.
country_event = {
	id = est_destruction.5
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		Not = {	
			has_country_flag = est_destruction_4_flag			
		}
		has_modifier = mod_est_destruction_4
	}

	immediate = {
		remove_modifier = "mod_est_destruction_4"
	}
}

#Destruction 5 (empires which cannot have rivals), influence while at war.
country_event = {
	id = est_destruction.6
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {	
		has_active_tradition = tr_est_destruction_5_no_rivals
	}
	
	immediate = {
		if = {
			limit = {
				is_at_war = yes
			}
			if = {
				limit = {
					Not = {
						has_modifier = mod_est_destruction_5_no_rivals
					}
				}
				add_modifier = {
					modifier = mod_est_destruction_5_no_rivals
					days = -1
				}
			}
		}
		else = {
			if = {
				limit = {
					has_modifier = mod_est_destruction_5_no_rivals
				}
				remove_modifier = mod_est_destruction_5_no_rivals
			}					
		}
	}
}

#Destruction finish, adds modifier on war declared. 
country_event = {
	id = est_destruction.7
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {	
		has_global_flag = est_destruction_finish_picked_flag
		from = {
			any_war_participant = { 
				is_at_war_with = root
				has_active_tradition = tr_est_destruction_finish
			}
		}
		Not = {
			has_modifier = mod_est_destruction_finish
		}
	}
	
	immediate = {
		add_modifier = {
			modifier = "mod_est_destruction_finish"
			days = -1
		}
	}
}

#Destruction finish, removes modifier when war ends.
country_event = {
	id = est_destruction.8
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {	
		has_modifier = mod_est_destruction_finish
		Or = {
			is_at_war = no
			Not = {
				any_country = {
					is_at_war_with = root
					has_active_tradition = tr_est_destruction_finish
				}
			}
		}
	}
	
	immediate = {
		remove_modifier = "mod_est_destruction_finish"
	}
}
