
#生命树种子数变化
#获得一个生命树种子
#scope:country
add_life_tree_seed = {
	change_variable =  { which = "seed_num"  value = 1 }	
	switch = {
			trigger = has_modifier
			m_life_tree_seed_num_0 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_1"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_0
			}
			m_life_tree_seed_num_1 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_2"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_1
			}
			m_life_tree_seed_num_2 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_3"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_2
			}
			m_life_tree_seed_num_3 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_4"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_3
			}
			m_life_tree_seed_num_4 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_5"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_4
			}
			m_life_tree_seed_num_5 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_6"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_5
			}
			m_life_tree_seed_num_6 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_7"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_6
			}
			m_life_tree_seed_num_7 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_8"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_7
			}
			m_life_tree_seed_num_8 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_9"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_8
			}
			m_life_tree_seed_num_9 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_10"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_9
			}
			m_life_tree_seed_num_10 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_11"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_10
			}
			m_life_tree_seed_num_11 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_12"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_11
			}
			m_life_tree_seed_num_12 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_13"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_12
			}
			m_life_tree_seed_num_13 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_14"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_13
			}
			m_life_tree_seed_num_14 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_15"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_14
			}
			m_life_tree_seed_num_15 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_16"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_15
			}
			m_life_tree_seed_num_16 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_17"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_16
			}
			m_life_tree_seed_num_17 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_18"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_17
			}
			m_life_tree_seed_num_18 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_19"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_18
			}
			m_life_tree_seed_num_19 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_20"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_19
			}
			m_life_tree_seed_num_20 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_21"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_20
			}
			m_life_tree_seed_num_21 = { }
	}
}

sub_life_tree_seed = {
			if = {
					limit = {
						check_variable =  { which = "seed_num"  value > 0 }	
					}
					change_variable =  { which = "seed_num"  value = -1 }	
			}
			switch = {
						trigger = has_modifier
						m_life_tree_seed_num_0 = { }
						m_life_tree_seed_num_1 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_0"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_1
						}
						m_life_tree_seed_num_2 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_1"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_2
						}
						m_life_tree_seed_num_3 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_2"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_3
						}
						m_life_tree_seed_num_4 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_3"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_4
						}
						m_life_tree_seed_num_5 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_4"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_5
						}
						m_life_tree_seed_num_6 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_5"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_6
						}
						m_life_tree_seed_num_7 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_6"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_7
						}
						m_life_tree_seed_num_8 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_7"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_8
						}
						m_life_tree_seed_num_9 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_8"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_9
						}
						m_life_tree_seed_num_10 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_9"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_10
						}
						m_life_tree_seed_num_11 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_10"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_11
						}
						m_life_tree_seed_num_12 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_11"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_12
						}
						m_life_tree_seed_num_13 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_12"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_13
						}
						m_life_tree_seed_num_14 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_13"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_14
						}
						m_life_tree_seed_num_15 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_14"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_15
						}
						m_life_tree_seed_num_16 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_15"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_16
						}
						m_life_tree_seed_num_17 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_16"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_17
						}
						m_life_tree_seed_num_18 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_17"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_18
						}
						m_life_tree_seed_num_19 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_18"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_19
						}
						m_life_tree_seed_num_20 = { 
								add_modifier = { modifier =  "m_life_tree_seed_num_19"  days = -1 } 
								remove_modifier = m_life_tree_seed_num_20
						}
						m_life_tree_seed_num_21 = { 
								if = {
										limit = { check_variable =  { which = "seed_num"  value = 20 }	 }
										add_modifier = { modifier =  "m_life_tree_seed_num_20"  days = -1 } 
										remove_modifier = m_life_tree_seed_num_21
								}					
						}
			}
}

#创建树灵
#scope:Planet
life_tree_create_pop = {
		#查找国内树灵种族
		if = {
				limit ={#国内有树灵人口
						owner = {
								any_owned_pop_species = {
										has_trait = trait_tree_spirit
								}
						}
				}
				owner = {
						random_owned_pop_species = {
								limit = {
										has_trait = trait_tree_spirit		
								}	
								save_event_target_as = tree_spirit_species
						}
				}
				#在生命树地格创建树灵
				random_tile = {
						limit = { has_building = building_life_tree }
						create_pop = {	species = event_target:tree_spirit_species	}
						last_created_pop = {
									modify_species =  { species = This  ideal_planet_class = PrevPrev }
						}
				}			
				else = {
						#检查是否拥有和谐国家理念
						if = {
								limit = {
										owner = {
												OR = { 
														has_valid_civic = civic_harmonious
														has_valid_civic = civic_harmonious_tree
												} 
										}
								}
								#创建一个树灵种族
								create_species = {
										name = "NAME_tree_spirit"
										plural = "PLURAL_tree_spirit"
										class = random_non_machine
										portrait = random
										traits = { trait = trait_hive_mind trait = trait_tree_spirit trait = random_traits}
										allow_negative_traits = no
										homeworld = this
								}	
								last_created_species = {
										rename_species = { name = random }
								}
								#在生命树地格创建树灵
								random_tile = {
									limit = { has_building = building_life_tree }
									create_pop = {	species =  last_created	}
								}	
								else = {
										#检查是否有“卡拉的礼物”
										if = {
												limit = {
														owner = { has_modifier = m_kala_gift }
												}
												#寻找卡拉种族
												if = {
														limit = {
																any_country = {  has_country_flag = f_kala }
														}
														random_country = {
																limit = { has_country_flag = f_kala }																
																save_event_target_as = tree_spirit_species
														}
														#在生命树地格创建树灵
														#创建物种树灵
														random_tile = {
																limit = { has_building = building_life_tree }
																create_pop = {	species =  event_target:tree_spirit_species }
																last_created_pop = {
																		modify_species =  { species = This add_trait = trait_tree_spirit   ideal_planet_class = PrevPrev }
																}
																last_created_species = {
																		rename_species = { name = random }
																}
														}																												
														#没有卡拉，创建星灵
														else = {
																#创建物种树灵
																create_species = {
																	name = "NAME_star_spirit"
																	plural = "PLURAL_star_spirit"
																	class = MOL
																	portrait = mol17
																	traits = {
																			trait = trait_hive_mind
																			trait = trait_tree_spirit
																			trait = random_traits
																	}
																	allow_negative_traits = no
																	homeworld = this
																}
																random_tile = {
																		limit = { has_building = building_life_tree }
																		create_pop = {	species =  last_created}
																}
														}
												}#if
										}#if
								}		
						}#if				
				}
		}#if
}

#移除星球负面特性
#scope:planet
remove_neg_planet_modifier = {
  while = {
    limit = { has_neg_planet_modifier = yes }
		switch = {
						trigger = has_modifier
						#荒凉
						bleak_planet = {
								remove_modifier = bleak_planet
								set_planet_flag = f_ever_bleak_planet
						}
						#贫矿的
						mineral_poor = {
								remove_modifier = mineral_poor
								set_planet_flag = f_ever_mineral_poor
						}
						#弱磁场
						weak_magnetic_field = {
								remove_modifier = weak_magnetic_field
								set_planet_flag = f_ever_weak_magnetic_field				
						}
						#高重力
						high_gravity = {
								remove_modifier = high_gravity
								set_planet_flag = f_ever_high_gravity						
						}						
		}
	}
}

#恢复星球负面特性
#scope:planet
recover_neg_planet_modifier = {
	while = {
		limit = { has_ever_neg_planet_modifier = yes }
		switch = {
						trigger = has_planet_flag
						#荒凉
						f_ever_bleak_planet = {
								add_modifier = { modifier =  "bleak_planet"  days = -1 }
								remove_planet_flag = f_ever_bleak_planet
						}
						#贫矿的
						f_ever_mineral_poor = {
								add_modifier = { modifier =  "mineral_poor"  days = -1 }
								remove_planet_flag = f_ever_mineral_poor
						}
						#弱磁场
						f_ever_weak_magnetic_field = {
								add_modifier = { modifier =  "weak_magnetic_field"  days = -1 }
								remove_planet_flag = f_ever_weak_magnetic_field				
						}
						#高重力
						f_ever_high_gravity = {
								add_modifier = { modifier =  "high_gravity"  days = -1 }
								remove_planet_flag = f_ever_high_gravity						
						}						
		}
	}
}

#升华星球特性
#scope:planet
sublime_planet_modifier = {
  while = {
  		limit = { has_sublimable_planet_modifier = yes }
  		switch = {
  				trigger = has_modifier
  				#不稳定构造->地质公园
  				unstable_tectonics = {
  					 	remove_modifier = unstable_tectonics
  					 	add_modifier = { modifier =  "m_geological_parks"  days = -1 }
  				}
  				#不能自转->永恒的黄昏
  				tidal_locked = {
  						remove_modifier = tidal_locked
  					 	add_modifier = { modifier =  "m_everlasting_dusk"  days = -1 }
  				}
  				#暴风雨->雨之都
  				wild_storms = {
  						remove_modifier = wild_storms
  					 	add_modifier = { modifier =  "m_paradise_of_rain"  days = -1 }
  				}
  				#危险的气候->驯服的气候
  				hazardous_weather = {
  						remove_modifier = hazardous_weather
  					 	add_modifier = { modifier =  "m_tamed_weather"  days = -1 }
  				}
  				#危险的野生动物->灵兽
  				dangerous_wildlife = {
  						remove_modifier = dangerous_wildlife
  					 	add_modifier = { modifier =  "m_intelligent_friendly_wildlife"  days = -1 }
  				}
  				#陨石撞击->许愿圣地
  				asteroid_impacts = {
  						remove_modifier = asteroid_impacts
  					 	add_modifier = { modifier =  "m_holy_place_to_make_wish"  days = -1 }
  				}
  		}
  }
}

#退化星球特性
#scope:planet
degenerate_planet_modifier = {
	while = {
  		limit = { is_planet_sublimed = yes }
  		switch = {
  				trigger = has_modifier
  				#不稳定构造<-地质公园
  				m_geological_parks = {
  					 	remove_modifier = m_geological_parks
  					 	add_modifier = { modifier =  "unstable_tectonics"  days = -1 }
  				}
  				#不能自转<-永恒的黄昏
  				m_everlasting_dusk = {
  						remove_modifier = m_everlasting_dusk
  					 	add_modifier = { modifier =  "tidal_locked"  days = -1 }
  				}
  				#暴风雨<-雨之都
  				m_paradise_of_rain = {
  						remove_modifier = m_paradise_of_rain
  					 	add_modifier = { modifier =  "wild_storms"  days = -1 }
  				}
  				#危险的气候<-驯服的气候
  				m_tamed_weather = {
  						remove_modifier = m_tamed_weather
  					 	add_modifier = { modifier =  "hazardous_weather"  days = -1 }
  				}
  				#危险的野生动物<-灵兽
  				m_intelligent_friendly_wildlife = {
  						remove_modifier = m_intelligent_friendly_wildlife
  					 	add_modifier = { modifier =  "dangerous_wildlife"  days = -1 }
  				}
  				#陨石撞击<-许愿圣地
  				m_holy_place_to_make_wish = {
  						remove_modifier = m_holy_place_to_make_wish
  					 	add_modifier = { modifier =  "asteroid_impacts"  days = -1 }
  				}
  		}
  }
}