(version 2)
(include "sci.sh")
(exports
    0 rm390
)
(use "Main")
(use "OccasionalCycle")
(use "Scaler")
(use "PolyPath")
(use "Polygon")
(use "CueObj")
(use "Cycle")
(use "Game")
(use "View")
(use "Obj")
(script 390)


(local
    local0

)
(instance public rm390 of Rm
    (properties
        noun 3
        picture 390
        horizon 65
    )

    (method (init)
        proc0_2()
        (send gMainIconBar:disable(9))
        (send gOwner:
            x(190)
            y(250)
            setScale(Scaler 100 65 128 50)
            actions(egoActions)
            init()
            normalize()
        )
        (super:init())
        (send gLongSong:
            number(390)
            setLoop(-1)
            play(127)
        )
        (send global2:addObstacle((send ((Polygon:new())):
                type(2)
                init(0 189 0 155 140 179 143 189)
                yourself()
            )
 (send ((Polygon:new())):
                type(2)
                init(319 147 290 149 229 133 148 138 122 127 81 115 78 104 58 92 100 89 214 86 283 87 277 91 248 97 286 107 319 104)
                yourself()
            )
 (send ((Polygon:new())):
                type(2)
                init(319 62 319 88 306 86 289 81 280 72 229 69 232 62)
                yourself()
            )
 (send ((Polygon:new())):
                type(2)
                init(164 76 148 81 100 85 64 83 52 89 0 99 0 67 162 67)
                yourself()
            )
))
        (send gLongSong3:
            number(391)
            setLoop(-1)
            play(127)
        )
        (peacePool:init())
        (mountains:init())
        (trees:init())
        (rocks:init())
        (fountain:
            setCycle(Fwd)
            init()
        )
        (leftRip:
            setCycle(Fwd)
            init()
        )
        (rightRip:
            setCycle(Fwd)
            init()
        )
        (theMoon:
            init()
            setPri(1)
        )
        (if (not global121)
            (cheetahBody:
                init()
                approachVerbs(4)
                addToPic()
            )
            (cheetahHead:
                init()
                approachVerbs(4)
            )
            (cheetahTail:
                setCycle(OccasionalCycle self 1 20 200)
                init()
                approachVerbs(4)
            )
        )
        (send gOwner:setScript(egoEnters))
        (if (not global121 and not proc0_6(98))
            (send global2:setScript(impalaDrinks))
        )
    )


    (method (dispose)
        (send gLongSong3:stop())
        (super:dispose())
    )


    (method (doVerb theVerb)
        (switch (theVerb)
            (case 81
                (send gQg3Messager:say(4 6 1))
            )
            (case 88
                (send gQg3Messager:say(4 6 1))
            )
            (case 83
                (send gQg3Messager:say(4 6 1))
            )
            (case 20
                (send gQg3Messager:say(4 6 1))
            )
            (case 11
                (send gQg3Messager:say(4 6 1))
            )
            (case 12
                (send gQg3Messager:say(4 6 1))
            )
            (case 56
                (send gQg3Messager:say(4 6 1))
            )
            (case 76
                (if (not (send global2:script))
                    (send global2:setScript(ScriptID(12 0) self 76))
                )(else
                    (send gQg3Messager:say(4 6 9))
                )
            )
            (case 74
                (if (not (send global2:script))
                    (send gOwner:code(0))
                    (self:setScript(goToBed))
                )
            )
            (default 
                (super:doVerb(theVerb))
            )
        )
    )


    (method (cue)
        (self:setScript(runeAppears))
    )

)
(instance runeAppears of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gQg3Messager:say(3 76 0 0 self))
            )
            (case 1
                (rune:
                    init()
                    setPri(14)
                    cycleSpeed(4)
                    setCycle(Fwd)
                )
                proc0_3()
                (send gLongSong3:
                    number(391)
                    setLoop(-1)
                    play()
                )
                (self:dispose())
            )
        )
    )

)
(instance goToBed of Script
    (properties)

    (method (changeState newState)
        (var temp0)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gOwner:setMotion(PolyPath 179 168 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_4(81)
                    = seconds 5
                )
            )
            (case 3
                (theMoon:
                    moveSpeed(4)
                    setMotion(MoveTo 335 15 self)
                )
            )
            (case 4
                PalVary(pvREVERSE 3)
                proc0_5(81)
                = seconds 4
            )
            (case 5
                (send (ScriptID(7 7)):init(5 40))
                (send gOwner:setCycle(Beg self))
            )
            (case 6
                (send gOwner:
                    normalize(6)
                    cel(6)
                    x(179)
                    changeGait(0)
                    code(outCheck)
                )
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance getWater of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gOwner:setMotion(PolyPath 92 119 self))
            )
            (case 1
                (send gOwner:
                    view(4)
                    loop(0)
                    cel(0)
                    setCycle(End)
                )
                = seconds 3
            )
            (case 2
                (switch (local0)
                    (case 0
                        (send gQg3Messager:say(1 4))
                        = gGOwnerMaxStamina[17] (send gOwner:maxStamina())
                    )
                    (case 1
                        (send gQg3Messager:say(1 25))
                        (send gOwner:
                            get(37)
                            drop(15 1)
                            solvePuzzle(258 3)
                        )
                    )
                    (case 2
                        (if (global121)
                            (if (not proc0_6(259))
                                (send gQg3Messager:say(1 50 5))
                                (send ((send gInv:at(39))):
                                    state(1)
                                    cel(7)
                                )
                                (Cursor:cel(7))
                            )
                            (send gOwner:solvePuzzle(259 6 2))
                        )(else
                            (send gQg3Messager:say(1 50 6))
                        )
                    )
                )
                (send gOwner:setCycle(Beg self))
            )
            (case 3
                (send gOwner:normalize())
                (send gLongSong3:
                    number(391)
                    setLoop(-1)
                    play()
                )
                = local0 0
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance egoEnters of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gOwner:
                    x(190)
                    y(250)
                    init()
                    setMotion(MoveTo 190 180 self)
                )
            )
            (case 1
                (send gQg3Messager:say(4 6 4 0 self))
            )
            (case 2
                (if (global121)
                    (send gQg3Messager:say(4 6 8 0 self))
                )(else
                    (self:cue())
                )
            )
            (case 3
                (send gOwner:code(outCheck))
                (send gMainIconBar:enable(9))
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance impalaDrinks of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_4(98)
                (impala:init())
                = seconds 6
            )
            (case 1
                (impala:
                    loop(1)
                    setCycle(End)
                )
                = seconds 7
            )
            (case 2
                (impala:
                    setLoop(3)
                    setCycle(Fwd)
                    setMotion(MoveTo 330 90 self)
                )
            )
            (case 3
                (impala:dispose())
                (self:dispose())
            )
        )
    )

)
(instance theMoon of Actor
    (properties
        x -10
        y 15
        noun 10
        view 393
        signal $6000
    )
)
(instance impala of Actor
    (properties
        x 255
        y 92
        noun 8
        view 392
        signal $4000
    )

    (method (doVerb theVerb)
        (if (== theVerb 1)
            (super:doVerb(theVerb))
        )(else
            (send global2:doVerb(theVerb))
        )
    )

)
(instance cheetahBody of View
    (properties
        x 116
        y 62
        noun 7
        approachX 111
        approachY 85
        view 391
        loop 1
        priority 4
        signal $4015
    )
)
(instance cheetahHead of Prop
    (properties
        x 114
        y 62
        noun 7
        approachX 111
        approachY 85
        view 391
        priority 4
        signal $0010
    )

    (method (doit param1)
        (if (< (send gOwner:x) 106)
            (self:cel(0))
        )(else
            (if (< (send gOwner:x) 212)
                (self:cel(1))
            )(else
                (self:cel(2))
            )
        )
        (super:doit(rest param1))
    )

)
(instance cheetahTail of Prop
    (properties
        x 104
        y 58
        noun 7
        approachX 111
        approachY 85
        view 391
        loop 2
        priority 4
        signal $0010
        detailLevel 3
    )
)
(instance fountain of Prop
    (properties
        x 163
        y 113
        noun 1
        view 390
        loop 2
        signal $4000
        detailLevel 3
    )

    (method (doVerb theVerb)
        (peacePool:doVerb(theVerb))
    )

)
(instance rune of Prop
    (properties
        x 81
        y 49
        noun 5
        view 393
        loop 3
        signal $4000
    )
)
(instance leftRip of Prop
    (properties
        x 129
        y 106
        noun 1
        view 390
        signal $4000
        detailLevel 3
    )

    (method (doVerb theVerb)
        (peacePool:doVerb(theVerb))
    )

)
(instance rightRip of Prop
    (properties
        x 193
        y 105
        noun 1
        view 390
        loop 1
        signal $4000
        detailLevel 3
    )

    (method (doVerb theVerb)
        (peacePool:doVerb(theVerb))
    )

)
(instance mountains of Feature
    (properties
        x 164
        y 30
        noun 2
        nsTop 24
        nsLeft 126
        nsBottom 37
        nsRight 203
        sightAngle 180
    )
)
(instance rocks of Feature
    (properties
        x 84
        y 58
        noun 9
        nsTop 41
        nsLeft 60
        nsBottom 76
        nsRight 109
        sightAngle 180
    )
)
(instance trees of Feature
    (properties
        x 32
        y 88
        noun 6
        nsBottom 177
        nsRight 65
        sightAngle 180
    )
)
(instance peacePool of Feature
    (properties
        x 180
        y 18
        noun 1
        sightAngle 40
        onMeCheck $0100
    )

    (method (doVerb theVerb)
        (switch (theVerb)
            (case 25
                = local0 1
                (send gOwner:setScript(getWater))
            )
            (case 50
                = local0 2
                (send gOwner:setScript(getWater))
            )
            (case 4
                = local0 0
                (send gOwner:setScript(getWater))
            )
            (default 
                (super:doVerb(theVerb))
            )
        )
    )

)
(instance outCheck of Code
    (properties)

    (method (doit)
        (var temp0, temp1, temp2)
        (if (GameIsRestarting())
            (send gLongSong3:
                number(391)
                setLoop(-1)
                play()
            )
        )
        = temp0 global122
        (if ((<> global123 6) or (> global120 500))
            ++temp0
        )
        = temp2 global120
        (if (((< temp2 601) and (> temp2 -1)) or ((> temp2 2999) and (< temp2 3601)))
            (if ((< temp2 601) and (> temp2 -1))
                (theMoon:x((+ 180 (/ temp2 5))))
            )(else
                (theMoon:x((+ 60 (/ (- temp2 3000) 5))))
            )
        )(else
            (theMoon:x(-50))
        )
        (if ((send gOwner:edgeHit))
            (send global2:newRoom(160))
        )
    )

)
(instance egoActions of Actions
    (properties)

    (method (doVerb theVerb)
        (send global2:doVerb(theVerb))
    )

)
