Building modding

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

A building is a structure built using Civilian factories in states or provinces.

Buildings

Buildings are defined within /Hearts of Iron IV/common/buildings/*.txt. Each building entry lies within the buildings = { ... } block, serving as its own block with arguments within defining the building, as this:

buildings = {
    my_building = {
        <...>
    }
}

Cost

Each building has a set price in industrial capacity required. This cost is defined with the lines of base_cost = 1000 and per_level_extra_cost = 100.

base_cost is the primary cost to build the building, added to each building level, while per_level_extra_cost gets added for each building level in an arithmetic progression. With the example of 1000 base_cost and 100 per_level_extra_cost, the first level will cost 1000 IC to build, while the 5th level will cost 1400 IC, as 4 levels have been built before that.

By default, each civilian factory provides 5 IC per day[1], which can be taken into account when calculating the cost. For comparison, by default a civilian factory costs 10800 IC, while infrastructure costs 6000 IC.

Additionally, infrastructure_construction_effect = yes, if included, will make the building get the building speed boost from any infrastructure built in the state, with a +20% boost per infastructure level[2].

Used slots

In general, buildings fall into 3 categories by used building slots:

  • Shared, which use the same, by default, 25 shared slots[3] for each state, such as civilian and military factories.
  • Non-shared, defined for states, but using slots that are unique for this building in particular, such as infrastructure or air bases.
  • Provincial, which get built for each province, using slots that are unique for this building in particular, such as forts or naval bases.

If not specified otherwise, a building is assumed to be non-shared. The 3 categories have separate zones in the country construction view where they are located.
provincial = yes, if added, will make the building be considered provincial, while shares_slots = yes will make it be considered shared if added. These cannot be combined.

Adding max_level = 10 can set a max level to which this building can be built. If it is unspecified, it gets assumed to be 15[4] by default.

By default, all levels of the building are unlocked by default. However, if there are technologies that enable construction of this building to a specified level, it becomes impossible to build without obtaining at least one of these technologies. It is to be noted that the add_building_construction effect or the starting state buildings can still be used to bypass the technological limit, while still not being possible to bypass the max level total.

Additional arguments

value = 3 decides the base health of a building for air bombing campaigns, which gets multiplied for each level of the building. Additionally, this also determines the price of the state to get during peace conferences or the cost in 政治点数政治点数 to occupy.

damage_factor = 0.3 modifies the damage that this building gets from air bombing or land combat. Positive values increase it, while negatives decrease it.

allied_build = yes, if specified, makes the building count as an allied building, making its modifiers apply not just on the country that built it, but also its allies (i.e. subjects, overlord, and/or faction members).

only_costal = yes (sic), if specified, will make the building only be possible to build in either provinces that are defined as coastal or states that contain any such provinces, depending on the type of the building.

disabled_in_dmz = yes, if added, will make the building impossible to build or use in states that are demilitarised zones.

Icon

The building icon is defined as icon_frame = 10. The integer shows which frame within the GFX_buildings_strip sprite gets used for this building.

By default, GFX_buildings_strip is defined within /Hearts of Iron IV/interface/countrystateview.gfx, however, it can be overwritten in any /Hearts of Iron IV/interface/*.gfx which is positioned later by filename order:

spriteType = {
    name = "GFX_buildings_strip"
    textureFile = "gfx/interface/buildings/building_icon_strip.dds"
    noOfFrames = 16     # As of 1.11
}

The noOfFrames decides in how many frames the specified sprite is divided into, dividing the image horizontally into chunks of approximately equal width. If planning to add a new building icon rather than using a base game one, the building icon strip will need to be updated both in the noOfFrames and in the .dds file. By default, each building has a 46x46 resolution in pixels.

Within the building construction menu, buildings are divided into 3 zones depending on their used building slots category. In order to change where they are to adjust for new or missing buildings, the elements within the possible_constructions container in /Hearts of Iron IV/interface/countryconstructionsview.gui can have their positions changed.

Models

主条目:Entity modding

There are several arguments related to models within buildings.
show_on_map = 3 decides how many building models should there be per state or per province (depending on the building type) defined for the building. Each building construction will add one more model. If unspecified, will have no map models.
show_on_map_meshes = 2 decides how many entities are used for each building model. By default assumed to be 1.
always_shown = yes, if specified, will make the building model appear regardless whether it's covered by the fog of war or not.
has_destroyed_mesh = yes, if specified, will make the game use a separate model if the building has been destroyed by air bombing or occupation.
centered = yes, if specified, will mak

In order to assign an entity to a building, it must have a name of building_<building name>, like building_my_building, within the /Hearts of Iron IV/gfx/entities/*.asset file. If a building is set to use several entities, then the number will get appended in the end like building_my_building_1, starting with 1. If there's a destroyed mesh, then it'll append _destroyed in the end as building_my_building_destroyed

The locations of building models for each state are defined in /Hearts of Iron IV/map/buildings.txt. An entry in that file is defined as such (If unspecified, assume a number with up to 2 decimal digits):

State ID (integer); building ID (string); X position; Y position; Z position; Rotation; Adjacent sea province (integer)
  • State ID defines which state the building is located in. Even for provincial buildings, this is the ID of the state, not the province. Instead, provincial buildings have several entries per state, with the XYZ position being used by the game to know which province it's for.
  • Building ID is defines which model is being located. While this includes each building, this also includes floating harbours as floating_harbor.
  • X, Y, and Z position represent the position on the map of the building model using the 3-dimensional Cartesian coordinate system. The X and Z positions are equivalent to the X and Y axes on the province bitmap with 1 pixel equalling 1 unit, left-to-right and down-to-up respectively. This is also what the game uses to know which province it's for for provincial buildings. The Y position, on the scale of 0 to 25.5, can be calculated with the heightmap by taking the colour value of the pixel at that position and making it fit on the scale of 0 to 25.5 (Such as by dividing it by 10 if it's on the scale of 0 to 255).
  • Rotation is measured in radians. A rotation of 0 will result in the building model pointing in the same direction as the model is set, while positives will rotate it counter-clockwise and negatives will rotate it clockwise. A full rotation resulting in the same position as 0 is equal to the number π multiplied by 2, roughly 6.28.
  • Adjacent sea province is only necessary to define for naval bases and floating harbours, in order to let the game know from which sea province ships or convoys can access the land province where it is located. If the building type is not a naval base, it should be left at 0.

It is preferable to generate the building models in the building section in the nudger, rather than filling it out manually. However, note that the game will crash if the currently-existing /Hearts of Iron IV/map/buildings.txt file is entirely empty, so there should be at least one definition, even if incorrect.

Effects

Each building can accept any state-scoped modifier within itself, applying that to the state when built. Some used in base game include local_resources_<resource>, air_defence (for anti-air), and nuclear_production_factor (for nuclear reactors). In case of provincial buildings, province-level modifiers are accepted instead. This can also be used with modifier tokens to create a custom effect as a variable system. Adding show_modifier = yes will make the modifiers show up in the tooltip of the building.

Aside from state-scoped modifiers, there are several other arguments to make the building have the same effect as a base game building or be considered one for the AI:

Name Effects Examples Type Notes
military_production Adds the specified amount of military factories to the controller.
military_production = 0.5
Flat. A value that's larger than 1 will be the same as 1 factory, but it can fall between 0 and 1.
general_production Adds the specified amount of civilian factories to the controller.
general_production = 0.5
Flat. A value that's larger than 1 will be the same as 1 factory, but it can fall between 0 and 1.
naval_production Adds the specified amount of dockyards to the controller.
naval_production = 0.5
Flat. A value that's larger than 1 will be the same as 1 factory, but it can fall between 0 and 1.
infrastructure Makes the building be marked as infrastructure.
infrastructure = yes
Boolean. Includes the construction speed bonus and extra resources.
air_base Makes the building be marked as an air base.
air_base = yes
Boolean.
supply_node Makes the building be marked as a supply node.
supply_node = yes
Boolean.
is_port Makes the building be marked as a naval port.
is_port = yes
Boolean.
land_fort Adds that many land forts to the province.
land_fort = 1
Flat.
naval_fort Adds that many coastal forts to the province.
naval_fort = 1
Flat.
refinery Makes the building be marked as a synthetic refinery.
refinery = yes
Boolean.
fuel_silo Makes the building be marked as a fuel silo.
fuel_silo = yes
Boolean.
radar Makes the building be marked as a radar station.
radar = yes
Boolean.
rocket_production Defines how much progress on rocket production is done daily.
rocket_production = 5
Flat.
rocket_launch_capacity Defines how many rockets the build can launch daily.
rocket_launch_capacity = 5
Flat.
nuclear_reactor Makes the building be marked as a nuclear reactor.
nuclear_reactor = yes
Boolean.

Example

buildings = {
    my_provincial_building = {
        base_cost = 10000
        infrastructure_construction_effect = yes
        
        provincial = yes
        max_level = 3
        
        value = 1
        
        icon_frame = 17
        
        show_on_map = 1
        always_shown = yes
        
        army_attack_factor = 0.1
        army_defence_factor = 0.3
    }
    my_shared_building = {
        base_cost = 1000
        per_level_extra_cost = 200
        infrastructure_construction_effect = yes
        
        shares_slots = yes  # Max level of 15 since undefined
        
        value = 15
        only_costal = yes
        
        icon_frame = 18
        
        show_on_map = 3
        show_on_map_meshes = 3
        has_destroyed_mesh = yes
        
        military_production = 1
        general_production = 1
        naval_production = 1
    }
    my_non_shared_building = {
        base_cost = 1000
        per_level_extra_cost = 2000
        
        max_level = 2
        
        value = 5
        
        icon_frame = 19     # No model is defined
        
        recruitable_population_factor = 0.5
    }
}

Localization

Buildings use the following localization keys, using my_building as an example:

 my_building: "My building"
 my_building_desc: "My building's description"
 my_building_plural: "My buildings"
 modifier_production_speed_my_building_factor: "§Y$my_building$§! construction speed"
 modifier_production_speed_my_building_factor_desc: "Modifies the speed of §Y$my_building$§! construction."
 modifier_state_production_my_building_factor:0 "§Y$my_building$§! construction speed"
 modifier_state_production_my_building_factor_desc:0 "Modifies the speed of §Y$my_building$§! construction in this state."

The first 3 are used for the building itself in various UI elements, while the last 4 are used to localise the modifiers automatically created for each building: production_speed_<building>_factor and state_production_speed_<building>_factor.

Types

These are the different types of buildings in the game as of 1.11 (Can also be found inside /Hearts of Iron IV/common/buildings/00_buildings.txt):

Icon Localised name Internal name Maximum level Type
Infrastructure.png Infrastructure infrastructure 5 Non-shared
Military factory.png Military factory arms_factory 20 Shared
Civilian factory.png Civilian factory industrial_complex 20 Shared
Air base.png Air base air_base 10 Non-shared
Supply hub.png Supply hub supply_node 1 Provincial
Railway.png Railway rail_way 5 Provincial
Land fort.png Land fort bunker 10 Provincial
Coastal fort.png Coastal fort coastal_bunker 10 Provincial
Naval dockyard.png Naval dockyard dockyard 20 Shared
Anti-air (building).png Anti-air anti_air_building 5 Non-shared
Synthetic refinery.png Synthetic refinery synthetic_refinery 3 Shared
Fuel silo.png Fuel silo fuel_silo 15 Shared
Radar station.png Radar station radar_station 6 Non-shared
Rocket site.png Rocket site rocket_site 2 Non-shared
Nuclear reactor.png Nuclear reactor nuclear_reactor 1 Non-shared

Note that while railways and supply nodes are buildings, not all traditional building operations apply to them. Their starting level is defined outside of state history and a separate effect must be used to construct railways mid-game, with the default add_building_construction or other building-related effects crashing the game.

References

  1. BASE_FACTORY_SPEED = 5 in common/defines/00_defines.lua
  2. INFRA_MAX_CONSTRUCTION_COST_EFFECT = 1 in common/defines/00_defines.lua means a +100% speed bonus for max infrastructure. By default, infrastructure has 5 max levels, making the boost be divided into 5 portions of 20%, depending on the building level.
  3. MAX_SHARED_SLOTS = 25 in common/defines/00_defines.lua
  4. MAX_BUILDING_LEVELS = 15 in common/defines/00_defines.lua