(version 2)
(include "sci.sh")
(use "Main")
(use "Cycle")
(use "User")
(use "Obj")
(script 850)



(procedure (localproc_0004 param1 param2)
    (var temp0)
    = temp0 (+ param1 param2)
    (if (> temp0 7)
        = temp0 0
    )(else
        (if (< temp0 0)
            = temp0 7
        )
    )
    return temp0
)


(procedure (localproc_002a param1)
    (switch (param1)
        (case 1
            4
        )
        (case 3
            6
        )
        (default 
            param1
        )
    )
)


(class TurnLooper of Code
    (properties
        client 0
        inited 0
        turningDir 0
        oldCycler 0
        viewNormal 0
        viewChange 0
        finalLoop 0
        currentLoop 0
        TLHandsOff 0
        TLUserInput 0
        TLUserControl 0
    )

    (method (doit theClient param2)
        (var temp0)
        (if (not inited)
            = inited 1
            = client theClient
            = viewNormal (send client:view)
        )
        (if (== turningDir 0)
            = currentLoop localproc_002a((send client:loop))
            DirLoop(client param2)
            = finalLoop localproc_002a((send client:loop))
            (if (<> currentLoop finalLoop)
                = temp0 (- finalLoop currentLoop)
                = turningDir 
                    (if ((== temp0 2) or (== temp0 -6))
                        1
                    )(else
                        -1
                    )
                = oldCycler (send client:cycler)
                (send client:
                    view(viewChange)
                    cycler(0)
                    moveSpeed(200)
                    cel(0)
                )
                (if (== client gEgo)
                    = TLHandsOff gTLHandsOff
                    = TLUserControl (User:controls)
                    = TLUserInput (User:canInput())
                    = gTLHandsOff 1
                    (User:
                        canInput(0)
                        controls(0)
                    )
                )
                (self:cue())
            )
        )
    )


    (method (dispose)
        (if (client)
            (send client:
                view(viewNormal)
                moveSpeed(0)
                setCycle(0)
            )
        )
        (if (oldCycler)
            (send oldCycler:dispose())
        )
        (super:dispose())
    )


    (method (cue)
        (var temp0)
        (if (== currentLoop finalLoop)
            (send client:
                view(viewNormal)
                cycler(oldCycler)
                moveSpeed(0)
                loop(
                    (switch (finalLoop)
                        (case 0
                            0
                        )
                        (case 2
                            2
                        )
                        (case 4
                            1
                        )
                        (case 6
                            3
                        )
                    )
)
            )
            = turningDir (= oldCycler 0)
            (if (== client gEgo)
                (User:controls(TLUserControl))
                (User:canInput(TLUserInput))
                = gTLHandsOff TLHandsOff
            )
        )(else
            = currentLoop localproc_0004(currentLoop turningDir)
            (if (% currentLoop 2)
                = temp0 (/ currentLoop 2)
                (send client:loop(temp0))
                (if (((== turningDir 1) and (== (% temp0 2) 0)) or ((== turningDir -1) and (% temp0 2)))
                    (send client:
                        setCel(0)
                        setCycle(End self)
                    )
                )(else
                    (send client:
                        setCel(255)
                        setCycle(Beg self)
                    )
                )
            )(else
                (self:cue())
            )
        )
    )

)
