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


(local
    newAct

)
(instance public rm5 of Rm
    (properties
        picture 5
        style 0
        horizon 10
        west 2
    )

    (method (init)
        (var temp0[50])
        (if (<> global12 9)
            (self:setLocales(700))
        )
        (SL:enable())
        (if (== global12 9)
            proc0_2()
        )
        (if (== global149 global11)
            Load(128 36)
            (motivator:init())
        )
        (if (== global12 9)
            Load(132 76)
            Load(128 258)
        )(else
            Load(128 0)
            (send gEgo:init())
        )
        (super:init())
        (self:setScript(rmScript))
    )


    (method (doit)
        (if ((send gEgo:inRect(152 138 292 148)) and (>= (send gEgo:x) 289))
            (send global2:newRoom(6))
        )
        (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))
                )
            )
        )
        (super:doit())
    )


    (method (handleEvent pEvent)
        (var temp0[50])
        (if ((send pEvent:claimed))
            return 
        )
        (switch ((send pEvent:type))
            (case 128
                (if (Said('look>'))
                    (if (Said('<in,in,through/craft,stage[<eva]') or Said('[<in,in,through,at]/pit,tube'))
                        proc255_0(5 0)
                    )(else
                        (if (Said('[<at]/craft,stage'))
                            proc255_0(5 1)
                        )(else
                            (if (Said('[<at]/bone,android,protrusion[<metallic]') or Said('[<at]/appendage,head[<bone,android,protrusion[<metallic]]'))
                                proc255_0(5 2)
                            )(else
                                (if (Said('/mog,finger,head,appendage[<android,man]'))
                                    proc255_0(5 3)
                                )(else
                                    (if (Said('[<around,at,in][/area,!*]'))
                                        proc255_0(5 4)
                                    )
                                )
                            )
                        )
                    )
                )(else
                    (if (Said('converse/man,mog,android'))
                        proc255_0(5 5)
                    )(else
                        (if (Said('climb,crawl/craft,stage'))
                            proc255_0(5 6)
                        )(else
                            (if (Said('crawl/console'))
                                proc255_0(5 7)
                            )(else
                                (if (Said('get/toaster'))
                                    proc255_0(5 8)
                                )(else
                                    (if (Said('get,explore,climb[<on,onto,up]/bone,android,protrusion[<metallic]'))
                                        proc255_0(5 9)
                                    )
                                )
                            )
                        )
                    )
                )
            )
            (case 1
                (if (((not (send pEvent:claimed) and (send gEgo:inRect(0 137 310 145))) and (> (send pEvent:x) 174)) and (< (send pEvent:y) 149))
                    (send gEgo:setMotion(MoveTo (send pEvent:x) (send gEgo:y)))
                    (send pEvent:claimed(1))
                )
            )
        )
    )

)
(instance rmScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (if (global157)
                    (send gEgo:setMotion(MoveTo 292 144))
                )(else
                    (if (== global12 9)
                        (motivator:setScript(grabScript))
                    )(else
                        (if (== global12 6)
                            (send gEgo:
                                setStep(-1 2)
                                posn(288 142)
                                init()
                            )
                        )
                    )
                )
            )
        )
    )

)
(instance motivator of Act
    (properties)

    (method (init)
        (super:init())
        (self:
            view(36)
            setLoop(0)
            setCel(0)
            x(
                (if (== global135 1)
                    147
                )(else
                    46
                )
)
            y(127 species 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(5 10)
                )(else
                    proc255_0(5 11)
                )
            )(else
                (if (Said('/plug[<modular,8,spaceware]') or Said('/spaceware[<8]'))
                    proc255_0(5 12)
                )(else
                    (if (Said('[<down,below,at][/dirt,deck]'))
                        proc255_0(5 13)
                    )
                )
            )
        )(else
            (if (Said('turn,get,manipulate,press,roll,drag/motivator,artifact,device'))
                proc255_0(5 14)
            )(else
                (if (Said('(turn<on),begin/motivator,artifact,device'))
                    proc255_0(5 15)
                )(else
                    (if (Said('press,drag,remove,get/plug[<modular,8,spaceware]'))
                        proc255_0(5 16)
                    )
                )
            )
        )
    )

)
(instance grabScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = newAct (Act:new())
                (send newAct:
                    view(258)
                    setLoop(
                        (if (== global135 3)
                            2
                        )(else
                            0
                        )
)
                    setPri(9)
                    setStep(1 2)
                    x(
                        (if (global147)
                            134
                        )(else
                            30
                        )
)
                    y(-19)
                    illegalBits(0)
                    ignoreHorizon(1)
                    ignoreActors(1)
                    init()
                    setCycle(Fwd)
                    setMotion(MoveTo 
                        (if (global147)
                            134
                        )(else
                            30
                        )
 110 self)
                )
            )
            (case 1
                (Timer:set(self 2))
            )
            (case 2
                (if (== global135 3)
                    = global148 4
                    = global135 global147
                    (motivator:init())
                    = global149 global11
                    (send gLongSong:
                        number(76)
                        loop(1)
                        play()
                    )
                    (send global1:changeScore(-15))
                    proc0_10()
                    proc255_0(5 17)
                )(else
                    (if ((== global149 global11) and (== global135 global147))
                        (send newAct:setLoop(2))
                        (motivator:hide())
                        = global149 0
                        = global135 3
                        = global148 5
                        (send gLongSong:
                            number(76)
                            loop(1)
                            play()
                        )
                        (send global1:changeScore(15))
                        proc0_10()
                        proc255_0(5 18)
                    )(else
                        proc255_0(5 19)
                        = 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))
            )
        )
    )

)
