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


(local
    newProp
    newView
    local2
    local3

)
(instance wave1 of Prop
    (properties)
)
(instance wave2 of Prop
    (properties)
)
(instance wave3 of Prop
    (properties)
)
(instance waves of List
    (properties)
)
(instance minBlock of Blk
    (properties
        top 115
        left 262
        bottom 121
        right 266
    )
)
(instance public Room13 of Rm
    (properties
        picture 13
    )

    (method (init)
        = north 7
        = south 19
        = east 14
        = west 31
        = horizon 80
        = global101 0
        (if (global100)
            = picture 113
        )
        (send gEgo:edgeHit(0))
        (super:init())
        (wave1:
            isExtra(1)
            view(665)
            loop(3)
            cel(2)
            posn(133 92)
            setPri(0)
            ignoreActors()
            cycleSpeed(3)
            init()
        )
        (wave2:
            isExtra(1)
            view(665)
            loop(4)
            cel(3)
            posn(126 121)
            setPri(0)
            ignoreActors()
            cycleSpeed(3)
            init()
        )
        (wave3:
            isExtra(1)
            view(665)
            loop(5)
            cel(1)
            posn(127 150)
            setPri(0)
            ignoreActors()
            cycleSpeed(3)
            init()
        )
        (waves:add(wave1 wave2 wave3))
        (wave1:setScript(waveActions))
        = local3 (+ (* (- global160 global213) 60) (- global159 global214))
        (if ((send ((Inv:at(9))):ownedBy(203)) and (>= local3 3))
            = global118 (/ (= global118 Random(1 30)) 10)
        )
        (if (== global118 1)
            (send (= gNewAct (Act:new())):
                posn(264 119)
                view(174)
                loop(2)
                setCel(0)
                illegalBits(0)
                init()
            )
            (send gEgo:observeBlocks(minBlock))
        )
        (self:setRegions(501 516 503 504 506))
        (if ((== global116 1) and not global100)
            (send (= newView (View:new())):
                view(534)
                setLoop(0)
                setCel(0)
                posn(65 55)
                init()
                addToPic()
            )
        )
        = newProp (Prop:new())
        (send newProp:
            view(625)
            posn(173 30)
            setLoop(1)
            setCycle(Fwd)
            cycleSpeed(2)
            init()
        )
        (if (== gPicture 14)
            = global105 0
        )
        (switch (global105)
            (case 0
                (
                (switch (gPicture)
                    (case 19
                        (
                        (if (> (send gEgo:x()) 233)
                            (send gEgo:
                                x(278)
                                y(188)
                            )
                        )(else
                            (send gEgo:
                                x(205)
                                y(188)
                            )
                        )
 )
                    )
                    (case 7
                        (
                        (if (> (send gEgo:x()) 208)
                            (send gEgo:
                                x(194)
                                y(+ horizon 2)
                            )
                        )(else
                            (send gEgo:posn(148 (+ horizon 2)))
                        )
 )
                    )
                    (case 14
                        (
                        (if (< (send gEgo:y()) horizon)
                            (send gEgo:
                                x(318)
                                y(+ horizon 2)
                            )
                        )(else
                            (send gEgo:x(318))
                        )
 )
                    )
                )
  )
            )
            (case 1
                (
                (switch (gPicture)
                    (case 19
                        ((send gEgo:
                            x(88)
                            y(188)
                        )
  )
                    )
                    (case 7
                        ((send gEgo:
                            x(133)
                            y(+ horizon 2)
                        )
 )
                    )
                )
  )
            )
            (case 2
                (
                (switch (gPicture)
                    (case 19
                        ((send gEgo:
                            x(88)
                            y(188)
                        )
  )
                    )
                    (case 7
                        ((send gEgo:
                            x(124)
                            y(+ horizon 2)
                        )
 )
                    )
                )
  )
            )
            (case 3
                (
                (switch (gPicture)
                    (case 19
                        ((send gEgo:
                            x(45)
                            y(188)
                        )
  )
                    )
                    (case 7
                        ((send gEgo:
                            x(108)
                            y(+ horizon 2)
                        )
 )
                    )
                )
  )
            )
            (case 4
                (
                (switch (gPicture)
                    (case 19
                        ((send gEgo:
                            x(16)
                            y(188)
                        )
  )
                    )
                    (case 7
                        (
                        (if (> (send gEgo:x()) 75)
                            (send gEgo:
                                x(75)
                                y(+ horizon 2)
                            )
                        )(else
                            (send gEgo:y((+ horizon (+ (send gEgo:yStep()) 1))))
                        )
 )
                    )
                    (case 31
                        (
                        (if (<= (send gEgo:y()) horizon)
                            (send gEgo:
                                x(1)
                                y(+ horizon 2)
                            )
                        )(else
                            (send gEgo:x(1))
                        )
 )
                    )
                )
 )
            )
        )
        (send gEgo:init())
    )


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


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed()))
            return 1
        )
        return 
            (if ((== (send pEvent:type()) 128) and Said('look>'))
                (if (Said('/grass'))
                    Print(13 0)
                )(else
                    (if (Said('/dock'))
                        (if (== global116 1)
                            Print(13 1)
                        )(else
                            Print(13 2)
                        )
                    )(else
                        (if (Said('/cottage'))
                            Print(13 2)
                        )(else
                            (if (Said('/fisherman,man,fishwife,person'))
                                (if ((send gCast:contains(gNewAct)))
                                    (send pEvent:claimed(0))
                                )(else
                                    (if (== global116 1)
                                        Print(13 3)
                                    )(else
                                        Print(13 4)
                                    )
                                )
                            )(else
                                (if (Said('[<around][/room]'))
                                    Print(13 5)
                                )
                            )
                        )
                    )
                )
            )(else
                0
            )
    )


    (method (newRoom param1)
        (if ((send gCast:contains(gNewAct)))
            = global213 global160
            = global214 global159
        )
        (super:newRoom(param1))
    )

)
(instance waveActions of Script
    (properties)

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

)
