{
  "id": "020_nanpi_surrender",
  "name": "Nanpi Surrender",
  "objectives": {
    "victory": "Bring Cao Cao to Nanpi's gate, then defeat Yuan Tan's last loyalists.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 16."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "nanpi_gate_opened" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 16, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Nanpi Surrender",
    "location": "Nanpi Gate, 203 CE",
    "lines": [
      "Nanpi's outer line has broken. Yuan Tan's court hides behind the city gate while frightened officers argue over surrender terms.",
      "Cao Cao advances to make the decision visible, with Zhang He reading which defenders still choose the Yuan name over survival."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "pressed_yuan_tan_surrender": true },
        "lines": [
          "Direct pressure leaves Yuan Tan's loyalists cornered and loud, but the court has little time left to invent courage."
        ]
      },
      {
        "campaign_flags": { "secured_nanpi_admin": true },
        "lines": [
          "Nanpi officials already know Cao Cao's terms, and several gate officers are waiting for the safest moment to lay down arms."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "pressed_yuan_tan_surrender": true },
        "items": ["war_drum"]
      },
      {
        "campaign_flags": { "secured_nanpi_admin": 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_ch20",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch20",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch20",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch20",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch20",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch20",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch20",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "yuan_tan_last_guard",
      "name": "Yuan Tan Last Guard",
      "class_id": "commander",
      "team": "enemy",
      "level": 19,
      "pos": [14, 4],
      "base": { "hp": 92, "mp": 24, "atk": 25, "def": 19, "int": 14, "agi": 13 }
    },
    {
      "unit_id": "nanpi_gate_loyalist",
      "name": "Nanpi Gate Loyalist",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 18,
      "pos": [12, 4],
      "base": { "hp": 68, "atk": 22, "def": 17 }
    },
    {
      "unit_id": "nanpi_court_advisor",
      "name": "Court Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 18,
      "pos": [15, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 56, "mp": 40, "atk": 7, "def": 9, "int": 21, "agi": 11 }
    },
    {
      "unit_id": "nanpi_inner_spear_north",
      "name": "Inner Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 18,
      "pos": [12, 3],
      "base": { "hp": 60, "atk": 21, "def": 14 }
    },
    {
      "unit_id": "nanpi_inner_spear_south",
      "name": "Inner Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 18,
      "pos": [12, 5],
      "base": { "hp": 60, "atk": 21, "def": 14 }
    },
    {
      "unit_id": "nanpi_inner_archer_north",
      "name": "Inner Archer",
      "class_id": "marksman",
      "team": "enemy",
      "level": 18,
      "pos": [13, 2],
      "base": { "hp": 50, "atk": 21, "def": 8, "agi": 16 }
    },
    {
      "unit_id": "nanpi_inner_archer_south",
      "name": "Inner Archer",
      "class_id": "marksman",
      "team": "enemy",
      "level": 18,
      "pos": [14, 6],
      "base": { "hp": 50, "atk": 21, "def": 8, "agi": 16 }
    },
    {
      "unit_id": "nanpi_last_rider",
      "name": "Nanpi Last Rider",
      "class_id": "elite_cavalry",
      "team": "enemy",
      "level": 18,
      "pos": [15, 3],
      "base": { "hp": 64, "atk": 22, "def": 13, "agi": 16 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Nanpi's gate waits between surrender and Yuan Tan's last loyalists." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Guo Jia", "text": "The gate officers are counting lives now. Yuan Tan's name is becoming an expensive habit." },
            { "speaker": "Cao Cao", "text": "Then we show them the price of keeping it." },
            { "speaker": "Zhang He", "text": "Those who still resist will be the ones with nowhere to stand after the gate opens." }
          ]
        }
      ]
    },
    {
      "id": "direct_surrender_pressure",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "pressed_yuan_tan_surrender": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Yuan Tan Last Guard", "text": "Cao Cao thinks pressure will open Nanpi. Let the gate see we still have blades." },
            { "speaker": "Xiahou Dun", "text": "Good. The loud ones are coming out where we can reach them." }
          ]
        },
        {
          "type": "spawn_deployment",
          "deployment": {
            "unit_id": "desperate_nanpi_rider",
            "name": "Desperate Nanpi Rider",
            "class_id": "cavalry",
            "team": "enemy",
            "level": 18,
            "pos": [16, 3],
            "base": { "hp": 54, "atk": 20, "def": 10, "agi": 14 }
          }
        }
      ]
    },
    {
      "id": "admin_gate_terms",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "secured_nanpi_admin": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Guo Jia", "text": "Nanpi officials have heard the terms twice. The gate only needs a reason to call them law." },
            { "speaker": "Cao Cao", "text": "Then advance with discipline. A city surrenders to order, not noise." }
          ]
        }
      ]
    },
    {
      "id": "turn_3_last_loyalists",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 3 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Nanpi Gate Loyalist", "text": "No gate opens while Yuan Tan still breathes inside it." },
            { "speaker": "Zhang He", "text": "They are defending the idea of a lord more fiercely than the lord himself." }
          ]
        }
      ]
    },
    {
      "id": "nanpi_gate_opened",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [10, 4] },
      "actions": [
        {
          "type": "set_objective",
          "victory": "Nanpi's gate is open. Defeat Yuan Tan's loyalists who reject surrender.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 16."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "Open the gate under my banner. Those who surrender will keep their households." },
            { "speaker": "Yuan Tan Last Guard", "text": "Then our households will remember us as men who did not kneel." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "yuan_tan_palace_guard",
              "name": "Yuan Tan Palace Guard",
              "class_id": "guard_captain",
              "team": "enemy",
              "level": 18,
              "pos": [16, 4],
              "base": { "hp": 64, "atk": 21, "def": 16 }
            },
            {
              "unit_id": "yuan_tan_palace_archer",
              "name": "Yuan Tan Palace Archer",
              "class_id": "archer",
              "team": "enemy",
              "level": 18,
              "pos": [16, 5],
              "base": { "hp": 44, "atk": 19, "def": 7, "agi": 14 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_8_nanpi_breaks",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 8 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Guo Jia", "text": "The gate has chosen tomorrow. Only yesterday is still armed." },
            { "speaker": "Cao Cao", "text": "Then disarm yesterday." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 3800,
    "items": ["bean", "wine", "imperial_seal"]
  },
  "post_battle_dialogue": [
    { "speaker": "Zhang He", "text": "Nanpi has surrendered. Yuan Tan's name no longer commands a gate, only scattered men." },
    { "speaker": "Guo Jia", "text": "Scattered men can still become banners if ignored long enough." },
    { "speaker": "Cao Cao", "text": "Then we decide whether to chase the banners or bind the province before they gather." }
  ],
  "post_battle_choices": [
    {
      "id": "pursue_yuan_brothers",
      "label": "Pursue Yuan Brothers",
      "description": "Cao Cao sends columns after the fleeing Yuan heirs before they find new allies.",
      "set_flags": { "pursued_yuan_brothers": true, "secured_bohai_commandery": false },
      "gold": 200,
      "items": ["war_drum"]
    },
    {
      "id": "secure_bohai_commandery",
      "label": "Secure Bohai",
      "description": "The army steadies Bohai commandery and turns surrendered towns into supply anchors.",
      "set_flags": { "pursued_yuan_brothers": false, "secured_bohai_commandery": true },
      "gold": 500,
      "items": ["iron_armor"]
    }
  ]
}
