{
  "id": "025_xinye_advance",
  "name": "Xinye Advance",
  "objectives": {
    "victory": "Reach the Xinye crossing with Cao Cao, then defeat Liu Bei's rearguard.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "xinye_crossing_seized" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 18, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Xinye Advance",
    "location": "Xinye, Jing Province, 208 CE",
    "lines": [
      "With the Yuan name extinguished in the north, Cao Cao turns south toward Jing Province and the roads that guard the Han River.",
      "Liu Bei's rearguard gathers near Xinye, buying time for local officers to decide whether Cao Cao arrives as order or conquest."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "accepted_liaodong_terms": true },
        "lines": [
          "Liaodong's accepted terms let Cao Cao march south with the northern commanderies quiet, making his banners look less like a chase and more like government."
        ]
      },
      {
        "campaign_flags": { "pressed_liaodong_authority": true },
        "lines": [
          "Cao Cao's hard pressure on Liaodong has traveled ahead of him. Jing officers now know delay may be answered by force."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "accepted_liaodong_terms": true },
        "items": ["imperial_seal"]
      },
      {
        "campaign_flags": { "pressed_liaodong_authority": 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_ch25",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch25",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch25",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch25",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch25",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch25",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch25",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "liu_bei_rear_captain",
      "name": "Liu Bei Rear Captain",
      "class_id": "commander",
      "team": "enemy",
      "level": 24,
      "pos": [14, 4],
      "base": { "hp": 104, "mp": 30, "atk": 28, "def": 22, "int": 18, "agi": 16 }
    },
    {
      "unit_id": "xinye_gate_captain",
      "name": "Xinye Gate Captain",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 23,
      "pos": [12, 4],
      "base": { "hp": 78, "atk": 25, "def": 21 }
    },
    {
      "unit_id": "jingzhou_advisor",
      "name": "Jingzhou Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 23,
      "pos": [15, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 66, "mp": 50, "atk": 7, "def": 12, "int": 26, "agi": 13 }
    },
    {
      "unit_id": "xinye_spear_north",
      "name": "Xinye Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 23,
      "pos": [12, 3],
      "base": { "hp": 68, "atk": 25, "def": 18 }
    },
    {
      "unit_id": "xinye_spear_south",
      "name": "Xinye Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 23,
      "pos": [12, 5],
      "base": { "hp": 68, "atk": 25, "def": 18 }
    },
    {
      "unit_id": "xinye_archer_north",
      "name": "Xinye Archer",
      "class_id": "marksman",
      "team": "enemy",
      "level": 23,
      "pos": [13, 2],
      "base": { "hp": 60, "atk": 25, "def": 10, "agi": 18 }
    },
    {
      "unit_id": "xinye_archer_south",
      "name": "Xinye Archer",
      "class_id": "marksman",
      "team": "enemy",
      "level": 23,
      "pos": [14, 6],
      "base": { "hp": 60, "atk": 25, "def": 10, "agi": 18 }
    },
    {
      "unit_id": "xinye_volunteer_rider",
      "name": "Xinye Volunteer Rider",
      "class_id": "elite_cavalry",
      "team": "enemy",
      "level": 23,
      "pos": [15, 3],
      "base": { "hp": 74, "atk": 26, "def": 15, "agi": 19 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Cao Cao's army turns south, and Xinye's rearguard tests the first road into Jing Province." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Guo Jia", "text": "The north is quiet enough to let the south hear us clearly." },
            { "speaker": "Cao Cao", "text": "Then we speak first at Xinye." },
            { "speaker": "Zhang He", "text": "Liu Bei's men are not holding a city. They are buying hours for everyone behind it." }
          ]
        }
      ]
    },
    {
      "id": "liaodong_terms_steady_march",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "accepted_liaodong_terms": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "The northern reports are quiet. The supply clerks are keeping pace with the vanguard." },
            { "speaker": "Cao Cao", "text": "Order behind us makes speed in front of us." }
          ]
        }
      ]
    },
    {
      "id": "authority_reputation_arrives",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "pressed_liaodong_authority": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xinye Gate Captain", "text": "Liaodong bent only after Cao Cao pressed the border. Xinye cannot look weak now." },
            { "speaker": "Xiahou Dun", "text": "Then let them stand tall enough to fall hard." }
          ]
        },
        {
          "type": "spawn_deployment",
          "deployment": {
            "unit_id": "xinye_alarm_rider",
            "name": "Xinye Alarm Rider",
            "class_id": "cavalry",
            "team": "enemy",
            "level": 23,
            "pos": [16, 3],
            "base": { "hp": 64, "atk": 24, "def": 13, "agi": 16 }
          }
        }
      ]
    },
    {
      "id": "turn_4_liubei_withdrawal",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 4 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Liu Bei Rear Captain", "text": "Hold the crossing. Every hour here gives our lord another road south." },
            { "speaker": "Guo Jia", "text": "There it is. They are guarding time, not ground." }
          ]
        }
      ]
    },
    {
      "id": "xinye_crossing_seized",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [10, 4] },
      "actions": [
        {
          "type": "set_objective",
          "victory": "The Xinye crossing is seized. Defeat Liu Bei's rearguard.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "The crossing is ours. Sweep away the rearguard before Xinye becomes a story of resistance." },
            { "speaker": "Liu Bei Rear Captain", "text": "If Xinye falls quickly, Jing Province will hear only Cao Cao's version of courage." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "xinye_crossing_guard",
              "name": "Xinye Crossing Guard",
              "class_id": "guard_captain",
              "team": "enemy",
              "level": 23,
              "pos": [16, 4],
              "base": { "hp": 76, "atk": 25, "def": 20 }
            },
            {
              "unit_id": "xinye_crossing_archer",
              "name": "Xinye Crossing Archer",
              "class_id": "archer",
              "team": "enemy",
              "level": 23,
              "pos": [16, 5],
              "base": { "hp": 54, "atk": 23, "def": 8, "agi": 16 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_9_xinye_pressure",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 9 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Zhang He", "text": "Their line is thinning toward the south road." },
            { "speaker": "Cao Cao", "text": "Then make the south road carry our shadow too." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 4800,
    "items": ["bean", "wine", "war_drum"]
  },
  "post_battle_dialogue": [
    { "speaker": "Guo Jia", "text": "Xinye is open, but Liu Bei's retreat will turn every village road into a delay if we let it breathe." },
    { "speaker": "Zhang He", "text": "The Han River routes matter now. A quick spear may reach farther than a careful wagon." },
    { "speaker": "Cao Cao", "text": "Then decide whether we press Xinye at once or secure the Han River supply line first." }
  ],
  "post_battle_choices": [
    {
      "id": "press_xinye_vanguard",
      "label": "Press Xinye",
      "description": "Cao Cao drives the vanguard forward before Liu Bei can settle a new rearguard.",
      "set_flags": { "pressed_xinye_vanguard": true, "secured_han_river_supply": false },
      "gold": 450,
      "items": ["war_drum"]
    },
    {
      "id": "secure_han_river_supply",
      "label": "Secure Supply",
      "description": "The army steadies the Han River supply road before chasing deeper into Jing Province.",
      "set_flags": { "pressed_xinye_vanguard": false, "secured_han_river_supply": true },
      "gold": 750,
      "items": ["imperial_seal"]
    }
  ]
}
