
# this = ship

has_any_leader_capturer_comp_no_pirate = {
    or = {
        has_component = PLNMG_RICNT_COMP
        has_ship_flag = has_leader_capturer_no_pirate
    }
}
has_any_ship_capturer_comp_no_pirate = {
    or = {
        has_component = PLNMG_RICNT_COMP
        has_ship_flag = has_ship_capturer_no_pirate
    }
}
has_any_comp_against_leader_capturer_comp = {
    or = {
        has_component = PLNMG_RICNT_COMP
        has_ship_flag = has_comp_against_leader_capturer
    }
}
has_any_comp_against_ship_capturer_comp = {
    or = {
        is_behemoth = yes
        is_ship_size = plnmg_plntmatter_heroship_2
        is_ship_size = plnmg_plntmatter_heroship_3
        has_component = PLNMG_RICNT_COMP
        has_ship_flag = has_comp_against_ship_capturer
    }
}

# This = Leader captured
# from = perpetrator country
# fromfrom = victim country
# fromfromfrom = system where it happened
leader_cannot_be_captured = {
    from = { not = { has_country_flag = can_ntr_leaders } }
    # is_leader_mia_or_in_transit = no
    # is_leader_excavating_site = no
    # is_exploring_astral_rift = no
    or = {
        is_event_leader = yes
        is_leader_tier = leader_tier_legendary
        fromfrom = { has_country_flag = leaders_cannot_be_captured }
        and = {
            has_leader_flag = daisuki_girlfriend
            fromfrom = { has_origin = origin_DaiDaiDaiDaiDaisuki }
        }
    }
}

# this = pop group

no_valid_pop_category = {
    is_pop_category = no_pop_category
    # not defined in any script. But it is intended:
    # After the category key lookup fails, the trigger stores an empty category object;
    # whereas when `is_pop_category` is evaluated, it directly compares the pop group's category pointer.
    # Therefore, according to the game engine logic, it will match pop groups with "no valid category."
}

# this = starbase

is_arkship_starbase_tier_3 = {
    OR = {
        has_starbase_size = civilian_arkship_tier_3
        has_starbase_size = science_arkship_tier_3
        has_starbase_size = military_arkship_tier_3
        has_starbase_size = military_arkship_champions_forge
    }
}

# this = megastructure

# this = colony or carrier

lithoid_pop_amount = { count_owned_pop_amount = { limit = { is_lithoid = yes } } }
spiritualist_pop_amount = { count_owned_pop_amount = { limit = { is_spiritualist = yes } } }

# this = system

has_quantum_catapult = { # solar system or country
    or = {
        has_megastructure = quantum_catapult_1
        has_megastructure = quantum_catapult_2
        has_megastructure = quantum_catapult_3
        has_megastructure = quantum_catapult_restored
        has_megastructure = quantum_catapult_restored_slingshot
        has_megastructure = quantum_catapult_improved_slingshot
    }
}

has_dyson_gun = { # solar system or country
    or = {
        has_megastructure = dyson_gun_0
        has_megastructure = dyson_gun_1
        has_megastructure = dyson_gun_2
        has_megastructure = dyson_gun_3
        has_megastructure = dyson_gun_0_restored
    }
}

# this = country

can_build_all_fe_level_2_buildings = {
    optimize_memory
    or = {
        is_fallen_empire = yes
        and = {
            has_technology = tech_fe_affluence_2
            has_technology = tech_fe_nourishment_2
            has_technology = tech_fe_fabricator_2
            has_technology = tech_fe_singularity_2
            has_technology = tech_fe_forge_2
            has_technology = tech_fe_dome_2
            has_technology = tech_fe_fortress_2
            has_technology = tech_fe_administration_2
            has_technology = tech_fe_assembly_2
            has_technology = tech_fe_clinic_2
            has_technology = tech_fe_security_2
            has_technology = tech_fe_market_2
            has_technology = tech_fe_silo_2
            has_technology = tech_fe_entertainment_2
            has_technology = tech_fe_lab_2
            has_technology = tech_fe_mine_2
        }
    }
}

is_playable_country = { any_playable_country = { is_same_value = prev } }

country_counts_for_victory_calc = {
    or = {
        is_default_or_fallen = yes
        is_country_type = awakened_marauders
        is_country_type = AAA_hidden_crisis
        is_country_type = holy_light
        is_country_type = PAG_gate_gurdian
        is_country_type = PAG_gate_gurdian_awake
        is_country_type = sxx_fallen_guardian
        is_country_type = sxx_awakened_fallen_guardian
    }
}

# this = any, i.e. global

can_win_timed_victory_trigger = {
    custom_tooltip = {
        fail_text = VICTORY_CONDITION_CRISIS_IN_PROGRESS
        NOT = {
            any_country = {
                is_crisis_faction = yes
                NOT = { is_country_type = awakened_marauders }
            }
        }
    }
    custom_tooltip = {
        fail_text = VICTORY_CONDITION_WAR_IN_HEAVEN_IN_PROGRESS
        NOT = { has_global_flag = war_in_heaven_ongoing }
    }
}

### inherited from other mods ###

AOW_trgr_MEGA_is_dyson_sphere = {
    optimize_memory
    or = {
        is_megastructure_type = dyson_sphere_2
        is_megastructure_type = dyson_sphere_3
        is_megastructure_type = dyson_sphere_4
        is_megastructure_type = dyson_sphere_5
        is_megastructure_type = dyson_sphere_restored
        is_megastructure_type = dyson_sphere_disco
        is_megastructure_type = dyson_sphere_disco_restored
    }
}
has_cwc_mod = { always = no }
KZ_VOY_MOD = { always = no }
has_planetary_diversity = { always = no }
has_gigastructures = { always = no }
is_acot_defines_activated = { always = no }
is_acot_override_activated = { always = no }

sxx_loaded = { #修仙传没写，我写了个封装，方便调用
    exists = event_target:sxx_pool_country
}
DAP_loaded = { #DAP没写，我写了个封装，方便调用
    exists = event_target:DAP_caidan
}
libra_mod_plnmg_check = { #童话天秤没写，我写了个封装，方便调用
    optimize_memory
    any_playable_country = { has_country_flag = libra_game_host }
}

### you wanna rickroll others who subscribed your mod? (not implemented yet)
ready2rickroll = {
    or = {
        has_global_flag = ready2rickroll
        and = {
            is_scope_type = country
            has_country_flag = ready2rickroll
        }
    }
}

### debug ###

is_in_any_resource_region = {
    solar_system = {
        or = {
            has_star_flag = resource_region_not_resource_rich
            has_star_flag = resource_region_exotic_gases_rich
            has_star_flag = resource_region_volatile_motes_rich
            has_star_flag = resource_region_rare_crystals_rich
        }
    }
}

is_in_any_resource_cluster = {
    solar_system = {
        or = {
            is_in_cluster = resource_cluster_0
            is_in_cluster = resource_cluster_1
            is_in_cluster = resource_cluster_2
            is_in_cluster = resource_cluster_3
            is_in_cluster = resource_cluster_4
            is_in_cluster = resource_cluster_5
        }
    }
}

#以下不封装两者均可，反之则皆不可
#可能是scripted_trigger封装的问题，也可能是check_variable_arithmetic的问题
#ps. 5.6发现total_workforce_with_job_tag也存在类似问题
# pop_amount_plnmg_debug_test_1 = {
#     check_variable_arithmetic = { which = value:sv_debug_test_plnmg_pop_amount value > 5199 }
# }
# pop_amount_plnmg_debug_test_2 = {
#     check_variable_arithmetic = { which = value:sv_debug_plnmg_copa value > 5199 }
# }
