Balance of power modding

本页面所适用的版本可能已经过时,最后更新于1.12

In Vanilla, Balance of powers are used to represent a conflict between two sides through a progress bar divided into distinct sections. The main functionality of Balance of power, also referred to as Bop or powerbalance in code, is located in /Hearts of Iron IV/common/bop/*.txt.

Basics

A Balance of power consists of two sides, which sit on opposite sides of a progress bar. By changing a variables in the Bop, a cursor is moved towards one of the two sides. The value 1 describes the maximum value in the Bop to the right side. The left side includes all values up to -1, 0 being the equilibrium. A modder can include a decision category in the Bop that supports the same functions as a regular decision category. The progressbar, which can be seen at the top of the Bop menu, can be divided into different sections, so-called ranges. Ranges can trigger different continuous or one-time effects when they are activated.

Structure

Balance of power

A Balance of power is defined using TAG_example_balance = { ... } syntax. The name of the Bop is used to identify it in code.

The following arguments are mandatory:

intial_value = ... Is for the starting value of the Bop. The value has to be between -1 and 1.

The sides of the Bop are defined as right_side = ... and left_side = .... The names need to be unique as they are used to identify the sides in code.

decision_category = TAG_example_category makes the decision_category appear in the Bop menu.

Side

Each Bop needs two sides, which are defined with side = { ... }. Each side requires a unique id = ... and icon = GFX_TAG_example_bop_icon. A side can then be divided into any number of ranges. However, the ranges must not overlap.

Range

Any range requires a unique id = ... as well as a min and max value. The values are used to determine which range is active at any given moment.

The effects of a range are scripted in the modifier = { ... } block. (Modifiers) Furthermore, effects can also be specified that are executed when the specific range is activated or deactivated. This can be achieved through the usage of on_activate = { ... } and on_deactivate = { ... }.


Example

TAG_example_balance = {
    initial_value = 0.25
    left_side = default_left_side
    right_side = default_right_side
    decision_category = TAG_example_category
    range = {
        id = mid_range
        min = -0.1
        max = 0.1
        modifier = {
            war_support_weekly = 0.5
        }
    }

    side = {
        id = default_left_side
        icon = GFX_idea_generic_agrarian_society
        range = {
            id = left_side_range
            min = -1
            max = -0.1
            modifier = {
                war_support_weekly = 0.1
            }
        }
    }

    side = {
        id = default_right_side
        icon = GFX_idea_generic_degauss_ship_hulls
        range = {
            id = right_side_range
            min = 0.1
            max = 1
            modifier = {
                war_support_weekly = 0.9
            }
        }
    }
}

Modifying a Balance of Power

There are two main ways of adding to or subtracting from a Balance of power. One can either add a flat value through an effect or apply a modifier for continuous Bop change.

Effect

The effect add_power_balance_value = { ... } requires the name of the power balance, for example TAG_example_balance and a value between -1 and 1.

add_power_balance_value = {
    id = TAG_example_balance
    value = -0.25
}

Bop Modifier

A Bop modifier is defined within common/modifiers/*.txt with the following syntax:

TAG_example_balance_modifier = {
    power_balance_daily = 0.05
}

Another valid argument would be power_balance_weekly = -0.005.

Bop modifiers can be applied or removed with the effect add_power_balance_modifier = { ... } and remove_power_balance_modifier = { ... }.