
is_plnmg_rebellion_fomented = {
    # this = planet
    optimize_memory
    or = {
        has_modifier = plnmg_foment_rebellion
        has_modifier = plnmg_foment_rebellion_more
        has_modifier = plnmg_foment_rebellion_less
        has_modifier = foment_rebellion
        has_modifier = foment_rebellion_more
        has_modifier = foment_rebellion_poor
        # if = {
        #     limit = { has_global_flag = better_diplo_installed }
        #     or = {
        #         has_modifier = foment_rebellion
        #         has_modifier = foment_rebellion_more
        #         has_modifier = foment_rebellion_poor
        #     }
        # }
    }
}

is_plnmg_able_to_be_stolen = {
    # this = pop, event_target:stealer_country or root must be a existing country!
    optimize_memory
    has_virtual_species_trait = no
    trait_is_wilderness_check = no
    not = { has_trait = trait_wilderness }
    if = {
        limit = {
            or = {
                root? = {
                    is_scope_type = country
                    not = { has_technology = tech_planetmega_junik }
                }
                and = {
                    exists = event_target:stealer_country
                    event_target:stealer_country = {
                        not = { has_technology = tech_planetmega_junik }
                    }
                }
            }
        }
        is_robotic_species = no
    }
    if = {
        limit = {
            or = {
                root? = {
                    is_scope_type = country
                    is_gestalt = no
                }
                and = {
                    exists = event_target:stealer_country
                    event_target:stealer_country = { is_gestalt = no }
                }
            }
        }
        is_hive_species = no
    }
    if = {
        limit = {
            or = {
                root? = {
                    is_scope_type = country
                    nor = {
                        is_gestalt = yes
                        has_policy_flag = interference_active
                        has_policy_flag = interference_aggressive
                    }
                }
                and = {
                    exists = event_target:stealer_country
                    event_target:stealer_country = {
                        nor = {
                            is_gestalt = yes
                            has_policy_flag = interference_active
                            has_policy_flag = interference_aggressive
                        }
                    }
                }
            }
        }
        is_sapient = yes
        is_pre_sapient = no
    }
}

is_plnmg_ally_of = {
    # this = country
    or = {
        has_overlord = $target$
        has_subject = $target$
        is_in_federation_with = $target$
        has_defensive_pact = $target$
        # is_guaranteeing = $target$
        # $target$ = { is_guaranteeing = prev }
    }
}

is_plnmg_quota_term_beneficial = {
    or = {
        and = {
            is_subject = yes
            any_agreement = {
                has_term_value = {
                    term = planetmega_engineering_aid
                    value = plnmg_aid_term_overlord_helper
                }
            }
        }
        and = {
            is_overlord = yes
            any_agreement = {
                has_term_value = {
                    term = planetmega_engineering_aid
                    value = plnmg_aid_term_subject_corvee
                }
            }
        }
    }
}
