{
  "id": "041_hanzhong_settlement",
  "name": "Hanzhong Settlement",
  "objectives": {
    "victory": "Reach the Hanzhong storehouse with Cao Cao, then defeat the settlement holdouts.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "hanzhong_storehouse_secured" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 18, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Hanzhong Settlement",
    "location": "Hanzhong Basin, Qinling Passes, 215 CE",
    "lines": [
      "Zhang Lu's gate has fallen, but Hanzhong is not settled until its storehouses, passes, and local captains accept Cao Cao's order.",
      "Cao Cao's army moves into the basin to decide whether the mountain province becomes a road east or a fortress held in the west."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "accepted_zhang_lu_submission": true },
        "lines": [
          "Accepting Zhang Lu's submission gives Cao Cao clerks, registers, and surrendered grain stores before the settlement fight begins."
        ]
      },
      {
        "campaign_flags": { "pacified_hanzhong": true },
        "lines": [
          "Pacifying Hanzhong by force breaks open the gates, but scattered mountain captains have sworn to make every storehouse expensive."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "accepted_zhang_lu_submission": true },
        "items": ["imperial_seal"]
      },
      {
        "campaign_flags": { "pacified_hanzhong": 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_ch41",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch41",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch41",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch41",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch41",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch41",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch41",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "ba_river_holdout_captain",
      "name": "Ba River Holdout Captain",
      "class_id": "commander",
      "team": "enemy",
      "level": 38,
      "pos": [14, 4],
      "base": { "hp": 132, "mp": 54, "atk": 39, "def": 31, "int": 31, "agi": 21 }
    },
    {
      "unit_id": "hanzhong_storehouse_guard",
      "name": "Hanzhong Storehouse Guard",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 38,
      "pos": [12, 4],
      "base": { "hp": 108, "atk": 39, "def": 32 }
    },
    {
      "unit_id": "five_peck_champion",
      "name": "Five-Peck Champion",
      "class_id": "champion",
      "team": "enemy",
      "level": 38,
      "pos": [15, 3],
      "base": { "hp": 136, "mp": 12, "atk": 41, "def": 29, "int": 12, "agi": 25 }
    },
    {
      "unit_id": "settlement_ritual_advisor",
      "name": "Settlement Ritual Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 38,
      "pos": [13, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 96, "mp": 80, "atk": 8, "def": 20, "int": 41, "agi": 19 }
    },
    {
      "unit_id": "ba_river_spear_north",
      "name": "Ba River Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 38,
      "pos": [12, 3],
      "base": { "hp": 98, "atk": 39, "def": 29 }
    },
    {
      "unit_id": "ba_river_spear_south",
      "name": "Ba River Spear Guard",
      "class_id": "infantry",
      "team": "enemy",
      "level": 38,
      "pos": [12, 5],
      "base": { "hp": 98, "atk": 39, "def": 29 }
    },
    {
      "unit_id": "hanzhong_basin_marksman",
      "name": "Hanzhong Basin Marksman",
      "class_id": "marksman",
      "team": "enemy",
      "level": 38,
      "pos": [13, 2],
      "base": { "hp": 90, "atk": 40, "def": 16, "agi": 28 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Cao Cao's army enters the Hanzhong basin to settle storehouses, captains, and pass roads after Zhang Lu's gate falls." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Yuan", "text": "The gate is behind us, but every granary ahead has men deciding who they fear more." },
            { "speaker": "Guo Jia", "text": "Then let them choose order before hunger chooses for them." },
            { "speaker": "Cao Cao", "text": "Hanzhong is won when the road feeds us instead of fighting us." }
          ]
        }
      ]
    },
    {
      "id": "submission_opens_registers",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "accepted_zhang_lu_submission": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Guo Jia", "text": "Zhang Lu's clerks have brought the grain registers. The storehouse guards know which way the seal now points." },
            { "speaker": "Cao Cao", "text": "Good. A province that writes its own surrender is already half governed." }
          ]
        }
      ]
    },
    {
      "id": "pacification_stirs_holdouts",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "pacified_hanzhong": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Ba River Holdout Captain", "text": "Cao Cao pacified the gate by force. The basin will answer by force." },
            { "speaker": "Zhang He", "text": "They mistake stubbornness for terrain. We will flatten both." }
          ]
        },
        {
          "type": "spawn_deployment",
          "deployment": {
            "unit_id": "hanzhong_holdout_riders",
            "name": "Hanzhong Holdout Riders",
            "class_id": "cavalry",
            "team": "enemy",
            "level": 38,
            "pos": [16, 3],
            "base": { "hp": 90, "atk": 36, "def": 20, "agi": 26 }
          }
        }
      ]
    },
    {
      "id": "turn_4_storehouse_unrest",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 4 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Settlement Ritual Advisor", "text": "If the grain stays shut, Cao Cao's road through Hanzhong stays hungry." },
            { "speaker": "Guo Jia", "text": "They understand supply. That makes this storehouse more important than the banners around it." }
          ]
        }
      ]
    },
    {
      "id": "hanzhong_storehouse_secured",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [10, 4] },
      "actions": [
        {
          "type": "set_objective",
          "victory": "The Hanzhong storehouse is secured. Defeat the settlement holdout captain.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "This storehouse opens the basin. Hold it, and Hanzhong becomes a road." },
            { "speaker": "Ba River Holdout Captain", "text": "Then the road must be paid for in men." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "storehouse_halberd_guard",
              "name": "Storehouse Halberd Guard",
              "class_id": "guard_captain",
              "team": "enemy",
              "level": 38,
              "pos": [16, 4],
              "base": { "hp": 106, "atk": 39, "def": 32 }
            },
            {
              "unit_id": "storehouse_arrow_screen",
              "name": "Storehouse Arrow Screen",
              "class_id": "archer",
              "team": "enemy",
              "level": 38,
              "pos": [16, 5],
              "base": { "hp": 84, "atk": 38, "def": 13, "agi": 27 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_9_basin_settles",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 9 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Yuan", "text": "The basin is quieting. Even the holdouts are watching the storehouse more than their captain." },
            { "speaker": "Cao Cao", "text": "Then make the storehouse the argument they cannot answer." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 8000,
    "items": ["bean", "wine", "war_drum"]
  },
  "post_battle_dialogue": [
    { "speaker": "Guo Jia", "text": "Hanzhong's storehouses answer to Cao Cao now. The west can be held, or its roads can feed a turn back toward the east." },
    { "speaker": "Xiahou Yuan", "text": "Leave me a strong garrison and Hanzhong will watch the mountain roads. Pull the army east and Ruxu will hear us sooner." },
    { "speaker": "Cao Cao", "text": "A settled province is useful only if we decide what it is for." }
  ],
  "post_battle_choices": [
    {
      "id": "garrison_hanzhong",
      "label": "Garrison Hanzhong",
      "description": "Cao Cao leaves a strong Hanzhong garrison to anchor the western mountain roads.",
      "set_flags": { "garrisoned_hanzhong": true, "pivoted_to_ruxu": false },
      "gold": 1300,
      "items": ["imperial_seal"]
    },
    {
      "id": "pivot_to_ruxu",
      "label": "Pivot to Ruxu",
      "description": "Cao Cao turns the settled Hanzhong roads into supply for an eastern campaign toward Ruxu.",
      "set_flags": { "garrisoned_hanzhong": false, "pivoted_to_ruxu": true },
      "gold": 1100,
      "items": ["war_drum"]
    }
  ]
}
