(version 2)
(include "sci.sh")
(exports
    0 rm52
)
(use "Main")
(use "Class_255_0")
(use "n958")
(use "Rev")
(use "Jump")
(use "Cycle")
(use "Game")
(use "User")
(use "PicView")
(use "Obj")
(script 52)


(local
    local0
    local1

)
(procedure (localproc_1440)
    (if (== (send gEgo:view) 14)
        proc255_0(52 27)
    )(else
        (if (((< 159 (send gEgo:x)) and (< (send gEgo:x) 252)) and (> (send gEgo:y) 125))
            proc255_0(52 41)
        )(else
            proc255_0(52 26)
        )
    )
)


(instance public rm52 of Rm
    (properties
        picture 52
        north 49
        west 51
    )

    (method (init)
        proc958_0(128 1 6 9 13 14 252 68)
        proc958_0(132 72 96 14 64)
        (self:style(
            (switch (gGNumber)
                (case north
                    8
                )
                (case east
                    2
                )
            )
))
        (weed1:
            setCycle(Fwd)
            setPri(0)
            init()
            ignoreActors()
        )
        (weed2:
            setCycle(Rev)
            setPri(0)
            init()
            ignoreActors()
        )
        (weed3:
            setCycle(Fwd)
            setPri(0)
            init()
            ignoreActors()
        )
        (weed4:
            setCycle(Rev)
            init()
            ignoreActors()
        )
        (if (not >= global101 1)
            (weed1:stopUpd())
            (weed2:stopUpd())
            (weed3:stopUpd())
            (weed4:stopUpd())
        )
        (super:init())
        (send gAddToPics:
            add(trunk)
            eachElementDo(#init)
            doit()
        )
        (switch (gGNumber)
            (case west
                (send gEgo:
                    posn(14 58)
                    illegalBits(-32512)
                    loop(0)
                )
                proc0_1()
            )
            (default 
                (send gEgo:
                    ignoreActors()
                    illegalBits(-32768)
                    posn(204 20)
                    setMotion(MoveTo 204 130)
                    setCycle(Fwd)
                    setPri(-1)
                    view(6)
                )
                = global130 4
                = local0 300
                (send (ScriptID(0 23)):
                    number(72)
                    loop(-1)
                    play()
                )
            )
        )
        (send gEgo:init())
    )


    (method (doit)
        (var temp0)
        (if (((== global130 4) and global136) and not --global136)
            (send global2:setScript(drowning))
        )
        (if (== (send gEgo:view) 6)
            (if (((< (send gEgo:y) 148) or (> (send gEgo:y) 158)) or (< (send gEgo:x) 140))
                (send gEgo:illegalBits(-32768))
            )(else
                (send gEgo:illegalBits(0))
            )
        )
        (if (script)
            (send script:doit())
        )(else
            = temp0 
                (switch ((send ((User:alterEgo)):edgeHit))
                    (case 1
                        north
                    )
                    (case 2
                        east
                    )
                    (case 3
                        south
                    )
                    (case 4
                        west
                    )
                )
            (if (temp0)
                (send (ScriptID(0 23)):fade())
                (self:newRoom(temp0))
            )(else
                (if (& (send gEgo:onControl(1)) $4000)
                    (send global2:setScript(upToSurface))
                )(else
                    (if ((((== (send gEgo:view) 0) or (== (send gEgo:view) 36)) and (& (send gEgo:onControl(1)) $0400)) and not gTLHandsOff)
                        (send global2:setScript(fallInWater))
                    )(else
                        (if (local0)
                            --local0
                            (if (== (send gEgo:view) 6)
                                (switch ((send gEgo:loop))
                                    (case 3
                                        (send gEgo:setStep(1 3))
                                    )
                                    (case 2
                                        (send gEgo:setStep(1 1))
                                    )
                                    (case 0
                                        (send gEgo:setStep(3 1))
                                    )
                                    (case 1
                                        (send gEgo:setStep(3 1))
                                    )
                                )
                            )
                        )(else
                            (if (== (send gEgo:view) 6)
                                (send global2:setScript(drownEgo))
                            )
                        )
                    )
                )
            )
        )
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )(else
            (if ((super:handleEvent(pEvent)))
                return 
            )(else
                (if (Said('smell,smell/'))
                    (if (== (send gEgo:view) 6)
                        proc255_0(52 0)
                        (send global2:setScript(drownEgo))
                    )(else
                        (send pEvent:claimed(0))
                    )
                )(else
                    (if (Said('dive'))
                        (switch ((send gEgo:view))
                            (case 14
                                proc255_0(52 1)
                            )
                            (case 6
                                proc255_0(52 2)
                            )
                            (case 13
                                (send global2:setScript(goDiving))
                            )
                            (default 
                                proc255_0(52 3)
                            )
                        )
                    )(else
                        (if (Said('swim<cease'))
                            (switch ((send gEgo:view))
                                (case 14
                                    proc255_0(52 4)
                                )
                                (case 13
                                    proc255_0(52 5)
                                )
                                (default 
                                    proc255_0(52 6)
                                )
                            )
                        )(else
                            (if (Said('swim'))
                                (switch ((send gEgo:view))
                                    (case 13
                                        proc255_0(52 7)
                                    )
                                    (case 14
                                        = global130 4
                                        (send (ScriptID(0 21)):
                                            number(51)
                                            loop(-1)
                                            init()
                                            play()
                                        )
                                        (send gEgo:
                                            show()
                                            view(13)
                                            illegalBits(-24576)
                                            setStep(1 1)
                                            setCycle(Fwd)
                                            setLoop(-1)
                                            setCel(-1)
                                            setPri(-1)
                                            cycleSpeed(0)
                                        )
                                        = global136 3000
                                        (send global2:setScript(0))
                                        proc0_3()
                                    )
                                    (case 6
                                        proc255_0(52 2)
                                    )
                                    (default 
                                        (send global2:setScript(goSwimming))
                                    )
                                )
                            )(else
                                (if (Said('climb,climb[<in]/water'))
                                    (if (not global130)
                                        proc255_0(52 8)
                                    )(else
                                        proc255_0(52 9)
                                    )
                                )(else
                                    (if (Said('climb,climb,get,get<out') or Said('exit/water'))
                                        (switch ((send gEgo:view))
                                            (case 14
                                                proc255_0(52 10)
                                            )
                                            (case 6
                                                proc255_0(52 11)
                                            )
                                            (case 13
                                                (send global2:setScript(getOutaWater))
                                            )
                                            (default 
                                                proc255_0(52 3)
                                            )
                                        )
                                    )(else
                                        (if (Said('climb,climb[/!*]'))
                                            proc255_0(52 12)
                                        )(else
                                            (if (Said('get,get/chest'))
                                                proc255_0(52 13)
                                            )(else
                                                (if (Said('enter,(get,get,jump<in)/water'))
                                                    proc255_0(52 14)
                                                )(else
                                                    (if (Said('enter,(get,get,jump<in)'))
                                                        proc255_0(52 15)
                                                    )(else
                                                        (if (Said('get,get/water') or Said('fill/bucket'))
                                                            (if (== (send gEgo:view) 14)
                                                                proc255_0(52 16)
                                                            )(else
                                                                (if (not (& (send gEgo:onControl(1)) $2000) and not proc999_5((send gEgo:view) 6 13))
                                                                    proc255_0(52 17)
                                                                )(else
                                                                    (if ((send gEgo:has(8)))
                                                                        (if (proc0_12(9))
                                                                            proc255_0(52 18)
                                                                        )(else
                                                                            (if (proc999_5((send gEgo:view) 6 13))
                                                                                proc255_0(52 19)
                                                                            )(else
                                                                                (self:setScript(fillBucket))
                                                                            )
                                                                            proc0_20(1)
                                                                        )
                                                                    )(else
                                                                        proc255_0(52 20)
                                                                    )
                                                                )
                                                            )
                                                        )(else
                                                            (if (Said('get,get/drink') or Said('drink[/water]'))
                                                                (if (== (send gEgo:view) 14)
                                                                    proc255_0(52 21)
                                                                )(else
                                                                    (if (not (& (send gEgo:onControl(1)) $2000) and not proc999_5((send gEgo:view) 6 13))
                                                                        (if ((send gEgo:has(8)) and proc0_12(9))
                                                                            proc255_0(52 22)
                                                                            proc0_20(0)
                                                                        )(else
                                                                            proc255_0(52 17)
                                                                        )
                                                                    )(else
                                                                        proc255_0(52 23)
                                                                    )
                                                                )
                                                            )(else
                                                                (if (Said('/hinge'))
                                                                    proc255_0(52 24)
                                                                )(else
                                                                    (if (Said('look,look/hole') or proc0_14(pEvent 47 48 99 62))
                                                                        (if (< (send gEgo:x) 128)
                                                                            proc255_0(52 25)
                                                                        )(else
                                                                            proc255_0(52 26)
                                                                        )
                                                                    )(else
                                                                        (if (Said('look,look>'))
                                                                            (if (Said('<up'))
                                                                                (if (== (send gEgo:view) 14)
                                                                                    proc255_0(52 27)
                                                                                )(else
                                                                                    (if ((== (send gEgo:view) 6) and (send gEgo:inRect(19 105 136 187)))
                                                                                        proc255_0(52 28)
                                                                                    )(else
                                                                                        (if (== (send gEgo:view) 6)
                                                                                            proc255_0(52 29)
                                                                                        )(else
                                                                                            proc255_0(52 30)
                                                                                        )
                                                                                    )
                                                                                )
                                                                            )(else
                                                                                (if (Said('[<at,around][/room,well,cave]'))
                                                                                    (switch ((send gEgo:view))
                                                                                        (case 6
                                                                                            (if (< (send gEgo:y) 118)
                                                                                                proc255_0(52 31)
                                                                                            )(else
                                                                                                proc255_0(52 32)
                                                                                            )
                                                                                        )
                                                                                        (default 
                                                                                            proc255_0(52 33)
                                                                                        )
                                                                                    )
                                                                                )(else
                                                                                    (if (Said('/water'))
                                                                                        proc255_0(52 34)
                                                                                    )
                                                                                )
                                                                            )
                                                                        )
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )

)
(instance weed1 of Prop
    (properties
        x 220
        y 133
        description 5503
        view 252
        cel 4
        cycleSpeed 3
    )

    (method (doVerb theVerb)
        (switch (theVerb)
            (case 1
                localproc_1440()
            )
        )
    )

)
(instance weed2 of Prop
    (properties
        x 149
        y 157
        description 5503
        view 252
        loop 1
        cel 1
        cycleSpeed 3
    )

    (method (doVerb theVerb)
        (switch (theVerb)
            (case 1
                localproc_1440()
            )
        )
    )

)
(instance weed3 of Prop
    (properties
        x 264
        y 140
        description 5503
        view 252
        loop 1
        cel 2
        cycleSpeed 3
    )

    (method (doVerb theVerb)
        (switch (theVerb)
            (case 1
                localproc_1440()
            )
        )
    )

)
(instance weed4 of Prop
    (properties
        x 187
        y 163
        description 5503
        view 252
        cel 3
        cycleSpeed 3
    )

    (method (doVerb theVerb)
        (switch (theVerb)
            (case 1
                localproc_1440()
            )
        )
    )

)
(instance trunk of PicView
    (properties
        x 194
        y 152
        noun 5463
        description 5532
        view 252
        loop 2
    )

    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )(else
            (if ((super:handleEvent(pEvent)))
                return 
            )(else
                (if (Said('look,look/chest'))
                    (self:doVerb(1 pEvent))
                )(else
                    (if (Said('look,look<down') or Said('look,look/floor'))
                        (self:doVerb(1))
                    )
                )
            )
        )
    )


    (method (doVerb theVerb)
        (switch (theVerb)
            (case 7
                proc255_0(52 35)
            )
            (case 2
                proc255_0(52 36)
            )
            (default 
                (if (== (send gEgo:view) 14)
                    proc255_0(52 27)
                )(else
                    (if ((send gEgo:has(1)))
                        (send ((send gInv:at(1))):showSelf(gEgo))
                        proc255_0(52 37)
                    )(else
                        (if ((((< 159 (send gEgo:x)) and (< (send gEgo:x) 252)) and (> (send gEgo:y) 125)) or (< paramTotal 1))
                            proc255_0(52 38)
                        )(else
                            proc255_0(52 26)
                        )
                    )
                )
            )
        )
    )

)
(instance upToSurface of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:hide())
                = cycles 9
            )
            (case 1
                = global130 4
                = global136 3000
                (send gEgo:
                    show()
                    posn(73 57)
                    illegalBits(-24576)
                    setStep(1 1)
                    view(13)
                    setCycle(Fwd)
                )
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance getOutaWater of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send (ScriptID(0 21)):
                    loop(1)
                    stop()
                )
                (send (ScriptID(0 23)):
                    loop(1)
                    fade()
                )
                (send gEgo:
                    illegalBits(0)
                    setLoop(1)
                    setMotion(MoveTo 65 58 self)
                )
            )
            (case 1
                (send gEgo:
                    view(9)
                    cel(0)
                    setLoop(0)
                    cycleSpeed(1)
                    posn(43 55)
                    setCycle(End self)
                )
            )
            (case 2
                = global130 0
                proc0_1()
                (send gEgo:
                    loop(1)
                    illegalBits(-32512)
                    setMotion(MoveTo 32 54 self)
                )
            )
            (case 3
                (if (not proc0_12(83) and not proc0_12(82))
                    (send (ScriptID(0 23)):
                        number(64)
                        loop(-1)
                        play()
                    )
                )
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance drownEgo of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gEgo:
                    cycleSpeed(1)
                    setMotion(0)
                )
                = cycles 14
            )
            (case 1
                proc0_2()
                (send gEgo:
                    setLoop(
                        (if ((send gEgo:loop))
                            5
                        )(else
                            4
                        )
)
                    setCycle(0)
                    setCel(0)
                )
                = cycles 4
            )
            (case 2
                (send gEgo:
                    setStep(1 1)
                    moveSpeed(1)
                    setMotion(MoveTo (send gEgo:x) 200)
                )
                = seconds 9
            )
            (case 3
                proc0_16("Well, well, well!  Water you going to do now?")
            )
        )
    )

)
(instance goSwimming of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:
                    illegalBits(0)
                    setMotion(MoveTo 43 55 self)
                )
            )
            (case 1
                (if (proc0_12(1))
                    proc255_0(52 39)
                    proc0_11(1)
                    proc0_11(17)
                    proc0_8(5)
                    (send gGame:changeScore(-3))
                    (self:cue())
                )(else
                    (self:cue())
                )
            )
            (case 2
                = global136 3000
                = global130 4
                (send gEgo:
                    view(9)
                    setLoop(0)
                    cel(6)
                    setCycle(Beg self)
                )
            )
            (case 3
                (send gEgo:
                    view(13)
                    setLoop(-1)
                    setCycle(Fwd)
                    illegalBits(-24576)
                    posn(72 59)
                    setMotion(MoveTo 73 57 self)
                )
            )
            (case 4
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance goDiving of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send (ScriptID(0 21)):
                    loop(1)
                    fade()
                )
                (send gEgo:
                    view(14)
                    cel(8)
                    setLoop(0)
                    setCycle(End self)
                )
            )
            (case 1
                = cycles 6
            )
            (case 2
                (send (ScriptID(0 23)):
                    number(72)
                    loop(-1)
                    play()
                )
                (send gEgo:
                    show()
                    setLoop(-1)
                    loop(2)
                    ignoreActors(1)
                    posn(70 130)
                    setMotion(MoveTo 70 184)
                    looper(0)
                    setCycle(Fwd)
                    view(6)
                )
                = global130 4
                = local0 300
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance fallInWater of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send (ScriptID(0 23)):
                    loop(-1)
                    fade()
                )
                (send gEgo:
                    view(14)
                    setLoop(1)
                    cel(0)
                    setCycle(0)
                    cycleSpeed(0)
                    setMotion(JumpTo 77 55 self)
                )
                = global130 4
            )
            (case 1
                (send (ScriptID(0 21)):
                    number(14)
                    loop(1)
                    init()
                    play()
                )
                (send gEgo:
                    cel(1)
                    cycleSpeed(1)
                    setCycle(End self)
                )
            )
            (case 2
                = global130 4
                (send (ScriptID(0 21)):
                    number(51)
                    loop(-1)
                    play()
                )
                (send gEgo:
                    show()
                    view(13)
                    illegalBits(-24576)
                    setStep(1 1)
                    setCycle(Fwd)
                    setLoop(-1)
                    setCel(-1)
                    setPri(-1)
                    cycleSpeed(0)
                )
                = global136 3000
                (send global2:setScript(0))
                proc0_3()
                (self:dispose())
            )
        )
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )(else
            (if ((super:handleEvent(pEvent)))
                return 
            )(else
                (if (Said('swim'))
                    proc0_3()
                    (send (ScriptID(0 23)):stop())
                    (send gEgo:
                        illegalBits(-24576)
                        view(13)
                        setLoop(-1)
                        cycleSpeed(0)
                        setCycle(Fwd)
                    )
                    = seconds 0
                    (self:dispose())
                )
            )
        )
    )

)
(instance drowning of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (User:canControl(0))
                (send gEgo:
                    setMotion(0)
                    setLoop(0)
                    view(14)
                    cel(5)
                    cycleSpeed(1)
                    setCycle(End self)
                )
            )
            (case 1
                (send gEgo:
                    cel(5)
                    setCycle(End self)
                )
            )
            (case 2
                (send gEgo:
                    cel(5)
                    setCycle(End self)
                )
            )
            (case 3
                (send gEgo:hide())
                = cycles 40
            )
            (case 4
                (send gEgo:
                    view(6)
                    loop(Random(4 5))
                    posn((send gEgo:x) 120)
                    show()
                    setStep(1 1)
                    illegalBits(0)
                    moveSpeed(1)
                    setMotion(MoveTo (send gEgo:x) 155 self)
                )
            )
            (case 5
                (if (not global136)
                    proc0_16("After swimming for a long time, your strength ebbs and your arms and legs grow weary.  As your life swims before your eyes, you decide to...")
                )(else
                    proc0_16("You splash around for awhile, but unfortunately that won't keep your head above water.  As you go down for the third time, a sense of peace washes over you...")
                )
            )
        )
    )

)
(instance fillBucket of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:setMotion(MoveTo 41 54 self))
            )
            (case 1
                (send gEgo:
                    view(68)
                    loop(0)
                    cel(0)
                    setCycle(End self)
                )
            )
            (case 2
                proc255_0(52 40)
                (self:cue())
            )
            (case 3
                (send gEgo:setCycle(Beg self))
            )
            (case 4
                (send gEgo:
                    view(2)
                    loop(0)
                )
                proc0_1()
                proc0_3()
                (self:dispose())
            )
        )
    )

)
