{
  "id": "031_huarong_retreat",
  "name": "Huarong Retreat",
  "objectives": {
    "victory": "Reach the Huarong road with Cao Cao, then defeat the coalition roadblock.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "huarong_road_opened" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 18, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Huarong Retreat",
    "location": "Huarong Road, Jing Province, 208 CE",
    "lines": [
      "Red Cliffs burns behind Cao Cao as rain, smoke, and broken drums scatter the fleet's survivors toward Huarong.",
      "The coalition pursuit is not a single army now, but roadblocks, riders, and old debts waiting in the mud."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "held_red_cliffs_line": true },
        "lines": [
          "Holding the fleet line preserved order among the survivors, but the delay let coalition pursuers close around Huarong."
        ]
      },
      {
        "campaign_flags": { "opened_huarong_retreat": true },
        "lines": [
          "Opening the retreat early put Cao Cao on the Huarong road sooner, though scattered detachments still stumble through the rain behind him."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "held_red_cliffs_line": true },
        "items": ["imperial_seal"]
      },
      {
        "campaign_flags": { "opened_huarong_retreat": 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_ch31",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch31",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch31",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch31",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch31",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch31",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch31",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "guan_yu_roadblock",
      "name": "Guan Yu Roadblock",
      "class_id": "champion",
      "team": "enemy",
      "level": 29,
      "pos": [14, 4],
      "base": { "hp": 120, "mp": 12, "atk": 33, "def": 25, "int": 14, "agi": 20 }
    },
    {
      "unit_id": "huarong_gate_captain",
      "name": "Huarong Gate Captain",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 28,
      "pos": [12, 4],
      "base": { "hp": 88, "atk": 29, "def": 23 }
    },
    {
      "unit_id": "pursuit_rider",
      "name": "Coalition Pursuit Rider",
      "class_id": "elite_cavalry",
      "team": "enemy",
      "level": 28,
      "pos": [15, 3],
      "base": { "hp": 86, "atk": 30, "def": 17, "agi": 23 }
    },
    {
      "unit_id": "rain_mist_advisor",
      "name": "Rain Mist Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 28,
      "pos": [15, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 76, "mp": 60, "atk": 8, "def": 14, "int": 31, "agi": 15 }
    },
    {
      "unit_id": "huarong_spear_north",
      "name": "Huarong Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 28,
      "pos": [12, 3],
      "base": { "hp": 78, "atk": 29, "def": 21 }
    },
    {
      "unit_id": "huarong_spear_south",
      "name": "Huarong Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 28,
      "pos": [12, 5],
      "base": { "hp": 78, "atk": 29, "def": 21 }
    },
    {
      "unit_id": "mud_road_archer_north",
      "name": "Mud Road Archer",
      "class_id": "marksman",
      "team": "enemy",
      "level": 28,
      "pos": [13, 2],
      "base": { "hp": 70, "atk": 30, "def": 11, "agi": 22 }
    },
    {
      "unit_id": "mud_road_archer_south",
      "name": "Mud Road Archer",
      "class_id": "marksman",
      "team": "enemy",
      "level": 28,
      "pos": [14, 6],
      "base": { "hp": 70, "atk": 30, "def": 11, "agi": 22 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Cao Cao's army retreats through Huarong as coalition pursuers gather around the rain-soaked road." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Guo Jia", "text": "The smoke hides us from the river, but not from men who know this road." },
            { "speaker": "Cao Cao", "text": "Then we leave them mud, corpses, and no clear count of our strength." },
            { "speaker": "Zhang He", "text": "A roadblock waits ahead. It is placed like a question, not a trap." }
          ]
        }
      ]
    },
    {
      "id": "held_line_draws_pursuit",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "held_red_cliffs_line": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Coalition Pursuit Rider", "text": "Cao Cao held the fleet too long. Close the road before his rearguard reforms." },
            { "speaker": "Cao Ren", "text": "The line bought order, and order can still bite." }
          ]
        },
        {
          "type": "spawn_deployment",
          "deployment": {
            "unit_id": "late_pursuit_column",
            "name": "Late Pursuit Column",
            "class_id": "cavalry",
            "team": "enemy",
            "level": 28,
            "pos": [16, 3],
            "base": { "hp": 74, "atk": 28, "def": 15, "agi": 19 }
          }
        }
      ]
    },
    {
      "id": "opened_retreat_keeps_gap",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "opened_huarong_retreat": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Dun", "text": "The early retreat kept a gap in the road, but the rear units are still limping through smoke." },
            { "speaker": "Cao Cao", "text": "A gap is enough. We widen it with steel." }
          ]
        }
      ]
    },
    {
      "id": "turn_4_rain_closes",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 4 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Rain Mist Advisor", "text": "Rain turns retreat into a ledger. Count every wagon that sinks." },
            { "speaker": "Guo Jia", "text": "They want us to move like a defeated army. Refuse the shape." }
          ]
        }
      ]
    },
    {
      "id": "huarong_road_opened",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [10, 4] },
      "actions": [
        {
          "type": "set_objective",
          "victory": "The Huarong road is open. Defeat the coalition roadblock.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "Huarong opens, but only if that roadblock breaks." },
            { "speaker": "Guan Yu Roadblock", "text": "The road remembers old favors and old wars. Show me which one walks here today." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "huarong_halberd_guard",
              "name": "Huarong Halberd Guard",
              "class_id": "guard_captain",
              "team": "enemy",
              "level": 28,
              "pos": [16, 4],
              "base": { "hp": 86, "atk": 29, "def": 23 }
            },
            {
              "unit_id": "coalition_crossbow_screen",
              "name": "Coalition Crossbow Screen",
              "class_id": "archer",
              "team": "enemy",
              "level": 28,
              "pos": [16, 5],
              "base": { "hp": 64, "atk": 28, "def": 9, "agi": 20 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_9_rear_straggles",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 9 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Zhang He", "text": "The rear units are still straggling. Every turn gives the pursuers another banner." },
            { "speaker": "Cao Cao", "text": "Then make every banner pay a toll." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 6000,
    "items": ["bean", "wine", "war_drum"]
  },
  "post_battle_dialogue": [
    { "speaker": "Guo Jia", "text": "Huarong did not swallow us, but the retreat has changed the shape of the southern campaign." },
    { "speaker": "Cao Ren", "text": "If we stand a rearguard here, Jiangling's survivors may gather. If we run north, Xuchang hears of us sooner." },
    { "speaker": "Cao Cao", "text": "Decide whether we secure the Huarong rearguard or rush the heartland before rumor outruns us." }
  ],
  "post_battle_choices": [
    {
      "id": "secure_huarong_rearguard",
      "label": "Secure Rearguard",
      "description": "Cao Cao steadies the Huarong road so more southern survivors can regroup before the next march.",
      "set_flags": { "secured_huarong_rearguard": true, "rushed_xuchang_return": false },
      "gold": 800,
      "items": ["imperial_seal"]
    },
    {
      "id": "rush_xuchang_return",
      "label": "Rush North",
      "description": "Cao Cao drives north quickly, reaching the heartland before rumor can turn retreat into panic.",
      "set_flags": { "secured_huarong_rearguard": false, "rushed_xuchang_return": true },
      "gold": 600,
      "items": ["war_drum"]
    }
  ]
}
