
@damage_taken_mult_per_district = 0.01
building_planetmega_reshaper = {
	icon = building_industrial_subsidiary
	position_priority = 10
	base_buildtime = @b5_time
	category = government
	can_build = yes
	building_sets = { government urban }

	planet_limit = 1
	potential = {
		carrier_is_type = planet
		owner? = { has_tradition = tr_pm_granchor_reshaper }
	}

	planet_modifier = {
		planet_max_districts_add = 1
		planet_building_capacity_add = 1
		#army_damage_taken_mult = @damage_taken_mult_per_district
		planet_orbital_bombardment_damage = @damage_taken_mult_per_district
		terraforming_cost_mult = -0.1
	}
	triggered_planet_modifier = {
		potential = { is_variable_set = plnmg_reshaper_times }
		planet_max_districts_add = 1
		#army_damage_taken_mult = @damage_taken_mult_per_district
		planet_orbital_bombardment_damage = @damage_taken_mult_per_district
		mult = plnmg_reshaper_times
	}

	system_modifier = { terraform_speed_mult = 1 }

	resources = {
		category = planet_buildings
		cost = { minerals = @b5_minerals }
		upkeep = { energy = 5 }
		upkeep = {
			trigger = { is_variable_set = plnmg_reshaper_times }
			energy = 5
			mult = value:sv_plnmg_reshaper_upkeep_mult
		}
	}

	triggered_desc = { text = building_planetmega_reshaper_tooltip }
	# show_in_tech = tech_planetmega_transfer_prereq
	# show_tech_unlock_if = { has_tradition = tr_pm_granchor_reshaper }
}

building_plnmg_nanite_swarm = {
	icon = building_colony_shelter_nanotech
	position_priority = 10
	base_buildtime = @b5_time
	category = army
	can_build = yes
	building_sets = {
		government
		urban
		fortress
	}

	planet_limit = {
		base = 1
		modifier = {
			has_plnmg_any_fortress = yes
			add = 1
		}
		modifier = {
			or = {
				has_deposit = d_plnmg_maginot_nexus
				has_carrier_flag = planet_has_plnmg_maginot_nexus
			}
			add = 1
		}
		modifier = {
			or = {
				has_deposit = d_plnmg_nano_storm
				has_carrier_flag = planet_has_plnmg_nano_storm
			}
			add = 1
		}
		modifier = {
			is_planet_class = pc_nanotech
			add = 1
		}
	}
	potential = {
		owner? = {
			is_ai = no
			has_active_tradition = tr_pm_granchor_swap_3_autodef
		}
	}
	allow = {
		or = {
			has_plnmg_any_fortress = yes
			has_deposit = d_plnmg_nano_storm
			hidden_trigger = { has_carrier_flag = planet_has_plnmg_nano_storm }
		}
	}

	planet_modifier = {
		army_defense_health_mult = 0.25
		army_defense_morale_mult = 0.25
		army_defense_damage_mult = 0.25
	}
	triggered_planet_modifier = {
		potential = { owner? = { has_tradition = tr_nanotech_finish } }
		army_defense_health_mult = 0.35
		army_defense_morale_mult = 0.35
		army_defense_damage_mult = 0.35
	}

	# army_modifier = {
	# 	army_health = 0.1
	# 	army_damage_mult = 0.1
	# 	army_collateral_damage_mult = 0.1
	# }
	# triggered_army_modifier = {
	# 	potential = { owner? = { has_tradition = tr_nanotech_finish } }
	# 	army_health = 0.2
	# 	army_damage_mult = 0.2
	# }

	resources = {
		category = planet_buildings
		cost = {
			minerals = @b3_minerals
			nanites = @b2_minerals
		}
		upkeep = {
			energy = 10
			nanites = 1
		}
		upkeep = {
			trigger = { owner? = { has_tradition = tr_nanotech_finish } }
			nanites = 9
		}
	}

	ai_weight_coefficient = 0
}

building_plnmg_automation_convert_1 = {
    base_buildtime = @b3_time
    category = pop_assembly
	can_build = yes
    building_sets = { government urban automation urban_automation urban_automation_arcology }
	prerequisites = { tech_planetmega_enigmatic_res }
	potential = { not = { has_building = building_plnmg_automation_convert_2 } }
	planet_limit = 1
	position_priority = 10

	triggered_planet_modifier = {
	    bonus_automated_workforce_mult = 0.5
	    mult = value:sv_building_plnmg_auto_cnv_mult
	}
	triggered_desc = { text = building_plnmg_automation_convert_1_tt }

	resources = {
		category = planet_buildings
		cost = {
			minerals = @b3_minerals
			energy = @b3_time
		}
		upkeep = {
			trigger = { check_modifier_value = { modifier = planet_automated_jobs_energy_upkeep_mult value > -1 } }
			energy = 8
			mult = value:sv_building_plnmg_auto_cnv_upkp_mult
		}
	}

	upgrades = { building_plnmg_automation_convert_2 }
    ai_weight_coefficient = 1.1
	additional_ai_weight = 15
}
building_plnmg_automation_convert_2 = {
	base_buildtime = @b5_time
	category = pop_assembly
	can_build = no
	building_sets = { government urban automation urban_automation urban_automation_arcology }
	prerequisites = { tech_planetmega_cosmogenesis }
	planet_limit = 1
	position_priority = 10

	triggered_planet_modifier = {
		bonus_automated_workforce_mult = 1
		mult = value:sv_building_plnmg_auto_cnv_mult
	}
	triggered_desc = { text = building_plnmg_automation_convert_2_tt }

	resources = {
		category = planet_buildings
		cost = {
			minerals = @b4_minerals
			energy = @b5_time
		}
		upkeep = {
			trigger = { check_modifier_value = { modifier = planet_automated_jobs_energy_upkeep_mult value > -1 } }
			energy = 15
			mult = value:sv_building_plnmg_auto_cnv_upkp_mult
		}
	}

	ai_weight_coefficient = 1.1
	additional_ai_weight = 15
}

# building_plnmg_test = {
# 	icon = building_plnmg_automation_convert_1
# 	base_buildtime = 1
# 	position_priority = 10
# 	category = pop_assembly
# 	can_build = yes
# 	building_sets = { government urban automation urban_automation urban_automation_arcology }
#
# 	planet_limit = 1
# 	potential = { not = { has_carrier_flag = cant_upgrade_plnmg_t0_admin } }
# 	on_queued = {
# 		set_timed_carrier_flag = { flag = cant_upgrade_plnmg_t0_admin days = 25 }
# 		planet_event = { id = planetmega.261 }
# 	}
# }
