(include "sci.sh")
(use "Main")
(use "Class_255_0")
(use "SQRoom")
(use "RandCycle")
(use "Polygon")
(use "Class_950_0")
(use "ForwardCounter")
(use "n958")
(use "Sound")
(use "Cycle")
(use "PicView")
(use "Obj")
(script 60)


(local
    local0[16] = (0 163 44 163 62 180 247 180 251 184 319 184 319 189 0 189 )

)
(instance public rm060 of SQRoom
    (properties
        picture 60
        style 30
        horizon 130
        north 45
        east 65
        west 55
    )

    (method (init)
        proc958_0(128 0 61)
        proc958_0(132 150 802)
        Load(rsSCRIPT 941)
        (switch (gWest)
            (case 40
                proc0_3()
                (send gEgo:
                    x(20)
                    y(+ horizon (send gEgo:yStep))
                )
            )
            (case 50
                proc0_3()
                (send gEgo:
                    x(300)
                    y(+ horizon (send gEgo:yStep))
                )
            )
            (case 59
                proc958_0(128 62 0 4)
                proc958_0(132 821 822 115)
                Load(rsSCRIPT 956)
                (send gLongSong2:
                    number(115)
                    priority(15)
                    vol(127)
                    loop(1)
                    init()
                    changeState()
                )
                proc0_2()
                (self:
                    setScript(ripScript)
                    style(42)
                )
            )
            (case 55
                proc0_2()
                (self:setScript(enterScript))
                (send gEgo:y(
                    (if (> (send gEgo:y) 160)
                        160
                    )(else
                        (if (< (send gEgo:y) (+ horizon (send gEgo:yStep)))
                            (+ horizon (send gEgo:yStep))
                        )(else
                            (send gEgo:y)
                        )
                    )
))
                (self:setScript(enterScript))
            )
            (case 65
                proc0_2()
                (send gEgo:y(
                    (if (> (send gEgo:y) 175)
                        172
                    )(else
                        (if (< (send gEgo:y) (+ horizon (send gEgo:yStep)))
                            (+ horizon (send gEgo:yStep))
                        )(else
                            (send gEgo:y)
                        )
                    )
))
                (self:setScript(enterScript))
            )
            (case 72
                (send gEgo:
                    x(160)
                    y(+ horizon (send gEgo:yStep))
                    setHeading(180)
                )
            )
            (case 45
                proc0_3()
                (send gEgo:
                    x(
                        (if (> (send gEgo:x) 290)
                            290
                        )(else
                            (if (< (send gEgo:x) 30)
                                30
                            )(else
                                (send gEgo:x)
                            )
                        )
)
                    y(+ horizon (send gEgo:yStep))
                )
            )
            (default 
                proc0_3()
                (send gIconBar:enable())
                (send gEgo:
                    x(155)
                    y(160)
                    setHeading(0)
                )
                (send gLongSong:
                    number(802)
                    loop(-1)
                    vol(127)
                    flags(1)
                    playBed()
                )
            )
        )
        (if (> (send gEgo:y) 175)
            (send gEgo:y(172))
        )
        (if (<> gWest 59)
            (lightning1:
                init()
                setScript(lightningScript)
            )
            (thunder:init())
        )
        (send ((theBuildings:new())):
            init()
            onMeCheck(8192)
            x(65436)
        )
        (send ((theBuildings:new())):
            init()
            onMeCheck(512)
            x(160)
        )
        (send ((theBuildings:new())):
            init()
            onMeCheck(128)
            x(400)
        )
        (theFrontRubble:init())
        (theBackRubble:init())
        (theStreet:init())
        (theSuperComputer:init())
        (theArea:init())
        (thunder:init())
        (poly1:
            points(@local0)
            size(8)
        )
        (if (not Btest(0))
            (self:setRegions(701))
        )
        proc0_14(12)
        (super:init())
        (self:
            setRegions(705)
            addObstacle(poly1)
        )
        (if (<> gWest 59)
            (send gEgo:init())
        )
        (if (== gWest 72)
            (send gLongSong:
                number(802)
                loop(-1)
                vol(127)
                flags(1)
                playBed()
            )
            proc0_3()
        )
    )


    (method (doit param1)
        (if (((<> curPic 31) and not (lightning1:script)) and (<> script ripScript))
            (lightning1:
                init()
                setScript(lightningScript)
            )
        )
        (super:doit(rest param1))
    )


    (method (newRoom param1)
        (if (<> script ripScript)
            (super:newRoom(param1))
        )
    )

)
(instance lightningScript of Script
    (properties)

    (method (doit param1)
        (if (== (send global2:curPic) 31)
            (self:dispose())
        )
        (super:doit(rest param1))
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = seconds Random(10 25)
            )
            (case 1
                = seconds 3
            )
            (case 2
                (self:
                    changeState(+ (* Random(0 1) 2) 3)
                    start(0)
                )
            )
            (case 3
                (lightning1:setCycle(RandCycle Random(1 3) self))
            )
            (case 4
                (lightning1:setCel(0))
                = cycles 1
            )
            (case 5
                (lightning2:
                    init()
                    setCycle(RandCycle Random(3 5) self)
                )
            )
            (case 6
                (lightning1:
                    setCel(0)
                    setCycle(Beg self)
                )
            )
            (case 7
                (lightning1:setCel(0))
                (lightning2:dispose())
                = seconds 2
            )
            (case 8
                (thunder:play())
                Animate((send gCast:elements) 0)
                (lightning1:dispose())
                (self:init())
            )
        )
    )

)
(instance ripScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = cycles 1
            )
            (case 1
                (send gLongSong2:
                    number(821)
                    loop(-1)
                    vol(127)
                    play()
                )
                (rip:
                    setLoop(0)
                    init()
                )
                (rip:setCycle(ForwardCounter 7 self))
            )
            (case 2
                (send gLongSong2:
                    number(822)
                    play()
                )
                (rip:
                    y(66)
                    setLoop(1)
                    setCel(0)
                    setCycle(End self)
                )
            )
            (case 3
                (rip:
                    setLoop(2)
                    setCel(0)
                )
                (rip:setCycle(ForwardCounter 4 self))
            )
            (case 4
                (send gEgo:
                    init()
                    normal(0)
                    x(155)
                    y(75)
                    yStep(10)
                    view(62)
                    setLoop(3)
                    setCel(0)
                    setCycle(0)
                    setPri(3)
                    ignoreActors(1)
                    ignoreHorizon(1)
                    setMotion(MoveTo 155 110 self)
                )
            )
            (case 5
                (send gEgo:
                    setStep(3 20)
                    setCel(0)
                    setCycle(0)
                    setMotion(MoveTo 155 160 self)
                )
            )
            (case 6
                (send gLongSong2:
                    priority(15)
                    vol(127)
                    number(115)
                    loop(1)
                    play()
                )
                (rip:
                    setLoop(1)
                    setCel(15)
                    setCycle(Beg)
                )
                (send gEgo:
                    cycleSpeed(0)
                    setCycle(CT 2 1 self)
                )
            )
            (case 7
                (rip:dispose())
                = seconds 2
            )
            (case 8
                (send gEgo:
                    cycleSpeed(1)
                    setCycle(End self)
                )
            )
            (case 9
                = seconds 2
            )
            (case 10
                (send gEgo:setCycle(CT 5 -1 self))
            )
            (case 11
                (send gLongSong2:number(0))
                (send gEgo:
                    setLoop(4)
                    setCel(0)
                    setCycle(End self)
                )
            )
            (case 12
                (send gLongSong:
                    number(802)
                    loop(-1)
                    flags(1)
                    playBed()
                )
                proc0_1(2 0)
                proc0_9()
                = seconds 3
            )
            (case 13
                (send gEgo:setHeading(0))
                = cycles 10
            )
            (case 14
                Print("\"NOW where am I?\" you wonder aloud to nonexistent auditory organs. This place sure looks homey. Hey, wait! This looks just like Xenon! It IS Xenon! It's.. it's.. it's really a pile.")
                Print("Along with the changes induced by an armed conflict, the city looks different - more modern with a heavy dash of post-disaster seasoning. Casually glancing at the status line you happen to notice that you're in Space Quest !")
                Print("What's happened? Who was that guy with the overdeveloped hair dryer? Why did you let yourself be talked into jumping into some strange shimmering hole? Why are you talking to yourself? These incredibly intriguing questions will quickly be forgotten with barely an electron stirred in that well-armored orb atop your shoulders.")
                (lightningScript:start(1))
                (lightning1:
                    init()
                    setScript(lightningScript)
                )
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance enterScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (switch (gWest)
                    (case 55
                        (send gEgo:
                            x(65528)
                            setMotion(MoveTo 10 (send gEgo:y) self)
                        )
                    )
                    (default 
                        (send gEgo:
                            x(328)
                            setMotion(MoveTo 310 (send gEgo:y) self)
                        )
                    )
                )
            )
            (case 1
                proc0_3()
                (send client:setScript(0))
            )
        )
    )

)
(instance rip of Prop
    (properties
        x 154
        y 82
        view 62
        loop 2
        cel 1
        priority 2
        signal 16
    )
)
(instance lightning1 of Prop
    (properties
        x 124
        y 15
        view 61
    )

    (method (doit)
        (super:doit())
        (if (== (send global2:curPic) 31)
            (self:z(1000))
        )(else
            (self:z(0))
        )
    )

)
(instance lightning2 of Prop
    (properties
        x 152
        y 24
        view 61
        loop 1
        priority 6
        signal 16
    )

    (method (doit)
        (super:doit())
        (if (== (send global2:curPic) 31)
            (self:z(1000))
        )(else
            (self:z(0))
        )
    )

)
(instance poly1 of Polygon
    (properties
        type 2
    )
)
(instance theFrontRubble of Feature
    (properties
        x 160
        y 300
        nsBottom 200
        nsRight 320
        description "rubble"
        sightAngle 45
        onMeCheck 64
        lookStr "A twisted and broken expanse of cityscape stretches south from here negating possible travel plans in that direction."
    )

    (method (doVerb param1)
        (switch (param1)
            (case 2
                Print("The rubble is rough and jagged. No sense in risking injury this early in the adventure. We'll get to that in due time.")
            )
            (case 10
                Print("The wreckage left by the destruction of the entire Xenon civilization tastes a little like some ancient ruins you once sampled.")
            )
            (case 11
                Print("The snappy scent of freshly chopped buildings fills the air.")
            )
            (default 
                (super:doVerb(param1))
            )
        )
    )

)
(instance theBackRubble of Feature
    (properties
        x 155
        y 78
        nsBottom 200
        nsRight 320
        description "rubble"
        sightAngle 45
        onMeCheck 16
        lookStr "More rubble can be seen to the north."
    )

    (method (doVerb param1)
        (switch (param1)
            (case 10
                Print("Even when you were a youngster way back in Space Quest 1 you couldn't have pulled that off at this distance.")
            )
            (case 11
                Print("The direction of the prevailing breezes prevents any hint of aroma.")
            )
            (default 
                (super:doVerb(param1))
            )
        )
    )

)
(instance theBuildings of Feature
    (properties
        nsBottom 200
        nsRight 320
        description "building"
        sightAngle 45
        lookStr "Decaying and destroyed buildings now house the apparently nonexistent population of Xenon."
    )

    (method (doVerb param1)
        (switch (param1)
            (case 10
                Print("A REAL man would actually walk up to a building if he wanted to taste it. Unless you were just trying to lap up the atmosphere?")
            )
            (case 11
                Print("You'll have to be closer to the buildings to give them a really good smell.")
            )
            (default 
                (super:doVerb(param1))
            )
        )
    )

)
(instance theStreet of Feature
    (properties
        nsBottom 200
        nsRight 320
        description "street"
        onMeCheck 4
    )

    (method (doVerb param1 param2)
        (switch (param1)
            (case 1
                (theArea:doVerb(1))
            )
            (case 3
                (send (ScriptID(705 4)):doVerb(3 param2))
            )
            (case 10
                Print("You transfer a thick smear of filth from the street to your tongue. Finding the taste unpleasant, you quickly swallow it. What a smart person you are!")
            )
            (case 11
                Print("You inhale deeply and detect the aroma of very old traffic.")
            )
            (default 
                (super:doVerb(param1))
            )
        )
    )

)
(instance theSuperComputer of Feature
    (properties
        x 160
        y 3
        nsBottom 200
        nsRight 320
        description "distant structure"
        sightAngle 45
        onMeCheck 8
        lookStr "It looks like a graphic referenced repeatedly in a product use brochure for a line of foot care aids. Speaking of foot care, you haven't changed your socks in a couple of sequels. It conjures an unpleasant olfactory image."
    )

    (method (doVerb param1)
        (switch (param1)
            (case 10
                Print("The prevailing noxious wind prevents this.")
            )
            (case 11
                Print("The prevailing noxious wind prevents this.")
            )
            (default 
                (super:doVerb(param1))
            )
        )
    )

)
(instance theArea of Feature
    (properties
        nsBottom 200
        nsRight 320
        description "area"
    )

    (method (doVerb param1 param2)
        (switch (param1)
            (case 1
                Print("You are in the southern area of a rare clearing in this destroyed cityscape. All around you inanimate victims of war litter the streets. Your home as you remembered it does not exist in this period of Xenon's time. A huge boil of a structure clogs the horizon.")
            )
            (case 3
                (send (ScriptID(705 4)):doVerb(3 param2))
            )
            (default 
                (super:doVerb(param1))
            )
        )
    )

)
(instance thunder of Sound
    (properties
        number 150
        priority 15
    )
)
