(include "sci.sh")
(use "Cycle")
(use "PV")
(script 988)



(procedure (localproc_00ae) of Extra
    (switch (pauseCel)
        (case -1
            (Random(0 (self:lastCel()))  )
        )
        (case 65534
            ((self:lastCel())  )
        )
        (default 
            (pauseCel )
        )
    )
)


(class Extra of Prop
    (properties
        y 0
        x 0
        yStep 2
        view 0
        loop 0
        cel 0
        priority 0
        underBits 0
        signal 0
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        lsTop 0
        lsLeft 0
        lsBottom 0
        lsRight 0
        brTop 0
        brLeft 0
        brBottom 0
        brRight 0
        cycleSpeed 1
        script 0
        cycler 0
        timer 0
        pauseCel 0
        minPause 10
        maxPause 30
        minCycles 8
        maxCycles 20
        state -1
        cycles 0
    )

    (method (init)
        (self:isExtra(1))
        = cel localproc_00ae()
        (self:changeState(0))
        (super:init())
    )


    (method (doit)
        (if (not --cycles)
            (self:cue())
        )
        (super:doit())
    )


    (method (cue)
        (self:changeState((+ state 1)))
    )


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


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


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= cycles Random(minPause maxPause)  )
            )
            (case 1
                ((self:setCycle(Fwd)) = cycles Random(minCycles maxCycles)  )
            )
            (case 2
                ((self:setCel(localproc_00ae())) (self:changeState(0)) )
            )
        )
    )

)
