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
					}
				}
	   		#移除modifier与flag
	   		country_event = { id = xilin_diplomacy.5  }
	   }
	}	
}

##
#被解放的希灵附庸移除相关modifier与flag
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 = { #否则解除附庸关系,移除相关modifier和flag
	      	set_subject_of = { who = none }
	      	#移除modifier与flag
	      	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]"
	   
	}	
}