{
  "id": "039_hanzhong_approach",
  "name": "Hanzhong Approach",
  "objectives": {
    "victory": "Reach the Hanzhong approach with Cao Cao, then defeat Zhang Lu's border guard.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "hanzhong_approach_reached" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 18, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Hanzhong Approach",
    "location": "Hanzhong Approach, Qinling Passes, 215 CE",
    "lines": [
      "With Ma Chao's retreat broken, Cao Cao turns from Guanzhong's roads toward Hanzhong's mountain gates.",
      "Zhang Lu's border guard watches the passes, where supply, faith, and narrow stone roads can slow even a victorious army."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "pacified_guanzhong": true },
        "lines": [
          "Pacified Guanzhong gives Cao Cao a quiet rear and fuller supply trains before the mountain approach."
        ]
      },
      {
        "campaign_flags": { "prepared_hanzhong_front": true },
        "lines": [
          "Preparations for Hanzhong put Cao Cao's vanguard in motion early, but Zhang Lu's border scouts have already lit the pass beacons."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "pacified_guanzhong": true },
        "items": ["imperial_seal"]
      },
      {
        "campaign_flags": { "prepared_hanzhong_front": 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_ch39",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch39",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch39",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch39",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch39",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch39",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch39",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "zhang_lu_border_guard",
      "name": "Zhang Lu Border Guard",
      "class_id": "commander",
      "team": "enemy",
      "level": 36,
      "pos": [14, 4],
      "base": { "hp": 126, "mp": 50, "atk": 37, "def": 29, "int": 30, "agi": 20 }
    },
    {
      "unit_id": "hanzhong_pass_champion",
      "name": "Hanzhong Pass Champion",
      "class_id": "champion",
      "team": "enemy",
      "level": 36,
      "pos": [15, 3],
      "base": { "hp": 130, "mp": 12, "atk": 39, "def": 27, "int": 12, "agi": 24 }
    },
    {
      "unit_id": "mountain_gate_captain",
      "name": "Mountain Gate Captain",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 36,
      "pos": [12, 4],
      "base": { "hp": 104, "atk": 37, "def": 30 }
    },
    {
      "unit_id": "hanzhong_ritual_advisor",
      "name": "Hanzhong Ritual Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 36,
      "pos": [13, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 92, "mp": 76, "atk": 8, "def": 18, "int": 39, "agi": 18 }
    },
    {
      "unit_id": "hanzhong_spear_north",
      "name": "Hanzhong Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 36,
      "pos": [12, 3],
      "base": { "hp": 94, "atk": 37, "def": 27 }
    },
    {
      "unit_id": "hanzhong_spear_south",
      "name": "Hanzhong Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 36,
      "pos": [12, 5],
      "base": { "hp": 94, "atk": 37, "def": 27 }
    },
    {
      "unit_id": "hanzhong_pass_marksman",
      "name": "Hanzhong Pass Marksman",
      "class_id": "marksman",
      "team": "enemy",
      "level": 36,
      "pos": [13, 2],
      "base": { "hp": 86, "atk": 38, "def": 14, "agi": 27 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Cao Cao's army approaches Hanzhong's mountain gates as Zhang Lu's border guard blocks the pass road." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Yuan", "text": "The road climbs quickly. Hanzhong will not fight like Guanzhong." },
            { "speaker": "Guo Jia", "text": "Mountains make small armies feel large and large armies feel slow." },
            { "speaker": "Cao Cao", "text": "Then we move before the mountain teaches them confidence." }
          ]
        }
      ]
    },
    {
      "id": "pacified_guanzhong_feeds_pass_column",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "pacified_guanzhong": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "Guanzhong is quiet enough to keep the pass column supplied." },
            { "speaker": "Cao Cao", "text": "A quiet rear lets a narrow road feel wider." }
          ]
        }
      ]
    },
    {
      "id": "prepared_hanzhong_front_lights_beacons",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "prepared_hanzhong_front": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Zhang Lu Border Guard", "text": "Cao Cao prepared for Hanzhong early. Light every pass beacon and make speed cost him." },
            { "speaker": "Zhang He", "text": "The pass is awake. We will have to cut through before it gathers." }
          ]
        },
        {
          "type": "spawn_deployment",
          "deployment": {
            "unit_id": "hanzhong_beacon_riders",
            "name": "Hanzhong Beacon Riders",
            "class_id": "cavalry",
            "team": "enemy",
            "level": 36,
            "pos": [16, 3],
            "base": { "hp": 86, "atk": 34, "def": 18, "agi": 24 }
          }
        }
      ]
    },
    {
      "id": "turn_4_pass_rituals",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 4 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Hanzhong Ritual Advisor", "text": "Hold the gates. Let the invaders learn how slowly a mountain opens." },
            { "speaker": "Guo Jia", "text": "They want delay to become belief. We cannot give them time." }
          ]
        }
      ]
    },
    {
      "id": "hanzhong_approach_reached",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [10, 4] },
      "actions": [
        {
          "type": "set_objective",
          "victory": "The Hanzhong approach is reached. Defeat Zhang Lu's border guard.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "This is the approach. Break the border guard before Hanzhong closes its gates." },
            { "speaker": "Zhang Lu Border Guard", "text": "The gate is not yours because you can see it." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "hanzhong_gate_halberd",
              "name": "Hanzhong Gate Halberd",
              "class_id": "guard_captain",
              "team": "enemy",
              "level": 36,
              "pos": [16, 4],
              "base": { "hp": 102, "atk": 37, "def": 30 }
            },
            {
              "unit_id": "hanzhong_gate_archer",
              "name": "Hanzhong Gate Archer",
              "class_id": "archer",
              "team": "enemy",
              "level": 36,
              "pos": [16, 5],
              "base": { "hp": 80, "atk": 36, "def": 12, "agi": 25 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_9_gate_in_sight",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 9 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Yuan", "text": "The gate road is in sight. Their border guard is running out of pass to hide behind." },
            { "speaker": "Cao Cao", "text": "Then make Hanzhong hear us before we knock." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 7600,
    "items": ["bean", "wine", "war_drum"]
  },
  "post_battle_dialogue": [
    { "speaker": "Guo Jia", "text": "The Hanzhong approach is open. Zhang Lu must now decide whether his gates are walls or bargaining tables." },
    { "speaker": "Xiahou Yuan", "text": "We can secure the approach and bring up supplies, or press the gate before Zhang Lu's priests steady the defenders." },
    { "speaker": "Cao Cao", "text": "Hanzhong can be opened by patience or shock. Choose the first argument." }
  ],
  "post_battle_choices": [
    {
      "id": "secure_hanzhong_approach",
      "label": "Secure Approach",
      "description": "Cao Cao secures the Hanzhong approach so the mountain column can advance safely.",
      "set_flags": { "secured_hanzhong_approach": true, "pressed_zhang_lu_gate": false },
      "gold": 1200,
      "items": ["imperial_seal"]
    },
    {
      "id": "press_zhang_lu_gate",
      "label": "Press Gate",
      "description": "Cao Cao presses Zhang Lu's gate before the Hanzhong defense can settle.",
      "set_flags": { "secured_hanzhong_approach": false, "pressed_zhang_lu_gate": true },
      "gold": 1000,
      "items": ["war_drum"]
    }
  ]
}
