{
  "id": "028_xiakou_pursuit",
  "name": "Xiakou Pursuit",
  "objectives": {
    "victory": "Reach the Xiakou harbor road with Cao Cao, then defeat the river rearguard.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "xiakou_harbor_reached" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 18, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Xiakou Pursuit",
    "location": "Xiakou, Yangtze Approach, 208 CE",
    "lines": [
      "Jiangling's storehouses now feed Cao Cao's advance, but Liu Bei's flight bends toward Xiakou and the river roads watched by Sun Quan.",
      "The pursuit presses into the humid crossings where a retreat can become a coalition if Cao Cao allows envoys enough time."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "pressed_xiakou_pursuit": true },
        "lines": [
          "Fast columns have kept Liu Bei's messengers from settling their stories, forcing Xiakou's rearguard to fight while still counting boats."
        ]
      },
      {
        "campaign_flags": { "secured_jiangling_storehouses": true },
        "lines": [
          "Jiangling's secured grain and ledgers support a steadier river approach, giving Cao Cao's officers confidence that the army can feed a fleet."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "pressed_xiakou_pursuit": true },
        "items": ["war_drum"]
      },
      {
        "campaign_flags": { "secured_jiangling_storehouses": true },
        "items": ["imperial_seal"]
      }
    ]
  },
  "roster": {
    "max_units": 7,
    "required_officers": ["cao_cao", "guo_jia"]
  },
  "formation": {
    "cells": [[1, 3], [1, 4], [1, 5], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [3, 2], [3, 3], [3, 4], [3, 5], [3, 6]]
  },
  "map": {
    "width": 18,
    "height": 11,
    "terrain": [
      "GGGGHHGGGGGGHHGGGG",
      "GGFFHHGGRRGGHHFFGG",
      "GGRRRRRRRRRRRRFFGG",
      "GGGFGHGGGGRRGGGGGG",
      "RRRRRRRRRRRRRRRRRR",
      "GGGGGHHGGGRRGFFGGG",
      "GGHHGFFFGGFFFGGHHG",
      "GGHHGFFFGGFFFGGHHG",
      "GGGGGGFFGGHHHGGGGG",
      "GGFFGGGGGGHHHFFGGG",
      "GGGGGGGGGGGGGGGGGG"
    ]
  },
  "deployments": [
    {
      "unit_id": "cao_cao_ch28",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch28",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch28",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch28",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch28",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch28",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch28",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "xiakou_harbor_captain",
      "name": "Xiakou Harbor Captain",
      "class_id": "commander",
      "team": "enemy",
      "level": 26,
      "pos": [14, 4],
      "base": { "hp": 108, "mp": 32, "atk": 30, "def": 23, "int": 20, "agi": 17 }
    },
    {
      "unit_id": "river_rearguard_captain",
      "name": "River Rearguard Captain",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 25,
      "pos": [12, 4],
      "base": { "hp": 82, "atk": 26, "def": 22 }
    },
    {
      "unit_id": "xiakou_advisor",
      "name": "Xiakou Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 25,
      "pos": [15, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 70, "mp": 54, "atk": 7, "def": 13, "int": 28, "agi": 14 }
    },
    {
      "unit_id": "xiakou_spear_north",
      "name": "Xiakou Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 25,
      "pos": [12, 3],
      "base": { "hp": 72, "atk": 26, "def": 19 }
    },
    {
      "unit_id": "xiakou_spear_south",
      "name": "Xiakou Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 25,
      "pos": [12, 5],
      "base": { "hp": 72, "atk": 26, "def": 19 }
    },
    {
      "unit_id": "xiakou_archer_north",
      "name": "Xiakou Archer",
      "class_id": "marksman",
      "team": "enemy",
      "level": 25,
      "pos": [13, 2],
      "base": { "hp": 64, "atk": 27, "def": 10, "agi": 20 }
    },
    {
      "unit_id": "xiakou_archer_south",
      "name": "Xiakou Archer",
      "class_id": "marksman",
      "team": "enemy",
      "level": 25,
      "pos": [14, 6],
      "base": { "hp": 64, "atk": 27, "def": 10, "agi": 20 }
    },
    {
      "unit_id": "river_escape_rider",
      "name": "River Escape Rider",
      "class_id": "elite_cavalry",
      "team": "enemy",
      "level": 25,
      "pos": [15, 3],
      "base": { "hp": 80, "atk": 28, "def": 16, "agi": 21 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Liu Bei's envoys race toward Xiakou while river defenders try to keep Cao Cao from the harbor road." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Guo Jia", "text": "Xiakou is where flight becomes diplomacy. If Liu Bei reaches Sun Quan cleanly, we inherit a river war." },
            { "speaker": "Cao Cao", "text": "Then muddy the river before he can cross it." },
            { "speaker": "Zhang He", "text": "The harbor guards are watching both us and the east. They expect a decision from Wu." }
          ]
        }
      ]
    },
    {
      "id": "xiakou_chase_disrupts_envoys",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "pressed_xiakou_pursuit": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiakou Harbor Captain", "text": "Cao Cao's riders are too close. The envoys cannot reach the docks without a fight." },
            { "speaker": "Xiahou Dun", "text": "Good. Make the docks hear steel before speeches." }
          ]
        },
        {
          "type": "spawn_deployment",
          "deployment": {
            "unit_id": "hurried_xiakou_rider",
            "name": "Hurried Xiakou Rider",
            "class_id": "cavalry",
            "team": "enemy",
            "level": 25,
            "pos": [16, 3],
            "base": { "hp": 68, "atk": 26, "def": 14, "agi": 18 }
          }
        }
      ]
    },
    {
      "id": "jiangling_stores_feed_fleet",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "secured_jiangling_storehouses": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "Jiangling's grain is counted and moving. The river columns can stay fed if Xiakou falls." },
            { "speaker": "Cao Cao", "text": "Then take the harbor road with discipline. Boats are worth more whole." }
          ]
        }
      ]
    },
    {
      "id": "turn_4_wu_shadow",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 4 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiakou Advisor", "text": "Hold until Wu answers. If Sun Quan sends ships, Cao Cao's road becomes water." },
            { "speaker": "Guo Jia", "text": "They are already borrowing courage from men not yet here." }
          ]
        }
      ]
    },
    {
      "id": "xiakou_harbor_reached",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [10, 4] },
      "actions": [
        {
          "type": "set_objective",
          "victory": "The Xiakou harbor road is reached. Defeat the river rearguard.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "The harbor road is in our hands. Break the guards before the river gives them allies." },
            { "speaker": "Xiakou Harbor Captain", "text": "If Xiakou falls, Liu Bei reaches Wu as a beggar. Hold the road!" }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "xiakou_harbor_guard",
              "name": "Xiakou Harbor Guard",
              "class_id": "guard_captain",
              "team": "enemy",
              "level": 25,
              "pos": [16, 4],
              "base": { "hp": 80, "atk": 26, "def": 22 }
            },
            {
              "unit_id": "xiakou_harbor_archer",
              "name": "Xiakou Harbor Archer",
              "class_id": "archer",
              "team": "enemy",
              "level": 25,
              "pos": [16, 5],
              "base": { "hp": 58, "atk": 25, "def": 8, "agi": 18 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_9_harbor_wavers",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 9 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Zhang He", "text": "Their harbor line is splitting between the river and the road." },
            { "speaker": "Cao Cao", "text": "Then choose for them. The road falls first." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 5400,
    "items": ["bean", "wine", "iron_armor"]
  },
  "post_battle_dialogue": [
    { "speaker": "Guo Jia", "text": "Xiakou is shaken, but the river has carried Liu Bei's need toward Sun Quan." },
    { "speaker": "Zhang He", "text": "The next fight will not be decided by roads alone. Ships and fire will matter." },
    { "speaker": "Cao Cao", "text": "Then decide whether we press the fleet toward Red Cliffs or secure Xiakou harbor before the river campaign begins." }
  ],
  "post_battle_choices": [
    {
      "id": "press_red_cliffs_fleet",
      "label": "Press Fleet",
      "description": "Cao Cao urges the fleet forward toward Red Cliffs before the coalition can settle.",
      "set_flags": { "pressed_red_cliffs_fleet": true, "secured_xiakou_harbor": false },
      "gold": 600,
      "items": ["war_drum"]
    },
    {
      "id": "secure_xiakou_harbor",
      "label": "Secure Harbor",
      "description": "The army secures Xiakou harbor and prepares the fleet before challenging the river coalition.",
      "set_flags": { "pressed_red_cliffs_fleet": false, "secured_xiakou_harbor": true },
      "gold": 900,
      "items": ["imperial_seal"]
    }
  ]
}
