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


(local
    newAct
    gEgoX
    local2
    local3
    local4

)
(instance public rm012 of Rm
    (properties
        picture 12
        style 0
        horizon 10
        east 9
    )

    (method (init)
        (var temp0[50])
        (self:setLocales(703))
        (User:
            canInput(1)
            canControl(1)
        )
        (if (== global132 4)
            Load(128 22)
            Load(128 258)
            Load(128 260)
        )
        (if (== global132 5)
            Load(128 23)
            Load(128 259)
            Load(128 261)
        )
        (if (== global132 3)
            Load(128 17)
            Load(132 45)
            Load(130 991)
            = local3 991
        )(else
            Load(132 74)
            Load(132 75)
            Load(132 76)
        )
        (if ((== global132 4) or (== global132 5))
            Load(132 52)
            Load(132 53)
        )
        (send gEgo:setStep(-1 1))
        (send gLongSong:
            priority(0)
            loop(-1)
        )
        (super:init())
        (self:setScript(
            (if (== global132 3)
                railWalkScript
            )(else
                grabScript
            )
))
    )


    (method (dispose)
        (if (== global132 3)
            DisposeScript(991)
        )
        (super:dispose())
    )


    (method (handleEvent pEvent)
        (super: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('/door,corridor,partition,pit[<w]'))
                        proc255_0(12 0)
                    )(else
                        (if (Said('[<at,around,in][/area,!*]'))
                            (if (== global132 3)
                                proc255_0(12 1)
                            )(else
                                proc255_0(12 2)
                            )
                        )
                    )
                )
            )
            (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(1)) 16384))
            (self:changeState(1))
            (User:
                canControl(0)
                canInput(0)
            )
            = global100 1
        )
        (if (< (send gEgo:x) 4)
            (send gEgo:setMotion(0))
            (send global2:newRoom(13))
        )
        (super:doit())
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gEgo:init())
                (if (== global12 13)
                    (send gEgo:posn(10 123))
                )
            )
            (case 1
                (send gEgo:
                    view(17)
                    setLoop((send gEgo:loop))
                    cel(0)
                    setMotion(0)
                    illegalBits(0)
                    setPri(
                        (if (< (send gEgo:y) 125)
                            8
                        )(else
                            9
                        )
)
                    setCycle(End self)
                )
            )
            (case 2
                (send gEgo:
                    setCycle(0)
                    setMotion(JumpTo (send gEgo:x) 244 self)
                )
                (send gLongSong:
                    number(45)
                    loop(1)
                    play()
                )
            )
            (case 3
                (send gEgo:hide())
                = local4 proc255_0(12 3 91)
                = seconds 5
            )
            (case 4
                proc0_12()
                proc0_17(901 0 0 1)
            )
        )
    )

)
(instance grabScript of Script
    (properties)

    (method (doit)
        (if (global155)
            return 
        )
        (if ((< global148 2) and 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 ((== global132 5) and (< (send gEgo:x) 95))
            (send gEgo:setMotion(0))
            (send global2:newRoom(13))
        )
        (if ((== global132 4) and (< (send gEgo:x) 4))
            (send gEgo:setMotion(0))
            (send global2:newRoom(13))
        )
        (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
                    (if (== global132 4)
                        (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 
                        (if (== global12 13)
                            400
                        )(else
                            -40
                        )
 (send gEgo:y)))
                )
                (if (== global12 13)
                    (User:prevDir(3))
                    (if (== global132 5)
                        (send gEgo:x(
                            (if (== global132 5)
                                98
                            )(else
                                4
                            )
))
                    )(else
                        (send gEgo:x(4))
                    )
                )
                (if (== global12 9)
                    (User:prevDir(7))
                )
                (if (> global148 3)
                    (send gEgo:
                        view(
                            (if (== global132 4)
                                22
                            )(else
                                23
                            )
)
                        loop(2)
                        posn(gGEgoX gGEgoY)
                    )
                    (User:canControl(0))
                    (send gEgo:setScript(clawScript))
                )
            )
        )
    )


    (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(12 4)
        )(else
            (if (Said('lower/claw[<grabber]') or Said('use,press,press/claw,button'))
                (if ((send gEgo:mover))
                    proc255_0(12 5)
                )(else
                    (if ((< (send gEgo:x) 30) or ((== global132 5) and (< (send gEgo:x) 124)))
                        proc255_0(12 6)
                    )(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(12 7)
                        )
                    )
                )
            )(else
                (if (Said('/chair[<grabber,device]'))
                    proc255_0(12 8)
                )(else
                    (if (Said('disembark[/grabber,device,!*]'))
                        proc255_0(12 9)
                    )
                )
            )
        )
    )

)
(instance clawScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (User:canControl(0))
                = 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 (> gEgoX 212)
                        = global147 1
                    )(else
                        = global147 0
                    )
                    = gGEgoX (send gEgo:x)
                    = gGEgoY (send gEgo:y)
                    (if (== global132 4)
                        (send global2:newRoom(3))
                    )(else
                        (send global2:newRoom(2))
                    )
                )
            )
        )
    )

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