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

Procedure Main(startAt)

  Dim ac = Nothing

  RegisterCommonEventHandlers()
  AddAreaZone(AddZone("THE_WORLD", 0, 0, 0, 511, 511, 99), 1)
  ChangeVisibility(0, 0, 0, 511, 511, 99)
  ChangeBGTex(1)
  
  If TestFlag("CaveA2_1") Then
    ChangeGeometry(420, 396, 0, 4)
  End If
  
  If TestFlag("CaveC1_1") Then
    ChangeGeometry(140, 248, 0, 22)
  End If
  
  If TestFlag("NorthTower_2") AndAlso Not TestFlag("CentralTower_2") Then
    ChangeGeometry(222, 255, 0, 23)
  End If
  
  AddZone("Pramarl", 229, 473, 0)
  RegisterEventHandler("PramarlEnter", Pramarl_Enter)

  AddZone("Ibye", 267, 322, 0)
  RegisterEventHandler("IbyeEnter", Ibye_Enter)

  AddZone("Medrod", 91, 262, 0)
  RegisterEventHandler("MedrodEnter", Medrod_Enter)

  AddZone("Rabro", 359, 457, 0)
  RegisterEventHandler("RabroEnter", Rabro_Enter)

  AddZone("Kaure", 323, 354, 0)
  RegisterEventHandler("KaureEnter", Kaure_Enter)

  AddZone("Bamcake", 453, 359, 0)
  RegisterEventHandler("BamcakeEnter", Bamcake_Enter)

  AddZone("Sontem", 397, 265, 0)
  RegisterEventHandler("SontemEnter", Sontem_Enter)

  AddZone("Enkera", 299, 225, 0)
  RegisterEventHandler("EnkeraEnter", Enkera_Enter)

  AddZone("Menom", 375, 154, 0)
  RegisterEventHandler("MenomEnter", Menom_Enter)

  AddZone("Bunge", 231, 418, 0)
  RegisterEventHandler("BungeEnter", Bunge_Enter)

  AddZone("Munalo", 163, 326, 0)
  RegisterEventHandler("MunaloEnter", Munalo_Enter)

  AddZone("Pinema", 88, 171, 0)
  RegisterEventHandler("PinemaEnter", Pinema_Enter)

  AddZone("Horoira", 154, 80, 0)
  RegisterEventHandler("HoroiraEnter", Horoira_Enter)

  AddZone("Yomsikl", 246, 19, 0)
  RegisterEventHandler("YomsiklEnter", Yomsikl_Enter)

  AddZone("Serebe", 306, 88, 0)
  RegisterEventHandler("SerebeEnter", Serebe_Enter)

  AddZone("Misikint", 228, 163, 0)
  RegisterEventHandler("MisikintEnter", Misikint_Enter)

  AddZone("EastTower", 404, 255, 0)
  RegisterEventHandler("EastTowerEnter", EastTower_Enter)

  AddZone("SouthTower", 222, 420, 0)
  RegisterEventHandler("SouthTowerEnter", SouthTower_Enter)

  AddZone("WestTower", 40, 255, 0)
  RegisterEventHandler("WestTowerEnter", WestTower_Enter)

  AddZone("NorthTower", 222, 90, 0)
  RegisterEventHandler("NorthTowerEnter", NorthTower_Enter)

  AddZone("NorthTowerBarrierN", 230, 74, 0)
  RegisterEventHandler("NorthTowerBarrierNEnter", NorthTowerBarrierN_Enter)
  AddZone("NorthTowerBarrierS", 220, 106, 0)
  RegisterEventHandler("NorthTowerBarrierSEnter", NorthTowerBarrierS_Enter)
  
  AddZone("CentralTower", 222, 255, 0)
  RegisterEventHandler("CentralTowerEnter", CentralTower_Enter)
  AddZone("Ending1", 221, 255, 0)

  AddZone("CaveA1", 310, 455, 0)
  RegisterEventHandler("CaveA1Enter", CaveA1_Enter)

  AddZone("CaveA2a", 373, 364, 0)
  RegisterEventHandler("CaveA2aEnter", CaveA2a_Enter)

  AddZone("CaveA2b", 405, 356, 0)
  RegisterEventHandler("CaveA2bEnter", CaveA2b_Enter)

  AddZone("CaveABa", 319, 375, 0)
  RegisterEventHandler("CaveABaEnter", CaveABa_Enter)

  AddZone("CaveABb", 316, 375, 0)
  RegisterEventHandler("CaveABbEnter", CaveABb_Enter)

  AddZone("CaveB1", 265, 258, 0)
  RegisterEventHandler("CaveB1Enter", CaveB1_Enter)

  AddZone("CaveB2", 351, 176, 0)
  RegisterEventHandler("CaveB2Enter", CaveB2_Enter)

  AddZone("CaveC1a", 157, 278, 0)
  RegisterEventHandler("CaveC1aEnter", CaveC1a_Enter)

  If TestFlag("CaveC1_1") Then
    AddZone("CaveC1b", 140, 248, 0)
    RegisterEventHandler("CaveC1bEnter", CaveC1b_Enter)
  End If

  AddZone("CaveC2", 132, 196, 0)
  RegisterEventHandler("CaveC2Enter", CaveC2_Enter)

  AddZone("CaveD1", 257, 113, 0)
  RegisterEventHandler("CaveD1Enter", CaveD1_Enter)

  AddZone("CaveD2", 163, 114, 0)
  RegisterEventHandler("CaveD2Enter", CaveD2_Enter)

  AddZone("LakeDragonA", 287, 118, 0)
  RegisterEventHandler("LakeDragonAEnter", LakeDragonA_Enter)

  AddZone("LakeDragonB", 285, 125, 0)
  RegisterEventHandler("LakeDragonBEnter", LakeDragonB_Enter)
  
  Dim bgm_zone1 = CreateList()
  Dim bgm_zone2 = CreateList()
  
  SetStepsOfMaterial(4, 10)
  SetStepsOfMaterial(5, 15)
  SetStepsOfMaterial(7, 15)
  SetStepsOfMaterial(8, 20)
  ResetStepsForEncountering()
  
  bgm_zone1.Add(AddZone("EncZone01", 201, 430, 0, 391, 492, 0))
  RegisterEventHandler("EncZone01Step", EncZone01_Step)

  bgm_zone1.Add(AddZone("EncZone02", 252, 382, 0, 439, 429, 0))
  RegisterEventHandler("EncZone02Step", EncZone02_Step)

  bgm_zone1.Add(AddZone("EncZone03", 315, 304, 0, 480, 381, 0))
  RegisterEventHandler("EncZone03Step", EncZone03_Step)

  bgm_zone1.Add(AddZone("EncZone04", 388, 231, 0, 455, 303, 0))
  RegisterEventHandler("EncZone04Step", EncZone04_Step)

  bgm_zone2.Add(AddZone("EncZone05a", 252, 255, 0, 314, 381, 0))
  RegisterEventHandler("EncZone05aStep", EncZone05_Step)
  bgm_zone2.Add(AddZone("EncZone05b", 252, 213, 0, 320, 254, 0))
  RegisterEventHandler("EncZone05bStep", EncZone05_Step)
  bgm_zone2.Add(AddZone("EncZone05c", 315, 365, 0, 317, 381, 0))
  bgm_zone2.Add(AddZone("EncZone05d", 252, 382, 0, 259, 385, 0))
  bgm_zone2.Add(AddZone("EncZone05e", 291, 382, 0, 314, 388, 0))

  bgm_zone2.Add(AddZone("EncZone06a", 258, 165, 0, 398, 212, 0))
  RegisterEventHandler("EncZone06aStep", EncZone06_Step)
  bgm_zone2.Add(AddZone("EncZone06b", 284, 112, 0, 381, 164, 0))
  RegisterEventHandler("EncZone06bStep", EncZone06_Step)
  bgm_zone2.Add(AddZone("EncZone06c", 201, 430, 0, 208, 434, 0))

  bgm_zone2.Add(AddZone("EncZone07a", 202, 278, 0, 251, 346, 0))
  RegisterEventHandler("EncZone07aStep", EncZone07_Step)
  bgm_zone2.Add(AddZone("EncZone07b", 148, 347, 0, 251, 429, 0))
  RegisterEventHandler("EncZone07bStep", EncZone07_Step)

  bgm_zone2.Add(AddZone("EncZone08a", 148, 278, 0, 201, 346, 0))
  RegisterEventHandler("EncZone08aStep", EncZone08_Step)
  bgm_zone2.Add(AddZone("EncZone08b",  32, 213, 0, 147, 312, 0))
  RegisterEventHandler("EncZone08bStep", EncZone08_Step)

  bgm_zone2.Add(AddZone("EncZone09a",  62, 112, 0, 138, 212, 0))
  RegisterEventHandler("EncZone09aStep", EncZone09_Step)
  bgm_zone2.Add(AddZone("EncZone09b",  79,  42, 0, 174, 111, 0))
  RegisterEventHandler("EncZone09bStep", EncZone09_Step)

  bgm_zone2.Add(AddZone("EncZone10a", 175,  16, 0, 262, 111, 0))
  RegisterEventHandler("EncZone10aStep", EncZone10_Step)
  bgm_zone2.Add(AddZone("EncZone10b", 263,  45, 0, 320, 111, 0))
  RegisterEventHandler("EncZone10bStep", EncZone10_Step)

  bgm_zone2.Add(AddZone("EncZone11a", 258, 112, 0, 283, 164, 0))
  RegisterEventHandler("EncZone11aStep", EncZone11_Step)
  bgm_zone2.Add(AddZone("EncZone11b", 139, 112, 0, 257, 212, 0))
  RegisterEventHandler("EncZone11bStep", EncZone11_Step)

  bgm_zone2.Add(AddZone("EncZone12", 148, 213, 0, 251, 277, 0))
  RegisterEventHandler("EncZone12Step", EncZone12_Step)
  
  RunThread(AnimateSea)
  
  If startAt = "Ending1" Then
    Dim we = CombineList(GetPartyMembers())
    For i = 1 To we.Count
      If we[i] <> [TheHero] Then RemovePartyMember(we[i])
    Next
    SetPrimaryActor([TheHero])
    RegisterEventHandler("Ending1", AS_Ending1)
    RaiseEvent("Ending1")
    DoInsideWarp(startAt, Direction.Down, False)
  Else
    DoInsideWarp(startAt, Direction.Down, False)
  End If

  Dim pm = GetPrimaryActor()
  Dim pm_x = pm.X
  Dim pm_y = pm.Y
  Dim pm_z = pm.Z
  Dim bgm_is_2 = False
  For i = 1 To bgm_zone2.Count
    If IsInZone(bgm_zone2[i], pm_x, pm_y, pm_z) Then
      bgm_is_2 = True
      Exit For
    End If
  Next
  If startAt = "Ending1" Then
    ChangeBGM(Music.Ending)
  Else
    If bgm_is_2 Then
      ChangeBGM(Music.Field2)
    Else
      ChangeBGM(Music.Field1)
    End If
  End If

  NotifyEntered()
  Idle(ProcessInput)
  NotifyExiting()

End Procedure

Procedure AnimateSea()
  Do
    AnimateArea(2, 1, 9)
    Sleep(500)
    AnimateArea(2, 1, 10)
    Sleep(500)
    AnimateArea(2, 1, 11)
    Sleep(500)
    AnimateArea(2, 1, 12)
    Sleep(500)
    AnimateArea(2, 1, 13)
    Sleep(500)
    AnimateArea(2, 1, 14)
    Sleep(500)
    AnimateArea(2, 1, 15)
    Sleep(500)
    AnimateArea(2, 1, 16)
    Sleep(500)
  Loop
End Procedure

Procedure Pramarl_Enter()
  BeginOutsideWarp([Pramarl], "Entrance")
End Procedure

Procedure Ibye_Enter()
  BeginOutsideWarp([Ibye], "Entrance")
End Procedure

Procedure Medrod_Enter()
  BeginOutsideWarp([Medrod], "Entrance")
End Procedure

Procedure Rabro_Enter()
  BeginOutsideWarp([Rabro], "Entrance")
End Procedure

Procedure Kaure_Enter()
  BeginOutsideWarp([Kaure], "Entrance")
End Procedure

Procedure Bamcake_Enter()
  BeginOutsideWarp([Bamcake], "Entrance")
End Procedure

Procedure Sontem_Enter()
  BeginOutsideWarp([Sontem], "Entrance")
End Procedure

Procedure Enkera_Enter()
  BeginOutsideWarp([Enkera], "Entrance")
End Procedure

Procedure Menom_Enter()
  BeginOutsideWarp([Menom], "Entrance")
End Procedure

Procedure Bunge_Enter()
  BeginOutsideWarp([Bunge], "Entrance")
End Procedure

Procedure Munalo_Enter()
  BeginOutsideWarp([Munalo], "Entrance")
End Procedure

Procedure Pinema_Enter()
  BeginOutsideWarp([Pinema], "Entrance")
End Procedure

Procedure Horoira_Enter()
  BeginOutsideWarp([Horoira], "Entrance")
End Procedure

Procedure Yomsikl_Enter()
  BeginOutsideWarp([Yomsikl], "Entrance")
End Procedure

Procedure Serebe_Enter()
  BeginOutsideWarp([Serebe], "Entrance")
End Procedure

Procedure Misikint_Enter()
  BeginOutsideWarp([Misikint], "Entrance")
End Procedure

Procedure EastTower_Enter()
  BeginOutsideWarp([EastTower], "Entrance")
End Procedure

Procedure SouthTower_Enter()
  BeginOutsideWarp([SouthTower], "Entrance")
End Procedure

Procedure WestTower_Enter()
  BeginOutsideWarp([WestTower], "Entrance")
End Procedure

Procedure NorthTower_Enter()
  BeginOutsideWarp([NorthTower], "Entrance")
End Procedure

Procedure NorthTowerBarrierN_Enter()
  If TestFlag("NorthEvo") AndAlso Not TestFlag("NorthTower_1") AndAlso Not TestFlag("Misikint_2") Then
    LetActorWalk(GetPrimaryActor(), Direction.Up)
    DoMsg("（結界が張られている……）")
  End If
End Procedure

Procedure NorthTowerBarrierS_Enter()
  If TestFlag("NorthEvo") AndAlso Not TestFlag("NorthTower_1") AndAlso Not TestFlag("Misikint_2") Then
    LetActorWalk(GetPrimaryActor(), Direction.Down)
    DoMsg("（結界が張られている……）")
  End If
End Procedure

Procedure CentralTower_Enter()
  If TestFlag("NorthTower_2") Then
    BeginOutsideWarp([CentralTower], "Entrance")
  End If
End Procedure

Procedure CaveA1_Enter()
  BeginOutsideWarp([CaveA1], "Entrance")
End Procedure

Procedure CaveA2a_Enter()
  If TestFlag("Kaure_2") Then
    BeginOutsideWarp([CaveA2], "Entrance1")
  Else
    DoMsg("（この先には　まだ行かないほうがよさそうだ）")
  End If
End Procedure

Procedure CaveA2b_Enter()
  BeginOutsideWarp([CaveA2], "Entrance2")
End Procedure

Procedure CaveABa_Enter()
  BeginOutsideWarp([CaveAB], "Entrance1")
End Procedure

Procedure CaveABb_Enter()
  BeginOutsideWarp([CaveAB], "Entrance2")
End Procedure

Procedure CaveB1_Enter()
  BeginOutsideWarp([CaveB1], "Entrance")
End Procedure

Procedure CaveB2_Enter()
  BeginOutsideWarp([CaveB2], "Entrance")
End Procedure

Procedure CaveC1a_Enter()
  BeginOutsideWarp([CaveC1], "Entrance1")
End Procedure

Procedure CaveC1b_Enter()
  BeginOutsideWarp([CaveC1], "Entrance2")
End Procedure

Procedure CaveC2_Enter()
  BeginOutsideWarp([CaveC2], "Entrance")
End Procedure

Procedure CaveD1_Enter()
  BeginOutsideWarp([CaveD1], "Entrance")
End Procedure

Procedure CaveD2_Enter()
  BeginOutsideWarp([CaveD2], "Entrance")
End Procedure

Procedure LakeDragonA_Enter()
  If TestFlag("Serebe_3") Then
    DoInsideWarp("LakeDragonB", Direction.Down, True)
  ElseIf TestFlag("Serebe_1") AndAlso Not TestFlag("Serebe_2") Then
    If DoNormalBattle({{[E209]}}) Then
      SetFlag("Serebe_2")
    End If
  End If
End Procedure

Procedure LakeDragonB_Enter()
  If TestFlag("Serebe_3") Then
    DoInsideWarp("LakeDragonA", Direction.Up, True)
  End If
End Procedure

Procedure EncZone01_Step(mat)
  If TestEncountering(mat) Then
    Dim lv = GetPartyLevel()
    Dim ep = CreateList()
    'lv2
    ep.Add({[E001], [E001]})
    ep.Add({[E002]})
    If lv >= 3 Then
      ep.Add({[E001], [E001], [E001]})
      ep.Add({[E002], [E001]})
      ep.Add({[E003]})
    End If
    If lv >= 4 Then
      ep.Add({[E001], [E001], [E001], [E001]})
      ep.Add({[E002], [E001], [E001]})
      ep.Add({[E002], [E002]})
      ep.Add({[E003], [E001]})
      ep.Add({[E004]})
    End If
    DoNormalBattle(ep)
    ResetStepsForEncountering()
  End If
End Procedure

Procedure EncZone02_Step(mat)
  If TestEncountering(mat) Then
    Dim lv = GetPartyLevel()
    Dim ep = CreateList()
    'lv5
    ep.Add({[E004], [E004]})
    ep.Add({[E005]})
    If lv >= 6 Then
      ep.Add({[E004], [E004], [E004]})
      ep.Add({[E005], [E004]})
      ep.Add({[E006]})
    End If
    If lv >= 7 Then
      ep.Add({[E004], [E004], [E004], [E004]})
      ep.Add({[E005], [E004], [E004]})
      ep.Add({[E005], [E005]})
      ep.Add({[E006], [E004]})
      ep.Add({[E007]})
    End If
    DoNormalBattle(ep)
    ResetStepsForEncountering()
  End If
End Procedure

Procedure EncZone03_Step(mat)
  If TestEncountering(mat) Then
    Dim lv = GetPartyLevel()
    Dim ep = CreateList()
    'lv8
    ep.Add({[E007], [E007]})
    ep.Add({[E008]})
    If lv >= 9 Then
      ep.Add({[E007], [E007], [E007]})
      ep.Add({[E008], [E007]})
      ep.Add({[E009]})
    End If
    If lv >= 10 Then
      ep.Add({[E007], [E007], [E007], [E007]})
      ep.Add({[E008], [E007], [E007]})
      ep.Add({[E008], [E008]})
      ep.Add({[E009], [E007]})
      ep.Add({[E010]})
    End If
    DoNormalBattle(ep)
    ResetStepsForEncountering()
  End If
End Procedure

Procedure EncZone04_Step(mat)
  If TestEncountering(mat) Then
    Dim lv = GetPartyLevel()
    Dim ep = CreateList()
    'lv11
    ep.Add({[E010], [E010]})
    ep.Add({[E011]})
    If lv >= 12 Then
      ep.Add({[E010], [E010], [E010]})
      ep.Add({[E011], [E010]})
      ep.Add({[E012]})
    End If
    If lv >= 13 Then
      ep.Add({[E010], [E010], [E010], [E010]})
      ep.Add({[E011], [E010], [E010]})
      ep.Add({[E011], [E011]})
      ep.Add({[E012], [E010]})
      ep.Add({[E013]})
    End If
    DoNormalBattle(ep)
    ResetStepsForEncountering()
  End If
End Procedure

Procedure EncZone05_Step(mat)
  If TestEncountering(mat) Then
    Dim lv = GetPartyLevel()
    Dim ep = CreateList()
    'lv14
    ep.Add({[E013], [E013]})
    ep.Add({[E014]})
    If lv >= 15 Then
      ep.Add({[E013], [E013], [E013]})
      ep.Add({[E014], [E014]})
      ep.Add({[E015]})
    End If
    If lv >= 16 Then
      ep.Add({[E013], [E013], [E013], [E013]})
      ep.Add({[E014], [E013], [E013]})
      ep.Add({[E014], [E014]})
      ep.Add({[E015], [E013]})
      ep.Add({[E016]})
    End If
    DoNormalBattle(ep)
    ResetStepsForEncountering()
  End If
End Procedure

Procedure EncZone06_Step(mat)
  If TestEncountering(mat) Then
    Dim lv = GetPartyLevel()
    Dim ep = CreateList()
    'lv17
    ep.Add({[E016], [E016]})
    ep.Add({[E017]})
    If lv >= 18 Then
      ep.Add({[E016], [E016], [E016]})
      ep.Add({[E017], [E016]})
      ep.Add({[E018]})
    End If
    If lv >= 19 Then
      ep.Add({[E016], [E016], [E016], [E016]})
      ep.Add({[E017], [E016], [E016]})
      ep.Add({[E017], [E017]})
      ep.Add({[E018], [E016]})
      ep.Add({[E019]})
    End If
    DoNormalBattle(ep)
    ResetStepsForEncountering()
  End If
End Procedure

Procedure EncZone07_Step(mat)
  If TestEncountering(mat) Then
    Dim lv = GetPartyLevel()
    Dim ep = CreateList()
    'lv20
    ep.Add({[E019], [E019]})
    ep.Add({[E020]})
    If lv >= 21 Then
      ep.Add({[E019], [E019], [E019]})
      ep.Add({[E020], [E019]})
      ep.Add({[E021]})
    End If
    If lv >= 22 Then
      ep.Add({[E019], [E019], [E019], [E019]})
      ep.Add({[E020], [E019], [E019]})
      ep.Add({[E020], [E020]})
      ep.Add({[E021], [E019]})
      ep.Add({[E022]})
    End If
    DoNormalBattle(ep)
    ResetStepsForEncountering()
  End If
End Procedure

Procedure EncZone08_Step(mat)
  If TestEncountering(mat) Then
    Dim lv = GetPartyLevel()
    Dim ep = CreateList()
    'lv23
    ep.Add({[E022], [E022]})
    ep.Add({[E023]})
    If lv >= 24 Then
      ep.Add({[E022], [E022], [E022]})
      ep.Add({[E023], [E022]})
      ep.Add({[E024]})
    End If
    If lv >= 25 Then
      ep.Add({[E022], [E022], [E022], [E022]})
      ep.Add({[E023], [E022], [E022]})
      ep.Add({[E023], [E023]})
      ep.Add({[E024], [E022]})
      ep.Add({[E025]})
    End If
    DoNormalBattle(ep)
    ResetStepsForEncountering()
  End If
End Procedure

Procedure EncZone09_Step(mat)
  If TestEncountering(mat) Then
    Dim lv = GetPartyLevel()
    Dim ep = CreateList()
    'lv26
    ep.Add({[E025], [E025]})
    ep.Add({[E026]})
    If lv >= 27 Then
      ep.Add({[E025], [E025], [E025]})
      ep.Add({[E026], [E025]})
      ep.Add({[E027]})
    End If
    If lv >= 28 Then
      ep.Add({[E025], [E025], [E025], [E025]})
      ep.Add({[E026], [E025], [E025]})
      ep.Add({[E026], [E026]})
      ep.Add({[E027], [E025]})
      ep.Add({[E028]})
    End If
    DoNormalBattle(ep)
    ResetStepsForEncountering()
  End If
End Procedure

Procedure EncZone10_Step(mat)
  If TestEncountering(mat) Then
    Dim lv = GetPartyLevel()
    Dim ep = CreateList()
    'lv29
    ep.Add({[E028], [E028]})
    ep.Add({[E029]})
    If lv >= 30 Then
      ep.Add({[E028], [E028], [E028]})
      ep.Add({[E029], [E028]})
      ep.Add({[E030]})
    End If
    If lv >= 31 Then
      ep.Add({[E028], [E028], [E028], [E028]})
      ep.Add({[E029], [E028], [E028]})
      ep.Add({[E029], [E029]})
      ep.Add({[E030], [E028]})
      ep.Add({[E031]})
    End If
    DoNormalBattle(ep)
    ResetStepsForEncountering()
  End If
End Procedure

Procedure EncZone11_Step(mat)
  If TestEncountering(mat) Then
    Dim lv = GetPartyLevel()
    Dim ep = CreateList()
    'lv32
    ep.Add({[E031], [E031]})
    ep.Add({[E032]})
    If lv >= 33 Then
      ep.Add({[E031], [E031], [E031]})
      ep.Add({[E032], [E031]})
      ep.Add({[E033]})
    End If
    If lv >= 34 Then
      ep.Add({[E031], [E031], [E031], [E031]})
      ep.Add({[E032], [E031], [E031]})
      ep.Add({[E032], [E032]})
      ep.Add({[E033], [E031]})
      ep.Add({[E034]})
    End If
    DoNormalBattle(ep)
    ResetStepsForEncountering()
  End If
End Procedure

Procedure EncZone12_Step(mat)
  If TestEncountering(mat) Then
    Dim lv = GetPartyLevel()
    Dim ep = CreateList()
    'lv35
    ep.Add({[E034], [E034]})
    ep.Add({[E035]})
    If lv >= 36 Then
      ep.Add({[E034], [E034], [E034]})
      ep.Add({[E035], [E034]})
      ep.Add({[E036]})
    End If
    If lv >= 37 Then
      ep.Add({[E034], [E034], [E034], [E034]})
      ep.Add({[E035], [E034], [E034]})
      ep.Add({[E035], [E035]})
      ep.Add({[E036], [E034]})
      ep.Add({[E209]})
    End If
    DoNormalBattle(ep)
    ResetStepsForEncountering()
  End If
End Procedure

Procedure AS_Ending1()
  Dim p_name = [TheHero].Name + "："
  Dim q_name = "神エラテ："
  FadeOutProc(255, 255, 255, 3000)
  DoMsgT({p_name, "（こ　ここは塔の外……）", _
    "（どうやら助かったらしい）"}, 6000)
  DoMsgT({p_name, "（このペンダントには）", _
    "（魔法が込められていたんだな……）"}, 6100)
  Sleep(1000)
  DoMsgT({p_name, "（神の声が聞こえる……）"}, 3700)
  DoMsgT({q_name, [TheHero].Name + "よ　よくやった", _
    "デロクは再びその力を失った", _
    "", _
    "あとは私が奴を　昔のように封印する", _
    "奴もまた神　決して死にはしないのだ……"}, 7700)
  Sleep(1000)
  DoMsgT({p_name, "（終わった……）"}, 3100)
  Sleep(1000)
  DoMsgT({p_name, "（帰るか　ラブロに）"}, 3500)
  BeginOutsideWarp([Rabro], "Ending2")
End Procedure
