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


(local
    newAct
    gEgoX
    gEgoY
    local3
    local4
    local5

)
(instance public rm002 of Rm
    (properties
        picture 2
        horizon 70
        east 5
        south 3
    )

    (method (init)
        (var temp0[50])
        (if (((((== global12 777) or (== global12 900)) or (== global12 1)) or (== global12 155)) or (== GameIsRestarting() 1))
            (send gLongSong:stop())
            = local4 1
        )
        = global193 0
        = global17 0
        (if (<> global12 12)
            (self:setLocales(700))
        )
        Load(128 12)
        Load(128 0)
        Load(128 6)
        Load(132 11)
        Load(132 76)
        (if (== global149 global11)
            Load(128 36)
            (motivator:init())
        )
        (if (== global12 12)
            proc0_2()
            Load(128 258)
            (self:setScript(grabScript))
        )(else
            Load(128 0)
            (TheMenuBar:
                state(1)
                draw()
            )
            (SL:enable())
            (if (local4)
                Load(130 991)
                = local3 991
                Load(128 11)
                Load(132 4)
                Load(132 5)
                Load(132 56)
                (send gEgo:
                    view(11)
                    loop(0)
                    cel(0)
                    setPri(9)
                    ignoreActors(1)
                    illegalBits(0)
                    posn(141 111)
                    get(0)
                )
                proc0_2()
                (self:setScript(doorScript))
            )
            (if ((global200 and (== global12 900)) and not local4)
                proc0_3()
                (send gEgo:
                    view(0)
                    setLoop(-1)
                    loop(2)
                    cel(0)
                    ignoreActors(1)
                    illegalBits(-32768)
                    setStep(3 2)
                    posn(142 141)
                    get(0)
                )
                = gEgoX (send gEgo:x)
                = gEgoY (send gEgo:y)
                = global159 0
                (send gLongSong:
                    number(11)
                    loop(-1)
                    play()
                )
            )
            (if (== global12 3)
                (send gEgo:x(170))
            )
            (send gEgo:init())
        )
        (door:init())
        (super: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 (dispose)
        (if (((<> global12 5) and (<> global12 12)) and (<> global12 3))
            DisposeScript(991)
        )
        (super:dispose())
    )


    (method (handleEvent pEvent)
        (super:handleEvent(pEvent))
        (if ((send pEvent:claimed))
            return 
        )
        (switch ((send pEvent:type))
            (case 128
                (if (Said('close/door'))
                    proc255_0(2 0)
                )(else
                    (if (Said('look>'))
                        (if (Said('<in,through/craft,chute,pane[<escape]'))
                            proc255_0(2 1)
                        )(else
                            (if (Said('/pane'))
                                proc255_0(2 2)
                            )(else
                                (if (Said('/door,door'))
                                    proc255_0(2 3)
                                )(else
                                    (if (Said('/nozzle'))
                                        proc255_0(2 4)
                                    )(else
                                        (if (Said('/craft,chute[<escape]'))
                                            proc255_0(2 5)
                                        )(else
                                            (if (Said('[<at,around,in][/area,!*]'))
                                                proc255_0(2 6)
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )(else
                        (if (Said('smell[/area,air]'))
                            proc255_0(2 7)
                        )(else
                            (if (Said('fix,open,pry/craft,chute,door[<escape]'))
                                proc255_0(2 8)
                            )(else
                                (if (Said('hoist,manipulate,press,drag/craft,chute[<escape]'))
                                    proc255_0(2 9)
                                )(else
                                    (if (Said('begin/chute,craft,engine'))
                                        proc255_0(2 10)
                                    )(else
                                        (if (Said('break/pane,glass'))
                                            proc255_0(2 11)
                                        )(else
                                            (if (Said('climb/craft,chute[<escape]'))
                                                proc255_0(2 12)
                                            )(else
                                                (if (Said('climb'))
                                                    proc255_0(2 13)
                                                )(else
                                                    (if (Said('climb,get<in,in/craft,chute[<escape]') or Said('enter,board[/craft,chute[<escape]]'))
                                                        proc255_0(2 14)
                                                    )(else
                                                        (if (Said('qa'))
                                                            (if (not global200)
                                                                (send pEvent:claimed(0))
                                                                return 
                                                            )
                                                            (switch (= local5 proc255_0(2 15 30 1 80 "QA-O-Matic" 81 "Space" 1 81 "Phleebhut" 2 81 "Ortega" 3 81 "Pestulon" 4 81 "End" 5))
                                                                (case 1
                                                                    = global136 4
                                                                    (send ((send global9:at(3))):moveTo(14))
                                                                    (send ((send global9:at(1))):moveTo(14))
                                                                    = global149 0
                                                                    = global135 4
                                                                    = global203 1
                                                                    = global210 1
                                                                    = global207 1
                                                                    = global208 2
                                                                    = global206 3
                                                                    = global15 134
                                                                    (send global1:changeScore(1))
                                                                    proc0_10()
                                                                    (send global2:newRoom(14))
                                                                )
                                                                (case 2
                                                                    = global136 4
                                                                    (send ((send global9:at(3))):moveTo(14))
                                                                    (send ((send global9:at(1))):moveTo(14))
                                                                    = global149 0
                                                                    = global135 4
                                                                    = global210 6
                                                                    = global214 39
                                                                    = global213 39
                                                                    = global161 3
                                                                    = global162 4
                                                                    = global163 3
                                                                    = global164 4
                                                                    proc0_10()
                                                                    (send global2:newRoom(21))
                                                                )
                                                                (case 3
                                                                    = global136 4
                                                                    (send ((send global9:at(3))):moveTo(14))
                                                                    (send ((send global9:at(1))):moveTo(14))
                                                                    = global149 0
                                                                    = global135 4
                                                                    = global210 5
                                                                    = global214 82
                                                                    = global213 82
                                                                    = global161 10
                                                                    = global162 7
                                                                    = global163 10
                                                                    = global164 7
                                                                    proc0_10()
                                                                    (send global2:newRoom(21))
                                                                )
                                                                (case 4
                                                                    = global136 4
                                                                    (send ((send global9:at(3))):moveTo(14))
                                                                    (send ((send global9:at(1))):moveTo(14))
                                                                    = global149 0
                                                                    = global135 4
                                                                    proc0_14(0 0)
                                                                    = global210 8
                                                                    = global214 69
                                                                    = global213 69
                                                                    = global161 9
                                                                    = global162 6
                                                                    = global163 9
                                                                    = global164 6
                                                                    proc0_10()
                                                                    (send global2:newRoom(21))
                                                                )
                                                                (case 5
                                                                    = global136 4
                                                                    (send ((send global9:at(3))):moveTo(14))
                                                                    (send ((send global9:at(1))):moveTo(14))
                                                                    = global149 0
                                                                    = global135 4
                                                                    = global210 7
                                                                    = global214 69
                                                                    = global213 69
                                                                    = global161 9
                                                                    = global162 6
                                                                    = global163 9
                                                                    = global164 6
                                                                    proc0_10()
                                                                    (send global2:newRoom(94))
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )

)
(instance doorScript of Script
    (properties)

    (method (doit)
        (if ((== (self:state) 19) and (== (doorSound:state) 0))
            (self:cue())
        )
        (super:doit())
    )


    (method (changeState newState)
        (var temp0[50])
        (switch (= state newState)
            (case 0
                (send gEgo:stopUpd())
                = seconds 3
            )
            (case 1
                (doorSound:play())
                = cycles 20
            )
            (case 2
                (door:setCycle(End self))
            )
            (case 3
                (door:stopUpd())
                = cycles 8
            )
            (case 4
                (send gEgo:
                    setPri(10)
                    cycleSpeed(1)
                    setCycle(End self)
                )
            )
            (case 5
                = cycles 7
            )
            (case 6
                (send gEgo:
                    loop(1)
                    cel(0)
                    setCycle(CT 4 1 self)
                )
            )
            (case 7
                = cycles 7
            )
            (case 8
                (send gEgo:setCycle(End self))
            )
            (case 9
                = cycles 10
            )
            (case 10
                (send gEgo:
                    loop(2)
                    cel(0)
                    setCycle(0)
                )
                = cycles 10
            )
            (case 11
                (send gEgo:
                    loop(2)
                    cel(0)
                    setCycle(CT 1 1 self)
                )
            )
            (case 12
                (send gEgo:
                    cycleSpeed(0)
                    setStep(-1 10)
                    setMotion(JumpTo 142 141 self)
                )
            )
            (case 13
                (send gEgo:setCycle(End self))
                (thump:play())
            )
            (case 14
                = cycles 7
            )
            (case 15
                (send gEgo:setCel((- (send gEgo:cel) 1)))
                = cycles 5
            )
            (case 16
                (send gEgo:
                    view(0)
                    loop(2)
                    cel(0)
                    illegalBits(-32768)
                    setStep(-1 2)
                    setCycle(Walk)
                    setPri(-1)
                )
                = gEgoX (send gEgo:x)
                = gEgoY (send gEgo:y)
                = global159 0
                = cycles 10
            )
            (case 17
                proc255_0(2 16 67 -1 20 70 280)
                (door:
                    setPri(9)
                    setCycle(Beg self)
                )
                = cycles 2
            )
            (case 18
                (doorSound:
                    number(5)
                    play()
                )
            )
            (case 19
                (door:stopUpd())
            )
            (case 20
                (door:
                    setLoop(1)
                    forceUpd()
                )
                = seconds 2
            )
            (case 21
                proc0_3()
                (send gLongSong:
                    number(11)
                    loop(-1)
                    play()
                )
            )
        )
    )

)
(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(
                        (if (global147)
                            13
                        )(else
                            10
                        )
)
                    setStep(1 2)
                    x(
                        (if (global147)
                            166
                        )(else
                            72
                        )
)
                    y(-16)
                    illegalBits(0)
                    ignoreHorizon(1)
                    ignoreActors(1)
                    init()
                    setCycle(Fwd)
                    setMotion(MoveTo 
                        (if (global147)
                            166
                        )(else
                            72
                        )
 153 self)
                )
            )
            (case 1
                (if (== global147 0)
                    (send newAct:setPri(13))
                )
                (Timer:set(self 2))
            )
            (case 2
                (if (== global147 0)
                    (send newAct:setPri(10))
                )
                (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(2 17)
                )(else
                    (if ((== global149 global11) and (== global135 global147))
                        (send gLongSong:
                            number(76)
                            loop(1)
                            play()
                        )
                        (send global1:changeScore(15))
                        (send newAct:setLoop(2))
                        (motivator:hide())
                        = global149 0
                        = global135 3
                        = global148 5
                        proc0_10()
                        proc255_0(2 18)
                    )(else
                        proc255_0(2 19)
                        = global148 4
                    )
                )
                (self:changeState(3))
            )
            (case 3
                (send newAct:
                    setLoop(
                        (if (== global135 3)
                            2
                        )(else
                            0
                        )
)
                    setMotion(MoveTo 
                        (if (global147)
                            166
                        )(else
                            72
                        )
 -16 self)
                )
            )
            (case 4
                (send global2:newRoom(12))
            )
        )
    )

)
(instance motivator of Act
    (properties)

    (method (init)
        (super:init())
        (self:
            view(36)
            setLoop(0)
            setCel(0)
            x(
                (if (== global135 1)
                    183
                )(else
                    87
                )
)
            y(169)
            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(2 20)
                )(else
                    proc255_0(2 21)
                )
            )(else
                (if (Said('/plug[<modular,8,spaceware]') or Said('/spaceware[<8]'))
                    proc255_0(2 22)
                )(else
                    (if (Said('[<down,below,at]/dirt,deck') or Said('<down,below,at[/dirt,deck]'))
                        proc255_0(2 23)
                    )
                )
            )
        )(else
            (if (Said('(turn<on),begin/motivator,artifact,device'))
                proc255_0(2 24)
            )(else
                (if (Said('turn,get,manipulate,press,roll,drag/device,motivator,artifact'))
                    proc255_0(2 25)
                )(else
                    (if (Said('remove,drag,press,get/plug[<modular,8,spaceware]'))
                        proc255_0(2 26)
                    )
                )
            )
        )
    )

)
(instance door of Prop
    (properties
        view 12
    )

    (method (init)
        (super:init())
        (self:
            cycleSpeed(1)
            setLoop(
                (if (local4)
                    0
                )(else
                    1
                )
)
            setPri(
                (if (((== global12 5) or (== global12 3)) or not local4)
                    9
                )(else
                    10
                )
)
            ignoreActors(1)
            posn(138 115)
            stopUpd()
        )
    )

)
(instance thump of Sound
    (properties
        number 56
        priority 2
    )
)
(instance doorSound of Sound
    (properties
        number 4
    )
)
