require("lib/common")

MiscPatch = {
  outerEastGate = 7,
  innerEastGate = 8,
  marketStandPixelVert = 9,
}

MiscDoor = {
  secretPassageInnerEast = 18,
  secretPassageInnerWest = 19,
  secretPassageOuter = 20,
  officerWithAmpuleDoor = 32,
  ampuleWomanDoor = 33,
  loanSharkDoor = 44,
  northWestBridgeHouseCathedralDoor = 119,
  northWestBridgeHouseBridgeDoor = 120,
  northWestBridgeHouseRampartDoor = 121,
}

MiscBuilding = {
  CastleTower = 4,
}

MiscAnimation = {
  pigeonsWestOfCathedral = 54,
  crowNorthWest01 = 55,
  crowNorthWest02 = 56,
  crowNorthWest03 = 57,
  crowSouthWest01 = 58,
  crowSouthWest02 = 59,
}

CastleFallGateRoom = {
  patch = 5,
  fallGate = 0,
  treadWheel = 4,
  torchAnimation = 31,

  Reveal = function(self)
    ApplyPatch(GetPatchScript(self.patch))
    Activate(GetActor("CastleTreadWheel"))
    Activate(GetActorScript(self.torchAnimation))
  end,

  Initialize = function(self)
    Deactivate(GetActor("CastleTreadWheel"))
  end,

  ActivateFallGate = function (self, soundLocation)
    StartSequence()
    SequencePlayAnimFreeze(GetActor("CastleTreadWheel"), 160)
    EndSequence()
    MakeNoise(soundLocation, 1)
    ApplyPatch(GetPatchScript(self.treadWheel))
    ApplyPatch(GetPatchScript(self.fallGate))
  end
}

CastleMainHall = {
  patch = 1,
  doorPatch = 3,

  Door = {
    entranceWest = 15,
    entranceSouth = 17,
    tower = 23
  },

  Animation = {
    candles = 1,
    chandelier1 = 2,
    chandelier2 = 3,
    towerTorch = 33,
  },

  Reveal = function (self)
    ApplyPatch(GetPatchScript(self.patch))
    ApplyPatch(GetPatchScript(self.doorPatch))
    ActivateDoorMouseSector(false, GetDoorScript(self.Door.entranceWest))
    ActivateDoorMouseSector(false, GetDoorScript(self.Door.entranceSouth))
    ActivateDoorMouseSector(true, GetDoorScript(self.Door.tower))
    ActivateAnimations(self.Animation)
  end,

  Initialize = function (self)
    ActivateDoorMouseSector(false, GetDoorScript(self.Door.tower))
    DeactivateAnimations(self.Animation)
  end
}

CastleHallway = {
  patch = 2,

  Door = {
    entranceSouth = 16,
    exitNorth = 17
  },

  Animation = {
    candles = 0,
    torch = 32
  },

  Reveal = function (self)
    ApplyPatch(GetPatchScript(self.patch))
    if not IsPatchApplied(GetPatchScript(CastleMainHall.patch)) then
      ActivateDoorMouseSector(true, GetDoorScript(self.Door.exitNorth))
    end
    ActivateDoorMouseSector(false, GetDoorScript(self.Door.entranceSouth))
    ActivateAnimations(self.Animation)
  end,

  Initialize = function (self)
    ActivateDoorMouseSector(false, GetDoorScript(self.Door.exitNorth))
    DeactivateAnimations(self.Animation)
  end
}

Church = {
  patch = 6,
  sideRoomDoor = 122,
  sideRoomBuilding = 73,

  Animation = {
    candles1 = 4,
    candles2 = 5,
    candles3 = 6,
    candles4 = 7,
    candles5 = 8,
    candles6 = 9,
    candles7 = 10,
    candles8 = 11,
    candles9 = 12,
    candles10 = 13,
  },

  Reveal = function (self)
    ApplyPatch(GetPatchScript(self.patch))
    ActivateDoorMouseSector(true, GetDoorScript(self.sideRoomDoor))
    ActivateAnimations(self.Animation)
  end,

  Initialize = function (self)
    ActivateDoorMouseSector(false, GetDoorScript(self.sideRoomDoor))
    DeactivateAnimations(self.Animation)
  end
}

function InitializeYork()
  CastleFallGateRoom:Initialize()
  CastleMainHall:Initialize()
  CastleHallway:Initialize()
  Church:Initialize()

  DeactivateSherwoodSigns()
end