Technology modding

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


科技

有两个相关的科技文件夹, /Hearts of Iron IV/common/technologies, 其中包含实际的科技树和/Hearts of Iron IV/common/technology_tags, 其中包含分配给科技的类别。

科技的通用格式如下:

technologies = {
    <technology> = {
        # 这里可以使用任何国家级别的修饰符。
        <modifier>
        
        doctrine = yes          # 把这项技术看作是一项学说科技。
        research_cost = <float> # 时间成本,其中1是默认的研究时间长度。
        start_year = <year>     # 这项科技在哪一年停止超前惩罚。
        
        # 科技完成的效果
        on_research_complete = {
            <effects>
        }
        show_effect_as_desc = yes   #在描述中显示效果。
        
        #改变单位属性和子属性
        <unit> = {
            <attribute> = <value> #必需的!
            
            <terrain> = {
                <attribute> <value>
            }
        }
        
        #更改类别的单位属性
        <category> = {
            <attribute> <value>
        }
        
        #启用子单元
        enable_subunits = {
            <unit>
        }
        
        #启用装备。
        enable_equipments = {
            <equipment name>
        }
        show_equipment_icon = yes   # Show the equipment icon that is unlocked
        
        # 启用建筑
        enable_building = {
            building = <name>
            level = 1
        }
        
        # 链接角落里的科技。用于基础科技的变体科技
        sub_technologies = {
            <technology>
        }
        
        # 采用该科技的科技依赖(而不是以前的科技)
        dependencies = {
            <technology> = 1
        }
        
        # Limits technology visibility if trigger is false. Used for DLC checks. Used for focus-only technologies. Used for modding nation-specific technologies.
        allow = {
            <triggers>
        }
        
        # Limits technology (and linked technologies) visibility if trigger is false. Used for DLC checks. Used for modding nation-specific technologies.
        allow_branch = {
            <triggers>
        }
        
        # Multiple allowed. Controls the links between technologies.
        path = {
            leads_to_tech = <technology>
            research_cost_coeff = <float>
        }
        
        # Used to either-or with other technologies. 
        XOR = {
            <technology>
        }
        
        # Controls which folder (tab) the technology appears under.
        folder = {
            name = <folder name> # Found in countrytechtreeview.gui
            
            # Position in the tech tree interface
            position = { 
                x = 0 
                y = 0 
            }
        }
        
        # Which technology categories apply to this technology.
        categories = {
            <categories>
        }
        
        # Weighting for the AI to pick the technology
        ai_will_do = {
            factor = <float>
            
            # Conditional modifier to the factor.
            modifier = {
                factor = <float>
                
                <triggers>
            }
        }
        
        # Adjusts weighting depending on taken technology (uses technology tags)
        ai_research_weights = {
            <type> = <float>
        }
    }
}

Effects

on_research_complete is used to execute effects upon the completion of a taken technology. This is often used to add divisions of a new subunit or to display custom tooltips.

Here is an example of adding a new division:

on_research_complete = {
    limit = {
        NOT = {    has_template_containing_unit = light_armor }
        NOT = {    has_template_containing_unit = heavy_armor }
        NOT = {    has_template_containing_unit = medium_armor }
    }
    hidden_effect = {
        if = {
            limit = {
                has_tech = motorised_infantry
            }

            load_oob = "unlock_tanks_mot"
        }
        if = {
            limit = {
                NOT = { has_tech = motorised_infantry }
            }

            load_oob = "unlock_tanks"
        }
    }

    custom_effect_tooltip = UNLOCK_DIVISION_TEMPLATE
}

Equipment

To enable new equipment, you need to use enable_equipments. Here is an example:

enable_equipments = {
    infantry_equipment_0
}

Units

To enable new subunits, you need to use enable_subunits. Here is an example:

enable_subunits = {
    infantry
}

To modify unit attributes, you need to either scope to a unit category like so:

category_all_infantry = {
    hard_attack = 0.25
    ap_attack = 1
}

Or scope to the exact unit:

cavalry = {
    soft_attack = 0.05
}

Buildings

To enable new buildings, you need to use enable_building. Here is an example:

enable_building = {
    building = radar_station
    level = 1
}

Sub-technologies

To add sub-technologies to a technology, you need to include sub_technologies in the technology you want them to appear on. Here is an example:

sub_technologies = {
    motorized_rocket_unit
}

Can only be added to equipment technologies.

UI

Technologies appear within technology folders (or tabs). The folder scope is used to place technology within a specified folder. A technology can be present in multiple folder by including multiple folder scopes, like so:

folder = {
    name = infantry_folder
    position = { x = 0 y = 4 }
}

folder = {
    name = support_folder
    position = { x = 7 y = 9 }
}

The position of the technology is defined by the position scope within a folder scope. The x co-ordinate controls the vertical position, and the y co-ordinate controls the horizontal position.

Typically, you will want to increase the x co-ordinate by 2 to place technology a unit lower, likewise with the y co-ordinate.

Technology Icons

The icon used for a technology must be defined in a .gfx file, such as /Hearts of Iron IV/interface/Technologies.gfx.

The format for a icon definition is:

spriteType = {
    name = "GFX_<technology>_medium"
    texturefile = "gfx/interface/technologies/<image>.dds"
}    

For tag-specific icons:

spriteType = {
    name = "GFX_<tag>_<technology>_medium"
    texturefile = "gfx/interface/technologies/<image>.dds"
}    

科技文件夹

科技文件夹通常是科技制作中最令人困惑的地方,它在/Hearts of Iron IV/interface/countrytechtreeview.gui/Hearts of Iron IV/interface/countrytechtreeview.gfx.

Adding the Folder Tab

To add a new folder tab, you need to start by going to the folder_tabs windowtype in countrytechtreeview.gui and adding a new button and icon for your folder.

containerWindowType = {
    name = "folder_tabs"
    position = { x=0 y=7 }
    size = { width = 100%% height = 30 }
            
    # Required for the folder to appear.
    buttonType = {
        name = "<folder>_tab"
        position = { x = 22 y = 0 }                     # Used to place the tab button
        quadTextureSprite = "GFX_<folder>_tab"   # Controls the tab active and inactive images
        frame = 1 
        clicksound = click_default
    }
    
    # ... other folders ...
}

The GFX_<folder>_tab here would be added to a .gfx file:

spriteType = {
    name = "GFX_<folder>_tab"
    textureFile = "gfx//interface//techtree//techtree_infantry_tab.dds"
    noOfFrames = 2        
}

This adds the folder tab button.

Adding the Folder

To add a new folder, you need to start by going to the countrytechtreeview windowtype in countrytechtreeview.gui and adding a new containerWindowType for your folder.

containerWindowType = {
    name = "countrytechtreeview"
    position = { x=-3 y=78 }
    size = { width = 100%% height = 100%% }
    fade_time = 400
    fade_type = linear

    # ... 

    containerWindowType = {
        name = "<folder>"           # Name you added to technology_folders
        position = { x=0 y=47 }
        size = { width = 100%% height = 100%% }
        margin = { top = 13 left = 13 bottom = 24 right = 25}
        drag_scroll = { left middle }
        verticalScrollbar = "right_vertical_slider"
        horizontalScrollbar = "bottom_horizontal_slider"

        background = {
            name = "Background"
            quadTextureSprite ="GFX_tiled_window_2b_border"
        }

        # Controls the graphical elements, such as the dates and the faded image background.
        containerWindowType = {
            name = "techtree_stripes"
            position = { x= 0 y= 0 }
            size = { 
                width = 1400 height = 1275
                min = { width = 100%% height = 100%% }
            }
            clipping = no

            # This is the background you see in the technology folders. 
            # Make sure the actual image is less than 100% alpha, so it fades into the regular background.
            iconType = {
                name ="<folder>_techtree_bg"
                spriteType = "GFX_infantry_techtree_bg"
                position = { x=0 y=0 }
                alwaystransparent = yes
            }
            
            # All the other elements are optional, refer to the actual file for details.
        }

        # These display the technology trees.
        # Each tree must start the the initial technology that starts the tree.
        # i.e. support_weapons_tree will display ALL technologies that are linked to the initial support_weapons technology.
        # You only need to specific the INITIAL (i.e. TOP) technologies for each tree.
        gridboxtype = {
            name = "<technology>_tree"
            position = { x = 140 y = 210 }
            slotsize = { width = 70 height = 70 }
            format = "LEFT"
        }
        
        # Add as many gridboxtype's as you have initial technologies.
    }
}

To further detail the gridboxtype, consider the Infantry Weapons technologies. The technology tree for them is as follows:

  • infantry_weapons
  • infantry_weapons1
  • infantry_weapons2
  • improved_infantry_weapons
  • improved_infantry_weapons_2 and infantry_at
  • advanced_infantry_weapons
  • advanced_infantry_weapons2
  • infantry_at
  • infantry_at2

To display this tree, you just need to add a gridbox with the name infantry_weapons_tree.

Adding the Technology Items

Each folder has it's own definition for each technology icon type. It is these that create the different type of technology "look and feel" between say the Infantry and Air Doctrine technologies.

There are two items:

  • techtree_<folder>_small_item: used for the non-equipment technologies.
  • techtree_<folder>_item: used for the equipment technologies.

Small Item

Used for non-equipment technologies.

containerWindowType = {
    name = "techtree_<folder>_small_item"
    position = { x=0 y=0 }
    size = { width = 72 height = 72 }
    clipping = no

    # This controls the unavailable icon for the non-equipment technology
    background = {
        name = "bg"
        quadTextureSprite ="GFX_technology_unavailable_item_bg"
    }

    # This grabs the GFX_<technology>_medium for the technology dynamically
    iconType = {
        name = "Icon"
        position = { x=3 y=3 }
        spriteType = "GFX_technology_medium"
        alwaystransparent = yes
    }    
        
    iconType = {
        name = "bonus_icon"
        position = { x=3 y=-22 }
        spriteType = "GFX_tech_bonus"
    }
    instantTextBoxType = {
        name = "bonus"
        position = { x = 17 y = -22 }
        textureFile = ""
        font = "hoi_16mbs"
        borderSize = {x = 4 y = 4}
        text = "lol boat"
        maxWidth = 50
        maxHeight = 20
        format = right
    }
}

Item

Used for equipment technologies, and sub-equipment technologies.

containerWindowType = {
    name = "techtree_<folder>_item"
    position = { x=-56 y=-7 }
    size = { width = 183 height = 84 }
    clipping = no

    # This controls the unavailable icon for the equipment technology
    background = {
        name = "Background"
        quadTextureSprite ="GFX_technology_unavailable_item_bg"
    }

    # This grabs the GFX_<technology>_medium for the technology dynamically
    iconType = {
        name = "Icon"
        position = { x=91 y=50 }
        spriteType = "GFX_technology_medium"
        centerposition = yes
        alwaystransparent = yes
    }

    instantTextBoxType = {
        name = "Name"
        position = { x = 3 y = -3 }
        textureFile = ""
        font = "hoi_20bs"
        borderSize = {x = 4 y = 4}
        text = "Happy-Go-Lucky-Tank"
        maxWidth = 160
        maxHeight = 20
        fixedsize = yes
        format = left
    }

    iconType = {
        name = "bonus_icon"
        position = { x=115 y=-22 }
        spriteType = "GFX_tech_bonus"
    }
    
    instantTextBoxType = {
        name = "bonus"
        position = { x = 129 y = -22 }
        textureFile = ""
        font = "hoi_16mbs"
        borderSize = {x = 4 y = 4}
        text = "lol boat"
        maxWidth = 50
        maxHeight = 20
        format = right
    }
        
    # Controls the sub-technology icon.
    containerWindowType = {
        name = "sub_technology_slot_0"
        position = { x=141 y=1 }
        size = { width = 35 height = 26 }
        clipping = no
            
        background = {
            name = "Background"
            spriteType ="GFX_subtechnology_unavailable_item_bg"
        }
            
        iconType = {
            name = "picture"
            position = { x=2 y=2 }
            spriteType = "GFX_subtech_rocket"
            alwaystransparent = yes
        }
    }        
}

Adding background for small items

If you see big (like equipment) icons even on non-equipment technologies you will also need to add item backround records to file countrytechtreeview.gfx. As you can see in next example most base game technologies (industry, infantry, etc.) actually use tech_doctrine background images, which may seem a little confusing.

	spriteType = {
		name = "GFX_technology_<folder>_folder_small_unavailable_item_bg"
		textureFile = "gfx//interface//techtree//tech_doctrine_unavailable_item_bg.dds"
	}	
	
	spriteType = {
		name = "GFX_technology_<folder>_folder_small_available_item_bg"
		textureFile = "gfx//interface//techtree//tech_doctrine_available_item_bg.dds"
	}

	spriteType = {
		name = "GFX_technology_<folder>_folder_small_researched_item_bg"
		textureFile = "gfx//interface//techtree//tech_landdoctrine_researched_item_bg.dds"
	}	

	spriteType = {
		name = "GFX_technology_<folder>_folder_small_branch_item_bg"
		textureFile = "gfx/interface/techtree/tech_doctrine_branch_item_bg.dds"
	}	
	
	frameAnimatedSpriteType = {
		name = "GFX_technology_<folder>_folder_small_currently_researching_item_bg"
		texturefile = "gfx//interface//techtree//tech_doctrine_researching_anim_strip.dds"
		noOfFrames = 9
		loadType = "INGAME"
		transparencecheck = yes
		animation_rate_fps = 15
		looping = yes
		play_on_show = yes
		pause_on_loop = 0.0
	}

Localization

Technologies and technology folders use the following localization keys:

 <technology>: "Name of technology"
 <technology>_desc: "Description of technology."
 <folder>: "Name of folder"
 <folder>_desc: "Description of folder."

Technology Categories

The /Hearts of Iron IV/common/technology_tags/00_technology.txt controls the technology categories (tags) a technology can belong to.

The categories here are used to refer to technologies in a broad sense, for example, in AI focuses, a technology category can be referred to, altering the AI weighting towards technologies that belong to the specified category.

Here is where technology categories are used:

  • ai_focuses: used with the research scope to alter AI weighting.
  • ideas: used with the research_bonus scope to apply research time bonuses.
  • national_focus: used with the add_tech_bonus effect to apply research time bonuses.
  • technologies: applied to technologies.
  • technology_sharing: applied to technology sharing groups.
  • technology_tags: defined here.

Technology Folders

The /Hearts of Iron IV/common/technology_tags/00_technology.txt controls the available technology folders. Be sure to define new folders here if you want them to appear.