# Reads AA, radar, and rocket building levels from var:target_state and composes # the multiplicative AA defence value into the `aa_defense` temp variable. # Result is clamped to a minimum of 1 so callers can divide by aa_defense # unconditionally (a state with no AA and no rocket sites yields 1, i.e. no # damage reduction and no plane-loss multiplier). calculate_aa_defense_value = { var:target_state = { set_temp_variable = { ROOT.aa_defense = THIS.non_damaged_building_level@anti_air_building } set_temp_variable = { ROOT.radar_mult = THIS.non_damaged_building_level@radar_station } set_temp_variable = { ROOT.rocket_mult = THIS.non_damaged_building_level@rocket_site } } add_to_temp_variable = { radar_mult = 0.5 } multiply_temp_variable = { aa_defense = radar_mult } multiply_temp_variable = { rocket_mult = radar_mult } if = { limit = { NOT = { check_variable = { rocket_mult = 0 } } } multiply_temp_variable = { aa_defense = rocket_mult } if = { limit = { check_variable = { aa_defense = 0 } } add_to_temp_variable = { aa_defense = rocket_mult } } } if = { limit = { check_variable = { aa_defense = 0 } } add_to_temp_variable = { aa_defense = 1 } } } # Composes aa_defense and applies it as the plane-loss multiplier. # Used in actor_effects after setting raid_planes_lost. calculate_raid_aa_defense = { calculate_aa_defense_value = yes multiply_temp_variable = { raid_planes_lost = aa_defense } } # Clamps, rounds, applies raid_damage_units, and shows the plane-loss tooltip. # Call after all war/non-war loss multipliers have been applied. finalize_raid_plane_losses = { clamp_temp_variable = { var = raid_planes_lost min = 0 } round_temp_variable = raid_planes_lost hidden_effect = { raid_damage_units = { plane_loss = raid_planes_lost ratio = no } } custom_effect_tooltip = { localization_key = plane_raid_losses_tt LOSSES = [?raid_planes_lost] } } apply_discounted_raid_pp_cost = { var:actor_country = { if = { limit = { NOT = { has_war_with = var:ROOT.victim_country } } set_temp_variable = { adjusted_raid_pp_loss = { value = PREV.raid_pp_loss multiply = { value = 1 add = modifier@raid_cost_factor } } } add_political_power = adjusted_raid_pp_loss } } } # Standard 3-tier building-damage flow for a victim_effects block. # Caller sets `building_damage_by_missile` (tier base damage) and `raid_damage_mult` # (the raid-specific post-multiply, e.g. 10/25/50/70) before calling. The helper # rolls per-tier missile luck, divides by aa_defense, and applies the raid # multiplier. aa_defense is assumed to have been computed by # calculate_aa_defense_value (which clamps it to >= 1). Per-tier luck ranges: # limited 0.4-0.6 # success 0.6-0.8 # critical 0.8-1.0 apply_raid_building_damage_limited = { set_temp_variable_to_random = { var = missile_luck_mod min = 0.4 max = 0.6 } multiply_temp_variable = { building_damage_by_missile = missile_luck_mod } divide_temp_variable = { building_damage_by_missile = aa_defense } multiply_temp_variable = { building_damage_by_missile = raid_damage_mult } } apply_raid_building_damage_success = { set_temp_variable_to_random = { var = missile_luck_mod min = 0.6 max = 0.8 } multiply_temp_variable = { building_damage_by_missile = missile_luck_mod } divide_temp_variable = { building_damage_by_missile = aa_defense } multiply_temp_variable = { building_damage_by_missile = raid_damage_mult } } apply_raid_building_damage_critical = { set_temp_variable_to_random = { var = missile_luck_mod min = 0.8 max = 1 } multiply_temp_variable = { building_damage_by_missile = missile_luck_mod } divide_temp_variable = { building_damage_by_missile = aa_defense } multiply_temp_variable = { building_damage_by_missile = raid_damage_mult } } # Standard 4-tier plane-loss flow for an actor_effects block. # Caller sets `set_temp_variable = { raid_pp_loss = -100 }` (or -300) before the call; # this value is added to political power if the actor is not at war with the victim. apply_raid_failure_losses = { set_temp_variable = { raid_planes_lost = 0 } set_temp_variable_to_random = { var = raid_planes_lost max = 8 } calculate_raid_aa_defense = yes if = { limit = { var:actor_country = { has_war_with = var:ROOT.victim_country } } multiply_temp_variable = { raid_planes_lost = 1.5 } } else = { set_temp_variable_to_random = { var = random_chance_on_dead_planes max = 2 integer = yes } if = { limit = { check_variable = { random_chance_on_dead_planes = 2 } } subtract_from_temp_variable = { random_chance_on_dead_planes = 1 } } multiply_temp_variable = { raid_planes_lost = random_chance_on_dead_planes } } finalize_raid_plane_losses = yes apply_discounted_raid_pp_cost = yes } apply_raid_limited_success_losses = { set_temp_variable = { raid_planes_lost = 0 } set_temp_variable_to_random = { var = raid_planes_lost max = 5 } calculate_raid_aa_defense = yes if = { limit = { var:actor_country = { has_war_with = var:ROOT.victim_country } } multiply_temp_variable = { raid_planes_lost = 1.25 } } else = { set_temp_variable_to_random = { var = random_chance_on_dead_planes max = 1 integer = yes } multiply_temp_variable = { raid_planes_lost = random_chance_on_dead_planes } } finalize_raid_plane_losses = yes apply_discounted_raid_pp_cost = yes } apply_raid_success_losses = { set_temp_variable = { raid_planes_lost = 0 } set_temp_variable_to_random = { var = raid_planes_lost max = 3 } calculate_raid_aa_defense = yes if = { limit = { var:actor_country = { has_war_with = var:ROOT.victim_country } } multiply_temp_variable = { raid_planes_lost = 1.15 } } else = { set_temp_variable_to_random = { var = random_chance_on_dead_planes max = 1 integer = yes } if = { limit = { NOT = { check_variable = { random_chance_on_dead_planes = 1 } } } set_temp_variable = { random_chance_on_dead_planes = 0 } } multiply_temp_variable = { raid_planes_lost = random_chance_on_dead_planes } } finalize_raid_plane_losses = yes apply_discounted_raid_pp_cost = yes } apply_raid_critical_success_losses = { set_temp_variable = { raid_planes_lost = 0 } set_temp_variable_to_random = { var = raid_planes_lost max = 2 } calculate_raid_aa_defense = yes if = { limit = { var:actor_country = { has_war_with = var:ROOT.victim_country } } multiply_temp_variable = { raid_planes_lost = 0.95 } } else = { set_temp_variable_to_random = { var = random_chance_on_dead_planes max = 1 } multiply_temp_variable = { raid_planes_lost = random_chance_on_dead_planes } } finalize_raid_plane_losses = yes apply_discounted_raid_pp_cost = yes } send_events_to_others = { hidden_effect = { for_each_loop = { array = FROM.faction_members value = raid_notification_recipient var:raid_notification_recipient = { if = { limit = { NOT = { tag = ROOT } NOT = { original_tag = FROM } NOT = { has_country_flag = disable_raid_notification } } country_event = MD_raid.12 } } } for_each_loop = { array = FROM.neighbors value = raid_notification_recipient var:raid_notification_recipient = { if = { limit = { NOT = { tag = ROOT } NOT = { original_tag = FROM } NOT = { is_in_faction_with = FROM } NOT = { has_country_flag = temp_flag_raids } NOT = { has_country_flag = disable_raid_notification } } country_event = { id = MD_raid.10 days = 1 } } } } } } send_raid_event_to_victim = { var:ROOT.actor_country = { if = { limit = { NOT = { has_war_with = var:ROOT.victim_country } } hidden_effect = { set_variable = { THIS.target_country = var:ROOT.victim_country } set_variable = { THIS.actor_country = var:ROOT.actor_country } country_event = MD_raid.8 } } } } send_ct_raid_events_to_victim = { hidden_effect = { var:ROOT.actor_country = { set_variable = { THIS.target_country = var:ROOT.victim_country } set_variable = { THIS.actor_country = var:ROOT.actor_country } country_event = MD_terror.17 } } } # Applies suicide-drone-swarm damage to the victim's divisions in target_state. # Caller must first set: # missile_luck_mod — pre-rolled luck multiplier per success tier # drone_damage_spread — base spread per success tier (higher = more damage) # Required scope vars: var:victim_country, var:target_state apply_drone_swarm_damage = { var:victim_country = { set_country_flag = { flag = drone_swarm_striked days = 1 value = 1 } set_temp_variable = { ROOT.num_divs_targeted = THIS.num_armies_in_state@var:ROOT.target_state } } var:target_state = { set_temp_variable = { ROOT.aa_defense = THIS.non_damaged_building_level@anti_air_building } set_temp_variable = { ROOT.radar_mult = THIS.non_damaged_building_level@radar_station } } add_to_temp_variable = { radar_mult = 0.5 } multiply_temp_variable = { aa_defense = radar_mult } set_temp_variable = { drone_damage_to_unit = 2 } multiply_temp_variable = { drone_damage_to_unit = missile_luck_mod } if = { limit = { check_variable = { aa_defense > 0 } } divide_temp_variable = { drone_damage_to_unit = aa_defense } } clamp_temp_variable = { var = num_divs_targeted min = 1 } divide_temp_variable = { drone_damage_spread = num_divs_targeted } multiply_temp_variable = { drone_damage_to_unit = drone_damage_spread } multiply_temp_variable = { drone_damage_to_unit = 0.5 } set_temp_variable = { str_dam = drone_damage_to_unit } var:target_state = { meta_effect = { text = { damage_units = { state = THIS limit = { has_country_flag = drone_swarm_striked } org_damage = [ORG] str_damage = [STR] ratio = no army = yes navy = no } } ORG = "[?drone_damage_to_unit]" STR = "[?str_dam]" } add_dynamic_modifier = { modifier = sucide_drone_swarms days = 10 } } } # Specific Raid Strike Success production_strike_success_damage = { if = { limit = { arms_factory > 0 } meta_effect = { text = { damage_building = { type = arms_factory damage = [DAM] } } DAM = "[?building_damage_by_missile]" } } if = { limit = { dockyard > 0 } meta_effect = { text = { damage_building = { type = dockyard damage = [DAM] } } DAM = "[?building_damage_by_missile]" } } if = { limit = { industrial_complex > 0 } meta_effect = { text = { damage_building = { type = industrial_complex damage = [DAM] } } DAM = "[?building_damage_by_missile]" } } if = { limit = { offices > 0 } meta_effect = { text = { damage_building = { type = offices damage = [DAM] } } DAM = "[?building_damage_by_missile]" } } if = { limit = { agriculture_district > 0 } meta_effect = { text = { damage_building = { type = agriculture_district damage = [DAM] } } DAM = "[?building_damage_by_missile]" } } }