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



(class OccasionalCycle of Cycle
    (properties
        client 0
        caller 0
        cycleDir 1
        cycleCnt 0
        completed 0
        lowerEnd 5
        upperEnd 6
        waitCycles 0
    )

    (method (init theClient param2 theCycleDir theLowerEnd theUpperEnd)
        (if (>= paramTotal 2)
            = client theClient
            (if (>= paramTotal 3)
                = cycleDir theCycleDir
                (if (>= paramTotal 4)
                    = lowerEnd theLowerEnd
                    (if (>= paramTotal 5)
                        = upperEnd theUpperEnd
                    )
                )
            )
        )
        = completed (= cycleCnt 0)
        (self:cycleDone())
    )


    (method (doit)
        (var temp0)
        (asm
            pushi   #nextCel
            pushi   0
            self    4
            sat     temp0
            pToa    waitCycles
            bnt     code_0083
            dpToa   waitCycles
            jmp     code_00ac
code_0083:  lst     temp0
            pushi   #lastCel
            pushi   0
            pToa    client
            send    4
            gt?     
            bt      code_0097
            lst     temp0
            ldi     0
            lt?     
            bnt     code_00a3
code_0097:  jmp     code_0099
code_0099:  bnt     code_00a3
            pushi   #cycleDone
            pushi   0
            self    4
            jmp     code_00ac
code_00a3:  pushi   #cel
            pushi   1
            lst     temp0
            pToa    client
            send    6
code_00ac:  ret     
        )
    )


    (method (cycleDone)
        = waitCycles Random(lowerEnd upperEnd)
        (send client:cel(
            (if (= cycleDir 1)
                0
            )(else
                (send client:lastCel())
            )
))
        = cycleCnt GetTime()
    )

)
