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

  AddZone("ExitArea", 103, 127, 0, 104, 127, 0)
  RegisterEventHandler("ExitAreaEnter", ExitArea_Enter)
  AddZone("Entrance", 104, 126, 0)

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

  'B2toB3
  AddZone("B2_3", 63, 54, 0, 63, 55, 0)
  RegisterEventHandler("B2_3Enter", B2_3_Enter)
  AddZone("B2_3D", 65, 54, 0)
  AddZone("B3_2", 64, 54, 0, 64, 55, 0)
  RegisterEventHandler("B3_2Enter", B3_2_Enter)
  AddZone("B3_2D", 62, 54, 0)

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

  'B4toB5
  AddZone("B4_5", 103, 63, 0)
  RegisterEventHandler("B4_5Enter", B4_5_Enter)
  AddZone("B4_5D", 103, 65, 0)
  AddZone("B5_4", 103, 64, 0)
  RegisterEventHandler("B5_4Enter", B5_4_Enter)
  AddZone("B5_4D", 103, 62, 0)

  'B5toB6
  AddZone("B5_6", 120, 95, 0)
  RegisterEventHandler("B5_6Enter", B5_6_Enter)
  AddZone("B5_6D", 120, 97, 0)
  AddZone("B6_5", 120, 96, 0)
  RegisterEventHandler("B6_5Enter", B6_5_Enter)
  AddZone("B6_5D", 120, 94, 0)
  
  AddBox("CaveB2_B1", 3, 38, 0, BoxContent.Tool, [RedHat], Nothing)
  AddBox("CaveB2_B2", 9, 58, 0, BoxContent.Tool, [BlueRing], Nothing)
  AddBox("CaveB2_B3", 39, 58, 0, BoxContent.Money, 2600, Nothing)
  AddBox("CaveB2_B4", 71, 38, 0, BoxContent.Money, 2200, Nothing)
  AddBox("CaveB2_B5", 124, 54, 0, BoxContent.Money, 1800, Nothing)
  AddBox("CaveB2_B6", 98, 86, 0, BoxContent.Money, 1400, 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_3_Enter()
  DoInsideWarp("B2_3D", Direction.None, True)
End Procedure

Procedure B3_2_Enter()
  DoInsideWarp("B3_2D", 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_5_Enter()
  DoInsideWarp("B4_5D", Direction.None, True)
End Procedure

Procedure B5_4_Enter()
  DoInsideWarp("B5_4D", 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 EncZone01_Step(mat)
  If TestEncountering(mat) Then
    Dim ep = CreateList()
    ep.Add({[E110], [E110], [E110], [E110], [E110]})
    ep.Add({[E111], [E110], [E110], [E110], [E110]})
    ep.Add({[E111], [E111], [E110], [E110]})
    ep.Add({[E111], [E111], [E111]})
    ep.Add({[E112], [E110], [E110], [E110]})
    ep.Add({[E112], [E111], [E110]})
    ep.Add({[E112], [E112]})
    DoNormalBattle(ep)
    ResetStepsForEncountering()
  End If
End Procedure
