{
  "id": "007_xian_emperor_escort",
  "name": "Xian Emperor Escort",
  "objectives": {
    "victory": "Move Cao Cao to the eastern road marker.",
    "defeat": "Cao Cao or the imperial envoy is defeated, or the battle reaches Turn 11."
  },
  "conditions": {
    "victory": {
      "type": "unit_reaches_tile",
      "team": "player",
      "officer_ids": ["cao_cao"],
      "pos": [13, 4]
    },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "any_unit_defeated", "unit_ids": ["imperial_envoy_ch7"] },
      { "type": "turn_reached", "turn": 11, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Xian Emperor Escort",
    "location": "Luoyang Road, 196 CE",
    "lines": [
      "The imperial carriage has slipped out of the ruined capital under pressure from rival warlords.",
      "Cao Cao must reach the eastern road marker and secure the escort route before the remnants close in."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "fortified_yan_province": true },
        "lines": [
          "The fortified roads in Yan Province have kept supplies moving, giving the escort column a steadier pace."
        ]
      },
      {
        "campaign_flags": { "pressed_lu_bu": true },
        "lines": [
          "The army arrives quickly after pressing Lu Bu, but the forced march leaves little time to rest."
        ]
      }
    ],
    "camp_conversations": [
      {
        "id": "xian_escort_council",
        "group": "officer",
        "officer_id": "cao_cao",
        "label": "Cao Cao - Imperial Escort",
        "speaker": "Cao Cao",
        "summary": "Set the escort route before rival remnants close in.",
        "lines": [
          { "speaker": "Cao Cao", "side": "left", "text": "The Son of Heaven travels with us now. Every cart wheel on this road will sound louder than a battle drum." },
          { "speaker": "Xiahou Dun", "side": "right", "text": "Then we keep the column moving and let the remnants waste their blades on empty dust." }
        ]
      },
      {
        "id": "xian_dian_wei_envoy_screen",
        "group": "officer",
        "officer_id": "dian_wei",
        "label": "Dian Wei - Envoy Screen",
        "speaker": "Dian Wei",
        "summary": "Assign Dian Wei to shield the imperial envoy.",
        "lines": [
          { "speaker": "Dian Wei", "side": "right", "text": "The envoy is not a soldier, but every spear will look for him once the road narrows." },
          { "speaker": "Cao Cao", "side": "left", "text": "Then stand where the road narrows first. If the carriage halts, the realm itself hesitates." }
        ]
      },
      {
        "id": "xian_fortified_road_supplies",
        "campaign_flags": { "fortified_yan_province": true },
        "group": "topic",
        "label": "Fortified Road Supplies",
        "summary": "Open the food stores kept moving by the fortified Yan Province roads.",
        "lines": [
          { "speaker": "Escort Road Sutler", "side": "right", "text": "The fortified roads did their work. I brought beans forward without losing a cart to the dust." },
          { "speaker": "Cao Ren", "side": "left", "text": "Good. Feed the men guarding the carriage before the remnants test the road." }
        ],
        "effects": [
          { "type": "grant_item", "item_id": "bean", "count": 1, "text": "The fortified road supplies add a Bean to the field supplies." }
        ]
      },
      {
        "id": "xian_forced_march_canteens",
        "campaign_flags": { "pressed_lu_bu": true },
        "group": "topic",
        "label": "Forced March Canteens",
        "summary": "Issue wine to soldiers exhausted by the rapid march from Lu Bu's front.",
        "lines": [
          { "speaker": "Xiahou Yuan", "side": "right", "text": "We reached the emperor's road quickly, but the men are counting rest by mouthfuls now." },
          { "speaker": "Cao Cao", "side": "left", "text": "Give the vanguard wine before the column moves. Speed bought us this chance; discipline must keep it." }
        ],
        "effects": [
          { "type": "grant_item", "item_id": "wine", "count": 1, "text": "The forced march canteens add Wine to the field supplies." }
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "antidote",
      "panacea",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "leather_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "fortified_yan_province": true },
        "items": ["iron_armor"]
      },
      {
        "campaign_flags": { "pressed_lu_bu": true },
        "items": ["war_axe"]
      }
    ],
    "merchant": {
      "name": "Escort Road Sutler",
      "lines": [
        "No shouting near the carriage. Point at what you need and count the coin quietly.",
        "A court escort spends more medicine than arrows. Warlord remnants prefer soft targets."
      ]
    }
  },
  "roster": {
    "max_units": 5,
    "required_officers": ["cao_cao"],
    "required_units": ["imperial_envoy_ch7"]
  },
  "formation": {
    "cells": [[1, 4], [1, 5], [2, 3], [2, 4], [2, 5], [3, 3], [3, 4], [3, 5]]
  },
  "map": {
    "width": 15,
    "height": 10,
    "terrain": [
      "GGGGGGGGGGGGGGG",
      "GGGFFGGGHHGGGGG",
      "GGGFFRRRHHGGGGG",
      "GGGGGRRRGGFFFGG",
      "RRRRRRRRRRRRRRR",
      "GGGGGRRRGGFFFGG",
      "GGHHGFFFGGGRRGG",
      "GGHHGFFFGGGWWGG",
      "GGGGGGFFGGGWWGG",
      "GGGGGGGGGGGGGGG"
    ]
  },
  "deployments": [
    {
      "unit_id": "cao_cao_ch7",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "imperial_envoy_ch7",
      "name": "Imperial Envoy",
      "class_id": "infantry",
      "team": "player",
      "level": 1,
      "controllable": false,
      "persist_progression": false,
      "ai_target_priority": 6,
      "pos": [1, 5],
      "base": { "hp": 28, "mp": 0, "atk": 1, "def": 4, "int": 8, "agi": 5 }
    },
    {
      "unit_id": "xiahou_dun_ch7",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [2, 4]
    },
    {
      "unit_id": "dian_wei_ch7",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch7",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "cao_ren_ch7",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "li_jue_vanguard",
      "name": "Li Jue Vanguard",
      "class_id": "cavalry",
      "team": "enemy",
      "level": 7,
      "pos": [9, 4],
      "base": { "hp": 48, "atk": 16, "def": 8, "agi": 11 }
    },
    {
      "unit_id": "guo_si_guard",
      "name": "Guo Si Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 7,
      "pos": [10, 5],
      "base": { "hp": 48, "atk": 15, "def": 10 }
    },
    {
      "unit_id": "escort_road_archer",
      "name": "Road Archer",
      "class_id": "archer",
      "team": "enemy",
      "level": 7,
      "pos": [11, 3],
      "base": { "hp": 34, "atk": 13, "def": 6 }
    },
    {
      "unit_id": "escort_hill_bandit",
      "name": "Hill Bandit",
      "class_id": "bandit",
      "team": "enemy",
      "level": 7,
      "pos": [8, 2],
      "base": { "hp": 42, "atk": 14, "def": 7 }
    },
    {
      "unit_id": "escort_strategist",
      "name": "Court Remnant",
      "class_id": "strategist",
      "team": "enemy",
      "level": 7,
      "pos": [12, 6],
      "base": { "hp": 36, "mp": 20, "atk": 7, "def": 6, "int": 13 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "The imperial escort road lies beyond the enemy vanguard." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "Do not chase every remnant. Our task is the road ahead." },
            { "speaker": "Xiahou Dun", "text": "Then we punch through the center and keep you moving." },
            { "speaker": "Dian Wei", "text": "I will keep their blades away from the envoy." }
          ]
        }
      ]
    },
    {
      "id": "turn_3_rear_pressure",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 3 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Scout", "text": "Enemy riders are circling behind us!" },
            { "speaker": "Cao Cao", "text": "Then the envoy cannot linger. Forward." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "rear_pressure_rider",
              "name": "Rear Rider",
              "class_id": "cavalry",
              "team": "enemy",
              "level": 7,
              "pos": [4, 1],
              "base": { "hp": 40, "atk": 15, "def": 7, "agi": 10 }
            },
            {
              "unit_id": "rear_pressure_bandit",
              "name": "Rear Bandit",
              "class_id": "bandit",
              "team": "enemy",
              "level": 7,
              "pos": [5, 7],
              "base": { "hp": 40, "atk": 14, "def": 7 }
            }
          ]
        }
      ]
    },
    {
      "id": "midroad_ambush",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "pos": [7, 4] },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Imperial Envoy", "text": "There are banners moving in the northern trees!" },
            { "speaker": "Cao Cao", "text": "So the road was bait. Keep the envoy covered and break through." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "midroad_ambush_guard",
              "name": "Ambush Guard",
              "class_id": "infantry",
              "team": "enemy",
              "level": 7,
              "pos": [7, 2],
              "base": { "hp": 42, "atk": 14, "def": 9 }
            },
            {
              "unit_id": "midroad_ambush_archer",
              "name": "Ambush Archer",
              "class_id": "archer",
              "team": "enemy",
              "level": 7,
              "pos": [8, 6],
              "base": { "hp": 32, "atk": 13, "def": 6 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_5_road_marker",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 5 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Yuan", "text": "The eastern road marker is in sight. Cao Cao only needs a clear lane." },
            { "speaker": "Cao Cao", "text": "Good. Hold the flanks and do not let the rear pressure break our pace." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 1100,
    "items": ["bean", "iron_armor"]
  },
  "post_battle_dialogue": [
    { "speaker": "Cao Cao", "text": "The Son of Heaven is safe on the road. That changes every banner in the realm." },
    { "speaker": "Xiahou Dun", "text": "Then every rival will look at us differently after today." },
    { "speaker": "Cao Cao", "text": "Let them. Authority is also a battlefield." }
  ],
  "post_battle_choices": [
    {
      "id": "secure_imperial_court",
      "label": "Secure the Court",
      "description": "Cao Cao focuses on stabilizing the imperial court.",
      "set_flags": { "secured_imperial_court": true },
      "gold": 200,
      "items": ["imperial_seal"]
    },
    {
      "id": "pursue_li_jue_remnants",
      "label": "Pursue Remnants",
      "description": "The army presses the scattered warlord remnants.",
      "set_flags": { "pursued_li_jue_remnants": true },
      "items": ["war_drum", "training_spear", "bean", "wine"]
    }
  ]
}
