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

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.