AI modding:修订间差异

本页面所适用的版本可能已经过时,最后更新于1.14.7
(文本替换 - 替换“[[Category:”为“[[分类:”)
无编辑摘要
第1行: 第1行:
{{version|1.5}}
{{version|1.14.7}}


钢铁雄心4中的 AI 可以在许多方面修改. 以下文件主要处理 AI:
The artificial intelligence controlling countries in Hearts of Iron IV can be changed in many different aspects. This includes changing the focuses or technologies it pursues, changing how many units or buildings it should produce and of which type, where it should focus forces, which templates or variants it should aim for, and so on.


* {{path|common/ai_areas}}
* {{path|common/ai_areas}}
第14行: 第14行:
 许多其他给玩家提供选择的地方应附有 AI 倾向来表达 AI 对各选项的权衡,这些地方使用'''ai_will_do。'''
 许多其他给玩家提供选择的地方应附有 AI 倾向来表达 AI 对各选项的权衡,这些地方使用'''ai_will_do。'''


== AI 倾向 ==
__TOC__
{{SVersion|1.8}}
 
== MTTH blocks ==
{{anchor|ai_will_do}}
{{anchor|ai_will_do}}
正如在许多文件中看到的那样,'''ai_will_do''' mb是一个为 AI 提供决策时权重的参数。在功能上它与 [[Event_modding#Mean_time_to_happen_2|mean_time_to_happen]] 非常相似。它与其使用相同的修正系统,尽管它对 ''base'' 和 ''factor'' 有不同的解释。
{{anchor|AI_will_do}}
{{anchor|AI_chance}}
{{SVersion|Timeless}}
MTTH blocks, named in the game within {{path|common/mtth/}}, are a way to assign a dynamic value to some block, whether it's a [[National focus modding#Focus tree|country = { ... } in a focus tree to assign which countries can get it]], a dynamically-changing variable value (as in {{path|common/mtth/}}), a [[Event modding#Triggering|mean-time-to-happen value for an event]], et cetera. As MTTH blocks are spread throughout the entire game, it's incredibly important to know how one works. Its most common application, however, is assigning a base AI weight to a database entry such as a national focus or a technology.


注意:AI 对这个参数的运算结果不是完全遵从的,而通常与 [[wp:Sampling_(statistics)#Probability-proportional-to-size_sampling|probability-proportional-to-size sampling]] 类似。
In most cases, marked with ai_will_do, the approach taken by the game is generating a decimal number between 0 and the value of the ai_will_do block, and picking the entry with the highest value. There can be other modifiers applied after the ai_will_do value, such as the ones applied within [[#AI strategy plans|AI strategy plans]] towards focuses and research or {{hover|When modifying defines, never copy over the entire 00_defines.lua file, but use overrides as specified within the corresponding article. Otherwise may lead to crashes, as even 'minor' updates commonly add new defines which'll not be in the mod if the entire file is copied.|the ones that get defined within [[Defines]]}}, which'll multiply the value you get. This can include different ai_will_do values such as what's done with country leader traits and with ideas or characters that use them.<br/>
Event options, instead, use ai_chance, which uses [[wp:Sampling_(statistics)#Probability-proportional-to-size_sampling|probability-proportional-to-size sampling]] with a virtual roll of d00 being the final deciding factor. Due to that, in the end, an event option cannot have a probability which isn't a multiple of 1/100 to be picked, although the total sum of each option's weights can be vastly different from 100. In other words, if one option has a value of 1, while the other has a value of 999, the probability for the first option to be picked will be 1% rather than 0.1%.


==== base ====
A MTTH block begins with an assumed value of 1. Further manipulations are done from that value as a starting point. There are 3 value-modifying arguments that can be done, <code>add</code>, <code>base</code>, and <code>factor</code>, done like <code>factor = 0.3</code>, <code>base = 10</code>, or <code>add = 5</code>. <code>add</code> adds the specified argument to the value, <code>factor</code> ''multiplies'' it, and <code>base</code>, typically done in the start before any changes, sets it to a different number entirely, akin to multiplying by 0 and adding the number.<br/>
''(Type: scoped variable, default: 1)'' 在应用其他修改前的基础数值。
In order for an operation to apply conditionally, a <code>modifier = { ... }</code> block is used. This also functions as a [[conditions|trigger block]], with the default scope (thus also ROOT) being the country for which the MTTH block is evaluated. Depending on the MTTH block, [[Decision modding#Targeted decisions|there may be additional scopes marked with FROM]] [[#AI peace|or FROM.FROM other than the default.]] The value-modifying arguments function as regular arguments, they can be put in anywhere directly within the <code>modifier = { ... }</code> block with almost no difference, whether it's in the end, the beginning, or between triggers.
==== factor ====
''(Type: number (with 3 decimal places), default: 1)'' 应用于计算的系数,


=== 例子 ===
[[Variables]] can be used within the value-modifying arguments as well. If using a temporary variable that is defined within the <code>modifier = { ... }</code> trigger block, then the value-modifying argument of the modifier has to be after the definition of the variable in order for the variable to apply as defined. Variables can also be used outside of the <code>modifier = { ... }</code> block and directly inside of the MTTH block itself.
 
=== Example ===
<pre>
<pre>
ai_will_do = {
ai_will_do = {
    base = 10.5 # may also be a variable
    base = 10.5
  
 
    # If the country is Germany, set the value to 0,
    # If the country is Germany, set the value to 0,
    # causing an early end of the evaluation.
    # causing an early end of the evaluation.
    modifier = { tag = GER factor = 0 }
    modifier = { tag = GER factor = 0 }
    modifier = { is_major = yes add = 1 }
    modifier = { is_major = yes add = 1 }
    modifier = {
    modifier = {
      factor = 3
      factor = 3
第42行: 第45行:
      tag = FRA
      tag = FRA
    }
    }
   factor = 2


    factor = 2
    modifier = {
     set_temp_variable = { t = num_of_civilian_factories }
     add_to_temp_variable = { t = num_of_military_factories }
     divide_temp_variable = { t = 10 }
     round_temp_variable = t
     add = t
   }
}</pre>
}</pre>
假设正常计算,对于GER(德国) 结果为0,对于FRA(法国)结果为74,对于其余主要国家为23,对于次要国家则为21。
Assuming that GER and FRA are major countries, the result is
== AI 区域 ==
* 0 for GER: <math>10.5 \cdot 0 = 0</math>
{{SVersion|1.8}}
* 74 for FRA: <math>((10.5 + 1) \cdot 3 + 2.5) \cdot 2 = 74</math>
{{path|common/ai_areas}} 直接控制了陆地[[province|省份]]在有命名的 AI 区域的分配。但它们只被下文定义的 AI 策略 <code>area_priority</code> 使用。 每个省份只被分配到一个 AI 区域,并且是第一个匹配的区域。没必要将每个省份都分给 AI 区域,但未被分配的不能被 <code>area_priority</code> 策略调用。
* 23 for other majors: <math>(10.5 + 1) \cdot 2 = 23</math>
* 21 for minors: <math>10.5 \cdot 2 = 21</math>
After calculating that value, the total number of civilian and military factories within the country, divided by 10 and rounded, will get added to the score. If FRA has a total of 43 civilian and military factories as it does in base game, then this will result in 4 being added to the prior 74 for a total of 78, for example.


在省份的 debug tooltip 可以看到 AI 区域。
== AI strategies ==
{{SVersion|1.11}}
AI strategies are used in order to pursue AI to do or avoid something. This includes diplomatic actions the AI will do, where and how exactly AI should focus and use its land army and the navy, the production lines for buildings and equipment, how AI should handle the intelligence system within the {{icon|lar|1}} DLC.<br/>
A value within an AI strategy can be either positive or negative, and it being negative will make AI desire to do it less.


这是一个通用示例:
Regular AI strategies are stored in {{path|common/ai_strategy/*.txt}} files, however, AI strategies may be defined outside of that file. The [[Effect#add_ai_strategy|add_ai_strategy effect]] can add a permament AI strategy within any effect block, and [[#AI strategy plans|AI strategy plans]] can also include AI strategies defined within of themselves. Overall, {{path|common/ai_strategy/*.txt}} files describe AI strategies that would enable and disable themselves automatically.<br/>
<pre>
Each entry within a {{path|common/ai_strategy/*.txt}} file is a block with the name of the AI strategy. This name can be anything, even allowing overlap between them: this will only appear in AI dumps and the player will never see it. If an AI strategy modifies the chance for AI to pick a diplomatic option with the player, it will be seen as <code>COUNTRY has strategic reasons to be ...</code> to the player when hovering over the option. This is an example of an AI strategy with the name of BHR_invade_qatar:
<area name> = {
<pre>BHR_invade_qatar = {
    # Used to add continents
   allowed = {
    continents = {
     original_tag = BHR
      <continent>
   }
   enable = {
     country_exists = QAT
    }
    abort = {
      has_war_with = QAT
    }
    }
    
    abort_when_not_enabled = yes
    # Used to add specific strategic regions
    ai_strategy = {
   strategic_regions = {
     type = invade
      <strategic region ids>
     id = QAT
      value = 200
    }
    }
}
}</pre>
</pre>


== AI 国策 ==
=== Arguments ===
参考 [[AI focuses#Modding]]
These in particular are arguments for {{path|common/ai_strategy/*.txt}} entries, rather for AI strategy entries within them.


== AI 和平策略 ==
<code>allowed = { ... }</code> is a trigger block that's '''checked only before the game's start''', permamently allowing or disallowing an AI strategy. Typically, only used for country checks (such as <code>tag = OMA</code>) or DLC checks that can never be unfulfilled once they are met.
{{SVersion|1.5}}
{{path|common/ai_peace}} 中的文件控制了 AI 如何完成和平会议。


There are five types of peace behaviour一共有 5 种 AI 和平策略:
<code>enable = { ... }</code> is a trigger block that must be met in order to enable the AI strategy. By default, this being unmet will ''not'' cancel the AI strategy. However, <code>abort_when_not_enabled = yes</code> can be used as a separate argument in order to make that be no longer the case. Unlike allowed, this is checked continuously.


* 内战
<code>abort = { ... }</code> is a trigger block that must be met in order to ''remove'' the AI strategy. It being unmet also prevents it from being added in the first place.
* 民主主义
* 共产主义
* 法西斯主义
* 默认


和平会议一共有 5 种和平行动:
<code>ai_strategy = { ... }</code> is, itself, the AI strategy that would be applied. The only argument shared for every AI strategy is <code>type = <AI strategy type></code>. [[#Types|The rest depends on the AI strategy]].


* 吞并国家
In addition, reversed AI strategies exist. These are used with AI strategies that use <code>id = TAG</code> to target towards a specific country to swap it around: that strategy will be enabled for TAG towards the country which meets <code>enable = { ... }</code>. In order to mark the AI strategy as reversed, <code>reversed = yes</code> is used. <code>enable_reverse = { ... }</code> is an additional trigger block required to ''enable'' this AI strategy. It does not have a default scope, so scoping into a country is required.<br/>
* 解放国家
An example of a reversed AI strategy is the following:
* 傀儡国家
<pre>BHR_support_neutrals = {
* 获取土地
   allowed = {
* 改变政府(原版民主主义专属)
     NOT = { original_tag = BHR }
 
   }
这是一个通用示例:
<pre>
<type>_peace = {
   # Determines when this peace AI is used by the AI (ROOT is taker, FROM is giver)
    enable = {
    enable = {
      <triggers>
      has_government = neutrality
   }
   enable_reverse = {
     BHR = { has_government = neutrality }
    }
    }
    
    reversed = yes
   # Random factors applied to AI decision making when determining which
    abort_when_not_enabled = yes
   # peace option to use.
    ai_strategy = {
   annex_randomness = <int>
      type = support
   liberate_randomness = <int>
      id = BHR
   puppet_randomness = <int>
      value = 100
    take_states_randomness = <int>
    force_government_randomness = <int>
  
   # Weighting towards the option. (ROOT is taker, FROM is giver)
   <peace option> = {
      factor = <float>
    
     <triggers>
      
      modifier = {
       factor = <float>
      
       <triggers>
     }
    }
    }
}
}</pre>Without <code>reversed = yes</code>, this would make every {{icon|non-aligned|1}} country support BHR. Due to that argument, the strategy is reversed: instead, BHR supports every {{icon|non-aligned|1}} country.
</pre>


== AI 策略 ==
=== Types ===
{{SVersion|1.8}}
{{SVersion|1.11}}
AI 策略影响在特定策略考量 ('''types''') 中,其他 AI 组件中的决策形成,这也可以是定向的。例如一个国家可以在策略上对保护另一国家有兴趣,而不考虑当前外交与同盟关系;或者它更倾向于训练某一特定类型的师。
This list may be outdated. A list of every AI strategy can be found within base game's {{path|common/ai_strategy/documentation.info}} file.<br/>


在结构层面,一个 AI 策略只有 4 个参数:<code>type</code> <code>value</code> <code>id</code> ,以及 <code>target</code> 。只有部分类型的 AI 策略使用了 <code>id</code> / <code>target</code> 。本来,4 个参数都是整型,但如果 <code>type</code> 先被指定,那么<code>id</code> 参数可以用名字来调用对应的值(参考下文表格)。<code>target_country</code> 是另一种设置 <code>target</code> 的方式。它接受一个国家下标或国家 Tag,并会检查其是否指向了一个可用的国家。
{| class="wikitable sortable mw-collapsible mw-collapsed" style="display: inline-block; padding: 5px" width="100%"
|+ style="text-align: center;" width = "100%" |{{nowrap|AI strategies related to diplomatic actions:}}
! width="10%" |Name
! width="25%" |Parameters
! width="25%" |Examples
! width="20%" |Description
! width="20%" |Notes
|-id="alliance"
|alliance
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = alliance
   id = USA
   value = -100
}</pre>
|Pursues AI to ally with a country, joining the same faction if possible.
|
|-id="antagonize"
|antagonize
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = antagonize
   id = USA
   value = -100
}</pre>
|Pursues AI to antagonize a country, refusing most diplomatic actions with them.
|
|-id="asking_foreign_garrison"
|asking_foreign_garrison
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = asking_foreign_garrison
   id = USA
   value = 100
}</pre>
|Pursues AI to ask for foreign manpower to fulfill garrisons, from a specific country if specified.
|If <code>id</code> is not specified, will apply towards every other country.
|-id="befriend"
|befriend
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = befriend
   id = USA
   value = 100
}</pre>
|Pursues AI to befriend a country, accepting most diplomatic actions with them.
|
|-id="conquer"
|conquer
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = conquer
   id = USA
   value = 100
}</pre>
|Pursues AI to conquer a country, being more likely to declare war and justify wargoals.
|This does ''not'' change how the AI will control frontlines when at war with that country.
|-id="consider_weak"
|consider_weak
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = consider_weak
   id = USA
   value = 100
}</pre>
|Pursues AI to consider a country more weak, decreasing hesitation for declaration of war or making alliance less likely.
|
|-id="contain"
|contain
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = contain
   id = USA
   value = 100
}</pre>
|Pursues AI to contain a country, protecting any countries that it would try to antagonize or invade.
|
|-id="declare_war"
|declare_war
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = declare_war
   id = USA
   value = 100
}</pre>
|Pursues AI to declare war on a country if a wargoal already exists.
|
|-id="diplo_action_acceptance"
|diplo_action_acceptance
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.<br/>
<code>target = <diplomatic action></code><br/>The diplomatic action to modify.
|<pre>ai_strategy = {
   type = diplo_action_acceptance
   id = USA
   value = 100
   target = join_allies
}</pre>
|Pursues AI to accept a diplomatic action if a different country requests it.
|AI will not be more likely to propose the diplomatic action in question. Names of diplomatic actions can usually be found from localisation keys used for the title, most of the time yet not always in the {{path|localisation/english/diplomacy_l_english.yml}} file: <code>DIPLOMACY_SEND_VOLUNTEERS_TITLE:0 "Send Volunteers"</code> means that the name of the diplomatic action for sending volunteers is <code>send_volunteers</code>.
|-id="diplo_action_desire"
|diplo_action_desire
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.<br/>
<code>target = <diplomatic action></code><br/>The diplomatic action to modify.
|<pre>ai_strategy = {
   type = diplo_action_desire
   id = USA
   value = 100
   target = call_allies
}</pre>
|Pursues AI to request a diplomatic action towards the specified country.
|AI will not be more likely to accept the diplomatic action in question if it gets proposed to them. Names of diplomatic actions can usually be found from localisation keys used for the title, most of the time yet not always in the {{path|localisation/english/diplomacy_l_english.yml}} file: <code>DIPLOMACY_SEND_VOLUNTEERS_TITLE:0 "Send Volunteers"</code> means that the name of the diplomatic action for sending volunteers is <code>send_volunteers</code>.
|-id="dont_join_wars_with"
|dont_join_wars_with
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.<br/>
<code>target_country = <country></code><br/>The country against whom the war is joined.
|<pre>ai_strategy = {
   type = dont_join_wars_with
   id = USA
   value = 100
   target_country = BHR
}</pre>
|Pursues AI to be less likely to join a war together with a specified country against a specific one.
|Does not make AI less likely to join a war together with a ''different'' country against target_country, even if it'll result in fighting against target_country together with the specified country.
|-id="ignore"
|ignore
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = ignore
   id = USA
   value = 100
}</pre>
|Pursues AI to be less likely to accept or desire any sort of diplomatic action with this country.
|
|-id="ignore_claim"
|ignore_claim
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = ignore_claim
   id = USA
   value = 1
}</pre>
|Pursues AI to ignore any claims that it has on the specified country.
|The value is boolean, just set to be 1.
|-id="protect"
|protect
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = protect
   id = USA
   value = 100
}</pre>
|Pursues AI to protect a certain country, guaranteeing them or adding to the same faction.
|A negative total value (taking every AI strategy into consideration) results in AI never guaranteeing that country.
|-id="support"
|support
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = support
   id = USA
   value = 100
}</pre>
|Pursues AI to support a certain country within wars, sending lend lease, volunteers, or expeditionary forces.
|
|-id="send_lend_lease_desire"
|send_lend_lease_desire
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = send_lend_lease_desire
   id = USA
   value = 100
}</pre>
|Pursues AI to lend-lease equipment to the specified country.
|
|-id="send_volunteers_desire"
|send_volunteers_desire
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = send_volunteers_desire
   id = USA
   value = 100
}</pre>
|Pursues AI to send volunteers to the specified country.
|
|}


AI 会自己生成动态策略,但想添加静态策略也是可行的。静态策略的主要被{{path|common/ai_strategy}} 中的 '''AI 策略条目''' 或 '''AI 策略计划''' 定义(见下文)。领导人特质({{path|common/country_leader}} 中)可以修改 AI 策略,当特质携带者成为国家领导人时。独立的策略也可以用'''add_ai_strategy'''命令直接添加(例如事件·,国策中,等等)。
{| class="wikitable sortable mw-collapsible mw-collapsed" style="display: inline-block; padding: 5px" width="100%"
|+ style="text-align: center;" width = "100%" |{{nowrap|AI strategies related to land army management:}}
! width="10%" |Name
! width="25%" |Parameters
! width="25%" |Examples
! width="20%" |Description
! width="20%" |Notes
|-id="invade"
|invade
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = invade
   id = USA
   value = -100
}</pre>
|Pursues AI to do naval invasions against the specified country.
|
|-id="naval_invasion_focus"
|naval_invasion_focus
|<code>value = <int></code><br/>The weight of the strategy.
|<pre>ai_strategy = {
   type = naval_invasion_focus
   value = 100
}</pre>
|Pursues AI to launch naval invasions.
|-id="prepare_for_war"
|prepare_for_war
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = prepare_for_war
   id = USA
   value = 100
}</pre>
|Pursues AI to prepare for a war against a specified country, moving troops to their border.
|
|-id="area_priority"
|area_priority
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <AI area></code><br/>The [[#AI areas|AI area]] to prioritise.
|<pre>ai_strategy = {
   type = area_priority
   id = europe
   value = 100
}</pre>
|Pursues AI to put more units within the specified AI area.
|
|-id="dont_defend_ally_borders"
|dont_defend_ally_borders
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = dont_defend_ally_borders
   id = POL
   value = 10
}</pre>
|Makes AI never put troops on the border between the specified country and countries that are at war with it.
|Strictly binary. If the total value (taking every AI strategy into consideration) is positive, AI will never put any troops on the border.
|-id="force_defend_ally_borders"
|force_defend_ally_borders
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = force_defend_ally_borders
   id = FRA
   value = 100
}</pre>
|Pursues AI to put troops on the border between the specified country and countries that are at war with it.
|Also accepts [[#AI areas|AI areas]] within <code>id</code>.
|-id="front_armor_score"
|front_armor_score
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = front_armor_score
   id = POL
   value = 100
}</pre>
|Pursues AI to put more tank units for invading the specified country.
|
|-id="front_control"
|front_control
|<code>state = <state></code><br/>The state to target.<br/>
<code>tag = <country></code><br/>The state to target.<br/>
<code>strategic_region = <ID></code><br/>The strategic region to target.<br/>
<code>area = <state></code><br/>The [[#AI areas|AI area]] to target.<br/>
<code>country_trigger = { ... }</code><br/>Trigger block checked for states to have them as a target.<br/>
<code>state_trigger = { ... }</code><br/>Trigger block checked for countries to have them as a target.


一个国家有效的 AI 策略保存在保存文件中,作为该国的<code>ai</code> 属性。
<code>ratio = <decimal></code><br/>How much of a frontline ratio the specified front must have '''as a requirement to enable the strategy'''. Defaults to 0.<br/>
<code>priority = <integer></code><br/>Sets the priority of this front control strategy. If there are contradictory front control strategies, the one with a higher priority is followed.<br/>
<code>ordertype = <front|invasion></code><br/>If set, this will make the AI strategy only apply on land frontlines or naval invasions respectively.<br/>
<code>execution_type = <careful|balanced|rush|rush_weak></code><br/>If set, this pursues AI to make the frontline plans have the set execution type. Only for front.<br/>
<code>execute_order = <bool></code><br/>If set, makes AI to either force execute the frontline order or force it being never executed.<br/>
<code>manual_attack = <bool></code><br/>If set to false, prevents AI from doing small engagements that are not a part of a frontline plan. Defaults to true, only for front.
|<pre>ai_strategy = {
   type = front_control
   state_trigger = {
     industrial_complex > 1
     is_owned_by = ENG
   }
   ratio = 0.1
   ordertype = front
   execution_type = rush
   manual_attack = no
}</pre>
<pre>ai_strategy = {
   type = front_control
   area = suez
   priority = 1
   ratio = 0.2
   ordertype = invasion
   execute_order = yes
}</pre>
|Modifies the orders that AI would give to divisions on a specified frontline.
|More than one target type can be used at a time, in which case each one must be met. This only changes the orders assigned to an already-existing frontline, this will not change the amount of units assigned to any particular front or force any to be created.
|-id="front_unit_request"
|front_unit_request
|<code>state = <state></code><br/>The state to target.<br/>
<code>tag = <country></code><br/>The state to target.<br/>
<code>strategic_region = <ID></code><br/>The strategic region to target.<br/>
<code>area = <state></code><br/>The [[#AI areas|AI area]] to target.<br/>
<code>country_trigger = { ... }</code><br/>Trigger block checked for states to have them as a target.<br/>
<code>state_trigger = { ... }</code><br/>Trigger block checked for countries to have them as a target.


=== 类型 ===
<code>value = <int></code><br/>The weight of the strategy.
定义 '''ai_strategy''' 时, 类型决定了 AI 策略改变的方面。
|<pre>ai_strategy = {
抵抗运动 dlc 中新增的 AI 策略可以在 common/ai_strategy/default.txt 中找到。
   type = front_unit_request
   tag = POL
   value = 100
}</pre>
<pre>ai_strategy = {
   type = front_unit_request
   country_trigger = {
     original_tag = SPR
     has_government = fascism
   }
   value = 100
}</pre>
|Pursues AI to put more units on a specified land frontline.
|More than one target type can be used at a time, in which case each one must be met.
|-id="invasion_unit_request"
|invasion_unit_request
|<code>state = <state></code><br/>The state to target.<br/>
<code>tag = <country></code><br/>The state to target.<br/>
<code>strategic_region = <ID></code><br/>The strategic region to target.<br/>
<code>area = <state></code><br/>The [[#AI areas|AI area]] to target.<br/>
<code>country_trigger = { ... }</code><br/>Trigger block checked for states to have them as a target.<br/>
<code>state_trigger = { ... }</code><br/>Trigger block checked for countries to have them as a target.


{| class="wikitable sortable mw-collapsible"
<code>value = <int></code><br/>The weight of the strategy.
|-
|<pre>ai_strategy = {
! scope = "col" | Type ID
   type = invasion_unit_request
! scope = "col" | Type
   state = 123
! scope = "col" | ID
   value = 100
! scope = "col" class = "unsortable" | Description
}</pre>
|-
<pre>ai_strategy = {
| 45
   type = invasion_unit_request
| added_military_to_civilian_factory_ratio
   strategic_region = 42
   value = 100
}</pre>
|Pursues AI to put more units on a naval invasion with the specified target.
|More than one target type can be used at a time, in which case each one must be met.
|-id="garrison"
|garrison
|<code>value = <int></code><br/>The weight of the strategy.
|<pre>ai_strategy = {
   type = garrison
   value = 10
}</pre>
|Controls the amount of units spent on defending the victory points and ports rather than being active on the frontline.
|
|-id="garrison_reinforcement_priority"
|garrison_reinforcement_priority
|<code>value = <int></code><br/>The weight of the strategy.
|<pre>ai_strategy = {
   type = garrison_reinforcement_priority
   value = 100
}</pre>
|Pursues AI to reinforce units that are put on garrisons, protecting victory points and naval bases, with higher priority.
|
|
| Alters the Military-to-Civilian factory ratio
|-id="ignore_army_incompetence"
|-
|ignore_army_incompetence
| 28
|<code>value = <int></code><br/>The weight of the strategy.
| air_factory_balance
|<pre>ai_strategy = {
   type = ignore_army_incompetence
   value = 100
}</pre>
|Pursues AI to ignore the modifier given by the lack of experience of divisions in calculations.
|
|
| Alters the Air factory ratio.
|-id="put_unit_buffers"
|-
|put_unit_buffers
| 8
|<code>ratio = <decimal></code><br/>The amount of units to buffer.<br/>
| alliance
<code>order_id = 2</code><br/> If two put_unit_buffers strategies use the same ID, the ratio used for them will be shared rather than them being added together.<br/>
| <tag>
<code>states = { ... }</code><br/> List of states where to buffer units<br/>
| Nudges diplomatic AI towards forming an alliance with another specified country.
<code>area = <AI area></code><br/> The AI area where to buffer units.<br/>
|-
<code>subtract_invasions_from_need = yes</code><br/> If true, naval invasions within the area will not count towards the ratio. Defaults to false.<br/>
| 3
<code>subtract_fronts_from_need = yes</code><br/> If true, land frontlines within the area will not count towards the ratio. Defaults to false.
| antagonize
|<pre>ai_strategy = {
| <tag>
   type = put_unit_buffers
| Nudges diplomatic AI towards being meaner to another specified country.
   ratio = 0.2
|-
   states = {
| 33
     123
| area_priority
     124
| [[AI_modding#AI_area|<ai_area>]]
     125
| Encourages the military AI to target specified AI area.
     126
|-
   }
| 4
   subtract_fronts_from_need = yes
| befriend
}</pre>
| <tag>
|Pursues AI to keep a certain ratio of divisions on garrison duty in the specified area.
| Nudges diplomatic AI towards being nicer to another specified country.
|-
| 10 || build_airplane ||  || Unused.
|-
| 11
| build_army
| <unit role>
| Orders the AI to build a type of division or equipment (as in air planes or ships) that belong to the specified unit role.
|-
| 12
| build_building
| <building>
| Orders the AI to build a specific building in a specific location. Uses '''target''' to specify the state location.
|-
| 9 || build_ship ||  || Unused.
|-
| 56
| building_target
| <building>
| Orders the AI to build towards specified amount of <building>. This includes those already owned and acquired by trade (Civilian Factory).
|-
| 1 || colonize ||  || Unused.
|-
| 0
| conquer
| <tag>
| Encourages the military AI to target specified tag.
|-
| 6
| consider_weak
| <tag>
| Nudges the AI disposition towards considering the specified tag weak.
|-
| 17
| contain
| <tag>
| Nudges the diplomatic AI towards taking actions against another country, such as guaranteeing their future potential enemies.
|-
| 41
| declare_war
| <tag>
| Nudges the AI disposition towards declaring war against the specified tag.
|-
| 48
| dockyard_to_military_factory_ratio
|
|
| Alters the Dockyard-to-Military factory ratio.
|-id="spare_unit_factor"
|-
|spare_unit_factor
| 49
|<code>value = <int></code><br/>The weight of the strategy.
| dont_defend_ally_borders
|<pre>ai_strategy = {
| <tag>
   type = spare_unit_factor
| Nudges the AI disposition towards not defending the specified ally's borders.
   value = 100
|-
}</pre>
| 44
|Pursues AI to spare more units towards defending allies.
| dont_join_wars_with
|-id="theatre_distribution_demand_increase"
| <tag>
|theatre_distribution_demand_increase
| Nudges the AI disposition towards not defending the target country when the specified tag is involved. Uses '''target_country''' to define the target country.
|<code>value = <int></code><br/>The weight of the strategy.<br/>
|-
<code>id = <state></code><br/>The target of the strategy.<br/>
| 29
|<pre>ai_strategy = {
| equipment_production_factor
   type = theatre_distribution_demand_increase
| <unit type>
   value = 10
| Alters the equipment production disposition for the specified unit type.
   id = 123
|-
}</pre>
| 31
|Pursues AI to put more units in the specified state's theater.
| equipment_production_min_factories
|A value of 1 translates to 1 unit.
| <unit type>
|}
| Sets the minimum factory count needed to start equipment production for the specified unit type.
{| class="wikitable sortable mw-collapsible mw-collapsed" style="display: inline-block; padding: 5px" width="100%"
|-
|+ style="text-align: center;" width = "100%" |{{nowrap|AI strategies related to navy management:}}
| 26
! width="10%" |Name
| equipment_stockpile_surplus_ratio
! width="25%" |Parameters
! width="25%" |Examples
! width="20%" |Description
! width="20%" |Notes
|-id="naval_avoid_region"
|naval_avoid_region
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <strategic region></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = naval_avoid_region
   id = 23
   value = 100
}</pre>
|Pursues AI to avoid a specific strategic region with its ships.
|
|
| Sets the base equipment stockpile surplus value.
|-id="naval_convoy_raid_region"
|-
|naval_convoy_raid_region
| 30
|<code>value = <int></code><br/>The weight of the strategy.<br/>
| equipment_variant_production_factor
<code>id = <strategic region></code><br/>The target of the strategy.
| <equipment>
|<pre>ai_strategy = {
| Alters the equipment variant production disposition for the specified equipment.
   type = naval_convoy_raid_region
|-
   id = 23
| 2 || explore ||  || Unused.
   value = 100
|-
}</pre>
| 46
|Pursues AI to raid convoys within the specified strategic region.
| factory_build_score_factor
|
|
| Modifies the AI build disposition for a state. Uses '''target''' to specific the target state.
|-id="naval_mission_threshold"
|-
|naval_mission_threshold
| 50
|<code>value = <int></code><br/>The weight of the strategy.<br/>
| force_defend_ally_borders ||  || Unused.
<code>id = <mission></code><br/>The mission to change the threshold of.
|-
|<pre>ai_strategy = {
| 15 || garrison || <integer> (scale of 100) || Used in ai_strategies/SOV.txt, USA.txt, ENG.txt how much of the army should be kept on garrison duty
   type = naval_mission_threshold
|-
   id = MISSION_CONVOY_RAIDING
| 32
   value = -100
| ignore
}</pre>
| <tag>
|Makes AI have a higher threshold for its desire to do a naval mission.
| Nudges the AI disposition towards ignoring the specified tag.
|A higher value means AI is less likely to do the mission. Names of missions can be found in {{path|localisation/english/core_l_english.yml}}, where a localisation key of <code>NAVAL_MISSION_NAME_CONVOY_RAIDING</code> means the mission is called <code>MISSION_CONVOY_RAIDING</code>
|-
|-id="strike_force_home_base"
| 42
|strike_force_home_base
| ignore_army_incompetence
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <strategic region></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = strike_force_home_base
   id = 18
   value = 70
}</pre>
|Pursues AI to do the strike force mission within the specified strategic region.
|
|
| Sets the AI disposition towards ignoring army incompetence.
|}
|-
{| class="wikitable sortable mw-collapsible mw-collapsed" style="display: inline-block; padding: 5px" width="100%"
| 47
|+ style="text-align: center;" width = "100%" |{{nowrap|AI strategies related to intelligence:}}
| ignore_claim
! width="10%" |Name
| <tag>
! width="25%" |Parameters
| Sets AI ignorance of claims against the specified tag. Accepts 1 as a value.
! width="25%" |Examples
|-
! width="20%" |Description
| 7 || influence || || Unused.
! width="20%" |Notes
|-
|-id="agency_ai_base_num_factories_factor"
| 18
|agency_ai_base_num_factories_factor
| invade
|<code>value = <int></code><br/>The weight of the strategy.
| <tag>
|<pre>ai_strategy = {
| Nudges the AI disposition towards invading the specified tag.
   type = agency_ai_base_num_factories_factor
|-
   value = 70
| 21 || land_xp_spend_priority ||  || Unused.
}</pre>
|-
|Changes the baseline used in the calculation of AI doing agency upgrades.
| 37
|A value of 1 equals to a 1% increase over the baseline in [[Defines]].
| naval_avoid_region
|-id="agency_ai_per_upgrade_factories_factor"
| <strategic region>
|agency_ai_per_upgrade_factories_factor
| Alters AI avoidance of the specified strategic region navally.
|<code>value = <int></code><br/>The weight of the strategy.
|-
|<pre>ai_strategy = {
| 35
   type = agency_ai_per_upgrade_factories_factor
| occupation_policy
   value = 70
| <tag>
}</pre>
| Determines the occupation policy towards the specified tag. Accepts values 0 to 3.
|Modifies the needed amount of factories used in the calculation of AI doing agency upgrades.
|-
|A value of 1 equals to a 1% increase over the baseline in [[Defines]].
| 40
|-id="intelligence_agency_branch_desire_factor"
| pp_spend_amount
|intelligence_agency_branch_desire_factor
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <branch></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = intelligence_agency_branch_desire_factor
   id = branch_crypto
   value = 70
}</pre>
|Modifies the needed amount of factories used in the calculation of AI doing agency upgrades.
|Branches are defined in {{path|common/intelligence_agency_upgrades/*.txt}} files.
|-id="intelligence_agency_usable_factories"
|intelligence_agency_usable_factories
|<code>value = <int></code><br/>The weight of the strategy.
|<pre>ai_strategy = {
   type = intelligence_agency_usable_factories
   value = 8
}</pre>
|Modifies the amount of factories that AI would use for intelligence agencies.
|
|
* admiral
|-id="operation_equipment_priority"
* relation
|operation_equipment_priority
* guarantee
|<code>value = <int></code><br/>The weight of the strategy.
* decision
|<pre>ai_strategy = {
* etc.
   type = operation_equipment_priority
| Sets the amount allowed for spending Political Power on the specified action.
   value = 80
|-
}</pre>
| 22
|Pursues the AI to prioritise equipment for funding operations over other usages.
| pp_spend_priority
|
|
* admiral
|-id="operative_mission"
* relation
|operative_mission
* guarantee
|<code>value = <int></code><br/>The weight of the strategy.<br/>
* decision
<code>mission = <mission></code><br/>The mission to prioritise<br/>
* etc.
<code>mission_target = <country></code><br/>The country to target<br/>
| Sets the priority for spending Political Power on the specified action.
<code>state = <state></code><br/>The state to prioritise within the target country if valid. Optional.<br/>
|-
<code>priority = <int></code><br/>If contradictory AI strategies are defined, the one with the highest priority is picked.
| 38
|<pre>ai_strategy = {
| prepare_for_war
   type = operative_mission
| <tag>
   value = 80
|it nudges the AI to plan an attack ahead of time for a possible war with target
   mission = quiet_intel_network
|-
   state = 123
| 5
   state = 321
| protect
   mission_target = ENG
| <tag>
}</pre>
| Nudges the diplomatic AI of a country to try to defend another specified country.
|Pursues the AI to do the specified mission over the target.
|-
|Multiple states can be defined, leading to one of them being prioritised. Mission names can be seen in {{path|localisation/english/operatives_l_english.yml}}. For example, <code>OPERATIVE_MISSION_BOOST_IDEOLOGY_TITLE:0 "Boost Ideology"</code> means that boosting ideology is boost_ideology.
| 13
|-id="operative_operation"
| research_tech
|operative_operation
| <technology>
|<code>value = <int></code></code><br/>The weight of the strategy.<br/>
| Orders the AI to research a specific technology, if possible.
<code>operation = <mission></code><br/>The mission to prioritise<br/>
|-
<code>operation_target = <country></code><br/>The country to target<br/>
| 20
<code>state = <state></code><br/>The state to prioritise within the target country if valid. Optional.<br/>
| role_ratio
<code>region = <strategic region></code><br/>The strategic region to prioritise within the target country if valid. Optional.<br/>
| <unit role>
<code>priority = <int></code><br/>If contradictory AI strategies are defined, the one with the highest priority is picked.
| Out of the entire army, this is the ratio (in %) of that unit role that the army should have. Roles can be defined arbitrarily in ''ai_templates''.
|<pre>ai_strategy = {
|-
   type = operative_operation
| 39
   value = 80
| save_equipment
   operation = heavy_water_raid
| <equipment>
   operation_target = ENG
| Makes the AI save equipment of the specified type to the set value.
}</pre>
|-
|Pursues the AI to do the specified operation over the target.
| 34
|Multiple states can be defined, leading to one of them being prioritised. Operations are defined within {{path|common/operations/*.txt}} files.
| send_volunteers_desire
|}
| <tag>
{| class="wikitable sortable mw-collapsible mw-collapsed" style="display: inline-block; padding: 5px" width="100%"
| Alters AI disposition towards sending volunteers to the specified tag.
|+ style="text-align: center;" width = "100%" |{{nowrap|AI strategies related to production, construction, and recruitment:}}
|-
! width="10%" |Name
| 43
! width="25%" |Parameters
| spare_unit_factor
! width="25%" |Examples
! width="20%" |Description
! width="20%" |Notes
|-id="added_military_to_civilian_factory_ratio"
|added_military_to_civilian_factory_ratio
|<code>value = <int></code><br/>The weight of the strategy.
|<pre>ai_strategy = {
   type = added_military_to_civilian_factory_ratio
   value = 50
}</pre>
|Modifies the ratio of military to civilian factories that the AI desires to keep.
|A positive value means more military factories.
|-id="air_factory_balance"
|air_factory_balance
|<code>value = <int></code><br/>The weight of the strategy.
|<pre>ai_strategy = {
   type = air_factory_balance
   value = 50
}</pre>
|Modifies the ratio of airforce to factories that the AI desires to keep.
|A positive value means more airforce.
|-id="dockyard_to_military_factory_ratio"
|dockyard_to_military_factory_ratio
|<code>value = <int></code><br/>The weight of the strategy.
|<pre>ai_strategy = {
   type = dockyard_to_military_factory_ratio
   value = 50
}</pre>
|Modifies the ratio of dockyards to military factories that the AI desires to keep.
|A positive value means more dockyards.
|-id="railway_gun_divisions_ratio"
|railway_gun_divisions_ratio
|<code>value = <int></code><br/>The weight of the strategy.
|<pre>ai_strategy = {
   type = railway_gun_divisions_ratio
   value = 5
}</pre>
|Modifies the ratio of railway guns to divisions that the AI desires to keep.
|Base ratio is RAILWAY_GUN_PRODUCTION_BASE_DIVISIONS_RATIO_PERCENT in [[Defines]], by default 0. This gets added to it, on the 0-100 scale.
|-id="build_building"
|build_building
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <building></code><br/>The target of the strategy.<br/>
<code>target = <state></code><br/>The state where to build.
|<pre>ai_strategy = {
   type = build_building
   id = industrial_complex
   target = 803
   value = 1
}</pre>
|Pursues AI to construct a specific building within the specified state.
|Value decides how many buildings AI would want to building in the state at once.
|-id="building_target"
|building_target
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <building></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = building_target
   id = industrial_complex
   value = 30
}</pre>
|Makes AI keep a higher desired target of the specified building.
|
|
| Sets the spare unit factor. Used to encourage AI to send more units off to assist in allied fronts and not garrison their home territory.
|-id="factory_build_score_factor"
|-
|factory_build_score_factor
| 36
|<code>value = <int></code><br/>The weight of the strategy.<br/>
| support
<code>target = <state></code><br/>The state where to build.
| <tag>
|<pre>ai_strategy = {
| Alters AI disposition towards supporting the specified tag against partisans.
   type = factory_build_score_factor
|-
   target = 365
| 23
   value = 1
| template_prio
}</pre>
| <unit type>
|Pursues AI to construct buildings within the specified state.
| Sets the template priority of the specified unit type for the AI.
|-
| 24
| template_xp_reserve
|
|
| Sets the XP reserved needed for the AI to consider template changes.
|-id="equipment_production_factor"
|-
|equipment_production_factor
| 61
|<code>value = <int></code><br/>The weight of the strategy.<br/>
| force_build_armies
<code>id = <equipment archetype type></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = equipment_production_factor
   id = armor
   value = 30
}</pre>
|Pursues AI to produce equipment types of the specified type.
|Types are defined for each equipment archetype in {{path|common/units/equipment/*.txt}} files within <code>types = { ... }</code>.
|-id="equipment_production_min_factories"
|equipment_production_min_factories
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <equipment archetype type></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = equipment_production_min_factories
   id = artillery
   value = 3
}</pre>
|Pursues AI to keep more factories on the production lines for the equipment types of the specified type.
|A value of 1 corresponds to 1 military factory. Types are defined for each equipment archetype in {{path|common/units/equipment/*.txt}} files within <code>types = { ... }</code>.
|-id="equipment_variant_production_factor"
|equipment_variant_production_factor
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <equipment archetype></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = equipment_variant_production_factor
   id = light_tank_chassis
   value = -100
}</pre>
|Pursues AI to produce more of the specified equipment archetype.
|Equipment archetypes are defined in {{path|common/units/equipment/*.txt}} files.
|-id="equipment_stockpile_surplus_ratio"
|equipment_stockpile_surplus_ratio
|<code>value = <int></code><br/>The weight of the strategy.
|<pre>ai_strategy = {
   type = equipment_stockpile_surplus_ratio
   value = 30
}</pre>
|Changes the ratio of equipment that AI would hold in stockpile rather than immediately using.
|
|
| Added in 1.6.2, to force AI build armies... Mainly used for China to prepare for war against Japan
|-id="build_army"
|-
|build_army
| 19
|<code>value = <int></code><br/>The weight of the strategy.<br/>
| unit_ratio
<code>id = <equipment archetype></code><br/>The target of the strategy.
| <[[Unit modding|unit type]]>
|<pre>ai_strategy = {
| Out of the entire army, this is the ratio (in %) of that unit type that the army should have
   type = build_army
|-
   id = suppression
| 25
   value = -1000
| equipment_design_priority
}</pre>
|Modifies the desired division amount for AI.
|The used target is roles within [[#AI templates|AI templates]].
|-id="force_build_armies"
|force_build_armies
|<code>value = <int></code><br/>The weight of the strategy.
|<pre>ai_strategy = {
   type = force_build_armies
   value = 30
}</pre>
|Forces AI to build divisions above the desired amount.
|
|
|-id="production_upgrade_desire_offset"
|production_upgrade_desire_offset
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <equipment type></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = production_upgrade_desire_offset
   id = artillery_equipment_2
   value = -50
}</pre>
|Pursues AI to upgrade production lines to the specified equipment type.
|Equipment types are defined in {{path|common/units/equipment/*.txt}} files.
|-id="role_ratio"
|role_ratio
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <role></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = role_ratio
   id = paratroopers
   value = 30
}</pre>
|Modifies the amount of templates that the AI makes for the specified role.
|Roles are defined within [[#AI templates|AI templates]] for unit templates and [[#AI equipment|AI equipment]] for ship and tank variants.
|-id="unit_ratio"
|unit_ratio
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <unit></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = unit_ratio
   id = cas
   value = 30
}</pre>
|Modifies the amount of templates that the AI makes with the specified unit.
|Units are defined in {{path|common/units/*.txt}} files. This includes the airforce and navy alongside land army.
|-id="min_wanted_supply_trains"
|min_wanted_supply_trains
|<code>value = <int></code><br/>The weight of the strategy.
|<pre>ai_strategy = {
   type = min_wanted_supply_trains
   value = 300
}</pre>
|Overrides the minimum amount of supply trains wanted by AI.
|
|
|-
|-id="min_wanted_supply_trucks"
| 58
|min_wanted_supply_trucks
| production_upgrade_desire_offset
|<code>value = <int></code><br/>The weight of the strategy.
| <equipment>
|<pre>ai_strategy = {
   type = min_wanted_supply_trucks
   value = 30
}</pre>
|Overrides the minimum amount of supply trucks wanted by AI.
|
|
|}
{| class="wikitable sortable mw-collapsible mw-collapsed" style="display: inline-block; padding: 5px" width="100%"
|+ style="text-align: center;" width = "100%" |{{nowrap|Other AI strategies:}}
! width="10%" |Name
! width="25%" |Parameters
! width="25%" |Examples
! width="20%" |Description
! width="20%" |Notes
|-id="scorched_earth_prio"
|scorched_earth_prio
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <country></code><br/>The owner of the states where to use scorched earth.<br/>
<code>states = { ... }</code><br/> List of states where to use scorched earth.
|<pre>ai_strategy = {
   type = scorched_earth_prio
   value = 100
   id = ENG
   states = {
     123
     124
     125
     126
   }
}</pre>
|Pursues AI to use scorched earth within the specified states.
|
|
|-
|-id="land_xp_spend_priority"
|land_xp_spend_priority
| put_unit_buffers
|<code>value = <int></code><br/>The weight of the strategy.<br/>
| See ai_strategy/default.txt
<code>id = <type></code><br/>The target of the strategy.
| Used to tell AI to garrison certain states
|<pre>ai_strategy = {
   type = land_xp_spend_priority
   id = division_template
   value = 30
}</pre>
|Modifies the priority for AI to spend land experience.
|Base game usages include <code>division_template</code> and <code>upgrade_xp_cutoff</code>.
|-id="pp_spend_amount"
|pp_spend_amount
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <type></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = pp_spend_amount
   id = idea
   value = 100
}</pre>
|Modifies the political power that AI should preserve for the specified purpose.
|Base game usages include <code>idea</code> and <code>decision</code>.
|-id="pp_spend_priority"
|pp_spend_priority
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <type></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = pp_spend_priority
   id = relation
   value = 100
}</pre>
|Modifies where AI should prioritise spending political power.
|Base game usages include the following:
* <code>admiral</code>
* <code>guarantee</code>
* <code>relation</code>
* <code>decision</code>
|-id="research_weight_factor"
|research_weight_factor
|<code>value = <int></code><br/>The weight of the strategy.<br/>
<code>id = <type></code><br/>The target of the strategy.
|<pre>ai_strategy = {
   type = research_weight_factor
   id = radio_detection
   value = 2000
}</pre>
|Modifies the AI weight (score) of a specific technology.
|value = 50 means 50% increase, -30 means 30% decrease, etc.
|}
|}


=== AI 策略条目 ===
== AI areas ==
一个策略条目包含了一个或多个 AI 策略,并定义了应用的时机和方式。在一个国家检查一个条目的时候,只有在<code>enable</code> 为真以及<code>abort</code> 为空或假时才会激活这个条目。条目将在<code>abort</code> 非空且为真时,或者填写了<code>abort_when_not_enabled</code> <code>enable</code> 为假时被废除。
{{SVersion|1.11}}
AI areas are defined within {{path|common/ai_areas/*.txt}} files. These are ''only'' used in a variety of previously-listed AI strategies, such as [[#area_priority|area_priority]]. A province may be in several AI areas and it may be in none. Hovering over a province with the debug mode turned on will provide information in which AI areas the province is, if any.
 
Each AI area is a separate block within the file, with the name of the block being the name of the area. Within these blocks, 2 things can be added:<br/>
<code>continents = { ... }</code> is a list of continents that make up the AI area. Continents are defined within {{path|map/continent.txt}} and assigned to provinces within [[Map modding#Provinces|their definitions]] in {{path|map/definition.csv}}. The full name of the continent should be used within the AI area's definition, rather than the ID used in the province definition.<br/>
<code>strategic_regions = { ... }</code> is a list of strategic regions that make up the AI area, by their ID number.
 
If there are multiple defined, the province has to be in ''any'' of them.
 
An example of an AI area is the following:
<pre>my_ai_area = {
   continents = {
     europe
     africa
   }
   strategic_regions = {
     53  # Caribbean
     189 # Burma
   }
}</pre>


一个'''逆'''('''reversed)''' 条目工作的方法却不同。如果条目在<code>ai_strategy</code>中作为<code>id</code>引用且<code>enable_reverse</code>为空或真,条目将对源国家激活。然后此条目将对目标国家检查。如果<code>target_array</code>和/或<code>targets</code> 有设置,它们将用作可能的目标;否则,所有国家都作为可能的目标。<code>enable</code> 和<code>abort</code> 触发器将对每个目标检查。如果一个国家通过了检查,那么条目中所有<code>ai_strategy</code>的将对源国家激活,同时从目标中移除他们的<code>id</code>。
== AI focuses ==
{{Main|AI focuses}}
AI focuses, defined within {{path|common/ai_focuses/*.txt}} files, are used to tell the game which technology categories and focuses the AI should pick depending on its currently-pursued focuses.


==== 属性/参数 ====
* allowed: ''(type: AND [[trigger]])'' 在游戏开始时只评估一次,因此条件应该是静态的 (例如 <code>tag = GER</code> 或 <code>is_historical_focus_on = yes</code>). 如果未通过条目,它将不再被检查以提高性能。
* enable: ''(type: AND [[trigger]])'' 激活条目 (除非 abort 非空且为真).
* abort: ''(type: AND [[trigger]])'' 若非空且为真,废除该条目。
* abort_when_not_enabled: ''(type: yes/no, default: no)'' 若为真,则在<code>enable</code>为假时废除该条目。
* ai_strategy: ''(type: AI strategy, may appear multiple times)'' 在条目激活后应用的 AI 策略。
* reversed: ''(type: yes/no, default: no)'' 使用上文所述的逆语义。
* enable_reverse: ''type: AND [[trigger]])'' 源国家通过逆触发器向目标国家传递的另一个触发器
* target_array: ''(type: variable)'' 包含反向目标的数组变量, 例如 <code>neighbors</code>, <code>exiles</code> 或 <code>enemies</code>.
* targets: ''(type: list of variables)'' 独立的反向目标列表, 例如 <code>{ GER ENG FRA }</code>


== AI 策略计划 ==
== AI peace ==
{{SVersion|1.5}}
{{SVersion|1.11}}
{{path|common/ai_strategy_plans}} 中的文件定义了特定 Tag 的全面 AI 行为,用以模拟历史上的战略计划。
{{VisibleCollapse|1=
The peace conference behaviour for AI is defined within {{path|common/peace_conference/ai_peace/*.txt}} files.<br/>
When defining the peace conference AI that would be used by the country, the game picks the first-defined one that meets the prerequisites. In this case, files are loaded sorted by their filename using [[wp:ASCII#Printable characters|ASCII character IDs]].


这是一个通用示例:
When evaluating the peace conference, ROOT (the default scope) is used to represent the currently-evaluated winner and FROM is used to represent the currently-evaluated loser. Additionally, the following [[Variables|temporary variables]] exist within:
<pre>
* taken_states@TAG is an array of states that are annexed by the country TAG as a part of the peace conference.
<strategy_plan> = {
* taken_by@123 is the country that took the specified state, in this case 123.
   name = <name>     # Name of the plan
* current_states@TAG is an array of states that aren't decided upon yet in the peace conference and are under the control of TAG that lost the war.
   desc = <desc>     # Description of the plan
* subject_states@TAG is an array of states that are, within the peace conference, set to be transferred to countries that are subjected by TAG.
  
* subject_countries@TAG is an array of countries that are, within the peace conference, set to be subjected by TAG.
   # When this plan is enabled.
* subjected_by@123 is the overlord of the country that is set to have the specified state in the peace conference, in this case 123.
* subjected_by@TAG is an array of countries that have TAG as their overlord.
* liberate_states@TAG is an array of states that are going to countries that have been liberated by TAG.
* liberate_countries@TAG is an array of countries that have been liberated by TAG.
 
The <code>enable {{=}} { ... }</code> trigger block is used to determine whether the AI should be enabled. If true and no other previously-loaded peace conference AI is true, this AI will be chosen.
 
There are the following peace options that are used in the game:
* annex - The country FROM gets entirely annexed by ROOT. This only evaluates the countries.
* liberate - The country FROM gets liberated by ROOT.
* puppet - The country FROM gets puppeted by ROOT.
* puppet_all - The country FROM gets puppeted by ROOT ''and'' is able to retain all of its states.
* puppet_state - The state ROOT gets transferred to FROM.FROM, which became a subject of FROM within the peace conference.
* take_states - The state FROM gets annexed by ROOT.
* force_government - The country FROM gets its ideology forcefully changed by ROOT.
When evaluating peace conferences, the controller of a given state is the same one that occupied it before the start of the conference while the owner is the original owner.
 
Each peace conference option is a [[#MTTH blocks|MTTH block]] within the file's definition.
Example:{{Collapse|
<pre>my_peace_conference = {
   enable = {
     has_government = my_ideology_group
   }
   annex = {
     base = 500
     modifier = {
       factor = 0
       any_allied_country = {
         any_state = {
           is_owned_by = FROM
           is_core_of = PREV
           NOT = {
             is_core_of = ROOT
             is_claimed_by = ROOT
           }
         }
       }
     }
   }
   puppet = {
     base = 100
     modifier = {
       factor = 0
       FROM = { tag = QAT }
     }
   }
   puppet_all = {
     base = 0
   }
   puppet_state = {
     base = 100
     modifier = {
       factor = 0
       FROM.FROM = { tag = QAT }
     }
     modifier = {
       factor = 0
       any_allied_country = {
         ROOT = {
           is_core_of = PREV
           NOT = {
             is_core_of = FROM.FROM
             is_claimed_by = FROM.FROM
           }
         }
       }
     }
   }
   take_states = {
     base = 100
     modifier = {
       factor = 0
       any_allied_country = {
         FROM = {
           is_core_of = PREV
           NOT = {
             is_core_of = ROOT
             is_claimed_by = ROOT
           }
         }
       }
     }
   }
}</pre>}}|2=Pre-1.12 AI peace}}
 
== AI strategy plans ==
{{SVersion|1.11}}
AI strategy plans to tell AI what to prioritise depending on circumstances: which advisors to pick, which technologies to research, which AI strategies to apply, which focuses to pick, etc. These are more detailed than general AI strategies, primarily intended to be activated for most of the game to tell the overall plan of a country. Multiple AI strategy plans can be defined and executed at the same time for a country.
 
AI strategy plans are defined within {{path|common/ai_strategy_plans/*.txt}} files. Within these files, a new strategy plan is done as a new block, the name of which must be the same as the internal ID of the plan.
 
Within that plan, <code>name = "AI plan's name"</code> and <code>desc = "AI plan's description"</code> decide the name and the description of the strategy plan. ''This is never intended to be shown to the player'', so localising it into different languages is never needed. Instead, this is used within the <code>aiview</code> console command, which tells info to the developer about what AI wants to prioritise.
 
<code>allowed = { ... }</code> is, similarly to decisions or ideas, is a trigger block '''checked only at the game's start'''. This is primarily used to tell which country and DLCs to restrict the strategy plan to.
 
<code>enable = { ... }</code> is checked each day if the allowed is met. If <code>enable = { ... }</code> is met, then the AI strategy plan will be assigned to the AI regardless of whether <code>enable = { ... }</code> turns false later or not. Commonly, [[Triggers#has_game_rule]] is used to make it work with custom game rules deciding what path the AI will pick. [[Triggers#is_historical_focus_on|is_historical_focus_on]] is commonly used with the default AI game rule, and country flags can be used for randomisation, by setting up an [[On actions|on_startup]] to set a random one using [[Scopes#random_list|random_list]]
 
<code>abort = { ... }</code> is checked every day in order to make the AI ''stop'' using this AI strategy plan if <code>enable = { ... }</code> is met. Additionally, it must be false in order for the AI strategy plan to be possible to be picked.
 
<code>ai_national_focuses = { TAG_focus_name_1 TAG_focus_name_2 }</code> is a list of national focuses, separated by whitespaces, in the order that the AI should take them. In this example, the AI will try to take TAG_focus_name_1 first if possible. If it's already taken or TAG_focus_name_1 is impossible to take, then AI will try to take TAG_focus_name_2. If both of the focuses are impossible to take due to being completed or unavailable, then it will move on to other focuses, taking <code>ai_will_do = { ... }</code> into consideration. While following a focus order, it ignores <code>ai_will_do = { ... }</code> values.
 
<code>focus_factors = { ... }</code> assigns a multiplier to ai_will_do values of the specified focus. An entry in this block looks like <code>TAG_focus_name = 3</code>. In this case, this will make the ai_will_do value of the focus be multiplied by 3, assuming AI strategy plan's weight of 1. If the focus has an ai_will_do value of 4 after applying modifiers, it'll become 12 if AI is following this strategy plan, and get treated as such. And, of course, a factor of 0 will make the focus be never picked without specification in ai_national_focuses. This can serve as a faster-to-write or a more randomised way to make AI follow a political path by making focuses it should never pick have a value of 0.
 
<code>research = { ... }</code> assigns a multiplier to ai_will_do values of the specified research categories. An entry in this block looks like <code>artillery = 3</code>. In this case, this will make the ai_will_do value of every technology within the category be multiplied by 3, assuming AI strategy plan's weight of 1. Other built-in modifiers still apply, but this will increase the likelihood.
 
Other blocks that also assign bonuses are <code>ideas = { ... }</code> and <code>traits = { ... }</code>, with the similar formatting. The ideas block is used for individual ideas (such as laws or designers) or advisors (using the idea_token in the entry), while traits are for country leader traits that are assigned to the ideas/advisors.
 
<code>ai_strategy = { ... }</code> allows an [[#AI strategies|AI strategy]] to apply when the strategy plan is turned on.
 
<code>weight = { ... }</code> is a [[#MTTH blocks|MTTH block]] assigning an overall weight to the plan. This multiplies each factor within the AI strategy plan by the weight before applying them. A weight of 1.25 will turn a focus factor of 4 into 5 before applying it, for instance. This can be used to make the AI follow the strategy plan more strictly in some cases and less strictly in others.
 
=== Example ===
{{Collapse|
<pre>BHR_historical = {
   name = "Historical plan for BHR"
   desc = "4 focuses in a specific order"
   allowed = {
     tag = BHR
   }
    enable = {
    enable = {
      <triggers>
      OR = {
       AND = {
         is_historical_focus_on = yes
         has_game_rule = {
           rule = BHR_ai_behavior
           option = DEFAULT
         }
       }
       has_country_flag = BHR_AI_RANDOM_HISTORICAL # Randomly set in on_actions if BHR_ai_behavior is set to RANDOM. Make sure to set that up!
       has_game_rule = {
         rule = BHR_ai_behavior
         option = HISTORICAL
       }
     }
    }
    }
  
   # When this plan is aborted.
    abort = {
    abort = {
      <triggers>
      OMA = {
       OR = {
         has_government = fascism
         has_government = communism
       }
     }
    }
    }
  
   # Defines which national focuses the AI picks first during this plan.
    ai_national_focuses = {
    ai_national_focuses = {
      <focus> # AI picks top downwards
      BHR_focus_name_1
   }
     BHR_focus_name_2
  
     BHR_focus_name_3
   # Defines which technology categories the AI has weighting towards/against during this plan.
      BHR_focus_name_4
   research = {
      <category> = <weight>
    }
    }
  
   # Defines which ideas the AI has weighting towards/against during this plan.
    ideas = {
    ideas = {
      <idea> = <weight>
      BHR_advisor = 3
    }
    }
  
   # Defines which traits the AI has weighting towards/against during this plan.
    traits = {
    traits = {
      <trait> = <weight>
      fascist_demagouge = 0
    }
    }
  
   # Defines AI strategies to apply during this plan.
    ai_strategy = {
    ai_strategy = {
      <strategy attributes>
      type = invade
     id = OMA
     value = 200
   }
}
BHR_alternate = {
   name = "Alternative plan for BHR"
   desc = "AI is just set to never do BHR_focus_name_2 and be more likely to do BHR_focus_name_5, especially if after 1937"
   enable = {
     OR = {
       has_country_flag = BHR_AI_RANDOM_ALTERNATE # Randomly set in on_actions if BHR_ai_behavior is set to RANDOM. Make sure to set that up!
       has_game_rule = {
         rule = BHR_ai_behavior
         option = ALTERNATE
       }
     }
    }
    }
  
   # Defines pick weights for specific focuses during this plan.
    focus_factors = {
    focus_factors = {
      <focus> = <weight>
      BHR_focus_name_2 = 0
     BHR_focus_name_5 = 2
    }
    }
  
   # Keep small, as it is used as a factor for some things (such as research needs)
   # Recommended around 1.0. Useful for relation between plans
    weight = {
    weight = {
     factor = 1.0
      modifier = {
      modifier = {
        factor = 1.0
        factor = 2
       date > 1937.1.1
      }
      }
    }
    }
}
   research = {
</pre>
     artillery = 2
   }
}</pre>}}
 
== AI templates ==
{{SVersion|1.11}}
{{path|common/ai_templates/*.txt}} files are used in order to define the templates that AI would aim for within the division template window.
 
A role template is defined as a block within any file in the folder with the name of the block being the same as the name of the role template.<br/>
These arguments are used for role templates themselves:
* <code>roles = { ... }</code> is a list of roles that the templates would have. These can be anything, getting used for the [[#role_ratio|role_ratio AI strategy]]. AI will try to have one template for each role it has.
* <code>available_for = { ... }</code> restricts the countries that use this role template to the tags in the list. If unspecified, every country uses them.
* <code>blocked_for = { ... }</code> restricts the countries that use this role template from being the tags in the list. This is only needed if there is no <code>available_for = { ... }</code> block.
* <code>match_to_count = 0.3</code> is a decimal on the scale of 0-1 that decides how much a division template should fulfill one of the templates within the role template in order to count as one. By default set to 0.5.
* <code>upgrade_prio = { ... }</code> is a [[#MTTH blocks|MTTH block]] that decides the 'importance' of the role template compared to other role templates for spending experience on improving. If there are several role templates with the same roles, the one with the highest priority gets used, otherwise this decides likelihood compared to role templates with different roles.


== AI 模板 ==
Additionally, within role templates each individual template is defined as a block with the name of the template being the name of the block. It may be anything, as long as there is no overlap.<br/>
{{SVersion|1.5}}
These arguments are used within a template definition:
{{path|common/ai_templates}}中的文件定义了 AI 角色所使用的模板,以指明其使用的模板。
* <code>upgrade_prio = { ... }</code> is a [[#MTTH blocks|MTTH block]] that decides the 'importance' of the template compared to other templates within the role template for spending experience on improving.
* <code>production_prio = { ... }</code> is a [[#MTTH blocks|MTTH block]] that decides the 'importance' of the template compared to other templates within the role template for actually producing.
* <code>replace_with = my_other_template</code> assigns a different template that serves as a more modern version of this one. When it becomes possible to create that template, AI will try to move towards using that one.
* <code>can_upgrade_in_field = { ... }</code> is a trigger block that decides when AI will try to upgrade divisions that are already assigned this template to the one that it's set to be replaced with.
* <code>custom_icon = 10</code> assigns the icon that AI would assign to this template. This example would assign the template icon using the sprites <code>GFX_div_templ_10_large</code> and <code>GFX_div_templ_10_small</code>. Optional, defaults to the majority brigade within the template.
* <code>reinforce_prio = 2</code> assigns the reinforce priority that AI would set on this template. The default priority is 1, appearing in-game as 'regular'. 0 is 'reserve', and 2 is 'elite'. Defaults to 1 if unset.
* <code>target_width = 20</code> assigns the combat width that the AI aims for on this template.
* <code>width_weight = 2.5</code> assigns how ''much'' the AI should focus on aiming towards the target width. The higher the weight, the more AI would avoid deviating from the target width.
* <code>column_swap_factor = 0.3</code> assigns a likelihood for AI to swap entire columns within the template to a different subunit group to meet the template.
* <code>stat_weights = { ... }</code> is a list of decimal values. Each one applies to different stats and decides what exactly AI should try to prioritise and what it should try to avoid. As within NDefines.NAI.DIVISION_DESIGN_WEIGHTS in [[Defines]], these stats are first the 17 army values, then air_attack, then common values and special values. In other words, Air and Navy values get skipped aside from air_attack, which is used by anti-air equipment. The value would be added to the default in defines: a 0.00 would mean it's the same priority as default.
* <code>allowed_types = { ... }</code> is a list of sub-units that the AI can add to the template. If one is omitted, then the AI would never add it. This can be used to make AI not put units of different varieties in the template, such as putting infantry in a mobile light tank division, slowing it down.
* <code>target_template = { ... }</code> assigns the template that AI should aim for. In particular, these arguments go inside of it:
** <code>weight = 0.8</code> is how much the AI should aim towards having that template.
** <code>match_value = 5000</code> is a value that decides how much the template is worth to AI if it's matched.
** <code>support = { ... }</code> is a list of support battalions within the target template. A single definition within looks like <code>artillery = 1</code>. The first decides the unit type, the second decides the amount. Since there is a limit of only one of the same support battalion being allowed, the number can't be anything other than 1.
** <code>regiments = { ... }</code> is a list of non-support, regular battalions within the target template. A single definition within looks like <code>artillery_brigade = 4</code>. The first decides the unit type, the second decides the amount.


角色是 AI 模板系统的核心。它们可以任意创建,允许 Modders 创建自定义角色。
Each template assigned to a role will form a group for the role, and then the fitness score of each available template is used to determine which is used at a specific moment for a specific role.


分配给某个角色的每个模板将组成一个组,然后以每个可用模板的适应度得来确定在特定时刻为角色使用哪个模板。
=== Example ===
{{Collapse|
<pre>armor_BHR = {


这是一个通用示例:
<pre>
<role_template_name> = {
   # Defines the actual role(s) the template covers.
   roles = {
     <roles>
   }
  
   # Restricts the template to only the specified tags. Optional.
    available_for = {
    available_for = {
      <tags>
      BHR
    }
    }
  
 
   # Blocks the template for the specified tags. Optional.
    roles = {
    blocked_for = {
      armor
      <tags>
    }
    }
  
 
   # Determines which existing templates are included in this role
   match_to_count = <float> # By default 0.5
  
   # Determines the importance of the role template, highest importance is the role used by the AI.
    upgrade_prio = {
    upgrade_prio = {
      factor = <float> # Base factor
      factor = 2.17
      
 
     # Modifies the base factor
     modifier = {
       factor = 7
       OR = {
         has_tech = basic_medium_tank
         has_tech = basic_medium_tank_chassis
       }
      }
 
      modifier = {
      modifier = {
        factor = <float>
        factor = 2
        
        OR = {
        <triggers>
         has_tech = main_battle_tank
         has_tech = main_battle_tank_chassis
        }
      }
      }
    }
    }
  
 
    # A template that belongs to this role. Multiple are allowed per role template.
    match_to_count = 0.5
    <template_name> = {
 
     # Determines the importance of the template amoungst other templates listed within the same role.
    medium_armor_BHR = {
 
 
      upgrade_prio = {
      upgrade_prio = {
        factor = <float> # Base factor
        factor = 2
        
     }
        # Modifies the base factor
 
        modifier = {
     target_width = 19.9
          factor = <float>
     width_weight = 3.0
          
     column_swap_factor = 0.1
          <triggers>
 
     stat_weights = {
       0.00 #-- default_morale
       1.10 #-- defense
       1.10 #-- breakthrough
       1.60 #-- hardness
       1.00 #-- soft_attack
       2.00 #-- hard_attack
       0.10 #-- recon
       0.01 #-- entrenchment
       0.10 #-- initiative
       0.01 #-- casualty_trickleback
       -0.05 #-- supply_consumption_factor
        -0.01 #-- supply_consumption
        0.00 #-- suppression
        0.00 #-- suppression_factor
       0.01 #-- experience_loss_factor
       0.00 #-- equipment_capture_factor
       0.00 #-- fuel_capacity
       #-- Air Values
       0.02 #-- air_attack
       #-- Common Values
       50.00 #-- max_organisation
       0.80 #-- max_strength
       1.0 #-- maximum_speed
       10.0 #-- armor_value
       0.05 #-- ap_attack
       0.10 #-- reliability
       0.10 #-- reliability_factor
       0.00 #-- weight
       0.00 #-- fuel_consumption
       0.00 #-- fuel_consumption_factor
       0.00 #-- strat_attack
       0.00 #-- carrier_size
       0.00 #-- acc_hot_gain
       0.00 #-- acc_cold_gain
       0.00 #-- build_cost_ic
     }
 
 
     target_template = {
       weight = 0.9
       match_value = 7000.0
 
       support = {
          engineer = 1
          maintenance_company = 1
          logistics_company = 1
       }
 
       regiments = {
         medium_armor = 6
         motorized = 5
        }
        }
      }
      }
      
 
      # Determines which template the AI will assign to a deployment line for a role. Highest score wins.
      allowed_types = {
      production_prio = {
       modern_armor
        factor = <float> # Base factor
       medium_armor
      
       motorized
       # Modifies the base factor
       mechanized
       infantry
 
       motorized_rocket_brigade
 
       engineer
       mot_recon
       armored_car_recon
       light_tank_recon
       signal_company
       maintenance_company
       logistics_company
 
       anti_tank
       military_police
       artillery
       anti_air
       rocket_artillery
     }
 
      replace_at_match = 0.8
     replace_with = modern_armor_BHR
     target_min_match = 0.5
   }
 
   modern_armor_BHR = {
 
      upgrade_prio = {
        factor = 2
 
        modifier = {
        modifier = {
          factor = <float>
          factor = 1
        
         <triggers>
        }
        }
      }
      }
    
     # Determines the requirement to upgrade in field
     can_upgrade_in_field = {
       <triggers>
     }
    
     custom_icon = <int>
     reinforce_prio = <int>
     target_width = <float>
     width_weight = <float>
     column_swap_factor = <float>


      # Determines the weights for each stat for this template.
      target_width = 19.9
      # Order determines which stat the value affects.
      width_weight = 3.0
     column_swap_factor = 0.1
 
      stat_weights = {
      stat_weights = {
        <float> #-- default_morale
        0.00 #-- default_morale
        <float> #-- defense
        1.10 #-- defense
        <float> #-- breakthrough
        1.10 #-- breakthrough
        <float> #-- hardness
        0.60 #-- hardness
        <float> #-- soft_attack
        2.00 #-- soft_attack
        <float> #-- hard_attack
        0.00 #-- hard_attack
        <float> #-- recon
        0.10 #-- recon
        <float> #-- entrenchment
        0.01 #-- entrenchment
        <float> #-- initiative
        0.10 #-- initiative
        <float> #-- casualty_trickleback
        0.01 #-- casualty_trickleback
        <float> #-- supply_consumption_factor
        -0.05 #-- supply_consumption_factor
        <float> #-- supply_consumption
        -0.01 #-- supply_consumption
        <float> #-- suppression
        0.00 #-- suppression
        <float> #-- suppression_factor
        0.00 #-- suppression_factor
        <float> #-- experience_loss_factor
        0.01 #-- experience_loss_factor
        <float> #-- equipment_capture_factor
        0.00 #-- equipment_capture_factor
        
        0.00 #-- fuel_capacity
        #-- Air Values
        #-- Air Values
        <float> #-- air_attack
        0.02 #-- air_attack
      
        #-- Common Values
        #-- Common Values
        <float> #-- max_organisation
        50.00 #-- max_organisation
        <float> #-- max_strength
        0.80 #-- max_strength
        <float> #-- maximum_speed
        10.0 #-- maximum_speed
        <float> #-- armor_value
        0.20 #-- armor_value
        <float> #-- ap_attack
        0.05 #-- ap_attack
        <float> #-- reliability
        0.10 #-- reliability
        <float> #-- reliability_factor
        0.10 #-- reliability_factor
        <float> #-- weight
        0.00 #-- weight
        <float> #-- build_cost_ic
        0.00 #-- fuel_consumption
       0.00 #-- fuel_consumption_factor
       0.00 #-- strat_attack
       0.00 #-- carrier_size
       0.00 #-- acc_hot_gain
       0.00 #-- acc_cold_gain
       0.00 #-- build_cost_ic
      }
      }
    
 
     #
      target_template = {
      target_template = {
        weight = <float>
        weight = 0.9
        match_value = <float>
        match_value = 9000.0
      
 
        support = {
        support = {
          <support unit> = <amount>
          engineer = 1
         recon = 1
         maintenance_company = 1
         logistics_company = 1
        }
        }
      
 
        regiments = {
        regiments = {
          <unit> = <amount>
          modern_armor = 4
         mechanized = 3
         medium_sp_artillery_brigade = 2
        }
        }
      }
      }
    
 
 
      allowed_types = {
      allowed_types = {
        <units>
        modern_armor
       mechanized
       motorized_rocket_brigade
       medium_sp_artillery_brigade
       engineer
       recon
       signal_company
       maintenance_company
       logistics_company
 
       anti_tank
       military_police
       artillery
       anti_air
       rocket_artillery
     }
   }
}</pre>}}
== AI equipment ==
{{SVersion|1.11}}
{{path|common/ai_equipment/*.txt}} files are used in order to define the equipment variants that the AI should aim for when assigning modules to tank or ship variants.
 
A role template is defined as a block within any file in the folder with the name of the block being the same as the name of the role template.<br/>
These arguments are used for role templates themselves:
* <code>category = <land|naval|air></code> decides whether the template is used for tanks, ships or planes respectively.
* <code>roles = { ... }</code> is a list of roles that the templates would have. These can be anything, getting used for the [[#role_ratio|role_ratio AI strategy]]. AI will try to have one variant for each role it has.
* <code>available_for = { ... }</code> restricts the countries that use this role template to the tags in the list. If unspecified, every country uses them.
* <code>blocked_for = { ... }</code> restricts the countries that use this role template from being the tags in the list. This is only needed if there is no <code>available_for = { ... }</code> block.
* <code>priority = { ... }</code> is a [[#MTTH blocks|MTTH block]] that decides the 'importance' of the role template compared to other role templates for spending experience on improving. If there are several role templates with the same roles, the one with the highest priority gets used, otherwise this decides likelihood compared to role templates with different roles.
 
Additionally, within role templates each individual design is defined as a block with the name of the design being the name of the block. It may be anything, as long as there is no overlap.<br/>
These arguments are used within a design definition:
* <code>name = angry_speedboat</code> required to enable the equipment to be used as preset. If not defined, for example German <code>light_tank_artillery_2</code> will use <code>GER_light_tank_artillery_equipment_2_short</code> localization if defined.
* <code>role_icon_index = 2</code> is used to assign a specific role icon to a ''ship''. This does not work within land equipment. The icons are defined as a part of <code>naval_equipment_role = { ... }</code> within {{path|gfx/army_icons/army_icons.txt}}.
* <code>priority = { ... }</code> is a [[#MTTH blocks|MTTH block]] that decides the 'importance' of the design compared to other templates within the role template for spending experience on improving.
* <code>enable = { ... }</code> is a trigger block that decides when AI should aim towards the design.
* <code>allowed_types = { ... }</code> is a list of sub-units that the AI can add to the design. If one is omitted, then the AI would never add it. This can be used to make AI not put units of different varieties in the design, such as putting infantry in a mobile light tank division, slowing it down.
* <code>target_variant = { ... }</code> assigns the variant that AI should aim for. In particular, these arguments go inside of it:
** <code>match_value = 5000</code> is a value that decides how much the template is worth to AI if it's matched.
** <code>type = light_tank_chassis_0</code> is the specific equipment type that must be used by the design.
** <code>modules = { ... }</code> is a list of modules that the equipment should have, in particular:
*** <code>main_armament_slot = tank_flamethrower</code> decides requirements for a specified module slot, in first place. The requirement may be a module category, a specific module, or the word <code>empty</code>. If specifying a module, the greater-than or lesser-than signs can be used in order to require greater or lesser modules: this is decided by the year defined within the module. If lesser is specified, AI aims towards oldest modules, if greater is specified, AI aims towards newest modules. If specifying empty, greater than can be used to ensure it's ''not'' empty.
*** <code>main_armament_slot = { ... }</code> allows specifying more details for a module slot:
**** <code>module = tank_flamethrower</code> decides a module requirement for the slot. This is the exact same formatting as previous <code>main_armament_slot = tank_flamethrower</code>: module categories, modules, or empty are allowed, and the equality signs can be used in the same way.
**** <code>any_of = { ... }</code> is a list of modules or module categories. The module slot must have at least one of them.
**** <code>upgrade = current</code> ensures that, when upgrading a variant to match this design, it must use the same one as on the existing equipment. If the 'greater than' sign is used (>), then it would require AI to upgrade this slot as well.
** <code>upgrades = { ... }</code> is a list of upgrades that the design should have, in particular:
*** <code>tank_nsb_engine_upgrade = 3</code> decides the AI priority that the specified upgrade should have to a fixed number.
*** <code>tank_nsb_engine_upgrade = { ... }</code> is a [[#MTTH blocks|MTTH block]] that assigns the AI priority to the specified upgrade dynamically.
* <code>requirements = { ... }</code> is a list of modules that the AI ''must'' have. This follows the same formatting as a specified module slot within a target variant's modules block: <code>module = tank_flamethrower</code>, <code>any_of = { ... }</code>, etc. However, this is not tied to a specific slot.
* <code>allowed_modules = { ... }</code> is a list of modules that the AI can use after the requirements in the target variant are met. If a module isn't here, it'll never be picked. The modules specified first take priority over the later ones.
 
=== Example ===
{{Collapse|
<pre>BHR_light_tanks = {
   category = land
 
   available_for = {BHR}
 
   roles = {
     land_light_tank
   }
 
   priority = {
     factor = 1000
   }
 
   great_war_tank_default = {
     priority = {
       factor = 1
       modifier = {
         has_tech = basic_light_tank_chassis
         factor = 0 #let's not waste XP here
       }
     }
 
     target_variant = {
       match_value = 1000
       type = light_tank_chassis_0
       modules = {
         main_armament_slot = tank_heavy_machine_gun
         turret_type_slot = tank_light_one_man_tank_turret
         suspension_type_slot = tank_bogie_suspension
         armor_type_slot = tank_riveted_armor
         engine_type_slot = tank_gasoline_engine
         special_type_slot_1 = empty
         special_type_slot_2 = empty
         special_type_slot_3 = empty
         special_type_slot_4 = empty
       }
       upgrades = {
         tank_nsb_engine_upgrade = 3
         tank_nsb_armor_upgrade = {
           base = 1
           modifier = {
             add = 1
             has_war = yes
           }
         }
       }
     }
 
     allowed_modules = {
       tank_heavy_machine_gun
       tank_light_one_man_tank_turret
       tank_bogie_suspension
       tank_riveted_armor
       tank_gasoline_engine
      }
      }
    
     replace_at_match = <float>
     replace_with = <template>
     target_min_match = <float>
    }
    }
}
}</pre>}}
</pre>


{{Modding navbox}}
{{Modding navbox}}
[[分类:Modding]]
[[分类:Modding]]

2024年8月9日 (五) 15:36的版本


The artificial intelligence controlling countries in Hearts of Iron IV can be changed in many different aspects. This includes changing the focuses or technologies it pursues, changing how many units or buildings it should produce and of which type, where it should focus forces, which templates or variants it should aim for, and so on.

  • /Hearts of Iron IV/common/ai_areas
  • /Hearts of Iron IV/common/ai_focuses
  • /Hearts of Iron IV/common/ai_peace
  • /Hearts of Iron IV/common/ai_strategy
  • /Hearts of Iron IV/common/ai_strategy_plans
  • /Hearts of Iron IV/common/ai_templates
  • /Hearts of Iron IV/common/ai_attitudes.txt
  • /Hearts of Iron IV/common/ai_personalities.txt

许多其他给玩家提供选择的地方应附有 AI 倾向来表达 AI 对各选项的权衡,这些地方使用ai_will_do。

MTTH blocks

MTTH blocks, named in the game within /Hearts of Iron IV/common/mtth/, are a way to assign a dynamic value to some block, whether it's a country = { ... } in a focus tree to assign which countries can get it, a dynamically-changing variable value (as in /Hearts of Iron IV/common/mtth/), a mean-time-to-happen value for an event, et cetera. As MTTH blocks are spread throughout the entire game, it's incredibly important to know how one works. Its most common application, however, is assigning a base AI weight to a database entry such as a national focus or a technology.

In most cases, marked with ai_will_do, the approach taken by the game is generating a decimal number between 0 and the value of the ai_will_do block, and picking the entry with the highest value. There can be other modifiers applied after the ai_will_do value, such as the ones applied within AI strategy plans towards focuses and research or the ones that get defined within Defines, which'll multiply the value you get. This can include different ai_will_do values such as what's done with country leader traits and with ideas or characters that use them.
Event options, instead, use ai_chance, which uses probability-proportional-to-size sampling with a virtual roll of d00 being the final deciding factor. Due to that, in the end, an event option cannot have a probability which isn't a multiple of 1/100 to be picked, although the total sum of each option's weights can be vastly different from 100. In other words, if one option has a value of 1, while the other has a value of 999, the probability for the first option to be picked will be 1% rather than 0.1%.

A MTTH block begins with an assumed value of 1. Further manipulations are done from that value as a starting point. There are 3 value-modifying arguments that can be done, add, base, and factor, done like factor = 0.3, base = 10, or add = 5. add adds the specified argument to the value, factor multiplies it, and base, typically done in the start before any changes, sets it to a different number entirely, akin to multiplying by 0 and adding the number.
In order for an operation to apply conditionally, a modifier = { ... } block is used. This also functions as a trigger block, with the default scope (thus also ROOT) being the country for which the MTTH block is evaluated. Depending on the MTTH block, there may be additional scopes marked with FROM or FROM.FROM other than the default. The value-modifying arguments function as regular arguments, they can be put in anywhere directly within the modifier = { ... } block with almost no difference, whether it's in the end, the beginning, or between triggers.

Variables can be used within the value-modifying arguments as well. If using a temporary variable that is defined within the modifier = { ... } trigger block, then the value-modifying argument of the modifier has to be after the definition of the variable in order for the variable to apply as defined. Variables can also be used outside of the modifier = { ... } block and directly inside of the MTTH block itself.

Example

ai_will_do = {
    base = 10.5

    # If the country is Germany, set the value to 0,
    # causing an early end of the evaluation.
    modifier = { tag = GER factor = 0 }
    modifier = { is_major = yes add = 1 }
    modifier = {
        factor = 3
        add = 2.5
        tag = FRA
    }
    factor = 2

    modifier = {
        set_temp_variable = { t = num_of_civilian_factories }
        add_to_temp_variable = { t = num_of_military_factories }
        divide_temp_variable = { t = 10 }
        round_temp_variable = t
        add = t
    }
}

Assuming that GER and FRA are major countries, the result is

  • 0 for GER: [math]\displaystyle{ 10.5 \cdot 0 = 0 }[/math]
  • 74 for FRA: [math]\displaystyle{ ((10.5 + 1) \cdot 3 + 2.5) \cdot 2 = 74 }[/math]
  • 23 for other majors: [math]\displaystyle{ (10.5 + 1) \cdot 2 = 23 }[/math]
  • 21 for minors: [math]\displaystyle{ 10.5 \cdot 2 = 21 }[/math]

After calculating that value, the total number of civilian and military factories within the country, divided by 10 and rounded, will get added to the score. If FRA has a total of 43 civilian and military factories as it does in base game, then this will result in 4 being added to the prior 74 for a total of 78, for example.

AI strategies

AI strategies are used in order to pursue AI to do or avoid something. This includes diplomatic actions the AI will do, where and how exactly AI should focus and use its land army and the navy, the production lines for buildings and equipment, how AI should handle the intelligence system within the 抵抗运动抵抗运动 DLC.
A value within an AI strategy can be either positive or negative, and it being negative will make AI desire to do it less.

Regular AI strategies are stored in /Hearts of Iron IV/common/ai_strategy/*.txt files, however, AI strategies may be defined outside of that file. The add_ai_strategy effect can add a permament AI strategy within any effect block, and AI strategy plans can also include AI strategies defined within of themselves. Overall, /Hearts of Iron IV/common/ai_strategy/*.txt files describe AI strategies that would enable and disable themselves automatically.
Each entry within a /Hearts of Iron IV/common/ai_strategy/*.txt file is a block with the name of the AI strategy. This name can be anything, even allowing overlap between them: this will only appear in AI dumps and the player will never see it. If an AI strategy modifies the chance for AI to pick a diplomatic option with the player, it will be seen as COUNTRY has strategic reasons to be ... to the player when hovering over the option. This is an example of an AI strategy with the name of BHR_invade_qatar:

BHR_invade_qatar = {
    allowed = {
        original_tag = BHR
    }
    enable = {
        country_exists = QAT
    }
    abort = {
        has_war_with = QAT
    }
    abort_when_not_enabled = yes
    ai_strategy = {
        type = invade
        id = QAT
        value = 200
    }
}

Arguments

These in particular are arguments for /Hearts of Iron IV/common/ai_strategy/*.txt entries, rather for AI strategy entries within them.

allowed = { ... } is a trigger block that's checked only before the game's start, permamently allowing or disallowing an AI strategy. Typically, only used for country checks (such as tag = OMA) or DLC checks that can never be unfulfilled once they are met.

enable = { ... } is a trigger block that must be met in order to enable the AI strategy. By default, this being unmet will not cancel the AI strategy. However, abort_when_not_enabled = yes can be used as a separate argument in order to make that be no longer the case. Unlike allowed, this is checked continuously.

abort = { ... } is a trigger block that must be met in order to remove the AI strategy. It being unmet also prevents it from being added in the first place.

ai_strategy = { ... } is, itself, the AI strategy that would be applied. The only argument shared for every AI strategy is type = <AI strategy type>. The rest depends on the AI strategy.

In addition, reversed AI strategies exist. These are used with AI strategies that use id = TAG to target towards a specific country to swap it around: that strategy will be enabled for TAG towards the country which meets enable = { ... }. In order to mark the AI strategy as reversed, reversed = yes is used. enable_reverse = { ... } is an additional trigger block required to enable this AI strategy. It does not have a default scope, so scoping into a country is required.
An example of a reversed AI strategy is the following:

BHR_support_neutrals = {
    allowed = {
        NOT = { original_tag = BHR }
    }
    enable = {
        has_government = neutrality
    }
    enable_reverse = {
        BHR = { has_government = neutrality }
    }
    reversed = yes
    abort_when_not_enabled = yes
    ai_strategy = {
        type = support
        id = BHR
        value = 100
    }
}

Without reversed = yes, this would make every 中立主义中立主义 country support BHR. Due to that argument, the strategy is reversed: instead, BHR supports every 中立主义中立主义 country.

Types

This list may be outdated. A list of every AI strategy can be found within base game's /Hearts of Iron IV/common/ai_strategy/documentation.info file.

AI strategies related to diplomatic actions:
Name Parameters Examples Description Notes
alliance value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.

ai_strategy = {
    type = alliance
    id = USA
    value = -100
}
Pursues AI to ally with a country, joining the same faction if possible.
antagonize value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.

ai_strategy = {
    type = antagonize
    id = USA
    value = -100
}
Pursues AI to antagonize a country, refusing most diplomatic actions with them.
asking_foreign_garrison value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.

ai_strategy = {
    type = asking_foreign_garrison
    id = USA
    value = 100
}
Pursues AI to ask for foreign manpower to fulfill garrisons, from a specific country if specified. If id is not specified, will apply towards every other country.
befriend value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.

ai_strategy = {
    type = befriend
    id = USA
    value = 100
}
Pursues AI to befriend a country, accepting most diplomatic actions with them.
conquer value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.

ai_strategy = {
    type = conquer
    id = USA
    value = 100
}
Pursues AI to conquer a country, being more likely to declare war and justify wargoals. This does not change how the AI will control frontlines when at war with that country.
consider_weak value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.

ai_strategy = {
    type = consider_weak
    id = USA
    value = 100
}
Pursues AI to consider a country more weak, decreasing hesitation for declaration of war or making alliance less likely.
contain value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.

ai_strategy = {
    type = contain
    id = USA
    value = 100
}
Pursues AI to contain a country, protecting any countries that it would try to antagonize or invade.
declare_war value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.

ai_strategy = {
    type = declare_war
    id = USA
    value = 100
}
Pursues AI to declare war on a country if a wargoal already exists.
diplo_action_acceptance value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.
target = <diplomatic action>
The diplomatic action to modify.

ai_strategy = {
    type = diplo_action_acceptance
    id = USA
    value = 100
    target = join_allies
}
Pursues AI to accept a diplomatic action if a different country requests it. AI will not be more likely to propose the diplomatic action in question. Names of diplomatic actions can usually be found from localisation keys used for the title, most of the time yet not always in the /Hearts of Iron IV/localisation/english/diplomacy_l_english.yml file: DIPLOMACY_SEND_VOLUNTEERS_TITLE:0 "Send Volunteers" means that the name of the diplomatic action for sending volunteers is send_volunteers.
diplo_action_desire value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.
target = <diplomatic action>
The diplomatic action to modify.

ai_strategy = {
    type = diplo_action_desire
    id = USA
    value = 100
    target = call_allies
}
Pursues AI to request a diplomatic action towards the specified country. AI will not be more likely to accept the diplomatic action in question if it gets proposed to them. Names of diplomatic actions can usually be found from localisation keys used for the title, most of the time yet not always in the /Hearts of Iron IV/localisation/english/diplomacy_l_english.yml file: DIPLOMACY_SEND_VOLUNTEERS_TITLE:0 "Send Volunteers" means that the name of the diplomatic action for sending volunteers is send_volunteers.
dont_join_wars_with value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.
target_country = <country>
The country against whom the war is joined.

ai_strategy = {
    type = dont_join_wars_with
    id = USA
    value = 100
    target_country = BHR
}
Pursues AI to be less likely to join a war together with a specified country against a specific one. Does not make AI less likely to join a war together with a different country against target_country, even if it'll result in fighting against target_country together with the specified country.
ignore value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.

ai_strategy = {
    type = ignore
    id = USA
    value = 100
}
Pursues AI to be less likely to accept or desire any sort of diplomatic action with this country.
ignore_claim value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.

ai_strategy = {
    type = ignore_claim
    id = USA
    value = 1
}
Pursues AI to ignore any claims that it has on the specified country. The value is boolean, just set to be 1.
protect value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.

ai_strategy = {
    type = protect
    id = USA
    value = 100
}
Pursues AI to protect a certain country, guaranteeing them or adding to the same faction. A negative total value (taking every AI strategy into consideration) results in AI never guaranteeing that country.
support value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.

ai_strategy = {
    type = support
    id = USA
    value = 100
}
Pursues AI to support a certain country within wars, sending lend lease, volunteers, or expeditionary forces.
send_lend_lease_desire value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.

ai_strategy = {
    type = send_lend_lease_desire
    id = USA
    value = 100
}
Pursues AI to lend-lease equipment to the specified country.
send_volunteers_desire value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.

ai_strategy = {
    type = send_volunteers_desire
    id = USA
    value = 100
}
Pursues AI to send volunteers to the specified country.
AI strategies related to land army management:
Name Parameters Examples Description Notes
invade value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.

ai_strategy = {
    type = invade
    id = USA
    value = -100
}
Pursues AI to do naval invasions against the specified country.
prepare_for_war value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.

ai_strategy = {
    type = prepare_for_war
    id = USA
    value = 100
}
Pursues AI to prepare for a war against a specified country, moving troops to their border.
area_priority value = <int>
The weight of the strategy.

id = <AI area>
The AI area to prioritise.

ai_strategy = {
    type = area_priority
    id = europe
    value = 100
}
Pursues AI to put more units within the specified AI area.
dont_defend_ally_borders value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.

ai_strategy = {
    type = dont_defend_ally_borders
    id = POL
    value = 10
}
Makes AI never put troops on the border between the specified country and countries that are at war with it. Strictly binary. If the total value (taking every AI strategy into consideration) is positive, AI will never put any troops on the border.
force_defend_ally_borders value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.

ai_strategy = {
    type = force_defend_ally_borders
    id = FRA
    value = 100
}
Pursues AI to put troops on the border between the specified country and countries that are at war with it. Also accepts AI areas within id.
front_armor_score value = <int>
The weight of the strategy.

id = <country>
The target of the strategy.

ai_strategy = {
    type = front_armor_score
    id = POL
    value = 100
}
Pursues AI to put more tank units for invading the specified country.
front_control state = <state>
The state to target.

tag = <country>
The state to target.
strategic_region = <ID>
The strategic region to target.
area = <state>
The AI area to target.
country_trigger = { ... }
Trigger block checked for states to have them as a target.
state_trigger = { ... }
Trigger block checked for countries to have them as a target.

ratio = <decimal>
How much of a frontline ratio the specified front must have as a requirement to enable the strategy. Defaults to 0.
priority = <integer>
Sets the priority of this front control strategy. If there are contradictory front control strategies, the one with a higher priority is followed.
ordertype = <front|invasion>
If set, this will make the AI strategy only apply on land frontlines or naval invasions respectively.
execution_type = <careful|balanced|rush|rush_weak>
If set, this pursues AI to make the frontline plans have the set execution type. Only for front.
execute_order = <bool>
If set, makes AI to either force execute the frontline order or force it being never executed.
manual_attack = <bool>
If set to false, prevents AI from doing small engagements that are not a part of a frontline plan. Defaults to true, only for front.

ai_strategy = {
    type = front_control
    state_trigger = {
        industrial_complex > 1
        is_owned_by = ENG
    }
    ratio = 0.1
    ordertype = front
    execution_type = rush
    manual_attack = no
}
ai_strategy = {
    type = front_control
    area = suez
    priority = 1
    ratio = 0.2
    ordertype = invasion
    execute_order = yes
}
Modifies the orders that AI would give to divisions on a specified frontline. More than one target type can be used at a time, in which case each one must be met. This only changes the orders assigned to an already-existing frontline, this will not change the amount of units assigned to any particular front or force any to be created.
front_unit_request state = <state>
The state to target.

tag = <country>
The state to target.
strategic_region = <ID>
The strategic region to target.
area = <state>
The AI area to target.
country_trigger = { ... }
Trigger block checked for states to have them as a target.
state_trigger = { ... }
Trigger block checked for countries to have them as a target.

value = <int>
The weight of the strategy.

ai_strategy = {
    type = front_unit_request
    tag = POL
    value = 100
}
ai_strategy = {
    type = front_unit_request
    country_trigger = {
        original_tag = SPR
        has_government = fascism
    }
    value = 100
}
Pursues AI to put more units on a specified land frontline. More than one target type can be used at a time, in which case each one must be met.
invasion_unit_request state = <state>
The state to target.

tag = <country>
The state to target.
strategic_region = <ID>
The strategic region to target.
area = <state>
The AI area to target.
country_trigger = { ... }
Trigger block checked for states to have them as a target.
state_trigger = { ... }
Trigger block checked for countries to have them as a target.

value = <int>
The weight of the strategy.

ai_strategy = {
    type = invasion_unit_request
    state = 123
    value = 100
}
ai_strategy = {
    type = invasion_unit_request
    strategic_region = 42
    value = 100
}
Pursues AI to put more units on a naval invasion with the specified target. More than one target type can be used at a time, in which case each one must be met.
garrison value = <int>
The weight of the strategy.
ai_strategy = {
    type = garrison
    value = 10
}
Controls the amount of units spent on defending the victory points and ports rather than being active on the frontline.
garrison_reinforcement_priority value = <int>
The weight of the strategy.
ai_strategy = {
    type = garrison_reinforcement_priority
    value = 100
}
Pursues AI to reinforce units that are put on garrisons, protecting victory points and naval bases, with higher priority.
ignore_army_incompetence value = <int>
The weight of the strategy.
ai_strategy = {
    type = ignore_army_incompetence
    value = 100
}
Pursues AI to ignore the modifier given by the lack of experience of divisions in calculations.
put_unit_buffers ratio = <decimal>
The amount of units to buffer.

order_id = 2
If two put_unit_buffers strategies use the same ID, the ratio used for them will be shared rather than them being added together.
states = { ... }
List of states where to buffer units
area = <AI area>
The AI area where to buffer units.
subtract_invasions_from_need = yes
If true, naval invasions within the area will not count towards the ratio. Defaults to false.
subtract_fronts_from_need = yes
If true, land frontlines within the area will not count towards the ratio. Defaults to false.

ai_strategy = {
    type = put_unit_buffers
    ratio = 0.2
    states = {
        123
        124
        125
        126
    }
    subtract_fronts_from_need = yes
}
Pursues AI to keep a certain ratio of divisions on garrison duty in the specified area.
spare_unit_factor value = <int>
The weight of the strategy.
ai_strategy = {
    type = spare_unit_factor
    value = 100
}
Pursues AI to spare more units towards defending allies.
theatre_distribution_demand_increase value = <int>
The weight of the strategy.

id = <state>
The target of the strategy.

ai_strategy = {
    type = theatre_distribution_demand_increase
    value = 10
    id = 123
}
Pursues AI to put more units in the specified state's theater. A value of 1 translates to 1 unit.
AI strategies related to navy management:
Name Parameters Examples Description Notes
strike_force_home_base value = <int>
The weight of the strategy.

id = <strategic region>
The target of the strategy.

ai_strategy = {
    type = strike_force_home_base
    id = 18
    value = 70
}
Pursues AI to do the strike force mission within the specified strategic region.
AI strategies related to intelligence:
Name Parameters Examples Description Notes
agency_ai_base_num_factories_factor value = <int>
The weight of the strategy.
ai_strategy = {
    type = agency_ai_base_num_factories_factor
    value = 70
}
Changes the baseline used in the calculation of AI doing agency upgrades. A value of 1 equals to a 1% increase over the baseline in Defines.
agency_ai_per_upgrade_factories_factor value = <int>
The weight of the strategy.
ai_strategy = {
    type = agency_ai_per_upgrade_factories_factor
    value = 70
}
Modifies the needed amount of factories used in the calculation of AI doing agency upgrades. A value of 1 equals to a 1% increase over the baseline in Defines.
intelligence_agency_branch_desire_factor value = <int>
The weight of the strategy.

id = <branch>
The target of the strategy.

ai_strategy = {
    type = intelligence_agency_branch_desire_factor
    id = branch_crypto
    value = 70
}
Modifies the needed amount of factories used in the calculation of AI doing agency upgrades. Branches are defined in /Hearts of Iron IV/common/intelligence_agency_upgrades/*.txt files.
intelligence_agency_usable_factories value = <int>
The weight of the strategy.
ai_strategy = {
    type = intelligence_agency_usable_factories
    value = 8
}
Modifies the amount of factories that AI would use for intelligence agencies.
operation_equipment_priority value = <int>
The weight of the strategy.
ai_strategy = {
    type = operation_equipment_priority
    value = 80
}
Pursues the AI to prioritise equipment for funding operations over other usages.
operative_mission value = <int>
The weight of the strategy.

mission = <mission>
The mission to prioritise
mission_target = <country>
The country to target
state = <state>
The state to prioritise within the target country if valid. Optional.
priority = <int>
If contradictory AI strategies are defined, the one with the highest priority is picked.

ai_strategy = {
    type = operative_mission
    value = 80
    mission = quiet_intel_network
    state = 123
    state = 321
    mission_target = ENG
}
Pursues the AI to do the specified mission over the target. Multiple states can be defined, leading to one of them being prioritised. Mission names can be seen in /Hearts of Iron IV/localisation/english/operatives_l_english.yml. For example, OPERATIVE_MISSION_BOOST_IDEOLOGY_TITLE:0 "Boost Ideology" means that boosting ideology is boost_ideology.
operative_operation value = <int>
The weight of the strategy.

operation = <mission>
The mission to prioritise
operation_target = <country>
The country to target
state = <state>
The state to prioritise within the target country if valid. Optional.
region = <strategic region>
The strategic region to prioritise within the target country if valid. Optional.
priority = <int>
If contradictory AI strategies are defined, the one with the highest priority is picked.

ai_strategy = {
    type = operative_operation
    value = 80
    operation = heavy_water_raid
    operation_target = ENG
}
Pursues the AI to do the specified operation over the target. Multiple states can be defined, leading to one of them being prioritised. Operations are defined within /Hearts of Iron IV/common/operations/*.txt files.
AI strategies related to production, construction, and recruitment:
Name Parameters Examples Description Notes
added_military_to_civilian_factory_ratio value = <int>
The weight of the strategy.
ai_strategy = {
    type = added_military_to_civilian_factory_ratio
    value = 50
}
Modifies the ratio of military to civilian factories that the AI desires to keep. A positive value means more military factories.
air_factory_balance value = <int>
The weight of the strategy.
ai_strategy = {
    type = air_factory_balance
    value = 50
}
Modifies the ratio of airforce to factories that the AI desires to keep. A positive value means more airforce.
dockyard_to_military_factory_ratio value = <int>
The weight of the strategy.
ai_strategy = {
    type = dockyard_to_military_factory_ratio
    value = 50
}
Modifies the ratio of dockyards to military factories that the AI desires to keep. A positive value means more dockyards.
railway_gun_divisions_ratio value = <int>
The weight of the strategy.
ai_strategy = {
    type = railway_gun_divisions_ratio
    value = 5
}
Modifies the ratio of railway guns to divisions that the AI desires to keep. Base ratio is RAILWAY_GUN_PRODUCTION_BASE_DIVISIONS_RATIO_PERCENT in Defines, by default 0. This gets added to it, on the 0-100 scale.
build_building value = <int>
The weight of the strategy.

id = <building>
The target of the strategy.
target = <state>
The state where to build.

ai_strategy = {
    type = build_building
    id = industrial_complex
    target = 803
    value = 1
}
Pursues AI to construct a specific building within the specified state. Value decides how many buildings AI would want to building in the state at once.
building_target value = <int>
The weight of the strategy.

id = <building>
The target of the strategy.

ai_strategy = {
    type = building_target
    id = industrial_complex
    value = 30
}
Makes AI keep a higher desired target of the specified building.
factory_build_score_factor value = <int>
The weight of the strategy.

target = <state>
The state where to build.

ai_strategy = {
    type = factory_build_score_factor
    target = 365
    value = 1
}
Pursues AI to construct buildings within the specified state.
equipment_production_factor value = <int>
The weight of the strategy.

id = <equipment archetype type>
The target of the strategy.

ai_strategy = {
    type = equipment_production_factor
    id = armor
    value = 30
}
Pursues AI to produce equipment types of the specified type. Types are defined for each equipment archetype in /Hearts of Iron IV/common/units/equipment/*.txt files within types = { ... }.
equipment_production_min_factories value = <int>
The weight of the strategy.

id = <equipment archetype type>
The target of the strategy.

ai_strategy = {
    type = equipment_production_min_factories
    id = artillery
    value = 3
}
Pursues AI to keep more factories on the production lines for the equipment types of the specified type. A value of 1 corresponds to 1 military factory. Types are defined for each equipment archetype in /Hearts of Iron IV/common/units/equipment/*.txt files within types = { ... }.
equipment_variant_production_factor value = <int>
The weight of the strategy.

id = <equipment archetype>
The target of the strategy.

ai_strategy = {
    type = equipment_variant_production_factor
    id = light_tank_chassis
    value = -100
}
Pursues AI to produce more of the specified equipment archetype. Equipment archetypes are defined in /Hearts of Iron IV/common/units/equipment/*.txt files.
equipment_stockpile_surplus_ratio value = <int>
The weight of the strategy.
ai_strategy = {
    type = equipment_stockpile_surplus_ratio
    value = 30
}
Changes the ratio of equipment that AI would hold in stockpile rather than immediately using.
build_army value = <int>
The weight of the strategy.

id = <equipment archetype>
The target of the strategy.

ai_strategy = {
    type = build_army
    id = suppression
    value = -1000
}
Modifies the desired division amount for AI. The used target is roles within AI templates.
force_build_armies value = <int>
The weight of the strategy.
ai_strategy = {
    type = force_build_armies
    value = 30
}
Forces AI to build divisions above the desired amount.
production_upgrade_desire_offset value = <int>
The weight of the strategy.

id = <equipment type>
The target of the strategy.

ai_strategy = {
    type = production_upgrade_desire_offset
    id = artillery_equipment_2
    value = -50
}
Pursues AI to upgrade production lines to the specified equipment type. Equipment types are defined in /Hearts of Iron IV/common/units/equipment/*.txt files.
role_ratio value = <int>
The weight of the strategy.

id = <role>
The target of the strategy.

ai_strategy = {
    type = role_ratio
    id = paratroopers
    value = 30
}
Modifies the amount of templates that the AI makes for the specified role. Roles are defined within AI templates for unit templates and AI equipment for ship and tank variants.
unit_ratio value = <int>
The weight of the strategy.

id = <unit>
The target of the strategy.

ai_strategy = {
    type = unit_ratio
    id = cas
    value = 30
}
Modifies the amount of templates that the AI makes with the specified unit. Units are defined in /Hearts of Iron IV/common/units/*.txt files. This includes the airforce and navy alongside land army.
min_wanted_supply_trains value = <int>
The weight of the strategy.
ai_strategy = {
    type = min_wanted_supply_trains
    value = 300
}
Overrides the minimum amount of supply trains wanted by AI.
min_wanted_supply_trucks value = <int>
The weight of the strategy.
ai_strategy = {
    type = min_wanted_supply_trucks
    value = 30
}
Overrides the minimum amount of supply trucks wanted by AI.
Other AI strategies:
Name Parameters Examples Description Notes
scorched_earth_prio value = <int>
The weight of the strategy.

id = <country>
The owner of the states where to use scorched earth.
states = { ... }
List of states where to use scorched earth.

ai_strategy = {
    type = scorched_earth_prio
    value = 100
    id = ENG
    states = {
        123
        124
        125
        126
    }
}
Pursues AI to use scorched earth within the specified states.
land_xp_spend_priority value = <int>
The weight of the strategy.

id = <type>
The target of the strategy.

ai_strategy = {
    type = land_xp_spend_priority
    id = division_template
    value = 30
}
Modifies the priority for AI to spend land experience. Base game usages include division_template and upgrade_xp_cutoff.
pp_spend_amount value = <int>
The weight of the strategy.

id = <type>
The target of the strategy.

ai_strategy = {
    type = pp_spend_amount
    id = idea
    value = 100
}
Modifies the political power that AI should preserve for the specified purpose. Base game usages include idea and decision.
pp_spend_priority value = <int>
The weight of the strategy.

id = <type>
The target of the strategy.

ai_strategy = {
    type = pp_spend_priority
    id = relation
    value = 100
}
Modifies where AI should prioritise spending political power. Base game usages include the following:
  • admiral
  • guarantee
  • relation
  • decision
research_weight_factor value = <int>
The weight of the strategy.

id = <type>
The target of the strategy.

ai_strategy = {
    type = research_weight_factor
    id = radio_detection
    value = 2000
}
Modifies the AI weight (score) of a specific technology. value = 50 means 50% increase, -30 means 30% decrease, etc.

AI areas

AI areas are defined within /Hearts of Iron IV/common/ai_areas/*.txt files. These are only used in a variety of previously-listed AI strategies, such as area_priority. A province may be in several AI areas and it may be in none. Hovering over a province with the debug mode turned on will provide information in which AI areas the province is, if any.

Each AI area is a separate block within the file, with the name of the block being the name of the area. Within these blocks, 2 things can be added:
continents = { ... } is a list of continents that make up the AI area. Continents are defined within /Hearts of Iron IV/map/continent.txt and assigned to provinces within their definitions in /Hearts of Iron IV/map/definition.csv. The full name of the continent should be used within the AI area's definition, rather than the ID used in the province definition.
strategic_regions = { ... } is a list of strategic regions that make up the AI area, by their ID number.

If there are multiple defined, the province has to be in any of them.

An example of an AI area is the following:

my_ai_area = {
    continents = {
        europe
        africa
    }
    strategic_regions = {
        53  # Caribbean
        189 # Burma
    }
}

AI focuses

主条目:AI focuses

AI focuses, defined within /Hearts of Iron IV/common/ai_focuses/*.txt files, are used to tell the game which technology categories and focuses the AI should pick depending on its currently-pursued focuses.


AI peace

Pre-1.12 AI peace
The peace conference behaviour for AI is defined within /Hearts of Iron IV/common/peace_conference/ai_peace/*.txt files.

When defining the peace conference AI that would be used by the country, the game picks the first-defined one that meets the prerequisites. In this case, files are loaded sorted by their filename using ASCII character IDs.

When evaluating the peace conference, ROOT (the default scope) is used to represent the currently-evaluated winner and FROM is used to represent the currently-evaluated loser. Additionally, the following temporary variables exist within:

  • taken_states@TAG is an array of states that are annexed by the country TAG as a part of the peace conference.
  • taken_by@123 is the country that took the specified state, in this case 123.
  • current_states@TAG is an array of states that aren't decided upon yet in the peace conference and are under the control of TAG that lost the war.
  • subject_states@TAG is an array of states that are, within the peace conference, set to be transferred to countries that are subjected by TAG.
  • subject_countries@TAG is an array of countries that are, within the peace conference, set to be subjected by TAG.
  • subjected_by@123 is the overlord of the country that is set to have the specified state in the peace conference, in this case 123.
  • subjected_by@TAG is an array of countries that have TAG as their overlord.
  • liberate_states@TAG is an array of states that are going to countries that have been liberated by TAG.
  • liberate_countries@TAG is an array of countries that have been liberated by TAG.

The enable = { ... } trigger block is used to determine whether the AI should be enabled. If true and no other previously-loaded peace conference AI is true, this AI will be chosen.

There are the following peace options that are used in the game:

  • annex - The country FROM gets entirely annexed by ROOT. This only evaluates the countries.
  • liberate - The country FROM gets liberated by ROOT.
  • puppet - The country FROM gets puppeted by ROOT.
  • puppet_all - The country FROM gets puppeted by ROOT and is able to retain all of its states.
  • puppet_state - The state ROOT gets transferred to FROM.FROM, which became a subject of FROM within the peace conference.
  • take_states - The state FROM gets annexed by ROOT.
  • force_government - The country FROM gets its ideology forcefully changed by ROOT.

When evaluating peace conferences, the controller of a given state is the same one that occupied it before the start of the conference while the owner is the original owner.

Each peace conference option is a MTTH block within the file's definition.

Example:
my_peace_conference = {
    enable = {
        has_government = my_ideology_group
    }
    annex = {
        base = 500
        modifier = {
            factor = 0
            any_allied_country = {
                any_state = {
                    is_owned_by = FROM
                    is_core_of = PREV
                    NOT = {
                        is_core_of = ROOT
                        is_claimed_by = ROOT
                    }
                }
            }
        }
    }
    puppet = {
        base = 100
        modifier = {
            factor = 0
            FROM = { tag = QAT }
        }
    }
    puppet_all = {
        base = 0
    }
    puppet_state = {
        base = 100
        modifier = {
            factor = 0
            FROM.FROM = { tag = QAT }
        }
        modifier = {
            factor = 0
            any_allied_country = {
                ROOT = {
                    is_core_of = PREV
                    NOT = {
                        is_core_of = FROM.FROM
                        is_claimed_by = FROM.FROM
                    }
                }
            }
        }
    }
    take_states = {
        base = 100
        modifier = {
            factor = 0
            any_allied_country = {
                FROM = {
                    is_core_of = PREV
                    NOT = {
                        is_core_of = ROOT
                        is_claimed_by = ROOT
                    }
                }
            }
        }
    }
}


AI strategy plans

AI strategy plans to tell AI what to prioritise depending on circumstances: which advisors to pick, which technologies to research, which AI strategies to apply, which focuses to pick, etc. These are more detailed than general AI strategies, primarily intended to be activated for most of the game to tell the overall plan of a country. Multiple AI strategy plans can be defined and executed at the same time for a country.

AI strategy plans are defined within /Hearts of Iron IV/common/ai_strategy_plans/*.txt files. Within these files, a new strategy plan is done as a new block, the name of which must be the same as the internal ID of the plan.

Within that plan, name = "AI plan's name" and desc = "AI plan's description" decide the name and the description of the strategy plan. This is never intended to be shown to the player, so localising it into different languages is never needed. Instead, this is used within the aiview console command, which tells info to the developer about what AI wants to prioritise.

allowed = { ... } is, similarly to decisions or ideas, is a trigger block checked only at the game's start. This is primarily used to tell which country and DLCs to restrict the strategy plan to.

enable = { ... } is checked each day if the allowed is met. If enable = { ... } is met, then the AI strategy plan will be assigned to the AI regardless of whether enable = { ... } turns false later or not. Commonly, Triggers#has_game_rule is used to make it work with custom game rules deciding what path the AI will pick. is_historical_focus_on is commonly used with the default AI game rule, and country flags can be used for randomisation, by setting up an on_startup to set a random one using random_list

abort = { ... } is checked every day in order to make the AI stop using this AI strategy plan if enable = { ... } is met. Additionally, it must be false in order for the AI strategy plan to be possible to be picked.

ai_national_focuses = { TAG_focus_name_1 TAG_focus_name_2 } is a list of national focuses, separated by whitespaces, in the order that the AI should take them. In this example, the AI will try to take TAG_focus_name_1 first if possible. If it's already taken or TAG_focus_name_1 is impossible to take, then AI will try to take TAG_focus_name_2. If both of the focuses are impossible to take due to being completed or unavailable, then it will move on to other focuses, taking ai_will_do = { ... } into consideration. While following a focus order, it ignores ai_will_do = { ... } values.

focus_factors = { ... } assigns a multiplier to ai_will_do values of the specified focus. An entry in this block looks like TAG_focus_name = 3. In this case, this will make the ai_will_do value of the focus be multiplied by 3, assuming AI strategy plan's weight of 1. If the focus has an ai_will_do value of 4 after applying modifiers, it'll become 12 if AI is following this strategy plan, and get treated as such. And, of course, a factor of 0 will make the focus be never picked without specification in ai_national_focuses. This can serve as a faster-to-write or a more randomised way to make AI follow a political path by making focuses it should never pick have a value of 0.

research = { ... } assigns a multiplier to ai_will_do values of the specified research categories. An entry in this block looks like artillery = 3. In this case, this will make the ai_will_do value of every technology within the category be multiplied by 3, assuming AI strategy plan's weight of 1. Other built-in modifiers still apply, but this will increase the likelihood.

Other blocks that also assign bonuses are ideas = { ... } and traits = { ... }, with the similar formatting. The ideas block is used for individual ideas (such as laws or designers) or advisors (using the idea_token in the entry), while traits are for country leader traits that are assigned to the ideas/advisors.

ai_strategy = { ... } allows an AI strategy to apply when the strategy plan is turned on.

weight = { ... } is a MTTH block assigning an overall weight to the plan. This multiplies each factor within the AI strategy plan by the weight before applying them. A weight of 1.25 will turn a focus factor of 4 into 5 before applying it, for instance. This can be used to make the AI follow the strategy plan more strictly in some cases and less strictly in others.

Example

BHR_historical = {
    name = "Historical plan for BHR"
    desc = "4 focuses in a specific order"
    allowed = {
        tag = BHR
    }
    enable = {
        OR = {
            AND = {
                is_historical_focus_on = yes
                has_game_rule = {
                    rule = BHR_ai_behavior
                    option = DEFAULT
                }
            }
            has_country_flag = BHR_AI_RANDOM_HISTORICAL # Randomly set in on_actions if BHR_ai_behavior is set to RANDOM. Make sure to set that up!
            has_game_rule = {
                rule = BHR_ai_behavior
                option = HISTORICAL
            }
        }
    }
    abort = {
        OMA = {
            OR = {
                has_government = fascism
                has_government = communism
            }
        }
    }
    ai_national_focuses = {
        BHR_focus_name_1
        BHR_focus_name_2
        BHR_focus_name_3
        BHR_focus_name_4
    }
    ideas = {
        BHR_advisor = 3
    }
    traits = {
        fascist_demagouge = 0
    }
    ai_strategy = {
        type = invade
        id = OMA
        value = 200
    }
}
BHR_alternate = {
    name = "Alternative plan for BHR"
    desc = "AI is just set to never do BHR_focus_name_2 and be more likely to do BHR_focus_name_5, especially if after 1937"
    enable = {
        OR = {
            has_country_flag = BHR_AI_RANDOM_ALTERNATE # Randomly set in on_actions if BHR_ai_behavior is set to RANDOM. Make sure to set that up!
            has_game_rule = {
                rule = BHR_ai_behavior
                option = ALTERNATE
            }
        }
    }
    focus_factors = {
        BHR_focus_name_2 = 0
        BHR_focus_name_5 = 2
    }
    weight = {
        modifier = {
            factor = 2
            date > 1937.1.1
        }
    }
    research = {
        artillery = 2
    }
}

AI templates

/Hearts of Iron IV/common/ai_templates/*.txt files are used in order to define the templates that AI would aim for within the division template window.

A role template is defined as a block within any file in the folder with the name of the block being the same as the name of the role template.
These arguments are used for role templates themselves:

  • roles = { ... } is a list of roles that the templates would have. These can be anything, getting used for the role_ratio AI strategy. AI will try to have one template for each role it has.
  • available_for = { ... } restricts the countries that use this role template to the tags in the list. If unspecified, every country uses them.
  • blocked_for = { ... } restricts the countries that use this role template from being the tags in the list. This is only needed if there is no available_for = { ... } block.
  • match_to_count = 0.3 is a decimal on the scale of 0-1 that decides how much a division template should fulfill one of the templates within the role template in order to count as one. By default set to 0.5.
  • upgrade_prio = { ... } is a MTTH block that decides the 'importance' of the role template compared to other role templates for spending experience on improving. If there are several role templates with the same roles, the one with the highest priority gets used, otherwise this decides likelihood compared to role templates with different roles.

Additionally, within role templates each individual template is defined as a block with the name of the template being the name of the block. It may be anything, as long as there is no overlap.
These arguments are used within a template definition:

  • upgrade_prio = { ... } is a MTTH block that decides the 'importance' of the template compared to other templates within the role template for spending experience on improving.
  • production_prio = { ... } is a MTTH block that decides the 'importance' of the template compared to other templates within the role template for actually producing.
  • replace_with = my_other_template assigns a different template that serves as a more modern version of this one. When it becomes possible to create that template, AI will try to move towards using that one.
  • can_upgrade_in_field = { ... } is a trigger block that decides when AI will try to upgrade divisions that are already assigned this template to the one that it's set to be replaced with.
  • custom_icon = 10 assigns the icon that AI would assign to this template. This example would assign the template icon using the sprites GFX_div_templ_10_large and GFX_div_templ_10_small. Optional, defaults to the majority brigade within the template.
  • reinforce_prio = 2 assigns the reinforce priority that AI would set on this template. The default priority is 1, appearing in-game as 'regular'. 0 is 'reserve', and 2 is 'elite'. Defaults to 1 if unset.
  • target_width = 20 assigns the combat width that the AI aims for on this template.
  • width_weight = 2.5 assigns how much the AI should focus on aiming towards the target width. The higher the weight, the more AI would avoid deviating from the target width.
  • column_swap_factor = 0.3 assigns a likelihood for AI to swap entire columns within the template to a different subunit group to meet the template.
  • stat_weights = { ... } is a list of decimal values. Each one applies to different stats and decides what exactly AI should try to prioritise and what it should try to avoid. As within NDefines.NAI.DIVISION_DESIGN_WEIGHTS in Defines, these stats are first the 17 army values, then air_attack, then common values and special values. In other words, Air and Navy values get skipped aside from air_attack, which is used by anti-air equipment. The value would be added to the default in defines: a 0.00 would mean it's the same priority as default.
  • allowed_types = { ... } is a list of sub-units that the AI can add to the template. If one is omitted, then the AI would never add it. This can be used to make AI not put units of different varieties in the template, such as putting infantry in a mobile light tank division, slowing it down.
  • target_template = { ... } assigns the template that AI should aim for. In particular, these arguments go inside of it:
    • weight = 0.8 is how much the AI should aim towards having that template.
    • match_value = 5000 is a value that decides how much the template is worth to AI if it's matched.
    • support = { ... } is a list of support battalions within the target template. A single definition within looks like artillery = 1. The first decides the unit type, the second decides the amount. Since there is a limit of only one of the same support battalion being allowed, the number can't be anything other than 1.
    • regiments = { ... } is a list of non-support, regular battalions within the target template. A single definition within looks like artillery_brigade = 4. The first decides the unit type, the second decides the amount.

Each template assigned to a role will form a group for the role, and then the fitness score of each available template is used to determine which is used at a specific moment for a specific role.

Example

armor_BHR = {

    available_for = {
        BHR
    }

    roles = {
        armor
    }

    upgrade_prio = {
        factor = 2.17

        modifier = {
            factor = 7
            OR = {
                has_tech = basic_medium_tank
                has_tech = basic_medium_tank_chassis
            }
        }

        modifier = {
            factor = 2
            OR = {
                has_tech = main_battle_tank
                has_tech = main_battle_tank_chassis
            }
        }
    }

    match_to_count = 0.5

    medium_armor_BHR = {


        upgrade_prio = {
            factor = 2
        }

        target_width = 19.9
        width_weight = 3.0
        column_swap_factor = 0.1

        stat_weights = {
            0.00 #-- default_morale
            1.10 #-- defense
            1.10 #-- breakthrough
            1.60 #-- hardness
            1.00 #-- soft_attack
            2.00 #-- hard_attack
            0.10 #-- recon
            0.01 #-- entrenchment
            0.10 #-- initiative
            0.01 #-- casualty_trickleback
            -0.05 #-- supply_consumption_factor
            -0.01 #-- supply_consumption
            0.00 #-- suppression
            0.00 #-- suppression_factor
            0.01 #-- experience_loss_factor
            0.00 #-- equipment_capture_factor
            0.00 #-- fuel_capacity
            #-- Air Values
            0.02 #-- air_attack
            #-- Common Values
            50.00 #-- max_organisation
            0.80 #-- max_strength
            1.0 #-- maximum_speed
            10.0 #-- armor_value
            0.05 #-- ap_attack
            0.10 #-- reliability
            0.10 #-- reliability_factor
            0.00 #-- weight
            0.00 #-- fuel_consumption
            0.00 #-- fuel_consumption_factor
            0.00 #-- strat_attack
            0.00 #-- carrier_size
            0.00 #-- acc_hot_gain
            0.00 #-- acc_cold_gain
            0.00 #-- build_cost_ic
        }


        target_template = {
            weight = 0.9
            match_value = 7000.0

            support = {
                engineer = 1
                maintenance_company = 1
                logistics_company = 1
            }

            regiments = {
                medium_armor = 6
                motorized = 5
            }
        }

        allowed_types = {
            modern_armor
            medium_armor
            motorized
            mechanized
            infantry

            motorized_rocket_brigade

            engineer
            mot_recon
            armored_car_recon
            light_tank_recon
            signal_company
            maintenance_company
            logistics_company

            anti_tank
            military_police
            artillery
            anti_air
            rocket_artillery
        }

        replace_at_match = 0.8
        replace_with = modern_armor_BHR
        target_min_match = 0.5
    }

    modern_armor_BHR = {

        upgrade_prio = {
            factor = 2

            modifier = {
                factor = 1
            }
        }

        target_width = 19.9
        width_weight = 3.0
        column_swap_factor = 0.1

        stat_weights = {
            0.00 #-- default_morale
            1.10 #-- defense
            1.10 #-- breakthrough
            0.60 #-- hardness
            2.00 #-- soft_attack
            0.00 #-- hard_attack
            0.10 #-- recon
            0.01 #-- entrenchment
            0.10 #-- initiative
            0.01 #-- casualty_trickleback
            -0.05 #-- supply_consumption_factor
            -0.01 #-- supply_consumption
            0.00 #-- suppression
            0.00 #-- suppression_factor
            0.01 #-- experience_loss_factor
            0.00 #-- equipment_capture_factor
            0.00 #-- fuel_capacity
            #-- Air Values
            0.02 #-- air_attack
            #-- Common Values
            50.00 #-- max_organisation
            0.80 #-- max_strength
            10.0 #-- maximum_speed
            0.20 #-- armor_value
            0.05 #-- ap_attack
            0.10 #-- reliability
            0.10 #-- reliability_factor
            0.00 #-- weight
            0.00 #-- fuel_consumption
            0.00 #-- fuel_consumption_factor
            0.00 #-- strat_attack
            0.00 #-- carrier_size
            0.00 #-- acc_hot_gain
            0.00 #-- acc_cold_gain
            0.00 #-- build_cost_ic
        }

        target_template = {
            weight = 0.9
            match_value = 9000.0

            support = {
                engineer = 1
                recon = 1
                maintenance_company = 1
                logistics_company = 1
            }

            regiments = {
                modern_armor = 4
                mechanized = 3
                medium_sp_artillery_brigade = 2
            }
        }


        allowed_types = {
            modern_armor
            mechanized
            motorized_rocket_brigade
            medium_sp_artillery_brigade
            engineer
            recon
            signal_company
            maintenance_company
            logistics_company

            anti_tank
            military_police
            artillery
            anti_air
            rocket_artillery
        }
    }
}

AI equipment

/Hearts of Iron IV/common/ai_equipment/*.txt files are used in order to define the equipment variants that the AI should aim for when assigning modules to tank or ship variants.

A role template is defined as a block within any file in the folder with the name of the block being the same as the name of the role template.
These arguments are used for role templates themselves:

  • category = <land|naval|air> decides whether the template is used for tanks, ships or planes respectively.
  • roles = { ... } is a list of roles that the templates would have. These can be anything, getting used for the role_ratio AI strategy. AI will try to have one variant for each role it has.
  • available_for = { ... } restricts the countries that use this role template to the tags in the list. If unspecified, every country uses them.
  • blocked_for = { ... } restricts the countries that use this role template from being the tags in the list. This is only needed if there is no available_for = { ... } block.
  • priority = { ... } is a MTTH block that decides the 'importance' of the role template compared to other role templates for spending experience on improving. If there are several role templates with the same roles, the one with the highest priority gets used, otherwise this decides likelihood compared to role templates with different roles.

Additionally, within role templates each individual design is defined as a block with the name of the design being the name of the block. It may be anything, as long as there is no overlap.
These arguments are used within a design definition:

  • name = angry_speedboat required to enable the equipment to be used as preset. If not defined, for example German light_tank_artillery_2 will use GER_light_tank_artillery_equipment_2_short localization if defined.
  • role_icon_index = 2 is used to assign a specific role icon to a ship. This does not work within land equipment. The icons are defined as a part of naval_equipment_role = { ... } within /Hearts of Iron IV/gfx/army_icons/army_icons.txt.
  • priority = { ... } is a MTTH block that decides the 'importance' of the design compared to other templates within the role template for spending experience on improving.
  • enable = { ... } is a trigger block that decides when AI should aim towards the design.
  • allowed_types = { ... } is a list of sub-units that the AI can add to the design. If one is omitted, then the AI would never add it. This can be used to make AI not put units of different varieties in the design, such as putting infantry in a mobile light tank division, slowing it down.
  • target_variant = { ... } assigns the variant that AI should aim for. In particular, these arguments go inside of it:
    • match_value = 5000 is a value that decides how much the template is worth to AI if it's matched.
    • type = light_tank_chassis_0 is the specific equipment type that must be used by the design.
    • modules = { ... } is a list of modules that the equipment should have, in particular:
      • main_armament_slot = tank_flamethrower decides requirements for a specified module slot, in first place. The requirement may be a module category, a specific module, or the word empty. If specifying a module, the greater-than or lesser-than signs can be used in order to require greater or lesser modules: this is decided by the year defined within the module. If lesser is specified, AI aims towards oldest modules, if greater is specified, AI aims towards newest modules. If specifying empty, greater than can be used to ensure it's not empty.
      • main_armament_slot = { ... } allows specifying more details for a module slot:
        • module = tank_flamethrower decides a module requirement for the slot. This is the exact same formatting as previous main_armament_slot = tank_flamethrower: module categories, modules, or empty are allowed, and the equality signs can be used in the same way.
        • any_of = { ... } is a list of modules or module categories. The module slot must have at least one of them.
        • upgrade = current ensures that, when upgrading a variant to match this design, it must use the same one as on the existing equipment. If the 'greater than' sign is used (>), then it would require AI to upgrade this slot as well.
    • upgrades = { ... } is a list of upgrades that the design should have, in particular:
      • tank_nsb_engine_upgrade = 3 decides the AI priority that the specified upgrade should have to a fixed number.
      • tank_nsb_engine_upgrade = { ... } is a MTTH block that assigns the AI priority to the specified upgrade dynamically.
  • requirements = { ... } is a list of modules that the AI must have. This follows the same formatting as a specified module slot within a target variant's modules block: module = tank_flamethrower, any_of = { ... }, etc. However, this is not tied to a specific slot.
  • allowed_modules = { ... } is a list of modules that the AI can use after the requirements in the target variant are met. If a module isn't here, it'll never be picked. The modules specified first take priority over the later ones.

Example

BHR_light_tanks = {
    category = land

    available_for = {BHR}

    roles = {
        land_light_tank
    }

    priority = {
        factor = 1000
    }

    great_war_tank_default = {
        priority = {
            factor = 1
            modifier = {
                has_tech = basic_light_tank_chassis
                factor = 0 #let's not waste XP here
            }
        }

        target_variant = {
            match_value = 1000
            type = light_tank_chassis_0
            modules = {
                main_armament_slot = tank_heavy_machine_gun
                turret_type_slot = tank_light_one_man_tank_turret
                suspension_type_slot = tank_bogie_suspension
                armor_type_slot = tank_riveted_armor
                engine_type_slot = tank_gasoline_engine
                special_type_slot_1 = empty
                special_type_slot_2 = empty
                special_type_slot_3 = empty
                special_type_slot_4 = empty
            }
            upgrades = {
                tank_nsb_engine_upgrade = 3
                tank_nsb_armor_upgrade = {
                    base = 1
                    modifier = {
                        add = 1
                        has_war = yes
                    }
                }
            }
        }

        allowed_modules = {
            tank_heavy_machine_gun
            tank_light_one_man_tank_turret
            tank_bogie_suspension
            tank_riveted_armor
            tank_gasoline_engine
        }
    }
}