(version 2)
(include "sci.sh")
(exports
    0 streetRgn
    1 wanderTalker
)
(use "Main")
(use "Blink")
(use "Scaler")
(use "n958")
(use "Timer")
(use "RegionPath")
(use "Cycle")
(use "Game")
(use "View")
(use "Obj")
(script 90)


(local
    local0[57] = (105 "Urchin" 11 106 "Carrie Sue" 2 117 "Rover, the town dog" 4 119 "Lucky" 5 120 "Trixie, the town sheep" 6 121 "Duck Gillespie" 7 122 "Colonel Shanders" 8 123 "Francis Bacon" 9 128 "See them tumblin' down" 10 824 "Preacher's Kid" 1 825 "Ragamuffin" 12 827 "Ol' Pickaxe Pete" 13 828 "Officer Wilke" 14 830 "Pony Express Rider" 16 832 "Clem" 17 833 "Amos" 18 835 "Miz Tucker" 19 836 "Miss Eulalie" 20 834 "Bridget and Rocko O'Hanrahan" 21 )
    local57
    local58
    local59
    theSSitDown[5] = (0 1 2 3 4 )
    local65[49] = (32767 220 160 152 355 152 32767 230 -35 152 355 152 32767 240 -35 152 355 152 32767 250 -35 152 190 152 32767 250 190 152 -35 152 32767 240 355 152 -35 152 32767 230 355 152 -35 152 32767 220 355 152 160 152 -32768 )
    local114[63] = (32767 240 160 125 -35 125 32767 230 355 125 230 125 -35 130 32767 220 355 130 109 130 32767 220 109 130 355 130 32767 230 -35 130 230 125 355 125 32767 240 -35 125 355 125 32767 250 -35 125 93 125 212 135 32767 250 212 135 93 125 -35 125 32767 240 355 125 160 125 -32768 )
    local177[57] = (32767 250 160 129 -35 129 32767 240 355 129 119 129 -35 168 32767 230 355 168 58 168 -35 146 32767 220 355 146 214 181 32767 220 214 181 355 146 32767 230 -35 146 58 168 355 168 32767 240 -35 168 119 129 355 129 32767 250 -35 129 160 129 -32768 )

)
(instance public streetRgn of Rgn
    (properties)

    (method (init)
        = theSSitDown[0] sSitDown
        = theSSitDown[1] sLieDown
        = theSSitDown[2] sWag
        = theSSitDown[3] sPant
        = theSSitDown[4] sLickTummy
        (if (proc0_2(71) or not proc999_5(gGNumber 220 230 240 250))
            (if (proc0_2(71))
                proc0_4(71)
            )
            = local57 (* Random(0 18) 3)
            = local58 Random(30 300)
            (wander1:
                view(local0[local57])
                name(local0[+ local58 1])
                noun(local0[+ local57 2])
            )
            (if (proc999_5((wander1:view) 827 828 830 106 832))
                (wander1:xStep(6))
            )(else
                (wander1:xStep(3))
            )
            (wanderTimer2:setReal(wanderTimer2 local58))
        )
        (if (> (send gGame:detailLevel()) (wander1:detailLevel()))
            (wander1:
                init()
                loop(0)
                setCycle(Walk)
                setMotion(wander1Path wander1)
            )
            (if ((wander1:findX()))
                (wander1Path:findNextRoom())
            )
        )
        (if (> (send gGame:detailLevel()) (wander2:detailLevel()))
            (wander2:
                init()
                loop(0)
                setCycle(Walk)
            )
        )
        (if (> (send gGame:detailLevel()) (wander3:detailLevel()))
            (wander3:
                init()
                loop(0)
                setCycle(Walk)
            )
        )
        (if (== (wander2:view) 1843)
            (wander2:z(1000))
        )(else
            (wander2:setMotion(wander2Path wander2))
            (if ((wander2:findX()))
                (wander2Path:findNextRoom())
            )
        )
        (if (== (wander3:view) 1843)
            (wander3:z(1000))
        )(else
            (wander3:setMotion(wander3Path wander3))
            (if ((wander3:findX()))
                (wander3Path:findNextRoom())
            )
        )
        (super:init())
    )


    (method (dispose)
        proc958_0(0 984)
        (send gTimers:delete(wanderTimer2 wanderTimer3 soundTimer1 soundTimer2 soundTimer3))
        (super:dispose())
    )


    (method (newRoom newRoomNumber)
        = keep proc999_5(newRoomNumber 220 230 240 250)
        = initialized 0
    )

)
(class Wanderer of Actor
    (properties
        x 0
        y 0
        z 1000
        heading 0
        noun 0
        modNum 90
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        sightAngle 26505
        actions 0
        onMeCheck $6789
        state $0000
        approachX 0
        approachY 0
        approachDist 0
        _approachVerbs 0
        yStep 2
        view 1843
        loop 0
        cel 0
        priority 0
        underBits 0
        signal $1000
        lsTop 0
        lsLeft 0
        lsBottom 0
        lsRight 0
        brTop 0
        brLeft 0
        brBottom 0
        brRight 0
        scaleSignal $0004
        scaleX 128
        scaleY 128
        maxScale 128
        cycleSpeed 6
        script 0
        cycler 0
        timer 0
        detailLevel 2
        scaler 0
        illegalBits $8000
        xLast 0
        yLast 0
        xStep 3
        origStep 770
        moveSpeed 6
        blocks 0
        baseSetter 0
        mover 0
        looper 0
        viewer 0
        avoider 0
        code 0
    )

    (method (init)
        (super:init())
        (self:setLoop(-1))
        (if (not proc999_5(view 829 830))
            (self:setScale(Scaler 100 76 162 110))
        )
        (if ((== gNumber 230) and (== gGNumber 500))
            = noun 24
        )
    )


    (method (doVerb theVerb)
        (wanderTalker:name(name))
        (super:doVerb(rest theVerb))
    )


    (method (cue)
        (super:cue())
        (if (proc999_5(view 117 832 833 824 827 835))
            (self:setScript(sSitDown 0 loop))
        )
    )


    (method (findX)
        return 
            (if ((< nsLeft 0) and (== (send gEgo:edgeHit) 4))
                (if (< (send mover:x) 0)
                    (if (< nsRight 0)
                        = x (- 320 CelWide(view loop cel))
                        return 1
                    )(else
                        = x (+ x 320)
                        return 1
                    )
                )(else
                    = x (+ x 320)
                    (send mover:findPrevRoom())
                    return 0
                )
            )(else
                (if (((< nsLeft 0) and (== (send gEgo:edgeHit) 2)) and (== (send mover:currentRoom) gNumber))
                    = x CelWide(view loop cel)
                    return 0
                )(else
                    (if ((> nsRight 320) and (== (send gEgo:edgeHit) 2))
                        (if (> (send mover:x) 320)
                            (if (> nsLeft 320)
                                = x CelWide(view loop cel)
                                return 1
                            )(else
                                = x (- x 320)
                                return 1
                            )
                        )(else
                            = x (- x 320)
                            (send mover:findPrevRoom())
                            return 0
                        )
                    )(else
                        (if (((> nsRight 320) and (== (send gEgo:edgeHit) 4)) and (== (send mover:currentRoom) gNumber))
                            = x (- 320 CelWide(view loop cel))
                            return 0
                        )(else
                            return 0
                        )
                    )
                )
            )
    )

)
(instance wander1 of Wanderer
    (properties)
)
(instance wander2 of Wanderer
    (properties)
)
(instance wander3 of Wanderer
    (properties)
)
(class WandererPath of RegionPath
    (properties
        client 0
        caller 0
        x 0
        y 0
        dx 0
        dy 0
        {b-moveCnt} 0
        {b-i1} 0
        {b-i2} 0
        {b-di} 0
        {b-xAxis} 0
        {b-incr} 0
        completed 1
        xLast 0
        yLast 0
        currentRoom 0
        value -1
        endType 1
        intermediate 0
        initialized 0
        savedOldStuff 0
        theRegion 90
        theOldBits 0
        theOldSignal 0
    )

    (method (init param1)
        (super:init(rest param1))
        = endType 
            (if (proc999_5((send client:view) 117 832 833 824 827 835))
                0
            )(else
                1
            )
    )


    (method (curRoomCheck)
        (var clientZ, temp1)
        = clientZ (send client:z)
        (if (== currentRoom gNumber)
            (send client:
                z(
                    (if (>= clientZ 1000)
                        - clientZ 1000
                    )(else
                        clientZ
                    )
)
                illegalBits(theOldBits)
                signal(theOldSignal)
            )
            (switch ((send client:noun))
                (case 4
                    = temp1 2117
                )
                (case 5
                    = temp1 2117
                )
                (case 6
                    = temp1 2120
                )
                (case 7
                    = temp1 2121
                )
                (case 8
                    = temp1 2122
                )
                (case 9
                    = temp1 2123
                )
                (default 
                    = temp1 0
                )
            )
            (if (temp1)
                (wander1Sound:number(temp1))
                (soundTimer1:setReal(soundTimer1 Random(5 10)))
            )
        )(else
            (send client:
                z(
                    (if (< clientZ 1000)
                        + clientZ 1000
                    )(else
                        clientZ
                    )
)
                illegalBits(0)
                ignoreActors(1)
                ignoreHorizon()
            )
            (send gTimers:delete(soundTimer1))
        )
    )


    (method (findNextRoom)
        (var clientX, clientY)
        = clientX (send client:x)
        = clientY (send client:y)
        (while (<> (self:at(value)) 32767)
            (self:nextValue(1))
        )
        (self:
            nextRoom()
            next()
        )
        (send client:posn(clientX clientY))
    )


    (method (findPrevRoom)
        (var clientX, clientY, theX, theY)
        = clientX (send client:x)
        = clientY (send client:y)
        = theX x
        = theY y
        (while (<> (self:at(value)) 32767)
            = value (- value 4)
            (self:nextValue(1))
        )
        = value (- value 4)
        (self:nextValue(1))
        (while (<> (self:at(value)) 32767)
            = value (- value 4)
            (self:nextValue(1))
        )
        (self:
            nextRoom()
            x(theX)
            y(theY)
        )
        (send client:posn(clientX clientY))
    )

)
(instance wander1Path of WandererPath
    (properties)

    (method (at param1)
        return local65[param1]
    )

)
(instance wander2Path of WandererPath
    (properties)

    (method (at param1)
        return local114[param1]
    )

)
(instance wander3Path of WandererPath
    (properties)

    (method (at param1)
        return local177[param1]
    )

)
(instance wanderTimer2 of Timer
    (properties)

    (method (setReal param1)
        (streetRgn:timer(self))
        (super:setReal(rest param1))
    )


    (method (cue)
        (if (== gNumber 240)
            (self:setReal(self local58))
        )(else
            (while (proc999_5(= local57 (* Random(0 18) 3) 830 (wander1:view) (wander3:view)))
            )
            = local58 Random(30 300)
            (wander2:
                view(local0[local57])
                name(local0[+ local58 1])
                noun(local0[+ local57 2])
            )
            (if (proc999_5((wander2:view) 827 828 830 106 832))
                (wander2:xStep(6))
            )(else
                (wander2:xStep(3))
            )
            (wanderTimer3:setReal(wanderTimer3 local58))
            (if (> (send gGame:detailLevel()) (wander2:detailLevel()))
                (wander2:
                    init()
                    loop(1)
                    setCycle(Walk)
                    setMotion(wander2Path wander2)
                )
            )
        )
    )

)
(instance wanderTimer3 of Timer
    (properties)

    (method (setReal param1)
        (streetRgn:timer(self))
        (super:setReal(rest param1))
    )


    (method (cue)
        (if (== gNumber 250)
            (self:setReal(self local58))
        )(else
            (while (proc999_5(= local57 (* Random(0 18) 3) 830 (wander1:view) (wander2:view)))
            )
            (wander3:
                view(local0[local57])
                name(local0[+ local57 1])
                noun(local0[+ local57 2])
            )
            (if (proc999_5((wander3:view) 827 828 830 106 832))
                (wander3:xStep(6))
            )(else
                (wander3:xStep(3))
            )
            (if (> (send gGame:detailLevel()) (wander3:detailLevel()))
                (wander3:
                    init()
                    loop(0)
                    setCycle(Walk)
                    setMotion(wander3Path wander3)
                )
            )
        )
    )

)
(instance soundTimer1 of Timer
    (properties)

    (method (setReal param1)
        (streetRgn:timer(self))
        (super:setReal(rest param1))
    )


    (method (cue)
        (if (< (wander1:z) 1000)
            (wander1Sound:play())
        )
        (self:setReal(self Random(5 10)))
    )

)
(instance soundTimer2 of Timer
    (properties)

    (method (setReal param1)
        (streetRgn:timer(self))
        (super:setReal(rest param1))
    )


    (method (cue)
        (if (< (wander2:z) 1000)
            (wander2Sound:play())
        )
        (self:setReal(self Random(5 10)))
    )

)
(instance soundTimer3 of Timer
    (properties)

    (method (setReal param1)
        (streetRgn:timer(self))
        (super:setReal(rest param1))
    )


    (method (cue)
        (if (< (wander3:z) 1000)
            (wander3Sound:play())
        )
        (self:setReal(self Random(5 10)))
    )

)
(instance sSitDown of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (if (proc999_5((send client:view) 117 832 827 835))
                    (send client:setLoop((+ 2 register)))
                )(else
                    (send client:setLoop(2))
                )
                (send client:
                    cel(0)
                    setCycle(End self)
                )
            )
            (case 1
                = local59 Random(1 4)
                (if (== (send client:view) 117)
                    (send client:setScript(theSSitDown[local59] 0 register))
                )(else
                    = cycles 2
                )
            )
            (case 2
                (if (proc999_5((send client:view) 827 835 832))
                    (send client:setLoop((+ (send client:loop) 2)))
                )(else
                    (send client:setLoop(3))
                )
                (send client:
                    cel(0)
                    setCycle(End self)
                )
            )
            (case 3
                (self:dispose())
            )
        )
    )

)
(instance sLieDown of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send client:
                    setLoop(+ 4 register)
                    cel(0)
                    setCycle(End self)
                )
            )
            (case 1
                (if (< (send client:z) 1000)
                    (send gTimers:delete(soundTimer1 soundTimer2 soundTimer3))
                    (dogSound:
                        number(2118)
                        loop(1)
                        play(self)
                    )
                )
            )
            (case 2
                = seconds 12
            )
            (case 3
                (self:changeState(1))
            )
        )
    )

)
(instance sWag of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send client:
                    setLoop(+ 8 register)
                    cel(0)
                    setCycle(Fwd)
                )
                = ticks Random(60 120)
            )
            (case 1
                = local59 Random(1 4)
                (send client:setScript(theSSitDown[local59] 0 register))
            )
        )
    )

)
(instance sPant of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send client:
                    setLoop(+ 10 register)
                    cel(0)
                    setCycle(End self)
                )
            )
            (case 1
                = ticks Random(60 120)
                = local59 Random(1 4)
                (send client:setScript(theSSitDown[local59] 0 register))
            )
        )
    )

)
(instance sLickTummy of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send client:
                    setLoop(+ 12 register)
                    cel(0)
                    setCycle(End self)
                )
            )
            (case 1
                (send client:
                    setLoop(+ 14 register)
                    cel(0)
                    setCycle(Fwd)
                )
                (if (proc999_5((send client:noun) 4 5) and (< (send client:z) 1000))
                    (send gTimers:delete(soundTimer1 soundTimer2 soundTimer3))
                    (dogSound:
                        number(2119)
                        loop(-1)
                        play()
                    )
                )
                = ticks Random(60 120)
            )
            (case 2
                = local59 Random(1 4)
                (send client:setScript(theSSitDown[local59] 0 register))
                (dogSound:stop())
            )
        )
    )

)
(instance public wanderTalker of Narrator
    (properties)

    (method (init param1)
        = font gFont
        = showTitle 1
        = back gBack
        (super:init(rest param1))
    )

)
(instance wander1Sound of FPSound
    (properties
        flags $0001
    )
)
(instance wander2Sound of FPSound
    (properties
        flags $0001
    )
)
(instance wander3Sound of FPSound
    (properties
        flags $0001
    )
)
(instance dogSound of FPSound
    (properties
        flags $0001
        loop -1
    )
)
