{
  "id": "032_jiangling_rearguard",
  "name": "Jiangling Rearguard",
  "objectives": {
    "victory": "Reach the Jiangling rearguard line with Cao Cao, then defeat the coalition pursuit.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "jiangling_rearguard_formed" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 18, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Jiangling Rearguard",
    "location": "Jiangling Approach, Jing Province, 208 CE",
    "lines": [
      "Huarong's mud is behind Cao Cao, but the southern road still bleeds stragglers, wagons, and broken banners.",
      "Near Jiangling, coalition detachments press the retreat, hoping to turn survival into a second defeat."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "secured_huarong_rearguard": true },
        "lines": [
          "The Huarong rearguard bought time for scattered units to reform, giving Cao Cao a steadier line near Jiangling."
        ]
      },
      {
        "campaign_flags": { "rushed_xuchang_return": true },
        "lines": [
          "The rush toward Xuchang carried news ahead of panic, but the Jiangling rear is thinner and more exposed."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "secured_huarong_rearguard": true },
        "items": ["imperial_seal"]
      },
      {
        "campaign_flags": { "rushed_xuchang_return": 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",
      "GGRRRRRRRRRRRRFFGG",
      "GGGFGHGGGGRRGGGGGG",
      "RRRRRRRRRRRRRRRRRR",
      "GGGGGHHGGGRRGFFGGG",
      "GGHHGFFFGGFFFGGHHG",
      "GGHHGFFFGGFFFGGHHG",
      "GGGGGGFFGGHHHGGGGG",
      "GGFFGGGGGGHHHFFGGG",
      "GGGGGGGGGGGGGGGGGG"
    ]
  },
  "deployments": [
    {
      "unit_id": "cao_cao_ch32",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch32",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch32",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch32",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch32",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch32",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch32",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "zhou_yu_rearguard_captain",
      "name": "Zhou Yu Rearguard Captain",
      "class_id": "commander",
      "team": "enemy",
      "level": 30,
      "pos": [14, 4],
      "base": { "hp": 116, "mp": 38, "atk": 32, "def": 25, "int": 23, "agi": 18 }
    },
    {
      "unit_id": "gan_ning_raider",
      "name": "Gan Ning Raider",
      "class_id": "champion",
      "team": "enemy",
      "level": 29,
      "pos": [15, 3],
      "base": { "hp": 118, "mp": 10, "atk": 34, "def": 23, "int": 12, "agi": 23 }
    },
    {
      "unit_id": "jiangling_gate_captain",
      "name": "Jiangling Gate Captain",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 29,
      "pos": [12, 4],
      "base": { "hp": 90, "atk": 30, "def": 24 }
    },
    {
      "unit_id": "southern_scout_advisor",
      "name": "Southern Scout Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 29,
      "pos": [15, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 78, "mp": 62, "atk": 8, "def": 14, "int": 32, "agi": 16 }
    },
    {
      "unit_id": "jiangling_spear_north",
      "name": "Jiangling Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 29,
      "pos": [12, 3],
      "base": { "hp": 80, "atk": 30, "def": 21 }
    },
    {
      "unit_id": "jiangling_spear_south",
      "name": "Jiangling Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 29,
      "pos": [12, 5],
      "base": { "hp": 80, "atk": 30, "def": 21 }
    },
    {
      "unit_id": "riverbank_marksman_north",
      "name": "Riverbank Marksman",
      "class_id": "marksman",
      "team": "enemy",
      "level": 29,
      "pos": [13, 2],
      "base": { "hp": 72, "atk": 31, "def": 11, "agi": 23 }
    },
    {
      "unit_id": "riverbank_marksman_south",
      "name": "Riverbank Marksman",
      "class_id": "marksman",
      "team": "enemy",
      "level": 29,
      "pos": [14, 6],
      "base": { "hp": 72, "atk": 31, "def": 11, "agi": 23 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Near Jiangling, Cao Cao forms a rearguard while coalition detachments test the retreating army's discipline." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "The wagons are moving again, but every bend in the road hides another banner." },
            { "speaker": "Guo Jia", "text": "A retreat survives when the enemy stops believing it is one." },
            { "speaker": "Cao Cao", "text": "Then give them a battle small enough to win and sharp enough to remember." }
          ]
        }
      ]
    },
    {
      "id": "secured_rearguard_reforms",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "secured_huarong_rearguard": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "The Huarong rearguard has caught up. The line can bend without breaking." },
            { "speaker": "Cao Cao", "text": "Good. Let Jiangling see that retreat has a spine." }
          ]
        }
      ]
    },
    {
      "id": "rushed_return_exposes_rear",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "rushed_xuchang_return": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Gan Ning Raider", "text": "Cao Cao hurried north and left his rear thin. Cut the wagons from the road." },
            { "speaker": "Xiahou Dun", "text": "They mistake speed for fear. We can correct that." }
          ]
        },
        {
          "type": "spawn_deployment",
          "deployment": {
            "unit_id": "river_pursuit_van",
            "name": "River Pursuit Van",
            "class_id": "cavalry",
            "team": "enemy",
            "level": 29,
            "pos": [16, 3],
            "base": { "hp": 76, "atk": 29, "def": 15, "agi": 20 }
          }
        }
      ]
    },
    {
      "id": "turn_4_southern_pressure",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 4 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Zhou Yu Rearguard Captain", "text": "Do not chase Cao Cao's banner. Chase the men who still believe they can follow it." },
            { "speaker": "Guo Jia", "text": "They understand morale. That makes this more dangerous than a simple pursuit." }
          ]
        }
      ]
    },
    {
      "id": "jiangling_rearguard_formed",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [10, 4] },
      "actions": [
        {
          "type": "set_objective",
          "victory": "The Jiangling rearguard is formed. Defeat the coalition pursuit.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "Here. Turn the road into a wall and make them spend blood for every wagon." },
            { "speaker": "Gan Ning Raider", "text": "A wall on a retreating road still has a back. Find it!" }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "jiangling_rearguard_guard",
              "name": "Jiangling Rearguard Guard",
              "class_id": "guard_captain",
              "team": "enemy",
              "level": 29,
              "pos": [16, 4],
              "base": { "hp": 88, "atk": 30, "def": 24 }
            },
            {
              "unit_id": "southern_arrow_screen",
              "name": "Southern Arrow Screen",
              "class_id": "archer",
              "team": "enemy",
              "level": 29,
              "pos": [16, 5],
              "base": { "hp": 66, "atk": 29, "def": 9, "agi": 21 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_9_wagons_clear",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 9 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Zhang He", "text": "The last wagons are clearing the road." },
            { "speaker": "Cao Cao", "text": "Then the rearguard has done its work. Finish what remains." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 6200,
    "items": ["bean", "wine", "imperial_seal"]
  },
  "post_battle_dialogue": [
    { "speaker": "Guo Jia", "text": "Jiangling's pursuit is broken. The south will keep watching, but it cannot swallow the retreat today." },
    { "speaker": "Cao Ren", "text": "We can stabilize the southern garrisons, or send the first strong detachments west before the passes harden." },
    { "speaker": "Cao Cao", "text": "The next war will not wait for our pride to heal. Choose where our strength gathers first." }
  ],
  "post_battle_choices": [
    {
      "id": "stabilize_jiangling_rearguard",
      "label": "Stabilize Jiangling",
      "description": "Cao Cao steadies the southern garrisons before turning his army toward the next front.",
      "set_flags": { "stabilized_jiangling_rearguard": true, "mobilized_tong_pass_vanguard": false },
      "gold": 900,
      "items": ["imperial_seal"]
    },
    {
      "id": "mobilize_tong_pass_vanguard",
      "label": "Mobilize West",
      "description": "Cao Cao sends the first detachments west, preparing for pressure around Tong Pass.",
      "set_flags": { "stabilized_jiangling_rearguard": false, "mobilized_tong_pass_vanguard": true },
      "gold": 650,
      "items": ["war_drum"]
    }
  ]
}
