namespace = xilin_diplomacy

#ϣ⽻¼

# ϣ۹ִĹҴ
# This = Planet scope
# From = Country
# FromFrom = Pop
planet_event = {
	id = xilin_diplomacy.1
	hide_window = yes
	
	is_triggered_only = yes
	
	trigger = {
		FROMFROM = {
			is_robot_pop = no
			is_sapient = yes
			NOT = { has_trait = "trait_hive_mind" }
			NOT = { has_purge_type = { country = from type = purge_neutering } }
		}
		is_controlled_by = FROM
		FROM = { NOT = { has_country_flag  = f_evil_country }}
	}
	
	immediate = {
		random_country = {
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				NOT = { is_same_species = ROOT }
				has_authority = auth_xilin_mind  #ϣ۹
			}
			#log = "From is [From.GetName]"
			#log = "FromFrom is [FromFrom.GetName]"
			root = { save_event_target_as = genocide_planet }
			FromFrom = { save_event_target_as = genocide_pop }
			From = {
			   save_event_target_as = genocide_country
			   set_country_flag = f_evil_country #ϣ۹Ϊа
			   add_modifier = { modifier = m_evil_country } 
			   #е˿ڱΪ
			   every_owned_pop ={
			     limit = {
			        is_same_species = prev
			        NOT = { has_pop_flag = f_pop_of_crime}
			     }
			     set_pop_flag = f_pop_of_crime
			     add_modifier = {
			    		modifier = pop_of_crime   
		  		 }
			   }
			}
			country_event = { id = xilin_diplomacy.11  }
		}		
	}
	
}

#ȳɳɵ˿ڴ
# A pop has become fully grown
# This = pop
pop_event = {
	 id = "xilin_diplomacy.2"
	 hide_window = yes
   is_triggered_only = yes
   
   trigger = {
       owner = { has_country_flag  = f_evil_country }
       is_same_species = owner
	}
 
	immediate = {
	  set_pop_flag = f_pop_of_crime
		add_modifier = {
			     modifier = pop_of_crime   
		}
	  
	}
}

#һҽ嵱ʵãȱ
# We changed a species right
# This = pop
pop_event = {
	 id = "xilin_diplomacy.3"
	 hide_window = yes
   is_triggered_only = yes
   
  trigger = {
       owner = { NOT = { has_country_flag  = f_evil_country } }
       has_slavery_type = { 
					country = owner
					type = slavery_livestock 
			} 
	}
 
	immediate = {
	    save_event_target_as = genocide_pop
	    owner = {
	       save_event_target_as = genocide_country
	       set_country_flag = f_evil_country #ϣ۹Ϊа
			   add_modifier = { modifier = m_evil_country } 
			   #е˿ڱΪ
			   every_owned_pop ={
			     limit = {
			        is_same_species = Prev
			        NOT = { has_pop_flag = f_pop_of_crime}
			     }
			     set_pop_flag = f_pop_of_crime
			     add_modifier = {
			    		modifier = pop_of_crime   
		  		 }
			   }
	    }
	    random_country = {
	       limit = { has_authority = auth_xilin_mind }
	       country_event = { id = xilin_diplomacy.12  }
	    }	  
	}
}

###
#ű߾ϣսƳű߾flag־
# This = country
# From = opponent war leader
# on_entering_war
country_event = {
	id = xilin_diplomacy.4
	hide_window = yes
  is_triggered_only = yes
	
	trigger = { #ϣս
	  OR = {
	  		has_authority = auth_xilin_mind 
	  		From = { has_authority = auth_xilin_mind } 	  
	  }     
	}
	
	immediate = {
	   #log = "[This.GetName] enter war against [From.GetName]"
	   remove_country_flag = f_open_border_to_xilin
	   remove_country_flag = f_agree_destroy_claim 
	   #ԭȵϣ۹ӹ,Ƴϣbuff
	   if = {
	   		limit = {
	      	OR = {
				  	has_modifier =  m_xilin_discipline
	   				has_modifier =  m_xilin_servant_vassal
	   				has_modifier =  m_xilin_follower
	   				has_modifier =  m_xilin_blessed
					}
				}
	   		#Ƴmodifierflag
	   		country_event = { id = xilin_diplomacy.5  }
	   }
	}	
}

##
#ŵϣ鸽ӹƳmodifierflag
country_event = {
	id = xilin_diplomacy.5
	hide_window = yes
  is_triggered_only = yes

	immediate = {
	   #Ƴϣ۹йصflag
	   remove_country_flag = f_open_border_to_xilin
	   remove_country_flag = f_refuse_open_border_to_xilin
	   #Ƴϣ鸽ӹйصmodifier
	   remove_modifier =  m_xilin_discipline
	   remove_modifier =  m_xilin_servant_vassal
	   remove_modifier =  m_xilin_follower
	   remove_modifier =  m_xilin_blessed
	}	
}

#ͽ¼
country_event = {
	id = xilin_diplomacy.6
	hide_window = yes
  is_triggered_only = yes
	
	trigger = {
	   is_subject = yes
     is_subject_type = xilin_discipline
	}
	
	immediate = {
	   save_event_target_as = vassal_country
	   overlord = {
	       save_event_target_as = overlord_country
	   }
	   if = { #ϣҳϣλΪʹӹ
	      limit = {
	         is_loyal_to = overlord 
	      }
	      set_subject_of = { who = overlord subject_type = xilin_servant }
	      set_timed_country_flag = { flag = f_new_vassal  days = 3600 }
			   if = {
			     limit = { NOT = { has_modifier = m_xilin_servant_vassal } }
			     add_modifier = { modifier = m_xilin_servant_vassal  }
			   }			   
			   if = {
			     limit = { NOT = { has_modifier = m_xilin_tech_dependence  } }
			     add_modifier = { modifier = m_xilin_tech_dependence  }
			   }			   
			   #Ƴԭļ
			   remove_modifier =  m_xilin_discipline
			   #Ƴű߾flag
			   remove_country_flag = f_refuse_open_border_to_xilin
			   remove_country_flag = f_open_border_to_xilin
	      #Ϣӹ
	      country_event = { id = xilin_diplomacy.7  }
	      #Ϣ
	      overlord = { country_event = { id = xilin_diplomacy.8  } }
	      
	      else = { #ӹϵ,Ƴmodifierflag
	      	set_subject_of = { who = none }
	      	#Ƴmodifierflag
	      	country_event = { id = xilin_diplomacy.5  }
	      	#֪ͨѾӹ
	        country_event = { id = xilin_diplomacy.9  }
	        #֪ͨѾӹ
	        event_target:overlord = { country_event = { id = xilin_diplomacy.10  } }
	      } #else
	   } #if
	}	
}

#ͽʾѽʹӹ
country_event = {
	id = xilin_diplomacy.7
	title = overloard_speak
	desc = xilin_diplomacy.7.desc
	
	is_triggered_only = yes
	diplomatic = yes
	force_open = yes
	
	picture_event_data = {	  
		portrait = event_target:overlord_country
		planet_background = event_target:overlord_country
		graphical_culture = event_target:overlord_country
		city_level = event_target:overlord_country
		room = event_target:overlord_country
	}
  
	option = {
	  name = LONG_LIVE_THE_EMPIRE
	}	
	
}

#ʾĳͽѽʹӹ
country_event = {
	id = xilin_diplomacy.8
	title = "xilin_diplomacy.8.name"
	desc = xilin_diplomacy.8.desc
	picture = GFX_evt_galactic_senate
	show_sound = tut_uplift_reminder
  is_triggered_only = yes
		
	option = {
	  name = OK
	}	
}

#ͽʾĳͽѾ
country_event = {
	id = xilin_diplomacy.9
	title = "xilin_diplomacy.9.name"
	desc = xilin_diplomacy.9.desc
	picture = GFX_evt_galactic_senate
	show_sound = tut_uplift_reminder
  is_triggered_only = yes
		
	option = {
	  name = WE_NEVER_FORGET
	}	
}
#ʾĳͽѾͽ
country_event = {
	id = xilin_diplomacy.10
	title = "xilin_diplomacy.9.name"
	desc = xilin_diplomacy.10.desc
	picture = GFX_evt_galactic_senate
	show_sound = tut_uplift_reminder
  is_triggered_only = yes
		
	option = {
	  name = I_KNOW
	}	
}

#ɱ
country_event = {
	id = xilin_diplomacy.11
	title = "xilin_diplomacy.11.name"
	desc = xilin_diplomacy.11.desc
	picture = GFX_evt_burning_settlement
	show_sound = tut_uplift_reminder
  is_triggered_only = yes
		
	option = {
	  name = EVIL_WILL_BE_PUNISHED
	}	
}

#
country_event = {
	id = xilin_diplomacy.12
	title = "xilin_diplomacy.12.name"
	desc = xilin_diplomacy.12.desc
	picture = GFX_evt_burning_settlement
	show_sound = tut_uplift_reminder
  is_triggered_only = yes
		
	option = {
	  name = EVIL_WILL_BE_PUNISHED
	}	
}

#׷()Զ׷(ӹ)
country_event = { 
	id = xilin_diplomacy.13
	hide_window = yes

	is_triggered_only = yes

	trigger = {
			 exists = overlord
			 overlord = { has_authority = auth_xilin_mind }
			 is_subject_type = xilin_follower_protector
			 tech_unlocked_ratio = {
									who = overlord
									ratio > 0.5
			 }
	}

	immediate = {
			set_subject_of = {  who = overlord  subject_type = xilin_follower_vassal	}	  
			set_timed_country_flag = { flag = f_new_vassal  days = 3600 }  
	}
}

# ϣսܱ
# A war has been lost
# This = Loser Warleader
# From = Winner Warleader
country_event = {
	id = xilin_diplomacy.14
	title = xilin_diplomacy.13.name
	desc = xilin_diplomacy.13.desc
	picture = GFX_evt_fallen_empire
	show_sound = event_planetary_riot
	location = root
	
	is_triggered_only = yes
	
	trigger = {
		from = { 
			has_authority = auth_xilin_mind
		}
		NOT = { has_ethic = ethic_gestalt_consciousness }
		has_country_flag  = f_insult_xilin
	}

	immediate = {	  
	  #log = "kill leader triggered"
	  save_event_target_as = insult_country
		ruler = {
			save_event_target_as = rulername
			kill_leader = {
				type = ruler
				show_notification = no
			}
		}
		from = { country_event = { id = xilin_diplomacy.15  } }
		remove_country_flag = f_insult_xilin
	}

	option = {
		name = fallen_empires.2.a
		custom_tooltip = fallen_empires.2.a.tooltip	
	}
}

country_event = {
	id = xilin_diplomacy.15
	title = xilin_diplomacy.14.name
	desc = xilin_diplomacy.14.desc
	picture = GFX_evt_fallen_empire
	show_sound = event_planetary_riot
	location = root
	
	is_triggered_only = yes
	
	option = {
		name = LONG_LIVE_THE_EMPIRE
	}
}

###
#
# This = country
# From = opponent war leader
# on_entering_war
country_event = {
	id = xilin_diplomacy.1000
	hide_window = yes
  is_triggered_only = yes
	
	
	immediate = {
	   log = "[This.GetName] enter war against [From.GetName]"
	   
	}	
}