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


(local
    local0
    local1
    local2
    local3
    local4[3]
    local7[3] = (195 23 251 )
    local10[3] = (104 90 118 )
    local13[3] = (1 3 3 )
    local16[3] = (-1 1 3 )

)
(procedure (localproc_140c param1)
    localproc_1432()
    proc255_0(rest param1 80 "Troll" 33 4 67 144 20 70 150 94)
)


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


(instance public rm25 of Rm
    (properties
        picture 25
        horizon 45
        north 40
        east 26
        south 24
        west 32
    )

    (method (init)
        Load(rsVIEW 241)
        proc958_0(128 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:y((+ horizon 2)))
            )
            (case south
                (send gEgo:y(188))
            )
            (case west
                (if (< (send gEgo:y) 100)
                    (send gEgo:posn(3 proc0_17(56 (send gEgo:y) (+ 2 horizon))))
                )(else
                    (send gEgo:posn(3 proc0_17(188 (send gEgo:y) 134)))
                )
            )
            (case east
                (if (< (send gEgo:y) 100)
                    (send gEgo:posn(317 proc0_17(57 (send gEgo:y) (+ 2 horizon))))
                )(else
                    (send gEgo:posn(317 proc0_17(188 (send gEgo:y) 130)))
                )
            )
            (default 
                (send gEgo:posn(3 137))
            )
        )
        (send gEgo:init())
        proc0_1()
        = local3 0
        (while (< local3 3)
            (send (= local4[local3] Clone(Ripple)):
                view(241)
                x(local7[local3])
                y(local10[local3])
                setLoop(local13[local3])
                setPri(local16[local3])
                ignoreActors(1)
                description("ripple")
                init()
                stopUpd()
            )
            (if (>= global101 1)
                (send local4[local3]:setCycle(Fwd))
            )
            ++local3
        )
        (self:setRegions(601))
        (self:setRegions(608))
        (bushAndRock:init())
        (bush1:init())
        (bush2:init())
        (bush3:init())
        (bush4:init())
        (bridge1:init())
        (bridge2:init())
        (bridge3:init())
        (bridge4:init())
        (river:init())
        (bank: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) 122)) and (>= (send gEgo:x) 104)) and (== (leftArm:cel) 0)) and (== (rightArm:cel) 0)) and not (send gMenace:script))
                (if (<= (send gEgo:y) 107)
                    (send gMenace:setScript(pushBack))
                )
            )(else
                (if ((>= (send gEgo:distanceTo(gMenace)) 45) or (((<= (send gEgo:distanceTo(gMenace)) 45) and (<= (send gEgo:x) 122)) and (>= (send gEgo:x) 104)))
                    (if (<> (leftArm:cel) 0)
                        (leftArm:setScript(leftArmBeg))
                    )
                    (if (<> (rightArm:cel) 0)
                        (rightArm:setScript(rightArmBeg))
                    )
                )(else
                    (if ((>= (send gEgo:x) 123) 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) 103) 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(bridge25Block))
            )(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(25 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(25 1)
                        )
                    )(else
                        (if (Said('look,look/ceder'))
                            proc255_0(25 2)
                        )
                    )
                )
            )
        )
    )

)
(instance TrollLeaves of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send (ScriptID(0 23)):fade())
                (send gEgo:stopUpd())
                (leftArm:dispose())
                (rightArm:dispose())
                (trollFace:dispose())
                (send gMenace:
                    view(120)
                    setLoop(-1)
                    setCycle(Walk)
                    setMotion(MoveTo 112 49 self)
                )
            )
            (case 1
                (send gMenace:setMotion(MoveTo -25 49 self))
            )
            (case 2
                (send gEgo:ignoreBlocks(bridge25Block))
                (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 gEgo:observeBlocks(bridge25Block))
                (send gMenace:
                    posn(-25 49)
                    show()
                    setMotion(MoveTo 112 49 self)
                )
            )
            (case 1
                (send gMenace:setMotion(MoveTo 112 95 self))
            )
            (case 2
                (leftArm:
                    init()
                    stopUpd()
                )
                (rightArm:
                    init()
                    stopUpd()
                )
                (trollFace:
                    init()
                    stopUpd()
                )
                (send gMenace:
                    view(123)
                    setLoop(0)
                    setCel(1)
                    ignoreControl()
                )
                = cycles 1
            )
            (case 3
                (send gMenace:stopUpd())
                (if (proc0_12(1))
                    proc255_0(25 3)
                )(else
                    proc255_0(25 4)
                )
                = cycles 1
            )
            (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()
                    stopUpd()
                )
                (rightArm:
                    hide()
                    stopUpd()
                )
                (trollFace:
                    hide()
                    stopUpd()
                )
                (send gMenace:
                    view(126)
                    setLoop(1)
                    setCycle(CT 2 1 self)
                )
            )
            (case 1
                (if (proc0_12(1))
                    proc255_0(25 5)
                    proc0_11(1)
                    (send gEgo:put(5))
                )
                (send gEgo:
                    view(44)
                    setLoop(1)
                )
                (send gMenace:
                    cel(2)
                    setCycle(End self)
                )
            )
            (case 2
                (send gEgo:y((+ (send gEgo:y) 4)))
                = 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()
                )
                (trollFace:
                    show()
                    stopUpd()
                )
                (send gMenace:
                    view(123)
                    setLoop(0)
                    setCel(1)
                    cycleSpeed(0)
                    ignoreControl()
                    stopUpd()
                )
                (send gEgo:
                    view(0)
                    loop(3)
                )
                proc0_1()
                (self:dispose())
            )
        )
    )

)
(instance trollFace of Prop
    (properties
        x 112
        y 66
        description 5650
        view 123
        loop 6
        priority 6
        signal $0010
    )
)
(instance splash of Prop
    (properties)
)
(instance leftArm of Prop
    (properties
        x 106
        y 58
        description 5650
        view 123
        loop 2
        priority 5
        signal $0010
    )

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

)
(instance rightArm of Prop
    (properties
        x 118
        y 58
        description 5650
        view 123
        loop 3
        priority 5
        signal $0010
    )

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

)
(instance bridge25Block of Blk
    (properties
        top 92
        left 82
        bottom 96
        right 144
    )
)
(instance GoatButt of Script
    (properties)

    (method (doit param1)
        (super:doit(rest param1))
        (if (((== state 2) and (<= (send gGoat:y) 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(25 6)
                (if (< (send gGoat:x) 121)
                    (send gEgo:setMotion(MoveTo 166 144 self))
                )(else
                    (send gEgo:setMotion(MoveTo 80 143 self))
                )
            )
            (case 1
                (send gEgo:
                    setLoop(3)
                    stopUpd()
                )
                (send gGoat:setMotion(MoveTo 112 145 self))
            )
            (case 2
                (send gGoat:setMotion(MoveTo 112 100 self))
            )
            (case 3
                (send (ScriptID(0 21)):
                    number(38)
                    init()
                    play()
                )
                (self:cue())
            )
            (case 4
                (leftArm:dispose())
                (rightArm:dispose())
                (trollFace:dispose())
                (send gGoat:stopUpd())
                (send gMenace:
                    view(124)
                    setPri(8)
                    illegalBits(0)
                    setStep(12 9)
                )
                (send gMenace:
                    setLoop(0)
                    setMotion(MoveTo 100 79 self)
                )
            )
            (case 5
                (send gMenace:setMotion(MoveTo 77 70 self))
            )
            (case 6
                (send gMenace:setMotion(MoveTo 53 82 self))
            )
            (case 7
                (send gMenace:setMotion(MoveTo 46 100 self))
            )
            (case 8
                (send (ScriptID(0 21)):
                    number(14)
                    play()
                )
                (splash:
                    view(124)
                    setLoop(2)
                    cycleSpeed(2)
                    setPri(2)
                    posn(39 110)
                    init()
                )
                (send gMenace:setMotion(MoveTo 42 107 self))
            )
            (case 9
                proc0_11(13)
                (send gMenace:dispose())
                (splash:setCycle(End self))
            )
            (case 10
                (splash:dispose())
                proc0_19(106 4)
                proc255_0(25 7)
                (send (ScriptID(0 23)):fade())
                (send ((send gGoat:looper)):viewNormal(165))
                (send gGoat:
                    setStep(3 2)
                    setMotion(MoveTo 112 220 self)
                )
            )
            (case 11
                (send gEgo:
                    illegalBits(-32768)
                    setLoop(-1)
                )
                proc0_3()
                proc0_11(2)
                proc0_10(5)
                (send gEgo:ignoreBlocks(bridge25Block))
                proc958_0(0 971 985)
                (send gGoat:dispose())
                (self:dispose())
            )
        )
    )

)
(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/brook,boulder,water'))
                proc255_0(25 8)
            )(else
                (super:handleEvent(pEvent))
            )
        )
    )


    (method (doVerb theVerb)
        (switch (theVerb)
            (case 1
                proc255_0(25 8)
            )
        )
    )

)
(instance bushAndRock of NewFeature
    (properties
        x 50
        y 139
        noun 5572
        nsTop 125
        nsLeft 25
        nsBottom 154
        nsRight 76
        description 5766
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5780
    )
)
(instance bush1 of NewFeature
    (properties
        x 256
        y 155
        noun 5572
        nsTop 149
        nsLeft 224
        nsBottom 162
        nsRight 288
        description 5865
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5870
    )
)
(instance bush2 of NewFeature
    (properties
        x 255
        y 143
        noun 5572
        nsTop 138
        nsLeft 241
        nsBottom 149
        nsRight 269
        description 5865
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5870
    )
)
(instance bush3 of NewFeature
    (properties
        x 19
        y 43
        noun 5572
        nsTop 27
        nsBottom 60
        nsRight 39
        description 5865
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5870
    )
)
(instance bush4 of NewFeature
    (properties
        x 44
        y 49
        noun 5572
        nsTop 40
        nsLeft 38
        nsBottom 59
        nsRight 51
        description 5865
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 5870
    )
)
(instance river of NewFeature
    (properties
        x 160
        y 105
        noun 5576
        nsTop 85
        nsBottom 129
        nsRight 320
        description 5953
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        lookStr 5959
    )
)
(instance bank of NewFeature
    (properties
        x 160
        y 73
        noun 5586
        nsTop 62
        nsBottom 84
        nsRight 320
        description 6039
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 6044
    )
)
(instance bridge1 of NewFeature
    (properties
        x 112
        y 95
        noun 5595
        nsTop 62
        nsLeft 90
        nsBottom 129
        nsRight 135
        description 6109
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 6116
    )
)
(instance bridge2 of NewFeature
    (properties
        x 140
        y 110
        noun 5595
        nsTop 93
        nsLeft 135
        nsBottom 128
        nsRight 145
        description 6109
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 6116
    )
)
(instance bridge3 of NewFeature
    (properties
        x 149
        y 121
        noun 5595
        nsTop 114
        nsLeft 145
        nsBottom 129
        nsRight 154
        description 6109
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 6116
    )
)
(instance bridge4 of NewFeature
    (properties
        x 85
        y 110
        noun 5595
        nsTop 92
        nsLeft 82
        nsBottom 129
        nsRight 89
        description 6109
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 6116
    )
)
(instance trollTalk of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (trollFace:setCycle(Fwd))
                (self:cue())
            )
            (case 1
                (switch (local0)
                    (case 0
                        localproc_140c(25 9)
                    )
                    (case 1
                        localproc_140c(25 10)
                    )
                    (default 
                        localproc_140c(25 11)
                    )
                )
                ++local0
                = 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))
                )
            )
        )
    )

)
