{
  "id": "033_tong_pass_vanguard",
  "name": "Tong Pass Vanguard",
  "objectives": {
    "victory": "Reach the Tong Pass outpost with Cao Cao, then defeat Ma Chao's vanguard.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "tong_pass_outpost_reached" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 18, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Tong Pass Vanguard",
    "location": "Tong Pass, Guanzhong, 211 CE",
    "lines": [
      "The southern retreat has settled enough for Cao Cao to look west, where Guanzhong's passes harden around Ma Chao and Han Sui.",
      "A vanguard moves toward Tong Pass, testing whether the army that survived Red Cliffs can still seize the initiative."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "stabilized_jiangling_rearguard": true },
        "lines": [
          "Jiangling's stabilized rearguard gives Cao Cao a firmer supply base before the western march begins."
        ]
      },
      {
        "campaign_flags": { "mobilized_tong_pass_vanguard": true },
        "lines": [
          "The early western mobilization reaches Tong Pass quickly, but Ma Chao's scouts are already riding to meet it."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "stabilized_jiangling_rearguard": true },
        "items": ["imperial_seal"]
      },
      {
        "campaign_flags": { "mobilized_tong_pass_vanguard": 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_ch33",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch33",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch33",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch33",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch33",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch33",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch33",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "ma_chao_vanguard",
      "name": "Ma Chao Vanguard",
      "class_id": "elite_cavalry",
      "team": "enemy",
      "level": 31,
      "pos": [14, 4],
      "base": { "hp": 122, "mp": 12, "atk": 35, "def": 24, "int": 13, "agi": 25 }
    },
    {
      "unit_id": "han_sui_envoy_guard",
      "name": "Han Sui Envoy Guard",
      "class_id": "commander",
      "team": "enemy",
      "level": 30,
      "pos": [15, 5],
      "base": { "hp": 114, "mp": 40, "atk": 32, "def": 25, "int": 24, "agi": 18 }
    },
    {
      "unit_id": "tong_pass_gate_captain",
      "name": "Tong Pass Gate Captain",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 30,
      "pos": [12, 4],
      "base": { "hp": 92, "atk": 31, "def": 25 }
    },
    {
      "unit_id": "western_tactic_advisor",
      "name": "Western Tactic Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 30,
      "pos": [15, 3],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 80, "mp": 64, "atk": 8, "def": 15, "int": 33, "agi": 16 }
    },
    {
      "unit_id": "tong_pass_spear_north",
      "name": "Tong Pass Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 30,
      "pos": [12, 3],
      "base": { "hp": 82, "atk": 31, "def": 22 }
    },
    {
      "unit_id": "tong_pass_spear_south",
      "name": "Tong Pass Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 30,
      "pos": [12, 5],
      "base": { "hp": 82, "atk": 31, "def": 22 }
    },
    {
      "unit_id": "western_marksman_north",
      "name": "Western Marksman",
      "class_id": "marksman",
      "team": "enemy",
      "level": 30,
      "pos": [13, 2],
      "base": { "hp": 74, "atk": 32, "def": 12, "agi": 24 }
    },
    {
      "unit_id": "western_marksman_south",
      "name": "Western Marksman",
      "class_id": "marksman",
      "team": "enemy",
      "level": 30,
      "pos": [14, 6],
      "base": { "hp": 74, "atk": 32, "def": 12, "agi": 24 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Cao Cao's vanguard reaches Tong Pass as Ma Chao's riders test the western road." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Yuan", "text": "The western riders move like the road belongs to them." },
            { "speaker": "Guo Jia", "text": "At Tong Pass, every hill believes it owns the army below." },
            { "speaker": "Cao Cao", "text": "Then teach the pass whose banners decide the road." }
          ]
        }
      ]
    },
    {
      "id": "jiangling_stability_supplies",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "stabilized_jiangling_rearguard": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "Jiangling's rear supply wagons have reached the column. The men know the south is not unraveling behind them." },
            { "speaker": "Cao Cao", "text": "A steady rear lets the front strike harder." }
          ]
        }
      ]
    },
    {
      "id": "early_western_mobilization_meets_scouts",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "mobilized_tong_pass_vanguard": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Ma Chao Vanguard", "text": "Cao Cao sent his western column early. Good. We will break the spear before the shaft arrives." },
            { "speaker": "Zhang He", "text": "Fast riders, hard ground. The first clash will decide their confidence." }
          ]
        },
        {
          "type": "spawn_deployment",
          "deployment": {
            "unit_id": "ma_clan_scout_van",
            "name": "Ma Clan Scout Van",
            "class_id": "cavalry",
            "team": "enemy",
            "level": 30,
            "pos": [16, 3],
            "base": { "hp": 78, "atk": 30, "def": 16, "agi": 21 }
          }
        }
      ]
    },
    {
      "id": "turn_4_pass_closes",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 4 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Han Sui Envoy Guard", "text": "Hold the pass mouth. Cao Cao's army is strongest when it chooses the field." },
            { "speaker": "Guo Jia", "text": "They know enough to deny us shape. We must take it." }
          ]
        }
      ]
    },
    {
      "id": "tong_pass_outpost_reached",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [10, 4] },
      "actions": [
        {
          "type": "set_objective",
          "victory": "The Tong Pass outpost is reached. Defeat Ma Chao's vanguard.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "This outpost opens the pass road. Break their vanguard before the western army gathers." },
            { "speaker": "Ma Chao Vanguard", "text": "Tong Pass is not yours because your horse reached it. Come take the road." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "tong_pass_halberd_guard",
              "name": "Tong Pass Halberd Guard",
              "class_id": "guard_captain",
              "team": "enemy",
              "level": 30,
              "pos": [16, 4],
              "base": { "hp": 90, "atk": 31, "def": 25 }
            },
            {
              "unit_id": "western_arrow_screen",
              "name": "Western Arrow Screen",
              "class_id": "archer",
              "team": "enemy",
              "level": 30,
              "pos": [16, 5],
              "base": { "hp": 68, "atk": 30, "def": 10, "agi": 22 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_9_pass_dust",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 9 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Yuan", "text": "Dust is rising beyond the pass. More riders are coming." },
            { "speaker": "Cao Cao", "text": "Then finish the vanguard before dust becomes an army." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 6400,
    "items": ["bean", "wine", "war_drum"]
  },
  "post_battle_dialogue": [
    { "speaker": "Guo Jia", "text": "The outpost is ours, but Ma Chao's riders yielded ground without yielding pride." },
    { "speaker": "Xiahou Yuan", "text": "We can fortify Tong Pass and force them to spend themselves, or press before their alliance settles." },
    { "speaker": "Cao Cao", "text": "Choose whether this pass becomes our shield or our spear." }
  ],
  "post_battle_choices": [
    {
      "id": "fortify_tong_pass",
      "label": "Fortify Pass",
      "description": "Cao Cao fortifies Tong Pass, preparing to absorb Ma Chao's counterstroke.",
      "set_flags": { "fortified_tong_pass": true, "pressed_ma_chao_vanguard": false },
      "gold": 950,
      "items": ["imperial_seal"]
    },
    {
      "id": "press_ma_chao_vanguard",
      "label": "Press Ma Chao",
      "description": "Cao Cao presses Ma Chao's vanguard before the western alliance can fully gather.",
      "set_flags": { "fortified_tong_pass": false, "pressed_ma_chao_vanguard": true },
      "gold": 700,
      "items": ["war_drum"]
    }
  ]
}
