(include "sci.sh")
(use "Main")
(use "Class_255_0")
(use "Cycle")
(use "Game")
(use "PV")
(use "Obj")
(script 40)


(local
    local0
    newProp
    newView

)
(instance waves of List
    (properties)
)
(instance wave1 of Prop
    (properties)
)
(instance wave2 of Prop
    (properties)
)
(instance public Room40 of Rm
    (properties
        picture 40
    )

    (method (init)
        = north 37
        = south 32
        = east 41
        = west 39
        = horizon 98
        = global101 0
        (super:init())
        (self:setRegions(505 501 503 504))
        (send gEgo:edgeHit(0))
        = newProp (Prop:new())
        = newView (View:new())
        (wave1:
            view(664)
            loop(3)
            cel(0)
            posn(40 178)
            setPri(0)
            ignoreActors()
            cycleSpeed(3)
            init()
        )
        (wave2:
            view(664)
            loop(4)
            cel(2)
            posn(280 178)
            setPri(0)
            ignoreActors()
            cycleSpeed(3)
            init()
        )
        (waves:add(wave1 wave2))
        (wave1:setScript(waveActions))
        (send newProp:
            view(650)
            loop(2)
            cel(2)
            posn(61 85)
            setPri(0)
            ignoreActors()
            setCycle(Fwd)
            init()
        )
        (send newView:
            view(613)
            loop(1)
            cel(0)
            posn(156 78)
            setPri(4)
            init()
            addToPic()
        )
        (if (== gPicture 32)
            (send gEgo:
                x(160)
                y(188)
            )
        )(else
            (if (== gPicture 39)
                (send gEgo:
                    x(1)
                    y((send gEgo:y()))
                )
            )(else
                (if (== gPicture 41)
                    (send gEgo:
                        x(318)
                        y((send gEgo:y()))
                    )
                )(else
                    (if (== gPicture 37)
                        (send gEgo:
                            x(158)
                            y(+ horizon (+ (send gEgo:yStep()) 1))
                        )
                    )
                )
            )
        )
        (send gEgo:
            xStep(2)
            yStep(1)
            init()
        )
        (send ((send gEgo:viewer())):doit())
    )


    (method (dispose)
        (waves:
            dispose()
            delete()
        )
        (super:dispose())
    )


    (method (handleEvent pEvent)
        (if ((== (send pEvent:type()) 128) and Said('look[<around][/room,island]'))
            Print(40 0)
        )
    )

)
(instance waveActions of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= local0 0 (while (< local0 (waves:size()))(send ((View:new())):
                        view((send ((waves:at(local0))):view()))
                        loop((send ((waves:at(local0))):loop()))
                        cel(0)
                        setPri(0)
                        ignoreActors()
                        x((send ((waves:at(local0))):x()))
                        y((send ((waves:at(local0))):y()))
                        init()
                        addToPic()
                        yourself()
                    )
 ++local0  ) = local0 0 
                (if (global190)
                    (self:changeState(1))
                )(else
                    (waves:eachElementDo(356))
                )
 )
            )
            (case 1
                ((send ((waves:at(local0))):
                    cel(0)
                    show()
                    setCycle(End self)
                )
  )
            )
            (case 2
                ((send ((waves:at(local0))):hide()) 
                (if (< local0 (- (waves:size()) 1))
                    ++local0
                )(else
                    = local0 0
                )
 (waveActions:changeState(1)) )
            )
        )
    )

)
