namespace = est_general

#Sets flag that the mod is in use
country_event = {
	id = est_general.1
	hide_window = yes
	fire_only_once = yes
	trigger = { 
		NOT = { 
			has_global_flag = expanded_stellaris_traditions_mod_in_use 
		}
	}
	immediate = { 
		set_global_flag = expanded_stellaris_traditions_mod_in_use 
	}
}

#Remove planet modifiers from a planet when ownerless or occupation is transfered.
planet_event = {
	id = est_general.2
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {					
		#Aesthetics
		if = {
			limit = { has_modifier = mod_est_aesthetics_adopt }
			remove_modifier = "mod_est_aesthetics_adopt"
		}
		
		#Commerce
		if = {
			limit = { has_modifier = mod_est_commerce_2_energy }
			remove_modifier = "mod_est_commerce_2_energy"
		}
		if = {
			limit = { has_modifier = mod_est_commerce_2_food }
			remove_modifier = "mod_est_commerce_2_food"
		}
		if = {
			limit = { has_modifier = mod_est_commerce_2_minerals }
			remove_modifier = "mod_est_commerce_2_minerals"
		}
				
		#Foundation/Confederacy/Subminds
		if = {
			limit = { has_modifier = mod_est_foundation_adopt }
			remove_modifier = "mod_est_foundation_adopt"
		}
		if = {
			limit = { has_modifier = mod_est_foundation_1 }
			remove_modifier = "mod_est_foundation_1"
		}
		if = {
			limit = { has_modifier = mod_est_foundation_2_1 }
			remove_modifier = "mod_est_foundation_2_1"
		}
		if = {
			limit = { has_modifier = mod_est_foundation_2_2 }
			remove_modifier = "mod_est_foundation_2_2"
		}
		if = {
			limit = { has_modifier = mod_est_foundation_2_3 }
			remove_modifier = "mod_est_foundation_2_3"
		}
		
		if = {
			limit = { has_modifier = mod_est_confederacy_adopt }
			remove_modifier = "mod_est_confederacy_adopt"
		}
		if = {
			limit = { has_modifier = mod_est_confederacy_2 }
			remove_modifier = "mod_est_confederacy_2"
		}
		
		if = {
			limit = { has_modifier = mod_est_subminds_adopt }
			remove_modifier = "mod_est_subminds_adopt"
		}
		if = {
			limit = { has_modifier = mod_est_subminds_2 }
			remove_modifier = "mod_est_subminds_2"
		}
		if = {
			limit = { has_modifier = mod_est_subminds_3_energy }
			remove_modifier = "mod_est_subminds_3_energy"
		}
		if = {
			limit = { has_modifier = mod_est_subminds_3_minerals }
			remove_modifier = "mod_est_subminds_3_minerals"
		}
		if = {
			limit = { has_modifier = mod_est_subminds_3_food }
			remove_modifier = "mod_est_subminds_3_food"
		}
		if = {
			limit = { has_modifier = mod_est_subminds_3_research }
			remove_modifier = "mod_est_subminds_3_research"
		}		
		if = {
			limit = { has_modifier = mod_est_subminds_3_unity }
			remove_modifier = "mod_est_subminds_3_unity"
		}		
		
		#Friendship/Malice/Perseverance (IP)
		if = {
			limit = { has_modifier = mod_est_friendship_finish }
			remove_modifier = "mod_est_friendship_finish"
		}
		
		if = {
			limit = { has_modifier = mod_est_malice_1_no_slaves }
			remove_modifier = "mod_est_malice_1_no_slaves"
		}	

		#Industry
		if = {
			limit = { has_modifier = mod_est_industry_5 }
			remove_modifier = "mod_est_industry_5"
		}
		if = {
			limit = { has_modifier = mod_est_industry_5_GC }
			remove_modifier = "mod_est_industry_5_GC"
		}
		if = {
			limit = { has_modifier = mod_est_industry_5_machines }
			remove_modifier = "mod_est_industry_5_machines"
		}

		#Liberty
		if = {
			limit = { has_modifier = mod_est_liberty_3 }
			remove_modifier = "mod_est_liberty_3"
		}	

		#Cooperativity		
		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"
		}	
		if = {
			limit = { has_modifier = mod_est_cooperativity_5 }
			remove_modifier = "mod_est_cooperativity_5"
		}	
		if = {
			limit = { has_modifier = mod_est_cooperativity_5_machines }
			remove_modifier = "mod_est_cooperativity_5_machines"
		}	

		#Spaceborn
		if = {
			limit = { has_modifier = mod_est_spaceborn_5_habitat }
			remove_modifier = "mod_est_spaceborn_5_habitat"
		}	

		#Collectivism/Perseverance
		if = {
			limit = { has_modifier = mod_est_collectivism_3 }
			remove_modifier = "mod_est_collectivism_3"
		}
	}
}

#Checks that the country have built a robot.
planet_event = {
	id = est_general.3
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {	
		owner = {
			Not = {
				has_country_flag = est_built_robot
			}
		}
	}
	
	immediate = {
		owner = {
			set_country_flag = est_built_robot
		}
	}
}

#A war have begun, triggers other events.
country_event = {
	id = est_general.4
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		country_event = {
			id = est_general.7
			days = 1
		}
	}
}

#A war have ended (triggered if one side won), triggers other events.
country_event = {
	id = est_general.5
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		fromfrom = {
			every_war_participant = {
				country_event = {
					id = est_general.7
					days = 1
				}
			}
		}
	}
}

#A war have ended (triggered on white peace), triggers other events.
country_event = {
	id = est_general.6
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		fromfromfromfrom = {
			every_war_participant = {
				country_event = {
					id = est_general.7
					days = 1
				}
			}
		}
	}
}

#Updates war modifiers
country_event = {
	id = est_general.7
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		country_event = {
			id = est_aesthetics.3
		}
		country_event = {
			id = est_friendship.3
		}
		country_event = {
			id = est_friendship.13
		}
		country_event = {
			id = est_isolation.3
		}
		country_event = {
			id = est_isolation.4
		}
		country_event = {
			id = est_proselytism.4
		}
		country_event = {
			id = est_destruction.6
		}
		country_event = {
			id = est_destruction.8
		}
		country_event = {
			id = est_liberty.4
		}
		country_event = {
			id = est_piracy.1
		}
	}
}