#
# can_expand = allowed to build outposts to expand borders
# potential = if possible to select in diplomatic interactions
# become_vassal = trigger when it converts into a vassal
# tech_cost_mult = tech cost multiplier if overlord has a tech
# overlord_influence = extra influence given to overlord
# joins_overlord_wars = Joins in if overlord goes to war (Defensive or Offensive)
# calls_overlord_to_war Calls overlord to war (Defensive only)
# can_do_diplomacy Can do some limited diplomacy
# overlord_becomes_warleader, if overlord takes over as warleader. Default true
# gets_sensor(yes): gets overlords sensors
# gets_access(yes): gets overlords access
# can_be_integrated(no): the overlord is able to integrate the subject
# can_switch_to: a list of other subject types this type can switch to.
# diplo_threat: threat generated from diplomatically vassalizing this type of subject
# effect: executes when subject relation is created

@protectorate_tech_threshold = 0.4
@protectorate_tech_switch = 0.5

vassal = {
	can_expand = no
	can_be_integrated = yes
	
	research_agreement = no
	research_sharing = yes	# for domination finisher

	joins_overlord_wars = yes
	calls_overlord_to_war = yes
	can_do_diplomacy = no
	
	diplo_threat = 1.5

	potential = {	
		from = { is_country_type = default }
		NOT = { has_authority = auth_xilin_mind } #希灵帝国不会成为附庸
		OR = {
			tech_unlocked_ratio = {
				who = from
				ratio > @protectorate_tech_threshold
			}
			tech_unlocked_ratio = {
				who = from
				ratio = @protectorate_tech_threshold
			}
		}
	}
	
	effect = {
		if = {
			limit = {
				from = { 	
					is_country_type_with_subjects = no
				}
			}
			set_subject_of = {
				who = none
			}
			break = yes
		}		
		if = {
			limit = {
				from = { has_valid_civic = civic_inwards_perfection }
			}
			set_subject_of = {
				who = from
				subject_type = tributary
			}
			break = yes
		}
		if = {
			limit = {
				from = { 	
					has_valid_civic = civic_hive_devouring_swarm
				}
			}
			set_subject_of = {
				who = none
			}
			break = yes
		}			
		if = {
			limit = {
				NOT = { is_same_species = from }
				from = { 
					has_valid_civic = civic_fanatic_purifiers
				}
			}
			set_subject_of = {
				who = none
			}
			break = yes
		}		
		if = {
			limit = {
				from = { 
					is_country_type = awakened_fallen_empire
					has_ethic = ethic_fanatic_materialist
				}
			}
			set_subject_of = {
				who = from
				subject_type = satellite
			}
			break = yes
		}	
		if = {
			limit = {
				from = { 
					is_country_type = awakened_fallen_empire
					has_ethic = ethic_fanatic_spiritualist
				}
			}
			set_subject_of = {
				who = from
				subject_type = dominion
			}
			break = yes
		}
		if = {
			limit = {
				from = { 
					is_country_type = awakened_fallen_empire
					has_ethic = ethic_fanatic_xenophile
				}
			}
			set_subject_of = {
				who = from
				subject_type = signatory
			}
			break = yes
		}
		if = {
			limit = {
				from = { 
					is_country_type = awakened_fallen_empire
					has_ethic = ethic_fanatic_xenophobe
				}
			}
			set_subject_of = {
				who = from
				subject_type = thrall
			}
			break = yes
		}
		#若是希灵帝国附庸转其他帝国附庸
		if = {
			limit = {
				from = { 
					NOT = { has_authority = auth_xilin_mind } #宗主国是希灵帝国
				}
				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  }
		}	
		#若是希灵帝国附庸
		if = {
			limit = {
				from = { 
					has_authority = auth_xilin_mind #宗主国是希灵帝国
				}
			}			
				#设置标记，十年后，可根据忠诚度提升为眷族
				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  }
			  }
			  #移除开放边境相关flag
			  remove_country_flag = f_refuse_open_border_to_xilin
			  remove_country_flag = f_open_border_to_xilin
			  #移除拒绝销毁宣称flag
			    remove_country_flag = f_refuse_destroy_claim
			    #不再是希灵宿敌
			    remove_country_flag = f_rival_of_xilin					     
		}		
	}	
}

protectorate = {
	can_expand = no
	can_be_integrated = yes
	
	research_agreement = no

	joins_overlord_wars = no
	calls_overlord_to_war = yes
	can_do_diplomacy = no

	tech_cost_mult = -0.80
	overlord_influence = 0.25
	
	diplo_threat = 0.75

	potential = {
		from = { is_country_type = default }
		NOT = { has_authority = auth_xilin_mind } #希灵帝国不会成为保护国
		tech_unlocked_ratio = {
			who = from
			ratio < @protectorate_tech_threshold
		}
	}
	
	effect = {
		if = {
			limit = {
				from = { 	
					is_country_type_with_subjects = no
				}
			}
			set_subject_of = {
				who = none
			}
			break = yes
		}		
		if = {
			limit = {
				from = { has_valid_civic = civic_inwards_perfection }
			}
			set_subject_of = {
				who = from
				subject_type = tributary
			}
			break = yes
		}
		if = {
			limit = {
				from = { 
					has_valid_civic = civic_hive_devouring_swarm
				}
			}
			set_subject_of = {
				who = none
			}
			break = yes
		}			
		if = {
			limit = {
				NOT = { is_same_species = from }
				from = { 
					has_valid_civic = civic_fanatic_purifiers
				}
			}
			set_subject_of = {
				who = none
			}
			break = yes
		}		
		if = {
			limit = {
				from = { 
					is_country_type = awakened_fallen_empire
					has_ethic = ethic_fanatic_materialist
				}
			}
			set_subject_of = {
				who = from
				subject_type = satellite
			}
			break = yes
		}	
		if = {
			limit = {
				from = { 
					is_country_type = awakened_fallen_empire
					has_ethic = ethic_fanatic_spiritualist
				}
			}
			set_subject_of = {
				who = from
				subject_type = dominion
			}
			break = yes
		}
		if = {
			limit = {
				from = { 
					is_country_type = awakened_fallen_empire
					has_ethic = ethic_fanatic_xenophile
				}
			}
			set_subject_of = {
				who = from
				subject_type = signatory
			}
			break = yes
		}
		if = {
			limit = {
				from = { 
					is_country_type = awakened_fallen_empire
					has_ethic = ethic_fanatic_xenophobe
				}
			}
			set_subject_of = {
				who = from
				subject_type = thrall
			}
			break = yes
		}
		#若是希灵帝国附庸转其他帝国附庸
		if = {
			limit = {
				from = { 
					NOT = { has_authority = auth_xilin_mind } #宗主国不是希灵帝国
				}
				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  }
		}
		#若是希灵帝国附庸
		if = {
			limit = {
				from = { 
					has_authority = auth_xilin_mind #宗主国是希灵帝国
				}
			}
				#设置标记，十年后，可根据忠诚度提升为追随者
				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  }
			   }			   
			   #移除开放边境相关flag
			   remove_country_flag = f_refuse_open_border_to_xilin
			   remove_country_flag = f_open_border_to_xilin	
			   #移除拒绝销毁宣称flag
			    remove_country_flag = f_refuse_destroy_claim
			    #不再是希灵宿敌
			    remove_country_flag = f_rival_of_xilin		
		}

	}		

	become_vassal = {
		tech_unlocked_ratio = {
			who = from
			ratio > @protectorate_tech_switch
		}
	}
}