{
  "id": "021_bohai_remnants",
  "name": "Bohai Remnants",
  "objectives": {
    "victory": "Reach the remnant camp with Cao Cao, then defeat the Yuan brothers' covering force.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 16."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "remnant_camp_exposed" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 16, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Bohai Remnants",
    "location": "Bohai Commandery, 204 CE",
    "lines": [
      "Nanpi's surrender has broken Yuan Tan's court, but Yuan Shang and Yuan Xi still gather desperate retainers near Bohai.",
      "Cao Cao marches to scatter the remnant camp before its fugitives can trade the Yuan name for Wuhuan shelter."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "pursued_yuan_brothers": true },
        "lines": [
          "Fast columns have kept pressure on the fleeing Yuan brothers, catching their camp before scouts can turn panic into distance."
        ]
      },
      {
        "campaign_flags": { "secured_bohai_commandery": true },
        "lines": [
          "Bohai's surrendered towns now feed Cao Cao's advance, leaving Yuan loyalists short on safe roads and honest guides."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "pursued_yuan_brothers": true },
        "items": ["war_drum"]
      },
      {
        "campaign_flags": { "secured_bohai_commandery": 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": [
      "GGGGGHHGGGGGGGGGGG",
      "GGFFGHHGGGFFGGGFFG",
      "GGRRRRRRRRRRRRGFFG",
      "GGGGGRGGGGRRGGGGGG",
      "RRRRRRRRRRRRRRRRRR",
      "GGGGGRGGGGRRGGGGGG",
      "GGHHGFFFGGFFFGGHHG",
      "GGHHGFFFGGFFFGGHHG",
      "GGGGGGFFGGHHHGGGGG",
      "GGFFGGGGGGHHHFFGGG",
      "GGGGGGGGGGGGGGGGGG"
    ]
  },
  "deployments": [
    {
      "unit_id": "cao_cao_ch21",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch21",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch21",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch21",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch21",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch21",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch21",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "yuan_brothers_guard",
      "name": "Yuan Brothers Guard",
      "class_id": "commander",
      "team": "enemy",
      "level": 20,
      "pos": [14, 4],
      "base": { "hp": 96, "mp": 26, "atk": 26, "def": 20, "int": 15, "agi": 13 }
    },
    {
      "unit_id": "bohai_remnant_captain",
      "name": "Bohai Remnant Captain",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 19,
      "pos": [12, 4],
      "base": { "hp": 70, "atk": 23, "def": 18 }
    },
    {
      "unit_id": "yuan_exile_advisor",
      "name": "Yuan Exile Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 19,
      "pos": [15, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 58, "mp": 42, "atk": 7, "def": 10, "int": 22, "agi": 11 }
    },
    {
      "unit_id": "bohai_spear_north",
      "name": "Bohai Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 19,
      "pos": [12, 3],
      "base": { "hp": 62, "atk": 22, "def": 15 }
    },
    {
      "unit_id": "bohai_spear_south",
      "name": "Bohai Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 19,
      "pos": [12, 5],
      "base": { "hp": 62, "atk": 22, "def": 15 }
    },
    {
      "unit_id": "bohai_archer_north",
      "name": "Bohai Archer",
      "class_id": "marksman",
      "team": "enemy",
      "level": 19,
      "pos": [13, 2],
      "base": { "hp": 52, "atk": 22, "def": 9, "agi": 16 }
    },
    {
      "unit_id": "bohai_archer_south",
      "name": "Bohai Archer",
      "class_id": "marksman",
      "team": "enemy",
      "level": 19,
      "pos": [14, 6],
      "base": { "hp": 52, "atk": 22, "def": 9, "agi": 16 }
    },
    {
      "unit_id": "bohai_escape_rider",
      "name": "Bohai Escape Rider",
      "class_id": "elite_cavalry",
      "team": "enemy",
      "level": 19,
      "pos": [15, 3],
      "base": { "hp": 66, "atk": 23, "def": 13, "agi": 17 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Yuan remnants gather near Bohai before fleeing farther northeast." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Zhang He", "text": "The Yuan brothers are not holding Bohai. They are using it as a door." },
            { "speaker": "Cao Cao", "text": "Then we close the door before it opens toward Wuhuan." },
            { "speaker": "Guo Jia", "text": "A door with frightened men on both sides is best kicked once." }
          ]
        }
      ]
    },
    {
      "id": "fast_columns_arrive",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "pursued_yuan_brothers": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Bohai Remnant Captain", "text": "Cao Cao's columns are already here. The brothers said we had time to move the camp." },
            { "speaker": "Xiahou Yuan", "text": "They had time. They spent it running in circles." }
          ]
        },
        {
          "type": "spawn_deployment",
          "deployment": {
            "unit_id": "startled_bohai_rider",
            "name": "Startled Bohai Rider",
            "class_id": "cavalry",
            "team": "enemy",
            "level": 19,
            "pos": [16, 3],
            "base": { "hp": 56, "atk": 21, "def": 11, "agi": 14 }
          }
        }
      ]
    },
    {
      "id": "bohai_supply_anchor",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "secured_bohai_commandery": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "Bohai towns are marking the remnant paths for us. The old Yuan guides are selling tomorrow early." },
            { "speaker": "Cao Cao", "text": "Then buy the road with order and pay the loyalists with steel." }
          ]
        }
      ]
    },
    {
      "id": "turn_3_remnant_resolve",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 3 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Yuan Brothers Guard", "text": "Hold until the brothers reach the northern riders. Bohai is nothing if the bloodline escapes." },
            { "speaker": "Guo Jia", "text": "There it is. They have stopped defending land and started defending distance." }
          ]
        }
      ]
    },
    {
      "id": "remnant_camp_exposed",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [10, 4] },
      "actions": [
        {
          "type": "set_objective",
          "victory": "The remnant camp is exposed. Defeat the Yuan brothers' covering force.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 16."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "Their camp is in reach. Burn the banners, not the homes behind them." },
            { "speaker": "Yuan Brothers Guard", "text": "If the banners fall, the north forgets us. Protect them!" }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "yuan_brothers_camp_guard",
              "name": "Yuan Camp Guard",
              "class_id": "guard_captain",
              "team": "enemy",
              "level": 19,
              "pos": [16, 4],
              "base": { "hp": 66, "atk": 22, "def": 17 }
            },
            {
              "unit_id": "yuan_brothers_camp_archer",
              "name": "Yuan Camp Archer",
              "class_id": "archer",
              "team": "enemy",
              "level": 19,
              "pos": [16, 5],
              "base": { "hp": 46, "atk": 20, "def": 8, "agi": 14 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_8_banners_falter",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 8 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Zhang He", "text": "Their banners are moving without orders now. Men are carrying symbols they no longer understand." },
            { "speaker": "Cao Cao", "text": "Then let the symbols fall before the men do." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 4000,
    "items": ["bean", "wine", "iron_armor"]
  },
  "post_battle_dialogue": [
    { "speaker": "Zhang He", "text": "Bohai is cleared, but Yuan Shang and Yuan Xi are already looking beyond Han borders for shelter." },
    { "speaker": "Guo Jia", "text": "A defeated family becomes dangerous when it borrows another people's horsemen." },
    { "speaker": "Cao Cao", "text": "Then decide whether we ride after them now or make the road north obey us first." }
  ],
  "post_battle_choices": [
    {
      "id": "press_liaoxi_pursuit",
      "label": "Press Liaoxi",
      "description": "Cao Cao drives northeast before the Yuan brothers can bind Wuhuan support.",
      "set_flags": { "pressed_liaoxi_pursuit": true, "secured_liaoxi_approaches": false },
      "gold": 250,
      "items": ["war_drum"]
    },
    {
      "id": "secure_liaoxi_approaches",
      "label": "Secure Liaoxi",
      "description": "The army secures roads and depots before crossing toward the northern riders.",
      "set_flags": { "pressed_liaoxi_pursuit": false, "secured_liaoxi_approaches": true },
      "gold": 550,
      "items": ["imperial_seal"]
    }
  ]
}
