(version 2)
(include "sci.sh")
(exports
    0 rm770
)
(use "Main")
(use "TellerIcon")
(use "n026")
(use "PolyPath")
(use "Polygon")
(use "Blk")
(use "CueObj")
(use "Track")
(use "n958")
(use "Wander")
(use "Chase")
(use "Orbit")
(use "Cycle")
(use "Game")
(use "View")
(use "Obj")
(script 770)


(local
    local0
    local1
    local2
    newGem1[5]
    local8[8] = (0 5 6 7 -9 -8 -10 999 )
    local16[2]
    local18[11] = (0 -21 -18 -32 -22 -27 -28 -26 -19 -20 999 )
    local29[2]

)
(procedure (localproc_0d9d)
    (send gLongSong3:
        number(772)
        setLoop(-1)
        play(127)
    )
    proc0_4(137)
    (if (== global394 0)
        ++global394
        (guardian:
            moveSpeed(2)
            cycleSpeed(2)
        )
        (send gOwner:addHonor(-20))
    )(else
        (if (== global394 1)
            ++global394
            (guardian:
                moveSpeed(0)
                cycleSpeed(0)
            )
            (send gOwner:addHonor(-30))
        )(else
            (if (== global394 2)
                (send gOwner:setScript(willSpin))
            )(else
                (if (== global394 3)
                    (guardian:setScript(kickHimOut))
                )
            )
        )
    )
)


(instance public rm770 of Rm
    (properties
        noun 10
        picture 770
        vanishingY -25
    )

    (method (init)
        proc0_4(132)
        = local16[0] @local8
        = local29[0] @local18
        proc958_0(128 6 771)
        (super:init())
        (send gLongSong2:stop())
        (send gLongSong2:
            number(914)
            setLoop(-1)
            play(127)
        )
        (send gLongSong3:
            number(771)
            setLoop(-1)
            play(127)
        )
        (send global2:addObstacle((send ((Polygon:new())):
                type(3)
                init(110 189 319 189 319 106 241 98 220 115 134 119 39 119)
                yourself()
            )
))
        (mushrooms:init())
        (globes:init())
        (vines:init())
        (upperGlobes:init())
        (plant:init())
        (bigVine:init())
        (if (proc0_6(51))
            (gem1:init())
            (send (= newGem1[1] (gem1:new())):
                loop(0)
                cel(1)
                x(174)
                y(137)
                init()
                addToPic()
            )
            (send (= newGem1[2] (gem1:new())):
                loop(0)
                cel(0)
                x(168)
                y(144)
                init()
                addToPic()
            )
            (send (= newGem1[3] (gem1:new())):
                loop(0)
                cel(0)
                x(149)
                y(140)
                init()
                addToPic()
            )
            (send (= newGem1[4] (gem1:new())):
                loop(0)
                cel(1)
                x(159)
                y(143)
                init()
                addToPic()
            )
        )
        (send gOwner:
            x(304)
            y(134)
            setScale(189)
            init()
            noun(4)
            normalize()
        )
        (guardian:
            maxScale(200)
            moveSpeed(4)
            ignoreHorizon(1)
            observeBlocks(deCage)
            init()
            setScript(guardianOrbits)
        )
        (egoTell:init(gOwner @local18 @local29))
        (if (== global394 1)
            (guardian:
                moveSpeed(2)
                cycleSpeed(2)
            )
        )(else
            (if (== global394 2)
                (guardian:
                    moveSpeed(0)
                    cycleSpeed(0)
                )
            )
        )
        (send gOwner:setScript(egoEnters))
    )


    (method (dispose)
        (send gLongSong3:stop())
        UnLoad(128 6)
        UnLoad(128 771)
        proc958_0(0 986 964 955 970 949)
        DisposeClone(gem1)
        (super:dispose())
    )


    (method (doVerb theVerb param2)
        (switch (theVerb)
            (case 81
                (self:setScript(ScriptID(32 0) 0 theVerb))
                localproc_0d9d()
            )
            (case 83
                (self:setScript(ScriptID(32 0) 0 theVerb))
                localproc_0d9d()
            )
            (case 32
                (self:setScript(ScriptID(32 0) 0 theVerb))
                localproc_0d9d()
            )
            (case 20
                (self:setScript(ScriptID(32 0) 0 theVerb))
                localproc_0d9d()
            )
            (case 33
                (self:setScript(ScriptID(32 0) 0 theVerb))
                localproc_0d9d()
            )
            (case 74
                (if ((send gGQg3KDHandler:contains(guardian)))
                    (send gQg3Messager:say(3 6 33))
                )(else
                    (self:setScript(goToBed))
                )
            )
            (default 
                (super:doVerb(theVerb rest param2))
            )
        )
    )

)
(instance goToBed of Script
    (properties)

    (method (changeState newState)
        (var temp0)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gOwner:setMotion(PolyPath 179 148 self))
            )
            (case 1
                (send gOwner:
                    view(35)
                    loop(0)
                    cel(0)
                    x(198)
                    setCycle(End self)
                )
            )
            (case 2
                = temp0 PalVary(pvGET_CURRENT_STEP)
                (if (temp0)
                    (if (< (= temp0 PalVary(pvGET_CURRENT_STEP)) 64)
                        PalVary(pvCHANGE_TICKS 3)
                        = seconds 5
                    )(else
                        (self:cue())
                    )
                )(else
                    PalVary(pvINIT 310 3)
                    proc0_6(81)
                    = seconds 15
                )
            )
            (case 3
                PalVary(pvREVERSE 3)
                proc0_5(81)
                = seconds 4
            )
            (case 4
                (send (ScriptID(7 7)):init(5 40))
                (send gOwner:setCycle(Beg self))
            )
            (case 5
                (send gOwner:
                    normalize(6)
                    cel(6)
                    x(179)
                    changeGait(0)
                    code(outCheck)
                )
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance gemsAppear of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (guardTell:dispose())
                (guardian:
                    show()
                    setMotion(MoveTo 171 100 self)
                )
                = local0 0
                (send gOwner:
                    normalize()
                    noun(4)
                )
            )
            (case 1
                = seconds 3
            )
            (case 2
                (gem1:init())
                (send (= newGem1[1] (gem1:new())):
                    loop(0)
                    cel(1)
                    x(174)
                    y(137)
                    init()
                )
                (send (= newGem1[2] (gem1:new())):
                    loop(0)
                    cel(0)
                    x(168)
                    y(144)
                    init()
                )
                (send (= newGem1[3] (gem1:new())):
                    loop(0)
                    cel(0)
                    x(149)
                    y(140)
                    init()
                )
                (send (= newGem1[4] (gem1:new())):
                    loop(0)
                    cel(1)
                    x(159)
                    y(143)
                    init()
                )
                DrawPic((send global2:picture) dpCLOSEREOPEN_HCENTER)
                = cycles 2
            )
            (case 3
                (guardian:
                    setMotion(Wander 75)
                    observeBlocks(deCage)
                )
                (gem1:stopUpd())
                (send newGem1[1]:addToPic())
                (send newGem1[2]:addToPic())
                (send newGem1[3]:addToPic())
                (send newGem1[4]:addToPic())
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance willSpin of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = seconds 3
            )
            (case 1
                (if (local1)
                    (send gOwner:setScript(kickHimOut))
                )(else
                    (send gOwner:setScript(egoSpins))
                )
                (self:dispose())
            )
        )
    )

)
(instance egoGetsGem of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gOwner:setMotion(PolyPath 181 146 self))
                (if (not proc0_6(51))
                    (send gOwner:
                        get(36)
                        addHonor(20)
                        solvePuzzle(326 5)
                    )
                    proc0_4(51)
                )(else
                    = global394 3
                    (send gQg3Messager:say(1 6 31))
                    (guardian:setScript(kickHimOut))
                )
            )
            (case 1
                (if (not == global394 3)
                    (send gOwner:
                        view(4)
                        loop(1)
                        cel(0)
                        setCycle(End self)
                    )
                )
            )
            (case 2
                (gem1:dispose())
                (send gOwner:setCycle(Beg self))
            )
            (case 3
                (send gOwner:normalize())
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance kickHimOut of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (if (not (send gGQg3KDHandler:contains(guardian)))
                    (guardian:
                        init()
                        observeBlocks(deCage)
                    )
                )
                proc0_2()
                (send gOwner:
                    code(0)
                    moveSpeed(0)
                    setMotion(0)
                )
                (guardian:
                    cycleSpeed(0)
                    moveSpeed(0)
                    setMotion(MoveTo (send gOwner:x) (send gOwner:y) self)
                )
            )
            (case 1
                (guardian:
                    ignoreBlocks(deCage)
                    setMotion(MoveTo 304 134 self)
                )
                (send gOwner:
                    view(6)
                    setScale()
                    setLoop(2)
                    setCel(1)
                    setCycle(0)
                    setMotion(tracker guardian)
                )
            )
            (case 2
                proc26_0()
            )
        )
    )

)
(instance egoEnters of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                = cycles 1
            )
            (case 1
                (send gQg3Messager:say(3 6 17))
                (send gOwner:setMotion(PolyPath 181 146 self))
            )
            (case 2
                (send gOwner:code(outCheck))
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance egoSpins of Script
    (properties)

    (method (doit param1)
        (if (< (guardianOrbits:state) 2)
            (send gOwner:setHeading(GetAngle((send gOwner:x) (send gOwner:y) (guardian:x) (guardian:y))))
        )
        (if ((== (guardianOrbits:state) 2) and (== state 0))
            (self:cue())
        )
        (super:doit(rest param1))
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gOwner:
                    view(5)
                    cel(0)
                )
            )
            (case 1
                (send gOwner:
                    view(6)
                    loop(3)
                    setCycle(End)
                )
                = seconds 3
            )
            (case 2
                (send gOwner:
                    loop(9)
                    cel(0)
                    setCycle(End self)
                )
            )
            (case 3
                proc0_13()
                (self:dispose())
            )
        )
    )

)
(instance guardianOrbits of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (guardian:
                    setCycle(Fwd)
                    setMotion(Wander 75)
                )
                = seconds 10
            )
            (case 1
                (guardian:
                    z(+ (send gOwner:z) 20)
                    ignoreBlocks(deCage)
                    setMotion(Orbit gOwner 25 0 0 45)
                )
                = seconds 15
            )
            (case 2
                proc0_13()
                (guardian:setMotion(Chase gOwner 0 self))
            )
            (case 3
                (egoTell:dispose())
                (guardTell:init(gOwner @local8 @local16))
                = local0 1
                (send gOwner:
                    view(772)
                    loop(1)
                    noun(1)
                    setCycle(End)
                )
                (guardian:hide())
                (send gQg3Messager:say(3 6 2 0 self))
            )
            (case 4
                (switch (global394)
                    (case 0
                        (send gQg3Messager:say(1 6 1))
                    )
                    (case 1
                        (send gQg3Messager:say(1 6 3))
                    )
                    (case 2
                        (send gQg3Messager:say(1 6 4))
                    )
                )
                proc0_13()
                = local1 1
                (send global2:setScript(contactScript))
                (self:dispose())
            )
        )
    )

)
(instance contactScript of Script
    (properties)

    (method (dispose param1)
        (send gOwner:code(outCheck))
        (super:dispose(rest param1))
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_13()
                (egoTell:init(gOwner @local18 @local29))
                (send gOwner:
                    view(772)
                    loop(0)
                    code(0)
                    normalize(2)
                    noun(4)
                )
                = seconds 3
            )
            (case 1
                (guardTell:init(gOwner @local8 @local16))
                (send gOwner:
                    view(772)
                    loop(1)
                    setCycle(Fwd)
                    noun(1)
                )
                = seconds 3
            )
            (case 2
                (send gOwner:setCycle(Beg self))
            )
            (case 3
                (self:init())
            )
        )
    )

)
(instance goodBye of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (guardTell:dispose())
                (egoTell:dispose())
                (send gOwner:
                    normalize()
                    noun(4)
                    actions(0)
                )
                (guardian:
                    show()
                    setMotion(MoveTo 20 40 self)
                )
            )
            (case 1
                (guardian:dispose())
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance guardian of Actor
    (properties
        x 100
        y 100
        noun 1
        view 771
        signal $4000
    )
)
(instance gem1 of View
    (properties
        x 160
        y 138
        noun 12
        view 770
        signal $4000
    )

    (method (doVerb theVerb)
        (switch (theVerb)
            (case 4
                (send gOwner:setScript(egoGetsGem))
            )
            (default 
                (super:doVerb(theVerb))
            )
        )
    )

)
(instance mushrooms of Feature
    (properties
        x 25
        y 170
        noun 2
        nsTop 151
        nsBottom 189
        nsRight 51
        sightAngle 180
    )
)
(instance globes of Feature
    (properties
        x 295
        y 157
        noun 5
        nsTop 126
        nsLeft 272
        nsBottom 188
        nsRight 319
        sightAngle 180
    )
)
(instance vines of Feature
    (properties
        x 91
        y 100
        noun 6
        nsTop 35
        nsLeft 54
        nsBottom 165
        nsRight 128
        sightAngle 180
    )
)
(instance upperGlobes of Feature
    (properties
        x 304
        y 58
        noun 9
        nsTop 39
        nsLeft 290
        nsBottom 78
        nsRight 319
        sightAngle 180
    )
)
(instance plant of Feature
    (properties
        x 194
        y 171
        noun 7
        nsTop 156
        nsLeft 162
        nsBottom 186
        nsRight 227
        sightAngle 180
    )
)
(instance bigVine of Feature
    (properties
        x 99
        y 107
        noun 8
        nsTop 52
        nsLeft 74
        nsBottom 163
        nsRight 125
        sightAngle 180
    )
)
(instance guardTell of Teller
    (properties)

    (method (showDialog)
        (super:showDialog(-9 
            (if ((== local0 1) and not proc0_6(157))
                proc0_6(58)
            )(else
                0
            )
 -8 
            (if (((== local0 1) and proc0_6(60)) and not (send gGQg3KDHandler:contains(gem1)))
                not (send gOwner:has(36))
            )(else
                0
            )
 -10 
            (if ((== local0 1) and proc0_6(133))
                not (send gOwner:has(44))
            )(else
                0
            )
))
    )


    (method (doChild)
        return 
            (switch (query)
                (case -8
                    (send global2:setScript(gemsAppear))
                    (send gOwner:noun(1))
                    return query
                )
                (default 
                    return query
                )
            )
    )


    (method (doVerb theVerb param2)
        (if ((== theVerb 2) and (== local0 0))
            (send gQg3Messager:say(3 6 30))
        )(else
            (super:doVerb(theVerb rest param2))
        )
    )

)
(instance egoTell of Teller
    (properties)

    (method (showDialog)
        (super:showDialog(-18 (== local0 0) -32 (== local0 1) -21 (== local0 1) -22 (== local0 1) -27 
            (if ((send gOwner:has(39)))
                not (send ((send gInv:at(39))):state)
            )(else
                0
            )
 -28 
            (if ((send gOwner:has(39)))
                (send ((send gInv:at(39))):state)
            )(else
                0
            )
 -26 
            (if ((send gOwner:has(37)))
                local0
            )(else
                0
            )
 -19 (== local0 0) -20 (== local0 1)))
    )


    (method (doChild)
        return 
            (switch (query)
                (case -32
                    (switch (global394)
                        (case 0
                            return = query -23
                        )
                        (case 1
                            return = query -24
                        )
                        (case 2
                            return = query -25
                        )
                    )
                )
                (case -20
                    (send global2:setScript(goodBye))
                    return query
                )
                (default 
                    return query
                )
            )
    )

)
(instance tracker of Track
    (properties)

    (method (init param1)
        (if (paramTotal)
            (super:init(rest param1))
        )
    )


    (method (doit)
        (var temp0)
        (send client:
            x(+ (send who:x) 10)
            y(+ (send who:y) yOffset)
            z(+ (send who:z) zOffset)
        )
    )

)
(instance deCage of Cage
    (properties
        top 25
        bottom 190
        right 320
    )
)
(instance deBase of Code
    (properties)

    (method (doit param1)
        Animate((send gGQg3KDHandler:elements) 0)
        BaseSetter(param1)
    )

)
(instance outCheck of Code
    (properties)

    (method (doit)
        (if ((send gOwner:inRect(300 100 319 189)))
            (send global2:newRoom(760))
        )
    )

)
