namespace = harmonious_planet

#г

#г(ӵкгǣ԰ͳ)
# No scope, like on_game_start
#on_monthly_pulse = {
event = {
	id = harmonious_planet.1
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
			any_country = {
					can_harmonize = yes
			}
	}

	immediate = {
	  #Ⱥг
		every_country = {
			limit = { 
					can_harmonize = yes
			}
			#׶θǻ,иǿƼֱӻ
			if = {
					limit = {
							#has_technology = "tech_gaia_creation"
							any_owned_planet = {
										NOT = { has_modifier = m_harmony_5 }
										OR = {
												has_modifier = m_harmony_4
												is_planet_class = pc_gaia
												habitable_structure = yes
										}										
			         			can_harmonize_planet = yes
			     		}
					}
					#Ը򣬸+1
			   every_owned_planet = {
			   		limit = {
			   				NOT = { has_modifier = m_harmony_5 }
			   				OR = {
			   		      has_modifier = m_harmony_4
			   		      is_planet_class = pc_gaia
									habitable_structure = yes
			   		    }
			         	can_harmonize_planet = yes
			   		}
			   		if = {
			   			limit = {  has_modifier = m_destroy_harmony  }
			   			remove_modifier =  m_destroy_harmony
			   		}
			   		if = {
			   			limit = {  NOT = { has_modifier = m_build_harmony }  }
			   			add_modifier = { modifier =  "m_build_harmony"  days = -1 }
			   		}			   		
			   		change_variable =  { which = "harmony_5"  value = 1 }			   		
			   		if = { #
			   		    limit = { check_variable = { which = "harmony_5" value > 119 } }
			   		    remove_modifier =  m_harmony_4
			   		    remove_modifier =  m_harmony_3
			   		    remove_modifier =  m_harmony_2
			   		    remove_modifier =  m_harmony_1
			   		    add_modifier = { modifier =  "m_harmony_5"  days = -1 }
			   		    remove_modifier =  m_build_harmony
			   		    if = {
			   		    	limit = {
			   		    		NOR = {
			   		    			is_planet_class = pc_gaia
											habitable_structure = yes
			   		    		}
			   		    	}
			   		    	change_pc = pc_gaia			   		    
			   		    }
			   		    #ƳƳĸ
			   		    remove_neg_planet_modifier = yes
			   		    #,ʧȥг˻Ϊԭ
			   		    sublime_planet_modifier = yes
			   		    #,ʧȥгƳ
			   		    
			   		}
			   }
					
			}
			#Ľ׶ҪָƼ
			if = {
					limit = {
							#has_technology = "tech_gaia_creation"
							has_technology = tech_climate_restoration
							any_owned_planet = {
										has_modifier = m_harmony_3
			         			can_harmonize_planet = yes
			         			NOR = {
			   		    				is_planet_class = pc_gaia
												habitable_structure = yes			   		    				
			         			}	
			     		}
					}
					#Ը򣬸+1
			   every_owned_planet = {
			   		limit = {
			   		    has_modifier = m_harmony_3
			         	can_harmonize_planet = yes
			         	NOR = {
			   		    		is_planet_class = pc_gaia
										habitable_structure = yes			   		    				
			         	}
			   		}
			   		if = {
			   			limit = {  has_modifier = m_destroy_harmony  }
			   			remove_modifier =  m_destroy_harmony
			   		}
			   		if = {
			   			limit = {  NOT = { has_modifier = m_build_harmony }  }
			   			add_modifier = { modifier =  "m_build_harmony"  days = -1 }
			   		}			   		
			   		change_variable =  { which = "harmony_4"  value = 1 }			   		
			   		if = { #
			   		    limit = { check_variable = { which = "harmony_4" value > 119 } }
			   		    remove_modifier =  m_harmony_3
			   		    add_modifier = { modifier =  "m_harmony_4"  days = -1 }
			   		    remove_modifier =  m_build_harmony
			   		    #Ƴ򲿷ָ
			   		    remove_neg_planet_modifier = yes
			   		}
			   }
					
			}	
			#׶Ҫٿش
			if = {
					limit = {
							#has_technology = "tech_atmospheric_manipulation"
							any_owned_planet = {
										has_modifier = m_harmony_2
			         			can_harmonize_planet = yes
			         			NOR = {
			   		    				is_planet_class = pc_gaia
												habitable_structure = yes			   		    				
			         			}
			     		}
					}
					#Ը򣬸+1
			   every_owned_planet = {
			   		limit = {
			   		    has_modifier = m_harmony_2
			         	can_harmonize_planet = yes
			         	NOR = {
			   		    				is_planet_class = pc_gaia
												habitable_structure = yes			   		    				
			         	}
			   		}
			   		if = {
			   			limit = {  has_modifier = m_destroy_harmony  }
			   			remove_modifier =  m_destroy_harmony
			   		}
			   		if = {
			   			limit = {  NOT = { has_modifier = m_build_harmony }  }
			   			add_modifier = { modifier =  "m_build_harmony"  days = -1 }
			   		}			   		
			   		change_variable =  { which = "harmony_3"  value = 1 }			   		
			   		if = { #
			   		    limit = { check_variable = { which = "harmony_3" value > 119 } }
			   		    remove_modifier =  m_harmony_2
			   		    add_modifier = { modifier =  "m_harmony_3"  days = -1 }
			   		    remove_modifier =  m_build_harmony
			   		}
			   }
					
			}			
			#ڶ׶ò
			if = {
					limit = {
							has_technology = "tech_terrestrial_sculpting"
							any_owned_planet = {
										has_modifier = m_harmony_1
			         			can_harmonize_planet = yes
			         			NOR = {
			   		    				is_planet_class = pc_gaia
												habitable_structure = yes			   		    				
			         			}
			     		}
					}
					#Ը򣬸+1
			   every_owned_planet = {
			   		limit = {
			   		    has_modifier = m_harmony_1
			         	can_harmonize_planet = yes
			         	NOR = {
			   		    				is_planet_class = pc_gaia
												habitable_structure = yes			   		    				
			         	}	
			   		}
			   		#log = "sescond harmony progress is [This.harmony_2]"
			   		if = {
			   			limit = {  has_modifier = m_destroy_harmony  }
			   			remove_modifier =  m_destroy_harmony
			   		}
			   		if = {
			   			limit = {  NOT = { has_modifier = m_build_harmony }  }
			   			add_modifier = { modifier =  "m_build_harmony"  days = -1 }
			   		}			   		
			   		change_variable =  { which = "harmony_2"  value = 1 }			   		
			   		if = { #
			   		    limit = { check_variable = { which = "harmony_2" value > 119 } }
			   		     remove_modifier =  m_harmony_1
			   		    add_modifier = { modifier =  "m_harmony_2"  days = -1 }
			   		    remove_modifier =  m_build_harmony
			   		}
			   }
					
			}
			##########
			#һ׶κг죬Ƽ,Ǻеָܽ
			if = {
			   limit = {
			     any_owned_planet = {
			         			NOR = { 
			         					has_modifier = m_harmony_1 
			         					has_modifier = m_harmony_2
			         					has_modifier = m_harmony_3
			         					has_modifier = m_harmony_4
			         					has_modifier = m_harmony_5
			         			}
			         			can_harmonize_planet = yes
			         			NOR = {
			         					is_planet_class = pc_nuked
			         					is_planet_class = pc_machine
			         			}	
			         			NOR = {
			   		    				is_planet_class = pc_gaia
												habitable_structure = yes			   		    				
			         			}	         			
			     }
			   }
			  
			   #ͻ򣬸+1
			   every_owned_planet = {
			   		limit = {
			   		    NOR = { 
			         					has_modifier = m_harmony_1 
			         					has_modifier = m_harmony_2
			         					has_modifier = m_harmony_3
			         					has_modifier = m_harmony_4
			         					has_modifier = m_harmony_5
			         	}
			         	can_harmonize_planet = yes
			         	NOR = {
			         					is_planet_class = pc_nuked
			         					is_planet_class = pc_machine
			         	}	
			         	NOR = {
			   		    				is_planet_class = pc_gaia
												habitable_structure = yes			   		    				
			         	}
			   		}
			   		if = {
			   			limit = {  has_modifier = m_destroy_harmony  }
			   			remove_modifier =  m_destroy_harmony
			   		}
			   		if = {
			   			limit = {  NOT = { has_modifier = m_build_harmony }  }
			   			add_modifier = { modifier =  "m_build_harmony"  days = -1 }
			   		}			   		
			   		change_variable =  { which = "harmony_1"  value = 1 }			   		
			   		if = { #
			   		    limit = { check_variable = { which = "harmony_1" value > 119 } }
			   		    add_modifier = { modifier =  "m_harmony_1"  days = -1 }
			   		    remove_modifier =  m_build_harmony
			   		}
			   }
			   
			}
			##################
			#׶Σָ
			#׶κг죬ָƼ
			if = {
			   limit = {
			   		#has_technology = tech_climate_restoration
			      any_owned_planet = {
			         			can_harmonize_planet = yes
			         			OR = {
			         					is_planet_class = pc_nuked
			         					is_planet_class = pc_machine
			         			}			         			
			       }
			   }
			  
			   #ͻ򣬸+1
			   every_owned_planet = {
			   		limit = {
			         	can_harmonize_planet = yes
			         	OR = {
			         					is_planet_class = pc_nuked
			         					is_planet_class = pc_machine
			         	}	
			   		}
			   		if = {
			   			limit = {  has_modifier = m_destroy_harmony  }
			   			remove_modifier =  m_destroy_harmony
			   		}	
			   		if = {
			   			limit = {  NOT = { has_modifier = m_build_harmony }  }
			   			add_modifier = { modifier =  "m_build_harmony"  days = -1 }
			   		}			   		
			   		change_variable =  { which = "harmony_0"  value = 1 }			   		
			   		if = { #ָ
			   		    limit = { check_variable = { which = "harmony_0" value > 119 } }
			   		    change_pc = rl_habitable_normal 
			   		    set_variable =  { which = "harmony_0"  value = 0 }	
			   		    remove_modifier =  m_build_harmony
			   		    remove_modifier = "irradiated_planet"
			   		}
			   }
			   
			}
			#######################################################
			#˻
			
			#ûͻ򣬸-4
			#ָ˻
			if = {
					limit = {
			      any_owned_planet = {
			         			can_harmonize_planet = no
			         			OR = {
			         					is_planet_class = pc_nuked
			         					is_planet_class = pc_machine
			         			}	
			         			OR = {
			         					has_modifier = m_build_harmony
			         					has_modifier = m_destroy_harmony
			         			}		         			
			       }
			   }
			   every_owned_planet = {
			   		limit = {
			   					  can_harmonize_planet = no
			         			OR = {
			         					is_planet_class = pc_nuked
			         					is_planet_class = pc_machine
			         			}	
			         			OR = {
			         					has_modifier = m_build_harmony
			         					has_modifier = m_destroy_harmony
			         			}	
			   		}
			   		if = {
			   			limit = {   has_modifier = m_build_harmony   }
			   			remove_modifier =  m_build_harmony
			   		}
			   		if = {
			   			limit = {  NOT = { has_modifier = m_destroy_harmony }  }
			   			add_modifier = { modifier =  "m_destroy_harmony"  days = -1 }
			   		}
			   		change_variable =  { which = "harmony_0"  value = -4 }	
			   		if = {
			   		    limit = { check_variable = { which = "harmony_0" value < 1 } }			   		   
			   		    remove_modifier =  m_destroy_harmony
			   		}
			   }
			}
			#һг˻
			if = {
				limit = {
			     any_owned_planet = {
			     					NOR = {  
			     							has_modifier = m_harmony_2
			     							has_modifier = m_harmony_3
			     							has_modifier = m_harmony_4
			     							has_modifier = m_harmony_5
			     					}
			     					OR = {
			     							has_modifier = m_harmony_1
			         					has_modifier = m_build_harmony
			         					has_modifier = m_destroy_harmony
			         			}			         			
			         			can_harmonize_planet = no
			         			NOR = {
			         					is_planet_class = pc_nuked
			         					is_planet_class = pc_machine
			         			}				         					         			
			     }
			   }
			  
			   #˻ٶ-4
			   every_owned_planet = {
			   		limit = {
			   		    		NOR = {  
			     							has_modifier = m_harmony_2
			     							has_modifier = m_harmony_3
			     							has_modifier = m_harmony_4
			     							has_modifier = m_harmony_5
			     					}
			     					OR = {
			     							has_modifier = m_harmony_1
			         					has_modifier = m_build_harmony
			         					has_modifier = m_destroy_harmony
			         			}			         			
			         			can_harmonize_planet = no
			         			NOR = {
			         					is_planet_class = pc_nuked
			         					is_planet_class = pc_machine
			         			}	
			         			
			   		}
			   		if = {
			   			limit = {   has_modifier = m_build_harmony   }
			   			remove_modifier =  m_build_harmony
			   		}
			   		if = {
			   			limit = {  NOT = { has_modifier = m_destroy_harmony }  }
			   			add_modifier = { modifier =  "m_destroy_harmony"  days = -1 }
			   		}
			   		change_variable =  { which = "harmony_1"  value = -4 }	
			   		if = {
			   		    limit = { check_variable = { which = "harmony_1" value < 1 } }			   		   
			   		    remove_modifier =  m_destroy_harmony
			   		    remove_modifier =  m_harmony_1
			   		}
			   }			
			}
			#ڶ˻
			if = {
					limit = {						
							any_owned_planet = {
			     					has_modifier = m_harmony_2	
			         			can_harmonize_planet = no
			     		}
					}
					#˻-4
			   every_owned_planet = {
			   		limit = {
			     					has_modifier = m_harmony_2	
			         			can_harmonize_planet = no
			   		}
			   		if = {
			   			limit = {   has_modifier = m_build_harmony   }
			   			remove_modifier =  m_build_harmony
			   		}
			   		if = {
			   			limit = {  NOT = { has_modifier = m_destroy_harmony }  }
			   			add_modifier = { modifier =  "m_destroy_harmony"  days = -1 }
			   		}		   		
			   		change_variable =  { which = "harmony_2"  value = -4 }			   		
			   		if = { 
			   		    limit = { check_variable = { which = "harmony_2" value < 1 } }
			   		     remove_modifier =  m_harmony_2
			   		    add_modifier = { modifier =  "m_harmony_1"  days = -1 }
			   		    
			   		}
			   }
					
			}			
			#˻
			if = {
					limit = {						
							any_owned_planet = {
			     					has_modifier = m_harmony_3	
			         			can_harmonize_planet = no
			     		}
					}
					#˻-4
			   every_owned_planet = {
			   		limit = {
			     					has_modifier = m_harmony_3	
			         			can_harmonize_planet = no
			   		}
			   		if = {
			   			limit = {   has_modifier = m_build_harmony   }
			   			remove_modifier =  m_build_harmony
			   		}
			   		if = {
			   			limit = {  NOT = { has_modifier = m_destroy_harmony }  }
			   			add_modifier = { modifier =  "m_destroy_harmony"  days = -1 }
			   		}		   		
			   		change_variable =  { which = "harmony_3"  value = -4 }			   		
			   		if = { 
			   		    limit = { check_variable = { which = "harmony_3" value < 1 } }
			   		     remove_modifier =  m_harmony_3
			   		    add_modifier = { modifier =  "m_harmony_2"  days = -1 }
			   		    
			   		}
			   }
					
			}	
			
			#Ľ˻
			if = {
					limit = {						
							any_owned_planet = {
			     					has_modifier = m_harmony_4	
			         			can_harmonize_planet = no
			     		}
					}
					#˻-4
			   every_owned_planet = {
			   		limit = {
			     					has_modifier = m_harmony_4	
			         			can_harmonize_planet = no
			   		}
			   		if = {
			   			limit = {   has_modifier = m_build_harmony   }
			   			remove_modifier =  m_build_harmony
			   		}
			   		if = {
			   			limit = {  NOT = { has_modifier = m_destroy_harmony }  }
			   			add_modifier = { modifier =  "m_destroy_harmony"  days = -1 }
			   		}		   		
			   		change_variable =  { which = "harmony_4"  value = -4 }			   		
			   		if = { 
			   		    limit = { check_variable = { which = "harmony_4" value < 1 } }
			   		     remove_modifier =  m_harmony_4
			   		    add_modifier = { modifier =  "m_harmony_3"  days = -1 }
			   		    #ָ
			   		    recover_neg_planet_modifier = yes
			   		}
			   }
					
			}	
			
			#˻   
			if = {
					limit = {						
							any_owned_planet = {
			     					has_modifier = m_harmony_5	
			         			can_harmonize_planet = no
			     		}
					}
					#˻-4
			   every_owned_planet = {
			   		limit = {
			     					has_modifier = m_harmony_5	
			         			can_harmonize_planet = no
			   		}
			   		if = {
			   			limit = {   has_modifier = m_build_harmony   }
			   			remove_modifier =  m_build_harmony
			   		}
			   		if = {
			   			limit = {  NOT = { has_modifier = m_destroy_harmony }  }
			   			add_modifier = { modifier =  "m_destroy_harmony"  days = -1 }
			   		}		   		
			   		change_variable =  { which = "harmony_5"  value = -4 }			   		
			   		if = { 
			   		    limit = { check_variable = { which = "harmony_5" value < 1 } }
			   		     remove_modifier =  m_harmony_5
								 remove_modifier =  m_destroy_harmony		
								 #˻	
								 degenerate_planet_modifier = yes   		    
			   		}
			   }
					
			}	
		}
	}
}

#г򱻸ߣƻг
planet_event = {
	id = harmonious_planet.2
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
			from = { allow_harmonize = no }
			OR = {
					has_modifier = m_harmony_1
					has_modifier = m_harmony_2
					has_modifier = m_harmony_3
					has_modifier = m_harmony_4
					has_modifier = m_harmony_5
					has_modifier = m_destroy_harmony
					has_modifier = m_build_harmony
			}
	}
	
	immediate = {
			remove_modifier =  m_build_harmony
			
			if = {
				limit = {
					NOR = {
							has_modifier = m_harmony_1
							has_modifier = m_harmony_2
							has_modifier = m_harmony_3
							has_modifier = m_harmony_4
							has_modifier = m_harmony_5
					}
				}
			  remove_modifier =  m_destroy_harmony
			  break = yes
			}
			if = {
			   			limit = {  NOT = { has_modifier = m_destroy_harmony }  }
			   			add_modifier = { modifier =  "m_destroy_harmony"  days = -1 }
			}
			planet_event = { id = harmonious_planet.3  days = 180   random = 20 }
	}
}

planet_event = {
	id = harmonious_planet.3
	hide_window = yes
	is_triggered_only = yes
		
	immediate = {
			if = {
				limit = { owner = { allow_harmonize = no }}
				remove_modifier =  m_destroy_harmony
				remove_modifier =  m_harmony_1
				remove_modifier =  m_harmony_2
				remove_modifier =  m_harmony_3
				remove_modifier =  m_harmony_4
				remove_modifier =  m_harmony_5
				#нȶΪ0
				set_variable =  { which = "harmony_0"  value = 0 }
				set_variable =  { which = "harmony_1"  value = 0 }
				set_variable =  { which = "harmony_2"  value = 0 }
				set_variable =  { which = "harmony_3"  value = 0 }
				set_variable =  { which = "harmony_4"  value = 0 }
				set_variable =  { which = "harmony_5"  value = 0 }
				#ͨ򣬻ָ
				if = {
					limit = {
						 NOR = {
								is_planet_class = pc_gaia
								habitable_structure = yes
						 }
					}
					recover_neg_planet_modifier = yes				
				}
				#˻	
				degenerate_planet_modifier = yes  
			}			
	}
}

########
#гͨ˿ڻ

planet_event = {
	id = harmonious_planet.4
	hide_window = yes
	
	trigger = {
		 has_owner = yes
		 owner = { allow_harmonize = yes }
		 OR = {
		 		has_modifier = m_harmony_3
				has_modifier = m_harmony_4
				has_modifier = m_harmony_5
		 }
		 any_pop = {
		 		NOR = {
		 				has_trait = trait_hive_mind
		 				has_trait = trait_magic_machine
		 				has_trait = trait_machine_unit
		 				has_trait = trait_mechanical
		 		}
		 		is_sapient = yes
		 		NOT = { has_trait = trait_psionic }
		 }
	}
	
	mean_time_to_happen = {
		months = 8
	}
		
	immediate = {
			random_pop = {
					limit = {
							NOR = {
		 						has_trait = trait_hive_mind
		 						has_trait = trait_magic_machine
		 						has_trait = trait_machine_unit
		 						has_trait = trait_mechanical
		 					}
		 					is_sapient = yes
		 					NOT = { has_trait = trait_psionic  }
					}
					if = {
							limit = { NOT = { has_trait = trait_latent_psionic } }
							modify_species = { species = This   add_trait = trait_latent_psionic  }
							else = {
									modify_species = { species = This   add_trait = trait_psionic    remove_trait = trait_latent_psionic  }
							}
					}
			}		
	}
}

#£
#A building construction has been completed.
# This = Planet
# From = Tile
#on_building_complete
#planet_event = {#(ãиõд)
#	id = harmonious_planet.5
#	hide_window = yes
#	is_triggered_only = yes
	
#	trigger = {
#			from = {
#					has_building = building_life_tree_seed
#			}
#	}
	
#	immediate = {
#			from = {
#					#set_blocker = tb_growing_life_tree
#			}
			#10󳤳
#			planet_event = { id = harmonious_planet.6  days = 10  random = 2 }
#	}
#}

#10󳤳
planet_event = {
	id = harmonious_planet.6
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
			#Ƿ񻹷(򱻸ݻᵼ)
			if = {
					limit = { owner = { allow_harmonize = no } }
					break = yes
			}
			#ɳΪ
			if = {
					limit ={ has_blocker =  tb_growing_life_tree  }
					random_tile = {
							limit ={ has_blocker =  tb_growing_life_tree  }
							remove_blocker = yes
							set_building = building_life_tree							
					}	
					#Ƴ
					remove_modifier = m_growing_life_tree
					#һȺ˿
					life_tree_create_pop = yes
					#ϣ۹Ͼ
					last_created_pop = {
							pop_event = { id = xilin_pop.2 } 
					}
					#һʾ
					if = {
						  limit = {
						  		owner = {
						  				 NOT = { has_country_flag = f_first_life_tree }  
						  		}						  		
						  }
						  owner = { 
						  		set_country_flag = f_first_life_tree
						  		country_event = { id = harmonious_planet.7 } 
						  }
					}	
					#δӵйĸ10ɳΪĸ	
					if = {
							limit = {
									owner = {
						  				 allow_grow_up_to_mother_life_tree = yes 
						  				 NOT = { has_country_flag = f_ever_have_mother_life_tree } 
						  		}								
							}
							planet_event = { id = harmonious_planet.8  days = 3600  random = 20 } 							
					}#if	
					#жǷҪ¼
					if = {
							limit = {
							   owner = {
							   		has_country_flag = f_xilin_empire
							   		has_country_flag =  f_kala_hive_mind #Ⱥ֧
							   		NOT = { has_country_flag = f_kala_child_end }
							   		has_modifier = m_kala_gift
							   }
								 any_playable_country = {
								 		has_country_flag = f_kala
								 }
							}
							random_playable_country = {
								 limit = { has_country_flag = f_kala }
							   country_event = { id = kala_story_rdlg.8  days = 10 random = 5 } 			
							}	
							owner = { set_country_flag = f_kala_child_end }			
					}
					#жǷľ
					if = {
							limit = {
									owner = {
									  has_country_flag = f_xilin_empire
									  has_country_flag =  f_kala_dingdang
										NOT = {	has_country_flag = f_redemption_of_dingdang_end } #֧
									}
							}
							owner = {
									add_event_chain_counter = { event_chain = redemption_of_dingdang_chain  counter = plant_tree   amount = 1 }
									set_country_flag = f_redemption_of_dingdang_end
					    		#Ůף
							 		country_event = { id = kala_story_dlg.18  days = 10  random = 5 } 
							}
					}
			}			
	}
}
#һʾ
country_event = {
  id = harmonious_planet.7
  title = harmonious_planet.7.name
  
	desc = {
		text = harmonious_planet.7.desc_1
		trigger = {
			NOT = { has_country_flag = f_xilin_empire } 
		}
	}
	desc = {
		text = harmonious_planet.7.desc_2
		trigger = {
			has_country_flag = f_xilin_empire
		}
	}
	picture = GFX_evt_alien_nature
	is_triggered_only = yes
	
	option = {
		name = OK
	}
}

#һĸ
planet_event = {
  id = harmonious_planet.8
  title = harmonious_planet.8.name
	desc = harmonious_planet.8.desc
	picture = GFX_evt_alien_nature
	is_triggered_only = yes
	
	trigger = {
			owner = {
					allow_harmonize = yes
					NOT = { has_country_flag = f_ever_have_mother_life_tree }  
			}		
			has_building = building_life_tree		
	}
	
	immediate = {
			#ɳΪĸ
			random_tile = {
					limit = { has_building = building_life_tree }
					set_building = building_mother_life_tree
			}
			owner = { 
					set_country_flag = f_ever_have_mother_life_tree  
					#õһ
					add_life_tree_seed = yes
			}
	}
	
	option = {
		name = OK
	}
  
}

#ʧȥĸͨѸٳɳΪĸ
planet_event = {
  id = harmonious_planet.9
  title = harmonious_planet.9.name
	desc = harmonious_planet.9.desc
	picture = GFX_evt_alien_nature
	is_triggered_only = yes
	
	trigger = {
			owner = {					
					has_country_flag = f_ever_have_mother_life_tree
					allow_grow_up_to_mother_life_tree = yes
					NOT = {
								any_owned_planet = {
													has_building = building_mother_life_tree																
								}
					}
			}	
			has_building = building_life_tree	
	}
	
	immediate = {
			#ɳΪĸ
			random_tile = {
					limit = { has_building = building_life_tree }
					set_building = building_mother_life_tree
			}
	}
	
	option = {
		name = OK
	}
  
}

#ĸ(Ⱥܻ)
event = {
	id = harmonious_planet.10
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		every_playable_country = {
			limit = {
					allow_grow_up_to_mother_life_tree = yes
					#<2000, 
					check_variable =  { which = "seed_num"  value < 2000 }	
			}
			every_owned_planet = {
				limit = {
					has_building = building_mother_life_tree
				}
				planet_event = { id = harmonious_planet.11 }
			}
		}
	}
}

#201
planet_event = {
  id = harmonious_planet.11
  hide_window = yes
	is_triggered_only = yes
	
	trigger = {	
			has_building = building_mother_life_tree
	}
	
	immediate = {
			#ݼ+1
			change_variable =  { which = "seed_year"  value = 1 }
			if = {
					limit = { check_variable =  { which = "seed_year"  value = 20 }	 }
			    owner = { add_life_tree_seed = yes }
			    set_variable =  { which = "seed_year"  value = 0 } #
			}	
	}
}

#ĸܱٻ
# A tile building has been ruined
# This = Planet
# From = Tile
#on_building_ruined
planet_event = {
  id = harmonious_planet.12
  hide_window = yes
	is_triggered_only = yes
	
	trigger = {	
		OR = {
			has_building = building_life_tree
			has_building = building_mother_life_tree
		}
	}
	
	immediate = {
			from = { set_ruined = no }
	}
}

#ʧȥĸĹ,ɳΪĸ
event = {
	id = harmonious_planet.13
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		every_playable_country = {
			limit = {
					has_country_flag = f_ever_have_mother_life_tree
					allow_grow_up_to_mother_life_tree = yes
					NOT = {
							any_owned_planet = {
									has_building = building_mother_life_tree
							}	
					}
					any_owned_planet = {
									has_building = building_life_tree
					}					
			}
			random_owned_planet = {
				limit = {
					has_building = building_life_tree
				}
				planet_event = { id = harmonious_planet.9 }
			}
		}
	}
}

#ǷȺгңʹ÷ȺΪ
event = {
	id = harmonious_planet.14
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		every_playable_country = {
			limit = {
					allow_grow_up_to_mother_life_tree = yes				
			}
			every_owned_planet = {
					limit = {
							OR = {
									has_blocker =  tb_growing_life_tree
									has_building = building_life_tree
									has_building = building_mother_life_tree						
							}
							any_pop = {
									has_trait = trait_hive_mind
									NOT = { has_trait =  trait_tree_spirit }
							}
					}
					random_pop = {
							limit = {
									has_trait = trait_hive_mind
									NOT = { has_trait =  trait_tree_spirit }
							}
							modify_species =  { species = This add_trait = trait_tree_spirit   ideal_planet_class = Prev }
					}
			}
		}
	}
}

#г򱻸ߣ
#Fired whenever a new owner is set for a planet,
#be it after a war or through a trade
#From = Country scope (new owner)
#This = Planet scope
#on_planet_transfer
planet_event = {
	id = harmonious_planet.15
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
			from = { allow_harmonize = no }
			has_blocker =  tb_growing_life_tree
	}
	
	immediate = {
			random_tile = {
							limit ={ has_blocker =  tb_growing_life_tree  }
							remove_blocker = yes						
			}	
			remove_modifier = m_growing_life_tree
	}
}

#ӵкгǷǷȺҳʼ
# secondary species: assign trait_machine_unit, turn into robotics, then create pops
# this: capital planet
# from: secondary species
planet_event = {
	id = harmonious_planet.16
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		from = { save_event_target_as = secondary_species }
		if = { limit = { owner = { has_valid_civic = civic_harmonious_tree } }
			while = {
				count = 4
				random_tile = {
					limit = {
						OR = {
							has_building = building_mining_network_1
							has_building = building_hydroponics_farm_1
						}
						has_pop = no
					}
					create_pop = {
						species = event_target:secondary_species
						ethos = random
					}
				}
			}
			#
			random_tile = {
      				limit = {      					
      						has_building = building_hydroponics_farm_1 
      				}
      				#ĸ
      				remove_building = yes
      				add_deposit = d_rich_society_deposit
      				set_building = building_mother_life_tree
      				
      } 
      owner = {
      		#country_flag
					set_country_flag = f_first_life_tree
					set_country_flag = f_ever_have_mother_life_tree
					#Ӽmoddifier
					add_modifier = { modifier =  "m_life_tree_seed_num_0"  days = -1 }     
      }
		}
		
	}
}

#гأû鴦ھ״̬
#Fired whenever a new owner is set for a planet,
#be it after a war or through a trade
#From = Country scope (new owner)
#This = Planet scope
#on_planet_transfer
planet_event = {
	id = harmonious_planet.17
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
			from = { 
				#ǷȺӵкг
				has_valid_civic = civic_harmonious_tree 
				#ӵпĹ
				has_modifier = m_kala_gift
			}
			NOR = {
				has_blocker =  tb_growing_life_tree
				has_building = building_life_tree
				has_building = building_mother_life_tree
			}	
			any_pop = {
				 has_trait = trait_tree_spirit
			}		
	}
	
	immediate = {
			every_owned_pop = {
							limit ={ has_trait = trait_tree_spirit  }
							purge = yes		
			}	
	}
}

#г򱻷Ⱥߣûʧȥ
#Fired whenever a new owner is set for a planet,
#be it after a war or through a trade
#From = Country scope (new owner)
#This = Planet scope
#on_planet_transfer
planet_event = {
	id = harmonious_planet.18
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
			from = { 
				has_authority = auth_hive_mind
			}
			NOR = {
				has_blocker =  tb_growing_life_tree
				has_building = building_life_tree
				has_building = building_mother_life_tree
			}	
			any_pop = {
				 has_trait = trait_tree_spirit 
			}		
	}
	
	immediate = {
			every_owned_pop = {
							limit ={ has_trait = trait_tree_spirit  }
							modify_species = { species = This   remove_trait = trait_tree_spirit  }
			}	
	}
}

#ؽֹͣ
planet_event = {
	id = harmonious_planet.19
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
			any_pop = {
				 has_trait = trait_tree_spirit
			}		
	}
	
	immediate = {
			every_owned_pop = {
							limit ={ has_trait = trait_tree_spirit  is_being_purged = yes }
							purge = no
			}	
	}
}

#ĸоĿ
# This = Country
#on_tech_increased
country_event = {
	id = harmonious_planet.20
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
			OR = {
				has_valid_civic = civic_harmonious_tree
				has_modifier = m_kala_gift
		 } 
		 #ӵлƼ
		 #has_technology = "tech_gaia_creation"
		 has_technology = tech_gene_expressions
		 #ӵĸ
		 has_country_flag = f_ever_have_mother_life_tree
		 #Ͳٴ
		 NOT = { has_country_flag = f_pro_cultivation_of_mother_life_tree } 
	}	
	
	immediate = { 
		set_country_flag = f_pro_cultivation_of_mother_life_tree
		country_event = { id = harmonious_planet.21  days = 10  random = 5 } 
	}	
	
}
#ĸоĿ
country_event = {
	id = harmonious_planet.21
	title = harmonious_planet.21.name
	desc = harmonious_planet.21.desc
	picture = GFX_evt_alien_nature
	is_triggered_only = yes
			
	option = {
		name = OK
		#ر𹤳
		capital_scope = {
			enable_special_project = {
				name = "PRO_CULTIVATION_OF_MOTHER_LIFE_TREE_RESEACH"
				location = this
				owner = root
			}
		}
	}	
}

#Ŀоɹmoddifier
country_event = {
	id = harmonious_planet.22
	title = harmonious_planet.22.name
	desc = harmonious_planet.22.desc
	picture = GFX_evt_alien_nature
	is_triggered_only = yes
			
	option = {
		name = OK
		#moddifier
		add_modifier = { modifier =  "m_cultivation_of_mother_life_tree"  days = -1 }
	}	
}

#ĸɹ
planet_event = {
	id = harmonious_planet.23
	title = harmonious_planet.23.name
	desc = harmonious_planet.23.desc
	picture = GFX_evt_alien_nature
	is_triggered_only = yes
	location = root
	
	immediate = {
		  #ɳΪĸ
			random_tile = {
					limit = { has_building = building_life_tree }
					set_building = building_mother_life_tree
			}	
	}
			
	option = {
		name = OK		
	}	
}

#˿ڳɳɣ˿Ƿﵽ2/3Ƿδﵽ1/3,鱣Ǽbuff
pop_event = {
	id = "harmonious_planet.24"
	hide_window = yes
	
	is_triggered_only = yes

	trigger = {
	  #
		NOT = { has_trait = trait_hive_mind }
		#鱣
		owner = { has_modifier = m_protect_tree_spirit_edict }
	  planet ={
	    #
	  	has_life_tree = yes
	  	#û鱣
	  	NOT = { has_modifier = m_protect_tree_spirit }
	    #δ1/3
	  	harmonize_hive_is_enough = no
	  	#˿ڴﵽ򳬹2/3
	  	can_grow_no_affect_tree_spirit = no	  
	  }
	}
	
	immediate = {
		planet = {
				add_modifier = { modifier =  "m_protect_tree_spirit"  days = -1 }
		}
	}
}

#˿ڴﵽ1/3,Ƴ鱣buff
pop_event = {
	id = "harmonious_planet.25"
	hide_window = yes
	
	is_triggered_only = yes

	trigger = {
	  #
		has_trait = trait_hive_mind
		#鱣
		owner = { has_modifier = m_protect_tree_spirit_edict }
	  planet ={
	  	#鱣
	  	has_modifier = m_protect_tree_spirit 
	    #1/3
	  	harmonize_hive_is_enough = yes	  	
	  }
	}
	
	immediate = {
		planet = {
				remove_modifier = m_protect_tree_spirit 
		}
	}
}

#˿ȥ˿δ2/3Ƴ鱣buff
# A pop has finished migrating to another planet
# Root = pop
# From = Tile on the new planet
# FromFrom = Tile on the old planet
# on_pop_migration_end
pop_event = {
	id = "harmonious_planet.26"
	hide_window = yes
	
	is_triggered_only = yes

	trigger = {
	  #
		NOT = { has_trait = trait_hive_mind }
		
		fromfrom = {
			planet = {
					#ԭ鱣
					owner = { has_modifier = m_protect_tree_spirit_edict }
					#鱣
	  			has_modifier = m_protect_tree_spirit 
					#˿δﵽ2/3
	  			can_grow_no_affect_tree_spirit = yes	  			
			}
		}
	}
	
	immediate = {
		fromfrom = {
			planet = {
					remove_modifier = m_protect_tree_spirit 
			}
		}
	}
}

#˿ڰóȥ˿δ2/3Ƴ鱣buff
# A pop has been resettled to another planet
# Root = pop
# From = Tile on the old planet
# on_pop_resettled
pop_event = {
	id = "harmonious_planet.27"
	hide_window = yes
	
	is_triggered_only = yes

	trigger = {
	  #
		NOT = { has_trait = trait_hive_mind }
		#鱣
		owner = { has_modifier = m_protect_tree_spirit_edict }
		from = {
			planet = {	
					#鱣
	  			has_modifier = m_protect_tree_spirit 				
					#˿δﵽ2/3
	  			can_grow_no_affect_tree_spirit = yes	  			
			}
		}
	}
	
	immediate = {
		from = {
			planet = {
					remove_modifier = m_protect_tree_spirit 
			}
		}
	}
}

#ȡǱߣǣĴϱ
country_event = {
	id = harmonious_planet.28
	hide_window = yes
	is_triggered_only = yes
					
	immediate = {
			every_owned_planet = {
					limit = {	
							#ûǱ	   
							NOT = { has_modifier = m_protect_tree_spirit }
							#
							has_life_tree = yes
							#δ1/3
	  					harmonize_hive_is_enough = no
	  					#˿ڴﵽ򳬹2/3
	  					can_grow_no_affect_tree_spirit = no
					}
					add_modifier = { modifier =  "m_protect_tree_spirit"  days = -1 }
			}
	}
}

#鱣ǷҪ
event = {
	id = harmonious_planet.29
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		#鱣ǷҪ
		every_playable_country = {
			limit = {	has_modifier = m_protect_tree_spirit_edict	}
			every_owned_planet = {
					limit = {
						has_modifier = m_protect_tree_spirit
						can_grow_no_affect_tree_spirit = yes
					}
					remove_modifier = m_protect_tree_spirit	
			}
		}
	}
}

#򱻶
#Fired whenever a new owner is set for a planet,
#be it after a war or through a trade
#From = Country scope (new owner)
#This = Planet scope
#on_planet_transfer
planet_event = {
	id = harmonious_planet.30
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
			from = { 
				 NOR = {
				 		has_valid_civic = civic_harmonious_tree
						has_modifier = m_kala_gift
				 } 
			}
	}
	immediate = {
			#Ƴ
			if = {
			   			limit = { has_modifier = m_tree_spirit_population_control }
			   			remove_modifier =  m_tree_spirit_population_control
			}
			#Ƴ鱣
			if = {
			   			limit = { has_modifier = m_protect_tree_spirit  }
			   			remove_modifier =  m_protect_tree_spirit 
			}
	}
}

#һˣǷ
# A pop has been built
# This = pop
#ʼ
#on_buildable_pop_created
pop_event = {
	id = "harmonious_planet.31"
	hide_window = yes
	
	is_triggered_only = yes

	trigger = {
	  #ǻ
		has_trait = trait_mechanical
		#鱣
		planet = { has_modifier = m_protect_tree_spirit  }
		
	}
	
	immediate = {
			if = {
					limit = { planet = { sector_controlled = yes } }
					planet = {
						#	sector = { add_minerals = 100 } #ʱ
					}
					else = {
							owner = { add_minerals = 100 }
					}
			}
		  kill_pop = yes
	}
}

#ʱǷҪ鱣
planet_event = {
	id = harmonious_planet.32
	hide_window = yes
	is_triggered_only = yes
		
	immediate = {
			#Ƴ
			if = {
			   			limit = { 
			   					#鱣
			   			    owner = { has_modifier = m_protect_tree_spirit_edict }
			   					#
	  							has_life_tree = yes
	  							#û鱣
	  							NOT = { has_modifier = m_protect_tree_spirit }
			   					#δ1/3
	  							harmonize_hive_is_enough = no
	  							#˿ڴﵽ򳬹2/3
	  							can_grow_no_affect_tree_spirit = no 
	  					}
			   			add_modifier = { modifier =  "m_protect_tree_spirit"  days = -1 }
			}
			
	}
}