# Do not remove or rename this

# Possible Variables for Buildings:
# strategic_resource: strategic resource, deprecated, strategic resource used by the building.
# allow: trigger to check for allowing construction of building.
# prerequisites: Tech requirements for building.
# empire_unique: boolean, can only build one if set to true.
# cost: resource table, cost of building.
# is_orbital: boolean, can only be built in orbital station.
# modifier: modifier, deprecated, applies a modifier to planet; use planet_modifier instead.
# planet_modifier, country_modifier, army_modifier: applies modifier to planet/country/armies
# triggered_planet_modifier = { key (optional), potential (scope: planet), modifier }: applies conditional modifier to planet
# base_buildtime: int, number of days for construction.
# requires_pop, boolean, building will require a pop for production.
# required_resources, resource table, required resources for production.
# produced_resources, resource table, produced resources in production.
# upgrades, buildings list, buildings this building can upgrade into.
# is_listed, boolean, toggles if this building is shown in the non-upgrade buildable list.
# planet_unique, toggles if one can build multiple of this type on a single planet.
# ai_weight, weight for AI, default is set to one, weight set to 0 means that AI will never build it
# is_colony: trigger to check if the building is a colony shelter for country (scope: country, from: planet). default: "always = no"
# active: trigger to check if a building can be active with a given pop worker (scope: pop) if you add a trigger here, you should also add the requirements in the description
# show_tech_unlock_if: trigger to show this building only conditionally in the technology screen. scope: country. default: { always = yes }
# planet_modifier_with_pop_trigger = { key (optional), potential (scope: pop), modifier }: applies modifier to pops on planet that satisfy condition in trigger

#对原版建筑修改

#灵能协会
building_psi_corps = {
	base_buildtime = 360
	empire_unique = yes
	
	cost = {
		minerals = 450
	}
	
	produced_resources = {
		unity = 10
	}
	
	required_resources = {
		energy = 4
	}
	
	country_modifier = {
		planet_unrest_mult = -0.1
		pop_government_ethic_attraction = 0.05
	}
	
	#2.0改动
	potential = {
		owner = {
		  OR= {
		     has_ascension_perk = ap_mind_over_matter
		     has_country_flag = f_mind_over_matter 
		  }
		}
		planet = {
			is_capital = yes
		}	
	}

	destroy_if = {
		exists = owner
		owner = { has_authority = auth_machine_intelligence }
	}	
	
	#2.0改动
	allow = {
		custom_tooltip = {
			fail_text = "requires_building_capital_1"
			planet = {
				OR = {
					has_building = "building_capital_1"
					has_building = "building_capital_2"
					has_building = "building_capital_3"
				}
			}
		}
	}
	
	ai_weight = {
		weight = 20
	}
}
#乐土穹顶
building_paradise_dome = {
	base_buildtime = 360
	planet_unique = yes
	
	cost = {
		minerals = 200
	}
	
	required_resources = {
		energy = 2
	}
	
	produced_resources = {
		food = 4
		unity = 2
	}
	
	planet_modifier = {
		pop_citizen_happiness = 0.05
	}
	
	potential = {
		owner = {
		  OR ={
		  		has_non_swapped_tradition = tr_harmony_utopian_dream
		  		has_swapped_tradition = tr_ideal_homeland
		  }
			
		}
	}

	destroy_if = {
		exists = owner
		owner = {
			OR = {
				has_authority = auth_machine_intelligence
				NOR ={
		  		has_non_swapped_tradition = tr_harmony_utopian_dream
		  		has_swapped_tradition = tr_ideal_homeland
		    }
			}
		}
	}
	
	allow = {
		custom_tooltip = {
			text = "requires_building_capital_1_or_hab"
			planet = {
				OR = {
					has_building = "building_hab_capital"
					has_building = "building_capital_1"
					has_building = "building_capital_2"
					has_building = "building_capital_3"
				}
			}
		}
	}
	
	ai_allow = {
		NOR = {
			has_resource = {
				type = sr_betharian
				amount > 0
			}	
			has_resource = {
				type = sr_alien_pets
				amount > 0
			}				
		}
		
		# If planet only has slaves/robots, keep it to mining and farming...
		is_slave_tile_or_planet = no	
	}

	ai_weight = {
		factor = 10
	}
}


#蜂巢突触
building_hive_synapse = {
	base_buildtime = 360
	planet_unique = yes
	
	cost = {
		minerals = 250
	}
	
	potential = {
		owner = {
		   OR = {
		   		has_swapped_tradition = tr_synchronicity_hive_mind_synapse
		   		has_swapped_tradition = tr_ideal_homeland
		   }			
		}
	}
	
	destroy_if = {
		exists = owner
		owner = { NOR = { 
		     has_swapped_tradition = tr_synchronicity_hive_mind_synapse 
		     has_swapped_tradition = tr_ideal_homeland
		} }
	}
	
	produced_resources = {
		energy = 2
		unity = 2
	}
	
	planet_modifier = {
		pop_resource_output = 0.05
	}
	
	ai_allow = {
		NOR = {
			has_resource = {
				type = sr_betharian
				amount > 0
			}	
			has_resource = {
				type = sr_alien_pets
				amount > 0
			}				
		}
		
		# If planet only has slaves/robots, keep it to mining and farming...
		is_slave_tile_or_planet = no			
	}

	ai_weight = {
		factor = 10
	}
}

#生命树种子
building_life_tree_seed = {
	base_buildtime = 0
	planet_unique = yes
	requires_pop = no
	
	cost = {
	}
	
	potential = {
		owner = {
			 check_variable =  { which = "seed_num"  value > 0 }	
		   OR = {
		   		has_modifier = m_kala_gift
		   		has_valid_civic = civic_harmonious	
		   		has_valid_civic = civic_harmonious_tree	   		
		   }			
		}
		planet = {
			NOR = {
					is_planet_class = pc_machine
					has_building = building_life_tree
					has_building = building_mother_life_tree
					has_blocker =  tb_growing_life_tree 
			}
		}
	}
	
	allow = {
			#空地数（hive_mind不算人口）要达星球的1/3(暂时不要求，不然ai不会种)
			#custom_tooltip = {
			#	fail_text = "LIFE_TREE_SEED_REQUIER_MORE_EMPTY_TILE"
			#	planet = {
			#		can_build_life_tree_seed = yes
			#	}
			#}
			#只能建在没有人口没有建筑的空地
			custom_tooltip = {
				fail_text = "LIFE_TREE_SEED_REQUIER_EMPTY_TILE"
				tile = {
					 has_pop = no
					 #has_building = no
				}
			}
			#行星不能在转化类型
			custom_tooltip = {
				fail_text = "LIFE_TREE_SEED_REQUIER_PLANET_NOT_TERFORMING"
				planet = {
					is_terraforming = no
				}
			}
	}
	
	destroy_if = {
		exists = owner
		owner = {
		   NOR = {
		   		has_modifier = m_kala_gift
		   		has_valid_civic = civic_harmonious 
		   		has_valid_civic = civic_harmonious_tree
		   }			
		}
	}
	
	produced_resources = {
	    food =2
	    society_research = 2
	}
	
	planet_modifier = {
	}
	
	on_queued = {
		planet = {
			owner = {
				sub_life_tree_seed = yes
			}
		}
		tile = {
				set_blocker = tb_growing_life_tree
		}		
		planet = { 
				#重建生命树，树灵停止灭绝
				planet_event = { id = harmonious_planet.19 } 
				#10年后长成生命树
				planet_event = { id = harmonious_planet.6  days = 3600  random = 20 } 
				add_modifier = { modifier =  "m_growing_life_tree"  days = 3620 }
				#检查是否要给行星添加树灵保护修正
				planet_event = { id = harmonious_planet.32 } 
		}
	}
	on_unqueued = {

	}
	
	ai_allow = {
		NOR = {
			has_resource = {
				type = sr_betharian
				amount > 0
			}	
			has_resource = {
				type = sr_alien_pets
				amount > 0
			}				
		}
		
		# If planet only has slaves/robots, keep it to mining and farming...
		#is_slave_tile_or_planet = no			
	}

	ai_weight = {
		factor = 20
	}
}

#生命树
building_life_tree = {
	is_listed = no
	planet_unique = yes
	can_demolish = no
	#requires_pop = no
	#icon = "building_primitive_factory"	
	
	defense_armies = 3
	
	allow = {
			always = no
	}
	
	destroy_if = {
		exists = owner
		owner = {
		   NOR = {
		   		has_modifier = m_kala_gift
		   		has_valid_civic = civic_harmonious 
		   		has_valid_civic = civic_harmonious_tree
		   }			
		}
	}
	
	produced_resources = {
		food = 2
		society_research = 8			
		unity = 8	
	}
	
	adjacency_bonus = {
		tile_building_resource_food_add = 1
		tile_building_resource_society_research_add = 1
		tile_building_resource_unity_add = 1
	}
	
	planet_modifier = {
		pop_happiness = 0.05
#		planet_fortification_strength = 0.5
		pop_growth_speed = 0.2
		pop_environment_tolerance = 0.10
		tile_resource_food_mult	= 0.10
	}	
	
	planet_modifier_with_pop_trigger = { 
			key = energy_tree
			potential = {
			    #生命树长在能量格上
				  planet = {
				  	any_tile = {
				  			has_building = building_life_tree
				  			has_resource = { type = energy amount > 0 }
				  	}
				  }
				  has_trait =  trait_tree_spirit
			}
			modifier = {
				#tile_resource_energy_add = 1	
				tile_resource_energy_mult	=0.15
			}	
	}
	
	planet_modifier_with_pop_trigger = { 
			key = betharian_tree
			potential = {
			    #生命树长在贝石上
				  planet = {
				  	any_tile = {
				  			has_building = building_life_tree
				  			has_resource = { type = sr_betharian amount > 0 }
				  	}
				  }
				  has_trait =  trait_tree_spirit
			}
			modifier = {
				#tile_resource_energy_add = 1	
				tile_resource_energy_mult	= 1
			}	
	}
	
	planet_modifier_with_pop_trigger = { 
			key = minerals_tree
			potential = {
			    #生命树长在矿物格上
				  planet = {
				  	any_tile = {
				  			has_building = building_life_tree
				  			has_resource = { type = minerals amount > 0 }
				  	}
				  }
				  has_trait =  trait_tree_spirit
			}
			modifier = {
				#tile_resource_energy_add = 1	
				tile_resource_minerals_mult	=0.15
			}	
	}
	
	
	ai_replace = no
	event_building = yes
}

#生命母树
building_mother_life_tree = {
	is_listed = no
	planet_unique = yes
	can_demolish = no
	#requires_pop = no
	#icon = "building_primitive_factory"	
	
	defense_armies = 5
	
	#base_buildtime = 0
	#cost = {
	#}
	
	allow = {
			always = no
			#owner = {
			#	has_modifier = m_kala_gift
			#}
	}
	
	destroy_if = {
		exists = owner
		owner = {
		   NOR = {
		   		has_modifier = m_kala_gift
		   		has_valid_civic = civic_harmonious 
		   		has_valid_civic = civic_harmonious_tree
		   }			
		}
	}
	
	produced_resources = {
		food = 4
		society_research = 10		
		unity = 12		
	}
	
	#该选项scope只能是country, 对全国唯一建筑比较容易控制
	#produced_resource_trigger = {
	#	modifier = {
	#		has_valid_civic = civic_agrarian_idyll
	#		NOT = { has_swapped_tradition = tr_adaptability_finish }
	#		resources = {
	#			unity = 1
	#		}
	#	}
	#}
	
	adjacency_bonus = {
		tile_building_resource_food_add = 2
		tile_building_resource_society_research_add = 2
		tile_building_resource_unity_add = 2
	}
	
	planet_modifier = {
		pop_happiness = 0.10
#		planet_fortification_strength = 1
		pop_growth_speed = 0.4
		pop_environment_tolerance = 0.20
		tile_resource_food_mult	= 0.25
	}	
	
	
	#生命树长在异星宠物上
	triggered_planet_modifier = { 
			key = alien_pets_tree_mod
			potential = {
				any_tile = {
						has_building = building_mother_life_tree
				  	has_resource = { type = sr_alien_pets amount > 0 }
				}
			} 
			modifier = {
				pop_happiness = 0.20
				tile_resource_unity_mult = 1.0
				tile_resource_society_research_mult = 1.0
			} 
	}
	
	#生命树长在贝石上
	triggered_planet_modifier = { 
			key = betharian_tree_mod
			potential = {
				any_tile = {
						has_building = building_mother_life_tree
				  	has_resource = { type = sr_betharian amount > 0 }
				}
			} 
			modifier = {				
				tile_resource_energy_mult = 1.0
			} 
	}
	
	planet_modifier_with_pop_trigger = { 
			key = energy_tree
			potential = {
			    #生命树长在能量格上
				  planet = {
				  	any_tile = {
				  			has_building = building_mother_life_tree
				  			has_resource = { type = energy amount > 0 }
				  	}
				  }
				  has_trait =  trait_tree_spirit
			}
			modifier = {
				#tile_resource_energy_add = 1	
				tile_resource_energy_mult	=0.25
			}	
	}
	
	planet_modifier_with_pop_trigger = { 
			key = betharian_tree
			potential = {
			    #生命树长在贝石上
				  planet = {
				  	any_tile = {
				  			has_building = building_mother_life_tree
				  			has_resource = { type = sr_betharian amount > 0 }
				  	}
				  }
				  has_trait =  trait_tree_spirit
			}
			modifier = {
				tile_resource_energy_add = 1	
				tile_resource_energy_mult	= 1
			}	
	}
	
	planet_modifier_with_pop_trigger = { 
			key = minerals_tree
			potential = {
			    #生命树长在矿物格上
				  planet = {
				  	any_tile = {
				  			has_building = building_mother_life_tree
				  			has_resource = { type = minerals amount > 0 }
				  	}
				  }
				  has_trait =  trait_tree_spirit
			}
			modifier = {
				#tile_resource_energy_add = 1	
				tile_resource_minerals_mult	=0.25
			}	
	}
	
	
	
	#country_modifier = {
	#	max_minerals = 3000
	#}
	
	#army_modifier = {
	#	army_damage_mult = 0.10
	#}
		
	
	ai_replace = no
	event_building = yes
}