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


(local
    gEgoOnControl
    local1

)
(instance waves of List
    (properties)
)
(instance wave1 of Prop
    (properties)
)
(instance wave2 of Prop
    (properties)
)
(instance wave3 of Prop
    (properties)
)
(instance public Room41 of Rm
    (properties
        picture 41
    )

    (method (init)
        = north 35
        = south 32
        = east 31
        = west 40
        = horizon 80
        = global101 0
        (send gEgo:edgeHit(0))
        (super:init())
        (self:setRegions(505 501 503 504))
        (wave1:
            view(664)
            loop(0)
            cel(3)
            posn(150 126)
            setPri(0)
            setCycle(Fwd)
            ignoreActors()
            cycleSpeed(1)
            init()
        )
        (wave2:
            view(664)
            loop(1)
            cel(2)
            posn(112 166)
            setPri(0)
            setCycle(Fwd)
            ignoreActors()
            cycleSpeed(1)
            init()
        )
        (wave3:
            view(664)
            loop(2)
            cel(3)
            posn(37 176)
            setPri(0)
            setCycle(Fwd)
            ignoreActors()
            cycleSpeed(1)
            init()
        )
        (waves:add(wave1 wave2 wave3))
        (wave1:setScript(waveActions))
        (switch (gPicture)
            (case 38
                ((send gEgo:
                    x(19)
                    y(98)
                )
  )
            )
            (case 35
                (
                (if (== (send gEgo:view()) 2)
                    (send gEgo:posn(117 107))
                )(else
                    (if (== (send gEgo:view()) 5)
                        (send gEgo:posn(186 113))
                    )(else
                        (if (== (send gEgo:view()) 6)
                            (send gEgo:posn(186 113))
                        )(else
                            (if (== (send gEgo:view()) 7)
                                (send gEgo:posn(201 113))
                            )(else
                                (if (== (send gEgo:view()) 8)
                                    (send gEgo:posn(237 113))
                                )(else
                                    (send gEgo:posn(182 113))
                                )
                            )
                        )
                    )
                )
 )
            )
            (case 31
                ((send gEgo:posn(318 110))  )
            )
            (case 32
                ((send gEgo:
                    x(138)
                    y(188)
                )
  )
            )
            (case 40
                ((send gEgo:posn(1 (send gEgo:y()))) )
            )
        )
        (send gEgo:
            xStep(2)
            yStep(1)
            init()
        )
        (send ((send gEgo:viewer())):doit())
    )


    (method (doit)
        (super:doit())
        (if ((& (= gEgoOnControl (send gEgo:onControl())) $0040) and ((<= (send gEgo:heading()) 90) or (>= (send gEgo:heading()) 270)))
            (send global2:newRoom(35))
        )
        (if (& gEgoOnControl $0010)
            (send global2:newRoom(38))
        )
    )


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


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

)
(instance waveActions of Script
    (properties)

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

)
(instance waveActions of Script
    (properties)

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

)
