(version 2)
(include "sci.sh")
(exports
    0 moatRg
)
(use "Main")
(use "Class_255_0")
(use "n958")
(use "Sound")
(use "Cycle")
(use "Game")
(use "PicView")
(use "Obj")
(script 605)


(local
    local0
    local1
    local2
    local3
    local4

)
(instance public moatRg of Rgn
    (properties)

    (method (init)
        proc958_0(128 14 107 108)
        (if (>= global101 1)
            proc958_0(128 80 75 76 81)
            (if (proc0_12(2))
                proc958_0(128 163 164)
            )
        )
        (self:keep(0))
        (super:init())
        (monsterHead1:
            setPri(4)
            init()
            hide()
            setChecks(1 8)
            shiftClick(1)
            setScript(monsterLeftRight)
        )
        (monsterTail1:
            setPri(4)
            init()
            hide()
            setChecks(1 8)
            shiftClick(1)
        )
        (moatMonster:
            setPri(4)
            init()
            hide()
            setChecks(1 8)
            shiftClick(1)
            setScript(monsterLookScript)
        )
        (if (>= global101 1)
            (egoReflect:init())
            (goatReflect:init())
        )
    )


    (method (doit)
        = local0 (send gEgo:onControl(1))
        (if (<> local0 local1)
            = local1 local0
            (switch (local0)
                (case 16
                    (egoReflect:dispose())
                    (moatMonster:setScript(0))
                    (send gEgo:setScript(drownFrontScript))
                )
            )
        )
        (super:doit())
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )(else
            (if ((super:handleEvent(pEvent)))
                return 
            )(else
                (if (Said('look,look>'))
                    (if (Said('[<at,around][/room]'))
                        proc255_0(605 0)
                    )(else
                        (if (Said('/castle'))
                            proc255_0(605 1)
                        )(else
                            (if (Said('/moat'))
                                proc255_0(605 2)
                            )(else
                                (if (Said('/water'))
                                    proc255_0(605 3)
                                )(else
                                    (if (Said('/ivy,vine'))
                                        proc255_0(605 4)
                                    )
                                )
                            )
                        )
                    )
                )(else
                    (if (Said('get,get,get,pick/ivy,vine'))
                        proc255_0(605 5)
                    )(else
                        (if (Said('pet,ride,capture/serpent,animal,animal'))
                            proc255_0(605 6)
                        )(else
                            (if (Said('attack,kill,shoot/serpent,animal,animal'))
                                proc255_0(605 7)
                            )(else
                                (if (Said('climb,climb[<in,in]/serpent,animal,animal'))
                                    proc255_0(605 8)
                                )(else
                                    (if (Said('drink,get,get/water,drink'))
                                        (if ((send gEgo:has(8)) and proc0_12(9))
                                            (send pEvent:claimed(0))
                                        )(else
                                            proc255_0(605 9)
                                        )
                                    )(else
                                        (if (Said('smell,smell[/moat,brook,water]'))
                                            proc255_0(605 10)
                                        )(else
                                            (if (Said('dive[<in,on,in][/moat]'))
                                                proc255_0(605 11)
                                            )(else
                                                (if (Said('climb,climb'))
                                                    proc255_0(605 12)
                                                )(else
                                                    (if ((Said('go/swim') or Said('swim')) or Said('enter,go/moat'))
                                                        proc255_0(605 13)
                                                    )(else
                                                        (if (Said('steal,pick,get,get/animal,serpent'))
                                                            proc255_0(605 14)
                                                        )(else
                                                            (if (Said('talk,speak/animal,serpent'))
                                                                proc255_0(605 15)
                                                            )(else
                                                                (if (Said('get,get/water') or Said('fill/bucket'))
                                                                    (if (proc0_12(9))
                                                                        proc255_0(605 16)
                                                                    )(else
                                                                        (if (not (send gEgo:has(8)))
                                                                            proc255_0(605 17)
                                                                        )(else
                                                                            (if (& (send gEgo:onControl(1)) $0200)
                                                                                proc255_0(605 18)
                                                                                proc0_20(1)
                                                                            )(else
                                                                                proc255_0(605 19)
                                                                            )
                                                                        )
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )

)
(instance drownFrontScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:
                    view(14)
                    yStep(5)
                    setLoop(1)
                    setCel(0)
                    setMotion(MoveTo (send gEgo:x) + (send gEgo:y) 25 self)
                )
            )
            (case 1
                (send (ScriptID(0 21)):
                    number(14)
                    init()
                    play()
                )
                (send gEgo:setCycle(End self))
            )
            (case 2
                (if (proc0_12(1))
                    proc255_0(605 20)
                    (send gGame:changeScore(-3))
                )
                (send (ScriptID(0 21)):
                    number(96)
                    loop(-1)
                    play()
                )
                (send gEgo:
                    setLoop(0)
                    cycleSpeed(0)
                    setCycle(Fwd)
                )
                = cycles 20
            )
            (case 3
                (send gEgo:setCycle(CT 5 1 self))
            )
            (case 4
                (if (< (send gEgo:x) 160)
                    (moatMonster:
                        view(108)
                        x(- (send gEgo:x) 18)
                        setLoop(1)
                    )
                )(else
                    (moatMonster:
                        x(+ (send gEgo:x) 18)
                        setLoop(0)
                    )
                )
                (send gEgo:setCycle(End))
                (moatMonster:
                    y(+ (send gEgo:y) 2)
                    view(107)
                    cycleSpeed(1)
                    setCycle(End self)
                    show()
                )
            )
            (case 5
                (send gEgo:hide())
                (moatMonster:
                    setLoop(+ 2 (< (send gEgo:x) 160))
                    setCycle(Fwd)
                )
                = cycles 40
            )
            (case 6
                (moatMonster:
                    setLoop(+ 4 (< (send gEgo:x) 160))
                    setCycle(End self)
                )
            )
            (case 7
                (moatMonster:hide())
                = cycles 30
            )
            (case 8
                (send (ScriptID(0 21)):
                    number(50)
                    loop(1)
                    play(self)
                )
                (moatMonster:
                    show()
                    view(108)
                    setLoop(+ 5 (> (send gEgo:x) 160))
                    setCel(0)
                    setCycle(End)
                )
                = cycles 30
            )
            (case 9
                (moatMonster:setCycle(Beg))
            )
            (case 10
                (moatMonster:dispose())
                proc0_16("The moat monsters appreciate your good taste.")
                proc0_3()
            )
        )
    )

)
(instance monsterLeftRight of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = local3 Random(0 1)
                (switch (gNumber)
                    (case 1
                        (monsterHead1:x(Random(60 260)))
                    )
                    (case 2
                        (monsterHead1:x(Random(120 260)))
                    )
                    (case 83
                        (monsterHead1:x(Random(60 200)))
                    )
                )
                (if (== gNumber 1)
                    (monsterHead1:y(Random(148 168)))
                )(else
                    (monsterHead1:y(Random(169 186)))
                )
                = cycles Random((/ 100 (+ global101 1)) (/ 600 (+ global101 1)))
            )
            (case 1
                (TempSound:
                    number(97)
                    loop(-1)
                    init()
                    play()
                )
                (monsterHead1:
                    show()
                    setLoop(local3)
                    setCel(0)
                    cycleSpeed(1)
                    setCycle(End self)
                )
            )
            (case 2
                (monsterTail1:
                    x((monsterHead1:x))
                    y((monsterHead1:y))
                    cycleSpeed(1)
                )
                (monsterHead1:
                    setLoop(+ local3 2)
                    setCel(0)
                    setCycle(End self)
                )
            )
            (case 3
                (monsterHead1:
                    x(+ (monsterHead1:x) (- (* local3 120) 60))
                    setLoop(local3)
                    setCel(0)
                    setCycle(End)
                )
                (monsterTail1:
                    show()
                    setLoop(+ local3 2)
                    setCel(0)
                    setCycle(End self)
                )
            )
            (case 4
                (monsterHead1:
                    setLoop(+ local3 2)
                    setCel(0)
                    setCycle(Fwd)
                )
                (monsterTail1:
                    setLoop(+ local3 4)
                    setCel(0)
                    setCycle(End self)
                )
            )
            (case 5
                (monsterHead1:hide())
                (monsterTail1:
                    x((monsterHead1:x))
                    setLoop(+ local3 2)
                    setCel(0)
                    setCycle(End self)
                )
            )
            (case 6
                (monsterTail1:
                    setLoop(+ local3 4)
                    setCel(0)
                    setCycle(End self)
                )
            )
            (case 7
                (TempSound:
                    loop(1)
                    fade()
                )
                (monsterTail1:
                    setCel(0)
                    hide()
                )
                = cycles 1
            )
            (case 8
                (self:init())
            )
        )
    )

)
(instance monsterLookScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = cycles Random((/ 100 (+ global101 1)) (/ 600 (+ global101 1)))
            )
            (case 1
                (if (== gNumber 1)
                    (moatMonster:y(Random(148 168)))
                )(else
                    (moatMonster:y(Random(169 186)))
                )
                (moatMonster:
                    x(Random(50 270))
                    show()
                    setLoop(2)
                    setCel(0)
                    cycleSpeed(Random(1 2))
                    setCycle(End self)
                )
            )
            (case 2
                = local2 Random(0 1)
                (moatMonster:
                    setLoop(local2)
                    setCel(0)
                    setCycle(End self)
                )
            )
            (case 3
                = local4 Random(0 1)
                (if (local4)
                    (moatMonster:
                        setLoop(+ local2 3)
                        setCel(0)
                        setCycle(End)
                    )
                    = cycles Random(40 60)
                )(else
                    (self:cue())
                )
            )
            (case 4
                (moatMonster:setCycle(Beg self))
            )
            (case 5
                (if (local4)
                    (moatMonster:
                        setLoop(local2)
                        setCel((moatMonster:lastCel()))
                        setCycle(Beg self)
                    )
                )(else
                    (self:cue())
                )
            )
            (case 6
                (moatMonster:
                    setLoop(2)
                    setCel((moatMonster:lastCel()))
                    setCycle(Beg self)
                )
            )
            (case 7
                (moatMonster:hide())
                = cycles 2
            )
            (case 8
                (moatMonster:stopUpd())
                (self:init())
            )
        )
    )

)
(instance monsterHead1 of Prop
    (properties
        x 45
        y 145
        description 4493
        view 107
        loop 1
    )

    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )(else
            (if ((super:handleEvent(pEvent)))
                return 
            )(else
                (if (Said('look,look/serpent,animal,animal'))
                    (self:doVerb(1))
                )
            )
        )
    )


    (method (doVerb theVerb param2)
        (switch (theVerb)
            (case 1
                proc255_0(605 21)
            )
            (default 
                (super:doVerb(theVerb rest param2))
            )
        )
    )

)
(instance monsterTail1 of Prop
    (properties
        x 45
        y 145
        description 4519
        view 107
        loop 5
    )

    (method (doVerb theVerb param2)
        (switch (theVerb)
            (case 1
                proc255_0(605 21)
            )
            (default 
                (super:doVerb(theVerb rest param2))
            )
        )
    )

)
(instance moatMonster of Prop
    (properties
        description 4493
        view 108
    )

    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )(else
            (if ((super:handleEvent(pEvent)))
                return 
            )(else
                (if (Said('look,look/serpent,animal,animal'))
                    (self:doVerb(1))
                )
            )
        )
    )


    (method (doVerb theVerb param2)
        (switch (theVerb)
            (case 1
                proc255_0(605 21)
            )
            (default 
                (super:doVerb(theVerb rest param2))
            )
        )
    )

)
(instance TempSound of Sound
    (properties
        priority 3
    )
)
(instance goatReflect of View
    (properties
        description 4569
        view 163
        priority 1
        signal $4010
    )

    (method (init param1)
        (super:init(rest param1))
        (if (proc0_12(2))
            (self:
                loop((send gGoat:loop))
                x((send gGoat:x))
                y(+ (send gGoat:y) 20)
                cel((send gGoat:cel))
            )
        )
    )


    (method (doit param1)
        (if ((>= global101 1) and proc0_12(2))
            (if (== (send gGoat:view) 165)
                (self:view(163))
            )(else
                (self:view(164))
            )
            (self:
                loop((send gGoat:loop))
                x((send gGoat:x))
                cel((send gGoat:cel))
                y(+ (send gGoat:y) 20)
            )
        )
        (super:doit(rest param1))
    )


    (method (doVerb theVerb param2)
        (switch (theVerb)
            (case 1
                proc255_0(605 22)
            )
            (default 
                (super:doVerb(theVerb rest param2))
            )
        )
    )

)
(instance egoReflect of View
    (properties
        description 4569
        closeRangeDist 500
        longRangeDist 500
        view 80
        priority 1
        signal $4010
    )

    (method (init param1)
        (super:init(rest param1))
        (if (>= global101 1)
            (self:
                loop((send gEgo:loop))
                x((send gEgo:x))
                cel((send gEgo:cel))
                y(+ (send gEgo:y) 20)
            )
            (if (proc0_12(1))
                (egoReflect:hide())
            )
        )
    )


    (method (doit param1)
        (asm
            lsg     global101
            ldi     1
            ge?     
            bnt     code_0f49
            pushi   1
            pushi   1
            callb   proc0_12, 2
            bnt     code_0ebd
            pushi   #hide
            pushi   0
            self    4
            jmp     code_0ec3
code_0ebd:  pushi   #show
            pushi   0
            self    4
code_0ec3:  pushi   5
            pushi   1
            pushi   #view
            pushi   0
            lag     gEgo
            send    4
            push    
            dup     
            ldi     0
            eq?     
            bnt     code_0eda
            ldi     80
            jmp     code_0f15
code_0eda:  dup     
            ldi     2
            eq?     
            bnt     code_0ee6
            ldi     81
            jmp     code_0f15
code_0ee6:  dup     
            pushi   1
            pushi   0
            callb   proc0_12, 2
            bnt     code_0ef4
            ldi     23
            jmp     code_0ef6
code_0ef4:  ldi     16
code_0ef6:  eq?     
            bnt     code_0eff
            ldi     76
            jmp     code_0f15
code_0eff:  dup     
            pushi   1
            pushi   0
            callb   proc0_12, 2
            bnt     code_0f0d
            ldi     17
            jmp     code_0f0f
code_0f0d:  ldi     15
code_0f0f:  eq?     
            bnt     code_0f15
            ldi     75
code_0f15:  toss    
            push    
            pushi   6
            pushi   1
            pushi   #loop
            pushi   0
            lag     gEgo
            send    4
            push    
            pushi   7
            pushi   1
            pushi   #cel
            pushi   0
            lag     gEgo
            send    4
            push    
            pushi   4
            pushi   1
            pushi   #x
            pushi   0
            lag     gEgo
            send    4
            push    
            pushi   3
            pushi   1
            pushi   #y
            pushi   0
            lag     gEgo
            send    4
            push    
            ldi     20
            add     
            push    
            self    30
code_0f49:  pushi   #doit
            pushi   0
            &rest   param1
            super   View, 4
            ret     
        )
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )(else
            (if ((super:handleEvent(pEvent)))
                return 
            )(else
                (if (Said('look,look/reflection'))
                    (self:doVerb(1))
                )
            )
        )
    )


    (method (doVerb theVerb param2)
        (switch (theVerb)
            (case 1
                proc255_0(605 23)
            )
            (default 
                (super:doVerb(theVerb rest param2))
            )
        )
    )

)
