
hidden_effect = {
    #reroll_random = yes
    solar_system = {
        set_variable = { which = temp_ship_aoe_damage_var value = $damage$ }
        ### randomization
        set_variable_to_random_value = { which = temp_ship_aoe_damage_mult min = 1 max = 100 rounded = yes }
        multiply_variable = { which = temp_ship_aoe_damage_mult value = 0.01 }
        multiply_variable = { which = temp_ship_aoe_damage_var value = temp_ship_aoe_damage_mult }
        clear_variable = temp_ship_aoe_damage_mult
        ### buffs
        multiply_variable = {
            which = temp_ship_aoe_damage_var
            value = from.value:scripted_modifier_mult|MODIFIER|$type$_weapon_damage_mult|
        }
        multiply_variable = {
            which = temp_ship_aoe_damage_var
            value = from.value:scripted_modifier_mult|MODIFIER|$role$_weapon_damage_mult|
        }
        multiply_variable = {
            which = temp_ship_aoe_damage_var
            value = from.value:scripted_modifier_mult|MODIFIER|$slot$_weapon_damage_mult|
        }
        # multiply_variable = {
        #     which = temp_ship_aoe_damage_var
        #     value = from.value:scripted_modifier_mult|MODIFIER|$behavior$_weapon_damage_mult|
        # }
        # multiply_variable = {
        #     which = temp_ship_aoe_damage_var
        #     value = from.value:scripted_modifier_mult|MODIFIER|$category$_weapon_damage_mult|
        # }
        # multiply_variable = {
        #     which = temp_ship_aoe_damage_var
        #     value = from.value:scripted_modifier_mult|MODIFIER|$extra_tag_n$_weapon_damage_mult|
        # }
        floor_variable = temp_ship_aoe_damage_var
        #create_ambient_object = { type = explosion_particle_object location = this }
        every_ship_in_system = {
            if = {
                limit = { distance = { source = prevprev max_distance <= $first_range$ same_solar_system = yes } }
                set_variable = { which = temp_ship_aoe_damage_var value = prev.temp_ship_aoe_damage_var }
                damage_ship = { amount = temp_ship_aoe_damage_var attacker = from }
                clear_variable = temp_ship_aoe_damage_var
            }
            else_if = {
                limit = { distance = { source = prevprev max_distance <= $second_range$ same_solar_system = yes } }
                set_variable = { which = temp_ship_aoe_damage_var value = prev.temp_ship_aoe_damage_var }
                divide_variable = { which = temp_ship_aoe_damage_var value = 2 }
                damage_ship = { amount = temp_ship_aoe_damage_var attacker = from }
                clear_variable = temp_ship_aoe_damage_var
            }
            else_if = {
                limit = { distance = { source = prevprev max_distance <= $third_range$ same_solar_system = yes } }
                set_variable = { which = temp_ship_aoe_damage_var value = prev.temp_ship_aoe_damage_var }
                divide_variable = { which = temp_ship_aoe_damage_var value = 3 }
                damage_ship = { amount = temp_ship_aoe_damage_var attacker = from }
                clear_variable = temp_ship_aoe_damage_var
            }
        }
        every_system_planet_colony = {
            set_variable = { which = temp_planet_devastation value = 100 }
            subtract_variable = { which = temp_planet_devastation value = trigger:planet_devastation }
            if = {
                limit = { distance = { source = prevprev max_distance <= $first_range$ same_solar_system = yes } }
                add_planet_devastation = temp_planet_devastation
            }
            else_if = {
                limit = { distance = { source = prevprev max_distance <= $second_range$ same_solar_system = yes } }
                multiply_variable = { which = temp_planet_devastation value = 0.5 }
                round_variable = temp_planet_devastation
                add_planet_devastation = temp_planet_devastation
            }
            else_if = {
                limit = { distance = { source = prevprev max_distance <= $third_range$ same_solar_system = yes } }
                multiply_variable = { which = temp_planet_devastation value = 0.25 }
                round_variable = temp_planet_devastation
                add_planet_devastation = temp_planet_devastation
            }
            clear_variable = temp_planet_devastation
        }
        clear_variable = temp_ship_aoe_damage_var
    }
    reroll_random = yes
}
