钢铁雄心 IV 中文离线资料库

Unit模组制作

原页面:Unit modding

本页中文翻译进度 73%,未译部分暂保留英文原文。

单位是装备被应用到的基层对象。在内部,单位实际上是硬编码单位类型(如步兵、骑兵、战斗机等)的子单位。

单位类别

单位类别位于/Hearts of Iron IV/common/unit_tags/00_categories.txt中。

每个单位都被指派一个类别,该类别在科技中用于一次性对一组单位施加效果。

以下来自某项科技的示例为所有带有category_all_infantry类别的单位提供加成:

category_all_infantry = {
    hard_attack = 0.25
    ap_attack = 1
}

单位

单位位于/Hearts of Iron IV/common/units/*.txt中。

单位遵循以下格式:

sub_units = {
    <unit name> = {
        sprite = <entity> # Refers to <name>_entity in a gfx/entities/.*.asset file - Controls the unit used on the map
        
        # Controls the map icon category used for the unit
        map_icon_category = <type>

        priority = <int>    # Controls which icon is used if multiple subunits of the same type exist
        ai_priority = <int>

        active = yes / no       # Whether the unit is usable without explicit unlocking in technology
        cavalry = yes           # Used to define subunit as cavalry 
        special_forces = yes    # Used to define subunit as special forces
        marines = yes           # Used to define subunit as marine
        can_exfiltrate_from_coast = yes # Used to define subunit opportunity of leaving the coast without a naval base
        mountaineers = yes      # Used to define subunit as mountaineers
        can_be_parachuted = yes # Used to define subunit as paratroopers.
        affects_speed = yes     # Used to check if the unit will affect the template's speed, support companies have it set to no.

        transport = <equipment> # Sets the speed of subunit via equipment. Used for motorized/mechanized
        
        # How the unit is grouped division-wise, i.e. appearing in the Support tab. Not used for air or naval units
        group = <group>
        
        # Internal types
        type = {
            <type>
        }
        
        # Categories the unit belongs to.
        categories = {
            <categories>
        }
        
        # Equipment that is required for this unit. Used when active = no
        essential = {
            <equipment>
        }
        
        # Equipment needed to produce this unit. Unit won't be available until the nation has this equipment
        need = {
            <equipment>
        }
        
        # Modifiers control the stats of the unit. More detail under the Stats section.
        <modifiers>
        
        # Modifiers that occur only in specific terrain
        <terrain> = {
            <modifiers>
        }
    }
}

你不能添加新的内部或地图图标类型,但可以添加新的组。

如何添加新组

在任何单位文件中,在「group」参数里输入新组的名称。游戏会在内部创建该组并将其指派给当前单位。例如:

group = <group name>

然后,为了给我们新创建的组添加本地化,我们必须前往任意本地化文件(最好是/Hearts of Iron IV/localisation/unit_I_english.yml),并按如下方式定义一个新的本地化键:

group_<group name>_title:0 "Group name here"

要为新的组指派图标,你必须前往/Hearts of Iron IV/interface/subuniticons.gfx并按如下方式定义一个新的 sprite 类型:

spriteType = { name = "GFX_group_<group name>_icon"	     textureFile = "gfx/interface/counters/divisions_large/<icon file name>.dds" noOfFrames = 2 }

Note that the textureFile path doesn't have to be strictly /Hearts of Iron IV/gfx/interface/counters/divisions_large/, it can be any path.

Models

另见:Entity模组制作

模型通过sprite = SPRITE属性来指派,默认把基础名称为SPRITE_entity的实体指派给师编制中该子单位占多数的单位。与country names类似,可以通过更改模型名称来指派更多条件,在本例中是在基础名称前加上前缀。优先级从默认名称作为最低,然后允许对graphical cultures、国家或外观标签使用独特模型。

一个/Hearts of Iron IV/gfx/entities/*.asset文件示例如下:

entity = {
	name = SPRITE_entity # A simple model for a land unit
	pdxmesh = example_mesh # References a mesh defined in a *.gfx file

	default_state = idle
	state = { name = attack			animation = attack 					animation_blend_time = 0.0  animation_speed = 1.0 }
	state = { name = defend			animation = defend 			animation_blend_time = 0.3  animation_speed = 1.0 }
	state = { name = support_attack	animation = support_attack 	animation_blend_time = 0.3 animation_speed = 1.0 }
	state = { name = move				animation = move 		 		animation_blend_time = 1.0 animation_speed = 1.0 }
	state = { name = retreat			animation = retreat 	 		animation_blend_time = 0.3 animation_speed = 1.0 }
	state = { name = death			animation = death 			animation_blend_time = 0.3 animation_speed = 1.0 }
	state = { name = idle				animation = idle       		animation_blend_time = 0.3 animation_speed = 1.0 }
	state = { name = training				animation = training 			animation_blend_time = 0.3 animation_speed = 1.0 }

	scale = 0.8
}
entity = {
    name = middle_eastern_gfx_SPRITE_entity # Countries with the middle_eastern_gfx graphical culture will use a different mesh, with all other details the same
    clone = SPRITE_entity
    pdxmesh = middle_eastern_example_mesh
}
entity = {
    name = BHR_SPRITE_entity # The country BHR will use a unique mesh
    clone = SPRITE_entity
    pdxmesh = BHR_example_mesh
}
entity = {
    name = COSMETICTAG_SPRITE_ENTITY # Countries with the cosmetic tag of COSMETICTAG will use BHR's version entity
    clone = BHR_SPRITE_entity
}

内部类型

  • 步兵
  • 支持
  • 火炮
  • anti_tank
  • anti_air
  • 装甲
  • fighter
  • cas
  • naval_bomber
  • interceptor
  • suicide
  • tactical_bomber
  • strategic_bomber
  • air_transport
  • missile
  • 潜艇
  • screen_ship
  • capital_ship
  • carrier
  • motorized
  • mechanized
  • flame
  • amphibious

组类型

  • 步兵
  • 支持
  • mobile
  • 装甲

地图图标类型

  • 步兵
  • armored
  • other
  • 舰船
  • transport
  • uboat

Stats

单位使用修正来决定它们拥有哪些属性以及可以采取哪些特殊行动。

通常空军单位不使用任何修正,而海军单位只使用supply_consumption与max_organisation。

陆军单位几乎总是使用以下内容:

manpower = <int>
max_strength = <int>
training_time = <int>
weight = <float>
default_morale = <float>
max_organisation = <int>    
combat_width = <int>        
supply_consumption = <float>

对于max_organisation,原版使用以下数值:

  • 步兵支援:20
  • 装甲:10
  • 装甲支援:0
  • 舰船:40
  • 骑兵:70

对于combat_width,原版使用以下数值:

  • 步兵:0
  • 火炮:0
  • 装甲支援:1
  • 装甲:2

修正项

以下列表是单位(以及装备)中所有可用的有效修正:

基础

max_organisation = 20           # Organisation indicates combat readiness and how organized a unit is. 
                                # Units with no organisation can't fight or move effectively.

reliability = 0.9               # Reliability controls how often equipment will suffer random failures.

weight = 0.1                    # Weight controls how many transports a unit needs to embark.

maximum_speed = 0.5             # Maximum speed acts as a "bonus" mulitipler to the speed determined by the unit equipment in km/h. 
                                # The formula for the calculated speed is <base speed> * (1 + maximum_speed)km/h; thus a maximum_speed
                                # of 0.5 gives a movement speed 50% faster, a maximum_speed of 2 equals 200% faster, etc.

supply_consumption = 0.02       # Supply consumption determmines how much supply a unit consumes per day

default_morale = 0.3            # Default morale determines how much extra organisation can be regained 
                                # hourly when not in combat

combat_width = 0.5              # Combat width determines how much this unit contributes to overall combat width.

Costs

lend_lease_cost = 1             # Space taken up in convoy
build_cost_ic = 0.4             # Production Cost - How much factory output this piece of equipment needs
manpower = 300                  # Manpower - Cost in manpower to produce
training_time = 120             # Training time - Time in days to train this unit

Offensive

# Offensive
attack = 0.1                    # Firepower - Amount of damage done per attack
soft_attack = -0.1              # Soft Attack - How many attacks the unit can make versus enemies with low hardness. (In this example here, this would mean that the unit would get 10% less Soft Attack than they 
would usually get from its equipment
hard_attack = -0.5              # Hard Attack - How many attacks the unit can make versus enemies with high hardness
air_attack = 1                  # Air Attack - How much damage we can do against airplanes. High Air Attack also helps to counter enemy Air Superiority effects
ap_attack = 1                   # Piercing - Having equal or greater Piercing to the targets Armor value allows you to do more damage.
breakthrough = 0.5              # Breakthrough - How many enemy attacks a unit can attempt to avoid while on the offensive, effectively allowing it to stay on the offense longer.

Defensive

# Defensive
defense = 0.1                   # Defense - How many enemy attacks a unit can avoid whilst on the defensive, effectively allowing it to stay on the defensive longer.
max_strength = 2                # HP - Strength represents how much damage this unit can suffer before it is destroyed
armor_value = 0                 # Armor - Armor that is higher than the opponents Piercing value reduces damage taken and allows more attacks to occur
hardness = 0.5                  # Hardness - Represents how much of your divsion is made up of armoured vehicles. High Hardness = High Hard Attacks, Low Soft Attack
entrenchment = 5                # Entrenchment - The ability to make proper defensive entrenchments before a hostile attack

Unique

movement = 0.1                  # Movement - Changes the unit's speed
experience_loss_factor = 0.1    # Exp. Loss - How much experience is lost in a division when they take casualities and have to replace them
casualty_trickleback = 0.2      # Trickleback - The proportion of losses in combat that can be saved and returned to the manpower pool
suppression_factor = 0.1        # Suppression bonus - Ability to supress local resistance
reliability_factor = 0.05       # Reliability - Applies to an equipment type's reliability and reduces the chance of breakdowns and accidents
recon = 1                       # Reconnaissance - Increases the chance that this unit can pick better tactics in battle
initiative = 0.2                # Initiative - The higher the initiative, the quicker it can reinforce into battle, and the quick is completes its planning

Boolean

can_be_parachuted = yes         # May be parachuted into battle
can_license = yes                # Can be licesed
is_convertable = yes            # Can be converted
carrier_capable = yes           # Is usable in carriers (air only)

Navy-specific

naval_speed = 28                        # Max Speed - maximum speed in kilometres per hour of the ship, higher means faster in combat too
fire_range = 32                         # Fire Range - The range of the ship's main guns
torpedo_attack = 1                      # Torpedo attack - How much damage we can do when using the ship's torpedos
anti_air_attack = 5                     # Anti-air - How much anti-air firepower the ship carries for shooting down enemy planes
shore_bombardment = 8                   # Shore Bombard - A unit's ability to do shore bombardment to help out in land battles neighbouring its sea province when on Hold mission
evasion = 15                            # Evasion - Ability for ships to evade enemy fire through maneuvering. Evasion is checked against enemy evasion, so high evasion improves hits against high evasion targets
surface_detection = 12                  # Surface detection - Ability to detect surface vessels
sub_detection = 5                       # Sub detection - Ability to detect submarines
surface_visibility = 25                 # Surface Visibility - How hard to find this ship is
sub_visibility = 20                     # Sub Visibility - How easy it is to detect this submarine
naval_range = 3000                      # Naval Range - max distance in kilometres the ship can travel from it's nearest Naval Base
port_capacity_usage = 1                 # Port capacity usage - How much room the ship requires in port
search_and_destroy_coordination = 0.1
convoy_raiding_coordination = 0.1

Air-specific

air_attack = 50                         # Air Attack - amount of damage done against other planes
air_defence = 50                        # Air Defence - how many hits a plane takes before being shot down
air_range = 500                         # Range - How far away missions the plane can perform
air_agility = 10                        # Agility - How agile a plane is. Agility effects how easy it is to hit another plane, and avoid being hit
air_bombing = 300                       # Strategic Bombing - how good the plane is at bombing
air_superiority = 1                     # Air Superiority - How much the plane helps the overall air superiority of a strategic area
naval_strike_attack = 1.5               # Naval Attack - how much damage the plane does against ships
naval_strike_targetting = 0.5           # Naval Targeting - how likely the plane is to hit a ship
carrier_size = 0.05
default_carrier_composition_weight = 1

Localization

每个单位都必须在.yml文件(位于你模组中的本地化文件夹内)中进行本地化。

<unit>: ""
<unit>_desc: ""

Icons

添加新单位时可能会出现你的单位在师设计器里显示随机图标的情况(比如防空图标之类的)。这是因为该单位实际上没有图标。你可以在/Hearts of Iron IV/gfx/interface/counters中提供 sprite。为你的新单位创建一个新的 gfx 文件。为/Hearts of Iron IV/interface/subuniticons.gfx中的每个单位添加以下内容

spriteTypes = {	

   spriteType = { 
     name = "GFX_unit_<your unit name>_icon_medium"				
     textureFile = "gfx/interface/counters/divisions_large/<your unit name>_icon.dds"  ## Thats the paradox shepe, but you can use any path and file naming you want
     noOfFrames = 2
   }

   spriteType = { 
     name = "GFX_unit_<your unit name>_icon_medium_white" # Do not omit "medium"						
     textureFile = "gfx/interface/counters/divisions_small/onmap_unit_<your unit name>_icon.dds" 
     noOfFrames = 2
   }

   spriteType = {
     name = "GFX_unit_<your unit name>_icon_small"
     texturefile = "gfx/texticons/unit_<your unit name>_icon_small.dds"
     legacy_lazy_load = no
     noOfFrames = 2		
   }		

}


模组制作
文档 效果 • 触发器 • 定义文件 • 修正项 • 修正项列表 • 作用域 • 本地化文件 • 事件钩子 • 数据结构(标记、事件目标、国家标签别名、变量、数组)
脚本 成就 • AI • AI 焦点 • 自治领 • 力量均势 • 书签/剧本 (游戏规则) • 建筑 • 角色与特质 • 外观标签 • 国家 • 师 • 决议 • 学说 • 装备 • 事件 • 阵营 • 理念 • 意识形态 • 军事工业组织 • 国策 • 资源 • 脚本化 GUI • 科技与学说 • 单位
地图 地图 • 州 • 补给区域 • 战略区域
图形 界面 • 图形资源 • 实体 • 后期特效 • 粒子 • 字体
外观 肖像 • 名称列表 • 音乐 • 音效
其他 控制台指令 • 疑难排查 • 模组结构 • 模组 • 地图编辑器