命令百科

effect · build_railway

Definition

  • Supported scope:any
  • Supported target:any

Description

Builds/adds railway level between two provinces or along a path. Example:
build_railway = {
  level = 1 # Defaults to 1
  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

  # You can specify a weight function that will be used in pathing. The scope will be the controller of the province it is trying to path to.
  # A negative value will make it not to path to that controller.
  # Non-negative values will be used as a path cost for that province.
  controller_priority = {
    base = 1

    modifier = {
      tag = MAN
      add = 2
    }
  }

  # 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 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。

实战用法

build_railway 常用于战役事件或国策完成后,在指定区域自动铺设铁路基础设施,例如模拟"大基建计划"或战时后勤保障场景。也可在占领事件中,根据控制方的阵营关系选择性地在友军领土上修建铁路网络。

# 国策完成后,在两州之间自动寻路修建一级铁路,仅限盟友领土
complete_national_focus = {
    effect = {
        build_railway = {
            level = 1
            build_only_on_allied = yes
            fallback = yes
            start_state = 42
            target_state = 67
            controller_priority = {
                base = 1
                modifier = {
                    is_ally_with = ROOT
                    add = 5
                }
            }
        }
    }
}

配合关系

  • [can_build_railway](/wiki/trigger/can_build_railway):在执行 build_railway 前先判断路径是否可修建,避免因路径不可达导致效果静默失败。
  • [has_railway_level](/wiki/trigger/has_railway_level):用于检测目标省份/州已有的铁路等级,配合 if 条件决定是否需要升级,防止重复建设。
  • [has_railway_connection](/wiki/trigger/has_railway_connection):验证两地之间是否已存在铁路连接,作为 build_railway 的前置或后置校验条件。
  • [custom_effect_tooltip](/wiki/effect/custom_effect_tooltip):由于 build_railway 本身的 UI 提示有时不够直观,搭配此命令向玩家显示更清晰的建设说明。

常见坑

  1. pathstart_province/start_state 混用导致逻辑冲突:三种寻路选项有优先级顺序,若同时写入多种选项但未开启 fallback = yes,游戏只会使用最高优先级的 path 字段,其余字段被完全忽略,新手常误以为会"自动选最优方案"。
  2. 在非国家 scope 下使用 build_only_on_allied = yes 无效:该字段仅在 scope 为 country 时生效,若在 state scope 或 province scope 下设置此项,不会报错但也不会产生任何过滤效果,容易造成在敌方领土意外建设铁路的 bug。