(include "sci.sh")
(use "Main")
(use "Class_255_0")
(use "Class_950_0")
(use "Sound")
(use "Game")
(use "User")
(use "PicView")
(use "Obj")
(script 815)


(local
    local0[4] = (0 10 20 30 )
    local4[5] = (0 10 20 30 40 )
    local9
    local10
    local11[10]
    local21[5]
    local26[5]
    local31
    local32

)
(procedure (localproc_000e param1 param2 param3)
    (send param1:
        nsLeft((send param1:x))
        nsTop((send param1:y))
        nsRight(+ (send param1:x) param2)
        nsBottom(+ (send param1:y) param3)
    )
)


(procedure (localproc_0047)
    (switch (StrLen(@local21))
        (case 0
            (l1:cel(1))
        )
        (case 1
            (l2:cel(1))
        )
        (case 2
            (l3:cel(1))
        )
        (case 3
            (l4:cel(1))
        )
    )
)


(procedure (localproc_009b)
    (l1:cel(0))
    (l2:cel(0))
    (l3:cel(0))
    (l4:cel(0))
)


(instance public rmProtect of Rm
    (properties
        picture 803
        style 30
    )

    (method (init)
        Load(rsVIEW 815)
        Load(rsFONT 10)
        Load(rsSOUND 812)
        (switch (gWest)
            (case 530
                = local31 531
            )
        )
        (User:mapKeyToDir(0))
        (send gIconBar:disable())
        = local10 (= local9 Random(Random(0 2) Random(3 4)))
        (while (== local10 local9)
            = local10 Random(Random(0 2) Random(3 4))
        )
        StrCpy(@local26 "")
        StrCpy(@local21 "")
        (switch (local9)
            (case 0
                StrCat(@local11 "")
                StrCpy(@local26 "XW")
            )
            (case 1
                StrCat(@local11 "")
                StrCpy(@local26 "AO")
            )
            (case 2
                StrCat(@local11 "")
                StrCpy(@local26 "ER")
            )
            (case 3
                StrCat(@local11 "")
                StrCpy(@local26 "SR")
            )
            (case 4
                StrCat(@local11 "")
                StrCpy(@local26 "AW")
            )
        )
        (switch (local10)
            (case 0
                StrCat(@local11 " ")
                StrCat(@local26 "XW")
            )
            (case 1
                StrCat(@local11 " ")
                StrCat(@local26 "AO")
            )
            (case 2
                StrCat(@local11 " ")
                StrCat(@local26 "ER")
            )
            (case 3
                StrCat(@local11 " ")
                StrCat(@local26 "SR")
            )
            (case 4
                StrCat(@local11 " ")
                StrCat(@local26 "AW")
            )
        )
        (super:init())
        (send global8:
            eachElementDo(150 1)
            doit()
        )
        (backGround:
            number(890)
            loop(-1)
            playBed()
        )
        (keyPad:init())
        (self:setScript(startScript))
    )


    (method (dispose)
        (User:mapKeyToDir(1))
        (send gIconBar:enable())
        (super:dispose())
    )

)
(class padButton of Feature
    (properties
        x 0
        y 0
        z 0
        heading 0
        noun 0
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        description 0
        sightAngle 26505
        actions 26505
        onMeCheck 26505
        lookStr 0
        theString 0
        strToCat 0
        keyEquiv 0
        who 0
        scriptToCue 0
    )

    (method (init theTheString param2)
        (super:init(rest param2))
        = theString theTheString
        (send gSq4MouseDownHandler:addToFront(self))
        (send gSq4KeyDownHandler:addToFront(self))
        (if (who)
            (send who:
                x((self:x))
                y((self:y))
                init()
                hide()
            )
        )
    )


    (method (doit)
        (send who:setScript(Clone(keyFlashScript) scriptToCue))
        (if (strToCat and (< StrLen(theString) 4))
            localproc_0047()
            StrCat(theString strToCat)
        )
    )


    (method (dispose)
        (send gSq4KeyDownHandler:delete(self))
        (send gSq4MouseDownHandler:delete(self))
        (if (who)
            (send who:dispose())
        )
        (super:dispose())
    )


    (method (handleEvent pEvent)
        (switch ((send pEvent:type))
            (case 4
                (if ((== (send pEvent:message) 13) or (== (& (send pEvent:message) $ffdf) keyEquiv))
                    (if (scriptToCue)
                        (send global2:setScript(scriptToCue))
                    )
                    (send pEvent:claimed(1))
                    (self:doit())
                )
            )
            (case 1
                (if (proc255_5(self pEvent))
                    (if (scriptToCue)
                        (send global2:setScript(scriptToCue))
                    )
                    (send pEvent:claimed(1))
                    (self:doit())
                )
            )
        )
    )

)
(instance keyFlashScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send client:show())
                (keySound:
                    number(812)
                    loop(0)
                    play()
                )
                = cycles 3
            )
            (case 1
                (send client:
                    hide()
                    setScript(0)
                )
            )
        )
    )

)
(instance keySound of Sound
    (properties)
)
(instance backGround of Sound
    (properties)
)
(instance enterScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                0
            )
            (case 1
                (if (not StrLen(@local21))
                    Print("Please enter the correct X/Y coordinates, then press 'DONE'.")
                )(else
                    (if (not StrCmp(@local26 @local21))
                        (send global8:
                            eachElementDo(150 0)
                            doit()
                        )
                        (backGround:stop())
                        proc0_7(78)
                        (send global2:newRoom(local31))
                    )(else
                        (if (<= ++local32 2)
                            StrCpy(@local21 "")
                            localproc_009b()
                            Print("Sorry, you entered in the wrong X/Y coordinates. We'll give you another chance.")
                        )(else
                            Print("Sorry, wrong X/Y coordinates.")
                            (send global2:newRoom(gWest))
                        )
                    )
                )
                (send client:setScript(0))
            )
        )
    )

)
(instance startScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                Display(815 3 105 300 100 26 29 106 166 101 1 102 global135)
                = cycles 1
            )
            (case 1
                Display(@local11 100 231 69 105 10 102 global135)
                = cycles 1
            )
            (case 2
                (self:dispose())
            )
        )
    )

)
(instance keyPad of View
    (properties
        x 228
        y 97
        view 815
    )

    (method (init param1)
        (super:init(rest param1))
        (self:signal(257))
        (send gSq4MouseDownHandler:addToFront(self))
        (send gSq4KeyDownHandler:addToFront(self))
        (l1:init())
        (l2:init())
        (l3:init())
        (l4:init())
        (aBut:
            who(aDown)
            init(@local21)
        )
        (bBut:
            who(bDown)
            init(@local21)
        )
        (cBut:
            who(cDown)
            init(@local21)
        )
        (eBut:
            who(eDown)
            init(@local21)
        )
        (gBut:
            who(gDown)
            init(@local21)
        )
        (iBut:
            who(iDown)
            init(@local21)
        )
        (lBut:
            who(lDown)
            init(@local21)
        )
        (oBut:
            who(oDown)
            init(@local21)
        )
        (rBut:
            who(rDown)
            init(@local21)
        )
        (sBut:
            who(sDown)
            init(@local21)
        )
        (tBut:
            who(tDown)
            init(@local21)
        )
        (wBut:
            who(wDown)
            init(@local21)
        )
        (xBut:
            who(xDown)
            init(@local21)
        )
        (enterBut:
            who(enterDown)
            scriptToCue(enterScript)
            init(@local21)
        )
        (hand:
            x((send ((User:curEvent)):x))
            y((send ((User:curEvent)):y))
            init()
        )
    )


    (method (dispose param1)
        (User:mapKeyToDir(1))
        (send global1:setCursor((send ((send gIconBar:curIcon)):cursor) 1))
        (send gSq4KeyDownHandler:delete(self))
        (send gSq4MouseDownHandler:delete(self))
        (super:dispose(rest param1))
    )

)
(instance l1 of View
    (properties
        view 815
        loop 2
        priority 6
        signal 16
    )

    (method (init param1)
        (self:
            x(+ (keyPad:x) 7)
            y(- (keyPad:y) 8)
        )
        (super:init(rest param1))
    )

)
(instance l2 of View
    (properties
        view 815
        loop 2
        priority 6
        signal 16
    )

    (method (init param1)
        (self:
            x(+ (keyPad:x) 14)
            y(- (keyPad:y) 8)
        )
        (super:init(rest param1))
    )

)
(instance l3 of View
    (properties
        view 815
        loop 2
        priority 6
        signal 16
    )

    (method (init param1)
        (self:
            x(+ (keyPad:x) 21)
            y(- (keyPad:y) 8)
        )
        (super:init(rest param1))
    )

)
(instance l4 of View
    (properties
        view 815
        loop 2
        priority 6
        signal 16
    )

    (method (init param1)
        (self:
            x(+ (keyPad:x) 28)
            y(- (keyPad:y) 8)
        )
        (super:init(rest param1))
    )

)
(instance hand of View
    (properties
        view 502
        cel 2
        priority 15
        signal 16
    )

    (method (doit)
        (var temp0, temp1, temp2)
        (asm
            pushi   #curEvent
            pushi   0
            class   User
            send    4
            sat     temp0
            pushi   #type
            pushi   0
            send    4
            push    
            ldi     7
            and     
            not     
            bnt     code_0be8
            pushi   1
            lst     temp0
            callk   GlobalToLocal, 2
            pushi   #x
            pushi   0
            lat     temp0
            send    4
            sat     temp1
            pushi   #y
            pushi   0
            lat     temp0
            send    4
            push    
            ldi     10
            add     
            sat     temp2
            pushi   6
            pushi   0
            pushi   0
            pushi   320
            pushi   190
            lst     temp1
            push    
            calle   proc999_4, 12
            bnt     code_0bd7
            pushi   #setCursor
            pushi   2
            pushi   69
            pushi   1
            lag     global1
            send    8
            pushi   #show
            pushi   0
            pushi   4
            pushi   1
            lst     temp1
            pushi   3
            pushi   1
            lst     temp2
            self    16
            jmp     code_0be8
code_0bd7:  pushi   #setCursor
            pushi   2
            lsg     global20
            pushi   1
            lag     global1
            send    8
            pushi   #hide
            pushi   0
            self    4
code_0be8:  pushi   #doit
            pushi   0
            super   View, 4
            ret     
        )
    )

)
(instance aBut of padButton
    (properties
        strToCat "A"
        keyEquiv 65
    )

    (method (init param1)
        (self:
            x(+ (keyPad:x) local0[0])
            y(+ (keyPad:y) local4[0])
        )
        localproc_000e(self 8 8)
        (super:init(rest param1))
    )

)
(instance bBut of padButton
    (properties
        strToCat "B"
        keyEquiv 66
    )

    (method (init param1)
        (self:
            x(+ (keyPad:x) local0[1])
            y(+ (keyPad:y) local4[0])
        )
        localproc_000e(self 8 8)
        (super:init(rest param1))
    )

)
(instance cBut of padButton
    (properties
        strToCat "C"
        keyEquiv 67
    )

    (method (init param1)
        (self:
            x(+ (keyPad:x) local0[2])
            y(+ (keyPad:y) local4[0])
        )
        localproc_000e(self 8 8)
        (super:init(rest param1))
    )

)
(instance eBut of padButton
    (properties
        strToCat "E"
        keyEquiv 69
    )

    (method (init param1)
        (self:
            x(+ (keyPad:x) local0[3])
            y(+ (keyPad:y) local4[0])
        )
        localproc_000e(self 8 8)
        (super:init(rest param1))
    )

)
(instance gBut of padButton
    (properties
        strToCat "G"
        keyEquiv 71
    )

    (method (init param1)
        (self:
            x(+ (keyPad:x) local0[0])
            y(+ (keyPad:y) local4[1])
        )
        localproc_000e(self 8 8)
        (super:init(rest param1))
    )

)
(instance iBut of padButton
    (properties
        strToCat "I"
        keyEquiv 73
    )

    (method (init param1)
        (self:
            x(+ (keyPad:x) local0[1])
            y(+ (keyPad:y) local4[1])
        )
        localproc_000e(self 8 8)
        (super:init(rest param1))
    )

)
(instance lBut of padButton
    (properties
        strToCat "L"
        keyEquiv 76
    )

    (method (init param1)
        (self:
            x(+ (keyPad:x) local0[2])
            y(+ (keyPad:y) local4[1])
        )
        localproc_000e(self 8 8)
        (super:init(rest param1))
    )

)
(instance oBut of padButton
    (properties
        strToCat "O"
        keyEquiv 79
    )

    (method (init param1)
        (self:
            x(+ (keyPad:x) local0[3])
            y(+ (keyPad:y) local4[1])
        )
        localproc_000e(self 8 8)
        (super:init(rest param1))
    )

)
(instance rBut of padButton
    (properties
        strToCat "R"
        keyEquiv 82
    )

    (method (init param1)
        (self:
            x(+ (keyPad:x) local0[0])
            y(+ (keyPad:y) local4[2])
        )
        localproc_000e(self 8 8)
        (super:init(rest param1))
    )

)
(instance sBut of padButton
    (properties
        strToCat "S"
        keyEquiv 83
    )

    (method (init param1)
        (self:
            x(+ (keyPad:x) local0[1])
            y(+ (keyPad:y) local4[2])
        )
        localproc_000e(self 8 8)
        (super:init(rest param1))
    )

)
(instance tBut of padButton
    (properties
        strToCat "T"
        keyEquiv 84
    )

    (method (init param1)
        (self:
            x(+ (keyPad:x) local0[2])
            y(+ (keyPad:y) local4[2])
        )
        localproc_000e(self 8 8)
        (super:init(rest param1))
    )

)
(instance wBut of padButton
    (properties
        strToCat "W"
        keyEquiv 87
    )

    (method (init param1)
        (self:
            x(+ (keyPad:x) local0[3])
            y(+ (keyPad:y) local4[2])
        )
        localproc_000e(self 8 8)
        (super:init(rest param1))
    )

)
(instance xBut of padButton
    (properties
        strToCat "X"
        keyEquiv 88
    )

    (method (init param1)
        (self:
            x(+ (keyPad:x) local0[0])
            y(+ (keyPad:y) local4[3])
        )
        localproc_000e(self 8 8)
        (super:init(rest param1))
    )

)
(instance enterBut of padButton
    (properties
        keyEquiv 13
    )

    (method (init param1)
        (self:
            x(+ (keyPad:x) local0[1])
            y(+ (keyPad:y) local4[3])
        )
        localproc_000e(self 28 8)
        (super:init(rest param1))
    )

)
(instance aDown of Prop
    (properties
        view 815
        loop 1
        priority 15
    )
)
(instance bDown of Prop
    (properties
        view 815
        loop 1
        cel 1
        priority 15
    )
)
(instance cDown of Prop
    (properties
        view 815
        loop 1
        cel 2
        priority 15
    )
)
(instance eDown of Prop
    (properties
        view 815
        loop 1
        cel 3
        priority 15
    )
)
(instance gDown of Prop
    (properties
        view 815
        loop 1
        cel 4
        priority 15
    )
)
(instance iDown of Prop
    (properties
        view 815
        loop 1
        cel 5
        priority 15
    )
)
(instance lDown of Prop
    (properties
        view 815
        loop 1
        cel 6
        priority 15
    )
)
(instance oDown of Prop
    (properties
        view 815
        loop 1
        cel 7
        priority 15
    )
)
(instance rDown of Prop
    (properties
        view 815
        loop 1
        cel 8
        priority 15
    )
)
(instance sDown of Prop
    (properties
        view 815
        loop 1
        cel 9
        priority 15
    )
)
(instance tDown of Prop
    (properties
        view 815
        loop 1
        cel 10
        priority 15
    )
)
(instance wDown of Prop
    (properties
        view 815
        loop 1
        cel 11
        priority 15
    )
)
(instance xDown of Prop
    (properties
        view 815
        loop 1
        cel 12
        priority 15
    )
)
(instance enterDown of Prop
    (properties
        view 815
        loop 1
        cel 13
        priority 15
    )
)
