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


(local
    gEgoViewer
    local1
    local2

)
(instance wave1 of Prop
    (properties)
)
(instance wave2 of Prop
    (properties)
)
(instance wave3 of Prop
    (properties)
)
(instance waves of List
    (properties)
)
(instance public Room19 of Rm
    (properties
        picture 19
    )

    (method (init)
        = north 13
        = south 25
        = east 20
        = west 31
        = horizon 104
        = global101 0
        (if (global100)
            = picture 119
        )
        (send gEgo:edgeHit(0))
        (super:init())
        = local2 (+ (* (- global160 global213) 60) (- global159 global214))
        (if ((send ((Inv:at(9))):ownedBy(203)) and (>= local2 3))
            = global118 (/ (= global118 Random(1 30)) 10)
        )
        (if (== global118 3)
            (send (= gNewAct (Act:new())):
                posn(293 117)
                view(174)
                loop(2)
                setCel(0)
                illegalBits(0)
                setPri(14)
                init()
            )
        )
        (self:setRegions(516 503 501 504))
        Load(rsVIEW 174)
        Load(rsVIEW 17)
        Load(rsVIEW 33)
        (wave1:
            view(666)
            loop(0)
            cel(0)
            posn(183 74)
            setPri(0)
            ignoreActors()
            cycleSpeed(3)
            init()
        )
        (wave2:
            view(666)
            loop(1)
            cel(0)
            posn(188 108)
            setPri(0)
            ignoreActors()
            cycleSpeed(3)
            init()
        )
        (wave3:
            view(666)
            loop(2)
            cel(0)
            posn(189 153)
            setPri(0)
            ignoreActors()
            cycleSpeed(3)
            init()
        )
        (waves:add(wave1 wave2 wave3))
        (wave1:setScript(waveActions))
        Load(rsVIEW 2)
        Load(rsVIEW 17)
        Load(rsVIEW 33)
        (if (== (send gEgo:view()) 2)
            = global105 0
        )(else
            = global107 0
        )
        (send gEgo:illegalBits(49152))
        (switch (global105)
            (case 0
                (
                (switch (gPicture)
                    (case 25
                        (
                        (if (> (send gEgo:x()) 210)
                            (send gEgo:
                                x(293)
                                y(188)
                            )
                            (send gEgo:
                                illegalBits(32768)
                                setPri(14)
                            )
                            = global107 11
                        )(else
                            (send gEgo:
                                x(212)
                                y(188)
                            )
                            = global107 0
                        )
 )
                    )
                    (case 13
                        (
                        (if (< (send gEgo:x()) 245)
                            = global107 0
                            (send gEgo:
                                x(215)
                                y(+ horizon (+ (send gEgo:yStep()) 1))
                            )
                        )(else
                            (send gEgo:
                                x(286)
                                y(+ horizon (+ (send gEgo:yStep()) 1))
                            )
                            (send gEgo:
                                setPri(14)
                                illegalBits(32768)
                            )
                            = global107 11
                        )
 )
                    )
                    (case 20
                        ((send gEgo:
                            setPri(14)
                            illegalBits(32768)
                        )
 = global107 11 = global105 0 
                        (if (< (send gEgo:y()) horizon)
                            (send gEgo:
                                x(318)
                                y(+ horizon 2)
                            )
                        )(else
                            (send gEgo:x(318))
                        )
 )
                    )
                    (default 
                        (= global107 11 (send gEgo:
                            x(318)
                            y(160)
                        )
 (send gEgo:illegalBits(32768)) (send gEgo:setPri(14)) )
                    )
                )
  )
            )
            (case 1
                (
                (switch (gPicture)
                    (case 25
                        (= global107 0 (send gEgo:
                            x(151)
                            y(188)
                        )
  )
                    )
                    (case 13
                        (= global107 0 (send gEgo:
                            x(180)
                            y(+ horizon (+ (send gEgo:yStep()) 1))
                        )
 )
                    )
                )
  )
            )
            (case 2
                (
                (switch (gPicture)
                    (case 25
                        (= global107 0 (send gEgo:
                            x(88)
                            y(188)
                        )
  )
                    )
                    (case 13
                        (= global107 0 (send gEgo:
                            x(152)
                            y(+ horizon (+ (send gEgo:yStep()) 1))
                        )
 )
                    )
                )
  )
            )
            (case 3
                (
                (switch (gPicture)
                    (case 25
                        (= global107 0 (send gEgo:
                            x(31)
                            y(188)
                        )
  )
                    )
                    (case 13
                        (= global107 0 (send gEgo:
                            x(128)
                            y(+ horizon (+ (send gEgo:yStep()) 1))
                        )
 )
                    )
                )
  )
            )
            (case 4
                (
                (switch (gPicture)
                    (case 25
                        ((send gEgo:
                            x(5)
                            y(188)
                        )
  )
                    )
                    (case 13
                        ((send gEgo:
                            x(104)
                            y(+ horizon (+ (send gEgo:yStep()) 1))
                        )
  )
                    )
                    (case 31
                        (
                        (if (< (send gEgo:y()) horizon)
                            (send gEgo:
                                x(1)
                                y(+ 1 horizon)
                            )
                        )(else
                            (send gEgo:x(1))
                        )
 )
                    )
                )
 )
            )
        )
        (send gEgo:init())
        = gEgoViewer (send gEgo:viewer())
    )


    (method (doit)
        (super:doit())
        (if (== global107 11)
            (if ((send gEgo:inRect(254 104 316 115)))
                (send gEgo:setPri(12))
            )(else
                (if ((<> global105 10) and (== (send gEgo:edgeHit()) 0))
                    (send gEgo:setPri(14))
                )
            )
        )
        (if ((== (send global2:script()) 0) and (== global107 11))
            (if (& (send gEgo:onControl(0)) $2000)
                (doFall:doit())
                (self:setScript(fallLmagenta))
            )(else
                (if (& (send gEgo:onControl(0)) $1000)
                    (doFall:doit())
                    (self:setScript(fallLred))
                )(else
                    (if (& (send gEgo:onControl(0)) $0100)
                        (doFall:doit())
                        (self:setScript(fallGrey))
                    )(else
                        (if (& (send gEgo:onControl(0)) $0080)
                            (doFall:doit())
                            (self:setScript(fallLgrey))
                        )(else
                            (if (& (send gEgo:onControl(0)) $0010)
                                (doFall:doit())
                                (self:setScript(fallRed))
                            )(else
                                (if (& (send gEgo:onControl(0)) $0040)
                                    (doFall:doit())
                                    (self:setScript(fallBrown))
                                )(else
                                    (if (& (send gEgo:onControl(0)) $0004)
                                        (doFall:doit())
                                        (self:setScript(fallGreen))
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )


    (method (dispose)
        (send gSounds:eachElementDo(172))
        (waves:dispose())
        (send gEgo:setPri(-1))
        (super:dispose())
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed()))
            return 1
        )
        return 
            (if ((== (send pEvent:type()) 128) and Said('look>'))
                (if (Said('/grass'))
                    Print(19 0)
                )(else
                    (if (Said('/cliff'))
                        Print(19 1)
                    )(else
                        (if (Said('[<around][/room]'))
                            Print(19 2)
                        )
                    )
                )
            )(else
                0
            )
    )


    (method (newRoom param1)
        (if ((send gCast:contains(gNewAct)))
            = global213 global160
            = global214 global159
        )
        (if (<> global105 10)
            (send gEgo:
                setPri(-1)
                illegalBits(32768)
            )
            (super:newRoom(param1))
        )
    )

)
(instance fallLmagenta of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() = global105 10 (send gEgo:
                    viewer(0)
                    illegalBits(0)
                    setPri(11)
                    yStep(10)
                    setLoop(1)
                    cel(0)
                    view(17)
                    posn((send gEgo:x()) - (send gEgo:y()) 4)
                    setMotion(MoveTo (send gEgo:x()) + (send gEgo:y()) 40 self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    view(33)
                    setLoop(0)
                    cel(0)
                )
 Animate((send gCast:elements()) 0) kernel[106](10 1) = seconds 5  )
            )
            (case 2
                (Print(19 3) = global127 1 )
            )
        )
    )

)
(instance fallLred of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() = global105 10 (send gEgo:
                    viewer(0)
                    setPri(13)
                    yStep(10)
                    setLoop(1)
                    cel(0)
                    view(17)
                    illegalBits(0)
                    setCycle(Fwd)
                    posn(- (send gEgo:x()) 12 (send gEgo:y()))
                    setMotion(MoveTo 222 170 self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    view(33)
                    setLoop(0)
                    cel(0)
                )
 Animate((send gCast:elements()) 0) kernel[106](10 1) = seconds 5  )
            )
            (case 2
                (Print(19 4) = seconds 5  )
            )
            (case 3
                (= global127 1 )
            )
        )
    )

)
(instance fallGrey of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() = global105 10 (send gEgo:
                    viewer(0)
                    illegalBits(0)
                    setPri(13)
                    yStep(10)
                    setLoop(1)
                    cel(0)
                    view(17)
                    setCycle(Fwd)
                    posn(- (send gEgo:x()) 8 (send gEgo:y()))
                    setMotion(MoveTo 263 173 self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    view(33)
                    setLoop(0)
                    cel(0)
                )
 Animate((send gCast:elements()) 0) kernel[106](10 1) = seconds 5  )
            )
            (case 2
                (Print(19 5) = seconds 5  )
            )
            (case 3
                (= global127 1 )
            )
        )
    )

)
(instance fallLgrey of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() = global105 10 (send gEgo:
                    viewer(0)
                    illegalBits(0)
                    setPri(13)
                    yStep(10)
                    xStep(8)
                    setLoop(1)
                    cel(0)
                    view(17)
                    setCycle(Fwd)
                    posn((send gEgo:x()) - (send gEgo:y()) 5)
                    setMotion(MoveTo 270 173 self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    view(33)
                    setLoop(0)
                    cel(0)
                )
 Animate((send gCast:elements()) 0) kernel[106](10 1) = seconds 5  )
            )
            (case 2
                (Print(19 4) = seconds 5  )
            )
            (case 3
                (= global127 1 )
            )
        )
    )

)
(instance fallRed of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() = global105 10 (send gEgo:
                    viewer(0)
                    illegalBits(0)
                    setPri(13)
                    yStep(10)
                    xStep(8)
                    setLoop(1)
                    cel(0)
                    view(17)
                    setCycle(Fwd)
                    posn((send gEgo:x()) - (send gEgo:y()) 5)
                    setMotion(MoveTo (send gEgo:x()) 178 self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    view(33)
                    setLoop(0)
                    cel(0)
                )
 Animate((send gCast:elements()) 0) kernel[106](10 1) = seconds 5  )
            )
            (case 2
                (Print(19 4) = seconds 5  )
            )
            (case 3
                (= global127 1 )
            )
        )
    )

)
(instance fallBrown of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() = global105 10 (send gEgo:
                    viewer(0)
                    illegalBits(0)
                    setPri(14)
                    yStep(10)
                    setLoop(1)
                    cel(0)
                    view(17)
                    setCycle(Fwd)
                    posn(- (send gEgo:x()) 8 (send gEgo:y()))
                    setMotion(MoveTo 239 187 self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    view(33)
                    setLoop(0)
                    cel(0)
                )
 Animate((send gCast:elements()) 0) kernel[106](10 1) = seconds 3  )
            )
            (case 2
                (Print(19 6) = seconds 5  )
            )
            (case 3
                (= global127 1 )
            )
        )
    )

)
(instance fallGreen of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() = global105 10 (send gEgo:
                    viewer(0)
                    illegalBits(0)
                    setPri(14)
                    yStep(10)
                    setLoop(1)
                    cel(0)
                    view(17)
                    setCycle(Fwd)
                    posn(- (send gEgo:x()) 8 (send gEgo:y()))
                    setMotion(MoveTo 240 219 self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    view(33)
                    setLoop(0)
                    cel(0)
                )
 Animate((send gCast:elements()) 0) kernel[106](10 1) = seconds 5  )
            )
            (case 2
                (Print(19 7) = seconds 5  )
            )
            (case 3
                (= global127 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)) )
            )
        )
    )

)
(instance doFall of Code
    (properties)

    (method (doit)
        (send gSounds:eachElementDo(172))
        (send ((Sound:new())):
            number(51)
            loop(1)
            play()
        )
        (if ((send gCast:contains(gNewAct)))
            (send gNewAct:setCycle(0))
        )
    )

)
