Wiki

trigger · ai_has_role_division

Definition

  • Supported scope:COUNTRY
  • Supported target:none

Description

check if the ai controlled country has any fielded divisions for a specific role

实战 · 配合 · 坑

实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。

实战用法

ai_has_role_division 常用于 AI 策略脚本中,判断某国 AI 是否已在前线部署了特定职能(如装甲、海军陆战队等)的师,从而决定是否触发补充建造逻辑或调整 AI 行为优先级。典型场景是搭配 AI 策略文件,避免 AI 在已有足量特定角色师时仍持续浪费资源重复生产。

# 仅当 AI 控制的国家尚未有任何装甲角色的师时,才触发相关决议
available = {
    is_ai = yes
    NOT = {
        ai_has_role_division = armor
    }
}

配合关系

  • [ai_has_role_template](/wiki/trigger/ai_has_role_template):先用此 trigger 确认 AI 是否拥有对应角色的师团模板,再用 ai_has_role_division 确认是否已实际部署,两者组合可区分"有模板但未下场"与"已出战"两种状态。
  • [ai_wants_divisions](/wiki/trigger/ai_wants_divisions):判断 AI 是否有扩军意愿,与 ai_has_role_division 联用可构建"无该角色师且 AI 有意愿扩军"的双重门槛,逻辑更严谨。
  • [has_army_size](/wiki/trigger/has_army_size):用于交叉验证整体军队规模,防止 AI 在总兵力已过载时仍因缺少某角色师而盲目生产。
  • [any_country_division](/wiki/trigger/any_country_division):若需要更细粒度地检查特定师的属性(如装备或支援连),可用此 trigger 作为补充,弥补 ai_has_role_division 仅做角色层级判断的不足。

常见坑

  1. 误用于玩家控制国家:此 trigger 专为 AI 控制国家设计,若未配合 is_ai = yes 限制作用域,在玩家控制国家上使用时结果不可预期,容易造成条件永远不满足或逻辑混乱。
  2. 混淆"角色模板存在"与"实际部署":新手常误以为只要有该角色的师团模板此 trigger 就会返回真,但它检查的是已上场的师,若 AI 有模板却尚未训练完成并部署任何师,结果仍为假,需配合 ai_has_role_template 区分两种情况。

Hands-On Notes

Hands-on notes are AI-generated and checked against the vanilla command vocabulary — treat them as a starting point, not authoritative reference. The definition above is the game's own documentation.

Hands-On Usage

ai_has_role_division is commonly used in AI strategy scripts to determine whether an AI-controlled nation has already deployed divisions of a specific role (such as armor, marines, etc.) on the front lines. This helps decide whether to trigger additional construction logic or adjust AI behavior priorities. A typical scenario is pairing this with AI strategy files to prevent the AI from wasting resources on redundant production when it already has a sufficient number of divisions in a specific role.

# Only trigger the relevant decision if the AI-controlled nation does not yet have any divisions with the armor role
available = {
    is_ai = yes
    NOT = {
        ai_has_role_division = armor
    }
}

Synergy

  • [ai_has_role_template](/wiki/trigger/ai_has_role_template): First use this trigger to confirm whether the AI possesses a division template of the corresponding role, then use ai_has_role_division to confirm whether it has actually been deployed. Together, these two triggers can distinguish between "has template but not deployed" and "already in combat" states.
  • [ai_wants_divisions](/wiki/trigger/ai_wants_divisions): Determines whether the AI has the intent to expand its military. When used together with ai_has_role_division, it creates a dual threshold of "lacks the role division AND AI has expansion intent," making the logic more rigorous.
  • [has_army_size](/wiki/trigger/has_army_size): Used for cross-validation of overall army size to prevent the AI from blindly producing units just because it lacks divisions of a certain role when its total manpower is already overextended.
  • [any_country_division](/wiki/trigger/any_country_division): If you need more granular inspection of specific division attributes (such as equipment or support companies), use this trigger as a supplement to compensate for the limitation that ai_has_role_division only evaluates at the role level.

Common Pitfalls

  1. Misuse on player-controlled nations: This trigger is designed specifically for AI-controlled nations. If not combined with the is_ai = yes scope restriction, using it on player-controlled nations produces unpredictable results and can easily cause conditions to never be satisfied or logic to become confused.
  2. Confusing "role template exists" with "actually deployed": Beginners often mistakenly assume that if a division template of that role exists, this trigger will return true. However, it checks for divisions already in the field. If the AI has a template but has not yet finished training and deployed any divisions, the result is still false. Use ai_has_role_template in combination to distinguish between the two cases.