(version 2)
(include "sci.sh")
(exports
    0 beanRg
)
(use "Main")
(use "Class_255_0")
(use "n958")
(use "Rev")
(use "Follow")
(use "Cycle")
(use "Game")
(use "PicView")
(use "Obj")
(script 606)


(local
    local0
    local1
    local2

)
(instance public beanRg of Rgn
    (properties)

    (method (init param1)
        (self:keep(0))
        (super:init(rest param1))
        proc958_0(128 1 270)
        Load(rsPIC 270)
        Load(rsSOUND 94)
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )(else
            (if ((super:handleEvent(pEvent)))
            )(else
                (if (Said('bury/bean'))
                    (if (gGNumber_4)
                        proc255_0(606 0)
                    )(else
                        (if (not (send gEgo:has(20)))
                            (if (proc0_12(35))
                                proc255_0(606 1)
                            )(else
                                proc0_6()
                            )
                        )(else
                            (if (not & (send gEgo:onControl(1)) $0400)
                                proc255_0(606 2)
                            )(else
                                (if ((send global2:script))
                                    proc0_22()
                                )(else
                                    (if (proc0_12(1))
                                        proc255_0(606 3)
                                    )(else
                                        (if ((send gCast:contains(gGoat)) and (send gGoat:inRect(110 125 220 150)))
                                            = local1 
                                                (if (< (send gGoat:x) 165)
                                                    -1
                                                )(else
                                                    1
                                                )
                                            = local2 
                                                (if (< (send gGoat:y) 137)
                                                    -1
                                                )(else
                                                    1
                                                )
                                        )
                                        (send global2:setScript(plantBeans))
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )

)
(instance plantBeans of Script
    (properties)

    (method (doit)
        (if ((> state 3) and (<> local0 (send (ScriptID(0 21)):prevSignal)))
            = local0 (send (ScriptID(0 21)):prevSignal)
            (self:cue())
        )
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:
                    ignoreActors()
                    illegalBits(0)
                    setMotion(MoveTo 131 138 self)
                )
            )
            (case 1
                proc0_19(109 2)
                (send gEgo:
                    loop(0)
                    cel(0)
                    view(1)
                    cycleSpeed(2)
                    setCycle(End self)
                )
            )
            (case 2
                (send gEgo:setCycle(Beg self))
            )
            (case 3
                proc0_1()
                proc255_0(606 4)
                (self:cue())
            )
            (case 4
                (send (ScriptID(0 21)):
                    number(94)
                    init()
                    play()
                )
                (send gEgo:
                    setLoop(0)
                    setCycle(SyncWalkBack 2)
                )
                (self:cue())
            )
            (case 5
                0
            )
            (case 6
                ShakeScreen(1 1)
                (stalk:
                    posn(149 138)
                    init()
                    setCycle(End)
                )
                (send gEgo:setMotion(MoveTo 127 138))
                (if (local1)
                    = gGGoatX (+ (send gGoat:x) (* local1 5))
                    = gGGoatY (+ (send gGoat:y) (* local2 3))
                    (send gGoat:setMotion(MoveTo gGGoatX gGGoatY))
                )
                = gGNumber_4 gNumber
            )
            (case 7
                ShakeScreen(8 3)
                (stalk:
                    loop(1)
                    cel(0)
                    setCycle(End)
                )
                (send gEgo:setMotion(MoveTo 117 138))
                (if (local1)
                    = gGGoatX (+ (send gGoat:x) (* local1 5))
                    = gGGoatY (+ (send gGoat:y) (* local2 3))
                    (send gGoat:setMotion(MoveTo gGGoatX gGGoatY))
                )
            )
            (case 8
                ShakeScreen(12 1)
                (stalk:
                    loop(2)
                    cel(0)
                    setCycle(CT 5 1)
                )
                (send gEgo:setMotion(MoveTo 107 138))
                (if (local1)
                    = gGGoatX (+ (send gGoat:x) (* local1 5))
                    = gGGoatY (+ (send gGoat:y) (* local2 3))
                    (send gGoat:setMotion(MoveTo gGGoatX gGGoatY))
                )
            )
            (case 9
                ShakeScreen(18 3)
                (if (local1)
                    = gGGoatX (+ (send gGoat:x) (* local1 5))
                    = gGGoatY (+ (send gGoat:y) (* local2 3))
                    (send gGoat:setMotion(MoveTo gGGoatX gGGoatY))
                )
                (stalk:stopUpd())
                (self:cue())
            )
            (case 10
                (send global2:overlay(270 4))
                proc0_1()
                proc0_15(gEgo stalk)
                (stalk:dispose())
                (if ((<> gGNumber_2 gNumber) and proc0_12(2))
                    = gGGoatX 0
                    = gGGoatY 0
                    (send gGoat:setMotion(Follow gEgo 60))
                )
                proc0_3()
                (send global2:setRegions(607))
                (self:dispose())
            )
        )
    )

)
(instance stalk of Prop
    (properties
        description 1686
        view 270
        cycleSpeed 2
    )
)
(class SyncWalkBack of Rev
    (properties
        client 0
        caller 0
        cycleDir -1
        cycleCnt 0
        completed 0
        xLast 0
        yLast 0
        vWalking 0
        vStopped 0
    )

    (method (init theClient theVStopped)
        (if (paramTotal)
            = vWalking (send ((= client theClient)):view)
            (if (>= paramTotal 2)
                = vStopped theVStopped
            )
        )
        (super:init(client))
    )


    (method (doit)
        (var clientMover, clientMover_2, temp2)
        = clientMover (send client:mover)
        (if (IsObject(clientMover) and ((<> (send client:x) xLast) or (<> (send client:y) yLast)))
            = xLast (send client:x)
            = yLast (send client:y)
            (super:doit())
        )
        (if ((send client:isStopped()))
            (if (== (send client:view) vWalking)
                (send client:view(vStopped))
                = clientMover_2 (send client:mover)
                (if (clientMover_2 and not (send ((= clientMover_2 (send client:mover))):completed))
                    (send client:setMotion(0))
                )
                (super:doit())
            )
        )(else
            (if (== (send client:view) vStopped)
                (send client:view(vWalking))
            )
            (super:doit())
        )
    )


    (method (dispose)
        (if (== (send client:view) vStopped)
            (send client:view(vWalking))
        )
        (super:dispose())
    )


    (method (nextCel)
        = cycleCnt (send client:cycleSpeed)
        (super:nextCel())
    )

)
