{
  "id": "063_hainan_coast",
  "name": "Hainan Coast",
  "objectives": {
    "victory": "Reach the Hainan coast marker with Cao Cao, then defeat the coast captain.",
    "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
  },
  "conditions": {
    "victory": { "type": "all_units_defeated", "team": "enemy", "after_event": "hainan_coast_marker_reached" },
    "defeat": [
      { "type": "any_officer_defeated", "team": "player", "officer_ids": ["cao_cao"] },
      { "type": "turn_reached", "turn": 18, "team": "player" }
    ]
  },
  "briefing": {
    "title": "Hainan Coast",
    "location": "Hainan Coast Road, Southern Sea, Eastern Front, 220 CE",
    "lines": [
      "The southern fleet anchorage has broken, but fleeing captains still use the Hainan coast to gather boats, records, and loyal guards.",
      "Cao Cao advances along the coast road to decide whether Hainan is secured under Wei order or the last harbor is pressed before the captains regroup."
    ],
    "conditional_lines": [
      {
        "campaign_flags": { "secured_southern_fleet": true },
        "lines": [
          "Securing the southern fleet gives Wei captured pilots and shore charts, narrowing the Hainan coast to a marked road and known coves."
        ]
      },
      {
        "campaign_flags": { "pressed_hainan_coast": true },
        "lines": [
          "Pressing Hainan early has scattered the captains across the coast, but they now fight with every remaining boat pulled close to shore."
        ]
      }
    ]
  },
  "shop": {
    "items": [
      "bean",
      "wine",
      "iron_sword",
      "training_spear",
      "short_bow",
      "hand_axe",
      "war_axe",
      "leather_armor",
      "iron_armor"
    ],
    "conditional_items": [
      {
        "campaign_flags": { "secured_southern_fleet": true },
        "items": ["imperial_seal"]
      },
      {
        "campaign_flags": { "pressed_hainan_coast": 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": [
      "WWWWWWWWWWWWWWWWWW",
      "WGGGFFWWRRWWFFGGGW",
      "GGGGWWGGGGRRGGGGGG",
      "GGFFWWGGRRRRGFFGGG",
      "RRRRRRRRRRRRRRRRRR",
      "GGFFWWGGRRRRGFFGGG",
      "GGGGWWGGGGRRGGGGGG",
      "GHHHWWGFFFGGFFFGGG",
      "GHHHWWGGGGHHHGGGGG",
      "GGGGWWGGGGHHHFFGGG",
      "WWWWWWWWWWWWWWWWWW"
    ]
  },
  "deployments": [
    {
      "unit_id": "cao_cao_ch63",
      "officer_id": "cao_cao",
      "team": "player",
      "pos": [1, 4]
    },
    {
      "unit_id": "guo_jia_ch63",
      "officer_id": "guo_jia",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 4]
    },
    {
      "unit_id": "zhang_he_ch63",
      "officer_id": "zhang_he",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 3]
    },
    {
      "unit_id": "xiahou_dun_ch63",
      "officer_id": "xiahou_dun",
      "team": "player",
      "pos": [1, 5]
    },
    {
      "unit_id": "dian_wei_ch63",
      "officer_id": "dian_wei",
      "team": "player",
      "requires_joined": true,
      "pos": [2, 5]
    },
    {
      "unit_id": "xiahou_yuan_ch63",
      "officer_id": "xiahou_yuan",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 3]
    },
    {
      "unit_id": "cao_ren_ch63",
      "officer_id": "cao_ren",
      "team": "player",
      "requires_joined": true,
      "pos": [3, 4]
    },
    {
      "unit_id": "hainan_coast_captain",
      "name": "Hainan Coast Captain",
      "class_id": "commander",
      "team": "enemy",
      "level": 60,
      "pos": [14, 4],
      "base": { "hp": 206, "mp": 100, "atk": 63, "def": 54, "int": 52, "agi": 39 }
    },
    {
      "unit_id": "hainan_shore_guard",
      "name": "Hainan Shore Guard",
      "class_id": "guard_captain",
      "team": "enemy",
      "level": 60,
      "pos": [12, 4],
      "base": { "hp": 154, "atk": 62, "def": 55 }
    },
    {
      "unit_id": "hainan_coast_boat",
      "name": "Hainan Coast Boat",
      "class_id": "champion",
      "team": "enemy",
      "move_type": "water",
      "level": 60,
      "pos": [4, 3],
      "base": { "hp": 182, "mp": 12, "atk": 64, "def": 50, "int": 16, "agi": 46 }
    },
    {
      "unit_id": "hainan_coast_advisor",
      "name": "Hainan Coast Advisor",
      "class_id": "military_advisor",
      "team": "enemy",
      "level": 60,
      "pos": [13, 5],
      "skills": ["blaze", "great_mend"],
      "base": { "hp": 140, "mp": 124, "atk": 8, "def": 41, "int": 63, "agi": 36 }
    },
    {
      "unit_id": "hainan_spear_north",
      "name": "Hainan Spear",
      "class_id": "infantry",
      "team": "enemy",
      "level": 60,
      "pos": [12, 3],
      "base": { "hp": 142, "atk": 61, "def": 51 }
    },
    {
      "unit_id": "hainan_spear_south",
      "name": "Hainan Spear",
      "class_id": "infantry",
      "team": "enemy",
      "level": 60,
      "pos": [12, 5],
      "base": { "hp": 142, "atk": 61, "def": 51 }
    },
    {
      "unit_id": "hainan_arrow_boat",
      "name": "Hainan Arrow Boat",
      "class_id": "marksman",
      "team": "enemy",
      "move_type": "water",
      "level": 60,
      "pos": [5, 5],
      "base": { "hp": 134, "atk": 62, "def": 37, "agi": 49 }
    }
  ],
  "events": [
    {
      "id": "opening",
      "once": true,
      "when": { "type": "battle_start" },
      "actions": [
        { "type": "log", "text": "Wei advances onto the Hainan coast to break the last southern shore road." }
      ]
    },
    {
      "id": "opening_dialogue",
      "once": true,
      "when": { "type": "battle_begin" },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Ren", "text": "The coast road is narrow, but the shore markers lead straight to their captain." },
            { "speaker": "Guo Jia", "text": "A coast is a wall for men without boats, and a door for men who still have them." },
            { "speaker": "Cao Cao", "text": "Then close the door and take the wall." }
          ]
        }
      ]
    },
    {
      "id": "secured_fleet_guides_hainan_advance",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 2, "campaign_flags": { "secured_southern_fleet": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Xiahou Yuan", "text": "The captured fleet pilots marked every cove. Their coast road has nowhere to vanish." },
            { "speaker": "Cao Cao", "text": "A pilot who chooses Wei turns the sea into a road. Advance." }
          ]
        }
      ]
    },
    {
      "id": "pressed_hainan_commits_cove_boat",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 2, "campaign_flags": { "pressed_hainan_coast": true } },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Hainan Coast Captain", "text": "Wei pressed us to the coast. Send the cove boat forward and keep the harbor path open." },
            { "speaker": "Dian Wei", "text": "They call it a harbor path. Sounds like a road for men already thinking of running." }
          ]
        },
        {
          "type": "spawn_deployment",
          "deployment": {
            "unit_id": "hainan_cove_boat",
            "name": "Hainan Cove Boat",
            "class_id": "champion",
            "team": "enemy",
            "move_type": "water",
            "level": 60,
            "pos": [5, 3],
            "base": { "hp": 132, "atk": 57, "def": 41, "agi": 47 }
          }
        }
      ]
    },
    {
      "id": "turn_4_coast_captain_holds_marker",
      "once": true,
      "when": { "type": "turn_start", "team": "enemy", "turn": 4 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Hainan Coast Advisor", "text": "Hold the coast marker. If Wei takes it, the last harbor will know no road remains." },
            { "speaker": "Guo Jia", "text": "They are already thinking beyond this shore. Good. That means this shore is ours to take." }
          ]
        }
      ]
    },
    {
      "id": "hainan_coast_marker_reached",
      "once": true,
      "when": { "type": "unit_reaches_tile", "team": "player", "officer_ids": ["cao_cao"], "pos": [10, 4] },
      "actions": [
        {
          "type": "set_objective",
          "victory": "The Hainan coast marker is reached. Defeat the coast captain.",
          "defeat": "Cao Cao is defeated or the battle reaches Turn 18."
        },
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Cao Cao", "text": "This coast no longer hides Wu's captains. Let the last harbor hear it." },
            { "speaker": "Hainan Coast Captain", "text": "A coast may fall, but the harbor beyond it can still refuse." }
          ]
        },
        {
          "type": "spawn_deployments",
          "deployments": [
            {
              "unit_id": "hainan_coast_last_guard",
              "name": "Hainan Coast Last Guard",
              "class_id": "guard_captain",
              "team": "enemy",
              "level": 60,
              "pos": [16, 4],
              "base": { "hp": 150, "atk": 61, "def": 54 }
            },
            {
              "unit_id": "hainan_crossbow_boat",
              "name": "Hainan Crossbow Boat",
              "class_id": "marksman",
              "team": "enemy",
              "move_type": "water",
              "level": 60,
              "pos": [10, 1],
              "base": { "hp": 126, "atk": 60, "def": 34, "agi": 48 }
            }
          ]
        }
      ]
    },
    {
      "id": "turn_9_coast_line_breaks",
      "once": true,
      "when": { "type": "turn_start", "team": "player", "turn": 9 },
      "actions": [
        {
          "type": "dialogue",
          "lines": [
            { "speaker": "Zhang He", "text": "Their coast line is breaking. The boats still hold the water, but the men on shore have lost the road." },
            { "speaker": "Cao Cao", "text": "Then take the shore from them and let the water carry only surrender." }
          ]
        }
      ]
    }
  ],
  "rewards": {
    "gold": 12400,
    "items": ["bean", "wine", "war_axe"]
  },
  "post_battle_dialogue": [
    { "speaker": "Guo Jia", "text": "The Hainan coast is broken. Wei can secure the coast and receive the remaining captains, or press the final harbor before their refusal finds another tide." },
    { "speaker": "Cao Ren", "text": "Securing the coast ends the shore road. Pressing the final harbor ends the next hiding place." },
    { "speaker": "Cao Cao", "text": "A coast is only safe when the harbor beyond it knows who commands the sea." }
  ],
  "post_battle_choices": [
    {
      "id": "secure_hainan_coast",
      "label": "Secure Coast",
      "description": "Cao Cao secures the Hainan coast and prepares to receive the remaining captains.",
      "set_flags": { "secured_hainan_coast": true, "pressed_final_harbor": false },
      "gold": 2400,
      "items": ["imperial_seal"]
    },
    {
      "id": "press_final_harbor",
      "label": "Press Harbor",
      "description": "Cao Cao presses the final harbor before the remaining captains can regroup.",
      "set_flags": { "secured_hainan_coast": false, "pressed_final_harbor": true },
      "gold": 2200,
      "items": ["war_drum"]
    }
  ]
}
