Reference
  Area\Util.txt
  Util\Audio.txt
  Util\Party.txt
  Util\CommonDialog.txt
End Reference

Procedure Main(startAt)

  Dim ac = Nothing

  RegisterCommonEventHandlers()
  AddAreaZone(AddZone("B1", 0, 0, 0, 31, 31, 100), 1)
  AddAreaZone(AddZone("B2", 32, 0, 0, 63, 31, 100), 1)
  AddAreaZone(AddZone("B3", 64, 0, 0, 95, 31, 100), 1)
  AddAreaZone(AddZone("B4", 96, 0, 0, 127, 31, 100), 1)
  AddAreaZone(AddZone("B5", 0, 32, 0, 31, 63, 100), 1)
  AddAreaZone(AddZone("B6", 32, 32, 0, 63, 63, 100), 1)
  AddAreaZone(AddZone("B7", 64, 32, 0, 95, 63, 100), 1)
  AddAreaZone(AddZone("B8", 96, 32, 0, 127, 63, 100), 1)
  AddAreaZone(AddZone("B9", 0, 64, 0, 31, 95, 100), 1)
  AddAreaZone(AddZone("B10", 32, 64, 0, 63, 95, 100), 1)

  AddZone("ExitArea", 15, 31, 0, 16, 31, 0)
  RegisterEventHandler("ExitAreaEnter", ExitArea_Enter)
  AddZone("Entrance", 15, 30, 0)

  'B1
  AddZone("B1_DS1", 3, 3, 0)
  RegisterEventHandler("B1_DS1Enter", B1_DS1_Enter)
  AddZone("B1_DS2", 28, 20, 0)
  RegisterEventHandler("B1_DS2Enter", B1_DS2_Enter)

  'B2
  AddZone("B2_US1", 35, 3, 0)
  RegisterEventHandler("B2_US1Enter", B2_US1_Enter)
  AddZone("B2_US2", 60, 20, 0)
  RegisterEventHandler("B2_US2Enter", B2_US2_Enter)
  AddZone("B2_DS1", 48, 14, 0)
  RegisterEventHandler("B2_DS1Enter", B2_DS1_Enter)
  AddZone("B2_DS2", 41, 26, 0)
  RegisterEventHandler("B2_DS2Enter", B2_DS2_Enter)

  'B3
  AddZone("B3_US1", 80, 14, 0)
  RegisterEventHandler("B3_US1Enter", B3_US1_Enter)
  AddZone("B3_US2", 73, 26, 0)
  RegisterEventHandler("B3_US2Enter", B3_US2_Enter)
  AddZone("B3_DS1", 92, 3, 0)
  RegisterEventHandler("B3_DS1Enter", B3_DS1_Enter)
  AddZone("B3_DS2", 67, 20, 0)
  RegisterEventHandler("B3_DS2Enter", B3_DS2_Enter)

  'B4
  AddZone("B4_US1", 124, 3, 0)
  RegisterEventHandler("B4_US1Enter", B4_US1_Enter)
  AddZone("B4_US2", 99, 20, 0)
  RegisterEventHandler("B4_US2Enter", B4_US2_Enter)
  AddZone("B4_DS1", 111, 3, 0)
  RegisterEventHandler("B4_DS1Enter", B4_DS1_Enter)

  'B5
  AddZone("B5_US1", 15, 35, 0)
  RegisterEventHandler("B5_US1Enter", B5_US1_Enter)
  AddZone("B5_DS1", 28, 41, 0)
  RegisterEventHandler("B5_DS1Enter", B5_DS1_Enter)
  AddZone("B5_DS2", 3, 58, 0)
  RegisterEventHandler("B5_DS2Enter", B5_DS2_Enter)

  'B6
  AddZone("B6_US1", 60, 41, 0)
  RegisterEventHandler("B6_US1Enter", B6_US1_Enter)
  AddZone("B6_US2", 35, 58, 0)
  RegisterEventHandler("B6_US2Enter", B6_US2_Enter)
  AddZone("B6_DS1", 41, 35, 0)
  RegisterEventHandler("B6_DS1Enter", B6_DS1_Enter)
  AddZone("B6_DS2", 48, 46, 0)
  RegisterEventHandler("B6_DS2Enter", B6_DS2_Enter)

  'B7
  AddZone("B7_US1", 73, 35, 0)
  RegisterEventHandler("B7_US1Enter", B7_US1_Enter)
  AddZone("B7_US2", 80, 46, 0)
  RegisterEventHandler("B7_US2Enter", B7_US2_Enter)
  AddZone("B7_DS1", 67, 46, 0)
  RegisterEventHandler("B7_DS1Enter", B7_DS1_Enter)
  AddZone("B7_DS2", 92, 58, 0)
  RegisterEventHandler("B7_DS2Enter", B7_DS2_Enter)

  'B8
  AddZone("B8_US1", 99, 46, 0)
  RegisterEventHandler("B8_US1Enter", B8_US1_Enter)
  AddZone("B8_US2", 124, 58, 0)
  RegisterEventHandler("B8_US2Enter", B8_US2_Enter)
  AddZone("B8_DS1", 124, 35, 0)
  RegisterEventHandler("B8_DS1Enter", B8_DS1_Enter)
  AddZone("B8_DS2", 112, 58, 0)
  RegisterEventHandler("B8_DS2Enter", B8_DS2_Enter)

  'B9
  AddZone("B9_US1", 28, 67, 0)
  RegisterEventHandler("B9_US1Enter", B9_US1_Enter)
  AddZone("B9_US2", 16, 90, 0)
  RegisterEventHandler("B9_US2Enter", B9_US2_Enter)
  AddZone("B9_DS1", 16, 67, 0)
  RegisterEventHandler("B9_DS1Enter", B9_DS1_Enter)

  'B10
  AddZone("B10_US1", 48, 67, 0)
  RegisterEventHandler("B10_US1Enter", B10_US1_Enter)
  
  If TestFlag("Pinema_1") AndAlso Not TestFlag("CaveC2_1") Then
    ac = AddStaticActor("DroppedGB", 36, 85, 1, [A_Null], DroppedGB_Contact)
  End If
  
  AddBox("CaveC2_B1", 17, 2, 0, BoxContent.Money, 3700, Nothing)
  AddBox("CaveC2_B2", 29, 13, 0, BoxContent.Money, 7200, Nothing)
  AddBox("CaveC2_B3", 98, 2, 0, BoxContent.Money, 4400, Nothing)
  AddBox("CaveC2_B4", 61, 34, 0, BoxContent.Money, 5100, Nothing)
  AddBox("CaveC2_B5", 34, 45, 0, BoxContent.Money, 7900, Nothing)
  AddBox("CaveC2_B6", 66, 34, 0, BoxContent.Money, 5800, Nothing)
  AddBox("CaveC2_B7", 14, 66, 0, BoxContent.Money, 6500, Nothing)
  
  SetStepsOfMaterial(4, 20)
  ResetStepsForEncountering()
  
  AddZone("EncZone01", 0, 0, 0, 127, 127, 0)
  RegisterEventHandler("EncZone01Step", EncZone01_Step)

  DoInsideWarp(startAt, Direction.Up, False)
  
  ChangeBGM(Music.Cave)

  NotifyEntered()
  Idle(ProcessInput)
  NotifyExiting()

End Procedure

Procedure ExitArea_Enter()
  BeginOutsideWarp([Field], GetAreaObject().Tag)
End Procedure

Procedure B1_DS1_Enter()
  DoInsideWarp("B2_US1", Direction.Down, True)
End Procedure

Procedure B1_DS2_Enter()
  DoInsideWarp("B2_US2", Direction.Down, True)
End Procedure

Procedure B2_US1_Enter()
  DoInsideWarp("B1_DS1", Direction.Down, True)
End Procedure

Procedure B2_US2_Enter()
  DoInsideWarp("B1_DS2", Direction.Down, True)
End Procedure

Procedure B2_DS1_Enter()
  DoInsideWarp("B3_US1", Direction.Down, True)
End Procedure

Procedure B2_DS2_Enter()
  DoInsideWarp("B3_US2", Direction.Down, True)
End Procedure

Procedure B3_US1_Enter()
  DoInsideWarp("B2_DS1", Direction.Down, True)
End Procedure

Procedure B3_US2_Enter()
  DoInsideWarp("B2_DS2", Direction.Down, True)
End Procedure

Procedure B3_DS1_Enter()
  DoInsideWarp("B4_US1", Direction.Down, True)
End Procedure

Procedure B3_DS2_Enter()
  DoInsideWarp("B4_US2", Direction.Down, True)
End Procedure

Procedure B4_US1_Enter()
  DoInsideWarp("B3_DS1", Direction.Down, True)
End Procedure

Procedure B4_US2_Enter()
  DoInsideWarp("B3_DS2", Direction.Down, True)
End Procedure

Procedure B4_DS1_Enter()
  DoInsideWarp("B5_US1", Direction.Down, True)
End Procedure

Procedure B5_US1_Enter()
  DoInsideWarp("B4_DS1", Direction.Down, True)
End Procedure

Procedure B5_DS1_Enter()
  DoInsideWarp("B6_US1", Direction.Down, True)
End Procedure

Procedure B5_DS2_Enter()
  DoInsideWarp("B6_US2", Direction.Down, True)
End Procedure

Procedure B6_US1_Enter()
  DoInsideWarp("B5_DS1", Direction.Down, True)
End Procedure

Procedure B6_US2_Enter()
  DoInsideWarp("B5_DS2", Direction.Down, True)
End Procedure

Procedure B6_DS1_Enter()
  DoInsideWarp("B7_US1", Direction.Down, True)
End Procedure

Procedure B6_DS2_Enter()
  DoInsideWarp("B7_US2", Direction.Down, True)
End Procedure

Procedure B7_US1_Enter()
  DoInsideWarp("B6_DS1", Direction.Down, True)
End Procedure

Procedure B7_US2_Enter()
  DoInsideWarp("B6_DS2", Direction.Down, True)
End Procedure

Procedure B7_DS1_Enter()
  DoInsideWarp("B8_US1", Direction.Down, True)
End Procedure

Procedure B7_DS2_Enter()
  DoInsideWarp("B8_US2", Direction.Down, True)
End Procedure

Procedure B8_US1_Enter()
  DoInsideWarp("B7_DS1", Direction.Down, True)
End Procedure

Procedure B8_US2_Enter()
  DoInsideWarp("B7_DS2", Direction.Down, True)
End Procedure

Procedure B8_DS1_Enter()
  DoInsideWarp("B9_US1", Direction.Down, True)
End Procedure

Procedure B8_DS2_Enter()
  DoInsideWarp("B9_US2", Direction.Down, True)
End Procedure

Procedure B9_US1_Enter()
  DoInsideWarp("B8_DS1", Direction.Down, True)
End Procedure

Procedure B9_US2_Enter()
  DoInsideWarp("B8_DS2", Direction.Down, True)
End Procedure

Procedure B9_DS1_Enter()
  DoInsideWarp("B10_US1", Direction.Down, True)
  If TestFlag("Pinema_1") AndAlso Not TestFlag("CaveC2_1") Then
    DoMsg("（水没している　どうやら最下層らしい）", _
      "（どこかに髪飾りが埋もれているかも）")
  End If
End Procedure

Procedure B10_US1_Enter()
  DoInsideWarp("B9_DS1", Direction.Down, True)
End Procedure

Procedure EncZone01_Step(mat)
  If TestEncountering(mat) Then
    Dim ep = CreateList()
    ep.Add({[E116], [E116], [E116], [E116], [E116]})
    ep.Add({[E117], [E116], [E116], [E116], [E116]})
    ep.Add({[E117], [E117], [E116], [E116]})
    ep.Add({[E117], [E117], [E117]})
    ep.Add({[E118], [E116], [E116], [E116]})
    ep.Add({[E118], [E117], [E116]})
    ep.Add({[E118], [E118]})
    DoNormalBattle(ep)
    ResetStepsForEncountering()
  End If
End Procedure

Procedure DroppedGB_Contact()
  DoMsg("（何か金色に光っている？……）")
  RemoveActor("DroppedGB")
  Sleep(500)
  DoMsg("（これは髪飾りだな）", _
    "（きっとジェレミーさんのだろう）")
  GiveUsTool([GoldenBarrette])
  SetFlag("CaveC2_1")
End Procedure
