#ϣ۹˿¼

namespace = xilin_pop

#popϳԵı
pop_event = {
	 id = "xilin_pop.1"
	 hide_window = yes
   is_triggered_only = yes
   
   immediate = {
     set_pop_flag = f_pop_eat_energy
   }
}

#ճʹͽ50ϳԵ
pop_event = {
   id = "xilin_pop.8"
	 hide_window = yes
   is_triggered_only = yes
   
   trigger = {
          has_trait = trait_magic_machine
	 }
   
   immediate = {
       if = { 
          limit = { has_pop_flag = f_pop_eat_energy }
          remove_pop_flag = f_pop_eat_energy
       }
       if = {
          limit = { #ٷְٳԵ
             owner = { has_policy_flag = shanduola_recipes_1 }
          }
          pop_event = { id = xilin_pop.1  }
       }
       if = {
          limit = { #75%Ե
             owner = { has_policy_flag = shanduola_recipes_2 }
          }
          random_list = {
				    75 = { pop_event = { id = xilin_pop.1  } } 
				    25 = {   }    
			    }
       }
       if = {
          limit = { #50%Ե
             owner = { has_policy_flag = shanduola_recipes_3 }
          }
          random_list = {
				    50 = { pop_event = { id = xilin_pop.1  } } 
				    50 = {   }    
			    }
       }
       if = {
          limit = { #25%Ե
             owner = { has_policy_flag = shanduola_recipes_4 }
          }
          random_list = {
				    25 = { pop_event = { id = xilin_pop.1  } } 
				    75 = {   }    
			    }
       }
       if = {
          limit = { #0%Ե
             owner = { has_policy_flag = shanduola_recipes_5 }
          }
          
       }
   }
}

#ɺıʳʱıϣʹͽԵ
country_event = {
	id = xilin_pop.9
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		last_changed_policy = shanduola_recipes
	}
	immediate = {
		every_owned_pop = {
			limit = { 
				has_trait = trait_magic_machine
			}
			pop_event = { id = xilin_pop.8  } 
			
		}
	}
}



#ϣ۹ӵоסȨķ
pop_event = {
	 id = "xilin_pop.2"
	 hide_window = yes
   is_triggered_only = yes
   
   trigger = {
    AND ={
       owner = { has_authority = auth_xilin_mind }
       NOR = {
          has_trait = trait_magic_machine
          has_trait = trait_divinity
          has_trait = trait_xilin_building 
 #         has_modifier = pop_be_blessed
       }
       has_citizenship_type ={
         country = owner
			   type = citizenship_limited
       }
    }
	}
 
	immediate = {
	  if = {
	    limit = { NOT = { has_modifier = pop_be_blessed  } }
			add_modifier = {
			    modifier = pop_be_blessed   
		  }
		}
	}
}
#ϣ۹ʧȥסȨķƳ
pop_event = {
	 id = "xilin_pop.10"
	 hide_window = yes
   is_triggered_only = yes
   
   trigger = {
    AND ={
       owner = { has_authority = auth_xilin_mind }
       NOR = {
          has_trait = trait_magic_machine
          has_trait = trait_divinity
          has_trait = trait_xilin_building 
       }
       NOT ={ 
         has_citizenship_type ={
            country = owner
			      type = citizenship_limited
         }
       }
    }
	}
 
	immediate = {
	  if = {
	    limit = { has_modifier = pop_be_blessed   }
	    remove_modifier = pop_be_blessed
		}
	}
}

#Ӿ
pop_event = {
   id = "xilin_pop.3"
	 hide_window = yes
   is_triggered_only = yes
   
   trigger = {
    AND ={
       exists = planet
       planet={
          owner = {
             has_authority = auth_xilin_mind
          }
       }
       NOR = {
          has_trait = trait_magic_machine
          has_trait = trait_divinity
       }
       has_citizenship_type ={
         country = owner
			   type = citizenship_limited
       }
    }
    
	}
 
	immediate = {
	  if = {
			 limit = { NOT = { has_modifier = pop_be_blessed  } }
			 add_modifier = {
			    modifier = pop_be_blessed   
			    #days = 1800 # 5 years
		   }		
		}		  
	}
}
#ȥƳ
pop_event = {
   id = "xilin_pop.4"
	 hide_window = yes
   is_triggered_only = yes
   
   trigger = {
    AND ={
       exists = planet
       planet={
          owner = {
             NOT = { has_authority = auth_xilin_mind }
          }
       }
       
    }
    
	}
 
	immediate = {
	  if = {
			 limit = {  has_modifier = pop_be_blessed   }
			 remove_modifier = pop_be_blessed
		}		  
	}
}

#򣬾þ
planet_event = {
  id = "xilin_pop.5"
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
	   owner = { has_authority = auth_xilin_mind }       
	}

	immediate = {
	   every_owned_pop ={
	     limit = {
          AND={
            NOR = {
               has_trait = trait_magic_machine
               has_trait = trait_divinity
               has_modifier = pop_be_blessed
            }
            has_citizenship_type ={
               country = owner
			         type = citizenship_limited
            }
         }
	     }
	     add_modifier = {
			    modifier = pop_be_blessed   
			    #days = 1800 # 5 years
		   }

	   }
	}
}


#ʧȥ򣬾ʧȥ

planet_event = {
  id = "xilin_pop.6"
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
	   owner = { NOT={has_authority = auth_xilin_mind} }       
	}

	immediate = {
	   every_owned_pop ={
	     limit = {  has_modifier = pop_be_blessed   }
	     remove_modifier = pop_be_blessed	   
	   }
	}
}

###
#ϣ˿ڻݣΪϣʹͽ
pop_event = {
	id = "xilin_pop.7"
	hide_window = yes
	
	is_triggered_only = yes

	trigger = {
	  AND = {
  		has_trait = trait_xilin_building 
		  owner = {  has_authority = auth_xilin_mind  }
		}
	}
	
	immediate = {
		change_species =  owner.owner_species
	}
}

##################################


#ͨˣתΪϣɻе
planet_event = {
  id = "xilin_pop.11"
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
	   owner = { has_authority = auth_xilin_mind }       
	}

	immediate = {
	   every_owned_pop ={
	     limit = {
	     		OR = {
	     				has_trait = trait_robotic_1
	     				has_trait = trait_robotic_2
	     		}
          NOR = { 
          		has_trait = trait_robot_awoken_01 
          		has_trait = trait_robot_awoken
          }
	     }
	     kill_pop = yes
	     ROOT = {
	     	  best_tile_for_pop = {
					  build_pop = {
    					name = buildable_robot_pop_xilin
    					grown = yes
					  }
			 	  }
			 }
	     #change_species = buildable_robot_pop_xilin
	   }
	}
}

#ʹͽ˿ϣʹͽκ
planet_event = {
  id = "xilin_pop.12"
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
	   owner = { NOT = { has_authority = auth_xilin_mind } }       
	}

	immediate = {
	   every_owned_pop ={
	     limit = {
	     		has_trait = trait_magic_machine
	     }
	     kill_pop = yes
	   }
	}
}

#
planet_event = {
  id = "xilin_pop.13"
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
	   owner = { has_authority = auth_xilin_mind  }       
	}

	immediate = {
	   every_owned_pop = { #ϴ˿
	        if = {
	           limit = { has_pop_flag = f_pop_of_crime }	           
	           kill_pop = yes
	        } 
	   }
	}
}