(version 2)
(include "sci.sh")
(use "Main")
(use "Class_255_0")
(use "Obj")
(script 950)



(procedure (localproc_0004 param1) of Feature
    (switch (param1)
        (case 1
            proc255_4(950 0 description description)
        )
        (case 2
            proc255_4(950 1 description)
        )
        (case 3
            proc255_4(950 2 description)
        )
        (case 4
            proc255_4(950 3 description)
        )
        (case 5
            proc255_4(950 4 description)
        )
        (case 6
            proc255_4(950 5 description)
        )
        (case 7
            proc255_4(950 6 description)
        )
        (case 8
            proc255_4(950 7 description)
        )
        (case 9
            proc255_4(950 8 description)
        )
    )
)


(class Feature of Obj
    (properties
        x 0
        y 0
        z 0
        heading 0
        noun 0
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        description 0
        sightAngle 90
        closeRangeDist 50
        longRangeDist 100
        shiftClick -32767
        contClick 7
        actions 0
        control 0
        verbChecks1 -17483
        verbChecks2 -17477
        verbChecks3 -17477
    )

    (method (init)
        (send gFeatures:add(self))
        (if (not description)
            = description name
        )
    )


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


    (method (handleEvent pEvent)
        (var temp0, temp1)
        (if ((send pEvent:claimed))
            return 1
        )
        (switch ((send pEvent:type))
            (case 128
                (if (not Said(noun))
                )(else
                    = temp1 (send pEvent:message)
                    (if (not temp1)
                        (send pEvent:claimed(0))
                    )(else
                        (if ((self:passedChecks(temp1)))
                            (self:doVerb(temp1))
                        )(else
                            (if (IsObject(actions))
                                (send actions:handleEvent(pEvent self))
                            )
                        )
                    )
                )
            )
            (case 1
                = temp0 (send pEvent:modifiers)
                (if (not temp0)
                )(else
                    (if (not (self:onMe(pEvent)))
                    )(else
                        (if (& temp0 $0003)
                            (if ((& shiftClick $8000) or (self:passedChecks(shiftClick)))
                                (self:doVerb((& $7fff shiftClick)))
                            )
                            (send pEvent:claimed(1))
                        )(else
                            (if (& temp0 $0004)
                                (if ((& contClick $8000) or (self:passedChecks(contClick)))
                                    (self:doVerb((& $7fff contClick)))
                                )
                                (send pEvent:claimed(1))
                            )
                        )
                    )
                )
            )
        )
        return (send pEvent:claimed)
    )


    (method (setChecks param1 param2)
        (var temp0, temp1)
        = temp1 (* 4 (% (- param1 1) 4))
        = temp0 (<< param2 temp1)
        (if (<= param1 4)
            = verbChecks1 (& verbChecks1 bnot (<< $000f temp1))
            = verbChecks1 (| verbChecks1 temp0)
        )(else
            (if (<= param1 8)
                = verbChecks2 (& verbChecks2 bnot (<< $000f temp1))
                = verbChecks2 (| verbChecks2 temp0)
            )(else
                = verbChecks3 (& verbChecks3 bnot (<< $000f temp1))
                = verbChecks3 (| verbChecks3 temp0)
            )
        )
    )


    (method (doVerb theVerb)
        localproc_0004(theVerb description)
    )


    (method (notInFar)
        proc255_4(950 9 description)
    )


    (method (notInNear)
        proc255_4(950 10 description)
    )


    (method (notFacing)
        (var temp0)
        proc255_4(950 11 description)
    )


    (method (facingMe param1)
        (var temp0, temp1)
        = temp0 
            (if (paramTotal)
                param1
            )(else
                gEgo
            )
        = temp1 Abs((- GetAngle((send temp0:x) (send temp0:y) x y) (send temp0:heading)))
        (if (> temp1 180)
            = temp1 (- 360 temp1)
        )
        return 
            (if (<= temp1 sightAngle)
                return 1
            )(else
                (self:notFacing())
                return 0
            )
    )


    (method (nearCheck param1)
        (var temp0)
        = temp0 
            (if (paramTotal)
                param1
            )(else
                gEgo
            )
        return 
            (if (<= GetDistance((send temp0:x) (send temp0:y) x y) closeRangeDist)
                return 1
            )(else
                (self:notInNear())
                return 0
            )
    )


    (method (farCheck param1)
        (var temp0)
        = temp0 
            (if (paramTotal)
                param1
            )(else
                gEgo
            )
        return 
            (if (<= GetDistance((send temp0:x) (send temp0:y) x y) longRangeDist)
                return 1
            )(else
                (self:notInFar())
                return 0
            )
    )


    (method (isNotHidden)
        return 1
    )


    (method (onMe param1 param2)
        (var temp0, temp1)
        (if (IsObject(param1))
            = temp0 (send param1:x)
            = temp1 (send param1:y)
        )(else
            = temp0 param1
            = temp1 param2
        )
        return 
            (if ((((<= nsLeft temp0) and (<= temp0 nsRight)) and (<= nsTop temp1)) and (<= temp1 nsBottom))
                (if (control)
                    & control OnControl(4 temp0 temp1)
                )(else
                    1
                )
            )(else
                0
            )
    )


    (method (passedChecks param1)
        (var temp0)
        (if (<= param1 4)
            verbChecks1
        )(else
            verbChecks2
        )
        (if ((not ((not (& (= temp0 (& (>> verbChecks2 (* 4 (% (- param1 1) 4))) $000f)) $0008) or (self:isNotHidden())) and (not (& temp0 $0004) or (self:farCheck()))) or not (not (& temp0 $0002) or (self:nearCheck()))) or not (& temp0 $0001))
        )(else
            (self:facingMe())
        )
    )

)
