
# this = ship

# plnmg_weapon_aoe_effect_fleet = {
#     # must be used in on_hit of weapon components
#     # this = target ship, from = shooter ship
#     fleet = {
#         every_controlled_ship = {
#             limit = { not = { is_same_value = prevprev } }
#             set_variable = { which = temp_ship_damage_var value = $damage$ }
#             [[random]
#                 set_variable_to_random_value = { which = temp_ship_damage_mult min = 1 max = 100 rounded = yes }
#                 reroll_random = yes
#                 multiply_variable = { which = temp_ship_damage_mult value = 0.01 }
#                 multiply_variable = { which = temp_ship_damage_var value = temp_ship_damage_mult }
#                 clear_variable = temp_ship_damage_mult
#             ]
#             [[type]
#                 multiply_variable = {
#                     which = temp_ship_damage_var
#                     value = value:scripted_modifier_mult|MODIFIER|$type$_weapon_damage_mult|
#                 }
#             ]
#             [[role]
#                 multiply_variable = {
#                     which = temp_ship_damage_var
#                     value = value:scripted_modifier_mult|MODIFIER|$role$_weapon_damage_mult|
#                 }
#             ]
#             [[slot]
#                 multiply_variable = {
#                     which = temp_ship_damage_var
#                     value = value:scripted_modifier_mult|MODIFIER|$slot$_weapon_damage_mult|
#                 }
#             ]
#             floor_variable = temp_ship_damage_var
#             #fire_on_action = { on_action = on_damage_taken scopes = { from = from } }
#             #create_ambient_object = { type = explosion_particle_object location = this }
#             if = {
#                 limit = {
#                     check_variable_arithmetic = {
#                         which = temp_ship_damage_var value >= value:sv_plnmg_total_ship_hp
#                     }
#                 }
#                 ship_event = { id = planetmega_pk.35 days = 1 }
#                 owner = {
#                     fire_on_action = {
#                         on_action = on_ship_destroyed_victim
#                         scopes = { from = from.owner fromfrom = prev fromfromfrom = from }
#                     }
#                 }
#                 from.owner = {
#                     fire_on_action = {
#                         on_action = on_ship_destroyed_perp
#                         scopes = { from = prev.owner fromfrom = prev.from fromfromfrom = prev }
#                     }
#                 }
#             }
#             else = { ship_event = { id = planetmega_pk.35 } }
#         }
#     }
# }

plnmg_ricnt_ship_resurrect_effect = {
    if = {
        limit = { exists = fleet }
        fleet = { create_ship = { name = prev design = prev.design } }
    }
    else = {
        create_fleet = {
            name = fleet
            effect = {
                create_ship = { name = prev design = prev.design }
                set_owner = prev.owner
                set_location = prev
            }
        }
    }
}

# this = fleet

plnmg_pk_eradicator_fleet_static_effect = {
    every_owned_ship = {
        #reduce_hp_percent = 0.99
        add_modifier = {
            modifier = plnmg_pk_eradicator_ship_modifier
            years = 1
        }
    }
}

plnmg_pk_eradicator_fleet_random_effect = {
    every_owned_ship = {
        random_list = {
            #10 = {}
            9 = {
                modifier = {
                    factor = 0
                    has_hp_percentage <= 0.1
                }
                reduce_hp_percent = 0.1
            }
            8 = {
                modifier = {
                    factor = 0
                    has_hp_percentage <= 0.2
                }
                reduce_hp_percent = 0.2
            }
            7 = {
                modifier = {
                    factor = 0
                    has_hp_percentage <= 0.3
                }
                reduce_hp_percent = 0.3
            }
            6 = {
                modifier = {
                    factor = 0
                    has_hp_percentage <= 0.4
                }
                reduce_hp_percent = 0.4
            }
            5 = {
                modifier = {
                    factor = 0
                    has_hp_percentage <= 0.5
                }
                reduce_hp_percent = 0.5
            }
            4 = {
                modifier = {
                    factor = 0
                    has_hp_percentage <= 0.6
                }
                reduce_hp_percent = 0.6
            }
            3 = {
                modifier = {
                    factor = 0
                    has_hp_percentage <= 0.7
                }
                reduce_hp_percent = 0.7
            }
            2 = {
                modifier = {
                    factor = 0
                    has_hp_percentage <= 0.8
                }
                reduce_hp_percent = 0.8
            }
            1 = {
                modifier = {
                    factor = 0
                    has_hp_percentage <= 0.9
                }
                reduce_hp_percent = 0.9
            }
        }
        reroll_random = yes
    }
}

plnmg_pmcar_perf_enhance = {
    initialize_mys_variable = { VAR = planet_sizes_carried }
    change_variable = { which = planet_sizes_carried value = $planet_sizes$ }
    erase_modifier = { MOD = plnmg_pmcar_pnsz_mod }
    add_modifier = { modifier = plnmg_pmcar_pnsz_mod mult = planet_sizes_carried }
    # set_variable = { which = planet_sizes_imp_temp value = planet_sizes_carried }
    # set_variable = { which = planet_sizes_imp value = 0 }
    # while = {
    #     limit = { check_variable = { which = planet_sizes_imp_temp value >= 10 } }
    #     divide_variable = { which = planet_sizes_imp_temp value = 10 }
    #     change_variable = { which = planet_sizes_imp value = 1 }
    # }
    # add_modifier = { modifier = plnmg_pmhs_pnsz_mod_imp mult = planet_sizes_imp_temp }
    # clear_variable = planet_sizes_imp
    # clear_variable = planet_sizes_imp_temp
}

# this = planet

# plnmg_pk_eradicator_plnt_effect = {
#     # this = the star targeted at
#     create_ambient_object = {
#         type = "star_explosion"
#         play_animation_once = yes
#         location = this
#         effect = {
#             set_location = {
#                 target = prev
#                 distance = 0
#                 angle = random
#             }
#         }
#     }
#     solar_system = { plnmg_pk_eradicator_sys_effect = yes }
# }

#以下SCOPE为GALACTIC_OBJECT(一般为SYSTEM)

plnmg_pk_eradicator_sys_effect = {
    # should exist event_target:fire_launcher as a fleet of attacker country
    every_system_planet_colony = {
        limit = { owner = { is_hostile = event_target:fire_launcher.controller } }
        random_list = {
            9 = {
                modifier = {
                    factor = 0
                    planet_devastation > 90
                }
                add_planet_devastation = 10
            }
            8 = {
                modifier = {
                    factor = 0
                    planet_devastation > 80
                }
                add_planet_devastation = 20
            }
            7 = {
                modifier = {
                    factor = 0
                    planet_devastation > 70
                }
                add_planet_devastation = 30
            }
            6 = {
                modifier = {
                    factor = 0
                    planet_devastation > 60
                }
                add_planet_devastation = 40
            }
            5 = {
                modifier = {
                    factor = 0
                    planet_devastation > 50
                }
                add_planet_devastation = 50
            }
            4 = {
                modifier = {
                    factor = 0
                    planet_devastation > 40
                }
                add_planet_devastation = 60
            }
            3 = {
                modifier = {
                    factor = 0
                    planet_devastation > 30
                }
                add_planet_devastation = 70
            }
            2 = {
                modifier = {
                    factor = 0
                    planet_devastation > 20
                }
                add_planet_devastation = 80
            }
            1 = {
                modifier = {
                    factor = 0
                    planet_devastation > 10
                }
                add_planet_devastation = 90
            }
        }
        if = {
            limit = { has_ground_combat = yes }
            export_trigger_value_to_variable = {
                trigger = count_ground_combat_attacker
                parameters = { limit = { always = yes } }
                variable = temp_attacker_army_count
            }
            export_trigger_value_to_variable = {
                trigger = count_ground_combat_defender
                parameters = { limit = { always = yes } }
                variable = temp_defender_army_count
            }
            set_variable = { which = temp_planet_devastation value = trigger:planet_devastation }
            divide_variable = { which = temp_planet_devastation value = 100 }
            multiply_variable = { which = temp_attacker_army_count value = temp_planet_devastation }
            round_variable = temp_attacker_army_count
            if = {
                limit = { check_variable = { which = temp_attacker_army_count value >= 1 } }
                subtract_variable = { which = temp_attacker_army_count value = 1 }
            }
            multiply_variable = { which = temp_defender_army_count value = temp_planet_devastation }
            round_variable = temp_defender_army_count
            if = {
                limit = { check_variable = { which = temp_defender_army_count value >= 1 } }
                subtract_variable = { which = temp_defender_army_count value = 1 }
            }
            save_event_target_as = target_planet
            random_ground_combat_attacker = { owner = { save_event_target_as = attacker_country } }
            random_ground_combat_defender = { owner = { save_event_target_as = defender_country } }
            while = {
                count = temp_attacker_army_count
                random_ground_combat_attacker = {
                    save_event_target_as = temp_army
                    event_target:attacker_country = {
                        fire_on_action = {
                            on_action = on_army_killed_in_combat
                            scopes = {
                                from = event_target:temp_army
                                fromfrom = event_target:defender_country
                                fromfromfrom = event_target:target_planet
                            }
                        }
                    }
                    remove_army = yes
                }
            }
            while = {
                count = temp_defender_army_count
                random_ground_combat_defender = {
                    save_event_target_as = temp_army
                    event_target:defender_country = {
                        fire_on_action = {
                            on_action = on_army_killed_in_combat
                            scopes = {
                                from = event_target:temp_army
                                fromfrom = event_target:attacker_country
                                fromfromfrom = event_target:target_planet
                            }
                        }
                    }
                    remove_army = yes
                }
            }
            clear_variable = temp_planet_devastation
            clear_variable = temp_attacker_army_count
            clear_variable = temp_defender_army_count
        }
        else = {
            export_trigger_value_to_variable = {
                trigger = count_planet_army
                parameters = { limit = { always = yes } }
                variable = temp_army_count
            }
            set_variable = { which = temp_planet_devastation value = trigger:planet_devastation }
            divide_variable = { which = temp_planet_devastation value = 100 }
            multiply_variable = { which = temp_army_count value = temp_planet_devastation }
            round_variable = temp_army_count
            if = {
                limit = { check_variable = { which = temp_army_count value >= 1 } }
                subtract_variable = { which = temp_army_count value = 1 }
            }
            while = {
                count = temp_army_count
                random_planet_army = {
                    save_event_target_as = temp_army
                    owner = {
                        fire_on_action = {
                            on_action = on_army_killed_no_combat
                            scopes = { from = event_target:temp_army }
                        }
                    }
                    remove_army = yes
                }
            }
            clear_variable = temp_army_count
            clear_variable = planet_devastation
        }
        reroll_random = yes
    }
    every_system_planet = {
        if = {
            limit = { exists = orbital_station }
            orbital_station = { dismantle = yes }
        }
        if = {
            limit = { has_planetary_shield_building = no }
            increase_planet_temperature_without_habitables = yes
            event_target:fire_launcher.owner = {
                set_timed_country_flag = { flag = resolution_breached_terraformed days = 3600 }
            }
        }
    }
    every_system_megastructure = {
        add_modifier = { modifier = plnmg_spacemega_eradicated months = 12 }
    }
    every_fleet_in_system = {
        limit = { not = { is_same_value = event_target:fire_launcher } }
        if = {
            limit = { controller? = { is_hostile = event_target:fire_launcher.controller } }
            plnmg_pk_eradicator_fleet_static_effect = yes
            plnmg_pk_eradicator_fleet_random_effect = yes
        }
        else_if = {
            limit = {
                controller? = {
                    is_nomadic = no
                    exists = capital_scope
                    or = {
                        is_same_value = event_target:fire_launcher.controller
                        is_forced_friendly = event_target:fire_launcher.controller
                        is_friendly_to = event_target:fire_launcher.controller
                    }
                }
            }
            set_mia = mia_return_home
        }
        else = { plnmg_pk_eradicator_fleet_random_effect = yes }
    }
}

# this = megastructure

# this = country

plnmg_aeg_colossus_fire_with_check = {
    # this = country
    # event_target:fired_planet must exist
    # event_target:fire_launcher must exist
    if = {
        limit = { has_any_plnmg_aeg_supportive_structure = yes }
        if = {
            limit = {
                resource_stockpile_compare = {
                    resource = energy
                    value >= @plntCore_rechargeBase
                    mult = value:sv_colossus_recharge_cost_mult
                }
            }
            add_resource = {
                energy = @plntCore_rechargeBase_neg
                mult = value:sv_colossus_recharge_cost_mult
            }
            event_target:fired_planet = {
                [[on_action]
                    fire_on_action = {
                        on_action = $on_action$_queued
                        scopes = { from = event_target:fire_launcher }
                    }
                    fire_on_action = {
                        on_action = $on_action$
                        scopes = { from = event_target:fire_launcher }
                    }
                ]
                [[event]
                    planet_event = {
                        id = $event$
                        scopes = { from = event_target:fire_launcher }
                    }
                ]
            }
        }
        # else_if = {
        #     limit = {
        #         has_global_flag = "has_real_space_mod"
        #         any_owned_megastructure = {
        #             not = { has_megastructure_flag = energy_overconsumed }
        #             is_plnmg_aeg_complete_supportive_mega = yes
        #         }
        #     }
        #     random_owned_megastructure = {
        #         limit = {
        #             not = { has_megastructure_flag = energy_overconsumed }
        #             is_plnmg_aeg_complete_supportive_mega = yes
        #         }
        #         planet = { change_planet_size = -1 }
        #         set_timed_megastructure_flag = { flag = energy_overconsumed months = 12 }
        #     }
        #     reroll_random = yes
        # }
        else = { country_event = { id = planetmega_pk.101 } }
    }
    else = { country_event = { id = planetmega_pk.103 } }
}

plnmg_aeg_colossus_fire_no_check = {
    add_resource = {
        energy = @plntCore_rechargeBase_neg
        mult = value:sv_colossus_recharge_cost_mult
    }
    event_target:fired_planet = {
        [[on_action]
            fire_on_action = {
                on_action = $on_action$_queued
                scopes = { from = event_target:fire_launcher }
            }
            fire_on_action = {
                on_action = $on_action$
                scopes = { from = event_target:fire_launcher }
            }
        ]
        [[event]
            planet_event = {
                id = $event$
                scopes = { from = event_target:fire_launcher }
            }
        ]
    }
}

# plnmg_colossus_fire_with_check = {
#     # event_target:fired_planet must exist
#     # event_target:fire_launcher must exist
#     if = {
#         limit = {
#             or = {
#                 any_owned_colony = { has_deposit = d_plnmg_colossus_assist }
#                 has_megastructure = planetmega_colossus_assistant_1
#                 has_megastructure = planetmega_colossus_assistant_2
#                 has_megastructure = planetmega_colossus_assistant_restored
#             }
#         }
#         planetmega_colossus_add_count = yes
#         if = {
#             limit = {
#                 check_variable = {
#                     which = num_plnmg_colossus_fired_count
#                     value <= num_plnmg_colossus_fired_limit
#                 }
#             }
#             event_target:fired_planet = {
#                 fire_on_action = {
#                     on_action = on_destroy_planet_with_$TYPE$
#                     scopes = { from = event_target:fire_launcher }
#                 }
#             }
#             if = {
#                 limit = { resource_stockpile_compare = { resource = energy value >= @plntCore_rechargeBase } }
#                 add_resource = { energy = @plntCore_rechargeBase mult = -1 }
#             }
#             else_if = {
#                 limit = {
#                     or = {
#                         has_megastructure = planetmega_colossus_assistant_2
#                         has_megastructure = planetmega_colossus_assistant_restored
#                     }
#                 }
#                 random_owned_megastructure = {
#                     limit = {
#                         or = {
#                             is_megastructure_type = planetmega_colossus_assistant_2
#                             is_megastructure_type = planetmega_colossus_assistant_restored
#                         }
#                         planet? = { planet_size > 10 }
#                     }
#                     planet = { change_planet_size = -1 }
#                     set_timed_megastructure_flag = { flag = energy_overconsumed months = 18 }
#                 }
#                 reroll_random = yes
#             }
#             else_if = {
#                 limit = { any_owned_colony = { has_deposit = d_plnmg_colossus_assist } }
#                 random_owned_colony = {
#                     limit = {
#                         has_deposit = d_plnmg_colossus_assist
#                         planet_size > 5
#                     }
#                     #change_planet_size = -1
#                     remove_random_district = yes
#                 }
#                 reroll_random = yes
#             }
#         }
#         else = {
#             country_event = { id = planetmega_pk.101 }
#             set_variable = { which = num_plnmg_colossus_fired_count value = 0 }
#             set_variable = { which = num_plnmg_colossus_fired_limit value = 0 }
#             every_owned_megastructure = {
#                 limit = {
#                     or = {
#                         is_megastructure_type = planetmega_colossus_assistant_2
#                         is_megastructure_type = planetmega_colossus_assistant_restored
#                     }
#                     exists = planet
#                 }
#                 solar_system = {
#                     plnmg_ca_spacemega_destroyed_system_effect = yes
#                     spawn_megastructure = {
#                         type = planetmega_colossus_assistant_ruined
#                         planet = prev.planet
#                         owner = prev.owner
#                     }
#                 }
#                 remove_megastructure = this
#             }
#             every_owned_colony = {
#                 limit = { has_deposit = d_plnmg_colossus_assist }
#                 remove_plnmg_mega = { TYPE = plnmg_colossus_assist }
#                 every_owned_pop_group = { kill_all_pop = yes }
#                 destroy_colony = yes
#                 if = {
#                     limit = { is_artificial = no }
#                     change_pc = pc_frozen
#                 }
#             }
#         }
#     }
#     else = { country_event = { id = planetmega_pk.103 } }
# }

plnmg_aeg_weapon_fire_with_check = {
    optimize_memory
    # this = country
    # event_target:target_ship must exist
    # event_target:shooter_ship must exist
    if = {
        limit = {
            has_any_plnmg_aeg_supportive_structure = yes
            resource_stockpile_compare = {
                resource = energy
                value >= @plntCore_rechargeBase
                mult = value:sv_colossus_recharge_cost_mult
            }
        }
        add_resource = {
            energy = @plntCore_rechargeBase_neg
            mult = value:sv_colossus_recharge_cost_mult
        }
    }
    else = { event_target:shooter_ship = { ship_event = { id = planetmega_pk.34 } } }
}

#unused
plnmg_ca_spacemega_destroyed_system_effect = {
    every_system_planet = {
        limit = {
            OR = {
                is_planet_class = pc_molten
                is_planet_class = pc_toxic
                habitable_planet = yes
            }
        }
        if = {
            limit = { is_colony = yes }
            destroy_colony = yes
        }
        change_pc = pc_frozen
    }
    every_system_planet = {
        limit = { is_planet_class = pc_barren }
        change_pc = pc_barren_cold
    }
    remove_system_terraforming_candidates = yes
}

### 以下应为天体、舰队或巨构等star与solar_system可作用者
create_plnmg_colossus_hit_se = {
    create_ambient_object = {
        type = $ao$
        location = this
        use_3d_location = yes
        entity_scale_to_size = yes
        base_angle_towards = star
        entity_face_object = star
        play_animation_once = yes
        duration = 2
    }
    last_created_ambient_object = {
        set_ambient_object_flag = plnmg_colossus_hit_se
        set_timed_ambient_object_flag = { flag = should_not_be_destroyed days = 2 }
    }
    solar_system = { system_event = { id = planetmega_pk.22 days = 3 } }
}

# this = solar_system
create_plnmg_colossus_system_hit_se = {
    [[planets]
        every_system_planet = {
            create_ambient_object = {
                type = $ao$
                location = this
                use_3d_location = yes
                entity_scale_to_size = yes
                base_angle_towards = star
                entity_face_object = star
                play_animation_once = yes
                duration = 2
            }
            last_created_ambient_object = {
                set_ambient_object_flag = plnmg_colossus_hit_se
                set_timed_ambient_object_flag = { flag = should_not_be_destroyed days = 2 }
            }
        }
    ]
    [[megastructures]
        every_system_megastructure = {
            create_ambient_object = {
                type = $ao$
                location = this
                use_3d_location = yes
                entity_scale_to_size = yes
                base_angle_towards = star
                entity_face_object = star
                play_animation_once = yes
                duration = 2
            }
            last_created_ambient_object = {
                set_ambient_object_flag = plnmg_colossus_hit_se
                set_timed_ambient_object_flag = { flag = should_not_be_destroyed days = 2 }
            }
        }
    ]
    system_event = { id = planetmega_pk.22 days = 3 }
}

### for button_effects ###

plnmg_itss_colossus_fire_with_check = {
    # this = target planet (should be checked before), from = shooter country
    if = {
        limit = {
            exists = event_target:fire_launcher_of_@from
            event_target:fire_launcher_of_@from = {
                owner? = {
                    resource_stockpile_compare = {
                        resource = energy
                        value >= @plntITSS_rechargeBase
                        mult = prev.value:sv_plnmg_itss_recharge_cost_mult
                    }
                }
            }
        }
        event_target:fire_launcher_of_@from = {
            owner = {
                add_resource = {
                    energy = @plntITSS_rechargeBase_neg
                    mult = prev.value:sv_plnmg_itss_recharge_cost_mult
                }
            }
        }
        [[on_action]
            fire_on_action = {
                on_action = $on_action$_queued
                scopes = { from = event_target:fire_launcher_of_@from }
            }
            fire_on_action = {
                on_action = $on_action$
                scopes = { from = event_target:fire_launcher_of_@from }
            }
        ]
        [[event]
            planet_event = {
                id = $event$
                scopes = { from = event_target:fire_launcher_of_@from }
            }
        ]
    }
    else = { from = { country_event = { id = planetmega_pk.101 } } }
}
plnmg_itss_colossus_fire_no_check = {
    # this = target planet (should be checked before), from = shooter country
    # event_target:fire_launcher_of_@from (planet) must exist
    event_target:fire_launcher_of_@from = {
        owner = {
            add_resource = {
                energy = @plntITSS_rechargeBase_neg
                mult = prev.value:sv_plnmg_itss_recharge_cost_mult
            }
        }
    }
    [[on_action]
        fire_on_action = {
            on_action = $on_action$_queued
            scopes = { from = event_target:fire_launcher_of_@from }
        }
        fire_on_action = {
            on_action = $on_action$
            scopes = { from = event_target:fire_launcher_of_@from }
        }
    ]
    [[event]
        planet_event = {
            id = $event$
            scopes = { from = event_target:fire_launcher_of_@from }
        }
    ]
}

plnmg_itss_specific_plnt_weapon_effect = {
    hidden_effect = {
        if = {
            limit = { has_carrier_flag = plnmg_itss_$TYPE$_of_@from }
            remove_carrier_flag = plnmg_itss_$TYPE$_of_@from
        }
        else = { set_carrier_flag = plnmg_itss_$TYPE$_of_@from }
    }
}

remove_all_plnmg_itss_plnt_weapon_flags = {
    remove_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_CRACKER }
    remove_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_SHIELDER }
    remove_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_NEUTRON }
    remove_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_GODRAY }
    remove_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_NANOBOTS }
    remove_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_DELUGE }
    remove_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_TOXIFIER }
    remove_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_DEVOLUTION }
    remove_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_MAW_AEG }
    remove_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_SMELTER }
    ###
    remove_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_STAR_CRACKER }
    remove_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_STAR_CRACKER_LITE_PLNMG }
    remove_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_PLNMG_STAR_OSCILLATOR }
}
remove_plnmg_itss_plnt_weapon_flag_indiv = {
    if = {
        limit = { has_carrier_flag = plnmg_itss_$TYPE$_of_@from }
        remove_carrier_flag = plnmg_itss_$TYPE$_of_@from
    }
}

# below should be only used in country events that call custom gui
clear_all_plnmg_itss_plnt_weapon_flags = {
    clear_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_CRACKER }
    clear_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_SHIELDER }
    clear_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_NEUTRON }
    clear_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_GODRAY }
    clear_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_NANOBOTS }
    clear_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_DELUGE }
    clear_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_TOXIFIER }
    clear_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_DEVOLUTION }
    clear_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_MAW_AEG }
    clear_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_SMELTER }
    ###
    clear_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_STAR_CRACKER }
    clear_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_STAR_CRACKER_LITE_PLNMG }
    clear_plnmg_itss_plnt_weapon_flag_indiv = { TYPE = PLANET_KILLER_PLNMG_STAR_OSCILLATOR }
}
clear_plnmg_itss_plnt_weapon_flag_indiv = {
    if = {
        limit = { has_carrier_flag = plnmg_itss_$TYPE$_of_@root }
        remove_carrier_flag = plnmg_itss_$TYPE$_of_@root
    }
}

clear_all_plnmg_itss_weapon_flags = {
    every_galaxy_planet = { clear_all_plnmg_itss_plnt_weapon_flags = yes }
    every_megastructure = {
        limit = { has_megastructure_flag = plnmg_itss_MEGASTRUCTURE_RUINER_of_@root }
        remove_megastructure_flag = plnmg_itss_MEGASTRUCTURE_RUINER_of_@root
    }
    every_galaxy_fleet = {
        limit = { has_fleet_flag = plnmg_itss_FLEET_DESTROYER_of_@root }
        remove_fleet_flag = plnmg_itss_FLEET_DESTROYER_of_@root
    }
}
