(version 2)
(include "sci.sh")
(exports
    0 rgGoat
    1 goatLooper
    2 killGoat
)
(use "Main")
(use "Class_255_0")
(use "TurnLooper")
(use "n958")
(use "Follow")
(use "Avoid")
(use "Sound")
(use "Cycle")
(use "Game")
(use "Obj")
(script 600)


(local
    local0
    local1
    local2

)
(instance public goatLooper of TurnLooper
    (properties)
)
(instance public rgGoat of Rgn
    (properties)

    (method (init param1)
        proc958_0(128 165 167 166)
        proc958_0(130 985 971 982)
        (super:init(rest param1))
        (goatLooper:viewChange(167))
        (send gGoat:
            view(165)
            ignoreHorizon(1)
            illegalBits(-7618)
            setLoop(-1)
            setPri(-1)
            looper(goatLooper)
            setAvoider(
                (if (proc999_5(gNumber 10 11 15 16 23))
                    0
                )(else
                    (if (proc999_5(gNumber 25 39 41))
                        (Avoid:offScreenOK(0))
                    )(else
                        (Avoid:offScreenOK(1))
                    )
                )
)
            setCycle(Walk)
            setMotion(Follow gEgo 60)
            init()
        )
        (switch (gGNumber)
            (case (send global2:west)
                (switch (gGNumber)
                    (case 15
                        (send gGoat:posn(-20 proc0_17(90 (send gGoat:y) (+ (send global2:horizon) 2))))
                    )
                    (default 
                        (send gGoat:posn((- (send gEgo:x) 30) (+ (send gEgo:y) 2)))
                    )
                )
            )
            (case (send global2:east)
                (switch (gGNumber)
                    (case 16
                        (send gGoat:posn(340 proc0_17(90 (send gGoat:y) (+ (send global2:horizon) 2))))
                    )
                    (case 11
                        (if (<= (send gEgo:y) 77)
                            (send gGoat:posn((+ (send gEgo:x) 20) (- (send gEgo:y) 2)))
                        )(else
                            (send gGoat:posn((+ (send gEgo:x) 20) (+ (send gEgo:y) 2)))
                        )
                    )
                    (default 
                        (send gGoat:posn((+ (send gEgo:x) 30) (+ (send gEgo:y) 2)))
                    )
                )
            )
            (case (send global2:north)
                (switch (gGNumber)
                    (case 14
                        (send gGoat:posn((send gEgo:x) (send global2:horizon)))
                    )
                    (case 30
                        (send gGoat:posn((- (send gEgo:x) 25) 50))
                    )
                    (case 32
                        (send gGoat:posn(proc0_17(309 (- (send gEgo:x) 25) 240) (send gEgo:y)))
                    )
                    (default 
                        (if (< (send gEgo:x) 160)
                            (send gGoat:posn((- (send gEgo:x) 25) (send gEgo:y)))
                        )(else
                            (send gGoat:posn((+ (send gEgo:x) 25) (send gEgo:y)))
                        )
                    )
                )
            )
            (case (send global2:south)
                (if (> (send gEgo:x) 160)
                    (send gGoat:posn((+ (send gEgo:x) 5) (+ (send gEgo:y) 30)))
                )(else
                    (send gGoat:posn((- (send gEgo:x) 5) (+ (send gEgo:y) 30)))
                )
            )
        )
        = gGNumber_3 gNumber
    )


    (method (doit)
        (super:doit())
        (if ((proc0_12(2) and local0) and (> (send gEgo:distanceTo(gGoat)) 120))
            (if (global130 and (& (send gEgo:onControl(1)) $059e))
                proc255_0(600 0)
            )(else
                proc255_0(600 1)
            )
            = local0 0
            proc0_11(2)
            (send gGoat:setScript(goatBobs))
        )
        (if (((global130 and proc0_12(2)) and not local0) and (& (send gEgo:onControl(1)) $0002))
            = local0 1
            (send gGoat:setMotion(0))
            (if (not local1)
                = local1 1
                proc255_0(600 2)
            )
        )
        (if ((> (send gGoat:y) (send global2:horizon)) and (send gGoat:ignoreHorizon()))
            (send gGoat:ignoreHorizon(0))
        )
        (if ((not global130 and local0) and proc0_12(2))
            = local0 0
            (send gGoat:setMotion(Follow gEgo 60))
        )
        (if (((proc0_12(1) and proc999_5(gNumber 25 39 41)) and (<> (send global2:script) goatLeaves)) and proc0_12(2))
            = local2 1
            (send global2:setScript(goatLeaves))
        )
    )


    (method (handleEvent pEvent)
        (super:handleEvent(pEvent))
        (if ((send pEvent:claimed) or (<> (send pEvent:type) 128))
            return 
        )
        (if (Said('attack,kick/goat'))
            (if (gGNumber_2)
                proc255_0(600 4)
            )(else
                proc255_0(600 5)
            )
        )(else
            (if (Said('look,look/goat'))
                (if (proc0_12(2))
                    proc255_0(600 6)
                )(else
                    (if (== (send gGoat:script) goatBobs)
                        proc255_0(600 7)
                    )(else
                        (send pEvent:claimed(0))
                    )
                )
            )(else
                (if (Said('kill/goat/shot') or Said('shoot/goat'))
                    (if ((send gEgo:has(10)) and (send gEgo:has(9)))
                        proc255_0(600 8)
                    )(else
                        (if (not (send gEgo:has(10)) or not (send gEgo:has(9)))
                            proc255_0(600 9)
                        )
                    )
                )(else
                    (if (Said('capture,move,move,get,get/goat'))
                        (if (proc0_12(2))
                            proc255_0(600 10)
                        )(else
                            proc255_0(600 11)
                        )
                    )(else
                        (if (Said('stab,kill/goat'))
                            (if (gGNumber_2)
                                proc255_0(600 12)
                            )(else
                                (if ((send global2:script))
                                    proc0_22()
                                )(else
                                    (if (> (send gEgo:distanceTo(gGoat)) 35)
                                        proc255_0(600 13)
                                    )(else
                                        (if (not (send gEgo:has(0)))
                                            proc255_0(600 14)
                                        )(else
                                            (send global2:setScript(killGoat))
                                        )
                                    )
                                )
                            )
                        )(else
                            (if (Said('feed,give/carrot[/goat]') or Said('feed,give/goat[/carrot]'))
                                (if (not (send gEgo:has(2)))
                                    proc0_6()
                                )(else
                                    (if (== (send gGoat:view) 166)
                                        (if (< (send gGoat:loop) 2)
                                            proc255_0(600 15)
                                        )(else
                                            (if (> (send gGoat:loop) 1)
                                                proc255_0(600 16)
                                            )
                                        )
                                    )(else
                                        (if ((send global2:script))
                                            proc0_22()
                                        )(else
                                            (if (> GetDistance((send gEgo:x) (send gEgo:y) (send gGoat:x) (send gGoat:y)) 26)
                                                proc0_4()
                                            )(else
                                                (if (proc0_12(1))
                                                    proc255_0(600 17)
                                                )(else
                                                    (if (== (send gGoat:script) goatBobs)
                                                        (if ((send gEgo:has(2)))
                                                            proc255_0(600 18)
                                                        )(else
                                                            proc255_0(600 19)
                                                        )
                                                    )(else
                                                        (if ((send gEgo:has(2)))
                                                            (send (ScriptID(0 21)):
                                                                number(44)
                                                                init()
                                                                play()
                                                            )
                                                            proc0_11(2)
                                                            (send gEgo:put(2))
                                                            (send gGame:changeScore(-2))
                                                            (if (proc999_5(gNumber 25 39 41))
                                                                (send global2:setScript(goatLeaves))
                                                            )(else
                                                                proc255_0(600 20)
                                                                (send gGoat:setScript(goatBobs))
                                                            )
                                                        )(else
                                                            proc255_0(600 19)
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )(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)))
                                        proc255_0(600 19)
                                    )(else
                                        (if (> GetDistance((send gEgo:x) (send gEgo:y) (send gGoat:x) (send gGoat:y)) 50)
                                            proc0_4()
                                        )(else
                                            (if (proc0_12(2))
                                                proc255_0(600 21)
                                            )(else
                                                (if (proc0_12(1))
                                                    proc255_0(600 17)
                                                )(else
                                                    proc255_0(600 22)
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )


    (method (newRoom newRoomNumber param2)
        (if (global130)
            proc255_0(600 3)
            proc0_11(2)
        )
        (super:newRoom(rest param2))
    )

)
(instance public killGoat of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                proc255_0(600 23)
                (goatKill:
                    init()
                    play()
                )
                (send gGoat:
                    view(166)
                    setCel(0)
                    setLoop(
                        (if (< (send gGoat:heading) 180)
                            0
                        )(else
                            1
                        )
)
                    setMotion(0)
                    setScript(0)
                    cycleSpeed(1)
                    setCycle(End self)
                )
            )
            (case 1
                (goatKill:stop())
                = gGNumber_2 gNumber
                = gGGoatX (send gGoat:x)
                = gGGoatY (send gGoat:y)
                = gGGoatLoop (send gGoat:loop)
                (send gEgo:put(0))
                (send gGame:changeScore(-5))
                proc0_11(2)
                proc0_3()
                (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 goatLeaves of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                proc0_11(2)
                (if (local2)
                    proc255_0(600 24)
                )(else
                    proc255_0(600 25)
                )
                (switch (gNumber)
                    (case 25
                        (send gGoat:setMotion(MoveTo (send gGoat:x) 220 self))
                    )
                    (case 41
                        (send gGoat:setMotion(MoveTo 340 101 self))
                    )
                    (case 39
                        (send gGoat:setMotion(MoveTo 340 (send gGoat:y) self))
                    )
                )
            )
            (case 1
                (send gGoat:dispose())
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance goatKill of Sound
    (properties
        number 104
        priority 10
    )
)
