require("lib/common")

MiscDoor = {
    sheriffCousinHouse = 4,
    mariannesHouse = 8,
    lockTutorialHouse1 = 9,
    lockTutorialHouse2 = 10,
    lockTutorialHouseNorth = 13,
    houseNorth2 = 15,
    towerNorthEast = 24,
    towerNorthEastExit = 25,
    prisonEntranceNorth = 76,
}

MiscPatch = {
    prisonNorthDoor = 1,
    prisonSouthDoor = 6,
    pixel_vert1 = 9,
    pixel_vert2 = 10
}

MiscAnimation = {
    gateBanner = 40,
}

Church = {
    Door = {
        sideEntrance = 54,
        mainEntrance = 55,
        confessionalBox1 = 56,
        confessionalBox2 = 57,
    },

    Animation = {
        candles = 28,
    },

    patch = 0,

    Reveal = function (self)
        ApplyPatch(GetPatchScript(self.patch))

        ActivateDoorMouseSector(true, GetDoorScript(self.Door.confessionalBox1))
        ActivateDoorMouseSector(true, GetDoorScript(self.Door.confessionalBox2))
        ActivateDoorMouseSector(false, GetDoorScript(self.Door.sideEntrance))
        ActivateDoorMouseSector(false, GetDoorScript(self.Door.mainEntrance))

        Activate(GetActorScript(self.Animation.candles))
    end,

    Initialize = function (self)
        ActivateDoorMouseSector(false, GetDoorScript(self.Door.confessionalBox1))
        ActivateDoorMouseSector(false, GetDoorScript(self.Door.confessionalBox2))

        Deactivate(GetActorScript(self.Animation.candles))
    end
}

PrisonNorth = {
    Door = {
        cell = 58,
        southEntrance = 59,
        exit = 74,
    },

    patch = 2,

    Reveal = function (self)
        ApplyPatch(GetPatchScript(self.patch))

        ActivateDoorMouseSector(true, GetDoorScript(self.Door.cell))
        ActivateDoorMouseSector(true, GetDoorScript(self.Door.exit))
        ActivateDoorMouseSector(false, GetDoorScript(self.Door.southEntrance))
    end,

    Initialize = function (self)
        ActivateDoorMouseSector(false, GetDoorScript(self.Door.cell))
        ActivateDoorMouseSector(false, GetDoorScript(self.Door.exit))
    end
}

FallGateRoom = {
    Animation = {
        torch = 35,
    },

    patch = 5,
    fallGate = 3,
    lever = 4,

    Reveal = function (self)
        ApplyPatch(GetPatchScript(self.patch))
        Activate(GetActor("Treadwheel"))
        Activate(GetActor(self.Animation.torch))
    end,

    Initialize = function (self)
        Deactivate(GetActor("Treadwheel"))
        Deactivate(GetActor(self.Animation.torch))
    end,

    ActivateFallGate = function(self, location)
        StartSequence()
        SequencePlayAnimFreeze(GetActor("Treadwheel"), AnimationAction.sittingToStanding)
        Then()
        SequenceCall(function()
          MakeNoise(location, 1) -- TODO: Check if Fallgate uses same Noise ID as Drawbridge does
        end)
        EndSequence()
        ApplyPatch(GetPatchScript(self.fallGate))
        ApplyPatch(GetPatchScript(self.lever))
      end
}

PrisonSouth = {
    Door = {
        sideEntrance = 81,
        mainEntrance = 82,
        cell = 83,
        stairs = 84,
    },

    Animation = {
        torch1 = 33,
        torch2 = 34,
    },

    patch = 7,

    Reveal = function (self)
        ApplyPatch(GetPatchScript(self.patch))

        Activate(GetActorScript(self.Animation.torch1))
        Activate(GetActorScript(self.Animation.torch2))

        ActivateDoorMouseSector(true, GetDoorScript(self.Door.cell))
        ActivateDoorMouseSector(true, GetDoorScript(self.Door.stairs))
        ActivateDoorMouseSector(false, GetDoorScript(self.Door.sideEntrance))
        ActivateDoorMouseSector(false, GetDoorScript(self.Door.mainEntrance))
    end,

    Initialize = function (self)
        Deactivate(GetActorScript(self.Animation.torch1))
        Deactivate(GetActorScript(self.Animation.torch2))

        ActivateDoorMouseSector(false, GetDoorScript(self.Door.cell))
        ActivateDoorMouseSector(false, GetDoorScript(self.Door.stairs))
    end
}

Chateau = {
    Door = {
        side = 86,
        main = 87,
        cupboard = 92
    },

    Animation = {
        chimney = 27,
        chandelier = 29,
        candles1 = 30,
        candles2 = 31,
        candles3 = 32,
    },

    patch = 8,

    Reveal = function (self)
        ApplyPatch(GetPatchScript(self.patch))

        Activate(GetActorScript(self.Animation.chimney))
        Activate(GetActorScript(self.Animation.chandelier))
        Activate(GetActorScript(self.Animation.candles1))
        Activate(GetActorScript(self.Animation.candles2))
        Activate(GetActorScript(self.Animation.candles3))

        ActivateDoorMouseSector(true, GetDoorScript(self.Door.main))
        ActivateDoorMouseSector(true, GetDoorScript(self.Door.cupboard))
        ActivateDoorMouseSector(false, GetDoorScript(self.Door.side))
    end,

    Initialize = function (self)
        Deactivate(GetActorScript(self.Animation.chimney))
        Deactivate(GetActorScript(self.Animation.chandelier))
        Deactivate(GetActorScript(self.Animation.candles1))
        Deactivate(GetActorScript(self.Animation.candles2))
        Deactivate(GetActorScript(self.Animation.candles3))

        ActivateDoorMouseSector(false, GetDoorScript(self.Door.main))
        ActivateDoorMouseSector(false, GetDoorScript(self.Door.cupboard))
    end
}

function InitializeNottingham()
    Church:Initialize()
    PrisonNorth:Initialize()
    FallGateRoom:Initialize()
    PrisonSouth:Initialize()
    Chateau:Initialize()

    DeactivateSherwoodSigns()
end