#关于希灵帝国的人口事件

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
	        } 
	   }
	}
}