{
  "id": "014_cangting_pursuit",
  "name": "Cangting Pursuit",
  "objectives": {
    "victory": "Defeat Yuan Shao's rear guard after the retreat line rallies.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 13."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "turn_3_yuan_rally" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 13, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Cangting Pursuit",
    "location": "Cangting, 201 CE",
    "lines": [
      "With Wuchao destroyed, Yuan Shao's great army breaks into columns of wounded pride and hungry soldiers.",
      "Cao Cao pursues the retreating rear guard before it can gather enough order to shield the northern crossings."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "pressed_yuan_rout": true },
        "lines": [
          "The army gave Yuan Shao no room to breathe after Wuchao, and the rear guard is already fraying."
        ]
      },
      {
        "campaign_flags": { "secured_wuchao_stores": true },
        "lines": [
          "Captured stores from Wuchao keep the pursuit fed, letting Cao Cao press north without stretching the supply train."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "pressed_yuan_rout": true },
        "items": ["war_drum"]
      },
      {
        "campaign_flags": { "secured_wuchao_stores": true },
        "items": ["imperial_seal"]
      }
    ]
  },
  "roster": {
    "max_units": 6,
    "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]]
  },
  "map": {
    "width": 17,
    "height": 11,
    "terrain": [
      "GGGGGHHGGGGGGGGGG",
      "GGFFGHHGGGFFGGGGG",
      "GGRRRRRRRRRRRGFFG",
      "GGGGGRGGGGRRGGGGG",
      "RRRRRRRRRRRRRRRRG",
      "GGGGGRGGGGRRGGGGG",
      "GGHHGFFFGGFFFGGGG",
      "GGHHGFFFGGFFFGGGG",
      "GGGGGGFFGGHHHGGGG",
      "GGFFGGGGGGHHHFFGG",
      "GGGGGGGGGGGGGGGGG"
    ]
  },
  "deployments": [
    {
      "unit_id": "cao_cao_ch14",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch14",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "xiahou_dun_ch14",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch14",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch14",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "cao_ren_ch14",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "yuan_shao_rearguard",
      "name": "Yuan Shao Rear Guard",
      "class_id": "commander",
      "team": "enemy",
      "level": 13,
      "pos": [14, 4],
      "base": { "hp": 72, "mp": 16, "atk": 20, "def": 14, "int": 13, "agi": 10 }
    },
    {
      "unit_id": "zhang_he_rearguard",
      "name": "Zhang He Rearguard",
      "class_id": "elite_cavalry",
      "team": "enemy",
      "level": 13,
      "pos": [11, 4],
      "base": { "hp": 62, "atk": 21, "def": 12, "agi": 16 }
    },
    {
      "unit_id": "yuan_rally_advisor",
      "name": "Yuan Rally Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 13,
      "pos": [13, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 46, "mp": 30, "atk": 7, "def": 8, "int": 17, "agi": 10 }
    },
    {
      "unit_id": "cangting_center_guard",
      "name": "Cangting Guard",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 12,
      "pos": [10, 4],
      "base": { "hp": 56, "atk": 18, "def": 14 }
    },
    {
      "unit_id": "cangting_north_guard",
      "name": "Cangting Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 12,
      "pos": [11, 3],
      "base": { "hp": 50, "atk": 17, "def": 11 }
    },
    {
      "unit_id": "cangting_south_guard",
      "name": "Cangting Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 12,
      "pos": [11, 5],
      "base": { "hp": 50, "atk": 17, "def": 11 }
    },
    {
      "unit_id": "cangting_archer_north",
      "name": "Cangting Archer",
      "class_id": "marksman",
      "team": "enemy",
      "level": 12,
      "pos": [12, 2],
      "base": { "hp": 40, "atk": 16, "def": 7, "agi": 14 }
    },
    {
      "unit_id": "cangting_archer_south",
      "name": "Cangting Archer",
      "class_id": "marksman",
      "team": "enemy",
      "level": 12,
      "pos": [13, 6],
      "base": { "hp": 40, "atk": 16, "def": 7, "agi": 14 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Yuan Shao's retreating army tries to rally near Cangting." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "Wuchao broke their hunger. Cangting must break their confidence." },
            { "speaker": "Guo Jia", "text": "Zhang He holds the rear with more discipline than the rest. If he wavers, the rout becomes a road." },
            { "speaker": "Xiahou Yuan", "text": "Then we strike the disciplined men first." }
          ]
        }
      ]
    },
    {
      "id": "fast_pursuit_pressure",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "pressed_yuan_rout": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Dun", "text": "Our pursuit caught them before their wagons even formed a wall." },
            { "speaker": "Cao Cao", "text": "Momentum is a weapon. Keep it sharp." }
          ]
        }
      ]
    },
    {
      "id": "stored_supply_arrives",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "secured_wuchao_stores": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Guo Jia", "text": "The Wuchao stores are feeding our own pursuit now. Yuan Shao pays for both armies." },
            { "speaker": "Cao Cao", "text": "A pleasant economy." }
          ]
        }
      ]
    },
    {
      "id": "turn_3_yuan_rally",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 3 },
      "actions": [
        {
          "type": "set_objective",
          "victory": "Defeat Yuan Shao's rallied rear guard and every covering unit.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 13."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Zhang He", "text": "Hold the road. If the rear collapses, the whole army becomes fugitives." },
            { "speaker": "Guo Jia", "text": "He sees the truth. That makes him dangerous, and useful." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "yuan_rout_rider_north",
              "name": "Rout Rider",
              "class_id": "cavalry",
              "team": "enemy",
              "level": 12,
              "pos": [15, 3],
              "base": { "hp": 46, "atk": 17, "def": 9, "agi": 12 }
            },
            {
              "unit_id": "yuan_rout_rider_south",
              "name": "Rout Rider",
              "class_id": "cavalry",
              "team": "enemy",
              "level": 12,
              "pos": [15, 5],
              "base": { "hp": 46, "atk": 17, "def": 9, "agi": 12 }
            }
          ]
        }
      ]
    },
    {
      "id": "center_pursuit_trap",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [9, 4] },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Yuan Guard", "text": "Cao Cao is in the center road. Close the retreat line behind him!" },
            { "speaker": "Dian Wei", "text": "Try closing it from the ground." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "cangting_road_guard",
              "name": "Road Guard",
              "class_id": "infantry",
              "team": "enemy",
              "level": 12,
              "pos": [8, 3],
              "base": { "hp": 48, "atk": 17, "def": 11 }
            },
            {
              "unit_id": "cangting_road_archer",
              "name": "Road Archer",
              "class_id": "archer",
              "team": "enemy",
              "level": 12,
              "pos": [8, 5],
              "base": { "hp": 36, "atk": 15, "def": 6, "agi": 12 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_6_zhang_he_wavers",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 6 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Guo Jia", "text": "Zhang He is guarding a lord who no longer listens to his guards." },
            { "speaker": "Cao Cao", "text": "Then let him see which camp rewards judgment." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 2300,
    "items": ["bean", "wine", "iron_armor", "dragon_spear"],
    "join_officers": ["zhang_he"]
  },
  "post_battle_dialogue": [
    { "speaker": "Zhang He", "text": "Yuan Shao would rather lose an army than hear the men who tried to save it." },
    { "speaker": "Cao Cao", "text": "Then serve where clear eyes are useful." },
    { "speaker": "Guo Jia", "text": "Cangting breaks the pursuit open. The Yuan heirs will now fight over what remains." }
  ],
  "post_battle_choices": [
    {
      "id": "advance_to_ye",
      "label": "Advance to Ye",
      "description": "Cao Cao prepares to press toward the Yuan heartland before the heirs can settle.",
      "set_flags": { "advanced_to_ye": true, "secured_hebei_crossings": false },
      "gold": 100,
      "items": ["war_drum"]
    },
    {
      "id": "secure_hebei_crossings",
      "label": "Secure Crossings",
      "description": "The army consolidates river crossings and supply lanes before moving deeper north.",
      "set_flags": { "advanced_to_ye": false, "secured_hebei_crossings": true },
      "gold": 300,
      "items": ["imperial_seal"]
    }
  ]
}
