(include "sci.sh")
(use "Main")
(use "rm241")
(use "Print")
(use "CueObj")
(use "View")
(use "Obj")
(script 242)


(local
    local0
    local1[11]
    local12
    theRegister

)
(procedure public ()
    (d3:startUpd())
    (d2:startUpd())
    (d1:startUpd())
    (d0:startUpd())
    (if ((< 0 (d0:loop)) and (< (d0:loop) 10))
        (d0:loop((- (d0:loop) 1)))
    )(else
        (if (== (d1:loop) 15)
            (d0:loop(15))
        )(else
            (d0:loop(9))
        )
        (if ((< 0 (d1:loop)) and (< (d1:loop) 6))
            (d1:loop((- (d1:loop) 1)))
        )(else
            (if (== (d2:loop) 15)
                (d1:loop(15))
            )(else
                (d1:loop(5))
            )
            (if ((< 0 (d2:loop)) and (< (d2:loop) 10))
                (d2:loop((- (d2:loop) 1)))
            )(else
                (if (== (d3:loop) 15)
                    (d2:loop(15))
                )(else
                    (d2:loop(9))
                )
                (if ((< 0 (d3:loop)) and (< (d3:loop) 10))
                    (d3:loop((- (d3:loop) 1)))
                )(else
                    (d3:loop(15))
                )
            )
        )
    )
)


(procedure (localproc_006c param1)
    = local12 1
    = local1[local0] param1
    = local0 (% ++local0 10)
    = local12 0
)


(procedure (localproc_0083)
    = local12 1
    (if (> local0 0)
        return local1[--local0]
    )(else
        return -1
    )
    return = local12 0
)


(procedure (localproc_009d param1)
    (if (< param1 10)
        (if (== (d3:loop) 15)
            (d3:
                startUpd()
                setLoop((d2:loop))
            )
            (d2:
                startUpd()
                setLoop((d1:loop))
            )
            (d1:
                startUpd()
                setLoop((d0:loop))
            )
            (d0:
                startUpd()
                setLoop(param1)
            )
        )
        (if (<> (d2:loop) 15)
            (colon:init())
        )(else
            (colon:dispose())
        )
    )
)


(procedure (localproc_0266 param1)
    return 
        (if (proc999_4((+ (pad:x) 15) (+ (pad:y) 27) (+ (pad:x) 63) (+ (pad:y) 66) param1) and not proc241_3())
            return + (+ (* (/ (- (send param1:y) (+ (pad:y) 27)) 13) 3) 1) (/ (- (send param1:x) (+ (pad:x) 15)) 16)
        )(else
            (if ((proc999_4((+ (pad:x) 15) (+ (+ (pad:y) 27) 52) (+ (+ (pad:x) 15) 48) (+ (+ (pad:y) 27) 65) param1) and localproc_062a()) and not proc241_3())
                return 14
            )(else
                (if (proc999_4((+ (+ (pad:x) 15) 53) (- (+ (pad:y) 27) 13) (+ (+ (pad:x) 15) 101) (+ (pad:y) 27) param1) and not proc241_3())
                    proc241_2(0)
                    return 10
                )(else
                    (if (proc999_4((+ (+ (pad:x) 15) 53) (+ (pad:y) 27) (+ (+ (pad:x) 15) 101) (+ (+ (pad:y) 27) 13) param1) and not proc241_3())
                        proc241_2(1)
                        return 11
                    )(else
                        (if (proc999_4((+ (+ (pad:x) 15) 53) (+ (+ (pad:y) 27) 13) (+ (+ (pad:x) 15) 101) (+ (+ (pad:y) 27) 26) param1) and not proc241_3())
                            proc241_2(2)
                            return 12
                        )(else
                            (if (proc999_4((+ (+ (pad:x) 15) 16) (+ (+ (pad:y) 27) 39) (+ (+ (pad:x) 15) 32) (+ (+ (pad:y) 27) 52) param1) and not proc241_3())
                                return 0
                            )(else
                                (if (proc999_4(+ (+ (pad:x) 15) 32 + (+ (pad:y) 27) 39 + (+ (pad:x) 15) 48 + (+ (pad:y) 27) 52 param1))
                                    return 13
                                )(else
                                    return -1
                                )
                            )
                        )
                    )
                )
            )
        )
)


(procedure (localproc_0509 param1)
    (switch (param1)
        (case 0
            (16  )
        )
        (case 14
            (0  )
        )
        (case 10
            (53  )
        )
        (case 11
            (53  )
        )
        (case 12
            (53  )
        )
        (case 13
            (32  )
        )
        (default 
            (* (% (- param1 1) 3) 16 )
        )
    )
)


(procedure (localproc_0556 param1)
    (switch (param1)
        (case 0
            (39  )
        )
        (case 14
            (52  )
        )
        (case 10
            (65523  )
        )
        (case 11
            (0  )
        )
        (case 12
            (13  )
        )
        (case 13
            (39  )
        )
        (default 
            (* (/ (- param1 1) 3) 13 )
        )
    )
)


(procedure (localproc_05a3 param1)
    (var temp0, temp1)
    (d0:loop(15))
    (d1:loop(15))
    (d2:loop(15))
    (d3:loop(15))
    = temp0 (/ param1 60)
    = temp1 (% param1 60)
    (if (temp0)
        (d2:loop((% temp0 10)))
        (if (= temp0 (/ temp0 10))
            (d3:loop((% (= temp0 (/ temp0 10)) 10)))
        )
    )
    (if (temp1)
        (d0:loop((% temp1 10)))
        (if (= temp1 (/ temp1 10))
            (d1:loop((% (= temp1 (/ temp1 10)) 10)))
        )
    )
)


(procedure (localproc_062a)
    (var temp0, temp1, d0Loop, d1Loop, d2Loop, d3Loop)
    = d0Loop (d0:loop)
    = d1Loop (d1:loop)
    = d2Loop (d2:loop)
    = d3Loop (d3:loop)
    (if (== (d0:loop) 15)
        = d0Loop 0
    )
    (if (== (d1:loop) 15)
        = d1Loop 0
    )
    (if (== (d2:loop) 15)
        = d2Loop 0
    )
    (if (== (d3:loop) 15)
        = d3Loop 0
    )
    = temp1 (+ d0Loop (* d1Loop 10))
    return + (* (= temp0 (+ d2Loop (* d3Loop 10))) 60) temp1
)


(instance d0 of Prop
    (properties
        view 264
        loop 15
        priority 15
        signal 16400
    )

    (method (init param1)
        (self:
            loop(15)
            signal(16400)
        )
        (self:posn((+ (+ 20 (pad:x)) 30) (+ 17 (pad:y))))
        (super:init(rest param1))
    )

)
(instance d1 of Prop
    (properties
        view 264
        loop 15
        priority 15
        signal 16400
    )

    (method (init param1)
        (self:
            loop(15)
            signal(16400)
        )
        (self:posn((+ (+ 20 (pad:x)) 20) (+ 17 (pad:y))))
        (super:init(rest param1))
    )

)
(instance d2 of Prop
    (properties
        view 264
        loop 15
        priority 15
        signal 16400
    )

    (method (init param1)
        (self:
            loop(15)
            signal(16400)
        )
        (self:posn((+ (+ 20 (pad:x)) 10) (+ 17 (pad:y))))
        (super:init(rest param1))
    )

)
(instance d3 of Prop
    (properties
        view 264
        loop 15
        priority 15
        signal 16400
    )

    (method (init param1)
        (self:
            loop(15)
            signal(16400)
        )
        (self:posn((+ (+ 20 (pad:x)) 0) (+ 17 (pad:y))))
        (super:init(rest param1))
    )

)
(instance tempKey of Prop
    (properties
        view 264
        cel 1
        priority 15
        signal 16400
    )

    (method (show param1 param2)
        (self:
            posn(+ localproc_0509(param1) (+ (pad:x) 15) + localproc_0556(param1) (+ (pad:y) 27))
            setLoop(param1)
            setCel(1)
        )
        (super:show(rest param2))
    )

)
(instance tempKey2 of Prop
    (properties
        view 264
        cel 1
        priority 15
        signal 16400
    )

    (method (show param1)
        (var temp0)
        (self:
            posn(+ localproc_0509((= temp0 (+ proc241_2() 10))) (+ (pad:x) 15) + localproc_0556(temp0) (+ (pad:y) 27))
            setLoop(temp0)
            setCel(1)
        )
        (super:show(rest param1))
    )

)
(instance colon of View
    (properties
        view 264
        loop 4
        cel 3
        priority 15
        signal 16400
    )

    (method (init param1)
        (self:signal(16400))
        (self:
            x(+ (+ (pad:x) 15) 22)
            y(- (+ (pad:y) 27) 9)
        )
        (super:init(rest param1))
    )

)
(instance pad of Prop
    (properties
        x 10
        y 85
        noun 5
        modNum 241
        view 264
        loop 14
        cel 3
        priority 14
        signal 16400
    )

    (method (init param1)
        (super:init(rest param1))
        (self:show())
        (d0:init())
        (d1:init())
        (d2:init())
        (d3:init())
        (tempKey:
            init()
            hide()
        )
        (directions:
            init()
            setOnMeCheck(26505)
        )
        (tempKey2:
            init()
            show()
        )
        localproc_05a3(theRegister)
        (send gMouseDownHandler:addToFront(self))
        (send gKeyDownHandler:addToFront(self))
    )


    (method (doit param1)
        (var temp0)
        (super:doit(rest param1))
        (if ((not script and local0) and not local12)
            = temp0 localproc_0083()
            (self:setScript(keyFlash 0 temp0))
        )
    )


    (method (dispose param1)
        (d0:dispose())
        (d1:dispose())
        (d2:dispose())
        (d3:dispose())
        (colon:dispose())
        (tempKey:dispose())
        (directions:dispose())
        (tempKey2:dispose())
        (send gKeyDownHandler:delete(self))
        (send gMouseDownHandler:delete(self))
        (super:dispose(rest param1))
    )


    (method (handleEvent pEvent param2)
        (var pEventMessage, temp1, temp2[20])
        (if ((send gUser:controls) and (send gUser:input))
            (if (== (send gSq5IconBar:curIcon) (send gSq5IconBar:at(1)))
                (super:handleEvent(pEvent rest param2))
            )(else
                (if ((((not (& (send pEvent:type) $4000) and (<> (send pEvent:message) 9)) and not (self:onMe(pEvent))) and not script) and not (send pEvent:modifiers))
                    (keyStuff:cue())
                    (send pEvent:claimed(1))
                    return 
                )(else
                    (if ((= pEventMessage (send pEvent:message)) and (& (send pEvent:type) $0004))
                        (if ((== pEventMessage 13) and (<> (= temp1 localproc_0266(pEvent)) -1))
                            (send pEvent:claimed(1))
                            localproc_006c(temp1)
                            (send pEvent:claimed)
                            return 
                        )(else
                            (if ((== pEventMessage 9) and not proc241_3())
                                (send pEvent:claimed(1))
                                proc241_2(% (+ proc241_2() 1) 3)
                                (tempKey2:show())
                                (send pEvent:claimed)
                                return 
                            )(else
                                (if ((<= 48 pEventMessage) and (<= pEventMessage 57))
                                    (send pEvent:claimed(1))
                                    localproc_006c(- (send pEvent:message) 48)
                                    (send pEvent:claimed)
                                    return 
                                )(else
                                    (if (proc999_5(pEventMessage 27 67 99))
                                        (send pEvent:claimed(1))
                                        localproc_006c(11)
                                        (send pEvent:claimed)
                                        return 
                                    )(else
                                        (if (proc999_5(pEventMessage 69 101))
                                            (send pEvent:claimed(1))
                                            localproc_006c(14)
                                            (send pEvent:claimed)
                                            return 
                                        )(else
                                            (super:handleEvent(pEvent rest param2))
                                        )
                                    )
                                )
                            )
                        )
                    )(else
                        (if (((& (send pEvent:type) $0001) and (<> (= temp1 localproc_0266(pEvent)) -1)) and not (send pEvent:modifiers))
                            (send pEvent:claimed(1))
                            localproc_006c(temp1)
                            (send pEvent:claimed)
                            return 
                        )(else
                            (super:handleEvent(pEvent rest param2))
                        )
                    )
                )
            )
        )(else
            (super:handleEvent(pEvent rest param2))
        )
    )


    (method (hide param1)
        (d0:hide())
        (d1:hide())
        (d2:hide())
        (d3:hide())
        (colon:hide())
        (tempKey:hide())
        (tempKey2:hide())
        (super:hide(rest param1))
    )

)
(instance keyFlash of Script
    (properties)

    (method (changeState newState)
        (var temp0[2])
        (switch (= state newState)
            (case 0
                ((send gSq5Music2:
                    number(124)
                    loop(1)
                    play()
                )
 
                (if ((< 9 register) and (< register 13))
                    (tempKey2:
                        startUpd()
                        show(register)
                    )
                )(else
                    (tempKey:
                        startUpd()
                        show(register)
                    )
                )
 (tempKey:
                    startUpd()
                    show(register)
                )
 = ticks 5  )
            )
            (case 1
                (localproc_009d(register) = ticks 5  )
            )
            (case 2
                (
                (switch (register)
                    (case 13
                        ((self:setScript(clearScript self))  )
                    )
                    (case 14
                        (
                        (if ((((d0:loop) or (d1:loop)) or (d2:loop)) or (d3:loop))
                            proc241_1(localproc_062a())
                        )
 
                        (if (== (tempKey2:loop) 10)
                            proc241_4(471)
                        )(else
                            proc241_4(472)
                        )
 = cycles 1  )
                    )
                    (default 
                        (= cycles 1 )
                    )
                )
  )
            )
            (case 3
                ((d0:stopUpd()) (d1:stopUpd()) (d2:stopUpd()) (d3:stopUpd()) (tempKey:hide()) (send gSq5Music2:stop()) (self:dispose()) )
            )
        )
    )

)
(instance public keyStuff of Script
    (properties)

    (method (init param1 param2 param3 param4 param5 param6)
        (if (> paramTotal 3)
            (pad:x(param4))
            (if (> paramTotal 4)
                (pad:y(param5))
            )
        )
        (super:init(param1 param2 param3 rest param6))
    )


    (method (changeState newState)
        (var temp0[20])
        (switch (= state newState)
            (case 0
                (= theRegister register (pad:init()) (send gSQ5:handsOn()) (send gSq5IconBar:disable(0 3 5 4 6)) (send gSQ5:setCursor(982 1 (+ (pad:x) 10) (+ (pad:y) 10))) (send gSq5IconBar:select((send gSq5IconBar:at(2))))  )
            )
            (case 1
                ((send gSQ5:handsOff()) (pad:hide()) 
                (if (> (d0:loop) 9)
                    (d0:loop(0))
                )
 
                (if (> (d1:loop) 9)
                    (d1:loop(0))
                )
 
                (if (> (d2:loop) 9)
                    (d2:loop(0))
                )
 
                (if (> (d3:loop) 9)
                    (d3:loop(0))
                )
 = cycles 6  )
            )
            (case 2
                ((pad:
                    dispose()
                    delete()
                )
 (self:dispose()) )
            )
        )
    )

)
(instance clearScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gRoom:setScript(0)) = cycles 1  )
            )
            (case 1
                ((d0:
                    startUpd()
                    loop(0)
                )
 (d1:
                    startUpd()
                    loop(0)
                )
 (d2:
                    startUpd()
                    loop(0)
                )
 (d3:
                    startUpd()
                    loop(0)
                )
 proc241_3(0) = theRegister 0 localproc_05a3(0) (colon:dispose()) = cycles 1  )
            )
            (case 2
                ((self:dispose()) )
            )
        )
    )

)
(instance directions of Feature
    (properties)

    (method (init param1)
        (self:
            nsLeft(+ (pad:x) 70)
            nsTop(+ (pad:y) 53)
            nsRight(+ (pad:x) 114)
            nsBottom(+ (pad:y) 92)
            y(200)
        )
        (super:init(rest param1))
    )


    (method (doVerb param1)
        (switch (param1)
            (case 1
                ((Print:
                    addText(2 1 0 1 0 0 241)
                    addText(2 1 14 1 0 12 241)
                    addText(2 1 15 1 130 12 241)
                    addText(2 1 14 2 0 24 241)
                    addText(2 1 15 2 130 24 241)
                )
 (Print:
                    addText(2 1 14 3 0 36 241)
                    addText(2 1 15 3 130 36 241)
                    addText(2 1 14 4 0 48 241)
                    addText(2 1 15 4 130 48 241)
                    addText(2 1 14 5 0 60 241)
                    addText(2 1 15 5 130 60 241)
                )
 (Print:
                    addText(2 1 14 6 0 72 241)
                    addText(2 1 15 6 130 72 241)
                    addText(2 1 14 7 0 84 241)
                    addText(2 1 15 7 130 84 241)
                    addText(2 1 14 8 0 96 241)
                    addText(2 1 15 8 130 96 241)
                )
 (Print:
                    addText(2 1 14 9 0 108 241)
                    addText(2 1 15 9 130 108 241)
                    addText(2 1 14 10 0 120 241)
                    addText(2 1 15 10 130 120 241)
                    init()
                )
 )
            )
        )
    )

)
