(version 2)
(include "sci.sh")
(exports
    0 water42Reg
)
(use "Main")
(use "Class_255_0")
(use "n958")
(use "StopWalk")
(use "Cycle")
(use "Game")
(use "User")
(use "PicView")
(use "Obj")
(script 612)


(local
    local0
    local1
    gEgoLoop
    local3

)
(instance public water42Reg of Rgn
    (properties)

    (method (init)
        (super:init())
        proc958_0(128 10 11 12 13 14)
        (if (== global130 4)
            = local3 1
        )
        (self:doit())
    )


    (method (doit)
        (super:doit())
        (if (not (send global2:script) and proc999_5((send gEgo:onControl(1)) 2 1024 128 256))
            (send global2:setScript(water))
        )
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed) or (<> (send pEvent:type) 128))
            return 
        )
        (if (Said('swim<cease'))
            (switch ((send gEgo:view))
                (case 13
                    proc255_0(612 0)
                )
                (default 
                    proc255_0(612 1)
                )
            )
        )(else
            (if (Said('swim/') or Said('go,enter/water,lake,lake'))
                (if ((== (send global2:script) drowning) and (>= (drowning:state) 3))
                    proc255_0(612 2)
                )(else
                    (if (== global130 4)
                        proc255_0(612 3)
                    )(else
                        (if ((& (send gEgo:onControl(1)) $0100) or (& (send gEgo:onControl(1)) $0080))
                            proc0_1()
                            = local3 1
                            = global130 4
                            = global136 1000
                            (send gEgo:
                                view(13)
                                setCycle(Fwd)
                            )
                            (send global2:setScript(water))
                            proc0_3()
                        )(else
                            (if ((& (send gEgo:onControl(1)) $0002) or (& (send gEgo:onControl(1)) $0400))
                                proc255_0(612 4)
                            )(else
                                (if (== global130 0)
                                    proc255_0(612 5)
                                )
                            )
                        )
                    )
                )
            )(else
                (if (Said('dive/'))
                    (if (== global130 0)
                        proc255_0(612 6)
                    )(else
                        (if (global130)
                            (if ((>= global130 1) and (<= global130 3))
                                proc255_0(612 7)
                            )(else
                                (if (& (send gEgo:onControl(1)) $0080)
                                    proc255_0(612 8)
                                )(else
                                    proc255_0(612 9)
                                )
                            )
                        )
                    )
                )(else
                    (if (Said('get,get/water') or Said('fill/bucket'))
                        (if (not global130)
                            proc255_0(612 10)
                        )(else
                            (if ((send gEgo:has(8)))
                                (if (proc0_12(9))
                                    proc255_0(612 11)
                                )(else
                                    (if (== global130 4)
                                        proc255_0(612 12)
                                    )(else
                                        proc255_0(612 13)
                                    )
                                    proc0_20(1)
                                )
                            )(else
                                proc255_0(612 14)
                            )
                        )
                    )
                )
            )
        )
    )

)
(instance water of Script
    (properties)

    (method (init param1)
        (super:init(rest param1))
        (self:doit())
    )


    (method (doit)
        (if (proc0_12(1) and (<> (send gEgo:onControl(1)) 1))
            proc255_0(612 15)
            proc0_11(1)
        )
        = local0 (send gEgo:onControl(1))
        (if ((((& local0 $0180) and (== global130 4)) and global136) and not --global136)
            (send global2:setScript(drowning))
        )
        (if (<> local0 local1)
            = local1 local0
            (switch (local0)
                (case 1
                    (if (== (send (ScriptID(0 21)):number) 51)
                        (send (ScriptID(0 21)):stop())
                    )
                    = global130 0
                    = local3 0
                    (splash:dispose())
                    (send gEgo:setCycle(StopWalk 2))
                    (self:dispose())
                )
                (case 2
                    (if (== (send (ScriptID(0 21)):number) 51)
                        (send (ScriptID(0 21)):stop())
                    )
                    = global130 1
                    = local3 0
                    (send gEgo:
                        setCycle(Walk)
                        view(0)
                        cycleSpeed(0)
                        moveSpeed(0)
                    )
                    (splash:
                        ignoreActors()
                        init()
                    )
                )
                (case 1024
                    (if (== (send (ScriptID(0 21)):number) 51)
                        (send (ScriptID(0 21)):stop())
                    )
                    = global130 2
                    (splash:dispose())
                    (send gEgo:
                        setCycle(Walk)
                        view(11)
                        cycleSpeed(1)
                        moveSpeed(1)
                    )
                    = local3 0
                )
                (case 128
                    (if (== (send (ScriptID(0 21)):number) 51)
                        (send (ScriptID(0 21)):stop())
                    )
                    (if (not local3)
                        (send gEgo:
                            setCycle(Walk)
                            view(12)
                            cycleSpeed(2)
                            moveSpeed(2)
                        )
                        = gEgoLoop (send gEgo:loop)
                        = global130 3
                    )(else
                        (send gEgo:setCycle(Fwd))
                    )
                )
                (case 256
                    = global130 4
                    = global136 1000
                    (send gEgo:
                        view(13)
                        cycleSpeed(0)
                        moveSpeed(0)
                        setCycle(Fwd)
                    )
                    (send (ScriptID(0 21)):
                        number(51)
                        loop(-1)
                        play()
                    )
                )
            )
        )
    )

)
(instance drowning of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (User:canControl(0))
                = gEgoLoop (send gEgo:loop)
                (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())
                = seconds 4
            )
            (case 4
                (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 splash of Prop
    (properties
        view 10
    )

    (method (doit param1)
        (self:
            posn((send gEgo:x) (send gEgo:y))
            cel((send gEgo:cel))
            loop((send gEgo:loop))
        )
        (super:doit(rest param1))
    )


    (method (doVerb)
    )

)
