(version 2)
(include "sci.sh")
(exports
    0 rm006
)
(use "Main")
(use "Class_255_0")
(use "Chase")
(use "Avoid")
(use "Sound")
(use "Cycle")
(use "Game")
(use "User")
(use "Feature")
(use "Obj")
(script 6)


(local
    local0

)
(instance public rm006 of Rm
    (properties
        picture 6
        style 0
        horizon 10
    )

    (method (init)
        (var temp0[50])
        (self:setLocales(700))
        Load(128 7)
        Load(128 15)
        Load(128 18)
        Load(128 751)
        Load(128 192)
        Load(128 0)
        Load(132 77)
        (send gEgo:
            view(0)
            setStep(-1 1)
        )
        (super:init())
        (send gEgo:
            setAvoider((Avoid:new()))
            x(
                (if (== global12 5)
                    -6
                )(else
                    326
                )
)
            y(147)
            setMotion(MoveTo 
                (if (== global12 5)
                    400
                )(else
                    -400
                )
 147)
            init()
        )
        (User:prevDir(
            (if (== global12 5)
                3
            )(else
                7
            )
))
        (shadow:init())
        (if (proc0_13(1))
            (wire:init())
        )
    )


    (method (doit)
        (if ((((send gEgo:has(3)) and (send gEgo:inRect(160 146 171 150))) and not global131) and not (send global5:contains(rat)))
            (rat:init())
        )(else
            (if (< (send gEgo:x) -6)
                (send global2:newRoom(5))
            )(else
                (if (> (send gEgo:x) 326)
                    (send global2:newRoom(
                        (if (global157)
                            27
                        )(else
                            7
                        )
))
                )
            )
        )
        (super:doit())
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )
        (switch ((send pEvent:type))
            (case 128
                (if (Said('look>'))
                    (if (Said('[<up,above,at]/ceiling') or Said('<up,above[/ceiling]'))
                        proc255_0(6 0)
                    )(else
                        (if (Said('/partition'))
                            proc255_0(6 1)
                        )(else
                            (if (Said('/door,console[<absent]'))
                                proc255_0(6 2)
                            )(else
                                (if (Said('<below/console[<absent]'))
                                    proc255_0(6 3)
                                )(else
                                    (if (Said('[<down,below,at]/dirt,deck') or Said('<down,below[/dirt,deck]'))
                                        proc255_0(6 4)
                                    )(else
                                        (if (Said('[<around,at,in][/area,tube,cave,pit,stage,!*]'))
                                            proc255_0(6 5)
                                        )(else
                                            (if (Said('/cable<left,fine'))
                                                (if (proc0_13(1))
                                                    proc255_0(6 6)
                                                )
                                            )(else
                                                (if (Said('/cable[<bad,jagged,all]'))
                                                    (if (proc0_13(1))
                                                        proc255_0(6 7)
                                                    )(else
                                                        proc255_0(6 8)
                                                    )
                                                )(else
                                                    (if (Said('[<in,at,through,in]/grate'))
                                                        proc255_0(6 9)
                                                    )(else
                                                        (if (Said('/mice,animal'))
                                                            (if ((send global5:contains(rat)))
                                                                proc255_0(6 10)
                                                            )(else
                                                                (if (global131)
                                                                    proc255_0(6 11)
                                                                )(else
                                                                    proc255_0(6 12)
                                                                )
                                                            )
                                                        )(else
                                                            (if (Said('[<in,in,through,at]/cavity'))
                                                                proc255_0(6 13)
                                                            )(else
                                                                (if (Said('/conduit'))
                                                                    proc255_0(6 14)
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )(else
                    (if (Said('climb/craft,pit,craft,side'))
                        proc255_0(6 15)
                    )(else
                        (if (Said('get,(drag[<on])/cable'))
                            (if (proc0_13(1))
                                (if ((send gEgo:inRect(64 147 85 149)))
                                    (self:setScript(wireScript))
                                )(else
                                    proc255_0(6 16)
                                )
                            )(else
                                proc255_0(6 17)
                            )
                        )(else
                            (if (Said('get/conduit'))
                                proc255_0(6 18)
                            )(else
                                (if (Said('get,climb,crawl,conceal[<in,in,through,below]/grate'))
                                    proc255_0(6 19)
                                )(else
                                    (if (Said('press,hoist,manipulate,open,get,remove/console,(iron[<mushroom])'))
                                        proc255_0(6 20)
                                    )
                                )
                            )
                        )
                    )
                )
            )
            (case 1
                (if (== (User:controls) 0)
                    return 
                )
                (send gEgo:setMotion(MoveTo 
                    (if (< (send pEvent:x) 30)
                        -30
                    )(else
                        (if (> (send pEvent:x) 295)
                            330
                        )(else
                            (send pEvent:x)
                        )
                    )
 (send gEgo:y)))
                (send pEvent:claimed(1))
            )
            (case 64
                (if (== (User:controls) 0)
                    return 
                )
                (switch ((send pEvent:message))
                    (case 1
                        (send gEgo:setMotion(0))
                        (send pEvent:claimed(1))
                        return 
                    )
                    (case 5
                        (send gEgo:setMotion(0))
                        (send pEvent:claimed(1))
                        return 
                    )
                    (case 8
                        (send gEgo:setMotion(0))
                        (send pEvent:claimed(1))
                        return 
                    )
                    (case 2
                        (send gEgo:setMotion(0))
                        (send pEvent:claimed(1))
                        return 
                    )
                    (case 4
                        (send gEgo:setMotion(0))
                        (send pEvent:claimed(1))
                        return 
                    )
                    (case 6
                        (send gEgo:setMotion(0))
                        (send pEvent:claimed(1))
                        return 
                    )
                )
            )
        )
        (super:handleEvent(pEvent))
    )

)
(instance wireScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:
                    view(192)
                    loop(
                        (if (< (send gEgo:x) (wire:x))
                            1
                        )(else
                            0
                        )
)
                    cel(0)
                    setMotion(0)
                    cycleSpeed(2)
                    setCycle(End self)
                )
            )
            (case 1
                = cycles 5
            )
            (case 2
                (wire:dispose())
                (send gEgo:get(1))
                = cycles 2
            )
            (case 3
                (send gEgo:setCycle(Beg self))
            )
            (case 4
                (send gEgo:
                    view(0)
                    cycleSpeed(0)
                    setCycle(Walk)
                )
                = cycles 2
                (send global1:changeScore(5))
            )
            (case 5
                proc255_0(6 21)
                proc0_3()
                (send global2:setScript(0))
            )
        )
    )

)
(instance shadowScript of Script
    (properties)

    (method (doit)
        (if ((send gEgo:inRect(-9 145 56 150)) or (send gEgo:inRect(281 145 329 150)))
            (shadow:
                loop((send gEgo:loop))
                cel((send gEgo:cel))
            )
            (if ((send gEgo:inRect(-9 145 56 150)))
                (shadow:view(7))
            )(else
                (shadow:view(18))
            )
            (shadow:posn(
                (if ((send gEgo:inRect(-9 145 56 150)))
                    (+ (send gEgo:x) 12)
                )(else
                    (- (send gEgo:x) 12)
                )
 147))
            (if (<> local0 1)
                (shadow:show())
                = local0 1
            )
        )(else
            (shadow:hide())
            = local0 0
        )
        (super:doit())
    )

)
(instance ratScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (rat:setMotion(MoveTo 197 (+ (send gEgo:y) 4) self))
                = global131 1
            )
            (case 1
                (User:canInput(0))
                (rat:
                    setStep(-1 5)
                    setLoop(-1)
                    loop(1)
                    setCycle(Walk)
                    setMotion(Chase gEgo 4 self)
                )
            )
            (case 2
                proc0_2()
                (rumbleSound:play())
                (send gEgo:setMotion(0))
                (rat:
                    setStep(1 1)
                    posn((send gEgo:x) - (send gEgo:y) 4)
                    setLoop(3)
                    setCycle(Fwd)
                    setPri(14)
                )
                = seconds 2
            )
            (case 3
                (biff:init())
                = seconds 2
            )
            (case 4
                (biff:
                    setCel(1)
                    posn(+ (rat:x) 17 - (rat:y) 12)
                )
                = seconds 2
                (if ((send gEgo:has(3)))
                    proc0_14(3 15)
                    (send global1:changeScore(-15))
                )
                (if ((send gEgo:has(1)))
                    proc0_14(1 15)
                    (send global1:changeScore(-5))
                )
            )
            (case 5
                (biff:dispose())
                = seconds 2
            )
            (case 6
                (send gEgo:
                    view(751)
                    loop(0)
                )
                (rat:
                    setLoop(0)
                    x(+ (send gEgo:x) 13)
                    y(+ (send gEgo:y) 4)
                    setStep(10)
                    setMotion(MoveTo 310 + (send gEgo:y) 4 self)
                )
                (rumbleSound:stop())
            )
            (case 7
                (rat:dispose())
                proc0_10()
                proc0_3()
                (send gEgo:
                    view(0)
                    setDirection(0)
                )
                proc0_10()
                proc255_0(6 22)
            )
        )
    )

)
(instance rat of Act
    (properties
        view 15
    )

    (method (init)
        (super:init())
        (self:
            ignoreActors(1)
            illegalBits(0)
            setLoop(2)
            posn(197 78)
            setStep(5 15)
            setMotion(MoveTo 197 + (send gEgo:y) 4 self)
            setScript(ratScript)
        )
    )

)
(instance wire of View
    (properties
        view 192
        loop 2
    )

    (method (init)
        (super:init())
        (self:
            ignoreActors(1)
            posn(77 124)
        )
    )

)
(instance shadow of Prop
    (properties)

    (method (init)
        (super:init())
        (self:
            view(
                (if (== global12 5)
                    7
                )(else
                    18
                )
)
            setLoop(
                (if (== global12 5)
                    0
                )(else
                    1
                )
)
            ignoreActors(1)
            x(
                (if (== global12 5)
                    6
                )(else
                    314
                )
)
            y(147)
            setPri(4)
            setScript(shadowScript)
            ignoreActors(1)
        )
    )

)
(instance biff of View
    (properties
        view 15
    )

    (method (init)
        (super:init())
        (self:
            setLoop(4)
            setCel(0)
            setPri(15)
            ignoreActors(1)
            posn(- (rat:x) 15 - (rat:y) 22)
        )
    )

)
(instance rumbleSound of Sound
    (properties
        number 77
        priority 5
        loop -1
    )
)
