(version 2)
(include "sci.sh")
(exports
    0 Room46
)
(use "Main")
(use "Class_255_0")
(use "AView")
(use "Avoid")
(use "Sound")
(use "Cycle")
(use "Game")
(use "Feature")
(use "Obj")
(script 46)


(local
    local0
    gEgoY
    theGGEgoX

)
(instance lightning of Prop
    (properties)
)
(instance thunder of Sound
    (properties)
)
(instance public Room46 of Rm
    (properties
        picture 46
    )

    (method (init)
        = east 47
        = west 45
        = north 42
        = south 50
        Load(128 76)
        = global109 9
        = global591 global109
        Load(132 31)
        Load(132 32)
        Load(128 76)
        (super:init())
        = global116 0
        proc0_1()
        (send gEgo:
            view(0)
            observeControl(8192)
            init()
        )
        (lightning:
            view(69)
            loop(4)
            cel(0)
            posn(14 52)
            ignoreActors()
            setScript(flash)
            init()
        )
        (switch (global12)
            (case 42
                = global104 4
                (send gEgo:
                    posn(120 60)
                    view(68)
                    ignoreControl(8192 2048)
                    setPri(3)
                    setStep(1 1)
                )
            )
            (case 45
                (switch (global104)
                    (case 0
                        (send gEgo:
                            posn(1 (send gEgo:y))
                            setPri(-1)
                            view(0)
                        )
                    )
                    (case 1
                        = global104 3
                        (send gEgo:
                            posn(1 97)
                            setPri(3)
                            ignoreControl(8192)
                            looper(ScriptID(501 1))
                            view(82)
                        )
                    )
                    (case 2
                        = global104 4
                        (send gEgo:
                            posn(1 75)
                            ignoreControl(8192)
                            setStep(1 1)
                            setPri(3)
                            view(68)
                        )
                    )
                )
            )
            (case 47
                (switch (global104)
                    (case 0
                        (send gEgo:view(0))
                        (send gEgo:posn(318 (send gEgo:y)))
                    )
                    (case 1
                        (send gEgo:
                            posn(318 158)
                            view(82)
                            looper(ScriptID(501 1))
                            ignoreControl(8192)
                            setStep(2 1)
                            setPri(5)
                        )
                    )
                    (case 2
                        = global104 2
                        (send gEgo:
                            view(82)
                            ignoreControl(8192 2048)
                            setPri(5)
                        )
                        (if (< (send gEgo:y) 107)
                            (send gEgo:posn(318 110))
                        )(else
                            (send gEgo:posn(318 (send gEgo:y)))
                        )
                    )
                    (case 3
                        (send gEgo:
                            posn(318 80)
                            view(82)
                            looper(ScriptID(501 1))
                            ignoreControl(8192)
                            observeControl(2048)
                            setStep(2 1)
                            setPri(3)
                        )
                    )
                    (case 4
                        (send gEgo:
                            posn(318 61)
                            view(68)
                            ignoreControl(8192)
                            setPri(3)
                            setStep(1 1)
                        )
                    )
                )
            )
            (case 50
                = global104 0
                proc0_1()
                (send gEgo:
                    posn((send gEgo:x) 188)
                    ignoreControl(2048)
                    view(0)
                )
            )
            (default 
                (send gEgo:
                    posn(154 174)
                    observeControl(1024)
                )
            )
        )
        (self:setRegions(501))
        (if ((send global5:contains(gNewAct)))
            (send gNewAct:
                view(106)
                setCycle(Walk)
                observeControl(2)
                observeControl(8192 16 16384)
                posn(1000 1000)
                init()
            )
            = gGEgoX 23
            = gGEgoY 90
            (switch (global12)
                (case east
                    (send gNewAct:posn(359 175))
                )
                (case west
                    (send gNewAct:posn(-40 175))
                )
                (case south
                    (send gNewAct:posn(160 249))
                )
                (case north
                    (send gNewAct:posn(23 90))
                )
            )
            = global110 1
            (send (ScriptID(501 0)):notify(1))
        )(else
            (send (ScriptID(501 0)):notify(4))
        )
        (send global2:setScript(Actions))
    )


    (method (doit)
        (super:doit())
        (if (<> global11 global13)
            return 
        )
        = local0 (send gEgo:onControl(0))
        (if ((<> (self:script) duneFall) and (((& local0 $0008) and ((== global104 1) or (== global104 2))) or ((& local0 $4000) and (== global104 0))))
            proc0_2()
            (self:setScript(duneFall))
        )
        (if (<> (send global2:script) duneFall)
            (if (& local0 $0100)
                (send global2:newRoom(42))
            )(else
                (if (((== global116 2) and not global155) and not (& local0 $0002))
                    = global116 0
                    (if (proc501_2(16))
                        (send gEgo:posn((send gEgo:x) (+ (send gEgo:y) 5)))
                    )
                )(else
                    (if (((== global116 4) and not global155) and not (& local0 $0004))
                        = global116 0
                    )(else
                        (if (((== global116 16) and not global155) and not (& local0 $0010))
                            = global116 0
                            (if (proc501_2(8))
                                (send gEgo:posn((send gEgo:x) (+ (send gEgo:y) 5)))
                            )
                        )(else
                            (if (((== global116 32) and not global155) and not (& local0 $0020))
                                = global116 0
                            )(else
                                (if ((((& local0 $0002) and (== global104 0)) and not global155) and not global116)
                                    = global116 2
                                    = global104 1
                                    = gGEgoX (send gEgo:x)
                                    = gGEgoY (send gEgo:y)
                                    (if (IsObject((send gEgo:mover)))
                                        (if (gGEgoY)
                                            = gEgoY 400
                                            = theGGEgoX gGEgoX
                                        )(else
                                            = gEgoY (+ (- (send gEgo:y) (send ((send gEgo:mover)):y)) (send gEgo:y))
                                            = theGGEgoX (send ((send gEgo:mover)):x)
                                        )
                                    )(else
                                        = gEgoY (send gEgo:y)
                                        = theGGEgoX (send gEgo:x)
                                    )
                                    (send gEgo:
                                        view(82)
                                        xStep(2)
                                        yStep(1)
                                        looper(ScriptID(501 1))
                                        observeControl(2048)
                                        setMotion(MoveTo theGGEgoX gEgoY)
                                        setPri(5)
                                    )
                                )(else
                                    (if ((((& local0 $0010) and (== global104 0)) and not global155) and not global116)
                                        = global104 3
                                        = global116 16
                                        (if (IsObject((send gEgo:mover)))
                                            (if (gGEgoY)
                                                = gEgoY 400
                                                = theGGEgoX gGEgoX
                                            )(else
                                                = gEgoY (+ (- (send gEgo:y) (send ((send gEgo:mover)):y)) (send gEgo:y))
                                                = theGGEgoX (send ((send gEgo:mover)):x)
                                            )
                                        )(else
                                            = gEgoY (send gEgo:y)
                                            = theGGEgoX (send gEgo:x)
                                        )
                                        (send gEgo:
                                            view(82)
                                            xStep(2)
                                            yStep(1)
                                            ignoreControl(8192)
                                            observeControl(2048)
                                            looper(ScriptID(501 1))
                                            setMotion(MoveTo theGGEgoX gEgoY)
                                            setPri(3)
                                        )
                                    )(else
                                        (if ((((& local0 $0002) and (== global104 1)) and not global155) and not global116)
                                            = global116 2
                                            = global104 0
                                            (if (IsObject((send gEgo:mover)))
                                                (if (gGEgoY)
                                                    = gEgoY gGEgoY
                                                    = theGGEgoX gGEgoX
                                                )(else
                                                    = gEgoY (+ (- (send gEgo:y) (send ((send gEgo:mover)):y)) (send gEgo:y))
                                                    = theGGEgoX (send ((send gEgo:mover)):x)
                                                )
                                            )(else
                                                = gEgoY (send gEgo:y)
                                                = theGGEgoX (send gEgo:x)
                                            )
                                            (send gEgo:
                                                view(0)
                                                xStep(3)
                                                yStep(2)
                                                looper(0)
                                                observeControl(8192)
                                                ignoreControl(2048)
                                                setMotion(MoveTo theGGEgoX gEgoY)
                                                setPri(-1)
                                                moveSpeed(0)
                                            )
                                        )(else
                                            (if ((((& local0 $0010) and (== global104 3)) and not global155) and not global116)
                                                = global116 16
                                                = global104 0
                                                (if (IsObject((send gEgo:mover)))
                                                    (if (gGEgoY)
                                                        = gEgoY gGEgoY
                                                        = theGGEgoX gGEgoX
                                                    )(else
                                                        = gEgoY (+ (- (send gEgo:y) (send ((send gEgo:mover)):y)) (send gEgo:y))
                                                        = theGGEgoX (send ((send gEgo:mover)):x)
                                                    )
                                                )(else
                                                    = gEgoY (send gEgo:y)
                                                    = theGGEgoX (send gEgo:x)
                                                )
                                                (send gEgo:
                                                    view(0)
                                                    xStep(3)
                                                    yStep(2)
                                                    looper(0)
                                                    ignoreControl(2048)
                                                    observeControl(8192)
                                                    setMotion(MoveTo theGGEgoX gEgoY)
                                                    setPri(-1)
                                                    moveSpeed(0)
                                                )
                                            )(else
                                                (if ((((== global104 1) and (& local0 $0004)) and not global155) and not global116)
                                                    = global116 4
                                                    = global104 2
                                                    (if (IsObject((send gEgo:mover)))
                                                        (if (gGEgoY)
                                                            = gEgoY gGEgoY
                                                            = theGGEgoX gGEgoX
                                                        )(else
                                                            = gEgoY (+ (- (send gEgo:y) (send ((send gEgo:mover)):y)) (send gEgo:y))
                                                            = theGGEgoX (send ((send gEgo:mover)):x)
                                                        )
                                                    )(else
                                                        = gEgoY (send gEgo:y)
                                                        = theGGEgoX (send gEgo:x)
                                                    )
                                                    (send gEgo:
                                                        view(82)
                                                        looper(0)
                                                        setPri(5)
                                                        posn((send gEgo:x) - (send gEgo:y) 3)
                                                        observeControl(8192 2048)
                                                        setStep(2 1)
                                                        setMotion(MoveTo theGGEgoX gEgoY)
                                                    )
                                                )(else
                                                    (if ((((== global104 3) and (& local0 $0020)) and not global155) and not global116)
                                                        = global116 32
                                                        = global104 4
                                                        (if (IsObject((send gEgo:mover)))
                                                            (if (gGEgoY)
                                                                = gEgoY gGEgoY
                                                                = theGGEgoX gGEgoX
                                                            )(else
                                                                = gEgoY (+ (- (send gEgo:y) (send ((send gEgo:mover)):y)) (send gEgo:y))
                                                                = theGGEgoX (send ((send gEgo:mover)):x)
                                                            )
                                                        )(else
                                                            = gEgoY (send gEgo:y)
                                                            = theGGEgoX (send gEgo:x)
                                                        )
                                                        (send gEgo:
                                                            view(68)
                                                            posn((send gEgo:x) - (send gEgo:y) 3)
                                                            looper(0)
                                                            setStep(1 1)
                                                            setMotion(MoveTo theGGEgoX gEgoY)
                                                        )
                                                    )(else
                                                        (if ((((== global104 2) and (& local0 $0004)) and not global155) and not global116)
                                                            = global104 1
                                                            = global116 4
                                                            (if (IsObject((send gEgo:mover)))
                                                                (if (gGEgoY)
                                                                    = gEgoY -400
                                                                    = theGGEgoX gGEgoX
                                                                )(else
                                                                    = gEgoY (+ (- (send gEgo:y) (send ((send gEgo:mover)):y)) (send gEgo:y))
                                                                    = theGGEgoX (send ((send gEgo:mover)):x)
                                                                )
                                                            )(else
                                                                = gEgoY (send gEgo:y)
                                                                = theGGEgoX (send gEgo:x)
                                                            )
                                                            (send gEgo:
                                                                view(82)
                                                                xStep(2)
                                                                yStep(1)
                                                                posn((send gEgo:x) - (send gEgo:y) 3)
                                                                looper(ScriptID(501 1))
                                                                ignoreControl(8192)
                                                                observeControl(2048)
                                                                setMotion(MoveTo theGGEgoX gEgoY)
                                                                setPri(5)
                                                            )
                                                        )(else
                                                            (if ((((== global104 4) and (& local0 $0020)) and not global155) and not global116)
                                                                = global116 32
                                                                = global104 3
                                                                (if (IsObject((send gEgo:mover)))
                                                                    (if (gGEgoY)
                                                                        = gEgoY -400
                                                                        = theGGEgoX gGEgoX
                                                                    )(else
                                                                        = gEgoY (+ (- (send gEgo:y) (send ((send gEgo:mover)):y)) (send gEgo:y))
                                                                        = theGGEgoX (send ((send gEgo:mover)):x)
                                                                    )
                                                                )(else
                                                                    = gEgoY (send gEgo:y)
                                                                    = theGGEgoX (send gEgo:x)
                                                                )
                                                                (send gEgo:
                                                                    view(82)
                                                                    xStep(2)
                                                                    yStep(1)
                                                                    posn((send gEgo:x) - (send gEgo:y) 3)
                                                                    looper(ScriptID(501 1))
                                                                    ignoreControl(8192)
                                                                    observeControl(2048)
                                                                    setMotion(MoveTo theGGEgoX gEgoY)
                                                                    setPri(3)
                                                                )
                                                            )(else
                                                                (if ((((== global104 0) or (== global104 3)) and (== global116 0)) and proc501_2(global109))
                                                                    = global104 3
                                                                    = gEgoY 180
                                                                    = theGGEgoX (send gEgo:x)
                                                                    (send gEgo:
                                                                        setPri(3)
                                                                        posn((send gEgo:x) + (send gEgo:y) 8)
                                                                    )
                                                                    proc0_10()
                                                                    (send gEgo:
                                                                        view(82)
                                                                        looper(ScriptID(501 1))
                                                                        xStep(2)
                                                                        yStep(1)
                                                                        setMotion(MoveTo theGGEgoX gEgoY)
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )


    (method (handleEvent pEvent)
        (var temp0[5])
        (if ((send pEvent:claimed) or (== global155 1))
            return 1
        )
        return 
            (switch ((send pEvent:type))
                (case 128
                    (if (Said('look>'))
                        (if ((Said('/area') or Said('/around')) or Said('[<around][/!*]'))
                            proc255_0(46 0)
                        )(else
                            (if (Said('/cavity,pit,dune,bank,partition'))
                                proc255_0(46 1)
                            )
                        )
                    )
                )
            )
    )


    (method (newRoom newRoomNumber)
        DisposeScript(988)
        (if ((send global5:contains(gNewAct)) and (< (send gEgo:distanceTo(gNewAct)) 120))
            = global110 2
        )
        (if (not global155)
            (super:newRoom(newRoomNumber))
        )
    )

)
(instance Actions of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (default 
            )
        )
    )

)
(instance duneFall of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:
                    view(76)
                    looper(0)
                    setStep(5 5)
                    setLoop(0)
                    setAvoider(Avoid)
                    setPri(5)
                )
                (if (< (send gEgo:x) 210)
                    (send gEgo:setMotion(MoveTo 204 170 self))
                )(else
                    (if (< (send gEgo:x) 269)
                        (send gEgo:setMotion(MoveTo 252 170 self))
                    )(else
                        (send gEgo:setMotion(MoveTo 296 168 self))
                    )
                )
            )
            (case 1
                proc0_3()
                (send gEgo:
                    view(82)
                    setLoop(-1)
                    setAvoider(0)
                    setStep(2 1)
                )
                = global104 2
                (send global2:setScript(0))
            )
        )
    )

)
(instance flash of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = seconds Random(8 30)
            )
            (case 1
                (lightning:
                    cel(255)
                    setCycle(End self)
                )
            )
            (case 2
                (lightning:cel(0))
                = seconds Random(2 5)
            )
            (case 3
                (thunder:
                    priority(2)
                    number(Random(31 32))
                    play(self)
                )
            )
            (case 4
                = state -1
            )
        )
    )

)
