(include "sci.sh")
(use "StopWalk")
(use "User")
(use "PicView")
(script 813)


(local
    theCel[8] = (0 4 2 5 1 7 3 6 )

)
(class SQEgo of Ego
    (properties
        x 0
        y 0
        z 0
        heading 0
        noun 0
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        description 0
        sightAngle 26505
        actions 26505
        onMeCheck 26505
        lookStr 0
        yStep 2
        view 0
        loop 0
        cel 0
        priority 0
        underBits 0
        signal 8192
        lsTop 0
        lsLeft 0
        lsBottom 0
        lsRight 0
        brTop 0
        brLeft 0
        brBottom 0
        brRight 0
        palette 0
        cycleSpeed 0
        script 0
        cycler 0
        timer 0
        illegalBits 32768
        xLast 0
        yLast 0
        xStep 3
        moveSpeed 0
        blocks 0
        baseSetter 0
        mover 0
        looper 0
        viewer 0
        avoider 0
        code 0
        edgeHit 0
        _head 0
        normal 1
        moveHead 1
    )

    (method (dispose)
        (if (_head)
            (send _head:dispose())
        )
        (super:dispose())
    )


    (method (stopUpd)
        (if (_head)
            (send _head:stopUpd())
        )
        (super:stopUpd())
    )


    (method (hide)
        (if (_head)
            (send _head:hide())
        )
        (super:hide())
    )


    (method (headView param1)
        (send _head:view(param1))
        (if (not & (send _head:signal) $0008)
            (send _head:showSelf())
        )
    )

)
(class Head of Prop
    (properties
        x 0
        y 0
        z 0
        heading 0
        noun 0
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        description 0
        sightAngle 26505
        actions 26505
        onMeCheck 26505
        lookStr 0
        yStep 2
        view 0
        loop 0
        cel 0
        priority 0
        underBits 0
        signal 0
        lsTop 0
        lsLeft 0
        lsBottom 0
        lsRight 0
        brTop 0
        brLeft 0
        brBottom 0
        brRight 0
        palette 0
        cycleSpeed 0
        script 0
        cycler 0
        timer 0
        client 0
        _cnt 0
        _offSet 0
    )

    (method (init param1)
        (self:
            client(param1)
            ignoreActors(1)
        )
        = loop (- NumLoops(self) 1)
        (send param1:_head(self))
        (super:init())
        (self:hide())
    )


    (method (doit)
        (if ((((((send client:normal) and not (& (send client:signal) $0008)) and (send client:isStopped())) and IsObject((send client:cycler))) and (send ((send client:cycler)):isKindOf(StopWalk))) and (== (send client:view) (send ((send client:cycler)):vStopped)))
            (if ((& signal $0004) and not (& signal $0002))
                (if (& (send client:signal) $0004)
                    return 
                )(else
                    (self:startUpd())
                )
            )
            (self:showSelf())
            (self:lookAround())
        )(else
            (if (not & signal $0008)
                (self:hide())
            )
        )
        (super:doit())
    )


    (method (showSelf)
        (var the_offSet)
        (if (& signal $0008)
            (self:cel((send client:loop)))
            = _cnt cycleSpeed
            = the_offSet 0
            (while (<= the_offSet 7)
                (if (== cel theCel[the_offSet])
                    = _offSet the_offSet
                )
                ++the_offSet
            )
        )
        (self:
            setPri((send client:priority))
            loop(- NumLoops(self) 1)
            x((send client:x))
            y((send client:y))
            z(CelHigh(view (send client:loop) (send client:cel)))
            show()
        )
    )


    (method (lookAround)
        (var temp0)
        (if ((send client:moveHead) and (< --_cnt 1))
            = _cnt cycleSpeed
            (if (> (= temp0 (+ _offSet (- Random(0 2) 1))) 7)
                = temp0 0
            )
            (if (< temp0 0)
                = temp0 7
            )
            = cel theCel[temp0]
        )
    )

)
