(include "sci.sh")
(use "Main")
(use "Class_255_0")
(script 999)



(procedure (localproc_0616) of Timer
    (var theClient)
    = theClient client
    = client 0
    (if (IsObject(theClient))
        (if ((send theClient:respondsTo(220)))
            (send theClient:timer(0))
        )
        (if ((send theClient:respondsTo(230)))
            (send theClient:cue())
        )
    )
)


(class Obj
    (properties)

    (method (new)
        Clone(self)
    )


    (method (init)
    )


    (method (doit)
    )


    (method (dispose)
        DisposeClone(self)
    )


    (method (showStr param1)
        StrCpy(param1 name)
    )


    (method (showSelf)
        (var temp0[65480])
        Print((self:showStr(@temp0)))
    )


    (method (perform param1 param2)
        (send param1:doit(self rest param2))
    )


    (method (isKindOf param1)
        (var ObjSuperClass)
        = ObjSuperClass (self:superClass())
        (if (not (== species (send param1:species())) and IsObject(ObjSuperClass))
            (send ObjSuperClass:isKindOf(param1))
        )
    )


    (method (isMemberOf param1)
        return 
            (if ((& (send param1:{-info-}()) $8000) and not (& {-info-} $8000))
                == species (send param1:species())
            )(else
                0
            )
    )


    (method (respondsTo param1)
        RespondsTo(self param1)
    )


    (method (yourself)
        return self
    )

)
(class Code of Obj
    (properties)

    (method (doit)
    )

)
(class Collect of Obj
    (properties
        elements 0
        size 0
    )

    (method (dispose)
        (if (elements)
            (self:eachElementDo(172))
            DisposeList(elements)
        )
        = size (= elements 0)
        (super:dispose())
    )


    (method (showStr param1)
        Format(param1 999 0 name size)
    )


    (method (showSelf)
        (var temp0[40])
        Print((self:showStr(@temp0)))
        (self:eachElementDo(176))
    )


    (method (add param1)
        (var temp0, temp1, temp2[41])
        (if (not elements)
            = elements NewList()
        )
        = temp1 0
        (while (< temp1 paramTotal)
            AddToEnd(elements NewNode(param1[temp1] param1[temp1]))
            ++size
            ++temp1
        )
        return self
    )


    (method (delete param1)
        (var temp0, temp1)
        = temp0 0
        = temp1 0
        (while (< temp0 paramTotal)
            (if (DeleteKey(elements param1[temp0]))
                --size
                ++temp1
            )
            ++temp0
        )
        return temp1
    )


    (method (eachElementDo param1 param2)
        (var temp0, temp1, temp2)
        = temp0 FirstNode(elements)
        (while (temp0)
            = temp1 NextNode(temp0)
            (if (not IsObject(= temp2 NodeValue(temp0)))
                return 
            )
            (send temp2:param1(rest param2))
            = temp0 temp1
        )
    )


    (method (firstTrue param1 param2)
        (var temp0, temp1)
        = temp0 FirstNode(elements)
        (while (temp0)
            = temp1 NextNode(temp0)
            (if ((send (NodeValue(temp0)):param1(rest param2)))
                return NodeValue(temp0)
            )
            = temp0 temp1
        )
        return 0
    )


    (method (allTrue param1 param2)
        (var temp0, temp1)
        = temp0 FirstNode(elements)
        (while (temp0)
            = temp1 NextNode(temp0)
            (if (not (send (NodeValue(temp0)):param1(rest param2)))
                return 0
            )
            = temp0 temp1
        )
        return 1
    )


    (method (contains param1)
        FindKey(elements param1)
    )


    (method (isEmpty)
        (if (== elements 0)
        )(else
            EmptyList(elements)
        )
    )


    (method (first)
        FirstNode(elements)
    )


    (method (next param1)
        NextNode(param1)
    )

)
(class List of Collect
    (properties
        elements 0
        size 0
    )

    (method (showStr param1)
        Format(param1 999 1 name size)
    )


    (method (at param1)
        (var temp0)
        = temp0 FirstNode(elements)
        (while (param1 and temp0)
            --param1
            = temp0 NextNode(temp0)
        )
        NodeValue(temp0)
    )


    (method (last)
        LastNode(elements)
    )


    (method (prev param1)
        PrevNode(param1)
    )


    (method (addToFront param1)
        (var temp0)
        (if (not elements)
            = elements NewList()
        )
        = temp0 (- paramTotal 1)
        (while (<= 0 temp0)
            AddToFront(elements NewNode(param1[temp0] param1[temp0]))
            ++size
            --temp0
        )
        return self
    )


    (method (addToEnd param1)
        (var temp0)
        (if (not elements)
            = elements NewList()
        )
        = temp0 0
        (while (< temp0 paramTotal)
            AddToEnd(elements NewNode(param1[temp0] param1[temp0]))
            ++size
            ++temp0
        )
        return self
    )


    (method (addAfter param1 param2)
        (var temp0, temp1, temp2)
        (if (= temp2 FindKey(elements param1))
            --paramTotal
            = temp0 0
            (while (< temp0 paramTotal)
                = temp2 AddAfter(elements temp2 NewNode(param2[temp0] param2[temp0]))
                ++size
                ++temp0
            )
        )
        return self
    )


    (method (indexOf param1)
        (var temp0, temp1)
        = temp0 0
        = temp1 FirstNode(elements)
        (while (temp1)
            (if (== param1 NodeValue(temp1))
                return temp0
            )
            ++temp0
            = temp1 NextNode(temp1)
        )
        return -1
    )

)
(class Set of List
    (properties
        elements 0
        size 0
    )

    (method (showStr param1)
        Format(param1 999 2 name size)
    )


    (method (add param1)
        (var temp0, temp1, temp2)
        (if (not elements)
            = elements NewList()
        )
        = temp1 0
        (while (< temp1 paramTotal)
            = temp2 param1[temp1]
            (if (not (self:contains(temp2)))
                AddToEnd(elements NewNode(temp2 temp2))
                ++size
            )
            ++temp1
        )
    )

)
(class Script of Obj
    (properties
        client 0
        state -1
        start 0
        timer 0
        cycles 0
        seconds 0
        lastSeconds 0
    )

    (method (init theClient)
        = client theClient
        (self:changeState(start))
    )


    (method (doit)
        (var theLastSeconds)
        (if (cycles)
            (if (not --cycles)
                (send client:cue())
            )
        )(else
            (if (seconds and (<> lastSeconds (= theLastSeconds GetTime(1))))
                = lastSeconds theLastSeconds
                (if (not --seconds)
                    (send client:cue())
                )
            )
        )
    )


    (method (dispose)
        (if (IsObject(timer))
            (send timer:dispose())
        )
        (if (IsObject(client))
            (send client:script(0))
        )
        (super:dispose())
    )


    (method (changeState newState)
        = state newState
    )


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


    (method (handleEvent)
    )

)
(class Event of Obj
    (properties
        type 0
        message 0
        modifiers 0
        y 0
        x 0
        claimed 0
    )

    (method (new param1)
        (var newSuper)
        = newSuper (super:new())
        GetEvent(
            (if (paramTotal)
                param1
            )(else
                32767
            )
 newSuper)
        return newSuper
    )

)
(class Timer of Obj
    (properties
        cycleCnt -1
        seconds -1
        lastTime -1
        client 0
    )

    (method (new)
        return 
            (if (== self Timer)
                (super:new())
            )(else
                self
            )
    )


    (method (init theClient)
        (if (IsObject((send theClient:timer())))
            (send ((send theClient:timer())):dispose())
        )
        = client theClient
        (send gTimers:add(self))
        (send theClient:timer(self))
    )


    (method (doit)
        (var theLastTime)
        (if (<> cycleCnt -1)
            (if (not --cycleCnt)
                localproc_0616()
            )
        )(else
            (if (<> lastTime (= theLastTime GetTime(1)))
                = lastTime theLastTime
                (if (not --seconds)
                    localproc_0616()
                )
            )
        )
    )


    (method (dispose)
        (if (IsObject(client) and (send client:respondsTo(220)))
            (send client:timer(0))
        )
        = client 0
    )


    (method (set param1 param2 param3 param4)
        (var newSelf, temp1, temp2, temp3[50])
        (if (== (= temp2 global3) 0)
            = temp2 1
        )
        = temp1 (/ (* param2 60) temp2)
        (if (> paramTotal 2)
            = temp1 (+ temp1 (/ (* param3 3600) temp2))
        )
        (if (> paramTotal 3)
            = temp1 (+ temp1 (* (/ (* param4 3600) temp2) 60))
        )
        (send (= newSelf (self:new())):
            init(param1)
            cycleCnt(temp1)
        )
        return newSelf
    )


    (method (setCycle param1 param2)
        (var newSelf)
        (send (= newSelf (self:new())):
            init(param1)
            cycleCnt(param2)
        )
        return newSelf
    )


    (method (setReal param1 param2 param3 param4)
        (var newSelf, temp1)
        = temp1 param2
        (if (> paramTotal 2)
            = temp1 (+ temp1 (* param3 60))
        )
        (if (> paramTotal 3)
            = temp1 (+ temp1 (* param4 3600))
        )
        (send (= newSelf (self:new())):
            init(param1)
            seconds(temp1)
        )
        return newSelf
    )


    (method (delete)
        (if (== client 0)
            (send gTimers:delete(self))
            (super:dispose())
        )
    )

)
(class TO
    (properties
        timeLeft 0
    )

    (method (set theTimeLeft)
        = timeLeft theTimeLeft
    )


    (method (doit)
        (if (timeLeft)
            --timeLeft
        )
    )

)
