namespace = est_aesthetics

### AESTHETICS ###

#Aesthetics adopt, adds/removes bonus when monument/temple built/destroyed
planet_event = {
	id = est_aesthetics.1
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {	
		Or = {
			And = {
				owner = {
					has_active_tradition = tr_est_aesthetics_adopt
				}
				Or = {
					last_building_changed = building_autochthon_monument
					last_building_changed = building_heritage_site
					last_building_changed = building_hypercomms_forum
					last_building_changed = building_autocurating_vault
				}
			}
			And = {
				owner = {
					has_active_tradition = tr_est_aesthetics_adopt_spiritualist
				}
				Or = {
					last_building_changed = building_temple
					last_building_changed = building_holotemple
					last_building_changed = building_sacred_nexus
					last_building_changed = building_citadel_of_faith
				}
			}
			And = {
				owner = {
					has_active_tradition = tr_est_aesthetics_adopt_megacorp
				}
				Or = {
					last_building_changed = building_corporate_monument
					last_building_changed = building_corporate_site
					last_building_changed = building_corporate_forum
					last_building_changed = building_corporate_vault	
				}
			}
		}
	}
	
	immediate = {
		if = {
			limit = {
				owner = {
					has_active_tradition = tr_est_aesthetics_adopt
				}
			}
			if = {
				limit = {
					Or = {
						has_building = building_autochthon_monument
						has_building = building_heritage_site
						has_building = building_hypercomms_forum
						has_building = building_autocurating_vault							
					}
				}
				if = {
					limit = {
						Not = {
							has_modifier = mod_est_aesthetics_adopt
						}
					}
					add_modifier = {
						modifier = mod_est_aesthetics_adopt
						days = -1
					}
				}
			}
			else = {
				if = {
					limit = {
						has_modifier = mod_est_aesthetics_adopt
					}
					remove_modifier = mod_est_aesthetics_adopt
				}
			}
		}	
		if = {
			limit = {
				owner = {
					has_active_tradition = tr_est_aesthetics_adopt_spiritualist
				}
			}
			if = {
				limit = {
					Or = {
						has_building = building_temple
						has_building = building_holotemple
						has_building = building_sacred_nexus
						has_building = building_citadel_of_faith							
					}
				}
				if = {
					limit = {
						Not = {
							has_modifier = mod_est_aesthetics_adopt
						}
					}
					add_modifier = {
						modifier = mod_est_aesthetics_adopt
						days = -1
					}
				}
			}
			else = {
				if = {
					limit = {
						has_modifier = mod_est_aesthetics_adopt
					}
					remove_modifier = mod_est_aesthetics_adopt
				}
			}
		}	
		if = {
			limit = {
				owner = {
					has_active_tradition = tr_est_aesthetics_adopt_megacorp
				}
			}
			if = {
				limit = {
					Or = {
						has_building = building_corporate_monument
						has_building = building_corporate_site
						has_building = building_corporate_forum
						has_building = building_corporate_vault								
					}
				}
				if = {
					limit = {
						Not = {
							has_modifier = mod_est_aesthetics_adopt
						}
					}
					add_modifier = {
						modifier = mod_est_aesthetics_adopt
						days = -1
					}
				}
			}
			else = {
				if = {
					limit = {
						has_modifier = mod_est_aesthetics_adopt
					}
					remove_modifier = mod_est_aesthetics_adopt
				}
			}
		}	
	}
}

#Aesthetics adopt, adds/removes bonus when monument/temple exists/don't exist on transfered planet (or new owner do not have tradition).
planet_event = {
	id = est_aesthetics.2
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {	
		Or = {
			And = {
				has_modifier = mod_est_aesthetics_adopt
				owner = {
					Not = {
						has_active_tradition = tr_est_aesthetics_adopt
						has_active_tradition = tr_est_aesthetics_adopt_spiritualist
						has_active_tradition = tr_est_aesthetics_adopt_megacorp					
					}
				}
			}
			And = {
				owner = {
					Or = {
						has_active_tradition = tr_est_aesthetics_adopt
						has_active_tradition = tr_est_aesthetics_adopt_spiritualist		
						has_active_tradition = tr_est_aesthetics_adopt_megacorp			
					}
				}
			}
		}
	}
	
	immediate = {
		if = {
			limit = {
				has_modifier = mod_est_aesthetics_adopt
				owner = {
					Not = {
						has_active_tradition = tr_est_aesthetics_adopt
						has_active_tradition = tr_est_aesthetics_adopt_spiritualist		
						has_active_tradition = tr_est_aesthetics_adopt_megacorp			
					}
				}			
			}
			remove_modifier = "mod_est_aesthetics_adopt"
		}
		else = {
			if = {
				limit = {
					Or = {
						And = {
							owner = {
								has_active_tradition = tr_est_aesthetics_adopt
							}
							Or = {
								has_building = building_autochthon_monument
								has_building = building_heritage_site
								has_building = building_hypercomms_forum
								has_building = building_autocurating_vault
							}		
						}
						And = {
							owner = {
								has_active_tradition = tr_est_aesthetics_adopt_spiritualist
							}
							Or = {
								has_building = building_temple
								has_building = building_holotemple
								has_building = building_sacred_nexus
								has_building = building_citadel_of_faith
							}		
						}
						And = {
							owner = {
								has_active_tradition = tr_est_aesthetics_adopt_megacorp
							}
							Or = {
								has_building = building_corporate_monument
								has_building = building_corporate_site
								has_building = building_corporate_forum
								has_building = building_corporate_vault		
							}		
						}
					}
				}
				add_modifier = {
					modifier = mod_est_aesthetics_adopt
					days = -1
				}					
			}
		}
	}
}

#Aesthetics 3 xenophobe, more unity while at war.
country_event = {
	id = est_aesthetics.3
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {	
		has_active_tradition = tr_est_aesthetics_3_xenophobe
	}
	
	immediate = {
		if = {
			limit = {
				is_at_war = yes
			}
			if = {
				limit = {
					Not = {
						has_modifier = mod_est_aesthetics_3_xenophobe
					}
				}
				add_modifier = {
					modifier = mod_est_aesthetics_3_xenophobe
					days = -1
				}
			}
		}
		else = {
			if = {
				limit = {
					has_modifier = mod_est_aesthetics_3_xenophobe
				}
				remove_modifier = mod_est_aesthetics_3_xenophobe
			}					
		}
	}
}

#Aesthetics 5, sets flag when wonder constructed.
planet_event = {
	id = est_aesthetics.4
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {	
		owner = {
			has_active_tradition = tr_est_aesthetics_5
		}
		Or = {
			last_building_changed = building_est_aesthetics_5_wonder_garden
			last_building_changed = building_est_aesthetics_5_wonder_monument
			last_building_changed = building_est_aesthetics_5_wonder_stage
			last_building_changed = building_est_aesthetics_5_wonder_halls
			last_building_changed = building_est_aesthetics_5_wonder_museum
		}
	}
	
	immediate = {
		switch = {
			trigger = has_building

			building_est_aesthetics_5_wonder_garden = {owner = { set_country_flag = flag_est_aesthetics_5_built_garden } }
			building_est_aesthetics_5_wonder_monument = {owner = { set_country_flag = flag_est_aesthetics_5_built_monument } }
			building_est_aesthetics_5_wonder_stage = {owner = { set_country_flag = flag_est_aesthetics_5_built_stage } }
			building_est_aesthetics_5_wonder_halls = {owner = { set_country_flag = flag_est_aesthetics_5_built_halls } }
			building_est_aesthetics_5_wonder_museum = {owner = { set_country_flag = flag_est_aesthetics_5_built_museum } }
		}
	}
}

#Aesthetics 5, removes flag when building destroyed.
planet_event = {
	id = est_aesthetics.5
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {	
		owner = {
			has_active_tradition = tr_est_aesthetics_5
		}
		Or = {
			last_building_changed = building_est_aesthetics_5_wonder_garden
			last_building_changed = building_est_aesthetics_5_wonder_monument
			last_building_changed = building_est_aesthetics_5_wonder_stage
			last_building_changed = building_est_aesthetics_5_wonder_halls
			last_building_changed = building_est_aesthetics_5_wonder_museum
		}
	}
	
	immediate = {
		switch = {
			trigger = last_building_changed

			building_est_aesthetics_5_wonder_garden = {owner = { remove_country_flag = flag_est_aesthetics_5_built_garden } }
			building_est_aesthetics_5_wonder_monument = {owner = { remove_country_flag = flag_est_aesthetics_5_built_monument } }
			building_est_aesthetics_5_wonder_stage = {owner = { remove_country_flag = flag_est_aesthetics_5_built_stage } }
			building_est_aesthetics_5_wonder_halls = {owner = { remove_country_flag = flag_est_aesthetics_5_built_halls } }
			building_est_aesthetics_5_wonder_museum = {owner = { remove_country_flag = flag_est_aesthetics_5_built_museum } }
		}
	}
}
