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


(local
    local0
    newAct
    local2

)
(instance public rm003 of Rm
    (properties
        picture 3
        style 0
        horizon 52
        north 2
        east 4
    )

    (method (init)
        (var temp0[50])
        = global56 120
        (if (<> global12 12)
            (self:
                setLocales(700)
                setFeatures(jupiter acme bow bore)
            )
        )
        (if (== global12 12)
            proc0_2()
        )(else
            proc0_3()
        )
        (if (== global12 12)
            Load(128 258)
            Load(132 76)
        )(else
            Load(128 0)
            Load(128 193)
            Load(128 6)
        )
        Load(132 45)
        (if (== global149 global11)
            Load(128 36)
            (motivator:init())
        )
        (if ((== global12 15) or (== global12 4))
            (send gEgo:setLoop(-1))
        )
        (if ((== global12 4) or (== global12 15))
            Load(132 11)
            (send gLongSong:
                number(11)
                loop(-1)
                play()
            )
        )
        (super:init())
        (if ((<> global12 15) and (<> global12 4))
            (send gEgo:
                posn(127 57)
                loop(1)
            )
        )
        (if (== global12 15)
            (if (not global133)
                proc255_0(3 0)
                = global133 1
            )
            (send gEgo:
                view(6)
                posn(37 162)
                setLoop(-1)
                setPri(-1)
                illegalBits(-32768)
            )
        )
        = global100 0
        (if (== global12 12)
            (self:setScript(grabScript))
        )(else
            (send gEgo:init())
        )
    )


    (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))
                )
            )
        )
        (super:doit())
    )


    (method (handleEvent pEvent)
        (if (global100 or (send pEvent:claimed))
            return 
        )
        (switch ((send pEvent:type))
            (case 128
                (if (Said('look>'))
                    (if (Said('/bow,bow,tie'))
                        proc255_0(3 1)
                    )(else
                        (if (Said('/acme'))
                            proc255_0(3 2)
                        )(else
                            (if (Said('/jup,2'))
                                proc255_0(3 3)
                            )(else
                                (if (Said('/nozzle'))
                                    proc255_0(3 4)
                                )(else
                                    (if ((global133 and proc0_13(2 15)) and Said('look/ladder'))
                                        (if ((send gEgo:inRect(22 149 66 175)))
                                            proc255_0(3 5)
                                        )(else
                                            proc255_0(3 6)
                                        )
                                    )(else
                                        (if (global133 and Said('[<in,in,through,at]/cavity'))
                                            (if ((send gEgo:inRect(22 149 66 175)))
                                                proc255_0(3 7)
                                            )(else
                                                proc255_0(3 8)
                                            )
                                        )(else
                                            (if (Said('[<in,through,at,in]/pane,port,(port<cavity)'))
                                                (if ((send gEgo:inRect(39 148 105 167)))
                                                    proc255_0(3 9)
                                                )(else
                                                    proc0_5()
                                                )
                                            )(else
                                                (if (Said('/box'))
                                                    proc255_0(3 10)
                                                )(else
                                                    (if (Said('[<below,at]/iron'))
                                                        proc255_0(3 11)
                                                    )(else
                                                        (if (Said('[<around,at,in][/area,!*]'))
                                                            proc255_0(3 12)
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )(else
                    (if (Said('break,open/pane,glass,aperture,port,(cavity<port)'))
                        proc255_0(3 13)
                    )(else
                        (if (Said('hoist,manipulate,press,drag/craft,chute,bow,bow,tie,bore,acme,jup,2,(craft<flying)'))
                            proc255_0(3 14)
                        )(else
                            (if (Said('listen[/sound]'))
                                proc255_0(3 15)
                            )(else
                                (if (Said('open,board,enter,(climb[<in,in])/craft,bow,bow,tie,bore,acme,jup,2,(craft<flying),door'))
                                    proc255_0(3 16)
                                )(else
                                    (if (Said('walk,climb[<on,up]/craft'))
                                        proc255_0(3 17)
                                    )(else
                                        (if (Said('clean'))
                                            proc255_0(3 18)
                                        )(else
                                            (if (Said('get,manipulate/box'))
                                                proc255_0(3 19)
                                            )(else
                                                (if (Said('erect,stand,place,drop,lower,use/ladder[/cavity[<in,in,in]]'))
                                                    (if ((send gEgo:has(2)) or (send ((send global9:at(2))):ownedBy(8)))
                                                        (if ((send gEgo:inRect(22 149 66 175)))
                                                            (if ((send gEgo:has(2)))
                                                                proc0_14(2 15)
                                                                (send global1:changeScore(-10))
                                                                proc255_0(3 20)
                                                            )(else
                                                                proc255_0(3 21)
                                                            )
                                                        )(else
                                                            proc255_0(3 22)
                                                        )
                                                    )(else
                                                        (send pEvent:claimed(0))
                                                        return 
                                                    )
                                                )(else
                                                    (if (Said('descend,climb,go[<down][/ladder,cavity]'))
                                                        (if (global133)
                                                            (if ((send gEgo:inRect(22 149 66 175)))
                                                                (if (not (send gEgo:has(2)) and not proc0_13(2 8))
                                                                    (send gEgo:hide())
                                                                    proc0_10()
                                                                    (send global2:newRoom(15))
                                                                )(else
                                                                    proc255_0(3 23)
                                                                )
                                                            )(else
                                                                proc255_0(3 22)
                                                            )
                                                        )(else
                                                            proc255_0(3 24)
                                                        )
                                                    )(else
                                                        (if (Said('use,get,climb/debris,scrap,iron'))
                                                            (if ((send gEgo:inRect(210 89 276 110)))
                                                                (send gEgo:setScript(bleedScript))
                                                            )(else
                                                                proc255_0(3 25)
                                                            )
                                                        )(else
                                                            (if (Said('get/ladder'))
                                                                (if (global133)
                                                                    (if (not (send gEgo:has(2)) and not global134)
                                                                        (if ((send gEgo:inRect(22 149 66 175)))
                                                                            (send global1:changeScore(10))
                                                                            (send gEgo:get(2))
                                                                            proc255_0(3 26)
                                                                            proc255_0(3 27)
                                                                        )(else
                                                                            proc255_0(3 22)
                                                                        )
                                                                    )(else
                                                                        proc255_0(3 28)
                                                                    )
                                                                )(else
                                                                    proc255_0(3 29)
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )


    (method (newRoom newRoomNumber)
        (if ((== newRoomNumber 15) or (== newRoomNumber 4))
            (send gLongSong:stop())
        )
        (super:newRoom(newRoomNumber))
    )

)
(instance rmScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = global100 1
                (send gEgo:hide())
                proc255_0(3 30)
                (Timer:set(self 2))
                (fallTune:play())
            )
            (case 1
                proc255_0(3 31)
                proc0_17(901 0 0 1)
            )
        )
    )

)
(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(8)
                    setStep(1 2)
                    x(
                        (if (global147)
                            249
                        )(else
                            81
                        )
)
                    y(-16)
                    illegalBits(0)
                    ignoreHorizon(1)
                    ignoreActors(1)
                    init()
                    setCycle(Fwd)
                    setMotion(MoveTo 
                        (if (global147)
                            249
                        )(else
                            81
                        )
 99 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(3 32)
                )(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(3 33)
                    )(else
                        proc255_0(3 34)
                        = global148 4
                    )
                )
                (self:changeState(3))
            )
            (case 3
                (send newAct:
                    setLoop(
                        (if (== global135 3)
                            2
                        )(else
                            0
                        )
)
                    setMotion(MoveTo 
                        (if (global147)
                            249
                        )(else
                            81
                        )
 -16 self)
                )
            )
            (case 4
                (send global2:newRoom(12))
            )
        )
    )

)
(instance bleedScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:
                    view(193)
                    illegalBits(0)
                    setLoop(0)
                    cel(0)
                    cycleSpeed(2)
                    setCycle(End self)
                )
                = local2 proc255_0(3 35 91)
            )
            (case 1
                (send gEgo:
                    setLoop(1)
                    cel(0)
                    cycleSpeed(1)
                    setCycle(Fwd)
                )
                = seconds 4
                proc0_12()
            )
            (case 2
                (send gEgo:cycleSpeed(3))
                = cycles 25
            )
            (case 3
                (send gEgo:cycleSpeed(6))
                = seconds 4
            )
            (case 4
                (send gEgo:cycleSpeed(3))
                = cycles 25
            )
            (case 5
                (send gEgo:
                    cel(0)
                    setCycle(0)
                )
                proc0_10()
                proc255_0(3 36 67 -1 20 70 280)
                proc0_17(901 0 6 8)
            )
        )
    )

)
(instance motivator of Act
    (properties
        view 36
    )

    (method (init)
        (super:init())
        (self:
            setLoop(0)
            setCel(0)
            x(
                (if (== global135 1)
                    264
                )(else
                    96
                )
)
            y(115)
            setPri(7)
            stopUpd()
        )
    )


    (method (handleEvent pEvent)
        (if ((<> (send pEvent:type) 128) or (send pEvent:claimed))
            return 
        )
        (if (Said('look>'))
            (if (Said('/motivator,artifact,device'))
                (if (global186)
                    proc255_0(3 37)
                )(else
                    proc255_0(3 38)
                )
            )(else
                (if (Said('/plug[<modular,8,spaceware]') or Said('/spaceware[<8]'))
                    proc255_0(3 39)
                )(else
                    (if (Said('[<down,below,at][/dirt,deck]'))
                        proc255_0(3 40)
                    )
                )
            )
        )(else
            (if (Said('turn,get,manipulate,press,roll,drag/motivator,artifact,device'))
                proc255_0(3 41)
            )(else
                (if (Said('(turn<on),begin/motivator,artifact,device'))
                    proc255_0(3 42)
                )(else
                    (if (Said('press,drag,remove,get/plug[<modular,8,spaceware]'))
                        proc255_0(3 43)
                    )
                )
            )
        )
    )

)
(instance jupiter of Feature
    (properties
        y 75
        x 269
    )

    (method (handleEvent pEvent)
        (if ((send pEvent:claimed) or (<> (send pEvent:type) 128))
            return 
        )(else
            (if (Said('look/craft'))
                proc255_0(3 3)
            )
        )
    )

)
(instance bow of Feature
    (properties
        y 144
        x 61
    )

    (method (handleEvent pEvent)
        (if ((send pEvent:claimed) or (<> (send pEvent:type) 128))
            return 
        )(else
            (if (Said('look/craft,bow,tie,bow'))
                proc255_0(3 1)
            )
        )
    )

)
(instance bore of Feature
    (properties
        y 138
        x 212
    )

    (method (handleEvent pEvent)
        (if ((send pEvent:claimed) or (<> (send pEvent:type) 128))
            return 
        )(else
            (if (Said('look/craft,bore,implement'))
                proc255_0(3 44)
            )
        )
    )

)
(instance acme of Feature
    (properties
        y 85
        x 172
    )

    (method (handleEvent pEvent)
        (if ((send pEvent:claimed) or (<> (send pEvent:type) 128))
            return 
        )(else
            (if (Said('look/craft'))
                proc255_0(3 45)
            )
        )
    )

)
(instance fallTune of Sound
    (properties
        number 45
        priority 5
    )
)
