(version 2)
(include "sci.sh")
(exports
    0 riverReg
)
(use "Main")
(use "Class_255_0")
(use "n958")
(use "Cycle")
(use "Game")
(use "User")
(use "Obj")
(script 608)


(local
    gEgoLoop

)
(instance public riverReg of Rgn
    (properties)

    (method (init)
        proc958_0(128 54 14)
        Load(rsSOUND 14)
        (self:keep(0))
        (super:init())
    )


    (method (doit)
        (super:doit())
        (if (((& (send gEgo:onControl(1)) $003c) and not (send global2:script)) and (== gNewRoomNumber gNumber))
            (send global2:setScript(intoRiver))
        )
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed) or (<> (send pEvent:type) 128))
            return 
        )
        (if (Said('dive/'))
            (if ((== (send global2:script) intoRiver) and (>= (intoRiver:state) 5))
                proc255_0(608 0)
            )(else
                (if (<> (send global2:script) intoRiver)
                    proc255_0(608 1)
                )(else
                    proc255_0(608 2)
                )
            )
        )(else
            (if ((Said('swim/') or Said('go,enter/water,brook,brook,brook')) and (<> gNumber 42))
                (if (<> (send global2:script) intoRiver)
                    proc255_0(608 3)
                )(else
                    proc255_0(608 4)
                )
            )(else
                (if (Said('drink/water') or Said('get,get/drink'))
                    proc255_0(608 5)
                )(else
                    (if (Said('get,get/water') or Said('fill/bucket'))
                        (if (== (send global2:script) intoRiver)
                            proc255_0(608 6)
                        )(else
                            (if ((send gEgo:has(8)))
                                proc255_0(608 7)
                            )(else
                                proc255_0(608 8)
                            )
                        )
                    )(else
                        (send pEvent:claimed(0))
                    )
                )
            )
        )
    )

)
(instance intoRiver of Script
    (properties)

    (method (doit param1)
        (super:doit(rest param1))
        (if (== state 0)
            (if ((((& (send gEgo:onControl(1)) $0200) or (> (send gEgo:x) 326)) or (< (send gEgo:x) -6)) or (> (send gEgo:y) 196))
                (send (ScriptID(0 21)):
                    number(14)
                    loop(1)
                    play()
                )
                (self:cue())
            )(else
                (if (< (send gEgo:yStep) 9)
                    (send gEgo:setStep(-1 (+ (send gEgo:yStep) 2)))
                )
            )
        )
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send (ScriptID(0 21)):
                    number(17)
                    init()
                    loop(1)
                    play()
                )
                = global130 6
                (send gEgo:
                    view(54)
                    illegalBits(0)
                    setCycle(0)
                    cel(0)
                    ignoreActors()
                    ignoreHorizon()
                    setStep(6 3)
                )
                (switch ((send gEgo:onControl(1)))
                    (case 4
                        (send gEgo:
                            setLoop(1)
                            setMotion(MoveTo - (send gEgo:x) 200 + (send gEgo:y) 140)
                        )
                    )
                    (case 32
                        (send gEgo:
                            yStep(1)
                            setLoop(2)
                            setMotion(MoveTo (send gEgo:x) 190)
                        )
                    )
                    (case 16
                        (send gEgo:
                            setLoop(3)
                            setMotion(MoveTo (send gEgo:x) 0)
                        )
                    )
                    (case 8
                        (send gEgo:
                            setLoop(0)
                            setMotion(MoveTo + (send gEgo:x) 200 + (send gEgo:y) 140)
                        )
                    )
                )
                (if ((send gCast:contains(gGoat)))
                    proc0_15(gGoat gEgo)
                    (send gGoat:setMotion(0))
                )
                (send gEgo:setPri(
                    (switch (gNumber)
                        (case 25
                            3
                        )
                        (case 39
                            (if (< (send gEgo:y) 107)
                                2
                            )(else
                                -1
                            )
                        )
                        (case 41
                            7
                        )
                        (case 26
                            (if (& (send gEgo:onControl(1)) $0004)
                                1
                            )(else
                                8
                            )
                        )
                        (case 42
                            (if ((> (send gEgo:y) 150) and (< (send gEgo:x) 50))
                                13
                            )(else
                                (if (> (send gEgo:y) 83)
                                    4
                                )(else
                                    1
                                )
                            )
                        )
                        (case 32
                            (if (== (send gEgo:loop) 3)
                                8
                            )(else
                                5
                            )
                        )
                        (case 34
                            3
                        )
                        (case 47
                            (if (< (send gEgo:x) 159)
                                (if (< (send gEgo:y) 170)
                                    7
                                )(else
                                    9
                                )
                            )(else
                                -1
                            )
                        )
                        (default 
                            -1
                        )
                    )
))
            )
            (case 1
                (User:canInput(1))
                (if (proc0_12(1))
                    proc255_0(608 9)
                    (send gGame:changeScore(-3))
                )
                (send gEgo:
                    setLoop(4)
                    setMotion(0)
                    cycleSpeed(1)
                    setCycle(End)
                )
                (if (== gNumber 17)
                    (self:changeState(6))
                )(else
                    = seconds 2
                )
            )
            (case 2
                (User:canControl(0))
                (send (ScriptID(0 21)):
                    number(96)
                    play()
                )
                = gEgoLoop (send gEgo:loop)
                (send gEgo:
                    view(14)
                    cycleSpeed(2)
                    setMotion(0)
                    setLoop(0)
                    cel(5)
                    cycleSpeed(1)
                    setCycle(End self)
                )
            )
            (case 3
                (send gEgo:
                    cel(5)
                    setCycle(End self)
                )
            )
            (case 4
                (send gEgo:
                    cel(5)
                    setCycle(End self)
                )
            )
            (case 5
                (send gEgo:hide())
                = seconds 4
            )
            (case 6
                proc0_16("The raging current pulls you under, never to be found.")
            )
        )
    )

)
