(version 2)
(include "sci.sh")
(use "Main")
(use "Cycle")
(script 874)

(class CycleBet of Cycle
    (properties
        client 0
        caller 0
        cycleDir 1
        cycleCnt 0
        completed 0
        startCel 0
        stopCel 1
        howManyTimes 1
    )

    (method (init param1 param2 param3 param4 theCaller)
        (var clientLastCel)
        (super:init(param1))
        (if (== param4 -1)
            = howManyTimes -1
        )(else
            = howManyTimes (* param4 2)
        )
        (if (> paramTotal 4)
            = caller theCaller
        )
        = clientLastCel (send client:lastCel())
        = startCel 
            (if (< param2 0)
                0
            )(else
                param2
            )
        = stopCel 
            (if (> param3 clientLastCel)
                clientLastCel
            )(else
                param3
            )
        = cycleDir 
            (if (> param3 param2)
                1
            )(else
                -1
            )
        (send client:cel(startCel))
    )


    (method (doit)
        (var temp0)
        (if (>= Abs((- gCycleCnt cycleCnt)) (send client:cycleSpeed))
            (send client:cel((+ (send client:cel) cycleDir)))
            = cycleCnt gCycleCnt
            (if ((== (send client:cel) stopCel) or (== (send client:cel) startCel))
                (self:cycleDone())
            )
        )
    )


    (method (cycleDone)
        (if (== howManyTimes -1)
            (if (== cycleDir 1)
                = cycleDir -1
            )(else
                = cycleDir 1
            )
        )(else
            (if (howManyTimes)
                (if (== cycleDir 1)
                    = cycleDir -1
                )(else
                    = cycleDir 1
                )
                = howManyTimes (- howManyTimes 1)
            )(else
                = completed 1
                (self:motionCue())
            )
        )
    )

)
