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


(local
    local0
    local1
    gEgoLoop
    local3

)
(instance public waterReg 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 4 8 16))
            (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(603 0)
                )
                (default 
                    proc255_0(603 1)
                )
            )
        )(else
            (if (Said('swim/') or Said('enter,go/water,lake,lake'))
                (if ((== (send global2:script) drowning) and (>= (drowning:state) 3))
                    proc255_0(603 2)
                )(else
                    (if (== global130 4)
                        proc255_0(603 3)
                    )(else
                        (if ((& (send gEgo:onControl(1)) $0010) or (& (send gEgo:onControl(1)) $0008))
                            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)) $0004))
                                proc255_0(603 4)
                            )(else
                                (if (== global130 0)
                                    proc255_0(603 5)
                                )
                            )
                        )
                    )
                )
            )(else
                (if (Said('dive/'))
                    (if (== global130 0)
                        proc255_0(603 6)
                    )(else
                        (if (global130)
                            (if ((>= global130 1) and (<= global130 3))
                                proc255_0(603 7)
                            )(else
                                (if (& (send gEgo:onControl(1)) $0008)
                                    proc255_0(603 8)
                                )(else
                                    proc255_0(603 9)
                                )
                            )
                        )
                    )
                )(else
                    (if (Said('get,get/water') or Said('fill/bucket'))
                        (if (not global130)
                            proc255_0(603 10)
                        )(else
                            (if ((send gEgo:has(8)))
                                (if (proc0_12(9))
                                    proc255_0(603 11)
                                )(else
                                    (if (== global130 4)
                                        proc255_0(603 12)
                                    )(else
                                        proc255_0(603 13)
                                    )
                                    proc0_20(1)
                                )
                            )(else
                                proc255_0(603 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(603 15)
            proc0_11(1)
            proc0_1()
        )
        = local0 (send gEgo:onControl(1))
        (if ((((& local0 $0018) and (== global130 4)) and global136) and not --global136)
            (send global2:setScript(drowning))
        )
        (if (<> local0 local1)
            = local1 local0
            (if (& local0 $0002)
                (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()
                )
            )(else
                (if (& local0 $0004)
                    (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
                )(else
                    (if (& local0 $0008)
                        (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))
                        )
                    )(else
                        (if (& local0 $0010)
                            = global130 4
                            = global136 1000
                            (send gEgo:
                                view(13)
                                cycleSpeed(0)
                                moveSpeed(0)
                                setCycle(Fwd)
                            )
                            (send (ScriptID(0 21)):
                                number(51)
                                loop(-1)
                                play()
                            )
                        )(else
                            (if ((<> 0 local0) and (<> local0 16384))
                                (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())
                            )
                        )
                    )
                )
            )
        )
    )

)
(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)
    )

)
