(version 2)
(include "sci.sh")
(exports
    0 rm040
)
(use "Main")
(use "Class_255_0")
(use "Sound")
(use "Cycle")
(use "Game")
(use "TheMenuBar")
(use "Feature")
(use "Obj")
(script 40)


(local
    local0[2]

)
(instance public rm040 of Rm
    (properties
        picture 40
    )

    (method (init)
        (var temp0[50])
        proc0_2()
        = global159 1
        (TheMenuBar:
            hide()
            state(0)
        )
        (SL:disable())
        Load(128 61)
        Load(128 62)
        Load(132 58)
        (super:init())
        (arnsBod:
            init()
            addToPic()
        )
        (arnsLegs:
            init()
            addToPic()
        )
        (arnsHead:
            init()
            stopUpd()
        )
        (arnsArm:
            init()
            stopUpd()
        )
        (topHatch:init())
        (midHatch:init())
        (bottomHatch:init())
        (self:setScript(rmScript))
    )


    (method (handleEvent pEvent)
        (super:handleEvent(pEvent))
        (if ((<> (send pEvent:type) 128) or (send pEvent:claimed))
            return 
        )
        (if (Said('look[/area]'))
            proc255_0(40 0)
        )
    )

)
(instance rmScript of Script
    (properties)

    (method (doit)
        (if ((== (termMusic:prevSignal) 10) and (== (self:state) 0))
            (self:cue())
        )(else
            (if ((== (termMusic:prevSignal) 20) and (== (self:state) 2))
                (self:cue())
            )(else
                (if ((== (termMusic:prevSignal) 30) and (== (self:state) 9))
                    (self:cue())
                )(else
                    (if ((== (termMusic:prevSignal) 40) and (== (self:state) 10))
                        (self:cue())
                    )(else
                        (if ((== (termMusic:prevSignal) 50) and (== (self:state) 11))
                            (self:cue())
                        )(else
                            (if ((== (termMusic:prevSignal) 60) and (== (self:state) 12))
                                (self:cue())
                            )(else
                                (if ((== (termMusic:prevSignal) 70) and (== (self:state) 13))
                                    (self:cue())
                                )(else
                                    (if ((== (termMusic:prevSignal) 80) and (== (self:state) 14))
                                        (self:cue())
                                    )(else
                                        (if ((== (termMusic:prevSignal) 90) or (== (termMusic:prevSignal) -1))
                                            (if (== global124 0)
                                                (send gLongSong:fade())
                                                = global159 0
                                                proc0_3()
                                                (TheMenuBar:
                                                    draw()
                                                    state(1)
                                                )
                                                (SL:enable())
                                                (send global2:newRoom(49))
                                            )(else
                                                (self:cue())
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
        (super:doit())
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (termMusic:play())
                (if (== global124 0)
                    = cycles 5
                )
            )
            (case 1
                (topHatch:setCycle(End))
                (midHatch:setCycle(End))
                (bottomHatch:setCycle(End self))
            )
            (case 2
                (topHatch:dispose())
                (midHatch:dispose())
                (bottomHatch:dispose())
            )
            (case 3
                (arnsHead:setCycle(End self))
            )
            (case 4
                (if (== global124 0)
                    = cycles 2
                )(else
                    = cycles 14
                )
            )
            (case 5
                (arnsArm:setCycle(End self))
            )
            (case 6
                (if (== global124 0)
                    = cycles 2
                )(else
                    = cycles 23
                )
            )
            (case 7
                (arnsHead:setCycle(Beg))
                (arnsArm:setCycle(Beg self))
            )
            (case 8
                (if (== global124 0)
                    = cycles 2
                )(else
                    = cycles 13
                )
            )
            (case 9
                (send global2:drawPic(40 8))
                (arnsHead:dispose())
                (arnsArm:dispose())
            )
            (case 10
                (firstSteps:
                    cel(0)
                    init()
                )
            )
            (case 11
                (firstSteps:
                    cel(1)
                    addToPic()
                )
            )
            (case 12
                (step1:addToPic())
            )
            (case 13
                (step2:addToPic())
            )
            (case 14
                (step3:addToPic())
            )
            (case 15
                (step4:addToPic())
            )
            (case 16
                (send gLongSong:fade())
                = global159 0
                proc0_3()
                (TheMenuBar:
                    draw()
                    state(1)
                )
                (SL:enable())
                (send global2:newRoom(49))
            )
        )
    )

)
(instance topHatch of Prop
    (properties)

    (method (init)
        (self:
            view(62)
            setLoop(0)
            setCel(0)
            ignoreActors(1)
            posn(113 60)
            setPri(5)
            cycleSpeed(1)
        )
        (super:init())
    )

)
(instance midHatch of Prop
    (properties)

    (method (init)
        (super:init())
        (self:
            view(62)
            setLoop(1)
            setCel(0)
            ignoreActors(1)
            posn(199 113)
            setPri(5)
            cycleSpeed(1)
        )
    )

)
(instance bottomHatch of Prop
    (properties)

    (method (init)
        (super:init())
        (self:
            view(62)
            setLoop(2)
            setCel(0)
            ignoreActors(1)
            posn(113 175)
            setPri(5)
            cycleSpeed(1)
        )
    )

)
(instance arnsHead of Prop
    (properties)

    (method (init)
        (super:init())
        (self:
            view(61)
            setLoop(2)
            setCel(0)
            ignoreActors(1)
            posn(155 17)
            setPri(4)
            cycleSpeed(
                (if (== global124 0)
                    0
                )(else
                    1
                )
)
        )
    )

)
(instance arnsArm of Prop
    (properties)

    (method (init)
        (super:init())
        (self:
            view(61)
            setLoop(1)
            setCel(0)
            ignoreActors(1)
            posn(116 64)
            setPri(4)
            cycleSpeed(
                (if (== global124 0)
                    0
                )(else
                    1
                )
)
        )
    )

)
(instance arnsBod of View
    (properties)

    (method (init)
        (super:init())
        (self:
            view(61)
            setLoop(0)
            setCel(0)
            ignoreActors(1)
            posn(157 94)
            setPri(4)
        )
    )

)
(instance arnsLegs of View
    (properties)

    (method (init)
        (super:init())
        (self:
            view(61)
            setLoop(0)
            setCel(1)
            ignoreActors(1)
            posn(154 166)
            setPri(4)
        )
    )

)
(instance firstSteps of View
    (properties
        view 853
    )

    (method (init)
        (super:init())
        (self:
            loop(0)
            posn(131 187)
        )
    )

)
(instance step1 of View
    (properties
        view 853
    )

    (method (init)
        (super:init())
        (self:
            loop(1)
            cel(1)
            posn(205 181)
        )
    )

)
(instance step2 of View
    (properties
        view 853
    )

    (method (init)
        (super:init())
        (self:
            loop(1)
            cel(0)
            posn(237 187)
        )
    )

)
(instance step3 of View
    (properties
        view 853
    )

    (method (init)
        (super:init())
        (self:
            loop(1)
            cel(1)
            posn(268 181)
        )
    )

)
(instance step4 of View
    (properties
        view 853
    )

    (method (init)
        (super:init())
        (self:
            loop(1)
            cel(0)
            posn(300 187)
        )
    )

)
(instance termMusic of Sound
    (properties
        number 58
        priority 5
    )
)
