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


(local
    local0
    gEgoY
    gEgoX

)
(instance lightning of Prop
    (properties)
)
(instance thunder of Sound
    (properties)
)
(instance public Room45 of Rm
    (properties
        picture 45
    )

    (method (init)
        = north 41
        = west 48
        = south 49
        = east 46
        = global109 17
        = global591 global109
        (self:setRegions(501))
        Load(132 31)
        Load(132 32)
        (super:init())
        = global116 0
        (send gEgo:init())
        (lightning:
            view(69)
            loop(4)
            cel(0)
            posn(218 54)
            setScript(flash)
            init()
        )
        (switch (global12)
            (case 41
                = global104 2
                (send gEgo:
                    posn(165 55)
                    view(68)
                    setPri(4)
                    looper(0)
                    setStep(1 1)
                )
            )
            (case 49
                = global104 0
                (send gEgo:view(0))
                (send gEgo:posn((send gEgo:x) 188))
            )
            (case 46
                (switch (global104)
                    (case 0
                        (send gEgo:
                            posn(318 (send gEgo:y))
                            setStep(3 2)
                            setPri(-1)
                        )
                    )
                    (case 3
                        = global104 1
                        (send gEgo:
                            posn(318 100)
                            setPri(4)
                            setStep(2 1)
                            looper(ScriptID(501 1))
                            ignoreControl(8192)
                        )
                    )
                    (case 4
                        = global104 2
                        (send gEgo:
                            view(68)
                            posn(318 80)
                            looper(0)
                            setStep(1 1)
                            setPri(4)
                        )
                    )
                )
            )
            (case 48
                (switch (global104)
                    (case 0
                        proc0_1()
                        (send gEgo:
                            view(0)
                            posn(1 (send gEgo:y))
                        )
                    )
                    (case 1
                        (send gEgo:
                            posn(1 111)
                            setPri(4)
                            setStep(2 1)
                            looper(ScriptID(501 1))
                            ignoreControl(8192)
                        )
                    )
                    (case 2
                        (send gEgo:
                            view(68)
                            posn(1 89)
                            looper(0)
                            setStep(1 1)
                            setPri(4)
                        )
                    )
                )
            )
            (default 
                (send gEgo:
                    view(0)
                    posn(160 160)
                )
            )
        )
        (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)
                posn(1000 1000)
                hide()
                init()
            )
            = gGEgoX_4 113
            = gGEgoY_3 113
            (switch (global12)
                (case east
                    (send gNewAct:posn(359 140))
                )
                (case west
                    (send gNewAct:posn(-40 140))
                )
                (case south
                    (send gNewAct:posn(160 249))
                )
                (case north
                    (send gNewAct:posn(113 113))
                )
            )
            = global110 1
            (send (ScriptID(501 0)):notify(1))
        )(else
            (send (ScriptID(501 0)):notify(4))
        )
    )


    (method (doit)
        (super:doit())
        (if (<> global11 global13)
            return 
        )
        = local0 (send gEgo:onControl(0))
        (if (& local0 $0008)
            (send global2:newRoom(41))
        )(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
                    (send gEgo:ignoreControl(4))
                )(else
                    (if ((((& local0 $0002) and not global155) and (== global104 0)) and not global116)
                        = global104 1
                        = gGEgoX_4 (send gEgo:x)
                        = gGEgoY_3 (send gEgo:y)
                        = global116 2
                        (if (IsObject((send gEgo:mover)))
                            (if (gGEgoY_4)
                                = gEgoY 400
                            )(else
                                = gEgoY (+ (- (send gEgo:y) (send ((send gEgo:mover)):y)) (send gEgo:y))
                                = gEgoX (send ((send gEgo:mover)):x)
                            )
                        )(else
                            = gEgoY (send gEgo:y)
                            = gEgoX (send gEgo:x)
                        )
                        (send gEgo:
                            view(82)
                            looper(ScriptID(501 1))
                            xStep(2)
                            yStep(1)
                            setMotion(MoveTo gEgoX gEgoY)
                            setPri(4)
                            ignoreControl(8192)
                        )
                    )(else
                        (if ((((& local0 $0002) and not global155) and (== global104 1)) and not global116)
                            = global104 0
                            = global116 2
                            (if (IsObject((send gEgo:mover)))
                                (if (gGEgoY_4)
                                    = gEgoY gGEgoY_4
                                    = gEgoX gGEgoX_5
                                )(else
                                    = gEgoY (+ (- (send gEgo:y) (send ((send gEgo:mover)):y)) (send gEgo:y))
                                    = gEgoX (send ((send gEgo:mover)):x)
                                )
                            )(else
                                = gEgoY (send gEgo:y)
                                = gEgoX (send gEgo:x)
                            )
                            (send gEgo:
                                view(0)
                                xStep(3)
                                yStep(2)
                                looper(0)
                                setMotion(MoveTo gEgoX gEgoY)
                                setPri(-1)
                                observeControl(8192)
                                moveSpeed(0)
                            )
                        )(else
                            (if ((((== global104 1) and not global155) and (& local0 $0004)) and not global116)
                                = global116 4
                                = global104 2
                                (if (IsObject((send gEgo:mover)))
                                    (if (gGEgoY_4)
                                        = gEgoY gGEgoY_4
                                        = gEgoX gGEgoX_5
                                    )(else
                                        = gEgoY (+ (- (send gEgo:y) (send ((send gEgo:mover)):y)) (send gEgo:y))
                                        = gEgoX (send ((send gEgo:mover)):x)
                                    )
                                )(else
                                    = gEgoY (send gEgo:y)
                                    = gEgoX (send gEgo:x)
                                )
                                (send gEgo:
                                    view(68)
                                    posn((send gEgo:x) - (send gEgo:y) 3)
                                    observeControl(4)
                                )
                                proc0_10()
                                (send gEgo:
                                    setStep(1 1)
                                    looper(0)
                                    setPri(4)
                                    setMotion(MoveTo gEgoX gEgoY)
                                )
                            )(else
                                (if ((((== global104 2) and not global155) and (& local0 $0004)) and not global116)
                                    = global104 1
                                    = global116 4
                                    (if (IsObject((send gEgo:mover)))
                                        (if (gGEgoY_4)
                                            = gEgoY -400
                                            = gEgoX gGEgoX_5
                                        )(else
                                            = gEgoY (+ (- (send gEgo:y) (send ((send gEgo:mover)):y)) (send gEgo:y))
                                            = gEgoX (send ((send gEgo:mover)):x)
                                        )
                                    )(else
                                        = gEgoY (send gEgo:y)
                                        = gEgoX (send gEgo:x)
                                    )
                                    (send gEgo:
                                        view(82)
                                        posn((send gEgo:x) - (send gEgo:y) 3)
                                        observeControl(4)
                                    )
                                    proc0_10()
                                    (send gEgo:
                                        view(82)
                                        looper(ScriptID(501 1))
                                        xStep(2)
                                        yStep(1)
                                        setMotion(MoveTo gEgoX gEgoY)
                                        setPri(4)
                                        ignoreControl(8192)
                                    )
                                )(else
                                    (if (((<> global104 2) and (== global116 0)) and proc501_2(global109))
                                        = global104 1
                                        = gEgoY 180
                                        = gEgoX (send gEgo:x)
                                        (send gEgo:
                                            setPri(4)
                                            posn((send gEgo:x) + (send gEgo:y) 8)
                                        )
                                        proc0_10()
                                        (send gEgo:
                                            view(82)
                                            looper(ScriptID(501 1))
                                            xStep(4)
                                            yStep(1)
                                            setMotion(MoveTo gEgoX gEgoY)
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )


    (method (handleEvent pEvent)
        (var temp0[5])
        (if ((send pEvent:claimed))
            return 1
        )
        return 
            (switch ((send pEvent:type))
                (case 128
                    (if (Said('look>') and ((Said('/area') or Said('/around')) or Said('[<around][/!*]')))
                        proc255_0(45 0)
                    )
                )
            )
    )


    (method (newRoom newRoomNumber)
        proc0_1()
        DisposeScript(988)
        (if ((send global5:contains(gNewAct)) and (< (send gEgo:distanceTo(gNewAct)) 120))
            = 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
            )
        )
    )

)
