(version 2)
(include "sci.sh")
(exports
    0 rm18
)
(use "Main")
(use "Class_255_0")
(use "NewFeature")
(use "Blk")
(use "n958")
(use "Wander")
(use "Cycle")
(use "Game")
(use "PicView")
(use "Obj")
(script 18)


(local
    local0

)
(instance elfCage of Cage
    (properties
        top 76
        left 1
        bottom 189
        right 319
    )
)
(instance public rm18 of Rm
    (properties
        picture 18
        horizon 65
        north 31
        east 17
        south 15
        west 19
    )

    (method (init)
        proc958_0(128 13 150)
        (self:style(
            (switch (gGNumber)
                (case north
                    5
                )
                (case west
                    3
                )
                (case east
                    2
                )
                (case south
                    4
                )
            )
))
        (super:init())
        (switch (gGNumber)
            (case north
                (send gEgo:posn(proc0_17(184 (send gEgo:x) 85) (+ horizon 2)))
            )
            (case south
                (send gEgo:y(188))
            )
            (case west
                (send gEgo:posn(3 proc0_17(188 (send gEgo:y) 79)))
            )
            (case east
                (if (global130)
                    (send gEgo:posn(317 proc0_17(166 (send gEgo:y) 96)))
                )(else
                    (send gEgo:posn(317 proc0_17(188 (send gEgo:y) 170)))
                )
            )
            (default 
                (send gEgo:posn(3 137))
                = local0 1
            )
        )
        proc0_1()
        (if (global130)
            (send gEgo:view(13))
        )
        (send gEgo:init())
        (self:setRegions(603))
        (if (((local0 and not proc0_12(11)) and not proc0_12(65)) or ((not proc0_12(11) and not proc0_12(65)) and Random(0 1)))
            (elf:
                init()
                illegalBits(-32750)
                setCycle(Walk)
                setMotion(Wander)
            )
            (elfCage:init())
            (elf:observeBlocks(elfCage))
            proc255_0(18 0)
        )
        (hill1:init())
        (hill2:init())
        (bush:init())
    )


    (method (handleEvent pEvent)
        (if (((((((Said('look,look/ceder[<pine]') or proc0_14(pEvent 142 78 201 133)) or proc0_14(pEvent 149 66 186 77)) or proc0_14(pEvent 159 57 177 66)) or proc0_14(pEvent 214 58 276 84)) or proc0_14(pEvent 223 40 271 58)) or proc0_14(pEvent 228 29 265 40)) or proc0_14(pEvent 242 19 258 29))
            proc255_0(18 1)
        )(else
            (if (((((Said('look,look/lake,lake,water,cliff,bank') or proc0_14(pEvent 287 95 320 113)) or proc0_14(pEvent 268 113 319 134)) or proc0_14(pEvent 239 116 268 128)) or proc0_14(pEvent 228 136 320 154)) or proc0_14(pEvent 252 154 320 165))
                proc255_0(18 2)
            )(else
                (if ((send pEvent:claimed))
                    return 
                )(else
                    (if ((super:handleEvent(pEvent)))
                        return 
                    )(else
                        (if (Said('climb,climb/hill'))
                            proc255_0(18 3)
                        )(else
                            (if (Said('/elf'))
                                (if (proc0_12(11))
                                    proc255_0(18 4)
                                )(else
                                    (if ((send gCast:contains(elf)))
                                        (if ((send (Said('aid,hug,kiss,touch,get,get/elf')):))
                                            proc255_0(18 5)
                                        )(else
                                            proc255_0(18 6)
                                        )
                                    )(else
                                        proc255_0(18 7)
                                    )
                                )
                            )(else
                                (if (Said('look,look>'))
                                    (if (Said('[<at,around][/room,clearing]'))
                                        (if ((send gCast:contains(elf)))
                                            proc255_0(18 8)
                                        )(else
                                            proc255_0(18 9)
                                        )
                                    )
                                )(else
                                    (if (Said('drink,get,get/water,drink'))
                                        (if (== (send gEgo:onControl(1)) 4)
                                            proc255_0(18 10)
                                        )(else
                                            (if (== (send gEgo:onControl(1)) 2)
                                                proc255_0(18 11)
                                            )(else
                                                (send pEvent:claimed(0))
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )

)
(instance elf of Actor
    (properties
        x 100
        y 150
        noun 2220
        view 150
    )

    (method (doit param1)
        (var temp0)
        (super:doit(rest param1))
        = temp0 (send gEgo:distanceTo(elf))
        (if (< temp0 40)
            (elf:setMotion(0))
            proc0_15(elf gEgo)
        )(else
            (if (< temp0 20)
                (elf:dispose())
                proc255_0(18 12)
            )
        )
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )(else
            (if (Said('look,look/elf,man,boy') or proc255_5(self pEvent 3))
                proc255_0(18 13)
            )(else
                (if (Said('kiss,hug/elf,man,boy'))
                    proc255_0(18 14)
                )(else
                    (if (Said('shoot,kick,stab,punch,kill,kill,attack,attack,bite/elf,man,boy') or Said('cast/dagger'))
                        proc255_0(18 15)
                        proc0_10(11)
                        (send global2:setScript(elfish))
                        (send pEvent:claimed(1))
                    )(else
                        (if (Said('cast,cast/boulder,pebble,pebble'))
                            (if ((send gEgo:has(9)))
                                proc255_0(18 15)
                                proc0_10(11)
                                (send global2:setScript(elfish))
                            )(else
                                proc255_0(18 16)
                            )
                            (send pEvent:claimed(1))
                        )(else
                            (if ((Said('hello>') or Said('talk,speak/elf,man,boy')) or Said('say/hello>'))
                                (if ((send global2:script))
                                    proc0_22()
                                )(else
                                    (if (< (send gEgo:distanceTo(elf)) 30)
                                        (send global2:setScript(elfish))
                                        (send pEvent:claimed(1))
                                    )(else
                                        proc255_0(18 17)
                                        (send pEvent:claimed(1))
                                    )
                                )
                            )(else
                                (if (Said('/elf,man,boy'))
                                    proc255_0(18 18)
                                    (send pEvent:claimed(1))
                                )(else
                                    (send pEvent:claimed(0))
                                )
                            )
                        )
                    )
                )
            )
        )
    )

)
(instance elfish of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (if (not proc0_12(11))
                    (send (ScriptID(0 21)):
                        number(105)
                        loop(1)
                        init()
                        play()
                    )
                    proc255_0(18 19)
                    proc255_0(18 20)
                    proc255_0(18 21)
                    proc255_0(18 22)
                    (send gEgo:get(5))
                    proc0_19(65 3)
                )
                (elf:
                    setLoop(4)
                    cel(0)
                    cycleSpeed(1)
                    setMotion(0)
                    setCycle(End self)
                )
            )
            (case 1
                (elf:dispose())
                = cycles 1
            )
            (case 2
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance hill1 of NewFeature
    (properties
        x 44
        y 32
        noun 2343
        nsTop -1
        nsBottom 65
        nsRight 88
        description 2382
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 2391
    )
)
(instance hill2 of NewFeature
    (properties
        x 104
        y 44
        noun 2343
        nsTop 34
        nsLeft 87
        nsBottom 54
        nsRight 122
        description 2382
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 2391
    )
)
(instance bush of NewFeature
    (properties
        x 197
        y 142
        noun 2347
        nsTop 133
        nsLeft 169
        nsBottom 151
        nsRight 225
        description 2475
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 2480
    )
)
