(version 2)
(include "sci.sh")
(exports
    0 rm11
)
(use "Main")
(use "Class_255_0")
(use "Sound")
(use "Cycle")
(use "Game")
(use "User")
(use "Feature")
(use "Obj")
(script 11)


(local
    newAct
    gEgoX
    local2
    local3
    local4
    local5

)
(instance public rm11 of Rm
    (properties
        picture 11
        style 0
        horizon 10
        west 10
    )

    (method (init)
        (var temp0[50])
        (self:setLocales(703))
        proc0_3()
        Load(128 25)
        Load(132 75)
        Load(132 76)
        Load(132 74)
        (if (== global132 3)
            Load(128 17)
            Load(132 45)
            Load(130 991)
            = local4 991
        )(else
            Load(128 22)
            Load(128 258)
            Load(128 260)
            Load(128 23)
            Load(128 259)
            Load(128 261)
            Load(132 52)
            Load(132 53)
        )
        (super:init())
        (if (== global132 3)
            (send gEgo:setScript(railWalkScript))
        )(else
            (send gEgo:setScript(grabScript))
        )
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )
        (switch ((send pEvent:type))
            (case 1
                (if (not global155 and (== (User:controls) 1))
                    (send gEgo:setMotion(MoveTo (send pEvent:x) (send gEgo:y)))
                    (send pEvent:claimed(1))
                )
            )
            (case 128
                (if (Said('look>'))
                    (if (Said('[<at,around,in][/area,!*]'))
                        (if (== global132 3)
                            proc255_0(11 0)
                        )(else
                            proc255_0(11 1)
                        )
                    )(else
                        (if (Said('/device,artifact'))
                            proc255_0(11 2)
                        )
                    )
                )(else
                    (if (Said('climb,jump/device'))
                        proc255_0(11 3)
                    )
                )
            )
            (case 64
                (if (global155 or ((<> global132 4) and (<> global132 5)))
                    return 
                )
                (switch ((send pEvent:message))
                    (case 1
                        (send gEgo:setMotion(0))
                        (send pEvent:claimed(1))
                        return 
                    )
                    (case 5
                        (send gEgo:setMotion(0))
                        (send pEvent:claimed(1))
                        return 
                    )
                    (case 8
                        (send gEgo:setMotion(0))
                        (send pEvent:claimed(1))
                        return 
                    )
                    (case 2
                        (send gEgo:setMotion(0))
                        (send pEvent:claimed(1))
                        return 
                    )
                    (case 4
                        (send gEgo:setMotion(0))
                        (send pEvent:claimed(1))
                        return 
                    )
                    (case 6
                        (send gEgo:setMotion(0))
                        (send pEvent:claimed(1))
                        return 
                    )
                )
            )
        )
    )


    (method (newRoom newRoomNumber)
        (super:newRoom(newRoomNumber))
    )

)
(instance railWalkScript of Script
    (properties)

    (method (doit)
        (if (not global100 and (<> (send gEgo:onControl(0)) 16384))
            (self:changeState(1))
            proc0_2()
            = global100 1
            (if (> (send gEgo:x) 240)
                = local3 1
            )
        )
        (super:doit())
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gEgo:
                    setPri(9)
                    init()
                )
            )
            (case 1
                (send gEgo:
                    view(17)
                    setLoop((send gEgo:loop))
                    cel(0)
                    setPri(
                        (if (not local3 and (< (send gEgo:y) 125))
                            8
                        )(else
                            9
                        )
)
                    setMotion(0)
                    illegalBits(0)
                    setCycle(End self)
                )
            )
            (case 2
                (send gEgo:
                    setStep(1 15)
                    setMotion(MoveTo (send gEgo:x) 244 self)
                    setCycle(0)
                )
                (send gLongSong:
                    number(45)
                    loop(1)
                    play()
                )
            )
            (case 3
                (send gEgo:hide())
                = local5 
                    (if (local3)
                        proc255_0(11 4 91)
                    )(else
                        proc255_0(11 5 91)
                    )
                = seconds 5
            )
            (case 4
                proc0_12()
                proc0_17(901 0 0 1)
            )
        )
    )

)
(instance grabScript of Script
    (properties)

    (method (doit)
        (if (not global155)
            (if (not (send gEgo:mover))
                (if ((== global132 4) and (<> (send gEgo:loop) 0))
                    (send gEgo:loop(0))
                )(else
                    (if ((== global132 5) and (<> (send gEgo:loop) 1))
                        (send gEgo:loop(1))
                    )
                )
                (if (== (send gLongSong:state) 3)
                    (send gLongSong:stop())
                )
            )(else
                (if (== global132 4)
                    (if ((== (send gEgo:loop) 0) and ((<> (send gLongSong:number) 52) or (<> (send gLongSong:state) 3)))
                        (send gLongSong:
                            stop()
                            number(52)
                            play()
                        )
                    )(else
                        (if ((== (send gEgo:loop) 1) and ((<> (send gLongSong:number) 53) or (<> (send gLongSong:state) 3)))
                            (send gLongSong:
                                stop()
                                number(53)
                                play()
                            )
                        )
                    )
                )(else
                    (if (== global132 5)
                        (if ((== (send gEgo:loop) 1) and ((<> (send gLongSong:number) 52) or (<> (send gLongSong:state) 3)))
                            (send gLongSong:
                                stop()
                                number(52)
                                play()
                            )
                        )(else
                            (if ((== (send gEgo:loop) 0) and ((<> (send gLongSong:number) 53) or (<> (send gLongSong:state) 3)))
                                (send gLongSong:
                                    stop()
                                    number(53)
                                    play()
                                )
                            )
                        )
                    )
                )
            )
        )
        (if (not global100)
            (if ((== global132 4) and (> (send gEgo:x) 248))
                = global100 1
                proc0_2()
                (self:changeState(1))
            )
            (if ((== global132 5) and (> (send gEgo:x) 103))
                = global100 1
                proc0_2()
                (self:changeState(4))
            )
        )
        (super:doit())
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (if (== global132 5)
                    (send gEgo:
                        view(
                            (if (== global135 3)
                                261
                            )(else
                                23
                            )
)
                        setPri(-1)
                        setStep(2)
                        y(88)
                    )
                )(else
                    (send gEgo:
                        view(
                            (if (== global135 3)
                                260
                            )(else
                                22
                            )
)
                        setPri(9)
                        setStep(3)
                        y(116)
                    )
                )
                (send gEgo:
                    init()
                    setCycle(Fwd)
                )
                (if (< global148 4)
                    (send gEgo:setMotion(MoveTo 400 (send gEgo:y)))
                    (User:prevDir(3))
                )
                (if (> global148 3)
                    (send gEgo:
                        view(
                            (if (== global132 4)
                                22
                            )(else
                                23
                            )
)
                        loop(2)
                        posn(gGEgoX gGEgoY)
                    )
                    proc0_2()
                    (send global2:setScript(clawScript))
                )
            )
            (case 1
                (User:
                    canControl(0)
                    canInput(1)
                )
                proc0_2()
                (send gEgo:
                    view(25)
                    setLoop(
                        (if (<> global135 3)
                            2
                        )(else
                            5
                        )
)
                    illegalBits(0)
                    x(251)
                    y(114)
                    setPri(-1)
                    setStep(1 2)
                    setMotion(MoveTo 251 108 self)
                )
            )
            (case 2
                (send gEgo:
                    setLoop(
                        (if (<> global135 3)
                            0
                        )(else
                            3
                        )
)
                    setStep(6 2)
                    setMotion(MoveTo 179 84 self)
                )
            )
            (case 3
                (send gEgo:
                    view(
                        (if (== global135 3)
                            261
                        )(else
                            23
                        )
)
                    setLoop(-1)
                    loop(1)
                    setStep(2 1)
                    posn(103 88)
                    illegalBits(-32768)
                    setMotion(MoveTo -50 88)
                )
                proc0_3()
                (User:prevDir(7))
                = global100 0
                = global132 5
            )
            (case 4
                (User:
                    canControl(0)
                    canInput(1)
                )
                proc0_2()
                (send gEgo:
                    view(25)
                    setLoop(
                        (if (<> global135 3)
                            1
                        )(else
                            4
                        )
)
                    setStep(6 2)
                    posn(179 84)
                    setMotion(MoveTo 251 108 self)
                )
            )
            (case 5
                (send gEgo:
                    setLoop(
                        (if (<> global135 3)
                            2
                        )(else
                            5
                        )
)
                    setStep(1 2)
                    setMotion(MoveTo 251 114 self)
                )
            )
            (case 6
                (send gEgo:
                    view(
                        (if (== global135 3)
                            260
                        )(else
                            22
                        )
)
                    setLoop(-1)
                    loop(0)
                    setPri(9)
                    setStep(3 1)
                    posn(248 116)
                    setMotion(MoveTo -1 116)
                    illegalBits(-32768)
                )
                proc0_3()
                (User:prevDir(7))
                = global132 4
                = global100 0
            )
        )
    )


    (method (handleEvent pEvent)
        (var temp0[100])
        (super:handleEvent(pEvent))
        (if (((<> (send pEvent:type) 128) or global100) or (send pEvent:claimed))
            return 
        )
        (if (Said('look/grabber'))
            proc255_0(11 6)
        )(else
            (if (Said('lower/claw[<grabber]') or Said('use,press,press/claw,button'))
                (if ((send gEgo:mover))
                    proc255_0(11 7)
                )(else
                    (if ((<> global148 2) and (<> global148 3))
                        = global159 1
                        proc0_2()
                        (send gEgo:setMotion(0))
                        (clunk:
                            number(74)
                            loop(1)
                            play()
                        )
                        (send gEgo:setScript(clawScript))
                    )(else
                        proc255_0(11 8)
                    )
                )
            )(else
                (if (Said('/chair[<grabber,device]'))
                    proc255_0(11 9)
                )(else
                    (if (Said('disembark[/grabber,device,!*]'))
                        proc255_0(11 10)
                    )
                )
            )
        )
    )

)
(instance clawScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                = gEgoX (send gEgo:x)
                = local2 
                    (if (== global132 4)
                        (+ (send gEgo:y) 42)
                    )(else
                        (+ (send gEgo:y) 22)
                    )
                (self:changeState(1))
            )
            (case 1
                (send gEgo:
                    view(
                        (if (== global132 4)
                            22
                        )(else
                            23
                        )
)
                    loop(2)
                )
                (if (not (send global5:contains(newAct)))
                    = newAct (Act:new())
                    (send newAct:
                        name("Claw")
                        x(gEgoX)
                        y(
                            (if (> global148 3)
                                191
                            )(else
                                local2
                            )
)
                        init()
                    )
                )(else
                    = gEgoX (send gEgo:x)
                    = local2 
                        (if (== global132 4)
                            (+ (send gEgo:y) 42)
                        )(else
                            (+ (send gEgo:y) 22)
                        )
                )
                (send newAct:
                    view(
                        (if (== global132 4)
                            258
                        )(else
                            259
                        )
)
                    setLoop(
                        (if (== global135 3)
                            2
                        )(else
                            0
                        )
)
                    setStep(1 
                        (if (== global132 4)
                            2
                        )(else
                            1
                        )
)
                    setPri((send gEgo:priority))
                    ignoreActors(1)
                    illegalBits(0)
                    setCycle(Fwd)
                    setMotion(MoveTo gEgoX 
                        (if (> global148 3)
                            local2
                        )(else
                            191
                        )
 self)
                )
            )
            (case 2
                (if (> global148 3)
                    (send gEgo:
                        view(
                            (if (== global135 3)
                                + (send gEgo:view) 238
                            )(else
                                (send gEgo:view)
                            )
)
                        loop(0)
                    )
                    (send newAct:dispose())
                    proc0_3()
                    = global159 0
                    (clunk:
                        number(
                            (if (== global148 4)
                                75
                            )(else
                                76
                            )
)
                        play()
                    )
                    (if (== global148 4)
                        = global148 0
                    )(else
                        = global148 1
                    )
                    (clawScript:dispose())
                )(else
                    (if (((== global132 4) and (< gEgoX 152)) or ((== global132 5) and (< gEgoX 50)))
                        = global147 0
                    )(else
                        = global147 1
                    )
                    = gGEgoX (send gEgo:x)
                    = gGEgoY (send gEgo:y)
                    (if (== global132 4)
                        (send global2:newRoom(8))
                    )(else
                        (send global2:newRoom(7))
                    )
                )
            )
        )
    )

)
(instance clunk of Sound
    (properties
        number 75
        priority 5
    )
)
