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


(local
    local0
    gEgoY
    theGGEgoX
    theTheGGEgoX
    local4
    local5

)
(instance lightning of Prop
    (properties)
)
(instance thunder of Sound
    (properties)
)
(instance public Room50 of Rm
    (properties
        picture 50
    )

    (method (init)
        = east 51
        = west 49
        = south 53
        = north 47
        = global109 1
        = global591 1
        = global116 0
        Load(132 31)
        Load(132 32)
        (super:init())
        (send gEgo:
            view(0)
            init()
        )
        (lightning:
            view(69)
            loop(4)
            cel(0)
            posn(185 58)
            setScript(flash)
            init()
        )
        (switch (global12)
            (case 46
                = global104 2
                (send gEgo:
                    posn(186 67)
                    view(68)
                    looper(0)
                    setPri(1)
                    setStep(1 1)
                    ignoreControl(8192)
                )
            )
            (case 49
                (send gEgo:observeControl(8192))
                (if ((> (send gEgo:y) 146) and (< (send gEgo:y) 155))
                    (send gEgo:posn(1 144))
                )(else
                    (send gEgo:posn(1 (send gEgo:y)))
                )
            )
            (case 51
                (switch (global104)
                    (case 1
                        (send gEgo:
                            view(82)
                            posn(317 (send gEgo:y))
                            ignoreControl(8192)
                            setStep(1 1)
                            setPri(1)
                        )
                    )
                    (case 2
                        (send gEgo:
                            view(68)
                            posn(317 (send gEgo:y))
                            setStep(1 1)
                            setPri(1)
                        )
                    )
                    (case 0
                        (send gEgo:
                            view(0)
                            posn(317 (send gEgo:y))
                            setStep(3 2)
                            observeControl(8192)
                            setPri(-1)
                        )
                    )
                )
            )
            (case 53
                proc0_1()
                (send gEgo:
                    view(0)
                    posn((send gEgo:x) 188)
                    observeControl(8192)
                )
            )
            (default 
                (send gEgo:
                    posn(180 98)
                    observeControl(8192)
                )
            )
        )
        (self:setRegions(501))
        (switch (global110)
            (case 1
                (if (== Random(1 3) 2)
                    = gNewAct (Act:new())
                    (send gNewAct:
                        posn(1000 1000)
                        init()
                    )
                    = gSeconds Random(2 10)
                )
            )
            (case 2
                = gNewAct (Act:new())
                (send gNewAct:
                    posn(1000 1000)
                    init()
                )
                = gSeconds 3
            )
        )
        (if ((send global5:contains(gNewAct)))
            (send gNewAct:
                view(106)
                setCycle(Walk)
                observeControl(2 8192)
                posn(1000 1000)
                init()
            )
            = gGEgoX 176
            = gGEgoY 85
            (switch (global12)
                (case east
                    (send gNewAct:posn(359 117))
                )
                (case west
                    (send gNewAct:posn(-40 117))
                )
                (case south
                    (send gNewAct:posn(160 249))
                )
                (case north
                    (send gNewAct:posn(176 85))
                )
            )
            = global110 1
            (send (ScriptID(501 0)):notify(1))
        )(else
            (send (ScriptID(501 0)):notify(4))
        )
        (send gEgo:observeControl(1024))
    )


    (method (doit)
        (super:doit())
        (if (<> global11 global13)
            return 
        )
        = local0 (send gEgo:onControl(0))
        (if (IsObject((send gEgo:mover)))
            = theTheGGEgoX (send ((send gEgo:mover)):x)
            = local4 (send ((send gEgo:mover)):y)
            = local5 1
        )(else
            = local5 0
        )
        (if ((== global116 2) and not (& local0 $0002))
            = global116 0
            (if (proc501_2(1))
                (send gEgo:posn((send gEgo:x) (+ (send gEgo:y) 5)))
            )
        )(else
            (if ((== global116 4) and not (& local0 $0004))
                (send gEgo:ignoreControl(4))
                = 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 (local5)
                        (if (gGEgoY)
                            = gEgoY 400
                            = theGGEgoX gGEgoX
                        )(else
                            = gEgoY (+ (- (send gEgo:y) local4) (send gEgo:y))
                            = theGGEgoX theTheGGEgoX
                        )
                    )(else
                        = gEgoY (send gEgo:y)
                        = theGGEgoX (send gEgo:x)
                    )
                    (send gEgo:
                        view(82)
                        looper(ScriptID(501 1))
                        xStep(2)
                        yStep(1)
                        setMotion(MoveTo theGGEgoX gEgoY)
                        setPri(1)
                        ignoreControl(8192)
                    )
                )(else
                    (if ((& local0 $0010) and (== global104 2))
                        (send global2:newRoom(46))
                    )(else
                        (if ((((& local0 $0002) and (== global104 1)) and not global155) and not global116)
                            = global116 2
                            = global104 0
                            (if (local5)
                                (if (gGEgoY)
                                    = gEgoY gGEgoY
                                    = theGGEgoX gGEgoX
                                )(else
                                    = gEgoY (+ (- (send gEgo:y) local4) (send gEgo:y))
                                    = theGGEgoX theTheGGEgoX
                                )
                            )(else
                                = gEgoY (send gEgo:y)
                                = theGGEgoX (send gEgo:x)
                            )
                            (send gEgo:
                                view(0)
                                xStep(3)
                                yStep(2)
                                looper(0)
                                setMotion(MoveTo theGGEgoX gEgoY)
                                setPri(-1)
                                observeControl(8192)
                                moveSpeed(0)
                            )
                        )(else
                            (if ((((== global104 1) and (& local0 $0004)) and not global155) and not global116)
                                = global116 4
                                = global104 2
                                (if (local5)
                                    (if (gGEgoY)
                                        = gEgoY gGEgoY
                                        = theGGEgoX gGEgoX
                                    )(else
                                        = gEgoY (+ (- (send gEgo:y) local4) (send gEgo:y))
                                        = theGGEgoX theTheGGEgoX
                                    )
                                )(else
                                    = gEgoY (send gEgo:y)
                                    = theGGEgoX (send gEgo:x)
                                )
                                (send gEgo:
                                    view(68)
                                    posn((send gEgo:x) - (send gEgo:y) 3)
                                    observeControl(4)
                                )
                                proc0_10()
                                (send gEgo:
                                    looper(0)
                                    setStep(1 1)
                                    setMotion(MoveTo theGGEgoX gEgoY)
                                )
                            )(else
                                (if ((((== global104 2) and (& local0 $0004)) and not global155) and not global116)
                                    = global116 4
                                    = global104 1
                                    (if (local5)
                                        (if (gGEgoY)
                                            = gEgoY -400
                                            = theGGEgoX gGEgoX
                                        )(else
                                            = gEgoY -400
                                            = theGGEgoX theTheGGEgoX
                                        )
                                    )(else
                                        = gEgoY (send gEgo:y)
                                        = theGGEgoX (send gEgo:x)
                                    )
                                    (send gEgo:
                                        view(82)
                                        posn((send gEgo:x) - (send gEgo:y) 3)
                                        observeControl(4)
                                    )
                                    proc0_10()
                                    (send gEgo:
                                        looper(ScriptID(501 1))
                                        setStep(2 1)
                                        setMotion(MoveTo theGGEgoX gEgoY)
                                        setPri(1)
                                        ignoreControl(8192)
                                    )
                                )(else
                                    (if (((<> global104 2) and (== global116 0)) and (((proc501_2(global109) or ((> (send gEgo:x) 217) and (< (send gEgo:y) 80))) or (((> (send gEgo:x) 87) and (< (send gEgo:x) 108)) and (< (send gEgo:y) 60))) or (< (send gEgo:y) 54)))
                                        = global104 1
                                        = gEgoY 180
                                        = theGGEgoX (send gEgo:x)
                                        (send gEgo:
                                            setPri(1)
                                            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)
                                            ignoreControl(8192)
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )


    (method (handleEvent pEvent)
        (var temp0[5])
        (if ((send pEvent:claimed))
            return 1
        )
        return 
            (switch ((send pEvent:type))
                (case 128
                    (if (Said('look>'))
                        (if ((Said('/area') or Said('/around')) or Said('[<around][/!*]'))
                            proc255_0(50 0)
                        )(else
                            (if (Said('/rock'))
                                proc255_0(50 1)
                            )(else
                                (if (Said('/dune'))
                                    proc255_0(50 2)
                                )(else
                                    (if (Said('/cavity'))
                                        proc255_0(50 3)
                                    )
                                )
                            )
                        )
                    )(else
                        (if (Said('/cavity'))
                            proc255_0(50 4)
                        )
                    )
                )
            )
    )


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

)
(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
            )
        )
    )

)
