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

  AddZone("ExitArea", 27, 127, 0, 28, 127, 0)
  RegisterEventHandler("ExitAreaEnter", ExitArea_Enter)
  AddZone("Entrance", 28, 126, 0)

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

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

  'B3toB4
  AddZone("B3_4", 3, 95, 0)
  RegisterEventHandler("B3_4Enter", B3_4_Enter)
  AddZone("B3_4D", 3, 97, 0)
  AddZone("B4_3", 3, 96, 0)
  RegisterEventHandler("B4_3Enter", B4_3_Enter)
  AddZone("B4_3D", 3, 94, 0)
  
  AddBox("CaveA1_B1", 9, 4, 0, BoxContent.Money, 260, Nothing)
  AddBox("CaveA1_B2", 3, 34, 0, BoxContent.Money, 220, Nothing)
  AddBox("CaveA1_B3", 28, 70, 0, BoxContent.Money, 180, Nothing)
  AddBox("CaveA1_B4", 25, 98, 0, BoxContent.Money, 140, 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 EncZone01_Step(mat)
  If TestEncountering(mat) Then
    Dim ep = CreateList()
    ep.Add({[E101], [E101], [E101], [E101], [E101]})
    ep.Add({[E102], [E101], [E101], [E101], [E101]})
    ep.Add({[E102], [E102], [E101], [E101]})
    ep.Add({[E102], [E102], [E102]})
    ep.Add({[E103], [E101], [E101], [E101]})
    ep.Add({[E103], [E102], [E101]})
    ep.Add({[E103], [E103]})
    DoNormalBattle(ep)
    ResetStepsForEncountering()
  End If
End Procedure
