(include "sci.sh")
(use "Main")
(use "Class_255_0")
(use "Class_950_0")
(use "Cycle")
(use "Obj")
(script 998)



(class PicView of Feature
    (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
        view 0
        loop 0
        cel 0
        priority -1
        signal 0
        palette 0
    )

    (method (init param1)
        (send gAddToPics:add(self))
        SetNowSeen(self)
        (super:init(rest param1))
    )


    (method (dispose)
        (send gFeatures:delete(self))
        DisposeClone(self)
    )


    (method (showSelf)
        Print(name #icon view loop cel)
    )


    (method (onMe param1)
        (if (& signal $0080)
            0
        )(else
            (super:onMe(rest param1))
        )
    )

)
(class View of Feature
    (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 257
        lsTop 0
        lsLeft 0
        lsBottom 0
        lsRight 0
        brTop 0
        brLeft 0
        brBottom 0
        brRight 0
        palette 0
    )

    (method (init param1 param2)
        = signal (& signal $7fff)
        (if (not (send gCast:contains(self)))
            = lsRight (= lsBottom (= lsLeft (= lsTop 0)))
            = signal (& signal $ff77)
        )
        BaseSetter(self)
        (super:init(rest param2))
    )


    (method (dispose)
        (self:
            startUpd()
            hide()
        )
        = signal (| signal $8000)
    )


    (method (showSelf)
        Print(name #icon view loop cel)
    )


    (method (isNotHidden)
        return not & signal $0088
    )


    (method (onMe param1)
        return 
            (if ((self:isNotHidden()))
                (super:onMe(rest param1))
            )(else
                0
            )
    )


    (method (posn theX theY theZ)
        (if (>= paramTotal 1)
            = x theX
            (if (>= paramTotal 2)
                = y theY
                (if (>= paramTotal 3)
                    = z theZ
                )
            )
        )
        BaseSetter(self)
        (self:forceUpd())
    )


    (method (stopUpd)
        = signal (| signal $0001)
        = signal (& signal $fffd)
    )


    (method (forceUpd)
        = signal (| signal $0040)
    )


    (method (startUpd)
        = signal (| signal $0002)
        = signal (& signal $fffe)
    )


    (method (setPri thePriority)
        (if (== paramTotal 0)
            = signal (| signal $0010)
        )(else
            (if (== thePriority -1)
                = signal (& signal $ffef)
            )(else
                = priority thePriority
                = signal (| signal $0010)
            )
        )
        (self:forceUpd())
    )


    (method (setLoop theLoop)
        (if (== paramTotal 0)
            = signal (| signal $0800)
        )(else
            (if (== theLoop -1)
                = signal (& signal $f7ff)
            )(else
                = loop theLoop
                = signal (| signal $0800)
            )
        )
        (self:forceUpd())
    )


    (method (setCel param1)
        (if (== paramTotal 0)
            = signal (| signal $1000)
        )(else
            (if (== param1 -1)
                = signal (& signal $efff)
            )(else
                = signal (| signal $1000)
                = cel 
                    (if (>= param1 (self:lastCel()))
                        (self:lastCel())
                    )(else
                        param1
                    )
            )
        )
        (self:forceUpd())
    )


    (method (ignoreActors param1)
        (if ((== 0 paramTotal) or param1)
            = signal (| signal $4000)
        )(else
            = signal (& signal $bfff)
        )
    )


    (method (hide)
        = signal (| signal $0008)
    )


    (method (show)
        = signal (& signal $fff7)
    )


    (method (delete)
        (if (& signal $8000)
            = signal (& signal $7fff)
            (send gCast:delete(self))
            (if (underBits)
                UnLoad(133 underBits)
                = underBits 0
            )
            (if (& signal $0020)
                (send gAddToPics:add((send ((PicView:new())):
                        view(view)
                        loop(loop)
                        cel(cel)
                        x(x)
                        y(y)
                        z(z)
                        priority(priority)
                        signal(signal)
                        yourself()
                    )
))
                (send gFeatures:add(self))
            )(else
                DisposeClone(self)
            )
        )
    )


    (method (addToPic)
        (if (not (send gCast:contains(self)))
            (self:init())
        )
        (self:signal((| signal $8021)))
    )


    (method (lastCel)
        return - NumCels(self) 1
    )


    (method (isExtra param1)
        (var temp0)
        = temp0 (& signal $0200)
        (if (paramTotal)
            (if (param1)
                = signal (| signal $0200)
            )(else
                = signal (& signal $fdff)
            )
        )
        return temp0
    )


    (method (motionCue)
    )

)
(class Prop of View
    (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
    )

    (method (doit)
        (var temp0)
        SetNowSeen(self nsTop)
        (if (& signal $8000)
            return 
        )
        (if (script)
            (send script:doit())
        )
        (if ((& signal $0004) and not (& signal $0002))
            return 
        )
        (if (cycler)
            (send cycler:doit())
        )
    )


    (method (handleEvent pEvent)
        (if (script)
            (send script:handleEvent(pEvent))
        )
        (super:handleEvent(pEvent))
    )


    (method (delete)
        (if (& signal $8000)
            (self:
                setScript(0)
                setCycle(0)
            )
            (if (timer)
                (send timer:dispose())
            )
            (super:delete())
        )
    )


    (method (motionCue)
        (if (cycler and (send cycler:completed))
            (send cycler:motionCue())
        )
    )


    (method (setCycle param1 param2)
        (if (cycler)
            (send cycler:dispose())
        )
        (if (param1)
            (self:setCel(-1))
            (self:startUpd())
            = cycler 
                (if (& (send param1:{-info-}) $8000)
                    (send param1:new())
                )(else
                    param1
                )
            (send cycler:init(self rest param2))
        )(else
            = cycler 0
        )
    )


    (method (setScript param1 param2)
        (if (IsObject(script))
            (send script:dispose())
        )
        (if (param1)
            (send param1:init(self rest param2))
        )
    )


    (method (cue)
        (if (script)
            (send script:cue())
        )
    )

)
(class Actor 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
        illegalBits 32768
        xLast 0
        yLast 0
        xStep 3
        moveSpeed 0
        blocks 0
        baseSetter 0
        mover 0
        looper 0
        viewer 0
        avoider 0
        code 0
    )

    (method (init param1)
        (super:init(rest param1))
        = xLast x
        = yLast y
    )


    (method (doit)
        (var temp0, theBrLeft, theBrRight)
        (if (& signal $8000)
            return 
        )
        (if (script)
            (send script:doit())
        )
        (if (code)
            (send code:doit(self))
        )
        (if ((& signal $0004) and not (& signal $0002))
            return 
        )
        (if (viewer)
            (send viewer:doit(self))
        )
        (if (avoider)
            (send avoider:doit())
        )(else
            (if (mover)
                (send mover:doit())
            )
        )
        (if (cycler)
            = theBrLeft brLeft
            = theBrRight brRight
            (send cycler:doit())
            (if (baseSetter)
                (send baseSetter:doit(self))
            )(else
                BaseSetter(self)
            )
            (if (((<> theBrLeft brLeft) or (<> theBrRight brRight)) and not (self:canBeHere()))
                (self:findPosn())
            )
        )
        = xLast x
        = yLast y
    )


    (method (posn theXLast theYLast param3)
        (super:posn(theXLast theYLast rest param3))
        = xLast theXLast
        = yLast theYLast
        (if (not (self:canBeHere()))
            (self:findPosn())
        )
    )


    (method (setLoop param1 param2)
        (var theLooper)
        = theLooper 
            (if (== paramTotal 0)
                (super:setLoop())
                0
            )(else
                (if (not IsObject(param1))
                    (super:setLoop(param1 rest param2))
                    0
                )(else
                    (if (& (send param1:{-info-}) $8000)
                        (send param1:new())
                    )(else
                        param1
                    )
                )
            )
        (if (= theLooper 
            (if (== paramTotal 0)
                (super:setLoop())
                0
            )(else
                (if (not IsObject(param1))
                    (super:setLoop(param1 rest param2))
                    0
                )(else
                    (if (& (send param1:{-info-}) $8000)
                        (send param1:new())
                    )(else
                        param1
                    )
                )
            )
)
            (if (looper)
                (send looper:dispose())
            )
            (send (= looper theLooper):init(self rest param2))
        )
    )


    (method (delete)
        (if (& signal $8000)
            (if (<> mover -1)
                (self:setMotion(0))
            )
            (self:setAvoider(0))
            (if (baseSetter)
                (send baseSetter:dispose())
                = baseSetter 0
            )
            (if (looper)
                (send looper:dispose())
                = looper 0
            )
            (if (viewer)
                (send viewer:dispose())
                = viewer 0
            )
            (if (blocks)
                (send blocks:dispose())
                = blocks 0
            )
            (if (code)
                (send code:dispose())
                = code 0
            )
            (if (IsObject(actions))
                (send actions:dispose())
                = actions 0
            )
            (super:delete())
        )
    )


    (method (motionCue)
        (if (mover and (send mover:completed))
            (send mover:motionCue())
        )
        (super:motionCue())
    )


    (method (setMotion param1 param2)
        (var temp0[40])
        (if (mover and (<> mover -1))
            (send mover:dispose())
        )
        (if (param1)
            (self:startUpd())
            = mover 
                (if (& (send param1:{-info-}) $8000)
                    (send param1:new())
                )(else
                    param1
                )
            (send mover:init(self rest param2))
        )(else
            = mover 0
        )
    )


    (method (setAvoider param1 param2)
        (if (avoider)
            (send avoider:dispose())
        )
        = avoider 
            (if (IsObject(param1) and (& (send param1:{-info-}) $8000))
                (send param1:new())
            )(else
                param1
            )
        (if (avoider)
            (send avoider:init(self rest param2))
        )
    )


    (method (ignoreHorizon param1)
        (if (not paramTotal or param1)
            = signal (| signal $2000)
        )(else
            = signal (& signal $dfff)
        )
    )


    (method (observeControl param1)
        (var temp0)
        = temp0 0
        (while (< temp0 paramTotal)
            = illegalBits (| illegalBits param1[temp0])
            ++temp0
        )
    )


    (method (ignoreControl param1)
        (var temp0)
        = temp0 0
        (while (< temp0 paramTotal)
            = illegalBits (& illegalBits bnot param1[temp0])
            ++temp0
        )
    )


    (method (observeBlocks param1)
        (if (not blocks)
            = blocks (Set:new())
        )
        (send blocks:add(rest param1))
    )


    (method (ignoreBlocks param1)
        (send blocks:delete(rest param1))
        (if ((send blocks:isEmpty()))
            (send blocks:dispose())
            = blocks 0
        )
    )


    (method (isStopped)
        return 
            (if (not not IsObject(mover) and (== x (send mover:xLast)))
                == y (send mover:yLast)
            )(else
                0
            )
    )


    (method (isBlocked)
        return & signal $0400
    )


    (method (findPosn)
        (var temp0, temp1, theX, theY, temp4)
        = theX x
        = theY y
        = temp4 0
        = temp1 1
        (while (not temp4)
            = temp0 0
            (while (not temp4 and (< temp0 8))
                = x (+ theX (* temp1 proc999_0(CosMult((* temp0 45) 100))))
                = y (- theY (* temp1 proc999_0(SinMult((* temp0 45) 100))))
                = temp4 
                    (if ((self:canBeHere()))
                        (self:onControl())
                    )(else
                        0
                    )
                ++temp0
            )
            ++temp1
        )
        (self:posn(x y))
    )


    (method (inRect param1 param2 param3 param4)
        return 
            (if (((<= param1 x) and (< x param3)) and (<= param2 y))
                < y param4
            )(else
                0
            )
    )


    (method (onControl param1)
        (if (paramTotal and param1)
            OnControl(4 x y)
        )(else
            OnControl(4 brLeft brTop brRight brBottom)
        )
    )


    (method (distanceTo param1)
        GetDistance(x y (send param1:x) (send param1:y) gPicAngle)
    )


    (method (canBeHere)
        (if (baseSetter)
            (send baseSetter:doit(self))
        )(else
            BaseSetter(self)
        )
        (if (not ((((== illegalBits 0) and (& signal $4000)) or CanBeHere(self (send gCast:elements))) and (((& signal $2000) or not IsObject(global2)) or (>= y (send global2:horizon)))) or (== blocks 0))
        )(else
            (send blocks:allTrue(60 self))
        )
    )


    (method (setStep theXStep theYStep)
        (if ((>= paramTotal 1) and (<> theXStep -1))
            = xStep theXStep
        )
        (if ((>= paramTotal 2) and (<> theYStep -1))
            = yStep theYStep
        )
        (if ((mover and (<> -1 mover)) and (send mover:isMemberOf(MoveTo)))
            (send ((self:mover)):init())
        )
    )


    (method (setDirection param1)
        (var temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7)
        = temp1 (send global2:vanishingY)
        = temp0 
            (if (== (= temp1 (send global2:vanishingY)) 35536)
                x
            )(else
                (send global2:vanishingX)
            )
        (if ((== xStep 0) and (== yStep 0))
            return 
        )
        = temp5 (/ 32000 proc999_3(xStep yStep))
        (switch (param1)
            (case 0
                (self:setMotion(0))
                return 
            )
            (case 1
                = temp2 (- temp0 x)
                = temp3 (- temp1 y)
            )
            (case 5
                = temp2 (- x temp0)
                = temp3 (- y temp1)
            )
            (case 3
                = temp2 temp5
                = temp3 0
            )
            (case 7
                = temp2 neg temp5
                = temp3 0
            )
            (default 
                = temp4 GetAngle(x y temp0 temp1)
                (if (< 180 temp4)
                    = temp4 (- temp4 360)
                )
                = temp4 (+ (/ (+ temp4 90) 2) (* 45 (- param1 2)))
                = temp2 SinMult(temp4 100)
                = temp3 neg CosMult(temp4 100)
            )
        )
        = temp5 (/ temp5 5)
        (while ((< Abs(temp3) temp5) and (< Abs(temp2) temp5))
            = temp2 (* temp2 5)
            = temp3 (* temp3 5)
        )
        = temp7 (send global2:obstacles)
        (if ((= temp7 (send global2:obstacles)) and global87)
            = temp6 AvoidPath(x y (+ x temp2) (+ y temp3) (send temp7:elements) (send temp7:size) 0)
            = temp2 (- proc999_6(temp6 2) x)
            = temp3 (- proc999_6(temp6 3) y)
            Memory(3 temp6)
        )
        (if (temp2 or temp3)
            (self:setMotion(MoveTo (+ x temp2) (+ y temp3)))
        )(else
            (if (param1)
                (self:
                    setMotion(0)
                    setHeading(* (- param1 1) 45)
                )
            )(else
                (self:setMotion(0))
            )
        )
    )


    (method (setHeading theHeading param2 param3)
        (if (paramTotal)
            = heading theHeading
        )
        (if (looper)
            (send looper:doit(self heading 
                (if (>= paramTotal 2)
                    param2
                )(else
                    0
                )
))
        )(else
            DirLoop(self heading)
            (if ((>= paramTotal 2) and IsObject(param2))
                (send param2:cue(rest param3))
            )
        )
        return heading
    )

)
