(include "sci.sh")
(use "Main")
(use "LockDevice")
(use "n958")
(use "Cycle")
(use "Sounds")
(use "View")
(use "Obj")
(script 335)


(local
    local0 = 2399
    local1
    local2
    local3

)
(procedure (localproc_0128)
    (send gUser:
        canControl(1)
        canInput(1)
    )
    (send gSq5IconBar:enable(2 1))
    (send gSQ5:setCursor(982 1))
    (send gSq5IconBar:select((send gSq5IconBar:at(2))))
)


(procedure (localproc_015e)
    (send gUser:
        canControl(0)
        canInput(0)
    )
    (send gSq5IconBar:disable(0 3 4 5 6 7 8))
)


(class LockDevice of Prop
    (properties
        x 0
        y 0
        z 0
        heading 0
        noun 0
        modNum -1
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        sightAngle 26505
        actions 0
        onMeCheck 26505
        state 0
        approachX 0
        approachY 0
        approachDist 0
        _approachVerbs 0
        yStep 2
        view -1
        loop 0
        cel 0
        priority 0
        underBits 0
        signal 20496
        lsTop 0
        lsLeft 0
        lsBottom 0
        lsRight 0
        brTop 0
        brLeft 0
        brBottom 0
        brRight 0
        scaleSignal 0
        scaleX 128
        scaleY 128
        maxScale 128
        cycleSpeed 6
        script 0
        cycler 0
        timer 0
        detailLevel 0
        scaler 0
        deviceNum 0
        openScript 0
        closeScript 0
    )

    (method (doVerb param1 param2)
        return 
            (switch (param1)
                (case 4
                    (
                    (if (not local1)
                        = local1 1
                        (digit1:
                            init()
                            setScript(sCountDown)
                        )
                    )
 
                    (if (== local2 deviceNum)
                        (send gRoom:setScript(openScript 0 deviceNum))
                        ++local2
                    )(else
                        (if (== local2 (+ deviceNum 1))
                            (send gRoom:setScript(closeScript 0 deviceNum))
                            --local2
                        )(else
                            (if (proc999_5(deviceNum 2 3 6 7))
                                (send gRoom:setScript(closeScript 0 deviceNum))
                            )(else
                                (send gTestMessager:say(noun 4 1 0))
                            )
                        )
                    )
 return 1  )
                )
                (default 
                    ((super:doVerb(param1 rest param2)) )
                )
            )
    )

)
(instance public rm335 of Rm
    (properties
        noun 7
        picture 67
    )

    (method (init param1)
        (self:setRegions(350))
        proc958_0(128 447 448)
        (super:init(rest param1))
        (centerPanel:init())
        (latchTop:init())
        (latchBottom:init())
        (knobTR:init())
        (knobTL:init())
        (knobBR:init())
        (knobBL:init())
        (doorTR:init())
        (doorTL:init())
        (doorBR:init())
        (doorBL:init())
        (cloakDevice:init())
        (cloakLight:
            init()
            setCycle(Fwd)
        )
        (send gRoom:setScript(sStart))
    )

)
(instance sStart of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (localproc_015e() = seconds 2  )
            )
            (case 1
                ((send gTestMessager:say(7 0 0 0 self))  )
            )
            (case 2
                ((send gSq5IconBar:enable()) (send gUser:
                    canControl(1)
                    canInput(1)
                )
 (send gSq5IconBar:enable(2 1)) (send gSQ5:setCursor(982 1)) (send gSq5IconBar:select((send gSq5IconBar:at(2)))) (self:dispose()) )
            )
        )
    )

)
(instance sOpenLatchTop of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (localproc_015e() (send gSq5Music2:
                    number(108)
                    setLoop(1)
                    play()
                )
 (latchTop:setCel(1)) = cycles 3  )
            )
            (case 1
                (localproc_0128() (self:dispose()) )
            )
        )
    )

)
(instance sCloseLatchTop of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (localproc_015e() (send gSq5Music2:
                    number(108)
                    setLoop(1)
                    play()
                )
 (latchTop:setCel(0)) = cycles 3  )
            )
            (case 1
                (localproc_0128() (self:dispose()) )
            )
        )
    )

)
(instance sOpenLatchBottom of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (localproc_015e() (send gSq5Music2:
                    number(108)
                    setLoop(1)
                    play()
                )
 (latchBottom:setCel(1)) = cycles 3  )
            )
            (case 1
                ((centerPanel:hide()) localproc_0128() (self:dispose()) )
            )
        )
    )

)
(instance sCloseLatchBottom of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (localproc_015e() (send gSq5Music2:
                    number(108)
                    setLoop(1)
                    play()
                )
 (latchBottom:setCel(0)) = cycles 3  )
            )
            (case 1
                ((centerPanel:show()) localproc_0128() (self:dispose()) )
            )
        )
    )

)
(instance sTurnKnob of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (localproc_015e() (send gSq5Music2:
                    number(232)
                    setLoop(1)
                    play()
                )
 
                (switch (register)
                    (case 2
                        (
                        (if (== (knobTL:cel) 0)
                            (knobTL:setCycle(End self))
                        )(else
                            (knobTL:setCycle(Beg self))
                        )
 )
                    )
                    (case 7
                        (
                        (if (== (knobTR:cel) 0)
                            (knobTR:setCycle(End self))
                        )(else
                            (knobTR:setCycle(Beg self))
                        )
 )
                    )
                    (case 3
                        (
                        (if (== (knobBR:cel) 0)
                            (knobBR:setCycle(End self))
                        )(else
                            (knobBR:setCycle(Beg self))
                        )
 )
                    )
                    (case 6
                        (
                        (if (== (knobBL:cel) 0)
                            (knobBL:setCycle(End self))
                        )(else
                            (knobBL:setCycle(Beg self))
                        )
 )
                    )
                )
  )
            )
            (case 1
                (localproc_0128() (self:dispose()) )
            )
        )
    )

)
(instance sOpenPanel of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (localproc_015e() (send gSq5Music2:
                    number(431)
                    setLoop(1)
                    play()
                )
 
                (switch (register)
                    (case 4
                        ((doorTL:setCel(1)) (knobTL:hide())  )
                    )
                    (case 5
                        ((doorBR:setCel(1)) (knobBR:hide())  )
                    )
                    (case 8
                        ((doorTR:setCel(1)) (knobTR:hide())  )
                    )
                    (case 9
                        ((doorBL:setCel(1)) (knobBL:hide()) )
                    )
                )
 = cycles 3  )
            )
            (case 1
                (
                (switch (register)
                    (case 4
                        ((doorTL:setCel(2))  )
                    )
                    (case 5
                        ((doorBR:setCel(2))  )
                    )
                    (case 8
                        ((doorTR:setCel(2))  )
                    )
                    (case 9
                        ((doorBL:setCel(2)) )
                    )
                )
 = cycles 3  )
            )
            (case 2
                (
                (if (== register 9)
                    = local2 20
                    (send gRoom:setScript(sSlideLatches))
                )
 localproc_0128() (self:dispose()) )
            )
        )
    )

)
(instance sClosePanel of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (localproc_015e() (send gSq5Music2:
                    number(431)
                    setLoop(1)
                    play()
                )
 
                (switch (register)
                    (case 4
                        ((doorTL:setCel(1))  )
                    )
                    (case 5
                        ((doorBR:setCel(1))  )
                    )
                    (case 8
                        ((doorTR:setCel(1))  )
                    )
                    (case 9
                        ((doorBL:setCel(1)) )
                    )
                )
 = cycles 3  )
            )
            (case 1
                (
                (switch (register)
                    (case 4
                        ((doorTL:setCel(0)) (knobTL:show())  )
                    )
                    (case 5
                        ((doorBR:setCel(0)) (knobBR:show())  )
                    )
                    (case 8
                        ((doorTR:setCel(0)) (knobTR:show())  )
                    )
                    (case 9
                        ((doorBL:setCel(0)) (knobBL:show()) )
                    )
                )
 = cycles 3  )
            )
            (case 2
                (localproc_0128() (self:dispose()) )
            )
        )
    )

)
(instance sSlideLatches of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (localproc_015e() = local3 0 = cycles 1  )
            )
            (case 1
                ((latchTop:y((- 37 local3))) (latchBottom:y((+ 139 local3))) 
                (if (< (= local3 (+ local3 3)) 35)
                    = state 0
                )
 = cycles 3  )
            )
            (case 2
                (localproc_0128() (self:dispose()) )
            )
        )
    )

)
(instance sRemoveDevice of Script
    (properties)

    (method (doit param1)
        (super:doit(rest param1))
        Palette(6 29 32 1 33 37 1)
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (localproc_015e() (cloakLight:hide()) (cloakDevice:hide()) (light1:init()) (light2:init()) proc0_10(212 200) = cycles 3  )
            )
            (case 1
                ((glow1:init()) (glow2:init()) = ticks 5  )
            )
            (case 2
                ((arc:
                    init()
                    setCycle(Fwd)
                )
 (send gSq5Music2:
                    number(145)
                    setLoop(-1)
                    play()
                )
 = seconds 2  )
            )
            (case 3
                ((send gTestMessager:say(4 0 0 0 self))  )
            )
            (case 4
                ((send gSq5Music2:fade()) (send gEgo:get(12)) localproc_0128() (send gRoom:newRoom(330)) (self:dispose()) )
            )
        )
    )

)
(instance sCountDown of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((digit2:init()) (hashmark:init()) (digit3:init()) (digit4:init()) (send gSq5Music1:
                    number(124)
                    setLoop(-1)
                    play()
                )
 = cycles 1  )
            )
            (case 1
                ((send gTestMessager:say(8 0 0 0 self))  )
            )
            (case 2
                ((digit4:cel((% (= local0 (- local0 1)) 10))) (digit3:cel((% (/ local0 10) 10))) (digit2:cel((% (/ local0 100) 10))) (digit1:cel((/ local0 1000))) 
                (if (> local0 0)
                    --state
                )
 = ticks 5  )
            )
            (case 3
                (proc0_9(21) (self:dispose()) )
            )
        )
    )

)
(instance latchTop of LockDevice
    (properties
        x 136
        y 37
        noun 6
        view 447
        loop 6
        priority 9
    )

    (method (init param1)
        (super:init(rest param1))
        (self:
            openScript(sOpenLatchTop)
            closeScript(sCloseLatchTop)
        )
    )

)
(instance latchBottom of LockDevice
    (properties
        x 136
        y 139
        noun 6
        view 447
        loop 7
        priority 9
        deviceNum 1
    )

    (method (init param1)
        (super:init(rest param1))
        (self:
            openScript(sOpenLatchBottom)
            closeScript(sCloseLatchBottom)
        )
    )

)
(instance knobTL of LockDevice
    (properties
        x 92
        y 57
        noun 5
        view 447
        loop 4
        priority 8
        deviceNum 2
    )

    (method (init param1)
        (super:init(rest param1))
        (self:
            openScript(sTurnKnob)
            closeScript(sTurnKnob)
        )
    )

)
(instance knobTR of LockDevice
    (properties
        x 205
        y 57
        noun 5
        view 447
        loop 4
        priority 8
        deviceNum 7
    )

    (method (init param1)
        (super:init(rest param1))
        (self:
            openScript(sTurnKnob)
            closeScript(sTurnKnob)
        )
    )

)
(instance knobBR of LockDevice
    (properties
        x 205
        y 197
        z 100
        noun 5
        view 447
        loop 4
        priority 8
        deviceNum 3
    )

    (method (init param1)
        (super:init(rest param1))
        (self:
            openScript(sTurnKnob)
            closeScript(sTurnKnob)
        )
    )

)
(instance knobBL of LockDevice
    (properties
        x 92
        y 197
        z 100
        noun 5
        view 447
        loop 4
        priority 8
        deviceNum 6
    )

    (method (init param1)
        (super:init(rest param1))
        (self:
            openScript(sTurnKnob)
            closeScript(sTurnKnob)
        )
    )

)
(instance doorTL of LockDevice
    (properties
        x 67
        y 36
        noun 3
        view 447
        priority 7
        deviceNum 4
    )

    (method (init param1)
        (super:init(rest param1))
        (self:
            openScript(sOpenPanel)
            closeScript(sClosePanel)
        )
    )

)
(instance doorTR of LockDevice
    (properties
        x 240
        y 36
        noun 3
        view 447
        loop 1
        priority 7
        deviceNum 8
    )

    (method (init param1)
        (super:init(rest param1))
        (self:
            openScript(sOpenPanel)
            closeScript(sClosePanel)
        )
    )

)
(instance doorBR of LockDevice
    (properties
        x 240
        y 139
        noun 3
        view 447
        loop 3
        priority 7
        deviceNum 5
    )

    (method (init param1)
        (super:init(rest param1))
        (self:
            openScript(sOpenPanel)
            closeScript(sClosePanel)
        )
    )

)
(instance doorBL of LockDevice
    (properties
        x 67
        y 139
        noun 3
        view 447
        loop 2
        priority 7
        deviceNum 9
    )

    (method (init param1)
        (self:
            openScript(sOpenPanel)
            closeScript(sClosePanel)
        )
        (super:init(rest param1))
    )

)
(instance cloakDevice of Prop
    (properties
        x 152
        y 84
        noun 2
        view 447
        loop 9
        priority 4
    )

    (method (doVerb param1 param2)
        (switch (param1)
            (case 4
                (
                (if ((== local2 20) and not (send gRoom:script))
                    (send gRoom:setScript(sRemoveDevice))
                )(else
                    (send gTestMessager:say(2 4 1 0))
                )
 )
            )
            (default 
                ((super:doVerb(param1 rest param2)) )
            )
        )
    )

)
(instance cloakLight of Actor
    (properties
        x 152
        y 84
        noun 2
        view 447
        loop 8
        priority 5
        signal 16400
    )

    (method (doVerb param1 param2)
        (switch (param1)
            (case 4
                (
                (if ((== local2 20) and not (send gRoom:script))
                    (send gRoom:setScript(sRemoveDevice))
                )(else
                    (send gTestMessager:say(2 4 1 0))
                )
 )
            )
            (default 
                ((super:doVerb(param1 rest param2)) )
            )
        )
    )

)
(instance centerPanel of Prop
    (properties
        x 124
        y 68
        noun 1
        view 447
        loop 5
        priority 6
        signal 16
    )
)
(instance light1 of Prop
    (properties
        x 220
        y 71
        view 447
        loop 10
    )
)
(instance light2 of Prop
    (properties
        x 87
        y 72
        view 447
        loop 10
        cel 1
    )
)
(instance glow1 of Prop
    (properties
        x 115
        y 69
        view 447
        loop 11
    )
)
(instance glow2 of Prop
    (properties
        x 192
        y 69
        view 447
        loop 11
        cel 1
    )
)
(instance arc of Prop
    (properties
        x 115
        y 69
        view 447
        loop LockDevice
        signal 16384
    )
)
(instance digit1 of Prop
    (properties
        x 100
        y 146
        view 448
        cel 8
        priority 14
        signal 16
    )
)
(instance digit4 of View
    (properties
        x 184
        y 146
        view 448
        cel 5
        priority 14
        signal 16
    )
)
(instance digit3 of View
    (properties
        x 159
        y 146
        view 448
        cel 4
        priority 14
        signal 16
    )
)
(instance hashmark of View
    (properties
        x 145
        y 145
        view 448
        loop 1
        priority 14
        signal 16
    )
)
(instance digit2 of View
    (properties
        x 125
        y 146
        view 448
        cel 9
        priority 14
        signal 16
    )
)
