(version 2)
(include "sci.sh")
(exports
    0 rm19
)
(use "Main")
(use "Class_255_0")
(use "NewFeature")
(use "ForwardCounter")
(use "n958")
(use "Follow")
(use "Cycle")
(use "Game")
(use "User")
(use "PicView")
(use "Obj")
(script 19)


(local
    local0[20]

)
(instance public rm19 of Rm
    (properties
        picture 19
        north 30
        east 18
        south 14
        west 20
    )

    (method (init)
        (self:style(
            (switch (gGNumber)
                (case north
                    5
                )
                (case west
                    3
                )
                (case east
                    2
                )
                (case south
                    4
                )
            )
))
        proc958_0(128 219 1 45)
        proc958_0(132 56 29)
        (super:init())
        (door:
            init()
            stopUpd()
        )
        proc0_11(39)
        (switch (gGNumber)
            (case north
                (send gEgo:
                    posn(proc0_17(90 (send gEgo:x) 30) 57)
                    init()
                )
                proc0_1()
            )
            (case south
                (send gEgo:
                    y(188)
                    init()
                )
                proc0_1()
            )
            (case west
                (send gEgo:
                    x(3)
                    init()
                )
                proc0_1()
            )
            (case east
                (send gEgo:
                    posn(317 proc0_17(189 (send gEgo:y) 120))
                    init()
                )
                proc0_1()
            )
            (default 
                (send gEgo:
                    posn(215 120)
                    init()
                )
                (door:
                    cel(8)
                    setScript(doorCloses)
                )
                (self:setScript(outOfMount))
            )
        )
        (smallTree:init())
        (bush1:init())
        (bush2:init())
        (hill1:init())
        (hill2:init())
        (hill3:init())
        (hill4:init())
        (hill5:init())
        (rock:init())
    )


    (method (doit)
        (var temp0)
        (if (script)
            (send script:doit())
        )(else
            (if (((((> (send gEgo:y) 119) and (> (send gEgo:x) 63)) and (< (send gGoat:y) 120)) and not (send gGoat:script)) and (send gCast:contains(gGoat)))
                (send gGoat:setScript(catchUp))
            )(else
                (if (((& (send gGoat:onControl(1)) $0002) and proc0_12(2)) and (<> (send gGoat:priority) 2))
                    (send gGoat:setPri(2))
                )(else
                    (if ((not (& (send gGoat:onControl(1)) $0002) and proc0_12(2)) and (== (send gGoat:priority) 2))
                        (send gGoat:setPri(-1))
                    )(else
                        = temp0 
                            (switch ((send ((User:alterEgo)):edgeHit))
                                (case 1
                                    north
                                )
                                (case 2
                                    east
                                )
                                (case 3
                                    south
                                )
                                (case 4
                                    west
                                )
                            )
                        (if (temp0)
                            (self:newRoom((= temp0 
                                    (switch ((send ((User:alterEgo)):edgeHit))
                                        (case 1
                                            north
                                        )
                                        (case 2
                                            east
                                        )
                                        (case 3
                                            south
                                        )
                                        (case 4
                                            west
                                        )
                                    )
)))
                        )(else
                            (if (((& (send gEgo:onControl(1)) $0002) and (<> (send gEgo:priority) 2)) and (<> (send gEgo:script) climbHill))
                                (send gEgo:setPri(2))
                            )(else
                                (if ((not (& (send gEgo:onControl(1)) $0002) and (== (send gEgo:priority) 2)) and (<> (send gEgo:script) climbHill))
                                    (send gEgo:setPri(-1))
                                )(else
                                    (if ((& (send gEgo:onControl(1)) $0200) and (<> (send gEgo:script) climbHill))
                                        (send gEgo:setScript(climbHill))
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )(else
            (if ((super:handleEvent(pEvent)))
                return 
            )(else
                (if (Said('look,look>'))
                    (if (Said('[<around,at][/room,hill]'))
                        proc255_0(19 0)
                    )(else
                        (if (Said('/keyhole'))
                            (if ((send gEgo:has(3)))
                                proc255_0(19 1)
                            )(else
                                proc255_0(19 2)
                            )
                        )(else
                            (if (Said('ceder'))
                                proc255_0(19 3)
                            )
                        )
                    )
                )(else
                    (if (Said('climb,climb/hill'))
                        proc255_0(19 4)
                    )(else
                        (if (Said('pick/lock'))
                            (if ((send gEgo:has(3)) and proc255_0(19 5))
                                proc255_0(19 6)
                            )(else
                                (if ((send gEgo:inRect(188 105 236 128)))
                                    proc255_0(19 7)
                                )(else
                                    proc255_0(19 8)
                                    (send pEvent:claimed(1))
                                )
                            )
                        )(else
                            (if (Said('bend/door,hinge,lock'))
                                (if ((send gEgo:inRect(188 105 236 128)))
                                    (send gEgo:loop(3))
                                    proc0_7()
                                    proc255_0(19 9)
                                )(else
                                    proc255_0(19 10)
                                )
                            )(else
                                (if (Said('knock[/door]'))
                                    (if ((send gEgo:inRect(188 105 236 128)))
                                        (send gEgo:loop(3))
                                        proc0_7()
                                        (send global2:setScript(knockDoor))
                                    )(else
                                        proc255_0(19 10)
                                    )
                                )(else
                                    (if (Said('open,open/door'))
                                        (if (not (send gEgo:inRect(188 105 236 128)))
                                            proc255_0(19 11)
                                        )(else
                                            (if (proc0_12(39))
                                                proc255_0(19 12)
                                            )(else
                                                (if ((send gEgo:has(3)))
                                                    (send gEgo:loop(3))
                                                    proc0_7()
                                                    proc255_0(19 13)
                                                    proc0_19(68 2)
                                                    (send gEgo:setScript(doorOpens))
                                                )(else
                                                    proc255_0(19 14)
                                                )
                                            )
                                        )
                                    )(else
                                        (if (not (send gEgo:inRect(188 105 236 128)) and (((Said('unlock/door') or Said('turn/knob')) or Said('use/key')) or Said('drop/key')))
                                            proc255_0(19 10)
                                        )(else
                                            (if (Said('use/key'))
                                                (if ((send gEgo:has(3)))
                                                    proc255_0(19 15)
                                                )(else
                                                    proc255_0(19 16)
                                                )
                                            )(else
                                                (if (Said('unlock/door,lock') or Said('drop/key'))
                                                    (if (proc0_12(39))
                                                        proc255_0(19 12)
                                                    )(else
                                                        (if ((send gEgo:has(3)))
                                                            (send gEgo:loop(3))
                                                            proc0_7()
                                                            proc255_0(19 13)
                                                            proc0_19(68 2)
                                                            (send gEgo:setScript(doorOpens))
                                                        )(else
                                                            proc255_0(19 17)
                                                        )
                                                    )
                                                )(else
                                                    (if (Said('turn/knob') or Said('close,close,lock,open,open/door'))
                                                        (if ((send global2:script))
                                                            proc0_22()
                                                        )(else
                                                            proc255_0(19 18)
                                                        )
                                                    )(else
                                                        (if (Said('look,look/keyhole'))
                                                            (if ((send gEgo:inRect(210 115 236 128)))
                                                                (send gEgo:
                                                                    loop(3)
                                                                    view(1)
                                                                    cel(3)
                                                                )
                                                                proc0_7()
                                                                proc255_0(19 19)
                                                                proc0_1()
                                                            )(else
                                                                proc255_0(19 20)
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )

)
(instance door of Prop
    (properties
        x 211
        y 113
        view 219
        cycleSpeed 1
    )

    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )(else
            (if ((super:handleEvent(pEvent)))
                return 
            )(else
                (if (Said('look,look/door,gate'))
                    (send pEvent:claimed(1))
                    (self:doVerb(1))
                )
            )
        )
    )


    (method (doVerb theVerb)
        (switch (theVerb)
            (case 1
                (if ((send gEgo:inRect(164 110 262 143)))
                    proc255_0(19 21)
                    proc0_15(gEgo 213 100)
                )(else
                    proc255_0(19 22)
                )
            )
        )
    )

)
(instance sparkle of Prop
    (properties
        view 219
        loop 1
    )
)
(instance doorOpens of Script
    (properties)

    (method (changeState newState)
        (var temp0)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send (ScriptID(0 21)):
                    number(56)
                    loop(-1)
                    init()
                    play()
                )
                = temp0 0
                (while (< temp0 (* (+ global101 1) 5))
                    (send (= local0[temp0] Clone(sparkle)):
                        posn(Random(193 233) Random(72 111))
                        ignoreActors()
                        setCycle(ForwardCounter Random(1 3))
                        cycleSpeed(Random(0 2))
                        setPri(15)
                        init()
                    )
                    ++temp0
                )
                = cycles 9
            )
            (case 1
                (door:setCycle(End self))
                proc0_10(39)
            )
            (case 2
                (send (ScriptID(0 21)):
                    loop(1)
                    fade()
                )
                (door:dispose())
                = temp0 0
                (while (< temp0 (* (+ global101 1) 5))
                    (send local0[temp0]:dispose())
                    ++temp0
                )
                (if ((>= (send gEgo:x) 220) or (<= (send gEgo:x) 213))
                    (send gEgo:setMotion(MoveTo 213 119 self))
                )(else
                    (send gEgo:setMotion(MoveTo (send gEgo:x) (- (send gEgo:y) 4) self))
                )
            )
            (case 3
                (send gEgo:
                    setLoop(3)
                    setMotion(MoveTo 252 102 self)
                )
                (send (ScriptID(0 23)):
                    loop(1)
                    fade()
                )
            )
            (case 4
                proc0_3()
                (send global2:newRoom(66))
            )
        )
    )

)
(instance doorCloses of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send (ScriptID(0 21)):
                    number(56)
                    loop(1)
                    init()
                    play()
                )
                (door:
                    cel(8)
                    setCycle(Beg self)
                )
            )
            (case 1
                (door:stopUpd())
                (self:dispose())
            )
        )
    )

)
(instance outOfMount of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:setMotion(MoveTo 215 130 self))
            )
            (case 1
                proc0_1()
                (send gEgo:loop(2))
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance knockDoor of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:
                    view(45)
                    loop(0)
                    cycleSpeed(
                        (if (>= global101 1)
                            1
                        )(else
                            0
                        )
)
                    cel(0)
                    setMotion(0)
                )
                = cycles 2
            )
            (case 1
                (send (ScriptID(0 21)):
                    number(29)
                    loop(2)
                    play(self)
                )
                (send gEgo:
                    loop(1)
                    setCycle(Fwd)
                )
            )
            (case 2
                (send gEgo:
                    loop(0)
                    cel(0)
                    setCycle(0)
                )
                = cycles 2
            )
            (case 3
                (send gEgo:
                    view(2)
                    loop(3)
                    cel(0)
                )
                proc0_1()
                proc255_0(19 23)
                (self:cue())
            )
            (case 4
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance climbHill of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (if ((send gEgo:looper))
                    (send ((send gEgo:looper)):dispose())
                )
                (send gEgo:
                    illegalBits(0)
                    setCycle(Walk)
                    setLoop(3)
                    setPri(1)
                    setMotion(MoveTo (send gEgo:x) + (send gEgo:y) 15 self)
                )
            )
            (case 1
                (send gEgo:stopUpd())
                proc0_1()
                proc0_3()
                (send global2:newRoom((send global2:north)))
                (self:dispose())
            )
        )
    )

)
(instance catchUp of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                proc255_0(19 24)
                proc0_15(gEgo gGoat)
                (send gGoat:setMotion(MoveTo 32 121 self))
            )
            (case 1
                proc0_3()
                (send gGoat:setMotion(Follow gEgo 60))
                (self:dispose())
            )
        )
    )

)
(instance smallTree of NewFeature
    (properties
        x 258
        y 133
        noun 4105
        nsTop 119
        nsLeft 224
        nsBottom 147
        nsRight 292
        description 4212
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 4223
    )
)
(instance bush1 of NewFeature
    (properties
        x 43
        y 153
        noun 4114
        nsTop 144
        nsLeft 21
        nsBottom 163
        nsRight 66
        description 4330
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 4335
    )
)
(instance bush2 of NewFeature
    (properties
        x 90
        y 152
        noun 4114
        nsTop 144
        nsLeft 66
        nsBottom 160
        nsRight 114
        description 4330
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 4335
    )
)
(instance hill1 of NewFeature
    (properties
        x 224
        y 94
        noun 4118
        nsTop 73
        nsLeft 129
        nsBottom 116
        nsRight 320
        description 4400
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 4405
    )
)
(instance hill2 of NewFeature
    (properties
        x 246
        y 59
        noun 4118
        nsTop 45
        nsLeft 172
        nsBottom 73
        nsRight 320
        description 4400
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 4405
    )
)
(instance hill3 of NewFeature
    (properties
        x 265
        y 35
        noun 4118
        nsTop 26
        nsLeft 211
        nsBottom 45
        nsRight 320
        description 4400
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 4405
    )
)
(instance hill4 of NewFeature
    (properties
        x 278
        y 19
        noun 4118
        nsTop 13
        nsLeft 237
        nsBottom 26
        nsRight 319
        description 4400
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 4405
    )
)
(instance hill5 of NewFeature
    (properties
        x 294
        y 6
        noun 4118
        nsTop -1
        nsLeft 269
        nsBottom 13
        nsRight 320
        description 4400
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 4405
    )
)
(instance rock of NewFeature
    (properties
        x 95
        y 81
        noun 4125
        nsTop 72
        nsLeft 81
        nsBottom 90
        nsRight 110
        description 4521
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 4526
    )
)
