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


(local
    local0
    local1
    local2
    local3
    local4[2]
    local6[2] = (281 58 )
    local8[2] = (162 159 )
    local10[2] = (3 1 )
    local12[2] = (6 6 )

)
(procedure (localproc_1474 param1)
    localproc_1499()
    proc255_0(rest param1 80 "Troll" 33 4 67 16 20 70 152 94)
)


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


(instance public rm41 of Rm
    (properties
        picture 41
        horizon 54
        north 8
        east 42
        south 40
        west 48
    )

    (method (init)
        proc958_0(128 241 120 124 123 126 168 44)
        (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(319 (send gEgo:x) 201) (+ horizon 2)))
            )
            (case south
                (send gEgo:posn(proc0_17(319 (send gEgo:x) 73) 188))
            )
            (case west
                (send gEgo:y(proc0_17(198 (send gEgo:y) (+ horizon 2))))
                (send gEgo:x(3))
            )
            (case east
                (send gEgo:posn(315 
                    (if (< (send gEgo:y) 134)
                        proc0_17(122 (send gEgo:y) 65)
                    )(else
                        proc0_17(188 (send gEgo:y) 178)
                    )
))
            )
            (default 
                (send gEgo:posn(163 188))
            )
        )
        (send gEgo:init())
        proc0_1()
        (rRock:init())
        (rRock1:init())
        (bridge:init())
        (bridge1:init())
        (tree:init())
        (tree1:init())
        (smallTree:init())
        (rocks:init())
        (trunk:init())
        (rock2:init())
        (tree3:init())
        (rock4:init())
        (bush3:init())
        (bush4:init())
        (river:init())
        = local3 0
        (while (< local3 2)
            (send (= local4[local3] Clone(Ripple)):
                view(241)
                x(local6[local3])
                y(local8[local3])
                setLoop(local10[local3])
                setPri(local12[local3])
                ignoreActors(1)
                description("ripple")
                init()
                stopUpd()
            )
            (if (>= global101 1)
                (send local4[local3]:setCycle(Fwd))
            )
            ++local3
        )
        (self:setRegions(601))
        (self:setRegions(608))
        (bridge41Block:init())
        (send gMenace: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))
            (if (((((<= (send gEgo:distanceTo(gMenace)) 45) and (<= (send gEgo:x) 212)) and (>= (send gEgo:x) 196)) and (== (leftArm:cel) 0)) and (== (rightArm:cel) 0))
                (if (>= (send gEgo:y) 132)
                    (send gMenace:setScript(pushBack))
                )
            )(else
                (if ((>= (send gEgo:distanceTo(gMenace)) 45) or (((<= (send gEgo:distanceTo(gMenace)) 45) and (>= (send gEgo:x) 196)) and (<= (send gEgo:x) 212)))
                    (if (<> (leftArm:cel) 0)
                        (leftArm:setScript(leftArmBeg))
                    )
                    (if (<> (rightArm:cel) 0)
                        (rightArm:setScript(rightArmBeg))
                    )
                )(else
                    (if ((>= (send gEgo:x) 213) and (<= (send gEgo:distanceTo(gMenace)) 45))
                        (if (<> (rightArm:cel) (rightArm:lastCel()))
                            (rightArm:setScript(rightArmEnd))
                        )
                        (if (== (leftArm:cel) (leftArm:lastCel()))
                            (leftArm:setScript(leftArmBeg))
                        )
                    )(else
                        (if ((<= (send gEgo:x) 195) and (<= (send gEgo:distanceTo(gMenace)) 45))
                            (if (<> (leftArm:cel) (leftArm:lastCel()))
                                (leftArm:setScript(leftArmEnd))
                            )
                            (if (== (rightArm:cel) (rightArm:lastCel()))
                                (rightArm:setScript(rightArmBeg))
                            )
                        )
                    )
                )
            )
        )(else
            0
        )
        (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
            (if ((& (send gEgo:onControl(1)) $003c) and proc0_12(13))
                (send gEgo:ignoreBlocks(bridge41Block))
            )(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(41 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(41 1)
                        )
                    )
                )
            )
        )
    )

)
(instance TrollLeaves of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send (ScriptID(0 23)):fade())
                (leftArm:dispose())
                (rightArm:dispose())
                (send gMenace:
                    view(120)
                    setStep(6 4)
                    setLoop(-1)
                    setCycle(Walk)
                )
                (send gMenace:setMotion(MoveTo 204 187 self))
            )
            (case 1
                (send gEgo:stopUpd())
                (send gMenace:setMotion(MoveTo 347 187 self))
            )
            (case 2
                (send gEgo:ignoreBlocks(bridge41Block))
                (self:cue())
            )
            (case 3
                (send gMenace:dispose())
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance TrollFirst of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (if (proc0_12(2))
                    (send gGoat:stopUpd())
                    (send (ScriptID(0 23)):
                        number(53)
                        init()
                        play()
                    )
                )(else
                    (send (ScriptID(0 23)):
                        number(61)
                        init()
                        play()
                    )
                )
                proc0_10(13)
                (if (not >= global101 1)
                    (send gEgo:
                        setMotion(0)
                        stopUpd()
                    )
                )
                (send gMenace:show())
                (send gEgo:observeBlocks(bridge41Block))
                (send gMenace:
                    posn(347 187)
                    setMotion(MoveTo 204 187 self)
                )
            )
            (case 1
                (send gMenace:setMotion(MoveTo 204 147 self))
            )
            (case 2
                (leftArm:
                    init()
                    stopUpd()
                )
                (rightArm:
                    init()
                    stopUpd()
                )
                (send gMenace:
                    view(123)
                    setLoop(0)
                    setCel(2)
                    ignoreControl()
                )
                (self:cue())
            )
            (case 3
                (send gMenace:stopUpd())
                (if (proc0_12(1))
                    proc255_0(41 2)
                )(else
                    proc255_0(41 3)
                )
                (self:cue())
            )
            (case 4
                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()
                (leftArm:hide())
                (rightArm:hide())
                (send gMenace:
                    view(126)
                    setLoop(2)
                    cel(0)
                    setCycle(CT 2 1 self)
                )
            )
            (case 1
                (if (proc0_12(1))
                    proc255_0(41 4)
                    proc0_11(1)
                    (send gEgo:put(5))
                )
                (send gEgo:
                    view(44)
                    setLoop(2)
                )
                (send gMenace:setCycle(End self))
            )
            (case 2
                (send gEgo:y((- (send gEgo:y) 3)))
                = cycles 1
            )
            (case 3
                (send gEgo:setMotion(MoveTo (send gEgo:x) (- (send gEgo:y) 10)))
                = cycles 3
            )
            (case 4
                (send gMenace:
                    cycleSpeed(1)
                    setCycle(Beg self)
                )
            )
            (case 5
                proc0_3()
                (leftArm:
                    show()
                    stopUpd()
                )
                (rightArm:
                    show()
                    stopUpd()
                )
                (send gMenace:
                    view(123)
                    setLoop(0)
                    setCel(2)
                    cycleSpeed(0)
                    ignoreControl()
                    stopUpd()
                )
                (send gEgo:
                    view(0)
                    loop(2)
                )
                proc0_1()
                (self:dispose())
            )
        )
    )

)
(instance leftArm of Prop
    (properties
        x 198
        y 109
        description 5692
        view 123
        loop 5
        priority 11
        signal $4010
    )

    (method (doVerb theVerb param2)
        (switch (theVerb)
            (case 1
                (send gMenace:doVerb(1))
            )
            (default 
                (super:doVerb(theVerb rest param2))
            )
        )
    )

)
(instance rightArm of Prop
    (properties
        x 210
        y 109
        description 5692
        view 123
        loop 4
        priority 11
        signal $4010
    )

    (method (doVerb theVerb param2)
        (switch (theVerb)
            (case 1
                (send gMenace:doVerb(1))
            )
            (default 
                (super:doVerb(theVerb rest param2))
            )
        )
    )

)
(instance bridge41Block of Blk
    (properties
        top 143
        left 175
        bottom 147
        right 240
    )
)
(instance GoatButt of Script
    (properties)

    (method (doit)
        (if (((== state 3) and (>= (send gGoat:y) 140)) 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(41 5)
                (send gEgo:setMotion(MoveTo (send gEgo:x) (- (send gEgo:y) 4) self))
            )
            (case 1
                (send gEgo:setMotion(MoveTo 240 117 self))
            )
            (case 2
                (send gEgo:setLoop(2))
                (send gGoat:setMotion(MoveTo 204 120 self))
            )
            (case 3
                (send gGoat:setMotion(MoveTo 204 145 self))
            )
            (case 4
                (send (ScriptID(0 21)):
                    number(38)
                    init()
                    play()
                )
                (self:cue())
            )
            (case 5
                (leftArm:dispose())
                (rightArm:dispose())
                (send gEgo:ignoreBlocks(bridge41Block))
                (send gMenace:
                    view(124)
                    setPri(8)
                    illegalBits(0)
                    setStep(12 9)
                    setLoop(0)
                    setMotion(MoveTo 193 132 self)
                )
            )
            (case 6
                (send gMenace:setMotion(MoveTo 161 124 self))
            )
            (case 7
                (send gMenace:setMotion(MoveTo 128 141 self))
            )
            (case 8
                (send gMenace:setMotion(MoveTo 116 167 self))
            )
            (case 9
                (send (ScriptID(0 21)):
                    number(14)
                    play()
                )
                (splash:
                    view(124)
                    setLoop(2)
                    cycleSpeed(2)
                    setPri(8)
                    posn(110 176)
                    init()
                )
                (send gMenace:setMotion(MoveTo 112 174 self))
            )
            (case 10
                (send gMenace:dispose())
                proc0_11(13)
                (splash:setCycle(End self))
            )
            (case 11
                (splash:dispose())
                proc0_19(106 4)
                proc255_0(41 6)
                (send (ScriptID(0 23)):fade())
                (send ((send gGoat:looper)):viewNormal(165))
                (send gGoat:
                    setStep(3 2)
                    setMotion(MoveTo 204 110 self)
                )
            )
            (case 12
                (send gGoat:setMotion(MoveTo 350 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)
)
(instance leftArmBeg of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (leftArm:setCycle(Beg self))
            )
            (case 1
                (leftArm:stopUpd())
                (self:dispose())
            )
        )
    )

)
(instance rightArmBeg of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (rightArm:setCycle(Beg self))
            )
            (case 1
                (rightArm:stopUpd())
                (self:dispose())
            )
        )
    )

)
(instance leftArmEnd of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (leftArm:setCycle(End self))
            )
            (case 1
                (leftArm:stopUpd())
                (self:dispose())
            )
        )
    )

)
(instance rightArmEnd of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (rightArm:setCycle(End self))
            )
            (case 1
                (rightArm:stopUpd())
                (self:dispose())
            )
        )
    )

)
(instance Ripple of Prop
    (properties)

    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )(else
            (if (Said('look,look/boulder'))
                proc255_0(41 7)
            )(else
                (super:handleEvent(pEvent))
            )
        )
    )


    (method (doVerb theVerb)
        (switch (theVerb)
            (case 1
                proc255_0(41 7)
            )
        )
    )

)
(instance bridge of NewFeature
    (properties
        x 218
        y 143
        noun 5611
        nsTop 128
        nsLeft 183
        nsBottom 159
        nsRight 253
        description 5798
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5805
    )
)
(instance bridge1 of NewFeature
    (properties
        x 170
        y 152
        noun 5611
        nsTop 143
        nsLeft 159
        nsBottom 161
        nsRight 181
        description 5798
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5805
    )
)
(instance tree1 of NewFeature
    (properties
        x 97
        y 31
        noun 5615
        nsTop -1
        nsBottom 64
        nsRight 195
        description 5917
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5922
    )
)
(instance tree of NewFeature
    (properties
        x 282
        y 29
        noun 5615
        nsTop -1
        nsLeft 265
        nsBottom 60
        nsRight 300
        description 5917
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5922
    )
)
(instance smallTree of NewFeature
    (properties
        x 64
        y 88
        noun 5619
        nsTop 69
        nsLeft 43
        nsBottom 108
        nsRight 86
        description 5917
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5980
    )
)
(instance trunk of NewFeature
    (properties
        x 110
        y 89
        noun 5615
        nsTop 64
        nsLeft 96
        nsBottom 114
        nsRight 125
        description 5917
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5922
    )
)
(instance rocks of NewFeature
    (properties
        x 145
        y 108
        noun 5628
        nsTop 104
        nsLeft 127
        nsBottom 113
        nsRight 164
        description 6037
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 6042
    )
)
(instance rock2 of NewFeature
    (properties
        x 75
        y 135
        noun 5628
        nsTop 118
        nsBottom 153
        nsRight 150
        description 6037
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 6112
    )
)
(instance tree3 of NewFeature
    (properties
        x 36
        y 87
        noun 5615
        nsTop 65
        nsLeft 29
        nsBottom 109
        nsRight 44
        description 5917
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5922
    )
)
(instance bush3 of NewFeature
    (properties
        x 302
        y 154
        noun 5632
        nsTop 140
        nsLeft 286
        nsBottom 169
        nsRight 319
        description 6198
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 6203
    )
)
(instance bush4 of NewFeature
    (properties
        x 310
        y 133
        noun 5632
        nsTop 126
        nsLeft 301
        nsBottom 140
        nsRight 319
        description 6198
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 6203
    )
)
(instance rock4 of NewFeature
    (properties
        x 270
        y 140
        noun 5628
        nsTop 128
        nsLeft 257
        nsBottom 152
        nsRight 284
        description 6037
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 6112
    )
)
(instance river of NewFeature
    (properties
        x 91
        y 158
        noun 5636
        nsTop 151
        nsLeft 32
        nsBottom 166
        nsRight 151
        description 6262
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        lookStr 6268
    )
)
(instance rRock of NewFeature
    (properties
        x 50
        y 152
        noun 5628
        nsTop 148
        nsLeft 42
        nsBottom 156
        nsRight 58
        description 6037
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 6302
    )
)
(instance rRock1 of NewFeature
    (properties
        x 274
        y 155
        noun 5628
        nsTop 153
        nsLeft 266
        nsBottom 158
        nsRight 282
        description 6037
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 6302
    )
)
(instance trollTalk of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (switch (local0)
                    (case 0
                        localproc_1474(41 8)
                    )
                    (case 1
                        localproc_1474(41 9)
                    )
                    (default 
                        localproc_1474(41 10)
                    )
                )
                ++local0
                = register 1
            )
            (case 1
                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))
                )
            )
        )
    )

)
