Wiki

trigger · has_railway_connection

Definition

  • Supported scope:any
  • Supported target:any

Description

Checks for an existing rail connection. Uses same params as can_build_railway. Example:
has_railway_connection = {
  build_only_on_allied = yes # No by default. If yes and the effect scope is country, it will only build on allied territories for the country

  # The following options are used for picking a path. You can specify multiple options and it will pick in following order:
  fallback = yes # Default no. If yes, each option will try to fallback to next one.
  # option 1: List of provinces to draw railways. If fallback = yes uses start and end provinces of the path as fallback in option 2.
  path = { 10 20 30 40 }
  # option 2: Specify start & end province IDs. It will pick the shortest path. If provinces are not valid and if fallback = yes it will use states of those provs and use in option 3.
  start_province = 42
  target_province = 84
  # option 3: Specify start & end state IDs. It will pick provinces with the best node (capital > nodes > naval )
  start_state = 50
  target_state = 100
}

实战 · 配合 · 坑

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

实战用法

has_railway_connection 常用于 mod 中判断两地之间是否已有铁路相连,从而控制某些决议、科技或事件的可用条件——例如只有在本国核心省份之间铁路贯通后才能触发工业化事件。也可用于 AI 策略逻辑,在补给线相关判断中验证前线与后方的铁路联通状态。

# 示例:只有首都与目标州之间存在铁路连接时,决议才可用
available = {
    has_railway_connection = {
        build_only_on_allied = yes
        start_state  = 500   # 己方首都所在州
        target_state = 742   # 目标工业州
    }
}

配合关系

  • [can_build_railway](/wiki/trigger/can_build_railway):两者参数完全相同,常先用 can_build_railway 检查"是否能建",再用 has_railway_connection 检查"是否已建",形成建前/建后的双重门控逻辑。
  • [build_railway](/wiki/effect/build_railway):在 has_railway_connection 返回假时触发 build_railway 补建铁路,典型模式是"没有连接则自动修建"。
  • [has_railway_level](/wiki/trigger/has_railway_level):配合使用可同时约束"存在连接"与"连接等级达标"两个维度,适合高铁/重型铁路 mod。
  • [custom_trigger_tooltip](/wiki/trigger/custom_trigger_tooltip):将 has_railway_connection 包裹其中,向玩家显示更可读的本地化提示,避免原始参数块直接暴露在 UI。

常见坑

  1. 路径选项优先级理解错误pathstart/target_provincestart/target_state 三种方式并非等价备选,游戏按固定顺序检测,仅当 fallback = yes 时才会在上一选项失败后降级到下一选项;若同时写了多种路径参数却忘记加 fallback = yes,往往只有最高优先级的那组生效,导致判断结果与预期不符。
  2. scope 与 build_only_on_allied 搭配失效build_only_on_allied = yes 只在 scope 为国家时有意义;若在州或省份 scope 下使用该参数,不会报错但行为未定义,容易让铁路连通性检查悄悄返回错误结果。

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

has_railway_connection is commonly used in mods to check whether two locations are connected by rail, thereby controlling the availability of certain decisions, technologies, or events—for example, triggering an industrialization event only after rail infrastructure is fully established between the player's core provinces. It can also be applied to AI strategy logic to verify rail connectivity between front lines and rear areas in supply line assessments.

# Example: A decision is available only when a railway connection exists between the capital and target state
available = {
    has_railway_connection = {
        build_only_on_allied = yes
        start_state  = 500   # State containing player's capital
        target_state = 742   # Target industrial state
    }
}

Synergy

  • [can_build_railway](/wiki/trigger/can_build_railway): Parameters are identical to this trigger. The typical pattern is to first use can_build_railway to check "whether construction is possible," then use has_railway_connection to check "whether it is already built," creating a dual-gate logic for pre-construction and post-construction scenarios.
  • [build_railway](/wiki/effect/build_railway): When has_railway_connection returns false, trigger build_railway to construct the railway retroactively. The classic pattern is "auto-build if no connection exists."
  • [has_railway_level](/wiki/trigger/has_railway_level): Using both in combination allows simultaneous constraints on "connection exists" and "connection level meets standard," ideal for high-speed rail or heavy rail mods.
  • [custom_trigger_tooltip](/wiki/trigger/custom_trigger_tooltip): Wrap has_railway_connection within this to display more readable localized tooltips to players, preventing raw parameter blocks from being exposed directly in the UI.

Common Pitfalls

  1. Misunderstanding path option priority: The three methods path, start/target_province, and start/target_state are not equivalent fallback options. The game checks them in a fixed order and only falls back to the next option if the previous one fails when fallback = yes is set. If you write multiple path parameters simultaneously but forget to add fallback = yes, typically only the highest-priority group takes effect, causing the judgment result to diverge from expectations.
  2. Scope and build_only_on_allied incompatibility: build_only_on_allied = yes is only meaningful when the scope is a country. Using this parameter under state or province scope will not throw an error, but behavior is undefined, easily causing rail connectivity checks to silently return incorrect results.