{
  "id": "047_maicheng_pursuit",
  "name": "Maicheng Pursuit",
  "objectives": {
    "victory": "Reach the Maicheng road with Cao Cao, then defeat Guan Yu's retreat guard.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "maicheng_road_sealed" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 18, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Maicheng Pursuit",
    "location": "Maicheng Road, Jing Province, 219 CE",
    "lines": [
      "Guan Yu's supply road is broken, and the siege army retreats toward Maicheng under a tightening sky of banners.",
      "Cao Cao's army must seal the road before Guan Yu's retreat guard turns hunger into one last charge."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "secured_fancheng_line": true },
        "lines": [
          "Securing Fancheng's line lets Cao Ren close the northern road while Cao Cao presses the retreat from the front."
        ]
      },
      {
        "campaign_flags": { "pursued_guan_yu_rearguard": true },
        "lines": [
          "Pursuing Guan Yu's rearguard kept the enemy's banners in sight, but desperate soldiers now guard every bend toward Maicheng."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "secured_fancheng_line": true },
        "items": ["imperial_seal"]
      },
      {
        "campaign_flags": { "pursued_guan_yu_rearguard": true },
        "items": ["war_drum"]
      }
    ]
  },
  "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",
      "GGRRRRGGFFGGRRRRGG",
      "GGGFGHGGGGRRGGGGGG",
      "RRRRRRRRRRRRRRRRRR",
      "GGGGGHHGGGRRGFFGGG",
      "GGHHGFFFGGFFFGGHHG",
      "GGHHGFFFGGFFFGGHHG",
      "GGGGGGFFGGHHHGGGGG",
      "GGFFGGGGGGHHHFFGGG",
      "GGGGGGGGGGGGGGGGGG"
    ]
  },
  "deployments": [
    {
      "unit_id": "cao_cao_ch47",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch47",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch47",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch47",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch47",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch47",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch47",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "guan_yu_maicheng_guard",
      "name": "Guan Yu",
      "class_id": "commander",
      "team": "enemy",
      "level": 44,
      "pos": [14, 4],
      "base": { "hp": 152, "mp": 68, "atk": 47, "def": 38, "int": 36, "agi": 25 }
    },
    {
      "unit_id": "guan_ping_rearguard",
      "name": "Guan Ping Rearguard",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 44,
      "pos": [12, 4],
      "base": { "hp": 122, "atk": 46, "def": 39 }
    },
    {
      "unit_id": "zhou_cang_last_charge",
      "name": "Zhou Cang Last Charge",
      "class_id": "champion",
      "team": "enemy",
      "level": 44,
      "pos": [15, 3],
      "base": { "hp": 150, "mp": 12, "atk": 48, "def": 34, "int": 13, "agi": 30 }
    },
    {
      "unit_id": "maicheng_retreat_advisor",
      "name": "Maicheng Retreat Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 44,
      "pos": [13, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 108, "mp": 92, "atk": 8, "def": 25, "int": 47, "agi": 22 }
    },
    {
      "unit_id": "maicheng_spear_north",
      "name": "Maicheng Spear",
      "class_id": "infantry",
      "team": "enemy",
      "level": 44,
      "pos": [12, 3],
      "base": { "hp": 110, "atk": 45, "def": 35 }
    },
    {
      "unit_id": "maicheng_spear_south",
      "name": "Maicheng Spear",
      "class_id": "infantry",
      "team": "enemy",
      "level": 44,
      "pos": [12, 5],
      "base": { "hp": 110, "atk": 45, "def": 35 }
    },
    {
      "unit_id": "maicheng_marksman",
      "name": "Maicheng Marksman",
      "class_id": "marksman",
      "team": "enemy",
      "level": 44,
      "pos": [13, 2],
      "base": { "hp": 102, "atk": 46, "def": 21, "agi": 33 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Cao Cao seals the road toward Maicheng as Guan Yu's retreat guard turns to fight." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "Fancheng's walls no longer hear Guan Yu's drums. Now the road hears his retreat." },
            { "speaker": "Guo Jia", "text": "A proud army retreats slowly because every step feels like an argument with itself." },
            { "speaker": "Cao Cao", "text": "Then we answer before pride finds another road." }
          ]
        }
      ]
    },
    {
      "id": "secured_line_closes_north",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "secured_fancheng_line": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "The secured Fancheng line is closing behind us. Guan Yu cannot turn north without finding our banners." },
            { "speaker": "Cao Cao", "text": "Good. A road is strongest when the enemy owns none of it." }
          ]
        }
      ]
    },
    {
      "id": "pursuit_draws_last_charge",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "pursued_guan_yu_rearguard": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Guan Yu", "text": "Cao Cao's pursuit has not loosened. Riders, strike the flank and buy the road another hour." },
            { "speaker": "Zhang He", "text": "The rearguard still bites. Let them spend the last of it where we can see." }
          ]
        },
        {
          "type": "spawn_deployment",
          "deployment": {
            "unit_id": "maicheng_desperate_riders",
            "name": "Maicheng Desperate Riders",
            "class_id": "cavalry",
            "team": "enemy",
            "level": 44,
            "pos": [16, 3],
            "base": { "hp": 100, "atk": 41, "def": 25, "agi": 31 }
          }
        }
      ]
    },
    {
      "id": "turn_4_retreat_pressure",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 4 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Maicheng Retreat Advisor", "text": "Hold the bend. If the road stays open until dusk, Maicheng can still gather the scattered men." },
            { "speaker": "Guo Jia", "text": "They are fighting for time now, not ground." }
          ]
        }
      ]
    },
    {
      "id": "maicheng_road_sealed",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [10, 4] },
      "actions": [
        {
          "type": "set_objective",
          "victory": "The Maicheng road is sealed. Defeat Guan Yu's retreat guard.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "This road is closed. Guan Yu must either break us or admit the retreat has ended." },
            { "speaker": "Guan Yu", "text": "A closed road still opens under a loyal blade." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "maicheng_inner_guard",
              "name": "Maicheng Inner Guard",
              "class_id": "guard_captain",
              "team": "enemy",
              "level": 44,
              "pos": [16, 4],
              "base": { "hp": 118, "atk": 45, "def": 38 }
            },
            {
              "unit_id": "maicheng_arrow_screen",
              "name": "Maicheng Arrow Screen",
              "class_id": "archer",
              "team": "enemy",
              "level": 44,
              "pos": [16, 5],
              "base": { "hp": 94, "atk": 44, "def": 18, "agi": 32 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_9_retreat_falters",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 9 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Dun", "text": "Their retreat is losing shape. Even the road behind Guan Yu sounds crowded." },
            { "speaker": "Cao Cao", "text": "Then give the road no room to become a rallying cry." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 9200,
    "items": ["bean", "wine", "war_drum"]
  },
  "post_battle_dialogue": [
    { "speaker": "Guo Jia", "text": "The Maicheng road is sealed. Guan Yu's retreat can no longer move like an army." },
    { "speaker": "Cao Ren", "text": "Wu also watches Jing Province. We can coordinate the encirclement, or secure Xiangfan before another front demands the army." },
    { "speaker": "Cao Cao", "text": "When a great enemy falls, the question is not only who strikes. It is who stands closest when the dust settles." }
  ],
  "post_battle_choices": [
    {
      "id": "coordinate_wu_encirclement",
      "label": "Coordinate Wu",
      "description": "Cao Cao coordinates with Wu pressure to close Jing Province around Guan Yu's retreat.",
      "set_flags": { "coordinated_wu_encirclement": true, "secured_xiangfan_front": false },
      "gold": 1600,
      "items": ["imperial_seal"]
    },
    {
      "id": "secure_xiangfan_front",
      "label": "Secure Xiangfan",
      "description": "Cao Cao secures Xiangfan first, keeping the northern front steady before chasing the next opportunity.",
      "set_flags": { "coordinated_wu_encirclement": false, "secured_xiangfan_front": true },
      "gold": 1400,
      "items": ["war_drum"]
    }
  ]
}
