namespace = planetmega

#总括
carrier_event = {
	id = planetmega.4
	title = planetmega.4.name
	desc = planetmega.4.desc
	picture = GFX_evt_designing_engineers
	is_triggered_only = yes
	location = root
    trigger = { owner? = { is_ai = no } }

	option = {
		name = planetmega_tier1
		allow = {
			if = {
				limit = { hidden_trigger = { owner = { has_plnmg_virtual_jobs = no } } }
				pop_amount >= @plnmg_base_pops
			}
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_t1_space = yes
			}
			owner = {
				resource_stockpile_compare = {
					resource = influence
					value >= @plnmg_influence_t1
					mult = value:scripted_modifier_mult|MODIFIER|country_influence_cost_mult|
				}
			}
		}
		hidden_effect = { carrier_event = { id = planetmega.1 } }
		owner = {
			add_resource = {
				influence = @plnmg_influence_t1
				mult = value:planetmega_modifier_negative_mult|MODIFIER|country_influence_cost_mult|
			}
		}
        ai_chance = { weight = 0 }
	}

	option = {
		name = planetmega_tier2
		trigger = { owner = { has_technology = tech_planetmega_improved } }
		allow = {
			if = {
				limit = { hidden_trigger = { owner = { has_plnmg_virtual_jobs = no } } }
				pop_amount >= @plnmg_more_pops
			}
			owner = {
				resource_stockpile_compare = {
					resource = influence
					value >= @plnmg_influence_t2
					mult = value:scripted_modifier_mult|MODIFIER|country_influence_cost_mult|
				}
			}
		}
		hidden_effect = { carrier_event = { id = planetmega.2 } }
		owner = {
			add_resource = {
				influence = @plnmg_influence_t2
				mult = value:planetmega_modifier_negative_mult|MODIFIER|country_influence_cost_mult|
			}
		}
        ai_chance = { weight = 0 }
	}

	option = {
		name = planetmega_tier3
		trigger = { owner = { has_technology = tech_planetmega_advanced } }
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = influence
					value >= @plnmg_influence_t3
					mult = value:scripted_modifier_mult|MODIFIER|country_influence_cost_mult|
				}
			}
		}
		hidden_effect = { carrier_event = { id = planetmega.3 } }
		owner = {
			add_resource = {
				influence = @plnmg_influence_t3
				mult = value:planetmega_modifier_negative_mult|MODIFIER|country_influence_cost_mult|
			}
		}
		ai_chance = { weight = 0 }
	}

	option = {
		name = planetmega.32.name
		trigger = { owner = { is_wilderness_empire = yes } }
		icon = { icon = GFX_wilderness_event_icon }
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = influence
					value >= @plnmg_influence_t1
					mult = value:scripted_modifier_mult|MODIFIER|country_influence_cost_mult|
				}
			}
		}
		hidden_effect = { carrier_event = { id = planetmega.32 } }
		owner = {
			add_resource = {
				influence = @plnmg_influence_t1
				mult = value:planetmega_modifier_negative_mult|MODIFIER|country_influence_cost_mult|
			}
		}
        ai_chance = { weight = 0 }
	}

	option = {
		name = planetmega.1.zzz
		# custom_tooltip = planetmega.1.zzz.desc
		default_hide_option = yes
		hidden_effect = { remove_carrier_flag = planet_has_plnmg_megabuild_listed }
		ai_chance = { weight = 1 }
	}
}

# 建造TIER1
carrier_event = {
	id = planetmega.1
	title = planetmega.1.name
	desc = planetmega.1.desc
	picture = GFX_evt_designing_engineers
	is_triggered_only = yes
	location = root
	trigger = { exists = owner }
	immediate = {
		initialize_plnmg_limit_sys_planet = yes
		decide_planetmega_building_leader = yes
	}
	diplomatic = yes
	diplomatic_title = planetmega.4.name
	picture_event_data = {
		room = owner_main_species # swappable for leader (species)
		portrait = event_target:planetmega_building_leader # this will use GIF, but I am still searching
		planet_background = carrier
		graphical_culture = owner
		city_level = owner
	}

	option = {
		name = planetmega.1.lab
		custom_tooltip = build_great_laboratory_desc
		trigger = {
			has_plnmg_any_lab = no
			is_building_plnmg_any_lab = no
			owner = { has_technology = tech_basic_science_lab_2 }
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
			}
			is_special_colony_type = no
			# if = {
			# 	limit = { hidden_trigger = { owner = { is_wilderness_empire = yes } } }
			# 	or = {
			# 		# has_building = building_brain_node_1
			# 		# has_building = building_brain_node_2
			# 		has_building = building_brain_node_3
			# 		has_building = building_brain_node_4
			# 	}
			# }
			owner = {
				has_technology = tech_basic_science_lab_3
				or = {
					has_technology = tech_global_research_initiative #wilderness can not research this
					has_technology = tech_space_science_5
				}
			}
		}
		owner = {
			start_situation = {
				type = planet_megastructure_construction
				target = root
				effect = { set_situation_flag = building_great_laboratory }
			}
		}
	}

	option = {
		name = planetmega.1.forge
		custom_tooltip = build_advanced_forge_desc
		trigger = {
			has_plnmg_any_forge = no
			is_building_plnmg_any_forge = no
			owner = {
				has_technology = tech_alloys_2
				is_wilderness_empire = no
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
			}
			not = { has_modifier = resort_colony }
			owner = { has_technology = tech_advanced_metallurgy_2 }
		}
		owner = {
			start_situation = {
				type = planet_megastructure_construction
				target = root
				effect = { set_situation_flag = building_advanced_forge }
			}
		}
	}

	option = {
		name = planetmega.1.heaven
		custom_tooltip = build_heaven_colossal_desc
		trigger = {
			has_plnmg_any_heaven = no
			not = { any_targeting_situation = { has_situation_flag = building_heaven_colossal } }
			owner = {
				is_gestalt = no
				# is_spiritualist = no # kept for future use
				has_technology = tech_heritage_site
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
			}
			NOR = {
				has_modifier = slave_colony
				has_modifier = penal_colony
			}
			owner = {
				has_technology = tech_hyper_entertainment_forum
				has_technology = tech_hypercomms_forum
			}
		}
		owner = {
			start_situation = {
				type = planet_megastructure_construction
				target = root
				effect = { set_situation_flag = building_heaven_colossal }
			}
		}
	}
    option = {
        name = d_hakkou_ichiu_tower
        custom_tooltip = build_hakkou_ichiu_desc
        trigger = {
            has_plnmg_any_militarist_tower = no
            not = { any_targeting_situation = { has_situation_flag = building_hakkou_ichiu_tower } }
            owner = { can_build_hakkou_ichiu_tower = yes }
        }
        allow = {
            if = {
                limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
                check_plnmg_build_reach_limit = yes
            }
            NOR = {
                has_modifier = slave_colony
                has_modifier = penal_colony
            }
            owner = {
                has_technology = tech_hypercomms_forum
                if = {
                    limit = { is_spiritualist = yes }
                    has_technology = tech_consecration_fields
                }
            }
        }
        owner = {
            start_situation = {
                type = planet_megastructure_construction
                target = root
                effect = { set_situation_flag = building_hakkou_ichiu_tower }
            }
        }
    }

	option = {
		name = planetmega.1.power
		custom_tooltip = build_giant_power_battery_desc
		trigger = {
			has_plnmg_any_generator = no
			is_building_plnmg_any_generator = no
			owner = {
				has_technology = tech_power_plant_3
				has_technology = tech_power_hub_1
				is_wilderness_empire = no
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
			}
			not = { has_modifier = resort_colony }
			owner = {
				has_technology = tech_power_hub_2
				has_technology = tech_power_plant_4
			}
		}
		owner = {
			start_situation = {
				type = planet_megastructure_construction
				target = root
				effect = { set_situation_flag = building_giant_power_battery }
			}
		}
	}

	option = {
		name = planetmega.1.factory 
		custom_tooltip = build_centralized_manufactory_desc
		trigger = {
			has_plnmg_any_factory = no
			is_building_plnmg_any_factory = no
			owner = {
				OR = {
					country_uses_consumer_goods = yes
					has_civic = civic_machine_obsessional_directive
					has_country_flag = need_goods_stockpile # I'd wonder how many modder will use it
				}
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
			}
			nor = {
				has_modifier = resort_colony
				has_modifier = pm_wenkwort_custodian
			}
			owner = {
				if = {
					limit = {
						hidden_trigger = {
							nor = {
								has_civic = civic_machine_obsessional_directive
								has_country_flag = need_goods_production_but_not_using
							}
						}
					}
					has_technology = tech_consumer_good_refinement_2
				}
			}
		}
		owner = {
			start_situation = {
				type = planet_megastructure_construction
				target = root
				effect = { set_situation_flag = building_centralized_manufactory }
			}
		}
	}

	option = {
		name = planetmega.1.demodulator
		custom_tooltip = build_matter_demodulator_desc
		trigger = {
			carrier_is_type = planet
			has_plnmg_any_mine = no
			is_building_plnmg_any_mine = no
			owner = {
				has_technology = tech_mining_2
				has_technology = tech_mineral_purification_1
				is_wilderness_empire = no
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
			}
			nor = {
				has_modifier = resort_colony
				has_modifier = pm_wenkwort_custodian
			}
			owner = {
				has_technology = tech_mining_3
				has_technology = tech_mineral_purification_2
			}
		}
		owner = {
			start_situation = {
				type = planet_megastructure_construction
				target = root
				effect = { set_situation_flag = building_matter_demodulator }
			}
		}
	}

	option = {
		name = planetmega.1.farm
		custom_tooltip = build_vertical_farm_edifice_desc
		trigger = {
			has_plnmg_any_farm = no
			is_building_plnmg_any_farm = no
			owner = {
				country_uses_food = yes
				is_hive_empire = no
				has_technology = tech_food_processing_1
				has_technology = tech_gene_crops
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
			}
			not = { has_modifier = resort_colony }
			owner = {
				has_technology = tech_nano_vitality_crops
				has_technology = tech_food_processing_2
				# tech_nutrient_replication reserved for adding buffs
			}
		}
		owner = {
			start_situation = {
				type = planet_megastructure_construction
				target = root
				effect = { set_situation_flag = building_vertical_farm_edifice }
			}
		}
	}

	option = {
		name = planetmega.1.farm_hive
		custom_tooltip = build_hive_farm_edifice_desc
		trigger = {
			has_plnmg_any_farm = no
			is_building_plnmg_any_farm = no
			owner = {
				country_uses_food = yes
				is_hive_empire = yes
				#is_wilderness_empire = no
				has_technology = tech_food_processing_1
				if = {
                    limit = { is_wilderness_empire = no }
                    has_technology = tech_gene_crops
                }
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
			}
			#not = { has_modifier = gestation_colony }
			owner = {
				#has_technology = tech_nano_vitality_crops
				has_technology = tech_food_processing_2
				# tech_nutrient_replication preserved for adding buffs
			}
		}
		owner = {
			start_situation = {
				type = planet_megastructure_construction
				target = root
				effect = { set_situation_flag = building_hive_farm_edifice }
			}
		}
	}

	option = {
		name = planetmega.1.commercial
		custom_tooltip = build_commercial_shikara_desc
		trigger = {
			has_plnmg_any_commerce = no
			not = { any_targeting_situation = { has_situation_flag = building_commercial_shikara } }
			owner = {
				is_gestalt = no
				has_technology = tech_interstellar_economics
				has_technology = tech_consumer_good_refinement_1
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
			}
			NOR = {
				has_modifier = slave_colony
				has_modifier = penal_colony
			}
			owner = {
				has_technology = tech_galactic_markets
				#has_technology = tech_consumer_good_refinement_2
			}
		}
		owner = {
			start_situation = {
				type = planet_megastructure_construction
				target = root
				effect = { set_situation_flag = building_commercial_shikara }
			}
		}
	}
	option = {
		name = d_logistics_shikara
		custom_tooltip = build_logistics_shikara_desc
		trigger = {
			has_plnmg_any_commerce = no
			not = { any_targeting_situation = { has_situation_flag = building_logistics_shikara } }
			owner = {
				is_gestalt = yes
				is_wilderness_empire = no
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
			}
			#NOT = { has_modifier = gestation_colony }
			solar_system = {
				or = {
					is_capital_system = yes
					custom_tooltip = {
						fail_text = IS_NOT_SECTOR_CAPITAL_SYSTEM
						success_text = IS_SECTOR_CAPITAL_SYSTEM
						exists = sector
						any_system_planet_colony = { is_same_value = sector.sector_capital }
					}
					is_bridge = yes #set in map\setup_scenarios\
					is_bottleneck_system = yes
					custom_tooltip = {
						fail_text = requires_existing_gateway
						success_text = requires_existing_gateway
						or = {
							has_megastructure = gateway_final
							has_megastructure = gateway_restored
						}
					}
					custom_tooltip = {
						fail_text = requires_lgate_nexus
						success_text = requires_lgate_nexus
						has_megastructure = lgate_base
						has_star_flag = lcluster1
					}
					if = {
						limit = { owner = { has_origin = origin_shroudwalker_apprentice } }
						custom_tooltip = {
							fail_text = requires_shroud_tunnel_nexus
							success_text = requires_shroud_tunnel_nexus
							has_natural_wormhole = yes
							has_star_flag = shroud_tunnel_nexus
						}
					}
					# if = {
					# 	limit = { owner = { has_ascension_perk = ap_galactic_hyperthermia } }
					# 	custom_tooltip = {
					# 		fail_text = BLANK_STRING #temp
					# 		has_natural_wormhole = yes
					# 		has_star_flag = hyperthermia_nexus
					# 	}
					# }
				}
			}
			is_special_colony_type = no
			#owner = { has_technology = tech_doctrine_navy_size_3 }
		}
		owner = {
			start_situation = {
				type = planet_megastructure_construction
				target = root
				effect = { set_situation_flag = building_logistics_shikara }
			}
		}
	}

	option = {
		name = planetmega.1.headquarter
		custom_tooltip = build_war_headquarter_desc
		trigger = {
			has_plnmg_any_fortress = no
			is_building_plnmg_any_fortress = no
			owner = {
				#is_wilderness_empire = no
				is_hive_empire = no
				has_technology = tech_ground_defense_planning
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
			}
			NOR = {
				has_modifier = penal_colony
				has_modifier = resort_colony
				#has_modifier = gestation_colony
			}
			owner = {
				or = {
					has_technology = tech_planetary_shield_generator
					has_technology = tech_global_defense_grid
				}
			}
		}
		owner = {
			start_situation = {
				type = planet_megastructure_construction
				target = root
				effect = { set_situation_flag = building_war_headquarter }
			}
		}
	}
	option = {
		name = d_resistance_organ
		custom_tooltip = build_resistance_organ_desc
		trigger = {
			has_plnmg_any_fortress = no
			is_building_plnmg_any_fortress = no
			owner = {
				#is_wilderness_empire = yes
				is_hive_empire = yes
				has_technology = tech_ground_defense_planning
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
			}
			#not = { has_modifier = gestation_colony }
			owner = {
				or = {
					has_technology = tech_planetary_shield_generator
					has_technology = tech_global_defense_grid
				}
			}
		}
		owner = {
			if = {
				limit = { is_wilderness_empire = yes }
				start_situation = {
					type = planetmega_wilderness_construction
					target = root
					effect = { set_situation_flag = building_resistance_organ }
				}
			}
			else = {
				start_situation = {
					type = planet_megastructure_construction
					target = root
					effect = { set_situation_flag = building_resistance_organ }
				}
			}
		}
	}

	option = {
		name = planetmega.1.pyramid
		custom_tooltip = build_primary_mind_pyramid_desc
		trigger = {
			has_plnmg_any_pyramid = no
			not = { any_targeting_situation = { has_situation_flag = building_primary_mind_pyramid } }
			owner = {
				is_wilderness_empire = no
				or = {
					and = {
						is_hive_empire = yes
						has_technology = tech_hive_cluster
					}
					and = {
						is_machine_empire = yes
						has_technology = tech_colonial_bureaucracy
						has_technology = tech_heritage_site
					}
				}
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
			}
			or = {
                and = {
                    is_capital = yes
                    hidden_trigger = {
                        owner = { not = { any_owned_colony = { has_carrier_flag = built_capital_pm_admin } } }
                    }
                }
				custom_tooltip = {
					fail_text = sector_plnmg_admin_failed_tt
					success_text = sector_plnmg_admin_success_tt
					owner = {
						count_owned_colony = {
							limit = {
								#is_capital = no
								has_plnmg_any_admin = yes
							}
							count < owner.value:sv_plnmg_admin_limit
						}
					}
				}
			}
			owner = {
				if = {
					limit = { hidden_trigger = { is_hive_empire = yes } }
					has_technology = tech_hive_confluence
				}
				else_if = {
					limit = { hidden_trigger = { is_machine_empire = yes } }
					has_technology = tech_micro_replicators
					has_technology = tech_galactic_bureaucracy
					has_technology = tech_hypercomms_forum
				}
			}
		}
		owner = {
			start_situation = {
				type = planet_megastructure_construction
				target = root
				effect = { set_situation_flag = building_primary_mind_pyramid }
			}
		}
	}

	option = {
		name = planetmega.1.admin
		custom_tooltip = build_admin_axis_desc
		trigger = {
			has_plnmg_any_admin = no
			not = { any_targeting_situation = { has_situation_flag = building_admin_axis } }
			owner = {
				is_gestalt = no
				has_technology = tech_planetmega_administration
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
			}
			or = {
				and = {
                    is_capital = yes
                    hidden_trigger = {
                        owner = { not = { any_owned_colony = { has_carrier_flag = built_capital_pm_admin } } }
                    }
                }
				custom_tooltip = {
					fail_text = sector_plnmg_admin_failed_tt
					success_text = sector_plnmg_admin_success_tt
					owner = {
						count_owned_colony = {
							limit = {
								#is_capital = no
								has_plnmg_any_admin = yes
							}
							count < owner.value:sv_plnmg_admin_limit
						}
					}
				}
			}
			is_special_colony_type = no
		}
		owner = {
			start_situation = {
				type = planet_megastructure_construction
				target = root
				effect = { set_situation_flag = building_admin_axis }
			}
		}
	}

	option = {
		name = d_ecodome_complex
		custom_tooltip = build_ecodome_complex_desc
		trigger = {
			nor = {
				has_deposit = d_ecodome_complex
				has_carrier_flag = planet_has_ecodome_complex
			}
			not = { any_targeting_situation = { has_situation_flag = building_ecodome_complex } }
			owner = {
				is_wilderness_empire = no
				has_technology = tech_housing_1
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
			}
			if = {
				limit = { hidden_trigger = { owner = { is_gestalt = no } } }
				NOR = {
					has_modifier = slave_colony
					has_modifier = penal_colony
				}
			}
			owner = {
				if = {
					limit = { hidden_trigger = { is_machine_empire = yes } }
					has_technology = tech_micro_replicators
				}
				else_if = {
					limit = { hidden_trigger = { is_hive_empire = yes } }
					has_technology = tech_housing_2
				}
				else = { has_technology = tech_paradise_dome }
			}
		}
		owner = {
			start_situation = {
				type = planet_megastructure_construction
				target = root
				effect = { set_situation_flag = building_ecodome_complex }
			}
		}
	}
	
	option = {
        name = planetmega.1.zzz
		# custom_tooltip = planetmega.1.zzz.desc
		default_hide_option = yes
		owner = {
			add_resource = {
				influence = @plnmg_influence_t1
				mult = value:scripted_modifier_mult|MODIFIER|country_influence_cost_mult|
			}
		}
		hidden_effect = { carrier_event = { id = planetmega.4 } }
	}
}

# 建造TIER2
carrier_event = {
	id = planetmega.2
	title = planetmega.2.name
	desc = planetmega.2.desc
	picture = GFX_evt_designing_engineers
	#show_sound = event_mystic_reveal_light
	is_triggered_only = yes
	location = root
	trigger = { exists = owner }
	immediate = {
		initialize_plnmg_limit_sys_planet = yes
		decide_planetmega_building_leader = yes
	}
	diplomatic = yes
	diplomatic_title = planetmega.4.name
	picture_event_data = {
		room = owner_main_species # swappable for leader (species)
		portrait = event_target:planetmega_building_leader # swappable for leader (species) and GIF
		planet_background = carrier
		graphical_culture = owner
		city_level = owner
	}

	option = {
		name = planetmega.3.matter
		custom_tooltip = build_plnmg_singularity_generator_desc
		trigger = {
			nor = {
				has_deposit = d_plnmg_singularity_generator
				has_carrier_flag = planet_has_plnmg_singularity_generator
			}
			not = { any_targeting_situation = { has_situation_flag = building_plnmg_singularity_generator } }
			owner = {
				is_nomadic = no
				is_wilderness_empire = no
				has_technology = tech_mine_dark_matter
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_upgrade_reach_limit = yes
				check_plnmg_1to2_space = yes
			}
			or = {
				has_deposit = d_giant_power_battery
				has_deposit = d_matter_demodulator
			}
			not = { has_modifier = pm_wenkwort_custodian }
			is_special_colony_type = no
			owner = { has_technology = tech_planetmega_singularity }
		}
		owner = {
			start_situation = {
				type = planet_megastructure_upgrading
				target = root
				effect = { set_situation_flag = building_plnmg_singularity_generator }
			}
		}
	}
	option = {
		name = planetmega.3.matter
		trigger = {
			nor = {
				has_deposit = d_plnmg_singularity_generator
				has_carrier_flag = planet_has_plnmg_singularity_generator
			}
			not = { any_targeting_situation = { has_situation_flag = building_plnmg_singularity_generator } }
			owner = {
				or = {
					is_nomadic = yes
					is_wilderness_empire = yes
				}
				has_technology = tech_mine_dark_matter
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
				check_plnmg_t2_space = yes
			}
			owner = { has_technology = tech_planetmega_singularity }
		}
		owner = {
			start_situation = {
				type = planet_megastructure_constimp
				target = root
				effect = { set_situation_flag = building_plnmg_singularity_generator }
			}
		}
	}

	option = {
		name = planetmega.2.bore
		custom_tooltip = build_plnmg_bore_of_the_shroud_desc
		trigger = {
			nor = {
				has_deposit = d_plnmg_bore_of_the_shroud
				has_carrier_flag = planet_has_plnmg_bore_of_the_shroud
			}
			not = { any_targeting_situation = { has_situation_flag = building_plnmg_bore_of_the_shroud } }
			owner = {
				has_technology = tech_mine_zro
				or = {
                    can_access_shroud = yes
                    has_breached_shroud = yes
					if = { #DAP
						limit = { DAP_loaded = yes }
						has_ascension_perk = ap_soul_induction
					}
                }
			}
		}
		allow = {
			#psionic_pop_amount >= 1000
			count_owned_pop_amount = { limit = { is_plnmg_psionic = yes } count >= 1000 }
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
				free_district_slots >= 2
			}
			is_special_colony_type = no
			owner = {
				or = {
					custom_tooltip = {
						fail_text = plnmg_shroud_bore_not_allowed
						has_country_flag = plnmg_shroud_bore_enabled
					}
					has_menace_perk = menp_megastructure
					if = { #DAP
						limit = { hidden_trigger = { DAP_loaded = yes } }
						has_ascension_perk = ap_soul_induction
					}
				}
			}
		}
		owner = {
			start_situation = {
				type = planet_megastructure_constimp
				target = root
				effect = { set_situation_flag = building_plnmg_bore_of_the_shroud }
			}
		}
	}

	option = {
		name = planetmega.3.maginot
		custom_tooltip = upgrade_to_plnmg_maginot_nexus_desc
		trigger = {
			nor = {
				has_deposit = d_plnmg_maginot_nexus
				has_carrier_flag = planet_has_plnmg_maginot_nexus
			}
			is_building_plnmg_any_headquarter = no
			owner = { has_technology = tech_planetmega_active_defense }
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_upgrade_reach_limit = yes
				check_plnmg_1to2_space = yes
			}
			or = {
				has_deposit = d_war_headquarter
				has_deposit = d_resistance_organ
			}
			custom_tooltip = {
				fail_text = requires_orbital_ring
				exists = orbital_defence.starbase
				orbital_defence.starbase = { is_orbital_ring = yes }
			}
			is_special_colony_type = no
		}
		owner = {
			start_situation = {
				type = planet_megastructure_upgrading
				target = root
				effect = { set_situation_flag = building_plnmg_maginot_nexus }
			}
		}
	}

	option = {
		name = planetmega.3.farm2
		custom_tooltip = upgrade_to_plnmg_advanced_agriculture_edifice_desc
		trigger = {
			nor = {
				has_deposit = d_plnmg_advanced_agriculture_edifice
				has_carrier_flag = planet_has_plnmg_advanced_agriculture_edifice
			}
			is_building_plnmg_any_farm = no
			owner = {
				is_hive_empire = no
				has_technology = tech_nutrient_replication
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_upgrade_reach_limit = yes
				check_plnmg_1to2_space = yes
			}
			has_deposit = d_vertical_farm_edifice
			is_special_colony_type = no
			owner = {
				is_planetmega_genetic = yes
				founder_species = { is_robotic_species = no }
			}
		}
		owner = {
			start_situation = {
				type = planet_megastructure_upgrading
				target = root
				effect = { set_situation_flag = building_plnmg_advanced_agriculture_edifice }
			}
		}
	}

	option = {
		name = planetmega.3.farm2_hive
		custom_tooltip = upgrade_to_plnmg_gene_farm_hive_desc
		trigger = {
			nor = {
				has_deposit = d_plnmg_gene_farm_hive
				has_carrier_flag = planet_has_plnmg_gene_farm_hive
			}
			is_building_plnmg_any_farm = no
			owner = {
				is_hive_empire = yes
				#is_wilderness_empire = no
				if = {
                    limit = { is_wilderness_empire = no }
                    #has_technology = tech_nutrient_replication
                    has_technology = tech_nano_vitality_crops
                }
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_upgrade_reach_limit = yes
				check_plnmg_1to2_space = yes
			}
			has_deposit = d_hive_farm_edifice
			#not = { has_modifier = gestation_colony }
			owner = { is_planetmega_genetic = yes }
		}
		owner = {
			start_situation = {
				type = planet_megastructure_upgrading
				target = root
				effect = { set_situation_flag = building_plnmg_gene_farm_hive }
			}
		}
	}

	option = {
		name = planetmega.3.supercom
		custom_tooltip = upgrade_to_plnmg_supercom
		trigger = {
			nor = {
				has_deposit = d_plnmg_supercom
				has_carrier_flag = planet_has_plnmg_supercom
			}
			is_building_plnmg_any_lab = no
			owner = {
				is_hive_empire = no
				has_technology = tech_plnmg_interthought
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_upgrade_reach_limit = yes
				check_plnmg_1to2_space = yes
			}
			has_deposit = d_great_laboratory
			is_special_colony_type = no
		}
		owner = {
			start_situation = {
				type = planet_megastructure_upgrading
				target = root
				effect = { set_situation_flag = building_plnmg_supercom }
			}
		}
	}
	# option = {
	# 	# supercom for machine gestalt (unused)
	# 	name = planetmega.2.supercom
	# 	custom_tooltip = build_plnmg_supercom_desc
	# 	trigger = {
	# 		nor = {
	# 			has_deposit = d_plnmg_supercom
	# 			has_carrier_flag = planet_has_plnmg_supercom
	# 		}
	# 		is_building_plnmg_any_lab = no
	# 		owner = {
	# 			is_machine_empire = yes
	# 			has_technology = tech_plnmg_interthought
	# 		}
	# 	}
	# 	allow = {
	# 		if = {
	# 			limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
	# 			check_plnmg_build_reach_limit = yes
	# 			check_plnmg_t2_space = yes
	# 		}
	# 		has_deposit = d_primary_mind_pyramid
	# 	}
	# 	owner = {
	# 		start_situation = {
	# 			type = planet_megastructure_constimp
	# 			target = root
	# 			effect = { set_situation_flag = building_plnmg_supercom }
	# 		}
	# 	}
	# }

	option = {
		name = planetmega.3.fusion_brain
		custom_tooltip = upgrade_to_plnmg_fusion_brain
		trigger = {
			nor = {
				has_deposit = d_plnmg_fusion_brain
				has_carrier_flag = planet_has_plnmg_fusion_brain
			}
			is_building_plnmg_any_lab = no
			owner = {
				is_hive_empire = yes
				has_technology = tech_plnmg_interthought
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_upgrade_reach_limit = yes
				check_plnmg_1to2_space = yes
			}
			has_deposit = d_great_laboratory
			#not = { has_modifier = gestation_colony }
		}
		owner = {
			start_situation = {
				type = planet_megastructure_upgrading
				target = root
				effect = { set_situation_flag = building_plnmg_fusion_brain }
			}
		}
	}

	option = {
		name = d_plnmg_nirvana_factory
		custom_tooltip = upgrade_to_plnmg_nirvana_factory
		trigger = {
			nor = {
				has_deposit = d_plnmg_nirvana_factory
				has_carrier_flag = planet_has_plnmg_nirvana_factory
			}
			not = { any_targeting_situation = { has_situation_flag = building_plnmg_nirvana_factory } }
			owner = { has_technology = tech_planetmega_nirvana }
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_upgrade_reach_limit = yes
				check_plnmg_1to2_space = yes
			}
			or = {
				has_deposit = d_advanced_forge
				has_deposit = d_centralized_manufactory
			}
			is_special_colony_type = no
		}
		hidden_effect = { carrier_event = { id = planetmega.210 } }
	}

	option = {
		name = d_plnmg_financial_shikara
		custom_tooltip = build_plnmg_financial_shikara_desc
		trigger = {
			nor = {
				has_deposit = d_plnmg_financial_shikara
				has_carrier_flag = planet_has_plnmg_financial_shikara
			}
			not = { any_targeting_situation = { has_situation_flag = building_plnmg_financial_shikara } }
			owner = { has_technology = tech_planetmega_financial }
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_upgrade_reach_limit = yes
				check_plnmg_1to2_space = yes
			}
			has_deposit = d_commercial_shikara
			not = { has_modifier = pm_wenkwort_custodian }
			is_special_colony_type = no
			custom_tooltip = {
				fail_text = no_galactic_market
				has_global_flag = galactic_market_founded
			}
		}
		owner = {
			start_situation = {
				type = planet_megastructure_upgrading
				target = root
				effect = { set_situation_flag = building_plnmg_financial_shikara }
			}
		}
	}

    option = {
        name = d_plnmg_tms_control
        custom_tooltip = build_plnmg_tms_control_desc
        trigger = {
            nor = {
                has_deposit = d_plnmg_tms_control
                has_carrier_flag = planet_has_plnmg_tms_control
            }
            not = { any_targeting_situation = { has_situation_flag = building_plnmg_tms_control } }
            owner = { has_technology = tech_plnmg_managed_ideas }
        }
        allow = {
            if = {
                limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
                check_plnmg_upgrade_reach_limit = yes
                check_plnmg_1to2_space = yes
            }
            is_special_colony_type = no
            or = {
                has_deposit = d_admin_axis
                has_deposit = d_primary_mind_pyramid
            }
        }
        owner = {
            start_situation = {
                type = planet_megastructure_upgrading
                target = root
                effect = { set_situation_flag = building_plnmg_tms_control }
            }
        }
    }

	option = {
        name = planetmega.1.zzz
		custom_tooltip = planetmega.1.zzz.desc
		default_hide_option = yes
		hidden_effect = { carrier_event = { id = planetmega.4 } }
		owner = {
			add_resource = {
				influence = @plnmg_influence_t2
				mult = value:scripted_modifier_mult|MODIFIER|country_influence_cost_mult|
			}
		}
	}
}

# 建造TIER3
carrier_event = {
	id = planetmega.3
	title = planetmega.3.name
	desc = planetmega.3.desc
	picture = GFX_evt_designing_engineers
	#show_sound = event_mystic_reveal_light
	is_triggered_only = yes
	location = root
	trigger = { exists = owner }
	immediate = {
		initialize_plnmg_limit_sys_planet = yes
		decide_planetmega_building_leader = yes
		every_owned_pop_group = {
			species = {
				initialize_mys_variable = { VAR = temp_pop_amount_var }
				change_variable = { which = temp_pop_amount_var value = prev.trigger:pop_group_size }
			}
		}
		ordered_owned_species = {
			position = 0
			order_by = temp_pop_amount_var
			save_event_target_as = temp_most_pop_amount_species
		}
		every_owned_species = { clear_variable = temp_pop_amount_var }
	}
	diplomatic = yes
	diplomatic_title = planetmega.4.name
	picture_event_data = {
		room = owner_main_species # swappable for leader (species)
		portrait = event_target:planetmega_building_leader # swappable for leader (species) and GIF
		planet_background = carrier
		graphical_culture = owner
		city_level = owner
	}

	option = {
		name = planetmega.2.colossus
		custom_tooltip = build_plnmg_colossus_assist_desc
		trigger = {
			nor = {
				has_deposit = d_plnmg_colossus_assist
				has_carrier_flag = planet_has_plnmg_colossus_assist
			}
			not = { any_targeting_situation = { has_situation_flag = building_plnmg_colossus_assist } }
			owner = { has_technology = tech_planetmega_colossus }
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
				#free_building_slots >= 1
			}
			custom_tooltip = {
				fail_text = requires_no_anomaly
				NOT = { has_anomaly = yes }
			}
			NOR = {
				has_modifier = resort_colony
				has_modifier = penal_colony
				#has_modifier = gestation_colony
			}
			if = {
				limit = { carrier_is_type = planet }
				is_plnmg_common_planet = yes
			}
		}
		owner = {
			start_situation = {
				type = planet_megastructure_constadv
				target = root
				effect = { set_situation_flag = building_plnmg_colossus_assist }
			}
		}
	}

	option = {
		name = planetmega.2.extra_galaxy
		custom_tooltip = build_plnmg_extra_galaxy_desc
		trigger = {
			nor = {
				has_deposit = d_plnmg_extra_galaxy
				has_carrier_flag = planet_has_plnmg_extra_galaxy
			}
			not = { any_targeting_situation = { has_situation_flag = building_plnmg_extra_galaxy } }
			owner = { is_wilderness_empire = no }
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
				#free_building_slots >= 2
			}
			is_special_colony_type = no
			owner = { has_technology = tech_planetmega_transfer }
			if = {
				limit = { hidden_trigger = { owner = { is_nomadic = no } } }
				custom_tooltip = {
					fail_text = system_cant_having_other_plnmg_eg
					solar_system = {
						not = {
							any_system_planet_colony = {
								or = {
									has_deposit = d_plnmg_extra_galaxy
									has_carrier_flag = planet_has_plnmg_extra_galaxy
								}
							}
						}
						not = {
							any_system_planet_colony = {
								any_targeting_situation = { has_situation_flag = building_plnmg_extra_galaxy }
							}
						}
					}
				}
			}
		}
		owner = {
			start_situation = {
				type = planet_megastructure_constadv
				target = root
				effect = { set_situation_flag = building_plnmg_extra_galaxy }
			}
		}
		ai_chance = { weight = 0 }
	}

	option = {
		name = d_plnmg_omnipotence
		custom_tooltip = build_plnmg_omnipotence_desc
		trigger = {
			nor = {
				has_deposit = d_plnmg_omnipotence
				has_carrier_flag = planet_has_plnmg_omnipotence
			}
			not = { any_targeting_situation = { has_situation_flag = building_plnmg_omnipotence } }
			owner = {
				or = {
					has_technology = tech_planetmega_omnipotence_engineering
					has_technology = tech_planetmega_omnipotence_physics
					has_technology = tech_planetmega_omnipotence_society
				}
			}
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
				free_district_slots >= 3
				#free_building_slots >= 3
			}
			or = {
				is_ideal = yes
				habitability = { who = event_target:temp_most_pop_amount_species value >= 1 }
			}
			is_special_colony_type = no
			pop_amount >= @plnmg_most_pops
            owner = { can_build_plnmg_omnipotence = yes }
		}
		owner = {
			start_situation = {
				type = planet_megastructure_constadv
				target = root
				effect = { set_situation_flag = building_plnmg_omnipotence }
			}
		}
		ai_chance = { weight = 0 }
	}

	option = {
		name = d_plnmg_nano_storm
		custom_tooltip = build_plnmg_nano_storm_desc
		trigger = {
			nor = {
				has_deposit = d_plnmg_nano_storm
				has_carrier_flag = planet_has_plnmg_nano_storm
			}
			not = { any_targeting_situation = { has_situation_flag = building_plnmg_nano_storm } }
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
				#free_building_slots >= 2
			}
			is_special_colony_type = no
			pop_amount >= @plnmg_most_pops
			owner = { has_technology = tech_plnmg_nano_field_cntr }
		}
		owner = {
			start_situation = {
				type = planet_megastructure_constadv
				target = root
				effect = { set_situation_flag = building_plnmg_nano_storm }
			}
		}
		ai_chance = { weight = 0 }
	}

    option = {
        name = d_plnmg_world_shaper
        custom_tooltip = build_plnmg_world_shaper_desc
        trigger = {
            nor = {
                has_deposit = d_plnmg_world_shaper
                has_carrier_flag = planet_has_plnmg_world_shaper
            }
            not = { any_targeting_situation = { has_situation_flag = building_plnmg_world_shaper } }
        }
        allow = {
            not = {
                has_modifier = resort_colony
                #has_modifier = gestation_colony
            }
            owner = { can_build_plnmg_world_shaper = yes }
        }
        owner = {
            start_situation = {
                type = planet_megastructure_constadv
                target = root
                effect = { set_situation_flag = building_plnmg_world_shaper }
            }
        }
        ai_chance = { weight = 0 }
    }

	option = {
        name = planetmega.1.zzz
		# custom_tooltip = planetmega.1.zzz.desc
		default_hide_option = yes
		owner = {
			add_resource = {
				influence = @plnmg_influence_t3
				mult = value:scripted_modifier_mult|MODIFIER|country_influence_cost_mult|
			}
		}
		hidden_effect = { carrier_event = { id = planetmega.4 } }
	}
}

#荒野
carrier_event = {
	id = planetmega.32
	title = planetmega.32.name
	desc = planetmega.4.desc
	picture = GFX_evt_designing_engineers
	is_triggered_only = yes
	location = root
	trigger = { owner? = { is_wilderness_empire = yes } }
	immediate = { initialize_plnmg_limit_sys_planet = yes }

	option = {
		name = d_plnmg_wilderness_flora
		custom_tooltip = build_plnmg_wilderness_flora_desc
		trigger = {
			nor = {
				has_deposit = d_plnmg_wilderness_flora
				has_carrier_flag = planet_has_plnmg_wilderness_flora
			}
			not = { any_targeting_situation = { has_situation_flag = building_plnmg_wilderness_flora } }
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
			}
		}
		owner = {
			start_situation = {
				type = planetmega_wilderness_construction
				target = root
				effect = { set_situation_flag = building_plnmg_wilderness_flora }
			}
		}
	}

	option = {
		name = d_plnmg_wilderness_terra
		custom_tooltip = build_plnmg_wilderness_terra_desc
		trigger = {
			nor = {
				has_deposit = d_plnmg_wilderness_terra
				has_carrier_flag = planet_has_plnmg_wilderness_terra
			}
			not = { any_targeting_situation = { has_situation_flag = building_plnmg_wilderness_terra } }
		}
		allow = {
			if = {
				limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
				check_plnmg_build_reach_limit = yes
			}
			#not = { has_modifier = gestation_colony }
		}
		owner = {
			start_situation = {
				type = planetmega_wilderness_construction
				target = root
				effect = { set_situation_flag = building_plnmg_wilderness_terra }
			}
		}
	}

	option = {
		name = planetmega.1.zzz
		# custom_tooltip = planetmega.1.zzz.desc
		default_hide_option = yes
		owner = {
			add_resource = {
				influence = @plnmg_influence_t1
				mult = value:scripted_modifier_mult|MODIFIER|country_influence_cost_mult|
			}
		}
		hidden_effect = { carrier_event = { id = planetmega.4 } }
	}
}

# 建造局势中转事件
situation_event = {
	id = planetmega.5
	title = planetmega.5.name
	desc = planetmega.5.desc
	picture = GFX_evt_designing_engineers
	#show_sound = event_mystic_reveal_light
	is_triggered_only = yes
	situation = this
	location = target

	trigger = { not = { has_situation_flag = no_cost_check } }
	immediate = {
		set_situation_flag = situation_locked
		target = { remove_carrier_flag = planet_has_plnmg_megabuild_listed }
	}

	option = { #Start Tier1
		name = planetmega.5.a
		trigger = { situation_is_plnmg_base = yes }
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = energy
					value >= @plnmg_energy_t1
					mult = prev.target.value:ground_megastructure_estimate_mult
				}
				resource_stockpile_compare = {
					resource = alloys
					value >= @plnmg_alloys_t1
					mult = prev.target.value:ground_megastructure_estimate_mult
				}
				if = {
					limit = { hidden_trigger = { owner = { is_wilderness_empire = yes } } }
					resource_stockpile_compare = {
						resource = biomass
						value >= @plnmg_biomass_t1
						mult = prev.target.value:ground_megastructure_estimate_mult
					}
				}
				else_if = {
					limit = { hidden_trigger = { prev = { situation_is_plnmg_hive_type = yes } } }
					resource_stockpile_compare = {
						resource = food
						value >= @plnmg_food_t1
						mult = prev.target.value:ground_megastructure_estimate_mult
					}
				}
				else = {
					resource_stockpile_compare = {
						resource = minerals
						value >= @plnmg_minerals_t1
						mult = prev.target.value:ground_megastructure_estimate_mult
					}
				}
			}
		}
		owner = {
			add_resource = {
				energy = @plnmg_energy_t1
				alloys = @plnmg_alloys_t1
				mult = prev.target.value:ground_megastructure_cost_mult
			}
			if = {
				limit = { hidden_trigger = { owner = { is_wilderness_empire = yes } } }
				add_resource = {
					biomass = @plnmg_biomass_t1
					mult = prev.target.value:ground_megastructure_cost_mult
				}
			}
			else_if = {
				limit = { hidden_trigger = { prev = { situation_is_plnmg_hive_type = yes } } }
				add_resource = {
					food = @plnmg_food_t1
					mult = prev.target.value:ground_megastructure_cost_mult
				}
			}
			else = {
				add_resource = {
					minerals = @plnmg_minerals_t1
					mult = prev.target.value:ground_megastructure_cost_mult
				}
			}
		}
		hidden_effect = {
			remove_situation_flag = situation_locked
            fire_on_action = { on_action = on_planetmega_build_begin }
			target = { set_carrier_flag = planet_building_groundmega }
			if = {
				limit = { owner = { is_wilderness_empire = yes } }
				target = {
					set_variable = { which = temp_spent_biomass value = @plnmg_biomass_t1 }
					multiply_variable = { which = temp_spent_biomass value = value:ground_megastructure_estimate_mult }
					plnmg_wilderness_biomass_spender = yes
				}
			}
		}
		ai_chance = { weight = 100 }
	}

	option = { #Start Tier2
		name = planetmega.5.a
		trigger = { situation_is_plnmg_improved = yes }
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = energy
					value >= @plnmg_energy_t2
					mult = prev.target.value:ground_megastructure_estimate_mult
				}
				resource_stockpile_compare = {
					resource = alloys
					value >= @plnmg_alloys_t2
					mult = prev.target.value:ground_megastructure_estimate_mult
				}
				if = {
					limit = { hidden_trigger = { owner = { is_wilderness_empire = yes } } }
					resource_stockpile_compare = {
						resource = biomass
						value >= @plnmg_biomass_t2
						mult = prev.target.value:ground_megastructure_estimate_mult
					}
				}
				else_if = {
					limit = { hidden_trigger = { prev = { situation_is_plnmg_hive_type = yes } } }
					resource_stockpile_compare = {
						resource = food
						value >= @plnmg_food_t2
						mult = prev.target.value:ground_megastructure_estimate_mult
					}
				}
				else = {
					resource_stockpile_compare = {
						resource = minerals
						value >= @plnmg_minerals_t2
						mult = prev.target.value:ground_megastructure_estimate_mult
					}
				}
			}
		}
		owner = {
			add_resource = {
				energy = @plnmg_energy_t2
				alloys = @plnmg_alloys_t2
				mult = prev.target.value:ground_megastructure_cost_mult
			}
			if = {
				limit = { hidden_trigger = { owner = { is_wilderness_empire = yes } } }
				add_resource = {
					biomass = @plnmg_biomass_t2
					mult = prev.target.value:ground_megastructure_cost_mult
				}
			}
			else_if = {
				limit = { hidden_trigger = { prev = { situation_is_plnmg_hive_type = yes } } }
				add_resource = {
					food = @plnmg_food_t2
					mult = prev.target.value:ground_megastructure_cost_mult
				}
			}
			else = {
				add_resource = {
					minerals = @plnmg_minerals_t2
					mult = prev.target.value:ground_megastructure_cost_mult
				}
			}
		}
		hidden_effect = {
			remove_situation_flag = situation_locked
            fire_on_action = { on_action = on_planetmega_build_begin }
            target = { set_carrier_flag = planet_building_groundmega }
			if = {
				limit = { owner = { is_wilderness_empire = yes } }
				target = {
					set_variable = { which = temp_spent_biomass value = @plnmg_biomass_t2 }
					multiply_variable = { which = temp_spent_biomass value = value:ground_megastructure_estimate_mult }
					plnmg_wilderness_biomass_spender = yes
				}
			}
		}
		ai_chance = { weight = 100 }
	}

	option = { #Start Tier3
		name = planetmega.5.a
		trigger = { situation_is_plnmg_advanced = yes }
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = energy
					value >= @plnmg_energy_t3
					mult = prev.target.value:ground_megastructure_estimate_mult
				}
				resource_stockpile_compare = {
					resource = alloys
					value >= @plnmg_alloys_t3
					mult = prev.target.value:ground_megastructure_estimate_mult
				}
				resource_stockpile_compare = {
					resource = minerals
					value >= @plnmg_minerals_t3
					mult = prev.target.value:ground_megastructure_estimate_mult
				}
				if = {
					limit = { hidden_trigger = { owner = { is_wilderness_empire = yes } } }
					resource_stockpile_compare = {
						resource = biomass
						value >= @plnmg_biomass_t3
						mult = prev.target.value:ground_megastructure_estimate_mult
					}
				}
			}
			owner = {
				if = {
					limit = { hidden_trigger = { prev = { has_situation_flag = building_plnmg_nano_storm } } }
					if = {
						limit = { hidden_trigger = { has_planetmega_nanotech = yes } }
						resource_stockpile_compare = {
							resource = nanites
							value >= @plnmg_nanites_t3_nanotech
							mult = prev.target.value:ground_megastructure_estimate_mult
						}
					}
					else = {
						resource_stockpile_compare = {
							resource = nanites
							value >= @plnmg_nanites_t3
							mult = prev.target.value:ground_megastructure_estimate_mult
						}
					}
				}
			}
		}
		owner = {
			add_resource = {
				energy = @plnmg_energy_t3
				alloys = @plnmg_alloys_t3
				minerals = @plnmg_minerals_t3
				mult = prev.target.value:ground_megastructure_cost_mult
			}
			if = {
				limit = { hidden_trigger = { owner = { is_wilderness_empire = yes } } }
				add_resource = {
					biomass = @plnmg_biomass_t3
					mult = prev.target.value:ground_megastructure_cost_mult
				}
			}
		}
		owner = {
			if = {
				limit = { hidden_trigger = { prev = { has_situation_flag = building_plnmg_nano_storm } } }
				if = {
					limit = { hidden_trigger = { has_planetmega_nanotech = yes } }
					add_resource = {
						nanites = @plnmg_nanites_t3_nanotech
						mult = prev.target.value:ground_megastructure_cost_mult
					}
				}
				else = {
					add_resource = {
						nanites = @plnmg_nanites_t3
						mult = prev.target.value:ground_megastructure_cost_mult
					}
				}
			}
		}
		hidden_effect = {
			remove_situation_flag = situation_locked
            fire_on_action = { on_action = on_planetmega_build_begin }
            target = { set_carrier_flag = planet_building_groundmega }
			if = {
				limit = { owner = { is_wilderness_empire = yes } }
				target = {
					set_variable = { which = temp_spent_biomass value = @plnmg_biomass_t3 }
					multiply_variable = { which = temp_spent_biomass value = value:ground_megastructure_estimate_mult }
					plnmg_wilderness_biomass_spender = yes
				}
			}
		}
		ai_chance = { weight = 100 }
	}

	option = { #Revoke
		name = planetmega.5.b
		owner = {
			if = {
				limit = { hidden_trigger = { prev = { situation_is_plnmg_base = yes } } }
				add_resource = {
					influence = @plnmg_influence_t1
					mult = value:scripted_modifier_mult|MODIFIER|country_influence_cost_mult|
				}
			}
			if = {
				limit = { hidden_trigger = { prev = { situation_is_plnmg_improved = yes } } }
				add_resource = {
					influence = @plnmg_influence_t2
					mult = value:scripted_modifier_mult|MODIFIER|country_influence_cost_mult|
				}
			}
			if = {
				limit = { hidden_trigger = { prev = { situation_is_plnmg_advanced = yes } } }
				add_resource = {
					influence = @plnmg_influence_t3
					mult = value:scripted_modifier_mult|MODIFIER|country_influence_cost_mult|
				}
			}
		}
		destroy_situation = this
	}
}

#荒野建造
situation_event = {
	id = planetmega.31
	is_triggered_only = yes
	title = planetmega.31.name
	desc = planetmega.31.desc
	picture = GFX_evt_giant_building_in_progress
	immediate = {
		set_situation_flag = situation_locked
		target = { remove_carrier_flag = planet_has_plnmg_megabuild_listed }
	}
	option = {
		name = OK
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = biomass
					value >= @plnmg_biomass_t1
					mult = prev.target.value:ground_megastructure_estimate_mult
				}
				if = {
					limit = { prev = { has_situation_flag = building_plnmg_wilderness_flora } }
					resource_stockpile_compare = {
						resource = food
						value >= @plnmg_food_t1
						mult = prev.target.value:ground_megastructure_estimate_mult
					}
				}
				else_if = {
					limit = { prev = { has_situation_flag = building_plnmg_wilderness_terra } }
					resource_stockpile_compare = {
						resource = minerals
						value >= @plnmg_minerals_t1
						mult = prev.target.value:ground_megastructure_estimate_mult
					}
				}
			}
		}
		owner = {
			add_resource = {
				biomass = @plnmg_biomass_t1
				mult = prev.target.value:ground_megastructure_cost_mult
			}
			if = {
				limit = { prev = { has_situation_flag = building_plnmg_wilderness_flora } }
				add_resource = {
					food = @plnmg_food_t1
					mult = prev.target.value:ground_megastructure_cost_mult
				}
			}
			else_if = {
				limit = { prev = { has_situation_flag = building_plnmg_wilderness_terra } }
				add_resource = {
					minerals = @plnmg_minerals_t1
					mult = prev.target.value:ground_megastructure_cost_mult
				}
			}
		}
		hidden_effect = {
            remove_situation_flag = situation_locked
            fire_on_action = { on_action = on_planetmega_build_begin }
			target = {
				set_variable = { which = temp_spent_biomass value = @plnmg_biomass_t1 }
				multiply_variable = { which = temp_spent_biomass value = value:ground_megastructure_estimate_mult }
				plnmg_wilderness_biomass_spender = yes
			}
        }
	}
	option = {
		name = CANCEL
		default_hide_option = yes
		destroy_situation = this
	}
}

# 升级局势中转事件
situation_event = {
	id = planetmega.6
	title = planetmega.6.name
	desc = planetmega.6.desc
	picture = GFX_evt_designing_engineers
	show_sound = event_mystic_reveal_light
	is_triggered_only = yes
	situation = this
	location = target

	immediate = {
		set_situation_flag = situation_locked
		target = { remove_carrier_flag = planet_has_plnmg_megabuild_listed }
	}

	option = { #Start T1 to T2
		name = planetmega.6.a
		#trigger = { situation_is_plnmg_improved = yes }
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = energy
					value >= @plnmg_energy_t1_upg
					mult = prev.target.value:ground_megastructure_estimate_mult
				}
				resource_stockpile_compare = {
					resource = alloys
					value >= @plnmg_alloys_t1_upg
					mult = prev.target.value:ground_megastructure_estimate_mult
				}
				if = {
					limit = { hidden_trigger = { owner = { is_wilderness_empire = yes } } }
					resource_stockpile_compare = {
						resource = biomass
						value >= @plnmg_biomass_t1_upg
						mult = prev.target.value:ground_megastructure_estimate_mult
					}
				}
				else_if = {
					limit = { hidden_trigger = { prev = { situation_is_plnmg_hive_type = yes } } }
					resource_stockpile_compare = {
						resource = food
						value >= @plnmg_food_t1_upg
						mult = prev.target.value:ground_megastructure_estimate_mult
					}
				}
				else = {
					resource_stockpile_compare = {
						resource = minerals
						value >= @plnmg_minerals_t1_upg
						mult = prev.target.value:ground_megastructure_estimate_mult
					}
				}
			}
		}
		owner = {
			add_resource = {
				energy = @plnmg_energy_t1_upg
				alloys = @plnmg_alloys_t1_upg
				mult = prev.target.value:ground_megastructure_cost_mult
			}
			if = {
				limit = { hidden_trigger = { owner = { is_wilderness_empire = yes } } }
				add_resource = {
					biomass = @plnmg_biomass_t1_upg
					mult = prev.target.value:ground_megastructure_cost_mult
				}
			}
			else_if = {
				limit = { hidden_trigger = { prev = { situation_is_plnmg_hive_type = yes } } }
				add_resource = {
					food = @plnmg_food_t1_upg
					mult = prev.target.value:ground_megastructure_cost_mult
				}
			}
			else = {
				add_resource = {
					minerals = @plnmg_minerals_t1_upg
					mult = prev.target.value:ground_megastructure_cost_mult
				}
			}
		}
		hidden_effect = {
			remove_situation_flag = situation_locked
            fire_on_action = { on_action = on_planetmega_upgrade_begin }
            target = { set_carrier_flag = planet_building_groundmega }
			if = {
				limit = { owner = { is_wilderness_empire = yes } }
				target = {
					set_variable = { which = temp_spent_biomass value = @plnmg_biomass_t1_upg }
					multiply_variable = { which = temp_spent_biomass value = value:ground_megastructure_estimate_mult }
					plnmg_wilderness_biomass_spender = yes
				}
			}
		}
		ai_chance = { weight = 100 }
	}

	option = { #Revoke
		name = planetmega.5.b
		custom_tooltip = planetmega.5.b.tooltip
		owner = {
			add_resource = {
				influence = @plnmg_influence_t2
				mult = value:scripted_modifier_mult|MODIFIER|country_influence_cost_mult|
			}
		}
		destroy_situation = this
	}
}

# 拆除巨构局势中转
situation_event = {
	id = planetmega.7
	title = planet_megastructure_teardown
	desc = planetmega.7.desc
	picture = GFX_evt_designing_engineers
	is_triggered_only = yes
	situation = this
	location = target
	immediate = { set_situation_flag = situation_locked }
	option = {
		name = OK
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = energy
					value >= 3000
					mult = prev.target.value:ground_megastructure_estimate_mult
				}
			}
		}
		owner = {
			add_resource = {
				energy = 3000
				mult = prev.target.value:ground_megastructure_cost_mult
			}
		}
        hidden_effect = {
			fire_on_action = { on_action = on_planetmega_demolish_begin }
			remove_situation_flag = situation_locked
		}
		ai_chance = { weight = 100 }
	}
	option = {
		name = planetmega.7.b
		destroy_situation = this
	}
}

#修复巨构局势中转
situation_event = {
	id = planetmega.8
	title = planetmega.8.name
	desc = planetmega.8.desc
	picture = GFX_evt_designing_engineers
	#show_sound = event_mystic_reveal_light
	is_triggered_only = yes
	situation = this
	location = target
	immediate = {
		set_situation_flag = situation_locked
		target = { initialize_plnmg_limit_sys_planet = yes }
	}
	option = {
		name = OK
		trigger = {
			nor = {
				situation_is_plnmg_hive_type = yes
				has_situation_flag = building_plnmg_bore_of_the_shroud
			}
		}
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = alloys
					value >= 100
				}
			}
		}
		owner = { add_resource = { alloys = -100 } }
		hidden_effect = { remove_situation_flag = situation_locked }
	}
	option = {
		name = planetmega.5.ab
		trigger = {
			or = {
				situation_is_plnmg_hive_type = yes
				has_situation_flag = building_plnmg_bore_of_the_shroud
			}
		}
		allow = {
			target = {
				if = {
					limit = { hidden_trigger = { is_planetmega_byd_space_need = no } }
					custom_tooltip = {
						fail_text = plnmg_reach_limit_text
						check_variable_arithmetic = {
							which = num_plnmg_mega_owned_count
							add = 1
							value <= value:plnmg_mega_owned_limit_value
						}
					}
				}
			}
			owner = {
				if = {
					limit = { hidden_trigger = { prev = { has_situation_flag = building_hive_farm_edifice } } }
					#resource_stockpile_compare = {
					#	resource = minerals
					#	value >= 1000
					#	mult = prev.target.value:ground_megastructure_estimate_mult
					#}
					resource_stockpile_compare = {
						resource = food
						value >= @plnmg_food_t1_re
						mult = prev.target.value:ground_megastructure_estimate_mult
					}
				}
				if = {
					limit = { hidden_trigger = { prev = { has_situation_flag = building_plnmg_bore_of_the_shroud } } }
					resource_stockpile_compare = {
						resource = alloys
						value >= 3500
						mult = prev.target.value:ground_megastructure_estimate_mult
					}
					resource_stockpile_compare = {
						resource = minerals
						value >= @plnmg_minerals_t2_re
						mult = prev.target.value:ground_megastructure_estimate_mult
					}
					resource_stockpile_compare = {
						resource = sr_zro
						value >= 250
						mult = prev.target.value:ground_megastructure_estimate_mult
					}
				}
				if = {
					limit = {
						hidden_trigger = {
							prev = {
								or = {
									has_situation_flag = building_plnmg_gene_farm_hive
									has_situation_flag = building_plnmg_fusion_brain
								}
							}
						}
					}
					resource_stockpile_compare = {
						resource = alloys
						value >= @plnmg_alloys_t1_re
						mult = prev.target.value:ground_megastructure_estimate_mult
					}
					resource_stockpile_compare = {
						resource = food
						value >= @plnmg_food_t2_re
						mult = prev.target.value:ground_megastructure_estimate_mult
					}
				}
			}
		}
		owner = {
			if = {
				limit = { hidden_trigger = { prev = { has_situation_flag = building_hive_farm_edifice } } }
				add_resource = {
					#minerals = @plnmg_minerals_t1_re_flesh
					food = @plnmg_food_t1_re
					mult = prev.target.value:ground_megastructure_cost_mult
				}
			}
			if = {
				limit = { hidden_trigger = { prev = { has_situation_flag = building_plnmg_bore_of_the_shroud } } }
				add_resource = {
					alloys = 3500
					minerals = @plnmg_minerals_t2_re
					sr_zro = 250
					mult = prev.target.value:ground_megastructure_cost_mult
				}
			}
			if = {
				limit = {
					hidden_trigger = {
						prev = {
							or = {
								has_situation_flag = building_plnmg_gene_farm_hive
								has_situation_flag = building_plnmg_fusion_brain
							}
						}
					}
				}
				add_resource = {
					alloys = @plnmg_alloys_t1_re
					food = @plnmg_food_t2_re
					mult = prev.target.value:ground_megastructure_cost_mult
				}
			}
		}
		hidden_effect = { remove_situation_flag = situation_locked }
		ai_chance = { weight = 100 }
	}
	option = {
		name = planetmega.8.b
		destroy_situation = this
	}
}

#拆除
situation_event = {
	id = planetmega.9
	is_triggered_only = yes
	title = planetmega.9.name
	desc = planetmega.9.desc
	picture = GFX_planet_mega_mod
	location = target
	situation = this
	after = {
		hidden_effect = {
			target = {
				if = {
					limit = {
						has_carrier_flag = planet_building_groundmega
						check_variable_arithmetic = {
							which = value:plnmg_mega_build_count_value
							subtract = 1
							value <= 0
						}
					}
					remove_carrier_flag = planet_building_groundmega
				}
			}
		}
		destroy_situation = this
	}

	option = {
		name = OK
		trigger = { is_situation_type = planet_megastructure_teardown }
		owner = {
			add_resource = {
				energy = @plnmg_energy_t1
				alloys = @plnmg_alloys_t1
				mult = prev.target.value:ground_megastructure_compensation_mult
			}
			# 需要脚本触发，但现在没时间写
			if = {
				limit = { hidden_trigger = { is_wilderness_empire = yes } }
				add_resource = {
					biomass = @plnmg_biomass_t1
					alloys = -1450
					mult = prev.target.value:ground_megastructure_compensation_mult
				}
			}
			else_if = {
				limit = { hidden_trigger = { prev = { situation_is_plnmg_hive_type = yes } } }
				add_resource = {
					food = @plnmg_food_t1
					mult = prev.target.value:ground_megastructure_compensation_mult
				}
			}
			else = {
				add_resource = {
					minerals = @plnmg_minerals_t1
					mult = prev.target.value:ground_megastructure_compensation_mult
				}
			}

			# add_resource = {
			# 	energy = @plnmg_energy_t2
			# 	alloys = @plnmg_alloys_t2
			# 	mult = value:ground_megastructure_compensation_mult
			# }
			# if = {
			# 	limit = { hidden_trigger = { prev = { situation_is_plnmg_hive_type = yes } } }
			# 	add_resource = {
			# 		food = @plnmg_food_t2
			# 		mult = value:ground_megastructure_compensation_mult
			# 	}
			# }
			# else = {
			# 	add_resource = {
			# 		minerals = @plnmg_minerals_t2
			# 		mult = value:ground_megastructure_compensation_mult
			# 	}
			# }
			if = {
				limit = { hidden_trigger = { prev = { has_situation_flag = dismantling_plnmg_nano_storm } } }
				add_resource = {
					nanites = 1000
					mult = prev.target.value:ground_megastructure_compensation_mult
				}
			}
		}
	}
	option = {
		name = OK
		trigger = { not = { is_situation_type = planet_megastructure_teardown } }
		owner = {
			if = {
				limit = { root = { is_situation_type = planet_megastructure_construction } }
				add_resource = {
					energy = @plnmg_energy_t1
					alloys = @plnmg_alloys_t1
					mult = prev.target.value:ground_megastructure_compensation_mult
				}
				if = {
					limit = { hidden_trigger = { prev = { situation_is_plnmg_hive_type = yes } } }
					add_resource = {
						food = @plnmg_food_t1
						mult = prev.target.value:ground_megastructure_compensation_mult
					}
				}
				else = {
					add_resource = {
						minerals = @plnmg_minerals_t1
						mult = prev.target.value:ground_megastructure_compensation_mult
					}
				}
			}
			else_if = {
				limit = { root = { is_situation_type = planet_megastructure_upgrading } }
				add_resource = {
					energy = @plnmg_energy_t1_upg
					alloys = @plnmg_alloys_t1_upg
					mult = prev.target.value:ground_megastructure_compensation_mult
				}
				if = {
					limit = { hidden_trigger = { prev = { situation_is_plnmg_hive_type = yes } } }
					add_resource = {
						food = @plnmg_food_t1_upg
						mult = prev.target.value:ground_megastructure_compensation_mult
					}
				}
				else = {
					add_resource = {
						minerals = @plnmg_minerals_t1_upg
						mult = prev.target.value:ground_megastructure_compensation_mult
					}
				}
			}
			else_if = {
				limit = { root = { is_situation_type = planet_megastructure_constimp } }
				add_resource = {
					energy = @plnmg_energy_t2
					alloys = @plnmg_alloys_t2
					mult = prev.target.value:ground_megastructure_compensation_mult
				}
				if = {
					limit = { hidden_trigger = { prev = { situation_is_plnmg_hive_type = yes } } }
					add_resource = {
						food = @plnmg_food_t2
						mult = prev.target.value:ground_megastructure_compensation_mult
					}
				}
				else = {
					add_resource = {
						minerals = @plnmg_minerals_t2
						mult = prev.target.value:ground_megastructure_compensation_mult
					}
				}
			}
			else_if = {
				limit = { root = { is_situation_type = planet_megastructure_constadv } }
				add_resource = {
					energy = @plnmg_energy_t2
					alloys = @plnmg_alloys_t2
					minerals = @plnmg_minerals_t2
					mult = prev.target.value:ground_megastructure_compensation_mult
				}
				if = {
					limit = { hidden_trigger = { prev = { has_situation_flag = building_plnmg_nano_storm } } }
					add_resource = {
						nanites = 1000
						mult = prev.target.value:ground_megastructure_compensation_mult
					}
				}
			}
		}
	}
}

# trigger general on_action of planetmega construction/upgrading situations
situation_event = {
	id = planetmega.11
	is_triggered_only = yes
	hide_window = yes
	situation = this
	trigger = {
		situation_monthly_progress > 0
		situation_progress > @plnmg_progress_add_little
		nor = {
			has_situation_flag = plnmg_const_sit_monthly_pulse_disabled #kept for compatibility
			has_situation_flag = situation_locked
			and = {
				is_variable_set = sit_monthly_pulse_disability_index
				check_variable = { which = sit_monthly_pulse_disability_index value > 0 }
			}
		}
	}
	immediate = { fire_on_action = { on_action = on_plnmg_const_sit_monthly_pulse } }
}

situation_event = {
	id = planetmega.18
	title = planetmega.18.name
	desc = planetmega.18.desc
	picture = GFX_evt_giant_building_in_progress
	is_triggered_only = yes
	situation = this
	location = target
	option = {
		name = planetmega.18.OK
		hidden_effect = { set_variable = { which = sit_monthly_pulse_disability_index value = 1 } }
	}
	option = {
		name = planetmega.18.automated
		custom_tooltip = planetmega.18.automated.tt
		hidden_effect = { set_variable = { which = sit_monthly_pulse_disability_index value = 2 } }
	}
	option = { name = planetmega.18.cancel }
	after = {
		hidden_effect = {
			if = {
				limit = { has_situation_flag = triggered_by_planetmega_250 }
				remove_situation_flag = triggered_by_planetmega_250
				situation_event = { id = planetmega.250 }
			}
		}
	}
}

situation_event = {
	id = planetmega.10
	title = planetmega.10.name
	desc = planetmega.10.desc
	picture = GFX_evt_giant_building_in_progress
	show_sound = event_power_down
	is_triggered_only = yes
	situation = this
	location = target
	immediate = { set_situation_locked = yes }
	after = { hidden_effect = { set_situation_locked = no } }

	option = { #delayed
		name = planetmega.10.a
		add_situation_progress = @plnmg_progress_subtract_big
		ai_chance = { weight = 100 }
	}
	option = { #pay energy 
		name = planetmega.10.b
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = energy
					value >= @plnmg_incident_energy_big
					mult = prev.target.value:ground_megastructure_estimate_mult
				}
			}
		}
		owner = {
			add_resource = {
				energy = @plnmg_incident_energy_big
				mult = prev.target.value:ground_megastructure_cost_mult
			}
		}
	}
}

situation_event = {
	id = planetmega.12
	title = planetmega.10.name
	desc = planetmega.10.desc
	picture = GFX_evt_giant_building_in_progress
	show_sound = event_power_down
	is_triggered_only = yes
	situation = this
	location = target
	inline_script = situations/plnmg_sit_random_weights_bad
	immediate = { set_situation_locked = yes }
	after = { hidden_effect = { set_situation_locked = no } }

	option = { #delayed
		name = planetmega.10.a
		add_situation_progress = @plnmg_progress_subtract_little
		ai_chance = { weight = 100 }
	}
	option = { #pay energy
		name = planetmega.10.b
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = energy
					value >= @plnmg_incident_energy_little
					mult = prev.target.value:ground_megastructure_estimate_mult
				}
			}
		}
		owner = {
			add_resource = {
				energy = @plnmg_incident_energy_little
				mult = prev.target.value:ground_megastructure_cost_mult
			}
		}
	}
}

# bad materials 
situation_event = {
	id = planetmega.15
	title = planetmega.15.name
	desc = planetmega.15.desc
	picture = GFX_evt_giant_building_in_progress
	show_sound = event_bad_omen
	is_triggered_only = yes
	situation = this
	location = target
	
	immediate = { set_situation_locked = yes }
	after = { hidden_effect = { set_situation_locked = no } }

	option = { # delayed
		name = planetmega.15.a
		add_situation_progress = @plnmg_progress_subtract_big
		ai_chance = {
			weight = 100
		}
	}
	option = { # pay alloys
		name = planetmega.15.b
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = alloys
					value >= @plnmg_incident_alloys_big
					mult = prev.target.value:ground_megastructure_estimate_mult
				}
				if = {
					limit = { prev = { has_situation_flag = building_plnmg_nano_storm } }
					resource_stockpile_compare = {
						resource = nanites
						value >= 108
						mult = prev.target.value:ground_megastructure_estimate_mult
					}
				}
			}
		}
		owner = {
			add_resource = {
				alloys = @plnmg_incident_alloys_big
				mult = prev.target.value:ground_megastructure_cost_mult
			}
			if = {
				limit = { prev = { has_situation_flag = building_plnmg_nano_storm } }
				add_resource = {
					nanites = 108
					mult = prev.target.value:ground_megastructure_cost_mult
				}
			}
		}
	}
}

situation_event = {
	id = planetmega.14
	title = planetmega.15.name
	desc = planetmega.15.desc
	picture = GFX_evt_giant_building_in_progress
	show_sound = event_bad_omen
	is_triggered_only = yes
	situation = this
	location = target
	inline_script = situations/plnmg_sit_random_weights_bad
	immediate = { set_situation_locked = yes }
	after = { hidden_effect = { set_situation_locked = no } }

	option = { # delayed
		name = planetmega.15.a
		add_situation_progress = @plnmg_progress_subtract_little
		ai_chance = {
			weight = 100
		}
	}
	option = { # pay alloys
		name = planetmega.15.b
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = alloys
					value >= @plnmg_incident_alloys_little
					mult = prev.target.value:ground_megastructure_estimate_mult
				}
			}
		}
		owner = {
			add_resource = {
				alloys = @plnmg_incident_alloys_little
				mult = prev.target.value:ground_megastructure_cost_mult
			}
		}
	}
}

situation_event = {
	id = planetmega.16
	title = planetmega.16.name
	desc = planetmega.16.desc
	picture = GFX_evt_giant_building_in_progress
	show_sound = event_bad_omen
	is_triggered_only = yes
	situation = this
	location = target
	immediate = { set_situation_locked = yes }
	after = { hidden_effect = { set_situation_locked = no } }

	option = { #delayed
		name = planetmega.10.a
		add_situation_progress = @plnmg_progress_subtract_big
		ai_chance = { weight = 100 }
	}
	option = { #pay energy 
		name = planetmega.16.b
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = minerals
					value >= @plnmg_incident_minerals_big
					mult = prev.target.value:ground_megastructure_estimate_mult
				}
				if = {
					limit = { prev = { has_situation_flag = building_plnmg_nano_storm } }
					resource_stockpile_compare = {
						resource = nanites
						value >= 54
						mult = prev.target.value:ground_megastructure_estimate_mult
					}
				}
			}
		}
		owner = {
			add_resource = {
				minerals = @plnmg_incident_minerals_big
				mult = prev.target.value:ground_megastructure_cost_mult
			}
			if = {
				limit = { prev = { has_situation_flag = building_plnmg_nano_storm } }
				add_resource = {
					nanites = 54
					mult = prev.target.value:ground_megastructure_cost_mult
				}
			}
		}
	}
}

situation_event = {
	id = planetmega.17
	title = planetmega.16.name
	desc = planetmega.16.desc
	picture = GFX_evt_giant_building_in_progress
	show_sound = event_bad_omen
	is_triggered_only = yes
	situation = this
	location = target
	inline_script = situations/plnmg_sit_random_weights_bad
	immediate = { set_situation_locked = yes }
	after = { hidden_effect = { set_situation_locked = no } }

	option = { #delayed
		name = planetmega.10.a
		add_situation_progress = @plnmg_progress_subtract_little
		ai_chance = { weight = 100 }
	}
	option = { #pay energy
		name = planetmega.16.b
		allow = {
			owner = {
				resource_stockpile_compare = {
					resource = minerals
					value >= @plnmg_incident_minerals_little
					mult = prev.target.value:ground_megastructure_estimate_mult
				}
			}
		}
		owner = {
			add_resource = {
				minerals = @plnmg_incident_minerals_little
				mult = prev.target.value:ground_megastructure_cost_mult
			}
		}
	}
}

# unexpected progress
situation_event = {
	id = planetmega.20
	title = planetmega.20.name
	desc = planetmega.20.desc
	picture = GFX_evt_metropolis_dawn
	is_triggered_only = yes
	show_sound = event_mystic_reveal_light
	situation = this
	location = target

	immediate = { set_situation_locked = yes }
	after = { hidden_effect = { set_situation_locked = no } }

	option = { # EXCELLENT
		name = EXCELLENT
		add_situation_progress = @plnmg_progress_add_big
	}
}

situation_event = {
	id = planetmega.21
	title = planetmega.20.name
	desc = planetmega.20.desc
	picture = GFX_evt_metropolis_dawn
	is_triggered_only = yes
	show_sound = event_mystic_reveal_light
	situation = this
	location = target
	weight_multiplier = {
		factor = 1
		modifier = {
			factor = 1.5
			target = { is_plnmg_governor_clean = yes }
		}
	}

	immediate = { set_situation_locked = yes }
	after = { hidden_effect = { set_situation_locked = no } }

	option = { # EXCELLENT
		name = EXCELLENT
		add_situation_progress = @plnmg_progress_add_little
	}
}

situation_event = {
	id = planetmega.22
	title = planetmega.22.name
	desc = planetmega.22.desc
	picture = GFX_evt_metropolis_dawn
	is_triggered_only = yes
	show_sound = event_mystic_reveal_light
	situation = this
	location = target
	trigger = {
		not = { has_situation_flag = already_has_excavated }
		target = { 
			carrier_is_type = planet 
			is_artificial = no
		}
	}
	immediate = { set_situation_flag = already_has_excavated }
	option = {
		name = planetmega.22.a
		set_situation_locked = yes
		situation_event = { id = planetmega.23 days = 30 random = 60 }
	}
	option = { name = planetmega.10.a }
}
situation_event = {
	id = planetmega.23
	title = planetmega.22.name
	desc = planetmega.23.desc
	picture = GFX_evt_archaeological_dig
	is_triggered_only = yes
	show_sound = event_mystic_reveal_light
	situation = this
	location = target

	option = {
		name = SPLENDID
		set_situation_locked = no
		owner = {
			add_resource = {
				minor_artifacts = 100
				mult = prev.value:plnmg_remaining_const_sit_progress_perc
			}
		}
	}
	option = {
		name = CURIOUS
		trigger = { not = { any_archaeological_site = { planet? = { is_same_value = root.target } } } }
		custom_tooltip = planetmega.22.more_arch_tt
		hidden_effect = {
			set_situation_flag = plnmg_const_holding4arch
			target = {
				# prevent_anomaly = yes
				create_archaeological_site = random
				set_carrier_flag = suppress_archaeological_sites #used in ancrel.9999 in vanilla
			}
		}
	}
}
fleet_event = {
	id = planetmega.28
	is_triggered_only = yes
	hide_window = yes
	trigger = { from.planet = { any_targeting_situation = { has_situation_flag = plnmg_const_holding4arch } } }
	immediate = {
		from.planet = {
			# prevent_anomaly = no
			every_targeting_situation = {
				limit = { has_situation_flag = plnmg_const_holding4arch }
				remove_situation_flag = plnmg_const_holding4arch
				set_situation_locked = no
			}
		}
	}
}

situation_event = {
	id = planetmega.24
	title = planetmega.24.name
	desc = planetmega.24.desc
	picture = GFX_evt_metropolis_dawn
	is_triggered_only = yes
	show_sound = event_mystic_reveal_light
	situation = this
	location = target
	trigger = { not = { has_situation_flag = fewer_bad_events } }
	weight_multiplier = {
		factor = 1
		modifier = {
			factor = 1.2
			target = { is_plnmg_governor_clean = yes }
		}
	}
	immediate = { set_situation_locked = yes }
	option = {
		name = planetmega.24.a
		custom_tooltip = fewer_bad_situation_events
		owner = {
			add_resource = {
				minerals = 500
				energy = 350
				mult = root.target.value:ground_megastructure_cost_mult
			}
		}
		hidden_effect = {
			initialize_mys_variable = { VAR = planetmega24_happened_count }
			change_variable = { which = planetmega24_happened_count value = 1 }
		}
	}
	option = { name = planetmega.10.a }
	after = { hidden_effect = { set_situation_locked = no } }
}

situation_event = {
	id = planetmega.27
	is_triggered_only = yes
	hide_window = yes
	immediate = { set_situation_flag = fewer_bad_events }
}

situation_event = {
	id = planetmega.25
	title = planetmega.25.name
	desc = planetmega.25.desc
	picture = GFX_evt_metropolis_dawn
	is_triggered_only = yes
	show_sound = event_yellow_alert
	situation = this
	location = target
	immediate = { set_situation_locked = yes }
	after = { hidden_effect = { set_situation_locked = no } }

	option = { 
		name = DISAPPOINTING
		add_situation_progress = @plnmg_progress_subtract_big
	}
}

situation_event = {
	id = planetmega.26
	title = planetmega.25.name
	desc = planetmega.25.desc
	picture = GFX_evt_metropolis_dawn
	is_triggered_only = yes
	show_sound = event_yellow_alert
	situation = this
	location = target
	inline_script = situations/plnmg_sit_random_weights_bad
	immediate = { set_situation_locked = yes }
	after = { hidden_effect = { set_situation_locked = no } }

	option = {
		name = DISAPPOINTING
		add_situation_progress = @plnmg_progress_subtract_little
	}
}

#取消巨构修复
situation_event = {
	id = planetmega.30
	is_triggered_only = yes
	title = planetmega_approach_cancel
	desc = planetmega.30.desc
	picture = GFX_planet_mega_mod
	immediate = { set_situation_locked = yes }
	option = {
		name = CANCEL
		default_hide_option = yes
		set_situation_locked = no
	}
	option = {
		name = OK
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}
}

###for planetmega_approach_setting
situation_event = {
	id = planetmega.250
	is_triggered_only = yes
	title = planetmega.250.name
	desc = planetmega.250.desc
	picture = GFX_evt_giant_building_in_progress
	trigger = { exists = owner }
	immediate = { set_situation_locked = yes }

	option = {
		name = planetmega.18.name
		hidden_effect = {
			set_situation_flag = triggered_by_planetmega_250
			situation_event = { id = planetmega.18 }
		}
	}
	option = {
		name = planetmega_mod.1.speed
		allow = {
			custom_tooltip = {
				fail_text = planetmega_mod.1.no_speed_repeat
				owner = { not = { has_country_flag = planetmega_const_speed_adjusting } }
			}
		}
		custom_tooltip = planetmega_mod.1.speed_tooltip
		hidden_effect = {
			save_global_event_target_as = plnmg_speed_adjusting_by_@owner
			owner = { country_event = { id = planetmega_mod.35 } }
		}
	}

	option = {
		name = DESTROY_SITUATION_NO_PARAM
		trigger = {
			OR = {
				NOT = { exists = target.owner }
				target.owner = { NOT = { is_same_value = root.owner } }
				owner = { has_country_flag = situation_destruction_quomodocunquization } #just for modders who like camellia:)
			}
		}
		destroy_situation = this
	}
	option = {
		name = OK
		hidden_effect = { set_situation_locked = no }
	}
}

# 时间线纪念
carrier_event = {
	id = planetmega.40
	is_triggered_only = yes
	hide_window = yes
	trigger = { exists = owner }
	immediate = {
        save_event_target_as = this_planet
        from = { save_event_target_as = this_deposit }
        owner = {
            if = {
                limit = {
                    can_early_build_planetmega = no
                    count_owned_colony = { limit = { has_plnmg_any_mega = yes } count = 1 }
                    not = {
                        any_owned_colony = {
                            count_deposit = { limit = { is_plnmg_any_mega = yes } count > 1 }
                        }
                    }
                }
                add_timeline_event = {
                    type = timeline_milestone
                    override_id = timeline_first_planetmega
                    override_tooltip = "TIMELINE_EVENT_FIRST_PLANETMEGA_TOOLTIP"
                    override_types = { planet deposit }
                    override_text = { "text:TIMELINE_EVENT_FIRST_PLANETMEGA" }
                    override_texture = { "background:GFX_evt_giant_building_in_progress" }
                    targets = { event_target:this_planet event_target:this_deposit }
                }
            }
            else = {
                add_timeline_event = {
                    type = timeline_empire
                    override_id = timeline_planetmega
                    override_tooltip = "TIMELINE_EVENT_PLANETMEGA_TOOLTIP"
                    override_types = { planet deposit }
                    override_text = { "text:TIMELINE_EVENT_PLANETMEGA" }
                    override_texture = { "background:GFX_evt_giant_building_in_progress" }
                    targets = { event_target:this_planet event_target:this_deposit }
                }
            }
        }
	}
}

carrier_event = {
	id = planetmega.42
	is_triggered_only = yes
	hide_window = yes
	trigger = { exists = owner }
	immediate = {
		save_event_target_as = this_planet
		from = { save_event_target_as = this_deposit }
		owner = {
			add_timeline_event = {
				type = timeline_empire
				override_id = timeline_planetmega_upgraded
				override_tooltip = "TIMELINE_EVENT_PLANETMEGA_UP_TOOLTIP"
				override_types = { planet deposit }
				override_text = { "text:TIMELINE_EVENT_PLANETMEGA_UP" }
				override_texture = { "background:GFX_evt_giant_building_in_progress" }
				targets = { event_target:this_planet event_target:this_deposit }
			}
		}
	}
}

carrier_event = {
    id = planetmega.41
    is_triggered_only = yes
    hide_window = yes
    trigger = {
        owner? = {
			not = { has_edict = planetmega_construction_no_shroud }
            or = {
                can_access_shroud = yes
                has_breached_shroud = yes
            }
        }
    }
    immediate = {
        owner = {
            if = {
                limit = {
                    is_cardinal_patron = whisperers_in_the_void
                    has_patron_relation = { patron = whisperers_in_the_void }
                }
                add_attunement = { whisperers_in_the_void = 8 }
                create_message = {
                    type = EVENT_MESSAGE_TYPE #temp
                    days = 15
                    localization = planetmega_built_witv_attunement_tt
                }
            }
            if = {
                limit = {
                    is_cardinal_patron = the_instrument_of_desire
                    has_patron_relation = { patron = the_instrument_of_desire }
                }
                add_attunement = { the_instrument_of_desire = 15 }
                create_message = {
                    type = EVENT_MESSAGE_TYPE #temp
                    days = 10
                    localization = planetmega_built_tiod_attunement_tt
                }
            }
        }
    }
}

carrier_event = {
	id = planetmega.45
	is_triggered_only = yes
	hide_window = yes
	immediate = {
        save_event_target_as = this_planet
        from = { save_event_target_as = this_deposit }
        owner? = {
            if = {
                limit = {
                    can_early_build_planetmega = no
                    count_owned_colony = { limit = { has_plnmg_any_mega = yes } count = 1 }
                    not = {
                        any_owned_colony = {
                            count_deposit = { limit = { is_plnmg_any_mega = yes } count > 1 }
                        }
                    }
                }
                add_timeline_event = {
                    type = timeline_milestone
                    override_id = timeline_first_planetmega_restored
                    override_tooltip = "TIMELINE_EVENT_FIRST_PLANETMEGA_RE_TOOLTIP"
                    override_types = { planet deposit }
                    override_text = { "text:TIMELINE_EVENT_FIRST_PLANETMEGA_RE" }
                    override_texture = { "background:GFX_evt_giant_building_in_progress" }
                    targets = { event_target:this_planet event_target:this_deposit }
                }
            }
            else = {
                add_timeline_event = {
                    type = timeline_empire
                    override_id = timeline_planetmega_restored
                    override_tooltip = "TIMELINE_EVENT_PLANETMEGA_RE_TOOLTIP"
                    override_types = { planet deposit }
                    override_text = { "text:TIMELINE_EVENT_PLANETMEGA_RE" }
                    override_texture = { "background:GFX_evt_giant_building_in_progress" }
                    targets = { event_target:this_planet event_target:this_deposit }
                }
            }
        }
	}
}

situation_event = {
	id = planetmega.49
	is_triggered_only = yes
	hide_window = yes
	trigger = { target = { check_modifier_value = { modifier = planet_building_capacity_add value > 1 } } }
	immediate = { set_situation_flag = can_use_building_capacity }
}

#局势结束中转事件
#building base
situation_event = {
	id = planetmega.50
	is_triggered_only = yes
	hide_window = yes
	situation = this

	immediate = {
		target = {
			if = {
				limit = {
					has_carrier_flag = planet_building_groundmega
					check_variable_arithmetic = {
						which = value:plnmg_mega_build_count_value
						subtract = 1
						value <= 0
					}
				}
				remove_carrier_flag = planet_building_groundmega
			}
		}
		situation_event = { id = planetmega.100 }
		situation_event = { id = planetmega.200 }
		situation_event = { id = planetmega.300 }
		situation_event = { id = planetmega.400 }
		situation_event = { id = planetmega.500 }
		situation_event = { id = planetmega.600 }
		situation_event = { id = planetmega.700 }
		situation_event = { id = planetmega.800 }
		situation_event = { id = planetmega.101 }
		situation_event = { id = planetmega.102 }
		situation_event = { id = planetmega.103 }
		situation_event = { id = planetmega.105 }
		situation_event = { id = planetmega.120 }
		situation_event = { id = planetmega.130 }
        situation_event = { id = planetmega.410 }
		situation_event = { id = planetmega.710 }
		if = {
			limit = { situation_is_plnmg_flagged = no }
			situation_event = { id = situation.1180 }
		}
	}
}

#荒野
situation_event = {
	id = planetmega.51
	is_triggered_only = yes
	hide_window = yes
	immediate = {
		target = {
			if = {
				limit = {
					has_carrier_flag = planet_building_groundmega
					check_variable_arithmetic = {
						which = value:plnmg_mega_build_count_value
						subtract = 1
						value <= 0
					}
				}
				remove_carrier_flag = planet_building_groundmega
			}
		}
		situation_event = { id = planetmega.160 }
		situation_event = { id = planetmega.150 }
		situation_event = { id = planetmega.710 }
		if = {
			limit = { situation_is_plnmg_flagged = no }
			situation_event = { id = situation.1180 }
		}
	}
}
situation_event = {
	id = planetmega.52
	is_triggered_only = yes
	hide_window = yes
	trigger = { situation_monthly_progress > 0 }
	immediate = {
		target = {
			set_variable = { which = temp_wilderness_biomass_spender value = value:sv_plnmg_sit_upkp_plus_mult }
			change_variable = { which = temp_wilderness_biomass_spender value = 1 }
			multiply_variable = { which = temp_wilderness_biomass_spender value = 10 }
			plnmg_wilderness_biomass_spender = { value = temp_wilderness_biomass_spender }
			clear_variable = temp_wilderness_biomass_spender
		}
	}
}

#upgrading
situation_event = {
	id = planetmega.60
	is_triggered_only = yes
	hide_window = yes
	situation = this

	immediate = {
		target = {
			if = {
				limit = {
					has_carrier_flag = planet_building_groundmega
					check_variable_arithmetic = {
						which = value:plnmg_mega_build_count_value
						subtract = 1
						value <= 0
					}
				}
				remove_carrier_flag = planet_building_groundmega
			}
		}
		situation_event = { id = planetmega.901 }
		situation_event = { id = planetmega.902 }
		situation_event = { id = planetmega.905 }
		situation_event = { id = planetmega.920 }
		situation_event = { id = planetmega.925 }
		situation_event = { id = planetmega.930 }
		situation_event = { id = planetmega.935 }
		situation_event = { id = planetmega.211 }
		situation_event = { id = planetmega.140 }
        situation_event = { id = planetmega.170 }
		if = {
			limit = { situation_is_plnmg_flagged = no }
			situation_event = { id = situation.1180 }
		}
	}
}

# building imp&adv
situation_event = {
	id = planetmega.70
	is_triggered_only = yes
	hide_window = yes
	situation = this

	immediate = {
		target = {
			if = {
				limit = {
					has_carrier_flag = planet_building_groundmega
					check_variable_arithmetic = {
						which = value:plnmg_mega_build_count_value
						subtract = 1
						value <= 0
					}
				}
				remove_carrier_flag = planet_building_groundmega
			}
		}
		situation_event = { id = planetmega.901 }
		situation_event = { id = planetmega.902 }
		situation_event = { id = planetmega.905 }
		situation_event = { id = planetmega.920 }
		situation_event = { id = planetmega.925 }
		situation_event = { id = planetmega.930 }
		situation_event = { id = planetmega.935 }
		situation_event = { id = planetmega.211 }
		#
		situation_event = { id = planetmega.950 }
		situation_event = { id = planetmega.960 }
		situation_event = { id = planetmega.970 }
		situation_event = { id = planetmega.980 }
        situation_event = { id = planetmega.180 }
		#
		if = {
			limit = { situation_is_plnmg_flagged = no }
			situation_event = { id = situation.1180 }
		}
	}
}

# restoration situation
situation_event = {
	id = planetmega.80
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		situation_event = { id = planetmega.901 }
		situation_event = { id = planetmega.902 }
		situation_event = { id = planetmega.905 }
		situation_event = { id = planetmega.920 }
		situation_event = { id = planetmega.925 }
		situation_event = { id = planetmega.930 }
		situation_event = { id = planetmega.935 }
		situation_event = { id = planetmega.211 }
		situation_event = { id = planetmega.140 }
		if = {
			limit = { situation_is_plnmg_flagged = no }
			situation_event = { id = situation.1180 }
		}
	}
}

#unused now
country_event = {
	id = planetmega.90
	is_triggered_only = yes
	hide_window = yes
	trigger = { always = no }
	immediate = {
	}
}

situation_event = {
	id = planetmega.99
	is_triggered_only = yes
	hide_window = yes
	immediate = {
		sit_dismantle_plnmg_mega_effect = yes
		situation_event = { id = planetmega.9 }
	}
}

# giant power battery
situation_event = {
	id = planetmega.100
	title = planetmega.100.name
	desc = planetmega.100.desc
	picture = GFX_evt_complete_giant_power_battery
	show_sound = event_construction
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { has_situation_flag = building_giant_power_battery }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = giant_power_battery on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = { # hooray
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_giant_power_battery } }
	}
}

# advanced forge
situation_event = {
	id = planetmega.200
	title = planetmega.200.name
	desc = planetmega.200.desc
	picture = GFX_evt_complete_advanced_forge
	show_sound = event_construction
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { has_situation_flag = building_advanced_forge }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = advanced_forge on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = { # hooray
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_advanced_forge } }
	}
}

# great laboratory
situation_event = {
	id = planetmega.300
	title = planetmega.300.name
	desc = planetmega.300.desc
	picture = GFX_evt_complete_great_laboratory
	show_sound = event_laboratory_sound
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { has_situation_flag = building_great_laboratory }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = great_laboratory on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = { # hooray
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_great_laboratory } }
	}
}

# heaven colossal
situation_event = {
	id = planetmega.400
	title = planetmega.400.name
	desc = planetmega.400.desc
	picture = GFX_evt_complete_heaven_colossal
	#show_sound = event_mysterious_signal
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { has_situation_flag = building_heaven_colossal }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = heaven_colossal on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = { # hooray
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_heaven_colossal } }
	}
}

country_event = {
	id = planetmega.401
	is_triggered_only = yes
	hide_window = yes
	immediate = { country_event = { id = planetmega.402 days = 2 } }
}
country_event = {
    id = planetmega.402
    is_triggered_only = yes
    hide_window = yes
    immediate = {
        if = {
            limit = { can_build_hakkou_ichiu_tower = yes }
            set_variable = { which = var_plnmg_conquered_planets value = value:count_plnmg_conquered_planets }
        }
        else = {
            ordered_owned_colony = {
                position = 0
                order_by = trigger:free_amenities
                inverse = no
                owner = { set_variable = { which = temp_highest_plnt_amenities value = prev.trigger:free_amenities } }
            }
            ordered_owned_colony = {
                position = 0
                order_by = trigger:free_amenities
                inverse = yes
                owner = { set_variable = { which = temp_lowest_plnt_amenities value = prev.trigger:free_amenities } }
            }
            set_variable = { which = var_plnmg_amenities_hc value = value:sv_plnmg_amenities_hc }
        }
    }
}
carrier_event = {
    id = planetmega.403
    is_triggered_only = yes
    hide_window = yes
    trigger = { fromfrom = { is_plnmg_regular_empire = yes } }
    immediate = { fromfrom = { country_event = { id = planetmega.402 } } }
}
carrier_event = {
    id = planetmega.405
    is_triggered_only = yes
    hide_window = yes
    trigger = { from = { is_plnmg_regular_empire = yes } }
    immediate = { from = { country_event = { id = planetmega.402 } } }
}

carrier_event = {
    id = planetmega.406
    hide_window = yes
    is_triggered_only = yes
    trigger = {
        from = {
            can_build_hakkou_ichiu_tower = yes
            any_owned_colony = { has_deposit = d_hakkou_ichiu_tower }
        }
    }
    immediate = {
        from = {
            initialize_mys_variable = { VAR = var_plnmg_purged_pops }
            owner = { change_variable = { which = var_plnmg_purged_pops value = root.value:per_100_local_pop_amount } }
        }
    }
}
pop_group_event = {
    id = planetmega.407
    hide_window = yes
    is_triggered_only = yes
    trigger = {
        owner? = {
            can_build_hakkou_ichiu_tower = yes
            any_owned_colony = { has_deposit = d_hakkou_ichiu_tower }
        }
    }
    immediate = {
        export_trigger_value_to_variable = {
            trigger = pop_group_size
            variable = temp_pop_amount_var
        }
        divide_variable = { which = temp_pop_amount_var value = 5 }
        floor_variable = temp_pop_amount_var
        owner = { initialize_mys_variable = { VAR = var_plnmg_purged_pops } }
        owner = { change_variable = { which = var_plnmg_purged_pops value = temp_pop_amount_var } }
        clear_variable = temp_pop_amount_var
    }
}
carrier_event = {
    id = planetmega.408
    hide_window = yes
    is_triggered_only = yes
    trigger = {
        from = {
            can_build_hakkou_ichiu_tower = yes
            any_owned_colony = { has_deposit = d_hakkou_ichiu_tower }
        }
    }
    immediate = {
        set_variable = { which = var_pop_bombed_temp value = local_kill_pop_amount }
        divide_variable = { which = var_pop_bombed_temp value = 2 }
        floor_variable = var_pop_bombed_temp
        owner = { initialize_mys_variable = { VAR = var_plnmg_purged_pops } }
        owner = { change_variable = { which = var_plnmg_purged_pops value = var_pop_bombed_temp } }
        clear_variable = var_pop_bombed_temp
    }
}
carrier_event = {
    id = planetmega.409
    hide_window = yes
    is_triggered_only = yes
    trigger = {
        from = {
            can_build_hakkou_ichiu_tower = yes
            any_owned_colony = { has_deposit = d_hakkou_ichiu_tower }
        }
    }
    immediate = {
        from = {
            initialize_mys_variable = { VAR = var_plnmg_cracked_planets }
            owner = { change_variable = { which = var_plnmg_cracked_planets value = 1 } }
        }
    }
}

situation_event = {
    id = planetmega.410
    title = planetmega.410.name
    desc = planetmega.410.desc
    picture = GFX_evt_complete_hakkou_ichiu
    show_sound = event_salute
    is_triggered_only = yes
    situation = this
    location = target
    trigger = { has_situation_flag = building_hakkou_ichiu_tower }
    immediate = {
        set_situation_locked = yes
        target = { add_plnmg_mega = { TYPE = hakkou_ichiu_tower on_actions = yes } }
    }
    after = {
        hidden_effect = { set_situation_locked = no }
        destroy_situation = this
    }

    option = { # hooray
        name = EXCELLENT
        tooltip = { target = { add_deposit = d_hakkou_ichiu_tower } }
    }
}


# commercial shikara
situation_event = {
	id = planetmega.500
	title = planetmega.500.name
	desc = planetmega.500.desc
	picture = GFX_evt_complete_commercial_shikara
	show_sound = event_galactic_community
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { has_situation_flag = building_commercial_shikara }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = commercial_shikara on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = { # hooray
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_commercial_shikara } }
	}
}

# centralized manufactory 
situation_event = {
	id = planetmega.600
	title = planetmega.600.name
	desc = planetmega.600.desc
	picture = GFX_evt_complete_centralized_manufactory 
	show_sound = event_construction
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { has_situation_flag = building_centralized_manufactory }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = centralized_manufactory on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = { # hooray
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_centralized_manufactory } }
	}
}

# war headquarter
situation_event = { # no carrier
	id = planetmega.700
	title = planetmega.700.name
	desc = planetmega.700.desc
	picture = GFX_evt_complete_war_headquarter
	show_sound = event_ground_battle
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { has_situation_flag = building_war_headquarter }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = war_headquarter on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = { # hooray
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_war_headquarter } }
	}
}

situation_event = { #no carrier
	id = planetmega.710
	title = planetmega.710.name
	desc = planetmega.710.desc
	picture = GFX_evt_planetmega_hive_fortress
	show_sound = event_ground_battle
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { has_situation_flag = building_resistance_organ }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = resistance_organ on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = { # hooray
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_resistance_organ } }
	}
}

# primary mind pyramid
situation_event = {
	id = planetmega.800
	title = planetmega.800.name
	desc = planetmega.800.desc
	picture = GFX_evt_complete_primary_mind_pyramid
	show_sound = event_machinery
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { has_situation_flag = building_primary_mind_pyramid }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = primary_mind_pyramid on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = { # hooray
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_primary_mind_pyramid } }
        hidden_effect = {
            target = {
                if = {
                    limit = { is_capital = yes }
                    set_carrier_flag = built_capital_pm_admin
                }
            }
        }
	}
}

# used with unity_tag_jobs_offspring_antineg_mult, not done yet
country_event = {
	id = planetmega.801
	is_triggered_only = yes
	hide_window = yes
	trigger = {
		always = no
		# has_origin = origin_progenitor_hive
		# any_owned_colony = {
		# 	not = {
		# 		check_modifier_value = {
		# 			modifier = unity_tag_jobs_offspring_antineg_mult
		# 			value = 0
		# 		}
		# 	}
		# }
	}
	immediate = { country_event = { id = planetmega.802 days = 2 } }
}

# not done yet
country_event = {
	id = planetmega.802
	is_triggered_only = yes
	hide_window = yes
	trigger = { has_origin = origin_progenitor_hive }
	immediate = {
		#
	}
}

# matter demodulator
situation_event = {
	id = planetmega.101
	title = planetmega.101.name
	desc = planetmega.101.desc
	picture = GFX_evt_mining_operations
	show_sound = event_construction
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { has_situation_flag = building_matter_demodulator }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = matter_demodulator on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = { # hooray
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_matter_demodulator } }
	}
}

carrier_event = {
	id = planetmega.110
	is_triggered_only = yes
	hide_window = yes
	trigger = {
		or = {
			has_deposit = d_matter_demodulator
            has_deposit = d_plnmg_singularity_generator
			has_carrier_flag = planet_has_matter_demodulator
            has_carrier_flag = planet_has_plnmg_singularity_generator
		}
	}
	immediate = {
        if = {
            limit = { check_modifier_value = { modifier = planet_miners_volatile_motes_produces_add value > 0 } }
            set_variable = {
                which = var_plnmg_miners_volatile_motes_produce_mult
                value = value:plnmg_miners_resource_produce_mult|type|volatile_motes|
            }
        }
        if = {
            limit = { check_modifier_value = { modifier = planet_miners_exotic_gases_produces_add value > 0 } }
            set_variable = {
                which = var_plnmg_miners_exotic_gases_produce_mult
                value = value:plnmg_miners_resource_produce_mult|type|exotic_gases|
            }
        }
        if = {
            limit = { check_modifier_value = { modifier = planet_miners_rare_crystals_produces_add value > 0 } }
            set_variable = {
                which = var_plnmg_miners_rare_crystals_produce_mult
                value = value:plnmg_miners_resource_produce_mult|type|rare_crystals|
            }
        }
    }
}
carrier_event = {
	id = planetmega.111
	is_triggered_only = yes
	hide_window = yes
	trigger = {
		or = {
			has_active_building = building_planetmega_refinery
			has_active_building = building_planetmega_chemical
			has_active_building = building_planetmega_crystal
		}
	}
	immediate = { refresh_plnmg_plnt_minerals_prod_var = yes }
}

# vertical farm edifice
situation_event = {
	id = planetmega.102
	title = planetmega.102.name
	desc = planetmega.102.desc
	picture = GFX_evt_complete_vertical_farm_edifice 
	show_sound = event_construction
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { has_situation_flag = building_vertical_farm_edifice }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = vertical_farm_edifice on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = { # hooray
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_vertical_farm_edifice } }
	}
}

# Hive Farm
situation_event = {
	id = planetmega.103
	title = planetmega.103.name
	desc = planetmega.103.desc
	picture = GFX_evt_complete_hive_farm_edifice 
	show_sound = event_swarm
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { has_situation_flag = building_hive_farm_edifice }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = hive_farm_edifice on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = { # hooray
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_hive_farm_edifice } }
	}
}

# admin axis
situation_event = {
	id = planetmega.105
	is_triggered_only = yes
	title = planetmega.105.name
	desc = planetmega.105.desc
	picture = GFX_evt_government_complex
	show_sound = event_construction
	trigger = { has_situation_flag = building_admin_axis }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = admin_axis on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = {
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_admin_axis } }
        hidden_effect = {
            target = {
                if = {
                    limit = { is_capital = yes }
                    set_carrier_flag = built_capital_pm_admin
                }
            }
        }
	}
}

country_event = {
	id = planetmega.106
	is_triggered_only = yes
	hide_window = yes
	trigger = {
		any_owned_colony = {
			not = {
				check_modifier_value = {
					modifier = unity_tag_jobs_empire_size_add
					value = 0
				}
			}
		}
	}
	immediate = { country_event = { id = planetmega.107 days = 1 } }
}

country_event = {
	id = planetmega.107
	is_triggered_only = yes
	hide_window = yes
	immediate = {
		set_variable = { which = empire_size_change_count value = 0 }
		every_owned_colony = {
			limit = {
				not = {
					check_modifier_value = {
						modifier = unity_tag_jobs_empire_size_add
						value = 0
					}
				}
			}
			export_trigger_value_to_variable = {
				trigger = total_workforce_with_job_tag
				parameters = { tags = { unity } }
				variable = empire_size_change_plnt_count
			}
			multiply_variable = { which = empire_size_change_plnt_count value = modifier:unity_tag_jobs_empire_size_add }
			prev = {
				change_variable = {
					which = empire_size_change_count
					value = prev.empire_size_change_plnt_count
				}
			}
			clear_variable = empire_size_change_plnt_count
		}
		divide_variable = { which = empire_size_change_count value = 100 } #4.0 compat
		update_modifier_amount_if_needed = {
			MODIFIER = empire_size_add_by_unity_tag_jobs
			MULT_VAR = empire_size_change_count
			PREV_MULT_VAR = empire_size_change_count_old
		}
	}
}

#ecodome
situation_event = {
	id = planetmega.120
	is_triggered_only = yes
	title = planetmega.120.name
	desc = planetmega.120.desc
	picture = GFX_evt_planetmega_ecodome_complex
	show_sound = event_construction
	trigger = { has_situation_flag = building_ecodome_complex }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = ecodome_complex on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = {
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_ecodome_complex } }
	}
}

#logistics
situation_event = {
	id = planetmega.130
	is_triggered_only = yes
	title = planetmega.130.name
	desc = planetmega.130.desc
	picture = GFX_evt_planetmega_logistics_building
	show_sound = event_construction
	trigger = { has_situation_flag = building_logistics_shikara }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = logistics_shikara on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = {
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_logistics_shikara } }
	}
}

#荒野
situation_event = {
	id = planetmega.150
	is_triggered_only = yes
	title = planetmega.150.name
	desc = planetmega.150.desc
	picture = GFX_evt_wilderness_colonizer
	show_sound = event_construction
	trigger = { has_situation_flag = building_plnmg_wilderness_flora }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = plnmg_wilderness_flora on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = {
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_plnmg_wilderness_flora } }
	}
}
situation_event = {
	id = planetmega.160
	is_triggered_only = yes
	title = planetmega.160.name
	desc = planetmega.160.desc
	picture = GFX_evt_planetmega_wildterra
	show_sound = event_construction
	trigger = { has_situation_flag = building_plnmg_wilderness_terra }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = plnmg_wilderness_terra on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = {
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_plnmg_wilderness_terra } }
	}
}

# Singularity Generator
situation_event = {
	id = planetmega.901
	title = planetmega.901.name
	desc = planetmega.901.desc
	picture = GFX_evt_complete_matter_demodulator 
	#show_sound = event_mysterious_signal
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { has_situation_flag = building_plnmg_singularity_generator }

	immediate = {
		set_situation_locked = yes
		target = {
			if = {
				limit = {
					nor = {
						has_carrier_flag = planet_has_plnmg_singularity_generator
						has_carrier_flag = plnmg_all_energy_prod
						has_carrier_flag = plnmg_all_matter_prod
					}
				}
				set_variable = { which = plnmg_temp_energy_count value = 0 }
				every_deposit = {
					limit = { is_deposit_type = d_giant_power_battery }
					prev = { change_variable = { which = plnmg_temp_energy_count value = 1 } }
				}
				set_variable = { which = plnmg_temp_matter_count value = 0 }
				every_deposit = {
					limit = { is_deposit_type = d_matter_demodulator }
					prev = { change_variable = { which = plnmg_temp_matter_count value = 1 } }
				}
				if = {
					limit = {
						check_variable = {
							which = plnmg_temp_energy_count
							value > plnmg_temp_matter_count
						}
					}
					set_carrier_flag = plnmg_all_energy_prod
				}
				else_if = {
					limit = {
						check_variable = {
							which = plnmg_temp_matter_count
							value > plnmg_temp_energy_count
						}
					}
					set_carrier_flag = plnmg_all_matter_prod
				}
				else = {
					random_list = {
						1 = { set_carrier_flag = plnmg_all_energy_prod }
						1 = { set_carrier_flag = plnmg_all_matter_prod }
					}
                    reroll_random = yes
				}
				clear_variable = plnmg_temp_energy_count
				clear_variable = plnmg_temp_matter_count
			}
		}
		target = { remove_plnmg_mega = { TYPE = giant_power_battery } }
		target = { remove_plnmg_mega = { TYPE = matter_demodulator } }
		target = { add_plnmg_mega = { TYPE = plnmg_singularity_generator on_actions = yes } }
	}

	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = { # hooray
		name = EXCELLENT
		tooltip = {
			target = {
				add_deposit = d_plnmg_singularity_generator
				if = {
					limit = { hidden_trigger = { has_carrier_flag = plnmg_all_energy_prod } }
					remove_deposit = d_giant_power_battery
				}
				if = {
					limit = { hidden_trigger = { has_carrier_flag = plnmg_all_matter_prod } }
					remove_deposit = d_matter_demodulator
				}
			}
		}
	}
}

situation_event = {
	id = planetmega.903
	is_triggered_only = yes
	hide_window = yes
	situation = this

	trigger = {
		has_situation_flag = building_plnmg_singularity_generator
		situation_monthly_progress > 0
	}
	immediate = {
		switch = {
			trigger = is_situation_type
			planet_megastructure_upgrading = {
				switch = {
					trigger = current_stage
					stage_2 = {
						owner = {
							add_resource = {
								sr_dark_matter = 1
								mult = value:scripted_modifier_mult|MODIFIER|country_sr_dark_matter_produces_mult|
							}
						}
					}
					stage_3 = {
						owner = {
							add_resource = {
								sr_dark_matter = 5
								mult = value:scripted_modifier_mult|MODIFIER|country_sr_dark_matter_produces_mult|
							}
						}
					}
					stage_4 = {
						owner = {
							add_resource = {
								sr_dark_matter = 10
								mult = value:scripted_modifier_mult|MODIFIER|country_sr_dark_matter_produces_mult|
							}
						}
					}
					default = {}
				}
				# random_list = {
				# 	99 = {}
				# 	1 = {
				# 		random_list = {
				# 			1 = {
				# 				target = { carrier_event = { id = planetmega.915 } }
				# 			}
				# 			1 = {
				# 				situation_event = { id = planetmega.916 }
				# 			}
				# 		}
				# 	}
				# }
			}
			planet_megastructure_restoration = {
				owner = {
					add_resource = {
						sr_dark_matter = 1
						mult = value:scripted_modifier_mult|MODIFIER|country_sr_dark_matter_produces_mult|
					}
				}
				random_list = {
					199 = {}
					1 = {
						random_list = {
							1 = { target = { carrier_event = { id = planetmega.915 } } }
							1 = { situation_event = { id = planetmega.916 } }
						}
					}
				}
			}
			default = {}
		}
        reroll_random = yes
	}
}

carrier_event = {
	id = planetmega.915
	title = planetmega.915.name
	desc = planetmega.915.desc
	picture = GFX_evt_complete_matter_demodulator 
	show_sound = event_mysterious_signal
	is_triggered_only = yes
	location = root

	option = {
		name = EXCELLENT
		owner = {
			add_resource = {
				sr_dark_matter = 100
				minerals = 3000
				energy = 5000
			}
		}
	}
}

situation_event = {
	id = planetmega.916
	title = planetmega.916.name
	desc = planetmega.916.desc
	picture = GFX_evt_complete_matter_demodulator 
	show_sound = event_mysterious_signal
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { situation_progress > @plnmg_progress_add_big }
	immediate = {
		add_situation_progress = @plnmg_progress_subtract_big
		target = {
			random_owned_pop_group = {
				limit = { pop_group_size > 100 }
				kill_single_pop = yes
			}
		}
	}

	option = {
		name = CURSES
		tooltip = {
			add_situation_progress = @plnmg_progress_subtract_big
			target = {
				random_owned_pop_group = {
					limit = { pop_group_size > 100 }
					kill_single_pop = yes
				}
			}
		}
	}
}

# Bore of the Shroud
situation_event = {
	id = planetmega.902
	title = planetmega.902.name
	desc = planetmega.902.desc
	picture = GFX_evt_complete_plnmg_bore_of_the_shroud 
	show_sound = event_shroud_song
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { has_situation_flag = building_plnmg_bore_of_the_shroud }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = plnmg_bore_of_the_shroud on_actions = yes } }
		owner = { set_country_flag = has_plnmg_bore_of_the_shroud }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = { # hooray
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_plnmg_bore_of_the_shroud } }
	}
}

situation_event = {
	id = planetmega.904
	is_triggered_only = yes
	hide_window = yes
	situation = this
	trigger = {
		has_situation_flag = building_plnmg_bore_of_the_shroud
		situation_monthly_progress > 0
	}

	immediate = {
		switch = {
			trigger = is_situation_type
			planet_megastructure_constimp = {
				switch = {
					trigger = current_stage
					stage_2 = {
						owner = {
							add_resource = {
								sr_zro = 1
								mult = value:scripted_modifier_mult|MODIFIER|country_sr_zro_produces_mult|
							}
						}
					}
					stage_3 = {
						owner = {
							add_resource = {
								sr_zro = 3
								mult = value:scripted_modifier_mult|MODIFIER|country_sr_zro_produces_mult|
							}
						}
					}
					stage_4 = {
						owner = {
							add_resource = {
								sr_zro = 5
								mult = value:scripted_modifier_mult|MODIFIER|country_sr_zro_produces_mult|
							}
						}
					}
					default = {}
				}
				# random = {
				# 	chance = 1
				# 	random_list = {
				# 		1 = { target = { carrier_event = { id = planetmega.910 } } }
				# 		1 = { target = { carrier_event = { id = planetmega.911 } } }
				# 	}
				# }
			}
			planet_megastructure_restoration = {
				owner = {
					add_resource = {
						sr_zro = 1
						mult = value:scripted_modifier_mult|MODIFIER|country_sr_zro_produces_mult|
					}
				}
				random = {
					chance = 1
					random_list = {
						1 = { target = { carrier_event = { id = planetmega.910 } } }
						1 = { target = { carrier_event = { id = planetmega.911 } } }
					}
				}
			}
			default = {}
		}
        reroll_random = yes
	}
}

carrier_event = { # Bless
	id = planetmega.910
	title = planetmega.910.name
	desc = planetmega.910.desc
	picture = GFX_evt_complete_plnmg_bore_of_the_shroud 
	show_sound = event_mysterious_signal
	is_triggered_only = yes
	location = root

	option = {
		name = EXCELLENT
		custom_tooltip = planetmega.910.great.desc
		hidden_effect = {
			owner = {
				random_list = {
					1 = { # ship
						random_list = {
							1 = { 
								add_modifier = {
									modifier = "shroud_speed"
									days = 1000
								}
								add_modifier = {
									modifier = "shroud_sensors"
									days = 1000
								}
							}
							1 = { 
								add_modifier = {
									modifier = "shroud_shield_boost"
									days = 1000
								}
								add_modifier = {
									modifier = "shroud_weapon_boost"
									days = 1000
								}
								add_modifier = {
									modifier = "shroud_firing_rate"
									days = 1000
								}
							} 
							1 = { 
								add_modifier = {
									modifier = "shroud_ship_upkeep"
									days = 1000
								}
								add_modifier = {
									modifier = "shroud_evasion"
									days = 1000
								}
								add_modifier = {
									modifier = "shroud_repair"
									days = 1000
								}
							}
						}
					}
					1 = { # empire
						random_list = {
							50 = {
								add_modifier = {
									modifier = "shroud_happiness"
									days = 1000
								}
								add_modifier = {
									modifier = "shroud_influence_boost"
									days = 1000
								}
								add_modifier = {
									modifier = "shroud_unity_boost"
									days = 1000
								}
							}
							49 = {
								add_modifier = {
									modifier = "shroud_research_speed"
									days = 1000
								}
							}
							1 = {
								every_owned_leader = {
									limit = { leader_age > 20 }
									set_age = 18
								}
							}
						}
					}
				}
                reroll_random = yes
			}
			create_army = {
				name = "NAME_Avatar"
				owner = root.owner
				type = "shroud_army"
			}
			create_fleet = {
				name = "NAME_Psionic_Avatar"
				settings = {
					can_upgrade = no
					can_change_composition = no
					can_change_leader = no
					uses_naval_capacity = no
					spawn_debris = no
				}
				effect = {
					set_owner = root.owner
					create_ship = {
						name = "NAME_Avatar"
						design = "NAME_Shroud_Avatar"
						prefix = no
						upgradable = no
					}
					set_location = root
				}
			}
		}
	}
}

carrier_event = { # Curse
	id = planetmega.911
	title = planetmega.911.name
	desc = planetmega.911.desc
	picture = GFX_evt_complete_plnmg_bore_of_the_shroud 
	show_sound = event_mysterious_signal
	is_triggered_only = yes
	location = root

	immediate = {
		if = {
			limit = { NOT = { exists = event_target:shroud_country } }
			create_country = {
				name = "NAME_Creatures_of_the_Shroud"
				type = shroud_spirits
				flag = {
					icon = {
						category = "special"
						file = "the_shroud.dds"
					}
					background= {
						category = "backgrounds"
						file = "00_solid.dds"
					}
					colors={
						"dark_purple"
						"black"
						"null"
					}
				}
				effect = {
					establish_communications_no_message = root.owner
					save_global_event_target_as = shroud_country
				}
			}
		}
		owner = {
			random_list = {
				1 = { # ship
					random_list = {
						1 = { 
						    add_modifier = {
							    modifier = "shroud_neg_speed"
							    days = 1000
						    }
				        }
						1 = {
							add_modifier = {
								modifier = "shroud_neg_sensors"
								days = 1000
							}
						}
				        1 = { 
						    add_modifier = {
							    modifier = "shroud_neg_armor"
							    days = 1000
						    }
				        } 
					}
				}
				1 = { # empire
					random_list = {
						5 = {
							add_modifier = {
								modifier = "shroud_neg_happiness"
								days = 1000
							}
							add_modifier = {
								modifier = "shroud_neg_growth"
								days = 1800
							}
						}
						6 = {
							add_modifier = {
								modifier = "shroud_neg_influence"
								days = 1000
							}
							add_modifier = {
								modifier = "shroud_neg_unity"
								days = 1000
							}
						}
						9 = {
							add_modifier = {
								modifier = "shroud_neg_research"
								days = 1000
							}
						}
					}
				}
			}
            reroll_random = yes
		}
		create_fleet = {
			name = "NAME_Corrupted_Avatar"
			settings = {
				spawn_debris = no
				is_boss = yes
			}
			effect = {
				set_owner = event_target:shroud_country
				create_ship = {
					name = "NAME_Corrupted_Avatar"
					design = "NAME_Corrupted_Avatar"
				}
				set_location = root
				set_fleet_stance = aggressive
				set_aggro_range_measure_from = return_point
				set_aggro_range = 300
			}
		}
		last_created_fleet = { # Despawn if enough time passes without being destroyed
			fleet_event = { id = utopia.3025 days = 3600 }
		}
	}

	option = {
		name = planetmega.911.fxxk
		custom_tooltip = planetmega.911.fxxk.desc
	}
}

country_event = {
	id = planetmega.912
	is_triggered_only = yes
	hide_window = yes
	trigger = {
		is_ai = no
		from? = { is_country_type = shroud }
		nor = {
			has_special_project = PLANETMEGA_PROJECT_SHROUD_BORE
			has_country_flag = plnmg_shroud_bore_enabled
		}
	}
	immediate = {
		if = {
			limit = { not = { has_country_flag = planetmega_913_ready } }
			country_event = {
				id = planetmega.913
				days = 1000
				random = 500
			}
			set_country_flag = planetmega_913_ready
		}
	}
}
country_event = {
	id = planetmega.913
	is_triggered_only = yes
	title = planetmega.913.name
	desc = planetmega.913.desc
	picture = GFX_evt_complete_plnmg_bore_of_the_shroud
	trigger = {
		nor = {
			has_special_project = PLANETMEGA_PROJECT_SHROUD_BORE
			has_country_flag = plnmg_shroud_bore_enabled
		}
	}
	option = {
		name = OK
		capital_scope = { enable_special_project = { name = PLANETMEGA_PROJECT_SHROUD_BORE } }
		hidden_effect = { remove_country_flag = planetmega_913_ready }
	}
}
country_event = {
	id = planetmega.914
	is_triggered_only = yes
	title = planetmega.914.name
	desc = planetmega.914.desc
	picture = GFX_evt_complete_plnmg_bore_of_the_shroud
	option = {
		name = OK
		hidden_effect = {
			if = {
				limit = { not = { has_country_flag = plnmg_shroud_bore_enabled } }
				set_country_flag = plnmg_shroud_bore_enabled
			}
		}
	}
}

# Maginot Nexus
situation_event = { #no carrier
	id = planetmega.905
	title = planetmega.905.name
	desc = planetmega.905.desc
	picture = GFX_evt_complete_war_headquarter
	show_sound = event_ground_battle
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { has_situation_flag = building_plnmg_maginot_nexus }
	immediate = {
		set_situation_locked = yes
		target = { remove_plnmg_mega = { TYPE = war_headquarter } }
		target = { remove_plnmg_mega = { TYPE = resistance_organ } }
		target = { add_plnmg_mega = { TYPE = plnmg_maginot_nexus on_actions = yes } }
		target = { carrier_event = { id = planetmega.906 days = 1 } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = { # hooray
		name = EXCELLENT
		#custom_tooltip = plnmg_maginot_nexus_desc
		tooltip = {
			target = {
				add_deposit = d_plnmg_maginot_nexus
				if = {
					limit = { hidden_trigger = { is_wilderness_empire = yes } }
					remove_deposit = d_resistance_organ
				}
				else = { remove_deposit = d_war_headquarter }
			}
		}
	}
}

#yearly (temporarily abandoned)
carrier_event = {
	id = planetmega.906
	is_triggered_only = yes
	hide_window = yes
	trigger = {
		always = no
		# or = {
		# 	has_deposit = d_plnmg_maginot_nexus
		# 	has_carrier_flag = planet_has_plnmg_maginot_nexus
		# }
	}
	immediate = {
		#
	}
}

#反制戴森炮 #triggered via on_dyson_shoot #not available for nomadic empires
system_event = {
	id = planetmega.907
	is_triggered_only = yes
	hide_window = yes
	trigger = {
		any_system_planet_colony = {
			#owner = { not = { has_technology = tech_plnmg_dyson_redirection } }
			or = {
				has_deposit = d_plnmg_maginot_nexus
				has_carrier_flag = planet_has_plnmg_maginot_nexus
			}
		}
	}
	immediate = {
		random_system_planet_colony = {
			limit = {
				or = {
					has_deposit = d_plnmg_maginot_nexus
					has_carrier_flag = planet_has_plnmg_maginot_nexus
				}
				#owner = { not = { has_technology = tech_plnmg_dyson_redirection } }
			}
			owner = {
				create_message = {
					type = MESSAGE_DYSON_SHOT
					localization = MESSAGE_DYSON_SHOT_PMRE_PREP_DESC
					days = 15 #@toast_message_days
					target = root.from.solar_system
					variable = { type = name localization = SYSTEM scope = root.from.solar_system }
				}
			}
		}
		from.owner = {
			set_variable = { which = dyson_gun_damage_reflection value = dyson_gun_damage }
			subtract_variable = { which = dyson_gun_damage_reflection value = dyson_gun_damage_shielded }
			create_message = {
				type = MESSAGE_DYSON_SHOT
				localization = MESSAGE_DYSON_SHOT_PMRE_VIC_DESC
				days = 10 #@toast_message_days
				target = root
				variable = { type = name localization = SYSTEM scope = root }
			}
		}
		from.solar_system = {
			every_ship_in_system = {
				damage_ship = {
					amount = root.from.owner.dyson_gun_damage_reflection
					attacker = root.from.owner
				}
			}
			if = {
				limit = { root.from.owner = { has_country_flag = dyson_gun_devastating_shot } }
				every_system_planet_colony = {
					if = {
						limit = { has_planetary_shield_building = yes }
						add_planet_devastation = 1
					}
					else = { add_planet_devastation = 10 }
				}
			}
		}
	}
}

situation_event = {
	id = planetmega.920
	title = planetmega.920.name
	desc = planetmega.920.desc
	picture = GFX_evt_complete_vertical_farm_edifice
	show_sound = event_construction
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { has_situation_flag = building_plnmg_advanced_agriculture_edifice }
	immediate = {
		set_situation_locked = yes
		target = { remove_plnmg_mega = { TYPE = vertical_farm_edifice } }
		target = { add_plnmg_mega = { TYPE = plnmg_advanced_agriculture_edifice on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = { # hooray
		name = EXCELLENT
		tooltip = {
			target = {
				remove_deposit = d_vertical_farm_edifice
				add_deposit = d_plnmg_advanced_agriculture_edifice
			}
		}
	}
}

carrier_event = { #monthly
	id = planetmega.921
	is_triggered_only = yes
	hide_window = yes
	trigger = {
		exists = owner
		or = {
			has_deposit = d_plnmg_advanced_agriculture_edifice
			has_carrier_flag = planet_has_plnmg_advanced_agriculture_edifice
		}
	}
	immediate = {
        carrier_event = { id = planetmega.922 days = 5 }
    }
}
carrier_event = {
	id = planetmega.922
	is_triggered_only = yes
	hide_window = yes
	trigger = { exists = owner }
	immediate = {
		initialize_mys_variable = { VAR = num_plnmg_usable_bodies }
		initialize_mys_variable = { VAR = num_plnmg_unfiltered_bodies }
		change_variable = {
			which = num_plnmg_unfiltered_bodies
			value = value:sv_plnmg_subject_monthly_add
		}
		while = {
			#limit = { check_variable = { which = num_plnmg_unfiltered_bodies value >= 100 } }
			count = value:sv_plnmg_subject_assembly_convert_passes
			change_variable = { which = num_plnmg_usable_bodies value = 1 }
			subtract_variable = { which = num_plnmg_unfiltered_bodies value = 100 }
		}
		refresh_plnmg_white_mice_traits = yes
	}
}

situation_event = {
	id = planetmega.925
	title = planetmega.925.name
	desc = planetmega.925.desc
	picture = GFX_evt_complete_hive_farm_edifice
	show_sound = event_swarm
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { has_situation_flag = building_plnmg_gene_farm_hive }
	immediate = {
		set_situation_locked = yes
		target = { remove_plnmg_mega = { TYPE = hive_farm_edifice } }
		target = { add_plnmg_mega = { TYPE = plnmg_gene_farm_hive on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = { # hooray
		name = EXCELLENT
		tooltip = {
			target = {
				remove_deposit = d_hive_farm_edifice
				add_deposit = d_plnmg_gene_farm_hive
			}
		}
	}
}

carrier_event = { #monthly
	id = planetmega.926
	is_triggered_only = yes
	hide_window = yes
	trigger = {
		or = {
			has_deposit = d_plnmg_gene_farm_hive
			has_carrier_flag = planet_has_plnmg_gene_farm_hive
		}
		owner? = { is_hive_empire = yes }
	}
	immediate = {
        carrier_event = { id = planetmega.922 days = 5 }
    }
}
# carrier_event = { # why I wrote a duplicate event before?
# 	id = planetmega.927
# 	is_triggered_only = yes
# 	hide_window = yes
# 	pre_triggers = { has_owner = yes }
# 	immediate = {
# 		initialize_mys_variable = { VAR = num_plnmg_usable_bodies }
# 		initialize_mys_variable = { VAR = plnmg_subject_assembly_organic_point }
# 		planet = {
# 			change_variable = {
# 				which = plnmg_subject_assembly_organic_point
# 				value = value:sv_plnmg_subject_monthly_add
# 			}
# 			while = {
# 				limit = { check_variable = { which = plnmg_subject_assembly_organic_point value >= 100 } }
# 				change_variable = { which = num_plnmg_usable_bodies value = 1 }
# 				subtract_variable = { which = plnmg_subject_assembly_organic_point value = 100 }
# 			}
# 			refresh_plnmg_white_mice_traits = yes
# 		}
# 	}
# }

situation_event = {
	id = planetmega.930
	is_triggered_only = yes
	situation = this
	location = target
	title = planetmega.930.name
	picture = GFX_evt_planetmega_supercom
	show_sound = event_laboratory_sound
	trigger = { has_situation_flag = building_plnmg_supercom }
	desc = {
		trigger = { is_situation_type = planet_megastructure_constimp }
		text = planetmega.930.desc.built
	}
	desc = {
		trigger = { is_situation_type = planet_megastructure_upgrading }
		text = planetmega.930.desc.upgraded
	}

	immediate = {
		set_situation_locked = yes
		target = {
			if = {
				limit = { root = { is_situation_type = planet_megastructure_upgrading } }
				remove_plnmg_mega = { TYPE = great_laboratory }
			}
		}
		target = { add_plnmg_mega = { TYPE = plnmg_supercom on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = { # hooray
		name = EXCELLENT
		tooltip = {
			if = {
				limit = {
					hidden_trigger = { is_situation_type = planet_megastructure_upgrading }
				}
				target = { remove_deposit = d_great_laboratory }
			}
			target = { add_deposit = d_plnmg_supercom }
		}
	}
}

carrier_event = {
	id = planetmega.931
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		or = {
			has_deposit = d_plnmg_supercom
			has_carrier_flag = planet_has_plnmg_supercom
			has_active_building = building_planetmega_lab2_hunger
		}
	}
	immediate = { carrier_event = { id = planetmega.933 days = 5 } }
}
carrier_event = {
	id = planetmega.933
	hide_window = yes
	is_triggered_only = yes
	trigger = { exists = owner }
	immediate = { plnmg_lab2_sacrifice_prod_upkp_effect = { TYPE = supercom } }
}

carrier_event = {
	id = planetmega.932
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		from = { is_homicidal = yes }
		fromfrom = { has_purge_type = { country = root.from type = purge_plnmg_torture } }
	}
	immediate = {
		from = {
			random_owned_colony = {
				limit = { has_plnmg_torture_building = yes }
				if = {
                    limit = { prev = { is_hive_empire = yes } }
                    initialize_mys_variable = { VAR = num_plnmg_brain_sacrifice }
					change_variable = { which = num_plnmg_brain_sacrifice value = local_pop_amount }
                }
                else = {
                    initialize_mys_variable = { VAR = num_plnmg_supercom_sacrifice }
					change_variable = { which = num_plnmg_supercom_sacrifice value = local_pop_amount }
                }
			}
		}
	}
}

situation_event = {
	id = planetmega.935
	title = planetmega.935.name
	desc = planetmega.935.desc
	picture = GFX_evt_planetmega_brain
	show_sound = event_swarm
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { has_situation_flag = building_plnmg_fusion_brain }

	immediate = {
		set_situation_locked = yes
		target = { remove_plnmg_mega = { TYPE = great_laboratory } }
		target = { add_plnmg_mega = { TYPE = plnmg_fusion_brain on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = { # hooray
		name = EXCELLENT
		tooltip = {
			target = {
				remove_deposit = d_great_laboratory
				add_deposit = d_plnmg_fusion_brain
			}
		}
	}
}

carrier_event = {
	id = planetmega.936
	is_triggered_only = yes
	hide_window = yes
	trigger = {
		or = {
			has_deposit = d_plnmg_fusion_brain
			has_carrier_flag = planet_has_plnmg_fusion_brain
			has_active_building = building_planetmega_lab2_hunger
		}
	}
	immediate = { carrier_event = { id = planetmega.937 days = 5 } }
}
carrier_event = {
	id = planetmega.937
	is_triggered_only = yes
	hide_window = yes
	trigger = { owner? = { is_hive_empire = yes } }
	immediate = { plnmg_lab2_sacrifice_prod_upkp_effect = { TYPE = brain } }
}

country_event = {
    id = planetmega.938
    is_triggered_only = yes
    hide_window = yes
    trigger = { has_menace_perk = menp_behemoth_hatchling }
    immediate = {
        export_trigger_value_to_variable = {
            trigger = count_owned_ship
            parameters = { limit = { is_behemoth = yes } }
            variable = var_plnmg_count_behemoths
        }
    }
}

carrier_event = {
	id = planetmega.210
	title = planetmega.210.name
	desc = planetmega.210.desc
	picture = GFX_evt_giant_building_in_progress
	is_triggered_only = yes
	location = root
	trigger = { exists = owner }
	immediate = {
		set_variable = { which = plnmg_upgrade2_mega_wip_nirfac value = 0 }
		every_targeting_situation = {
			limit = { has_situation_flag = building_plnmg_nirvana_factory }
			prev = { change_variable = { which = plnmg_upgrade2_mega_wip_nirfac value = 1 } }
		}
		set_variable = { which = plnmg_existing_base_mega_forge value = 0 }
		every_deposit = {
			limit = { is_deposit_type = d_advanced_forge }
			prev = { change_variable = { which = plnmg_existing_base_mega_forge value = 1 } }
		}
		set_variable = { which = plnmg_existing_base_mega_factory value = 0 }
		every_deposit = {
			limit = { is_deposit_type = d_centralized_manufactory }
			prev = { change_variable = { which = plnmg_existing_base_mega_factory value = 1 } }
		}
	}
	after = {
		hidden_effect = {
			clear_variable = plnmg_upgrade2_mega_wip_nirfac
			clear_variable = plnmg_existing_base_mega_forge
			clear_variable = plnmg_existing_base_mega_factory
		}
	}

	option = {
		name = planetmega.210.forge
		trigger = { has_deposit = d_advanced_forge }
		allow = {
			custom_tooltip = {
				fail_text = planetmega_beyond_mega_exist
				check_variable_arithmetic = {
					which = plnmg_upgrade2_mega_wip_nirfac
					add = 1
					value <= plnmg_existing_base_mega_forge
				}
			}
		}
		owner = {
			start_situation = {
				type = planet_megastructure_upgrading
				target = root
				effect = {
					set_situation_flag = building_plnmg_nirvana_factory
					set_situation_flag = based_on_forge
					if = {
						limit = { owner = { not = { has_technology = tech_planetmega_nirvana } } }
						set_situation_flag = building_nirfac_with_artifact
					}
				}
			}
		}
	}

	option = {
		name = planetmega.210.factory
		trigger = { has_deposit = d_centralized_manufactory }
		allow = {
			custom_tooltip = {
				fail_text = planetmega_beyond_mega_exist
				check_variable_arithmetic = {
					which = plnmg_upgrade2_mega_wip_nirfac
					add = 1
					value <= plnmg_existing_base_mega_factory
				}
			}
		}
		owner = {
			start_situation = {
				type = planet_megastructure_upgrading
				target = root
				effect = {
					set_situation_flag = building_plnmg_nirvana_factory
					set_situation_flag = based_on_factory
					if = {
						limit = { owner = { not = { has_technology = tech_planetmega_nirvana } } }
						set_situation_flag = building_nirfac_with_artifact
					}
				}
			}
		}
	}

	option = {
		name = planetmega.1.zzz
		# custom_tooltip = planetmega.1.zzz.desc
		default_hide_option = yes
		owner = {
			add_resource = {
				influence = @plnmg_influence_t2
				mult = value:scripted_modifier_mult|MODIFIER|country_influence_cost_mult|
			}
		}
		hidden_effect = { carrier_event = { id = planetmega.4 } }
	}
}

situation_event = {
	id = planetmega.211
	title = planetmega.211.name
	desc = planetmega.211.desc
	picture = GFX_evt_urban_landmark_building
	show_sound = event_construction
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { has_situation_flag = building_plnmg_nirvana_factory }
	immediate = {
		set_situation_locked = yes
		target = { remove_plnmg_mega = { TYPE = advanced_forge } }
		target = {
			if = {
				limit = { prev = { has_situation_flag = based_on_forge } }
				#remove_plnmg_mega = { TYPE = advanced_forge }
				if = {
					limit = {
						nor = {
							has_carrier_flag = plnmg_all_alloys_prod
							has_carrier_flag = plnmg_all_goods_prod
							has_carrier_flag = plnmg_nirfac_both_prod
						}
					}
					set_carrier_flag = plnmg_all_alloys_prod
				}
			}
		}
		target = { remove_plnmg_mega = { TYPE = centralized_manufactory } }
		target = {
			if = {
				limit = { prev = { has_situation_flag = based_on_factory } }
				#remove_plnmg_mega = { TYPE = centralized_manufactory }
				if = {
					limit = {
						nor = {
							has_carrier_flag = plnmg_all_alloys_prod
							has_carrier_flag = plnmg_all_goods_prod
							has_carrier_flag = plnmg_nirfac_both_prod
						}
					}
					set_carrier_flag = plnmg_all_goods_prod
				}
			}
		}
		target = {
			if = {
				limit = { prev = { has_situation_flag = building_nirfac_with_artifact } }
				owner = {
					if = {
						limit = { not = { is_variable_set = nano_forge_build_count } }
						set_variable = { which = nano_forge_build_count value = 0 }
					}
					if = {
						limit = { not = { is_variable_set = affluence_center_build_count } }
						set_variable = { which = affluence_center_build_count value = 0 }
					}
					subtract_variable = { which = nano_forge_build_count value = 2 }
					subtract_variable = { which = affluence_center_build_count value = 2 }
				}
			}
		}
		target = { add_plnmg_mega = { TYPE = plnmg_nirvana_factory on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = {
		name = EXCELLENT
		tooltip = {
			target = {
				if = {
					limit = { hidden_trigger = { prev = { has_situation_flag = based_on_forge } } }
					remove_deposit = d_advanced_forge
					add_deposit = d_plnmg_nirvana_factory
				}
				else_if = {
					limit = { hidden_trigger = { prev = { has_situation_flag = based_on_factory } } }
					remove_deposit = d_centralized_manufactory
					add_deposit = d_plnmg_nirvana_factory
				}
			}
		}
	}
}

# event triggered by tradable action, this = recipient, from = actor
country_event = {
	id = planetmega.215
	is_triggered_only = yes
	title = TRANSMISSION
	desc = planetmega.215.desc
	show_sound = event_mystic_reveal_light
	diplomatic = yes
	diplomatic_title = planetmega.215.name
	picture_event_data = {
		room = from
		portrait = from.ruler
		graphical_culture = from
		planet_background = from
		city_level = from
	}

	inline_script = { script = events/pm_diplo_dist_fe_tech_build_option build_set = fe_affluence }
	inline_script = { script = events/pm_diplo_dist_fe_tech_build_option build_set = fe_nourishment }
	inline_script = { script = events/pm_diplo_dist_fe_tech_build_option build_set = fe_fabricator }
	inline_script = { script = events/pm_diplo_dist_fe_tech_build_option build_set = fe_singularity }
	inline_script = { script = events/pm_diplo_dist_fe_tech_build_option build_set = fe_forge }
	inline_script = { script = events/pm_diplo_dist_fe_tech_build_option build_set = fe_dome }
	inline_script = { script = events/pm_diplo_dist_fe_tech_build_option build_set = fe_fortress }
	inline_script = { script = events/pm_diplo_dist_fe_tech_build_option build_set = fe_administration }
	inline_script = { script = events/pm_diplo_dist_fe_tech_build_option build_set = fe_assembly }
	inline_script = { script = events/pm_diplo_dist_fe_tech_build_option build_set = fe_clinic }
	inline_script = { script = events/pm_diplo_dist_fe_tech_build_option build_set = fe_security }
	inline_script = { script = events/pm_diplo_dist_fe_tech_build_option build_set = fe_market }
	inline_script = { script = events/pm_diplo_dist_fe_tech_build_option build_set = fe_silo }
	inline_script = { script = events/pm_diplo_dist_fe_tech_build_option build_set = fe_entertainment }
	inline_script = { script = events/pm_diplo_dist_fe_tech_build_option build_set = fe_lab }
	inline_script = { script = events/pm_diplo_dist_fe_tech_build_option build_set = fe_mine }

	inline_script = { script = events/pm_diplo_dist_fe_tech_option TECH = tech_dark_matter_deflector }
	inline_script = {
		script = events/pm_diplo_dist_fe_tech_option_bio
		TECH = tech_dark_matter_power_core BIO = tech_bio_dark_matter_power_core
	}
	inline_script = {
		script = events/pm_diplo_dist_fe_tech_option_bio
		TECH = tech_dark_matter_propulsion BIO = tech_bioship_thrusters_5
	}

	inline_script = { script = events/pm_diplo_dist_fe_tech_option TECH = tech_dragon_armor }
	inline_script = { script = events/pm_diplo_dist_fe_tech_option TECH = tech_enigmatic_encoder }
	inline_script = { script = events/pm_diplo_dist_fe_tech_option TECH = tech_enigmatic_decoder }
	inline_script = { script = events/pm_diplo_dist_fe_tech_option TECH = tech_nanite_repair_system }
	inline_script = {
		script = events/pm_diplo_dist_fe_tech_option_bio
		TECH = tech_nanite_autocannon BIO = tech_bio_nanite_autocannon
	}
	inline_script = {
		script = events/pm_diplo_dist_fe_tech_option_bio
		TECH = tech_nanite_flak_batteries BIO = tech_bio_nanite_flak_batteries
	}

	inline_script = { script = events/pm_diplo_dist_fe_tech_option TECH = tech_cosmogenesis_escort }
	inline_script = { script = events/pm_diplo_dist_fe_tech_option TECH = tech_cosmogenesis_battlecruiser }
	inline_script = { script = events/pm_diplo_dist_fe_tech_option TECH = tech_cosmogenesis_FE_titan }
	inline_script = { script = events/pm_diplo_dist_fe_tech_option TECH = tech_cosmogenesis_weaver }
	inline_script = { script = events/pm_diplo_dist_fe_tech_option TECH = tech_cosmogenesis_mauler }
	inline_script = { script = events/pm_diplo_dist_fe_tech_option TECH = tech_cosmogenesis_harbinger }
	inline_script = { script = events/pm_diplo_dist_fe_tech_option TECH = tech_cosmogenesis_stinger }

	option = {
		name = CANCEL
		response_text = planetmega.215.cancel_response
		default_hide_option = yes
		ai_chance = { weight = 0 }
		#random_country = { limit = { is_fallen_empire = yes } save_global_event_target_as = fe_tech_sharer }
		#country_event = { id = planetmega.215 scopes = { from = event_target:fe_tech_sharer } }
	}
}

#financial
situation_event = {
	id = planetmega.140
	is_triggered_only = yes
	title = planetmega.140.name
	desc = planetmega.140.desc
	picture = GFX_evt_planetmega_financial_building
	show_sound = event_construction
	trigger = { has_situation_flag = building_plnmg_financial_shikara }
	immediate = {
		set_situation_locked = yes
		target = { remove_plnmg_mega = { TYPE = commercial_shikara } }
		#target = { remove_plnmg_mega = { TYPE = logistics_shikara } }
		target = { add_plnmg_mega = { TYPE = plnmg_financial_shikara on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = {
		name = EXCELLENT
		tooltip = {
			target = {
				remove_deposit = d_commercial_shikara
				add_deposit = d_plnmg_financial_shikara
			}
		}
	}
}

#t2admin
situation_event = {
    id = planetmega.170
    is_triggered_only = yes
    title = planetmega.170.name
    desc = planetmega.170.desc
    picture = GFX_evt_planetmega_tamashi_control
    show_sound = event_the_cradle_of_souls
    trigger = { has_situation_flag = building_plnmg_tms_control }
    immediate = {
        set_situation_locked = yes
        target = { remove_plnmg_mega = { TYPE = primary_mind_pyramid } }
		target = { remove_plnmg_mega = { TYPE = admin_axis } }
        target = { add_plnmg_mega = { TYPE = plnmg_tms_control on_actions = yes } }
    }
    after = {
        hidden_effect = { set_situation_locked = no }
        destroy_situation = this
    }

    option = {
        name = EXCELLENT
        tooltip = {
            target = {
                add_deposit = d_plnmg_tms_control
                if = {
                    limit = { hidden_trigger = { owner = { is_gestalt = yes } } }
                    remove_deposit = d_primary_mind_pyramid
                }
                else = { remove_deposit = d_admin_axis }
            }
        }
        hidden_effect = {
            target = {
                if = {
                    limit = { is_capital = yes }
                    set_carrier_flag = built_capital_pm_admin
                }
            }
        }
    }
}

#t3
#colossus
situation_event = {
	id = planetmega.950
	title = planetmega.950.name
	desc = planetmega.950.desc
	picture = GFX_evt_complete_plnmg_colossus_assist
	is_triggered_only = yes
	situation = this
	location = target
	trigger = { has_situation_flag = building_plnmg_colossus_assist }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = plnmg_colossus_assist on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = {
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_plnmg_colossus_assist } }
	}
}

carrier_event = { #yearly #unused
	id = planetmega.951
	is_triggered_only = yes
	hide_window = yes
	trigger = {
		always = no
		# exists = owner
		# or = {
		# 	has_deposit = d_plnmg_colossus_assist
		# 	has_carrier_flag = planet_has_plnmg_colossus_assist
		# }
	}
	immediate = {
		if = {
			limit = {
				owner = {
					is_variable_set = num_plnmg_colossus_fired_count
					check_variable = { which = num_plnmg_colossus_fired_count value > 0 }
				}
				exists = orbital_defence.starbase
				orbital_defence.starbase = {
					is_orbital_ring = yes
					has_starbase_building = colossus_assist_orbital_accessory
				}
			}
			subtract_variable = { which = num_plnmg_colossus_fired_count value = 1 }
		}
	}
}

# THIS = Target System, FROM = Megastructure
system_event = {
    id = planetmega.952
    is_triggered_only = yes
    hide_window = yes
    trigger = {
		or = {
			#from.owner = { has_technology = tech_plnmg_dyson_bypassing }
			nor = { #crisis cannot be harmed unless you have proper tech
				any_ship_in_system = {
					or = {
						is_ship_size = leviathan_01_voidspawn
						is_ship_size = dimensional_portal_ed
						is_ship_size = synth_queen_titan
					}
				}
				any_system_planet = {
					is_planet_class = pc_ai
					owner = { is_country_type = ai_empire }
				}
			}
		}
		from.owner = {
			check_modifier_value = { modifier = dyson_gun_plnmg_damage_mult value > 0 }
		}
	}
    immediate = {
		from.owner = {
			set_variable = { which = dyson_gun_damage_multiplied value = dyson_gun_damage }
			multiply_variable = { which = dyson_gun_damage_multiplied value = modifier:dyson_gun_plnmg_damage_mult }
			round_variable = dyson_gun_damage_multiplied
			set_variable = { which = dyson_gun_damage_shielded_multiplied value = dyson_gun_damage_shielded }
			multiply_variable = { which = dyson_gun_damage_shielded_multiplied value = modifier:dyson_gun_plnmg_damage_mult }
			round_variable = dyson_gun_damage_shielded_multiplied
		}
		every_ship_in_system = {
			if = {
				limit = {
					or = {
						fleet = { starbase? = { has_starbase_building = defense_grid } }
						owner? = { is_crisis_faction = yes }
					}
				}
				damage_ship = {
					amount = from.owner.dyson_gun_damage_shielded_multiplied
					attacker = from.owner
				}
			}
			else = {
				damage_ship = {
					amount = from.owner.dyson_gun_damage_multiplied
					attacker = from.owner
				}
			}
		}
    }
}

situation_event = {
	id = planetmega.960
	is_triggered_only = yes
	title = planetmega.960.name
	desc = planetmega.960.desc
	picture = GFX_evt_planetmega_extra_galaxy
	location = target
	situation = this
	trigger = { has_situation_flag = building_plnmg_extra_galaxy }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = plnmg_extra_galaxy on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = {
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_plnmg_extra_galaxy } }
	}
}

situation_event = {
	id = planetmega.970
	is_triggered_only = yes
	title = planetmega.970.name
	desc = planetmega.970.desc
	picture = GFX_evt_planetmega_omnipotence
	location = target
	situation = this
	trigger = { has_situation_flag = building_plnmg_omnipotence }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = plnmg_omnipotence on_actions = yes } }
		target = { carrier_event = { id = planetmega.971 } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = {
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_plnmg_omnipotence } }
	}
}
carrier_event = {
    id = planetmega.971
    is_triggered_only = yes
    hide_window = yes
    trigger = {
		exists = owner
        or = {
			has_deposit = d_plnmg_omnipotence
			has_carrier_flag = planet_has_plnmg_omnipotence
		}
    }
    immediate = {
		if = {
			limit = { owner = { has_plnmg_virtual_jobs = yes } }
			if = {
				limit = { has_carrier_flag = planetmega_omnipotent_encouraged }
				remove_carrier_flag = planetmega_omnipotent_encouraged
			}
		}
		else = {
			set_variable = { which = var_job_plnmg_omnis_amount value = value:sv_job_plnmg_omnis_amount_mult }
		}
    }
}

situation_event = {
	id = planetmega.980
	is_triggered_only = yes
	title = planetmega.980.name
	desc = planetmega.980.desc
	picture = GFX_evt_vortex
	show_sound = event_alien_signal
	location = target
	situation = this
	trigger = { has_situation_flag = building_plnmg_nano_storm }
	immediate = {
		set_situation_locked = yes
		target = { add_plnmg_mega = { TYPE = plnmg_nano_storm on_actions = yes } }
	}
	after = {
		hidden_effect = { set_situation_locked = no }
		destroy_situation = this
	}

	option = {
		name = EXCELLENT
		tooltip = { target = { add_deposit = d_plnmg_nano_storm } }
	}
}

situation_event = {
	id = planetmega.981
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		has_situation_flag = building_plnmg_nano_storm
		situation_monthly_progress > 0
	}
	immediate = {
		if = {
			limit = { owner = { not = { has_planetmega_nanotech = yes } } }
			random_list = {
				94 = {}
				3 = {
					set_situation_flag = nanites_destructiveness_little
					situation_event = { id = planetmega.982 }
				}
				2 = {
					set_situation_flag = nanites_destructiveness_big
					situation_event = { id = planetmega.982 }
				}
				1 = {
					modifier = {
						factor = 0
						not = { has_active_shroudwalker_divination = yes }
					}
					# set_situation_flag = building_with_shroudwalker_divination
					# situation_event = { id = planetmega.983 }
				}
			}
		}
		else_if = {
			limit = {
				owner = {
					or = {
						has_technology = tech_synth_queen_knowledge
						has_technology = tech_nanite_repair_system_synth_queen
						has_modifier = synth_queen_nanite_apprentice
					}
				}
			}
			random_list = {
				97 = {}
				3 = {
					set_situation_flag = nanites_destructiveness_little
					situation_event = { id = planetmega.982 }
				}
			}
		}
		else = {
			random_list = {
				95 = {}
				2 = {
					set_situation_flag = nanites_destructiveness_big
					situation_event = { id = planetmega.982 }
				}
				# 3 = { situation_event = { id = planetmega.983 } }
			}
		}
        reroll_random = yes
	}
}

situation_event = {
	id = planetmega.982
	title = planetmega.982.name
	desc = planetmega.982.desc
	picture = GFX_evt_giant_building_in_progress
	show_sound = event_bad_omen
	is_triggered_only = yes
	situation = this
	location = target

	immediate = { set_situation_locked = yes }
	after = {
		hidden_effect = {
			set_situation_locked = no
			if = {
				limit = { has_situation_flag = nanites_destructiveness_little }
				remove_situation_flag = nanites_destructiveness_little
			}
			if = {
				limit = { has_situation_flag = nanites_destructiveness_big }
				remove_situation_flag = nanites_destructiveness_big
			}
		}
	}

	option = { # delayed
		name = planetmega.15.a
		if = {
			limit = { hidden_trigger = { has_situation_flag = nanites_destructiveness_little } }
			add_situation_progress = @plnmg_progress_subtract_little
			target = { add_planet_devastation = -5 }
		}
		if = {
			limit = { hidden_trigger = { has_situation_flag = nanites_destructiveness_big } }
			add_situation_progress = @plnmg_progress_subtract_big
			target = { add_planet_devastation = -10 }
		}
		ai_chance = { weight = 100 }
	}
	option = { # pay
		name = CURSES
		allow = {
			owner = {
				if = {
					limit = { hidden_trigger = { prev = { has_situation_flag = nanites_destructiveness_little } } }
					resource_stockpile_compare = {
						resource = nanites
						value >= 150
						mult = root.target.value:ground_megastructure_estimate_mult
					}
				}
				if = {
					limit = { hidden_trigger = { prev = { has_situation_flag = nanites_destructiveness_big } } }
					resource_stockpile_compare = {
						resource = nanites
						value >= 250
						mult = root.target.value:ground_megastructure_estimate_mult
					}
				}
			}
		}
		owner = {
			if = {
				limit = { hidden_trigger = { prev = { has_situation_flag = nanites_destructiveness_little } } }
				add_resource = {
					nanites = 150
					mult = root.target.value:ground_megastructure_cost_mult
				}
			}
			if = {
				limit = { hidden_trigger = { prev = { has_situation_flag = nanites_destructiveness_big } } }
				add_resource = {
					nanites = 250
					mult = root.target.value:ground_megastructure_cost_mult
				}
			}
		}
	}
}

situation_event = {
	id = planetmega.983
	title = planetmega.983.name
	desc = planetmega.983.desc
	desc = {
		exclusive_trigger = { has_situation_flag = building_with_shroudwalker_divination }
		text = planetmega.983.desc_shroudwalker
	}
	picture = GFX_evt_metropolis_dawn
	is_triggered_only = yes
	show_sound = event_mystic_reveal_light
	situation = this
	location = target

	immediate = { set_situation_locked = yes }
	after = { hidden_effect = { set_situation_locked = no } }

	option = {
		name = EXCELLENT
		exclusive_trigger = {
			or = {
				has_situation_flag = building_with_shroudwalker_divination
				owner = {
                    or = {
                        can_access_shroud = yes
                        has_breached_shroud = yes
                    }
                }
			}
		}
		add_situation_progress = @plnmg_progress_add_big
		hidden_effect = {
			if = {
				limit = { has_situation_flag = building_with_shroudwalker_divination }
				remove_situation_flag = building_with_shroudwalker_divination
			}
		}
	}
	option = {
		name = EXCELLENT
		add_situation_progress = @plnmg_progress_add_little
	}
}

country_event = {
	id = planetmega.984
	hide_window = yes
	is_triggered_only = yes
	fire_only_once = yes
	immediate = { randomly_decide_nanostorm_similarity = yes }
}

#星球塑形器
situation_event = {
    id = planetmega.180
    is_triggered_only = yes
    title = planetmega.180.name
    desc = planetmega.180.desc
    picture = GFX_evt_planetmega_world_shaper_set
    show_sound = event_construction
    trigger = { has_situation_flag = building_plnmg_world_shaper }
    immediate = {
        set_situation_locked = yes
        target = { add_plnmg_mega = { TYPE = plnmg_world_shaper on_actions = yes } }
    }
    after = {
        hidden_effect = { set_situation_locked = no }
        destroy_situation = this
    }

    option = {
        name = EXCELLENT
        tooltip = { target = { add_deposit = d_plnmg_world_shaper } }
    }
}


###pret1 buildings (using 260~299 I think)###
# carrier_event = {
#     id = planetmega.260
#     is_triggered_only = yes
#     title = planetmega.260.name
#     desc = planetmega.260.desc
#     picture = GFX_evt_giant_building_in_progress
#     pre_triggers = { has_owner = yes }
#     trigger = {
#         or = {
#             last_building_changed = building_plnmg_t0_lab
#         }
#         owner = { not = { has_country_flag = plnmg_t0_queue_noticed } }
#     }
#     option = {
#         name = OK
#         default_hide_option = yes
#     }
#     option = {
#         name = planetmega.260.no_more
#         hidden_effect = { owner = { set_country_flag = plnmg_t0_queue_noticed } }
#     }
# }

carrier_event = {
    id = planetmega.261
    is_triggered_only = yes
    title = planetmega.261.name
	desc = planetmega.261.desc
	immediate = { set_timed_carrier_flag = { flag = cant_upgrade_plnmg_t0_admin days = 2 } }
    option = { name = TERRIBLE }
}


