{
  "id": "003_xingyang_ambush",
  "name": "Xingyang Ambush",
  "objectives": {
    "victory": "Defeat Xu Rong's rearguard.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 11."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "turn_3_ambush" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 11, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Xingyang Ambush",
    "location": "Xingyang, 190 CE",
    "lines": [
      "Dong Zhuo abandons Luoyang and retreats west.",
      "Cao Cao's vanguard turns toward the enemy rearguard near Xingyang.",
      "The road narrows ahead. Keep the vanguard together and watch the forest line."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "pursued_dong_zhuo": true },
        "lines": [
          "The rapid pursuit leaves little time for scouting, but may catch Xu Rong before he regroups."
        ]
      },
      {
        "campaign_flags": { "regrouped_after_sishui": true },
        "lines": [
          "Scouts from Sishui report suspicious movement in the trees. Expect an ambush and prepare accordingly."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "antidote",
      "panacea",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "pursued_dong_zhuo": true },
        "items": ["hand_axe"]
      },
      {
        "campaign_flags": { "regrouped_after_sishui": true },
        "items": ["leather_armor"]
      }
    ]
  },
  "roster": {
    "max_units": 3,
    "required_officers": ["cao_cao"]
  },
  "formation": {
    "cells": [[1, 3], [1, 4], [1, 5], [2, 3], [2, 4], [2, 5]]
  },
  "map": {
    "width": 12,
    "height": 9,
    "terrain": [
      "GGGFFRRGGGGG",
      "GGGFFRRGHHGG",
      "GGGGGRRGHHGG",
      "RRRRRRRRRRRR",
      "GGGGFRRFGGGG",
      "GGGHFRRFGGGG",
      "GGGHHRRGFFGG",
      "GGGGGRRGFFGG",
      "GGWWGRRGGGGG"
    ]
  },
  "deployments": [
    {
      "unit_id": "cao_cao_ch3",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "xiahou_dun_ch3",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch3",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "cao_ren_ch3",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xu_rong_rearguard",
      "name": "Xu Rong Rearguard",
      "class_id": "cavalry",
      "team": "enemy",
      "level": 3,
      "pos": [9, 4],
      "base": { "hp": 46, "atk": 15, "def": 8 }
    },
    {
      "unit_id": "liang_spearman",
      "name": "Liang Spearman",
      "class_id": "infantry",
      "team": "enemy",
      "level": 3,
      "pos": [7, 3],
      "base": { "hp": 36, "atk": 12, "def": 7 }
    },
    {
      "unit_id": "liang_strategist",
      "name": "Liang Strategist",
      "class_id": "strategist",
      "team": "enemy",
      "level": 3,
      "pos": [8, 5],
      "base": { "hp": 30, "mp": 14, "atk": 7, "def": 4, "int": 10 }
    },
    {
      "unit_id": "rearguard_archer",
      "name": "Rearguard Archer",
      "class_id": "archer",
      "team": "enemy",
      "level": 3,
      "pos": [8, 2],
      "base": { "hp": 30, "atk": 11, "def": 5 }
    }
  ],
  "events": [
    {
      "id": "opening_pursuit",
      "once": true,
      "when": { "type": "battle_start", "campaign_flags": { "pursued_dong_zhuo": true } },
      "actions": [
        { "type": "log", "text": "Cao Cao's rapid pursuit closes on Dong Zhuo's rearguard." }
      ]
    },
    {
      "id": "opening_regroup",
      "once": true,
      "when": { "type": "battle_start", "campaign_flags": { "regrouped_after_sishui": true } },
      "actions": [
        { "type": "log", "text": "Cao Cao advances after gathering scouts and supplies at Sishui." }
      ]
    },
    {
      "id": "opening_dialogue_pursuit",
      "once": true,
      "when": { "type": "battle_begin", "campaign_flags": { "pursued_dong_zhuo": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "The coalition hesitates while Dong Zhuo escapes. We will not let this chance pass." },
            { "speaker": "Xiahou Dun", "text": "The road is too quiet. If they mean to spring a trap, let them try it." },
            { "speaker": "Xiahou Yuan", "text": "I will watch the ridges. Their bowmen will favor the high ground." }
          ]
        }
      ]
    },
    {
      "id": "opening_dialogue_regroup",
      "once": true,
      "when": { "type": "battle_begin", "campaign_flags": { "regrouped_after_sishui": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "The delay at Sishui bought us scouts and fresh supplies. Now we move with clear eyes." },
            { "speaker": "Cao Ren", "text": "Our riders report movement in the forest line. Xu Rong may be waiting ahead." },
            { "speaker": "Xiahou Yuan", "text": "Then we draw them out and break their trap before it closes." }
          ]
        }
      ]
    },
    {
      "id": "turn_3_ambush",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 3 },
      "actions": [
        { "type": "log", "text": "The forest line shifts as Xu Rong's ambush springs." }
      ]
    },
    {
      "id": "turn_3_ambush_pursuit",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 3, "campaign_flags": { "pursued_dong_zhuo": true } },
      "actions": [
        { "type": "log", "text": "Xu Rong's ambush force closes in from the forest." },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xu Rong", "text": "Cao Cao took the bait. Seal the road and cut down his vanguard." },
            { "speaker": "Cao Cao", "text": "So this was their plan. Hold formation and break through!" }
          ]
        },
        {
          "type": "set_objective",
          "victory": "Defeat Xu Rong and every ambush unit.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 11."
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "ambush_bandit_1",
              "name": "Ambush Raider",
              "class_id": "bandit",
              "team": "enemy",
              "level": 3,
              "pos": [5, 1],
              "base": { "hp": 34, "atk": 12, "def": 5 }
            },
            {
              "unit_id": "ambush_bandit_2",
              "name": "Ambush Raider",
              "class_id": "bandit",
              "team": "enemy",
              "level": 3,
              "pos": [5, 7],
              "base": { "hp": 34, "atk": 12, "def": 5 }
            },
            {
              "unit_id": "ambush_archer",
              "name": "Ambush Archer",
              "class_id": "archer",
              "team": "enemy",
              "level": 3,
              "pos": [10, 6],
              "base": { "hp": 28, "atk": 11, "def": 4 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_3_ambush_regroup",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 3, "campaign_flags": { "regrouped_after_sishui": true } },
      "actions": [
        { "type": "log", "text": "Scouts expose Xu Rong's ambush before the trap fully closes." },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xu Rong", "text": "They found our screen too soon. Attack before Cao Cao can withdraw!" },
            { "speaker": "Cao Cao", "text": "Their trap is revealed. Strike the exposed units and keep the road open." }
          ]
        },
        {
          "type": "set_objective",
          "victory": "Defeat Xu Rong and the exposed ambush units.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 11."
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "ambush_bandit_scouted",
              "name": "Exposed Raider",
              "class_id": "bandit",
              "team": "enemy",
              "level": 3,
              "pos": [5, 1],
              "base": { "hp": 32, "atk": 11, "def": 5 }
            },
            {
              "unit_id": "ambush_archer_scouted",
              "name": "Exposed Archer",
              "class_id": "archer",
              "team": "enemy",
              "level": 3,
              "pos": [10, 6],
              "base": { "hp": 26, "atk": 10, "def": 4 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_5_pressure",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 5, "campaign_flags": { "pursued_dong_zhuo": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Yuan", "text": "Their line is stretched. Push through the road before they regroup." }
          ]
        }
      ]
    },
    {
      "id": "turn_5_regroup_pressure",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 5, "campaign_flags": { "regrouped_after_sishui": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "Their hidden troops are fewer than expected. The scouts earned their pay." },
            { "speaker": "Cao Cao", "text": "Good. Keep the pressure on Xu Rong before he reforms the line." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 700,
    "items": ["bean", "wine", "iron_sword"]
  },
  "post_battle_dialogue": [
    { "speaker": "Cao Cao", "text": "Xu Rong's trap failed, but Dong Zhuo has bought himself time." },
    { "speaker": "Xiahou Dun", "text": "Then we sharpen the army and wait for the next opening." }
  ]
}
