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


(local
    bucketCel
    newAct
    gEgoX
    local3
    local4
    local5

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

    (method (init)
        (var temp0[50])
        (self:setLocales(703))
        (if (== global12 4)
            proc0_2()
        )(else
            proc0_3()
        )
        Load(128 13)
        Load(128 750)
        Load(128 17)
        Load(132 75)
        Load(132 76)
        Load(132 74)
        Load(132 45)
        (if (== global132 4)
            Load(128 22)
            Load(128 258)
            Load(128 260)
        )(else
            (if (== global132 5)
                Load(128 23)
                Load(128 259)
                Load(128 261)
            )(else
                (if (== global132 1)
                    Load(132 56)
                )(else
                    Load(130 991)
                    = local4 991
                )
            )
        )
        (if ((== global132 4) or (== global132 5))
            Load(132 52)
            Load(132 53)
        )(else
            Load(132 41)
        )
        (send gLongSong:priority(1))
        (send gEgo:setStep(-1 1))
        (super:init())
        (self:setScript(rmScript))
    )


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


    (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('/conveyer,belt,bucket,hoist,elevator'))
                        (if (== global124 0)
                            proc255_0(9 0)
                        )(else
                            proc255_0(9 1)
                        )
                    )(else
                        (if (Said('/iron,scrap,debris,heap,garbage'))
                            (if (== global124 0)
                                proc255_0(9 2)
                            )(else
                                proc255_0(9 3)
                            )
                        )(else
                            (if (Said('[<at,around,in][/area,!*]'))
                                (if (== global132 3)
                                    proc255_0(9 4)
                                )(else
                                    (if (== global132 2)
                                        proc255_0(9 5)
                                    )(else
                                        proc255_0(9 6)
                                    )
                                )
                            )
                        )
                    )
                )(else
                    (if (Said('jump/conveyer,belt,bucket'))
                        proc255_0(9 7)
                    )
                )
            )
            (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)
        (if (== global132 2)
            (send gEgo:cycleSpeed(0))
        )
        (if ((<> global132 4) and (<> global132 5))
            (send gLongSong:stop())
        )
        (super:newRoom(newRoomNumber))
    )

)
(instance rmScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (if ((> global124 0) or (== global132 1))
                    (elevSound:play())
                    (pile:init())
                    (bucket:init())
                )
                (if (> global132 1)
                    proc0_3()
                    (if (== global132 3)
                        (send gEgo:
                            init()
                            setScript(railWalkScript)
                        )
                    )(else
                        (if ((== global132 5) or (== global132 4))
                            (send gEgo:setScript(grabScript))
                        )
                    )
                )
            )
        )
    )

)
(instance pileScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (pile:setMotion(MoveTo 337 147))
            )
            (case 1
                (pile:
                    x(
                        (if (< global12 9)
                            271
                        )(else
                            309
                        )
)
                    y(147)
                    setCel(bucketCel)
                )
                (self:changeState(0))
            )
        )
    )

)
(instance bScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (bucket:
                    setCycle(0)
                    setMotion(MoveTo 240 114 self)
                )
            )
            (case 1
                = bucketCel (bucket:cel)
                (if (== (bucket:cel) 2)
                    (send gEgo:
                        setCycle(0)
                        setScript(dumpScript)
                        init()
                    )
                )
                (bucket:
                    setLoop(1)
                    cel(0)
                    posn(256 114)
                    setMotion(0)
                    setCycle(End self)
                )
            )
            (case 2
                (bucket:
                    setLoop(0)
                    setCel(Random(0 1))
                    posn(240 212)
                )
                (self:changeState(0))
                (pileScript:cue())
            )
        )
    )

)
(instance dumpScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gEgo:
                    view(17)
                    setLoop(0)
                    cel(0)
                    setPri(6)
                    posn(255 95)
                    illegalBits(0)
                    ignoreActors(1)
                    setStep(4 8)
                    setMotion(MoveTo 289 159 self)
                    cycleSpeed(1)
                    setCycle(0)
                    setCycle(End)
                )
                = global132 2
            )
            (case 1
                (thump:play())
                (send gEgo:
                    view(750)
                    setLoop(1)
                    cel(0)
                    posn(291 147)
                    cycleSpeed(2)
                    setCycle(End)
                    setStep(2 1)
                    setMotion(MoveTo 400 147)
                )
            )
        )
    )

)
(instance railWalkScript of Script
    (properties)

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


    (method (changeState newState)
        (switch (= state newState)
            (case 1
                (send gEgo:
                    view(17)
                    setLoop((send gEgo:loop))
                    cel(0)
                    setPri(
                        (if (< (send gEgo:y) 125)
                            8
                        )(else
                            9
                        )
)
                    illegalBits(0)
                    setCycle(End self)
                )
            )
            (case 2
                (send gLongSong:
                    number(45)
                    loop(1)
                    priority(15)
                    play()
                )
                (send gEgo:
                    setStep(1 15)
                    setMotion(JumpTo (send gEgo:x) 244 self)
                    setCycle(0)
                )
            )
            (case 3
                (send gEgo:hide())
                = local5 proc255_0(9 8 91)
                (Timer:set(self 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()
                                )
                            )
                        )
                    )
                )
            )
        )
        (super:doit())
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (if (== global132 5)
                    (send gEgo:
                        view(
                            (if (== global135 3)
                                261
                            )(else
                                23
                            )
)
                        setPri(4)
                        setStep(2)
                        y(88)
                    )
                )(else
                    (send gEgo:
                        view(
                            (if (== global135 3)
                                260
                            )(else
                                22
                            )
)
                        setPri(14)
                        setStep(3)
                        y(116)
                    )
                )
                (send gEgo:
                    init()
                    setCycle(Fwd)
                )
                (if (< global148 4)
                    (send gEgo:setMotion(MoveTo 
                        (if (== global12 10)
                            -40
                        )(else
                            400
                        )
 (send gEgo:y)))
                    (User:prevDir(
                        (if (== global12 10)
                            7
                        )(else
                            3
                        )
))
                )
                (if (> global148 3)
                    (send gEgo:
                        view(
                            (if (== global132 4)
                                22
                            )(else
                                23
                            )
)
                        loop(2)
                        posn(gGEgoX gGEgoY)
                    )
                    proc0_2()
                    (send global2: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(9 9)
        )(else
            (if (Said('lower/claw[<grabber]') or Said('use,press,press/claw,button'))
                (if ((send gEgo:mover))
                    proc255_0(9 10)
                )(else
                    (if ((<> global148 2) and (<> global148 3))
                        proc0_2()
                        = global159 1
                        (send gEgo:setMotion(0))
                        (clunk:
                            number(74)
                            loop(1)
                            play()
                        )
                        (send gEgo:setScript(clawScript))
                    )(else
                        proc255_0(9 11)
                    )
                )
            )(else
                (if (Said('/chair[<grabber,device]'))
                    proc255_0(9 12)
                )(else
                    (if (Said('disembark[/grabber,device,!*]'))
                        proc255_0(9 13)
                    )
                )
            )
        )
    )

)
(instance clawScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                = gEgoX (send gEgo:x)
                = local3 
                    (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
                                local3
                            )
)
                        init()
                    )
                )(else
                    = gEgoX (send gEgo:x)
                    = local3 
                        (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(
                        (if (== global132 5)
                            4
                        )(else
                            (send gEgo:priority)
                        )
)
                    ignoreActors(1)
                    illegalBits(0)
                    setCycle(Fwd)
                    setMotion(MoveTo gEgoX 
                        (if (> global148 3)
                            local3
                        )(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())
                    (clunk:
                        number(
                            (if (== global148 4)
                                75
                            )(else
                                76
                            )
)
                        play()
                    )
                    proc0_3()
                    = global159 0
                    (if (== global148 4)
                        = global148 0
                    )(else
                        = global148 1
                    )
                    (clawScript:dispose())
                )(else
                    (if (> gEgoX 141)
                        = global147 1
                    )(else
                        = global147 0
                    )
                    = gGEgoX (send gEgo:x)
                    = gGEgoY (send gEgo:y)
                    (if (== global132 4)
                        (send global2:newRoom(4))
                    )(else
                        (send global2:newRoom(5))
                    )
                )
            )
        )
    )

)
(instance pile of Act
    (properties
        view 750
    )

    (method (init)
        (super:init())
        (self:
            setLoop(0)
            setCel(Random(0 1))
            setPri(6)
            ignoreActors(1)
            illegalBits(0)
            posn(309 147)
            setStep(2)
            setScript(pileScript)
        )
    )

)
(instance bucket of Act
    (properties
        view 13
        illegalBits 0
        moveSpeed 1
    )

    (method (init)
        (super:init())
        (bucket:
            posn(240 
                (if (< global12 9)
                    224
                )(else
                    204
                )
)
            setPri(7)
            setStep(-1 2)
            setLoop(0)
            setCel(
                (if (< global132 2)
                    2
                )(else
                    Random(0 1)
                )
)
            cycleSpeed(4)
            setScript(bScript)
            ignoreActors(1)
        )
    )

)
(instance elevSound of Sound
    (properties
        number 41
        loop -1
    )
)
(instance thump of Sound
    (properties
        number 56
        priority 2
    )
)
(instance clunk of Sound
    (properties
        number 75
        priority 5
    )
)
