namespace = xilin_ai

#当希灵帝国是ai时的ai处理

#希灵ai处理入口
# No scope, like on_game_start
#on_monthly_pulse = {
event = {
	id = xilin_ai.1
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
			any_country = {
					has_authority = auth_xilin_mind
					is_ai = yes
			}
	}

	immediate = {
		random_country = {
			limit = { 
					has_authority = auth_xilin_mind
					is_ai = yes
			}
			country_event = { id = xilin_ai.2 }
		}
	}
}
#希灵ai外交思考回路
#要求其他国家开放边境
country_event = {
	id = xilin_ai.2
	hide_window = yes
  is_triggered_only = yes
  
  trigger = {
			has_authority = auth_xilin_mind
			is_ai = yes
	}

	immediate = {
	   		#第1天考虑要求ai开放边境
	  		if = {
	  				limit = {
	  						any_country ={
	  								has_communications = prev
	  								has_closed_borders = prev
	  								is_country_type = default
	  								OR = {
			    							relative_power = { who = prev  category = fleet  value = equivalent }
			    							relative_power = { who = event_target:Dip_Country  category = fleet  value = inferior }
			    							relative_power = { who = event_target:Dip_Country  category = fleet  value = pathetic }
			    					}
			    					NOT = { has_country_flag  = f_refuse_open_border_to_xilin	}
	  						}
	  						#没有正在进行的其它外交对话
	  						NOT = { has_country_flag  = more_diplomacy_engaged	}
	  				}
	  				random_country = {
	  						limit = {
	  								has_communications = prev
	  								has_closed_borders = prev
	  								is_country_type = default
	  								OR = {	  										
			    							relative_power = { who = prev  category = fleet  value = equivalent }
			    							relative_power = { who = event_target:Dip_Country  category = fleet  value = inferior }
			    							relative_power = { who = event_target:Dip_Country  category = fleet  value = pathetic }
			    					}
			    					NOT = { has_country_flag  = f_refuse_open_border_to_xilin	}  						
	  						}
	  						save_event_target_as = Dip_More_OP_Country
	  				}
	  				#打开要求开放边境对话
	  				set_country_flag = more_diplomacy_engaged
	  				country_event = { id = xilin_diplo_dlg.2 }
	  		}
	   		#过2天考虑下一步
	      country_event = { id = xilin_ai.3   days = 2   random = 1 }
	}	
}

#考虑仆从国晋升
country_event = {
	id = xilin_ai.3
	hide_window = yes
  is_triggered_only = yes
  
  trigger = {
			has_authority = auth_xilin_mind
			is_ai = yes
	}

	immediate = {
	   		#第3天考虑仆从国晋升,能晋升则晋升
	  		if = {
	  				limit = {
	  						any_country ={
	  								is_subject = yes
	  								is_subject_type = xilin_servant
			       				exists = overlord
			       				overlord = { is_same_empire = prev }
			       				is_loyal_to = prev
	  								NOT = { has_country_flag = f_new_vassal }	  								
	  						}
	  						#没有正在进行的其它外交对话
	  						NOT = { has_country_flag  = more_diplomacy_engaged	}
	  				}
	  				random_country = {
	  						limit = {
	  								is_subject = yes
	  								is_subject_type = xilin_servant
			       				exists = overlord
			       				overlord = { is_same_empire = prev }
			       				is_loyal_to = prev
	  								NOT = { has_country_flag = f_new_vassal }	 						
	  						}
	  						save_event_target_as = Dip_More_OP_Country
	  				}
	  				#仆从国晋升
	  				set_country_flag = more_diplomacy_engaged
	  				country_event = { id = xilin_diplo_dlg.4 }
	  		}
	   		#过2天考虑下一步
	      country_event = { id = xilin_ai.4   days = 2   random = 1 }	   
	}	
}

#考虑对附庸的科技援助
country_event = {
	id = xilin_ai.4
	hide_window = yes
  is_triggered_only = yes
  
  trigger = {
			has_authority = auth_xilin_mind
			is_ai = yes
	}

	immediate = {
	   		#第6天考虑对附庸的科技援助
	  		if = {
	  				limit = {
	  						any_country ={
	  								is_subject = yes
			       				exists = overlord
			       				overlord = { is_same_empire = prev }
			       				is_loyal_to = prev
			       				NOT = { 
			       					is_subject_type = xilin_discipline
										}
										NOT = {
											tech_unlocked_ratio = {
												who = root
												ratio > 0.8
											}
										}
										has_country_flag = f_get_tech_lib
	  								NOT = { has_modifier = m_xilin_tech_assistance  } 
	  						}
	  						#没有正在进行的其它外交对话
	  						NOT = { has_country_flag  = more_diplomacy_engaged	}
	  				}
	  				random_country = {
	  						limit = {
	  								is_subject = yes
			       				exists = overlord
			       				overlord = { is_same_empire = prev }
			       				is_loyal_to = prev
			       				NOT = { 
			       					is_subject_type = xilin_discipline
										}
										NOT = {
											tech_unlocked_ratio = {
												who = root
												ratio > 0.8
											}
										}
										has_country_flag = f_get_tech_lib
	  								NOT = { has_modifier = m_xilin_tech_assistance  } 			
	  						}
	  						save_event_target_as = Dip_More_OP_Country
	  				}
	  				#科技援助
	  				set_country_flag = more_diplomacy_engaged
	  				country_event = { id = xilin_diplo_dlg.6 }
	  		}
	   		#过2天考虑下一步
	      country_event = { id = xilin_ai.5   days = 2   random = 1 }	   
	   
	}	
}

#考虑要求链接科技数据库
country_event = {
	id = xilin_ai.5
	hide_window = yes
  is_triggered_only = yes
  
  trigger = {
			has_authority = auth_xilin_mind
			is_ai = yes
	}

	immediate = {
	   		#第9天考虑要求链接科技数据库
	  		if = {
	  				limit = {
	  						any_country ={
	  								AND = {
			       						is_subject = yes
			       						exists = overlord
			       						overlord = { is_same_empire = root }
			    					}
			    					NOT = { has_country_flag = f_get_tech_lib }
	  						}
	  						#没有正在进行的其它外交对话
	  						NOT = { has_country_flag  = more_diplomacy_engaged	}
	  				}
	  				random_country = {
	  						limit = {
	  								AND = {
			       						is_subject = yes
			       						exists = overlord
			       						overlord = { is_same_empire = root }
			    					}
			    					NOT = { has_country_flag = f_get_tech_lib }	
	  						}
	  						save_event_target_as = Dip_More_OP_Country
	  				}
	  				#链接数据库
	  				set_country_flag = more_diplomacy_engaged
	  				country_event = { id = xilin_diplo_dlg.21 }
	  		}
	   		#过2天考虑下一步
	      country_event = { id = xilin_ai.6   days = 2   random = 1 }		   
	}	
}

#考虑要求放弃对希灵领土宣称
country_event = {
	id = xilin_ai.6
	hide_window = yes
  is_triggered_only = yes
  
  trigger = {
			has_authority = auth_xilin_mind
			is_ai = yes
	}

	immediate = {
	   		#第12天考虑要求放弃对希灵领土宣称
	  		if = {
	  				limit = {
	  						any_country ={
	  								has_claim = ROOT
			    					NOR = { 
			    							has_country_flag = f_refuse_destroy_claim 
					 							has_country_flag = f_agree_destroy_claim 					  
										}
										#不是希灵的敌人
										is_xilin_enemy = no
	  						}
	  						#没有正在进行的其它外交对话
	  						NOT = { has_country_flag  = more_diplomacy_engaged	}
	  				}
	  				random_country = {
	  						limit = {
	  								has_claim = ROOT
			    					NOR = { 
			    							has_country_flag = f_refuse_destroy_claim 
					 							has_country_flag = f_agree_destroy_claim 					  
										}
										#不是希灵的敌人
										is_xilin_enemy = no
	  						}
	  						save_event_target_as = Dip_More_OP_Country
	  				}
	  				#要求放弃宣称
	  				set_country_flag = more_diplomacy_engaged
	  				country_event = { id = xilin_diplo_dlg.19 }
	  		}
	   		#过2天考虑下一步
	      country_event = { id = xilin_ai.7   days = 2   random = 1 }		   
	}	
}

#要求附庸改革政府
country_event = {
	id = xilin_ai.7
	hide_window = yes
  is_triggered_only = yes
  
  trigger = {
			has_authority = auth_xilin_mind
			is_ai = yes
	}

	immediate = {
	   		#第15天考虑要求附庸改革政府
	  		if = {
	  				limit = {
	  						influence > 100
								unity > 1000
	  						any_country ={
	  								AND = {
			       					is_subject = yes
			       					exists = overlord
			       					overlord = { is_same_empire = root }
			    					}
			    					NOT = { 
					  					is_subject_type = xilin_discipline
										}
										subject_need_rebuild_gov = yes
										is_loyal_to = root
	  						}
	  						#没有正在进行的其它外交对话
	  						NOT = { has_country_flag  = more_diplomacy_engaged	}
	  				}
	  				random_country = {
	  						limit = {
	  								AND = {
			       					is_subject = yes
			       					exists = overlord
			       					overlord = { is_same_empire = root }
			    					}
			   	 					NOT = { 
					  					is_subject_type = xilin_discipline
										}
										subject_need_rebuild_gov = yes
										is_loyal_to = root
	  						}
	  						save_event_target_as = Dip_More_OP_Country
	  				}
	  				#要求附庸改革政府
	  				set_country_flag = more_diplomacy_engaged
	  				country_event = { id = xilin_diplo_dlg.7 }
	  		}
	   
	   
	}	
}