(version 2)
(include "sci.sh")
(exports
    0 rm004
)
(use "Main")
(use "Class_255_0")
(use "Timer")
(use "Sound")
(use "Cycle")
(use "Game")
(use "Feature")
(use "Obj")
(script 4)


(local
    newAct

)
(instance public rm004 of Rm
    (properties
        picture 4
        style 0
        west 3
    )

    (method (init)
        (var temp0[50])
        (if (<> global12 9)
            (self:setLocales(700))
        )(else
            proc0_2()
        )
        (SL:enable())
        Load(128 13)
        (if (== global149 global11)
            Load(128 36)
            (motivator:init())
        )
        (if (== global12 9)
            Load(128 258)
            Load(132 76)
        )(else
            Load(128 0)
            Load(128 6)
            (send gEgo:init())
        )
        Load(132 41)
        (send gLongSong:
            number(41)
            loop(-1)
            priority(1)
            play()
        )
        (bucket:init())
        (super:init())
        (if (== global12 9)
            (send gEgo:setScript(grabScript))
        )(else
            proc0_3()
        )
    )


    (method (doit)
        (if ((== (send gEgo:view) 0) or (== (send gEgo:view) 6))
            (if ((== (send gEgo:onControl(0)) 4) or (== (send gEgo:onControl(0)) 5))
                (send gEgo:view(6))
            )(else
                (if (== (send gEgo:onControl(0)) 1)
                    (send gEgo:view(0))
                )
            )
        )
        (if ((((send global5:contains(gEgo)) and (== (send gEgo:onControl(0)) 3)) and (> (bucket:y) 89)) and (< (bucket:y) 105))
            proc0_2()
            (send gEgo:dispose())
            (bucket:setCel(2))
            (if (not global239)
                = global239 1
                (send global1:changeScore(5))
            )
            = global132 1
        )
        (super:doit())
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )
        (switch ((send pEvent:type))
            (case 128
                (if (Said('look>'))
                    (if (Said('/bucket,conveyer,device,elevator,hoist[/belt]'))
                        proc255_0(4 0)
                    )(else
                        (if (Said('[<around,at,in][/area,!*]'))
                            proc255_0(4 1)
                        )(else
                            (if (Said('[<at]/appendage,finger,appendage,branch[<android,big]'))
                                proc255_0(4 2)
                            )(else
                                (if (Said('/jup,craft,2,chute'))
                                    proc255_0(4 3)
                                )(else
                                    (if (Said('[<in,in,through,at]/craft,pane,port,jup,2,chute'))
                                        proc255_0(4 4)
                                    )(else
                                        (if (Said('/nozzle'))
                                            proc255_0(4 5)
                                        )(else
                                            (if (Said('/cog,wheel'))
                                                proc255_0(4 6)
                                            )(else
                                                (if (Said('/box,pulley,dome,pole'))
                                                    proc255_0(4 7)
                                                )(else
                                                    (if (Said('/pit'))
                                                        proc255_0(4 8)
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )(else
                    (if (Said('cease,(turn<off),(close<down)/conveyer,elevator,hoist'))
                        proc255_0(4 9)
                    )(else
                        (if (Said('break,open/pane,glass,aperture,port,(cavity<port),finger,appendage,appendage'))
                            proc255_0(4 10)
                        )(else
                            (if (Said('board,enter,(get<on,onto,in,in),(climb,stair<in,up,in,onto,on)/bucket,conveyer,tower'))
                                proc255_0(4 11)
                            )(else
                                (if (Said('climb[<on,up]/craft,chute,jup,2'))
                                    proc255_0(4 12)
                                )(else
                                    (if (Said('hoist,manipulate,press,drag/craft,chute,jup,2'))
                                        proc255_0(4 13)
                                    )(else
                                        (if (Said('bite,tickle,buff/appendage,appendage[<android,big,green]'))
                                            proc255_0(4 14)
                                        )(else
                                            (if (Said('get,manipulate,drag,press,hoist[<up]/box,pulley,dome,pole'))
                                                proc255_0(4 15)
                                            )(else
                                                (if (Said('get,manipulate,drag,press,hoist,get,climb/appendage,appendage,finger[<android,big]'))
                                                    proc255_0(4 16)
                                                )(else
                                                    (if (Said('get>'))
                                                        (if (Said('/cog,wheel'))
                                                            proc255_0(4 17)
                                                        )(else
                                                            (send pEvent:claimed(0))
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )


    (method (newRoom newRoomNumber)
        (if (<> newRoomNumber 9)
            (send gLongSong:fade())
        )
        (super:newRoom(newRoomNumber))
    )

)
(instance bucket of Act
    (properties)

    (method (init)
        (super:init())
        (bucket:
            view(13)
            setPri(6)
            setCel(Random(0 1))
            setLoop(0)
            illegalBits(0)
            ignoreActors(1)
            ignoreHorizon(1)
            posn(242 65)
            setStep(-1 2)
            moveSpeed(1)
            setCycle(0)
            setMotion(MoveTo 242 -3 self)
            setScript(bScript)
        )
    )

)
(instance bScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (bucket:setPri(6))
            )
            (case 1
                (if (== (bucket:cel) 2)
                    (send global2:newRoom(9))
                )(else
                    (bucket:
                        setCel(Random(0 1))
                        posn(242 107)
                        setMotion(MoveTo 242 -3 self)
                    )
                    (self:state((- state 1)))
                )
            )
        )
    )

)
(instance motivator of Act
    (properties)

    (method (init)
        (super:init())
        (self:
            view(36)
            setLoop(0)
            setCel(0)
            x(
                (if (== global135 1)
                    227
                )(else
                    102
                )
)
            y(128)
            setPri(9)
            stopUpd()
        )
    )


    (method (handleEvent pEvent)
        (super:handleEvent(pEvent))
        (if ((<> (send pEvent:type) 128) or (send pEvent:claimed))
            return 
        )
        (if (Said('look>'))
            (if (Said('/motivator,artifact,device'))
                (if (global186)
                    proc255_0(4 18)
                )(else
                    proc255_0(4 19)
                )
            )(else
                (if (Said('/plug[<modular,8,spaceware]') or Said('/spaceware[<8]'))
                    proc255_0(4 20)
                )(else
                    (if (Said('[<down,below,at][/dirt,deck]'))
                        proc255_0(4 21)
                    )
                )
            )
        )(else
            (if (Said('drag,press,remove,get/plug[<modular,8,spaceware]'))
                proc255_0(4 22)
            )(else
                (if (Said('turn,get,manipulate,press,roll,drag/motivator,artifact,device'))
                    proc255_0(4 23)
                )(else
                    (if (Said('(turn<on),begin/motivator,artifact,device'))
                        proc255_0(4 24)
                    )
                )
            )
        )
    )

)
(instance grabScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = newAct (Act:new())
                (send newAct:
                    name("Claw")
                    view(258)
                    setLoop(
                        (if (== global135 3)
                            2
                        )(else
                            0
                        )
)
                    setPri(9)
                    setStep(1 2)
                    x(
                        (if (global147)
                            211
                        )(else
                            88
                        )
)
                    y(-19)
                    illegalBits(0)
                    ignoreHorizon(1)
                    ignoreActors(1)
                    init()
                    setCycle(Fwd)
                    setMotion(MoveTo 
                        (if (global147)
                            211
                        )(else
                            88
                        )
 112 self)
                )
            )
            (case 1
                (Timer:set(self 2))
            )
            (case 2
                (if (== global135 3)
                    = global148 4
                    = global135 global147
                    (clunkTune:play())
                    (send global1:changeScore(-15))
                    (motivator:init())
                    proc0_10()
                    = global149 global11
                    proc255_0(4 25)
                )(else
                    (if ((== global149 global11) and (== global135 global147))
                        (send newAct:setLoop(2))
                        (motivator:hide())
                        = global149 0
                        (clunkTune:play())
                        (send global1:changeScore(15))
                        = global135 3
                        = global148 5
                        proc0_10()
                        proc255_0(4 26)
                    )(else
                        proc255_0(4 27)
                        = global148 4
                    )
                )
                (self:changeState(3))
            )
            (case 3
                (send newAct:
                    setLoop(
                        (if (== global135 3)
                            2
                        )(else
                            0
                        )
)
                    setMotion(MoveTo (send newAct:x) -19 self)
                )
            )
            (case 4
                (send global2:newRoom(9))
            )
        )
    )

)
(instance clunkTune of Sound
    (properties
        number 76
        priority 15
    )
)
