{
  "id": "017_ye_surrender",
  "name": "Ye Surrender",
  "objectives": {
    "victory": "Break the last Yuan holdouts after the surrender signal reaches the palace road.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 14."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "surrender_signal_sent" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 14, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Ye Surrender",
    "location": "Ye Palace Road, 202 CE",
    "lines": [
      "Ye's inner gate has fallen. Only palace loyalists and frightened Yuan officers remain between Cao Cao and the city's surrender.",
      "Zhang He warns that the last defenders will either break quickly or fight wildly to prove loyalty to absent heirs."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "forced_ye_surrender": true },
        "lines": [
          "Direct pressure on Ye leaves the palace guard short of time, but their cornered officers are ready for a final stand."
        ]
      },
      {
        "campaign_flags": { "negotiated_yuan_defections": true },
        "lines": [
          "Negotiations have drawn several Yuan captains away from the palace, leaving the loyalists angry and isolated."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "forced_ye_surrender": true },
        "items": ["war_drum"]
      },
      {
        "campaign_flags": { "negotiated_yuan_defections": 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_ch17",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch17",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch17",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch17",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch17",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch17",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch17",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "ye_last_loyalist",
      "name": "Ye Last Loyalist",
      "class_id": "commander",
      "team": "enemy",
      "level": 16,
      "pos": [14, 4],
      "base": { "hp": 78, "mp": 18, "atk": 22, "def": 16, "int": 12, "agi": 11 }
    },
    {
      "unit_id": "yuan_palace_guard",
      "name": "Yuan Palace Guard",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 15,
      "pos": [12, 4],
      "base": { "hp": 62, "atk": 19, "def": 15 }
    },
    {
      "unit_id": "yuan_palace_advisor",
      "name": "Palace Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 15,
      "pos": [15, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 50, "mp": 34, "atk": 7, "def": 8, "int": 18, "agi": 10 }
    },
    {
      "unit_id": "ye_palace_spear_north",
      "name": "Palace Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 15,
      "pos": [12, 3],
      "base": { "hp": 54, "atk": 18, "def": 12 }
    },
    {
      "unit_id": "ye_palace_spear_south",
      "name": "Palace Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 15,
      "pos": [12, 5],
      "base": { "hp": 54, "atk": 18, "def": 12 }
    },
    {
      "unit_id": "ye_palace_archer_north",
      "name": "Palace Archer",
      "class_id": "marksman",
      "team": "enemy",
      "level": 15,
      "pos": [13, 2],
      "base": { "hp": 44, "atk": 18, "def": 8, "agi": 14 }
    },
    {
      "unit_id": "ye_palace_archer_south",
      "name": "Palace Archer",
      "class_id": "marksman",
      "team": "enemy",
      "level": 15,
      "pos": [14, 6],
      "base": { "hp": 44, "atk": 18, "def": 8, "agi": 14 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Ye's last loyalists gather near the palace road." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Zhang He", "text": "The loyalists have no plan left, only the need to be seen dying for one." },
            { "speaker": "Cao Cao", "text": "Then let the city see survival rewarded as clearly as resistance is ended." },
            { "speaker": "Guo Jia", "text": "A surrender must look inevitable before it is signed." }
          ]
        }
      ]
    },
    {
      "id": "forced_pressure",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "forced_ye_surrender": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Dun", "text": "The direct pressure has them packed against the palace road." },
            { "speaker": "Cao Cao", "text": "Good. A cornered guard can no longer pretend to command a city." }
          ]
        }
      ]
    },
    {
      "id": "defection_pressure",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "negotiated_yuan_defections": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Palace Advisor", "text": "Two more captains have opened their gates to Cao Cao. The loyalists are fighting alone." },
            { "speaker": "Guo Jia", "text": "A city can surrender one door at a time." }
          ]
        }
      ]
    },
    {
      "id": "turn_3_last_stand",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 3 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Ye Last Loyalist", "text": "If the Yuan name must leave Ye, let Cao Cao pay for every stone." },
            { "speaker": "Zhang He", "text": "That is no longer strategy. It is grief with a spear." }
          ]
        }
      ]
    },
    {
      "id": "surrender_signal_sent",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [10, 4] },
      "actions": [
        {
          "type": "set_objective",
          "victory": "The surrender signal is sent. Defeat the loyalists who refuse it.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 14."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "Raise the surrender banner. Those who lay down arms will live under law." },
            { "speaker": "Ye Last Loyalist", "text": "Then we die outside that law." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "ye_last_rider",
              "name": "Last Rider",
              "class_id": "elite_cavalry",
              "team": "enemy",
              "level": 15,
              "pos": [16, 4],
              "base": { "hp": 56, "atk": 19, "def": 11, "agi": 14 }
            },
            {
              "unit_id": "ye_last_archer",
              "name": "Last Archer",
              "class_id": "archer",
              "team": "enemy",
              "level": 15,
              "pos": [16, 5],
              "base": { "hp": 38, "atk": 16, "def": 6, "agi": 12 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_7_city_surrenders",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 7 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Guo Jia", "text": "The palace road is quieting. Ye is deciding that tomorrow matters more than yesterday." },
            { "speaker": "Cao Cao", "text": "Then end the last yesterday standing in our way." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 3000,
    "items": ["bean", "wine", "iron_armor"]
  },
  "post_battle_dialogue": [
    { "speaker": "Zhang He", "text": "Ye has surrendered. The Yuan house still runs north, but its capital is no longer theirs." },
    { "speaker": "Guo Jia", "text": "A capital lost is a family argument made permanent." },
    { "speaker": "Cao Cao", "text": "Then Hebei must learn whether it belongs to heirs, rebels, or order." }
  ],
  "post_battle_choices": [
    {
      "id": "pursue_yuan_shang",
      "label": "Pursue Yuan Shang",
      "description": "Cao Cao turns immediately toward the fleeing Yuan heir.",
      "set_flags": { "pursued_yuan_shang": true, "stabilized_ye": false },
      "gold": 100,
      "items": ["war_drum"]
    },
    {
      "id": "stabilize_ye",
      "label": "Stabilize Ye",
      "description": "The army secures Ye's administration before marching farther north.",
      "set_flags": { "pursued_yuan_shang": false, "stabilized_ye": true },
      "gold": 350,
      "items": ["imperial_seal"]
    }
  ]
}
