{
  "id": "016_ye_siege",
  "name": "Ye Siege",
  "objectives": {
    "victory": "Reach Ye's inner gate with Cao Cao, then defeat the palace defenders.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 15."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "inner_gate_breached" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 15, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Ye Siege",
    "location": "Ye, 202 CE",
    "lines": [
      "Ye's outer line has broken, but the Yuan heirs still command the inner city through suspicion and fear.",
      "Cao Cao orders a direct push toward the inner gate while Zhang He marks the streets where the defenders will try to seal the advance."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "pressed_ye_siege": true },
        "lines": [
          "The rapid siege leaves Yuan Shang's inner guard scrambling to reinforce streets that were still being repaired."
        ]
      },
      {
        "campaign_flags": { "split_yuan_heirs": true },
        "lines": [
          "Rumors spread through Ye that Yuan Tan has been abandoned, and some defenders hesitate before answering Yuan Shang's orders."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "pressed_ye_siege": true },
        "items": ["war_drum"]
      },
      {
        "campaign_flags": { "split_yuan_heirs": 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_ch16",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch16",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch16",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch16",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch16",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch16",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch16",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "yuan_shang_inner_guard",
      "name": "Yuan Shang Inner Guard",
      "class_id": "commander",
      "team": "enemy",
      "level": 15,
      "pos": [14, 4],
      "base": { "hp": 76, "mp": 18, "atk": 21, "def": 15, "int": 13, "agi": 11 }
    },
    {
      "unit_id": "ye_gate_captain",
      "name": "Ye Gate Captain",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 14,
      "pos": [11, 4],
      "base": { "hp": 62, "atk": 19, "def": 15 }
    },
    {
      "unit_id": "ye_inner_advisor",
      "name": "Inner City Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 14,
      "pos": [15, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 50, "mp": 34, "atk": 7, "def": 8, "int": 18, "agi": 10 }
    },
    {
      "unit_id": "ye_north_wall_guard",
      "name": "Ye Wall Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 14,
      "pos": [12, 3],
      "base": { "hp": 54, "atk": 18, "def": 12 }
    },
    {
      "unit_id": "ye_south_wall_guard",
      "name": "Ye Wall Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 14,
      "pos": [12, 5],
      "base": { "hp": 54, "atk": 18, "def": 12 }
    },
    {
      "unit_id": "ye_wall_archer_north",
      "name": "Ye Wall Archer",
      "class_id": "marksman",
      "team": "enemy",
      "level": 14,
      "pos": [13, 2],
      "base": { "hp": 44, "atk": 18, "def": 8, "agi": 14 }
    },
    {
      "unit_id": "ye_wall_archer_south",
      "name": "Ye Wall Archer",
      "class_id": "marksman",
      "team": "enemy",
      "level": 14,
      "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": "Cao Cao's army enters the streets outside Ye's inner gate." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Zhang He", "text": "The inner gate is not Ye's strongest point. It is simply where the heirs trust each other least." },
            { "speaker": "Cao Cao", "text": "Then we press where mistrust must give orders." },
            { "speaker": "Guo Jia", "text": "A siege ladder is useful. A frightened messenger is faster." }
          ]
        }
      ]
    },
    {
      "id": "direct_siege_pressure",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "pressed_ye_siege": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Dun", "text": "The rapid assault has them reinforcing with half-formed companies." },
            { "speaker": "Cao Cao", "text": "Then do not give the other half time to arrive." }
          ]
        }
      ]
    },
    {
      "id": "heirs_split_inside",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "split_yuan_heirs": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Ye Guard", "text": "Yuan Tan's men are refusing the inner gate order. They say Yuan Shang means to abandon them." },
            { "speaker": "Guo Jia", "text": "Good. Every rumor is now doing the work of a ram." }
          ]
        }
      ]
    },
    {
      "id": "turn_3_inner_gate_pressure",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 3 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Yuan Shang Inner Guard", "text": "Hold the gate. If Cao Cao takes the inner road, Ye will hear his drums before ours." },
            { "speaker": "Zhang He", "text": "He is defending the sound of command, not the city." }
          ]
        }
      ]
    },
    {
      "id": "inner_gate_breached",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [10, 4] },
      "actions": [
        {
          "type": "set_objective",
          "victory": "The inner gate is breached. Defeat Yuan Shang's palace defenders.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 15."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "The gate is open. Drive through before the city remembers how to obey." },
            { "speaker": "Guo Jia", "text": "The palace guard is moving. This is the last hard knot." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "ye_palace_guard",
              "name": "Ye Palace Guard",
              "class_id": "guard_captain",
              "team": "enemy",
              "level": 14,
              "pos": [16, 4],
              "base": { "hp": 58, "atk": 18, "def": 14 }
            },
            {
              "unit_id": "ye_palace_rider",
              "name": "Ye Palace Rider",
              "class_id": "cavalry",
              "team": "enemy",
              "level": 14,
              "pos": [16, 5],
              "base": { "hp": 50, "atk": 18, "def": 10, "agi": 12 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_7_city_wavers",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 7 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Zhang He", "text": "Ye's defenders are waiting to see which heir survives the day." },
            { "speaker": "Cao Cao", "text": "Then give them an easier answer." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 2800,
    "items": ["bean", "wine", "imperial_seal"]
  },
  "post_battle_dialogue": [
    { "speaker": "Zhang He", "text": "The inner gate is broken. Ye cannot pretend the Yuan house is whole." },
    { "speaker": "Guo Jia", "text": "One city remains, but the family that held it has become several smaller enemies." },
    { "speaker": "Cao Cao", "text": "Then we choose whether to take the city by force or make the heirs surrender it piece by piece." }
  ],
  "post_battle_choices": [
    {
      "id": "force_ye_surrender",
      "label": "Force Surrender",
      "description": "Cao Cao prepares a final direct pressure on Ye's remaining defenders.",
      "set_flags": { "forced_ye_surrender": true, "negotiated_yuan_defections": false },
      "gold": 150,
      "items": ["war_drum"]
    },
    {
      "id": "negotiate_yuan_defections",
      "label": "Negotiate Defections",
      "description": "The army courts frightened Yuan officers and turns the city's divisions inward.",
      "set_flags": { "forced_ye_surrender": false, "negotiated_yuan_defections": true },
      "gold": 300,
      "items": ["iron_armor"]
    }
  ]
}
