# See wg_example.txt for an explanation

#开放边境，割让被占领的宣称星系，成为希灵仆从国
wg_open_border = {
	casus_belli = cb_open_border
	
	hide_if_no_cb = yes
	#set_defender_wargoal = wg_assert_overlordship
	cede_claims = occupied_only
	
	surrender_acceptance = -50
	
	potential = {
		has_authority = auth_xilin_mind #进攻方是希灵帝国
	}
	possible = {
		always = yes
	}
		
	on_accept = {
		custom_tooltip = wg_open_border_accept
		hidden_effect = {
		  #强迫开放边境
			set_country_flag = f_open_border_to_xilin
	    remove_country_flag = f_refuse_open_border_to_xilin
	    #对希灵帝国外交评价，他们强迫我们开放边境
			add_opinion_modifier = { modifier = opinion_forced_to_open_border   who = root }
				
			#获得100点影响力
			add_influence = 100						
		}
	}
	
	
	ai_weight = {
		weight = 100
	}
}

#仆从国(征服)
wg_xilin_servant = {
	casus_belli = cb_xilin_subjugation
	
	hide_if_no_cb = yes
	
	cede_claims = yes
	
	surrender_acceptance = -100
	
	potential = {
		has_authority = auth_xilin_mind #进攻方是希灵帝国
	}
	possible = {
		always = yes
	}
		
	on_accept = {
		hidden_effect = {
			from = {
				add_threat = {
					who = root
					amount = 0.5
				}				
			}	
		}		
		from = {
			set_subject_of = {
				who = root
				subject_type = xilin_servant
			}	
		}	
	}
	
	
	ai_weight = {
		weight = 150
	}
}

#惩戒
wg_xilin_discipline = {
	casus_belli = cb_xilin_discipline
	
	hide_if_no_cb = yes
	
	cede_claims = yes
	
	surrender_acceptance = -100
	
	potential = {
		has_authority = auth_xilin_mind #进攻方是希灵帝国
	}
	possible = {
		always = yes
	}
		
	on_accept = {
		hidden_effect = {
			from = {
				add_threat = {
					who = root
					amount = 0.5
				}				
			}	
		}		
		from = {
			set_subject_of = {
				who = root
				subject_type = xilin_discipline
			}	
		}	
	}
	
	
	ai_weight = {
		weight = 150
	}
}

#清洗邪恶
wg_punish_evil = {
	casus_belli = cb_evil
	
	hide_if_no_cb = yes
	total_war = yes
	set_defender_wargoal = wg_against_xilin
	
	surrender_acceptance = -1000
	war_exhaustion = 0.25

	potential = {
		always = yes
	}
	possible = {
		always = yes
	}
	
	ai_weight = {
		weight = 200
	}
}

#反抗希灵暴政
wg_against_xilin = {
	casus_belli = cb_event

	total_war = yes
	
	surrender_acceptance = -1000
	war_exhaustion = 0.25
	
	potential = {
		always = no # event only
	}
	possible = {
		always = yes
	}
	
	ai_weight = {
		weight = 200
	}
}

#反抗暴政(解放)
wg_xilin_liberate = {
	casus_belli = cb_xilin_liberate
	
	hide_if_no_cb = yes
	
	cede_claims = no
	
	surrender_acceptance = -100
	
	potential = {
		has_authority = auth_xilin_mind #进攻方是希灵帝国
	}
	possible = {
		#对殖民地有宣称
		from = {
				always = yes
		}
	}
		
	on_accept = {
		custom_tooltip = wg_xilin_liberate_accept
		hidden_effect = {
		 #若有宣称星球已消失则终止
		 if = {
		 			limit = {
		 					NOT = {
		 						#有殖民星球星系有宣称
		 					  from = {		 							
	      					any_system_within_border = {
										any_planet = { 
												is_colony = yes
										}
										root = { has_claim = prev }
									}
								}
		 					}	
		 			}
		 			#log = "no colony claim"
		 			break = yes
		 }
		 #选择一个已有宣称的星球
		 from = {
				random_owned_planet = {
						limit = {
								is_colony = yes
								solar_system = { root = { has_claim = prev } }
						}
						save_event_target_as = new_country_species
						save_event_target_as = new_country_planet
				}				
		 }
		 #宣称的星系建立新国家
		 create_country = {
				name = random
				type = default
				#auto_delete = <bool>
				#name_list = <key>
				#ship_prefix = <string>
				species = event_target:new_country_species
				authority = random
				ethos = random
				civics = random 				
				flag =  random 
				day_zero_contact = no		
				ignore_initial_colony_error = yes		
				effect = { 
						#调整思潮
						if = {
								limit = {								
										OR = {
												has_ethic = ethic_fanatic_xenophobe
												has_ethic = ethic_xenophobe
										}
									
								}
								shift_ethic = ethic_xenophile
						}
						if = {
								limit = {
									 has_ethic = ethic_fanatic_authoritarian									
								}
								shift_ethic = ethic_egalitarian
						}
						save_event_target_as = new_country
				} #effect
			}
			#把有宣称星系给新国家
			from = {
				every_system_within_border = {
						limit = {
								root = { has_claim = prev }
						}
						#星系内的星球给新国家
						every_system_planet = {
								limit = {	is_colony = yes	}
								set_owner = event_target:new_country
								set_controller = event_target:new_country
						}
						#星堡给新国家
						if = {
							limit = {
								exists = starbase
							}
							starbase = { 
								set_owner = event_target:new_country 								
							}
						}
						#移除其它国家宣称
						remove_claims = { who = root }
						remove_claims = { who = prev }
				}
				
		  }
			event_target:new_country = {
			    #建立外交关系，并添加观点
					establish_communications_no_message = root
					establish_communications_no_message = from
					establish_contact = { who = root location = event_target:new_country_planet }
					establish_contact = { who = from location = event_target:new_country_planet }						
					add_modifier = {
								modifier = "recently_liberated"
								days = 7200
					}
					add_opinion_modifier = { modifier = opinion_liberated_us who = root }
					root = { add_opinion_modifier = { modifier = opinion_we_liberated who = prev } }
					
					every_country = {
								limit = { is_in_federation_with = root }
								establish_communications_no_message = prev
								establish_contact = { who = prev location = event_target:new_country_planet }
								add_opinion_modifier = { modifier = opinion_we_liberated who = prev }
								event_target:new_country = { add_opinion_modifier = { modifier = opinion_liberated_us who = prev } }				
					}
					#创建舰队
					create_fleet_from_naval_cap = 0.5
			}
			#给目标国家添加威胁值
			from = {
				add_threat = {
					who = root
					amount = 0.25
				}				
			}
		} #hidden_effect
	}
	
	ai_weight = {
		weight = 150
	}
}