(version 2)
(include "sci.sh")
(exports
    0 rm10
)
(use "Main")
(use "Class_255_0")
(use "mwAvoider")
(use "TurnLooper")
(use "NewFeature")
(use "Blk")
(use "n958")
(use "Wander")
(use "Follow")
(use "Avoid")
(use "Cycle")
(use "Game")
(use "Obj")
(script 10)


(local
    local0

)
(instance public rm10 of Rm
    (properties
        picture 10
        horizon 57
        north 23
        east 11
        south 7
        west 9
    )

    (method (init)
        (self:style(
            (switch (gGNumber)
                (case north
                    5
                )
                (case west
                    3
                )
                (case east
                    40
                )
                (case south
                    4
                )
            )
))
        (super:init())
        proc958_0(130 985 982 970 971)
        (switch (gGNumber)
            (case north
                (send gEgo:posn(proc0_17(319 proc0_18(255 (send gEgo:x) 236) 171) (+ 2 horizon)))
            )
            (case south
                (send gEgo:posn(proc0_17(319 (send gEgo:x) 90) 188))
            )
            (case west
                (send gEgo:posn(3 proc0_17(183 (send gEgo:y) 113)))
            )
            (default 
                (send gEgo:posn(317 proc0_17(189 (send gEgo:y) (+ horizon 2))))
            )
        )
        (send gEgo:init())
        proc0_1()
        (trough:init())
        (tree7:init())
        (tree5:init())
        (tree8:init())
        (tree6:init())
        (tree3:init())
        (tree4:init())
        (tree2:init())
        (tree:init())
        (tree1:init())
        (bush1:init())
        (bush:init())
        (if (not proc0_12(2))
            (if (not gGNumber_2 and not proc0_12(80))
                proc958_0(128 21 167)
                (goatLpr:viewChange(167))
                (if ((== gGNumber_3 11) and not proc0_12(36))
                    (send gGoat:
                        view(165)
                        posn(340 Random(120 140))
                        init()
                        looper(goatLpr)
                        setCycle(Walk)
                        setScript(changeGoatRoom)
                    )
                    = local0 Random(100 180)
                )(else
                    (send gGoat:
                        view(165)
                        posn(Random(232 260) Random(120 140))
                        init()
                        looper(goatLpr)
                        setCycle(Walk)
                        observeBlocks(pen)
                        setScript(goatWander)
                    )
                    = local0 Random(Random(100 140) Random(160 200))
                )
            )
        )(else
            (if ((& (send gEgo:onControl(1)) $3000) and proc0_12(36))
                proc0_11(2)
                proc255_0(10 0)
            )
        )
    )


    (method (handleEvent pEvent)
        (if (Said('rub/ring'))
            (if (proc0_12(1))
                proc255_0(10 1)
            )(else
                (if (not global134)
                    proc255_0(10 2)
                )(else
                    (if (proc0_12(17))
                        proc255_0(10 3)
                        proc0_10(1)
                        proc0_1()
                        (if (proc0_12(2) and not proc0_12(36))
                            proc255_0(10 4)
                            proc0_11(2)
                            proc0_11(80)
                            (goatLpr:viewChange(167))
                            (if (== gGNumber_3 11)
                                (send gGoat:
                                    posn(340 Random(120 140))
                                    init()
                                    looper(goatLpr)
                                    setCycle(Walk)
                                    setScript(changeGoatRoom)
                                )
                                = local0 Random(100 180)
                            )(else
                                (send gGoat:
                                    init()
                                    looper(goatLpr)
                                    setCycle(Walk)
                                    observeBlocks(pen)
                                    setScript(goatWander)
                                )
                                = local0 Random(Random(100 140) Random(160 200))
                            )
                        )
                    )(else
                        proc255_0(10 5)
                    )
                )
            )
        )(else
            (if (Said('remove/ring') or Said('get<off/ring'))
                (if (== (send gEgo:view) 
                (if (proc0_12(0))
                    23
                )(else
                    16
                )
)
                    proc0_22()
                )(else
                    (if (not proc0_12(17))
                        proc255_0(10 6)
                    )(else
                        proc255_0(10 7)
                        proc0_11(17)
                        proc0_11(1)
                        proc0_1()
                    )
                )
            )(else
                (if ((send pEvent:claimed))
                    return 
                )(else
                    (if ((super:handleEvent(pEvent)))
                        return 
                    )(else
                        (if ((send gCast:contains(gGoat)))
                            (if (gGNumber_2)
                                (send pEvent:claimed(0))
                            )(else
                                (if (Said('talk,speak,say,call') or Said('/hello'))
                                    proc255_0(10 8)
                                )(else
                                    (if (Said('capture,move,move,get,get/goat'))
                                        (if (proc0_12(2))
                                            proc255_0(10 9)
                                        )(else
                                            (if (& (send gEgo:onControl(1)) $3000)
                                                proc255_0(10 10)
                                            )(else
                                                proc255_0(10 11)
                                            )
                                        )
                                    )(else
                                        (if (Said('feed/goat[/!*]'))
                                            proc255_0(10 12)
                                        )(else
                                            (if (Said('pet,free/goat'))
                                                proc255_0(10 13)
                                            )(else
                                                (if (Said('ride/goat'))
                                                    proc255_0(10 14)
                                                )(else
                                                    (if (Said('feed/carrot') or Said('give/carrot'))
                                                        (if (not (send gEgo:has(2)))
                                                            proc255_0(10 15)
                                                        )(else
                                                            (if (> (send gEgo:distanceTo(gGoat)) 32)
                                                                proc255_0(10 16)
                                                            )(else
                                                                (if (proc0_12(1))
                                                                    proc255_0(10 17)
                                                                )(else
                                                                    (if (proc0_12(2))
                                                                        proc255_0(10 18)
                                                                    )(else
                                                                        proc255_0(10 19)
                                                                    )
                                                                    proc0_8(2 15)
                                                                    proc0_11(2)
                                                                    (if (not proc0_12(23) and (& (send gGoat:onControl(1)) $3000))
                                                                        proc0_11(80)
                                                                        (goatLpr:viewChange(167))
                                                                        (send gGoat:
                                                                            view(165)
                                                                            looper(goatLpr)
                                                                            setCycle(Walk)
                                                                            observeBlocks(pen)
                                                                            setScript(goatWander)
                                                                        )
                                                                    )(else
                                                                        (send gGoat:setScript(goatBobs))
                                                                    )
                                                                    proc0_11(64)
                                                                    (send gGame:changeScore(-2))
                                                                )
                                                            )
                                                        )
                                                    )(else
                                                        (if (((Said('show/carrot') or Said('coax,coax/goat')) or Said('show/goat/carrot')) or Said('coax,coax/goat/carrot'))
                                                            (if (not (send gEgo:has(2)))
                                                                proc0_6()
                                                            )(else
                                                                (if (proc0_12(2))
                                                                    proc255_0(10 20)
                                                                )(else
                                                                    (if ((& (send gGoat:onControl(1)) $3000) and not (& (send gEgo:onControl()) $3000))
                                                                        proc255_0(10 21)
                                                                    )(else
                                                                        (if (> (send gEgo:distanceTo(gGoat)) 36)
                                                                            proc255_0(10 22)
                                                                        )(else
                                                                            (if (proc0_12(1))
                                                                                proc255_0(10 23)
                                                                            )(else
                                                                                (if ((send global2:script))
                                                                                    proc0_22()
                                                                                )(else
                                                                                    (if ((not proc0_12(36) and (& (send gEgo:onControl(1)) $3000)) and not (& (send gGoat:onControl(1)) $3000))
                                                                                        proc255_0(10 24)
                                                                                    )(else
                                                                                        (send global2:setScript(getGoat))
                                                                                    )
                                                                                )
                                                                            )
                                                                        )
                                                                    )
                                                                )
                                                            )
                                                        )(else
                                                            (if (Said('shoot/goat') or Said('kill/goat/shot'))
                                                                (if (gGNumber_2)
                                                                    proc255_0(10 25)
                                                                )(else
                                                                    (if ((send global2:script))
                                                                        proc0_22()
                                                                    )(else
                                                                        (if (proc0_12(1))
                                                                            proc255_0(10 26)
                                                                        )(else
                                                                            (if (not proc0_12(36) and not (& (send gGoat:onControl()) $3000))
                                                                                proc255_0(10 24)
                                                                            )(else
                                                                                (if (not (send gEgo:has(9)) or not (send gEgo:has(10)))
                                                                                    proc255_0(10 27)
                                                                                )(else
                                                                                    proc255_0(10 28)
                                                                                )
                                                                            )
                                                                        )
                                                                    )
                                                                )
                                                            )(else
                                                                (if (Said('stab,kill/goat') or Said('use,cast/dagger'))
                                                                    (if (gGNumber_2)
                                                                        proc255_0(10 25)
                                                                    )(else
                                                                        (if ((send global2:script))
                                                                            proc0_22()
                                                                        )(else
                                                                            (if ((> (send gGoat:x) 320) and not proc0_12(36))
                                                                                proc255_0(10 24)
                                                                            )(else
                                                                                (if (not (& (send gEgo:onControl(1)) $3000) and not proc0_12(36))
                                                                                    proc255_0(10 29)
                                                                                )(else
                                                                                    (if (> (send gEgo:distanceTo(gGoat)) 35)
                                                                                        proc255_0(10 30)
                                                                                    )(else
                                                                                        (if (not (send gEgo:has(0)))
                                                                                            proc255_0(10 31)
                                                                                        )(else
                                                                                            (send global2:setScript(ScriptID(600 2)))
                                                                                        )
                                                                                    )
                                                                                )
                                                                            )
                                                                        )
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )(else
                            (if (Said('/goat') or Said('show/carrot'))
                                (if (proc0_12(1))
                                    proc255_0(10 32)
                                )(else
                                    (if (proc0_12(2))
                                        proc255_0(10 20)
                                    )(else
                                        proc255_0(10 33)
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
        (if (Said('jump/fence'))
            proc255_0(10 34)
        )(else
            (if (Said('climb,climb/fence'))
                proc255_0(10 35)
            )(else
                (if ((((((Said('look,look/fence') or proc0_14(pEvent 215 131 319 157)) or proc0_14(pEvent 198 121 214 148)) or proc0_14(pEvent 186 103 199 124)) or proc0_14(pEvent 191 73 215 86)) or proc0_14(pEvent 178 81 192 98)) or proc0_14(pEvent 215 66 319 83))
                    (if (& (send gEgo:onControl(1)) $3000)
                        proc255_0(10 36)
                    )(else
                        proc255_0(10 37)
                    )
                )(else
                    (if (Said('look,look>'))
                        (if (Said('[<at,around][/room,fence]'))
                            (if (& (send gEgo:onControl(1)) $3000)
                                proc255_0(10 38)
                            )(else
                                proc255_0(10 39)
                            )
                        )(else
                            (if (Said('/gate'))
                                proc255_0(10 40)
                            )
                        )
                    )(else
                        (if (Said('open,open,close,close,find/gate'))
                            proc255_0(10 41)
                        )(else
                            (if (Said('attack,kick/goat'))
                                (if (gGNumber_2)
                                    proc255_0(10 42)
                                )(else
                                    proc255_0(10 43)
                                )
                            )
                        )
                    )
                )
            )
        )
    )

)
(instance goatLpr of TurnLooper
    (properties)
)
(instance pen of Cage
    (properties
        top 92
        left 213
        bottom 142
        right 316
    )
)
(instance goatWander of Script
    (properties)

    (method (doit param1)
        (super:doit(rest param1))
        (if (not gGNumber_2 and (< (send gEgo:distanceTo(gGoat)) 30))
            = cycles 0
            (send gGoat:setScript(goatRuns))
        )(else
            (if (== --local0 0)
                (send gGoat:setScript(changeGoatRoom))
            )
        )
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gGoat:
                    setLoop(-1)
                    setMotion(Wander)
                    startUpd()
                )
                = cycles Random(14 30)
            )
            (case 1
                (send gGoat:setMotion(0))
                = cycles Random(8 17)
            )
            (case 2
                (self:changeState(0))
            )
        )
    )

)
(instance goatRuns of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gGoat:
                    setAvoider(mwAvoider)
                    ignoreBlocks(pen)
                    setMotion(MoveTo 333 (send gGoat:y) self)
                )
            )
            (case 1
                = gGNumber_3 11
                (send gGoat:
                    hide()
                    setScript(goatCounter)
                )
                (self:dispose())
            )
        )
    )

)
(instance getGoat of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                proc0_15(gEgo gGoat)
                proc0_15(gGoat gEgo)
                (send gEgo:
                    view(21)
                    cel(0)
                    setCycle(End)
                )
                (send gGoat:
                    setMotion(0)
                    setScript(0)
                )
                = cycles 22
            )
            (case 1
                (if (proc0_12(4))
                    proc255_0(10 44)
                )(else
                    proc255_0(10 45)
                    proc0_19(80 5)
                )
                (send (ScriptID(0 21)):
                    number(60)
                    init()
                    play()
                )
                (send gEgo:setCycle(Beg self))
            )
            (case 2
                proc0_1()
                proc0_3()
                (if (not proc0_12(4))
                    (send gGoat:
                        setAvoider(Avoid)
                        setMotion(Follow gEgo 50)
                    )
                    proc0_10(2)
                )
                (self:dispose())
            )
        )
    )

)
(instance changeGoatRoom of Script
    (properties)

    (method (doit)
        (super:doit())
        (if ((== state 0) and (& (send gGoat:onControl()) $3000))
            = gGNumber_3 10
        )(else
            = gGNumber_3 11
        )
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (if (== gGNumber_3 10)
                    (send gGoat:
                        setLoop(-1)
                        setAvoider(mwAvoider)
                        ignoreBlocks(pen)
                        setMotion(MoveTo 340 (send gGoat:y) self)
                    )
                )(else
                    (send gGoat:
                        show()
                        setLoop(-1)
                        setAvoider(0)
                        setMotion(MoveTo 300 (send gGoat:y) self)
                    )
                )
            )
            (case 1
                (if (<> gGNumber_3 10)
                    (self:changeState(2))
                )(else
                    (send gGoat:
                        observeBlocks(pen)
                        setScript(goatWander)
                    )
                    = local0 Random(Random(100 140) Random(160 200))
                    (self:dispose())
                )
            )
            (case 2
                (if (proc0_12(23) and (== gGNumber_3 11))
                    (self:dispose())
                )(else
                    = cycles 70
                )
            )
            (case 3
                (self:changeState(0))
            )
        )
    )

)
(instance goatCounter of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = cycles 70
            )
            (case 1
                (send client:setScript(changeGoatRoom))
                (self:dispose())
            )
        )
    )

)
(instance goatBobs of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gGoat:
                    setAvoider(0)
                    illegalBits(-16322)
                    setMotion(MoveTo Random(10 310) Random(+ (send global2:horizon) 2 180))
                )
                = cycles Random(20 40)
            )
            (case 1
                (self:changeState(0))
            )
        )
    )

)
(instance trough of NewFeature
    (properties
        x 286
        y 82
        noun 4863
        nsTop 77
        nsLeft 260
        nsBottom 87
        nsRight 313
        description 4961
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 4968
    )
)
(instance tree8 of NewFeature
    (properties
        x 78
        y 50
        noun 4867
        nsTop -1
        nsBottom 101
        nsRight 157
        description 5038
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5043
    )
)
(instance tree7 of NewFeature
    (properties
        x 27
        y 142
        noun 4867
        nsTop 101
        nsLeft 10
        nsBottom 184
        nsRight 44
        description 5038
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5043
    )
)
(instance tree6 of NewFeature
    (properties
        x 53
        y 111
        noun 4867
        nsTop 101
        nsLeft 43
        nsBottom 121
        nsRight 63
        description 5038
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5043
    )
)
(instance tree5 of NewFeature
    (properties
        x 84
        y 111
        noun 4867
        nsTop 101
        nsLeft 63
        nsBottom 122
        nsRight 105
        description 5038
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5043
    )
)
(instance tree4 of NewFeature
    (properties
        x 165
        y 37
        noun 4867
        nsTop -1
        nsLeft 157
        nsBottom 76
        nsRight 173
        description 5038
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5043
    )
)
(instance tree3 of NewFeature
    (properties
        x 181
        y 23
        noun 4867
        nsTop -1
        nsLeft 172
        nsBottom 48
        nsRight 191
        description 5038
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5043
    )
)
(instance tree2 of NewFeature
    (properties
        x 255
        y 17
        noun 4867
        nsTop -1
        nsLeft 191
        nsBottom 36
        nsRight 320
        description 5038
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5043
    )
)
(instance tree1 of NewFeature
    (properties
        x 244
        y 45
        noun 4867
        nsTop 36
        nsLeft 229
        nsBottom 54
        nsRight 259
        description 5038
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5043
    )
)
(instance tree of NewFeature
    (properties
        x 252
        y 63
        noun 4867
        nsTop 54
        nsLeft 242
        nsBottom 72
        nsRight 262
        description 5038
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5043
    )
)
(instance bush of NewFeature
    (properties
        x 164
        y 110
        noun 4871
        nsTop 104
        nsLeft 146
        nsBottom 117
        nsRight 183
        description 5148
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5153
    )
)
(instance bush1 of NewFeature
    (properties
        x 173
        y 99
        noun 4871
        nsTop 94
        nsLeft 166
        nsBottom 104
        nsRight 181
        description 5148
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5153
    )
)
