(version 2)
(include "sci.sh")
(exports
    0 rm39
)
(use "Main")
(use "Class_255_0")
(use "NewFeature")
(use "n958")
(use "Cycle")
(use "Game")
(use "User")
(use "PicView")
(use "Obj")
(script 39)


(local
    local0
    local1
    local2
    local3

)
(procedure (localproc_0e7e param1)
    localproc_0ea3()
    proc255_0(rest param1 80 "Troll" 33 4 67 16 120 70 280 94)
)


(procedure (localproc_0ea3)
    (if (gTheNewDialog)
        (send gTheNewDialog:dispose())
    )
)


(instance public rm39 of Rm
    (properties
        picture 39
        horizon 60
        north 42
        east 38
        south 26
        west 40
    )

    (method (init)
        proc958_0(128 239 120 124 123 126 168 44)
        (self:style(
            (switch (gGNumber)
                (case north
                    5
                )
                (case west
                    3
                )
                (case east
                    2
                )
                (case south
                    4
                )
            )
))
        (super:init())
        (pinetree:init())
        (pinetree2:init())
        (treesOnBank:init())
        (treesOnBank2:init())
        (bridge:init())
        (water:init())
        (water2:init())
        (pinetree3:init())
        (tree:init())
        (tree2:init())
        (switch (gGNumber)
            (case north
                (send gEgo:posn(proc0_17(319 proc0_18(217 (send gEgo:x) 160) 157) 62))
            )
            (case south
                (if (< (send gEgo:x) 122)
                    (send gEgo:posn(9 188))
                )(else
                    (send gEgo:posn(proc0_17(319 (send gEgo:x) 215) 188))
                )
            )
            (case west
                (send gEgo:x(3))
            )
            (case east
                (send gEgo:posn(317 proc0_17(188 proc0_18(141 (send gEgo:y) 129) (+ horizon 2))))
            )
            (default 
                (send gEgo:posn(3 137))
            )
        )
        (send gEgo:init())
        proc0_1()
        (self:setRegions(601))
        (self:setRegions(608))
        (waterRock:
            setPri(7)
            ignoreActors()
            init()
            stopUpd()
        )
        (if (>= global101 1)
            (waterRock:setCycle(Fwd))
        )
        (send gMenace:
            illegalBits(0)
            stopUpd()
        )
    )


    (method (doit)
        (var temp0)
        (if ((== (send gEgo:view) 54) and proc0_12(13))
            (send (ScriptID(0 23)):fade())
        )
        (if (((proc0_12(13) and not (send gMenace:script)) and not (& (send gEgo:onControl(1)) $003c)) and (<= (send gEgo:distanceTo(gMenace)) 40))
            (send gMenace:setScript(pushBack))
        )
        (if (proc0_12(4))
            proc0_11(4)
            = local2 1
            (self:setScript(TrollLeaves))
        )
        (if ((((((<> gGNumber 40) and (== (send gEgo:onControl(1)) 2048)) and not proc0_12(13)) and not proc0_12(4)) and not proc0_12(5)) and not local2)
            (send gMenace:setScript(TrollFirst))
        )
        (if (script)
            (send script:doit())
        )(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
                            )
                        )
)))
            )
        )
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )(else
            (if ((super:handleEvent(pEvent)))
                return 
            )(else
                (if (Said('look,look[<at,around][/room]'))
                    proc255_0(39 0)
                )(else
                    (if (((Said('talk,speak//troll') or Said('talk,speak')) or Said('hello')) or Said('say/hello'))
                        (if (proc0_12(13))
                            (send global2:setScript(trollTalk))
                        )(else
                            proc255_0(39 1)
                        )
                    )
                )
            )
        )
    )

)
(instance TrollLeaves of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (trollFace:dispose())
                (send (ScriptID(0 23)):fade())
                (send gEgo:stopUpd())
                (send gMenace:
                    view(120)
                    setStep(6 4)
                    setLoop(-1)
                    setCycle(Walk)
                )
                (send gMenace:setMotion(MoveTo 20 106 self))
            )
            (case 1
                (send gEgo:stopUpd())
                (send gMenace:setMotion(MoveTo 20 145 self))
            )
            (case 2
                (send gMenace:setMotion(MoveTo -25 145 self))
            )
            (case 3
                (send gMenace:dispose())
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance TrollFirst of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send (ScriptID(0 23)):dispose())
                (self:cue())
            )
            (case 1
                proc0_2()
                (if (proc0_12(2))
                    (send gGoat:stopUpd())
                    (send (ScriptID(0 23)):
                        number(53)
                        play()
                    )
                )(else
                    (send (ScriptID(0 23)):
                        number(61)
                        play()
                    )
                )
                proc0_10(13)
                (if (not >= global101 1)
                    (send gEgo:
                        setMotion(0)
                        stopUpd()
                    )
                )
                (send gMenace:show())
                (send gMenace:
                    posn(-25 145)
                    setMotion(MoveTo 20 145 self)
                )
            )
            (case 2
                (send gMenace:setMotion(MoveTo 20 106 self))
            )
            (case 3
                (send gMenace:setMotion(MoveTo 80 106 self))
            )
            (case 4
                (send gMenace:
                    view(123)
                    setLoop(0)
                    setCel(0)
                    ignoreControl()
                )
                (trollFace:
                    init()
                    stopUpd()
                )
                (self:cue())
            )
            (case 5
                (send gMenace:stopUpd())
                (if (proc0_12(1))
                    proc255_0(39 2)
                )(else
                    proc255_0(39 3)
                )
                (self:cue())
            )
            (case 6
                proc0_3()
                (if (((send gCast:contains(gGoat)) or proc0_12(2)) and (<> gGNumber_2 gNumber))
                    (send global2:setScript(GoatButt))
                )(else
                    (self:dispose())
                )
            )
        )
    )

)
(instance pushBack of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (trollFace:hide())
                (send gMenace:
                    view(126)
                    setLoop(0)
                    setCycle(CT 2 1 self)
                )
            )
            (case 1
                (if (proc0_12(1))
                    proc255_0(39 4)
                    proc0_11(1)
                    (send gEgo:put(5))
                )
                (send gEgo:
                    view(44)
                    setLoop(0)
                )
                (send gMenace:setCycle(End self))
            )
            (case 2
                (send gEgo:x((+ (send gEgo:x) 4)))
                = cycles 1
            )
            (case 3
                (send gMenace:setCycle(Beg))
                (send gEgo:setMotion(MoveTo (+ (send gEgo:x) 15) (send gEgo:y) self))
            )
            (case 4
                proc0_3()
                (send gMenace:
                    view(123)
                    setLoop(0)
                    setCel(0)
                    ignoreControl()
                    stopUpd()
                )
                (trollFace:
                    show()
                    stopUpd()
                )
                proc0_1()
                (send gEgo:
                    view(0)
                    loop(1)
                )
                (self:dispose())
            )
        )
    )

)
(instance trollFace of Prop
    (properties
        description 4367
        view 123
        loop 1
        priority 8
        signal $0010
    )

    (method (init)
        = x (+ (send gMenace:x) 17)
        = y (- (send gMenace:y) 29)
        (super:init())
    )


    (method (show)
        = x (+ (send gMenace:x) 17)
        = y (- (send gMenace:y) 29)
        (super:show())
    )

)
(instance waterRock of Prop
    (properties
        x 92
        y 152
        description 4383
        view 239
        cycleSpeed 1
    )

    (method (doVerb theVerb param2)
        (switch (theVerb)
            (case 1
                proc255_0(39 5)
            )
            (default 
                (super:doVerb(theVerb rest param2))
            )
        )
    )

)
(instance GoatButt of Script
    (properties)

    (method (doit)
        (if (((== state 2) and (<= (send gGoat:x) 105)) and not local1)
            = local1 1
            (self:cue())
        )
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send ((send gGoat:looper)):viewNormal(168))
                (send gGoat:
                    view(168)
                    setStep(6 4)
                    setAvoider(0)
                    setMotion(0)
                    ignoreActors()
                    illegalBits(0)
                )
                proc255_0(39 6)
                (if (> (send gGoat:x) 175)
                    (send gEgo:
                        illegalBits(0)
                        setMotion(MoveTo 155 95 self)
                    )
                )(else
                    (send gEgo:
                        illegalBits(0)
                        setMotion(MoveTo 175 125 self)
                    )
                )
            )
            (case 1
                (send gEgo:
                    setLoop(1)
                    stopUpd()
                )
                (if (< (send gGoat:y) 64)
                    = local0 1
                    (send gGoat:setMotion(MoveTo 242 65 self))
                )(else
                    (if (< (send gGoat:y) 121)
                        = local0 2
                        (send gGoat:setMotion(MoveTo 175 106 self))
                    )(else
                        = local0 3
                        (send gGoat:setMotion(MoveTo 191 147 self))
                    )
                )
            )
            (case 2
                (switch (local0)
                    (case 1
                        (send gGoat:setMotion(MoveTo 242 79 self))
                    )
                    (default 
                        (self:cue())
                    )
                )
            )
            (case 3
                (send gGoat:setMotion(MoveTo 150 106 self))
            )
            (case 4
                (send gGoat:setMotion(MoveTo 100 106 self))
            )
            (case 5
                (send (ScriptID(0 21)):
                    number(38)
                    init()
                    play()
                )
                (self:cue())
            )
            (case 6
                (trollFace:dispose())
                (send gGoat:stopUpd())
                (send gMenace:
                    view(124)
                    setPri(8)
                    illegalBits(0)
                    ignoreActors()
                    setStep(12 9)
                    setLoop(1)
                    setMotion(MoveTo 82 95 self)
                )
            )
            (case 7
                (send gMenace:setMotion(MoveTo 84 100 self))
            )
            (case 8
                (send gMenace:setMotion(MoveTo 90 130 self))
            )
            (case 9
                (send gMenace:setMotion(MoveTo 99 176 self))
            )
            (case 10
                (send (ScriptID(0 21)):
                    number(14)
                    play()
                )
                (splash:init())
                (send gMenace:setMotion(MoveTo 102 183 self))
            )
            (case 11
                (send gMenace:dispose())
                proc0_11(13)
                (splash:setCycle(End self))
            )
            (case 12
                (splash:dispose())
                proc0_19(106 4)
                proc255_0(39 7)
                (send (ScriptID(0 23)):fade())
                (send ((send gGoat:looper)):viewNormal(165))
                (send gGoat:
                    setStep(3 2)
                    setMotion(MoveTo 340 110 self)
                )
            )
            (case 13
                (send gEgo:
                    illegalBits(-32768)
                    setLoop(-1)
                )
                proc0_3()
                proc0_11(2)
                proc0_10(5)
                proc958_0(0 971 985)
                (send gGoat:dispose())
                (self:dispose())
            )
        )
    )

)
(instance splash of Prop
    (properties
        x 102
        y 185
        view 124
        loop 2
        priority 9
        signal $4810
        cycleSpeed 2
    )

    (method (doVerb)
    )

)
(instance pinetree of NewFeature
    (properties
        x 271
        y 86
        noun 4294
        nsTop 39
        nsLeft 246
        nsBottom 133
        nsRight 296
        description 4414
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 4423
    )
)
(instance pinetree2 of NewFeature
    (properties
        x 231
        y 108
        noun 4294
        nsTop 81
        nsLeft 217
        nsBottom 136
        nsRight 245
        description 4471
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 4423
    )
)
(instance treesOnBank of NewFeature
    (properties
        x 165
        y 36
        noun 4301
        nsLeft 114
        nsBottom 73
        nsRight 166
        description 4481
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 4423
    )
)
(instance treesOnBank2 of NewFeature
    (properties
        x 45
        y 42
        noun 4301
        nsLeft 25
        nsBottom 85
        nsRight 66
        description 4493
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 4423
    )
)
(instance bridge of NewFeature
    (properties
        x 98
        y 111
        noun 4308
        nsTop 95
        nsLeft 44
        nsBottom 128
        nsRight 152
        description 4506
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        lookStr 4513
    )
)
(instance water of NewFeature
    (properties
        x 102
        y 174
        noun 4315
        nsTop 160
        nsLeft 57
        nsBottom 189
        nsRight 148
        description 4588
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        lookStr 4594
    )
)
(instance water2 of NewFeature
    (properties
        x 87
        y 69
        noun 4315
        nsTop 46
        nsLeft 66
        nsBottom 93
        nsRight 109
        description 4673
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        lookStr 4680
    )
)
(instance trollTalk of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (trollFace:setCycle(Fwd))
                (self:cue())
            )
            (case 1
                (switch (local3)
                    (case 0
                        localproc_0e7e(39 8)
                    )
                    (case 1
                        localproc_0e7e(39 9)
                    )
                    (default 
                        localproc_0e7e(39 10)
                    )
                )
                ++local3
                = register 1
            )
            (case 2
                (trollFace:setCycle(Beg self))
            )
            (case 3
                proc0_3()
                (self:dispose())
            )
        )
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )(else
            (if ((super:handleEvent(pEvent)))
                return 
            )(else
                (if ((== (send pEvent:type) 1) or ((== (send pEvent:type) 4) and (== (send pEvent:message) 13)))
                    (if (gTheNewDialog)
                        proc0_7()
                        (send gTheNewDialog:dispose())
                        (if (seconds)
                            = seconds 0
                            = cycles 1
                        )
                        (if (register)
                            = register 0
                            = cycles 1
                        )
                    )
                    (send pEvent:claimed(1))
                )
            )
        )
    )

)
(instance pinetree3 of NewFeature
    (properties
        x 190
        y 42
        noun 4294
        nsTop 17
        nsLeft 163
        nsBottom 68
        nsRight 217
        description 4414
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 4423
    )
)
(instance tree of NewFeature
    (properties
        x 305
        y 28
        noun 4322
        nsTop -1
        nsLeft 291
        nsBottom 57
        nsRight 320
        description 4754
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 4423
    )
)
(instance tree2 of NewFeature
    (properties
        x 269
        y 18
        noun 4322
        nsTop -1
        nsLeft 249
        nsBottom 38
        nsRight 289
        description 4754
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 4423
    )
)
