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", 32, 0, 0, 63, 31, 100), 1)
  AddAreaZone(AddZone("B2", 32, 32, 0, 63, 63, 100), 1)
  AddAreaZone(AddZone("B3", 64, 32, 0, 95, 63, 100), 1)
  AddAreaZone(AddZone("B4", 96, 32, 0, 127, 63, 100), 1)
  AddAreaZone(AddZone("B5", 32, 64, 0, 63, 95, 100), 1)
  AddAreaZone(AddZone("B6", 64, 64, 0, 95, 95, 100), 1)
  AddAreaZone(AddZone("B7", 96, 64, 0, 127, 95, 100), 1)
  AddAreaZone(AddZone("B8", 96, 96, 0, 127, 127, 100), 1)

  AddZone("ExitArea", 111, 127, 0, 112, 127, 0)
  RegisterEventHandler("ExitAreaEnter", ExitArea_Enter)
  AddZone("Entrance", 112, 126, 0)

  'B1toB2
  AddZone("B1_2", 43, 31, 0)
  RegisterEventHandler("B1_2Enter", B1_2_Enter)
  AddZone("B1_2D", 43, 33, 0)
  AddZone("B2_1", 43, 32, 0)
  RegisterEventHandler("B2_1Enter", B2_1_Enter)
  AddZone("B2_1D", 43, 30, 0)

  'B2toB5
  AddZone("B2_5", 51, 63, 0)
  RegisterEventHandler("B2_5Enter", B2_5_Enter)
  AddZone("B2_5D", 51, 65, 0)
  AddZone("B5_2", 51, 64, 0)
  RegisterEventHandler("B5_2Enter", B5_2_Enter)
  AddZone("B5_2D", 51, 62, 0)

  'B5toB6
  AddZone("B5_6", 63, 86, 0, 63, 87, 0)
  RegisterEventHandler("B5_6Enter", B5_6_Enter)
  AddZone("B5_6D", 65, 86, 0)
  AddZone("B6_5", 64, 86, 0, 64, 87, 0)
  RegisterEventHandler("B6_5Enter", B6_5_Enter)
  AddZone("B6_5D", 62, 86, 0)

  'B3toB6
  AddZone("B3_6", 79, 63, 0)
  RegisterEventHandler("B3_6Enter", B3_6_Enter)
  AddZone("B3_6D", 79, 65, 0)
  AddZone("B6_3", 79, 64, 0)
  RegisterEventHandler("B6_3Enter", B6_3_Enter)
  AddZone("B6_3D", 79, 62, 0)

  'B3toB4
  AddZone("B3_4", 95, 38, 0, 95, 39, 0)
  RegisterEventHandler("B3_4Enter", B3_4_Enter)
  AddZone("B3_4D", 97, 38, 0)
  AddZone("B4_3", 96, 38, 0, 96, 39, 0)
  RegisterEventHandler("B4_3Enter", B4_3_Enter)
  AddZone("B4_3D", 94, 38, 0)

  'B4toB7
  AddZone("B4_7", 107, 63, 0)
  RegisterEventHandler("B4_7Enter", B4_7_Enter)
  AddZone("B4_7D", 107, 65, 0)
  AddZone("B7_4", 107, 64, 0)
  RegisterEventHandler("B7_4Enter", B7_4_Enter)
  AddZone("B7_4D", 107, 62, 0)

  'B7toB8
  AddZone("B7_8", 103, 95, 0)
  RegisterEventHandler("B7_8Enter", B7_8_Enter)
  AddZone("B7_8D", 103, 97, 0)
  AddZone("B8_7", 103, 96, 0)
  RegisterEventHandler("B8_7Enter", B8_7_Enter)
  AddZone("B8_7D", 103, 94, 0)
  
  AddBox("CaveD1_B1", 46, 5, 0, BoxContent.Money, 17800, Nothing)
  AddBox("CaveD1_B2", 39, 54, 0, BoxContent.Money, 17000, Nothing)
  AddBox("CaveD1_B3", 66, 34, 0, BoxContent.Money, 14600, Nothing)
  AddBox("CaveD1_B4", 119, 58, 0, BoxContent.Money, 13800, Nothing)
  AddBox("CaveD1_B5", 35, 66, 0, BoxContent.Money, 16200, Nothing)
  AddBox("CaveD1_B6", 88, 82, 0, BoxContent.Money, 15400, Nothing)
  AddBox("CaveD1_B7", 99, 70, 0, BoxContent.Money, 13000, Nothing)
  AddBox("CaveD1_B8", 103, 110, 0, BoxContent.Money, 12200, 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_2_Enter()
  DoInsideWarp("B1_2D", Direction.None, True)
End Procedure

Procedure B2_1_Enter()
  DoInsideWarp("B2_1D", Direction.None, True)
End Procedure

Procedure B2_5_Enter()
  DoInsideWarp("B2_5D", Direction.None, True)
End Procedure

Procedure B5_2_Enter()
  DoInsideWarp("B5_2D", Direction.None, True)
End Procedure

Procedure B5_6_Enter()
  DoInsideWarp("B5_6D", Direction.None, True)
End Procedure

Procedure B6_5_Enter()
  DoInsideWarp("B6_5D", Direction.None, True)
End Procedure

Procedure B3_6_Enter()
  DoInsideWarp("B3_6D", Direction.None, True)
End Procedure

Procedure B6_3_Enter()
  DoInsideWarp("B6_3D", Direction.None, True)
End Procedure

Procedure B3_4_Enter()
  DoInsideWarp("B3_4D", Direction.None, True)
End Procedure

Procedure B4_3_Enter()
  DoInsideWarp("B4_3D", Direction.None, True)
End Procedure

Procedure B4_7_Enter()
  DoInsideWarp("B4_7D", Direction.None, True)
End Procedure

Procedure B7_4_Enter()
  DoInsideWarp("B7_4D", Direction.None, True)
End Procedure

Procedure B7_8_Enter()
  DoInsideWarp("B7_8D", Direction.None, True)
End Procedure

Procedure B8_7_Enter()
  DoInsideWarp("B8_7D", Direction.None, True)
End Procedure

Procedure EncZone01_Step(mat)
  If TestEncountering(mat) Then
    Dim ep = CreateList()
    ep.Add({[E119], [E119], [E119], [E119], [E119]})
    ep.Add({[E120], [E119], [E119], [E119], [E119]})
    ep.Add({[E120], [E120], [E119], [E119]})
    ep.Add({[E120], [E120], [E120]})
    ep.Add({[E121], [E119], [E119], [E119]})
    ep.Add({[E121], [E120], [E119]})
    ep.Add({[E121], [E121]})
    DoNormalBattle(ep)
    ResetStepsForEncountering()
  End If
End Procedure
