
#situation scope

plnmg_spacemega_build_speed_mult = {
    modifier = {
        add = owner.modifier:megastructure_build_speed_mult
        owner? = {
            or = {
                is_ai = no
                is_default_or_fallen = yes
            }
        }
    }
    mult = @progressBase_buildPlanetMega
    mult = 1.5
    modifier = {
        current_situation_approach = planetmega_approach_reverse
        min = 0
    }
}
plnmg_spacemega_build_speed_mult_uti = {
    modifier = {
        add = owner.modifier:megastructure_build_speed_mult
        owner? = {
            or = {
                is_ai = no
                is_default_or_fallen = yes
            }
        }
    }
    mult = @progressBase_buildPlanetMega
    modifier = {
        current_situation_approach = planetmega_approach_reverse
        min = 0
    }
}

plnmg_mega_build_speed_mult = {
    modifier = {
        add = target.modifier:ground_megastructure_build_speed_mult
        target? = { is_scope_type = planet }
    }
    mult = @progressBase_buildPlanetMega
    modifier = {
        current_situation_approach = planetmega_approach_reverse
        min = 0
    }
}
plnmg_mega_build_speed_mult_uti = {
    modifier = {
        add = target.modifier:ground_megastructure_build_speed_mult
        target? = { is_scope_type = planet }
    }
    mult = @progressBase_buildPlanetMega
    mult = 0.5
    modifier = {
        current_situation_approach = planetmega_approach_reverse
        min = 0
    }
}

plnmg_plnt_build_speed_mult = {
    modifier = {
        add = target.modifier:planet_building_build_speed_mult
        target? = { is_scope_type = planet }
    }
    mult = @progressBase_buildPlanetMega
    mult = 0.5 #小削一下
    modifier = {
        current_situation_approach = planetmega_approach_reverse
        min = 0
    }
}

planetmega_custom_speed_mult = {
    modifier = {
        add = owner.num_plnmg_mega_speed_custom_mult
        owner? = { is_variable_set = num_plnmg_mega_speed_custom_mult }
    }
    modifier = {
        add = event_target:global_event_country.num_plnmg_mega_speed_custom_mult
        event_target:global_event_country = { is_variable_set = num_plnmg_mega_speed_custom_mult }
    }
    modifier = {
        event_target:global_event_country = { is_variable_set = num_plnmg_mega_speed_player_mult }
        owner? = { is_ai = no }
    }
    modifier = {
        add = event_target:global_event_country.num_plnmg_mega_speed_ai_mult
        event_target:global_event_country = { is_variable_set = num_plnmg_mega_speed_ai_mult }
        owner? = { is_ai = yes }
    }
    mult = @progressBase_buildPlanetMega
    modifier = {
        is_scope_type = situation
        current_situation_approach = planetmega_approach_reverse
        min = 0
    }
}

sv_plnmg_sit_upkp_mult = {
    base = 1
    add = value:sv_plnmg_sit_upkp_bm_mult
    add = value:sv_plnmg_sit_upkp_plus_mult
    add = target.modifier:ground_megastructure_build_upkeep_mult
    min = 0
}
sv_plnmg_sit_upkp_bm_mult = {
    add = target.modifier:planet_buildings_mega_upkeep_mult
    mult = 0.5
}

sv_plnmg_sit_upkp_plus_mult = { #final is percent, should not obtain base=1
    base = 1
    add = value:sv_plnmg_sit_speed_plus_mult
    modifier = {
        check_variable_arithmetic = { which = value:sv_plnmg_sit_speed_plus_mult value > 0 }
        or = {
            not = { exists = owner }
            owner = { can_do_planetmega_ultimate_adjusting = no }
        }
        pow = 2
    }
    subtract = 1
    min = -1
}

sv_plnmg_sit_speed_plus_mult = { #final is percent, should not obtain base=1
    modifier = { #situation only or planet only
        or = {
            is_scope_type = situation
            is_scope_type = planet
        }
        is_variable_set = var_plnmg_sit_speed_plus_mult
        add = var_plnmg_sit_speed_plus_mult
    }
    modifier = { #from situation get planet
        target? = { is_variable_set = var_plnmg_sit_speed_plus_mult }
        add = target.var_plnmg_sit_speed_plus_mult
    }
    modifier = { #from any get country
        owner? = { is_variable_set = var_plnmg_sit_speed_plus_mult }
        add = owner.var_plnmg_sit_speed_plus_mult
    }
    #min = 0
}
sv_plnmg_sit_speed_final_mult = { #applys to situation progress, would be a multiplier
    base = 1
    add = value:sv_plnmg_sit_speed_plus_mult
}

plnmg_const_sit_tp_non_cntr_mult = {
    base = 1
    modifier = {
        add = 0.1
        or = {
            has_situation_flag = building_admin_axis
            has_situation_flag = building_primary_mind_pyramid
            has_situation_flag = building_plnmg_tms_control
            has_situation_flag = building_plnmg_omnipotence
        }
    }
    modifier = {
        add = 0.05
        or = {
            has_situation_flag = building_commercial_shikara
            has_situation_flag = building_plnmg_financial_shikara
            has_situation_flag = building_great_laboratory
            has_situation_flag = building_plnmg_supercom
            has_situation_flag = building_plnmg_fusion_brain
            has_situation_flag = building_heaven_colossal
            has_situation_flag = building_hakkou_ichiu_tower
            has_situation_flag = building_logistics_shikara
            has_situation_flag = building_plnmg_extra_galaxy
        }
    }
    modifier = {
        subtract = 0.05
        or = {
            has_situation_flag = building_ecodome_complex
            has_situation_flag = building_plnmg_singularity_generator
        }
    }
    modifier = {
        subtract = 0.1
        or = {
            has_situation_flag = building_giant_power_battery
            has_situation_flag = building_vertical_farm_edifice
            has_situation_flag = building_hive_farm_edifice
            has_situation_flag = building_matter_demodulator
            has_situation_flag = building_plnmg_world_shaper
        }
    }
}

# this = planet

plnmg_mega_owned_count_value = {
    complex_trigger_modifier = {
        trigger = count_deposit
        parameters = { limit = { is_plnmg_any_mega = yes } }
        mode = set
    }
}

plnmg_mega_owned_limit_value = {
    set = trigger:planet_size
    add = modifier:planet_max_districts_add
    modifier = {
        add = modifier:planet_artificial_max_districts_add
        is_artificial = yes
    }
    modifier = {
        add = modifier:planet_non_artificial_max_districts_add
        is_artificial = no
    }
    modifier = {
        add = owner.modifier:habitat_max_districts_add
        planet_is_habitat_equivalent = yes
    }
    divide = @plnmg_mega_owned_limit_divisor
    # modifier = {
    #     # habitat's planet size is 6 currently
    #     mult = @plnmg_mol_divisor_hab_compensation
    #     planet_is_habitat_equivalent = yes
    # }
    # modifier = {
    #     # ringworld's planet size is 10 currently
    #     mult = @plnmg_mol_divisor_rw_compensation
    #     planet_is_ring_world_equivalent = yes
    # }
    # modifier = {
    #     # arkship's planet size is 9 currently
    #     mult = @plnmg_mol_divisor_ark_compensation
    #     is_planet_class = pc_ark
    # }
    divide = value:scripted_modifier_mult_capped|MODIFIER|planetmega_space_need_mult|CAP|0.05|
    modifier = {
        is_artificial = yes
        divide = owner.value:scripted_modifier_mult_capped|MODIFIER|planetmega_space_need_artificial_mult|CAP|0.05|
    }
    modifier = {
        is_ideal = yes
        is_artificial = no
        divide = owner.value:scripted_modifier_mult_capped|MODIFIER|planetmega_space_need_ideal_mult|CAP|0.05|
    }
    modifier = {
        or = {
            and = { planet_is_ecu_equivalent = yes }
            is_plnmg_mod_city_world = yes
        }
        is_artificial = no
        is_ideal = no
        divide = owner.value:scripted_modifier_mult_capped|MODIFIER|planetmega_space_need_ecu_mult|CAP|0.05|
    }
    round = yes
    add = modifier:planetmega_owned_limit_add
    modifier = {
        add = owner.modifier:planetmega_owned_limit_habitat_add
        planet_is_habitat_equivalent = yes
    }
    modifier = {
        add = owner.modifier:planetmega_owned_limit_ringworld_add
        planet_is_ring_world_equivalent = yes
    }
    modifier = {
        add = owner.modifier:planetmega_owned_limit_arkship_add
        carrier_is_type = ship
    }
    min = 0
    max = value:plnmg_mega_owned_limit_max
}
plnmg_mega_owned_limit_max = {
    set = trigger:planet_size
    modifier = {
        mult = @plnmg_mega_owned_limit_max_mult
        or = {
            has_carrier_flag = planetmega_owned_limit_breaked
            owner? = { has_country_flag = planetmega_owned_limit_breaked }
        }
    }
}

plnmg_mega_build_count_value = {
    complex_trigger_modifier = {
        trigger = count_targeting_situation
        parameters = { limit = { situation_is_plnmg_construction = yes } }
        mode = set
    }
}

plnmg_mega_build_limit_value = {
    add = modifier:planet_building_capacity_add
    divide = 3
    round = yes
    add = 1
    add = modifier:ground_megastructure_build_cap_add
    add = owner.modifier:country_megastructure_build_cap_add
    # modifier = {
    #     owner = { has_tradition = tr_pm_granchor_dynexp_1 }
    #     add = 1000
    # }
    min = 1
}
