(version 2)
(include "sci.sh")
(use "Cycle")
(use "PicView")
(script 988)



(procedure (localproc_018a) of Extra
    (switch (pauseCel)
        (case -1
            Random(0 (self:lastCel()))
        )
        (case -2
            (self:lastCel())
        )
        (case == cycleType 0
            pauseCel
        )
    )
)


(class Extra of Prop
    (properties
        x 0
        y 0
        z 0
        heading 0
        noun 0
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        description 0
        sightAngle 90
        closeRangeDist 50
        longRangeDist 100
        shiftClick -32767
        contClick 7
        actions 0
        control 0
        verbChecks1 -17483
        verbChecks2 -17477
        verbChecks3 -17477
        yStep 2
        view 0
        loop 0
        cel 0
        priority 0
        underBits 0
        signal $0000
        lsTop 0
        lsLeft 0
        lsBottom 0
        lsRight 0
        brTop 0
        brLeft 0
        brBottom 0
        brRight 0
        palette 0
        cycleSpeed 1
        script 0
        cycler 0
        timer 0
        cycleType 0
        hesitation 0
        pauseCel 0
        minPause 10
        maxPause 30
        minCycles 8
        maxCycles 20
        counter 0
        state $ffff
        cycles 0
    )

    (method (init)
        = cel localproc_018a()
        (self:changeState(0))
        (super:init())
    )


    (method (doit)
        (if (((== cycleType 1) and (== cel pauseCel)) and (<> pauseCel 0))
            = cycles (+ hesitation 1)
        )
        (if (cycles and not --cycles)
            (self:cue())
        )
        (super:doit())
    )


    (method (cue)
        (if (& signal $0005)
        )(else
            (self:changeState((+ state 1)))
        )
    )


    (method (stopExtra)
        (self:
            setCel(localproc_018a())
            stopUpd()
        )
    )


    (method (startExtra)
        (self:changeState(1))
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (if (<= counter 0)
                    (if (<> cycleType 0)
                        = counter (- Random(minCycles maxCycles) 1)
                    )
                    (if (not = cycles Random(minPause maxPause))
                        (self:cue())
                    )
                )(else
                    --counter
                    (self:cue())
                )
            )
            (case 1
                (if (== cycleType 0)
                    (self:setCycle(Fwd))
                    = cycles Random(minCycles maxCycles)
                )(else
                    (if ((== cycleType 2) and (== pauseCel -2))
                        (self:setCycle(Beg self))
                    )(else
                        (self:setCycle(End self))
                    )
                )
            )
            (case 2
                (if (hesitation and (== cycleType 2))
                    = cycles hesitation
                )(else
                    (self:cue())
                )
            )
            (case 3
                (if (== cycleType 2)
                    (if (<> pauseCel -2)
                        (self:setCycle(Beg self))
                    )(else
                        (self:setCycle(End self))
                    )
                )(else
                    (self:cue())
                )
            )
            (case 4
                (self:setCel(localproc_018a()))
                (self:changeState(0))
            )
        )
    )

)
