Wiki

effect · add_ai_strategy

Definition

  • Supported scope:COUNTRY
  • Supported target:THIS, ROOT, PREV, FROM, OWNER, CONTROLLER, OCCUPIED, CAPITAL

Description

Adds strategy entry to country AI

实战 · 配合 · 坑

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

实战用法

add_ai_strategy 主要用于在事件、决策或国策触发时动态干预 AI 的行为逻辑,例如让某国 AI 优先攻击特定目标、与某国保持友好关系,或提高对某类行动的倾向权重。常见于外交事件链中,让被拉拢的 AI 盟友提高对特定国家的好感权重,或在战争触发后让 AI 集中兵力方向。

# 在一个事件 option 中,让目标国 AI 提高对玩家的联盟倾向
country_event = {
    id = my_mod.1
    option = {
        name = my_mod.1.a
        FROM = {
            add_ai_strategy = {
                type = alliance
                id = "TAG"
                value = 100
            }
        }
    }
}

配合关系

  • [has_country_flag](/wiki/trigger/has_country_flag):先用 flag 检测是否已执行过策略注入,避免重复叠加同类 strategy 导致权重失控。
  • [add_opinion_modifier](/wiki/effect/add_opinion_modifier):外交场景中与 AI 策略调整配合,既改变 AI 决策倾向,又给玩家可见的关系数值反馈,逻辑上更完整。
  • [add_named_threat](/wiki/effect/add_named_threat):在威胁值上升的事件中,同步调整 AI 对特定国家的敌意策略,使 AI 行为与世界局势变化同步。
  • [ai_irrationality](/wiki/trigger/ai_irrationality):作为前置条件检查 AI 的随机行为幅度,在理性 AI 状态下才注入关键策略,防止策略被随机因素覆盖。

常见坑

  1. 策略类型(type)与参数搭配错误:不同 type 值所需的子字段(如 id 填国家 TAG 还是填其他标识)并不相同,若直接套用模板却不核对类型文档,会导致策略静默失效而 AI 行为毫无变化,且控制台不会报错。
  2. 正负值语义混淆value 的正负含义取决于 strategy 类型,并非所有类型都是"正值 = 更倾向",例如某些类型中负值才代表敌意提升,填反后 AI 行为会与预期完全相反。

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

add_ai_strategy is primarily used to dynamically intervene in AI behavioral logic when events, decisions, or national focuses are triggered—for example, making a certain nation's AI prioritize attacking specific targets, maintain friendly relations with another nation, or increase weighting toward certain action types. It is commonly found in diplomatic event chains, where it increases an AI ally's affinity weighting toward a specific nation, or after war erupts, concentrates AI military forces in particular directions.

# In an event option, increase the target nation's AI alliance tendency toward the player
country_event = {
    id = my_mod.1
    option = {
        name = my_mod.1.a
        FROM = {
            add_ai_strategy = {
                type = alliance
                id = "TAG"
                value = 100
            }
        }
    }
}

Synergy

  • [has_country_flag](/wiki/trigger/has_country_flag): Use flags first to detect whether a strategy injection has already been executed, avoiding repeated stacking of similar strategies that could cause weight values to spiral out of control.
  • [add_opinion_modifier](/wiki/effect/add_opinion_modifier): In diplomatic scenarios, pair with AI strategy adjustments to both alter AI decision tendencies and provide visible relationship feedback to the player—more logically complete.
  • [add_named_threat](/wiki/effect/add_named_threat): When events raise threat levels, simultaneously adjust the AI's hostility strategy toward specific nations, keeping AI behavior synchronized with global situation changes.
  • [ai_irrationality](/wiki/trigger/ai_irrationality): Serve as a precondition check for the AI's random behavior variance; inject critical strategies only when the AI is in a rational state to prevent strategies from being overridden by random factors.

Common Pitfalls

  1. Mismatched strategy type (type) and parameter combinations: Different type values require different subfields (such as whether id should contain a nation TAG or another identifier). Using a template without verifying the type documentation causes the strategy to silently fail with no AI behavior change, and the console will not report an error.
  2. Confusion over positive/negative value semantics: The positive or negative meaning of value depends on the strategy type; not all types follow "positive value = higher tendency." For example, in certain types, negative values represent increased hostility, and reversing the sign will cause AI behavior to be completely opposite to expectations.