
tech_plnmg_rebuild_the_abandoned = {
	cost = @tier3cost3
	area = engineering
	icon = tech_ground_megastructure
	category = { industry }
	tier = 3
	potential = {
		or = {
			has_technology = tech_housing_2
			is_wilderness_empire = yes
		}
	}
	weight = @tier3weight3

	weight_modifier = {
		inline_script = {
			script = technologies/tech_t1breakthrough_plnmg_weightmod
			TECH = tech_plnmg_rebuild_the_abandoned
		}
        modifier = {
            factor = 2.5
            has_technology = tech_assembly_pattern
        }
		modifier = {
			factor = 0
			NOT = { any_owned_colony = { has_plnmg_any_destroyed_mega = yes } }
		}
	}

	prereqfor_desc = {
	 	custom = {
	 		title = "TECH_PLANETMEGA_REBUILD_EXTRA_TITLE"
	 		desc = "TECH_PLANETMEGA_REBUILD_EXTRA_DESC"
	 	}
	}

	ai_weight = {
		weight = @tier3weight2
		inline_script = {
			script = technologies/tech_t1breakthrough_plnmg_weightmod
			TECH = tech_plnmg_rebuild_the_abandoned
		}
		# modifier = {
		# 	factor = 0
		# 	NOT = { any_owned_colony = { has_plnmg_any_destroyed_mega = yes } }
		# }
	}
}

tech_ground_megastructure = {
	cost = @tier4cost1
	area = engineering
	category = { industry }
	tier = 4
	potential = {
		or = {
			has_technology = tech_housing_2
			is_wilderness_empire = yes
		}
	}
	weight = @tier4weight1

	weight_modifier = {
		inline_script = {
			script = technologies/tech_t1breakthrough_plnmg_weightmod
			TECH = tech_ground_megastructure
		}
        modifier = {
            factor = 2.5
            has_technology = tech_construction_templates
        }
		modifier = {
			factor = 3.5
			has_technology = tech_plnmg_rebuild_the_abandoned
		}
        modifier = {
            factor = 2
            years_passed > 50
        }
        modifier = {
            factor = 3
            years_passed > 55
        }
        modifier = {
            factor = 4
            years_passed > 60
        }
        modifier = {
            factor = 2
			has_tradition = tr_prosperity_sct
        }
		modifier = {
			factor = 3
			or = {
				has_tradition = tr_domination_imperious_architecture
				owner_main_species = { has_dystopian_society_living_standard_type = yes }
			}
		}
	}

	prereqfor_desc = {
		custom = {
			title = "TECH_GROUND_MEGASTRUCTURE_EXTRA_TITLE"
			desc = "TECH_GROUND_MEGASTRUCTURE_EXTRA_DESC"
		}
	}

	ai_weight = {
		weight = @tier4weight1
        modifier = {
            factor = 10
			any_plnmg_neighbor_has_tech = { TECH = tech_ground_megastructure }
        }
        modifier = {
			factor = 30
            or = {
                has_any_abandoned_planetmega_in_empire = yes
                has_any_planetmega_in_empire = yes
            }
        }
		modifier = {
			factor = 3.5
			has_technology = tech_plnmg_rebuild_the_abandoned
		}
	}
}

tech_planetmega_refinery = {
	cost = @tier4cost2
	area = engineering
	category = { materials }
	tier = 4
	prerequisites = { "tech_ground_megastructure" "tech_exotic_gases" "tech_volatile_motes" "tech_rare_crystals" }
	weight = @tier4weight2
	modifier = {
		planet_jobs_volatile_motes_produces_mult = 0.05
		planet_jobs_rare_crystals_produces_mult = 0.05
		planet_jobs_exotic_gases_produces_mult = 0.05
	}
	weight_modifier = {
		inline_script = {
			script = technologies/tech_t1base_plnmg_weight_modifiers
			TECH = tech_planetmega_refinery
		}
		modifier = {
			factor = 0.1
			nand = {
				has_technology = tech_mine_exotic_gases
				has_technology = tech_mine_rare_crystals
				has_technology = tech_mine_volatile_motes
			}
		}
	}
	ai_weight = {
		weight = @tier4weight2
		inline_script = {
			script = technologies/tech_t1base_plnmg_weight_modifiers
			TECH = tech_planetmega_refinery
		}
		modifier = {
			factor = 0.1
			nand = {
				has_technology = tech_mine_exotic_gases
				has_technology = tech_mine_rare_crystals
				has_technology = tech_mine_volatile_motes
			}
		}
	}
}

tech_planetmega_administration = {
	cost = @tier4cost2
	area = society
	category = { statecraft }
	tier = 4
	prerequisites = {
		tech_ground_megastructure
		tech_galactic_administration
		or = {
			tech_collective_self
			tech_embodied_dynamism
		}
	}
	potential = { is_wilderness_empire = no }
	weight = @tier4weight2
	# prereqfor_desc = {
	# 	custom = {
	# 		title = "TECH_PLANETMEGA_ADMINISTRATION_EXTRA_TITLE"
	# 		desc = "TECH_PLANETMEGA_ADMINISTRATION_EXTRA_DESC"
	# 	}
	# }
	modifier = {
		custom_tooltip = TECH_PLANETMEGA_ADMINISTRATION_EXTRA_TITLE
		show_only_custom_tooltip = no
		# empire_size_mult = -0.05
		# tradition_cost_empire_size_mult = -0.05
		planetmega_admin_limit_add = 1
		divided_patrongage_max_subjects = 1
	}
	weight_modifier = {
		inline_script = {
			script = technologies/tech_t1base_plnmg_weight_modifiers
			TECH = tech_planetmega_administration
		}
	}
	ai_weight = {
		weight = @tier4weight2
		inline_script = {
			script = technologies/tech_t1base_plnmg_weight_modifiers
			TECH = tech_planetmega_administration
		}
	}

	technology_swap = {
		name = tech_plnmg_administration_ges
        #inherit_name = yes
		inherit_icon = yes
		inherit_effects = no
		trigger = { is_gestalt = yes }
		modifier = {
			custom_tooltip = TECH_PLANETMEGA_ADMINISTRATION_EXTRA_TITLE
			show_only_custom_tooltip = no
			# empire_size_mult = -0.05
			# tradition_cost_empire_size_mult = -0.05
			planetmega_admin_limit_add = 2
			divided_patrongage_max_subjects = 1
		}
	}
}

tech_planetmega_efficiency = {
	cost = 13000
	area = engineering
	category = { industry }
	icon = tech_ground_megastructure
	tier = 4
	prerequisites = { "tech_ground_megastructure" "tech_planetary_infrastructure_2" }
	weight = @tier5weight3

	weight_modifier = {
		modifier = {
			factor = 1.25
			OR = {
				has_trait_in_council = { TRAIT = leader_trait_expertise_industry }
				has_trait_in_council = { TRAIT = leader_trait_curator }
				has_trait_in_council = { TRAIT = leader_trait_spark_of_genius }
				has_trait_in_council = { TRAIT = leader_trait_spark_of_genius_2 }
				has_trait_in_council = { TRAIT = leader_trait_maniacal }
				has_trait_in_council = { TRAIT = leader_trait_maniacal_2 }
				has_trait_in_council = { TRAIT = leader_trait_maniacal_3 }
			}
		}
	}

	modifier = {
		planet_building_build_speed_mult = 0.1
		planet_structures_cost_mult = -0.1
		megastructure_build_speed_mult = 0.05
		ground_megastructure_build_speed_mult = 0.1
		planet_building_capacity_add = 1
		ground_megastructure_build_cap_add = 1
	}

	ai_weight = { weight = @tier5weight3 }
}

tech_planetmega_habitat_opt = {
    cost = 13000
    area = engineering
    category = { industry }
    icon = tech_ground_megastructure
    tier = 4
    prerequisites = { "tech_ground_megastructure" }
    weight = @tier5weight3
    is_rare = yes
	potential = {
		or = {
			has_technology = tech_habitat_2
			is_nomadic = yes
		}
	}

    weight_modifier = {
        inline_script = {
            script = technologies/rare_technologies_weight_modifiers
            TECHNOLOGY = tech_planetmega_habitat_opt
        }
        modifier = {
            factor = 1.5
            is_void_dweller_empire = yes
        }
        modifier = {
            factor = 5
            has_void_dweller_origin = yes
        }
    }

    modifier = {
        habitat_max_districts_add = 1
        planetmega_owned_limit_habitat_add = 1
    }

	technology_swap = {
		name = tech_planetmega_arkship_opt
		inherit_icon = yes
		inherit_effects = no
		trigger = { is_nomadic = yes }
		modifier = {
			#arkship_max_districts_add = 1
			planetmega_owned_limit_arkship_add = 1
		}
	}

    ai_weight = { weight = @tier5weight3 }
}

tech_planetmega_enigmatic_res = {
	cost = 15000
	area = engineering
	is_rare = yes
	category = { industry }
	icon = tech_ground_megastructure
	tier = 4
	prerequisites = { "tech_planetmega_efficiency" }
	weight = @tier4weight3

	weight_modifier = {
		modifier = {
			is_variable_set = num_researched_cosmogenesis_techs
			factor = num_researched_cosmogenesis_techs
		}
		modifier = {
			factor = 1.25
			has_ascension_perk = ap_enigmatic_engineering
		}
		modifier = {
			factor = 1.35
			is_tankbound_empire = yes
		}
		inline_script = technologies/tech_plnmg_cosmogenesis_factor
		modifier = {
			factor = 0
			calc_true_if = {
				amount < 4
				has_technology = tech_fe_affluence_1
				has_technology = tech_fe_nourishment_1
				has_technology = tech_fe_fabricator_1
				has_technology = tech_fe_singularity_1
				has_technology = tech_fe_forge_1
				has_technology = tech_fe_dome_1
				has_technology = tech_fe_fortress_1
				has_technology = tech_fe_administration_1
				has_technology = tech_fe_assembly_1
				has_technology = tech_fe_clinic_1
				has_technology = tech_fe_security_1
				has_technology = tech_fe_market_1
				has_technology = tech_fe_silo_1
				has_technology = tech_fe_entertainment_1
				has_technology = tech_fe_lab_1
				has_technology = tech_fe_mine_1
			}
		}
	}

	modifier = {
		planet_buildings_mega_produces_mult = 0.1
		planet_buildings_mega_upkeep_mult = 0.1
		jobs_about_planetmega_produces_mult = 0.1
		jobs_about_planetmega_upkeep_mult = 0.1
		planetmega_job_amount_mult = 0.1
		planet_building_capacity_add = 1
	}

	ai_weight = { weight = 1000 }
}

### improved planetmega techs ###

tech_planetmega_improved = {
	icon = tech_ground_megastructure
	cost = @tier5cost1
	area = engineering
	is_rare = yes
	category = { industry }
	tier = 5
	prerequisites = { "tech_planetmega_efficiency" }
	weight = @tier5weight1
	potential = { not = { has_global_flag = planetmega_improved_banned } }

	weight_modifier = {
		inline_script = {
			script = technologies/tech_t2breakthrough_plnmg_weightmod
			TECH = tech_planetmega_improved
		}
		inline_script = {
			script = technologies/rare_technologies_weight_modifiers
			TECHNOLOGY = tech_planetmega_improved
		}
	}

	prereqfor_desc = {
		custom = {
			title = "TECH_PLANETMEGA_IMPROVED_EXTRA_TITLE"
			desc = "TECH_PLANETMEGA_IMPROVED_EXTRA_DESC"
		}
	}
	modifier = { district_planetmega_expansion_max_add = 5 }

	ai_weight = {
		weight = @tier5weight1
		inline_script = {
			script = technologies/tech_t2breakthrough_plnmg_weightmod
			TECH = tech_planetmega_improved
		}
		inline_script = {
			script = technologies/rare_technologies_weight_modifiers
			TECHNOLOGY = tech_planetmega_improved
		}
	}
}

tech_plnmg_admin_repeatable_1 = {
	icon = tech_planetmega_administration
	cost = @tier5cost2
	area = society
	category = { statecraft }
	tier = 5
	prerequisites = { tech_planetmega_improved tech_planetmega_administration }
	weight = @tier5weight2
	weight_modifier = {
		modifier = {
			factor = 0.1
			num_owned_colonies < 2
		}
	}

	levels = 3
	cost_per_level = @tier4cost2
	# weight_groups = { repeatable }
	# mod_weight_if_group_picked = { repeatable = 0.1 }

	modifier = {
		planetmega_admin_limit_add = 1
		divided_patrongage_max_subjects = 0.5
	}
	ai_weight = {
		weight = @tier5weight2
		modifier = {
			factor = 0.1
			num_owned_colonies < 3
		}
	}

	technology_swap = {
		name = tech_plnmg_admin_rept_1_ges
        #inherit_name = yes
		inherit_icon = yes
		inherit_effects = no
		trigger = { is_gestalt = yes }
		modifier = {
			planetmega_admin_limit_add = 2
			divided_patrongage_max_subjects = 0.5
		}
	}
}

tech_planetmega_cosmogenesis = {
	cost = @fallentechcost
	area = engineering
	is_rare = yes
	is_dangerous = yes
	category = { industry }
	icon = tech_ground_megastructure
	tier = 5
	prerequisites = { "tech_planetmega_improved" "tech_planetmega_enigmatic_res" }
	weight = @tier5weight3
	potential = {
		or = {
			has_menace_perk = menp_cosmo_buildings_1
			has_country_flag = ZH_dl_tech_research
			has_ascension_perk = ap_AIO_allinone
			is_country_type = AIO_Aforgomom
			can_build_all_fe_level_2_buildings = yes
		}
	}

	weight_modifier = {
		modifier = {
			is_variable_set = num_researched_cosmogenesis_techs
			factor = num_researched_cosmogenesis_techs
		}
		inline_script = technologies/tech_plnmg_cosmogenesis_factor
	}

	modifier = {
		planet_buildings_mega_produces_mult = 0.2
		planet_buildings_mega_upkeep_mult = 0.2
		planetmega_job_amount_mult = 0.15
	}

	ai_weight = { weight = 1000 }
}

tech_planetmega_active_defense = {
	cost = @tier5cost2
	area = engineering
	category = { voidcraft }
	tier = 5
	prerequisites = { "tech_planetmega_improved" "tech_planetary_shield_generator" "tech_global_defense_grid" }
	weight = @tier5weight2

	weight_modifier = {
		inline_script = {
			script = technologies/tech_t2base_plnmg_weight_modifiers
			TECH = tech_planetmega_active_defense
		}
	}

	prereqfor_desc = {
		custom = {
			title = "TECH_PLANETMEGA_ACTIVE_DEFENSE_EXTRA_TITLE"
			desc = "TECH_PLANETMEGA_ACTIVE_DEFENSE_EXTRA_DESC"
		}
	}

	modifier = {
		deep_space_citadel_limit_add = 1
		starbase_defense_platform_capacity_add = 7
	}

	ai_weight = {
		weight = @tier5weight2
		inline_script = {
			script = technologies/tech_t2base_plnmg_weight_modifiers
			TECH = tech_planetmega_active_defense
		}
	}
}

tech_plnmg_interthought = {
	area = physics
	cost = @tier5cost2
	tier = 5
	category = { computing }
	prerequisites = { "tech_planetmega_improved" "tech_basic_science_lab_3"  "tech_space_science_5" }
	weight = @tier5weight2

	prereqfor_desc = {
		custom = {
			title = "TECH_PLANETMEGA_INTERTHOUGHT_EXTRA_TITLE"
			desc = "TECH_PLANETMEGA_INTERTHOUGHT_EXTRA_DESC"
		}
	}

	modifier = {
		tech_cost_empire_size_mult = -0.05
		physics_tech_cost_mult = -0.05
		society_tech_cost_mult = -0.05
		engineering_tech_cost_mult = -0.05
	}

	weight_modifier = {
		inline_script = {
			script = technologies/tech_t2base_plnmg_weight_modifiers
			TECH = tech_plnmg_interthought
		}
	}

	ai_weight = {
		weight = @tier5weight2
		inline_script = {
			script = technologies/tech_t2base_plnmg_weight_modifiers
			TECH = tech_plnmg_interthought
		}
	}
}

tech_plnmg_managed_ideas = {
    area = physics
    cost = @tier5cost3
    tier = 5
    category = { computing }
    prerequisites = { "tech_plnmg_interthought" }
    weight = @tier5weight3
    weight_modifier = {
        inline_script = {
            script = technologies/tech_t2base_plnmg_weight_modifiers
            TECH = tech_plnmg_interthought
        }
        modifier = {
            factor = 1.1
            is_materialist = yes
        }
        modifier = {
            factor = 1.5
            is_planetmega_psionic = yes
        }
        # modifier = {
        #     factor = 1.25
        #     is_xenophile = yes
        # }
        modifier = {
            factor = 2
            or = {
                is_gestalt = yes
                is_authoritarian = yes
            }
        }
        modifier = {
            factor = 2.5
            is_authoritarian = yes
            is_spiritualist = yes
        }
        modifier = {
            factor = 0.5
            is_xenophile = yes
        }
        modifier = {
            factor = 0.1
            is_egalitarian = yes
        }
    }

    prereqfor_desc = {
        custom = {
            title = "TECH_PLNMG_MANAGED_IDEAS_EXTRA_TITLE"
            desc = "TECH_PLNMG_MANAGED_IDEAS_EXTRA_DESC"
        }
    }

    modifier = {
        pop_government_ethic_attraction = 0.1
        planet_pops_unity_produces_mult = 0.01
    }

	technology_swap = { # 管理式民主（笑）
		name = tech_plnmg_managed_democracy
		inherit_icon = yes
		inherit_effects = yes
		trigger = { is_democracy = yes }
	}

    ai_weight = {
        weight = @tier5weight2
        inline_script = {
            script = technologies/tech_t2base_plnmg_weight_modifiers
            TECH = tech_plnmg_interthought
        }
    }
}

tech_planetmega_junik = {
	area = society
	cost = @tier5cost3
	tier = 5
	is_rare = yes
	category = { biology }
	prerequisites = { tech_plnmg_interthought }
	weight = @tier5weight3
	weight_modifier = {
		modifier = {
			factor = 2
			or = {
				has_technology = tech_synthetic_leaders
				any_neighbor_country = { has_technology = tech_synthetic_leaders }
			}
		}
		inline_script = {
			script = technologies/rare_technologies_weight_modifiers
			TECHNOLOGY = tech_planetmega_junik
		}
	}
	prereqfor_desc = {
		custom = {
			title = "TECH_PLANETMEGA_JUNIK_EXTRA_TITLE"
			desc = "TECH_PLANETMEGA_JUNIK_EXTRA_DESC"
		}
	}
	ai_weight = {
		weight = @tier5weight3
		modifier = {
			factor = 0.5
			not = { is_hive_empire = yes }
		}
		modifier = {
			factor = 3
			or = {
				has_technology = tech_synthetic_workers
				any_neighbor_country = { has_technology = tech_synthetic_workers }
			}
		}
		modifier = {
			factor = 5
			or = {
				has_technology = tech_synthetic_leaders
				any_neighbor_country = { has_technology = tech_synthetic_leaders }
			}
		}
		inline_script = {
			script = technologies/rare_technologies_weight_modifiers
			TECHNOLOGY = tech_planetmega_junik
		}
	}
}

tech_planetmega_singularity = {
	area = physics
	category = { particles }
	cost = @pmtech_tier5cost4
	tier = @fallentechtier
	is_dangerous = yes
	prerequisites = {
		tech_mine_dark_matter
		tech_planetmega_improved
		or = {
			tech_dark_matter_power_core
			tech_fe_fabricator_2
		}
	}
	weight = @tier5weight3
	prereqfor_desc = {
		custom = {
			title = "TECH_PLANETMEGA_SINGULARITY_EXTRA_TITLE"
			desc = "TECH_PLANETMEGA_SINGULARITY_EXTRA_DESC"
		}
	}
	modifier = { country_sr_dark_matter_produces_mult = 0.05 }
	weight_modifier = {
		modifier = {
			factor = 1.5
			OR = {
				has_trait_in_council = { TRAIT = leader_trait_expertise_particles }
				has_trait_in_council = { TRAIT = leader_trait_curator }
				has_trait_in_council = { TRAIT = leader_trait_spark_of_genius }
				has_trait_in_council = { TRAIT = leader_trait_spark_of_genius_2 }
				has_trait_in_council = { TRAIT = leader_trait_maniacal }
				has_trait_in_council = { TRAIT = leader_trait_maniacal_2 }
				has_trait_in_council = { TRAIT = leader_trait_maniacal_3 }
			}
		}
	}

	ai_weight = {
		weight = @tier5weight3
	}
}

tech_planetmega_nirvana = {
	area = engineering
	cost = @pmtech_tier5cost4
	tier = @fallentechtier
	is_rare = yes
	category = { industry }
	prerequisites = { "tech_planetmega_improved" "tech_fe_affluence_2" "tech_fe_forge_2" }
	potential = { is_wilderness_empire = no }
	weight = @pmtech_tier6weight1
	weight_modifier = {
		inline_script = {
			script = technologies/rare_technologies_weight_modifiers
			TECHNOLOGY = tech_planetmega_nirvana
		}
	}
	prereqfor_desc = {
		custom = {
			title = "TECH_PLANETMEGA_NIRVANA_EXTRA_TITLE"
			desc = "TECH_PLANETMEGA_NIRVANA_EXTRA_DESC"
		}
	}
	modifier = {
		country_alloys_produces_mult = 0.01
		country_consumer_goods_produces_mult = 0.01
	}
	ai_weight = {
		weight = @tier5weight3
		inline_script = {
			script = technologies/rare_technologies_weight_modifiers
			TECHNOLOGY = tech_planetmega_nirvana
		}
	}
}

tech_planetmega_transfer_prereq = {
	cost = @pmtech_tier5cost4
	area = physics
	category = { particles }
	tier = 5
	icon = tech_planetmega_transfer
	prerequisites = {
		tech_planetmega_improved
		tech_hyper_relays
		or = {
			tech_jump_drive_1
			tech_psi_jump_drive_1
		}
	}
	potential = { is_wilderness_empire = no }

	weight = @tier5weight3
	weight_modifier = {
		inline_script = {
			script = technologies/tech_t2base_plnmg_weight_modifiers
			TECH = tech_planetmega_transfer_prereq
		}
		modifier = {
			factor = @ap_grasp_the_void_travel_tech
			has_ascension_perk = ap_grasp_the_void
		}
		modifier = {
			factor = @eager_explorer_effect
			is_eager_explorer_empire = yes
		}
		modifier = {
			factor = 2.5
			any_neighbor_country = { has_technology = tech_planetmega_transfer }
		}
	}

	modifier = {
		ship_winddown_mult = -0.05
		ship_windup_mult = -0.05
	}

	ai_weight = {
		weight = @tier5weight3
		inline_script = {
			script = technologies/tech_t2base_plnmg_weight_modifiers
			TECH = tech_planetmega_transfer_prereq
		}
		modifier = {
			mult = 2.5
			any_neighbor_country = { has_technology = tech_planetmega_transfer }
		}
	}
}

tech_planetmega_space_opt = {
	icon = tech_ground_megastructure #temp
	area = engineering
	cost = 30000
	tier = @fallentechtier
	is_rare = yes
	category = { industry }
	prerequisites = { tech_planetmega_improved }
	weight = @pmtech_tier6weight1
	weight_modifier = {
		inline_script = {
			script = technologies/rare_technologies_weight_modifiers
			TECHNOLOGY = tech_planetmega_space_opt
		}
	}

	# prereqfor_desc = {
	# 	feature = {
	# 		title = "TECH_PLANETMEGA_SPACE_OPT_EXTRA_TITLE"
	# 		desc = "TECH_PLANETMEGA_SPACE_OPT_EXTRA_DESC"
	# 	}
	# }
    modifier = {
        planetmega_space_need_mult = -0.05
        planetmega_space_need_artificial_mult = -0.5
        planetmega_space_need_ecu_mult = -0.35
    }
}

tech_planetmega_habitat_opt_2 = {
    cost = 35000
    area = engineering
    category = { industry }
    icon = tech_ground_megastructure
    tier = @fallentechtier
    prerequisites = { "tech_planetmega_improved" "tech_habitat_3" "tech_planetmega_habitat_opt" }
    potential = {
		or = {
			has_void_dweller_origin = yes
			is_nomadic = yes
		}
	}
    weight = @pmtech_tier6weight1
    is_rare = yes

    weight_modifier = {
        inline_script = {
            script = technologies/rare_technologies_weight_modifiers
            TECHNOLOGY = tech_planetmega_habitat_opt_2
        }
    }

    modifier = {
        habitat_max_districts_add = 2
        planetmega_owned_limit_habitat_add = 1
    }

	technology_swap = {
		name = tech_planetmega_arkship_opt_2
		inherit_icon = yes
		inherit_effects = no
		trigger = { is_nomadic = yes }
		modifier = {
			#arkship_max_districts_add = 1
			planetmega_owned_limit_arkship_add = 1
		}
	}

    ai_weight = { weight = @tier5weight3 }
}

tech_planetmega_ringworld_opt = {
	cost = 30000
	area = engineering
	category = { industry }
	icon = tech_ground_megastructure
	tier = @fallentechtier
	prerequisites = { "tech_planetmega_improved" "tech_ring_world" }
	weight = @tier5weight3
	is_rare = yes
	potential = { is_nomadic = no }

	levels = 3
	cost_per_level = @tier4cost2
	# weight_groups = { repeatable }
	# mod_weight_if_group_picked = { repeatable = 0.1 }

	weight_modifier = {
		inline_script = {
			script = technologies/rare_technologies_weight_modifiers
			TECHNOLOGY = tech_planetmega_ringworld_opt
		}
		modifier = {
			factor = 1.5
			has_gw_ring_world = yes
		}
		modifier = {
			factor = 5
			any_owned_colony = { planet_is_ring_world_equivalent = yes }
		}
	}

	modifier = {
		#ringworld_max_districts_add = 1
		planetmega_owned_limit_ringworld_add = 1
	}

	ai_weight = { weight = @tier5weight3 }
}

tech_planetmega_financial = {
	icon = tech_fe_market_2
	area = physics
	cost = @tier5cost3
	tier = 5
    weight = @tier5weight3
	is_rare = yes
	category = { computing }
	prerequisites = { "tech_planetmega_improved" }
	potential = {
        #is_fallen_empire = no
		has_technology = tech_galactic_markets
        or = {
            has_technology = tech_fe_market_2
            has_technology = tech_prescient_data_modeling
            is_market_leader = yes
            is_plnmg_galaxy_laeder = yes
        }
    }
	
	prereqfor_desc = {
		custom = {
			title = "TECH_PLANETMEGA_FINANCIAL_EXTRA_TITLE"
			desc = "TECH_PLANETMEGA_FINANCIAL_EXTRA_DESC"
		}
	}

	weight_modifier = {
        modifier = {
            factor = 50
            is_plnmg_gov_financial = yes
        }
        modifier = {
            factor = 100
            wanna_extend_plnmg_financial_influence = yes
        }
		inline_script = {
			script = technologies/rare_technologies_weight_modifiers
			TECHNOLOGY = tech_planetmega_financial
		}
		modifier = {
			factor = 2.5
			any_spynetwork = { has_espionage_asset = asset_economist }
		}
		modifier = {
			factor = 1.5
			is_rival_superior_in_category = { CATEGORY = economy }
		}
		modifier = {
            factor = 0
            or = {
                has_civic = civic_fanatic_purifiers
                has_civic = civic_dystopian_society
                has_civic = civic_selective_kinship
                has_civic = civic_inwards_perfection
                has_civic = civic_barbaric_despoilers
            }
        }
	}

	ai_weight = { weight = 0 }
}

### advanced planetmega techs ###

tech_planetmega_advanced = {
	icon = tech_ground_megastructure
	cost = {
		factor = @pmtech_tier6cost1
		modifier = {
			event_target:global_event_country = { is_variable_set = tech_costs_scale_compensation_mult }
			factor = event_target:global_event_country.tech_costs_scale_compensation_mult
		}
	}
	area = engineering
	is_rare = yes
	category = { industry }
	tier = 5
	prerequisites = { tech_planetmega_improved tech_mega_engineering }
	weight = @pmtech_tier6weight3 #@pmtech_tier6weight3
	potential = {
		or = {
			has_ascension_perk = ap_planetmega_advanced
			has_country_flag = as_planetmega_advanced
		}
		not = { has_global_flag = planetmega_advanced_banned }
	}

	prereqfor_desc = {
		custom = {
			title = "TECH_PLANETMEGA_ADVANCED_EXTRA_TITLE"
			desc = "TECH_PLANETMEGA_ADVANCED_EXTRA_DESC"
		}
	}
	modifier = {
		district_planetmega_expansion_max_add = 5
	}

	weight_modifier = {
		inline_script = {
			script = technologies/tech_t3breakthrough_plnmg_weightmod
			TECH = tech_planetmega_advanced
		}
		inline_script = {
			script = technologies/rare_technologies_weight_modifiers
			TECHNOLOGY = tech_planetmega_advanced
		}
	}

	ai_weight = {
		weight = @pmtech_tier6weight1
		inline_script = {
			script = technologies/tech_t3breakthrough_plnmg_weightmod
			TECH = tech_planetmega_advanced
		}
		inline_script = {
			script = technologies/rare_technologies_weight_modifiers
			TECHNOLOGY = tech_planetmega_advanced
		}
	}
}

tech_plnmg_admin_repeatable_2 = {
	icon = tech_planetmega_administration
	cost = @pmtech_tier6cost2
	area = society
	category = { statecraft }
	tier = 5
	prerequisites = {
		#tech_planetmega_advanced
		tech_plnmg_admin_repeatable_1
		tech_planetmega_omnipotence_society
	}
	weight = @pmtech_tier6weight2

	levels = 3
	cost_per_level = @tier5cost2
	# weight_groups = { repeatable }
	# mod_weight_if_group_picked = { repeatable = 0.01 }

	modifier = {
		empire_size_mult = -0.05
		tradition_cost_empire_size_mult = -0.05
		planetmega_admin_limit_add = 1
		divided_patrongage_max_subjects = 1
	}
	ai_weight = { weight = @pmtech_tier6weight2 }

	technology_swap = {
		name = tech_plnmg_admin_rept_2_ges
        #inherit_name = yes
		inherit_icon = yes
		inherit_effects = no
		trigger = { is_gestalt = yes }
		modifier = {
			empire_size_mult = -0.05
			tradition_cost_empire_size_mult = -0.05
			planetmega_admin_limit_add = 2
			divided_patrongage_max_subjects = 1
		}
	}
}

tech_planetmega_colossus = {
	cost = {
		factor = @pmtech_tier6cost2
		modifier = {
			event_target:global_event_country = { is_variable_set = tech_costs_scale_compensation_mult }
			factor = event_target:global_event_country.tech_costs_scale_compensation_mult
		}
	}
	area = engineering
	is_rare = yes
	is_dangerous = yes
	is_reverse_engineerable = no
	category = { voidcraft }
	tier = 5
	prerequisites = {
		tech_planetmega_advanced
		tech_colossus
		or = {
			tech_jump_drive_1
			tech_psi_jump_drive_1
		}
	}
	weight = @pmtech_tier6weight2

	prereqfor_desc = {
		custom = {
			title = "TECH_PLANETMEGA_COLOSSUS_EXTRA_TITLE"
			desc = "TECH_PLANETMEGA_COLOSSUS_EXTRA_DESC"
		}
	}

	modifier = {
		ship_accuracy_mult = 0.02
		ship_tracking_mult = 0.02
	}

	weight_modifier = {
		inline_script = {
			script = technologies/tech_t3base_plnmg_weight_modifiers
			TECH = tech_planetmega_colossus
		}
		modifier = {
			factor = 2.5
			or = {
				has_menace_perk = menp_undertaker
				has_ascension_perk = ap_galactic_contender
			}
		}
		inline_script = technologies/tech_plnmg_cosmogenesis_factor
	}

	ai_weight = {
		factor = @pmtech_tier6weight2
		inline_script = {
			script = technologies/tech_t3base_plnmg_weight_modifiers
			TECH = tech_planetmega_colossus
		}
	}
}

tech_planetmega_aeg_weapon = {
	icon = tech_planetmega_colossus
	cost = {
		factor = 44000 #90000
		modifier = {
			event_target:global_event_country = { is_variable_set = tech_costs_scale_compensation_mult }
			factor = event_target:global_event_country.tech_costs_scale_compensation_mult
		}
	}
	area = engineering
	is_rare = yes
	is_dangerous = yes
	is_reverse_engineerable = no
	category = { voidcraft }
	tier = 5
	prerequisites = { tech_planetmega_colossus }
	weight = @pmtech_tier6weight3

	modifier = {
		ship_accuracy_mult = 0.05
		ship_tracking_mult = 0.05
	}

	weight_modifier = {
		inline_script = {
			script = technologies/tech_t3base_plnmg_weight_modifiers
			TECH = tech_planetmega_aeg_weapon
		}
		modifier = {
			factor = 3.5
			or = {
				has_menace_perk = menp_undertaker
				has_ascension_perk = ap_galactic_contender
			}
		}
	}

	#ai_update_type = military
	ai_weight = { weight = 0 }
}

tech_planetmega_aeg_utility = {
	icon = tech_planetmega_colossus
	cost = {
		factor = 44000 #90000
		modifier = {
			event_target:global_event_country = { is_variable_set = tech_costs_scale_compensation_mult }
			factor = event_target:global_event_country.tech_costs_scale_compensation_mult
		}
	}
	area = engineering
	is_rare = yes
	#is_dangerous = yes
	is_reverse_engineerable = no
	category = { voidcraft }
	tier = 5
	prerequisites = {
		tech_planetmega_colossus
		tech_planetmega_active_defense
	}
	weight = @pmtech_tier6weight3

	modifier = {
		ship_reactor_power_mult = 0.05
		ship_windup_mult = -0.05
		ship_jumpdrive_cooldown_mult = -0.05
	}

	weight_modifier = {
		inline_script = {
			script = technologies/tech_t3base_plnmg_weight_modifiers
			TECH = tech_planetmega_aeg_utility
		}
		modifier = {
			factor = 3.5
			or = {
				has_menace_perk = menp_undertaker
				has_ascension_perk = ap_galactic_contender
			}
		}
	}

	#ai_update_type = all
	ai_weight = { weight = 0 }
}

tech_plnmg_nano_field_cntr = {
	cost = {
		factor = @pmtech_tier6cost3
		modifier = {
			event_target:global_event_country = { is_variable_set = tech_costs_scale_compensation_mult }
			factor = event_target:global_event_country.tech_costs_scale_compensation_mult
		}
	}
	area = physics
	tier = 5
	is_rare = yes
	icon = tech_nanite_repair_system_synth_queen
	category = { particles }
	prerequisites = { "tech_planetmega_advanced" }
	potential = { is_nomadic = no }
	weight = @pmtech_tier6weight2
	weight_modifier = {
		inline_script = {
			script = technologies/tech_t3base_plnmg_weight_modifiers
			TECH = tech_plnmg_nano_field_cntr
		}
		inline_script = technologies/tech_plnmg_cosmogenesis_factor
		modifier = {
			factor = 0
			nor = {
				has_planetmega_nanotech = yes
				# synth queen
				has_country_flag = protected_from_queen_storm
				has_country_flag = synth_queen_can_raid_outposts
				has_technology = tech_nanite_repair_system_synth_queen
				has_technology = tech_synth_queen_knowledge
				has_modifier = synth_queen_nanite_apprentice
				# common techs
				has_technology = tech_nanite_repair_system
				has_technology = tech_nanite_transmutation
				has_technology = tech_nanite_autocannon
				has_technology = tech_nanite_flak_batteries
			}
		}
	}

	prereqfor_desc = {
		custom = {
			title = "TECH_PLNMG_NANO_FIELD_CNTR_EXTRA_TITLE"
			desc = "TECH_PLNMG_NANO_FIELD_CNTR_EXTRA_DESC"
		}
	}
	ai_weight = {
		weight = @pmtech_tier6weight2
		inline_script = {
			script = technologies/tech_t3base_plnmg_weight_modifiers
			TECH = tech_plnmg_nano_field_cntr
		}
	}
}

tech_planetmega_transfer = {
	cost = {
		factor = @pmtech_tier6cost2
		modifier = {
			event_target:global_event_country = { is_variable_set = tech_costs_scale_compensation_mult }
			factor = event_target:global_event_country.tech_costs_scale_compensation_mult
		}
	}
	area = engineering
	is_rare = yes
	is_dangerous = yes
	category = { voidcraft }
	tier = 5
	prerequisites = { "tech_planetmega_advanced" "tech_planetmega_transfer_prereq" }
	potential = { is_wilderness_empire = no }
	weight = @pmtech_tier6weight2
	weight_modifier = {
		inline_script = {
			script = technologies/tech_t3base_plnmg_weight_modifiers
			TECH = tech_planetmega_transfer
		}
		modifier = {
			factor = @ap_grasp_the_void_travel_tech
			has_ascension_perk = ap_grasp_the_void
		}
		modifier = {
			factor = @eager_explorer_effect
			is_eager_explorer_empire = yes
		}
	}

    prereqfor_desc = {
        custom = {
            title = TECH_PLANETMEGA_TRANSFER_EXTRA_TITLE
            desc = TECH_PLANETMEGA_TRANSFER_EXTRA_DESC
        }
    }

	modifier = {
		ship_evasion_mult = 0.05
        ship_windup_mult = -0.05
        ship_winddown_mult = -0.1
	}

	ai_weight = {
		weight = @pmtech_tier6weight2
		inline_script = {
			script = technologies/tech_t3base_plnmg_weight_modifiers
			TECH = tech_planetmega_transfer
		}
	}
}

tech_planetmega_omnipotence_physics = {
	cost = {
		factor = @pmtech_tier6cost4
		modifier = {
			event_target:global_event_country = { is_variable_set = tech_costs_scale_compensation_mult }
			factor = event_target:global_event_country.tech_costs_scale_compensation_mult
		}
		modifier = {
			is_variable_set = var_plnmg_adv_tech_mult
			factor = var_plnmg_adv_tech_mult
		}
	}
	weight = @pmtech_tier6weight3
	area = physics
	is_rare = yes
	category = { field_manipulation }
	icon = tech_planetmega_omnipotence
	tier = 5
	prerequisites = { tech_planetmega_advanced tech_planetmega_singularity }
	potential = { is_wilderness_empire = no }
	prereqfor_desc = {
		custom = {
			title = TECH_PLANETMEGA_OMNIPOTENCE_EXTRA_TITLE
			desc = TECH_PLANETMEGA_OMNIPOTENCE_EXTRA_DESC
		}
	}
	ai_weight = { weight = @pmtech_tier7weight1 }
}
tech_planetmega_omnipotence_society = {
	cost = {
		factor = @pmtech_tier6cost4
		modifier = {
			event_target:global_event_country = { is_variable_set = tech_costs_scale_compensation_mult }
			factor = event_target:global_event_country.tech_costs_scale_compensation_mult
		}
		modifier = {
			is_variable_set = var_plnmg_adv_tech_mult
			factor = var_plnmg_adv_tech_mult
		}
	}
	weight = @pmtech_tier6weight3
	area = society
	is_rare = yes
	category = { biology }
	icon = tech_planetmega_omnipotence
	tier = 5
	prerequisites = { tech_planetmega_advanced tech_planetmega_junik }
	potential = {
		is_ai = no
        is_wilderness_empire = no
    }
	prereqfor_desc = {
		custom = {
			title = TECH_PLANETMEGA_OMNIPOTENCE_EXTRA_TITLE
			desc = TECH_PLANETMEGA_OMNIPOTENCE_EXTRA_DESC
		}
	}
	ai_weight = { weight = 0 } # AI will not get heart
}
tech_planetmega_omnipotence_engineering = {
	cost = {
		factor = @pmtech_tier6cost4
		modifier = {
			event_target:global_event_country = { is_variable_set = tech_costs_scale_compensation_mult }
			factor = event_target:global_event_country.tech_costs_scale_compensation_mult
		}
		modifier = {
			is_variable_set = var_plnmg_adv_tech_mult
			factor = var_plnmg_adv_tech_mult
		}
	}
	weight = @pmtech_tier6weight3
	area = engineering
	is_rare = yes
	category = { materials }
	icon = tech_planetmega_omnipotence
	tier = 5
	prerequisites = { tech_planetmega_advanced tech_planetmega_nirvana }
	prereqfor_desc = {
		custom = {
			title = TECH_PLANETMEGA_OMNIPOTENCE_EXTRA_TITLE
			desc = TECH_PLANETMEGA_OMNIPOTENCE_EXTRA_DESC
		}
	}
	ai_weight = { weight = @pmtech_tier7weight1 }

	technology_swap = {
		name = tech_plnmg_omni_engineering_wilderness
		inherit_icon = yes
		inherit_effects = no
		trigger = { is_wilderness_empire = yes }
		weight = { factor = 1 }
	}
}

tech_plnmg_interthought_plus = {
	icon = tech_plnmg_interthought
	area = physics
	tier = 5
	is_rare = yes
	category = { computing }
	cost = {
		factor = @pmtech_tier6cost4
		modifier = {
			event_target:global_event_country = { is_variable_set = tech_costs_scale_compensation_mult }
			factor = event_target:global_event_country.tech_costs_scale_compensation_mult
		}
		modifier = {
			is_variable_set = var_plnmg_adv_tech_mult
			factor = var_plnmg_adv_tech_mult
		}
	}
	weight = @pmtech_tier6weight2
	prerequisites = { tech_planetmega_advanced tech_plnmg_interthought }
	# prereqfor_desc = {
	# 	feature = {
	# 		title = TECH_PLNMG_INTERTHOUGHT_PLUS_EXTRA_TITLE
	# 		desc = TECH_PLNMG_INTERTHOUGHT_PLUS_EXTRA_DESC
	# 	}
	# }
	weight_modifier = {
		inline_script = {
			script = technologies/tech_t3base_plnmg_weight_modifiers
			TECH = tech_plnmg_interthought_plus
		}
		inline_script = {
			script = technologies/rare_technologies_weight_modifiers
			TECHNOLOGY = tech_plnmg_interthought_plus
		}
		# modifier = {
		# 	factor = 0
		# 	not = {
		# 		any_owned_colony = {
		# 			or = {
		# 				has_deposit = d_plnmg_supercom
		# 				has_deposit = d_plnmg_fusion_brain
		# 			}
		# 		}
		# 	}
		# }
		modifier = {
			factor = 0
			nor = {
				has_tradition = tr_virtuality_finish
				and = {
					has_technology = tech_planetmega_omnipotence_physics
					has_technology = tech_planetmega_omnipotence_engineering
					has_technology = tech_planetmega_omnipotence_society
				}
			}
		}
	}
	ai_weight = {
		weight = @pmtech_tier6weight2
		inline_script = {
			script = technologies/tech_t3base_plnmg_weight_modifiers
			TECH = tech_plnmg_interthought_plus
		}
		inline_script = {
			script = technologies/rare_technologies_weight_modifiers
			TECHNOLOGY = tech_plnmg_interthought_plus
		}
	}
}

tech_plnmg_ship_space_extension = {
	area = physics
	tier = 5
	is_rare = yes
	is_dangerous = yes
	category = { field_manipulation }
	cost = @pmtech_tier6cost4
	prerequisites = { tech_planetmega_advanced tech_planetmega_active_defense }
	weight = @pmtech_tier6weight3
	weight_modifier = {
		inline_script = {
			script = technologies/tech_t3base_plnmg_weight_modifiers
			TECH = tech_plnmg_ship_space_extension
		}
	}
	#ai_update_type = military
	ai_weight = { weight = 0 }
}

### ultimate planetmega techs ###

tech_planetmega_ultimate = {
	icon = tech_ground_megastructure
	cost = {
		factor = @pmtech_tier7cost1
		modifier = {
			event_target:global_event_country = { is_variable_set = tech_costs_scale_compensation_mult }
			factor = event_target:global_event_country.tech_costs_scale_compensation_mult
		}
		modifier = {
			is_variable_set = var_plnmg_ult_tech_mult
			factor = var_plnmg_ult_tech_mult
		}
	}
	weight = 0
	area = physics
	is_rare = yes
	is_dangerous = yes
	category = { computing }
	tier = 5
	potential = { has_country_flag = planetmega_1000_triggered }
	prereqfor_desc = {
		custom = {
			title = TECH_PLANETMEGA_ULTIMATE_EXTRA_TITLE
			desc = TECH_PLANETMEGA_ULTIMATE_EXTRA_DESC
		}
	}
	# weight_modifier = {
	# 	modifier = {
	# 		add = 1
	# 		any_neighbor_country = { has_technology = tech_planetmega_ultimate }
	# 	}
	# }
	ai_weight = { weight = 0 }
}

tech_planetmega_ultimate_sp = {
	icon = tech_ground_megastructure
	cost = {
		factor = @pmtech_tier7cost1
		modifier = {
			event_target:global_event_country = { is_variable_set = tech_costs_scale_compensation_mult }
			factor = event_target:global_event_country.tech_costs_scale_compensation_mult
		}
		modifier = {
			is_variable_set = var_plnmg_ult_tech_mult
			factor = var_plnmg_ult_tech_mult
		}
	}
	weight = @pmtech_tier7weight1
	area = engineering
	is_rare = yes
	category = { industry }
	tier = 5
	potential = { has_country_flag = planetmega_ultimate_enabled }
	prerequisites = { tech_planetmega_ultimate }
	prereqfor_desc = {
		custom = {
			title = TECH_PLANETMEGA_ULTIMATE_SP_EXTRA_TITLE
			desc = TECH_PLANETMEGA_ULTIMATE_SP_EXTRA_DESC
		}
	}
	weight_modifier = {
		modifier = {
			add = 1
			any_plnmg_neighbor_has_tech = { TECH = tech_planetmega_ultimate_sp }
		}
	}
	ai_weight = { weight = 0 }
}

tech_planetmega_reincarnation = {
	icon = tech_cosmogenesis_world
	cost = {
		factor = @pmtech_tier7cost2
		modifier = {
			event_target:global_event_country = { is_variable_set = tech_costs_scale_compensation_mult }
			factor = event_target:global_event_country.tech_costs_scale_compensation_mult
		}
		modifier = {
			is_variable_set = var_plnmg_ult_tech_mult
			factor = var_plnmg_ult_tech_mult
		}
	}
	weight = @pmtech_tier7weight1
	area = society
	is_rare = yes
	category = { industry }
	tier = 5
	prerequisites = { tech_planetmega_ultimate_sp }
	potential = { is_ai = no } # just in case
	weight_modifier = {
		inline_script = {
			script = technologies/tech_t4_plnmg_weight_modifiers
			TECH = tech_planetmega_reincarnation
		}
	}
	##ai_update_type = all
	ai_weight = { weight = 0 }
}

tech_planetmega_realedit = {
	icon = old_tech_icons/tech_physics_lab_5 #temp
	cost = {
		factor = @pmtech_tier7cost3
		modifier = {
			event_target:global_event_country = { is_variable_set = tech_costs_scale_compensation_mult }
			factor = event_target:global_event_country.tech_costs_scale_compensation_mult
		}
		modifier = {
			is_variable_set = var_plnmg_ult_tech_mult
			factor = var_plnmg_ult_tech_mult
		}
	}
	weight = @pmtech_tier7weight1
	area = engineering
	is_rare = yes
	is_dangerous = yes
	category = { industry }
	tier = 5
	prerequisites = { tech_planetmega_ultimate_sp }
	weight_modifier = {
		inline_script = {
			script = technologies/tech_t4_plnmg_weight_modifiers
			TECH = tech_planetmega_realedit
		}
	}
	ai_weight = { weight = 0 }
}
